function JAuxNavegacao(name){ //ajustar para rotina trataRetorno
	this.name = name;
	this.desempilhaJAux = desempilhaJAux;
	this.empilhaJAux = empilhaJAux;
	this.Elem = new Array();
	this.oNavegacao = null;
	this.setNavegacao = setNavegacao;
	this.setTamanho = setTamanho;
	this.largura = null;
	this.altura = null;
}

function setTamanho(largura, altura){
	this.largura = largura;
	this.altura = altura;
}

function setNavegacao(oNavegacao){
	this.oNavegacao = oNavegacao;	
}

function Navegacao(name){ 
	this.name = name;
	this.desempilha = desempilha;
	this.empilha = empilha;
	this.Elem = new Array();
	this.carrega = carrega;
	this.setUltPaginaCarregada = setUltPaginaCarregada;
	
	/*	Propriedade que indica se o form teve entrada de dados */
	this.bFoiDigitado = false;
	this.setFoiDigitado = setFoiDigitado;
	this.getFoiDigitado = getFoiDigitado;
	
	this.bFSetTransacaoJahCarregado = false;
	this.getFSetTransacaoJahCarregado = getFSetTransacaoJahCarregado;
	this.setFSetTransacaoJahCarregado = setFSetTransacaoJahCarregado;

	this.bAcoesJahCarregado = false;
	this.getAcoesJahCarregado = getAcoesJahCarregado;
	this.setAcoesJahCarregado = setAcoesJahCarregado;

	this.bEhEhPrimeiraEnt = true; //inicia como primeira entrada
	this.getEhPrimeiraEnt = getEhPrimeiraEnt;
	this.setEhPrimeiraEnt = setEhPrimeiraEnt;

	this.setFrameOcultoCarregado = setFrameOcultoCarregado;
	this.getFrameOcultoCarregado = getFrameOcultoCarregado;
	this.bFrameOcultoCarregado = false;

	this.setRelacionamentoCarregado = setRelacionamentoCarregado;
	this.getRelacionamentoCarregado = getRelacionamentoCarregado;
	this.bRelacionamentoCarregado = false;

	this.setCaminhoBase = setCaminhoBase;
	this.getCaminhoBase = getCaminhoBase;
	this.caminhoBase=null;
	this.bSetadoCaminhoBase=false; //seta pra true caso o usuario use um caminho diferente do default

}

function setFoiDigitado(valor){
	this.bFoiDigitado = valor;
}

function getFoiDigitado(){
	return this.bFoiDigitado;
}

function carrega(){
	var topo = (this.Elem.length - 1);
	
/*	if (this.getRelacionamentoCarregado()){//verifica se eh relacionamento, futuramente baixar o grau de coesão (sabe de outra forma se estah carregado ou não)
		//quando for um relacionamento e estiver sendo carregado uma página, deve-se bloquear o frame acoes
		frameSetTransacao.oAcoes.setBloqueado(true);
		this.setRelacionamentoCarregado(false);
	}*/

	if (!frameSetTransacao.oAcoes.getBloqueado()){//só limpa acoes, a tela que não for de relacionamento. Quando relacionamento virá bloqueado
		frameSetTransacao.oAcoes.limpaAcoes() //limpa o frame de ações
	}

	frameSetTransacao.Dados.document.location = this.Elem[topo].pagina;
	this.setFoiDigitado(false); //quando carrega a página, já seta form como não alterado

	if (this.getFrameOcultoCarregado()){ //se tiver carregado, então descarrega
		frameSetTransacao.Geral.document.location = this.getCaminhoBase() +"/Html/Geral.html";
		this.setFrameOcultoCarregado(false);
	}

}

function setFrameOcultoCarregado(valor){
	this.bFrameOcultoCarregado = valor;
}
function getFrameOcultoCarregado(){
	return this.bFrameOcultoCarregado;
}

function setRelacionamentoCarregado(valor){
	this.bRelacionamentoCarregado = valor;
}
function getRelacionamentoCarregado(){
	return this.bRelacionamentoCarregado;
}


/*	Seta o último elemento empilhado	*/
function setUltPaginaCarregada(pagina){
	this.Elem[this.Elem.length-1].pagina = pagina;
}

function empilha(pagina, ehRelacionamento){
	if (!ehRelacionamento){ehRelacionamento=false} //default eh false
	
	//retorna o último índice e empilha
	var i = this.Elem.push();
	this.Elem[i] = new Object();
	this.Elem[i].pagina = this.getCaminhoBase() +"/" + gModuloCorrente.pastaModulo+ "/Html/" + pagina;
	this.setRelacionamentoCarregado(ehRelacionamento);
}



function desempilha(){
	//retorna o valor do topo e desempilha o array
	if (!this.Elem.pop()){
		alert("Erro. Não existe mais tela a ser desempilhada.")
		return
	}
}


/*	Devido ao menu ser carregado antes do frameset Transacao, é precisar setar se pelo menos uma vez
	o menu foi clicado	*/
function getFSetTransacaoJahCarregado(){
	return this.bFSetTransacaoJahCarregado;
}
function setFSetTransacaoJahCarregado(valor){
	this.bFSetTransacaoJahCarregado = valor
	//alert("carregou fsettransa this.bFSetTransacaoJahCarregado=" +this.bFSetTransacaoJahCarregado)
}
function getAcoesJahCarregado(){
	return this.bAcoesJahCarregado;
}
function setAcoesJahCarregado(valor){
	this.bAcoesJahCarregado = valor
	//alert("setando......: this.bAcoesJahCarregado=" +this.bAcoesJahCarregado)
	//alert("carregou fsettransa this.bAcoesJahCarregado=" +this.bAcoesJahCarregado)
}


