var imageInsertText="../img/iTM2-insert.png";
function URIInsertText(component)
{
	return("itexmac2://insert?"+encodeURIComponent(component));
}
function markInsert()
{
	document.write("<img src=\""+imageInsertText+"\" class=\"insert\" alt=\"None\" name=\"None\" onmousedown=\"doInsertText()\">");
}
function doInsertText()
{
	var theTarget;
	if (!theEvent)
		var theEvent = window.event
	if (theEvent.target)
		theTarget = theEvent.target
	else if (theEvent.srcElement)
		theTarget = theEvent.srcElement
	if (theTarget.nodeType == 3) // defeat Safari bug
	{
		theTarget = theTarget.parentNode;
	}
	var theSibling = theTarget.nextObject();
	if(theSibling.getAttribute("class") == "insert")
	{
		window.location = URIInsertText(theSibling.textContent());
	}
}
//http://pompage.net/pompe/pieds/
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
function adjustFooterPosition() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentHeight = document.getElementById('content').offsetHeight;
			var footerElement = document.getElementById('footer');
			var footerHeight  = footerElement.offsetHeight;
			if (windowHeight - (contentHeight + footerHeight) >= 0) {
				footerElement.style.position = 'relative';
				footerElement.style.top = (windowHeight - (contentHeight + footerHeight)) + 'px';
			}
			else {
				footerElement.style.position = 'static';
			}
		}
	}
}
window.onload = function() {
	adjustFooterPosition();
}
window.onresize = function() {
	adjustFooterPosition();
}
Object.prototype.nextObject = function() {
	var n = this;
	do n = n.nextSibling;
	while (n && n.nodeType != 1);
	return n;
}
Object.prototype.previousObject = function() {
	var p = this;
	do p = p.previousSibling;
	while (p && p.nodeType != 1);
	return p;
}
Object.prototype.textContent = function() {
	if(this.nodeType == 3)
	{
		return this.data;
	}
	var result = "";
  	for (var i = 0, child; child = this.childNodes[i]; i++) {
	        result = result+child.textContent();
    	}
	return result
}
