//http://www.texsoft.it/index.php?c=software&m=sw.js.htmltooltip&l=it
function xstooltip_findPosX(obj) 
{
  var curleft = 0;
  if (obj.offsetParent) 
  {
    while (obj.offsetParent) 
        {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function xstooltip_findPosY(obj) 
{
    var curtop = 0;
    if (obj.offsetParent) 
    {
        while (obj.offsetParent) 
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}

function xstooltip_show(tooltipId, parentId, posX, posY)
{
    tip = document.getElementById(tooltipId);
    
    if ((tip.style.top == '' || tip.style.top == 0) 
        && (tip.style.left == '' || tip.style.left == 0))
    {
        // need to fixate default size (MSIE problem)
        tip.style.width = tip.offsetWidth + 'px';
        tip.style.height = tip.offsetHeight + 'px';
        
        par = document.getElementById(parentId); 
    
        // if tooltip is too wide, shift left to be within parent 
        if (posX + tip.offsetWidth > par.offsetWidth) posX = par.offsetWidth - tip.offsetWidth;
        if (posX < 0 ) posX = 0; 
        
        x = xstooltip_findPosX(par) + posX;
        y = xstooltip_findPosY(par) + posY + par.offsetHeight;
        
        tip.style.top = y + 'px';
        tip.style.left = x + 'px';
        tip.style.width = (par.offsetWidth - 8) + 'px';
    }
    
    tip.style.visibility = 'visible'; 
}

function xstooltip_hide(id)
{
    tip = document.getElementById(id); 
    tip.style.visibility = 'hidden'; 
}

