//this city function 
//省份ID,城市ID,商业区ID,行政区ID,第二商业区ID,指定省份值,指定城市值,指定行政区,指定商业区,指定第二商业区
//全局函数 showprovince()
//行政区与商业区单独使用函数 Districts(行政区ID,商业区ID,指定城市值,指定行政区,指定商业区)
//第二商业区单独使用函数     OtherDistrict(第二商业区指定ID,指定城市值,指定第二商业区值)

function showprovince(ProvinceID,CityID,District1ID,District2ID,District3ID,SelectedProvince,SelectedCity,SelectedDistrict1,SelectedDistrict2,SelectedDistrict3)
{
	
document.getElementById(ProvinceID).options.length=ProvinceValue.length//设置省份列表框长度ProvinceText==ProvinceValue

for(var i=0;i<ProvinceValue.length;i++)
{

document.getElementById(ProvinceID).options[i]=new  Option(ProvinceText[i],ProvinceValue[i]);//赋值
}
document.getElementById(ProvinceID).options[1].selected=true;

if(SelectedProvince!=null)//选中已有省份
{
for(var  i=0;i<document.getElementById(ProvinceID).options.length;i++)
{
						if ((document.getElementById(ProvinceID).options[i].value.indexOf(SelectedProvince))!=-1)
							{
							 //alert(CityNamevalue+OptionName.options[i].text)
							 document.getElementById(ProvinceID)[i].selected=true
							 //  change(省份，酒店ID,设置区域开关证明有选中城市值(，城市,行政区，商业区,当这么参数为NULL时不被初行))
 							 change(ProvinceID,CityID,District1ID,District2ID,District3ID,SelectedProvince,SelectedCity,SelectedDistrict1,SelectedDistrict2,SelectedDistrict3);
							 break
							}
					}
}
else
	{
	change(ProvinceID,CityID,District1ID,District2ID,District3ID,document.getElementById(ProvinceID).options[1].value,null,null,null,null);//没有要选中的省份中和城市，默认选项中值以1开头
	}
			
			
}

function change(ProvinceID,CityID,District1ID,District2ID,District3ID,SelectedProvince,SelectedCity,SelectedDistrict1,SelectedDistrict2,SelectedDistrict3)
{
	
//*******省份Selected设置********	
				for(var  z=0;z<document.getElementById(ProvinceID).length;z++)
				{

				if ((document.getElementById(ProvinceID)[z].value.indexOf(SelectedProvince))!=-1)
					
				{

				document.getElementById(ProvinceID)[z].selected=true

				break
				}
				}
//*******省份Selected设置结束********


	document.getElementById(CityID).options.length=ProvinceText[SelectedProvince].length//设置城市列表框长度
	for(var x=0;x<ProvinceText[SelectedProvince].length;x++)
	{
	document.getElementById(CityID).options[x]=new  Option(ProvinceText[SelectedProvince][x],ProvinceValue[SelectedProvince][x]);//赋值
	}

	if(SelectedCity!=null)//有指定/选中城市
			{ 
			//alert(SelectedCity)
				for(var  i=0;i<document.getElementById(CityID).options.length;i++)
				{
						//alert(document.getElementById(CityID).options[i].value)
					if ((document.getElementById(CityID).options[i].value.indexOf(SelectedCity))!=-1)
					
				{
								 //alert(CityNamevalue+OptionName.options[i].text)
						 document.getElementById(CityID)[i].selected=true
							    // change(SelectedProvince,PCityID,1,SelectedCity,SelectedDistrict1,SelectedDistrict2);
					break
				}
				}
			}
	 else
	 {
	 document.getElementById(CityID)[0].selected=true //没有指定/选择城市时使用首选值
	 }	 
	 //启用商业区域与行政区域
	 if(District1ID!=null)
	 {
	  Districts(District1ID,District2ID,document.getElementById(CityID).value,SelectedDistrict1,SelectedDistrict2)
	 }
	 //启用第二商业区域
	 if(District3ID!=null)
	 {
	   OtherDistrict(District3ID,document.getElementById(CityID).value,SelectedDistrict3)
	 }	 
}
//用户直接输入城市信息
function TextCityWrite(District1ID,District2ID,WriteCity,CityID)
{
			document.getElementById(CityID).options.length=1
			document.getElementById(CityID).options[0]=new Option(WriteCity,WriteCity);
			document.getElementById(CityID).options[0].selected=true;
			Districts(District1ID,District2ID,WriteCity,null,null)//查找用户输入城市区域
	
}
//用户直接输入城市信息


