// JavaScript Document
var div = document.getElementsByTagName('div');

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) {
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
	} else {
		xScroll=document.body.offsetWidth;
		yScroll=document.body.offsetHeight;
	}
	var windowWidth,windowHeight;
	if(self.innerHeight){
		windowWidth=self.innerWidth;
		windowHeight=self.innerHeight;
	} else if(document.documentElement&&document.documentElement.clientHeight) {
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	} else if(document.body){
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}
	
	if(yScroll<windowHeight) {
		pageHeight=windowHeight;
	} else {
		pageHeight=yScroll;
	}
	
	if(xScroll<windowWidth) {
		pageWidth=windowWidth;
	}else {
		pageWidth=xScroll;
	}
	arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

function ocultar( descricao ) {
	// Fechar popups da pagina cafe "closePopupsCafe". Os quais serão ocultados ao clicar na div lockPagina.
	if (descricao == "closePopupsCafe") {
		// Fechar todos
		var str="";
		var pos=0;
		for (var i=0; i < div.length; i++) {
			str = div[i].id;
			pos = str.indexOf("popupCafe");
			if (div[i].id == "lockPagina" || pos >= 0) {
				div[i].style.display = "none";
			}
			pos=0;
		}
	} else {
		// Fechar especifico
		for (var i=0; i < div.length; i++) {
			if (div[i].id == descricao) {
				div[i].style.display = "none";
				document.getElementById('lockPagina').style.display = "none";
			}
		}
	}
}

function visualizar( descricao ) {	
	arrayPageSize=new Array(4);
	arrayPageSize=getPageSize();
				
	for ( var i=0; i < div.length; i++ ) {
		if (div[i].className == 'popupCorpo' ) {
            // Alinha o popup sempre no centro da tela.
			div[i].style.left = Math.floor(arrayPageSize[0]/2) - 300 +"px"; // pageWidth menos 300 que é a metado do popup.
			div[i].style.top = Math.floor(arrayPageSize[3]/2) - 200 +"px"; // pageWidth menos 300 que é a metado do popup.
		}
		if ( div[i].id == descricao ) {
			//alert(div[i].className +"     "+ div[i].id +"     "+ div[i].style.left);
			if (div[i].style.display == "block") {
				div[i].style.display = "none";
				document.getElementById('lockPagina').style.display = "none";
			} else {				
				// mostra o popup
				div[i].style.display = "block";
				// segundo plano.
				var lock = document.getElementById('lockPagina');
				lock.style.width = arrayPageSize[2]+"px"; // windowWidth
				lock.style.height = arrayPageSize[1]+"px"; // pageHeight
				lock.style.display = "block";				
			}
		}
	}
}

function mostrarPopup(divId) {
	visualizar(divId);
}

function ocultarPopup(divId) {
	ocultar(divId);
}

