/*
// En el HTML:
<div id="div_message" class="divPopup" style="display:none;">
	bla bla bla aca va el html del mensaje
</div>

<!-- este div va justo antes del cierre del tag body: -->
<div id="overlay" style="display:none"></div>
</body>
*/

function msgbox_hide(div, timeout)
{
	if (isNaN(timeout)) timeout = 0;
	setTimeout(function() {
		div = parent.$('#'+div);
		div.hide();  
		$('#overlay').hide();
	}, timeout);
	
}
function msgbox_show(div, heightCorrection, timeout)
{
	if (isNaN(timeout)) timeout = 0;
	if (isNaN(heightCorrection)) heightCorrection = 0;
	setTimeout(function() {
		var scrolls = getPageSizeWithScroll();
		$('#overlay').css('top', 0);
		//$('#overlay').css('height', (document.body.scrollHeight)+"px");
		$('#overlay').css('height', (scrolls[1] + heightCorrection) + "px");
		$('#overlay').show();
		center_div(div);
	}, timeout);
}
function center_div(element)
{	
	element = $('#'+element);

	var my_width  = get_window_width();
	var my_height = get_window_height();
	
	element.css('position', 'absolute');
	element.css('z-index', 9999999999); //999999999
	
	var scrollY = 0;
	if ( document.documentElement && document.documentElement.scrollTop ) {
		scrollY = document.documentElement.scrollTop;
	} else if ( document.body && document.body.scrollTop ) {
		scrollY = document.body.scrollTop;
	} else if ( window.pageYOffset ) {
		scrollY = window.pageYOffset;
	} else if ( window.scrollY ) {
		scrollY = window.scrollY;
	}
	var setX = (my_width  - element.width()) / 2;
	var setY = (my_height - element.height()) / 2 + scrollY;

	setX = (setX < 0) ? 0 : setX;
	setY = (setY < 0) ? 0 : setY;

	element.css('left', setX);
	element.css('top', setY);
	element.css('display', 'block');
}
// Alto de la Pagina (sin contar el scroll).
function get_window_height()
{
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		} else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
// Ancho de la Pagina (sin contar el scroll).
function get_window_width()
{
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	} else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		} else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}
// Retorna un array con los valores de ancho y alto de la pagina, teniendo en cuenta el scroll.
function getPageSizeWithScroll()
{
	if (window.innerHeight && window.scrollMaxY) { // Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
		yWithScroll = (yWithScroll > window.innerHeight) ? yWithScroll : window.innerHeight;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
		yWithScroll = (yWithScroll > document.body.scrollHeight) ? yWithScroll : document.body.scrollHeight;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
		yWithScroll = (yWithScroll > document.body.offsetHeight) ? yWithScroll : document.body.offsetHeight;
		yWithScroll += 200;
  	}
	return [xWithScroll, yWithScroll];
}