function inspect(elm){var str = "";for (var i in elm){str += i + ": " + elm.getAttribute(i) + "\n";}status = "inspect:" + str;/*el('ta').value = str;*/}
function show(id){var elem = el(id);if (elem){elem.style.visibility = 'visible';elem.style.display = 'inline';}}
function showblock(id){var elem = el(id);if (elem){elem.style.visibility = 'visible';elem.style.display = 'block';}}
function hide(id){var elem = el(id);if (elem){elem.style.visibility = 'hidden';elem.style.display = 'none';}}        
function el(id){return document.getElementById(id);}
function isUndefined(v){return (typeof v == 'undefined');}
function point(){var x;var y;}
function getOffsets(elem)
{
    var p = new point();
    if (elem)
    {
        var l = elem.offsetLeft;
        var parent = elem.offsetParent;
        while (parent)
        {
            if (parent.offsetLeft)
            {
                l += parent.offsetLeft;
            }
            parent = parent.offsetParent;
        }
        p.x = l;
        //status = body.scrollTop;
        var t = elem.offsetTop;
        parent = elem.offsetParent;
        while (parent)
        {
            if (parent.offsetTop)
            {
                t += parent.offsetTop;
            }
            parent = parent.offsetParent;
        }
        p.y = t;// + body.scrollTop;
    }
    return p;
}

function getEventSource(e)
{
    if (!e)
    {
        e = window.event;
    }
    if (e && e.target)
    {
        return e.target;
    }
    else
    if (e && e.srcElement)
    {
        return e.srcElement;
    }
    return null;
}

String.prototype.trim = new Function("return this.replace(/^\\s+|\\s+$/g,'')");

var clickX;
var clickY;
var windowWidth;
var windowHeight;
var popupWidth;
var scrollTop;
var scrollLeft;
var scrollBottom;
var scrollRight;
function positionPopup(popupId)
{
   popupWidth = el(popupId).offsetWidth;
   popupHeight = el(popupId).offsetHeight;
   //alert(popupWidth + " " + popupHeight);
   //Check if the popup is forcing a scroll right
   //If it is try to position it to the left.
   //But if the left is clipping the window positiong to the right anyways
   var overflowsRight = (clickX + popupWidth) > windowWidth;
   var posnLeft = clickX + scrollLeft;
   if (overflowsRight){posnLeft = posnLeft - popupWidth;}
   if (posnLeft < 0)
   {
       posnLeft = clickX + scrollLeft;
   }
   //Check if the popup is forcing a scroll down
   //If it is try to position it to the top.
   //But if the left is clipping the window positiong to the right anyways
   var overflowsBottom = (clickY + popupHeight) > windowHeight;
   //alert('cx=' + clickX + ' cy=' + clickY + ' ww=' + windowWidth + ' wh=' + windowHeight + ' pw=' + popupWidth + ' ph=' + popupHeight + ' st=' + scrollTop + ' sl=' + scrollLeft + ' sb=' + scrollBottom + ' sr=' + scrollRight);
   //alert(overflowsRight + ' ' + overflowsBottom);
   var posnTop = clickY + scrollTop;
   if (overflowsBottom){posnTop = posnTop - popupHeight;}
   if (posnTop < 0)
   {
       var posnTop = clickY + scrollTop;
   }           
   //
   el(popupId).style.left = posnLeft;
   el(popupId).style.top = posnTop;
}
