function show_middle (layer) {
	var div = document.getElementById(layer);	
	div.className = 'show';
	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;
	}
	
	div.style.left = (parseInt(windowWidth) - parseInt(div.offsetWidth)) / 2 + 'px';        	
	div.style.top = (parseInt(windowHeight) - parseInt(div.offsetHeight)) / 2 + 'px';
}

function show_middle_fundo (layer) {
	var div = document.getElementById(layer);	
	div.className = 'show';
	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;
	}
	
	var div2 = document.getElementById('fundo');	
	div2.style.width = windowWidth + 'px';
	div2.style.height = windowHeight + 'px';
	div2.className = 'show';
	
	div.style.left = (parseInt(windowWidth) - parseInt(div.offsetWidth)) / 2 + 'px';        	
	div.style.top = (parseInt(windowHeight) - parseInt(div.offsetHeight)) / 2 + 'px';
}

function close_parent(layer)
{
	parent.janela_aberta = false;
	var div2 = parent.document.getElementById('fundo');
	div2.className = 'hide';
	var div = parent.document.getElementById(layer);
	div.className = 'hide';
}

function show(layer)
{
	var div = document.getElementById(layer);	
	div.className = 'show';
}

function hide(layer)
{
	var div = document.getElementById(layer);	
	div.className = 'hide';	
}

function abre_janela(layer, superior)
{
if (document.getElementById(layer)) {
		if (typeof superior != 'undefined') {
			janela_aberta = layer;
			abre_janela_fundo(layer, superior);
		} else {
			janela_aberta = layer;
			abre_janela_fundo(layer);
		}
	}
}

function fecha_janela(layer)
{
	var div2 = document.getElementById('fundo');
	div2.className = 'hide';
	var div = document.getElementById(layer);
	div.className = 'hide';
	janela_aberta = false;
}


function resize()
{
	if (janela_aberta) abre_janela_fundo(janela_aberta);
}

var janela_aberta = false;


function abre_janela_fundo(layer, posicao_top)
{
	var arrayPageSize = getPageSize();
	var fundo = document.getElementById('fundo');
	var janelinha = document.getElementById(layer);
	var arrayPageScroll = getScrollOffsets();
	var arrayClientSize = getClientSize();
	var windowTop = arrayPageScroll[1]; // canto superior 			
	var windowLeft = arrayPageScroll[0]; // canto esquerdo
	
				
	// modifica o fundo	
	fundo.style.width = arrayPageSize[0] + 'px';
	fundo.style.height = arrayPageSize[1] + 'px';
	fundo.className = 'show';	
	
	// modifica a janelinha		
	janelinha.className = 'show';
	var windowMidTop;
	if (typeof posicao_top != 'undefined') {
		windowMidTop = windowTop + posicao_top;
	} else {
		windowMidTop = Math.min(Math.max(Math.ceil(((arrayClientSize[1]/2) - (janelinha.offsetHeight/2)) + windowTop) , 0), arrayPageSize[1]- janelinha.offsetHeight);
	}	
	var windowMidLeft = (arrayPageSize[0] + windowLeft - janelinha.offsetWidth)/2 + windowLeft;
	janelinha.style.top = windowMidTop + 'px';
	janelinha.style.left = windowMidLeft + 'px';	
}


function getPageSize() 
{	        
	 var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		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
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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 = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}

function getScrollOffsets()
{
	return Array( window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft,
	  window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop);
}

function getClientSize()
{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return Array(myWidth,myHeight );
}