var targetSelect;

function showProvince(targetSel,http)
{ 
    targetSelect = document.getElementById(targetSel);
   
    $.ajax({
       type: "POST",
       url: http,
       data: null,
       dataType: "xml",
       success: function(xml){
            removeAllOpt(targetSelect);
           
            property = $(xml).find("item");
           
            if(targetSelect.options.length >= 0) {
                targetSelect.options[0] = new Option();
                targetSelect.options[0].value = "0";
                targetSelect.options[0].text = "请选择";
            }
           
            if(property.length >0){//对应的省份有城市信息则显示
                for (var i=0,x=1;i<property.length;i++,x++)
                {
                    name = $("name",property[i]).text();
                    value = $("value",property[i]).text();
                    targetSelect.options[x] = new Option();
                    targetSelect.options[x].value = value;
                    targetSelect.options[x].text = name;
                }
            }
        }
    });
}

function index_showProvince(targetSel,http,proid,cityid,cityname,citySel)
{ 
    targetSelect = document.getElementById(targetSel);
    $.ajax({
       type: "POST",
       url: http,
       data: null,
       dataType: "xml",
       success: function(xml){
            removeAllOpt(targetSelect);
            
            property = $(xml).find("item");
            
            if(cityid!=null&&cityid.length>0){
            	
	            var tagrcitySel = document.getElementById(citySel);
	            removeAllOpt(tagrcitySel);
	            if(tagrcitySel.options.length >= 0) {
	                tagrcitySel.options[0] = new Option();
	                tagrcitySel.options[0].value = cityid;
	                tagrcitySel.options[0].text = cityname;
	            }
            }
            
            if(targetSelect.options.length >= 0) {
                targetSelect.options[0] = new Option();
                targetSelect.options[0].value = "0";
                targetSelect.options[0].text = "请选择";
            }
           
            if(property.length >0){//对应的省份有城市信息则显示
            	
                for (var i=0,x=1;i<property.length;i++,x++)
                {
                    name = $("name",property[i]).text();
                    value = $("value",property[i]).text();
                    targetSelect.options[x] = new Option();
                    targetSelect.options[x].value = value;
                    targetSelect.options[x].text = name;
                    if(parseInt(proid)==parseInt(value)){
                   		targetSelect.options[x].selected=true;
                    }
                }
            }
        }
    });
}

function showCity(sourceSel,targetSel,http)
{
    var prov = document.getElementById(sourceSel);
	var sendData = "provinceId=" + prov.options[prov.selectedIndex].value;
    targetSelect = document.getElementById(targetSel);
   
    $.ajax({
       type: "POST",
       url: http,
       data: sendData,
       dataType: "xml",
       success: function(xml){
            removeAllOpt(targetSelect);
           
            property = $(xml).find("item");
           
            if(targetSelect.options.length >= 0) {
                targetSelect.options[0] = new Option();
                targetSelect.options[0].value = "0";
                targetSelect.options[0].text = "请选择";
            }
           
            if(property.length >0){//对应的省份有城市信息则显示
                for (var i=0,x=1;i<property.length;i++,x++)
                {
                    name = $("name",property[i]).text();
                    value = $("value",property[i]).text();
                    targetSelect.options[x] = new Option();
                    targetSelect.options[x].value = value;
                    targetSelect.options[x].text = name;
                }
            }
        }
    });
}


function removeAllOpt(sel) {
    sel.options.length = 0;
}
