// JavaScript Document
// Created By: 	Ivaylo Stefanov
// Website: 	http://maimunarnik.com
// Date: 		12.12.2009
// ------------------------------------------------------------------------------------------------------------------------------

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 messageShow( obj, w, h ) {
	// scroll to top ot the page
	scrollTo(0,0);
	
	// hide select and objects in IE
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++) {
			if(selects[i].form.name != 'lightboxForm')
				selects[i].style.visibility = "hidden";
		}
		flashObjects = document.getElementsByTagName("object");
		for (i = 0; i != flashObjects.length; i++) {
			flashObjects[i].style.visibility = "hidden";
		}
	}
	
	// hide body scrollbars
	document.getElementById('body').style.overflow = "hidden";
	
	// get page size
	var arrayPageSize = getPageSize();

	// overlay
	var overlay = document.getElementById('overlayContainer');
	overlay.style.display = 'block';
	overlay.style.width = arrayPageSize[0]+'px';
	overlay.style.height = arrayPageSize[1]+'px';
	
	// message
	var html = document.getElementById(obj).innerHTML;
	var messageBox = document.getElementById('messageBox');
	messageBox.innerHTML = '<div style="border:solid 1px #ffffff">'+html+'</div>';
	messageBox.style.width = w+'px';
	messageBox.style.height = h+'px';
	messageBox.style.top = ((arrayPageSize[3] - h) / 2)+'px';
	messageBox.style.left = ((arrayPageSize[0] - w) / 2)+'px';
	messageBox.style.display = 'block';
}

function messageHide() {
	// show select and objects in IE
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = "visible";
		}
		flashObjects = document.getElementsByTagName("object");
		for (i = 0; i != flashObjects.length; i++) {
			flashObjects[i].style.visibility = "visible";
		}
	}
	
	// show body scrollbars
	document.getElementById('body').style.overflow = "auto";
	
	// hide overlayContainer and messageBox
	document.getElementById('messageBox').style.display = 'none';
	document.getElementById('overlayContainer').style.display = 'none';
}