var errfound = false;
//function to validate by length
function ValidLength(item, len) {
   return (item.length >= len);
}
//function to validate an email address
function ValidEmail(item) {
   if (!ValidLength(item, 5)) return false;
   ss=item.indexOf ('@', 1);
   if (ss == -1) return false;
   ss=item.indexOf ('.', ss);
   if (ss == -1) return false;
   return true;
}
// display an error alert
function error(elem, text) {
// abort if we already found an error
   if (errfound) return;
   window.alert(text);
   elem.select();
   elem.focus();
   errfound = true;
}
// main validation function
function Validate() {
   errfound = false;
   if (!ValidLength(document.psurvey.fname.value,3))
      error(document.psurvey.fname,"Enter First name");
	  if (!ValidLength(document.psurvey.lname.value,3))
      error(document.psurvey.lname,"Enter Last name");
   if (!ValidLength(document.psurvey.address.value,10))
      error(document.psurvey.address, "Invalid Mailing Address");
   if (!ValidLength(document.psurvey.city.value,4))
      error(document.psurvey.city, "Invalid City");
   if (!ValidLength(document.psurvey.state.value,2))
      error(document.psurvey.state, "Invalid State");
   if (!ValidLength(document.psurvey.zip.value,5))
      error(document.psurvey.zip, "Invalid Postal/Zip Code");
   if (!ValidLength(document.psurvey.phone.value,7))
      error(document.psurvey.phone,"Invalid phone number");
   if (!ValidEmail(document.psurvey.email.value))
      error(document.psurvey.email, "Invalid Email Address");
   if (!ValidLength(document.psurvey.speciality.value,2))
      error(document.psurvey.speciality,"Enter Speciality");
    
   return !errfound; /* true if there are no errors */
}