var websiteAbsolutlyPath = "";

//生成菜单路径
function ShowUrlConn(tag, obj, menuindex, path, usertype, fullpath) {

    var temp = Header.SetMENUIndex(menuindex);

    if (tag == "6") {
        alert("Under Construction!!  Come up SOON!!");
        return;
    } else if (tag == "7" && usertype != "GTT") {
        var confirmInfo = "(1)GTT will charge $10 Service Fee for each Ticket and 4% Credit Card fee.  Pls include this in your Selling Price.\n";
        confirmInfo = confirmInfo + "(2) Pls click 'Order' link on upper right corner and you will be linked to China Flight Search/Booking webpages ALL in English (it may tak 30-50 sec, pls wait...).\n";
        confirmInfo = confirmInfo + "(3) Once order is completed with Order Number, pls click the 'China Flight Order Mgmt'(under GttGlboal Booking Tab) and enter Credit Card Payment info to issue Ticket.  Pls order ticket in 24 hours to avoid price change.";
        if (!confirm(confirmInfo))
            return;
    }
    var AccountCodeNo = "";
    try {
        SaveItemClickRecord(tag);
        if (document.getElementById("ctl00_Header1_HideAccountCode") != null)
            AccountCodeNo = document.getElementById("ctl00_Header1_HideAccountCode").value;
        else if (document.getElementById("Header1_HideAccountCode") != null)
            AccountCodeNo = document.getElementById("Header1_HideAccountCode").value;
        if (tag != "14" && tag != "0" && tag != "100" && tag != "105" && tag != "107" && tag != "108" && tag != "104" && tag != "110" && tag != "116") {
            if (AccountCodeNo == "") {
                alert("Welcome to GTT Global's Demo booking program.\nThis program allows you to see live availability and pricing but you cannot complete\na reservation until you have been set up with an account code. To get an account.\ncode, please send a request to sales@gttglobal.com.")
                //return;
            }
        }
    }
    catch (e) { }

   
    if (tag == "100") {
        obj.href = path + "Index.aspx";
        obj.target = "_top";
        obj.click();
    }
    else if (tag == "101") {
        obj.href = path + "SearchFare/searchFare.aspx";
        obj.target = "_top";
        obj.click();
    }
    else if (tag == "102") {
        obj.href = path + "BasePage/Upload.aspx";
        obj.target = "_top";
        obj.click();
    }
    else if (tag == "103") {
        obj.href = path + "BasePage/GTTReport.aspx";
        obj.target = "_top";
        obj.click();
    }
    else if (tag == "104") {
        obj.href = path + "BasePage/TermsConditions.aspx";
        obj.target = "_top";
        obj.click();
    }
    else if (tag == "105") {
        obj.href = path + "BasePage/UserInfo.aspx";
        obj.target = "_top";
        obj.click();
    }
    //        else if (tag == "106") {
    //            obj.href = "#";
    //            obj.target = "_top";
    //            obj.click();
    //        }
    else if (tag == "107") {
        obj.href = path + "BasePage/AboutUs.aspx";
        obj.target = "_top";
        obj.click();
    }
    else if (tag == "108") {
        obj.href = path + "BasePage/branch.aspx";
        obj.target = "_top";
        obj.click();
    }
    else if (tag == "109") {
        obj.href = path + "BookingManage/OrderInfo.aspx";
        obj.target = "_top";
        obj.click();
    }
    else if (tag == "110") {
        obj.href = path + "BasePage/Register.aspx";
        obj.target = "_top";
        obj.click();
    }
    else if (tag == "111") {
        obj.href = path + "BasePage/Office.aspx";
        obj.target = "_top";
        obj.click();
    }
    else if (tag == "112") {
        obj.href = path + "BasePage/UserInfo02.aspx";
        obj.target = "_top";
        obj.click();
    }
    else if (tag == "113") {
        obj.href = path + "BasePage/UserInfo03.aspx";
        obj.target = "_top";
        obj.click();
    }
    else if (tag == "114") {
        obj.href = path + "BasePage/MistakeReport.aspx";
        obj.target = "_top";
        obj.click();
    }
    else if (tag == "115") {
        obj.href = path + "BasePage/ForgotPassword.aspx";
        obj.target = "_top";
        obj.click();
    }
    else if (tag == "116") {
        obj.href = path + "BasePage/Careers.aspx";
        obj.target = "_top";
        obj.click();
    }
    else if (tag == "1") {
        obj.href = "../Sabre/SearchFlight.aspx";
        obj.target = "_self";
        obj.click();
    } else if (tag == "2") {
        //        obj.href = "../Default.aspx?type=" + tag;
        obj.href = fullpath;
        obj.target = "_blank";
        obj.click();
    } else if (tag == "24") {
        //        obj.href = "../Default.aspx?type=" + tag;
        obj.href = fullpath;
        obj.target = "_blank";
        obj.click();
    }
    else if (tag == "25") {
        //        obj.href = "../Default.aspx?type=" + tag;
        obj.href = fullpath;
        obj.target = "_blank";
        obj.click();
    }
    else if (tag == "3") {
        obj.href = "../Default.aspx?type=" + tag;
        obj.click();
        obj.target = "_top";
    } else if (tag == "4") {
        obj.href = "../Default.aspx?type=" + tag;
        obj.click();
        obj.target = "_top";
    } else if (tag == "5") {
        obj.href = "../Default.aspx?type=" + tag;
        obj.click();
        obj.target = "_top";
    } else if (tag == "7") {
        createFormAndSubmit();
    } else if (tag == "8") {
        //        obj.href = "../Default.aspx?type=" + tag;
        obj.href = fullpath;
        obj.target = "_blank";
        obj.click();
    } else if (tag == "9") {
        obj.href = "../Default.aspx?type=" + tag;
        obj.click();
        obj.target = "_top";
    } else if (tag == "10") {
        //        obj.href = "../Default.aspx?type=" + tag;
        obj.href = fullpath;
        obj.target = "_blank";
        obj.click();
    } else if (tag == "11") {
        obj.href = "../Default.aspx?type=" + tag;
        obj.click();
        obj.target = "_top";
    } else if (tag == "12") {
        obj.href = "../Default.aspx?type=" + tag;
        obj.click();
        obj.target = "_top";
    } else if (tag == "13") {
        obj.href = "../Default.aspx?type=" + tag;
        obj.click();
        obj.target = "_top";
    } else if (tag == "14") {
        obj.href = "../Default.aspx?type=" + tag;
        obj.click();
        obj.target = "_top";
    } else if (tag == "15") {
        obj.href = "../Default.aspx?type=" + tag;
        obj.click();
        obj.target = "_top";
    } else if (tag == "16") {
        obj.href = path + "AgencyForm/Forms.aspx";
        obj.target = "_top";
        obj.click();
    } else if (tag == "17") {
        obj.href = "../SearchFare/searchTourFare.aspx?MJV=T";
        obj.target = "_top";
        obj.click();
    } else if (tag == "18") {
        //        obj.href = "../Default.aspx?type=" + tag;
        obj.href = fullpath.replace("TYPE=T", "TYPE=I");
        obj.target = "_blank";
        obj.click();
    } else if (tag == "19") {
        obj.href = "../Worldspan/SearchFlight.aspx";
        obj.target = "_self";
        obj.click();
    } else if (tag == "20") {
        obj.href = "../AgencyForm/AgentInfo.aspx";
        obj.target = "_top";
        obj.click();
    } else if (tag == "21") {
        obj.href = "../Worldspan/SearchFlight.aspx?BookingType=3";
        obj.target = "_self";
        obj.click();
    } else if (tag == "22") {
        obj.href = "../TravelSky/SearchFlight.aspx?BookingType=4";
        obj.target = "_self";
        obj.click();
    } else if (tag == "23") {
        obj.href = '../Ean/EanFrame.aspx';
        obj.target = "_top";
        obj.click();
    }
    else if (tag == "26") {
        obj.href = "../SearchFare/searchTSFare.aspx?MJV=TS";
        obj.target = "_top";
        obj.click();
    }
    else if (tag == "27") {
        obj.href = "../BasePage/UserUpdate.aspx";
        obj.target = "_top";
        obj.click();
    }
    else if (tag == "28") {
        obj.href = "../BasePage/AgentCommisionSheet.aspx";
        obj.target = "_top";
        obj.click();
    }
}