function getEhPrimeiraEnt(){
	return this.bEhPrimeiraEnt;
}

function setEhPrimeiraEnt(valor){
	this.bEhPrimeiraEnt = valor
	//alert("carregou fsettransa this.bFSetTransacaoJahCarregado=" +this.bFSetTransacaoJahCarregado)
}

function setCaminhoBase(caminhoBase){
	if (this.bMudouCaminhoBase){
		alert("Erro. Já foi definido um caminho base, ele não pode ser modificado novamente.")
		return
	}else{
		this.caminhoBase = caminhoBase;
		this.bMudouCaminhoBase=true;
	}
}

function getCaminhoBase(){
	return this.caminhoBase;
}

function empilhaJAux(strPagina,sRotinaRetorno,janelaPai,ehModal){
	//obs: o parâmetro strPagina refere-se ao nome reduzido da pagina. ex: "Objeto-Listar.jsp;jsessionid="+(new Date().getTime());
	
	var width, height;
/* INICIO da alteração feita por renato-diogo@procergs.rs.gov.br - 08/03/2004 */
	var top, left;
/* FINAL  da alteração feita por renato-diogo@procergs.rs.gov.br - 08/03/2004 */

	if (sRotinaRetorno!="" && sRotinaRetorno!=null){
		sRotinaRetorno = "&" + sRotinaRetorno;
	}else{
		sRotinaRetorno = "";
	}
	if (janelaPai==null){janelaPai = frameSetTransacao.Dados;}

	//retorna o último índice e empilha
	var i = this.Elem.push();
	this.Elem[i] = new Object();
	this.Elem[i].pagina = this.oNavegacao.getCaminhoBase()+ '/Html/FSetAuxiliar.html?' +this.oNavegacao.getCaminhoBase()+ '/' +gModuloCorrente.pastaModulo+'/Html/' +strPagina+sRotinaRetorno
	this.Elem[i].strPagina = strPagina
	this.Elem[i].rotinaRetorno = sRotinaRetorno;
	this.Elem[i].janelaPai = janelaPai;
	this.Elem[i].flagOcultoCarregado = oNavegacao.getFrameOcultoCarregado(); //guarda na pilha o estado do flag que indica se o frame oculto (compartilhado) está carregado ou não (problema de uma janela auxiliar com abas separadas por páginas).

	oNavegacao.setFrameOcultoCarregado(false) //seta como não carregado sempre que abrir uma janela auxiliar

	/*	Caso não seja passado parametro para o tamanho e a largura da janela auxiliar, pega o definido para o sistema*/
	if (this.largura!=null && this.largura > 0){
		width = this.largura
		this.largura = null
	}else{
		width = widthTelaAux
	}
	if (this.altura!=null && this.altura  > 0){
		height = this.altura
		this.altura = null 
	}else{
		height = heightTelaAux
	}

	//faz o carregamento
	self.name = "Dados"
	
	/*	
		Alteração feita em 03/02/2004

		O nome da variável janela precisa ter um diferencial (janela concatenado com indice da janela), pois quando aberta mais de 2 níveis de janela, a terceira passa a usar a mesma 
		instância de browser da segunda. Assim, quando é fechado a terceira, o usuário tem a impressão de todas são fechadas (a segunda e 
		a terceira instância)
		
		
	*/

//	alert("push........ pagina=="+this.Elem[i].pagina)
/* INICIO da alteração feita por renato-diogo@procergs.rs.gov.br - 08/03/2004 */
 	left = centerWidth(width);
 	top = centerHeight(height);
	eval('janela'+i+' = window.open("' +this.Elem[i].pagina+ '","janela'+i+'","width=' +width+ ',height=' +height+ ', top=' +top+ ', left=' +left+ ',scrollbars=no,hscroll=0,dependent=yes,toolbar=no")')
/* FINAL  da alteração feita por renato-diogo@procergs.rs.gov.br - 08/03/2004 */
	eval('janela'+i+'.opener = janelaPai.self');
//	alert("janela.opener.trataRetorno=="+janela.opener.trataRetorno+", janelaPai.self.trataRetorno=="+janelaPai.self.trataRetorno)
	eval('janela'+i+'.focus()');
	eval('this.Elem[i].janela = janela'+i); //armazena na pilha a instância da janela aberta atual
}


function desempilhaJAux(pagina){
	//parametro pagina no formato "Objeto-Lista.jsp;jsessionid="+(new Date().getTime());
	var i;
	var oJanelaAFechar = null; //janela que será fechada
	
	if (!pagina){
		alert("Erro. Deve-se especificar a janela a ser fechada. Verificar se a PRGerais está atualizada.")
	}
	//verifica se a pagina existe na pilha
	for (i=0; i<this.Elem.length && this.Elem[i].strPagina.toUpperCase()!=pagina.toUpperCase(); i++) {}

	if (this.Elem[i].strPagina.toUpperCase()==pagina.toUpperCase()){
		//existe a pagina na pilha
		oJanelaAFechar = this.Elem[i];
		nJan = this.Elem.length;
		for (var j=nJan-1; j>=i; j--){
			this.Elem[j].janela.close(); //fecha as janelas filhas caso existam
			this.Elem.pop(); //destrói janela do array
		}
	}else{
		alert("Erro. a página solicitada para ser fechada não existe na pilha de navegação");
		return
	}
	
	oJanelaAFechar.janelaPai.focus(); //a partir da janela que será fechada, seta o foco na sua janela-pai
	oNavegacao.setFrameOcultoCarregado(oJanelaAFechar.janelaPai.flagOcultoCarregado); //retorna o estado (onde se encontrava antes de ter empilhado)
}
