/* ************************************ */
/*           SAMPLE ROUTINES            */
/* ************************************ */
//dummy shell to keep examples organized, like all functions here, theForm is the form object
// on your page which you wish to validate.
function NeverCallThis(theForm)
{
// Text Boxes
  if (theForm.NameOfTextBox.value == "")
  {
    alert("Insert Error Message Here");
    theForm.NameOfTextBox.focus();
    return (false);
  }
  // in the next expression, 5 represents the required length of the field.
  // depending on your textbox parameters, this may also become a less than
  // statement, a greater than statement, or a combination of the above.
  if (theForm.NameOfTextBox.value.length != 5)
  {
    alert("Insert Error Message Here");
    theForm.NameOfTextBox.focus();
    return (false);
  }
  // this string represents the array of valid characters--in this example alphabetic
  // you may also restrict to numeric, or a combination of the two.  You may also include
  // symbols such as hyphens or apostrophes.  Don't forget the trouble SQL has with apostrophes,
  // however.  Remember, JavaScript is case-sensitive.
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  var checkStr = theForm.NameOfTextBox.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("Insert Error Message Here");
    theForm.NameOfTextBox.focus();
    return (false);
  }
// Radio Buttons
  aBoolean = false;
  aNumber = 9; //placeholder--represents the number of radio buttons in your array
  for (aCounter = 0; aCounter <= aNumber; aCounter++)
  {
    if (theForm.NameOfRadioArray(aCounter).checked)
    {
      aBoolean = true;
      break;
    }
  }
  if (!aBoolean)
  {
    alert ("Insert Error Message Here");
    theForm.NameOfRadioArray(0).focus();
    return (false);
  }
}

/* ************************************ */
/*    VALIDATOR FOR LOGIN PAGE          */
/* ************************************ */
function LoginValidator(theForm)
{
  if (theForm.Pin.value == "")
  {
    alert("Please enter a value for the \"Pin Number\" field.");
    theForm.Pin.focus();
    return (false);
  }
  if (theForm.Pin.value.length != 5)
  {
    alert("Please a 5-digit number in the \"Pin Number\" field.");
    theForm.Pin.focus();
    return (false);
  }
  var checkOK = "0123456789";
  var checkStr = theForm.Pin.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 digit characters in the \"Pin Number\" field.");
    theForm.Pin.focus();
    return (false);
  }
  if (theForm.InsuredSSN.value == "")
  {
    alert("Please enter a value for the \"Social Security Number\" field.");
    theForm.InsuredSSN.focus();
    return (false);
  }
  if (theForm.InsuredSSN.value.length != 9)
  {
    alert("Please enter 9 digits in the \"Social Security Number\" field.  Do not use dashes.");
    theForm.InsuredSSN.focus();
    return (false);
  }
  var checkOK = "0123456789";
  var checkStr = theForm.InsuredSSN.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 digit characters in the \"Social Security Number\" field.");
    theForm.InsuredSSN.focus();
    return (false);
  }
  return (true);
}


/* ************************************ */
/*    VALIDATOR FOR BENEFITS PAGE       */
/* ************************************ */
function BenefitsValidator(theForm)
{
  if (!(theForm.tobacco[0].checked) && !(theForm.tobacco[1].checked))
  {
    alert("Please tell us whether you use tobacco products.");
    theForm.tobacco[0].focus();
    return (false);
  }

  medChecked = false;
  for (mCi = 0; mCi < 9; mCi++)
  {
    if (theForm.MedLevel[mCi].checked)
    {
      medChecked = true;
      break;
    }
  }
  if (!medChecked)
  {
    alert ("You have not selected a Medical Coverage Plan.  Please choose one of the 8 options, or select 'No Coverage'.");
    theForm.MedLevel(0).focus();
    return (false);
  }
    
  if (theForm.MedLevel.value = "")
    theForm.DentalCoverage.value = "";
    
  visChecked = false;
  for (vCi = 0; vCi <= 4; vCi++)
  {
    if (theForm.VisionCov[vCi].checked)
    {
      visChecked = true;
      break;
    }
  }
  if (!visChecked)
  {
    alert ("You have not selected a Vision Coverage Plan.  Please choose one of the 4 options, or select 'NONE'.");
    theForm.VisionCov(0).focus();
    return (false);
  }
  
  if (theForm.MedLevel[8].checked)  //no medical coverage; dental coverage optional
  {
    denChecked = false;
    for (dCi = 0; dCi <= 4; dCi++)
    {
      if (theForm.DentalCov[dCi].checked)
      {
        denChecked = true;
        break;
      }
    }
    if (!denChecked)
    {
      alert ("You have not selected a Dental Coverage Plan.  Please choose one of the 4 options, or select 'NONE'.");
      theForm.DentalCov(0).focus();
      return (false);
    }
  }
  
  canChecked = false;
  for (cCi = 0; cCi <= 10; cCi++)
  {
    if (theForm.Cancer[cCi].checked)
    {
      canChecked = true;
      break;
    }
  }
  if (!canChecked)
  {
    alert ("You have not selected a Cancer Coverage Plan.  Please choose one of the 4 options, or select 'No Coverage'.");
    theForm.Cancer(0).focus();
    return (false);
  }
  
  if (theForm.MedExAcct.checked)
  {
    DDChecked = false;
    for (DDi = 0; DDi < 2; DDi++)
    {
      if (theForm.FlexAcctDD[DDi].checked)
      {
        DDChecked = true;
        break;
      }
    }
    if (!DDChecked)
    {
      alert ("Please choose whether or not you would like to have your reimbursement checks placed into your bank account via Direct Deposit.");
      theForm.FlexAcctDD(0).focus();
      return (false);
    }
  }
  
  if (theForm.DepCareAcct.checked)
  {
    DDCheckeda = false;
    for (DDj = 0; DDj < 2; DDj++)
    {
      if (theForm.FlexAcctDD[DDj].checked)
      {
        DDCheckeda = true;
        break;
      }
    }
    if (!DDCheckeda)
    {
      alert ("Please choose whether or not you would like to have your reimbursement checks placed into your bank account via Direct Deposit.");
      theForm.FlexAcctDD(0).focus();
      return (false);
    }
  }  
  
  if (theForm.NoExAcct.checked)
    theForm.FlexAcctDD.value = "";
  
  runTot = theForm.RunningTotal.value;
  if (runTot >= 0.01)
  {
    alertString = "You must use all available Flexdollars allocated to you.  ";
    alertString = alertString + "Please allocate your remaining " + formatCurrency(runTot);
    alertString = alertString + " to either your Medical Expense or Dependent Care Spending Accounts."
    alert (alertString);
    theForm.MedExAcct.focus();
    return (false);
  }
  else
  {
    if (runTot > 0)  // there is a fraction of a cent left over
    {
      runTot = 0;
      theForm.RunningTotal.value = 0;
    }
  }
  
  var checkOK = "0123456789.";
  var checkStr = theForm.MedExAmt.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 digits and decimal points in the \"Medical Expense Spending Account\" field.");
    theForm.MedExAmt.focus();
    return (false);
  }

  var checkOK = "0123456789.";
  var checkStr = theForm.DepCareAmt.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 digits and decimal points in the \"Dependent Care Spending Account\" field.");
    theForm.DepCareAmt.focus();
    return (false);
  }

  if (theForm.MedExAmt.value > 2500)
  {
    alert ("You may only defer a maximum of $2500 into your Medical Expense Spending Account.");
    theForm.MedExAmt.focus();
    return (false);
  }
  
  if (theForm.DepCareAmt.value > 5000)
  {
    alert ("You may only defer a maximum of $5000 into your Dependent Care Spending Account.");
    theForm.DepCareAmt.focus();
    return (false);
  }
  
  if (theForm.CanSubmit.value == "True")
    return (true);
  else
  {
    alert("You have made changes which may potentially change the amount of money you have deducted from your paycheck.  Please verify this amount before submitting the form.");
    theForm.CanSubmit.value = "True";
    return (false);
  }
}

