
//Gets the browser specific XmlHttpRequest Object 
function getXmlHttpRequestObject() {
 if (window.XMLHttpRequest) {
    return new XMLHttpRequest(); //Mozilla, Safari ...
 } else if (window.ActiveXObject) {
    return new ActiveXObject("Microsoft.XMLHTTP"); //IE
 } else {
    //Display our error message
    alert("Your browser doesn't support the XmlHttpRequest object.");
 }
}

//Our XmlHttpRequest object
var receiveReq = getXmlHttpRequestObject();

//Initiate the AJAX request
function makeRequestBestel(url, param) {
//If our readystate is either not started or finished, initiate a new request
 if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
   //Set up the connection to captcha_test.html. True sets the request to asyncronous(default) 
   receiveReq.open("POST", url, true);
   //Set the function that will be called when the XmlHttpRequest objects state changes
   receiveReq.onreadystatechange = updatePageBestel; 

   receiveReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   receiveReq.setRequestHeader("Content-length", param.length);
   receiveReq.setRequestHeader("Connection", "close");

   //Make the request
   receiveReq.send(param);
 }   
}

//Called every time our XmlHttpRequest objects state changes
function updatePageBestel() {
 //Check if our response is ready
 if (receiveReq.readyState == 4) {
   //Set the content of the DIV element with the response text
   document.getElementById('resultBestel').innerHTML = receiveReq.responseText;
   //Get a reference to CAPTCHA image
   img = document.getElementById('imgCaptcha'); 
   //Change the image
   img.src = 'captcha/create_image.php?' + Math.random();
 }
}

//Called every time when form is perfomed
function getParamBestel(theForm) {
 //Set the URL
 var url = 'captcha/captcha_bestel.php';
 //Set up the parameters of our AJAX call
 var postStr = theForm.txtCaptcha.name + "=" + encodeURIComponent( theForm.txtCaptcha.value );
 var postName = encodeURIComponent( theForm.txtName.value );
 var postAdres = encodeURIComponent( theForm.txtAdres.value );
 var postPostcode = encodeURIComponent( theForm.txtPostcode.value );
 var postPlaats = encodeURIComponent( theForm.txtPlaats.value ); 
 var postEmail = encodeURIComponent( theForm.txtEmail.value );
 
 var postCd09 = encodeURIComponent( theForm.txtCd09.checked );
 var postCd08 = encodeURIComponent( theForm.txtCd08.checked );
 var postCd07 = encodeURIComponent( theForm.txtCd07.checked );
 var postCd06 = encodeURIComponent( theForm.txtCd06.checked );
 var postCd05 = encodeURIComponent( theForm.txtCd05.checked );
  
 //var postOl2008abri = encodeURIComponent( theForm.ol2008abri.checked );
 //var postOl2008a0 = encodeURIComponent( theForm.ol2008a0.checked );
 //var postOl2007abri = encodeURIComponent( theForm.ol2007abri.checked );
 //var postOl2007a0 = encodeURIComponent( theForm.ol2007a0.checked );
 //var postOl2007a2 = encodeURIComponent( theForm.ol2007a2.checked ); 
 //var postOl2006abri = encodeURIComponent( theForm.ol2006abri.checked );
 
 //var postStr = postStr +"|"+ postName +"|"+postAdres +"|"+postPostcode +"|"+postPlaats +"|"+postEmail + "|"+postCd08 + "|"+postCd07 + "|"+postCd06 + "|"+postCd05 +"|"+ postOl2008abri +"|"+postOl2008a0 +"|"+ postOl2007abri +"|"+ postOl2007a0 +"|"+ postOl2007a2+"|"+ postOl2006abri;
 var postStr = postStr +"|"+ postName +"|"+postAdres +"|"+postPostcode +"|"+postPlaats +"|"+postEmail + "|"+postCd08 + "|"+postCd07 + "|"+postCd06 + "|"+postCd05 + "|" +postCd09;
 //Call the function that initiate the AJAX request
 makeRequestBestel(url, postStr);
}




