/* Corrib.js, (c) 2008 vitvar.com
 * JavaScript for the corrib style
 */

// this function is used to adjust the page height; 
// it is used as the hook function when loading content
// the element ids are defined in html-root element 
adjustPageHeight = function() {
	s = document.getElementById('sdbr');
	c = document.getElementById('cntr');
	p = document.getElementById('pcnt');
	f = document.getElementById('ftr');
	
	if (c != null && s != null && p != null) {
		if (p.clientHeight < s.clientHeight) {
			c.style.height = s.clientHeight + 40 + "px"; 
		} else
			c.style.height = p.clientHeight + 40 + "px";
		if (f != null)
			f.style.display = 'block';
	}
}

// functions that is called on state change when dynamic content needs to be loaded into the html element
function loadPage(page_request, element, hook) {
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) {
		element.innerHTML=page_request.responseText;
		if (hook != null)
			hook();
	}
} 		

// function to load the content at url into the element with elementId
function loadDynamicContent(elementId, url, onloadscript, onunloadscript, onstart, onend) {
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else 
		if (window.ActiveXObject){ // if IE
			try {
				page_request = new ActiveXObject("Msxml2.XMLHTTP")
			} catch (e) {
				try {
					page_request = new ActiveXObject("Microsoft.XMLHTTP")
				} catch (e){}
			}
		} else 
			return false;
				
	page_request.onreadystatechange=function() {
        if (this.readyState == 1 && onstart != null) { // open
            onstart();
            onstart = null;
        }
		if (this.readyState == 4) { // done loading
			loadPage(page_request, document.getElementById(elementId));
			if (onunloadscript != null && onunloadscript != "")
				eval(onunloadscript);
			if (onloadscript != null && onloadscript != "")
				eval(onloadscript);
			adjustPageHeight();
            if (onend != null) {
                onend();
                onend = null;
            }
		}
	}

	page_request.open('GET', url, true);
	page_request.send(null);
}

function decodeem(es) {
	location.href= "mailto:" + decodeBase64(es);
}
