//--********************************************************************-->
//--                                                                    -->
//--   Frontier Software Pty Ltd                                        -->
//--                                                                    -->
//--   File Name     : ftrmenu.js                                       -->
//--                                                                    -->
//--   History       :                                                  -->
//--   jfmngt - 13.02.03 - Created.                                     -->
//--   007634 - 02.07.03 - Clerical Self-Service.                       -->
//--   009047 - 11.09.03 - Set the Global variables back to the Manager -->
//--                       values.                                      -->
//--   008983 - 04.12.03 - Changed to use LDAP name Login Name.         -->
//--   007816 - 09.01.04 - FrontLine: Version 1.0.                      -->
//--   009098 - 18.02.04 - Only add menu options if product code        -->
//--                       exists in activation key                     -->
//--   009442 - 11.02.04 - Hold Selected employee value                 -->
//--   007259 - 30.08.04 - Introducing the ToolBar Window               -->
//--   010064 - 15.10.04 - Confirmation Prompt On Form Change           -->
//--   010063 - 17.12.04 - Opera (10062) & Mozilla (10063) supported    -->
//--   010408 - 01.03.05 - Add new starters                             -->
//--   008834 - 22.03.05 - Force a refresh of the page after check.     -->
//--   010982 - 26.07.05 - Secretary Access.                            -->
//--   010391 - 15.09.05 - Executive Reporting Merged                   -->
//--   011171 - 05.10.05 - Corrected back button on workflow pages      -->
//--   011225 - 25.10.05 - Correctly set the sHold variables            -->
//--   011316 - 22.11.05 - Staff search default corrected               -->
//--   011687 - 20.03.06 - Staff tools fixed                            -->
//--   011799 - 20.04.06 - Alert When Modified Corrected On Exit        -->
//--   013668 - 02.03.07 - All times in hh:mm format                    -->
//--********************************************************************-->

// *********************************************************************
//is it in menu debug mode
var gMenuDebug = false;
//gMenuDebug = true;

// String for storing all the menu related building
var sMenuDebug = "";

// *********************************************************************
// 007259 Variables for the toolbar
var oToolWin = null;

// *********************************************************************
function menuPageSelect(sToPage) {
    // Temporary objects to find out which menu the page is in
    var oTemp = menuObjectLoad(sToPage);
    if (oTemp) {
        // Close Time Window
        if ((oTimeWin) && (oTimeWin != null) && (!oTimeWin.closed)) oTimeWin.close();
        // Close Calendar Window
        if ((oCalWin) && (oCalWin != null) && (!oCalWin.closed)) oCalWin.close();
        // Close View Window
        if ((oVewSelWin) && (oVewSelWin != null) && (!oVewSelWin.closed)) oVewSelWin.close();
        // Set the oDataPage Object back to be the dataFrame
        oDataPage = dataFrame;
        // 010408 - data entry for new staff
        switch (sToPage) {
            // 011316 - Set values for the data entry logon
            case "mdwfelst":
                menuEntSwap();
                break;
            // 011687 - Set man mode for terminations   
            case "modetdet":
            case "moterdet":
                bNewStaff = true;
                if (sToPage == "moterdet") {
                    sEmpNo = sHoldEmpNo;
                    sEmpSurInit = sHoldEmpSurInit;
                    menuManSet();
                }
                break;
            default:
                if (bNewStaff) {
                    bNewStaff = false;
                    if (sNewStaffNo != "") loadResetNewStaff();
                }
                break;
        }
        // 010064 - Show a confirm message if required, then move to the selected page
        if (loadPageConfirm()) oDataPage.updatClick(); 
        else oDataPage.location.replace(loadPagePath(sToPage));
    }
    return;
}

