
var offsetxpoint = 20; //Customize x offset of tooltip
var offsetypoint = 10; //Customize y offset of tooltip
var tipenabled = false;
var tipobj;

function positiontip (e) {
	var posX = 0;
	var posY = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		posX = e.pageX;
		posY = e.pageY;
	}
	else if (e.clientX || e.clientY) {
		posX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}

	var tipHeight = tipobj.offsetHeight;
	var winHeight = (typeof(window.innerHeight) == 'number') ? window.innerHeight : document.documentElement.clientHeight;
	var scrollHeight = (typeof(window.pageYOffset) == 'number') ? window.pageYOffset :
		(document.body && document.body.scrollTop) ? document.body.scrollTop : document.documentElement.scrollTop;

	// Position X
	tipobj.style.left = posX + offsetxpoint + 'px';

	// Position Y
	if (posY - scrollHeight + offsetypoint + tipHeight + 4 > winHeight)
		tipobj.style.top = scrollHeight + winHeight - tipHeight - 4 + 'px';
	else
		tipobj.style.top = posY + offsetypoint + 'px';

	tipobj.style.visibility = "visible";
}

function showtip (thetext, thecolor) {
	if (tipenabled) return;
	if (thetext == '') return;
	tipenabled = true;
	if (typeof thecolor != "undefined" && thecolor != "") tipobj.style.backgroundColor = thecolor;
	tipobj.innerHTML = '<div>'+thetext+'</div>';
	document.onmousemove = positiontip;
}

function forcetip (thetext, thecolor) {
	tipenabled = false;
	showtip(thetext, thecolor);
}

function hidetip () {
	tipenabled = false;
	document.onmousemove = null;
	tipobj.style.visibility = "hidden";
	tipobj.style.backgroundColor = '';
}

function tipByTitle(t) {
	var e = document.getElementsByTagName(t);
	for (var i = 0; i < e.length; i++) {
		if (e[i].title) {
			e[i].onmouseover = function() { showtip(this.mytitle); };
			e[i].onmouseout = function() { hidetip(); };
			e[i].mytitle = e[i].title;
			e[i].title = '';
		}
	}
}


