var xmlHttp;

function getpic()
{
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request")
    return
  } 
  var url= "hc.php";
  xmlHttp.onreadystatechange=stateChanged; 
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
} 


function validate()
{
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request")
    return
  } 
  var url= "check.php?hc=" + document.getElementById("humancheck").value;
  xmlHttp.onreadystatechange=stateChangedChk; 
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
} 

function stateChanged() 
{ 
 if(xmlHttp.readyState==1){
	 document.body.style.cursor = 'wait'; 
 }
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
  document.getElementById("hcdiv").innerHTML=xmlHttp.responseText;
  document.body.style.cursor = 'default';
  document.getElementById("humancheck").value = "";
 } 
}

function stateChangedChk() 
{ 
 if(xmlHttp.readyState==1){
	 document.body.style.cursor = 'wait'; 
 }
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
  document.body.style.cursor = 'default';
  if(xmlHttp.responseText == "1"){
		document.lead_form.submit();
	}else{
		alert("Please type the characters from the picture into the textbox below.");
		document.lead_form.humancheck.focus();
		getpic();
	}
 } 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try{
 xmlHttp=new XMLHttpRequest();
 }
catch (e){
	 try{
	   	 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	 catch (e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!");
				return false;
			}
	  }
 }
return xmlHttp;
}
