//<![CDATA[
<!-- Included from inforequest.php via PHP variable $JScriptLocal and Header1.php -->
<!-- Copyright© Adam's Computing® . Web designer: Hal Adam -->
<!-- NO, this web page did NOT evolve over eons of time from -->
<!-- some suposed primodial alphabet soup, it took a designer.  :) -->
<!-- Comment out for Browsers which do NOT support Scripting
// Define some global variables used in various functions.
var tableStart = "<table class='ErrorBox'><tr><td>";
var tableEnd ="</td></tr></table>"; 

// function to reset the value of all form elements to blanks or some initial value
function Reset() 
{
 // Could also be done by document.forms[x].elements[y].value = ""; x = 0, y = 0 to 5 
 // the form name is Form1 and the children objects are the names of the input fields.
 // The selectedIndex property is the index of the selected item from the option array. 
 // Reset error message field 
 document.all.ErrorMsg.innerHTML = "";
 document.Form1.Title.selectedIndex = 0;
 document.Form1.FirstName.value = "";
 document.Form1.LastName.value = "";
 document.Form1.Address.value = "";
 document.Form1.City.value = "";
 document.Form1.Province.selectedIndex = 1; // BC is 2nd Province.
 document.Form1.Country.selectedIndex = 37; // Canada is 38th country
 document.Form1.PostalCode.value = "";
 // display Postal Code formating for Canada
 document.all.Format.innerHTML = "LnL nLn L=Letter n=number";
 document.Form1.Title.focus();
}

// I don't verify the Title since it is assumed it is entered correctly
// via a dropdown list and is not dependent on any other input field.

// Function to be executed from onsubmit event.  
function submitForm() 
{
 // If input fields all verify as OK (true or 1 is set) 
 if ((verifyFirstName()) && (verifyLastName()) && (verifyAddress())
  && (verifyCity()) && (verifyProvince()) && (verifyPostalCode()) )
    // then if 
    if (confirm("You're about to e-mail the form.\n\nClick on OK to E-mail.\n\nClick on CANCEL to stop the E-mail."))
       { 
        alert("Your submission will now be E-mailed to :\n\n steve@ShawniganAlliance.bc.ca\n\nThank you!");
        return true;
        }
    else
        {
         alert("You have chosen to cancel the E-mailing.");
         return false;       
         }
// else false or 0 is set
 else return false;
}

// Verify FirstName input field .
function verifyFirstName()
{
 document.all.ErrorMsg.innerHTML = ""; /* reset any previous Error msg */
 // Get First Name entered.
 var firstName = document.Form1.FirstName.value;
 var firstNameLength = firstName.length;
 if (firstName == "")
    {
     document.all.ErrorMsg.innerHTML = tableStart + "The First Name is null.&nbsp;&nbsp;Please re-enter your First Name." + tableEnd;
     // Put focus back onto this form element (ie position cursor here)
     document.Form1.FirstName.focus();
     return false;
     }
  // check for Minimum length of first name (ie. Chinese NG )
  if (firstNameLength < 2)
     {
      document.all.ErrorMsg.innerHTML = tableStart + "The First Name entered is " + firstNameLength + " characters long.<br />Minumum First Name length is 2 characters long.<br />Please re-enter your First Name." + tableEnd;
	// execute select method to select the text entered into the FirstName field.
      document.Form1.FirstName.select();
      // execute focus method to point form cursor to FirstName input field
      document.Form1.FirstName.focus();
      return false;
      }
  // Set letter counter
  var letterCount = 0;
  // Check each character to make sure it is a to z and A to Z and NOT blank.
  for (var i = 0; i < firstName.length; i++) 
  {
  var ch = firstName.substring(i, i + 1);
  if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ') 
     {
      document.all.ErrorMsg.innerHTML = tableStart + "The First Name field only accepts letters and spaces.<br />Please re-enter your First Name." + tableEnd;
      // execute select method to select the text entered into the FirstName field.
      document.Form1.FirstName.select();
      // execute focus method to point form cursor to FirstName input field
      document.Form1.FirstName.focus();
      return false;
      }
  // Check for a letter.
  if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch))) {}
  else {
        letterCount = letterCount + 1;
       }
  } // end for loop
