﻿// JScript 文件
//滚动
function sc1(){
    $("#beijingDiv").css("top",$(document).scrollTop());
}
function sc2(){
 document.getElementById("yd_div").style.top=(document.documentElement.scrollTop+(document.documentElement.clientHeight-document.getElementById("yd_div").offsetHeight)/2)+"px";
 document.getElementById("yd_div").style.left=(document.documentElement.scrollLeft+(document.documentElement.clientWidth-document.getElementById("yd_div").offsetWidth)/2)+"px";
 
 document.getElementById("ok_div").style.top=(document.documentElement.scrollTop+(document.documentElement.clientHeight-document.getElementById("ok_div").offsetHeight)/2)+"px";
 document.getElementById("ok_div").style.left=(document.documentElement.scrollLeft+(document.documentElement.clientWidth-document.getElementById("ok_div").offsetWidth)/2)+"px";
}
function scall(){
 sc1();
 sc2();
 window.onscroll=scall;
 window.onresize=scall;
 window.onload=scall;
}


$(function(){
    $(".mid_dhl").find("ul").find("li:eq(1)").addClass("ul_li_xz");
    
    
    //预定按钮
    $(".yudinganniu").click(function(){
       if($(this).attr("name")=="0")
        {
            $("#hidd_Hotel_id").val($(this).attr("alt"));
            $("#beijingDiv").show();
            $("#yd_div").show();
            scall();
        }
        else
        {
            alert("因特价房间数有限，暂不接受网络预订服务，\n\n请到酒店前台或电话咨询，谢谢！");
        }
    });
    //关闭
    $("#guanbi").click(function(){
        $("#beijingDiv").hide();
        $("#yd_div").hide();
    });
    
    
    //预定间数
    $("#room_num").focus(function(){
        
        $("#lsjd_div_sexAndnum").css("width","100")
    
        $("#lsjd_div_sexAndnum").empty(); //删除  
        var _html = "<table cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">";
        _html += "<tr><td style=\"cursor:pointer;\"><span> 1 间</span><input type=\"hidden\" value=\"1\" /></td></tr>";
        _html += "<tr><td style=\"cursor:pointer;\"><span> 2 间</span><input type=\"hidden\" value=\"2\" /></td></tr>";
        _html += "<tr><td style=\"cursor:pointer;\"><span> 3 间</span><input type=\"hidden\" value=\"3\" /></td></tr>";
        _html += "<tr><td style=\"cursor:pointer;\"><span> 4 间</span><input type=\"hidden\" value=\"4\" /></td></tr>";
        _html += "<tr><td style=\"cursor:pointer;\"><span> 5 间</span><input type=\"hidden\" value=\"5\" /></td></tr>";
        _html += "<tr><td style=\"cursor:pointer;\"><span> 6 间</span><input type=\"hidden\" value=\"6\" /></td></tr>";
        _html += "<tr><td style=\"cursor:pointer;\"><span> 7 间</span><input type=\"hidden\" value=\"7\" /></td></tr>";
        _html += "<tr><td style=\"cursor:pointer;\"><span> 8 间</span><input type=\"hidden\" value=\"8\" /></td></tr>";
        _html += "<tr><td style=\"cursor:pointer;\"><span> 9 间</span><input type=\"hidden\" value=\"9\" /></td></tr>";
        _html += "<tr><td style=\"cursor:pointer;\"><span> 10 间</span><input type=\"hidden\" value=\"10\" /></td></tr>";
        _html += "<tr><td style=\"cursor:pointer;\"><span> 10 间以上</span><input type=\"hidden\" value=\"0\" /></td></tr>";
        _html += "</table>";
        $("#lsjd_div_sexAndnum").append(_html);
        
        $("#lsjd_div_sexAndnum").find("table").each(function(){
            $(this).find("tr").find("td").mousemove(function(){
                $(this).css("background","#C8E3FC");
                $("#hidd_room_num").val($(this).find("input:hidden").val());
                $("#room_num").val($(this).find("span").html());
             
            }).mouseout(function(){
                $(this).css("background","#ffffff");
                $("#hidd_room_num").val($(this).find("input:hidden").val());
                $("#room_num").val($(this).find("span").html());
            });
            
        });
        
        var ls_offset = $("#room_num").offset();
        var ls_top = ls_offset.top+$("#room_num").height()+5;
        var ls_left = ls_offset.left;
        $("#lsjd_div_sexAndnum").css("top",ls_top+"px");
        $("#lsjd_div_sexAndnum").css("left",ls_left+"px");
        $("#lsjd_div_sexAndnum").show();
    });

    $("#room_num").blur(function(){
        $("#lsjd_div_sexAndnum").hide();
    });
    $("#room_num").keydown(function(e){
        if(e.which==13)
        {
            return false;
        }
    });    
    
    //性别
    $("#txt_sex").focus(function(){
        
        $("#lsjd_div_sexAndnum").css("width","60")
    
        $("#lsjd_div_sexAndnum").empty(); //删除  
        var _html = "<table cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">";
        _html += "<tr><td style=\"cursor:pointer;\"> 先生</td></tr>";
        _html += "<tr><td style=\"cursor:pointer;\"> 小姐</td></tr>";
        _html += "</table>";
        $("#lsjd_div_sexAndnum").append(_html);
        
        $("#lsjd_div_sexAndnum").find("table").each(function(){
            $(this).find("tr").find("td").mousemove(function(){
                $(this).css("background","#C8E3FC");
                $("#txt_sex").val($(this).html());
             
            }).mouseout(function(){
                $(this).css("background","#ffffff");
                $("#txt_sex").val($(this).html());
            });
            
        });
        
        var ls_offset = $("#txt_sex").offset();
        var ls_top = ls_offset.top+$("#txt_sex").height()+5;
        var ls_left = ls_offset.left;
        $("#lsjd_div_sexAndnum").css("top",ls_top+"px");
        $("#lsjd_div_sexAndnum").css("left",ls_left+"px");
        $("#lsjd_div_sexAndnum").show();
    });

    $("#txt_sex").blur(function(){
        $("#lsjd_div_sexAndnum").hide();
    });
    $("#txt_sex").keydown(function(e){
        if(e.which==13)
        {
            return false;
        }
    });
    
    //确认按钮==========================================================
    $("#an_qrtj").click(function(){

        if($("#yd_rRq").val()=="")
        {
            alert("请选择您入住日期");
            $("#yd_rRq").focus();
            return false;
        }
        else if($("#yd_lRq").val()=="")
        {
            alert("请选择您离店日期");
            $("#yd_lRq").focus();
            return false;
        }
        else if($("#room_num").val()=="")
        {
            alert("请选择您要预定的间数");
            
            $("#lsjd_div_sexAndnum").css("width","100")
    
            $("#lsjd_div_sexAndnum").empty(); //删除  
            var _html = "<table cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">";
            _html += "<tr><td style=\"cursor:pointer;\"><span> 1 间</span><input type=\"hidden\" value=\"1\" /></td></tr>";
            _html += "<tr><td style=\"cursor:pointer;\"><span> 2 间</span><input type=\"hidden\" value=\"2\" /></td></tr>";
            _html += "<tr><td style=\"cursor:pointer;\"><span> 3 间</span><input type=\"hidden\" value=\"3\" /></td></tr>";
            _html += "<tr><td style=\"cursor:pointer;\"><span> 4 间</span><input type=\"hidden\" value=\"4\" /></td></tr>";
            _html += "<tr><td style=\"cursor:pointer;\"><span> 5 间</span><input type=\"hidden\" value=\"5\" /></td></tr>";
            _html += "<tr><td style=\"cursor:pointer;\"><span> 6 间</span><input type=\"hidden\" value=\"6\" /></td></tr>";
            _html += "<tr><td style=\"cursor:pointer;\"><span> 7 间</span><input type=\"hidden\" value=\"7\" /></td></tr>";
            _html += "<tr><td style=\"cursor:pointer;\"><span> 8 间</span><input type=\"hidden\" value=\"8\" /></td></tr>";
            _html += "<tr><td style=\"cursor:pointer;\"><span> 9 间</span><input type=\"hidden\" value=\"9\" /></td></tr>";
            _html += "<tr><td style=\"cursor:pointer;\"><span> 10 间</span><input type=\"hidden\" value=\"10\" /></td></tr>";
            _html += "<tr><td style=\"cursor:pointer;\"><span> 10 间以上</span><input type=\"hidden\" value=\"0\" /></td></tr>";
            _html += "</table>";
            $("#lsjd_div_sexAndnum").append(_html);
            
            $("#lsjd_div_sexAndnum").find("table").each(function(){
                $(this).find("tr").find("td").mousemove(function(){
                    $(this).css("background","#C8E3FC");
                    $("#hidd_room_num").val($(this).find("input:hidden").val());
                    $("#room_num").val($(this).find("span").html());
                 
                }).mouseout(function(){
                    $(this).css("background","#ffffff");
                    $("#hidd_room_num").val($(this).find("input:hidden").val());
                    $("#room_num").val($(this).find("span").html());
                });
                
            });
            
            var ls_offset = $("#room_num").offset();
            var ls_top = ls_offset.top+$("#room_num").height()+5;
            var ls_left = ls_offset.left;
            $("#lsjd_div_sexAndnum").css("top",ls_top+"px");
            $("#lsjd_div_sexAndnum").css("left",ls_left+"px");
            $("#lsjd_div_sexAndnum").show();
            
            $("#room_num").focus();
            return false;
        }
        else if($("#txt_yd_name").val()=="")
        {
            alert("请填写您的真实名称");
            $("#txt_yd_name").focus();
            return false;
        }
        else if($("#txt_sex").val()=="")
        {
            alert("请选择您性别");
            
            $("#lsjd_div_sexAndnum").css("width","60")
    
            $("#lsjd_div_sexAndnum").empty(); //删除  
            var _html = "<table cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">";
            _html += "<tr><td style=\"cursor:pointer;\"> 先生</td></tr>";
            _html += "<tr><td style=\"cursor:pointer;\"> 小姐</td></tr>";
            _html += "</table>";
            $("#lsjd_div_sexAndnum").append(_html);
            
            $("#lsjd_div_sexAndnum").find("table").each(function(){
                $(this).find("tr").find("td").mousemove(function(){
                    $(this).css("background","#C8E3FC");
                    $("#txt_sex").val($(this).html());
                 
                }).mouseout(function(){
                    $(this).css("background","#ffffff");
                    $("#txt_sex").val($(this).html());
                });
                
            });
            
            var ls_offset = $("#txt_sex").offset();
            var ls_top = ls_offset.top+$("#txt_sex").height()+5;
            var ls_left = ls_offset.left;
            $("#lsjd_div_sexAndnum").css("top",ls_top+"px");
            $("#lsjd_div_sexAndnum").css("left",ls_left+"px");
            $("#lsjd_div_sexAndnum").show();
            
            $("#txt_sex").focus();
            return false;
        }
        else if($("#txt_tel").val()=="")
        {
            alert("请填写您的联系电话");
            $("#txt_tel").focus();
            return false;
        }
        else
        {
            var rzrq=new Date(Date.parse($("#yd_rRq").val().replace("-", "/")));
            var ldrq=new Date(Date.parse($("#yd_lRq").val().replace("-", "/")));
            if(rzrq>=ldrq)
            {
                alert("离店日期不能早于或等于入住日期");
                $("#yd_rRq").val();
                $("#yd_lRq").val();
                $("#yd_rRq").focus();
                return false;
            }
            else
            {
                //插入订单
                //AddOrder(入住日期, 离店日期, 房间数, 用户名称, 用户性别, 用户电话,城市id,房价,酒店名称,房型名称)
                var cs_cityId = $("#"+shiId).val();
                var cs_RoomJiage = $("#"+$("#hidd_Hotel_id").val()).parent().parent().parent().find("td:eq(1)").find("span").html().split(" ")[0];
                var cs_HotelName = $("#"+$("#hidd_Hotel_id").val()).parent().parent().parent().parent().parent().parent().parent().parent().parent().find(".mid_xxjd_xx").find(".hotel_name").html();
                
                var cs_RoomName = $("#"+$("#hidd_Hotel_id").val()).parent().parent().parent().find("td:eq(0)").find("span").html();
                   
//                var yes_no = Page_Hotel.AddOrder($("#yd_rRq").val(),$("#yd_lRq").val(),$("#hidd_room_num").val(),$("#txt_yd_name").val(),
//                             $("#txt_sex").val(),$("#txt_tel").val(),cs_cityId,cs_RoomJiage,cs_HotelName,cs_RoomName).value;
//                             
//                if(yes_no == "yes")
//                {
//                    $("#yd_div").hide();
//                    $("#ok_div").show();           
// document.getElementById("ok_div").style.top=(document.documentElement.scrollTop+(document.documentElement.clientHeight-document.getElementById("ok_div").offsetHeight)/2)+"px";
// document.getElementById("ok_div").style.left=(document.documentElement.scrollLeft+(document.documentElement.clientWidth-document.getElementById("ok_div").offsetWidth)/2)+"px";

//                }
                //绑定填写数据
                //AddOrder(入住日期, 离店日期, 房间数, 用户名称, 用户性别, 用户电话,城市id,房价,酒店名称,房型名称)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                $("#qr_hname").text(" "+cs_HotelName);
                $("#qr_kname_sex").text(" "+$("#txt_yd_name").val()+" "+$("#txt_sex").val());
                $("#qr_tel").text(" "+$("#txt_tel").val());
                $("#qr_inday").text(" "+$("#yd_rRq").val());
                $("#qr_outday").text(" "+$("#yd_lRq").val());
                $("#qr_fx").text(" "+cs_RoomName);
                var jianshu=$("#hidd_room_num").val();
                var qr_fj=new Object();
                qr_fj=Page_Hotel.GetFangJia(cs_HotelName,cs_RoomName,$("#yd_rRq").val(),$("#yd_lRq").val()).value;
                // 价格显示
                if(qr_fj != null && qr_fj.Rows.length>0)
                {
                    $("#qr_jg_div").empty(); //删除
                    var _html = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"font-family: Arial; margin-top: 6px;\"><tr style=\"height: 42px;\">";
                    var zong_jia=0;
                    for(var i=1;i<=qr_fj.Rows.length; i++)
                    {
                        _html += "<td style=\"height: 36\">";
                        _html += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"color: #57697A; width: 39px;\">";
                        _html += "<tr>";
                        _html += "<td align=\"center\" style=\"height: 18px;\">";
                        _html += qr_fj.Rows[i-1].t_riqi+"</td>";
                        _html += "</tr>";
                        _html += "<tr>";
                        if(qr_fj.Rows[i-1].ys ==0 )
                            _html += "<td align=\"center\" style=\"color: #57697A; height: 18px;\">";
                        else
                            _html += "<td align=\"center\" style=\"color: #F2328D; height: 18px;\">";
                        _html += qr_fj.Rows[i-1].col2+"￥</td>";
                        _html += "</tr>";
                        _html += "</table>";
                        _html += "</td>";
                        zong_jia=zong_jia+qr_fj.Rows[i-1].col2;
                        if(i%7==0)
                        {
                            _html += "</tr><tr style=\"height: 42px;\">";
                        }
                        
                    }
                    _html += "</tr>";
                    _html += "</table>";
                    if(jianshu!='0')
                    {
                        _html += "<div style=\"margin-top:21px;\">";
                        _html += "<span style=\"color: #57697A; line-height: 24px; margin-left: 88px;\">总价 : <span style=\"color: #F2328D;font-weight: bold;\">"+zong_jia+"￥</span></span></div>";
                    }
                    
                    $("#qr_jg_div").append(_html);
                }
                     
                // 价格显示
                if(jianshu!='0')
                {
                    $("#qr_num").text(" "+jianshu+'间');
                }    
                else
                {
                    $("#qr_num").text("10间以上"); 
                
                }
                //
                //弹出一个确认对话框
                //
                $("#qr_div").show();
                $("#yd_div").hide();
                document.getElementById("qr_div").style.top=(document.documentElement.scrollTop+(document.documentElement.clientHeight-document.getElementById("qr_div").offsetHeight)/2)+"px";
                document.getElementById("qr_div").style.left=(document.documentElement.scrollLeft+(document.documentElement.clientWidth-document.getElementById("qr_div").offsetWidth)/2)+"px";
 
            }
        }
    });
    //确认关闭
    $("#qr_gb").click(function(){
        $("#beijingDiv").hide();
        $("#qr_div").hide();
    });
    //修改按钮--------------------------------------new
    $("#an_xg").click(function(){
        $("#qr_div").hide();
        $("#yd_div").show();
    });
    //确认入住--------------------------------------new
    $("#an_qrtja").click(function(){
        //插入订单
        //AddOrder(入住日期, 离店日期, 房间数, 用户名称, 用户性别, 用户电话,城市id,房价,酒店名称,房型名称)
        var cs_cityId = $("#"+shiId).val();
        var cs_RoomJiage = $("#"+$("#hidd_Hotel_id").val()).parent().parent().parent().find("td:eq(1)").find("span").html().split(" ")[0];
        var cs_HotelName = $("#"+$("#hidd_Hotel_id").val()).parent().parent().parent().parent().parent().parent().parent().parent().parent().find(".mid_xxjd_xx").find(".hotel_name").html();
        
        var cs_RoomName = $("#"+$("#hidd_Hotel_id").val()).parent().parent().parent().find("td:eq(0)").find("span").html();
           
        var yes_no = Page_Hotel.AddOrder($("#yd_rRq").val(),$("#yd_lRq").val(),$("#hidd_room_num").val(),$("#txt_yd_name").val(),
                     $("#txt_sex").val(),$("#txt_tel").val(),cs_cityId,cs_RoomJiage,cs_HotelName,cs_RoomName).value;
                     
        if(yes_no == "yes")
        {
            $("#qr_div").hide();
            $("#ok_div").show();           
document.getElementById("ok_div").style.top=(document.documentElement.scrollTop+(document.documentElement.clientHeight-document.getElementById("ok_div").offsetHeight)/2)+"px";
document.getElementById("ok_div").style.left=(document.documentElement.scrollLeft+(document.documentElement.clientWidth-document.getElementById("ok_div").offsetWidth)/2)+"px";

        }
    });
    
    
    
    
    //google地图==============================================================================
    initialize();
    showAddress($("#"+xinxi).val());
    //google地图==============================================================================
    
    
    
    //酒店图片 交通信息====================================
    //<li id="li_tpxx" class="ulli_jdtp_x"><span>酒店图片</span></li>
    //<li id="li_jtxx" class="ulli_jtxq"><span>交通详情</span></li>
    $("#li_tpxx").click(function(){
        $(this).removeClass();
        $(this).addClass("ulli_jdtp_x");
        $("#li_jtxx").removeClass();
        $("#li_jtxx").addClass("ulli_jtxq");
        
        $("#tpxx_div").show();
        $("#jtxx_div").hide();
    });
    $("#li_jtxx").click(function(){
        $(this).removeClass();
        $(this).addClass("ulli_jtxq_x");
        $("#li_tpxx").removeClass();
        $("#li_tpxx").addClass("ulli_jdtp");
        
        $("#jtxx_div").show();
        $("#tpxx_div").hide();
    });
    
    
    //酒店图片**************************************************************************************************************
    if(img_Array.length>0)
    {
        $("#img_id").attr("src",".."+img_Array[0][0]);
        $(".settdt").html(img_Array[0][2]);
        $("#img_id").load(function(){
            DrawImage(".."+img_Array[0][0],300,200);
        });
        $("#img_index").val("1");
        
    }
    else
    {
        $("#tpxx_div").empty(); 
        $("#tpxx_div").append("<b>暂无图片</b>"); 
    }
    
    $(".an_s").click(function(){
        if($("#img_index").val()==1)
        {
            alert("已是第一张");
        }
        else
        {
            $("#img_index").val(Number($("#img_index").val())-1);
            
            $("#img_id").attr("src",".."+img_Array[Number($("#img_index").val())-1][0]);
            $(".settdt").html(img_Array[Number($("#img_index").val())-1][2]);
            $("#img_table").hide();
            $("#img_table").fadeIn("slow");
            $("#img_id").load(function(){
                DrawImage(".."+img_Array[Number($("#img_index").val())-1][0],300,200);
            });
        }
    });
    $(".an_x").click(function(){
        if($("#img_index").val()==img_Array.length)
        {
            alert("已是最后一张");
        }
        else
        {
            $("#img_index").val(Number($("#img_index").val())+1);
            $(".settdt").html(img_Array[Number($("#img_index").val())-1][2]);
            $("#img_id").attr("src",".."+img_Array[Number($("#img_index").val())-1][0]);
            $("#img_table").hide();
            $("#img_table").fadeIn("slow");
            $("#img_id").load(function(){
                DrawImage(".."+img_Array[Number($("#img_index").val())-1][0],300,200);
            });
        }
    });
    //酒店图片**************************************************************************************************************
}); 
//图片等比例压缩
function DrawImage(ImgUrl,iwidth,iheight)
{
    
    //参数(图片,允许的宽度,允许的高度)
    var image=new Image();
    image.src=ImgUrl;
    if(image.width>0 && image.height>0)
    {
        if(image.width/image.height>= iwidth/iheight)
        {
            if(image.width>iwidth)
            {  
                $("#img_id").width(iwidth); 
                $("#img_id").height((image.height*iwidth)/image.width); 
            }
            else
            {
                $("#img_id").width(image.width); 
                $("#img_id").height(image.height); 
            }
        }
        else
        {
            if(image.height>iheight)
            {  
                $("#img_id").height(iheight);
                $("#img_id").width((image.width*iheight)/image.height);        
            }
            else
            {
                $("#img_id").width(image.width);  
                $("#img_id").height(image.height);
            }
        }
    }
    
} 


