
function Form_Validator(theForm)
{
  
  if (theForm.firstName.value == "")
  {
    alert("Please enter a value for \"First Name\"");
    theForm.firstName.focus();
    return (false);
  }
  if (theForm.lastName.value == "")
  {
    alert("Please enter a value for \"Last Name\"");
    theForm.lastName.focus();
    return (false);
  }
  if (theForm.company.value == "")
  {
    alert("Please enter a value for \"Company\"");
    theForm.company.focus();
    return (false);
  }
  if (theForm.address.value == "")
  {
    alert("Please enter a value for \"Address\"");
    theForm.address.focus();
    return (false);
  }
  if (theForm.city.value == "")
  {
    alert("Please enter a value for \"City\"");
    theForm.city.focus();
    return (false);
  }
  if (theForm.zip.value == "")
  {
    alert("Please enter a value for \"Zip Code\"");
    theForm.zip.focus();
    return (false);
  }
  if (theForm.phone.value == "")
  {
    alert("Please enter a value for \"Phone\"");
    theForm.phone.focus();
    return (false);
  }
  if (theForm.email.value == "")
  {
    alert("Please enter a value for \"E-mail\"");
    theForm.email.focus();
    return (false);
  }
 
 
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var s=theForm.email.value
		
	var matchArray=s.match(emailPat);
	if (matchArray==null) 
		{
			alert("email seems incorrect (check @ and .'s)");
    		theForm.email.focus();
    		return (false);
		}
		
	var user=matchArray[1];
	var domain=matchArray[2];
	if (user.match(userPat)==null) 
		{
		    alert("The email username doesn't seem to be valid");
			theForm.email.focus();
		    return false;
		}
	
	var domainArray=domain.match(domainPat);		
	if (domainArray==null) 
		{
			alert("The email domain name doesn't seem to be valid");
			theForm.email.focus();
			return false;
		}

	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4) 
		{
	   		alert("Email must end in a three or four letter domain, or two letter country.");
			theForm.email.focus();
			return false;
		}
	
	if (len<2) 
		{
		   adderror("Make sure there's a host email name preceding the domain.");
		   theForm.email.focus();
		   return false;
		}
		
   if (theForm.password.value == "")
  {
    alert("Please enter a value for \"Password\"");
    theForm.password.focus();
    return (false);
  }
		
  if (theForm.password.value.length < 5)
  {
    alert("Password must be at least 5 characters");
    theForm.password.focus();
    return (false);
  }
  
  return (true);
}
