<!-- Set up functions to validate user's form input -->

function submitit(feedbackform)
{
<!-- Check the date of visit -->
if (BadVisit(feedbackform.DateofVisit.value))
	{
	 alert("Please enter the date in the mm/dd/yyyy format of your visit to Shoeless Joe's.");
	 feedbackform.DateofVisit.focus();

         <!-- this "selects" (highlights) the contents -->
          feedbackform.DateofVisit.select();          
	  return false;
	}

<!-- Ensure user selects answer to question 1 -->
   
    if ((!feedbackform.a01_The_host_or_hostess_was_polite[0].checked) && (!feedbackform.a01_The_host_or_hostess_was_polite[1].checked) && 
(!feedbackform.a01_The_host_or_hostess_was_polite[2].checked) && 
(!feedbackform.a01_The_host_or_hostess_was_polite[3].checked) && 
(!feedbackform.a01_The_host_or_hostess_was_polite[4].checked) )
     {
      alert("Please let us know how satisfied you were with your host/hostess (question #1).");
      return false;
     }

<!-- Ensure user selects answer to question 2 -->
   
    if ((!feedbackform.a02_The_server_was_polite[0].checked) && (!feedbackform.a02_The_server_was_polite[1].checked) && 
(!feedbackform.a02_The_server_was_polite[2].checked) && 
(!feedbackform.a02_The_server_was_polite[3].checked) && 
(!feedbackform.a02_The_server_was_polite[4].checked) )
     {
      alert("Please let us know how satisfied you were with your server (question #2).");
      return false;
     }

<!-- Ensure user selects answer to question 3 -->
   
    if ((!feedbackform.a03_The_menu_was_easy_to_read[0].checked) && (!feedbackform.a03_The_menu_was_easy_to_read[1].checked) && 
(!feedbackform.a03_The_menu_was_easy_to_read[2].checked) && 
(!feedbackform.a03_The_menu_was_easy_to_read[3].checked) && 
(!feedbackform.a03_The_menu_was_easy_to_read[4].checked) )
     {
      alert("Please let us know how satisfied you were with the readability of our menu (question #3).");
      return false;
     }

<!-- Ensure user selects answer to question 4 -->
   
    if ((!feedbackform.a04_I_was_satisfied_with_the_selection_of_food[0].checked) && (!feedbackform.a04_I_was_satisfied_with_the_selection_of_food[1].checked) && 
(!feedbackform.a04_I_was_satisfied_with_the_selection_of_food[2].checked) && 
(!feedbackform.a04_I_was_satisfied_with_the_selection_of_food[3].checked) && 
(!feedbackform.a04_I_was_satisfied_with_the_selection_of_food[4].checked) )
     {
      alert("Please let us know how satisfied you were with our selection of food (question #4).");
      return false;
     }

<!-- Ensure user selects answer to question 5 -->
   
    if ((!feedbackform.a05_I_was_satisfied_with_the_selection_of_wine[0].checked) && (!feedbackform.a05_I_was_satisfied_with_the_selection_of_wine[1].checked) && 
(!feedbackform.a05_I_was_satisfied_with_the_selection_of_wine[2].checked) && 
(!feedbackform.a05_I_was_satisfied_with_the_selection_of_wine[3].checked) && 
(!feedbackform.a05_I_was_satisfied_with_the_selection_of_wine[4].checked) )
     {
      alert("Please let us know how satisfied you were with our selection of wine (question #5).");
      return false;
     }

<!-- Ensure user selects answer to question 6 -->
   
    if ((!feedbackform.a06_I_was_satisfied_with_the_selection_of_beer[0].checked) && (!feedbackform.a06_I_was_satisfied_with_the_selection_of_beer[1].checked) && 
(!feedbackform.a06_I_was_satisfied_with_the_selection_of_beer[2].checked) && 
(!feedbackform.a06_I_was_satisfied_with_the_selection_of_beer[3].checked) && 
(!feedbackform.a06_I_was_satisfied_with_the_selection_of_beer[4].checked) )
     {
      alert("Please let us know how satisfied you were with our selection of beer (question #6).");
      return false;
     }

<!-- Ensure user selects answer to question 7 -->
   
    if ((!feedbackform.a07_I_was_satisfied_with_the_selection_of_drinks_other_than_wine_and_beer[0].checked) && (!feedbackform.a07_I_was_satisfied_with_the_selection_of_drinks_other_than_wine_and_beer[1].checked) && 
(!feedbackform.a07_I_was_satisfied_with_the_selection_of_drinks_other_than_wine_and_beer[2].checked) && 
(!feedbackform.a07_I_was_satisfied_with_the_selection_of_drinks_other_than_wine_and_beer[3].checked) && 
(!feedbackform.a07_I_was_satisfied_with_the_selection_of_drinks_other_than_wine_and_beer[4].checked) )
     {
      alert("Please let us know how satisfied you were with our selection of drinks other than wine and beer (question #7).");
      return false;
     }

<!-- Ensure user selects answer to question 8 -->
   
    if ((!feedbackform.a08_My_order_was_taken_and_served_correctly[0].checked) && (!feedbackform.a08_My_order_was_taken_and_served_correctly[1].checked) && 
(!feedbackform.a08_My_order_was_taken_and_served_correctly[2].checked) && 
(!feedbackform.a08_My_order_was_taken_and_served_correctly[3].checked) && 
(!feedbackform.a08_My_order_was_taken_and_served_correctly[4].checked) )
     {
      alert("Please let us know how satisfied you were with your order (question #8).");
      return false;
     }

<!-- Ensure user selects answer to question 9 -->
   
    if ((!feedbackform.a09_The_food_tasted_good[0].checked) && (!feedbackform.a09_The_food_tasted_good[1].checked) && 
(!feedbackform.a09_The_food_tasted_good[2].checked) && 
(!feedbackform.a09_The_food_tasted_good[3].checked) && 
(!feedbackform.a09_The_food_tasted_good[4].checked) )
     {
      alert("Please let us know how satisfied you were with our food (question #9).");
      return false;
     }

<!-- Ensure user selects answer to question 10 -->
   
    if ((!feedbackform.a10_The_dining_area_was_clean[0].checked) && (!feedbackform.a10_The_dining_area_was_clean[1].checked) && 
(!feedbackform.a10_The_dining_area_was_clean[2].checked) && 
(!feedbackform.a10_The_dining_area_was_clean[3].checked) && 
(!feedbackform.a10_The_dining_area_was_clean[4].checked) )
     {
      alert("Please let us know how satisfied you were with the cleanliness of our dining area (question #10).");
      return false;
     }

<!-- Ensure user selects answer to question 11 -->
   
    if ((!feedbackform.a11_Shoeless_Joes_offers_reasonable_prices[0].checked) && (!feedbackform.a11_Shoeless_Joes_offers_reasonable_prices[1].checked) && 
(!feedbackform.a11_Shoeless_Joes_offers_reasonable_prices[2].checked) && 
(!feedbackform.a11_Shoeless_Joes_offers_reasonable_prices[3].checked) && 
(!feedbackform.a11_Shoeless_Joes_offers_reasonable_prices[4].checked) )
     {
      alert("Please let us know how satisfied you were with our prices (question #11).");
      return false;
     }

<!-- Ensure user selects answer to question 12 -->
   
    if ((!feedbackform.a12_I_was_satisfied_with_the_selection_of_music[0].checked) && (!feedbackform.a12_I_was_satisfied_with_the_selection_of_music[1].checked) && 
(!feedbackform.a12_I_was_satisfied_with_the_selection_of_music[2].checked) && 
(!feedbackform.a12_I_was_satisfied_with_the_selection_of_music[3].checked) && 
(!feedbackform.a12_I_was_satisfied_with_the_selection_of_music[4].checked) )
     {
      alert("Please let us know how satisfied you were with the music selections (question #12).");
      return false;
     }

<!-- Ensure user selects answer to question 13 -->
   
    if ((!feedbackform.a13_I_was_satisfied_with_the_selection_of_games[0].checked) && (!feedbackform.a13_I_was_satisfied_with_the_selection_of_games[1].checked) && 
(!feedbackform.a13_I_was_satisfied_with_the_selection_of_games[2].checked) && 
(!feedbackform.a13_I_was_satisfied_with_the_selection_of_games[3].checked) && 
(!feedbackform.a13_I_was_satisfied_with_the_selection_of_games[4].checked) )
     {
      alert("Please let us know how satisfied you were with the selection of games (question #13).");
      return false;
     }

<!-- Ensure user selects answer to question 14 -->
   
    if ((!feedbackform.a14_I_would_recommend_Shoeless_Joes_to_others[0].checked) && (!feedbackform.a14_I_would_recommend_Shoeless_Joes_to_others[1].checked) && 
(!feedbackform.a14_I_would_recommend_Shoeless_Joes_to_others[2].checked) && 
(!feedbackform.a14_I_would_recommend_Shoeless_Joes_to_others[3].checked) && 
(!feedbackform.a14_I_would_recommend_Shoeless_Joes_to_others[4].checked) )
     {
      alert("Please let us know how agreeable you would be to recommend Shoeless Joe's to others (question #14).");
      return false;
     }

<!-- Ensure user selects answer to question 15 -->
   
    if ((!feedbackform.a15_It_is_likely_that_I_will_return_to_Shoeless_Joes[0].checked) && (!feedbackform.a15_It_is_likely_that_I_will_return_to_Shoeless_Joes[1].checked) && 
(!feedbackform.a15_It_is_likely_that_I_will_return_to_Shoeless_Joes[2].checked) && 
(!feedbackform.a15_It_is_likely_that_I_will_return_to_Shoeless_Joes[3].checked) && 
(!feedbackform.a15_It_is_likely_that_I_will_return_to_Shoeless_Joes[4].checked) )
     {
      alert("Please let us know how agreeable you are to return to Shoeless Joe's (question #15).");
      return false;
     }

<!-- Ensure user enters a first name -->
    if (feedbackform.FirstName.value == "")
     {
      alert("Please enter your first name");
      feedbackform.FirstName.focus();
      return false;
     }

<!-- Check the email address -->
if (BadEmail(feedbackform.EmailAddress.value))
	{
	 alert("Please check your Email address. It appears to be incorrect.");
	 feedbackform.EmailAddress.focus();

         <!-- this "selects" (highlights) the contents -->
          feedbackform.EmailAddress.select();          
	  return false;
	}

   return true;
}

