﻿// JScript 文件

 function ddlAreaCode_Show(selectid, selectid2) {
    var obj = document.getElementById('ddlAreaCode_'+selectid);
    var obj2 = document.getElementById('ddlAreaCode_'+selectid2);
    
    if (obj2 == null) { return; } 
        obj2.options.length = 0;
    if (obj.selectedIndex == -1) 
    {
        var newselectid2 = parseInt(selectid2) + 1;
        ddlAreaCode_Show(selectid2, newselectid2);
        return;
    }
    var index = obj.selectedIndex;
    var id = obj.options[index].value;
	for(var j=0;j<AreaMenu.length; j++)
	{
		if(AreaMenu[j][0].toString()==id){
			id = AreaMenu[j][2].toString();
			break;
		}else{
			continue;
		}
	}
	
    if (id.length == 0) 
    {
        var newselectid2 = parseInt(selectid2) + 1;
        ddlAreaCode_Show(selectid2, newselectid2);
     return;
    }
    var op = document.createElement("option"); 
    op.text = "请选择"; 
    op.value = ""; 
    obj2.options.add(op);
    for (var i = 0; i < AreaMenu.length; i++) 
    {
        if (AreaMenu[i][2].substring(0, id.length) == id && AreaMenu[i][2].length == id.length + 3) 
        {
            var op = document.createElement("option"); 
            op.text = AreaMenu[i][1]; 
            op.value = AreaMenu[i][0]; 
            obj2.options.add(op);
         }
    }
            var newselectid2 = parseInt(selectid2) + 1;
            ddlAreaCode_Show(selectid2, newselectid2);
            //alert(newselectid2);
            //填充最后一个控件的默认值
            var opa=document.getElementById("ddlAreaCode_"+newselectid2);
            if(opa){
            var o = document.createElement("option"); 
            o.text = "请选择"; 
            o.value = ""; 
            opa.options.add(o); 
            }  
 }
 
 function setArea1(selectid, selectid2)
 {
    if(selectid==2)//城市 
    {
        var objCity=document.getElementById('ddlAreaCode_2');
        var objCountry=document.getElementById('ddlAreaCode_3');

    }    
    if(selectid==3)//乡镇
    {
        var objCity=document.getElementById('ddlAreaCode_2');
        var objCountry=document.getElementById('ddlAreaCode_3');
        if(objCountry.selectedIndex!=-1)
        {
            document.getElementById('hidCountryName').value=objCountry.options[objCountry.selectedIndex].text;
        }
    }

 }
 
 //获取时给相应的隐藏域赋值，存储修改时使用
 function setArea()
 {
    var objCity=document.getElementById('ddlAreaCode_2');
    var objCountry=document.getElementById('ddlAreaCode_3');
    if(document.getElementById('hidCityID')!=null)
    {
        document.getElementById('hidCityID').value=objCity.value;
    }
    if(document.getElementById('hidCityName')!=null && objCity.length>0)
    {
     if(objCity.options.length>0)
        document.getElementById('hidCityName').value=objCity.options[objCity.selectedIndex].text;
    }
    if(document.getElementById('hidCountryID')!=null)
    {
        document.getElementById('hidCountryID').value=objCountry.value;
    }
    if(objCountry.selectedIndex!=-1)
    {
        document.getElementById('hidCountryName').value=objCountry.options[objCountry.selectedIndex].text;
    }
 }
 
function ddlAreaCode_Default(selectid, val1,val2,val3){
 	var obj = document.getElementById('ddlAreaCode_'+selectid);
	for(var i=0;i<obj.options.length;i++){
		if(obj.options[i].value == val1){
			obj.options[i].selected=true;
			break;
		}
	}
	//二三级开始
	var newselectid = parseInt(selectid) + 1;//下一级
	ddlAreaCode_Show(selectid,newselectid);//显示下一级
	switch(newselectid){
		case  2:
			ddlAreaCode_Default(newselectid, val2,'',val3);//默认值
			break;
		case 3:
			ddlAreaCode_Default(newselectid, val3);
			break;
		case 4:
			break;
		default:
	}
	obj = null;//释放资源
	setArea();
 }
 //调用实例
// ddlAreaCode_Default('1', '236','269',"280");