//google地图==================================================
var map = null;
var geocoder = null;

var baseIcon = new GIcon();
    baseIcon.shadow = "http://www.google.cn/mapfiles/shadow50.png";
    baseIcon.iconSize = new GSize(24, 24);
    baseIcon.shadowSize = new GSize(0, 24);
    baseIcon.iconAnchor = new GPoint(9, 34);
    baseIcon.infoWindowAnchor = new GPoint(9, 2);
    baseIcon.infoShadowAnchor = new GPoint(18, 25);


function initialize() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(0, 0), 15);
	
	//map.addControl(new GLargeMapControl());
	map.addControl(new GSmallMapControl());
	//map.addControl(new GMapTypeControl());
	
    geocoder = new GClientGeocoder();
	
	
  }
}
//根基酒店地址判断坐标
function showAddress(Add) {
  if (geocoder) {
    geocoder.getLatLng(
      Add,
      function(point) {
        if (!point) {
          //alert("不能解析: " + address);
        } else {
          map.setCenter(point, 15);
          map.addOverlay(createMarker(point));
        }
      }
    );
  }
}
//设置图像标注样式
function createMarker(point) {
    var letteredIcon = new GIcon(baseIcon);
    letteredIcon.image = "../images/a.png";

    // 设置 GMarkerOptions 对象
    markerOptions = { icon:letteredIcon };
    var marker = new GMarker(point, markerOptions);

//    GEvent.addListener(marker, "click", function() {
//	marker.openInfoWindowHtml("<table><tr><td rowspan=\"2\"></td></tr></table>");
//			
//    });
  return marker;
}
//google地图==================================================
