var arrProvValue = new Array();
var arrProvItem = new Array();
var arrProvGroup = new Array();

var arrCityValue = new Array();
var arrCityItem = new Array();
var arrCityItemGroup = new Array();


  
    arrProvValue[1] = "";
    arrProvItem[1] = "<Select Province>";
    arrProvGroup[1] = "CAN";
  
  
  
    arrProvValue[2] = "2";
    arrProvItem[2] = "Alberta";
    arrProvGroup[2] = "CAN";
    


       arrCityValue[1] = "";
       arrCityItem[1] = "<Select Closest City>";
       arrCityItemGroup[1] = "";    

         arrCityValue[2] = "3";
         arrCityItem[2] = "Calgary";
         arrCityItemGroup[2] = "2";
         
         arrCityValue[3] = "8";
         arrCityItem[3] = "Edmonton";
         arrCityItemGroup[3] = "2";
         
         arrCityValue[4] = "111";
         arrCityItem[4] = "Grande Prairie";
         arrCityItemGroup[4] = "2";
         
         arrCityValue[5] = "107";
         arrCityItem[5] = "Lethbridge";
         arrCityItemGroup[5] = "2";
         
         arrCityValue[6] = "108";
         arrCityItem[6] = "Red Deer";
         arrCityItemGroup[6] = "2";
         
  
    arrProvValue[3] = "3";
    arrProvItem[3] = "British Columbia";
    arrProvGroup[3] = "CAN";
    


       arrCityValue[1] = "";
       arrCityItem[1] = "<Select Closest City>";
       arrCityItemGroup[1] = "";    

         arrCityValue[7] = "84";
         arrCityItem[7] = "Kamloops";
         arrCityItemGroup[7] = "3";
         
         arrCityValue[8] = "85";
         arrCityItem[8] = "Kelowna";
         arrCityItemGroup[8] = "3";
         
         arrCityValue[9] = "83";
         arrCityItem[9] = "Prince George";
         arrCityItemGroup[9] = "3";
         
         arrCityValue[10] = "5";
         arrCityItem[10] = "Vancouver";
         arrCityItemGroup[10] = "3";
         
         arrCityValue[11] = "6";
         arrCityItem[11] = "Victoria";
         arrCityItemGroup[11] = "3";
         
  
    arrProvValue[4] = "4";
    arrProvItem[4] = "Manitoba";
    arrProvGroup[4] = "CAN";
    


       arrCityValue[1] = "";
       arrCityItem[1] = "<Select Closest City>";
       arrCityItemGroup[1] = "";    

         arrCityValue[12] = "9";
         arrCityItem[12] = "Brandon";
         arrCityItemGroup[12] = "4";
         
         arrCityValue[13] = "72";
         arrCityItem[13] = "Churchill";
         arrCityItemGroup[13] = "4";
         
         arrCityValue[14] = "10";
         arrCityItem[14] = "Winnipeg";
         arrCityItemGroup[14] = "4";
         
  
    arrProvValue[5] = "5";
    arrProvItem[5] = "New Brunswick";
    arrProvGroup[5] = "CAN";
    


       arrCityValue[1] = "";
       arrCityItem[1] = "<Select Closest City>";
       arrCityItemGroup[1] = "";    

         arrCityValue[15] = "15";
         arrCityItem[15] = "Fredericton";
         arrCityItemGroup[15] = "5";
         
         arrCityValue[16] = "14";
         arrCityItem[16] = "Moncton";
         arrCityItemGroup[16] = "5";
         
         arrCityValue[17] = "27";
         arrCityItem[17] = "Saint John";
         arrCityItemGroup[17] = "5";
         
  
    arrProvValue[6] = "6";
    arrProvItem[6] = "Newfoundland and Labrador";
    arrProvGroup[6] = "CAN";
    


       arrCityValue[1] = "";
       arrCityItem[1] = "<Select Closest City>";
       arrCityItemGroup[1] = "";    

         arrCityValue[18] = "22";
         arrCityItem[18] = "Corner Brook";
         arrCityItemGroup[18] = "6";
         
         arrCityValue[19] = "20";
         arrCityItem[19] = "Labrador City";
         arrCityItemGroup[19] = "6";
         
         arrCityValue[20] = "19";
         arrCityItem[20] = "St. John's";
         arrCityItemGroup[20] = "6";
         
  
    arrProvValue[7] = "7";
    arrProvItem[7] = "Northwest Territories";
    arrProvGroup[7] = "CAN";
    


       arrCityValue[1] = "";
       arrCityItem[1] = "<Select Closest City>";
       arrCityItemGroup[1] = "";    

         arrCityValue[21] = "109";
         arrCityItem[21] = "Yellowknife";
         arrCityItemGroup[21] = "7";
         
  
    arrProvValue[8] = "8";
    arrProvItem[8] = "Nova Scotia";
    arrProvGroup[8] = "CAN";
    


       arrCityValue[1] = "";
       arrCityItem[1] = "<Select Closest City>";
       arrCityItemGroup[1] = "";    

         arrCityValue[22] = "16";
         arrCityItem[22] = "Halifax";
         arrCityItemGroup[22] = "8";
         
         arrCityValue[23] = "18";
         arrCityItem[23] = "Sydney";
         arrCityItemGroup[23] = "8";
         
  
    arrProvValue[9] = "13";
    arrProvItem[9] = "Nunavut";
    arrProvGroup[9] = "CAN";
    


       arrCityValue[1] = "";
       arrCityItem[1] = "<Select Closest City>";
       arrCityItemGroup[1] = "";    

         arrCityValue[24] = "106";
         arrCityItem[24] = "Iqaluit";
         arrCityItemGroup[24] = "13";
         
  
    arrProvValue[10] = "1";
    arrProvItem[10] = "Ontario";
    arrProvGroup[10] = "CAN";
    


       arrCityValue[1] = "";
       arrCityItem[1] = "<Select Closest City>";
       arrCityItemGroup[1] = "";    

         arrCityValue[25] = "47";
         arrCityItem[25] = "Hamilton";
         arrCityItemGroup[25] = "1";
         
         arrCityValue[26] = "55";
         arrCityItem[26] = "Kingston";
         arrCityItemGroup[26] = "1";
         
         arrCityValue[27] = "49";
         arrCityItem[27] = "Kitchener-Waterloo";
         arrCityItemGroup[27] = "1";
         
         arrCityValue[28] = "45";
         arrCityItem[28] = "London";
         arrCityItemGroup[28] = "1";
         
         arrCityValue[29] = "48";
         arrCityItem[29] = "Niagara Falls";
         arrCityItemGroup[29] = "1";
         
         arrCityValue[30] = "1";
         arrCityItem[30] = "Ottawa";
         arrCityItemGroup[30] = "1";
         
         arrCityValue[31] = "63";
         arrCityItem[31] = "Sault-Ste. Marie";
         arrCityItemGroup[31] = "1";
         
         arrCityValue[32] = "62";
         arrCityItem[32] = "Sudbury";
         arrCityItemGroup[32] = "1";
         
         arrCityValue[33] = "67";
         arrCityItem[33] = "Thunder Bay";
         arrCityItemGroup[33] = "1";
         
         arrCityValue[34] = "2";
         arrCityItem[34] = "Toronto";
         arrCityItemGroup[34] = "1";
         
         arrCityValue[35] = "46";
         arrCityItem[35] = "Windsor";
         arrCityItemGroup[35] = "1";
         
  
    arrProvValue[11] = "9";
    arrProvItem[11] = "Prince Edward Island";
    arrProvGroup[11] = "CAN";
    


       arrCityValue[1] = "";
       arrCityItem[1] = "<Select Closest City>";
       arrCityItemGroup[1] = "";    

         arrCityValue[36] = "11";
         arrCityItem[36] = "Charlottetown";
         arrCityItemGroup[36] = "9";
         
         arrCityValue[37] = "24";
         arrCityItem[37] = "Summerside";
         arrCityItemGroup[37] = "9";
         
  
    arrProvValue[12] = "10";
    arrProvItem[12] = "Quebec";
    arrProvGroup[12] = "CAN";
    


       arrCityValue[1] = "";
       arrCityItem[1] = "<Select Closest City>";
       arrCityItemGroup[1] = "";    

         arrCityValue[38] = "40";
         arrCityItem[38] = "Chibougamau";
         arrCityItemGroup[38] = "10";
         
         arrCityValue[39] = "38";
         arrCityItem[39] = "Gatineau";
         arrCityItemGroup[39] = "10";
         
         arrCityValue[40] = "12";
         arrCityItem[40] = "Montreal";
         arrCityItemGroup[40] = "10";
         
         arrCityValue[41] = "13";
         arrCityItem[41] = "Quebec City";
         arrCityItemGroup[41] = "10";
         
         arrCityValue[42] = "113";
         arrCityItem[42] = "Rimouski";
         arrCityItemGroup[42] = "10";
         
         arrCityValue[43] = "35";
         arrCityItem[43] = "Saguenay";
         arrCityItemGroup[43] = "10";
         
         arrCityValue[44] = "112";
         arrCityItem[44] = "Sept-?les";
         arrCityItemGroup[44] = "10";
         
         arrCityValue[45] = "39";
         arrCityItem[45] = "Sherbrooke";
         arrCityItemGroup[45] = "10";
         
         arrCityValue[46] = "41";
         arrCityItem[46] = "Trois-Rivi?res";
         arrCityItemGroup[46] = "10";
         
         arrCityValue[47] = "37";
         arrCityItem[47] = "Val d'Or";
         arrCityItemGroup[47] = "10";
         
  
    arrProvValue[13] = "11";
    arrProvItem[13] = "Saskatchewan";
    arrProvGroup[13] = "CAN";
    


       arrCityValue[1] = "";
       arrCityItem[1] = "<Select Closest City>";
       arrCityItemGroup[1] = "";    

         arrCityValue[48] = "74";
         arrCityItem[48] = "Regina";
         arrCityItemGroup[48] = "11";
         
         arrCityValue[49] = "75";
         arrCityItem[49] = "Saskatoon";
         arrCityItemGroup[49] = "11";
         
  
    arrProvValue[14] = "12";
    arrProvItem[14] = "Yukon";
    arrProvGroup[14] = "CAN";
    


       arrCityValue[1] = "";
       arrCityItem[1] = "<Select Closest City>";
       arrCityItemGroup[1] = "";    

         arrCityValue[50] = "110";
         arrCityItem[50] = "Whitehorse";
         arrCityItemGroup[50] = "12";
         


