
//TOOLTIP code
//http://www.dynamicdrive.com/dynamicindex5/dhtmltooltip.htm
// IE4+, NS6+, and Opera 7+
function loadTipObj(){
	if ((tipobj==null)){
		if (tt_ie||tt_ns6){
			tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : null;
		}
	}
}

function loadTipObj2(){
	if(tt_ie||tt_ns6){
		tipobj2=document.all? document.all["dhtmltooltiptable"] : document.getElementById? document.getElementById("dhtmltooltiptable") : null;
	}
}


function getTipObj2(){
	if(tt_ie||tt_ns6){
		return document.all? document.all["dhtmltooltiptable"] : document.getElementById? document.getElementById("dhtmltooltiptable") : null;
	}else{
		return null;
	}
}


function getObj(id){
	if(tt_ie||tt_ns6){
		return document.all? document.all[id] : document.getElementById? document.getElementById(id) : null;
	}else{
		return null;
	}
}

function ietruebody(){
	return(document.compatMode && document.compatMode!="BackCompat") ? document.documentElement : document.body;
}

function show_tool_tip(imgrelurl, thetext, thewidth, theheigth){
	var divhtml="";
	var thecolor="lightyellow";
	var paddings = 0;
	var table1 = '<table id=\"dhtmltooltiptable\" style=\"margin:0px;padding:' + paddings + 'px; \"><tr><td id=\"tttd1\">';  // width:' + (thewidth+2*paddings) + ';
	var table2 = '</td></tr><tr><td id=\"tttd1\">';
	var table3 = '</td></tr></table>';
	var img1 = '<img src=\"' + imgrelurl + '\" alt=\"' + thetext + '\" style=\"border:0px;\" />';
	//divhtml = img1;
	divhtml = table1 + thetext + table2 + img1 + table3 ;

	if(tt_ns6||tt_ie){
		loadTipObj();
		if (typeof thewidth!="undefined") {tipobj.style.width=(thewidth+2*paddings)+"px";}
		if (typeof thecolor!="undefined" && thecolor!="") {tipobj.style.backgroundColor=thecolor;}
		tipobj.innerHTML=divhtml;
		loadTipObj2();
		
		if(tt_ns6){		
			//tipobj.style.width=tipobj2.style.width +"px";
			//alert(getObj("tttd1").offsetWidth);
			tipobj.style.width = getObj("tttd1").offsetWidth + "px";
			//alert(getTipObj2().parentNode.innerHTML);
		}
		tipobj.style.visibility="visible";		
		enabletip=true;
		return false;
	}
}

function positiontip_forward(e){
	if(enabletip){
		loadTipObj2();
		var curX=(tt_ns6)?e.pageX : event.x+ietruebody().scrollLeft;
		var curY=(tt_ns6)?e.pageY : event.y+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window

		if(tt_ie&&!window.opera){
			var rightedge=ietruebody().clientWidth - event.clientX - offsetxpoint;
			var bottomedge=ietruebody().clientHeight-event.clientY-offsetypoint;
		}else{
			var rightedge=window.innerWidth        - e.clientX     - offsetxpoint - 20; //??? hmmm
			var bottomedge=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

		var a;
		if(rightedge<tipobj.offsetWidth){
			if(tt_ie){
				a = ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth;
			}else{
				a = window.pageXOffset+e.clientX-tipobj.offsetWidth; //move the horizontal position of the menu to the left by it's width
			}
			//window.status = "a" + "  " + a + " rightedge = " + rightedge + "  tipobj.offsetWidth = "  + tipobj.offsetWidth;
		}else if(curX<leftedge){
			a = 0;
		}else{
			a=curX+offsetxpoint; //position the horizontal position of the menu where the mouse is positioned
		}
		tipobj.style.left = ((a<0)?0:a) + "px";
		//same concept with the vertical position
		if(bottomedge<tipobj.offsetHeight){
			if(tt_ie){
				a = ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint;
			}else{
				a = window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint;
			}
		}else{
			a = curY+offsetypoint;
		}
		tipobj.style.top=((a<0)?0:a)+"px";

		tipobj.style.visibility="visible";
		//tipobj.innerHTML = 	("top = " + tipobj.style.top + "  left = " +  tipobj.style.left);
		//alert("top = " + tipobj.style.top + "  left = " +  tipobj.style.left);
		//window.status = "top = " + tipobj.style.top + "  left = " +  tipobj.style.left;
	}
}

function positiontip(e){
	if(enabletip){
		positiontip_forward(e);
	}
}

function hide_tool_tip(){
	if(tt_ns6||tt_ie){
		loadTipObj();
		enabletip=false;
		tipobj.innerHTML="";
		tipobj.style.visibility="hidden";
		tipobj.style.left="-1000px";
		tipobj.style.backgroundColor='';
		tipobj.style.width='';
	}
}
function writetooltipdiv(){
	//if(doc==null){doc = document;}
	document.write('<div id=\"dhtmltooltip\"></div>');
}


var tt_ie=document.all;
var tt_ns6=document.getElementById && !document.all;

if (tt_ie||tt_ns6){
	var offsetxpoint=20; //Customize x offset of tooltip
	var offsetypoint=20; //Customize y offset of tooltip
	var enabletip=false;
	var tipobj=null;
	var tipobj2=null;
	document.onmousemove=positiontip;
}



