$(document).ready(function(){
     //设置属性
     $(".top ul li:eq(0)").css("text-align","left");
     $(".top ul li:eq(1)").css("text-align","center");
     $(".top ul li:eq(2)").css("text-align","right");
     $(".left ul li:eq(0)").css("border","0px");
     $(".left ul li:eq(0)").css("height","180px");
    
     //控制酒店房间的隐藏和显示
        hot();
     //获取数据
     var Countrystr=Country();
     if(Countrystr!="")
     {       
        $("#Country").append(Countrystr);
     }else
     {
       alert("未能加载任何国家");
     }
     $("#Country").change(function(){
        $("#Sheng").empty(); 
        $("#Sheng").append("<option selected='true' vaule=''>--请选择省--</option>")
        $("#Shi").empty(); 
        $("#Shi").append("<option selected='true' vaule=''>--请选择市--</option>")
        $("#Xian").empty(); 
        $("#Xian").append("<option selected='true' vaule=''>--请选择(区/县)--</option>");
        $(".right .Loading:first").css("display","block");
        setTimeout(function(){
         $(".right .Loading:first").css("display","none");
          $("#Sheng").append(Sheng($("#Country").val())); 
        },1000);
       
     });
    $("#Sheng").change(function(){
        $("#Shi").empty(); 
        $("#Shi").append("<option selected='true' vaule=''>--请选择市--</option>")
        $("#Xian").empty(); 
        $("#Xian").append("<option selected='true' vaule=''>--请选择(区/县)--</option>");
          $(".right .Loading:first").css("display","block");
        setTimeout(function(){
         $(".right .Loading:first").css("display","none");
          $("#Shi").append(Shi($("#Country").val(),$("#Sheng").val())); 
        },1000);
    });
     $("#Shi").change(function(){
      $("#Xian").empty(); 
      $("#Xian").append("<option selected='true' vaule=''>--请选择(区/县)--</option>")
      $(".right .Loading:first").css("display","block");
      setTimeout(function(){
         $(".right .Loading:first").css("display","none");
           $("#Xian").append(Xian($("#Country").val(),$("#Sheng").val(),$("#Shi").val())); 
        },1000);
     });
     //查询酒店
     $("#butSearch").click(function(){
       
		$(".left>ul li:eq(2)").children(":not(.Loading,.title)").remove()
		$(".left  .Loading:first").css("display","block");
		$(".hotelcontent").children(":not(.Loading)").remove();
		$(".right .hotelcontent .Loading:first").css("display","block");
		$(".PageFY").remove();
     setTimeout(function(){
         $.get("Hotel.aspx?Type=tuijian"+getAddress(),function(HtoelTuijian){
            if(HtoelTuijian!='')
            {
               $(".left>ul li:eq(2) .Loading").after(HtoelTuijian);
            }else
            {
               $(".left>ul li:eq(2) .Loading").after("<li>没有找到相关酒店推荐信息</li>");
            }
         });
		 $.get(getWhere("Hotel.aspx?Type=Select"),function(hotelInfo){
	         if(hotelInfo!='')
	         {
	           $(".hotelcontent .Loading").after(hotelInfo);
	            hot();
	            	 $.get(getWhere("Hotel.aspx?Type=Page"),function(PageStr){
		   if(PageStr!='')
			{
				$(".hotelcontent>.PageFY").remove();
				$(".hotelcontent").after(PageStr);
						$(".PageFY a").bind("click",function(){
						  clicka($(".PageFY a:eq("+$(".PageFY a").index(this)+")").attr("id"));
						});
			}
		});
	         }else
	         {
	           $(".hotelcontent .Loading").after("<li>没有查询到相关酒店</li>");
	         }
	     $(".right .hotelcontent .Loading:first").css("display","none");
	     $(".left  .Loading:first").css("display","none");
		});
	
	  },1000);
	  
    });
    $(".PageFY a").click(function(){
     clicka($(".PageFY a:eq("+$(".PageFY a").index(this)+")").attr("id"));
    });
});

