var newhttp

function getXmlHttpRequestObject() {
        if (window.XMLHttpRequest) {
                return new XMLHttpRequest();
        } else if (window.ActiveXObject) {
                return new ActiveXObject("Microsoft.XMLHTTP");
        } else {
        }
}

function InfoWindow (url, name, height, width) {
	window.open(url, name, "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,height="+height+",width="+width);
	return false;
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function'){
        window.onload = func;
    } else {
        window.onload = function(){
        oldonload();
        func();
        }
    }

}

function showDiv (showDiv, hideDiv) {
	document.getElementById(showDiv).style.display = 'block';
	if (hideDiv) {
		document.getElementById(hideDiv).style.display = 'none';
	}
}

var currentSearch = 'search';

function searchTab () {

	if (currentSearch == 'search') {
			document.getElementById('advancedsearch').style.display = 'block';
			document.getElementById('normalsearch').style.display = 'none';
			document.getElementById('search_tab').src = '/_images/buttons/nav_search.gif';
			currentSearch = 'advancedsearch';

	} else {
			document.getElementById('normalsearch').style.display = 'block';
			document.getElementById('advancedsearch').style.display = 'none';
			document.getElementById('search_tab').src = '/_images/buttons/advancedsearch.gif';
			currentSearch = 'search';
	}

}

function showLoading () {
	var objOverlay = document.getElementById('overlay');
	var objImage = document.getElementById('loading_image');

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	

	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';

	if (objImage) {
		objImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 32) / 2) + 'px');
		objImage.style.left = (arrayPageSize[2] / 2) - 32  + 'px';
		objImage.style.zIndex = '100';
		objImage.style.display = 'block';
	}

}

function hideLoading () {
	objOverlay = document.getElementById('overlay');
	objOverlay.style.display = 'none';
}

function initLoading () {
	var objBody = document.getElementsByTagName("body").item(0);

	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.onclick = function () { hideLoading(); return false; }
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '90';
	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);

	var imgPreloader = new Image();

		var objLoadingImageLink = document.createElement("a");
		objLoadingImageLink.setAttribute('href','#');
		objLoadingImageLink.onclick = function () {hideLoading(); return false;}
		objOverlay.appendChild(objLoadingImageLink);

		var objLoadingImage = document.createElement("img");
		objLoadingImage.src = '/_images/template/list_loading.gif';
		objLoadingImage.setAttribute('id','loading_image');
		objLoadingImage.style.position = 'absolute';
		objLoadingImage.style.zIndex = '150';
		objLoadingImageLink.appendChild(objLoadingImage);

		imgPreloader.onload=function(){};       //      clear onLoad, as IE will flip out w/animated gifs

	imgPreloader.src = '/_images/template/list_loading.gif';

	showLoading();
}