// make sure at least 2 letters where found.
if (letterCount < 2)
   {
    document.all.ErrorMsg.innerHTML = tableStart + letterCount + " letters have been found.<br />The First Name must be at least 2 letters long.<br />Please re-enter your First Name." + tableEnd;
    // execute select method to select the text entered into the name field.
    document.Form1.FirstName.select();
    // execute focus method to point form cursor to FirstName input field
    document.Form1.FirstName.focus();
    return false;
    }
return true;
} // end verifyFirstName function

// Verify LastName input field .
function verifyLastName()
{
  // Get Last name entered.
  var lastName = document.Form1.LastName.value;
  var lastNameLength = lastName.length;
  // check for null lastName
  if (lastName == "")
     {
      document.all.ErrorMsg.innerHTML = tableStart + "The Last Name is null.<br />Please re-enter your Last Name." + tableEnd;
      // execute focus method to point form cursor to LastName input field
      document.Form1.LastName.focus();
      return false;
      }
  // check for Minimum length of last name (ie. Chinese NG )
  if (lastNameLength < 2)
     {
      document.all.ErrorMsg.innerHTML = tableStart + "The Last Name entered is " + lastNameLength + " characters long.<br />Minumum last name length is 2 characters long.<br />Please re-enter your Last Name" + tableEnd;
	// execute select method to select the text entered into the Last Name field.
      document.Form1.LastName.select();
      // execute focus method to point form cursor to LastName input field
      document.Form1.LastName.focus();
      return false;
      }
  // Set letter counter
  var letterCount = 0;
  for (var i = 0; i < lastNameLength; i++) 
  {
   var ch = lastName.substring(i, i + 1);
   // Check each character to make sure it is a to z and A to Z and NOT blank.
   if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ') 
      {
       document.all.ErrorMsg.innerHTML = tableStart + "The Last Name field only accepts letters and spaces.<br />Please re-enter your Last Name." + tableEnd;
       // execute select method to select the text entered into the name field.
       document.Form1.LastName.select();
       // execute focus method to point form cursor to LastName input field
       document.Form1.LastName.focus();
       return false;
       }
    // Check for a letter.
    if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch))) {}
    else {
         letterCount = letterCount + 1;
         }
      } // end for loop
// make sure at least 2 letters where found.
if (letterCount < 2)
   {
    document.all.ErrorMsg.innerHTML = tableStart + letterCount + " letters have been found.<br />The Last Name must be at least 2 letters long.<br />Please re-enter your Last Name." + tableEnd;
    // execute select method to select the text entered into the name field.
    document.Form1.LastName.select();
    // execute focus method to point form cursor to LastName input field
    document.Form1.LastName.focus();
    return false;
    }
return true;
} // end verifyLastName function

// Verify Address input field .
function verifyAddress()
{
  // Get Address entered.
  var address = document.Form1.Address.value;
  var addressLength = address.length;
  if (address == "")
     {
      document.all.ErrorMsg.innerHTML = tableStart + "The Address is null.<br />Please re-enter your Address." + tableEnd;
      // execute focus method to point form cursor to address input field
      document.Form1.Address.focus();
      return false;
      }
// Check each character to make sure it is a-z, A-Z, and 0-9 and NOT blank.
for (var i = 0; i < addressLength; i++) 
 {
 var ch = address.substring(i, i + 1);
 if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch < "/" || "9" < ch))
    && ch != ' ') 
    {
     document.all.ErrorMsg.innerHTML = tableStart + "The Address field only accepts letters, numbers & spaces.<br />Please re-enter your Address." + tableEnd;
     // execute select method to select the text entered into the address field.
     document.Form1.Address.select();
     // execute focus method to point form cursor to address input field
     document.Form1.Address.focus();
     return false;
     }
 }
