/*
	Litebox JS by Alexander Shabuniewicz - http://eye.loveline.ru
	2006-04-11

	inspired by Lightbox JS - Lokesh Dhakar - http://www.huddletogether.com
	and portfolio script of Cameron Adams - http://portfolio.themaninblue.com
*/

function showBox(widthMBox, heightMBox, msgText) {
	var theBody = document.getElementsByTagName('body')[0];
	var pageCoords = getPageCoords();

	var theShadow = document.createElement('div');
	theShadow.id = 'theshadow';
	theShadow.className = "page_shadow";
	theShadow.style.height = (pageCoords[1] + 'px');
	theShadow.align = "center";
	
	theBody.insertBefore(theShadow, theBody.firstChild);

	var theBox = document.createElement('div');
	theBox.id = 'thebox';
	theBox.style.width = widthMBox + 'px';
	theBox.style.height = heightMBox + 'px';
	theBox.style.background = "#FFFFFF";
	theBox.style.border = "solid black 2px";
	theBox.style.marginTop = parseInt(pageCoords[2] + (pageCoords[0] - heightMBox - 50) / 2) + 'px';
			
    theBox.innerHTML = 'Загрузка данных...';
	theShadow.appendChild(theBox);
}

function getPageCoords() {
	var coords = [0, 0, 0]; // height of window, document, scroll pos
	// all except IE
	if (window.innerHeight) {
		coords[0] = window.innerHeight;
		coords[2] = window.pageYOffset;
	}
	// IE 6 Strict
	else if (document.documentElement && document.documentElement.clientHeight != 0) {
		coords[0] = document.documentElement.clientHeight;
		coords[2] = document.documentElement.scrollTop;
	}
	else if (document.body) {
		coords[0] = document.body.clientHeight;
		coords[2] = document.body.scrollTop;
	}

	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight;
	if (test1 > test2) {
		coords[1] = document.body.scrollHeight;
	} else {
		coords[1] = document.body.offsetHeight;
	}
	if (coords[1] < coords[0]) coords[1] = coords[0];

	return coords;
}

function closeBox() {
	document.getElementById('theshadow').style.display = 'none';
	document.getElementById('thebox').style.display = 'none';

	return false;
}

function showPageMsg(widthMBox, heightMBox, msgText){
	showBox(widthMBox, heightMBox, '');
	var msgBox = document.getElementById('thebox');
	msgBox.innerHTML = '<table width="100%" height="100%" border="0"><tr><td align="center" valign="middle"><div align="center" class="header_2" style="color:red;">' + msgText + '</div><div align="right"><input type="button" value=" Закрыть " onclick="closeBox();" />&nbsp;&nbsp;</div></td></tr></table>';
}