// JavaScript Document
function Districts(District1ID,District2ID,CityValue,SelectedDistrict1,SelectedDistrict2)
{
var DistrictSelect =document.getElementById(District1ID)//行政区
var DistrictSelect2=document.getElementById(District2ID)//商业区
var S1Text=DistrictSelect.options[0].text
var S2Text=DistrictSelect2.options[0].text
 //设置行政区初始
	for(var  i=0;i<DistrictSelect.options.length;i++)
	{
		 DistrictSelect.removeChild(DistrictSelect.options[i])
		 
		 //CityNumbers.value=OptionName.options[i].value
		
		 //break
	}
	DistrictSelect.options.length=1
	DistrictSelect.options[0]=new Option(S1Text,'')//商业区
 //设置行政区初始结束	
 
  //设置商业区初始
	for(var  i=0;i<DistrictSelect2.options.length;i++)
	{
		 DistrictSelect2.removeChild(DistrictSelect2.options[i])
		 
		 //CityNumbers.value=OptionName.options[i].value
		
		 //break
	}
	DistrictSelect2.options.length=1
	DistrictSelect2.options[0]=new Option(S2Text,"")//商业区
  
  //设置行政区初始结束
    var Check=0//设置开关当有选项中值时不再循环  	
	for(var s=0;s<D1City.length;s++)//循环需要商业区的城市
		{
			if(D1City[s]==CityValue)//当找到商业城市值时
				{
					for (var i=0;i<District[CityValue].length;i++)
					  {
						   if (i==0)
						   {
							DistrictSelect.options[i]=new Option(S1Text.replace("行政区","不限"),'')//商业区   
						   }
					   else
						   {
							DistrictSelect.options[i]=new Option(District[CityValue][i][1],District[CityValue][i][1])//添加行政区下拉列值
							}
							if(SelectedDistrict1!=null&&Check==0)//判断是否有指定行政区值，有则需要设置为selected
							{
								if((District[CityValue][i][1].indexOf(SelectedDistrict1))!=-1)
							    {
								 DistrictSelect.options[i].selected=true
								 Check=1
							    }
							}
					  }
				break	  
				}
		}
    var Check2=0//设置开关当有选项中值时不再循环
	for(s=0;s<D2City.length;s++)
		{  
			if(D2City[s]==CityValue)
				{
					for (var i=0;i<District2[CityValue].length;i++)
					{
					   if (i==0)
					   {
						DistrictSelect2.options[i]=new Option(S2Text.replace("商业区","不限"),'')//商业区   
					   }
					   else
					   {
					    DistrictSelect2.options[i]=new Option(District2[CityValue][i][1],District2[CityValue][i][1])//商业区
					   }
					   if(SelectedDistrict2!=null&&Check2==0)//判断是否有指定商业区值，有则需要设置为selected
							{
							 if((District2[CityValue][i][1].indexOf(SelectedDistrict2))!=-1)
							    {
								 DistrictSelect2.options[i].selected=true
								 Check2=1//关闭开关
								}
							}					  
					  }

				break	  
				}
				
		}
}		

//第二商业区
function OtherDistrict(DistrictSelect3ID,CityValue,SelectedDistrict)
{
    var DistrictSelect3=document.getElementById(DistrictSelect3ID)
 //alert (DistrictSelect3.value)
 //设置行政区初始
	for(var  i=0;i<DistrictSelect3.options.length;i++)
	{
		DistrictSelect3.removeChild(DistrictSelect3.options[i])
		 
		 //CityNumbers.value=OptionName.options[i].value
		
		 //break
	}
	DistrictSelect3.options.length=1
	DistrictSelect3.options[0]=new Option("-----不限-----",'')//初始值为空
 //设置行政区初始结束	
 
  //设置商业区初始
	for(var  i=0;i<DistrictSelect3.options.length;i++)
	{
	DistrictSelect3.removeChild(DistrictSelect3.options[i])
		 
		 //CityNumbers.value=OptionName.options[i].value
		
		 //break
	}
	DistrictSelect3.options.length=1
	DistrictSelect3.options[0]=new Option("-----不限-----","")//商业区
  
  //设置行政区初始结束
    var Check3=0//设置开关当有选项中值时不再循环  	
	for(var s=0;s<D3City.length;s++)//循环需要商业区的城市
		{
		if(D3City[s]==CityValue)//当找到商业城市值时
			{
			for (var i=0;i<District3[CityValue].length;i++)
				{
				if (i==0)
				{
				DistrictSelect3.options[i]=new Option('-----不限-----','')//商业区   
				}
				else
				{
				DistrictSelect3.options[i]=new Option(District3[CityValue][i][1],District3[CityValue][i][1])//添加行政区下拉列值
				
							if(SelectedDistrict!=null&SelectedDistrict!=''&Check3==0)//判断是否有指定行政区值，有则需要设置为selected
						    {
								if((District3[CityValue][i][1].indexOf(SelectedDistrict))!=-1)
								  {
								 DistrictSelect3.options[i].selected=true
								 Check=1
								  }
				            }
				}
				  
				}
		break	
		}
		}

}	



