
function validEmail(email) {
   invalidChars = " /:,;";
   for (i=0; i<invalidChars.length; i++) {
      badChar = invalidChars.charAt(i);
      if (email.indexOf(badChar,0) > -1) {
         return false;
      }
   }
   atPos = email.indexOf("@",1);
   if (atPos == -1) {
      return false;
   }
   if (email.indexOf("@",atPos+1) != -1) {
      return false;
   }
   periodPos = email.indexOf(".",atPos);
   if (periodPos == -1) {
      return false;
   }
   if (periodPos+3 > email.length)  {
      return false;
   }
   return true;
}

function validate(theForm) {
   theForm.contact_name.className         = "bold_text_field";
   theForm.contact_company_name.className = "bold_text_field";
   theForm.contact_email.className        = "bold_text_field";

   if (theForm.contact_name.value == "")
   {
   theForm.contact_name.className = "bold_text_field_bad";
   alert("Please enter your name.");
   theForm.contact_name.focus();
   return (false);
   }

   if (theForm.contact_company_name.value == "")
   {
   theForm.contact_company_name.className = "bold_text_field_bad";
   alert("Please enter your company name.");
   theForm.contact_company_name.focus();
   return (false);
   }

   if (theForm.contact_email.value == "")
   {
   theForm.contact_email.className = "bold_text_field_bad";
   alert("Please enter a valid email address.");
   theForm.contact_email.focus();
   return (false);
   }
   var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@._ ";
   var checkStr = theForm.contact_email.value;
   var allValid = true;
   for (i = 0;  i < checkStr.length;  i++)
   {
   ch = checkStr.charAt(i);
   for (j = 0;  j < checkOK.length;  j++)
   if (ch == checkOK.charAt(j))
   break;
   if (j == checkOK.length)
   {
   allValid = false;
   break;
   }
   }
   if (!allValid)
   {
   theForm.contact_email.className = "bold_text_field_bad";
   alert("You can only use normal characters and numbers in your email address.");
   theForm.contact_email.focus();
   return (false);
   }
   
   if (!validEmail(theForm.contact_email.value))
   if ((theForm.contact_email.value != "") && (!validEmail(theForm.contact_email.value)))
   {
   theForm.contact_email.className = "bold_text_field_bad";
   alert("You have entered an invalid email address.");
   theForm.contact_email.focus();
   return (false);
   }
   
   return (true);
}


