// Copyright (c) 2008 Andrew Dockery
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// country.js
// Nov 11, 2008
//
// Contains information about the names and codes of countries.

// Array of all countries in the world
var countryNames = new Array("Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola",
								 "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba",
								 "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh",
								 "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan",
								 "Bolivia", "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil", "Britain",
								 "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso",
								 "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands",
								 "Central African Republic", "Chad", "Chile", "China", "Christmas Island",
								 "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Cook Islands",
								 "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Cote d'Ivoire",
								 "Denmark", "Djibouti", "Dominica", "Dominican Republic", "East Timor", "Ecuador",
								 "Egypt", "El Salvador", "England", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia",
								 "Falkland Islands", "Faroe Islands", "Fiji", "Finland", "France", "French Guiana",
								 "French Polynesia", "French Southern Territories", "Gabon", "Gambia", "Georgia",
								 "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe",
								 "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti",
								 "Heard Island and McDonald Islands", "Holy See (Vatican City State)", "Honduras",
								 "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Ireland", "Isle of Man",
								 "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakstan", "Kenya", "Kiribati",
								 "Kuwait", "Kyrgystan", "Lao", "Latvia", "Lebanon", "Lesotho", "Liberia",
								 "Libyan Arab Jamahiriya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau",
								 "Macedonia (FYR)", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali",
								 "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte",
								 "Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", "Montserrat", "Morocco",
								 "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands",
								 "Netherlands Antilles", "Neutral Zone", "New Caledonia", "New Zealand",
								 "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "Northern Ireland",
								 "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama",
								 "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn", "Poland",
								 "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation",
								 "Rwanda", "Saint Helena", "Saint Kitts and Nevis", "Saint Lucia",
								 "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa",
								 "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Scotland", "Senegal", "Seychelles",
								 "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia",
								 "South Africa", "South Georgia", "South Korea", "Spain", "Sri Lanka", "Sudan",
								 "Suriname", "Svalbard and Jan Mayen Islands", "Swaziland", "Sweden", "Switzerland",
								 "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Togo", "Tokelau",
								 "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan",
								 "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates",
								 "United Kingdom", "United States Minor Outlying Islands",
								 "United States of America", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Wales",
								 "Viet Nam", "Virgin Islands (British)", "Virgin Islands (U.S.)",
								 "Wallis and Futuna Islands", "Western Sahara", "Yemen", "Yugoslavia", "Zaire",
								 "Zambia", "Zimbabwe");

// WorldPay country codes
var countryCodes = new Array("AF", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU",
							 "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO",
							 "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV",
							 "KY", "CF", "td", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CK", "CR", "HR",
							 "CU", "CY", "CZ", "CI", "DK", "DJ", "DM", "DO", "TP", "EC", "EG", "SV", "GQ",
							 "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM",
							 "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GN", "GW", "GY",
							 "HT", "HM", "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IE", "IL", "IT",
							 "JM", "JP", "JO", "KZ", "KE", "KI", "KW", "KG", "LA", "LV", "LB", "LS", "LR",
							 "LY", "LI", "LT", "LU", "MO", "MK", "MG", "MW", "MY", "MV", "ML", "MT", "MH",
							 "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "MS", "MA", "MZ", "MM",
							 "NA", "NR", "NP", "NL", "AN", "NT", "NC", "NZ", "NI", "NE", "NG", "NU", "NF",
							 "KP", "MP", "NO", "OM", "PK", "PW", "PA", "PG", "PY", "PE", "PH", "PN", "PL",
							 "PT", "PR", "QA", "RE", "RO", "RU", "RW", "SH", "KN", "LC", "PM", "VC", "WS",
							 "SM", "ST", "SA", "SN", "SC", "SL", "SG", "SK", "SI", "SB", "SO", "ZA", "GS",
							 "KR", "ES", "LK", "SD", "SR", "SJ", "SZ", "SE", "CH", "SY", "TW", "TJ", "TZ",
							 "TH", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE",
							 "GB", "UM", "US", "UY", "UZ", "VU", "VE", "VN", "VG", "VI", "WF", "EH", "YE",
							 "YU", "ZR", "ZM", "ZW");

// countryName2Code: Transalates the name of a country to a 2 letter code accepted by Worldpay
function countryName2Code(country) {
	var i = 0;
	
	if (country == "") {
		return "";
	}
	
	while (country != countryNames[i] && i < countryNames.length) {
		i++;
	}

	return countryCodes[i];
}

// Populate a minimally filled select control with country names.  The control must
// contain two options - usually "Please select a country" and the default country.
function populateCountrySelect(control) {
	if(control.length != 2) {
		return;
	}

	var i=0;
	while (i < countryNames.length) {
		newOption = new Option();
		newOption.text = countryNames[i];
		newOption.value = countryNames[i];
		control.options[control.length] = newOption;
		i++;
	}
}

