﻿var isTongHang = true; //标识是否是同行
window.onload = function() {
    if (typeof (isB2C) != "undefined" && isB2C == "true") {
        switchLogin($("liVisitor"), 1);
    }
    else {
        if ($("liTonghang")) {
            switchLogin($("liTonghang"), 0);
            $("regit").title = "同行注册";
        }
    }
    if ($("txtName"))
        setTxtOnKeyPress();
    if (typeof (userInfoArr) != "undefined" && userInfoArr.length > 0) {
        if ($("txtName")) {
            $("txtName").value = userInfoArr[0];
            //$("txtPass").value = userInfoArr[1];
        }
    }
    if ($("floatQQ")) { //qq悬浮
        initialFloatQQ();
    }

}
function chkLogin() {
    if ($("txtName").value.length == 0) {
        //alert("用户名不能为空!");
        showWarningTip("用户名不能为空!", $("txtName"));
        $("txtName").focus();
        return;
    }
    if ($("txtPass").value.length == 0) {
        //alert("密码不能为空!");
        showWarningTip("密码不能为空!", $("txtPass"));
        $("txtPass").focus();
        return;
    }
    if ($("txtName").value.length > 0 && $("txtPass").value.length > 0) {
        var oForm = document.forms[0];
        oForm.method = "post";
        if ($("liTonghang").className == "bg")
            oForm.action = "/Index.aspx?actions=login";
        else {
            oForm.action = "/Index.aspx?actions=visitorLogin";
            //b2c用户预订前登录
            if ($("hfPrevParam"))
                oForm.action = "/Index.aspx?actions=visitorLogin&params=" + escape($("hfPrevParam").value.substring(1));
        }
        oForm.submit();
    }
}

function chkCurrentPgLogin() {
    if ($("txtName").value.length == 0) {
        //alert("用户名不能为空!");
        showWarningTip("用户名不能为空!", $("txtName"));
        $("txtName").focus();
        return;
    }
    if ($("txtPass").value.length == 0) {
        //alert("密码不能为空!");
        showWarningTip("密码不能为空!", $("txtPass"));
        $("txtPass").focus();
        return;
    }
    if ($("txtName").value.length > 0 && $("txtPass").value.length > 0) {
        var oForm = document.forms[0];
        var oUrl = "http://" + window.location.host + window.location.pathname;
        oForm.method = "post";
        if ($("liTonghang").className == "bg") {
            if (window.location.search.length == 0 && window.location.pathname.indexOf("Flights.aspx") != -1) {
                oForm.action = "/Index.aspx?actions=login";
            }
            else
                oForm.action = oUrl + "?actions=login&" + window.location.search.substring(1);
        }
        else {
            if (window.location.search.length == 0 && window.location.pathname.indexOf("Flights.aspx") != -1) {
                oForm.action = "/Index.aspx?actions=visitorLogin";
            }
            else
                oForm.action = oUrl + "?actions=visitorLogin&" + window.location.search.substring(1);
        }
        oForm.submit();
    }
}


function logout() {
    var oForm = document.forms[0];
    oForm.method = "post";
    oForm.action = "/Index.aspx?actions=logout";
    oForm.submit();
}

//处理在登录框文本框内按下回车的情况
function handleEnterOnTxt(evt) {
    var key = (isIE ? window.event.keyCode : evt.which);
    if (key == 13) {
        $("login").focus(); // 登录按钮获得焦点
        if ($("txtContactName")) {
            chkCurrentPgLogin();
        }
        else
            chkLogin();
        return false;
    }
    return true;
}

function showAirCompanys(oNum) {
    if (parseInt(oNum) == 1) {
        $("trAirCompany1").style.display = "none";
        $("trAirCompany2").style.display = "";
        $("liMore").style.display = "none";
        $("liSource").style.display = "";
    }
    else {

        $("trAirCompany1").style.display = "";
        $("trAirCompany2").style.display = "none";

        $("liMore").style.display = "";
        $("liSource").style.display = "none";

    }
}

function setHidValue(oTxt) {
    switch (oTxt.id.toString()) {
        case "txtName":
            if (isTongHang)
                $("hfTUserName").value = $("txtName").value;
            else
                $("hfVisitorName").value = $("txtName").value;
            break;
        case "txtPass":
            if (isTongHang)
                $("hfTPwd").value = $("txtPass").value;
            else
                $("hfVisitorPwd").value = $("txtPass").value;
            break;
    }
}

// 公司同行和游客切换
function switchLogin(oLi, oNum) {
    var oUrl = "";
    if (parseInt(oNum) == 0) {
        isTongHang = true;
        oUrl = "/InfoMyself/Register.aspx";
        $("liTonghang").className = "bg";
        $("liVisitor").className = "";
        $("regit").title = "同行注册";
        $("txtName").value = $("hfTUserName").value;
        $("txtPass").value = $("hfTPwd").value;
    }
    else {
        isTongHang = false;
        oUrl = "/InfoMyself/VisitorRegister.aspx";
        if ($("liTonghang")) {
            $("liVisitor").className = "bg";
            $("liTonghang").className = "";
            $("regit").title = "游客注册";
            $("txtName").value = $("hfVisitorName").value;
            $("txtPass").value = $("hfVisitorPwd").value;
        }
    }
    if ($("regit")) {
        $("regit").onclick = function() {
            window.location = oUrl;
        }
    }
}

// 使IE和FF同时兼容onkeypress事件
function setTxtOnKeyPress() {
    var oName = $("txtName");
    var oPwd = $("txtPass");
    var oChkCode = $("txtCheckCode");

    EventUtil.addEvent(oName, "keypress", handleEnterOnTxt); //添加事件 
    EventUtil.addEvent(oPwd, "keypress", handleEnterOnTxt);
    EventUtil.addEvent(oChkCode, "keypress", handleEnterOnTxt);
    //EventUtil.removeEvent(oChkCode, "keypress", handleEnterOnTxt); //移除事件
}