var Container, ShowList;
ShowList = 0;
function GetRoom(Obj, tm1, tm2, SL, Path) {
    if (!Obj) { Obj = Container; } else { Container = Obj } //容器
    if (!tm1) { tm1 = ''; } //入住时间
    if (!tm2) { tm2 = ''; } //离店时间
    if (!SL) { SL = ShowList; } else { ShowList = SL } //显示列数
    //拼写酒店ID
    var HID = '';
    $(Obj).each(function () {
        HID += ',' + $(this).attr('hid');
    });
    if (HID == '') return;
    if (HID != '') HID = HID.substring(1);
    var ajaxpath = Path + 'sys/ajax/GetRoom.aspx?hid=' + HID + '&tm1=' + tm1 + '&tm2=' + tm2;
    $.ajax({
        type: 'GET', cache: false,
        url: ajaxpath,
        dataType: 'xml',
        success: function (xml) {
            $(Obj).each(function () {
                var thisHID = $(this).attr('hid');
                var temp = '';
                var children;
                $(xml).find('rooms>room[r_hotelid="' + thisHID + '"]').each(function () {
                    temp += '<tr class="hous_text">';
                    temp += '<td><a href="javascript:void(0);" onclick="$(\'#roomid_' + $(this).attr('r_id') + '\').toggle();">' + $(this).attr('r_name') + '</a></td>';
                    temp += '<td width="70"><span class="marketPrice">¥' + $(this).attr('r_rackrate') + '</span></td>';
                    temp += '<td width="70"><span class="offerPrice">¥' + $(this).attr('averageprice') + '</span></td>';
                    temp += '<td width="70"><span class="offerPrice">¥' + $(this).attr('r_bonus') + '</span></td>';
                    temp += '<td width="60">' + ($(this).attr('r_breakfast') == 1 ? '有' : '无') + '</td>';
                    temp += '<td width="60">' + ($(this).attr('r_internet') == 1 ? '有' : '无') + '</td>';
                    temp += '<td width="70"><input type="button" onclick="HotelBooking(' + $(this).attr('r_id') + ');" class="form_sk5" /></td>';
                    temp += '</tr>';
                    temp += '<tr class="hous_msg" id="roomid_' + $(this).attr('r_id') + '">';
                    temp += '<td colspan="7" style="position:relative;">';
                    temp += '<ul class="hous_msgText">';
                    temp += '<li>床型：' + $(this).attr('r_bedcategory') + '</li>';
                    temp += '<li>楼层：' + $(this).attr('r_floor') + '楼</li>';
                    temp += '<li>面积：' + $(this).attr('r_area') + '8平方</li>';
                    temp += '<li>窗户：' + $(this).attr('r_windows') + '</li>';
                    temp += '<li>卫浴：' + $(this).attr('r_bathroom') + '</li>';
                    temp += '<li>加床：' + $(this).attr('r_addbed') + '元/床</li>';
                    temp += '</ul>';
                    temp += '</td>';
                    temp += '</tr>';
                });
                if (temp != '') {
                    $(this).html(temp);
                    //children = $(this).children().children();//获取所有房间
                    children = $(this).find('.hous_text');
                    if (SL > 0 && children.length > SL + 1) {
                        $(children).filter(':gt(' + (SL - 1) + ')').hide(); //隐藏多余房间
                        $(this).after('<div class="hous_expand"><a href="javascript:void(0);" id="OpenRoom_' + thisHID + '" hid="' + thisHID + '">查看全部房型(' + children.length + ')</a> <img src="' + Path + 'Images/icoMoresE.gif" /></div>'); //显示所有房间链接
                        $('#OpenRoom_' + thisHID).click(function () { //显示所有房间事件
                            if ($(this).attr('open') != 'true') {
                                $(Obj).filter('[hid="' + $(this).attr('hid') + '"]').find('.hous_text').show();
                                $(this).attr('open', 'true');
                                $(this).next('img').attr('src', Path + 'Images/icoMoresT.gif');
                            } else {
                                $(Obj).filter('[hid="' + $(this).attr('hid') + '"]').find('tr:gt(' + ((ShowList - 1) * 2) + ')').hide();
                                $(this).attr('open', 'false');
                                $(this).next('img').attr('src', Path + 'Images/icoMoresE.gif');
                            }
                        });
                    }
                } else {
                    $(this).html('<tr class="hous_text"><td>暂无房型</td></tr>');
                }
            });
        }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.responseText); }
    });
}
function menu(t) {
    var img = $(t).find('img');
    if ($(img).attr('src').indexOf('open.gif') == -1) {
        $(img).attr('src', $(img).attr('src').replace('close.gif', 'open.gif'));
        $(t).siblings().show();
    } else {
        $(img).attr('src', $(img).attr('src').replace('open.gif', 'close.gif'));
        $(t).siblings().hide();
    }
}


