var url = 'captcheck.asp?code='; 
//alert(url);
var captchaOK = 2; 
// 2 - not yet checked, 1 - correct, 0 - failed 
function getHTTPObject()
 {
  try
   { 
   req = new XMLHttpRequest();
    }
	 catch (err1)
	  {
	   try
	    {
		 req = new ActiveXObject("Msxml12.XMLHTTP");
		  } 
		  catch (err2) 
		  { 
		  try
		   { 
		   req = new ActiveXObject("Microsoft.XMLHTTP"); 
		   }
		    catch (err3) 
			{ 
			req = false;
			 } 
			 } 
			 }
			  return req;
			   } 
			   var http = getHTTPObject(); 
// We create the HTTP Object 
function handleHttpResponse() 
{
 if (http.readyState == 4) 
 { 
 captchaOK = http.responseText; 
 //alert(captchaOK);
 if(captchaOK != 1) 
 {
  alert('The entered code was not correct. Please try again');
   document.myform.code.value=''; document.myform.code.focus(); 
   return false; 
   }
    document.myform.submit(); 
	}
	 }
	  function checkcode(thecode)
	   { 
	//   alert(thecode);
	   http.open("GET", url + escape(thecode), true); 
	//   alert(url + escape(thecode));
	   http.onreadystatechange = handleHttpResponse;
	    http.send(null); 
		}
		 function checkform() 
		 { 
// First the normal form validation 
if(document.myform.name.value=='')
 {
  alert('Please enter Name field'); 
  document.myform.name.focus(); 
  return false; 
  }

 if (document.myform.email.value == "")
	{
	alert("Please enter a value for the \"Email\" field.");
	document.myform.email.focus();
	return (false);
	}
	else 
    {
	var checkEmail = "@.";
	var checkStr = document.myform.email.value;
	var EmailValid = false;
	var EmailAt = false;
	var EmailPeriod = false;
	for (i = 0; i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkEmail.length;  j++)
		{
		if (ch == checkEmail.charAt(j) && ch == "@")
		EmailAt = true;
		if (ch == checkEmail.charAt(j) && ch == ".")
		EmailPeriod = true;
		  if (EmailAt && EmailPeriod)
		break;
      	  if (j == checkEmail.length)
		break;
		}
			if (EmailAt && EmailPeriod)
			{
			EmailValid = true
			break;
			}
		}
		if (!EmailValid)
		{
		alert("Invalid Email ID entered");
		document.myform.email.focus();
		return (false);
		}
}
if(document.myform.phone.value=='')
 {
  alert('Please enter Phone field'); 
  document.myform.phone.focus(); 
  return false; 
  }
    if(document.myform.country.value=='')
 {
  alert('Please complete the Country field'); 
  document.myform.country.focus(); 
  return false; 
  }
    if(document.myform.code.value=='')
    { 
	alert('Please enter the string from the displayed image'); 
	document.myform.code.value=''; 
	document.myform.code.focus(); 
	return false; 
	} 
// Now the Ajax CAPTCHA validation 
checkcode(document.myform.code.value); 
return false; 
}
