function jssetchain(jschain) {
   document.srchForm.chain.options.selectedIndex=parseInt(jschain);
   location="#form_start";
   return;
}

function jsfixedstate_chk(form_flds)  {
   var fname = form_flds.placename.value;
   var tblnks = "                    ";
   if (fname == tblnks.substring(0,fname.length))  {
      alert("Please enter a Destination");
      return false;
   }

   return true;
}

function jsform_chk(form_flds)  {
   var fname = form_flds.placename.value;
   var tblnks = "                    ";
   cntry_index = form_flds.country.options.selectedIndex;
   var cntry_val = form_flds.country.options[cntry_index].value;
   var cntry_txt = form_flds.country.options[cntry_index].text;
   state_index = form_flds.state_country.options.selectedIndex;
   var state_txt = form_flds.state_country.options[state_index].text;
   type_index = form_flds.placetype.options.selectedIndex;
   var placetype_val = form_flds.placetype.options[type_index].value;
   if (fname == tblnks.substring(0,fname.length))  {
      //Destination is required
      alert("Please enter a Destination");
      return false;
   }
   else if (placetype_val == "postalcode") {
      //make sure country is US or CA for postal code search
      //and a zip code has been entered
      if ((form_flds.placename.value == "") || (form_flds.placename.value == null)) {
         alert("Please enter a valid postal code.");
	 return false;
      }
      else if ((cntry_index == 0) || ((cntry_val != "US") && (cntry_val != "CA")))   {
	 alert("Invalid country selected for Postal Code search. \n" +
	     "Please select either 'United States' or 'Canada' ");
	 return false;
      }
   }
   else if (state_index != 0 && cntry_index != 0) {
      // make sure state/country combo is valid

      if (cntry_val == "US")  {
	 if (state_txt.indexOf("Canada") > 0 || state_txt.indexOf("Australia") >= 0 || state_txt.indexOf("United Kingdom") > 0) {
	    alert("Invalid state selected for United States");
	    return false;
	 }
      }
      else if (cntry_val == "CA")  {
	 if (state_txt.indexOf("Canada") < 0)  {
	    alert("Invalid province selected for Canada");
	    return false;
	 }
      }
      else if (cntry_val == "GB")  {
	 if (state_txt.indexOf("United Kingdom") < 0)  {
	    alert("Invalid state/province selected for United Kingdom");
	    return false;
	 }
      }
      else if (cntry_val == "AU")  {
	 if (state_txt.indexOf("Australia") < 0)  {
	    alert("Invalid state selected for Australia");
	    return false;
	 }
      }
      else  {
	 alert("Invalid state/province selected for " + cntry_txt);
	 return false;
      }
   }

   return true;
}

function basicStateVerify(given_state, given_country, form_flds) {
   /*  Country WAS selected */
   var ix = eval("form_flds." + given_country + ".options.selectedIndex");
   var cntry_val = eval("form_flds." + given_country + ".options[eval(ix)].value");
   var cntry_txt = eval("form_flds." + given_country + ".options[eval(ix)].text");
   var state_selectedIndex = eval("form_flds." + given_state + ".options.selectedIndex");

   if (state_selectedIndex == "")  {
      /*  State/Province = (none)  */
      if (cntry_val == "US" || cntry_val == "CA" || cntry_val == "GB" || cntry_val == "AU")  {
	 alert("Please select a state/province for " + cntry_txt);
	 return false;
      }
   }
   else  {
      /*  Country WAS selected AND State WAS selected  */
      ix = eval("form_flds." + given_state + ".options.selectedIndex");
      var state_txt = eval("form_flds." + given_state + ".options[ix].text");
      if (cntry_val == "US")  {
	 if (state_txt.indexOf("Canada") > 0 || 
	 state_txt.indexOf("United Kingdom") > 0 || 
	 state_txt.indexOf("Australia") >= 0) {
	    alert("Invalid state selected for United States");
	    return false;
	 }
      }
      else if (cntry_val == "CA")  {
	 if (state_txt.indexOf("Canada") < 0)  {
	    alert("Invalid province selected for Canada");
	    return false;
	 }
      }
      else if (cntry_val == "GB")  {
	 if (state_txt.indexOf("United Kingdom") < 0)  {
	    alert("Invalid state/province selected for United Kingdom");
	    return false;
	 }
      }
      else if (cntry_val == "AU")  {
	 if (state_txt.indexOf("Australia") < 0)  {
	    alert("Invalid state selected for Australia");
	    return false;
	 }
      }
      else  {
	 alert("Invalid state/province selected for " + cntry_txt);
	 return false;
      }
   }
   return true;
}
