var tld = "";

function getTLD(obj) {
    var str = obj.value;
    tld = str.substring(str.lastIndexOf('.') + 1, str.length);
}

function setSelectCountry(iso2) {
    if (iso2.length != 2)
        return;

    var countrySelect = document.getElementById("contactForm:A7_country");

    iso2 = iso2.toUpperCase();

    if (iso2 == "UK")
        iso2 = "GB";

    if (countrySelect.options[0].selected == true) {
        
        for (var i = 0; i < countrySelect.length; i++) {

            if (iso2 == countrySelect.options[i].value) {
                countrySelect.options[i].selected = true;
                break;
            }
        }

    }
}

function setCountry(obj) {
    getTLD(obj);
    setSelectCountry(tld);
}