/* *************************************************** */
/*    VALIDATOR FOR ADDRESS VERIFICATION PAGE          */
/* *************************************************** */
function AddressValidator(theForm)
{
  if (theForm.Res_Address1.value == "")
  {
    alert("Please enter a value for the \"Street Address\" field.");
    theForm.Res_Address1.focus();
    return (false);
  }

  if (theForm.Res_Address1.value.length < 1)
  { 
    alert("Please enter a value for the \"Street Address\" field.");
    theForm.Res_Address1.focus();
    return (false);
  }
 
  if (theForm.Res_Address1.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"Street Address\" field.");
    theForm.Res_Address1.focus();
    return (false);
  }
  
  if (theForm.ResCity.value == "")
  {
    alert("Please enter a value for the \"City\" field.");
    theForm.ResCity.focus();
    return (false);
  }

  if (theForm.ResCity.value.length < 1)
  { 
    alert("Please enter a value for the \"City\" field.");
    theForm.ResCity.focus();
    return (false);
  }

  if (theForm.ResCity.value.length > 25)
  {
    alert("Please enter at most 25 characters in the \"City\" field.");
    theForm.ResCity.focus();
    return (false);
  }
  
  if (theForm.ResState.value == "")
  {
    alert("Please enter a value for the \"State\" field.");
    theForm.ResState.focus();
    return (false);
  }
 
  if (theForm.ResState.value.length != 2)
  {  
    alert("Please enter a 2 character abbreviation in the \"State\" field.");
    theForm.ResState.focus();
    return (false);
  }
  
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  var checkStr = theForm.ResState.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 letters in the \"State\" field.");
    theForm.ResState.focus();
    return (false);
  }
  
  if (theForm.ResZip.value == "")
  {
    alert("Please enter a value for the \"Zip Code\" field.");
    theForm.ResZip.focus();
    return (false);
  }
  
  if ((theForm.ResZip.value.length != 5) && (theForm.ResZip.value.length != 9) && (theForm.ResZip.value.length != 10))
  {
    alert("Please enter your 5 or 9 digit Zip Code in the \"Zip Code\" field.");
    theForm.ResZip.focus();
    return (false);
  }
   
  var checkOK = "0123456789-";
  var checkStr = theForm.ResZip.value;
  var allValid = true;
  var hyphens = 0;
  var hyphndx = 0;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
      {
        if (ch == "-")
        {
          hyphens = hyphens + 1;
          hyphndx = i;
        }
        break;
      }
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only digit characters or hyphens (\"-\") in the \"Zip Code\" field.");
    theForm.ResZip.focus();
    return (false);
  } 
  if (((theForm.ResZip.value.length == 5) && (hyphens > 0)) || ((theForm.ResZip.value.length == 9) && (hyphens > 0)) || ((theForm.ResZip.value.length == 10) && ((hyphens != 1) || (hyphndx != 5))))
  {
    alert("Please enter your 5 or 9 digit Zip Code in the \"Zip Code\" field.");
    theForm.ResZip.focus();
    return (false);
  } 
  
  if ((theForm.Mail_Address1.value != "") || (theForm.Mail_Address2.value != "") || (theForm.MailCity.value != "") || (theForm.MailState.value != "") || (theForm.MailZip.value != ""))
  {
    if (theForm.Mail_Address1.value == "")
    {
      alert("Please enter a value for the \"Street Address\" field under \"Mailing Address\".");
      theForm.Mail_Address1.focus();
      return (false);
    }

    if (theForm.Mail_Address1.value.length < 1)
    { 
      alert("Please enter a value for the \"Street Address\" field under \"Mailing Address\".");
      theForm.Mail_Address1.focus();
      return (false);
    }
   
    if (theForm.Mail_Address1.value.length > 30)
    {
      alert("Please enter at most 30 characters in the \"Street Address\" field under \"Mailing Address\".");
      theForm.Mail_Address1.focus();
      return (false);
    }
  
    if (theForm.MailCity.value == "")
    {
      alert("Please enter a value for the \"City\" field under \"Mailing Address\".");
      theForm.MailCity.focus();
      return (false);
    }

    if (theForm.MailCity.value.length < 1)
    { 
      alert("Please enter a value for the \"City\" field under \"Mailing Address\".");
      theForm.MailCity.focus();
      return (false);
    }

    if (theForm.MailCity.value.length > 25)
    {
      alert("Please enter at most 25 characters in the \"City\" field under \"Mailing Address\".");
      theForm.MailCity.focus();
      return (false);
    }
  
    if (theForm.MailState.value == "")
    {
      alert("Please enter a value for the \"State\" field under \"Mailing Address\".");
      theForm.MailState.focus();
      return (false);
    }
  
    if (theForm.MailState.value.length != 2)
    {  
      alert("Please enter a 2 character abbreviation in the \"State\" field under \"Mailing Address\".");
      theForm.MailState.focus();
      return (false);
    }
  
    var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    var checkStr = theForm.MailState.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 letters in the \"State\" field under \"Mailing Address\".");
      theForm.MailState.focus();
      return (false);
    }
    
    if (theForm.MailZip.value == "")
    {
      alert("Please enter a value for the \"Zip Code\" field under \"Mailing Address\".");
      theForm.MailZip.focus();
      return (false);
    }
  
    if ((theForm.MailZip.value.length != 5) && (theForm.MailZip.value.length != 9) && (theForm.MailZip.value.length != 10))
    {
      alert("Please enter your 5 or 9 digit Zip Code in the \"Zip Code\" field under \"Mailing Address\".");
      theForm.MailZip.focus();
      return (false);
    }
   
    var checkOK = "0123456789-";
    var checkStr = theForm.MailZip.value;
    var allValid = true;
    var hyphens = 0;
    var hyphndx = 0;
    for (i = 0;  i < checkStr.length;  i++)
    {
      ch = checkStr.charAt(i);
      for (j = 0;  j < checkOK.length;  j++)
        if (ch == checkOK.charAt(j))
        {
          if (ch == "-")
          {
            hyphens = hyphens + 1;
            hyphndx = i;
          }
          break;
        }
      if (j == checkOK.length)
      {
        allValid = false;
        break;
      }
    }
    if (!allValid)
    {
      alert("Please enter only digit characters or hyphens (\"-\") in the \"Zip Code\" field under \"Mailing Address\".");
      theForm.MailZip.focus();
      return (false);
    } 
    if (((theForm.MailZip.value.length == 5) && (hyphens > 0)) || ((theForm.MailZip.value.length == 9) && (hyphens > 0)) || ((theForm.MailZip.value.length == 10) && ((hyphens != 1) || (hyphndx != 5))))
    {
      alert("Please enter your 5 or 9 digit Zip Code in the \"Zip Code\" field under \"Mailing Address\".");
      theForm.ResZip.focus();
      return (false);
    } 
  }

  // note than month numbers in JavaScript begin with 0, not 1.
  var EffDate = new Date(theForm.MoveYear.options[theForm.MoveYear.selectedIndex].value, (theForm.MoveMonth.options[theForm.MoveMonth.selectedIndex].value - 1), theForm.MoveDay.options[theForm.MoveDay.selectedIndex].value);
  var theNow = new Date();
  if (EffDate.getMonth() != (theForm.MoveMonth.options[theForm.MoveMonth.selectedIndex].value -1))
  {
    alert("There are not " + theForm.MoveDay.value + " days in that month.  Please enter a valid Effective Date.");
    theForm.MoveDay.focus();
    return (false);
  }
  else
  {
    dateDiff = parseInt((EffDate - theNow)/86400000);  //conversion of milliseconds to days; then drop fractional days [this allows for submittal of today].
    if (dateDiff < 0) //then they entered a date earlier than today
    {
      alert("You cannot enter an Effective Date earlier than today.  If you have already moved, then set today as the Effective Date.");
      theForm.MoveMonth.focus();
      return (false);
    }
  }
  
  if (theForm.HomePhone.value.length < 10)
  {
    alert("Please enter your area code with your phone number.");
    theForm.HomePhone.focus();
    return(false);
  }

  var checkOK = "0123456789-() ";
  var checkStr = theForm.HomePhone.value;
  var allValid = true;
  openparens = 0;
  opndx = 0;
  closeparens = 0;
  closendx = 0;
  hyphens = 0;
  hyphndx = 0;
  hyphndx1 = 0;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
      {
        if (ch == "(")
        {
          openparens = openparens + 1;
          opndx = i;
        }
        if (ch == ")")
        {
          closeparens = closeparens + 1;
          closendx = i;
        }
        if ((ch == "-") || (ch == " "))
        {
          hyphens = hyphens + 1;
          if (hyphndx == 0)
            hyphndx = i;
          else
            hyphndx1 = i;
        }
        break;
      }
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only digit characters, \"(\", \")\", or a \"-\" in the \"Home Phone\" field.");
    theForm.HomePhone.focus();
    return (false);
  } 
  switch (theForm.HomePhone.value.length)
  {
    case 10:   
      if ((openparens > 0) || (closeparens > 0) || (hyphens > 0))
      {
        alert("Please enter a valid phone number in the \"Home Phone\" field.");
        theForm.HomePhone.focus();
        return(false);
      }
      break;
    case 11:
      if ((openparens > 0) || (closeparens > 0) || ((hyphens != 1) || (hyphndx != 3)))
      {
        alert("Please enter a valid phone number in the \"Home Phone\" field.");
        theForm.HomePhone.focus();
        return(false);
      }
      break;
    case 12:
      switch (closendx)
      {
        case 0:
          if ((openparens > 0) || ((hyphens != 2) || ((hyphndx != 3) || (hyphndx1 != 7))))
          {
            alert("Please enter a valid phone number in the \"Home Phone\" field.");
            theForm.HomePhone.focus();
            return(false);
          }
          break;
        case 4:
          if (((openparens != 1) || (opndx != 0)) || ((closeparens != 1) || (closendx != 4)) || (hyphens != 0))
          {
            alert("Please enter a valid phone number in the \"Home Phone\" field.");
            theForm.HomePhone.focus();
            return(false);
          }
          break;
        default:
          alert("Please enter a valid phone number in the \"Home Phone\" field.");
          theForm.HomePhone.focus();
          return(false);
      }
      break;
    case 13:
      if (((openparens != 1) || (opndx != 0)) || ((closeparens != 1) || (closendx != 4)) || ((hyphens != 1) || (hyphndx != 8)))
      {
        alert("Please enter a valid phone number in the \"Home Phone\" field.");
        theForm.HomePhone.focus();
        return(false);
      }
      break;  
    case 14:  
      if (((openparens != 1) || (opndx != 0)) || ((closeparens != 1) || (closendx != 4)) || ((hyphens != 2) || ((hyphndx != 5) || (hyphndx1 != 9))))
      {
        alert("Please enter a valid phone number in the \"Home Phone\" field.");
        theForm.HomePhone.focus();
        return(false);
      }
      break;  
    default:
      alert("Please enter a valid phone number in the \"Home Phone\" field.");
      theForm.HomePhone.focus();
      return(false);
  }
  return (true);
}

