//--********************************************************************-->
//--                                                                    -->
//--   Frontier Software Pty Ltd                                        -->
//--                                                                    -->
//--   File Name     : ftrlink.js                                       -->
//--                                                                    -->
//--   History       :                                                  -->
//--   jfmngt - 02.08.04 - Created.                                     -->
//--   009098 - 18.02.04 - linkBarLists() only loads links if product   -->
//--                       code exists in activation key                -->
//--   007259 - 28.07.04 - Introducing the ToolBar Window               -->
//--   010063 - 17.12.04 - Opera (10062) & Mozilla (10063) supported    -->
//--   007775 - 06.12.04 - Search by Pay Period                         -->
//--   010982 - 26.07.05 - Secretary Access.                            -->
//--   013901 - 10.05.07 - loadPageCurrent function created             -->
//--   013949 - 23.05.07 - Correcting Title and Runtime Error           -->
//--********************************************************************-->

// *********************************************************************
function linkBarButton(oLinkBar, sLinkBar, bLinkPerRow) {
    var sHtml = "";
    if (bLinkPerRow) { 
        sHtml += "</tr><tr>";
        if (bButtonHtml) sHtml += "<td>&nbsp;</td>";
        sHtml += "</tr><tr>";
    }
    sHtml += hdftButtonLoad('lnk_' + sLinkBar,'View Staff ' + oLinkBar['title'],oLinkBar['title'],sLinkBar);  
    sHtml += "<td><img src='" + loadPageResource("menu") + "pixel.png' width='10' height='1' alt=''></td>";
    return sHtml;
}

// *********************************************************************
// Sets the Link Options on any type of Staff List Page
//
// PLEASE NOTE: 
// ============
// DO NOT ALTER THE CODE IN THE FUNCTION BELOW WITHOUT FIRST CHECKING
// WITH THE WEB TEAM LEADER.
//
function linkBarLists(sLinkType) {
    // Check if iButtonPerRow is set in config, else default it to 7
    var iButtonPerRow = 7;
    if (oDataPage.oDict["buttons"]) iButtonPerRow = oDataPage.oDict["buttons"]["labeltext"];
    // Reset the count variable to zero everytime the function is called
    var iButtonCount = 0;
    // Load the string with the first table tags
    var sHtml = "<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr>";
    // Seperate out into the Staff Link Bar for Staff List and other HR21 Profile Link Bars
    // Select the correct menu object to scan
    var oDictMenu = new Object();
    if ((bHorizMenu) && (!bHorizShort)) oDictMenu = aHorizMenu;
    else if ((bVertMenu) && (!bVertShort)) oDictMenu = aVertMenu;
    else if ((bHorizShort) || (bVertShort)) oDictMenu = aShortMenu;
    else oDictMenu = aDictMenu;
    // Scan the oDictMenu settings for those that need to be on the link bar
    for (var sIndex in oDictMenu) {
        if ((oDictMenu[sIndex]) && (oDictMenu[sIndex].parent) && (oDictMenu[sIndex].ref) && (oDictMenu[sIndex].parent != "top")) {
            switch (oDictMenu[sIndex].mode) {
                case "lnk":
                    if ((sLinkType == "Staff") && (sMenuProfile != "sec") && ((!bActivationKey) || (sActivationKey.indexOf(oDictMenu[sIndex].productcode) != -1))) {
                        sHtml += linkBarButton(oDictMenu[sIndex],sIndex,(iButtonCount % iButtonPerRow == 0));
                        iButtonCount++;
                    }
                    break;
                case "clr":
            		if ((sLinkType == "Clerical") || (sLinkType == "Staff")) {
                        sHtml += linkBarButton(oDictMenu[sIndex],sIndex,(iButtonCount % iButtonPerRow == 0));
                        iButtonCount++;
                    }
                    break;
                case "ent":
            		if ((sLinkType == "Data") || ((sLinkType == "Staff") && (sIndex.indexOf("md") == -1))) {
                        sHtml += linkBarButton(oDictMenu[sIndex],sIndex,(iButtonCount % iButtonPerRow == 0));
                        iButtonCount++;
                    }
                    break;
                case "rvw":
            		if (sLinkType == "Review") {
                        sHtml += linkBarButton(oDictMenu[sIndex],sIndex,(iButtonCount % iButtonPerRow == 0));
                        iButtonCount++;
                    }
                    break;
                case "sec":
            		if ((sLinkType == "Staff") && (sMenuProfile == "sec")) {
                        sHtml += linkBarButton(oDictMenu[sIndex],sIndex,(iButtonCount % iButtonPerRow == 0));
                        iButtonCount++;
                    }
                    break;
            }
        }
    }
    sHtml += "</tr></table><br>";
    return sHtml;
}