return true;
}

// Verify City input field .
function verifyCity()
{
  // Get City entered.
  var city = document.Form1.City.value;
  var cityLength = city.length;
  if (city == "")
     {
      document.all.ErrorMsg.innerHTML = tableStart + "The City entered is null.<br />Please re-enter your City." + tableEnd;
	// execute focus method to point form cursor to city input field
      document.Form1.City.focus();
      return false;
      }
// Check each character to make sure it is a to z and A to Z and NOT blank.
for (var i = 0; i < cityLength; i++) 
 {
 var ch = city.substring(i, i + 1);
 if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ') 
    {
     document.all.ErrorMsg.innerHTML = tableStart + "The City field only accepts letters &amp; spaces.<br />Please re-enter your City." + tableEnd;
     // execute select method to select the text entered into the city field.
     document.Form1.City.select();
     // execute focus method to point form cursor to city input field
     document.Form1.City.focus();
     return false;
     }
 } // end for loop
return true;
} // end verifyCity function 

// Verify Province pull down selection against country selected.
// Obviously different countries have different provinces or states.
function verifyProvince()
{
 var selectedCountry = document.Form1.Country.selectedIndex;
// Get the selected country from the options array.
 var country = document.Form1.Country.options[selectedCountry].text;
// get number of selected province from pull down list
 var selectedProvince = document.Form1.Province.selectedIndex;
// Get the selected province from the options array.
 var province = document.Form1.Province.options[selectedProvince].text;

switch (country)
  {
  case "Canada": 
    // If Country selected is Canada, make sure one of provinces selected is Canada's
  //make sure selected province is 0 to 12 in province options array
  if ((selectedProvince >-1) && (selectedProvince < 13))
  return true;
  else {
	  document.all.ErrorMsg.innerHTML = tableStart + "The selected country is " + country + ".<br />The province selected, " + province + ", is not a province of " + country + ".<br />Please re-select your province." + tableEnd;
        document.Form1.Province.focus();
        return false;
        }
   break;

   case "United States": 
  // If Country selected is United States, make sure one of states selected is UAS's
  //make sure selected state is 13 to 235 in province options array
  if ((selectedProvince > 12) && (selectedProvince < 236))
  return true;
  else {
	  document.all.ErrorMsg.innerHTML = tableStart + "The selected country is " + country + ".<br />The state selected, " + province + ", is not a state of the " + country + ".<br />Please re-select your state." + tableEnd;
        document.Form1.Province.focus();
        return false;
        }
   break;
 
   default:
   document.all.ErrorMsg.innerHTML = tableStart + "No Checking is available for " + country + "'s Province, " + province + ".<br />The province will be E-mailed without having verified it's authenticty" + tableEnd;
   return true;
  }; // end switch
} // end function verifyProvince

