﻿
/*国际机票搜索*/
$(document).ready(function() {
    $("#txt_departDate,#txt_returnDate,#txt_godate,#txt_backdate").bind("focus", function() {
        DoActive(this, false);
    })
    $("#rb_OneWay").bind("click", function() {
        selectDual(true);
    })
    $("#rb_TowWay").bind("click", function() {
        selectDual(false);
    })
//    $("#btn_search").bind("click", function() {
//        searchTicket(1);
//    })
//    $("#btn_searchFlightTime").bind("click", function() {
//        searchTicket(2);
//    })
    //折扣代码
    if ($("#txt_DC_Code").val() == "") {
        $("#txt_DC_Code").val('请输入折扣代码');
        $("#txt_DC_Code").addClass("Gray1");
        $("#txt_DC_Code").bind("focus", function() {
            $(this).removeClass("Gray1");
            $(this).unbind("focus");
            $(this).val('');
        })
    }
})
//查询航班与航班时刻表
function searchTicket(type) {
    var departCity = XP_Get3Code($("#txt_begionCity").val());
    if (departCity == "") {
        alert("请选择出发城市！")
        $("#txt_begionCity").click();
        $("#txt_begionCity").focus();
        return false;
    }
    var arrivalCity = XP_Get3Code($("#txt_endCity").val());
    if (arrivalCity == "") {
        alert("请选择抵达城市！");
        $("#txt_endCity").click();
        $("#txt_endCity").focus();
        return false;
    }
    if (departCity == arrivalCity) {
        alert("出发城市与抵达城市不能是同一个城市，请重新选择！");
        $("#txt_endCity").click();
        $("#txt_endCity").focus()
        return false;
    }
    var departDate = $("#txt_departDate").val();
    var returnDate = $("#txt_returnDate").val();
    if (!isDate(departDate)) {
        alert("请选择出发日期！")
        $("#txt_departDate").focus();
        return false;
    }
    var dual = 0;
    if ($("#rb_TowWay")[0].checked == true) {
        dual = 1;
        if (!isDate(returnDate)) {
            alert("请选择回程日期！")
            $("#txt_returnDate").focus();
            return false;
        }
        if (departDate == returnDate) {
            alert("回程日期与出发日期不能是同一天！")
            $("#txt_returnDate").focus();
            return false;
        }
        if (!CheckDatesBS(departDate, returnDate)) {
            alert("回程日期不能小于出发日期")
            $("#txt_returnDate").focus();
            return false;
        }
    }
    var urlData = "";
    var airlinc = "";
    if (type == 1) {
        urlData = "/passPages/SearchTicket.aspx";
    }
    else {
        urlData = "/passPages/SearchFlightTime.aspx";
        if ($("#txt_airlinc").val() != undefined) {
            airlinc = $("#txt_airlinc").val();
            if (airlinc.length > 0 && airlinc.length != 2) {
                alert("请输入航空公司2字代码！");
                $("#txt_airlinc").focus();
                return false;
            }
        }
    }
    var dcCode = $("#txt_DC_Code").val();
    if (dcCode == "undefined" || dcCode == null || dcCode == "" || checkCH(dcCode))
        dcCode = "";
    urlData += "?dual=" + dual + "&begioncity=" + departCity + "&endcity=" + arrivalCity + "&startime=" + departDate + "&backtime=" + returnDate + "&airlinc=" + airlinc + "&dcCode=" + dcCode;
    if (type == 2)
        getLoadingUrl2(urlData);
    else
        getLoadingUrl(urlData);
}

//点击图象按钮时触发日期控件的选择
function GetShowInputClear(temp) {
    var txt_begionDate = document.getElementById(XP_txt_begionDate);
    var txt_endDate = document.getElementById(XP_txt_returnDate);
    if (temp == 1) { txt_begionDate.onfocus(); }
    else if (temp == 2) { txt_endDate.onfocus(); }
}
//点击图象按钮时触发城市控件的选择
function GetShowInputCitys(temp) {
    var txt_begioncitys = document.getElementById(XP_txt_begionCitys);
    var txt_endcitys = document.getElementById(XP_txt_endCitys);
    if (temp == 1) { txt_begioncitys.onclick(); }
    else if (temp == 2) { txt_endcitys.onclick(); }
}
//单程时的日期选择式显示
function selectDual(flag) {
    $("#txt_returnDate").attr("disabled", flag);
}

//绑定选择条件
function bindSearchDateAndDual(strdual) {
    if (strdual == "0") {
        $("#rb_OneWay")[0].checked = true;
        selectDual(true);
    }
    else {
        $("#rb_TowWay")[0].checked = true;
        selectDual(false);
    }
}

//绑定查询的条件
function GetBindSearchInfo(strbegioncity, strendcity, begioncitycode, endcitycode) {
    var begionCitys = $("#txt_begionCity")[0];
    var endCitys = $("#txt_endCity")[0];
    if (strbegioncity != "") {
        begionCitys.value = strbegioncity + "(" + begioncitycode + ")";
        begionCitys.style.color = "#000";
        begionCitys.title = strbegioncity + "(" + begioncitycode + ")";
    }
    if (strendcity != "") {
        endCitys.value = strendcity + "(" + endcitycode + ")";
        endCitys.style.color = "#000";
        endCitys.title = strendcity + "(" + endcitycode + ")";
    }
}

