var hvrTimeouts = new Array();
var tipDiv;
function createPopup(divId, hoverText, width, borderColor, backColor, useDropShadow) {
    var contentDivId = divId + '_content';
    if (hvrTimeouts[contentDivId])
        window.clearTimeout(hvrTimeouts[contentDivId]);
    var contentDiv = document.getElementById(contentDivId);

    if (contentDiv) {
        contentDiv.innerHTML = hoverText;
    }

    if (!backColor) {
        backColor = "ffe59a";
    }

    if (!borderColor) {
        borderColor = "000";
    }

    if (!document.getElementById(divId)) {
        if (useDropShadow) {
            tipDiv = document.createElement('div');
            tipDiv.id = divId;
            tipDiv.className = 'dropShadowContainer';

            contentDiv = document.createElement('div');
            contentDiv.id = contentDivId;
            contentDiv.className = 'dropShadowContent';

            contentDiv.style.backgroundColor = "#" + backColor;
            contentDiv.style.border = "1px solid #" + borderColor;
            contentDiv.style.padding = "5px";
            if (width && width != "auto") {
                contentDiv.style.width = width + "px";
            }
            contentDiv.innerHTML = hoverText;

            tipDiv.appendChild(contentDiv);
            tipDiv.innerHTML += '<div class="dropShadowBottomLeft"></div><div class="dropShadowBottom"></div><div class="dropShadowBottomRight"></div><div class="dropShadowBottomRightCorner"></div><div class="dropShadowRightBottom"></div><div class="dropShadowRight"></div><div class="dropShadowRightTop"></div>';
        }
        else {
            tipDiv = document.createElement('div');
            tipDiv.id = divId;
            tipDiv.style.backgroundColor = "#" + backColor;
            tipDiv.style.border = "1px solid #" + borderColor;
            tipDiv.style.padding = "5px";
            if (width && width != "auto") {
                tipDiv.style.width = width + "px";
            }
            tipDiv.innerHTML = hoverText;
        }

        tipDiv.style.position = 'absolute';
        tipDiv.style.display = 'none';
        tipDiv.style.zIndex = '999999';
        document.body.insertBefore(tipDiv, document.body.firstChild);
    }
    else {
        tipDiv = document.getElementById(divId);
    }
    document.body.onmousemove = positionPopup;
    positionPopup(null);
}

function hidePopup(divId) {
    if (divId != null && divId != "") {
        var objdiv = document.getElementById(divId);
        if (objdiv != null) {
            hvrTimeouts[divId] = window.setTimeout('document.getElementById(\'' + divId + '\').style.display=\'none\';', 100);
        }
        tipDiv = null;
    }
    document.body.onmousemove = '';
}

function positionPopup(e) {
    ie = document.all ? true : false
    var x = 0;
    var y = 0;
    if (tipDiv != null) {
        var width = tipDiv.clientWidth;
        var height = tipDiv.clientHeight;

        // get the window dimensions
        var myWidth = 0, myHeight = 0;
        if (typeof (window.innerWidth) == 'number') {
            //Non-IE
            myWidth = window.innerWidth;
            myHeight = window.innerHeight;
        } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
        } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
            //IE 4 compatible
            myWidth = document.body.clientWidth;
            myHeight = document.body.clientHeight;
        }

        // get the scroll amount
        var scrOfX = 0, scrOfY = 0;
        if (document.body.scrollTop != undefined) {	// IE model
            var ieBox = document.compatMode != "CSS1Compat";
            var cont = ieBox ? document.body : document.documentElement;
            scrOfX = cont.scrollLeft;
            scrOfY = cont.scrollTop;
        } else {
            scrOfX = window.pageXOffset;
            scrOfY = window.pageYOffset;
        }

        if (ie) {
            x = event.clientX + scrOfX;
            y = event.clientY + scrOfY;
        } else if (e) {
            x = e.pageX
            y = e.pageY
        }
        y -= height;

        // catch possible negative values
        if (x < 0) {
            x = 0
        }
        if (y < 0) {
            y = 0
        }

        var xVal = document.getElementById("xVal");
        var yVal = document.getElementById("yVal");



        // Don't let the bubble drop off the side of the page.
        if ((myWidth - x) < width) {
            x = x - width - 8;
        }
        else {
            x = x + 5;
        }

        if (tipDiv) {
            tipDiv.style['top'] = y + 8 + "px";
            tipDiv.style['left'] = x + "px";
            tipDiv.style.display = '';
        }
    }
}
