﻿function showType(type) {
    if (type == 1) {
        $("#fancheng").css("visibility", "hidden");
    }
    else {
        $("#fancheng").css("visibility", "visible");
    }
}

function doSubmit(searchDay) {
    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;
    }
    var val = Date.parse($("#indate").val().replace(/-/gi, "/"));
    var last = Date.parse(nowDate) + searchDay * 24 * 3600 * 1000;
    if (val > last) {
        alert("最新價格在調整中，請聯繫客服！");
        return false;
    }
    if (!CompareDate($("#indate").val(), $("#outdate").val())) {
        alert("離店日期不能早於入住日期.");
        return false;
    }
    var val2 = Date.parse($("#outdate").val().replace(/-/gi, "/"));
    var last2 = Date.parse(nowDate) + searchDay * 24 * 3600 * 1000;
    if (val2 > last2) {
        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();
}