// *********************************************************************
// Open Tool Bar Window
function menuToolBar() {
    // Close the Window before opening a new one
    if (oToolWin && (!oToolWin.closed)) {
        oToolWin.close();
    }
    // Set up the initial size values
    var iWidth = 20;
    var iHeight = 110;
    // Increase the width with each addtional item
    if (aDictDetail["setopvew"]["i_print"]) iWidth += 80;
    if (aDictDetail["setopvew"]["i_refresh"]) iWidth += 80;
    if (aDictDetail["setopvew"]["i_zoomin"]) iWidth += 80;
    if (aDictDetail["setopvew"]["i_zoomout"]) iWidth += 80;
    if (aDictDetail["setopvew"]["i_message"]) iWidth += 80;
    // If links have been turned on then set the size of the window
    if (aDictDetail["setopvew"]["i_links"]) {
        iWidth = 420;
        iHeight = 180;
    }
    // Open the ToolBar Window
    var sWindowParameter = sDefaultWindow + ",screenX=100,left=100,screenY=100,top=100,width=" + iWidth + ",height=" + iHeight;
    oToolWin = window.parent.open("setopvew.htm","ToolBarWindow",sWindowParameter,true);
    if (!oToolWin.opener) {
        oToolWin.opener = window;
    }
    return;
}

// *********************************************************************
// Set number of pixels to scroll on the menu
var iScrollInterval = 50;

// *********************************************************************
// 009098 - menuSubCount() returns the number of submenu items where the product code is included
// within the activation key. If this count equals zero, then there is no point displaying
// the parent link.
function menuSubCount(sParentName) {
    if (bActivationKey) {
        // count of number of sub menu items
        var iCount = 0;
        var oTempMenu = new Array();
        if ((bHorizMenu) && (!bHorizShort)) oTempMenu = aHorizMenu;
        else if ((bVertMenu) && (!bVertShort)) oTempMenu = aVertMenu;
        else if ((bHorizShort) || (bVertShort)) oTempMenu = aShortMenu;
        else oTempMenu = aDictMenu;
        for (var sPageName in oTempMenu) {
            if ((oTempMenu[sPageName].parent == sParentName) && (sActivationKey.indexOf(oTempMenu[sPageName].productcode)!=-1)) iCount++;
        }
        return iCount;
    }
    else return true;
}

// *********************************************************************
// Select the appropriate pages here for a specific-page login
function menuObjectLoad(sObjPage) {
    // Set up the oMenu for the page
    var oTemp = false;
    // Allocate the return values
    if (sObjPage) {
        if ((bHorizMenu) && (!bHorizShort) && (aHorizMenu[sObjPage])) oTemp = aHorizMenu[sObjPage];
        else if ((bVertMenu) && (!bVertShort) && (aVertMenu[sObjPage])) oTemp = aVertMenu[sObjPage];
        else if (((bHorizShort) || (bVertShort)) && (aShortMenu[sObjPage])) oTemp = aShortMenu[sObjPage];
        else if (aDictMenu[sObjPage]) oTemp = aDictMenu[sObjPage];
    }
    // Menu Debug
    if (gMenuDebug) sMenuDebug += "menuObjectLoad:\n" + oTemp["title"] + "\n";
    return oTemp;
}

// *********************************************************************
// Select the appropriate pages here for a specific-page login
function menuPageType(sObjPage) {
    // Set up the oMenu for the page
    var sTemp = false;
    // Allocate the return values
    if (sObjPage) {
        var oTemp = menuObjectLoad(sObjPage);
        if (oTemp) sTemp = oTemp["mode"];
    }
    // Menu Debug
    if (gMenuDebug) sMenuDebug += "menuPageType:\n" + sTemp + "\n";
    return sTemp;
}

// *********************************************************************
function menuHorizLogo() {
    var sHtml = "";
    //Set Background colour and image for main menu
    if (sHorizBG) horizFrame.document.body.background = loadPageResource("logo", true) + sHorizBG;
    if (hHorizBG) horizFrame.document.body.style.color = hHorizBG;
    // Menu Debug
    if (gMenuDebug) sMenuDebug += "menuHorizLogo:\n" + sHtml + "\n";
    return sHtml;
}

// *********************************************************************
function menuHorizColor() {
    return ((sHorizBG) ? 'transparent' : hHorizBG);
}

