﻿function showType(type) {
    if (type == 1) {
        $("#fancheng").css("visibility", "hidden");
    }
    else {
        $("#fancheng").css("visibility", "visible");
    }
}

function doSubmit() {
    if ($("#indate").val() == "" || $("#startdate").val() == "yyyy-mm-dd") {
        alert("入住日期不能为空.");
        $("#indate").focus();
        return false;
    }
    if (!chkDate($("#indate").val())) {
        alert("入住日期输入错误.");
        $("#indate").focus();
        return false;
    }
    if ($("#outdate").val() == "" || $("#startdate").val() == "yyyy-mm-dd") {
        alert("离店日期不能为空.");
        $("#outdate").focus();
        return false;
    }
    if (!chkDate($("#outdate").val())) {
        alert("离店日期输入错误.");
        $("#outdate").focus();
        return false;
    }
    var nowDate = new Date();
    //nowDate.setDate(nowDate.getDate()+1);
    var nowYear = nowDate.getFullYear();
    var nowMonth = nowDate.getMonth() + 1;
    var nowDay = nowDate.getDate() == 1 ? nowDate.getDate() : (nowDate.getDate() - 1);
    if (!CompareDate(nowYear + "-" + nowMonth + "-" + nowDay, $("#indate").val())) {
        alert("入住日期不能早于或等于当前日期.");
        return false;
    }
    if (!CompareDate($("#indate").val(), $("#outdate").val())) {
        alert("离店日期不能早于入住日期.");
        return false;
    }
    if ($("#pricebegin").val() != "") {
        if (!chkInt($("#pricebegin").val())) {
            alert("价格输入错误.");
            $("#pricebegin").focus();
            return false;
        }
    }
    if ($("#priceend").val() != "") {
        if (!chkInt($("#priceend").val())) {
            alert("价格输入错误.");
            $("#priceend").focus();
            return false;
        }
    }
}

//日期比较....
function CompareDate(v1, v2) {
    if (v1 == "" || v2 == "") {
        //alert('请输入日期！');
        return false;
    }
    if (!chkDate(v1) || !chkDate(v2)) {
        //alert('日期格式不正确！');
        return false;
    }
    else {
        //大小判断，转成日期变量，然后比较符判断即可...
        //打算用到展会开始时间和结束时间的判断，那个破验证控件不知道怎么弄。
        //直接用脚本....
        var v1Ary = v1.split('-');
        var v2Ary = v2.split('-');
        var d1 = new Date(v1Ary[1] + '/' + v1Ary[2] + '/' + v1Ary[0]);
        var d2 = new Date(v2Ary[1] + '/' + v2Ary[2] + '/' + v2Ary[0]);
        if (d1.getTime() > d2.getTime()) {
            //alert('前面的日期必须小于后面的日期！');
            return false;
        }
        else {
            return true;
        }
    }
}

//检查是否整数
function chkInt(val) {
    if ((!isFinite(val)) || (isNaN(parseInt(val))) || val.lastIndexOf(".") > -1) {
        return false
    }
    return true
}

//------------------初始化数据---------------------------
function oninit() {
    //出发/返程时间
    $("#starttime").append(betime);
    $("#endtime").append(betime);
    //航空公司
    $("#aircompanyid").append(aircompany);
    //舱位等级
    $("#berthtypeid").append(berthtype);
}

//------------------全部酒店----------------------------
$(document).ready(function() {
    $("#rangeid_all").click(function() {
        $("#hotellist").empty().append("<div><img src=\"http://" + window.location.host + "/Images/loading2.gif\" alt\"\"/> 数据加载中...</div>");
        var html = '';
        $.each([5, 4, 3, 2], function(i, n) {
            html += "<h3><img src=\"http://" + window.location.host + "/Images/start" + n + ".gif\" alt=\"\" /></h3>";
            $.each(hotels, function(j, m) {
                if (hotels[j][0] == n) {
                    html += "<a href=\"#\" onclick=\"javascript:selectHotel(" + hotels[j][0] + ",'" + hotels[j][3] + "','" + hotels[j][2] + "');return false;\">" + hotels[j][2];
                    if (hotels[j][4] != '')
                        html += '<span style="color:blue">-位于' + hotels[j][4] + "</span>";
                    html += "</a>";
                }
            });
        });
        $("#hotellist div").empty().append(html);

        $("#hotellist").css({ 'left': '0px', 'padding': '5px  8px', 'color': '#096C89', 'width': '800px', 'height': '530px', 'background-color': '#fff', 'border': '1px solid #096C89' });
        $("#hotellist h3").css({ 'margin': '5px 0', 'height': '22px', 'border-bottom': '1px dotted #ccc' });
        $("#hotellist div").css({ 'margin': '5px 0', 'verflow': 'auto', 'height': '500px' });
        $("#hotellist div a").css({ 'display': 'inline-block', 'width': '350px', 'color': '#ff6600', 'text-decoration': 'underline', 'padding-right': '5px', 'line-height': '20px' });
        box = $.weeboxs.open('#hotellist', { title: '选择酒店', type: 'dialog', showButton: false, width: 800, height: 530 });
    });
});

function selectHotel(starlevel, areaid, hotelname) {
    $.each($('input[name="starlevel"]'), function(i, n) {
        if (n.value == starlevel)
            n.checked = true;
        else
            n.checked = false;
    });
    var areas = $('input[name="rangeid"]');
    if (areaid != '') {
        for (var i = 0; i < areas.length; i++) {
            if (areas[i].value == areaid) {
                areas[i].checked = "checked";
                break;
            }
        }
    }
    else {
        areas[0].checked = "checked";
    }
    $('#hotelname').val(hotelname);
    box.close();
}