function selectChange(control, controlToPopulate, ItemArrayValue, ItemArray, GroupArray)
{
  var myEle;
  var x ;
  // Empty the second drop down box of any choices

  var lenObj = controlToPopulate.options.length +1 ;
  for (q=0;q<=lenObj;q++) 
      controlToPopulate.options[0]=null;
  
      
/*  for (var q=controlToPopulate.options.length;q>=0;q--)
      controlToPopulate.options[q]=null;
*/

  if (control.name == "country") {
    if (control.value != "CAN") //Remove Province DropDown
    {
      // Empty the province dropdown if not Canada
      for (var q=document.frmSubscribe.province.options.length;q>=0;q--) document.frmSubscribe.province.options[q] = null;
      document.frmSubscribe.province.disabled = true;
    }
    else
    {
      document.frmSubscribe.province.disabled = false;
    }
 }
  //controlToPopulate.add(myEle) ;
  // Now loop through the array of individual items
  // Any containing the same child id are added to
  // the second dropdown box
  for ( x = 0 ; x < ItemArray.length  ; x++ )
    {
      if ( GroupArray[x] == control.value && GroupArray[x] != "" && GroupArray[x] != null )
        {
          myEle = document.createElement("option") ;
          myEle.value = ItemArrayValue[x] ;
          myEle.text = ItemArray[x] ;
         
           controlToPopulate.add(myEle);
         
          if (myEle.value == "")
            myEle.selected = true;
        }
    }
}



