  function toSearch(){
     var ks=document.searchform.fzrq.value;
     var js=document.searchform.ldrq.value; 
     var cs=document.searchform.szcs.value;
     if(cs==""||cs==null){alert(" 请选择城市! ");return false;}
     if(ks=="")
     	{
     	alert("预订时间不能为空!");
     	document.searchform.fzrq.onclick();
     	return false ;}
     if(js==""){
     alert("退订时间不能为空!");
     document.searchform.ldrq.onclick();
     return false ;}
     var bol = CheckTime();
     if(bol == 0){return false ;}
     var ts = DateDiff(ks,js);
     if(ts > 20){
       alert('本系统不支持超过20天的预订,请电话联系!');
       return false ;
     }
     document.searchform.submit();     
  }
  
  //清除快速城市
  function clearcitys(){
    var citys=document.getElementsByName('city');
 	var length=citys.length;
    for(i=0;i<length-1;i++){
      citys[i].checked='';
    }
  }
  
  function selinput(){
  	var citys=document.getElementsByName('city');
 	var length=citys.length;
 	citys[length-1].checked='checked';
 	document.searchform.szcs.value= "";
 	sel();
  }
  
  function sel(){
 
   var index = document.getElementsByName("areatype").length;
    var roleid;
		 for(var i=0; i < index; i++){
		     	if(document.getElementsByName("areatype")[i].checked){		       
		            roleid = document.getElementsByName("areatype")[i].value;		       
		        }
		    } 
   seleArea(roleid);
    
  }
  
 function selcity(szcs){
 
   document.searchform.szcs.value= szcs;
   document.searchform.csmc.value= "";
   sel();
    
  }


  //新增根据城市NBBH取区域方法2007-11-23
  function seleArea(typeid){
  
  var szcs =  document.searchform.szcs.value;

   if(szcs == ""){
  // alert("请先选择城市！");
  // return false;
   }
       
	var showResponse=function(transport)
	{	
		var json = eval("("+transport.responseText+")"); 
		$('areaid').options.length=0;
		var rows=json.rows;
		var defNode;
		if(typeid==0){
			defNode=new Option();
			defNode.value='';
			defNode.text='------商业区-----'
		}else{
			defNode=new Option();
			defNode.value='';
			defNode.text='------行政区-----'
		}
		defNode.selected='true';
		$('areaid').options.add(defNode);
		
		for(var i=0;i<json.total;i++){
			var oNewNode=new Option();
			oNewNode.value=rows[i].ID;
		    oNewNode.text=rows[i].MC;
			$('areaid').options.add(oNewNode);
		}
	}
	
	var myAjax = new Ajax.Request(
		'/acc/news/hotelList/nbbh.shtml',
		{
			method: 'post',
			requestHeaders:{Accept:'application/json'},
			parameters: 'areatype='+typeid+'&nbbh='+szcs+'&ctx=${ctx}',
			onComplete: showResponse
		}
	);
}

window.attachEvent('onload',function(){

	//autowc('sfmc','szsf',1, '/acc/news/hotelList/nbbh_sel.shtml?seltype=country');
	autowc('csmc','szcs',2,'/acc/news/hotelList/nbbh_sel.shtml?seltype=city&ctx=${ctx}');
	//首次自动选中快速城市
	if(document.getElementsByName('city')[0]!=null){
      document.getElementsByName('city')[0].checked='checked';
      document.searchform.szcs.value = document.getElementsByName('city')[0].value;
      selcity(document.searchform.szcs.value);
    }
}
);

