if (document.images) {
	preload_image = new Image(16,16);
	preload_image.src="images/structure/loading.gif";
}

var xmlHttp = 'unset';
var xmlComm = '';

function ploading(obj) {
	obj.innerHTML = '<h1><img src="images/structure/loading.gif" style="margin-right:10px;" />Loading Data...</h1>';
	centerDiv(obj);
	obj.style.display = 'block';
}

function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);

	return arrayPageSizeWithScroll;
}

function pblackout(obj) {
	page_dimensions = getPageSizeWithScroll();
	obj.style.width = page_dimensions[0]+'px';
	obj.style.height = page_dimensions[1]+'px';
	obj.style.left = '0px';
	obj.style.top = '0px';
	obj.style.display = 'block';
 	setOpacity('7', obj);
}

function fetch_ajax_data(url) {
	if(document.getElementById('lightbox')) {
		var lightbox = document.getElementById('lightbox');
	}

	ploading(lightbox);

	if(document.getElementById('blackout')) {
		var blackout = document.getElementById('blackout');
	}

	pblackout(blackout);

	if(xmlHttp!='unset') { xmlHttp.abort; }
	set_xmlHttp();
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);
}

function fetch_ajax_page(url, comm) {
	xmlComm = comm;
	fetch_ajax_data(url);
}

function centerDiv(divobj) {
	divobj.style.top = '0px';
	divobj.style.left = '0px';
	divobj.style.display = 'block';
	var ie=document.all && !window.opera
	var dom=document.getElementById
	var x = ((document.body.clientWidth-divobj.clientWidth)/2);
	this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
	var scroll_top=(ie)? this.standardbody.scrollTop : window.pageYOffset
	var docheight=(ie)? this.standardbody.clientHeight: window.innerHeight
	var docheightcomplete=(this.standardbody.offsetHeight>this.standardbody.scrollHeight)? this.standardbody.offsetHeight : this.standardbody.scrollHeight //Full scroll height of document
	var objheight=divobj.offsetHeight //height of div element
	var topposition=(docheight>objheight)? scroll_top+docheight/2-objheight/2+"px" : scroll_top+10+"px" //Vertical position of div element: Either centered, or if element height larger than viewpoint height, 10px from top of viewpoint
	divobj.style.left=x+'px';
	divobj.style.top=Math.floor(parseInt(topposition))+"px"
}

function unload_lbox() {
	if(document.getElementById('lightbox')) {
		document.getElementById('lightbox').style.display = 'none';
		document.getElementById('lightbox').innerHTML = '';
	}
	if(document.getElementById('blackout')) {
		document.getElementById('blackout').style.display = 'none';
	}
}
					
function set_xmlHttp() {
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		try {
			// Internet Explorer
			xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			try {
				xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e) {
				// Your browser does not support AJAX!
				return false;
			}
		}
	}
		
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			if(document.getElementById('lightbox')) {
				var lightbox = document.getElementById('lightbox');
				lightbox.style.display = 'none';
				lightbox.innerHTML = xmlHttp.responseText;
				centerDiv(lightbox);
			}

			if(xmlComm != '') {
				if(typeof(xmlComm) == 'function') {
					xmlComm();
				}
				xmlComm = '';
			}
		}
	}
}

function lightboxit() {
	if(document.getElementById('lightbox')) {
		var lightbox = document.getElementById('lightbox');
	}

	if(document.getElementById('blackout')) {
		var blackout = document.getElementById('blackout');
	}

	pblackout(blackout);
	lightbox.style.display = 'block';
	centerDiv(lightbox);
	
}