
// Creates a list of contries and related functions to go with it.

// Country structure
function country (name, char2Code, char3Code, numberCode, FIPSCode) {
	this.name = name;
	this.char2Code = char2Code;
	this.char3Code = char3Code;
	this.numberCode = numberCode;
	this.FIPSCode = FIPSCode;
}

var countries = new Array();

// ------------------------------------------------------------------------------------

// Load the countries array

countries[0] = new country ("Afghanistan", "AF", "AFG", "004", "AF");
countries[1] = new country ("Albania", "AL", "ALB", "008", "AL");
countries[2] = new country ("Algeria", "DZ", "DZA", "012", "AG");
countries[3] = new country ("American Samoa", "AS", "ASM", "016", "AQ");
countries[4] = new country ("Andorra", "AD", "AND", "020", "AN");
countries[5] = new country ("Angola", "AO", "AGO", "024", "AO");
countries[6] = new country ("Anguilla", "AI", "AIA", "660", "AV");
countries[7] = new country ("Antarctica", "AQ", "ATA", "010", "AY");
countries[8] = new country ("Antigua and Barbuda", "AG", "ATG", "028", "AC");
countries[9] = new country ("Argentina", "AR", "ARG", "032", "AR");
countries[10] = new country ("Armenia", "AM", "ARM", "051", "AM");
countries[11] = new country ("Aruba", "AW", "ABW", "533", "AA");
countries[12] = new country ("Australia", "AU", "AUS", "036", "AS");
countries[13] = new country ("Austria", "AT", "AUT", "040", "AU");
countries[14] = new country ("Azerbaijan", "AZ", "AZE", "031", "AJ");
countries[15] = new country ("Bahamas", "BS", "BHS", "044", "BF");
countries[16] = new country ("Bahrain", "BH", "BHR", "048", "BA");
countries[17] = new country ("Bangladesh", "BD", "BGD", "050", "BG");
countries[18] = new country ("Barbados", "BB", "BRB", "052", "BB");
countries[19] = new country ("Belarus", "BY", "BLR", "112", "BO");
countries[20] = new country ("Belgium", "BE", "BEL", "056", "BE");
countries[21] = new country ("Belize", "BZ", "BLZ", "084", "BH");
countries[22] = new country ("Benin", "BJ", "BEN", "204", "BN");
countries[23] = new country ("Bermuda", "BM", "BMU", "060", "BD");
countries[24] = new country ("Bhutan", "BT", "BTN", "064", "BT");
countries[25] = new country ("Bolivia", "BO", "BOL", "068", "BL");
countries[26] = new country ("Bosnia and Herzegovina", "BA", "BIH", "070", "BK");
countries[27] = new country ("Botswana", "BW", "BWA", "072", "BC");
countries[28] = new country ("Bouvet Island", "BV", "BVT", "074", "BV");
countries[29] = new country ("Brazil", "BR", "BRA", "076", "BR");
countries[30] = new country ("British Indian Ocean Territory", "IO", "IOT", "086", "IO");
countries[31] = new country ("Brunei Darussalam", "BN", "BRN", "096", "BX");
countries[32] = new country ("Bulgaria", "BG", "BGR", "100", "BU");
countries[33] = new country ("Burkina Faso", "BF", "BFA", "854", "UV");
countries[34] = new country ("Burundi", "BI", "BDI", "108", "BY");
countries[35] = new country ("Cambodia", "KH", "KHM", "116", "CB");
countries[36] = new country ("Cameroon", "CM", "CMR", "120", "CM");
countries[37] = new country ("Canada", "CA", "CAN", "124", "CA");
countries[38] = new country ("Cape Verde", "CV", "CPV", "132", "CV");
countries[39] = new country ("Cayman Islands", "KY", "CYM", "136", "CJ");
countries[40] = new country ("Central African Republic", "CF", "CAF", "140", "CT");
countries[41] = new country ("Chad", "TD", "TCD", "148", "CD");
countries[42] = new country ("Chile", "CL", "CHL", "152", "CI");
countries[43] = new country ("China", "CN", "CHN", "156", "CH");
countries[44] = new country ("Christmas Island", "CX", "CXR", "162", "KT");
countries[45] = new country ("Cocos (Keeling) Islands", "CC", "CCK", "166", "CK");
countries[46] = new country ("Colombia", "CO", "COL", "170", "CO");
countries[47] = new country ("Comoros", "KM", "COM", "174", "CN");
countries[48] = new country ("Congo", "CG", "COG", "178", "CF");
countries[49] = new country ("Congo, The Democratic Republic Of The", "CD", "COD", "180", "CG");
countries[50] = new country ("Cook Islands", "CK", "COK", "184", "CW");
countries[51] = new country ("Costa Rica", "CR", "CRI", "188", "CS");
countries[52] = new country ("Croatia", "HR", "HRV", "191", "HR");
countries[53] = new country ("Cuba", "CU", "CUB", "192", "CU");
countries[54] = new country ("Cyprus", "CY", "CYP", "196", "CY");
countries[55] = new country ("Czech Republic", "CZ", "CZE", "203", "EZ");
countries[56] = new country ("C\u00f4te D'Ivoire", "CI", "CIV", "384", "IV");
countries[57] = new country ("Denmark", "DK", "DNK", "208", "DA");
countries[58] = new country ("Djibouti", "DJ", "DJI", "262", "DJ");
countries[59] = new country ("Dominica", "DM", "DMA", "212", "DO");
countries[60] = new country ("Dominican Republic", "DO", "DOM", "214", "DR");
countries[61] = new country ("Ecuador", "EC", "ECU", "218", "EC");
countries[62] = new country ("Egypt", "EG", "EGY", "818", "EG");
countries[63] = new country ("El Salvador", "SV", "SLV", "222", "ES");
countries[64] = new country ("Equatorial Guinea", "GQ", "GNQ", "226", "EK");
countries[65] = new country ("Eritrea", "ER", "ERI", "232", "ER");
countries[66] = new country ("Estonia", "EE", "EST", "233", "EN");
countries[67] = new country ("Ethiopia", "ET", "ETH", "231", "ET");
countries[68] = new country ("Falkland Islands  (Malvinas)", "FK", "FLK", "238", "FK");
countries[69] = new country ("Faroe Islands", "FO", "FRO", "234", "FO");
countries[70] = new country ("Fiji", "FJ", "FJI", "242", "FJ");
countries[71] = new country ("Finland", "FI", "FIN", "246", "FI");
countries[72] = new country ("France", "FR", "FRA", "250", "FR");
countries[73] = new country ("French Guiana", "GF", "GUF", "254", "FG");
countries[74] = new country ("French Polynesia", "PF", "PYF", "258", "FP");
countries[75] = new country ("French Southern Territories", "TF", "ATF", "260", "FS");
countries[76] = new country ("Gabon", "GA", "GAB", "266", "GB");
countries[77] = new country ("Gambia", "GM", "GMB", "270", "GA");
countries[78] = new country ("Georgia", "GE", "GEO", "268", "GG");
countries[79] = new country ("Germany", "DE", "DEU", "276", "GM");
countries[80] = new country ("Ghana", "GH", "GHA", "288", "GH");
countries[81] = new country ("Gibraltar", "GI", "GIB", "292", "GI");
countries[82] = new country ("Greece", "GR", "GRC", "300", "GR");
countries[83] = new country ("Greenland", "GL", "GRL", "304", "GL");
countries[84] = new country ("Grenada", "GD", "GRD", "308", "GJ");
countries[85] = new country ("Guadeloupe", "GP", "GLP", "312", "GP");
countries[86] = new country ("Guam", "GU", "GUM", "316", "GQ");
countries[87] = new country ("Guatemala", "GT", "GTM", "320", "GT");
countries[88] = new country ("Guernsey", "GG", "GGY", "831", "GK");
countries[89] = new country ("Guinea", "GN", "GIN", "324", "GV");
countries[90] = new country ("Guinea-Bissau", "GW", "GNB", "624", "PU");
countries[91] = new country ("Guyana", "GY", "GUY", "328", "GY");
countries[92] = new country ("Haiti", "HT", "HTI", "332", "HA");
countries[93] = new country ("Heard and McDonald Islands", "HM", "HMD", "334", "HM");
countries[94] = new country ("Holy See (Vatican City State)", "VA", "VAT", "336", "VT");
countries[95] = new country ("Honduras", "HN", "HND", "340", "HO");
countries[96] = new country ("Hong Kong", "HK", "HKG", "344", "HK");
countries[97] = new country ("Hungary", "HU", "HUN", "348", "HU");
countries[98] = new country ("Iceland", "IS", "ISL", "352", "IC");
countries[99] = new country ("India", "IN", "IND", "356", "IN");
countries[100] = new country ("Indonesia", "ID", "IDN", "360", "ID");
countries[101] = new country ("Iran, Islamic Republic Of", "IR", "IRN", "364", "IR");
countries[102] = new country ("Iraq", "IQ", "IRQ", "368", "IZ");
countries[103] = new country ("Ireland", "IE", "IRL", "372", "EI");
countries[104] = new country ("Isle of Man", "IM", "IMN", "833", "IM");
countries[105] = new country ("Israel", "IL", "ISR", "376", "IS");
countries[106] = new country ("Italy", "IT", "ITA", "380", "IT");
countries[107] = new country ("Jamaica", "JM", "JAM", "388", "JM");
countries[108] = new country ("Japan", "JP", "JPN", "392", "JA");
countries[109] = new country ("Jersey", "JE", "JEY", "832", "JE");
countries[110] = new country ("Jordan", "JO", "JOR", "400", "JO");
countries[111] = new country ("Kazakhstan", "KZ", "KAZ", "398", "KZ");
countries[112] = new country ("Kenya", "KE", "KEN", "404", "KE");
countries[113] = new country ("Kiribati", "KI", "KIR", "296", "KR");
countries[114] = new country ("Korea, Democratic People's Republic Of", "KP", "PRK", "408", "KN");
countries[115] = new country ("Korea, Republic of", "KR", "KOR", "410", "KS");
countries[116] = new country ("Kuwait", "KW", "KWT", "414", "KU");
countries[117] = new country ("Kyrgyzstan", "KG", "KGZ", "417", "KG");
countries[118] = new country ("Lao People's Democratic Republic", "LA", "LAO", "418", "LA");
countries[119] = new country ("Latvia", "LV", "LVA", "428", "LG");
countries[120] = new country ("Lebanon", "LB", "LBN", "422", "LE");
countries[121] = new country ("Lesotho", "LS", "LSO", "426", "LT");
countries[122] = new country ("Liberia", "LR", "LBR", "430", "LI");
countries[123] = new country ("Libyan Arab Jamahiriya", "LY", "LBY", "434", "LY");
countries[124] = new country ("Liechtenstein", "LI", "LIE", "438", "LS");
countries[125] = new country ("Lithuania", "LT", "LTU", "440", "LH");
countries[126] = new country ("Luxembourg", "LU", "LUX", "442", "LU");
countries[127] = new country ("Macao", "MO", "MAC", "446", "MC");
countries[128] = new country ("Macedonia, the Former Yugoslav Republic Of", "MK", "MKD", "807", "MK");
countries[129] = new country ("Madagascar", "MG", "MDG", "450", "MA");
countries[130] = new country ("Malawi", "MW", "MWI", "454", "MI");
countries[131] = new country ("Malaysia", "MY", "MYS", "458", "MY");
countries[132] = new country ("Maldives", "MV", "MDV", "462", "MV");
countries[133] = new country ("Mali", "ML", "MLI", "466", "ML");
countries[134] = new country ("Malta", "MT", "MLT", "470", "MT");
countries[135] = new country ("Marshall Islands", "MH", "MHL", "584", "RM");
countries[136] = new country ("Martinique", "MQ", "MTQ", "474", "MB");
countries[137] = new country ("Mauritania", "MR", "MRT", "478", "MR");
countries[138] = new country ("Mauritius", "MU", "MUS", "480", "MP");
countries[139] = new country ("Mayotte", "YT", "MYT", "175", "MF");
countries[140] = new country ("Mexico", "MX", "MEX", "484", "MX");
countries[141] = new country ("Micronesia, Federated States Of", "FM", "FSM", "583", "FM");
countries[142] = new country ("Moldova, Republic of", "MD", "MDA", "498", "MD");
countries[143] = new country ("Monaco", "MC", "MCO", "492", "MN");
countries[144] = new country ("Mongolia", "MN", "MNG", "496", "MG");
countries[145] = new country ("Montenegro", "ME", "MNE", "499", "MJ");
countries[146] = new country ("Montserrat", "MS", "MSR", "500", "MH");
countries[147] = new country ("Morocco", "MA", "MAR", "504", "MO");
countries[148] = new country ("Mozambique", "MZ", "MOZ", "508", "MZ");
countries[149] = new country ("Myanmar", "MM", "MMR", "104", "BM");
countries[150] = new country ("Namibia", "NA", "NAM", "516", "WA");
countries[151] = new country ("Nauru", "NR", "NRU", "520", "NR");
countries[152] = new country ("Nepal", "NP", "NPL", "524", "NP");
countries[153] = new country ("Netherlands", "NL", "NLD", "528", "NL");
countries[154] = new country ("Netherlands Antilles", "AN", "ANT", "530", "NT");
countries[155] = new country ("New Caledonia", "NC", "NCL", "540", "NC");
countries[156] = new country ("New Zealand", "NZ", "NZL", "554", "NZ");
countries[157] = new country ("Nicaragua", "NI", "NIC", "558", "NU");
countries[158] = new country ("Niger", "NE", "NER", "562", "NG");
countries[159] = new country ("Nigeria", "NG", "NGA", "566", "NI");
countries[160] = new country ("Niue", "NU", "NIU", "570", "NE");
countries[161] = new country ("Norfolk Island", "NF", "NFK", "574", "NF");
countries[162] = new country ("Northern Mariana Islands", "MP", "MNP", "580", "CQ");
countries[163] = new country ("Norway", "NO", "NOR", "578", "NO");
countries[164] = new country ("Oman", "OM", "OMN", "512", "MU");
countries[165] = new country ("Pakistan", "PK", "PAK", "586", "PK");
countries[166] = new country ("Palau", "PW", "PLW", "585", "PS");
countries[167] = new country ("Palestinian Territory, Occupied", "PS", "PSE", "275", "WE/GZ");
countries[168] = new country ("Panama", "PA", "PAN", "591", "PM");
countries[169] = new country ("Papua New Guinea", "PG", "PNG", "598", "PP");
countries[170] = new country ("Paraguay", "PY", "PRY", "600", "PA");
countries[171] = new country ("Peru", "PE", "PER", "604", "PE");
countries[172] = new country ("Philippines", "PH", "PHL", "608", "RP");
countries[173] = new country ("Pitcairn", "PN", "PCN", "612", "PC");
countries[174] = new country ("Poland", "PL", "POL", "616", "PL");
countries[175] = new country ("Portugal", "PT", "PRT", "620", "PO");
countries[176] = new country ("Puerto Rico", "PR", "PRI", "630", "RQ");
countries[177] = new country ("Qatar", "QA", "QAT", "634", "QA");
countries[178] = new country ("Romania", "RO", "ROU", "642", "RO");
countries[179] = new country ("Russian Federation", "RU", "RUS", "643", "RS");
countries[180] = new country ("Rwanda", "RW", "RWA", "646", "RW");
countries[181] = new country ("R\u00e9union", "RE", "REU", "638", "RE");
countries[182] = new country("Saint Barth\u00e9lemy", "BL", "BLM", "652", "TB");
countries[183] = new country ("Saint Helena", "SH", "SHN", "654", "SH");
countries[184] = new country ("Saint Kitts And Nevis", "KN", "KNA", "659", "SC");
countries[185] = new country ("Saint Lucia", "LC", "LCA", "662", "ST");
countries[186] = new country ("Saint Martin", "MF", "MAF", "663", "RN");
countries[187] = new country ("Saint Pierre And Miquelon", "PM", "SPM", "666", "SB");
countries[188] = new country ("Saint Vincent And The Grenedines", "VC", "VCT", "670", "VC");
countries[189] = new country ("Samoa", "WS", "WSM", "882", "WS");
countries[190] = new country ("San Marino", "SM", "SMR", "674", "SM");
countries[191] = new country ("Sao Tome and Principe", "ST", "STP", "678", "TP");
countries[192] = new country ("Saudi Arabia", "SA", "SAU", "682", "SA");
countries[193] = new country ("Senegal", "SN", "SEN", "686", "SG");
countries[194] = new country ("Serbia", "RS", "SRB", "688", "RI");
countries[195] = new country ("Seychelles", "SC", "SYC", "690", "SE");
countries[196] = new country ("Sierra Leone", "SL", "SLE", "694", "SL");
countries[197] = new country ("Singapore", "SG", "SGP", "702", "SN");
countries[198] = new country ("Slovakia", "SK", "SVK", "703", "LO");
countries[199] = new country ("Slovenia", "SI", "SVN", "705", "SI");
countries[200] = new country ("Solomon Islands", "SB", "SLB", "090", "BP");
countries[201] = new country ("Somalia", "SO", "SOM", "706", "SO");
countries[202] = new country ("South Africa", "ZA", "ZAF", "710", "SF");
countries[203] = new country ("South Georgia and the South Sandwich Islands", "GS", "SGS", "239", "SX");
countries[204] = new country ("Spain", "ES", "ESP", "724", "SP");
countries[205] = new country ("Sri Lanka", "LK", "LKA", "144", "CE");
countries[206] = new country ("Sudan", "SD", "SDN", "736", "SU");
countries[207] = new country ("Suriname", "SR", "SUR", "740", "NS");
countries[208] = new country ("Svalbard And Jan Mayen", "SJ", "SJM", "744", "SV");
countries[209] = new country ("Swaziland", "SZ", "SWZ", "748", "WZ");
countries[210] = new country ("Sweden", "SE", "SWE", "752", "SW");
countries[211] = new country ("Switzerland", "CH", "CHE", "756", "SZ");
countries[212] = new country ("Syrian Arab Republic", "SY", "SYR", "760", "SY");
countries[213] = new country ("Taiwan, Province Of China", "TW", "TWN", "158", "TW");
countries[214] = new country ("Tajikistan", "TJ", "TJK", "762", "TI");
countries[215] = new country ("Tanzania, United Republic of", "TZ", "TZA", "834", "TZ");
countries[216] = new country ("Thailand", "TH", "THA", "764", "TH");
countries[217] = new country ("Timor-Leste", "TL", "TLS", "626", "TT");
countries[218] = new country ("Togo", "TG", "TGO", "768", "TO");
countries[219] = new country ("Tokelau", "TK", "TKL", "772", "TL");
countries[220] = new country ("Tonga", "TO", "TON", "776", "TN");
countries[221] = new country ("Trinidad and Tobago", "TT", "TTO", "780", "TD");
countries[222] = new country ("Tunisia", "TN", "TUN", "788", "TS");
countries[223] = new country ("Turkey", "TR", "TUR", "792", "TU");
countries[224] = new country ("Turkmenistan", "TM", "TKM", "795", "TX");
countries[225] = new country ("Turks and Caicos Islands", "TC", "TCA", "796", "TK");
countries[226] = new country ("Tuvalu", "TV", "TUV", "798", "TV");
countries[227] = new country ("Uganda", "UG", "UGA", "800", "UG");
countries[228] = new country ("Ukraine", "UA", "UKR", "804", "UP");
countries[229] = new country ("United Arab Emirates", "AE", "ARE", "784", "AE");
countries[230] = new country ("United Kingdom", "GB", "GBR", "826", "UK");
countries[231] = new country ("United States", "US", "USA", "840", "US");
countries[232] = new country ("United States Minor Outlying Islands", "UM", "UMI", "581", "");
countries[233] = new country ("Uruguay", "UY", "URY", "858", "UY");
countries[234] = new country ("Uzbekistan", "UZ", "UZB", "860", "UZ");
countries[235] = new country ("Vanuatu", "VU", "VUT", "548", "NH");
countries[236] = new country ("Venezuela, Bolivarian Republic of", "VE", "VEN", "862", "VE");
countries[237] = new country ("Viet Nam", "VN", "VNM", "704", "VM");
countries[238] = new country ("Virgin Islands, British", "VG", "VGB", "092", "VI");
countries[239] = new country ("Virgin Islands, U.S.", "VI", "VIR", "850", "VQ");
countries[240] = new country ("Wallis and Futuna", "WF", "WLF", "876", "WF");
countries[241] = new country ("Western Sahara", "EH", "ESH", "732", "WI");
countries[242] = new country ("Yemen", "YE", "YEM", "887", "YM");
countries[243] = new country ("Zambia", "ZM", "ZMB", "894", "ZA");
countries[244] = new country ("Zimbabwe", "ZW", "ZWE", "716", "ZI");
countries[245] = new country ("\u00c5land Islands", "AX", "ALA", "248", "");

// ------------------------------------------------------------------------------------

// Find the 2-character ISO 3166 code from the country name

function char2CodeFromName (name) {

	
	for (var i in countries) {
		if (countries[i].name == name)
			return countries[i].char2Code;
	}
	return "";
}

// ------------------------------------------------------------------------------------

// Find the country from the char2Code

function countryByChar2Code (char2Code) {


	for (var i in countries) {
		if (countries[i].char2Code == char2Code)
			return countries[i];
	}
	return null;
}


// ------------------------------------------------------------------------------------

// Outputs all the countries as an html options string
// Include the United states at the beginning as well

function countryOptions () {

	var usa = countryByChar2Code ("US");
	var options = "";
	
	options = '<option value="">Select a country</option>\n';
	options += "<option>" + usa.name + "</option>\n";
	for (var i in countries) {
		options += "<option>" + countries[i].name + "</option>\n";
	}
	return options;
}