function activateFootnote(RefNr) {

	var i = 1;
	var tr = document.getElementById("footnote" + i);
	while (tr) {
		if (i==RefNr)
			tr.className = "active"
		else
			tr.className = "";
		i++;
		tr = document.getElementById("footnote" + i);
	}
}
function blinkRef(RefNr, NumberOfTimes) {

	var a = document.getElementById("reference" + RefNr);
	if (a) {
		if (NumberOfTimes % 2 == 1)
			a.style.visibility = "hidden"
		else
			a.style.visibility = "";
		if (NumberOfTimes>=0) {
			NumberOfTimes--;
			window.setTimeout("blinkRef(" + RefNr + ", " + NumberOfTimes + ")", 75);
		}
	}
}
function isIE() {
	return (document.all) ? true : false;
}
function isIE7() {
	
	return (isIE()) && (typeof document.body.style.maxHeight != "undefined");
}
function fixFootnoteText(html) {

	var isItalic = false;
	var isInTag = false;
	var s = "";
	var i=0;
	while (i<html.length) {
		var char = html.substr(i, 1);
		if ((/\s/.test(char))&&(isItalic)&&(!isInTag))
			char = "</i> <i>"
		else if (char=="<") {
			isInTag = true;
			if (html.substr(i, 2).toLowerCase()=="<i")
				isItalic = true
			else if (html.substr(i, 3).toLowerCase()=="</i")
				isItalic = false;
			}
		else if (char==">")
			isInTag = false;
			
		s = s + char;
		i++;
	}
	return s;
}
function showFootnoteTooltip(RefNr, Element) {
	
	var x, y;
	cancelHidingOfFootnoteTooltip();
	var d = document.getElementById("tooltip");
	if (d) {
		d.style.visibility = "hidden";
		d.style.width = "";
		d.style.display = "block";
		d.style.left = "0px";
		d.style.top = "0px";
		var tr = document.getElementById("footnote" + RefNr);
		if (tr) {
			var td = tr.lastChild;
			if (td) {
				var footnoteText = td.innerHTML;
				if (isIE7()) footnoteText = fixFootnoteText(footnoteText);
				d.innerHTML = "<table><tr><td>" + footnoteText + "</table>";
				var windowHeight = document.documentElement.clientHeight;
				var windowWidth = document.documentElement.clientWidth;
				var scrollTop = document.documentElement.scrollTop;
				var scrollLeft = document.documentElement.scrollLeft;
				var tooltipHeight = d.firstChild.offsetHeight;
				var tooltipWidth = d.firstChild.offsetWidth;
				var menuWidth = 160;
				var main = document.getElementById("main");
				var menuHeight = (main) ? main.offsetTop : 62;

				if (isIE()) {
					if (isIE7()) {
						menuWidth = 0;
						menuHeight = 0;
					}
					x = window.event.clientX + document.documentElement.scrollLeft - menuWidth;
					y = window.event.clientY + document.documentElement.scrollTop + 20 - menuHeight;
				}
				else {
					var t = Element;
					x = 0;
					y = 30;
					while (t) {
						if (t.id=="main")
							break;
						x += t.offsetLeft;
						y += t.offsetTop;
						t = t.offsetParent;
					}
				}
				var spaceLeft = (windowWidth + scrollLeft) - (menuWidth + x + tooltipWidth);  // right
				if (spaceLeft<0) x += spaceLeft;
				spaceLeft = (windowHeight + scrollTop) - (menuHeight + y + tooltipHeight);   // bottom
				if (spaceLeft<0) y -= 35 + tooltipHeight;
				
				d.style.width = tooltipWidth + "px";
				d.style.left = x + "px";
				d.style.top = y  + "px";
				d.style.visibility = "visible";	
			}
		}
	}
}
var TooltipTimer;
function hideFootnoteTooltipAfterDelay() {
	TooltipTimer = window.setTimeout("hideFootnoteTooltip()", 800);
}
function hideFootnoteTooltip() {
	
	var d = document.getElementById("tooltip");
	if (d) {
		d.style.display = "none";
		d.style.visibility = "hidden";
		d.innerHTML = "";
		d.style.left = "0px";
		d.style.top = "0px";
	}
}
function cancelHidingOfFootnoteTooltip() {
	if (TooltipTimer)
		window.clearTimeout(TooltipTimer);
}
function toRef(RefNr) {
	activateFootnote(0); 
	blinkRef(RefNr, 13);
	return true;
}
function toFootnote(RefNr) {
	activateFootnote(RefNr); 
	hideFootnoteTooltip(RefNr);
	return true;
}
window.onunload = cancelHidingOfFootnoteTooltip;