// *********************************************************************
// Sets the Skill Control Options row on Course Skills List page
function linkBarSkill() {
    var sHtml = "<table border='0' cellpadding='0' cellspacing='0' align='center' width='100%'>";
    sHtml += hdftHeadingCreate();
    sHtml += "<td><a href='javascript:void(0)' class='Headings'>Courses for skill: " + aDrillDownData[2] + "</a></td>";
    sHtml += "</tr></table><br>";
    return sHtml;
}

// *********************************************************************
// Function added to handle the Timesheet Controls
// Sets the Time Control Options row on Pending Timesheets page
function linkBarTime() {
    var sHtml = "<table border='0' cellpadding='0' cellspacing='0' align='center' width='100%'>";
    sHtml += hdftHeadingCreate();
    switch (sKskType) {
        case "STG":
            sHtml += "<td><a href='javascript:void(0)' class='Headings' onClick='if (!(oGlob.bListEmpty)) { chkAll(0); } this.blur(); return false;'>Decline All</a></td>";
            sHtml += "<td><a href='javascript:void(0)' class='Headings' onClick='if (!(oGlob.bListEmpty)) { chkAll(1); } this.blur(); return false;'>Hold All</a></td>";
            sHtml += "<td><a href='javascript:void(0)' class='Headings' onClick='if (!(oGlob.bListEmpty)) { chkAll(2); } this.blur(); return false;'>No Act All</a></td>";
            sHtml += "<td><a href='javascript:void(0)' class='Headings' onClick='if (!(oGlob.bListEmpty)) { chkAll(3); } this.blur(); return false;'>Approve All</a></td>";
            sHtml += "<td><a href='javascript:void(0)' class='Headings' onClick='if (!(oGlob.bListEmpty)) { chkAll(4); } this.blur(); return false;'>Reset All</a></td>";
            break;
        default:    
            sHtml += "<td><a href='javascript:void(0)' class='Headings' onClick='if (!(oGlob.bListEmpty)) { chkAll(0); } this.blur(); return false;'>Approve All</a></td>";
            sHtml += "<td><a href='javascript:void(0)' class='Headings' onClick='if (!(oGlob.bListEmpty)) { chkAll(1); } this.blur(); return false;'>Decline All</a></td>";
            sHtml += "<td><a href='javascript:void(0)' class='Headings' onClick='if (!(oGlob.bListEmpty)) { chkAll(2); } this.blur(); return false;'>Reject All</a></td>";
            sHtml += "<td><a href='javascript:void(0)' class='Headings' onClick='history.go(0); return true;'>Reset All</a></td>";
            break;
    }
    sHtml += "</tr></table><br>";
    return sHtml;
}

// *********************************************************************
// 007259 - Storage object for bookmark data
var oLink = new Object();
oLink.aLink = new Array();

//**********************************************************************
function LinkField(sPage, sTitle, sGraphic) {
    this.linkpage = sPage;
    this.title = sTitle;
    this.graphic = sGraphic;
    this.deleted = false;
}

