﻿function ShowPopup(e, title, text, popupWidth, lmode, tmode) {
    // Old ShowPopup - shifting variables [Works in IE ONLY]
    if (typeof (e) === "string" || (e instanceof String)) {
        tmode = lmode;
        lmode = popupWidth;
        popupWidth = text;
        text = title;
        title = e;
        e = null;
    }

    var isIE = false;
    if (window.event) // IE
    { isIE = true; }
    else if (e) {
        // Firefox
        window.event = e;
        window.event.x = e.target.x;
        window.event.y = e.target.y;
    }
    else {
        // We need an event to continue
        return;
    }

    /*
    * Show the popup window
    */
    var scrollTop = 0;
    var scrollLeft = 0;
    var dwidth = 0;
    var dheight = 0;
    // HEIGHT
    if (document.documentElement && !document.documentElement.scrollHeight) {
        // IE6 +4.01 but no scrolling going on
    }
    else if (document.documentElement && document.documentElement.scrollHeight) {
        // IE6 +4.01 and user has scrolled
        dheight = parseInt(document.documentElement.scrollHeight);
    }
    else if (document.body && document.body.scrollHeight) {
        // IE5 or DTD 3.2
        dheight = parseInt(document.body.scrollHeight);
    }
    // WIDTH
    if (document.documentElement && !document.documentElement.scrollWidth) {
        // IE6 +4.01 but no scrolling going on
    }
    else if (document.documentElement && document.documentElement.scrollWidth) {
        // IE6 +4.01 and user has scrolled
        dwidth = parseInt(document.documentElement.scrollWidth);
    }
    else if (document.body && document.body.scrollWidth) {
        // IE5 or DTD 3.2
        dwidth = parseInt(document.body.scrollWidth);
    }
    // TOP
    if (document.documentElement && !document.documentElement.scrollTop) {
        // IE6 +4.01 but no scrolling going on
    }
    else if (document.documentElement && document.documentElement.scrollTop) {
        // IE6 +4.01 and user has scrolled
        scrollTop = parseInt(document.documentElement.scrollTop);
    }
    else if (document.body && document.body.scrollTop) {
        // IE5 or DTD 3.2
        scrollTop = parseInt(document.body.scrollTop);
    }
    // LEFT
    if (document.documentElement && !document.documentElement.scrollLeft) {
        // IE6 +4.01 but no scrolling going on
    }
    else if (document.documentElement && document.documentElement.scrollLeft) {
        // IE6 +4.01 and user has scrolled
        scrollLeft = parseInt(document.documentElement.scrollLeft);
    }
    else if (document.body && document.body.scrollLeft) {
        // IE5 or DTD 3.2
        scrollLeft = parseInt(document.body.scrollLeft);
    }
    var eleft = parseInt(window.event.x) + scrollLeft - 10;
    var etop = parseInt(window.event.y) + scrollTop;
    var pophtml = '';
    pophtml += '<table cellpadding=2 cellspacing=0 border=0 class=\'Popup\' width=\'100%\'>';
    pophtml += '<tr><td class=\'PopupTitle\'><font class=\'PopupTitle\'>' + title + '</font></td></tr>';
    pophtml += '<tr><td class=\'PopupText\'><font class=\'PopupText\'> ' + text + '</font></td></tr>';
    pophtml += '</table>';
    var popupInfo;
    if (document.all) {
        popupInfo = document.all.PopupInfo;
    }
    else {
        popupInfo = document.getElementById("PopupInfo");
    }
    if (!popupInfo) {
        if (!isIE) {
            popupInfo = document.createElement("span");
            popupInfo.className = 'Popup';
            if (e) {
                window.event.target.onmouseout = HidePopup;
            }
            else {
                popupInfo.onmouseout = HidePopup;
            }
        }
        else {
            popupInfo = document.createElement('<span class=\'Popup\' id=\'PopupInfo\' onmouseout=\'HidePopup();\'></span>');
        }


        popupInfo.id = 'PopupInfo';
        popupInfo.innerHTML = pophtml;
        popupInfo.style.position = 'absolute';
        popupInfo.style.cursor = 'hand';
        popupInfo.style.width = popupWidth + "px";
        popupInfo.style.padding = '2px';
        document.body.appendChild(popupInfo);
    }
    else {
        popupInfo.innerHTML = pophtml;
        popupInfo.style.display = '';
        popupInfo.style.width = popupWidth + "px";
    }
    if (lmode == "left") {
        eleft = scrollLeft + 10;
    }
    else if (lmode == "right") {
        eleft = scrollLeft + dwidth - parseInt(popupInfo.clientWidth) - 10;
    }
    popupInfo.style.left = '' + eleft + "px";
    var moveleft = parseInt(window.event.x) + parseInt(popupInfo.clientWidth);
    if (moveleft > dwidth) {
        var l = moveleft - dwidth;
        popupInfo.style.left = eleft - l;
    }

    popupInfo.style.top = '' + "" + (etop - parseInt(popupInfo.clientHeight) - 10) + "px";

    var minTop = scrollTop;
    if (parseInt(popupInfo.style.top) < minTop) {
        popupInfo.style.top = minTop + "px";
        popupInfo.style.left = parseInt(popupInfo.style.left) + "px";
    }

}
function HidePopup() {
    /*
    * Hide the popup window
    */
    var popupInfo;
    if (document.all) {
        popupInfo = document.all.PopupInfo;
    }
    else {
        popupInfo = document.getElementById("PopupInfo");
    }
    if (popupInfo) {
        popupInfo.style.display = 'none';
    }
}