function isValidEmail(strValue)
{
//This function will 
  var regExp = /^(.+@[^\.].*\.[a-z]{2,})(;.+@[^\.].*\.[a-z]{2,})*$/
     // set the default return value
     var blnResult = true;
     var arrMatch = strValue.match(regExp);

     if (arrMatch == null)
          blnResult = false;

     return (blnResult);
}



function ValidateForm(form)
{

if ( (trimAll(form.from.value)) == "")
  {
    alert("Please insert an email address");
    form.from.focus();
    return false;
  }

    //Validate the email address
    //if (!isValidEmail(form.from.value)) {
    if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/.test(form.from.value)){
      alert("Please insert a valid email address.");
      form.from.focus();
      return false;
    }
    
    if (form.phone.value.length > 0) {
  var temp_phone = form.phone.value;
  while (temp_phone.indexOf("(") >= 0) temp_phone = temp_phone.replace("(", "");
  while (temp_phone.indexOf(")") >= 0) temp_phone = temp_phone.replace(")", "");
  while (temp_phone.indexOf(" ") >= 0) temp_phone = temp_phone.replace(" ", "");
  while (temp_phone.indexOf("-") >= 0) temp_phone = temp_phone.replace("-", "");
  
  if (isNaN(temp_phone))
  {
    alert("Telephone Number must contain all numbers");
    form.phone.focus();
    return false;
  }

  if (temp_phone.length != 10 && form.country.value == "CAN")
  {
    alert("Please insert a ten-digit telephone number.");
    form.phone.focus();
    return false;
  }
}
//Province
   if (form.Subject.value == "" && form.country.value == "CAN")
   {
   alert("Please select a subject.");
   form.Subject.focus();
   return false;
   }