function createCitsSubmit() {
    var submitForm = getNewSubmitForm();
    submitForm.action = "http://10.227.52.12:12345";
    createNewFormElement(submitForm, "UserID", '<%=UserID %>');
    createNewFormElement(submitForm, "Type", '<%=UserType %>');
    submitForm.target = "_blank";
    submitForm.submit();
}

function getNewSubmitForm() {
    var submitForm = document.createElement("FORM");
    document.body.appendChild(submitForm);
    submitForm.method = "POST";
    return submitForm;
}

function createNewFormElement(inputForm, elementName, elementValue) {
    var newElement = document.createElement("input");
    newElement.type = "hidden";
    newElement.name = elementName;
    inputForm.appendChild(newElement);
    newElement.value = elementValue;
    return newElement;
}

function createFormAndSubmit() {
    var submitForm = getNewSubmitForm();
    submitForm.action = "http://b2b.cits.com.cn/citsonlineWeb/online/gttLogin.jsp";
    createNewFormElement(submitForm, "UserName", "GTT-CITS");
    createNewFormElement(submitForm, "Password", "cits");
    createNewFormElement(submitForm, "UserID", '<%=UserID %>');
    createNewFormElement(submitForm, "AgentName", '<%=AgentName %>');
    createNewFormElement(submitForm, "AgentCode", '<%=UserNo %>');
    createNewFormElement(submitForm, "Telephone", '<%=Telephone %>');
    createNewFormElement(submitForm, "Email", '<%=EmailAddress %>');
    createNewFormElement(submitForm, "Branch", '<%=BranchOffice %>');
    createNewFormElement(submitForm, "ExchangeRate", '<%=CitisRmbRate %>');
    submitForm.target = "_blank";
    submitForm.submit();
}

