var currentLBEl = null;
var selectBuff = null;
var imgs = {};

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;
}

/* * * * * * * * * * * * * * * * */
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;
}

/* * * * * * * * * * * * * * * * */
function showLightBox(elID) {
	var objOverlay = document.getElementById('overlay');
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	objOverlay.style.height = (arrayPageSize[1] + 'px');
	//objOverlay.style.width = (arrayPageSize[0] + 'px');
	objOverlay.style.width = (document.body.clientWidth + 'px');

	if (currentLBEl) {
		srcEl = document.getElementById(currentLBEl);
		if (srcEl) {
			srcEl.style.display = 'none';
		}
	}

	srcEl = document.getElementById(elID);
	if (srcEl) {
		srcEl.style.visibility = 'hidden';
		srcEl.style.display = 'block';
		var height = srcEl.clientHeight;
		var width = srcEl.clientWidth;

		srcEl.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - height) / 2) + 'px');
		srcEl.style.left = (((arrayPageSize[0] - 20 - width) / 2) + 'px');
		srcEl.style.visibility = 'visible';


	}
	currentLBEl = elID;
	if (selectBuff == null) {
		selectBuff = [];
		var selects = document.getElementsByTagName('select');
		var vselects = srcEl.getElementsByTagName('select');
		var i,j,flag;
		for (i = 0;i < selects.length;i++) {
			flag = false;
			for (j = 0;j < vselects.length;j++) {
				if (vselects[j] == selects[i]) {
					flag = true;
					break;
				}
			}
			if (!flag) selectBuff.push(selects[i]);
		}
	}
	for (var i = 0;i < selectBuff.length;i++) {
		selectBuff[i].style.visibility = 'hidden';
	}

	objOverlay.style.display = 'block';
}

/* * * * * * * * * * * * * * * * */
function hideLightBox() {
	var objOverlay = document.getElementById('overlay');
	objOverlay.style.display = 'none';
	var srcEl = document.getElementById(currentLBEl);
	if (srcEl) {
		srcEl.style.display = 'none';
	}
	for (var i = 0;i < selectBuff.length;i++) {
		selectBuff[i].style.visibility = 'visible';
	}
	currentLBEl = null;
}

/* * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * */
function showBoxImage(elID,img) {
	var srcEl = document.getElementById(elID);
	var el = document.getElementById('branchmap');
	if (imgs[img] != undefined) {
		el.src = img;
	} else {
		el.style.background = 'white url(\'images/icon_wait.gif\') no-repeat center center';
		el.src = "images/dd.gif";
		var imaga = new Image();
		imaga.src = img;
		imaga.onload = function () {
			var im = document.getElementById('branchmap');
			im.src = img;
		}
		imgs[img] = imaga;
	}
	showLightBox(elID);

}