﻿// JScript File
function OpenNewPopupWindow(url, width, height)
{
    window.open(url, '_blank', 'resizable=yes,toolbar=no, location=yes, directories=no, status=no, menubar=no, copyhistory=yes, width=' + width + ', height=' + height);
}

function GetAbsoluteTop(element)
{
    var i = 0;
    var c = element;
    while(c!=null)
    {
        i += c.offsetTop;
        c = c.offsetParent;
    }
    return i;
}

function GetAbsoluteLeft(element)
{
    var i = 0;
    var c = element;
    while(c!=null)
    {
        i += c.offsetLeft;
        c = c.offsetParent;
    }
    return i;
}


var _cur_mnu = null;
var _timer_mnu = null;

function DelayHide()
{
    if (_timer_mnu!=null)
        CancelHide();
    _timer_mnu = window.setTimeout("HideMenu();", 500);
}

function CancelHide()
{
    window.clearTimeout(_timer_mnu);
    _timer_mnu = null;
}

function HideMenu()
{
    if (_timer_mnu!=null)
    {
        CancelHide();
    }
    if (_cur_mnu!=null)
    {
        _cur_mnu.style.display = "none";
        _cur_mnu = null;
    }
}

function ShowMenu(menuElementId, srcElement)
{
    HideMenu();
    _cur_mnu = $get(menuElementId);
    if (_cur_mnu==null)
        return;
    // move the element to the body tag
    _cur_mnu.parentNode.removeChild(_cur_mnu);
    document.body.appendChild(_cur_mnu);
    
    var x = GetAbsoluteLeft(srcElement);
    var y = 95; //RG:doesn't work with absolute positioning   GetAbsoluteTop(srcElement) + srcElement.offsetHeight;
    
    _cur_mnu.style.position = "absolute";
    _cur_mnu.style.left = x.toString() + "px";
    _cur_mnu.style.top = y.toString() + "px";
    _cur_mnu.style.display = "block";
    _cur_mnu.onmouseover = function() { CancelHide(); };
    srcElement.onmousemove = function(evt)
                                {
                                    if (!evt)
                                        window.event.cancelBubble = true;
                                    else
                                        evt.stopPropagation();
                                };
    _cur_mnu.onmousemove = function(evt)
                                {
                                    if (!evt)
                                        window.event.cancelBubble = true;
                                    else
                                        evt.stopPropagation();
                                };                     
    window.document.body.onmousemove = function() { DelayHide(); };
    
    
}