/* ************************************************* */
/*    VALIDATOR FOR DEPENDENT COVERAGE PAGE          */
/* ************************************************* */
function DepCareValidator(theControl)
{
  /* two controls, MCdepnum and VCdepnum (where depnum is a 
     dependent ID number) are mutually exclusive.  the goal is
     as follows: when passed one of these controls, find out if it
     is checked; and if it is, uncheck the paired control and alert
     the user of the error.  */
  //if theControl.checked
  {
    aStr = theControl.name;
    if (aStr.indexOf("MC") == 0)
    {
      newStr = "D";
      for(i = 1; i < aStr.length; i++)
       newStr = newStr + aStr.charAt(i); 
      if (theControl.form.elements[newStr].checked)
      {
        theControl.checked = false;
        theControl.focus;
        alert ("No person can be covered on both medical and dental.  Medical coverage includes dental coverage.  Supplemental dental coverage is only for dependents not carried as medical dependents.");
        return (false);
      }
    }
    if (aStr.indexOf("DC") == 0)
    {
      newStr = "M";
      for(i = 1; i < aStr.length; i++)
        newStr = newStr + aStr.charAt(i); 
      hasMed = false;
      for(i = 0; i < theControl.form.elements.count; i++)
        if (theControl.form.elements[i].name == newStr)
          hasMed = true;
      if ((hasMed) && (theControl.form.elements[newStr].checked))
      {
        theControl.checked = false;
        theControl.focus;
        alert ("No person can be covered on both medical and dental.  Medical coverage includes dental coverage.  Supplemental dental coverage is only for dependents not carried as medical dependents.");
        return (false);
      }
    }
  }      
  return (true);
}

