﻿var _TOOLTIP_ = 'bubble_tooltip';

function showToolTip(text, event) {
	if(!event) var event=window.event;
	if(!event) return;
	if(!event.pageX) event.pageX = event.clientX + document.body.scrollLeft;
	if(!event.pageY) event.pageY = event.clientY + document.body.scrollTop;
	var evx = event.pageX;
	var evy = event.pageY;

	var obj = document.getElementById(_TOOLTIP_);
	if(obj.style.display == 'block') return;
	var obj2 = document.getElementById(_TOOLTIP_ + '_cont');
	obj2.innerHTML = text;
	obj.style.display = 'block';

	obj.style.left = Math.max(0, evx - 240) + 'px';
	obj.style.top = Math.max(0, evy - obj.offsetHeight - 1) + 'px';
}	

function hideToolTip()
{
	document.getElementById(_TOOLTIP_).style.display = 'none';
}

function embedToolTip() {
	document.write('<div id="' + _TOOLTIP_ + '">');
	document.write('<div class="bubble_top"></div>');
	document.write('<div class="bubble_middle" id="' + _TOOLTIP_ + '_cont"></div>');
	document.write('<div class="bubble_bottom"></div>');
	document.write('</div>');
}

function getElementWidth(elm) {
	if (!document.all) {
		return elm.offsetWidth;
	} else {
		return elm.offsetWidth;
	}
}

function getElementHeight(elm) {
	if (!document.all) {
		return elm.offsetHeight;
	} else {
		return elm.offsetHeight;
	}
}

function getElementLeft(elm) {
	if (!document.all) {
		return elm.offsetLeft;
	} else {
		return elm.offsetLeft;
	}
}

function getElementTop(elm) {
	if (!document.all) {
		return elm.offsetTop;
	} else {
		return elm.offsetTop;
	}
}

function getScrollLeft() {
	if(!document.all){
		return document.body.scrollLeft;
	} else {
		return document.body.scrollLeft;
	}
}

function getScrollTop() {
	if(!document.all){
		return document.body.scrollTop;
	} else {
		return document.body.scrollTop;
	}
}

function getWindowWidth() {
	var w = 0;
	if(document.body && document.body.clientWidth) {
		w = document.body.clientWidth;
	}
	else if(window.innerWidth) {
		w = window.innerWidth;
	}
	return w;
}

function getWindowHeight() {
	var h = 0;
	if(document.body && document.body.clientHeight) {
		h = document.body.clientHeight;
	}
	else if(window.innerHeight){
		h = window.innerHeight;
	}
	return h;
}

function showCitation(id, event) {
	var elm=document.getElementById('citation_'+id);
	if(!elm) return;
	var html=elm.innerHTML;
	showToolTip(html,event);
}

function showNote(id, event) {
	var elm=document.getElementById('note_'+id);
	if(!elm) return;
	var html=elm.innerHTML;
	showToolTip(html,event);
}

function enterKeyword(id, elm, event) {
	elm.style.color='#e00';
	var html=sendRequest('/keyword?id='+id);
	showToolTip(html,event);
}

function exitKeyword(elm) {
	elm.style.color='';
	hideToolTip();
}

function getHttpRequest() {
	var httpRequest;

	// Mozilla, Safari, ...
	if (window.XMLHttpRequest) {
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType) {
			httpRequest.overrideMimeType('text/xml');
		}
	} 
	// IE
	else if (window.ActiveXObject) {
		try {
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) {
			try {
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) {}
		}
	}
	return httpRequest;
}

function sendRequest(url) {
	var httpRequest=getHttpRequest();

	if (!httpRequest) {
		alert('Giving up : Cannot create an XMLHTTP instance');
		return '';
	}

	httpRequest.open('GET', url, false);
	httpRequest.send('');
	if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) {
			return httpRequest.responseText;
		} else {
			alert('There was a problem with the request. status: '+httpRequest.status);
		}
	}
	else {
		alert('There was a problem with the request. not ready: '+httpRequest.status);
	}
	return '';
}

function expandTree(tree,button) {
	var pnl = document.getElementById(tree); 
	if(pnl.style.display=='block') {
		pnl.style.display='none';
		button.value='▼';	}
	else {
		pnl.style.display='block';
		button.value='▲';
	}
}



