// Form validation code
function SBW_Form1_Validator(theForm)
{

  if (theForm.PreferredDay.selectedIndex < 0)
  {
    alert("Please select one of the \"Please Select A Day\" options.");
    theForm.PreferredDay.focus();
    return (false);
  }

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

  if (theForm.PreferredTime.selectedIndex < 0)
  {
    alert("Please select one of the \"Please Select A Time\" options.");
    theForm.PreferredTime.focus();
    return (false);
  }

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

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

  if (theForm.OfficeLocation.selectedIndex == 0)
  {
    alert("The first \"Please Select An 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 \"Please Select A Purpose For Visit\" options.");
    theForm.PurposeOfVisit.focus();
    return (false);
  }

  if (theForm.PurposeOfVisit.selectedIndex == 0)
  {
    alert("The first \"Please Select A 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);
  }

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

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

  if (theForm.PatientRelationship.selectedIndex == 0)
  {
    alert("The first \"Please Select Your 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 \"Please enter your First Name\" field.");
    theForm.FirstName.focus();
    return (false);
  }

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

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

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

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

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

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

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

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

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

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

  if (theForm.Zip.value.length < 5)
  {
    alert("Please enter at least 5 characters in the \"Please enter a 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 \"Please enter a 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 \"Please Enter 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 \"Please Enter 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 \"Please Enter 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 \"Please Enter 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 \"Please Enter 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 \"Please Enter 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 \"Please Enter 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 \"Please Enter 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 \"Please Enter 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 \"Please Enter 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 \"Please Enter 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 \"Please Enter 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 \"Please Enter 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 \"Please Enter 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 \"Please Enter 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 \"Please Enter 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 \"Please Enter 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 \"Please Enter 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 \"Please Enter 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 \"Please Enter 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);
}