/* **************************************************** */
/*    VALIDATOR FOR DEPENDENT INFORMATION PAGE          */
/* **************************************************** */
function DepInfoValidator(theForm)
{
  if (theForm.FirstName.value == "")
  {
    alert("Please enter a value for the \"First Name\" field.");
    theForm.FirstName.focus();
    return(false);
  }
  if (theForm.FirstName.value.length < 1)
  { 
    alert("Please enter a value for the \"First Name\" field.");
    theForm.FirstName.focus();
    return(false);
  } 
  if (theForm.FirstName.value.length > 15)
  {
    alert("Please enter at most 15 characters in the \"First Name\" field.");
    theForm.FirstName.focus();
    return(false);
  }
  
  if (theForm.MidInit.value.length > 1)
  {
    alert("Please enter only 1 character in the \"MI\" field.");
    theForm.MidInit.focus();
    return(false);
  }
  if (theForm.MidInit.value.length = 1)
  {
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  var checkStr = theForm.MidInit.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 a single alphabetic character in the \"MI\" field.");
    theForm.MidInit.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 < 1)
  { 
    alert("Please enter a value for the \"Last Name\" field.");
    theForm.LastName.focus();
    return(false);
  } 
  if (theForm.LastName.value.length > 20)
  {
    alert("Please enter no more than 20 characters in the \"Last Name\" field.");
    theForm.LastName.focus();
    return(false);
  }
  
  if (theForm.SSN.value == "")
  {
    alert("Please enter a value for the \"Social Security Number\" field.");
    theForm.SSN.focus();
    return (false);
  }
  if (theForm.SSN.value.length < 1)
  { 
    alert("Please enter a value for the \"Social Security Number\" field.");
    theForm.SSN.focus();
    return (false);
  } 
  if (theForm.SSN.value.length > 9)
  {
    alert("Please enter nine digits in the \"Social Security Number\" field.");
    theForm.SSN.focus();
    return (false);
  }
  var checkOK = "0123456789";
  var checkStr = theForm.SSN.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 digit characters in the \"Social Security Number\" field.  Do not use dashes or spaces.");
    theForm.SSN.focus();
    return (false);
  } 

  if (theForm.Relat.selectedIndex == 0)
  {
    alert("Please select a relationship for this dependent from the \"Relationship\" list.");
    theForm.Relat.focus;
    return (false);
  }

  if (theForm.Relat.selectedIndex == 1)  //it's a spouse, get a marriage date
  {
    if ((theForm.MarriageMonth.selectedIndex == 0) || (theForm.MarriageDay.selectedIndex == 0) || (theForm.MarriageYear.selectedIndex == 0))
    {
      alert("Please provide your marraige date (Month, Day, and Year).")
      if (theForm.MarriageMonth.selectedIndex == 0)
        theForm.MarriageMonth.focus();
      else
        if (theForm.MarriageDay.selectedIndex == 0)
          theForm.MarriageDay.focus();
        else
          theForm.MarriageYear.focus();
      return (false);
    }
    else
    {
      // note than month numbers in JavaScript begin with 0, not 1.
      var EffDate = new Date(theForm.MarriageYear.options[theForm.MarriageYear.selectedIndex].value, (theForm.MarriageMonth.options[theForm.MarriageMonth.selectedIndex].value - 1), theForm.MarriageDay.options[theForm.MarriageDay.selectedIndex].value);
      var theNow = new Date();
      if (EffDate.getMonth() != (theForm.MarriageMonth.options[theForm.MarriageMonth.selectedIndex].value -1))
      {
        alert("There are not " + theForm.MarriageDay.value + " days in that month.  Please enter a valid Marriage Date.");
        theForm.MarriageDay.focus();
        return (false);
      }
    }
  }
  
  if ((theForm.DOBMonth.selectedIndex == 0) || (theForm.DOBDay.selectedIndex == 0) || (theForm.DOBYear.selectedIndex == 0))
  {
    alert("Please provide a birthdate (Month, Day, and Year).")
    if (theForm.DOBMonth.selectedIndex == 0)
      theForm.DOBMonth.focus();
    else
      if (theForm.DOBDay.selectedIndex == 0)
        theForm.DOBDay.focus();
      else
        theForm.DOBYear.focus();
    return (false);
  }
  else
  {
    // note than month numbers in JavaScript begin with 0, not 1.
    var EffDate = new Date(theForm.DOBYear.options[theForm.DOBYear.selectedIndex].value, (theForm.DOBMonth.options[theForm.DOBMonth.selectedIndex].value - 1), theForm.DOBDay.options[theForm.DOBDay.selectedIndex].value);
    var theNow = new Date();
    if (EffDate.getMonth() != (theForm.DOBMonth.options[theForm.DOBMonth.selectedIndex].value -1))
    {
      alert("There are not " + theForm.DOBDay[theForm.DOBDay.selectedIndex].value + " days in that month.  Please enter a valid Birthdate.");
      theForm.DOBDay.focus();
      return (false);
    }
  }


  return (true);
}

/* *********************************************************** */
/*    VALIDATOR FOR CANCER INSURANCE APPLICATION PAGE          */
/* *********************************************************** */
function CancerApplyValidator(theForm)
{
  aBoolean = false;
  for (aCounter = 0; aCounter <= 1; aCounter++)
  {
    if (theForm.Question4A(aCounter).checked)
    {
      aBoolean = true;
      break;
    }
  }
  aBoolean2 = false;
  for (aCounter = 0; aCounter <= 1; aCounter++)
  {
    if (theForm.Question4B(aCounter).checked)
    {
      aBoolean2 = true;
      break;
    }
  }
  if (!aBoolean || !aBoolean2)
  {
    alert ("Please answer the questions in the Non-Medical Questionnaire.");
    if (!aBoolean)
      theForm.Question4A(0).focus();
    else
      theForm.Question4B(0).focus();
    return (false);
  }

  if (theForm.Question4A(0).checked || theForm.Question4B(0).checked) //they have an exception, and must have listed an affected dependent
  {
    aBoolean = false;
    if (theForm.DepCount.value > 1)
    {
      for (aCounter = 0; aCounter <= (theForm.DepCount.value - 1); aCounter++)
      {
        if ((theForm.DepOut(aCounter).value != "") || (theForm.DepCond(aCounter).value != ""))
          aBoolean = true;
      }
    }
    else
    {
      if ((theForm.DepOut.value != "") || (theForm.DepCond.value != ""))
        aBoolean = true;
    }
    if (!aBoolean)
      {
        alert("You answered \"Yes\" to one of the questions in the Non-Medical Questionnaire.  Please list the name and medical condition of the person affected.");
        if (theForm.DepCount.value > 1)
          theForm.DepOut(0).focus();
        else
          theForm.DepOut.focus();
        return (false);
      }
  }

  aBoolean = false;
  for (aCounter = 0; aCounter <= 1; aCounter++)
  {
    if (theForm.Question5(aCounter).checked)
    {
      aBoolean = true;
      break;
    }
  }
  if (!aBoolean)
  {
    alert ("Please indicate whether this policy will replace an existing policy.");
    theForm.Question5(0).focus();
    return (false);
  }

  if (theForm.Question5(0).checked) //they are replacing a policy, and must list the current policy number and company name
  {
    aBoolean = false;
    if (!((theForm.PrevCompany.value != "") && (theForm.PrevPolicy.value != "")))
    {
        alert("You indicated that you are replacing an existing policy.  Please provide us with the Company Name and Policy Number of your current coverage.");
        theForm.PrevCompany.focus();
        return (false);
    }
  }
  
  if (!(theForm.accept.checked)) //they haven't accepted the legal statement
  {
    alert("You must read, understand and accept the statement of understanding at the bottom of this form.  Please indicate acceptance by checking the box to its left.");
    theForm.accept.focus();
    return(false);
  } 
  
  return (true);
}

