﻿function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}
 
function FormValidator(theForm)
{
  if (theForm.name.value == "")
  {
    alert("Please enter your name.");
    theForm.name.focus();
    return (false);
  }
  if (theForm.contact.value == "Please Select")
  {
    alert("Please select how you whish to be contacted.");
    theForm.contact.focus();
    return (false);
  }
  if (theForm.contact.value == "Telephone")
  {
    if (theForm.phone.value == "")
    {
      alert("Please enter your telephone number.");
      theForm.phone.focus();
      return (false);
    }
  }
  if (theForm.contact.value == "Email")
  {
    if (theForm.email.value == "")
    {
      alert("Please enter a value for the \"email\" field.");
      theForm.email.focus();
      return (false);
    }
    if (!isEmailAddr(theForm.email.value))
    {
      alert("Please enter a valid email address in the form: yourname@yourdomain.ext");
      theForm.email.focus();
      return (false);
    }
    if (theForm.email.value.length < 3)
    {
      alert("Please enter at least 3 characters in the \"email\" field.");
      theForm.email.focus();
      return (false);
    }
  }
  return jcap();
}