function validate_OnClick()
{
	var company=document.request.company.value;
	var field=document.request.field.value;
	var contact=document.request.contact.value;
	var address1=document.request.address1.value;
	var address2=document.request.address2.value;
	var city=document.request.city.value;
	var state=document.request.state.value;
	var phone=document.request.phone.value;
	var fax=document.request.fax.value;
	var e_mail=document.request.e_mail.value;
	var message=document.request.message.value;
        var linkurl=document.request.url.value;
	if(document.request.contact.value == "")
	{
		alert("Name can not be blank");
		document.request.contact.focus();
		return;
	}
	if(document.request.address1.value == "")
	{
		alert("Address can not be blank");
		document.request.address1.focus();
		return;
	}
	if(document.request.phone.value == "")
	{
		alert("Phone No. can not be blank");
		document.request.phone.focus();
		return;
	}
	else
	{
		if(isInteger(document.request.phone.value) == false )
		{
			alert("This is not a valid Phone No.");
			document.request.phone.focus();
			return;
		}
	}
	
	if(document.request.e_mail.value == "")
	{
		alert("Email can not be blank");
		document.request.e_mail.focus();
		return;
	}
	else
	{
		if(EmailValidator(document.request.e_mail.value) == false)
		{
			alert("Enter a valid Email Address");
			document.request.e_mail.focus();
			return;
		}
	}
	if(document.request.message.value == "")
	{
		alert("Enter the requirement");
		document.request.message.focus();
		return;
	}	
	
	window.location="send-mail.php?company="+company+"&field="+field+"&contact="+contact+"&address1="+address1+"&address2="+address2+"&city="+city+"&state="+state+"&phone="+phone+"&fax="+fax+"&e_mail="+e_mail+"&message="+message+"&linkurl="+linkurl;
}

function isInteger(fieldValue)
{
	var num = '0123456789.-';
	
	var i,j,found;
	found = false;
	
	for(i=0;i<fieldValue.length;i++)
	{
		for(j=0;j<num.length;j++)
		{
			if(fieldValue.charAt(i) == num.charAt(j))
			{
				found = true; break;
			}
		}
		if(found == false) {return false;}
		if(found == true) {found=false;}
	}
	
	return true;
}



function EmailValidator(email)
{
	var validflag=false		
	// primary condition checking
	if((email !="") && (email.indexOf("@")>0) && (email.indexOf(".")>0) )
	{
		var atcount=0
		var spflag=false
		var badflag
		for (var atloop=0 ; atloop<=email.length-1 ; ++atloop)
		{   
			atchr=email.charAt(atloop)
			// checking for special character
					   
			if (atchr=="@"){ atcount=atcount+1 }
			if  ( (atchr>=String.fromCharCode(32)) && (atchr<=String.fromCharCode(44))) { spflag=true }
			if ((atchr==String.fromCharCode(47)) || (atchr==String.fromCharCode(96)) || (atchr==String.fromCharCode(123)) )  spflag=true
			if ((atchr>=String.fromCharCode(58)) && (atchr<=String.fromCharCode(63))) spflag=true
			if ((atchr>=String.fromCharCode(91)) && (atchr<=String.fromCharCode(94))) spflag=true
		}
		if ((atcount==1) && (spflag==false))
		{
			badflag=false;
			sp=email.split('@');	 
			var username=sp[0];
			var domain=sp[1]; 
			if ((username="") || (domain=="")) badflag=true
			if (domain.charAt(0)==".") badflag=true
			if (domain.charAt(domain.len)==".") { badflag=true }
				validflag=true;
		}
	}
	
 	if (badflag==true)	validflag=false 
 	return validflag	   
}