/* **************************************************** */
/*    VALIDATOR FOR GTLI INSURANCE CHANGE PAGE          */
/* **************************************************** */
function GTLIChangeValidator(theForm)
{
  if (!(theForm.confirm.checked)) //they haven't accepted the legal statement
  {
    alert("You must read, understand and accept the statement of understanding at the top of this form.  Please indicate acceptance by checking the box to its left.");
    theForm.confirm.focus();
    return(false);
  } 

  if (theForm.EmpOption.value == "Yes")
  {
    if (theForm.Empheightft.selectedIndex == 0)
    {
      alert("You must enter your height.");
      theForm.Empheightft.focus;
      return(false);
    }
    if (theForm.Empheightin.selectedIndex == 0)
    {
      alert("You must enter your height (both feet and inches).");
      theForm.Empheightin.focus;
      return(false);
    }
    
    if (theForm.Empweight.value == "")
    {
      alert("You must enter your weight.");
      theForm.Empweight.focus();
      return (false);
    }
    if ((theForm.Empweight.value.length < 2) || (theForm.Empweight.value.length > 3))
    {
      alert("Please enter your correct weight.");
      theForm.Empweight.focus();
      return (false);
    }
    var checkOK = "0123456789";
    var checkStr = theForm.Empweight.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 digits in the \"Weight\" field.");
      theForm.Empweight.focus();
      return (false);
    }
      
    if (theForm.EmpBeneChange.checked)
    {
      totalBenes = 0;
      totalPct = 0;
      for (i = 0; i <= 3; i++)
      {
        if ((((theForm.EmpBeneName(i).value != "") || (theForm.EmpBenePct(i).value != "")) || (theForm.EmpBeneSSN(i).value != "")) || ((((theForm.EmpBeneDOBMonth(i).selectedIndex > 0) || (theForm.EmpBeneDOBDay(i).selectedIndex > 0)) || (theForm.EmpBeneDOBYear(i).selectedIndex > 0)) || (theForm.EmpBeneRelat(i).value != "")))
        {
          if (!((((theForm.EmpBeneName(i).value != "") && (theForm.EmpBenePct(i).value != "")) && (theForm.EmpBeneSSN(i).value != "")) && ((((theForm.EmpBeneDOBMonth(i).selectedIndex > 0) && (theForm.EmpBeneDOBDay(i).selectedIndex > 0)) && (theForm.EmpBeneDOBYear(i).selectedIndex > 0)) && (theForm.EmpBeneRelat(i).value != ""))))
          {
            alert("You must enter all information for each beneficiary of your insurance.  You currently have incomplete information for beneficiary number " + (i + 1) + " under the \"Employee Coverage\" section.");
            theForm.EmpBeneName(i).focus();
            return (false);
          }
          else
          {
            totalBenes = totalBenes + 1;
            totalPct = totalPct + parseFloat(theForm.EmpBenePct(i).value);
          }
          var checkOK = "0123456789";
          var checkStr = theForm.EmpBenePct(i).value;
          var allValid = true;
          for (k = 0;  k < checkStr.length;  k++)
          {
            ch = checkStr.charAt(k);
            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 digits in the Percentage field.");
            theForm.EmpBenePct(i).focus();
            return (false);
          }
          if (theForm.EmpBeneSSN(i).value.length != 9)
          {
            alert("Please enter all Social Security Numbers as nine-digit numbers.  Do not use dashes.  Thank you.");
            theForm.EmpBeneSSN(i).focus();
            return (false);
          }
          var checkOK = "0123456789";
          var checkStr = theForm.EmpBeneSSN(i).value;
          var allValid = true;
          for (k = 0;  k < checkStr.length;  k++)
          {
            ch = checkStr.charAt(k);
            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 all Social Security Numbers as nine-digit numbers.  Do not use dashes.  Thank you.");
            theForm.EmpBeneSSN(i).focus();
            return (false);
          }
        }
      }
      if (totalBenes == 0)
      {
        alert("You have not entered any beneficiary information under the \"Employee Coverage\" section.  Please tell us your new beneficiaries, or uncheck the box indicating that you would like to change beneficiaries.");
        theForm.EmpBeneChange.focus();
        return (false);
      }
      if (totalPct > 100)
      {
        alert("You have allocated more than 100% of your coverage to your beneficiaries.  Please change the percentages you entered in the \"Beneficiaries\" section under \"Employee Coverage.\"");
        theForm.EmpBenePct(0).focus();
        return (false);
      }
      if (totalPct < 100)
        if (totalBenes == 4)
          alert("You have not yet allocated all 100% of your coverage to your beneficiaries.  Please write down the remaining beneficiary information, using the format on this page, making sure that the percentages add up to 100%.  Sign and date this  piece of paper and deliver it to personnel.");        
        else
        {
          alert("You have not yet allocated all 100% of your coverage to your beneficiaries.  Please change the percentages, or add more beneficiaries, in the \"Beneficiaries\" section under \"Employee Coverage.\"");
          theForm.EmpBenePct(0).focus();
          return (false);
        }
    }
  }
    
  if (theForm.SpouseOption.value == "Yes")
  {
    if (theForm.Spouseheightft.selectedIndex == 0)
    {
      alert("You must enter your Spouse's height.");
      theForm.Spouseheightft.focus;
      return(false);
    }
    if (theForm.Spouseheightin.selectedIndex == 0)
    {
      alert("You must enter your Spouse's height (both feet and inches).");
      theForm.Spouseheightin.focus;
      return(false);
    }
  
    if (theForm.Spouseweight.value == "")
    {
      alert("You must enter your Spouse's weight.");
      theForm.Spouseweight.focus();
      return (false);
    }
    if ((theForm.Spouseweight.value.length < 2) || (theForm.Spouseweight.value.length > 3))
    {
      alert("Please enter your Spouse's correct weight.");
      theForm.Spouseweight.focus();
      return (false);
    }
    var checkOK = "0123456789";
    var checkStr = theForm.Spouseweight.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 digits in the \"Weight\" field under \"Spouse's Coverage.\"");
      theForm.Spouseweight.focus();
      return (false);
    }
  
    if (theForm.SpouseBeneChange.checked)
    {
      totalBenes = 0;
      totalPct = 0;
      for (i = 0; i <= 3; i++)
      {
        if ((((theForm.SpouseBeneName(i).value != "") || (theForm.SpouseBenePct(i).value != "")) || (theForm.SpouseBeneSSN(i).value != "")) || ((((theForm.SpouseBeneDOBMonth(i).selectedIndex > 0) || (theForm.SpouseBeneDOBDay(i).selectedIndex > 0)) || (theForm.SpouseBeneDOBYear(i).selectedIndex > 0)) || (theForm.SpouseBeneRelat(i).value != "")))
        {
          if (!((((theForm.SpouseBeneName(i).value != "") && (theForm.SpouseBenePct(i).value != "")) && (theForm.SpouseBeneSSN(i).value != "")) && ((((theForm.SpouseBeneDOBMonth(i).selectedIndex > 0) && (theForm.SpouseBeneDOBDay(i).selectedIndex > 0)) && (theForm.SpouseBeneDOBYear(i).selectedIndex > 0)) && (theForm.SpouseBeneRelat(i).value != ""))))
          {
            alert("You must enter all information for each beneficiary of your Spouse's insurance.  You currently have incomplete information for beneficiary number " + (i + 1) + " under the \"Spouse's Coverage\" section.");
            theForm.SpouseBeneName(i).focus();
            return (false);
          }
          else
          {
            totalBenes = totalBenes + 1;
            totalPct = totalPct + parseFloat(theForm.SpouseBenePct(i).value);
          }
          var checkOK = "0123456789";
          var checkStr = theForm.SpouseBenePct(i).value;
          var allValid = true;
          for (k = 0;  k < checkStr.length;  k++)
          {
            ch = checkStr.charAt(k);
            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 digits in the Percentage field.");
            theForm.SpouseBenePct(i).focus();
            return (false);
          }
          if (theForm.SpouseBeneSSN(i).value.length != 9)
          {
            alert("Please enter all Social Security Numbers as nine-digit numbers.  Do not use dashes.  Thank you.");
            theForm.SpouseBeneSSN(i).focus();
            return (false);
          }
          var checkOK = "0123456789";
          var checkStr = theForm.SpouseBeneSSN(i).value;
          var allValid = true;
          for (k = 0;  k < checkStr.length;  k++)
          {
            ch = checkStr.charAt(k);
            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 all Social Security Numbers as nine-digit numbers.  Do not use dashes.  Thank you.");
            theForm.SpouseBeneSSN(i).focus();
            return (false);
          }
        }
      }
      if (totalBenes == 0)
      {
        alert("You have not entered any beneficiary information under the \"Spouse's Coverage\" section.  Please tell us your new beneficiaries, or uncheck the box indicating that you would like to change beneficiaries.");
        theForm.SpouseBeneChange.focus();
        return (false);
      }
      if (totalPct > 100)
      {
        alert("You have allocated more than 100% of your Spouse's coverage to his or her beneficiaries.  Please change the percentages you entered in the \"Beneficiaries\" section under \"Spouse's Coverage.\"");
        theForm.SpouseBenePct(0).focus();
        return (false);
      }
      if (totalPct < 100)
        if (totalBenes == 4)
          alert("You have not yet allocated all 100% of your Spouse's coverage to his or her beneficiaries.  Please write down the remaining beneficiary information, using the format on this page, making sure that the percentages add up to 100%.  Sign and date this  piece of paper and deliver it to personnel.");        
        else
        {
          alert("You have not yet allocated all 100% of your Spouse's coverage to his or her beneficiaries.  Please change the percentages, or add more beneficiaries, in the \"Beneficiaries\" section under \"Spouse's Coverage.\"");
          theForm.SpouseBenePct(0).focus();
          return (false);
        }
    }
  }
  
  if (theForm.ChildOption.value == "Yes")
  {
    if (theForm.ChildBeneChange.checked)
    {
      totalBenes = 0;
      totalPct = 0;
      for (i = 0; i <= 3; i++)
      {
        if ((((theForm.ChildBeneName(i).value != "") || (theForm.ChildBenePct(i).value != "")) || (theForm.ChildBeneSSN(i).value != "")) || ((((theForm.ChildBeneDOBMonth(i).selectedIndex > 0) || (theForm.ChildBeneDOBDay(i).selectedIndex > 0)) || (theForm.ChildBeneDOBYear(i).selectedIndex > 0)) || (theForm.ChildBeneRelat(i).value != "")))
        {
          if (!((((theForm.ChildBeneName(i).value != "") && (theForm.ChildBenePct(i).value != "")) && (theForm.ChildBeneSSN(i).value != "")) && ((((theForm.ChildBeneDOBMonth(i).selectedIndex > 0) && (theForm.ChildBeneDOBDay(i).selectedIndex > 0)) && (theForm.ChildBeneDOBYear(i).selectedIndex > 0)) && (theForm.ChildBeneRelat(i).value != ""))))
          {
            alert("You must enter all information for each beneficiary of your Child(ren)'s insurance.  You currently have incomplete information for beneficiary number " + (i + 1) + " under the \"Child(ren)'s Coverage\" section.");
            theForm.ChildBeneName(i).focus();
            return (false);
          }
          else
          {
            totalBenes = totalBenes + 1;
            totalPct = totalPct + parseFloat(theForm.ChildBenePct(i).value);
          }
          var checkOK = "0123456789";
          var checkStr = theForm.ChildBenePct(i).value;
          var allValid = true;
          for (k = 0;  k < checkStr.length;  k++)
          {
            ch = checkStr.charAt(k);
            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 digits in the Percentage field.");
            theForm.ChildBenePct(i).focus();
            return (false);
          }
           if (theForm.ChildBeneSSN(i).value.length != 9)
          {
            alert("Please enter all Social Security Numbers as nine-digit numbers.  Do not use dashes.  Thank you.");
            theForm.ChildBeneSSN(i).focus();
            return (false);
          }
          var checkOK = "0123456789";
          var checkStr = theForm.ChildBeneSSN(i).value;
          var allValid = true;
          for (k = 0;  k < checkStr.length;  k++)
          {
            ch = checkStr.charAt(k);
            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 all Social Security Numbers as nine-digit numbers.  Do not use dashes.  Thank you.");
            theForm.ChildBeneSSN(i).focus();
            return (false);
          }
        }
      }
      if (totalBenes == 0)
      {
        alert("You have not entered any beneficiary information under the \"Child(ren)'s Coverage\" section.  Please tell us your new beneficiaries, or uncheck the box indicating that you would like to change beneficiaries.");
        theForm.ChildBeneChange.focus();
        return (false);
      }
      if (totalPct > 100)
      {
        alert("You have allocated more than 100% of your Child(ren)'s coverage to his/her/their beneficiaries.  Please change the percentages you entered in the \"Beneficiaries\" section under \"Child(ren)'s Coverage.\"");
        theForm.ChildBenePct(0).focus();
        return (false);
      }
      if (totalPct < 100)
        if (totalBenes == 4)
          alert("You have not yet allocated all 100% of your Child(ren)'s coverage to his/her/their beneficiaries.  Please write down the remaining beneficiary information, using the format on this page, making sure that the percentages add up to 100%.  Sign and date this piece of paper and deliver it to personnel.");        
        else
        {
          alert("You have not yet allocated all 100% of your Child(ren)'s coverage to his/her/their beneficiaries.  Please change the percentages, or add more beneficiaries, in the \"Beneficiaries\" section under \"Child(ren)'s Coverage.\"");
          theForm.ChildBenePct(0).focus();
          return (false);
        }
    }
  }
  
  return (true);
}