if ( (trimAll(form.firstname.value)) == "")
  {
    alert("Please enter your first name");
    form.firstname.focus();
    return false;
  }
if ( (trimAll(form.LastName.value)) == "")
  {
    alert("Please enter your last name");
    form.LastName.focus();
    return false;
  }
  //Phone
  if (form.phone.value == "" && form.country.value == "CAN")
  {
    alert("Please insert a ten-digit telephone number.");
    form.phone.focus();
    return false;
  }

   //Province
   if (form.province.value == "" && form.country.value == "CAN")
   {
   alert("Please select a province. If the Province drop down menu is not visible then please click refresh.");
   form.province.focus();
   return false;
   }
function isPostalCode(entry)
{
  strlen = entry.length; 
  if (strlen != 6) {return false;}
  entry=entry.toUpperCase();        // in case of lowercase characters
  // Check for legal characters in string - note index starts at zero
  if ('ABCEGHJKLMNPRSTVWXYZ'.indexOf(entry.charAt(0)) < 0) {return false;}
  if ('0123456789'.indexOf(entry.charAt(1)) < 0) {return false;}
  if ('ABCEGHJKLMNPRSTVWXYZ'.indexOf(entry.charAt(2)) < 0) {return false;}
  if ('0123456789'.indexOf(entry.charAt(3)) < 0) {return false;}
  if ('ABCEGHJKLMNPRSTVWXYZ'.indexOf(entry.charAt(4)) < 0) {return false;}
  if ('0123456789'.indexOf(entry.charAt(5)) < 0) {return false;}
  return true; 
}
  //Postal Code
  if (form.postalcode.value == "" && form.country.value == "CAN")
  {
    alert("Please insert a postal code (Format: X9X 9X9)");
    form.postalcode.focus();
    return false;
  }

  //Postal Code Validation
  var temp_postal = form.postalcode.value.replace(/ /g,"");
  
  if (!isPostalCode(temp_postal) && form.country.value == "CAN")
  {
    alert("Please insert a valid postal code (Format: X9X 9X9)");
    form.postalcode.focus();
    return false;
  }

  
  return true;
}//end ValidateForm

function SelectAll(selectall, fields)
{
  if (selectall.checked) {
  for (i = 0; i < fields.length; i++)
    fields[i].checked = true;
  }
  else {
  for (i = 0; i < fields.length; i++)
    fields[i].checked = false;
 }

}  
//Javascript Trim equivalent
function trimAll(sString) 
{
   while (sString.substring(0,1) == ' ')
   {
      sString = sString.substring(1, sString.length);
   }
   while (sString.substring(sString.length-1, sString.length) == ' ')
   {
      sString = sString.substring(0,sString.length-1);
   }
   return sString;
}



