function isValidEmail(inputString) 
{
   var x
   var domain_name;
	var y
	var retValue
	var z1
	var z2
	var z3
	var z4
	var z5
	var z6
	var z7
	var z8
	
	x = inputString.indexOf("@")
	y = inputString.lastIndexOf(".")
	z1 = inputString.lastIndexOf(".net")
   z2 = inputString.lastIndexOf(".com")
	z3 = inputString.lastIndexOf(".org")
	z4 = inputString.lastIndexOf(".edu")
	z5 = inputString.lastIndexOf(".gov")
	z6 = inputString.lastIndexOf(".mil")
	z7 = inputString.lastIndexOf(".cc")
	z8 = inputString.lastIndexOf(".us")
	if(x!= -1)
	domain_name = inputString.substr(x+1,inputString.length);
	if (x == -1) 
	{
	   retValue = "Email Address must contain an '@' symbol.";
	}
	else if (z1 == -1 && z2 == -1 && z3 == -1 && z4 == -1 && z5 == -1 && z6 == -1 && z7 == -1 && z8 == -1) 
	{
	   retValue = "Email Address must end with '.com', '.net', '.org', '.edu', '.gov', '.mil', '.us' or '.cc'.";
	} 
	else if (x > y || y > inputString.length-3) 
	{
	   retValue = "Email Address must end with a valid domain extension. (.com, .net ...)";
	} 
	else if(domain_name == 'hotmail.com' || domain_name == 'yahoo.com' || domain_name == 'aol.com' || domain_name == 'lyos.com' || domain_name == 'verizon.com' || domain_name == 'gmail.com' || domain_name == 'lycos.com' || domain_name == 'excite.com' )
	{
	retValue = "You must enter a business e-mail address as this is an \"employer\" service only.  \n No personal searches please.";	
	}
	else 
	{
	   retValue = "";
	}
   
	return retValue;
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function EmailErrorCheck() {
   var errCount
	var errTag
	var errMesg
	var tempPhone
	var v
	
	tempPhone = trim(document.Form1.phone1.value) + trim(document.Form1.phone2.value) + trim(document.Form1.phone3.value)
	
	errMesg = ""
	errTag = 0
	errCount = 0
	
	if (trim(document.Form1.lastName.value) == "") {
      errTag = 1;
		errCount = errCount + 1;
		errMesg = errMesg + errCount + ". You must enter a Last Name.\n";
	}	
	if (trim(document.Form1.firstName.value) == "") {
      errTag = 1;
		errCount = errCount + 1;
		errMesg = errMesg + errCount + ". You must enter a First Name.\n";
	}	
	if (trim(document.Form1.company.value) == "") {
		errTag = 1;
		errCount = errCount + 1;
		errMesg = errMesg + errCount + ". You must enter a Company.\n";
   }
	if (tempPhone == "") {
      errTag = 1;
		errCount = errCount + 1;
		errMesg = errMesg + errCount + ". You must enter a Phone Number.\n";
	} else {
      if (isNaN(tempPhone)) {
		   errTag = 1;
		   errCount = errCount + 1;
		   errMesg = errMesg + errCount + ". Phone Numbers can only contain numbers.\n";
	   }
		if (tempPhone.length != 10) {
         errTag = 1;
		   errCount = errCount + 1;
		   errMesg = errMesg + errCount + ". Phone Numbers must be 10 digits long.\n";
	   }
	}
	if (trim(document.Form1.email.value) == "")
	{
		errTag = 1;
		errCount = errCount + 1;
		errMesg = errMesg + errCount + ". You must enter an Email Address.\n";
   } 
   else
   {
	   v = isValidEmail(trim(document.Form1.email.value));
	   if (v != "") {
		errTag = 1;
		   errCount = errCount + 1;
		   errMesg = errMesg + errCount + ". Contact " + v + "\n";
		}
	}
	if (document.Form1.state.selectedIndex == 0) {
      errTag = 1;
		errCount = errCount + 1;
		errMesg = errMesg + errCount + ". You must select a State.\n";
   }
	if (document.Form1.businessType.selectedIndex == 0) {
      errTag = 1;
		errCount = errCount + 1;
		errMesg = errMesg + errCount + ". You must select a Business Type.\n";
   }
				
	if (errTag == 1) {
	   alert(errMesg);
	} else {
		document.Form1.submit();
	}
}