function CheckFields()
{
  //This function checks all fields to make sure they are filled in before the user submits the form.

  var isValid;
  var errorMessage;

  //Initialize variables.
  isValid = true;
  errorMessage = "";

  //Name, Phone number, and E-mail address are required fields.
  if (document.forms["emailform"].txtName.value == "")
  {
    isValid = isValid && false;
    errorMessage = errorMessage += "Please enter your name.\n";
  }

  if(document.forms["emailform"].txtPhone.value == "")
  {
    isValid = isValid && false;
    errorMessage = errorMessage += "Please enter your phone number.\n";
  }

  if(document.forms["emailform"].txtEmail.value == "")
  {
    isValid = isValid && false;
    errorMessage = errorMessage += "Please enter your e-mail address.\n";
  }
  else
  {
    //They enterred an e-mail address.  Make sure it's valid.
    if (ValidEmail(document.forms["emailform"].txtEmail) == false)
    {
      isValid = isValid && false;
      errorMessage += "Please enter a valid e-mail address of the form johndoe@website.com\n";
    }
  }

  if (isValid == true)
  {
    document.forms[0].action = "mailer.asp";
    document.forms[0].submit();
  }
  else
  {
    window.alert(errorMessage);
    return false;
  }
} //end function CheckFields

function ValidEmail(field)
{
  var sValue;
  var bReturn;
  var iAtIndex;
  var iPeriodIndex;

  //Initialize values.
  sValue = field.value;
  bReturn = true;
  iAtIndex = sValue.indexOf("@");
  iPeriodIndex = sValue.indexOf(".");

  if (iAtIndex < 0 || iPeriodIndex < 0)
  {
    //There is no @ sign or period in the e-mail address, hence it is invalid.
    bReturn = false;
  }
  //There is an @ sign in the e-mail address.
  //Make sure it's not the first char.
  else if (iAtIndex == 0)
  {
    //The @ sign is the first char.
    //Invalid e-mail address.
    bReturn = false;
  }
  //The @sign isn't the first char in the e-mail address.
  //Make sure that the period isn't the last char in the e-mail address.
  else if (iPeriodIndex == sValue.length - 1)
  {
    //The period is at the last position in the string.
    bReturn = false;
  }
  //The period isn't the last char in the string.
  //Make sure the @ sign is before the period.
  else if (iPeriodIndex < iAtIndex)
  {
    //The Period is before the @ sign.
    bReturn = false;
  }
  //The period isn't before the @ sign.
  //Make sure that they aren't right next to each other.
  else if (iAtIndex + 1 == iPeriodIndex)
  {
    //The @ sign is right next to the period.
    bReturn = false;
  }
  //If we've successfully passed all these tests, then we've
  //got a valid e-mail address.
  //I defaulted bReturn to true, so I don't need to set it here.

  return bReturn;
}
