function isEmail(emailStr) {

var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);

if (matchArray==null) {
	alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}

if (user.match(userPat)==null) {
	alert("The username doesn't seem to be valid.");
return false;
}

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

if (len<2) {
alert("This address is missing a hostname!");
return false;
}

return true;
}
/**************************************************************************************/
function EstimateValidateForm(theForm)
{

 if ((theForm.First_Name.value == "") || (theForm.First_Name.value.length <2))
  {
    alert("First Name Entered is invalid.");
    theForm.First_Name.focus();
    return (false);
  }

 if ((theForm.Last_Name.value == "") || (theForm.Last_Name.value.length <2))
  {
    alert("Last Name Entered is invalid.");
    theForm.Last_Name.focus();
    return (false);
  }

  if (theForm.Address1.value.length <5)
  {
    alert("Address(1) Entered is invalid.");
    theForm.Address1.focus();
    return (false);
  }

  if (theForm.City.value.length <3)
  {
    alert("City Entered is invalid.");
    theForm.City.focus();
    return (false);
  }

  if (theForm.stateid.value==0)
  {
    alert("State Selected is invalid.");
    theForm.stateid.focus();
    return (false);
  }
  if (theForm.Zip_Code.value.length<5)
  {
    alert("Zip Code Entered is invalid.");
    theForm.Zip_Code.focus();
    return (false);
  }

  return (true);
}

/*************************************************************************************/
function ServiceCallValidateForm(theForm)
{

 if ((theForm.First_Name.value == "") || (theForm.First_Name.value.length <2))
  {
    alert("First Name Entered is invalid.");
    theForm.First_Name.focus();
    return (false);
  }

 if ((theForm.Last_Name.value == "") || (theForm.Last_Name.value.length <2))
  {
    alert("Last Name Entered is invalid.");
    theForm.Last_Name.focus();
    return (false);
  }

  if (theForm.Address1.value.length <5)
  {
    alert("Address(1) Entered is invalid.");
    theForm.Address1.focus();
    return (false);
  }

  if (theForm.City.value.length <3)
  {
    alert("City Entered is invalid.");
    theForm.City.focus();
    return (false);
  }

  if (theForm.stateid.value==0)
  {
    alert("State Selected is invalid.");
    theForm.stateid.focus();
    return (false);
  }
  if (theForm.Zip_Code.value.length<5)
  {
    alert("Zip Code Entered is invalid.");
    theForm.Zip_Code.focus();
    return (false);
  }
  if (theForm.worktypeid.value==0)
  {
    alert("Select Type of Equipment.");
    theForm.worktypeid.focus();
    return (false);
  }
  if (theForm.brandid.value==0)
  {
    alert("Select Make of Equipment.");
    theForm.brandid.focus();
    return (false);
  }
  if (theForm.ageid.value==0)
  {
    alert("Select Age of Equipment.");
    theForm.ageid.focus();
    return (false);
  }
  if (theForm.Problem.value == "")
  {
    alert("Enter Problem or Work Desired.");
    theForm.Problem.focus();
    return (false);
  }

  if (theForm.Location.value == "")
  {
    alert("Enter Zone or Location.");
    theForm.Location.focus();
    return (false);
  }

  if (theForm.Time_Preference.value == "")
  {
    alert("Enter Date and Time Preference.");
    theForm.Time_Preference.focus();
    return (false);
  }
  return (true);
}
/*************************************************************************************/
function AgreementValidateForm(theForm)
{

 if ((theForm.Full_Name.value == "") || (theForm.Full_Name.value.length <2))
  {
    alert("Name Entered is invalid.");
    theForm.Full_Name.focus();
    return (false);
  }

if ((theForm.Phone.value == "") || (theForm.Phone.value.length <7))
  {
    alert("Enter a valid phone number.");
    theForm.Phone.focus();
    return (false);
  }

if (!isEmail(theForm.Email_Address.value))
  {
    theForm.Email_Address.focus();
    return (false);
  }
 return (true);
}
/*************************************************************************************/
function RefrigerationServiceAgreementValidateForm(theForm)
{

 if ((theForm.Name.value == "") || (theForm.Name.value.length <2))
  {
    alert("Name Entered is invalid.");
    theForm.Name.focus();
    return (false);
  }

if ((theForm.Phone.value == "") || (theForm.Phone.value.length <7))
  {
    alert("Enter a valid phone number.");
    theForm.Phone.focus();
    return (false);
  }

if (!isEmail(theForm.Email_Address.value))
  {
    theForm.Email_Address.focus();
    return (false);
  }
 return (true);
}
/*************************************************************************************/
function SignupValidateForm(theForm)
{
 if ((theForm.UserID.value == "") || (theForm.UserID.value.length <6))
  {
    alert("User ID must be at least 6 character long.");
    theForm.UserID.focus();
    return (false);
  }

 if ((theForm.Password.value == "") || (theForm.Password.value.length <6))
  {
    alert("Password must be at least 6 character long.");
    theForm.Password.focus();
    return (false);
  }

 if ((theForm.Password1.value == "") || (theForm.Password1.value.length <6))
  {
    alert("Password (2) must be at least 6 character long.");
    theForm.Password1.focus();
    return (false);
  }  

 if (theForm.Password.value != theForm.Password1.value)
  {
    alert("Password confirmation failed. Renter passwords");
    theForm.Password.focus();
    return (false);
  }  

 if ((theForm.First_Name.value == "") || (theForm.First_Name.value.length <2))
  {
    alert("First Name Entered is invalid.");
    theForm.First_Name.focus();
    return (false);
  }

 if ((theForm.Last_Name.value == "") || (theForm.Last_Name.value.length <2))
  {
    alert("Last Name Entered is invalid.");
    theForm.Last_Name.focus();
    return (false);
  }

  if (theForm.Address1.value.length <5)
  {
    alert("Address(1) Entered is invalid.");
    theForm.Address1.focus();
    return (false);
  }

  if (theForm.City.value.length <3)
  {
    alert("City Entered is invalid.");
    theForm.City.focus();
    return (false);
  }

  if (theForm.stateid.value==0)
  {
    alert("State Selected is invalid.");
    theForm.stateid.focus();
    return (false);
  }
  if (theForm.Zip_Code.value.length<5)
  {
    alert("Zip Code Entered is invalid.");
    theForm.Zip_Code.focus();
    return (false);
  }

if (!isEmail(theForm.Email_Address.value))
  {
    theForm.Email_Address.focus();
    return (false);
  }

  return (true);
}
/*************************************************************************************/
function ApplyOnLineValidateForm(theForm)
{
 
 if ((theForm.First_Name.value == "") || (theForm.First_Name.value.length <2))
  {
    alert("First Name Entered is invalid.");
    theForm.First_Name.focus();
    return (false);
  }

 if ((theForm.Last_Name.value == "") || (theForm.Last_Name.value.length <2))
  {
    alert("Last Name Entered is invalid.");
    theForm.Last_Name.focus();
    return (false);
  }

  if (theForm.Address1.value.length <5)
  {
    alert("Address(1) Entered is invalid.");
    theForm.Address1.focus();
    return (false);
  }

  if (theForm.City.value.length <3)
  {
    alert("City Entered is invalid.");
    theForm.City.focus();
    return (false);
  }

  if (theForm.stateid.value==0)
  {
    alert("State Selected is invalid.");
    theForm.stateid.focus();
    return (false);
  }
  if (theForm.Zip_Code.value.length<5)
  {
    alert("Zip Code Entered is invalid.");
    theForm.Zip_Code.focus();
    return (false);
  }
  
  if (theForm.epositionid.value==0)
  {
    alert("Select a Position Applying for.");
    theForm.epositionid.focus();
    return (false);
  }
  if (theForm.educationid.value==0)
  {
    alert("Select hignest level of education.");
    theForm.educationid.focus();
    return (false);
  }
  if (theForm.Salary.value.length ==0)
  {
    alert("Enter minimum annual salary you are seeking.");
    theForm.Salary.focus();
    return (false);
  }

  return (true);
}
/*************************************************************************************/
function GuestBookValidateForm(theForm)
{

 if ((theForm.First_Name.value == "") || (theForm.First_Name.value.length <2))
  {
    alert("First Name Entered is invalid.");
    theForm.First_Name.focus();
    return (false);
  }

 if ((theForm.Last_Name.value == "") || (theForm.Last_Name.value.length <2))
  {
    alert("Last Name Entered is invalid.");
    theForm.Last_Name.focus();
    return (false);
  }

  if (theForm.Address1.value.length <5)
  {
    alert("Address(1) Entered is invalid.");
    theForm.Address1.focus();
    return (false);
  }

  if (theForm.City.value.length <3)
  {
    alert("City Entered is invalid.");
    theForm.City.focus();
    return (false);
  }

  if (theForm.stateid.value==0)
  {
    alert("State Selected is invalid.");
    theForm.stateid.focus();
    return (false);
  }
  if (theForm.Zip_Code.value.length<5)
  {
    alert("Zip Code Entered is invalid.");
    theForm.Zip_Code.focus();
    return (false);
  }

  return (true);
}

