var emailfilter = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;

// Checks for a valid email address
function checkmail(e){
	var returnval = emailfilter.test(e.value);
	if (returnval == false){
		alert("Please enter a valid email address.");
		e.select();
	}
	return returnval;
}
// JavaScript Document// JavaScript Document

function chex()
{

	
	if (document.form1.first_name.value=='' )
	{
	alert('You must fill out first name field to proceed');
	document.form1.first_name.focus();
	document.form1.first_name.style.backgroundColor="#FF9900";
	return false;
	
	}
	if (document.form1.last_name.value=='' )
	{
	alert('You must fill out last name field to proceed');
	document.form1.last_name.focus();
	document.form1.last_name.style.backgroundColor="#FF9900";
	return false;
	
	}
		
	if (document.form1.phone.value=='')
	{
	alert('You must fill out phone field to proceed');
	document.form1.phone.focus();
	document.form1.phone.style.backgroundColor="#FF9900";
	return false;
	
	}
	if(document.form1.phone.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1)
   {
      alert("The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.");
	  document.form1.phone.focus();
	document.form1.phone.style.backgroundColor="#FF9900";
      return false;
   }

	
if (document.form1.email_address.value=='')
		
		
	
	{
	alert('You must fill out the email field to proceed');
	document.form1.email_address.focus();
	document.form1.email_address.style.backgroundColor="#FF9900";
	return false;
	
	}
	if (echeck(document.form1.email_address.value)==false){
		document.form1.email_address.value=""
		document.form1.email_address.focus()
  		document.form1.email_address.style.backgroundColor="#FF9900";
		return false
	}


		
}
	




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 Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

 		 return true					
	}


	
	

