// JavaScript Document
//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 makeRequest_1(url, param, flag) {
//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
   //if (flag==0) {
		receiveReq.onreadystatechange = updatePage; 
   //} else {
	//	receiveReq.onreadystatechange = updatePagefield;
   //}

   //Add HTTP headers to the request
   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 updatePage() {
//Check if our response is ready
	if (receiveReq.readyState == 4 && receiveReq.status == 200) { 
			strReturn = receiveReq.responseText;
		 
			if( strReturn=='Match'){  
				document.getElementById('cimgcheck').value = 1;	
				document.getElementById('captcha_wrong').style.display = 'none';
				document.getElementById('captcha_corr').style.display = '';
				
				submitMe();
			}else{  
				document.getElementById('cimgcheck').value = 0;
				document.getElementById('captcha_err_mess').style.display = '';
				document.getElementById('captcha_wrong').style.display = '';
				document.getElementById('captcha_corr').style.display = 'none';
			}
			
		//document.getElementById('result').innerHTML = receiveReq.responseText;
	} else {
		   //document.getElementById('result').innerHTML = "Loading...";
		//alert('There was a problem with the request.');
	}
		
}

///////////////////////////
///////////////////////////////////////
/////////////////////////////////////////////////
//Initiate the AJAX request
function makeRequest_2(url, param, flag) {
//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
   //if (flag==0) {
		receiveReq.onreadystatechange = updatePagefield; 
   //} else {
	//	receiveReq.onreadystatechange = updatePagefield;
   //}

   //Add HTTP headers to the request
   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);
 }   
}

function updatePagefield() {
//Check if our response is ready
	if (receiveReq.readyState == 4 && receiveReq.status == 200) { 
			strReturn = receiveReq.responseText;
		 
			if( strReturn=='Match'){  
				document.getElementById('cimgcheck').value = 1;	
				document.getElementById('captcha_wrong').style.display = 'none';
				document.getElementById('captcha_corr').style.display = '';
				
				//submitMe();
			}else{  
				document.getElementById('cimgcheck').value = 0;
				document.getElementById('captcha_err_mess').style.display = '';
				document.getElementById('captcha_wrong').style.display = '';
				document.getElementById('captcha_corr').style.display = 'none';
			}
			
		//document.getElementById('result').innerHTML = receiveReq.responseText;
	} else {
		   //document.getElementById('result').innerHTML = "Loading...";
		//alert('There was a problem with the request.');
	}
		
}