var countries = { "Afghanistan": 1, "Akrotiri": 2, "Albania": 3, "Algeria": 4, "American Samoa": 5, "Andorra": 6, "Angola": 7, "Anguilla": 8, "Antarctica": 9, "Antigua and Barbuda": 10, "Argentina": 11, "Armenia": 12, "Aruba": 13, "Ashmore and Cartier Islands": 14, "Australia": 15, "Austria": 16, "Azerbaijan": 17, "Bahamas": 18, "Bahrain": 19, "Bangladesh": 20, "Barbados": 21, "Bassas da India": 22, "Belarus": 23, "Belgium": 24, "Belize": 25, "Benin": 26, "Bermuda": 27, "Bhutan": 28, "Bolivia": 29, "Bosnia and Herzegovina": 30, "Botswana": 31, "Bouvet Island": 32, "Brazil": 33, "British Indian Ocean Territory": 34, "British Virgin Islands": 251, "Brunei Darussalam": 36, "Bulgaria": 37, "Burkina Faso": 38, "Burma": 39, "Burundi": 40, "Cambodia": 41, "Cameroon": 42, "Canada": 43, "Cape Verde": 44, "Cayman Islands": 45, "Central African Republic": 46, "Chad": 47, "Chile": 48, "China": 49, "Christmas Island": 50, "Clipperton Island": 51, "Cocos (Keeling) Islands": 52, "Colombia": 53, "Comoros": 54, "Congo, Democratic Republic of the": 55, "Congo, Republic of the": 56, "Cook Islands": 57, "Coral Sea Islands": 58, "Costa Rica": 59, "Cote d'Ivoire": 60, "Croatia": 61, "Cuba": 62, "Cyprus": 63, "Czech Republic": 64, "Denmark": 65, "Dhekelia": 66, "Djibouti": 67, "Dominica": 68, "Dominican Republic": 69, "Ecuador": 70, "Egypt": 71, "El Salvador": 72, "Equatorial Guinea": 73, "Eritrea": 74, "Estonia": 75, "Ethiopia": 76, "Europa Island": 77, "Falkland Islands (Islas Malvinas)": 78, "Faroe Islands": 79, "Fiji": 80, "Finland": 81, "France": 82, "French Guiana": 83, "French Polynesia": 84, "French Southern and Antarctic Lands": 85, "Gabon": 86, "Gambia, The": 87, "Gaza Strip": 88, "Georgia": 89, "Germany": 90, "Ghana": 91, "Gibraltar": 92, "Glorioso Islands": 93, "Greece": 94, "Greenland": 95, "Grenada": 96, "Guadeloupe": 97, "Guam": 98, "Guatemala": 99, "Guernsey": 100, "Guinea": 101, "Guinea-Bissau": 102, "Guyana": 103, "Haiti": 104, "Heard Island and McDonald Islands": 105, "Holy See (Vatican City)": 106, "Honduras": 107, "Hong Kong SAR China": 108, "Hungary": 109, "Iceland": 110, "India": 111, "Indonesia": 112, "Iran": 113, "Iraq": 114, "Ireland": 115, "Isle of Man": 116, "Israel": 117, "Italy": 118, "Jamaica": 119, "Jan Mayen": 120, "Japan": 121, "Jersey": 122, "Jordan": 123, "Juan de Nova Island": 124, "Kazakhstan": 125, "Kenya": 126, "Kiribati": 127, "Korea, Republic of": 215, "Kosovo": 259, "Kuwait": 128, "Kyrgyzstan": 129, "Laos": 130, "Latvia": 131, "Lebanon": 132, "Lesotho": 133, "Liberia": 134, "Libya": 135, "Liechtenstein": 136, "Lithuania": 137, "Luxembourg": 138, "Macau": 139, "Macedonia": 140, "Madagascar": 141, "Malawi": 142, "Malaysia": 143, "Maldives": 144, "Mali": 145, "Malta": 146, "Marshall Islands": 147, "Martinique": 148, "Mauritania": 149, "Mauritius": 150, "Mayotte": 151, "Mexico": 152, "Micronesia, Federated States of": 153, "Moldova": 154, "Monaco": 155, "Mongolia": 156, "Montenegro": 157, "Montserrat": 158, "Morocco": 159, "Mozambique": 160, "Namibia": 161, "Nauru": 162, "Navassa Island": 163, "Nepal": 164, "Netherlands": 165, "Netherlands Antilles": 166, "New Caledonia": 167, "New Zealand": 168, "Nicaragua": 169, "Niger": 170, "Nigeria": 171, "Niue": 172, "Norfolk Island": 173, "North Korea": 174, "Northern Mariana Islands": 175, "Norway": 176, "Oman": 177, "Pakistan": 178, "Palau": 179, "Panama": 180, "Papua New Guinea": 181, "Paracel Islands": 182, "Paraguay": 183, "Peru": 184, "Philippines": 185, "Pitcairn Islands": 186, "Poland": 187, "Portugal": 188, "Puerto Rico": 189, "Qatar": 190, "Reunion": 191, "Romania": 192, "Russia": 193, "Rwanda": 194, "Saint Helena, Ascension and Tristan da Cunha": 195, "Saint Kitts and Nevis": 196, "Saint Lucia": 197, "Saint Pierre and Miquelon": 198, "Saint Vincent and the Grenadines": 199, "Samoa": 200, "San Marino": 201, "Sao Tome and Principe": 202, "Saudi Arabia": 203, "Senegal": 204, "Serbia": 205, "Seychelles": 206, "Sierra Leone": 207, "Singapore": 208, "Slovakia": 209, "Slovenia": 210, "Solomon Islands": 211, "Somalia": 212, "South Africa": 213, "South Georgia and the South Sandwich Islands": 214, "Spain": 216, "Spratly Islands": 217, "Sri Lanka": 218, "Sudan": 219, "Suriname": 220, "Svalbard": 221, "Swaziland": 222, "Sweden": 223, "Switzerland": 224, "Syria": 225, "Taiwan": 226, "Tajikistan": 227, "Tanzania": 228, "Thailand": 229, "Timor-Leste": 230, "Togo": 231, "Tokelau": 232, "Tonga": 233, "Trinidad and Tobago": 234, "Tromelin Island": 235, "Tunisia": 236, "Turkey": 237, "Turkmenistan": 238, "Turks and Caicos Islands": 239, "Tuvalu": 240, "Uganda": 241, "Ukraine": 242, "United Arab Emirates": 243, "United Kingdom": 244, "United States Virgin Islands": 35, "United States of America": 245, "Uruguay": 246, "Uzbekistan": 247, "Vanuatu": 248, "Venezuela": 249, "Vietnam": 250, "Wake Island": 252, "Wallis and Futuna": 253, "West Bank": 254, "Western Sahara": 255, "Yemen": 256, "Zambia": 257, "Zimbabwe": 258 }; function add_select_option(sel, name, value) { var opt = document.createElement('option'); opt.text = name; opt.value = value; try { sel.add(opt, null); } catch( e ) { sel.add(opt); } } function populate_select_with_list(select, first_item_text, defval, list) { if( !select ) return; if( first_item_text != null ) add_select_option(select, first_item_text, ""); for( name in list ) add_select_option(select, name, list[name]); if( defval ) select.value = defval; } function populate_select_with_countries(select, first_item_text, defval) { return populate_select_with_list(select, first_item_text, defval, countries); } function select_get_text_from_value(select, value) { for( var i = 0; i < select.options.length; ++i ) if( select.options[i].value == value ) return select.options[i].text; return null; } function select_get_closest_option_match(select, text) { var match = null, match_text = null; text = text.toLowerCase(); for( var i = 0; i < select.options.length; ++i ) { var opt = select.options[i].text.toLowerCase(); if( opt == text ) return select.options[i].value; var j = opt.indexOf(text); if( j != -1 && (match == null || j < match_text.indexOf(text)) ) { match = select.options[i].value; match_text = opt; } } return match; } function link_text_and_select_inputs(text, select) { select.onchange = function() { text.value = select_get_text_from_value(select, select.value); }; text.onkeypress = function(event) { if( !event ) event = window.event; if( event.keyCode == 13 ) { try { event.stopPropagation(); } catch( e ) { event.cancelBubble = true; } return false; } return true; }; text.onkeydown = function(event) { if( !event ) event = window.event; if( event.keyCode == 13 ) { try { event.stopPropagation(); } catch( e ) { event.cancelBubble = true; } return false; } return true; }; text.onkeyup = function(event) { if( !event ) event = window.event; var value = select_get_closest_option_match(select, text.value); if( value != null ) select.value = value; if( event.keyCode == 13 ) { if( select.value ) text.value = select_get_text_from_value(select, select.value); try { event.stopPropagation(); } catch( e ) { event.cancelBubble = true; } return false; } return true; }; }