	
	var opac = 0;
	var step = 1;
	var mouseOnTooltip = false;
	var offX = 8;
	var offY = 12;
	var showDelay = 1000;
	var hideDelay = 0;
	var timer = null;
	var tip = null;
	var timerId = 0;
	var toolTipId = "tipDiv";
	var windowWidth = 0;
	var windowHeight = 0;
	var scrollX;
	var scrollY;

	function convertText(text, reverse) {
		var replaceChars = [["<", "&lt;"], [">", "&gt;"], ["  ", "&nbsp; "], ["\n", "<br>"]];
		for(i in replaceChars) {
			var srcChar = (!reverse)?replaceChars[i][0] : replaceChars[i][1];
		    var desChar = (!reverse)?replaceChars[i][1] : replaceChars[i][0];
		    var regexp = new RegExp("(" + srcChar + ")", "i");
		    while(text.match(regexp)) {
				text = text.replace(new RegExp(RegExp.$1, "g"), desChar);
			}
		}
		return text;	
	}

	function initialTooltip() {
		if(document.createElement && document.body && typeof document.body.appendChild != "undefined"){
			if(!document.getElementById(this.toolTipId)){ 
				var elementTooltip = document.createElement("div");
				elementTooltip.id = this.toolTipId;
				document.body.appendChild(elementTooltip);
			}
		}
	}

	function showTooltip(event, message) {
		if(timer){
			clearTimeout(timer);
			timer = 0;
		}
		this.tip = document.getElementById(toolTipId);
		if(mouseOnTooltip) {
			alert("in show=" + mouseOnTooltip);
			addEvent(document, "mousemove", trackingMousePointer, true);
		}
		writeTooltip("");
		writeTooltip(message);
		getPositionInfo();

		positionTooltip(event);
		timer = setTimeout("checkToShowTooltip('"+ toolTipId +"', 'visible')", showDelay);
	}

	function writeTooltip(message) {
		if(this.tip && typeof this.tip.innerHTML != "undefined")
		this.tip.innerHTML = this.convertText(message, false);
	}

	function hideTooltip() {
		if(this.timer){
			clearTimeout(this.timer);
			this.timer = 0;
		}
		this.timer = setTimeout("checkToShowTooltip('" + this.toolTipId + "', 'hidden')", this.hideDelay);
		if(this.mouseOnTooltip) {
			removeEvent(document,"mousemove", trackingMousePointer,true);
		}
		this.tip = null;		
	}
	function fadeTooltip(id) {
		var tooltipObj = document.getElementById(id);
		var timer;
		opac += 5;
		if(tooltipObj.filters) { 
		   tooltipObj.style.filter='alpha(opacity='+ opac+')';
		}
		else {
			tooltipObj.style.opacity=(opac/100)-0.001;
		}
 		if (opac >= 100 ) {
 			opac = 0;
 			clearTimeout(timer);
 			return;
 		}
 		timer = setTimeout("fadeTooltip('"+ id + "')", 5);
	}

	function checkToShowTooltip(id, isVisible) {
		var element = document.getElementById(id);
		if (isVisible == 'hidden') {
			element.style.filter='alpha(opacity=0)';
		}			
		if(element) {
			element.style.visibility = isVisible;
		}
		fadeTooltip(id);
	}

	function trackingMousePointer() {
		e = getEventFromElement(e);
		positionTip(e);
	}
	function getPositionInfo() {
		getWindowWidth();
		getWindowHeight();
		getScrollX();
		getScrollY();
	}
	function getMouseYIE(e) {
		var mouseX = 0;
		var mouseY = 0;
		if (!e) var e = window.event;
		if (e.pageX || e.pageY) {
			mouseX = e.pageX;
			mouseY = e.pageY;
		}
		else if (e.clientX || e.clientY) {
			mouseX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			mouseY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}
		return mouseY;
	}
	function positionTooltip(event) {

		if(this.tip && this.tip.style) {

			var x = event.pageX ? event.pageX : event.clientX + scrollX;
			var y = event.pageY ? event.pageY : event.clientY + scrollY;
			if (is_ie) {
				y = getMouseYIE(event);
			}
			if (x + this.tip.offsetWidth + this.offX > windowWidth + scrollX) {
				x = x - this.tip.offsetWidth - this.offX;
				if(x < 0) {
					x = 0;
				}
			} else {
				x = x + this.offX;
			}
			if (y + this.tip.offsetHeight + this.offY > windowHeight + scrollY) {
				y = y - this.tip.offsetHeight - this.offY;
				if(y < scrollY) {
					y = windowHeight + scrollY - this.tip.offsetHeight;
				}
			} else {
				y = y + this.offY;
			}

			this.tip.style.left= x + "px";
			this.tip.style.top= y + "px";
		}
	}
	function getWindowWidth() {
		windowWidth = 0;
		if (window.innerWidth) {
			windowWidth = window.innerWidth - 18;
		} else if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else if (document.body && document.body.clientWidth) {
			windowWidth = document.body.clientWidth;
		}
	}

	function getWindowHeight() {
		windowHeight = 0;
		if (window.innerHeight) {
			windowHeight = window.innerHeight - 18;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body && document.body.clientHeight) {
			windowHeight = document.body.clientHeight;
		}
	}

	function getScrollX() {
		scrollX = 0;
	  	if (typeof window.pageXOffset == "number") {
	  		scrollX = window.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollLeft) {
			scrollX = document.documentElement.scrollLeft;
		} else if (document.body && document.body.scrollLeft) {
			scrollX = document.body.scrollLeft; 
	  	} else if (window.scrollX) {
	  		scrollX = window.scrollX;
	  	}
	}

	function getScrollY() {
		scrollY = 0;
	  	if (typeof window.pageXOffset == "number") {
	  		scrollY = window.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollLeft) {
			scrollY = document.documentElement.scrollLeft;
		} else if (document.body && document.body.scrollLeft) {
			scrollY = document.body.scrollLeft; 
	  	} else if (window.scrollY) {
	  		scrollY = window.scrollY;
	  	}
	}	  

	function addEvent(object, eventType, listener, isUseCapture) {
	    isUseCapture = isUseCapture || false;
	    if (object.addEventListener) {
	    	object.addEventListener(eventType, listener, isUseCapture);
	    }
	    else if (object.attachEvent) {
	    	object.attachEvent("on" + eventType, listener);
	    }
	}

	function removeEvent(object, eventType, listener, isUseCapture) {
		isUseCapture = isUseCapture || false;
		if (object.removeEventListener) { 
			object.removeEventListener(eventType, listener, isUseCapture);
		}
		else if (object.detachEvent) { 
			object.detachEvent("on" + eventType, listener);
		}
	 }

	function getEventFromElement (event) {
		event = event ? event: window.event;
		event.tgt = event.srcElement ? event.srcElement : event.target;
	    
	    if (!event.preventDefault) 
	    	event.preventDefault = function () { 
				return false; 
	    	}
		if (!event.stopPropagation) 
		   	event.stopPropagation = function () { 
			if (window.event) 
				window.event.cancelBubble = true; 
		  	}
		return event;
	 }
	 function trackingMousePointer(event) {
		event = getEventFromElement(event);
		positionTooltip(event);
	 }
	function cleanTimer() {
		if (timerId) { 
			clearTimeout(timerId); 
			timerId = 0; 
		}
	}
	function hideTip() {
		if (document.getElementById(toolTipId) == null) {
			return;
		}
		timerId = setTimeout("hideTooltip()", 300);
	}
	function tooltipOutCheck(event) {
		event = getEventFromElement(event);
		var toElement = event.relatedTarget ? event.relatedTarget : event.toElement;
		if (this != toElement && !contained(toElement, this)) 
			hideTooltip();
	}
	// returns true of oNode is contained by oCont (container)
	function contained(oNode, oCont) {
		if (!oNode) return; // in case alt-tab away while hovering (prevent error)
		while (oNode = oNode.parentNode) 
			if (oNode == oCont) 
				return true;
		return false;
	}
	function clearTimer() {
		if(timerId) {
			clearTimeout(timerId);
			timerId = 0;
		}
	}
	
	function unHookHover() {
		var tip = document.getElementById ? document.getElementById(toolTipId): null;
		if (tip) {
	        tip.onmouseover = null; 
	        tip.onmouseout = null;
	        tip = null;
	    }
	}
	
	addEvent(window, "unload", unHookHover, true);	

	
	//Initial
	function doTooltip(e, msg) {
		
		if (document.getElementById(toolTipId) == null) {
			return;
		}
		
		clearTimer();
		
		var tip = document.getElementById ? document.getElementById(toolTipId) : null;
		if (tip && tip.onmouseout == null) {
      		tip.onmouseout = tooltipOutCheck;
		    tip.onmouseover = clearTimer;
		}
		
		showTooltip(e, msg);
	}
	
	function doTooltipXY(x, y, msg) {
		if (document.getElementById(toolTipId) == null) {
			return;
		}
		clearTimer();
		var tip = document.getElementById ? document.getElementById(toolTipId) : null;
		if (tip && tip.onmouseout == null) {
      		tip.onmouseout = tooltipOutCheck;
		    tip.onmouseover = clearTimer;
		}
		showTooltipXY(x, y, msg);
	}
	
	function showTooltipXY(x, y, message) {
		if(timer){
			clearTimeout(timer);
			timer = 0;
		}
		this.tip = document.getElementById(toolTipId);
		if(mouseOnTooltip) {
			alert("in show=" + mouseOnTooltip);
			addEvent(document, "mousemove", trackingMousePointer, true);
		}
		writeTooltip("");
		writeTooltip(message);
		positionTooltipXY(x, y);
		timer = setTimeout("checkToShowTooltip('"+ toolTipId +"', 'visible')", showDelay);
	}
	
	function positionTooltipXY(x, y) {
		if(this.tip && this.tip.style) {
			this.tip.style.left= x + "px";
			this.tip.style.top= y + "px";
		}
	}
	
	function positionTooltipX(event, tipOffsetWidth) {
		
		var x = event.pageX ? event.pageX : event.clientX + scrollX;
		if (x + tipOffsetWidth + this.offX > windowWidth + scrollX) {
			x = x - tipOffsetWidth - this.offX;
			if(x < 0) {
				x = 0;
			}
		} else {
			x = x + this.offX;
		}

		return x;
		
	}
	
	function positionTooltipY(event, tipOffsetHeight) {
		var y = event.pageY ? event.pageY : event.clientY + scrollY;
		if (is_ie) {
			y = getMouseYIE(event);
		}
		if (y + tipOffsetHeight + this.offY > windowHeight + scrollY) {
			y = y - tipOffsetHeight - this.offY;
			if(y < scrollY) {
				y = windowHeight + scrollY - tipOffsetHeight;
			}
		} else {
			y = y + this.offY;
		}

		return y;
	}