// Form validation code
function SBW_Form1_Validator(theForm)
{

  var radioSelected = false;
  for (i = 0;  i < theForm.Q1StaffPhone.length;  i++)
  {
    if (theForm.Q1StaffPhone[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 1\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q2ListenToNeeds.length;  i++)
  {
    if (theForm.Q2ListenToNeeds[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 2\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q3ExamEducation.length;  i++)
  {
    if (theForm.Q3ExamEducation[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 3\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q4ValueReceived.length;  i++)
  {
    if (theForm.Q4ValueReceived[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 4\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q5StaffCourteousProfessional.length;  i++)
  {
    if (theForm.Q5StaffCourteousProfessional[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 5\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q6OrderFollowUp.length;  i++)
  {
    if (theForm.Q6OrderFollowUp[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 6\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q7Recommend.length;  i++)
  {
    if (theForm.Q7Recommend[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 7\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q8DownloadNewPatientForms.length;  i++)
  {
    if (theForm.Q8DownloadNewPatientForms[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 8\" options.");
    return (false);
  }

  if (theForm.Q9LikeBest.value == "")
  {
    alert("Please enter a value for the \"Question 9\" field.");
    theForm.Q9LikeBest.focus();
    return (false);
  }

  if (theForm.Q9LikeBest.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"Question 9\" field.");
    theForm.Q9LikeBest.focus();
    return (false);
  }

  if (theForm.Q10Recommendations.value == "")
  {
    alert("Please enter a value for the \"Question 10\" field.");
    theForm.Q10Recommendations.focus();
    return (false);
  }

  if (theForm.Q10Recommendations.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"Question 10\" field.");
    theForm.Q10Recommendations.focus();
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q11TimeSpentWas.length;  i++)
  {
    if (theForm.Q11TimeSpentWas[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 11\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q12HowChooseECA.length;  i++)
  {
    if (theForm.Q12HowChooseECA[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 12\" options.");
    return (false);
  }

  if (theForm.Q15Recognize.value == "")
  {
    alert("Please enter a value for the \"Question 15\" field.");
    theForm.Q15Recognize.focus();
    return (false);
  }

  if (theForm.Q15Recognize.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"Question 15\" field.");
    theForm.Q15Recognize.focus();
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q16Contact.length;  i++)
  {
    if (theForm.Q16Contact[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 16\" options.");
    return (false);
  }

  if (theForm.Q17OpticianName.value == "")
  {
    alert("Please enter a value for the \"Question 17\" field.");
    theForm.Q17OpticianName.focus();
    return (false);
  }

  if (theForm.Q17OpticianName.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"Question 17\" field.");
    theForm.Q17OpticianName.focus();
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q18OpticianQuality.length;  i++)
  {
    if (theForm.Q18OpticianQuality[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 18a\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q18OpticianSatisfaction.length;  i++)
  {
    if (theForm.Q18OpticianSatisfaction[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 18b\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q18OpticianHelpfulness.length;  i++)
  {
    if (theForm.Q18OpticianHelpfulness[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 18c\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q18OpticianResponsiveness.length;  i++)
  {
    if (theForm.Q18OpticianResponsiveness[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 18d\" options.");
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Q18OpticianFriendliness.length;  i++)
  {
    if (theForm.Q18OpticianFriendliness[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Question 18e\" options.");
    return (false);
  }

  if (theForm.ApptMonth.selectedIndex < 0)
  {
    alert("Please select one of the \"Appointment Month\" options.");
    theForm.ApptMonth.focus();
    return (false);
  }

  if (theForm.ApptMonth.selectedIndex == 0)
  {
    alert("The first \"Appointment Month\" option is not a valid selection.  Please choose one of the other options.");
    theForm.ApptMonth.focus();
    return (false);
  }

  if (theForm.ApptDate.selectedIndex < 0)
  {
    alert("Please select one of the \"Appointment Date\" options.");
    theForm.ApptDate.focus();
    return (false);
  }

  if (theForm.ApptDate.selectedIndex == 0)
  {
    alert("The first \"Appointment Date\" option is not a valid selection.  Please choose one of the other options.");
    theForm.ApptDate.focus();
    return (false);
  }

  if (theForm.ApptYear.selectedIndex < 0)
  {
    alert("Please select one of the \"Appointment Year\" options.");
    theForm.ApptYear.focus();
    return (false);
  }

  if (theForm.ApptYear.selectedIndex == 0)
  {
    alert("The first \"Appointment Year\" option is not a valid selection.  Please choose one of the other options.");
    theForm.ApptYear.focus();
    return (false);
  }

  if (theForm.Doctor.selectedIndex < 0)
  {
    alert("Please select one of the \"Doctor Name\" options.");
    theForm.Doctor.focus();
    return (false);
  }

  if (theForm.Doctor.selectedIndex == 0)
  {
    alert("The first \"Doctor Name\" option is not a valid selection.  Please choose one of the other options.");
    theForm.Doctor.focus();
    return (false);
  }

  if (theForm.OfficeLocation.selectedIndex < 0)
  {
    alert("Please select one of the \"Office Location\" options.");
    theForm.OfficeLocation.focus();
    return (false);
  }

  if (theForm.OfficeLocation.selectedIndex == 0)
  {
    alert("The first \"Office Location\" option is not a valid selection.  Please choose one of the other options.");
    theForm.OfficeLocation.focus();
    return (false);
  }

  if (theForm.PurposeOfVisit.selectedIndex < 0)
  {
    alert("Please select one of the \"Purpose For Visit\" options.");
    theForm.PurposeOfVisit.focus();
    return (false);
  }

  if (theForm.PurposeOfVisit.selectedIndex == 0)
  {
    alert("The first \"Purpose For Visit\" option is not a valid selection.  Please choose one of the other options.");
    theForm.PurposeOfVisit.focus();
    return (false);
  }

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

  if (theForm.PatientName.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"Patient Name\" field.");
    theForm.PatientName.focus();
    return (false);
  }

  if (theForm.PatientRelationship.selectedIndex < 0)
  {
    alert("Please select one of the \"Relationship to Patient\" options.");
    theForm.PatientRelationship.focus();
    return (false);
  }

  if (theForm.PatientRelationship.selectedIndex == 0)
  {
    alert("The first \"Relationship to Patient\" option is not a valid selection.  Please choose one of the other options.");
    theForm.PatientRelationship.focus();
    return (false);
  }

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

  if (theForm.FirstName.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"First Name\" field.");
    theForm.FirstName.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);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.Age18.length;  i++)
  {
    if (theForm.Age18[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Verify Age 18 or Older\" options.");
    return (false);
  }

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

  if (theForm.Address.value.length < 6)
  {
    alert("Please enter at least 6 characters in the \"Your Address\" field.");
    theForm.Address.focus();
    return (false);
  }

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

  if (theForm.City.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"Your City\" field.");
    theForm.City.focus();
    return (false);
  }

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

  if (theForm.State.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"Your State\" field.");
    theForm.State.focus();
    return (false);
  }

  if (theForm.Zip.value == "")
  {
    alert("Please enter a value for the \"Your Zip Code\" field.");
    theForm.Zip.focus();
    return (false);
  }

  if (theForm.Zip.value.length < 5)
  {
    alert("Please enter at least 5 characters in the \"Your Zip Code\" field.");
    theForm.Zip.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = theForm.Zip.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  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 (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Your Zip Code\" field.");
    theForm.Zip.focus();
    return (false);
  }

  if (decPoints > 1)
  {
    alert("Please enter a valid number in the \"Zip\" field.");
    theForm.Zip.focus();
    return (false);
  }

  if (theForm.HomePhoneAreaCode.value == "")
  {
    alert("Please enter a value for the \"Home Phone 3-Digit Area Code\" field.");
    theForm.HomePhoneAreaCode.focus();
    return (false);
  }

  if (theForm.HomePhoneAreaCode.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"Home Phone 3-Digit Area Code\" field.");
    theForm.HomePhoneAreaCode.focus();
    return (false);
  }

  if (theForm.HomePhoneAreaCode.value.length > 3)
  {
    alert("Please enter at most 3 characters in the \"Home Phone 3-Digit Area Code\" field.");
    theForm.HomePhoneAreaCode.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = theForm.HomePhoneAreaCode.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  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 (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Home Phone 3-Digit Area Code\" field.");
    theForm.HomePhoneAreaCode.focus();
    return (false);
  }

  if (decPoints > 1)
  {
    alert("Please enter a valid number in the \"HomePhoneAreaCode\" field.");
    theForm.HomePhoneAreaCode.focus();
    return (false);
  }

  if (theForm.HomePhoneExchange.value == "")
  {
    alert("Please enter a value for the \"Home Phone 3-Digit Exchange\" field.");
    theForm.HomePhoneExchange.focus();
    return (false);
  }

  if (theForm.HomePhoneExchange.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"Home Phone 3-Digit Exchange\" field.");
    theForm.HomePhoneExchange.focus();
    return (false);
  }

  if (theForm.HomePhoneExchange.value.length > 3)
  {
    alert("Please enter at most 3 characters in the \"Home Phone 3-Digit Exchange\" field.");
    theForm.HomePhoneExchange.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = theForm.HomePhoneExchange.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  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 (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Home Phone 3-Digit Exchange\" field.");
    theForm.HomePhoneExchange.focus();
    return (false);
  }

  if (decPoints > 1)
  {
    alert("Please enter a valid number in the \"HomePhoneExchange\" field.");
    theForm.HomePhoneExchange.focus();
    return (false);
  }

  if (theForm.HomePhoneNumber.value == "")
  {
    alert("Please enter a value for the \"Home Phone Last 4-Digits\" field.");
    theForm.HomePhoneNumber.focus();
    return (false);
  }

  if (theForm.HomePhoneNumber.value.length < 4)
  {
    alert("Please enter at least 4 characters in the \"Home Phone Last 4-Digits\" field.");
    theForm.HomePhoneNumber.focus();
    return (false);
  }

  if (theForm.HomePhoneNumber.value.length > 4)
  {
    alert("Please enter at most 4 characters in the \"Home Phone Last 4-Digits\" field.");
    theForm.HomePhoneNumber.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = theForm.HomePhoneNumber.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  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 (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Home Phone Last 4-Digits\" field.");
    theForm.HomePhoneNumber.focus();
    return (false);
  }

  if (decPoints > 1)
  {
    alert("Please enter a valid number in the \"HomePhoneNumber\" field.");
    theForm.HomePhoneNumber.focus();
    return (false);
  }

  if (theForm.WorkPhoneAreaCode.value == "")
  {
    alert("Please enter a value for the \"Work Phone 3-Digit Area Code\" field.");
    theForm.WorkPhoneAreaCode.focus();
    return (false);
  }

  if (theForm.WorkPhoneAreaCode.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"Work Phone 3-Digit Area Code\" field.");
    theForm.WorkPhoneAreaCode.focus();
    return (false);
  }

  if (theForm.WorkPhoneAreaCode.value.length > 3)
  {
    alert("Please enter at most 3 characters in the \"Work Phone 3-Digit Area Code\" field.");
    theForm.WorkPhoneAreaCode.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = theForm.WorkPhoneAreaCode.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  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 (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Work Phone 3-Digit Area Code\" field.");
    theForm.WorkPhoneAreaCode.focus();
    return (false);
  }

  if (decPoints > 1)
  {
    alert("Please enter a valid number in the \"WorkPhoneAreaCode\" field.");
    theForm.WorkPhoneAreaCode.focus();
    return (false);
  }

  if (theForm.WorkPhoneExchange.value == "")
  {
    alert("Please enter a value for the \"Work Phone 3-Digit Exchange\" field.");
    theForm.WorkPhoneExchange.focus();
    return (false);
  }

  if (theForm.WorkPhoneExchange.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"Work Phone 3-Digit Exchange\" field.");
    theForm.WorkPhoneExchange.focus();
    return (false);
  }

  if (theForm.WorkPhoneExchange.value.length > 3)
  {
    alert("Please enter at most 3 characters in the \"Work Phone 3-Digit Exchange\" field.");
    theForm.WorkPhoneExchange.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = theForm.WorkPhoneExchange.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  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 (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Work Phone 3-Digit Exchange\" field.");
    theForm.WorkPhoneExchange.focus();
    return (false);
  }

  if (decPoints > 1)
  {
    alert("Please enter a valid number in the \"WorkPhoneExchange\" field.");
    theForm.WorkPhoneExchange.focus();
    return (false);
  }

  if (theForm.WorkPhoneNumber.value == "")
  {
    alert("Please enter a value for the \"Work Phone Last 4-Digits\" field.");
    theForm.WorkPhoneNumber.focus();
    return (false);
  }

  if (theForm.WorkPhoneNumber.value.length < 4)
  {
    alert("Please enter at least 4 characters in the \"Work Phone Last 4-Digits\" field.");
    theForm.WorkPhoneNumber.focus();
    return (false);
  }

  if (theForm.WorkPhoneNumber.value.length > 4)
  {
    alert("Please enter at most 4 characters in the \"Work Phone Last 4-Digits\" field.");
    theForm.WorkPhoneNumber.focus();
    return (false);
  }

  var radioSelected = false;
  for (i = 0;  i < theForm.PrefTimeToCall.length;  i++)
  {
    if (theForm.PrefTimeToCall[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Best Time To Call\" options.");
    return (false);
  }

  if (theForm.EMail.value == "")
  {
    alert("Please enter a value for the \"E-Mail Address\" field.");
    theForm.EMail.focus();
    return (false);
  }

  if (theForm.EMail.value.length < 6)
  {
    alert("Please enter at least 6 characters in the \"E-Mail Address\" field.");
    theForm.EMail.focus();
    return (false);
  }
  return (true);
}
