//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 receiveReq1 = getXmlHttpRequestObject();
 
//Initiate the AJAX request
function makeRequest1(url1, param1) {
//If our readystate is either not started or finished, initiate a new request
 if (receiveReq1.readyState == 4 || receiveReq1.readyState == 0) {
   //Set up the connection to captcha_test.html. 
   //True sets the request to asyncronous(default) 
   receiveReq1.open("POST", url1, true);
   //Set the function that will be called 
   //when the XmlHttpRequest objects state changes
   receiveReq1.onreadystatechange = updatePage1; 
 
   receiveReq1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   receiveReq1.setRequestHeader("Content-length", param1.length);
   receiveReq1.setRequestHeader("Connection", "close");
 
   //Make the request
   receiveReq1.send(param1);
 }   
}
 
//Called every time our XmlHttpRequest objects state changes
function updatePage1() {
 //Check if our response is ready
 if (receiveReq1.readyState == 4) {
   //Set the content of the DIV element with the response text
   	if(receiveReq1.responseText==1){
   		//document.getElementById('result1').innerHTML = receiveReq1.responseText;
   	}else{
		document.getElementById('txtCaptcha1').value = "";
	   //Get a reference to CAPTCHA image
	   img = document.getElementById('imgCaptcha1'); 
	   //Change the image
	   img.src = 'create_image1.php?' + Math.random();	
	}
 }
}
 
//Called every time when form is perfomed
function getParam1(theForm1) {
 //Set the URL
 var url1 = 'captcha1.php';
 //Set up the parameters of our AJAX call
 var postStr1 = theForm1.txtCaptcha1.name + "=";
 postStr1 += encodeURIComponent( theForm1.txtCaptcha1.value );
 //Call the function that initiate the AJAX request
 makeRequest1(url1, postStr1);

}