function selectUnit(replace,find,price) {
  eval('document.' + find + '.ArtikelID.value = ' + replace);
  eval('document.' + find + '.Prijs_totaal.value = ' + price +'') ;
  eval('document.' + find + '.Prijs.value = ' + price +'');
  eval('document.' + find + '.Prijs_original.value = ' + price +'');    
      rCells=document.getElementsByTagName('td');
      for (i = 0; i < rCells.length; i++) {
          if (rCells[i].className.search('_aangeklikt') > 1) {
            rCells[i].className = rCells[i].className.substring(0,9)
            //alert(rCells[i].className);
        }
      }
      //document.getElementById('artikel_' + replace).style.backgroundColor= 'green';
      document.getElementById('artikel_'+ replace + '').className = document.getElementById('artikel_'+ replace + '').className + '_aangeklikt';
}

function makeGETRequest(url, parameters) {
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
     http_request = new XMLHttpRequest();
     if (http_request.overrideMimeType) {
        // set type accordingly to anticipated content type
        //http_request.overrideMimeType('text/xml');
        http_request.overrideMimeType('text/html');
     }
  } else if (window.ActiveXObject) { // IE
     try {
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
        try {
           http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
     }
  }
  if (!http_request) {
     alert('Cannot create XMLHTTP instance');
     return false;
  }
  
  http_request.onreadystatechange = alertContents2;
  http_request.open('GET', url, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}
function alertContents2() {
  if (http_request.readyState == 4) {
     if (http_request.status == 200) {
        //alert(http_request.responseText);
        result = http_request.responseText;
        Popup.hide('modal_load');
        document.getElementById('modal').innerHTML = result;                
        Popup.showModal('modal',null,null);return false;

     } else {
        alert('There was a problem with the request.');
     }
  }
}

function bestellen(artikelcode,catid,unit,form,price,aantal) {
  selectUnit(unit,form,price);
  artikelid = eval('document.' + form + '.ArtikelID.value');
  document.getElementById('modal_load').innerHTML = "<img src='/images/loading-bar.gif'>";
  Popup.showModal('modal_load',null,null);
  makeGETRequest('/getpage.php?page=bestelling&artikelid=' + artikelid + '&prijs=' + price + '&categorie=' + catid +'&artikelcode=' + artikelcode + '&aantal=' + aantal,"?a");
}

function draaien() {
  document.getElementById('modal_load').innerHTML = "<img src='/images/loading-bar.gif'>";
  Popup.showModal('modal_load',null,null);
}

function checkbesteling(find,teller){  
  /*rCells=document.getElementsByTagName('tr');
  for (i = 0; i < rCells.length; i++) {
      if (rCells[i].className.search('_aangeklikt') > 1) {
        rCells[i].className = rCells[i].className.substring(0,3);
        //alert(rCells[i].className);
    }
  }
  document.getElementById('' +  teller + '').className = document.getElementById('' +  teller + '').className + '_aangeklikt';  
  */
  if(document.forms['' +  find + ''].ArtikelID.value == ""){
        alert('Om een product te bestellen klikt u op het gewenste product, afmeting en/of oplage in de prijstabel.');
        //document.forms['contact'].naam.focus();
        return false;
    }else{
      //document.forms['vulwagen' + find].submit(); 
       return true;
    } 
}
 
var regexp = / /g;
function verzenden2(){
    if(document.forms['productinfo'].naam.value.replace(regexp,"") == ""){
        alert('Voer alstublieft uw naam in.');
        document.forms['productinfo'].naam.focus();
        return false;
    }
    if(document.forms['productinfo'].mail.value.replace(regexp,"") == ""){
        alert('Voer alstublieft uw e-mailadres in.');
        document.forms['productinfo'].mail.focus();
        return false;
    }
    if(document.forms['productinfo'].mail.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
        alert('U heeft een ongeldig e-mailadres ingevuld.');
        document.forms['productinfo'].mail.focus();
        return false;
    }
    document.forms['productinfo'].submit();
}
