﻿function Validator(theForm)
{

  if (theForm.FIRSTLETTER.value == "")
  {
    alert("Please enter a value for the \"First Name\" field.");
    theForm.FIRSTLETTER.focus();
    return (false);
  }

  if (theForm.FIRSTLETTER.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"First Name\" field.");
    theForm.FIRSTLETTER.focus();
    return (false);
  }

  if (theForm.FIRSTLETTER.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"First Name\" field.");
    theForm.FIRSTLETTER.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz- '\t\r\n\f";
  var checkStr = theForm.FIRSTLETTER.value;
  var allValid = true;
  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)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter and whitespace characters in the \"First Name\" field.");
    theForm.FIRSTLETTER.focus();
    return (false);
  }

  if (theForm.LASTNAME.value == "")
  {
    alert("Please enter a value for the \"Last name\" field.");
    theForm.LASTNAME.focus();
    return (false);
  }

  if (theForm.LASTNAME.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"Last name\" field.");
    theForm.LASTNAME.focus();
    return (false);
  }

  if (theForm.LASTNAME.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"Last name\" field.");
    theForm.LASTNAME.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz- '\t\r\n\f";
  var checkStr = theForm.LASTNAME.value;
  var allValid = true;
  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)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter and whitespace characters in the \"Last name\" field.");
    theForm.LASTNAME.focus();
    return (false);
  }
  return (true);
}