// *********************************************************************
function menuHorizLink(thisType, thisText, thisColor) {
    var tempString = "a" + ((thisType == "pseudo") ? ":" : ".");
    return (tempString + thisText + "{color:" + thisColor + ";background:" + menuHorizColor() + ";}");
}

// *********************************************************************
function menuHorizStyle() {
    // Load common style sheet
    var sHtml = "<link rel='stylesheet' type='text/css' href='styles/";
    if (sCssStyle) sHtml += sCssStyle;
    else sHtml += "common";
    sHtml += ".css'>";
    // Load horiz menu styles
    sHtml += "<style type='text/css'>";
    sHtml += "body {background-color:" + menuHorizColor() + ";} ";
    sHtml += "a {text-decoration:none;color:" + hHorizInactive + ";} ";
    sHtml += menuHorizLink("pseudo","hover", hHorizActive);
    sHtml += "</style>";
    // Menu Debug
    if (gMenuDebug) sMenuDebug += "menuHorizStyle:\n" + sHtml + "\n";
    return sHtml;
}

// *********************************************************************
var horizDivObj = new Object();

// *********************************************************************
function menuHorizInitial() {
    horizDivObj = horizFrame.frames.horizMenu.document.getElementById("horizDiv");
    horizDivObj.style.zIndex = (is.moz) ? 0 : -1;
    return;
}

// *********************************************************************
function menuHorizRight() {
    if ((parseInt(horizDivObj.style.top)) > -1200) {    
        horizDivObj.style.top = (parseInt(horizDivObj.style.top) - iScrollInterval);
    }
    return;
}

// *********************************************************************
function menuHorizLeft() {
    if ((parseInt(horizDivObj.style.top)) < 0) {    
        horizDivObj.style.top = (parseInt(horizDivObj.style.top) + iScrollInterval);
    }
    return;
}

// *********************************************************************
function menuVertLogo() {
    var sHtml = "";
    //Set Background colour and image for main menu
    if (sVertBG) vertFrame.document.body.background = loadPageResource("logo",true) + sVertBG;
    if (hVertBG) vertFrame.document.body.style.color = hVertBG;
    //Only load up Company Logo if specified
    if (sCompanyLogo) {
        if (iVertOffset) {
            sHtml += "<table border='0' width='100%' cellpadding='0' cellspacing='0'><tr><td><img src='" + loadPageResource("menu", true) + "pixel.png' width='1' height='" + iVertOffset + "' border='0' alt=''></td></tr>";
            sHtml += "<tr><td height='2' bgcolor='white'><img src='" + loadPageResource("menu", true) + "pixel.png' width='1' height='1' border='0' alt=''></td></tr>";
            sHtml += "<tr><td><img src='" + loadPageResource("menu", true) + "pixel.png' width='1' height='4' border='0' alt=''></td></tr></table>";
        } else {
            sHtml += "<table border='0' width='100%' cellpadding='0' cellspacing='0'><tr><td><img src='" + loadPageResource("menu", true) + "pixel.png' width='1' height='4' border='0' alt=''></td></tr>";
            sHtml += "<tr><td valign='top' align='center'><img id='companylogo' src='" + loadPageResource("logo", true) + sCompanyLogo + "' alt='" + sCompanyName + "' border='0'></td></tr>";
            sHtml += "<tr><td height='4'><img src='" + loadPageResource("menu", true) + "pixel.png' width='1' height='4' border='0' alt=''></td></tr>";
            sHtml += "<tr><td height='2' bgcolor='white'><img src='" + loadPageResource("menu", true) + "pixel.png' width='1' height='2' border='0' alt=''></td></tr></table>";
        }
    } else {
        sHtml += "<table border='0' width='100%' cellpadding='0' cellspacing='0'><tr><td><img src='" + loadPageResource("menu", true) + "pixel.png' width='1' height='" + iVertOffset + "' border='0' alt=''></td></tr></table>";
    }
    // Menu Debug
    if (gMenuDebug) sMenuDebug += "menuVertLogo:\n" + sHtml + "\n";
    return sHtml;
}

