  function chkEmail(eml)
{
	var re = /^[0-9a-zA-Z\-\.\_]+@[0-9a-zA-Z\-]+\.[0-9a-zA-Z\-\.]+$/;
	if (!eml.match(re)) 
		return 0;
	else
		return 1;

}

function LTrim(str)
{
  var whitespace = new String(" \t\n\r");

  var s = new String(str);

  if (whitespace.indexOf(s.charAt(0)) != -1) {
    // We have a string with leading blank(s)...

    var j=0, i = s.length;

    // Iterate from the far left of string until we
    // don't have any more whitespace...
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
    j++;


    // Get the substring from the first non-whitespace
    // character to the end of the string...
    s = s.substring(j, i);
  }

  return s;
}


 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 == 1)
  {
  document.getElementById('sent').innerHTML="<img src='images/ajax-loader.gif' alt='Loading....' border=0>";
  }
  if (http.readyState == 4) 
  { 
  captchaOK = http.responseText; 
  
   if(captchaOK == 1)
   {
   	document.getElementById('sent').innerHTML="Information has been sent successfully.";
	var fname 	= document.getElementById('sname').value="";
	var comp 	= document.getElementById('comp').value="";
	var phone 	= document.getElementById('sphone').value=""; 
	var email 	= document.getElementById('semail').value=""; 
	//var service = document.getElementById('sservice').value=""; 
	
	var comment = document.getElementById('scomments').value=""; 
	var capcode = document.getElementById('scode').value=""; 
   }
  if(captchaOK != 1)
   { 
   document.getElementById('sent').innerHTML="";
   alert('The entered code was not correct. Please try again');
   //alert(captchaOK);
   document.leadform.scode.value=''; 
   document.leadform.scode.focus();
   return false; 
   } 
  
   //document.leadform.submit(); 
   
   } 
   }






function checklead(lform)
{
	
  var sname 	=LTrim(lform.sname.value);
  if(sname=="") {
   alert('Please complete the "required" field.'); 
   lform.sname.focus(); return false; 
   }
   if(LTrim(lform.scomp.value)=='') {
   alert('Please complete the "required" field.'); 
   lform.scomp.focus(); return false; 
   }
   if(LTrim(lform.semail.value)=='') {
   alert('Please complete the "required" field.'); 
   lform.semail.focus(); return false; 
   }
   

    if(chkEmail(lform.semail.value)==0) {
   alert('Please enter valid email address.'); 
   lform.semail.focus(); return false; 
   }
   
    if(lform.scode.value=='') {
	 alert('Please enter the string from the displayed image.'); 
	 lform.scode.value='';
	 lform.scode.focus(); 
	 return false; 
	 } // Now the Ajax CAPTCHA validation
   checkcode(lform.scode.value); return false;
	
}


