/***********************************************
* Cool DHTML tooltip script - Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetxpoint=10; //Customize x offset of tooltip
var offsetypoint=10; //Customize y offset of tooltip
var enabletip=false;
var timeoutObj;
var currentHtml;
var tipobj = null;
var useXmlObj;

function ietruebody()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth)
{
	if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px";
	if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor;
	
	//Fill here with xmlhttprequest
	updateHtml(thetext);
	enabletip=true;
	
	//Position the tip
	var rightedge=browserIsIE()&&!window.opera? ietruebody().clientWidth-tempX-offsetxpoint : window.innerWidth-tempX-offsetxpoint-20;
	var bottomedge=browserIsIE()&&!window.opera? ietruebody().clientHeight-tempY-offsetypoint : window.innerHeight-tempY-offsetypoint-20;
	var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000;
	tipobj.style.left=tempX+offsetxpoint+"px";
	tipobj.style.top=tempY+offsetypoint+"px";
}

function updateHtml(thetext)
{
	if(!useXmlObj)
	{
		tipobj.innerHTML = thetext;
		tipobj.style.visibility="visible";
	}
	else
	{
		getTT(thetext);
	}
}

function getTT()
{
	if(!xmlhttp || xmlhttp==null)
		return;
	if(callInProgress(xmlhttp))
		return;
	
	myRandom=parseInt(Math.random()*99999999);
	myUrl = xmlUrl + "?random=" + myRandom + "&id=" + getTT.arguments[0];

//	if(getTT.arguments.length>1)
//	{
//		for(i=1;i<getTT.arguments.length;i++)
//		{
//			myUrl += "&arg" + (i+1) + "=" + getTT.arguments[i];
//		}
//		alert(myUrl);
//	}
	
	xmlhttp.open("GET", myUrl, true);
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			if(xmlhttp.status!=200)
			{
				return;
			}
			else
			{
				if(xmlhttp.responseText.indexOf("DOCTYPE HTML PUBLIC") > -1)
				{
					return;	
				}
				tipobj.innerHTML = xmlhttp.responseText;
				tipobj.style.visibility="visible";
			}
		}
	}
	xmlhttp.send(null);
}

function hideddrivetip()
{
	document.onmousemove = null;
	
	clearTimeout(timeoutObj);
	if(tipobj==null)return;
	enabletip=false;
	tipobj.style.visibility="hidden";
	tipobj.style.backgroundColor="";
	tipobj.style.width="";
}

function init_ddrivetip(thetext,useXmlRequest)
{
	document.onmousemove = getMouseXY;
	
	//If the container for tooltips is null, create it
	useXmlObj = useXmlRequest;
	tipobj = document.getElementById("dhtmltooltip");
	if(tipobj==null)
	{
		return;
	}
	timeoutObj = setTimeout("ddrivetip('" + thetext.replace("'","&#39;") + "')",500);
}

if (!browserIsIE()) document.captureEvents(Event.MOUSEMOVE);
var tempX = 0;
var tempY = 0;
function getMouseXY(e) 
{
	if (browserIsIE())
	{ 
		// grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else 
	{  
		// grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}  
	return true;
}