// Verify PostalCode input field .
function verifyPostalCode()
{
 var j = 0;
 // Get PostalCode entered.
 var postalCode = document.Form1.PostalCode.value;
 var postalCodeLength = postalCode.length;
 if (postalCode == "") // if postalCode is null
    {
     document.all.ErrorMsg.innerHTML = tableStart + "The Postal Code is null.<br />Please enter your Postal Code." + tableEnd;
     // Put focus back onto this form element (ie position cursor here)
     document.Form1.PostalCode.focus();
     return false;
     }
var selectedCountry = document.Form1.Country.selectedIndex;
// Get the selected country from the options array.
var country = document.Form1.Country.options[selectedCountry].text;
switch (country)
  {
   case "Canada":
   // display formating for Canada
   document.all.Format.innerHTML = "LnL nLn L=Letter n=number";
   // Check Canadian Postal Code 
        if ((postalCodeLength != 7 )) // Length of Postal Code MUST be 7 digits
           {
            document.all.ErrorMsg.innerHTML = tableStart + "Length of Postal Code must be 7 characters long." + "<br />Length of Postal code entered was: " + postalCodeLength + tableEnd;
            document.Form1.PostalCode.select();
            document.Form1.PostalCode.focus();
            return false;
            }
        // loop through postalCode 
        for (var i = 0; i < postalCodeLength; i++)
            {
            char = "" + postalCode.substring(i, i+1); // get character to examine
            // Check these positions in postalCode to see if they are letters.
            if ((i == 0) || (i ==2) || (i == 5)) // if letter position 
               {// then if char is not a letter 
               if (((char < "a" || "z" < char) && (char < "A" || "Z" < char))) 
                  {// then we have an invalid Postal Code 
                  j = i + 1;
                  document.all.ErrorMsg.innerHTML = tableStart +  char + " at position " + j + " is not a letter.<br />Please re-enter your Postal Code in the form<br />LnL nLn were L is a Letter and n is a number." + tableEnd;
                  // execute select method to select the text entered into the name field.
                  // document.Form1.PostalCode.select();
                  // execute focus method to point form cursor to name input field
                  document.Form1.PostalCode.focus();
                  return false;
                  } // end char is not a letter code.
               } // end char is in letter position code.
            if ((i == 1) || (i == 4) || (i == 6)) // if number position 
               {// then if char is not a number
               if (char < "0" || "9" < char)
                  {// then we have an invalid Postal Code
                  j = i + 1;
                  document.all.ErrorMsg.innerHTML = tableStart + char + " at position " + j + " is not a number.<br />Please re-enter your Postal Code in the form<br /> LnL nLn were L is a Letter and n is a number." + tableEnd;
                  // execute select method to select the text entered into the name field.
                  document.Form1.PostalCode.select();
                  // execute focus method to point form cursor to name input field
                  document.Form1.PostalCode.focus();
                  return false;
                  } 
               } // end char is not a number position  
            }  // end for loop
   return true;
   break;

  case "United States": 
   // display formating for USA    
   document.all.Format.innerHTML = "nnnnn OR nnnnn-nnnn n=number";
    // Check US Zip Code.
     var valid = "0123456789-";
     var hyphencount = 0;
     if (postalCodeLength != 5 && postalCodeLength != 10)
        {document.all.ErrorMsg.innerHTML = tableStart + "Please enter your 5 digit or 5 digit+4 zip code." + tableEnd;
         document.Form1.PostalCode.select();
         document.Form1.PostalCode.focus();
         return false;
        }
     for (var i = 0; i < postalCodeLength; i++)
         {
          temp = "" + postalCode.substring(i, i+1);
          if (temp == "-") hyphencount++;
          if (valid.indexOf(temp) == "-1")
             {
              document.all.ErrorMsg.innerHTML = tableStart + "Invalid characters in your zip code.<br />Please re-enter your postal code." + tableEnd;
              document.Form1.PostalCode.select();
              document.Form1.PostalCode.focus();
              return false;
              }
          if ((hyphencount > 1) || ((postalCodeLength == 10) 
          && "" + postalCode.charAt(5) != "-"))
             {
              document.all.ErrorMsg.innerHTML = tableStart + "The hyphen character should be used with a properly" + 
              "<br />formatted 5 + 4 digit zip code, like '12345-6789'." +
              "<br />Please re-enter your zip code." + tableEnd;
              document.Form1.PostalCode.select();
              document.Form1.PostalCode.focus();
              return false;
              }
          } // end for loop
      return true;
   break;
      default:
      // display warning that no format available    
      document.all.Format.innerHTML = "Postal Code Format unknown";
      document.all.ErrorMsg.innerHTML = tableStart + "No Checking is available for " + country + "'s Postal Code, " + postalCode + ".<br />Your Postal Code will be E-mailed without having verified it's authenticty" + tableEnd;
      return true;
  }  // end switch
}    // end function verifyPostalCode
// End of JScript commenting for Non-Scripting enabled Browsers -->
//]]>
