﻿//--------------------------------------------------------------------------------------
//
// ContextSensitiveHelp.js
//
//--------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------
var csi_cancelOpenArray = new Array();
var csi_cancelCloseArray = new Array();

//--------------------------------------------------------------------------------------
function csi_showHelpFloatWindow(windowID, objID, horizPadding, vertPadding, goRight, waitDurationInMilliseconds) {
    // keep the window open
    csi_cancelCloseArray[windowID] = true;
    csi_cancelOpenArray[windowID] = false;

    setTimeout("csi_showHelpFloatWindowInternal('" + windowID + "','" + objID + "'," + horizPadding + "," + vertPadding + "," + goRight + ");", waitDurationInMilliseconds);
}

//--------------------------------------------------------------------------------------
function csi_showHelpFloatWindowInternal(windowID, objID, horizPadding, vertPadding, goRight) {
    // exit function immediately if open command has been cancelled
    if (csi_cancelOpenArray[windowID] == true) return;

    var w = document.getElementById(windowID);
    var obj = document.getElementById(objID);
    if (w != null && obj != null) {
        w.style.display = 'block';
        w.style.visibility = 'visible';

        w.style.top = (getAscendingTops(obj) + vertPadding) + 'px';

        if (getAscendingTops(obj) + vertPadding < 0) w.style.top = '0px';

        if (goRight == true)
            w.style.left = (getAscendingLefts(obj) + obj.offsetWidth + horizPadding) + 'px';
        else {
            w.style.left = (getAscendingLefts(obj) - horizPadding - w.offsetWidth) + 'px';
            if ((getAscendingLefts(obj) - horizPadding - w.offsetWidth) < 0) w.style.left = (getAscendingLefts(obj) + obj.offsetWidth + horizPadding) + 'px';
        }
    }
}

//--------------------------------------------------------------------------------------
function csi_hideHelpFloatWindow(windowID, waitDurationInMilliseconds) {
    // cancel the open
    csi_cancelOpenArray[windowID] = true;

    // wait before hiding window
    csi_cancelCloseArray[windowID] = false;

    setTimeout("csi_hideHelpFloatWindowInternal('" + windowID + "');", waitDurationInMilliseconds);
}

//--------------------------------------------------------------------------------------
function csi_hideHelpFloatWindowInternal(windowID) {
    // exit function immediately if close command has been cancelled
    if (csi_cancelCloseArray[windowID] == true) return;

    var w = document.getElementById(windowID);
    if (w != null) {
        w.style.display = 'none';
        w.style.visibility = 'hidden';

        w.top = '-999px';
        w.left = '-999px';
    }
}

//--------------------------------------------------------------------------------------
function getAscendingLefts(elem) {
    if (elem == null) {
        return 0;
    } else {
        return elem.offsetLeft + getAscendingLefts(elem.offsetParent);
    }
}

//--------------------------------------------------------------------------------------
function getAscendingTops(elem) {
    if (elem == null) {
        return 0;
    } else {
        return elem.offsetTop + getAscendingTops(elem.offsetParent);
    }
}

//--------------------------------------------------------------------------------------
// End of file
//--------------------------------------------------------------------------------------
