<!--
function Form_Validator(theForm)
{

  if (theForm.Name.value == "")
  {
    alert("Please enter a name in the \"Name\" field.");
    theForm.Name.focus();
    return (false);
  }

  if (checkNumeric(theForm.Name.value,""))
  {
    alert("Please enter only characters in the \"Name\" field.");
    theForm.Name.focus();
    return (false);
  }

  if (theForm.Phone1.value == "")
  {
    alert("Please enter a value for \"Phone Area Code\" field.");
    theForm.Phone1.focus();
    return (false);
  }

  if (!checkNumeric(theForm.Phone1.value,""))
  {
    alert("Please enter only digits in the \"Phone Area Code\" field.");
    theForm.Phone1.focus();
    return (false);
  }

  if (theForm.Phone2.value == "")
  {
    alert("Please enter a value for \"Phone\" field.");
    theForm.Phone2.focus();
    return (false);
  }

  if (!checkNumeric(theForm.Phone2.value,"-"))
  {
    alert("Please enter only digits or dash (-) in the \"Phone\" field.");
    theForm.Phone2.focus();
    return (false);
  }

  if(!validPhone(theForm.Phone2.value))
  {
    alert("You have entered an invalid Phone number. Please re-enter it.");
    theForm.Phone2.focus();
    return (false);
  }

  if(!validEmail(theForm.EmailAddress.value))
  {
    alert("You have entered an invalid Email address. Please re-enter it.");
    theForm.EmailAddress.focus();
    return (false);
  }

  if (theForm.Subject.value == "")
  {
    alert("Please enter a subject in the \"Subject\" field.");
    theForm.Subject.focus();
    return (false);
  }

  if (theForm.Message.value == "")
  {
    alert("Please enter a message in the \"Message\" field.");
    theForm.Message.focus();
    return (false);
  }

  return (true);
}

function checkNumeric(checkStr, more)
{
  var checkOK = "0123456789" + more;

  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
      return(false);
  }

  return(true);

}

function validEmail(email)
{
  var invalidchars = " ~`!#$%^&*()+={}[]|\"<>,?'/:;" //@ and . ok

// remove leading spaces
	while(email.substring(0,1)==" ")
	{
		email = email.substring(1,email.length);
	}

// remove trailing spaces
	while(email.substring(email.length-1,email.length)==" ")
	{
		email = email.substring(0,email.length-1);
	}

	if(email == "")
	{			//checks to see if blank field
		return (false);
	}

	for(i=0;i<invalidchars.length;i++) //checks for invalid chars
	{
		badchars = invalidchars.charAt(i)

		if(email.indexOf(badchars,0)!= -1)
		{
			return (false);
		}
	}
	atPos = email.indexOf("@",1)  //holds position of "@"

	if(atPos == -1)
	{	//checks to see if "@" present
		return (false);
	}

	if(email.indexOf("@",atPos+1) != -1)
	{ //checks for second "@"
		return (false);
	}

	periodPos = email.indexOf(".",atPos) //holds position of "." after "@"

	if(periodPos == -1)
	{ //checks for presence of "."
		return (false);
	}

	if (periodPos == (atPos + 1))
	{ //checks for "@."
		return (false);
	}

	if(periodPos+3 > email.length)
	{//makes sure at least two chars after the period
		return (false);
	}

	return (true);
}

function validPhone(phone)
{
// remove leading spaces
	while(phone.substring(0,1)==" ")
	{
		phone = phone.substring(1,phone.length);
	}

// remove trailing spaces
	while(phone.substring(phone.length-1,phone.length)==" ")
	{

		phone = phone.substring(0,phone.length-1);
	}

	if(phone == "")
	{			//checks to see if blank field
		return (false);
	}

	if(phone.length < 7)
	{			//checks to see if not enough or too many numbers
		return (false);
	}

	if(phone.length == 7)
    {
		dashPos = phone.indexOf("-",1)  //holds position of first "-"

		if(dashPos != -1)
			return (false);

	}

	if(phone.length == 8)
    {
		dashPos = phone.indexOf("-",1)  //holds position of first "-"

		if(dashPos != 3)
			return (false);

		if(phone.indexOf("-",dashPos+1) != -1)
			return (false);
	}

	return (true);
}

//-->
