function enableTooltips(id) {
	if(!document.getElementById || !document.getElementsByTagName) {
		return;
	}
	
	var eSpan=document.createElement("SPAN");
	document.getElementsByTagName("body")[0].appendChild(eSpan);
	eSpan.style.position="absolute";
	eSpan.setAttribute("id","btc");
	
	var eLinks = (id == null) ? document.getElementsByTagName("A") : document.getElementById(id).getElementsByTagName("A") ;
	for(var i = 0; i < eLinks.length; i++) {
		if(eLinks[i].title != '') {
	    		Prepare(eLinks[i]);
	    	}
    	}
}


function Prepare(eLink) {
	var sTitle = eLink.getAttribute("title");
	eLink.removeAttribute("title");
	
	var tooltip = CreateEl("span","tooltip");
	tooltip.innerHTML = '<table summary="" width="150" cellspacing="0" cellpadding="0">'
			  + '<thead>'
			  + '<tr valign="top">'
			  + '<td width="9" height="9"><img src="kalender/bg.toolbox_top_left.gif" width="9" height="9" unselectable="on" alt="" /></td>'
			  + '<td width="202" align="right" style="background:#5C9E1D;" height="9">'
			  + '<img src="kalender/icon.toolbox_info.gif" width="9" height="9" unselectable="on" alt="" style="z-index:10; position:relative; top:8px; right:-3px;" />'
			  + '</td>'
			  + '<td><img src="kalender/bg.toolbox_top_right.gif" width="9" height="9" unselectable="on" alt="" /></td>'
			  + '</tr>'
			  + '<tr><td colspan="3" style="background:#5C9E1D;">&nbsp;</td></tr>'
			  + '</thead>'
			  + '<tfoot>'
			  + '<tr valign="bottom">'
			  + '<td width="9" height="9"><img src="kalender/bg.toolbox_bottom_left.gif" width="9" height="9" unselectable="on" alt="" /></td>'
			  + '<td width="80" style="background:#5C9E1D;"></td>'
			  + '<td><img src="kalender/bg.toolbox_bottom_right.gif" width="9" height="9" unselectable="on" alt="" /></td>'
			  + '</tr>'
			  + '<tr valign="top">'
			  + '<td width="9"></td>'
			  + '<td><img src="kalender/bg.toolbox_pointer.gif" name="toolbox_pointer" id="toolbox_pointer" width="23" height="17" unselectable="on" alt="" /></td>'
			  + '<td width="9"></td>'
			  + '</tr>'
			  + '</tfoot>'
			  + '<tbody>'
			  + '<tr valign="top">'
			  + '<td width="9" style="background:#5C9E1D;"></td>'
			  + '<td height="50" style="background:#5C9E1D; color:#fff; font-size:9px; font-family: Trebuchet MS;">'
			  + sTitle
 			  + '</td>'
			  + '<td width="9" style="background:#5C9E1D;"></td>'
			  + '</tr>'
			  + '</tbody>'
			  + '</table>'
	
	eLink.tooltip = tooltip;	
	eLink.onmouseover = showTooltip;
	eLink.onmouseout  = hideTooltip;
}

function showTooltip(e){
	document.getElementById("btc").appendChild(this.tooltip);
	Locate(e);
}

function hideTooltip(e){
	var d=document.getElementById("btc");
	if(d.childNodes.length>0) d.removeChild(d.firstChild);
}

function setOpacity(el){
	el.style.filter="alpha(opacity:95)";
	el.style.KHTMLOpacity="0.95";
	el.style.MozOpacity="0.95";
	el.style.opacity="0.95";
}

function CreateEl(t,c){
	var x=document.createElement(t);
	x.className=c;
	x.style.display="block";
	return(x);
}

function AddCss(){
	var l=CreateEl("link");
	l.setAttribute("type","text/css");
	l.setAttribute("rel","stylesheet");
	l.setAttribute("href","bt.css");
	l.setAttribute("media","screen");
	document.getElementsByTagName("head")[0].appendChild(l);
}

function Locate(e){
	var posx=0,posy=0;
	if(e==null) e=window.event;
	if(e.pageX || e.pageY) {
	    posx = e.pageX; 
	    posy = e.pageY;
   	} else if(e.clientX || e.clientY) {
		if(document.documentElement.scrollTop){
        		posx = e.clientX+document.documentElement.scrollLeft;
        		posy = e.clientY+document.documentElement.scrollTop;
        	} else {
        		posx = e.clientX+document.body.scrollLeft;
        		posy = e.clientY+document.body.scrollTop;
        	}
    	}
	
	/**
	 * FLIP INFOBOX:
	 * Filp the 'info box' horizontaly when
	 * its near the right edge of the browser.
	 */
	var iEdge = document.body.offsetWidth - 220;
	var eIMGPointer = document.getElementById('toolbox_pointer');
	var eTD = eIMGPointer.parentNode;
	var bFlip = (posx > iEdge);
	
	eTD.align = (bFlip == true) ? 'right' :'left';	
	eIMGPointer.src = (bFlip == true) ? 'kalender/bg.toolbox_pointer_right.gif' : 'kalender/bg.toolbox_pointer.gif';
	document.getElementById("btc").style.left = (bFlip == true) ? (posx - 150) + "px" : (posx - 16) + "px";
	document.getElementById("btc").style.top = ((posy - document.getElementById("btc").offsetHeight) - 10) + "px";
}
