/**
 * function loader_show()
 *
 * show loader with overlay to stop users from performing
 * multiple XHRs
 *
 * param string "node" (node identifying where was the loader called)
 */
 
function loader_show(additional) {

	/**
	 * loader must not be already set
	 */
	if (loader == null) {

		/**
		 * get document height including scrolls, because we want the overlay to
		 * blank everything even on places hidden by scroll		 
		 */
		if (window.innerHeight && window.scrollMaxY) {
			document_height = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){
			document_height = document.body.scrollHeight;
		} else {
			document_height = document.body.offsetHeight;
	  	}

		/**
		 * create loader overlay and append styles
		 */
		loader = document.createElement("div");
		loader.id = "loader";
		loader.style.opacity = "0";
		loader.style.filter = "alpha(opacity=0)";
		loader.style.width = "100%";
		loader.style.height = document_height + "px";
		document.body.appendChild(loader);

		/**
		 * create loader image and text and append styles
		 */
		var loader_text = document.createElement("div");
		loader_text.id = "loader_text";
		loader_text.style.left = ((window.innerWidth ? window.innerWidth : document.documentElement.clientWidth) - 300) / 2 + "px";
		loader_text.style.top = ((window.innerHeight ? window.innerHeight : document.documentElement.clientHeight) - 60) / 2 + "px";
		loader_text.innerHTML = "<img src=\"" + url + "images/loading.gif\" alt=\"\" /><br />Pracuji...";
		document.body.appendChild(loader_text);
		
		if (additional != null) {
			additional.style.marginTop = "10px";
			loader_text.style.height = "100px";
			loader_text.appendChild(additional);
		}
	}
}


/**
 * function loader_hide()
 *
 * remove loader and overlay from body
 *
 * param string "node" (node identifying where was the loader called)
 */
function loader_hide() {
	if (loader) {
		var loader_text = document.getElementById("loader_text")
	
		while (loader_text.childNodes.length > 0) loader_text.removeChild(loader_text.lastChild);
	
		document.body.removeChild(loader_text);
		document.body.removeChild(loader);
		
		loader_text = null;
		loader = null;
	}
}