function showDistrict(sImg,Scid,Noimg)
{
	if(isFirefox=navigator.userAgent.indexOf("Firefox")>0)//FF下列表框会自动增宽,将不应用自定义增长框架
	{ 
	//return
	} 
    //document.getElementById('DistrictSelect2').onBlur
	var oImg=document.getElementById(sImg);
	var oCid=document.getElementById(Scid);
	if(!oImg){alert("控制对象不存在！");return;}
	if(!oCid){alert("控制对象不存在！");return;}	
	var eT=0,eL=0,p=oImg;
	var sT=document.body.scrollTop,sL=document.body.scrollLeft;
	var eH=oImg.height,eW=oImg.width;	
	var bH=document.body.clientHeight
	var bW=document.body.clientWidth
    //alert(p.offsetLeft)
	while(p&&p.tagName!="BODY"){eT+=p.offsetTop;eL+=p.offsetLeft;p=p.offsetParent;}
	{
	if(!Noimg)
	oCid.style.top=eT

	else
	{
	oCid.style.top=eT
	}
	}

	oCid.style.left=eL+88;


	if(Number(eL)>800)
	{

	//oCid.style.left=eL-(oCid.style.width).replace("px","");
	}
	oCid.style.display="block";

}
	//document.write('<iframe id="SetDistrict" src="/hotels/district.html"  name="SetDistrict"  frameborder="0" style="display:none;position:absolute;z-index:108;width:98px;" ondblclick="this.style.display=\''+'none'+'\'" ></iframe>')

