// Contact form validation and checking 30-Aug-2003 MSS
// JavaScript functions put in <head> section.

// ----------------------------------------------------------------------------------------
// checkInformation()
// Reports if all forms have filled out properly.
// ----------------------------------------------------------------------------------------
function checkInformation(form)
{
  // contact method - email
  if (form.contact_method[0].checked) {
     if (isEmail(form) == false) return false;
  }
  // contact method - phone
  else {
     if (isPhone(form) == false) return false;
  }
  
  // validate personal information
  if (isName(form) == false) return false;
  if (isCompany(form) == false) return false;
  if (isCountry(form) == false) return false;

  return true;
}

// ----------------------------------------------------------------------------------------
// checkContact()
// Reports if all forms have filled out properly.
// ----------------------------------------------------------------------------------------
function checkContact(form)
{
  // validate name and email address
  if (isName(form) == false) return false;
  if (isEmail(form) == false) return false;
  if (isSubject(form) == false) return false;
  if (isMessage(form) == false) return false;
  return true;
}


// ----------------------------------------------------------------------------------------
// isName()
// Checks the Name field.
// ----------------------------------------------------------------------------------------
function isName(form)
{
  if (form.name.value == "") {
    alert("\nThe Name field is blank.\n\nPlease enter your name.")
    form.name.focus();
    return false;
  }
}

// ----------------------------------------------------------------------------------------
// isPhone()
// Checks the Phone field.
// ----------------------------------------------------------------------------------------
function isPhone(form)
{
  if (form.phone.value == "") {
    alert("\nThe Phone field is blank.\n\nPlease enter your phone number.")
    form.phone.focus();
    return false;
  }
}

// ----------------------------------------------------------------------------------------
// isEmail()
// Checks the E-MAIL field.
// ----------------------------------------------------------------------------------------
function isEmail(form)
{
  // Return false if e-mail field is blank.
  if (form.email.value == "") {
    alert("\nThe Email field is blank.\n\nPlease enter your email address.")
    form.email.focus();
    return false;
  }

  // Regular expression to validate email address.
  // Example email address:  mike.seifert@test-engrasp.com
  // Left Part -   \w+          One or more alphanumeric characters (including underscores)
  //               [\.-]?\w+    followed by an optional series of alphanumeric strings
  //                            separated by periods or dashes.
  // @ Symbol      @
  //
  // Right Part    \w+          An alphanumeric string
  //               ([\.-]\w+)*  followed by an optional series of strings separated by periods or dashes
  //               ([\.]\w+)    and terminated by a string preceded by a period.  (for example, .com)
  re = /^\w+([\.-]\w+)*@\w+([\.-]\w+)*([\.]\w+)$/
  if (!re.test(form.email.value)) {
    alert("\nThe Email field contains an invalid email address.\n\nPlease re-enter your email address.");
    form.email.focus();
    return false;
  }
}

// ----------------------------------------------------------------------------------------
// isSubject()
// ----------------------------------------------------------------------------------------
function isSubject(form)
{
  if (form.subject.value == "") {
    alert("\nThe Subject field is blank.\n\nPlease enter a subject for your message.")
    form.subject.focus();
    return false;
  }
}

// ----------------------------------------------------------------------------------------
// isCompany()
// Checks the Company field.
// ----------------------------------------------------------------------------------------
function isCompany(form)
{
  if (form.company.value == "") {
    alert("\nThe Company field is blank.\n\nPlease enter your company name.")
    form.company.focus();
    return false;
  }
}

// ----------------------------------------------------------------------------------------
// isCountry()
// Checks the Country field.
// ----------------------------------------------------------------------------------------
function isCountry(form)
{
  if (form.country.value == "") {
    alert("\nThe Country field is blank.\n\nPlease enter your country.")
    form.country.focus();
    return false;
  }
}

// ----------------------------------------------------------------------------------------
// isMessage()
// ----------------------------------------------------------------------------------------
function isMessage(form)
{
//  Allow for blank messages in this form.
//  if (form.message.value == "") {
//    alert("\nThe Message field is blank.\n\nPlease enter a short description of your feedback in the Message field.")
//    form.message.focus();
//    return false;
//  }
}




