var xmlHttp;
function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}

function sendRequest2(url) {
    createXMLHttpRequest();
    xmlHttp.onreadystatechange = county2;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
    
}
function selectProvince2() {
    var province = document.getElementById("city2").value;
    if(province=="0"){
        clearcounty2();
        return;
    }
    var url = "/wuliu/pages/city/county.shtml?reservedAction=countylist&province=" + province;
    sendRequest2(url);
}

function county2(){
	
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
        var dataObj = xmlHttp.responseXML;
//      var citysObj = dataObj.getElementsByTagName("citys")[0];
        var countyObj = dataObj.getElementsByTagName("countys")[0] ;
        //alert(countyObj);
        var countyChild = countyObj.childNodes;
        var length = countyChild.length;
        var countySelect2=document.getElementById("county2");
        var leng=countySelect2.length;
        if(leng>0){
            clearcounty2();
        }
        for (var i = 0; i < length; i++) {
            var text = countyChild[i].getElementsByTagName("countyname")[0].firstChild.nodeValue;
            var optionObj2 = createOption2();
            var optionText = document.createTextNode(text);
            var optionValue=countyChild[i].getElementsByTagName("countyid")[0].firstChild.nodeValue;
            optionObj2.value=optionValue;
            optionObj2.appendChild(optionText);
            countySelect2.appendChild(optionObj2); 
        }
    }
}

function createOption2() {
    var optionObj = document.createElement("option");
    return optionObj;
}

function clearcounty2(){
   var citySelect=document.getElementById("county2");
   var citys=citySelect.childNodes;
    var length=citySelect.length;
    for(var i=0;i<length;i++){
        citySelect.removeChild(citys[0]);
    }
}
