var parent;
var sub;
var parent_value = "0";
var sub_value 	 = "0";

function InitLinkedSelect(select1,select2,index1,index2){
	parent = document.getElementById(select1);
	sub = document.getElementById(select2)
	parent_value = index1;
	sub_value = index2;
	LoadParentSelect();
	parent.onchange = LoadSubSelect;
}
function InitSingleSelect(select1,index1){
	var p = document.getElementById(select1);
	try{
    	var valuelist = eval("pid" + ".split('#')");
    	var textlist = eval("pname" + ".split('#')");
    	p.options.length = valuelist.length+1;
		p.options[0].value = 0;
    	p.options[0].text = "ÇëÑ¡Ôñ...";
    	for(var i=1; i<valuelist.length+1; i++){
    		p.options[i].value = valuelist[i-1];
    		p.options[i].text = textlist[i-1];
			if(valuelist[i-1]==index1){
    			p.selectedIndex = i;
    		}
    	}
    	LoadSubSelect(); 
	}catch(e){}
}
function LoadParentSelect(){
	try{
    	var valuelist = eval("pid" + ".split('#')");
    	var textlist = eval("pname" + ".split('#')");
    	parent.options.length = valuelist.length+1;
		parent.options[0].value = 0;
    	parent.options[0].text = "ÇëÑ¡Ôñ...";
    	for(var i=1; i<valuelist.length+1; i++){
    		parent.options[i].value = valuelist[i-1];
    		parent.options[i].text = textlist[i-1];
			if(valuelist[i-1]==parent_value){
    			parent.selectedIndex = i;
    		}
    	}
    	LoadSubSelect(); 
	}catch(e){}
}

function LoadSubSelect(){
	try{
    	var valuecode = parent.options[parent.selectedIndex].value;
    	if(valuecode!=0){    	
	    	var valuelist = eval("pid" + valuecode + ".split('#')");
	        var textlist = eval("pname" + valuecode + ".split('#')");
	    	sub.options.length = valuelist.length + 1;
	    	sub.options[0].value = 0;
    		sub.options[0].text = "ÇëÑ¡Ôñ...";
	    	for(var i=1; i<valuelist.length+1; i++){
	    		sub.options[i].value = valuelist[i-1];
	    		sub.options[i].text = textlist[i-1];
	    		if(valuelist[i-1]==sub_value){
	    			sub.selectedIndex = i;
	    		}
	        }
        }else{
        	sub.options.length = 1;
    		sub.options[0].value = 0;
    		sub.options[0].text = "ÇëÑ¡Ôñ...";
        }
	}catch(ee){}
}
function getProvince(param){
	try{
    	var valuelist = eval("pid" + ".split('#')");
    	var textlist = eval("pname" + ".split('#')");
    	for(var i=0; i<valuelist.length; i++){
			if(valuelist[i]==param){
    			return textlist[i];
    		}
    	}
    	return
	}catch(e){}
}
function getCity(param1,param2){
	try{
    	if(param1>0){
	    	var valuelist = eval("pid" + param1 + ".split('#')");
	        var textlist = eval("pname" + param1 + ".split('#')");
	    	for(var i=0; i<valuelist.length; i++){
	    		if(valuelist[i]==param2){
	    			return textlist[i];
	    		}
	        }
        }
		return;
	}catch(ee){}
}