/* =overlay popup
-------------------------------------------------- */
function g(id){
	return document.getElementById(id);
}

var openOverlayContent = null;

function showOverlaySelectBoxes(element){
	if (element.tagName=="SELECT"){
		element.style.visibility = "visible";
	}
	if (!element.childNodes) return;
	for (var i=0; i<element.childNodes.length; i++){
		showOverlaySelectBoxes(element.childNodes[i]);
	}
}

function showOverlay(target){
	var arrayPageSize = getPageSize();
	var popup         = document.getElementById(target);
	var overlay = document.getElementById('overlay');

	if (openOverlayContent != null){
		g(openOverlayContent).style.display = 'none';
	}
	openOverlayContent = target;

	if (self.pageYOffset) { // all except Explorer
		var scroll_left = self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
		var scroll_left = document.documentElement.scrollLeft;
	}
	else if (document.body) { // all other Explorers
		var scroll_left = document.body.scrollLeft;
	}

	overlay.style.display = 'block';

	

	hideSelectBoxes();
	showOverlaySelectBoxes(popup);

	popup.style.display = 'block';

	if (self.pageYOffset) { // all except Explorer
		var scroll_top = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
		var scroll_top = document.documentElement.scrollTop;
		overlay.style.height = arrayPageSize[1] + 'px';
	overlay.style.width = arrayPageSize[0] + scroll_left + 'px';
	}
	else if (document.body) { // all other Explorers
		var scroll_top = document.body.scrollTop;
	}

	popup.style.top = scroll_top + ((arrayPageSize[3] / 2) - (popup.offsetHeight / 2)) + 'px';
	popup.style.marginLeft = '-' + (popup.offsetWidth / 2) + 'px';

	return false;
}

/* =hide overlay
-------------------------------------------------- */
function hideOverlay(popupId) {
	var popup = document.getElementById(popupId);
	var overlay = document.getElementById('overlay');

	popup.style.display = 'none';
	overlay.style.display = 'none';

	showSelectBoxes();
	return false;
}
function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (var i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}
function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (var i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

/* =get page size
-------------------------------------------------- */
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;
}
