home *** CD-ROM | disk | FTP | other *** search
- const countryListUS = 'United States';
- const countryListDefault = countryListUS;
- const countryList = [
- "Afghanistan",
- "Albania",
- "Algeria",
- "American Samoa",
- "Andorra",
- "Angola",
- "Anguilla",
- "Antigua and Barbuda",
- "Argentina",
- "Armenia",
- "Australia",
- "Austria",
- "Azerbaijan Republic",
- "Bahamas",
- "Bahrain",
- "Bangladesh",
- "Barbados",
- "Belarus",
- "Belgium",
- "Belize",
- "Benin",
- "Bermuda",
- "Bhutan",
- "Bolivia",
- "Bosnia and Herzegovina",
- "Botswana",
- "Brazil",
- "British Virgin Islands",
- "Brunei Darussalam",
- "Bulgaria",
- "Burkina Faso",
- "Burma",
- "Burundi",
- "Cambodia",
- "Cameroon",
- "Canada",
- "Cape Verde Islands",
- "Cayman Islands",
- "Central African Republic",
- "Chad",
- "Chile",
- "China",
- "Colombia",
- "Congo",
- "Cook Islands",
- "Costa Rica",
- "Cote d Ivoire (Ivory Coast)",
- "Croatia, Republic of",
- "Cyprus",
- "Czech Republic",
- "Denmark",
- "Djibouti",
- "Dominica",
- "Dominican Republic",
- "Ecuador",
- "Egypt",
- "El Salvador",
- "Equatorial Guinea",
- "Eritrea",
- "Falkland Islands (Islas Malvinas)",
- "Fiji",
- "Finland",
- "France",
- "French Guiana",
- "French Polynesia",
- "Gabon Republic",
- "Gambia",
- "Georgia",
- "Germany",
- "Ghana",
- "Gibraltar",
- "Greece",
- "Greenland",
- "Grenada",
- "Guadeloupe",
- "Guam",
- "Guatemala",
- "Guernsey",
- "Guinea",
- "Guinea-Bissau",
- "Guyana",
- "Haiti",
- "Honduras",
- "Hong Kong",
- "Hungary",
- "Iceland",
- "India",
- "Indonesia",
- "Ireland",
- "Jersey",
- "Jordan",
- "Kazakhstan",
- "Kenya Coast Republic",
- "Kiribati",
- "Korea, South",
- "Kuwait",
- "Kyrgyzstan",
- "Laos",
- "Latvia",
- "Lebanon",
- "Liechtenstein",
- "Lithuania",
- "Luxembourg",
- "Macau",
- "Macedonia",
- "Madagascar",
- "Malawi",
- "Malaysia",
- "Maldives",
- "Mali",
- "Malta",
- "Marshall Islands",
- "Martinique",
- "Mauritania",
- "Mauritius",
- "Mayotte",
- "Mexico",
- "Micronesia",
- "Moldova",
- "Monaco",
- "Mongolia",
- "Montserrat",
- "Morocco",
- "Mozambique",
- "Namibia",
- "Nauru",
- "Nepal",
- "Netherlands",
- "Netherlands Antilles",
- "New Caledonia",
- "New Zealand",
- "Nicaragua",
- "Niger",
- "Nigeria",
- "Niue",
- "Norway",
- "Oman",
- "Pakistan",
- "Palau",
- "Panama",
- "Papua New Guinea",
- "Paraguay",
- "Peru",
- "Philippines",
- "Poland",
- "Portugal",
- "Puerto Rico",
- "Qatar",
- "Romania",
- "Russian Federation",
- "Rwanda",
- "Saint Helena",
- "Saint Kitts-Nevis",
- "Saint Lucia",
- "Saint Pierre and Miquelon",
- "Saint Vincent and the Grenadines",
- "San Marino",
- "Saudi Arabia",
- "Senegal",
- "Seychelles",
- "Sierra Leone",
- "Singapore",
- "Slovakia",
- "Slovenia",
- "Solomon Islands",
- "Somalia",
- "South Africa",
- "Spain",
- "Sri Lanka",
- "Suriname",
- "Svalbard",
- "Swaziland",
- "Sweden",
- "Switzerland",
- "Syria",
- "Tahiti",
- "Taiwan",
- "Tajikistan",
- "Tanzania",
- "Thailand",
- "Togo",
- "Tonga",
- "Trinidad and Tobago",
- "Tunisia",
- "Turkey",
- "Turkmenistan",
- "Turks and Caicos Islands",
- "Tuvalu",
- "Uganda",
- "Ukraine",
- "United Arab Emirates",
- "United Kingdom",
- countryListUS,
- "Uruguay",
- "Uzbekistan",
- "Vanuatu",
- "Vatican City State",
- "Venezuela",
- "Vietnam",
- "Virgin Islands (U.S.)",
- "Wallis and Futuna",
- "Western Sahara",
- "Western Samoa",
- "Yemen",
- "Yugoslavia",
- "Zambia",
- "Zimbabwe"
- ];
-
- function findClosestCountryMatch(dubiousCountry) {
- dubiousCountry = dubiousCountry.toLowerCase();
- // First the trivial cases
- if (!dubiousCountry || (dubiousCountry == ''))
- return countryListUS;
- // Next check for exact matches (case insensitive)
- for (var i = 0; i < countryList.length; i++) {
- var candidateMatchCountry = countryList[i].toLowerCase();
- if (dubiousCountry == candidateMatchCountry)
- return countryList[i];
- }
- // Next check for specific variations
- if ((dubiousCountry == 'us') ||
- (dubiousCountry == 'usa') ||
- (dubiousCountry == 'u.s.') ||
- (dubiousCountry == 'u.s.a.') ||
- (dubiousCountry == 'united states of america'))
- {
- return countryListUS;
- }
- // Next check for substring matches
- for (var i = 0; i < countryList.length; i++) {
- var candidateMatchCountry = countryList[i].toLowerCase();
- if ((dubiousCountry.indexOf(candidateMatchCountry) > -1) ||
- (candidateMatchCountry.indexOf(dubiousCountry) > -1))
- {
- return countryList[i];
- }
- }
- // Default to United States
- return countryListUS;
- }