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_top = getXmlHttpRequestObject();

//Initiate the AJAX request
function makeRequest_top(url,param) {
	
	
//If our readystate is either not started or finished, initiate a new request
 if (receiveReq_top.readyState == 4 || receiveReq_top.readyState == 0) {
   //Set up the connection to captcha_test.html. True sets the request to asyncronous(default) 
   receiveReq_top.open("POST", url, true);
   //Set the function that will be called when the XmlHttpRequest objects state changes
   receiveReq_top.onreadystatechange = updatePage_top; 

   receiveReq_top.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  // receiveReq_top.setRequestHeader("Content-length", param.length);
   receiveReq_top.setRequestHeader("Content-length", param.length);
   receiveReq_top.setRequestHeader("Connection", "close");

   //Make the request
   receiveReq_top.send(param);
   
 }   
  
}

//Called every time our XmlHttpRequest objects state changes
function updatePage_top() {
 //Check if our response is ready
 if (receiveReq_top.readyState == 4) {
   //Set the content of the DIV element with the response text
   //alert(receiveReq_top.responseText);
  
  // document.getElementById('result').value = receiveReq_top.responseText;
   //Get a reference to CAPTCHA image
   img = document.getElementById('imgCaptcha_top'); 
   //Change the image
  
   if(receiveReq_top.responseText=="true")
   {
   	document.form_top.submit()
   }else
   {
	   document.getElementById('result_top').innerHTML = "Error! Invalid verification code";
	   img.src = 'create_image_top.php?' + Math.random();
   }
   
   
   
 }
}


function echeck(str) 
{
        var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		  
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		    return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   
		    return false
		 }

 		 return true					
}

//Called every time when form is perfomed
function getParam_top(theForm) {
 //Set the URL
 
 var url = 'captcha_top.php';
 //Set up the parameters of our AJAX call
 var postStr = theForm.txtCaptcha_top.name + "=" + encodeURIComponent( theForm.txtCaptcha_top.value );
 //Call the function that initiate the AJAX request
 makeRequest_top(url, postStr);

}

<!-- Begin
function checkFields_top() {
 
missinginfo = "";

if(document.form_top.Name.value == "" | document.form_top.Name.value=='Name') {
missinginfo += "\n     -  Name";
}
if(document.form_top.Email.value == "" | document.form_top.Email.value=='Email') {
missinginfo += "\n     -  Email";
}else if(echeck(document.form_top.Email.value)==false) {
missinginfo += "\n     -  Invalid E-mail ID";
}if(document.form_top.Phone.value == "" | document.form_top.Phone.value=='Phone') {
missinginfo += "\n     -  Phone";
}
if(document.form_top.Question.value == "" | document.form_top.Question.value=='Question?') {
missinginfo += "\n     -  Question?";
}

if(document.form_top.txtCaptcha_top.value == "") {
missinginfo += "\n     -  Verification Code";
}

if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"Please complete the missing required fields:\n" +
missinginfo + "\n_____________________________" +
"\nPlease re-enter and submit again!";
alert(missinginfo);
return false;
}else
{
getParam_top(document.form_top);


return false;
}
//return true;
}
//  End -->

