// Check browser version
var net3 = (parseInt(navigator.appVersion) >= 3);

if (net3) {
  var states_hash = new Array();

  // Canada
  states_hash['Canada'] = new Array('AB', 'BC', 'MB', 'NB', 'NS', 'ON', 'PE', 'SK', 'NF', 'NT', 'NU', 'YK','QC');
  // USA
  states_hash['USA'] = new Array('AK', 'AL', 'AR', 'AZ', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI', 'IA', 'ID', 'IL', 'IN', 'KS', 'KY', 'LA', 'MA', 'MD', 'ME', 'MI', 'MN', 'MS', 'MO', 'MT', 'NC', 'ND', 'NE', 'NH', 'NJ', 'NM', 'NV', 'NY', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VA', 'VT', 'WA', 'WI', 'WV', 'WY');


}

function populate_states() {
   if(net3) {
      var state = '';
      if (document.inv.state.options[document.inv.state.selectedIndex].value) {
        state = document.inv.state.options[document.inv.state.selectedIndex].value;
      }
      document.inv.state.length = 0;
      var ind = document.inv.country.selectedIndex;
      var country = document.inv.country[ind].value;
      if (ind == 0) {
        document.inv.state.options[0] = new Option ('Select a state/province', '');
        document.inv.state.options[0].selected = true;

        var cnt = 0;
        var k = states_hash['Canada'];
        k.sort();
        for (i=0;i<k.length;i++)
        {
           cnt ++;
	   var value = k[i];
	   var display = value + ' - Canada';
           document.inv.state.options[cnt] = new Option(display, value);

           if (value == state) {
             document.inv.state.options[cnt].selected = true;
             document.inv.selectedIndex = cnt;
           }
        }
        document.inv.state.options[++cnt] = new Option('-------------', '');

        k = states_hash['USA'];
        k.sort();
        for (i=0;i < k.length;i++)
        {
           cnt ++;
	   var value = k[i];
	   var display = value + ' - USA';
           document.inv.state.options[cnt] = new Option(display, value);

           if (value == state) {
             document.inv.state.options[cnt].selected = true;
             document.inv.selectedIndex = cnt;
           }
        }

      } else {
        document.inv.state.options[0] = new Option('All','');
        document.inv.state.options[0].selected = true;

        var k = states_hash[country];
        k.sort();
        for (i in k)
        {
	   var display = k[i];
	   var value = display;
	   var idx = document.inv.state.options.length;
           document.inv.state.options[idx] = new Option(display, value);

           if (value == state) {
             document.inv.state.options[idx].selected = true;
             document.inv.selectedIndex = idx;
           }
        }
      }
   }
   else
   {
      return 0;
   }
}
