/******************************************************************************************/
/* messageLightbox objektum                                                                \
/* ----------------------------------------------------------------------------------------\
/* Üzenetablakok modális megjelenítésére szolgáló objektum.                                \
/*                                                                                         \
/* működése - használata                                                                   \
/* ----------------------------------------------------------------------------------------\
/* 1, window.onload-ra kell mmeghívni az init() taggfüggvényt                              \
/* 2, Valamely layer megjelenítéséhez a show([layerObj, width, height]) taggfüggvényt kell \
/*    meghívni, ahol a layerObj egy div elem, amelyre kerül a kiírandó ablak, üzenet.      \
/* 3, Eltüntetéshez a hide() tagfüggvény használaható.                                     \
/* ----------------------------------------------------------------------------------------\
/*                                                                                         \
/* FONTOS!                                                                                 \
/* ----------------------------------------------------------------------------------------\
/* A megjelenítendő layernek kell hogy legyen stílusban megadott (style:height:00px)       \
/* magassága és szélessége, mert ezekből lesznek kiszámítva a koordináták a layer középre  \
/* helyezéséhez.                                                                           \
/******************************************************************************************/

messageLightbox = {}

messageLightbox.overlay = 'warning_overlay'

messageLightbox.lightbox = 'warning_lightbox'

messageLightbox.init = function()
{	
	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', messageLightbox.overlay);	
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '190';
 	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);
	
	var arrayPageSize = this.getPageSize();
	var arrayPageScroll = this.getPageScroll();

	// create lightbox div, same note about styles as above
	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id', messageLightbox.lightbox);
	objLightbox.style.display = 'none';
	objLightbox.style.position = 'absolute';
	objLightbox.style.zIndex = '200';	
	objBody.insertBefore(objLightbox, objOverlay.nextSibling);
	
	this.addOtherFunctions();	
}

messageLightbox.getPageScroll = function()
{
	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;
}

messageLightbox.getPageSize = function()
{
	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;
}

messageLightbox.hide = function()
{	
	// get objects
	objOverlay = document.getElementById(messageLightbox.overlay);
	objLightbox = document.getElementById(messageLightbox.lightbox);
	
	// hide lightbox and overlay    
	objOverlay.style.display = 'none';
	objLightbox.style.display = 'none';
	objLightbox.innerHTML = '';

	// make select boxes visible
	selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}	
}

messageLightbox.show = function(pars)
{			
	// prep objects
	var objOverlay = document.getElementById(this.overlay);
	var objLightbox = document.getElementById(this.lightbox);	
	
	var arrayPageSize = this.getPageSize();
	var arrayPageScroll = this.getPageScroll();	

	// set height of Overlay to take up whole page and show
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';	
			

	// center lightbox and make sure that the top and left values are not negative
	// and the image placed outside the viewport
	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - pars[2]) / 2); 
	var lightboxLeft = ((arrayPageSize[0] - 20 - pars[1]) / 2); 
		
	objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
	objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";		

	// Hide select boxes as they will 'peek' through the image in IE
	selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) {
          selects[i].style.visibility = "hidden";
    }

    objLightbox.innerHTML = '';
	objLightbox.style.display = 'block';

	// After image is loaded, update the overlay height as the new image might have
	// increased the overall page height.
	arrayPageSize = this.getPageSize();
	objOverlay.style.height = (arrayPageSize[1] + 'px');	
	
	objLightbox.appendChild(pars[0]);
}

messageLightbox.addOtherFunctions = function()
{
	build2MinWarningBox();
}

onLoadFuncts+="messageLightbox.init();";