<!-- This function returns true if the date of visit is bad. -->
<!-- Returns false if the date of visit appears okay. -->

function BadVisit(DateofVisit)
{
	<!-- blank is bad -->
	if (DateofVisit == "") return true;

	<!-- need one slash, and it can't be in first spot (0) -->
	var a = DateofVisit.indexOf("/");
	if (a < 1) return true;

	<!-- must have 2 slashes -->
	if (DateofVisit.indexOf("/") != 2) return true;

	<!-- need a slash, and at least 2 characters after -->
	p = DateofVisit.indexOf("/",a+2);
	if (p == -1 || p > DateofVisit.length-3) return true;

	<!-- these characters can't be anywhere in the date -->
	var bad = " @,;:";

        <!-- re-use "a" as counter -->
	for (a=0; a<5; a++)  
	{

        <!-- re-use "p" for one bad character -->
	  p = bad.charAt(a);
	  if (DateofVisit.indexOf(p) > -1) return true;
	}

	<!-- if we get here, it appears okay... so "Bad" is false: -->
	return false;
}

<!-- This function returns true if the email address is bad. -->
<!-- Returns false if email address appears okay. -->

function BadEmail(EmailAddress)
{
	<!-- blank is bad -->
	<!-- if (EmailAddress == "") return true; -->

	<!-- blank is ok -->
	if (EmailAddress == "") return false;

	<!-- need one @, and it can't be in first spot (0) -->
	var a = EmailAddress.indexOf("@");
	if (a < 1) return true;

	<!-- can't have 2 @'s -->
	if (EmailAddress.indexOf("@",a+1) != -1) return true;

	<!-- need a period, and at least 2 characters after -->
	p = EmailAddress.indexOf(".",a+2);
	if (p == -1 || p > EmailAddress.length-3) return true;

	<!-- these characters can't be anywhere in an address -->
	var bad = " /,;:";

        <!-- re-use "a" as counter -->
	for (a=0; a<5; a++)  
	{

        <!-- re-use "p" for one bad character -->
	  p = bad.charAt(a);
	  if (EmailAddress.indexOf(p) > -1) return true;
	}

	<!-- if we get here, it appears okay... so "Bad" is false: -->
	return false;
}