// *********************************************************************
function menuVertColor() {
    return ((sVertBG) ? 'transparent' : hVertBG);
}

// *********************************************************************
function menuVertLink(thisType, thisText, thisColor) {
    var tempString = "a" + ((thisType == "pseudo") ? ":" : ".");
    return (tempString + thisText + "{color:" + thisColor + ";background:" + menuVertColor() + ";}");
}

// *********************************************************************
function menuVertStyle() {
    // Load common style sheet
    var sHtml = "<link rel='stylesheet' type='text/css' href='styles/";
    if (sCssStyle) sHtml += sCssStyle;
    else sHtml += "common";
    sHtml += ".css'>";
    // Load vert menu styles
    sHtml += "<style type='text/css'>";
    sHtml += "body {background-color:" + menuVertColor() + ";} ";
    sHtml += "a {text-decoration:none;color:" + hVertInactive + ";} ";
    sHtml += menuVertLink("pseudo","hover", hVertActive);
    sHtml += "</style>";
    // Menu Debug
    if (gMenuDebug) sMenuDebug += "menuVertStyle:\n" + sHtml + "\n";
    return sHtml;
}

// *********************************************************************
var vertLogoObj = new Object();
var vertDivObj = new Object();

// *********************************************************************
function menuVertInitial() {
    if (bVertShort) {
        vertLogoObj = vertFrame.frames.shortMenu.document.getElementById("shortLogo");
        vertDivObj = vertFrame.frames.shortMenu.document.getElementById("shortDiv");
    } else {
        vertLogoObj = vertFrame.frames.vertMenu.document.getElementById("vertLogo");
        vertDivObj = vertFrame.frames.vertMenu.document.getElementById("vertDiv");
    }
    vertLogoObj.style.zIndex = 1;
    vertDivObj.style.zIndex = (is.moz) ? 0 : -1;
    return;
}

// *********************************************************************
function menuVertDown() {
    if ((parseInt(vertDivObj.style.top)) > -1200) { 
        vertDivObj.style.top = (parseInt(vertDivObj.style.top) - iScrollInterval);
    }
    return;
}

// *********************************************************************
function menuVertUp() {
    var iTop = ((oGlob.is.opera) ? 100 : 0);
    if ((parseInt(vertDivObj.style.top)) < iTop) { 
        vertDivObj.style.top = (parseInt(vertDivObj.style.top) + iScrollInterval);
    }
    return;
}

// *********************************************************************
function menuShortColor() {
    if (bHorizShort) {
        return ((sHorizBG) ? 'transparent' : hHorizBG);
    } else {
        return ((sVertBG) ? 'transparent' : hVertBG);
    }
}

// *********************************************************************
function menuShortLink(thisType, thisText, thisColor) {
    var tempString = "a" + ((thisType == "pseudo") ? ":" : ".");
    if (bHorizShort) {
        return (tempString + thisText + "{color:" + thisColor + ";background:" + menuHorizColor() + ";}");
    } else {
        return (tempString + thisText + "{color:" + thisColor + ";background:" + menuVertColor() + ";}");
    }
}

// *********************************************************************
function menuShortStyle() {
    // Load common style sheet
    var sHtml = "<link rel='stylesheet' type='text/css' href='styles/";
    if (sCssStyle) sHtml += sCssStyle;
    else sHtml += "common";
    sHtml += ".css'>";
    // Load vert menu styles
    sHtml += "<style type='text/css'>body {";
    sHtml += "background-color:" + menuShortColor();
    sHtml += ";} #root {color:" + menuShortColor() + ";} ";
    sHtml += "a {text-decoration:none;color:" + ((bHorizShort) ? hHorizInactive : hVertInactive) + ";} ";
    sHtml += menuShortLink("pseudo","hover", ((bHorizShort) ? hHorizActive : hVertActive));
    sHtml += "</style>";
    // Menu Debug
    if (gMenuDebug) sMenuDebug += "menuShortStyle:\n" + sHtml + "\n";
    return sHtml;
}

