﻿insertTooltipBase();

	if (document.layers) { // Netscape
	    document.captureEvents(Event.MOUSEMOVE);
	    document.onmousemove = captureMousePosition;
	} else if (document.all) { // Internet Explorer
	    document.onmousemove = captureMousePosition;
	} else if (document.getElementById) { // Netcsape 6
	    document.onmousemove = captureMousePosition;
	}
	// Global variables
	xMousePos = 0; // Horizontal position of the mouse on the screen
	yMousePos = 0; // Vertical position of the mouse on the screen
	xMousePosMax = 0; // Width of the page
	yMousePosMax = 0; // Height of the page


function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in 
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}

function showDebug(msg)
{
	if (document.getElementById("debugobj"))
	{
		document.getElementById("debugobj").innerHTML = msg;
	}
}

function setTooltipPos()
{
	var tooltipsize = getTooltipSize(tooltiptable);
	var X = yMousePos-tooltipsize.Y-5;
	var Y = xMousePos-15;
	setTooltipPosAtXY(X,Y);
}

function setTooltipPosAtXY(X,Y)
{
	var tooltiptable = document.getElementById("tooltiptable");
	tooltiptable.style.top = Y+"px";
	tooltiptable.style.left = X+"px";
}

function showTooltipBase(msg)
{
	document.getElementById("toolitipcontent").innerHTML = msg;
	if (!(document.getElementById("tooltiptable").style.display == "block"))
	{
		document.getElementById("tooltiptable").style.display = "block";
		document.getElementById("tooltipimage").style.position = "relative";
		document.getElementById("tooltipimage").style.top = "-1";
		var tooltiptable = document.getElementById("tooltiptable");
	}
}

function showTooltip(msg)
{
	showTooltipBase(msg);
	setTooltipPos();
	var tooltipsize = getTooltipSize(tooltiptable);
	var Y = yMousePos-tooltipsize.Y-5;
	var X = xMousePos-15;
	setTooltipPosAtXY(X,Y);
}

function showTooltipAtXY(msg,X,Y)
{
	showTooltipBase(msg);
	setTooltipPosAtXY(X,Y)
}

function showTooltipToObject(obj,msg)
{
	showTooltipBase(msg);
	//alert("bbbb");
	var tooltipsize = getObjSize(document.getElementById("tooltiptable"));
	//alert("cccc");
	var X = yMousePos-tooltipsize.Y-5;
	var Y = xMousePos-15;
	
	if (obj)
	{
		var objpos = new CPoint(0,0);
		checkAbsoluteObjPos(obj,objpos);
		//var s = "";
		
		X = objpos.X;
		Y = objpos.Y;
		//s = "X:"+X+"\nY:"+Y+"\n--------\n";
		Y -=  tooltipsize.Y;
		//s += "X:"+X+"\nY:"+Y+"\n";
		//alert(s)
	}
	setTooltipPosAtXY(X,Y)
}

function hideTooltip()
{
	document.getElementById("tooltiptable").style.display = "none";
}

function insertTooltipBase()
{
	var s = "<table id=\"tooltiptable\" style=\"display: none; position: absolute; top: 0px; left: 0px;\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td  id=\"toolitipcontent\" style=\"background-color: white; border-top: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; border-bottom: 0px solid #FFFFFF; padding: 5px 5px 5px 5px;\"></td></tr><tr><td id=\"toolitipbottom2\" style=\"border-top: 1px solid #CCCCCC;\"><img id=\"tooltipimage\" src=\"/images/cloud-bottom.gif\" style=\"position: relative; top: -1px;\"></td></tr></table>";
	document.write(s);
}

function getTooltipSize(toobject){
	aPoint = new TooltipSizePoint(0,0);
	try{	
		if (toobject){
			//alert('[1:'+toobject.style.height+']\n[2:'+toobject.offsetHeight+']');
			if ((toobject.style.width).length>1){
				aPoint.X = parseInt(toobject.style.width);
			}else{
				aPoint.X = toobject.offsetWidth;
			}
			if ((toobject.style.height).length>1){
				aPoint.Y = parseInt(toobject.style.height);
			}else{
				aPoint.Y = toobject.offsetHeight;
			}			
		}
	}catch(e){;}
	return aPoint;
}

function TooltipSizePoint(X,Y) {this.X=X;this.Y=Y;}