function SubmitToCITS(uid,agentName,uno,tel,email,branch,citisRmbRate) {
    var submitForm = getNewSubmitForm();
    submitForm.action = "http://b2b.cits.com.cn/citsonlineWeb/online/gttLogin.jsp";
    createNewFormElement(submitForm, "UserName", "GTT-CITS");
    createNewFormElement(submitForm, "Password", "cits");
    createNewFormElement(submitForm, "UserID", uid);
    createNewFormElement(submitForm, "AgentName", agentName);
    createNewFormElement(submitForm, "AgentCode", uno);
    createNewFormElement(submitForm, "Telephone", tel);
    createNewFormElement(submitForm, "Email", email);
    createNewFormElement(submitForm, "Branch", branch);
    createNewFormElement(submitForm, "ExchangeRate", citisRmbRate);
    submitForm.target = "_blank";
    submitForm.submit();
}

//Session超时后弹出等待页面
function sessionTimeout() {
    try {
        var timeleft = $("#lblTime").val();
        timeleft = timeleft - 1;
        $("#lblTime").val(timeleft);

        if (timeleft <= 0) {
            window.clearInterval(sessionTimeout);

            var dialogContent = "<div id='popTimeOut' class='search_frame'><div class='search_top'><div class='search_pic'><img src='" + websiteAbsolutlyPath + "images/popup_timeout.jpg' alt='' /></div><div class='search_bold'>Timeout Notification</div><div class='popup_txt'>Your session has timed out after 60 minutes of inactivity.</div><div class='popup_txt'>Please click OK to login again.</div><div class='popup_txt'><span class='popup_btn'><a href='javascript:void(0)' onclick='Timeout_Logout();'>OK</a></span></div></div><div class='search_bot'></div></div>";
            //弹出等待页面
            var timeoutDialog = $.dialog({
                id: 'searching',
                content: dialogContent,
                lock: true,
                opacity: 0,
                drag: false,
                esc: false,
                cancel: false,
                cancelVal: null,
                title: null,
                resize: false
            });
        }
    } catch (e) { }
}

//跳转到Logout页面，实现登出，清空Session
function Timeout_Logout() {
    top.document.location.href = websiteAbsolutlyPath + "BasePage/Logout.aspx";
}

//每分钟判断一次Session是否超时
self.setInterval("sessionTimeout()", 60000);

//记录菜单点击数量
//具体业务逻辑实现在Header的cs文件中
function SaveItemClickRecord(tag) {
    switch (tag) {
        case "19":
            Header.SaveItemClickRecord("WorldSpanBooking");
            break;
        case "1":
            Header.SaveItemClickRecord("EVABooking");
            break;
        case "3":
            Header.SaveItemClickRecord("In-House Credit Card Charge");
            break;
        case "2":
            Header.SaveItemClickRecord("Hotel & Tour Booking");
            break;
        case "7":
            Header.SaveItemClickRecord("China Flight Booking");
            break;
        case "8":
            Header.SaveItemClickRecord("Tour Booking");
            break;
        case "9":
            Header.SaveItemClickRecord("China Flight Order Mgmt");
            break;
        case "10":
            Header.SaveItemClickRecord("GTA Hotel");
            break;
    }
}
