﻿var tipShowing = false;
var _suppressTip = false;
var inDiv = false;
var _bId = 0;
Dea.ToolTip = function(event, node, bId, router) {
    if (bId && bId !== null) {
        _bId = bId;
    }
    var e = event || window.event;
    var node_tooltip = Dea.Get("emsTip");
    Dea.ToolTip.node = node;
    Dea.ToolTip.isFocus = e.type === "focus";
    if (_suppressTip === false) {
        showHandler();
    }
    return Dea.browser.stopPropagation(e);

    function showHandler() {
        if (tipShowing === true) {
            return false;
        }

        Dea.ToolTip.tip.style.visibility = "visible";
        Dea.setHtml(Dea.Get("emsTipContent"), ems_PauseToLoadMsg);
        Dea.setDisplay(node_tooltip, "block", null, null, "absolute");
        Dea.ToolTip.setPosition();
        Dea.browser.addEvent(node, "mouseout", hideHandler, true);

        Dea.ToolTip.currentTipTimer = window.setTimeout("Dea.ToolTip.getTip(" + bId + ", '" + router + "')", 1000);
        tipShowing = true;
    }

    function hideHandler(event) {
        overDiv(Dea.Mouse.x, Dea.Mouse.y);

        if (!inDiv) {
            var e = event || window.event;

            if (Dea.ToolTip.hideTip()) {
                Dea.setDisplay(node_tooltip, "none", null, null, null);
                Dea.browser.removeEvent(node, "mouseout", hideHandler, true);
                Dea.setHtml(Dea.Get("emsTipContent"), ems_PauseToLoadMsg);
                tipShowing = false;
            }
        }
        else {
            Dea.ToolTip.currentTipTimer = window.setTimeout('Dea.ToolTip.hideTip()', 1000);
        }
    }
}

Dea.ToolTip.closeTip = function() {
    if (Dea.ToolTip.currentTipTimer !== null) {
        window.clearTimeout(Dea.ToolTip.currentTipTimer);
        Dea.ToolTip.currentTipTimer = null;
    }

    Dea.setHtml(Dea.Get("emsTipContent"), ems_PauseToLoadMsg);
    Dea.setDisplay(Dea.ToolTip.tip, "none");
    tipShowing = false;
    return true;
}


Dea.ToolTip.hideTip = function() {
    var coordX, coordY;

    coordX = (Dea.ToolTip.tip.offsetLeft < Dea.Mouse.x) ? Dea.Mouse.x - 5 : Dea.Mouse.x + 20;
    coordY = (Dea.ToolTip.tip.offsetTop < Dea.Mouse.y) ? Dea.Mouse.y : Dea.Mouse.y + 20;

    overDiv(coordX, coordY);
    if (!inDiv) {
        if (Dea.ToolTip.currentTipTimer !== null) {
            window.clearTimeout(Dea.ToolTip.currentTipTimer);
            Dea.ToolTip.currentTipTimer = null;
        }

        Dea.setHtml(Dea.Get("emsTipContent"), ems_PauseToLoadMsg);
        Dea.setDisplay(Dea.ToolTip.tip, "none");
        tipShowing = false;
        return true;
    }
    else {
        window.setTimeout('Dea.ToolTip.hideTip()', 1000);
        return false;
    }
}

Dea.ToolTip.loadTipHtml = function(tipHtml, tipWidth, tipColor, tipBorder) {
    if (typeof tipWidth !== "undefined" && tipWidth !== null) {
        Dea.ToolTip.tip.style.width = tipWidth = "px";
    }

    if (typeof tipColor !== "undefined" && tipColor !== null) {
        Dea.ToolTip.tip.style.bgColor = tipColor;
    }

    if (typeof tipBorder !== "undefined" && tipBorder !== null) {
        Dea.ToolTip.tip.style.border = tipBorder;
    }
    Dea.setHtml(Dea.Get("emsTipContent"), tipHtml);
    Dea.ToolTip.setPosition();
    return false;
}

