//-----------------------------------------------------------------------------
// <description>
//    This file contains the javascript functions that support the PSE.com right
//    navigation control.
// </description>
// <author>Vertex Seattle</author>
// <created>07/28/2010</created>
// <updatelog>
// Date         Developer       Description
//-----------------------------------------------------------------------------
// 12/08/2021   John Doe        Sample
// </updatelog>
//-----------------------------------------------------------------------------
function showPopup(navPopUp, navItem, navLink) {
    setBox(navPopUp, navItem);

    document.getElementById(navPopUp).style.display = 'inline';
    document.getElementById(navItem).style.background = 'url("/Style%20Library/PSEcom/Images/right_nav_bg.png") 0px -76px no-repeat';
}


function hidePopup(navPopUp, navItem, navLink) {
    setBox(navPopUp, navItem);

    document.getElementById(navPopUp).style.display = 'none';
    document.getElementById(navItem).style.background = 'url("/Style%20Library/PSEcom/Images/right_nav_bg.png") 0px 0px no-repeat';
}


function getPos(el) {
    for (var lx = 0, ly = 0; el != null; lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);
    return { x: lx, y: ly };
}


function setBox(navPopUp, navItem) {
    // position of the nav item
    var x = findPosX(document.getElementById(navItem));
    var y = findPosY(document.getElementById(navItem));
    var ribbonOffset = 0;
    if (document.getElementById("s4-ribbonrow") != null) {
        ribbonOffset = document.getElementById("s4-ribbonrow").offsetHeight
    }
    // get the poup's width (without the px)
    var popupWidth = document.getElementById(navPopUp).style.width;
    var margin = -11;
    var popupWidth = popupWidth.replace("px", "");

    // get the poup's height (without the px)
    var popupHeight = document.getElementById(navPopUp).style.height;
    var adjVal = +7 - ribbonOffset;
    var popupHeight = popupHeight.replace("px", "");

    // create new positions for the popup
    var newX = (x - popupWidth + margin);
    var newY = y - (popupHeight / 2) + adjVal;

    // set the new position for the popup
    document.getElementById(navPopUp).style.left = "" + newX + "px";
    document.getElementById(navPopUp).style.top = "" + newY + "px";
}


function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent)
        while (1) {
            curleft += obj.offsetLeft;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent)
        while (1) {
            curtop += obj.offsetTop;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}

