var to;

function tipon(event, text)
{
    if (to) clearTimeout(to);
    to = setTimeout("tipshow("+event.pageX+","+event.pageY+",'"+text+"')", 100);
}

function tipshow(eventX, eventY, text)
{
    var ttip = document.getElementById('tooltip');
    
    // Set the tool tip text now so that the computed width is correct.
    // Set the position to 0,0 to prevent display glitches.
    ttip.style.left = '0px';
    ttip.style.top  = '0px';
    ttip.innerHTML = text;
    
    // The default location for the tooltip is at center right (of the mouse)
    var left = (eventX + 15);
    var top  = (eventY - 15);
    
    // If we are on the right edge of the screen, show it at bottom left
    if ((left + ttip.clientWidth+4) > (window.innerWidth + window.pageXOffset))
	{
	    left = left - ttip.clientWidth - 20;
	    top  = top + 30;
	        
	    // If we are on the bottom right corner of the screen, show it at top left
	    if ((top + ttip.clientHeight+4) > (window.innerHeight + window.pageYOffset))
		{ top  = top - 40; }
	}
    
    ttip.style.left = left+'px';
    ttip.style.top  = top+'px';
    ttip.style.visibility = 'visible';
}

function tipoff(event)
{
    if (to) clearTimeout(to);
    var ttip = document.getElementById('tooltip');
    ttip.style.visibility = 'hidden';
    ttip.innerHTML = '';
    ttip.timeout = null;
}
