// Form validation code
function SBW_Form1_Validator(theForm)
{

  if (theForm.InvoiceNo.value == "")
  {
    alert("Please enter a value for the \"5-7 Digit Invoice No.\" field.");
    theForm.InvoiceNo.focus();
    return (false);
  }

  if (theForm.InvoiceNo.value.length < 5)
  {
    alert("Please enter at least 5 characters in the \"5-7 Digit Invoice No.\" field.");
    theForm.InvoiceNo.focus();
    return (false);
  }

  if (theForm.InvoiceNo.value.length > 7)
  {
    alert("Please enter at most 7 characters in the \"5-7 Digit Invoice No.\" field.");
    theForm.InvoiceNo.focus();
    return (false);
  }

  var checkOK = "0123456789-.";
  var checkStr = theForm.InvoiceNo.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
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"5-7 Digit Invoice No.\" field.");
    theForm.InvoiceNo.focus();
    return (false);
  }

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

  var radioSelected = false;
  for (i = 0;  i < theForm.ContactsOrGlasses.length;  i++)
  {
    if (theForm.ContactsOrGlasses[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("Please select one of the \"Contacts or Glasses\" options.");
    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.PatientHistory.selectedIndex < 0)
  {
    alert("Please select one of the \"Purpose For Visit\" options.");
    theForm.PatientHistory.focus();
    return (false);
  }

  if (theForm.PatientHistory.selectedIndex == 0)
  {
    alert("The first \"Purpose For Visit\" option is not a valid selection.  Please choose one of the other options.");
    theForm.PatientHistory.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);
}