// *********************************************************************
// 011316 - Only use for the data entry logon (KIOSKENT profile on USR).
// We always want bManMode to be true, and we never want sEmpNo to be 
// the value of the person logged on.
function menuEntSwap() {
    if (sManNo == sEmpNo) {
        sEmpSurInit = "";
        sEmpNo = "";
        bManMode = true;
    }
    return;
}

// *********************************************************************
function menuManload(sTemp) {
    var oTemp = menuObjectLoad(sTemp);
    if (oTemp && oTemp["parent"]) {
        var sMenuType = oTemp["parent"].substr(5,3);
        if (sMenuType != "" && sMenuType != "ver" && sMenuType != "hor") sTemp = oTemp["parent"];
        menuPageSelect(sTemp);
    }
    sLoadPage = "";
    return;
}

// *********************************************************************
function menuManMode(bManPage) {
    // Reset the sManPage to prevent drill down to a page automatically
    if (bManPage) sManPage = "";
    // Set global values for staff depending on manager mode
    // 011687 - Don't reset if in bNewStaff mode
    if (!oGlob.bNewStaff) {
        if (bManMode) {
            iEmpSeqNo = iHoldEmpSeqNo;
            sEmpNo = sHoldEmpNo;
            sEmpSurInit = sHoldEmpSurInit;
        } else {
            sEmpNo = sManNo;
            sEmpSurInit = sManSurInit;
        }
    } 
    return;
}

// *********************************************************************
// Changed for ZBG 7022, JOB 8407
function menuManSwap() {
    // Set the Manager Mode global variables
    menuManMode(true);
    // 008834: Force a refresh of the page after swapping check
    // Temporary objects to find out which menu the page is in
    var sTemp = dataFrame.location.href.substr(dataFrame.location.href.length-12,8);
    if (sTemp == sErrorPage) sTemp = sLoadPage;
    switch (menuPageType(sTemp)) {
        case "adm":
        case "sys":
        case "ent":
        case "man":
        case "rvw":
            break;
        case "sec":
            switch (sTemp) {
                case "mswfelst":
                    break;
                default:
                    menuManload(sTemp);
                    break;
            }
            break;
        default:
            menuManload(sTemp);
            break;
    }
    return;
}

// *********************************************************************
// Automatically sets page to Man Mode
function menuManSet() {
    var oManSwitch = null;
    // Find out if the manSwitch checkbox object exists on the menu
    if ((bHorizMenu) && (horizFrame.frames.horizMenu)) {
        oManSwitch = horizFrame.frames.horizMenu.document.getElementById("manSwitch");
    } else if ((bVertMenu) && (vertFrame.frames.vertMenu)) {
        oManSwitch = vertFrame.frames.vertMenu.document.getElementById("manSwitch");
    }
    // Now make a change if object exists
    if (oManSwitch) {
        oManSwitch.disabled = false;
        oManSwitch.checked = false;
    }
    // Turn on Manager Mode
    bManMode = true;
    return;
}

// *********************************************************************
function menuPagePrint() {
    if ((oHelpWin) && (!oHelpWin.closed)) {
        oHelpWin.frames[1].frames[1].focus();
        oHelpWin.frames[1].frames[1].print();
    } else if ((oVewSelWin) && (!oVewSelWin.closed)) {
        var oTemp = oVewSelWin.frames.length > 0 ? oVewSelWin.frames[0] : oVewSelWin;
        oTemp.focus();
        oTemp.print();
    } else {
        dataFrame.focus();
        dataFrame.print();
    }
    return;
}

// *********************************************************************
function menuExit() {
    if (loadPageConfirm()) oDataPage.updatClick();
    else {
        // Tidy up any opened windows
        closeWindows();
        // Send the logoff GTR
        var gtrHolder = new Object();
        setGTRField(gtrHolder,"cbr","logoff");
        //8983 - Changed to use LDAP Login Name
        setGTRField(gtrHolder,"user",sLoginName);
        sendGTR(gtrHolder,"Exiting " + sKskTitle + " ...");
    }
    return;
}

// *********************************************************************

