﻿

// Data & function(s) for ISO 3166-1 country names and codes


// Get HTML for a list of Select options of ISO 3166-1 country names and codes.
// eg "<option value="GB">United Kingdom</option>
//     <option value="US" SELECTED>United States</option>"
// Parameters: strSelectedValue is a value that will be marked as "SELECTED" 
//             if it is found in the options list
function getCountryOptionsListHtml(strSelectedValue) {
    var strCountryOptionsList = '<option value="">Please select...</option>\n';
    for (var i = 0; i < countries.length; i++) {  
        strCountryOptionsList += '<option value="' + countries[i].code + '"'
        if (strSelectedValue == countries[i].code) {
            strCountryOptionsList += " SELECTED"
        }
        strCountryOptionsList += ">" + countries[i].name + "</option>\n";
    }
    return strCountryOptionsList;
}


// Get the country name for a given code.
function getCountryName(strCountryCode) {
    for (var i = 0; i < countries.length; i++) {  
        if (strCountryCode == countries[i].code) {
            return countries[i].name;
        }
    }
    return "";
}


// ISO 3166-1 country names and codes from http://opencountrycodes.appspot.com/javascript		
countries = [
    {code: "GB", name: "England"},
	{code: "IE", name: "Eire"},
	{code: "IE", name: "Northern Ireland"},
	{code: "GB", name: "Scotland"},
	{code: "GB", name: "Wales"}
    
];