/* ********************************************************* */
/*    VALIDATOR FOR GTLI INSURANCE APPLICATION PAGE          */
/* ********************************************************* */
function GTLIApplyValidator(theForm)
{
  if (theForm.EmpOption.value == "Yes")
  {
    if (theForm.Empheightft.selectedIndex == 0)
    {
      alert("You must enter your height.");
      theForm.Empheightft.focus;
      return(false);
    }
    if (theForm.Empheightin.selectedIndex == 0)
    {
      alert("You must enter your height (both feet and inches).");
      theForm.Empheightin.focus;
      return(false);
    }
    if (theForm.Empweight.value == "")
    {
      alert("You must enter your weight.");
      theForm.Empweight.focus();
      return (false);
    }
    if ((theForm.Empweight.value.length < 2) || (theForm.Empweight.value.length > 3))
    {
      alert("Please enter your correct weight.");
      theForm.Empweight.focus();
      return (false);
    }
    var checkOK = "0123456789";
    var checkStr = theForm.Empweight.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 digits in the \"Weight\" field.");
      theForm.Empweight.focus();
      return (false);
    }
    
    totalBenes = 0;
    totalPct = 0;
    for (i = 0; i <= 3; i++)
    {
      if ((((theForm.EmpBeneName(i).value != "") || (theForm.EmpBenePct(i).value != "")) || (theForm.EmpBeneSSN(i).value != "")) || ((((theForm.EmpBeneDOBMonth(i).selectedIndex > 0) || (theForm.EmpBeneDOBDay(i).selectedIndex > 0)) || (theForm.EmpBeneDOBYear(i).selectedIndex > 0)) || (theForm.EmpBeneRelat(i).value != "")))
      {
        if (!((((theForm.EmpBeneName(i).value != "") && (theForm.EmpBenePct(i).value != "")) && (theForm.EmpBeneSSN(i).value != "")) && ((((theForm.EmpBeneDOBMonth(i).selectedIndex > 0) && (theForm.EmpBeneDOBDay(i).selectedIndex > 0)) && (theForm.EmpBeneDOBYear(i).selectedIndex > 0)) && (theForm.EmpBeneRelat(i).value != ""))))
        {
          alert("You must enter all information for each beneficiary of your insurance.  You currently have incomplete information for beneficiary number " + (i + 1) + " under the \"Employee Coverage\" section.");
          theForm.EmpBeneName(i).focus();
          return (false);
        }
        else
        {
          totalBenes = totalBenes + 1;
          totalPct = totalPct + parseFloat(theForm.EmpBenePct(i).value);
        }
        var checkOK = "0123456789";
        var checkStr = theForm.EmpBenePct(i).value;
        var allValid = true;
        for (k = 0;  k < checkStr.length;  k++)
        {
          ch = checkStr.charAt(k);
          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 digits in the Percentage field.");
          theForm.EmpBenePct(i).focus();
          return (false);
        }
        if (theForm.EmpBeneSSN(i).value.length != 9)
        {
          alert("Please enter all Social Security Numbers as nine-digit numbers.  Do not use dashes.  Thank you.");
          theForm.EmpBeneSSN(i).focus();
          return (false);
        }
        var checkOK = "0123456789";
        var checkStr = theForm.EmpBeneSSN(i).value;
        var allValid = true;
        for (k = 0;  k < checkStr.length;  k++)
        {
          ch = checkStr.charAt(k);
          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 all Social Security Numbers as nine-digit numbers.  Do not use dashes.  Thank you.");
          theForm.EmpBeneSSN(i).focus();
          return (false);
        }
      }
    }
    if (totalBenes == 0)
    {
      alert("You have not entered any beneficiary information under the \"Employee Coverage\" section.");
      theForm.EmpBeneName(0).focus();
      return (false);
    }
    if (totalPct > 100)
    {
      alert("You have allocated more than 100% of your coverage to your beneficiaries.  Please change the percentages you entered in the \"Beneficiaries\" section under \"Employee Coverage.\"");
      theForm.EmpBenePct(0).focus();
      return (false);
    }
    if (totalPct < 100)
      if (totalBenes == 4)
        alert("You have not yet allocated all 100% of your coverage to your beneficiaries.  Please write down the remaining beneficiary information, using the format on this page, making sure that the percentages add up to 100%.  Sign and date this  piece of paper and deliver it to personnel.");        
      else
      {
        alert("You have not yet allocated all 100% of your coverage to your beneficiaries.  Please change the percentages, or add more beneficiaries, in the \"Beneficiaries\" section under \"Employee Coverage.\"");
        theForm.EmpBenePct(0).focus();
        return (false);
      }
  
    for ( i = 1 ; i <= 7 ; i++)
    {
      if (!(theForm.elements['EQ' + String(i)](0).checked) && !(theForm.elements['EQ' + String(i)](1).checked))
      {
        alert("Please make sure you answer questions A through K in the health questionnaire.");
        theForm.elements['EQ' + String(i)](0).focus();
        return(false);
      }
    }
  }  
  
    
  if (theForm.SpouseOption.value == "Yes")
  {
    if (theForm.Spouseheightft.selectedIndex == 0)
    {
      alert("You must enter your Spouse's height.");
      theForm.Spouseheightft.focus;
      return(false);
    }
    if (theForm.Spouseheightin.selectedIndex == 0)
    {
      alert("You must enter your Spouse's height (both feet and inches).");
      theForm.Spouseheightin.focus;
      return(false);
    }
  
    if (theForm.Spouseweight.value == "")
    {
      alert("You must enter your Spouse's weight.");
      theForm.Spouseweight.focus();
      return (false);
    }
    if ((theForm.Spouseweight.value.length < 2) || (theForm.Spouseweight.value.length > 3))
    {
      alert("Please enter your Spouse's correct weight.");
      theForm.Spouseweight.focus();
      return (false);
    }
    var checkOK = "0123456789";
    var checkStr = theForm.Spouseweight.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 digits in the \"Weight\" field under \"Spouse's Coverage.\"");
      theForm.Spouseweight.focus();
      return (false);
    }
  
    totalBenes = 0;
    totalPct = 0;
    for (i = 0; i <= 3; i++)
    {
      if ((((theForm.SpouseBeneName(i).value != "") || (theForm.SpouseBenePct(i).value != "")) || (theForm.SpouseBeneSSN(i).value != "")) || ((((theForm.SpouseBeneDOBMonth(i).selectedIndex > 0) || (theForm.SpouseBeneDOBDay(i).selectedIndex > 0)) || (theForm.SpouseBeneDOBYear(i).selectedIndex > 0)) || (theForm.SpouseBeneRelat(i).value != "")))
      {
        if (!((((theForm.SpouseBeneName(i).value != "") && (theForm.SpouseBenePct(i).value != "")) && (theForm.SpouseBeneSSN(i).value != "")) && ((((theForm.SpouseBeneDOBMonth(i).selectedIndex > 0) && (theForm.SpouseBeneDOBDay(i).selectedIndex > 0)) && (theForm.SpouseBeneDOBYear(i).selectedIndex > 0)) && (theForm.SpouseBeneRelat(i).value != ""))))
        {
          alert("You must enter all information for each beneficiary of your Spouse's insurance.  You currently have incomplete information for beneficiary number " + (i + 1) + " under the \"Spouse's Coverage\" section.");
          theForm.SpouseBeneName(i).focus();
          return (false);
        }
        else
        {
          totalBenes = totalBenes + 1;
          totalPct = totalPct + parseFloat(theForm.SpouseBenePct(i).value);
        }
        var checkOK = "0123456789";
        var checkStr = theForm.SpouseBenePct(i).value;
        var allValid = true;
        for (k = 0;  k < checkStr.length;  k++)
        {
          ch = checkStr.charAt(k);
          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 digits in the Percentage field.");
          theForm.SpouseBenePct(i).focus();
          return (false);
        }
        if (theForm.SpouseBeneSSN(i).value.length != 9)
        {
          alert("Please enter all Social Security Numbers as nine-digit numbers.  Do not use dashes.  Thank you.");
          theForm.SpouseBeneSSN(i).focus();
          return (false);
        }
        var checkOK = "0123456789";
        var checkStr = theForm.SpouseBeneSSN(i).value;
        var allValid = true;
        for (k = 0;  k < checkStr.length;  k++)
        {
          ch = checkStr.charAt(k);
          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 all Social Security Numbers as nine-digit numbers.  Do not use dashes.  Thank you.");
          theForm.SpouseBeneSSN(i).focus();
           return (false);
        }
      }
    }
    if (totalBenes == 0)
    {
      alert("You have not entered any beneficiary information under the \"Spouse's Coverage\" section.");
      theForm.SpouseBeneName(0).focus();
      return (false);
    }
    if (totalPct > 100)
    {
      alert("You have allocated more than 100% of your Spouse's coverage to his or her beneficiaries.  Please change the percentages you entered in the \"Beneficiaries\" section under \"Spouse's Coverage.\"");
      theForm.SpouseBenePct(0).focus();
      return (false);
    }
    if (totalPct < 100)
      if (totalBenes == 4)
        alert("You have not yet allocated all 100% of your Spouse's coverage to his or her beneficiaries.  Please write down the remaining beneficiary information, using the format on this page, making sure that the percentages add up to 100%.  Sign and date this  piece of paper and deliver it to personnel.");        
      else
      {
        alert("You have not yet allocated all 100% of your Spouse's coverage to his or her beneficiaries.  Please change the percentages, or add more beneficiaries, in the \"Beneficiaries\" section under \"Spouse's Coverage.\"");
        theForm.SpouseBenePct(0).focus();
        return (false);
      }

    for ( i = 1 ; i <= 7 ; i++)
    {
      if (!(theForm.elements['SQ' + String(i)](0).checked) && !(theForm.elements['SQ' + String(i)](1).checked))
      {
        alert("Please make sure you answer questions A through K in the health questionnaire under \"Spouse's Coverage.\"");
        theForm.elements['SQ' + String(i)](0).focus();
        return(false);
      }
    }
  }
 
  
  if (theForm.ChildOption.value == "Yes")
  {
    totalBenes = 0;
    totalPct = 0;
    for (i = 0; i <= 3; i++)
    {
      if ((((theForm.ChildBeneName(i).value != "") || (theForm.ChildBenePct(i).value != "")) || (theForm.ChildBeneSSN(i).value != "")) || ((((theForm.ChildBeneDOBMonth(i).selectedIndex > 0) || (theForm.ChildBeneDOBDay(i).selectedIndex > 0)) || (theForm.ChildBeneDOBYear(i).selectedIndex > 0)) || (theForm.ChildBeneRelat(i).value != "")))
      {
        if (!((((theForm.ChildBeneName(i).value != "") && (theForm.ChildBenePct(i).value != "")) && (theForm.ChildBeneSSN(i).value != "")) && ((((theForm.ChildBeneDOBMonth(i).selectedIndex > 0) && (theForm.ChildBeneDOBDay(i).selectedIndex > 0)) && (theForm.ChildBeneDOBYear(i).selectedIndex > 0)) && (theForm.ChildBeneRelat(i).value != ""))))
        {
          alert("You must enter all information for each beneficiary of your Child(ren)'s insurance.  You currently have incomplete information for beneficiary number " + (i + 1) + " under the \"Child(ren)'s Coverage\" section.");
          theForm.ChildBeneName(i).focus();
          return (false);
        }
        else
        {
          totalBenes = totalBenes + 1;
          totalPct = totalPct + parseFloat(theForm.ChildBenePct(i).value);
        }
        var checkOK = "0123456789";
        var checkStr = theForm.ChildBenePct(i).value;
        var allValid = true;
        for (k = 0;  k < checkStr.length;  k++)
        {
          ch = checkStr.charAt(k);
          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 digits in the Percentage field.");
          theForm.ChildBenePct(i).focus();
          return (false);
        }
        if (theForm.ChildBeneSSN(i).value.length != 9)
        {
          alert("Please enter all Social Security Numbers as nine-digit numbers.  Do not use dashes.  Thank you.");
          theForm.ChildBeneSSN(i).focus();
          return (false);
        }
        var checkOK = "0123456789";
        var checkStr = theForm.ChildBeneSSN(i).value;
        var allValid = true;
        for (k = 0;  k < checkStr.length;  k++)
        {
          ch = checkStr.charAt(k);
          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 all Social Security Numbers as nine-digit numbers.  Do not use dashes.  Thank you.");
          theForm.ChildBeneSSN(i).focus();
          return (false);
        }
      }
    }
    if (totalBenes == 0)
    {
      alert("You have not entered any beneficiary information under the \"Child(ren)'s Coverage\" section.");
      theForm.ChildBeneName(0).focus();
      return (false);
    }
    if (totalPct > 100)
    {
      alert("You have allocated more than 100% of your Child(ren)'s coverage to his/her/their beneficiaries.  Please change the percentages you entered in the \"Beneficiaries\" section under \"Child(ren)'s Coverage.\"");
      theForm.ChildBenePct(0).focus();
      return (false);
    }
    if (totalPct < 100)
      if (totalBenes == 4)
        alert("You have not yet allocated all 100% of your Child(ren)'s coverage to his/her/their beneficiaries.  Please write down the remaining beneficiary information, using the format on this page, making sure that the percentages add up to 100%.  Sign and date this piece of paper and deliver it to personnel.");        
      else
      {
        alert("You have not yet allocated all 100% of your Child(ren)'s coverage to his/her/their beneficiaries.  Please change the percentages, or add more beneficiaries, in the \"Beneficiaries\" section under \"Child(ren)'s Coverage.\"");
        theForm.ChildBenePct(0).focus();
        return (false);
      }
  }

  for (i=1; i<=4; i++)
  {
    if (!(theForm.elements['Accept' + String(i)].checked)) //they haven't accepted the 4 legal statements
    {
      alert("You must read, understand and accept the four statements of understanding at the bottom of this form.  Please indicate acceptance by checking the box to its left.  You have not yet checked the box for statement number " + String(i) + ".");
      theForm.elements['Accept' + String(i)].focus();
      return(false);
    } 
  }
     
  return (true);
}

/* *********************************************************** */
/*    VALIDATOR FOR CANCER INSURANCE APPLICATION PAGE          */
/* *********************************************************** */
function SmileCardValidator(theForm)
{
  ConfirmOneYearOK=false
  if (theForm.ConfirmOneYear.checked) ConfirmOneYearOK=true;

  
  if (theForm.ChosenDentist.value == "")
      {
        alert("You must provide the name of the dentist you are selecting");
        return (false);
      }
  
if (!ConfirmOneYearOK)
      {
        alert("You must confirm you have read the enrollment agreement at the bottom of the form");
        return (false);
      }  

  return (true);
  
}

