// Global variables
var tip=false,win,xOffset=0,yOffset=0,mx=0,my=0;
//Turns off the tooltip span
function byId(id){
	if(document.getElementById(id)){
		return document.getElementById(id);
	}else{
		return null;
	}
}

function killTip() {
    if (byId('tooltip')) {
        byId('tooltip').style.display = 'none';
    }
} //killTip()
// Replace titles with popup
function toolTip() {
typeArr = new Array("a","img","acronym","div","span","title","input","select","label");
	for(x=0;x<typeArr.length;x++){
	tags = document.getElementsByTagName(typeArr[x]);
		for(ln=0;ln<tags.length;ln++) {
			var lnk = tags[ln];
			if(lnk.title){
				lnk.setAttribute("popup",lnk.title);
				lnk.removeAttribute("title");
			}else if (lnk.alt){
			    lnk.setAttribute("popup", lnk.alt);
			    lnk.removeAttribute("alt");
			}
			addEvent(lnk,"mouseover",showTip);
			addEvent(lnk,"mouseout",hideTip);
			addEvent(lnk,"click",hideTip);
			if(lnk.getAttribute("rel")=="ext"){
				lnk.target="_blank";
			}//if
		} //for
	} //for
} //toolTip()

// Add event function
function addEvent(obj, Event, func){
if(obj.addEventListener){
	obj.addEventListener(Event, func, true);
}else if(obj.attachEvent){
	obj.attachEvent("on"+Event,func)
}else{
	obj["on"+Event]=func;
}
  return true;
} //addEvent()


// Get mouse position then call displayTip after half a second
function showTip(e) {
if (window.event && window.event.srcElement) {
        lnk = window.event.srcElement;
    }else{
    	lnk = e.target;
    }
    dispText = '' + lnk.getAttribute("popup")
	if(dispText!="null" && dispText!="" && String(dispText)!="undefined"){
		tip=true;
	}
	var scrolled;
	if (document.documentElement && document.documentElement.scrollTop) {
	    scrolled = parseInt(document.documentElement.scrollTop);

	} else if (window.pageYOffset) {
	    scrolled = parseInt(window.pageYOffset);
	} else if(document.body && document.body.scrollTop) {
	    scrolled = parseInt(document.body.scrollTop);
	}
	if(isNaN(scrolled)){
		scrolled=0;
}
	//debug('Scrolled: '+scrolled);
	if(window.event){
		xOffset = window.event.clientX+15;
		yOffset = window.event.clientY + 15 + scrolled;
	}else{
		xOffset = e.pageX+15;
		yOffset = e.pageY+15;
	}
	if (tip) {
		setTimeout("displayTip(dispText)",500);
	}
} //function showTip()
// Hide tip calls killTip after an interval of a quarter second
function hideTip() {
		tip=false;
		setTimeout("killTip()",250);
	} //hideTip()



// Show tip span and drop shadow and populate with title attribute text
function displayTip(text){
    if (byId("tooltip") && byId("tooltiptext")) {
		if(tip==true){
			ttip = byId("tooltip");
			ttipt = byId("tooltiptext");
			ttip.style.top = yOffset + "px";
			ttip.style.left = xOffset + "px";
			var clientWidth = 0;
			if (document.documentElement && document.documentElement.clientWidth) {
			    clientWidth = document.documentElement.clientWidth
			} else if (document.body && document.body.clientWidth) {
			    clientWidth = document.body.clientWidth;
			}
			if (xOffset + 200 > clientWidth) {
				ttip.style.left = clientWidth-205 + "px";
			}
			if(clientWidth<205){
				ttip.style.left = '0px';
            }
			text = formatText(text);
			ttipt.innerHTML = text;
			ttip.style.display = 'block';
		} //if
	}
} //displayTip()
// onload

