var url = 'captcheck.php?code='; 

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; 
 
 if(captchaOK != 1) 
 {
  alert('The entered code was not correct. Please try again');
   document.frm.code.value=''; document.frm.code.focus(); 
   return false; 
   }
    document.frm.submit(); 
	}
	 }
	  function checkcode(thecode)
	   { 
	
	   http.open("GET", url + escape(thecode), true); 
	   //alert(url + escape(thecode));
	   http.onreadystatechange = handleHttpResponse;
	    http.send(null); 
		}

function checkform(frm)
{			
		v1=frm.name
		if(isblank(v1)==false) 
	 		{
			alert("Name cannot be blank.");
			v1.focus(); 
			return false
			}	
			
			v1=frm.email
		if(isblank(v1)==false) 
			{
			alert("E-mail cannot be blank.");
			v1.focus(); 
			return false
			}
		if(isEmail(v1)==false) 
			{
			alert("The email \""+ v1.value+" \"is not valid email");
			v1.focus(); 
			return false;
			}
			v1=frm.phone
		if(isblank(v1)=="") 
	 		{
			alert("Phone no. cannot be blank.");
			v1.focus(); 
			return false;
			}
			
			if(isblank(v1)!="")
 			{
			if (isNaN(frm.phone.value)==true)
			{
			alert("Please enter phone no. in numeric");
			frm.phone.value=""
			frm.phone.focus();
			return false;
			}
}	
			
			v1=frm.code
		if(isblank(v1)==false) 
			{
			alert("you must enter varification code");
			v1.value=''; 
			v1.focus(); 
			return false
			}
			checkcode(document.frm.code.value); 
return false;
}




function isblank(s3) 
{
	if (s3.value == "") 
	{
	return false;
	}
else 
	{
	return true;
   }
}



function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function isEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\ \,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
	 return false
	} else if (!emailFilter.test(tfld)) {              //test email for illegal characters
   	return false
   
   } else if (fld.value.match(illegalChars)) {
	return false
    } else {
        //fld.style.background = 'White';
    }
    return true;
}


