// JavaScript Document
// CRIA POPUP 
function popUp(page, width, height, posx, posy, name){	
	if(!name) name = "winPop";
	if(!width){
		var width = (window.screen.width/1.1);
		var height = (window.screen.height/1.1);
	}
	if(!posx){
		var posx = (window.screen.width/2) - (width / 2) - 5;
		var posy = (window.screen.height/2) - (height / 2) - 25;
	}
		
	var settings = " status = "+ 0 +
		",toolbar		= "+ 0 +
		",location		= "+ 0 +
		",menubar		= "+ 0 +
		",directories	= "+ 0 +
		",scrollbars	= auto" + 
		",fullscreen	= "+ 0 +
		",width			= "+ width +
		",height		= "+ height +
		",left			= "+ posx +
		",top			= "+ posy +
		",screenX		= "+ posx +
		",screenY		= "+ posy;

	openPop = window.open(page, name, settings);
	
	if(openPop){
		openPop.resizeTo(width, height);
		openPop.moveTo(posx, posy);
		return openPop;
	}
	else return false;
}

function popupVoltar(){
	total = elements_pop.length;
	if(atual == 0) atual = elements_pop.length-1;
	else atual--; 
	popImage(atual, elements_pop[atual]);
}
function popupAvancar(){
	total = elements_pop.length;
	if(atual >= total-1) atual = 0;
	else atual++; 
	popImage(atual, elements_pop[atual]);
}
function popImage(atu, elements_pop){	
	atual = atu;
	imagem	= elements_pop[0];
	width	= elements_pop[1];
	height	= elements_pop[2];
	legenda	= elements_pop[3];
	// 	WINDOW para abrir popup
	end = "";
	tipo = "layer";
	if(!legenda) legenda = "";
	if(tipo == "window"){
		var end;
		var titulo = window.document.title;
		var page = window.location;
		var name = "popImagem";
		
		openPop = popUp(page, width, height, posx, posy, name);

		if(openPop){
		
			codHtml = "<html><head>\n";
			codHtml += "<title>"+ titulo +"</title>\n";
			codHtml += "<link href=\"css/style_screen.css\" rel=\"stylesheet\" type=\"text/css\">\n";
			codHtml += "</head><body style=''>\n";
			codHtml += "<table width=\"100%\" height=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">\n";
			codHtml += "<tr><td align='center'>\n";
			codHtml += "<a href=\"javascript:window.close();\" title='Clique para fechar a janela'><img src=\""+ end + imagem +"\" alt=\"Fechar\"  border=\"0\" class='imagem'/></a>\n";
			codHtml += "</td></tr>\n";
			codHtml += "</table>\n";
			codHtml += "</body></html>\n";
			
			openPop.document.open();
			openPop.document.write(codHtml);
			openPop.document.close();
			openPop.focus();
			return false;
		}
	}
	// 	LAYER para abrir em camada
	else{

		botoes = "<a href=\"javascript:popupVoltar();\" id=\"vem\" title='Clique para voltar'><img src=\"img/seta_esq.gif\" alt=\"Voltar\" width=\""+ 18 +"\" height=\""+ 18 +"\"  border=\"0\"/></a>";
		botoes += "<a href=\"javascript:popupAvancar();\" id=\"vai\" title='Clique para voltar'><img src=\"img/seta_dir.gif\" alt=\"Avançar\" width=\""+ 18 +"\" height=\""+ 18 +"\"  border=\"0\"/></a>";

		codHtml = "<table width=\"100%\" height=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">\n";
		codHtml += "<tr><td align='center'>\n";
		codHtml += "<a href=\"javascript:popupRemove('boxPOPUP');\" title='Clique para fechar a janela'><img src=\""+ end + imagem +"\" alt=\"Fechar\" width=\""+ width +"\" height=\""+ height +"\"  border=\"0\" class='imagem'/></a>\n";
		codHtml += "</td></tr>\n";
		codHtml += "<tr><td align='left'>\n";
		codHtml += "<div class='legenda'><div id='popNav'> "+ botoes +" </div>"+legenda+ "</div>";
		codHtml += "</td></tr>\n";
		codHtml += "</table>\n";

		popLayer(codHtml, width, height);
	}
}

function popLayer(content, width, height){
	
	var obj = document.getElementById('boxPOPUP');
	if (!obj){
		
		target = document.body;
		
		var newElement = document.createElement('div');
		newElement.setAttribute('id',		'boxPOPUP');
		newElement.setAttribute('name',		'boxPOPUP');
		target.appendChild(newElement);
		obj = newElement;
	}
	
	obj.innerHTML = "";
	obj.style.display = "block";

	var posTop = -( (height+18)/2 - document.documentElement.scrollTop);
	
	var strHTML = "<div id='boxPOPUPint' style=\"width:" + width + "px;  position:absolute; z-index:3; top:50%; left:50%; margin:" + posTop + "px 0px 0px -" + width/2 + "px; background-color:#E5E7EC; border:5px solid #E5E7EC\">";
		strHTML += "<div class=\"popupTitle\" style=\"text-align:right\"><a href=\"javascript:popupRemove('boxPOPUP')\" style=' font-size:9px;'>FECHAR <strong>X</strong></a></div>";
		strHTML += content;
		strHTML += "</div>";
	 	strHTML += "<div style=\"width:" + 100 + "%; height:" + document.getElementById("BASE_INT").offsetHeight + "px; position:absolute; z-index:2; top:0; left:0; opacity: .21; filter: alpha(opacity=21); background-color:#60646B;\">";
		strHTML += "</div>";
		
	obj.innerHTML = strHTML;
}

function popupRemove(obj){
	obj = document.getElementById(obj);
	if (obj) obj.style.display = "none";
}