$(document).ready(function() {
    $('#continentList').change(function() {
        var id = $('#continentList option:selected').val();
        $.ajax({
            url:PATH + "ajax.php?noheader=true",
            data:{'type':'xmlCityReader','filter':id},
            type:'POST',
            success:function(data) {
                $('#city_list').html(data);
            }
        });
    });
});


var XmlHttpObj;

function CreateXmlHttpObj() {
    try {
        XmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e) {
        try {
            XmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(oc) {
            XmlHttpObj = null;
        }
    }
    if (!XmlHttpObj && typeof XMLHttpRequest != "undefined") {
        XmlHttpObj = new XMLHttpRequest();
    }
}
function ContinentListOnChange() {
    var continentList = document.getElementById("continentList");

    var selectedContinent = continentList.options[continentList.selectedIndex].value;

    var requestUrl;
    requestUrl = PATH + "ajax.php?type=xmlCityReader&noheader=true&filter=" + encodeURIComponent(selectedContinent);

    CreateXmlHttpObj();

    if (XmlHttpObj) {

        XmlHttpObj.onreadystatechange = StateChangeHandler;

        XmlHttpObj.open("GET", requestUrl, true);

        XmlHttpObj.send(null);
    }
}


function StateChangeHandler() {
    if (XmlHttpObj.readyState == 4) {
        if (XmlHttpObj.status == 200) {
            PopulateCountryList(XmlHttpObj.responseXML.documentElement);
        }
        else {
            alert("problem retrieving data from the server, status code: " + XmlHttpObj.status);
        }
    }
}

function PopulateCountryList(countryNode) {
    var countryList = document.getElementById("city_list");
    for (var count = countryList.options.length - 1; count > -1; count--) {
        countryList.options[count] = null;
    }

    var countryNodes = countryNode.getElementsByTagName('city');
    var idValue;
    var textValue;
    var optionItem;
    for (var count = 0; count < countryNodes.length; count++) {
        textValue = GetInnerText(countryNodes[count]);
        idValue = countryNodes[count].getAttribute("id");
        optionItem = new Option(textValue, idValue, false, false);
        countryList.options[countryList.length] = optionItem;
    }
}

function GetInnerText(node) {
    return (node.textContent || node.innerText || node.text);
}










