function locateCountry(id, hiddenId) {
    if (!document.getElementById(id) || !document.getElementById(hiddenId)) {
        return;
    }
    if (document.getElementById(id).disabled == true) {
        return;
    }
    if (document.getElementById(hiddenId).value != '') {
        return;
    }
    if (window.jQuery && !(jQuery.browser.msie && jQuery.browser.version == "6.0")) {
        if (id == 'tag01') {
            jQuery.getScript("http://membercenter.made-in-china.com/account.do?xcase=parseIPToCountryKey", function() {
                adjustPosition(id);
            });
        }
        else if (id == 'tag02') {
            adjustPosition(id);
        }
    }
    else {
        var locationCountryTimerMax = 1700;
        var locationCountryTimer = null;
        var countryContent = document.createElement("script");
        if (id == 'tag01') {
            countryContent.setAttribute("type", "text/javascript");
            countryContent.setAttribute("src", "http://membercenter.made-in-china.com/account.do?xcase=parseIPToCountryKey");
            document.getElementsByTagName("head").item(0).appendChild(countryContent);
        }
        locationCountryTimer = setInterval(function() {
            adjustPosition(id);
            locationCountryTimerMax -= 50;
            if (locationCountryTimerMax < 0) {
                clearInterval(locationCountryTimer);
            }
        }, 50);
    }
    function adjustPosition(id) {
        var response = window.countryKey;
        if (!response) {
            return;
        }
        clearInterval(locationCountryTimer);
        var chinaOption;
        var adjusted;
        if (window.jQuery) {
            emptyOption = jQuery('#' + id).find("option[value='']").eq(0);
            adjusted = false;
            if (response != 'N/A') {
                jQuery('#' + id).find("option").each(function(index) {
                    if (jQuery(this).val() == response) {
                        jQuery(this).attr("selected", true);
                        adjusted = true;
                        return false;
                    }
                });
            }
            if (!adjusted) {
                emptyOption.attr("selected", true);
            }
        }
        else {
            var contrySel = document.getElementById(id);
            for (var i = 0, j = contrySel.length; i < j; i++) {
                if (contrySel[i].value == '') {
                    emptyOption = contrySel[i];
                    break;
                }
            }
            if (response != 'N/A') {
                for (var i = 0, j = contrySel.length; i < j; i++) {
                    if (contrySel[i].value == response) {
                        contrySel[i].selected = true;
                        adjusted = true;
                        break;
                    }
                }
            }
            if (!adjusted) {
                emptyOption.selected = true;
            }
        }
    }
}