/*************************************************************************************/
function ResponseCardValidateForm(theForm)
{

 if ((theForm.First_Name.value == "") || (theForm.First_Name.value.length <2))
  {
    alert("First Name Entered is invalid.");
    theForm.First_Name.focus();
    return (false);
  }

 if ((theForm.Last_Name.value == "") || (theForm.Last_Name.value.length <2))
  {
    alert("Last Name Entered is invalid.");
    theForm.Last_Name.focus();
    return (false);
  }

  if (theForm.Address1.value.length <5)
  {
    alert("Address(1) Entered is invalid.");
    theForm.Address1.focus();
    return (false);
  }

  if (theForm.City.value.length <3)
  {
    alert("City Entered is invalid.");
    theForm.City.focus();
    return (false);
  }

  if (theForm.stateid.value==0)
  {
    alert("State Selected is invalid.");
    theForm.stateid.focus();
    return (false);
  }
  if (theForm.Zip_Code.value.length<5)
  {
    alert("Zip Code Entered is invalid.");
    theForm.Zip_Code.focus();
    return (false);
  }

  return (true);
}

/*************************************************************************************/
function SendEmailValidateForm(theForm)
{

 if (!isEmail(theForm.SendFrom.value))
  {
//    alert("Enter a Valid From Address.");
    theForm.SendFrom.focus();
    return (false);
  }

 if ((theForm.Subject.value == "") || (theForm.Subject.value.length <2))
  {
    alert("Enter a valid subject line.");
    theForm.Subject.focus();
    return (false);
  }

 if ((theForm.Message.value == "") || (theForm.Message.value.length <2))
  {
    alert("Message is too short.");
    theForm.Message.focus();
    return (false);
  }

  return (true);
}

/**************************************************************************************/
function FindValidateForm(theForm)
{

 if (theForm.SearchString.value == "")
  {
    alert("Enter a valid string to search for.");
    theForm.SearchString.focus();
    return (false);
  }

  return (true);
}