// This code is used to validate information submited via the contact information form.

function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}

function validate_email(field,alerttxt)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
  else {return true;}
  }
}

function validate_form(thisform)
{
with (thisform)
  {
// This code is used to validate that the name field is populated.
  if (validate_required(name,"Name is a required field!")==false)
  {name.focus();return false;} else
// This code is used to validate that the email field is populated.
  if (validate_required(email,"Email is a required field!")==false)
  {email.focus();return false;} else
// This code is used to validate that the phone field is populated.
  if (validate_required(phone,"Phone number is a required field!")==false)
  {phone.focus();return false;} else
// This code is used to validate that the email field is the correct format.
  if (validate_email(email,"Not a valid e-mail address!")==false)
  {email.focus();return false;}
  }
  
// This code is used to validate that the phone field is the correct format.
  if(document.contact.phone.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1)
   {
      alert("The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.");
      return false;
   }
}