function WriteDistrict()
{
		var   City=document.getElementById('city').value
		var   C=-1
		var   TableWidth=0
		var   TableWidthStr=""	
		var   TdBgColor=""
		var   SetDistrictHtml=""
		if (!document.getElementById('SetDistrict')){
		document.write('  <div id="SetDistrict" style="display:none;position:absolute;z-index:99;background-color:#ffffff;border:solid #ccc 1px" ondblclick="this.style.display=\''+'none'+'\'" ></div>')
		}

	  
	  SetDistrictHtml+=('  <table  width="100%"  border="0" cellpadding="0" >')
	  SetDistrictHtml+=('  <tr>')
	  SetDistrictHtml+=('  <td  align="left" valign="top" bgcolor="#ffffff" style="word-break:break-all">')
	  SetDistrictHtml+=('  <table width="100%"  border="0" cellpadding="0" cellspacing="0">')
      SetDistrictHtml+=('  <tr><td  height=20  style="word-break:break-all;background-color:#67a1e2;padding-left:10px;" colspan=6><A href="javascript:SetInput(\''+''+'\',3)"><font  style="font-size:12px;color:#fff">选择酒店所在地理位置</font></A></td></tr>')	  	  
      SetDistrictHtml+=('  <tr><td  height=20  style="word-break:break-all;border-bottom:dashed #999 1px;padding-left:10px" colspan=4 align="left"><font style="font-size:12px;color:#999">商业区</font></td></tr>')	  	  		
    



	  if(District2[City])
	  {
	  //alert(District2[City].length)

	  if(District2[City].length>1){
	  for(var s=1;s<District2[City].length;s++)
	  {
	  //取余
	  C=C+1
	  Mod=eval(C%3)
	  TdBgColor=""
      if (C!=0&&(Mod==0))
	  {

	  
	  
      SetDistrictHtml+=('  </tr><tr>')	
	  
	  //TdBgColor="#E7F3FE"
	  }

	  s>0?SetDistrictHtml+=(' <td height=20 style="word-break:break-all;padding:5px;background-color:'+TdBgColor+';"><A href="javascript:SetInput(\''+District2[City][s][1]+'\',1)" class=black>'+District2[City][s][1]+'</a></td>'):true
	        
	  if((District2[City][s][1].length)>TableWidth)
	  {
	  TableWidth=District2[City][s][1].length
  
	  }	  
	  }
	  }
	  }
	  //alert(TableWidth)
	  var SetDistrictWidth=Number(TableWidth*8*5)

	  if(SetDistrictWidth<400)
	  {
	  SetDistrictWidth=400
	  } 
      SetDistrictHtml+=('</table></td>')
      SetDistrictHtml+=('</tr>')
	  SetDistrictHtml+=('</table>')

	  C=-1
	  SetDistrictHtml+=('  <table  width="100%"  border="0" cellpadding="0"  >')
	  SetDistrictHtml+=('  <tr>')
	  SetDistrictHtml+=('  <td  align="left" valign="top" bgcolor="#ffffff" style="word-break:break-all">')
	  SetDistrictHtml+=('  <table width="100%"  border="0" cellpadding="0" cellspacing="0">')

      SetDistrictHtml+=('  <tr><td  height=20  style="word-break:break-all;border-bottom:dashed #999 1px;padding-left:10px" colspan=6 align="left"><font style="font-size:12px;color:#999">行政区</font></td></tr>')	  		
        //document.write('  <tr>')	

	  if(District[City])
	  {
	  //alert(District2[City].length)

	  if(District[City].length>1){
	  for(var s=1;s<District[City].length;s++)
	  {
	  //取余
	  C=C+1
	  Mod=eval(C%6)
	  TdBgColor=""
      if (C!=0&&(Mod==0))
	  {

      SetDistrictHtml+=('  </tr><tr>')			  
	  //TdBgColor="#E7F3FE"
	  }

	  s>0?SetDistrictHtml+=(' <td height=20 style="word-break:break-all;padding:5px;background-color:'+TdBgColor+'"><A href="javascript:SetInput(\''+District[City][s][1]+'\',0)"  >'+District[City][s][1]+'</a></td>'):true
	        
	  if((District[City][s][1].length)>TableWidth)
	  {
	  TableWidth=District[City][s][1].length
  
	  }	  
	  }
	  }
	  }
	  SetDistrictHtml+=('  </tr><tr>')
      SetDistrictHtml+=('</table></td>')
      SetDistrictHtml+=('</tr>')
	  SetDistrictHtml+=('</table>')
	  	  
	 
	  
	  document.getElementById('SetDistrict').innerHTML=SetDistrictHtml
	  document.getElementById('SetDistrict').style.width=SetDistrictWidth
	  document.getElementById('DistrictInput').focus();
	

}


	  function hideWriteDistrict()
	  {
	  if (!(document.activeElement.name)&&document.activeElement.name!='DistrictInput'&&document.getElementById('DistrictInput')){
	  document.getElementById('SetDistrict').style.display='none'
	  }
	  }

	  function Set(PostValue)
	  {
	  var   City=document.getElementById('City').value
	  Districts('DistrictSelect','DistrictSelect2',City,null,PostValue)
	  document.getElementById('DistrictSelect2').disabled=false
	  document.getElementById('SetDistrict').style.display='none'
	  }
	  
	  function SetInput(PostValue,PostNum)
	  {
	  var   City=document.getElementById('city').value
	  if (PostValue!="")
	  {
		  if (PostNum==0)
			  {
			  document.getElementById('DistrictInput').value=PostValue
			 // Districts('DistrictSelect','DistrictSelect2',City,PostValue,null)
			  document.getElementById('District1').value=PostValue
			  document.getElementById('District2').value=''			  
			  document.getElementById('SetDistrict').style.display='none'
			  }
		  else
			  {
			  document.getElementById('DistrictInput').value=PostValue
			 // Districts('DistrictSelect','DistrictSelect2',City,null,PostValue)
			 // document.getElementById('DistrictSelect').disabled=false
			  document.getElementById('District1').value=''				 
			  document.getElementById('District2').value=PostValue			 
			  document.getElementById('SetDistrict').style.display='none'		  
			  }
	  }
	  else
	  {
			  document.getElementById('District1').value=''				 
			  document.getElementById('District2').value=''			  
			  document.getElementById('DistrictInput').value='';
  			  document.getElementById('SetDistrict').style.display='none'		
	  }	  
	  }
	  

