function validate(theForm) {
   var msg;
   var errors = "";
   var firsterror = 0;
   var firstname_pattern = /[^a-zA-Z\- ]+/;
   var lastname_pattern = /[^a-zA-Z\-\.,' ]+/;
   var phone_pattern = /[^0-9]+/;
   var card_pattern = /[^0-9\-]+/;
   var email_pattern = /.+@.+/;
   var work_warned = 0;

   if ((theForm.firstname.value == null) || (theForm.firstname.value == "") || isblank(theForm.firstname.value)) {
      errors += "- The First Name field is required.\n";

      if (firsterror == 0) {
         theForm.firstname.focus();
         firsterror = 1;
      }

   }

   if (firstname_pattern.test(theForm.firstname.value)) {
      errors += "- The First Name field contains invalid characters.\n";

      if (firsterror == 0) {
         theForm.firstname.focus();
         firsterror = 1;
      }

   }

   if ((theForm.lastname.value == null) || (theForm.lastname.value == "") || isblank(theForm.lastname.value)) {
      errors += "- The Last Name field is required.\n";

      if (firsterror == 0) {
         theForm.lastname.focus();
         firsterror = 1;
      }

   }

   if (lastname_pattern.test(theForm.lastname.value)) {
      errors += "- The Last Name field contains invalid characters.\n";

      if (firsterror == 0) {
         theForm.lastname.focus();
         firsterror = 1;
      }

   }

   if ((theForm.emailaddress.value == null) || (theForm.emailaddress.value == "") || isblank(theForm.emailaddress.value)) {
      errors += "- The Email Address field is required.\n";

      if (firsterror == 0) {
         theForm.emailaddress.focus();
         firsterror = 1;
      }

   }

   if (!(email_pattern.test(theForm.emailaddress.value))) {
      errors += "- Please enter a valid email address.\n";

      if (firsterror == 0) {
         theForm.emailaddress.focus();
         firsterror = 1;
      }

   }

   if ((theForm.address1.value == null) || (theForm.address1.value == "") || isblank(theForm.address1.value)) {
      errors += "- The Address 1 field is required.\n";

      if (firsterror == 0) {
         theForm.address1.focus();
         firsterror = 1;
      }

   }

   if ((theForm.city.value == null) || (theForm.city.value == "") || isblank(theForm.city.value)) {
      errors += "- The City field is required.\n";

      if (firsterror == 0) {
         theForm.city.focus();
         firsterror = 1;
      }

   }

   if ((theForm.state.options[theForm.state.selectedIndex].value == "00") || (theForm.state.options[theForm.state.selectedIndex].value == "01")) {
      errors += "- You must select a US State.\n";

      if (firsterror == 0) {
         theForm.state.focus();
         firsterror = 1;
      }

   }

   if ((theForm.zip.value == null) || (theForm.zip.value == "") || isblank(theForm.zip.value)) {
      errors += "- The Zip/Postal Code field is required.\n";

      if (firsterror == 0) {
         theForm.zip.focus();
         firsterror = 1;
      }

   }

   if ((theForm.home_area.value == null) || (theForm.home_area.value == "") || isblank(theForm.home_area.value) || (theForm.home_area.value.length != 3)) {
      errors += "- The Home Phone Area Code field is required.\n";

      if (firsterror == 0) {
         theForm.home_area.focus();
         firsterror = 1;
      }

   }

   if (phone_pattern.test(theForm.home_area.value)) {
      errors += "- Please enter a valid Home Phone Area Code.\n";

      if (firsterror == 0) {
         theForm.home_area.focus();
         firsterror = 1;
      }

   }

   if ((theForm.home_prefix.value == null) || (theForm.home_prefix.value == "") || isblank(theForm.home_prefix.value) || (theForm.home_prefix.value.length != 3)) {
      errors += "- The Home Phone Prefix field is required.\n";

      if (firsterror == 0) {
         theForm.home_prefix.focus();
         firsterror = 1;
      }

   }

   if (phone_pattern.test(theForm.home_prefix.value)) {
      errors += "- Please enter a valid Home Phone Prefix.\n";

      if (firsterror == 0) {
         theForm.home_prefix.focus();
         firsterror = 1;
      }

   }

   if ((theForm.home_number.value == null) || (theForm.home_number.value == "") || isblank(theForm.home_number.value) || (theForm.home_number.value.length != 4)) {
      errors += "- The Home Phone Number field is required.\n";

      if (firsterror == 0) {
         theForm.home_number.focus();
         firsterror = 1;
      }

   }

   if (phone_pattern.test(theForm.home_number.value)) {
      errors += "- Please enter a valid Home Phone Number.\n";

      if (firsterror == 0) {
         theForm.home_number.focus();
         firsterror = 1;
      }

   }

   if ((theForm.work_area.value == null) || (theForm.work_area.value == "") || isblank(theForm.work_area.value)) {

   }
   else {
      work_warned = 1;

      if ( (phone_pattern.test(theForm.work_area.value)) || ( theForm.work_area.value.length != 3 ) ) {
         errors += "- Please enter a valid Work Phone Area Code.\n";

         if (firsterror == 0) {
            theForm.work_area.focus();
            firsterror = 1;
         }

      }

      if ( (phone_pattern.test(theForm.work_prefix.value)) || ( theForm.work_prefix.value.length != 3 ) ) {
         errors += "- Please enter a valid Work Phone Prefix.\n";

         if (firsterror == 0) {
            theForm.work_prefix.focus();
            firsterror = 1;
         }

      }

      if ( (phone_pattern.test(theForm.work_number.value)) || ( theForm.work_number.value.length != 4 ) ) {
         errors += "- Please enter a valid Work Phone Number.\n";

         if (firsterror == 0) {
            theForm.work_number.focus();
            firsterror = 1;
         }

      }

   }

   if ((theForm.work_prefix.value == null) || (theForm.work_prefix.value == "") || isblank(theForm.work_prefix.value)) {

   }
   else if ( work_warned == 0 ) {
      work_warned = 1;

      if ( (phone_pattern.test(theForm.work_area.value)) || ( theForm.work_area.value.length != 3 ) ) {
         errors += "- Please enter a valid Work Phone Area Code.\n";

         if (firsterror == 0) {
            theForm.work_area.focus();
            firsterror = 1;
         }

      }

      if ( (phone_pattern.test(theForm.work_prefix.value)) || ( theForm.work_prefix.value.length != 3 ) ) {
         errors += "- Please enter a valid Work Phone Prefix.\n";

         if (firsterror == 0) {
            theForm.work_prefix.focus();
            firsterror = 1;
         }

      }

      if ( (phone_pattern.test(theForm.work_number.value)) || ( theForm.work_number.value.length != 4 ) ) {
         errors += "- Please enter a valid Work Phone Number.\n";

         if (firsterror == 0) {
            theForm.work_number.focus();
            firsterror = 1;
         }

      }

   }

   if ((theForm.work_number.value == null) || (theForm.work_number.value == "") || isblank(theForm.work_number.value)) {

   }
   else if ( work_warned == 0 ) {
      work_warned = 1;

      if ( (phone_pattern.test(theForm.work_area.value)) || ( theForm.work_area.value.length != 3 ) ) {
         errors += "- Please enter a valid Work Phone Area Code.\n";

         if (firsterror == 0) {
            theForm.work_area.focus();
            firsterror = 1;
         }

      }

      if ( (phone_pattern.test(theForm.work_prefix.value)) || ( theForm.work_prefix.value.length != 3 ) ) {
         errors += "- Please enter a valid Work Phone Prefix.\n";

         if (firsterror == 0) {
            theForm.work_prefix.focus();
            firsterror = 1;
         }

      }

      if ( (phone_pattern.test(theForm.work_number.value)) || ( theForm.work_number.value.length != 4 ) ) {
         errors += "- Please enter a valid Work Phone Number.\n";

         if (firsterror == 0) {
            theForm.work_number.focus();
            firsterror = 1;
         }

      }

   }

   if ((theForm.contacttime.value == null) || (theForm.contacttime.value == "") || isblank(theForm.contacttime.value)) {
      errors += "- The Best Time to Contact You field must be filled in.\n";

      if (firsterror == 0) {
         theForm.contacttime.focus();
         firsterror = 1;
      }

   }

   if (!errors) return true;

   msg = "________________________________________________________________\n\n";
   msg += "The form was not submitted because of the following error(s).\n";
   msg += "Please correct these error(s) and resubmit.\n";
   msg += "________________________________________________________________\n\n"
;
   msg += errors;

   alert(msg);

   return false;

}

function isblank(s) {

   for(var i = 0; i < s.length; i++) {
      var c = s.charAt(i);

      if ((c != " ") && (c != "\n") && (c != "\t")) return false;

   }

   return true;
}