// *********************************************************************
function linkCreate(sLinkType) {
    // Load the Object
    var oDictMenu = new Object();
    if ((bHorizMenu) && (!bHorizShort)) oDictMenu = aHorizMenu;
    else if ((bVertMenu) && (!bVertShort)) oDictMenu = aVertMenu;
    else if ((bHorizShort) || (bVertShort)) oDictMenu = aShortMenu;
    else oDictMenu = aDictMenu;
    // Scan the oDictMenu settings for those that need to be on the link bar
    for (var sIndex in oDictMenu) {
        if ((oDictMenu[sIndex]) && (oDictMenu[sIndex].parent) && (oDictMenu[sIndex].ref) && (oDictMenu[sIndex].parent != "top")) {
            switch (oDictMenu[sIndex].mode) {
                case "lnk":
                    if ((sLinkType == "Staff") && (sMenuProfile != "sec") && ((!bActivationKey) || (sActivationKey.indexOf(oDictMenu[sIndex].productcode) != -1))) {
                        oLink.aLink[oLink.aLink.length] = new LinkField(sIndex,oDictMenu[sIndex].title,oDictMenu[sIndex].graphic);
                    }
                    break;
                case "clr":
            		if ((sLinkType == "Clerical") || (sLinkType == "Staff")) {
                        oLink.aLink[oLink.aLink.length] = new LinkField(sIndex,oDictMenu[sIndex].title,oDictMenu[sIndex].graphic);
                    }
                    break;
                case "ent":
            		if (sLinkType == "Data") {
                        oLink.aLink[oLink.aLink.length] = new LinkField(sIndex,oDictMenu[sIndex].title,oDictMenu[sIndex].graphic);
                    }
                    break;
                case "rvw":
            		if (sLinkType == "Review") {
                        oLink.aLink[oLink.aLink.length] = new LinkField(sIndex,oDictMenu[sIndex].title,oDictMenu[sIndex].graphic);
                    }
                    break;
                case "sec":
            		if ((sLinkType == "Staff") && (sMenuProfile == "sec")) {
                        oLink.aLink[oLink.aLink.length] = new LinkField(sIndex,oDictMenu[sIndex].title,oDictMenu[sIndex].graphic);
                    }
                    break;
            }
        }
    }
    return;
}

// *********************************************************************
function linkAdd() {
    var oTempMenu = new Object();
    var sTempPage = loadPageCurrent();
    var sType = loadPageType(sDataPage);
    if (sType != "V" && sType != "S" && (!bDrillMode) && (!linkCheck())) { 
        if (aHorizMenu[sTempPage]) oTempMenu = aHorizMenu[sTempPage]; 
        else if (aVertMenu[sTempPage]) oTempMenu = aVertMenu[sTempPage]; 
        else oTempMenu = aDictMenu[sTempPage];
        // Create the aLink Array
        oLink.aLink[oLink.aLink.length] = new LinkField(sTempPage,oTempMenu.title,oTempMenu.graphic);
        linkRefresh();
    }
    return;
}

// *********************************************************************
function linkRemove() {
    linkCheck(true);
    linkRefresh();
    return;
}

// *********************************************************************
function linkCheck(bDelete) {
    var oTemp = oLink.aLink;
    var sTempPage = loadPageCurrent();
    var bMatchFound = false;
    for (var i = 0; i < oTemp.length; i++) {
        if ((oTemp[i].linkpage == sTempPage) && (!oTemp[i].deleted)) {
            bMatchFound = true;
            if (bDelete) oLink.aLink[i].deleted = true;
        }
    }
    return bMatchFound;
}

// *********************************************************************
// 010063 - method for setting element events fixed for all supported browsers
function linkRefresh() {
    var oTemp = oLink.aLink;
    var oTableBody = oToolWin.document.getElementById("bdyLinks");
    var oTableMain = oToolWin.document.getElementById("tblLinks");
    if ((oTableMain) && (oTableBody)) {
        // remove the existing table
        for (var i = oTableMain.rows.length-1; i >= 0; i--) {
            oTableMain.deleteRow(i);
        }
        // redraw the table
        for (var i = 0; i < oTemp.length; i++) { 
            if (!oTemp[i].deleted) {
                var sType = oTemp[i].graphic;
                var oRow = oToolWin.document.createElement("tr");
                oRow.onmouseover = function() {oGlob.listSetRowActive(this);}
                oRow.onmouseout = function() {oGlob.listSetRowInactive(this);}
                eval("oRow.onclick = function() {oGlob.menuPageSelect('" + oTemp[i].linkpage + "');}");
                oRow.title = "Jump to " + oTemp[i].title;
                oTableBody.appendChild(oRow);
                // Insert page image
                var oCell = oToolWin.document.createElement("td");
                oCell.width = '70';
                oCell.innerHTML = "<img src='" + loadPageResource("menu", true) + sType + ".png' height='18' width='18' border='0'>";
                oRow.appendChild(oCell);
                // Insert page title
                oCell = oToolWin.document.createElement("td");
                oCell.innerHTML = "<a href='javascript:void(0);' class='HTMLLabel'>" + oTemp[i].title + "</a>";
                oCell.className = "Prompt";
                oRow.appendChild(oCell);
            }
        }
    }
    return;
}

// *********************************************************************
