

//点击列表时，所有的Radio变为非选中状态
function SelectionFocused(radioCtrl){
    for(i=0;i<radioCtrl.length;i++)
      radioCtrl[i].checked=false;
}

//点击radio时，清空列表 
function clearM(){
	document.getElementById("worldCity").length = 0;	
}


//选择国家后，动态在目标控件中载入城市	
function SelectCoutry(targetCountryID,targetCtrl){
    	if(targetCountryID=="")
    	{
          targetCtrl.options.length=0; 
          targetCtrl.selectedIndex = -1;	
    	  return;
    	}
    	
       	
		var itemArray = eval("CityList" + targetCountryID);
			
		
		for(i = targetCtrl.options.length;i>=0;i--)
		{
			targetCtrl.options[i] = null;
		}
		
		LoadList(itemArray,targetCtrl);
		targetCtrl.selectedIndex=0;
      
}

//将选择移动到index－1行
function SelectItem(Ctrl,index){
  Ctrl.selectedIndex = index;
}

//Bug6191
function OnRadioClick(cityID){
      
   
   if(document.HotSrch.CountrySelection.selectedIndex == -1) return;
   document.HotSrch.CountrySelection.selectedIndex = -1;
   document.HotSrch.CitySelection.options.length=0;
  
}

//***********以下方法进行首页人数＆房间数的逻辑处理

//李军20050915
//这段程序房间数，儿童数，每间房儿童的年龄的关联问题
//儿童显示程序
//这一段，用来设置儿童1到儿童6的文字是否显示.
var child0=new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);//临时数组
var child1=new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
var child2=new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
var child3=new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
var child4=new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
var child5=new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
var child6=new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
var elongFlag=true;//新增,满足开发需求。20051123.
//显示每间房屋儿童的年龄
function showChild(whichUL,whichLI,totalLI)
{ //alert(whichUL+":"+whichLI+":"+totalLI);
  var i=0;
  document.getElementById("yd1UL"+whichUL).style.display=whichLI==0?"none":"block"; 
  
  for(i=0;i<=totalLI-1;i++)
  {
   if(i<=whichLI)
   {
   
     
     
   document.getElementById("yd1UL"+whichUL+"_"+i).style.display="block";
    eval("child"+i)[whichUL-1]=1;
   }
   else
   {document.getElementById("yd1UL"+whichUL+"_"+i).style.display="none";
    eval("child"+i)[whichUL-1]=0; 
   }
  } 
  
var showchild1=child1[0]||child1[1]||child1[2]||child1[3]||child1[4]||child1[5]||child1[6]||child1[7]||child1[8]||child1[9]||child1[10]||child1[11]||child1[12]||child1[13]||child1[14];
var showchild2=child2[0]||child2[1]||child2[2]||child2[3]||child2[4]||child2[5]||child2[6]||child2[7]||child2[8]||child2[9]||child2[10]||child2[11]||child2[12]||child2[13]||child2[14];
var showchild3=child3[0]||child3[1]||child3[2]||child3[3]||child3[4]||child3[5]||child3[6]||child3[7]||child3[8]||child3[9]||child3[10]||child3[11]||child3[12]||child3[13]||child3[14];
var showchild4=child4[0]||child4[1]||child4[2]||child4[3]||child4[4]||child4[5]||child4[6]||child4[7]||child4[8]||child4[9]||child4[10]||child4[11]||child4[12]||child4[13]||child4[14];
var showchild5=child5[0]||child5[1]||child5[2]||child5[3]||child5[4]||child5[5]||child5[6]||child5[7]||child5[8]||child5[9]||child5[10]||child5[11]||child5[12]||child5[13]||child5[14];
var showchild6=child6[0]||child6[1]||child6[2]||child6[3]||child6[4]||child6[5]||child6[6]||child6[7]||child6[8]||child6[9]||child6[10]||child6[11]||child6[12]||child6[13]||child6[14];
document.getElementById("yd1UL0").style.display=showchild1?"block":"none";
document.getElementById("yd1UL0_0").style.display=showchild1?"block":"none";

for(j=1;j<=6;j++)
{
   document.getElementById("yd1UL0_"+j).style.display=eval("showchild"+j)?"block":"none";
}

if(showchild1||showchild2||showchild3||showchild4||showchild5||showchild6)
{
   document.getElementById("childTr").style.background="#F4FCFF";
   document.getElementById("yd1UL").style.display="block";
}
else
{
   document.getElementById("childTr").style.background="#ffffff";
   document.getElementById("yd1UL").style.display="none";
}

//如果不显示儿童，则年龄置为-?-
setChildByStatus(whichUL);

}