function formatText(txt){
	if(txt){
		width="15"
	height="18"
		txt = (txt.replace(/^\s+/,'')).replace(/\s+$/,'');
		btxt =" " + txt + " ";
		btxt = btxt.replace(/\n/g,"<br>\n");
		btxt = btxt.replace(/\s\/(.*?)\/\s/g," <i>$1</i> ");
		btxt = btxt.replace(/\s_(.*?)_/g, " <u>$1</u>");
		btxt = btxt.replace(/\+(.*?)\+/g, " <b>$1</b>");
		suffix = "blank";
		btxt = btxt.replace(/>:\((?![^<>]*>)/g,"<img src=\"/images/14"+suffix+".gif\" class=\"smiley b0\" alt=\"]: (\" width=\""+width+"\" height=\""+height+"\" />");		
		btxt = btxt.replace(/:D(?![^<>]*>)/g," <img src=\"/images/00"+suffix+".gif\" class=\"smiley b0\" alt=\": D\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/\=D(?![^<>]*>)/g," <img src=\"/images/01"+suffix+".gif\" class=\"smiley b0\" alt=\"= D\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/\:B(?![^<>]*>)/g," <img src=\"/images/02"+suffix+".gif\" class=\"smiley b0\" alt=\": B\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/;\)(?![^<>]*>)/g," <img src=\"/images/02.5"+suffix+".gif\" class=\"smiley b0\" alt=\"; )\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/:\)(?![^<>]*>)/g," <img src=\"/images/03"+suffix+".gif\" class=\"smiley b0\" alt=\": )\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/=\)(?![^<>]*>)/g," <img src=\"/images/04"+suffix+".gif\" class=\"smiley b0\" alt=\"= )\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/:\](?![^<>]*>)/g," <img src=\"/images/05"+suffix+".gif\" class=\"smiley b0\" alt=\": ]\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/:\}(?![^<>]*>)/g," <img src=\"/images/06"+suffix+".gif\" class=\"smiley b0\" alt=\": }\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/:\|(?![^<>]*>)/g," <img src=\"/images/07"+suffix+".gif\" class=\"smiley b0\" alt=\": |\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/=\|(?![^<>]*>)/g," <img src=\"/images/08"+suffix+".gif\" class=\"smiley b0\" alt=\": }\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/=\/(?![^<>]*>)/g," <img src=\"/images/09"+suffix+".gif\" class=\"smiley b0\" alt=\"= /\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/=\\(?![^<>]*>)/g," <img src=\"/images/09"+suffix+".gif\" class=\"smiley b0\" alt=\"= \\\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/:S(?![^<>]*>)[^a-z0-9]/gi," <img src=\"/images/10"+suffix+".gif\" class=\"smiley b0\" alt=\": S\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/:\((?![^<>]*>)/g," <img src=\"/images/11"+suffix+".gif\" class=\"smiley b0\" alt=\": (\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/=\((?![^<>]*>)/g," <img src=\"/images/12"+suffix+".gif\" class=\"smiley b0\" alt=\"= (\" />");
		btxt = btxt.replace(/:\'\((?![^<>]*>)/g," <img src=\"/images/13"+suffix+".gif\" class=\"smiley b0\" alt=\": '(\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/:P(?![^<>]*>)/g," <img src=\"/images/15"+suffix+".gif\" class=\"smiley b0\" alt=\": P\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/0:-\)(?![^<>]*>)/g," <img src=\"/images/16"+suffix+".gif\" class=\"smiley b0\" alt=\"0: -)\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/0:\)(?![^<>]*>)/g," <img src=\"/images/16"+suffix+".gif\" class=\"smiley b0\" alt=\"0: -)\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/O:\)(?![^<>]*>)/g," <img src=\"/images/16"+suffix+".gif\" class=\"smiley b0\" alt=\"0: -)\" width=\""+width+"\" height=\""+height+"\" />");
		btxt = btxt.replace(/:\$(?![^<>]*>)/g," <img src=\"/images/17"+suffix+".gif\" class=\"smiley b0\" alt=\"0: -)\" width=\""+width+"\" height=\""+height+"\" />");
	
	/*end smileys*/
	return btxt;
		}
	}
	function openWin(item){
		var win=window.open(item.href);
		return false;
	}