function validateForm() {
   theform = document.getElementById("theform");
   if(trim(theform.name.value)==""){
      alert("Please enter your name.");
      theform.name.focus();
      return false;
   }
   if(trim(theform.phone.value)==""){
      alert("Please enter your phone.");
      theform.phone.focus();
      return false;
   }
   if(trim(theform.email.value)==""){
      alert("Please enter your email address.");
      theform.email.focus();
      return false;
   }
   if(! CheckEmail (theform.email.value) ) {
      alert("Invalid email address.");
      theform.email.focus();
      return false;
   }
   return true;
}
function CheckEmail(field) {
   var i = 1;
   var sLength = field.length;

   while (( i < sLength) && (field.charAt(i) != "@")) {
      i++;
   }
   if ((i >= sLength) || field.charAt(i) != "@"){
      return false;
   } else {
      i += 2;
   }
   while ((i < sLength) && (field.charAt(i) != ".")) {
      i++;
   }
   if ((i >= sLength - 1) || (field.charAt(i) != ".")) {
      return false;
   } else {
      return true;
   }
}
function trim(stringToTrim) {
   return stringToTrim.replace(/^\s+|\s+$/g,"");
}