//如果不显示儿童，则年龄置为-?-
function setChildByStatus(i)
{
      var obj1;
      for(var j=1;j<=6;j++)
      {
		if(document.getElementById('yd1UL'+i+'_'+j).style.display == 'none')
		{
	         
			obj1= eval('document.HotSrch.child_age_'+i+'_'+j);
	         
			obj1.selectedIndex = 0;
			 
		}
      }
}

function restoreStatus()
{
  document.HotSrch.RoomNum.onchange(); 
  var obj,obj1,obj2;
  for(var i=1;i<=5;i++)//roomNum
  {
    if(document.getElementById('yd1Table'+i).style.display != 'none')
    {
       obj = eval('document.HotSrch.child_room'+i);
       obj.onchange();
    } 
   
  }
}

function setChildValueByDisplayStatus()
{
  var obj1;
  for(var i=1;i<=5;i++)
  {
    for(var j=1;j<=6;j++)
    {
      if(document.getElementById('yd1UL'+i+'_'+j).style.display == 'none')
      {
         
         obj1= eval('document.HotSrch.child_age_'+i+'_'+j);
         
         obj1.selectedIndex = 0;
		 
      }
    }
  }
}


function showRoom(objId,objTotal){ 
//alert("asdfasfhadfj");
 var i=1;
 for(i=1;i<=objTotal;i++) {
  if(i<=objId){
     document.getElementById("yd1Table"+i).style.display="block";
  }else {
   document.getElementById("yd1Table"+i).style.display="none";
 
  }//end if
 }//end for
}


//验证儿童年龄是否全部正确选择
function checkChildren()
{

  var obj1;
  for(var i=1;i<=5;i++)
  {
    for(var j=1;j<=6;j++)
    {
      obj1= eval('document.Inthotel.child_age_'+i+'_'+j);
	   
      if(document.getElementById('yd1UL'+i+'_'+j).style.display!='none')
      {

		 if(obj1.value=='-1')
         {
           
            obj1.focus();
            return false;
         }
      }
    }
  }
  return true;
}


//验证查询条件
function checkInput()
{
   
   for(i=0;i<document.HotSrch.raCityName.length;i++)
   {
      if(document.HotSrch.raCityName[i].checked)
         return true;
         
   }
   if(document.HotSrch.CountrySelection.selectedIndex<0)
   {
      return false;
   }
   else
   {
      if(document.HotSrch.CitySelection.options[0].value=="请选择城市"||document.HotSrch.CitySelection.selectedIndex < 0)
        return false;
      else
        return true;  
   }
}

function CheckHotelName()
{
   var hotelName = document.HotSrch.HotelName.value;
   if(hotelName.length>0)
   {
     if(!IsEnglishName(hotelName))
	{
		alert(HOTEL_REQUEST_HOTEL_NAME_NOT_EN);
		return false;
	}
	if(hotelName.length>255)
	{
	  alert(HOTEL_REQUEST_HOTEL_NAME_LENGTH);
	  return false;
	}
	
   }
   return true;
   
}


function CheckSafeString(obj,Msg)
{
    if (obj !=null)
    {
       var strObjValue = obj.value;
       if (strObjValue !="")
	   {
	      if (!IsSafeString(strObjValue))
	      {
	          alert( Msg);			
	          obj.focus();
	          return (false);
	      }
	   } 
    }    
    return true;
}

