StateUpdater = function() {
var countries = new Array(
"Select a Country",
"United States of America",
"Canada",
"Afghanistan",
"Albania",
"Algérie",
"Allemagne  ",
"American Samoa",
"Andorra",
"Angola",
"Anguilla",
"Anonymous Proxy",
"Antarctica",
"Antigua",
"Antigua and Barbuda",
"Antilles",
"Argentina",
"Armenia",
"Aruba",
"Asia/Pacific Region",
"Australia",
"Austria",
"Azerbaijan",
"Azores",
"Bahamas",
"Bahrain",
"Bangladesh",
"Barbados",
"Barbuda",
"Belarus",
"Belgique",
"Belgium",
"Belize",
"Benin",
"Bermuda",
"Bhutan",
"Bolivia",
"Bosnia/Hercegovina",
"Botswana",
"Bouvet Island",
"Brazil",
"British Indian Ocean Territory",
"British Virgin Islands",
"Brunei",
"Bulgaria",
"Burkina Faso",
"Burundi",
"Cambodia",
"Cameroon",
"Canary Islands",
"Cape Verde",
"Cayman Island",
"Central African Republic",
"Chad",
"CHANNEL ISLANDS",
"Chile",
"China",
"Christmas Island",
"Cocos (Keeling) Islands",
"Colombia",
"Comoros",
"Congo",
"CONGO, BRAZZAVILLE",
"Cook Islands",
"Costa Rica",
"Côte d'Ivoire",
"Croatia",
"Cuba",
"Curacao",
"Cyprus",
"Czech Republic",
"Denmark",
"Djibouti",
"Dominica",
"Dominican Republic",
"East Timor",
"Ecuador",
"Egypt",
"El Salvador",
"Equatorial Guinea",
"Eritrea",
"Espagne",
"Estonia",
"Ethiopia",
"Europe",
"Falkland Islands (Malvinas)",
"Faroe Islands",
"Fiji",
"Finland",
"France",
"France, Metropolitan",
"French Guiana",
"FRENCH POLYNESIA",
"French Southern Territories",
"FYRO Macedonia",
"Gabon",
"Gambia",
"Georgia",
"Germany",
"Ghana",
"GIBRALTAR",
"Grecia",
"Greece",
"Greenland",
"Grenada",
"Guadalope",
"Guam",
"Guatemala",
"Guinea",
"Guinea-Bissau",
"Guyana",
"Guyane Française",
"Haiti",
"Heard Island and McDonald Islands",
"HERZEGOVINA",
"Holy See (Vatican City State)",
"Honduras",
"Hong Kong",
"Hungary",
"Iceland",
"Ile de la Réunion",
"India",
"Indonesia",
"Iran",
"Iraq",
"Ireland",
"Islas Canarias",
"Israel",
"Italia",
"Jamaica",
"Japan",
"Jordan",
"Kazakhstan",
"Kenya",
"Kiribati",
"Kuwait",
"Kyrgystan",
"Laos",
"Latvia",
"Lebanon",
"Lesotho",
"Liberia",
"Libya",
"Liechtenstein",
"Lithuania",
"Luxembourg",
"Macao",
"Macedonia",
"Madagascar",
"Malawi",
"Malaysia",
"Maldives",
"Mali",
"Malta",
"Marshall Islands",
"Martinique",
"Mauritania",
"Mauritius",
"Mayotte",
"Mexico",
"Micronesia",
"Moldava",
"Moldova",
"Monaco",
"Mongolia",
"Montenegro",
"Montserrat",
"Morocco",
"Mozambique",
"Myanmar",
"Namibia",
"Nauru",
"Nepal",
"Netherlands",
"New Caledonia",
"New Zealand",
"Nicaragua",
"Niger",
"Nigeria",
"Niue",
"Norfolk Island",
"North Korea",
"Northern Ireland",
"Northern Mariana",
"Northern Mariana Islands",
"Norway",
"Nouvelle Calédonie",
"Oman",
"Pakistan",
"Palau",
"Palestine",
"Panama",
"Papua New Guinea",
"Paraguay",
"Penang",
"Peru",
"Philippines",
"Pitcairn",
"Poland",
"Portugal",
"Puerto Rico",
"Qatar",
"Reunion",
"Réunion",
"Romania",
"Russia",
"Rwanda",
"S. Georgia and S. Sandwich Islands",
"Saint Helena",
"Saint Pierre and Miquelon",
"Saipan",
"San Marino",
"São Tomé and Príncipe",
"Satellite Provider",
"Saudi Arabia",
"Senegal",
"Serbia",
"Seychelles",
"Sierra Leone",
"Singapore",
"Slovakia",
"Slovenia",
"Solomon Islands",
"Somalia",
"South Africa",
"South Korea",
"Spain",
"Sri Lanka",
"St Vincent and the Grenadines",
"St. Barthelemy",
"St. Christopher",
"St. Croix",
"St. Eustatius",
"St. John",
"St. Kitts",
"St. Lucia",
"St. Maarten",
"St. Martin",
"Sudan",
"Suisse",
"Surinam",
"Suriname",
"Svalbard and Jan Mayen",
"Swaziland",
"Sweden",
"Switzerland",
"Syria",
"Taiwan",
"Tajikistan",
"Tanzania",
"Thailand",
"The Gambia",
"The Netherlands",
"Tinian",
"Togo",
"Tokelau",
"Tonga",
"Tortola",
"Trinidad",
"Trinidad and Tobago",
"Truk",
"Tunisia",
"Turkey",
"Turkmenistan",
"Turks Islands",
"Turmenistan",
"Tuvalu",
"U.S. Virgin Islands",
"Uganda",
"Ukraine",
"United Arab Emirates",
"United Kingdom",
"United States Minor Outlying Islands",
"Uruguay",
"Uzbekistan",
"Vanuatu",
"Venezuela",
"Vietnam",
"Virgin Gorda",
"Wake Island",
"Wallis and Futuna",
"West Indies",
"Western Sahara",
"Western Samoa",
"Yap",
"Yemen",
"Yugoslavia",
"Zaire",
"Zambia",
"Zimbabwe"

);

  var us_states = new Array(["Select a State",""],
["Alabama","AL"],
["Alaska","AK"],
["Arizona","AZ"],
["Arkansas","AR"],
["California","CA"],
["Colorado","CO"],
["Connecticut","CT"],
["Delaware","DE"],
["District Of Columbia","DC"],
["Florida","FL"],
["Georgia","GA"],
["Hawaii","HI"],
["Idaho","ID"],
["Illinois","IL"],
["Indiana","IN"],
["Iowa","IA"],
["Kansas","KS"],
["Kentucky","KY"],
["Louisiana","LA"],
["Maine","ME"],
["Maryland","MD"],
["Massachusetts","MA"],
["Michigan","MI"],
["Minnesota","MN"],
["Mississippi","MS"],
["Missouri","MO"],
["Montana","MT"],
["Nebraska","NE"],
["Nevada","NV"],
["New Hampshire","NH"],
["New Jersey","NJ"],
["New Mexico","NM"],
["New York","NY"],
["North Carolina","NC"],
["North Dakota","ND"],
["Ohio","OH"],
["Oklahoma","OK"],
["Oregon","OR"],
["Pennsylvania","PA"],
["Puerto Rico","PR"],
["Rhode Island","RI"],
["South Carolina","SC"],
["South Dakota","SD"],
["Tennessee","TN"],
["Texas","TX"],
["Utah","UT"],
["Vermont","VT"],
["Virginia","VA"],
["Washington","WA"],
["West Virginia","WV"],
["Wisconsin","WI"],
["Wyoming","WY"]);

  var canadian_states = new Array(["Select a State",""],
["Alberta","AB"],
["British Columbia", "BC"],
["Manitoba", "MB"],
["New Brunswick", "NB"],
["Nova Scotia", "NS"],
["Northwest Territories", "NT"],
["Ontario", "ON"],
["Quebec", "QC"],
["Saskatchewan", "SK"],
["Yukon", "YT"]);

  function populate_countries(country_form_field) {
    var i=0;
    for (i=1;i<=(countries.length - 1);i++) {
        $(country_form_field).options[i] = new Option(countries[i], countries[i]);
    }
  };

  // See http://stevenharman.net/blog/archive/2007/07/10/add-option-elements-to-a-select-list-with-javascript.aspx
  function populate_states(country_form_field, state_form_field){

    var country = $(country_form_field).getValue();
    var state_array = new Array();

    var options = $(state_form_field).options;
    options.length = 1;

    if(country == 'United States of America'){
      var i=0;
      for(i=0;i<=(us_states.length - 1);i++){
        state_array.push(new Option(us_states[i][0], us_states[i][1]));
        $(state_form_field).options[i] = state_array[i];
      }
    }
    else if(country == 'Canada'){
      for(i=0;i<=(canadian_states.length - 1);i++){
        state_array.push(new Option(canadian_states[i][0], canadian_states[i][1]));
        $(state_form_field).options[i] = state_array[i];
      }
    }
    else if(country == ''){
      $(state_form_field).options[0] = new Option('Select a State', '');
    }
    else{
      $(state_form_field).options[0] = new Option('Outside US or Canada', 'Outside US or Canada');
    }
  };

  return({
    populate_states: populate_states,
    populate_countries: populate_countries
  });
}();

 function set_location_select(select_form_field, value) {
    select_object = $(select_form_field);

    for(index = 0; index < select_object.length; index++) {
      if(select_object[index].value == value){
       select_object.selectedIndex = index;
      }
    }
 }

