function validateForm(theForm) {
   var why = "";
   why += isEmpty(theForm.name.value, theForm.name, "name");
   why += checkPhone(theForm.phone.value, theForm.phone);
   why += checkEmail(theForm.email.value, theForm.email);
   why += checkDropdown(theForm.inquiry.selectedIndex, theForm.inquiry, "How can we help?");
   why += isEmpty(theForm.comments.value, theForm.comments);
   if (why != "") {
      alert(why);
      return false;
   }
return true;
}

function checkEmail (strng, frmName) {
   var error="";
   if (strng == "") {
      error = "You didn't enter an email address.\n";
      frmName.className = "text_err";
   }

   var emailFilter=/^.+@.+\..{2,3}$/;
   if (!(emailFilter.test(strng))) { 
      error = "Please enter a valid email address.\n";
      frmName.className = "text_err";
   }
   else {
      //test email for illegal characters
      var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
      if (strng.match(illegalChars)) {
         error = "The email address contains illegal characters.\n";
         frmName.className = "text_err";
      }
   }
   if (error == "") {
      frmName.className = "text";
   }
return error;    
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng, frmName) {
   var error = "";
   if (strng == "") {
      error = "You didn't enter a phone number.\n";
      frmName.className = "text_err";
   }

   var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
   if (isNaN(parseInt(stripped))) {
      error = "The phone number contains illegal characters.";
      frmName.className = "text_err";
   }
   if (!(stripped.length == 10)) {
      error = "The phone number is the wrong length. Make sure you included an area code.\n";
      frmName.className = "text_err";
   }
   else {
      frmName.className = "text";
   }
return error;
}


// non-empty textbox

function isEmpty(strng, frmName, field) {
   var error = "";
   if (strng.length == 0) {
      error = "The " + field + " area has not been filled in.\n"
      frmName.className = "text_err";
   }
   else {
      frmName.className = "text";
   }
return error;	  
}

function verifyEmail (email, vemail, frmName) {
   var error = "";
   if (vemail != email || email == "") {
      error = "You need to verify your email address.\n"
      frmName.className = "text_err";
   }
   else {
      frmName.className = "text";
   }
return error;	  
}

// exactly one radio button is chosen

function checkRadio(frmName, field) {
   var error = "";
   var found_it;
   for (var i=0; i<frmName.length; i++)  {
      if (frmName[i].checked)  {
         found_it = true;
      }
   }
   if (!found_it) {
      error = "Please check a radio button for '" + field + "'\n"
   }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice, frmName, field) {
   var error = "";
   if (choice == 0) {
      error = "You didn't choose an option from the '" + field + "' drop-down list.\n";
      frmName.className = "select_err";
   }    
   else {
      frmName.className = "select";
   }
return error;
}