// JavaScript Document
var offsetxpoint=+40 //Customize x offset of tooltip
var offsetypoint=-75 //Customize y offset of tooltip
var IntID='';
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(tmptext, term, term_id, thewidth, thecolor){
	clearInterval(IntID);
    url_term = "/Glossary.php?term_id=" + term_id;
	thetext = '<dl><dt>' + term + '</dt><dd>'+tmptext+'<br><img src="images/trans.gif" height="8"><br><img src="images/arrow_doubleline.gif" width="8" height="7" style="padding-right:5px;"><a href="' + url_term + '" class="more_tooltip">more</a><em></em></dd></dl>';
    //countBallons(term_id);
	if (ns6||ie){
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
		tipobj.innerHTML=thetext
		enabletip=true
		return false
	}
}

function positiontip(e){
	if (enabletip){
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
		var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth){
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px";
		} else if (curX<leftedge) {
			tipobj.style.left="5px";
		} else {
			//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left=curX+offsetxpoint+"px"

			//same concept with the vertical position
//			if (bottomedge<tipobj.offsetHeight){
				tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
//				tipobj.style.top=ie? event.clientY+"px" : e.clientY+"px"
/*			} else {
				tipobj.style.top=curY+offsetypoint+"px"
				alert(tipobj.style.top);
			}*/
			tipobj.style.visibility="visible"
		}
		enabletip=false
	}
}

function hideddrivetip(){
	IntID=setInterval('t_hideddrivetip()',3000);
}

function t_hideddrivetip(){
	if (ns6||ie){
		enabletip=false
		tipobj.style.visibility="hidden"
		tipobj.style.left="-1000px"
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
	}
}

document.onmousemove=positiontip

/*
    	function count request for Baloons Term
	*/
	function countBallons(id) {
        httpRequest();
        //http_request.onreadystatechange = responseBaloon;
        var url = "";
        url = "/count_term.php?term_id=" + id;
        //alert(url);
        http_request.open('GET', url);
        http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http_request.send(null);
	}

    function httpRequest() {
	        if (window.XMLHttpRequest)
	            {
	            http_request = new XMLHttpRequest();
	            if (http_request.overrideMimeType) {
	                http_request.overrideMimeType('text/xml');
	                // See note below about this line
	            }
	        } else if (window.ActiveXObject) { // IE
	            try {
	                http_request = new ActiveXObject("Msxml2.XMLHTTP");
	            } catch (e) {
	                try {
	                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
	                } catch (e) {}
	            }
	        }
	        if (!http_request) {
	            alert('Giving up :( Cannot create an XMLHTTP instance');
	            return false;
	        };
	}