/*
地区操作
create by:shenjk
http://www.shenjk.com
*/
/*引用地区基础数据*/
document.write('<script language="javascript" src="\http://china.jagol.com/scripts\/address.js"><\/script>');
/*以下地区操作函数实例*/
function InitAddress(countryall,country,provice,city,section,txtprovice,txtcity){
	this.countryall=countryall;
	this.country=country;
	this.provice=provice;
	this.city=city;
	this.section=section;
	this.txtprovice=txtprovice;
	this.txtcity=txtcity;
	if(arguments.length>7){
		this.InitStartSelect(arguments[7],arguments[8],arguments[9],arguments[10]);
	}else{
		this.InitStartSelect();
	}
	this.country.onchange=function(){
		if(this.value=='其他国家或地区'){
			countryall.style.display='';
			txtprovice.parentNode.style.display='';
			txtcity.parentNode.style.display='';
			provice.style.display='none';
			city.style.display='none';
			section.style.display='none';
			this.style.display='none';
		}else if(this.value!='中国' && this.value.substring(0,2)=='中国'){
			txtprovice.parentNode.style.display='';
			txtcity.parentNode.style.display='none';
			provice.style.display='none';
			city.style.display='none';
			section.style.display='none';
		}else{
			txtprovice.parentNode.style.display='none';
			txtcity.parentNode.style.display='none';
			provice.style.display='';
			city.style.display='';
			section.style.display='';
		}
		if(countryall.value.substring(0,2)=='中国'){
			countryall.selectedIndex=0;
		}
		Show_Adr();
		AddValidator(provice,city,section,txtprovice,txtcity);//加入验证
	}
	this.countryall.onchange=function(){
		if(this.value=='中国'){
			country.value=this.value;
			country.style.display='';
			provice.style.display='';
			city.style.display='';
			section.style.display='';
			txtprovice.parentNode.style.display='none';
			txtcity.parentNode.style.display='none';
			this.style.display='none';
		}else if(this.value!='中国' && this.value.substring(0,2)=='中国'){
			txtcity.parentNode.style.display='none';
			country.value=this.value;
			country.style.display='';
			this.style.display='none';
		}else{
			txtcity.parentNode.style.display='';
		}
		Show_Adr();
		AddValidator(provice,city,section,txtprovice,txtcity);//加入验证
	}
	this.provice.onchange=function(){
		if(this.value!=''){
			var tempprovice=texttovalue(ary_provice,this.value);
			var k=0;
			city.options.length=1;
			for(var i=0;i<ary_city.length;i++){
				if(ary_city[i][2]==tempprovice){
					city.options[k+1]=new Option(ary_city[i][1],ary_city[i][1]);
					k++;
				}
			}
			section.options.length=1;
		}else{
			city.options.length=1;
			section.options.length=1;
		}
		Show_Adr();
		AddValidator(provice,city,section,txtprovice,txtcity);//加入验证
	}
	this.city.onchange=function(){
		if(this.value!=''){
		var tempcity=texttovalue(ary_city,this.value);
		var k=0;
			for(var i=0;i<ary_city.length;i++){
				if(ary_city[i][2]==tempcity){
					section.options[k+1]=new Option(ary_city[i][1],ary_city[i][1]);
					k++;
				}
			}
		}else{
			section.options.length=1;
		}
		Show_Adr();
		AddValidator(provice,city,section,txtprovice,txtcity);//加入验证
	}
}

