// JavaScript Document
// JavaScript Document
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){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

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

 		 return true					
	}




function require()
{
	if(document.WebToLeadForm.first_name.value=="")
	{
		alert("Please Enter Your First Name!");
		document.WebToLeadForm.first_name.focus();
		return false;
	}
	if(document.WebToLeadForm.last_name.value=="")
	{
		alert("Please Enter Your Last Name!");
		document.WebToLeadForm.last_name.focus();
		return false;
	}
	if(document.WebToLeadForm.webtolead_email1.value=="")
	{
		alert("Please Enter Your Email Address!");
		document.WebToLeadForm.webtolead_email1.focus();
		return false;
	}
	if (echeck(document.WebToLeadForm.webtolead_email1.value)==false){
		document.WebToLeadForm.webtolead_email1.focus();
		return false
	}
	
	if(document.WebToLeadForm.description.value=="")
	{
		alert("Please Enter Your Requirement!");
		document.WebToLeadForm.description.focus();
		return false;
	}
	
	// ajax  cod e is staert  from here
	
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
   ajaxRequest.onreadystatechange=function()
  {
  if (ajaxRequest.readyState==4 && xmlhttp.status==200)
    {
    	document.getElementById("txtHint").value=ajaxRequest.responseText;
		alert(document.getElementById("txtHint").value);
		return true;
    }
  }
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			//document.getElementById('description').value = ajaxRequest.responseText;
			return true;
		}
	}
	
	var first_name = document.getElementById('first_name').value;
	
	var last_name = document.getElementById('last_name').value;
	
	var account_name = document.getElementById('account_name').value;
	
	var webtolead_email1 = document.getElementById('webtolead_email1').value;
	
	var phone = document.getElementById('phone_work').value;
	
	var description = document.getElementById('description').value;
	//alert('hello');
	var queryString = "?first_name=" + first_name + "&last_name=" + last_name + "&account_name=" + account_name + "&webtolead_email1=" + webtolead_email1 + "&phone=" + phone + "&description=" + description;
	
	//alert(queryString);
	
	ajaxRequest.open("GET", "insert.php" + queryString, true);
	ajaxRequest.send(); 
	// Ajax  code  end  here
}