﻿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);
}