InitAddress.prototype.InitStartSelect=function(){
	for(var i=0;i<ary_country.length;i++){
		var tmpreg=/^[\u0391-\uFFE5]+$/;
		if(tmpreg.test(ary_country[i][1])){
			this.country.options[this.country.options.length]=new Option(ary_country[i][1],ary_country[i][1]);				
		}
	}
	for(var i=0;i<ary_country.length;i++){
		this.countryall.options[i]=new Option(ary_country[i][1],ary_country[i][1]);
	}
	this.provice.options[0]=new Option("省份",'');
	for(var i=0;i<ary_provice.length;i++){
		this.provice.options[i+1]=new Option(ary_provice[i][1],ary_provice[i][1]);
	}
	this.city.options[0]=new Option('地级市','');
	this.section.options[0]=new Option('市，县级市，县','');
	if(arguments.length>0){
		if(arguments[0]=='中国'){	
			this.countryall.style.display='none';
			this.country.style.display='';		
			this.provice.value=arguments[1];
			var tempprovice=texttovalue(ary_provice,this.provice.value);
			var k=0;
			for(var i=0;i<ary_city.length;i++){
				if(ary_city[i][2]==tempprovice){
					this.city.options[k+1]=new Option(ary_city[i][1],ary_city[i][1]);
					k++;
				}
			}
			this.city.value=arguments[2];
			var tempcity=texttovalue(ary_city,this.city.value);
			var k=0;
			for(var i=0;i<ary_city.length;i++){
				if(ary_city[i][2]==tempcity){
					this.section.options[k+1]=new Option(ary_city[i][1],ary_city[i][1]);
					k++;
				}
			}
			this.section.value=arguments[3];
		}else if(arguments[0]!='中国' && arguments[0].substring(0,2)=='中国'){
			this.countryall.style.display='none';
			this.country.style.display='';
			this.country.value=arguments[0];
			this.txtprovice.parentNode.style.display='';
			this.provice.style.display='none';
			this.city.style.display='none';
			this.section.style.display='none';
			this.txtprovice.value=arguments[1];
		}else{
			this.country.style.display='none';
			this.countryall.style.display='';
			this.countryall.value=arguments[0];
			this.txtprovice.parentNode.style.display='';
			this.txtcity.parentNode.style.display='';
			this.provice.style.display='none';
			this.city.style.display='none';
			this.section.style.display='none';
			this.txtprovice.value=arguments[1];
			this.txtcity.value=arguments[2];
		}
	}else{
		this.countryall.style.display='none';
	}
	Show_Adr();
	AddValidator(this.provice,this.city,this.section,this.txtprovice,this.txtcity);
}

function texttovalue(ary,str){
	var ret='';
	for(var i=0;i<ary.length;i++){
		if(ary[i][1]==str){
			ret=ary[i][0];
			break;
		}
	}
	return ret;
}
/*
加入验证
*/
function AddValidator(provice,city,section,txtprovice,txtcity){
	return;
	if(provice.style.display!='none' && IsValidate<2){
		provice.setAttribute("dataType","Require");
		provice.setAttribute("msg","请选择省份");
	}else{
		if(provice.getAttribute('dataType')!=null)	
			provice.removeAttribute('dataType');
		if(provice.getAttribute('msg')!=null)
			provice.removeAttribute('msg');
	}
	if(IsValidate==1){
		if(city.style.display!='none'){
			city.setAttribute("dataType","Require");
			city.setAttribute("msg","请选择城市");
		}else{
			if(city.getAttribute('dataType')!=null)
				city.removeAttribute('dataType');
			if(city.getAttribute('msg')!=null)
				city.removeAttribute('msg');
		}
		if(section.style.display!='none' && section.options.length>1 && adr_catetype!=2){
			section.setAttribute("dataType","Require");
			section.setAttribute("msg","请选择县区");
		}else{
			if(section.getAttribute('dataType')!=null)
				section.removeAttribute('dataType');
			if(section.getAttribute('msg')!=null)
				section.removeAttribute('msg');
		}
	}
	if(txtprovice.parentNode.style.display!='none' && adr_catetype!=2){
		txtprovice.setAttribute("dataType","Require");
		txtprovice.setAttribute("msg","请填写城市地区");
	}else{
		if(txtprovice.getAttribute('dataType')!=null)
			txtprovice.removeAttribute('dataType');
		if(txtprovice.getAttribute('msg')!=null)
			txtprovice.removeAttribute('msg');
	}
	if(txtcity.parentNode.style.display!='none' && adr_catetype!=2){
		txtcity.setAttribute("dataType","Require");
		txtcity.setAttribute("msg","请填写城市地区");
	}else{
		if(txtcity.getAttribute('dataType')!=null)
			txtcity.removeAttribute('dataType');
		if(txtcity.getAttribute('msg')!=null)
			txtcity.removeAttribute('msg');
	}
}


function Show_Adr(){
	if(adr_catetype==1){
		document.getElementById('adr_section').style.display='none';
		document.getElementById('adr_country').style.display='none';
	}else if(adr_catetype==2){
		document.getElementById('adr_section').style.display='none';
	}
}
/*
应用实例:
<select id="adr_countryall"></select>
<select id="adr_country"></select>
<select id="adr_provice"></select>
<select id="adr_city"></select>
<select id="adr_section"></select>
<div style="display:none"><input type="text" id="adr_txtprovice"/>(*省)</div>
<div style="display:none"><input type="text" id="adr_txtcity"/>(*市)</div>
<script language="javascript">
	var country=document.getElementById('adr_country');
	var provice=document.getElementById('adr_provice');
	var city=document.getElementById('adr_city');
	var section=document.getElementById('adr_section');
	var txtprovice=document.getElementById('adr_txtprovice');
	var txtpcity=document.getElementById('adr_txtcity');
	new InitAddress(document.getElementById('adr_countryall'),country,provice,city,section,txtprovice,txtpcity);
</script>
*/