function g(id){
	if (undefined===eval('window.g'+id)) {
		eval('window.g'+id+' = document.getElementById(id)');
		return eval('window.g'+id);
	} else {
		return eval('window.g'+id);
	}
};

function display(el,show){
	if (show){
		g(el).style.display = 'block';
	} else {
		g(el).style.display = 'none';
	}
	
};

function enableTooltips(){
	var links,i,h;
	if(!document.getElementById || !document.getElementsByTagName) return;
	h=document.createElement("span");
	h.id="btc";
	h.setAttribute("id","btc");
	h.style.position="absolute";
	document.getElementsByTagName("body")[0].appendChild(h);

	elements=document.getElementsByTagName("*");
	for(i=0;i<elements.length;i++){
		if(elements[i].className == "hint"){
    		Prepare(elements[i]);
		}
    }
};

function Prepare(el){
	var tooltip,t,b,s,l,iframe;
		
	t=el.getAttribute("title");
	el.removeAttribute("title");
	tooltip=CreateEl("span","tooltip");
	s=CreateEl("span","top");
	s.appendChild(document.createTextNode(t));
	tooltip.appendChild(s);
	b=CreateEl("b","bottom");
	tooltip.appendChild(b);
	
	setOpacity(tooltip);
	el.tooltip=tooltip;
	
	// Iframe til at skjule select-elementer
	iframe=CreateEl("iframe","tooltipiframe");
	iframe.setAttribute("frameborder","0");
	el.iframen=iframe;
	
	el.onmouseover=showTooltip;
	el.onmouseout=hideTooltip;
	el.onmousemove=Locate;
};

function showTooltip(e){
	if(navigator.appVersion.indexOf('MSIE 6.0')!=-1) {
		g("btc").appendChild(this.iframen);

	}
	g("btc").appendChild(this.tooltip);
	Locate(e);
};

function hideTooltip(e){
	var d=g("btc");
	if(d.childNodes.length>0) d.removeChild(d.firstChild);
	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 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;
			}
		}
	g("btc").style.top=(posy+10)+"px";
	g("btc").style.left=(posx-10)+"px";
};

function createDiv(text) {
    var divTag = document.createElement('div'); // create dynamically div tag

    /*if (divTag.addEventListener) {
        // firefox, etc.
        divTag.addEventListener("mouseup", function(e) { return close(e) }, true);
    }
    else {
        // IE
        divTag.attachEvent("onmouseup", function(e) { return close(e) });
    }*/

    var pos = getScroolPos();
    var dim = getWindowDims();
    var top = 300;
    if (dim.h > 0) {
        top = dim.h / 2;
    }

    var left = 0;
    if (dim.w > 0) {
        left = dim.w / 2;
    }

    // Set div attributes
    divTag.setAttribute('id', "comment");
    divTag.style.width = "200px";
    divTag.style.top = parseFloat(pos.y + top) + "px";
    divTag.style.left = parseFloat(left - 150) + "px";
    divTag.innerHTML = "<div id=\"header\" onclick=\"javascript:removeElement('comment');\">[x]</div>" + text;

    document.body.appendChild(divTag);
}

function close(e) {
    var div = e.srcElement || e.currentTarget;
    document.body.removeChild(div);
}

function removeElement(elem) {
    var element = document.getElementById(elem);
    document.body.removeChild(element);
}

function ShowComment(comment) {
    createDiv(comment);
}

function getScroolPos() {
    if (window.pageYOffset) {
        return { y: window.pageYOffset, x: window.pageXOffset };
    }
    if (document.documentElement && document.documentElement.scrollTop) {
        return { y: document.documentElement.scrollTop, x: document.documentElement.scrollLeft };
    }
    if (document.body) {
        return { y: document.body.scrollTop, x: document.body.scrollLeft };
    }
    return { x: 0, y: 0 };
}

function getWindowDims() {
    if (window.innerWidth) {
        return { w: window.innerWidth, h: window.innerHeight };
    }
    if (document.documentElement && document.documentElement.clientWidth) {
        return { w: document.documentElement.clientWidth, h: document.documentElement.cliendHeight };
    }
    if (document.body) {
        return { w: document.body.clientWidth, h: document.body.clientHeight };
    }
    return { w: 0, h: 0 }
}

window.onload=function(){enableTooltips()};