//提交查询条件
function submitData(obj,strServerDate,Theme)
{   
	calpersonnun();
    if(!checkdate()){
		alert("离店日期不能早于入店日期");
		return false;
	}
    if(!checkcity()){
		alert("请选择城市");
		return false;
	}

	doSub();
}

function sw(obj)
{
 var objTable=document.getElementById(obj)
 var objStyle=objTable.style.display;
 objTable.style.display=objStyle=="none"?"block":"none";
}
function roomShow(objElement)
{
 var x=objElement.options.length;
 var y=objElement.selectedIndex+1;
 for(i=2;i<=x;i++)
 {
  if(i<=y)
   document.getElementById("room"+i).style.display="block"
   else
   {document.getElementById("room"+i).style.display="none";
   if(document.getElementById("child_room"+i).selectedIndex!=0)
   {
     document.getElementById("child_room"+i).selectedIndex=0;
	showChild(i,0,7);
	
   }
   }
 }
}
function HotelTypeClickEverest(i)
{
    
	for(j=1;j<=3;j++)
	{
	    if(j==i)
		{
		//	var tmpForm = eval ( "document.HotSrch.hotel_type_title"+j);
		//	tmpForm.className="jiudian_haha";
			document.getElementById("hotel_type_title"+j).className="jiudian_haha";
			document.getElementById("sh_title_td" + j).style.backgroundImage='url(' + "images/hotel_title_bg" + j + ".jpg" +')';
			
		}
		else
		{
			document.getElementById("hotel_type_title"+j).className="white";
			document.getElementById("sh_title_td" + j).style.backgroundImage='url(none)';
			
		}
		
	}
}


//在酒店详细页中根据保存的值重设child数组的值
function setChildArrayValue ()
{
	for (  i=1;i<=5;i++ )
		{
			for (  j=1;j<=6;j++ )
			{
				if ( document.getElementById("yd1UL"+i+"_"+j).style.display=="block")
				{
					eval("child"+j)[i-1]=1;
				}
				else
				{
				
					eval("child"+j)[i-1]=0;
				}
			}
		}	
}
//验证提交
function checkdata(){
	var flag = true;
	var rn = parseInt(document.getElementById("roomnum").value);//房间数
	for(i=1;i<=rn;i++){
		var adultnum = parseInt(document.getElementById("adult_room"+i).value);//每间房的成人数 
		var childnum = parseInt(document.getElementById("child_room"+i).value);//每间房的儿童数
		if(childnum>(adultnum*2)){
			alert("每个成人只能带2名儿童");
			document.getElementById("child_room"+i).focus();
			flag = false;
			break;
		}
	}
	return flag;
}
function checkcity(){
	var citystr = "";
	var cityobj = document.getElementsByName("destination");
	for(i=0;i<cityobj.length;i++){
		if(cityobj[i].checked){
			citystr = cityobj[i].value;
			break;
		}
	}
	if(citystr=="" && (document.getElementById("worldCity").value=="" ||document.getElementById("worldCity").value=="NO")){
		return false;
	}else{
		return true;	
	}
}

function checkdate(){
	var checkindate = document.getElementById("dateCheckIn").value;
	var checkoutdate = document.getElementById("dateCheckOut").value;
	var dd1 = new Date(parseInt(checkindate.split("-")[0],10),parseInt(checkindate.split("-")[1],10)-1,parseInt(checkindate.split("-")[2],10));
	var dd2 = new Date(parseInt(checkoutdate.split("-")[0],10),parseInt(checkoutdate.split("-")[1],10)-1,parseInt(checkoutdate.split("-")[2],10));
	if(dd2.getTime()-dd1.getTime()<=0){
		return false;
	}else{
		return true;	
	}
}

function calpersonnun(){
	var roomnum = parseInt(document.getElementById("roomnum").value,10);
	var personnum = 0;
	var babynum = 0;
	for(var a=1;a<=roomnum;a++){
		personnum+=parseInt(document.getElementById("adult_room"+a).value,10);
		//babynum+=parseInt(document.getElementById("child_room"+a).value,10);
	}

	document.getElementById("personnum").value = personnum;
	document.getElementById("babynum").value = babynum;
}