function hot(){
  $(".hotelinfo span a[title='房间信息']").toggle(
          function(){
              var hrid=$(".hotelinfo span a[title='房间信息']").index(this);
             if( $(".roominfo:eq("+ $(".hotelinfo span a[title='房间信息']").index(this)+")").html()=='')
             {
               var HotelID=$(".hotelinfo span a[title='房间信息']:eq("+$(".hotelinfo span a[title='房间信息']").index(this)+")").attr("id");
               var HotelName=$(".hotelinfo span a[title='房间信息']:eq("+$(".hotelinfo span a[title='房间信息']").index(this)+")").attr("name");
               $.get("Hotel.aspx?Type=Room&Hotelid="+HotelID+"&HotelName="+HotelName,function(hotelroom){
					if(hotelroom!="")
					{
					    $(".roominfo:eq("+hrid+")").html(hotelroom);
					    $(".roominfo ul:first-child li").css("background-color","#F2F2F2").css("border-top","1px solid #F2F2F2").css("border-bottom","1px solid #F2F2F2");//设置酒店房间的背景颜色以及边框
					}else
					{
					   $(".roominfo:eq("+hrid+")").html("没有找到房间信息");
					}
               });
             }
             $(".roominfo:eq("+hrid+")").show(500);
             $(".hotelinfo span a[title='房间信息']:eq("+hrid+")").html("隐藏房间信息▼");
          },
          function(){
             $(".roominfo:eq("+ $(".hotelinfo span a[title='房间信息']").index(this)+")").hide(500);
             $(".hotelinfo span a[title='房间信息']:eq("+$(".hotelinfo span a[title='房间信息']").index(this)+")").html("查看房间信息▲");
          }
        );
}
function getAddress()
{
  	 var Address=""
        if(trim($("#Country").val()).length>0 && trim($("#Country").val())!="--请选择国家--")
        {
           Address=Address+"&Country="+encodeURI(encodeURI($("#Country option:selected").text()));
           if(trim($("#Sheng").val()).length>0 && trim($("#Sheng").val())!="--请选择省--")
           {
             Address=Address+"&Provice="+encodeURI(encodeURI($("#Sheng option:selected").text()));
             if(trim($("#Shi").val()).length>0 && trim($("#Shi").val())!="--请选择市--")
             {
                Address=Address+"&City="+encodeURI(encodeURI($("#Shi option:selected").text()));
                if(trim($("#Xian").val()).length>0 && trim($("#Xian").val())!="--请选择(区/县)--")
                {
                  Address=Address+"&Area="+encodeURI(encodeURI($("#Xian option:selected").text()));
                }
             }
           }
        }
        return Address;
}
function getWhere(URL)
{
   var selectStr="";
        selectStr=selectStr+getAddress();
        var Star="";
         $("input:checkbox[name='BoxStart']").each(function(){ 
				if($(this).attr("checked"))
				{
				   Star=Star+$(this).val()+",";           
				}  
			});	
		if(Star.length>0 && Star!='')
			{
				Star=Star.substr(0,Star.length-1);
				selectStr=selectStr+"&ClassNum="+encodeURI(encodeURI(Star));
			}
		if($("#txtHotelName").val()!='' && $("#txtHotelName").val()!="输入酒店名称或酒店拼音首字母")
		{
		    selectStr=selectStr+"&HotelName="+encodeURI(encodeURI($("#txtHotelName").val()));
		}
		if($("#txtZB").val()!='' && $("#txtZB").val()!="输入周边环境设施")
		{
		   selectStr=selectStr+"&AboutStr="+encodeURI(encodeURI($("#txtZB").val()));
		}
		if(trim($("#listMoney").val()).length>0 && $("#listMoney").val()!="不限")
		{
		   selectStr=selectStr+"&price="+encodeURI(encodeURI($("#listMoney").val()));
		}
		if(trim($("#internet").val()).length>0 && $("#internet").val()!="--请选择宽带类型--")
		{
		  selectStr=selectStr+"&internet="+encodeURI(encodeURI(trim($("#internet").val())));
		}
		if(trim($("#breakfirst").val()).length>0 && $("#breakfirst").val()!="--请选择早餐类型--")
		{
		  selectStr=selectStr+"&breakfrist="+encodeURI(encodeURI(trim($("#breakfirst").val())));
		}
     if(selectStr!='')
     {
       URL=URL+selectStr;
     }
     return URL;
}

function clicka(index)
{
    var PageSize=10;
      var wherestr=getWhere("Hotel.aspx?Type=Page");
      wherestr=wherestr+"&PageIndex="+index+"&PageSize="+PageSize;
      $(".hotelcontent").children(":not(.Loading)").remove();
      $(".PageFY").remove();
	  $(".right .hotelcontent .Loading:first").css("display","block");
	  setTimeout(function(){
	   $.get(getWhere("Hotel.aspx?Type=Select")+"&PageIndex="+index+"&PageSize="+PageSize,function(hotelInfo){
	         if(hotelInfo!='')
	         {
	            $(".hotelcontent").html($(".hotelcontent").html()+hotelInfo);
	            hot();
	             $.get(wherestr,function(PageStr){
					if(PageStr!='')
					{
						$(".hotelcontent").after(PageStr);
						$(".PageFY a").bind("click",function(){
						  clicka($(".PageFY a:eq("+$(".PageFY a").index(this)+")").attr("id"));
						});
					}
				});
	         }else
	         {
	           $(".hotelcontent").html($(".hotelcontent").html()+"<ul><li>没有查询到相关酒店</li></ul>");
	         }
	          
	     $(".right .hotelcontent .Loading:first").css("display","none");
		});
	  },1000);
}

document.onkeydown=function (){
 if(event.keyCode==13)
 {
   if($("#pagenum").val().length>0 &&　$("#pagenum").val()>0)
   {
    clicka($("#pagenum").val());
   }else
   {
     alert("页面跳转必须输入一个大于0的整数！")
   }
 }
}
function trim(str){ 
return str.replace(/(^\s*)|(\s*$)/g, "");
}
