

//根据地区选择城市
function change_city(change_select,currently_name){
	
	var i,j=1;
	
	var select1 = document.getElementById(change_select);
	
	//循环对应数组，查找对应的城市值，放如下拉框中
	for(i=0;i<eval(change_select).length;i++){
		if(eval(change_select)[i][2]==currently_name){
			select1.options.length=j;
			select1.options[j-1].value=eval(change_select)[i][1];
			select1.options[j-1].text=eval(change_select)[i][0];
			j=j+1;
		}
	}
	
	//该地区无城市,默认选择所有城市
	if(j==1){
		select1.options.length=1;
		select1.options[0].value=eval(change_select)[0][1];
		select1.options[0].text = eval(change_select)[0][0];
		return false;
	}	
	
	//该地区存在城市,默认选中所有城市
	if(select1.options.length>0 && select1.options[0].value != '0'){
		select1.options.length=select1.options.length+1;
		select1.options[select1.options.length-1].value=eval(change_select)[0][1];
		select1.options[select1.options.length-1].text=eval(change_select)[0][0];
		select1.options[select1.options.length-1].selected="selected";
	}
	
}



//根据省份选择地区和城市
function change_district(change_select1,change_select2,currently_value){
		
	//将参数change_select1和change_select2转换成对应的下拉框
	var select1 = document.getElementById(change_select1);
	var select2 = document.getElementById(change_select2);


	var i,j=1,k=1;
	
	//根据省份获得该省份的所有地区
	for(i=0;i<eval(change_select1).length;i++){
		if(eval(change_select1)[i][2]==currently_value){
			select1.options.length=j;
			select1.options[j-1].value=eval(change_select1)[i][1];
			
			select1.options[j-1].text=eval(change_select1)[i][0];
			j=j+1;
		}
	}


	//如果该省份没有地区，默认所有地区
	if(j==1){
		select1.options.length=1;	
		select1.options[0].value=eval(change_select1)[0][1];
		select1.options[0].text = eval(change_select1)[0][0];
		select2.options.length=1;
		select2.options[0].value=eval(change_select2)[0][1];
		select2.options[0].text = eval(change_select2)[0][0];
		return ;
	}
	
	//获得change_select1下拉框的第一个选项值
//	var new_currently_value=select1.options[0].value;
	
	//根据地区获得所有城市
//	for(i=0;i<eval(change_select2).length;i++){
//		
//		if(eval(change_select2)[i][2]==new_currently_value){
//			select2.options.length=k;
//			select2.options[k-1].value=eval(change_select2)[i][1];
//			select2.options[k-1].text=eval(change_select2)[i][0];
//			k=k+1;
//		}
//	}
	
	//该地区无城市，这默认所有城市
//	if(k==1){
		select2.options.length=1;
		select2.options[0].value=eval(change_select2)[0][1];
		select2.options[0].text = eval(change_select2)[0][0];
//	}
	
	//默认为所有地区
	if((select1.options.length>=1) && (select1.options[0].value!=eval(change_select1)[0][1])){
		select1.options.length=select1.options.length+1;
		select1.options[select1.options.length-1].value=eval(change_select1)[0][1];
		select1.options[select1.options.length-1].text=eval(change_select1)[0][0];
		select1.options[select1.options.length-1].selected="selected";
	}
		
	//默认为所有城市
//	if(select2.options.length>1 && (select2.options[0].value!=eval(change_select2)[0][1])){
//		select2.options.length=select2.options.length+1;
//		select2.options[select2.options.length-1].value=eval(change_select2)[0][1];
//		select2.options[select2.options.length-1].text=eval(change_select2)[0][0];
//		select2.options[select2.options.length-1].selected="selected";
//	}

}


//重置省份、地区、城市
function resetSelect() {
	//省份
	var provinceSelect = document.getElementById("province");
	provinceSelect.options[0].selected = "selected";

	//地区
	var districtSelect = document.getElementById("district");
	districtSelect.options.length = 1;
	districtSelect.options[0].value = eval("district")[0][1];
	districtSelect.options[0].text = eval("district")[0][0];

	//城市
	var citySelect = document.getElementById("city");
	citySelect.options.length = 1;
	citySelect.options[0].value = eval("city")[0][1];
	citySelect.options[0].text = eval("city")[0][0];
}

//根据参数选中、省份、地区、城市
function showinfo(provinceName, districtName, cityName) {
	
	//将参数change_select1和change_select2转换成对应的下拉框
	var provinceSelect = document.getElementById("province");
	var districtSelect = document.getElementById("district");
	var citySelect = document.getElementById("city");
	var i = 0, f, provinceValue, districtValue, cityValue;
	for (i = 0; i < provinceSelect.length; i++) {
		if (provinceSelect.options[i].text == provinceName) {
			provinceSelect.options[i].selected = "selected";
			f = i;
		}
	}
	provinceValue = provinceSelect.options[f].value;
	for (i = 0; i < eval("district").length; i++) {
		if (eval("district")[i][0] == districtName) {
			districtValue = eval("district")[i][1];
		}
	}
	for (i = 0; i < eval("city").length; i++) {
		if (eval("city")[i][0] == cityName) {
			cityValue = eval("city")[i][1];
		}
	}
	change_district("district", "city", provinceValue);
	change_city("city",districtValue);
	for (i = 0; i < districtSelect.length; i++) {
		if (districtSelect.options[i].text == districtName) {
			districtSelect.options[i].selected = "selected";
		}
	}
	for (i = 0; i < citySelect.length; i++) {
		if (citySelect.options[i].text == cityName) {
			citySelect.options[i].selected = "selected";
		}
	}
}

