function validate_required(field,alerttxt)
{
	with (field)
	{
		if (value==null||value=="0"||value=="")
		  {alert(alerttxt);return false}
			else {return true}
	}
}
function validate_form(thisform)
{
	with (thisform)
	{
		if (validate_required(firstname,"First name must be filled out")==false)
		  {firstname.focus();return false}
		if (validate_required(lastname,"Last name must be filled out")==false)
		  {lastname.focus();return false}
		if (validate_required(address1,"Address must be filled out")==false)
		  {address1.focus();return false}
		if (validate_required(city,"City must be filled out")==false)
		  {city.focus();return false}
		if (validate_required(state,"State must be selected")==false)
		  {state.focus();return false}
		if (validate_required(zipcode,"Zip code must be filled out")==false)
		  {zipcode.focus();return false}
		if ((email.value==null)||(email.value=="")){
		  alert("Please enter your email address")
		  email.focus()
		  return false
		}
		if (echeck(email.value)==false){
		  email.value=""
		  email.focus()
		  return false
		}
		
				
		else
			{
			return true;
			}
		
	}
}



function submitform(formName, page)
{
 	if (validate_form(document.forms[formName]) == true )
  	{
	  document.forms[formName].action = page	
  	  document.forms[formName].submit();
	 
	}
}




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					
	}