<!--


/**********************************************************************
   Country / State
 *********************************************************************/

function initCountryState(countrySelect) {
   
   // populate state select
   populateState(countrySelect.options[countrySelect.selectedIndex].value);
   
   // add onchange event handler to country select to populate state select
   countrySelect.onchange = function() { populateState(this.options[this.selectedIndex].value); };

   // add onreset event handler to form to re-init state / country
   countrySelect.form.onreset = showCountryMessage;
}

function showCountryMessage() {
   
   // show message to select a country
   document.getElementById('state-select-country-message').style.display = 'block';
   
   // show state required label
   document.getElementById('state-required-label').style.display = 'block';
   document.getElementById('state-not-required-label').style.display = 'none';
   
   // hide and disable text input
   var stateInput = document.getElementById('state-input');
   stateInput.style.display = 'none';
   stateInput.disabled = true;
   
   // hide and enable select
   var stateSelect = document.getElementById('state-select');
   stateSelect.style.display = 'none';
   stateSelect.disabled = false;
}


function populateState(country) {
   if (country == 'USA') {
      var stateArray =  new Array("('Select State','',true,true)",
         "('Alabama','Alabama')",
         "('Alaska','Alaska')",
         "('Arizona','Arizona')",
         "('Arkansas','Arkansas')",
         "('California','California')",
         "('Colorado','Colorado')",
         "('Connecticut','Connecticut')",
         "('Delaware','Delaware')",
         "('District of Columbia','District of Columbia')",
         "('Florida','Florida')",
         "('Georgia','Georgia')",
         "('Hawaii','Hawaii')",
         "('Idaho','Idaho')",
         "('Illinois','Illinois')",
         "('Indiana','Indiana')",
         "('Iowa','Iowa')",
         "('Kansas','Kansas')",
         "('Kentucky','Kentucky')",
         "('Louisiana','Louisiana')",
         "('Maine','Maine')",
         "('Maryland','Maryland')",
         "('Massachusetts','Massachusetts')",
         "('Michigan','Michigan')",
         "('Minnesota','Minnesota')",
         "('Mississippi','Mississippi')",
         "('Missouri','Missouri')",
         "('Montana','Montana')",
         "('Nebraska','Nebraska')",
         "('Nevada','Nevada')",
         "('New Hampshire','New Hampshire')",
         "('New Jersey','New Jersey')",
         "('New Mexico','New Mexico')",
         "('New York','New York')",
         "('North Carolina','North Carolina')",
         "('North Dakota','North Dakota')",
         "('Ohio','Ohio')",
         "('Oklahoma','Oklahoma')",
         "('Oregon','Oregon')",
         "('Pennsylvania','Pennsylvania')",
         "('Rhode Island','Rhode Island')",
         "('South Carolina','South Carolina')",
         "('South Dakota','South Dakota')",
         "('Tennessee','Tennessee')",
         "('Texas','Texas')",
         "('Utah','Utah')",
         "('Vermont','Vermont')",
         "('Virginia','Virginia')",
         "('Washington','Washington')",
         "('West Virginia','West Virginia')",
         "('Wisconsin','Wisconsin')",
         "('Wyoming','Wyoming')"
      );
   }
   else if (country == 'Canada') {
      var stateArray =  new Array("('Select Province','',true,true)",
         "('Alberta','Alberta')",
         "('British Columbia','British Columbia')",
         "('Manitoba','Manitoba')",
         "('New Brunswick','New Brunswick')",
         "('Newfoundland','Newfoundland')",
         "('Northwest Territories','Northwest Territories')",
         "('Nova Scotia','Nova Scotia')",
         "('Nunavut','Nunavut')",
         "('Ontario','Ontario')",
         "('Prince Edward Island','Prince Edward Island')",
         "('Quebec','Quebec')",
         "('Saskatchewan','Saskatchewan')",
         "('Yukon Territory','Yukon Territory')"
      );
   }

   // for non-empty selection
   if (country != '') {
      
      // hide message to select a country
      document.getElementById('state-select-country-message').style.display = 'none';
      
      // countries that require a state / province selection
      if (country == 'USA' || country == 'Canada') {
         
         // show state required label
         document.getElementById('state-required-label').style.display = 'block';
         document.getElementById('state-not-required-label').style.display = 'none';
         
         // hide and disable text input
         var stateInput = document.getElementById('state-input');
         stateInput.style.display = 'none';
         stateInput.disabled = true;
   
         // show and enable select
         var stateSelect = document.getElementById('state-select');
         stateSelect.style.display = 'block';
         stateSelect.disabled = false;
         
         // populate state select
         eval("document.getElementById('state-select').options.length = stateArray.length");
         for (var optionIndex = 0; optionIndex < stateArray.length; optionIndex++) {
            eval("document.getElementById('state-select').options[optionIndex]=" + "new Option" + stateArray[optionIndex]);
         }
      }
      
      // for other selections 
      else {
         
         // show state not required label
         document.getElementById('state-required-label').style.display = 'none';
         document.getElementById('state-not-required-label').style.display = 'block';
         
         // show and enable text input
         var stateInput = document.getElementById('state-input');
         stateInput.style.display = 'block';
         stateInput.disabled = false;
   
         // hide and disable select
         var stateSelect = document.getElementById('state-select');
         stateSelect.style.display = 'none';
         stateSelect.disabled = true;
      }
   }
   
   // for an empty selection
   else {
      showCountryMessage();
   }
}


//-->
