
var tipOffsetX = -20;
var tipOffsetY = 10;
var tipEnabled = false;


function showTip(strText, intWidth, e) {
    var objTip = document.getElementById("toolTip");
    if (objTip) {
        //objTip.style.width = intWidth + "px";
        objTip.innerHTML = strText;
        tipEnabled = true;
        positionTip(e);
        setTimeout("displayTip()",1700);
    }
    return false;
}

function displayTip() {
    var objTip = document.getElementById("toolTip");
    if (objTip) {
        objTip.style.visibility = "visible";
    }
}

function positionTip(e){
    var objTip = document.getElementById("toolTip");
    if (tipEnabled && objTip) {
        var curX = e.pageX;
        var curY = e.pageY;
        var rightEdge = window.innerWidth - e.clientX - tipOffsetX - 20;
        var bottomEdge = window.innerHeight - e.clientY - tipOffsetY - 20;
        var leftEdge = (tipOffsetX < 0) ? tipOffsetX * (-1) : -1000;

        if (rightEdge < objTip.offsetWidth) {
            objTip.style.left = window.pageXOffset + e.clientX - objTip.offsetWidth + "px";
        } else if (curX < leftEdge) {
            objTip.style.left = "5px";
        } else {
            objTip.style.left = curX + tipOffsetX + "px";
        }
    
        if (bottomEdge < objTip.offsetHeight) {
            objTip.style.top = window.pageYOffset + e.clientY - objTip.offsetHeight - tipOffsetY + "px";
        } else {
            objTip.style.top = curY + tipOffsetY + "px";
        }
        
    }
}

function hideTip() {
    tipEnabled = false;
    var objTip = document.getElementById("toolTip");
    if (objTip) {
        objTip.style.visibility = "hidden";
        objTip.style.left = "-1000px";
    }
}

//document.onmousemove = positionTip;




// ************************ old tooltip code: 



function ShowIt(sDesc, e, iLen, showAbove, showLeft)
{ 

//	var e = window.event;
	if (e.pageX || e.pageY)
	{
		x = e.pageX;
		y = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		x = e.clientX + document.body.scrollLeft;
		y = e.clientY + document.body.scrollTop;
	}
	else 
	{
		x=100;
		y=100;
        }
    
        if(showAbove) {
    	    y -= 15;
        } else {
    	    y += 15;
        }

        if (showLeft) {
            x -= 80;
        }
    
        //alert("in show " + x + "  " + y);

        var toolTip = document.createElement('div');
        toolTip.setAttribute('id','theTip');
        toolTip.setAttribute('style','display:none;position:absolute;z-index:1; top:'+y+'; left:'+x+';');
        document.body.appendChild(toolTip);
        document.getElementById("theTip").innerHTML = 
            "<table bgcolor=lightyellow border=1 cellpadding=2 cellspacing=0><tr><td style=\"font-family:'Arial';font-size:8pt;\">" + sDesc + "</td></tr></table>" ;
        setTimeout("DisplayIt()",1500);
}

// Removes the Pop up box when the mouse moves away from the document 
function LoseIt()
{
  window.onerror=handleError;
  TheTip = document.getElementById("theTip");
  TheTip.innerHTML = "";
  TheTip.outerHTML = "";
  window.onerror=handleError;
}

function handleError(msg, url, line) {
	// uncomment this if you suspect javascript errors and want to debug
	//alert('Error: ' + msg + '\nURL: ' + url + '\nLine: ' + line);
	return true;
}

function DisplayIt() {
    document.getElementById("theTip").style['display'] = 'block';
	return true;
}