Dea.ToolTip.init = function() {
    Dea.ToolTip.tip = Dea.Get("emsTip");
    Dea.ToolTip.node = null;
    Dea.ToolTip.isFocus = false;
    Dea.ToolTip.currentTipTimer = null;
    Dea.setHtml(Dea.Get("emsTipContent"), ems_PauseToLoadMsg);
}

Dea.ToolTip.setPosition = function() {
if (Dea.ToolTip.tip) {
    var pageX = Dea.Mouse.x;
    var pageY = Dea.Mouse.y;
    var offset = 10;
        if (tipShowing) {

            if (Dea.ToolTip.isFocus) {
                var p = Dea.findPos(Dea.ToolTip.node);
                Dea.setDisplay(Dea.ToolTip.tip, "", Number(p[0]) - 15 + "px", p[1] + Dea.ToolTip.node.offsetHeight + "px")
            }
            else {
                Dea.ToolTip.tip.style.visibility = "hidden";

                if ((pageX + offset + Dea.ToolTip.tip.offsetWidth) > Dea.Mouse.windowWidth) {
                    Dea.ToolTip.tip.style.left = pageX - (Dea.ToolTip.tip.offsetWidth + offset) + "px";
                }
                else {
                    Dea.ToolTip.tip.style.left = pageX + offset + "px";
                }

                if ((pageY + offset + Dea.ToolTip.tip.offsetHeight) > Dea.Mouse.windowHeight) {
                    Dea.ToolTip.tip.style.top = Dea.Mouse.windowHeight - (Dea.ToolTip.tip.offsetHeight) + "px";
                }
                else {
                    Dea.ToolTip.tip.style.top = pageY + "px";
                }

            }
            Dea.ToolTip.tip.style.visibility = "visible";
        }
        else {
            if ((pageX + offset + Dea.ToolTip.tip.offsetWidth + 125) > Dea.Mouse.windowWidth) {
                Dea.ToolTip.tip.style.left = pageX - (Dea.ToolTip.tip.offsetWidth + offset) + "px";
            }
            else {
                Dea.ToolTip.tip.style.left = pageX + offset + "px";
            }

            if ((pageY + offset + Dea.ToolTip.tip.offsetHeight + 125) > Dea.Mouse.windowHeight) {
                Dea.ToolTip.tip.style.top = Dea.Mouse.windowHeight - (Dea.ToolTip.tip.offsetHeight) + "px";
            }
            else {
                Dea.ToolTip.tip.style.top = pageY + "px";
            }
        }
    }
}

Dea.ToolTip.getTip = function(itemId, router) {
    if(_bId > 0) {
        itemId = _bId;
    }
    var coordX, coordY;
    coordX = (Dea.ToolTip.tip.offsetLeft < Dea.Mouse.x) ? Dea.Mouse.x : Dea.Mouse.x + 10;
    coordY = (Dea.ToolTip.tip.offsetTop < Dea.Mouse.y) ? Dea.Mouse.y : Dea.Mouse.y + 10;
    overDiv(coordX, coordY);

    if (overDiv) {
        Dea.setEmsData(true);
        Dea.emsData.tipItemId = itemId;
        Dea.makeCallback(router);
    }
    
    return;
}

function showDetails(page, qs, w, h) {
    var link = PathToRoot + page + "?" + qs;
    var width = w || 500;
    var height = h || 550;
    showPopWin(link, width, height, null, true);
    return false;
}

function overDiv(x, y) {
    var toolTip = Dea.ToolTip.tip;
    var left = toolTip.offsetLeft;
    var right = toolTip.offsetLeft + toolTip.offsetWidth;
    var top = toolTip.offsetTop;
    var bottom = toolTip.offsetTop + toolTip.offsetHeight;

    if ((x > left && x <= right + 20) && (y > top && y < bottom + 20)) {
        inDiv = true;
    }
    else {
        inDiv = false;
    }   
 }

 document.write("<div id='emsTip'><div id='closeTip' onclick='Dea.ToolTip.closeTip();'><img src='Images/Close.gif' /></div><div id='emsTipContent'></div></div>");
Dea.widgets.add(Dea.ToolTip);