function hotelsearch(webpath) {
    var t1 = $('#tm1').val(), t2 = $('#tm2').val(), d = new Date(), c = $('#cid').val();
    if (c == 0) { alert('请选择地区！'); return false; }
    var url = webpath + 'Hotel/List.aspx?cid=' + c; c = $('#tid').val(); if (c) url += '&tid=' + c; c = $('#p1').val(); if (c) url += '&p1=' + c; c = $('#p2').val(); if (c) url += '&p2=' + c;
    if (t1 != '' || t2 != '') {
        if (t1 == '') { alert('请选择入住时间！'); return false; }
        if (t2 == '') { alert('请选择离店时间！'); return false; }
        if (Date.parse(t1.replace(/-/g, '/')) >= Date.parse(t2.replace(/-/g, '/'))) {
            alert('入住时间必须大于离店时间！'); return false;
        } else if (Date.parse(d.getFullYear() + '/' + (d.getMonth() + 1) + '/' + d.getDate()) > Date.parse(t1.replace(/-/g, '/'))) {
            alert('入住时间不能小于今天！'); return false;
        }
        url += '&tm1=' + t1 + '&tm2=' + t2;
    }
    location = url + '&key=' + $('#key').val();
}

$(function () {
    //入住时间
    var t1 = GetCookie("tm1"), t2 = GetCookie("tm2"); if (t1 == '') { var D = new Date(); var D1 = Date.parse(D.getFullYear() + '/' + (D.getMonth() + 1) + '/' + D.getDate()); t1 = D.getFullYear() + '-' + (D.getMonth() + 1) + '-' + D.getDate(); SetCookie("tm1", t1); D = new Date(D1 + 86400000); t2 = D.getFullYear() + '-' + (D.getMonth() + 1) + '-' + D.getDate(); SetCookie("tm2", t2); } $('#tm1').val(t1); $('#tm2').val(t2);
    //地区菜单
    $('[hc_id]').click(function () {
        $('#cid').val($(this).attr('hc_id')); $("#CityName").val($(this).attr('hc_name')); $('.hSDown').hide();
    }).mouseover(function () { $("[hc_id]").removeClass("selected"); $(this).addClass("selected"); });
    $("#CityName").keyup(function (e) {
        if (!e) var e = window.event; var n = e.which || w.keyCode; var v = $(this).val().toLowerCase(); if (n == 40 || n == 48 || n == 13) return; $("[hc_id]").removeClass("selected").hide(); $(v == '' ? '[hc_id]' : '[hc_py^="' + v + '"],[hc_name^="' + v + '"]').show().filter(':first').addClass("selected"); $('.hSDown').show();
    }).keydown(function (e) { if (!e) var e = window.event; var n = e.which || w.keyCode; switch (n) { case 40: var s = -1, h = $('[hc_id]:visible'); if (h.length < 2) return; for (var i = 0; i < h.length; i++) if ($(h[i]).hasClass('selected')) { s = i; break; } s = s == -1 || h.length == s + 1 ? 0 : s + 1; $("[hc_id]").removeClass("selected"); $(h[s]).addClass('selected'); break; case 38: var s = 0, h = $('[hc_id]:visible'); if (h.length < 2) return; for (var i = 0; i < h.length; i++) if ($(h[i]).hasClass('selected')) { s = i; break; } s = s == 0 ? h.length - 1 : s - 1; $("[hc_id]").removeClass("selected"); $(h[s]).addClass('selected'); break; case 13: $('#cid').val($('.selected').attr('hc_id')); $(this).val($('.selected').attr('hc_name')); $('.hSDown').hide(); break; default: break; } }).focus(function () { if ($(this).val() == '中文/拼音') $(this).val('').css('color', ''); var offset = $(this).offset(), v = $(this).val().toLowerCase(); $('.hSDown').show().css({ 'left': offset.left, 'top': offset.top + 20 }); $("[hc_id]").removeClass('selected'); if (v != '') { $('[hc_id]').hide(); $('[hc_py^="' + v + '"],[hc_name^="' + v + '"]').show(); } $("[hc_id]:visible:first").addClass('selected'); }).blur(function () { setTimeout(function () { var v = $("#CityName").val(); var h = $('[hc_py^="' + v + '"],[hc_name^="' + v + '"]'); if (h.length == 1) { $("#CityName").val($(h).attr('hc_name')); $('#cid').val($(h).attr('hc_id')); } else { $('#cid').val(0); } if ($("#CityName").val() == '') $("#CityName").val('中文/拼音').css('color', '#333'); $('.hSDown').hide() }, 500); }).blur();
    $('#tjHotel>.skin1').each(function () { $(this).mouseover(function () { $('#tjHotel>.skin1').show(); $('#tjHotel>.skin2').hide(); $(this).hide(); $(this).next('.skin2').show(); }); }); $('#tjHotel>.skin1:first').mouseover();
});