autowc = function(inputfiled,inputid,lx, url){
    
	if (lx==undefined){
		lx="";
	}else{
		lx="&lx="+lx;
	}
	try{
		if($('spinner')==undefined){
		document.body.insertAdjacentHTML('afterBegin'," <img alt='Loading' id='spinner' src='/images/skin1/loading.gif' style='display:none; float:right;position:absolute' />");
		}
	}catch(e){}
	
	var rand=parseInt(Math.random()*1000);
	pick_inputfiled=inputfiled+rand;
	Event.observe($(inputfiled),"keydown",function(event){
	   switch(event.keyCode) {
       case Event.KEY_TAB:
       	 return;
       case Event.KEY_RETURN:
         return;
       case Event.KEY_ESC:         
         return;
       case Event.KEY_LEFT:
         return;
       case Event.KEY_RIGHT:
         return;
       case Event.KEY_UP:         
         return;
       case Event.KEY_DOWN:         
         return;
      }
      $('spinner').style.left  = Position.positionedOffset($(inputfiled))[0];
	  $('spinner').style.top  = Position.positionedOffset($(inputfiled))[1] + $(inputfiled).getHeight();
	  if(inputid!=""){$(inputid).value="";};
	});
    new Insertion.After(inputfiled, "<div class='auto_complete' id='"+pick_inputfiled+"'></div>");
	$(inputfiled).addClassName("Winput");
	$(inputfiled).title="";
	afterupdate =function(e,se){if(inputid!=""){$(inputid).value=se.dh;sel();};$(inputfiled).value=se.text;}
	new Ajax.Autocompleter(inputfiled, pick_inputfiled, url, {frequency:1,paramName:'text',afterUpdateElement:afterupdate})
}


 //检查 开始时间 小于 结束时间
   function CheckTime(){
     var beginvalue=document.searchform.fzrq.value;
     var endvalue=document.searchform.ldrq.value;

     if(beginvalue!=""){
	      var begin=new Array();
	      var end=new Array();
	      begin=beginvalue.split("-");
	      end=endvalue.split("-");
	      var beginnum=begin[0]+begin[1]+begin[2];
	      var endnum=end[0]+end[1]+end[2];

	      if(endnum<beginnum){
	       alert("对不起，结束时间必须大于开始时间");
	       document.searchform.ldrq.value = "" ;
	       return 0;
	      }
	      //预订不能大于六晚
	      var days = DateDiff(beginvalue,endvalue);
	      days = Number(days) ;
	      if(days > 7){
	       //  alert("如果您需要预订一周以上,请电话与我们联系,谢谢!!");
	       //  return 0 ;
	      }
     }
   } 
    
 //计算天数差的函数  
   function  DateDiff(sDate1,  sDate2){    //sDate1和sDate2是2006-12-18格式  
       var  aDate,  oDate1,  oDate2,  iDays  
       aDate  =  sDate1.split("-")  
       oDate1  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0])    //转换为12-18-2006格式  
       aDate  =  sDate2.split("-")  
       oDate2  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0])  
       iDays  =  parseInt(Math.abs(oDate1  -  oDate2)  /  1000  /  60  /  60  /24)    //把相差的毫秒数转换为天数  
       return  iDays  ;
   }    
    
   //星级
    function in_xj_c(){
	   var xy = document.searchform.xj_c_che;
	   var xy_1 ='';
	   for(var i=0; i<xy.length;i++){
	     if(xy[i].checked){
	       if(xy_1==''){
	           xy_1 = xy[i].value ;
	       }else{
	           xy_1 = xy_1 +","+ xy[i].value  ;
	       }
	       
	     }
	   }
	   document.searchform.xj.value = xy_1 ;
	}
    
    //房间 人数 函数
   function RoomNumChange(num){
   
     if(num==1){
        document.searchform.man_num.value = '1' ;
     }else if(num==2){
        document.searchform.man_num.value = '2' ;
     }else if(num==3){
        document.searchform.man_num.value = '3' ;
     }else if(num==4){
        document.searchform.man_num.value = '4' ;
     }else if(num==5){
        document.searchform.man_num.value = '5' ;
     }
     
        
   }

	window.attachEvent('onload',function(){
	   //---
	   var hl_areatype = '${param.areatype}' ;
	   if(hl_areatype == '1'){
	     seleArea(1);
	   }else{
	     seleArea(0);
	   }
	    
	}
	);
