function isValid(parm,val) {
  if (parm == "") return true;
  for (i=0; i<parm.length; i++) {
    if (val.indexOf(parm.charAt(i),0) == -1) return false;
  }
  return true;
}

var numb = '0123456789';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function isAlpha(parm) {return isValid(parm,lwr+upr);}
function isNum(parm) {return isValid(parm,numb);}
function isName(parm) {return isValid(parm, lwr + upr + '\'\. ');}
function isAlphaNum(parm) { return isValid(parm, numb + lwr + upr);}

function validateClientForm() {

  var fName = document.myForm.fName;
  var mi = document.myForm.mInitial;
  var lName = document.myForm.lName;
  var i = 0;
  if (fName.value.length == 0) {
    alert("First name is a required field.");
    fName.focus();
    return false;
  }
  if (!isName(fName.value)) {
    alert("First name can only contain characters");
    fName.focus();
    return false;
  }

  if (!isAlpha(mi.value) && mi.value.length > 0) {
    alert("Middle Initial must be a character.");
    mi.focus();
    return false;
  }
  if (lName.value.length == 0) {
    alert("Last name is a required field.");
    lName.focus();
    return false;
  }
  if (!isName(lName.value)) {
    alert("Last name can only contain characters");
    lName.focus();
    return false;
  }

  var keycode = document.myForm.keycode;
  if (keycode.value.length != 0 && (keycode.value.length < 3 || !isAlphaNum(keycode.value))) {
    alert("Key Code is invalid.");
    keycode.focus();
    return false;
  }

  var zip = document.myForm.zip;
  var zip2 = document.myForm.zip2;
  if (zip.value.length == 0) {
    alert("First five digits of zip code are required.");
    zip.focus();
    return false;
  }
  if (zip.value.length != 5) {
    alert("First 5 digits of zip code not formed properly.");
    zip.focus();
    return false;
  }
  if (zip2.value.length != 0 && zip2.value.length != 4) {
    alert("Last 4 digits of zip code not properly formed.");
    zip2.focus();
    return false;
  }
  if (!isNum(zip.value)) {
    alert("First part of zip code cannot contain non-digits");
    zip.focus();
    return false;
  }
  if (!isNum(zip2.value)) {
    alert("Last part of zip code cannot contain non-digits");
    zip2.focus();
    return false;
  }

  var phone1 = document.myForm.primaryPhone1;
  var phone2 = document.myForm.primaryPhone2;
  var phone3 = document.myForm.primaryPhone3;

  if (!isNum(phone1.value) || (phone1.value.length < 3)) {
    alert("Area Code of Phone Number must be 3 digits.");
    phone1.focus();
    return false;
  }
  if (!isNum(phone2.value) || (phone2.value.length < 3)) {
    alert("Second three numbers of phone number must be 3 digits.");
    phone2.focus();
    return false;
  }
  if (!isNum(phone3.value) || (phone3.value.length < 4)) {
    alert("Last four numbers of phone number must be 4 digits.");
    phone3.focus();
    return false;
  }

  var fax1 = document.myForm.fax1;
  var fax2 = document.myForm.fax2;
  var fax3 = document.myForm.fax3;
  if (fax1.value.length > 0 || fax2.value.length > 0 || fax3.value.length > 0) {
    if (!isNum(fax1) || fax1.value.length < 3) {
      alert("Fax number is invalid.\nNote: This field is not required.");
      fax1.focus();
      return false;
    }
    if (!isNum(fax2) || fax2.value.length < 3) {
      alert("Fax number is invalid.\nNote: This field is not required.");
      fax2.focus();
      return false;
    }
    if (!isNum(fax3) || fax3.value.length < 4) {
      alert("Fax number is invalid.\nNote: This field is not required.");
      fax3.focus();
      return false;
    }
  }

  var cell1 = document.myForm.cell1;
  var cell2 = document.myForm.cell2;
  var cell3 = document.myForm.cell3;
  if (cell1.value.length > 0 || cell2.value.length > 0 || cell3.value.length > 0) {
    if (!isNum(cell1) || cell1.value.length < 3) {
      alert("Cell number is invalid.\nNote: This field is not required.");
      cell1.focus();
      return false;
    }
    if (!isNum(cell2) || cell2.value.length < 3) {
      alert("Cell number is invalid.\nNote: This field is not required.");
      cell2.focus();
      return false;
    }
    if (!isNum(cell3) || cell3.value.length < 4) {
      alert("Cell number is invalid.\nNote: This field is not required.");
      cell3.focus();
      return false;
    }
  }

  var emailAdd = document.myForm.email;

  if (emailAdd.value.length == 0) {
    alert("E-mail field is required.");
    emailAdd.focus();
    return false;
  }
  var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/
  if (!email.test(emailAdd.value)) {
    emailAdd.focus();
    alert("E-mail address is invalid.");
    return false;
  }

  return true;
}
