
var offsetxpoint=-20;
var offsetypoint=20;
var ie=document.all;
var ns6=document.getElementById && !document.all;
var enabletip=false;
var loadFinished = false;
var tipobj = null;

var textTips = new Array( 
		'<div class="box-tip"><div class="box-top"><div class="box-bt">___CONTENT___</div></div></div>'
	);
	
// 
function ietruebody(){
	if(!loadFinished) return false;
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function ddrivetip(thetext, type, thecolor, thewidth){

	if(!loadFinished) return false;
	if(!type) type = 0;
	if( type >= textTips.length ) type = textTips.length-1;
	if (ns6||ie){
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px";
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor;
		

		tipobj.innerHTML = textTips[type].replace( /___CONTENT___/, 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";
		else
			tipobj.style.top=curY+offsetypoint+"px";
		tipobj.style.visibility="visible";
		tipobj.style.display="";
	}
}

function hideddrivetip(){
	if(!loadFinished) return false;
	if (ns6||ie){
		enabletip=false;
		tipobj.style.visibility="hidden";
		tipobj.style.display="none";
		tipobj.style.left="-1000px";
		tipobj.style.backgroundColor='';
		tipobj.style.width='';
	}
}
var __inited__ = false;
if( !window.onDomReady ) __inited__ = true;

var __loadTooltip__ = window.onload;
function __loadTip(e) {
	if(!__inited__ && typeof(__loadTooltip__) == 'function') __loadTooltip__.call();
	// '<div id="dhtmltooltip"></div>';
	tipobj = document.createElement('div');
	tipobj.setAttribute('id', 'dhtmltooltip');
	document.body.appendChild(tipobj);
	tipobj.style.display="none";
	// if (ie||ns6) tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "";
	loadFinished = true;
	document.onmousemove=positiontip;
}
if( !__inited__ ) window.onload = __loadTip;
else window.onDomReady(__loadTip);

if( !__inited__ && typeof($) != 'function' ) {
	window.$ = function(id){
		if( !id ) return null;
		if(typeof(id) == 'object') return id;
		var el = null;
		if( document.getElementById ) el = document.getElementById(id);
		if( !el && document.all ) el = document.all[id];
		return el;
	}
}

//Open popup
function openWindow(filename, winname, width, height, feature) {
	var features, top, left;
	var reOpera = /opera/i;
	var winnameRequired = ((navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 4) || reOpera.test(navigator.userAgent));

	left = (window.screen.width - width) / 2;
	top = (window.screen.height - height) / 2;
	if(feature == '')
		features = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",status=0,location=0";
	else
		features = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + "," + feature;
	// if(!winnameRequired) winname = "";
	var newwindow = window.top.open(filename,winname,features);
	if( newwindow )	newwindow.focus();
	return newwindow;
}

