window.onerror = null;

var menuTimer = null;
var menuTimerScroll = null;

var IE4 = (document.all) ? 1:0;
var NS4 = (document.layers) ? 1:0;
var DOM = (document.getElementById) ? 1:0;
/* ---  MENU LISTA --- */
// bg selecionado
var BGSelecionado = "#FFFFFF";
// bg nao selecionado
var BGNormal = "#EBEBEB";

// imagem da seta do menu selecionado
var imgSelecionada = "imgSetaItemMnu2.gif";
// imagem da seta do menu não selecionado
var imgNormal = "imgSetaItemMnu.gif";	

// imagem bullet selecionado
var bulSelecionada = "imgBulletMnuOn.gif";
// imagem bullet nao selecionado
var bulNormal = "imgBulletMnuOff.gif";	

//Diretório das Imagens
var diretorioImagem;
var diretorioInclude;
var codigoSessao;
var menuPreview;
var BoxSugestao;
var Lancamentos;

function setDiretorioImagem(valor){
	diretorioImagem = valor;
}
function setDiretorioInclude(valor){
	diretorioInclude = valor;
}
function setCodigoSessao(valor){
	codigoSessao = valor;
}
function setMenuPreview(valor){
	menuPreview = valor;
}

function setBoxSugestao(valor){
	BoxSugestao = valor;
}

function setIndLancamento(valor){
	Lancamentos = valor;
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function SubstituiAcentos(s) { // Substitui caracteres acetuados
	var i;   									  
	var c;
	var Palavra = "";
	
	for (i=0;i<s.length;i++) {	
		c = s.charAt(i); 
	
	 	if ((c == "á") || (c == "à") || (c == "ã") || (c == "â") || 
	 		(c == "Á") || (c == "À") || (c == "Ã") || (c == "Â"))
		{
			c = "A"
		}
		if ((c == "é") || (c == "è") || (c == "ê") || 
		 	(c == "É") || (c == "È") || (c == "Ê"))
		{
			c = "E"
		}
		if ((c == "í") || (c == "ì") || (c == "î") || 
		 	(c == "Í") || (c == "Ì") || (c == "Î"))
		{
			c = "I"
		}
		if ((c == "ó") || (c == "ò") || (c == "õ") || (c == "ô") || 
	 		(c == "Ó") || (c == "Ò") || (c == "Õ") || (c == "Ô"))
		{
			c = "O"
		}
		if ((c == "ú") || (c == "ù") || (c == "û") || (c == "ü") ||
		 	(c == "Ú") || (c == "Ù") || (c == "Û") || (c == "Ü"))
		{
			c = "U"
		}
		if ((c == "ç") || (c == "Ç"))
		{
			c = "C"
		}
	
		Palavra = Palavra + c.toUpperCase();
	}						
	return Palavra;
}

function Pesquisa(diretorio, pStrCodSessao) {
	var strconvertida = SubstituiAcentos(document.form.pStrPesquisa.value);
	{
		url = diretorio + "ZsaPesquisaAvancada.cfm?pStrCodSessao=" + pStrCodSessao + "&pStrPesquisa=" + escape(strconvertida)
		window.parent.fPrincipal.location.href=url;
		strconvertida = "";	
		return false;
	}
}

function Pesquisartecla(diretorio, pStrCodSessao) {
	if (navigator.userAgent.indexOf("MSIE")!=-1)
		var tecla = event.keyCode;
	else if(navigator.userAgent.indexOf("Netscape") || navigator.userAgent.indexOf("Firefox")!=-1)
		var tecla = e.which;

	if (!((tecla != 34 && tecla != 39) || (tecla == 0))) { // se não for " ou '
    	if (tecla != 8) // backspace
			if (navigator.userAgent.indexOf("MSIE")!=-1)
				event.keyCode = 0;
			else if(navigator.userAgent.indexOf("Netscape") || navigator.userAgent.indexOf("Firefox")!=-1)
				return false;
    }

	var strconvertida = SubstituiAcentos(document.form.pStrPesquisa.value);
	{
		netscape = "";
		ver = navigator.appVersion; len = ver.length;
	    for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
		netscape = (ver.charAt(iln+1).toUpperCase() != "C");	
		k = (netscape) ? onkeypress.which : event.keyCode;
		if (k == 13) { // enter key pressed
			url = diretorio + "ZsaPesquisaAvancada.cfm?pStrCodSessao=" + pStrCodSessao + "&pStrPesquisa=" + escape(strconvertida)
			window.parent.fPrincipal.location.href=url;
			strconvertida = "";	
			return true;
		}
	}
}

//INÍCIO - Scripts Topo
function ChamarPaginaTopo(url){
	LimparBotoes();
	LimparMarcas();
	
	opcaoAnterior = 0;
				
	top.fPrincipal.location.href = url;
}

function SelMnuTopo(id, imagemclicado) {
	if (document.images) {
		LimparMarcas();
		
		var botao = id + "BTN";
		var imgOn = diretorioImagem + imagemclicado;
						
		if(document.images[botao].src == imgOn && parent.fPrincipal.document.getElementById("divMenu").style.visibility == 'visible'){
			parent.fPrincipal.document.getElementById("divMenu").style.visibility = 'hidden';

			setTimeout("DesativarBotaoAnterior(" + opcaoAnterior + ")", 10);
		}
		else {
			setTimeout("DesativarBotaoAnterior(" + opcaoAnterior + ")", 10);
			
			setTimeout("SelecionarBotao('" + id + "', '" + imagemclicado + "')", 50);
			
			if (opcaoAnterior != id){
				parent.fPrincipal.document.getElementById("iFrmMenu").src = diretorioInclude + "iZsaIfrmMenu.cfm?pIntCodMenuNivel1=" + id + "&pStrCodSessao=" + codigoSessao + "&pIntMenuPreview=" + menuPreview +"&lStrBoxSugestao=" + BoxSugestao;
				opcaoAnterior = id;	
			}
			parent.fPrincipal.document.getElementById("divMenu").style.visibility = 'visible';
			parent.fPrincipal.document.getElementById("divMenu").style.top = parent.fPrincipal.document.body.scrollTop;
		}
	}
}

function SelMnuTopoMigalha(menuNivel0, menuNivel1, menuNivel2, imagemclicado) {

	if (document.images) {
		var botao = menuNivel0 + "BTN";
		var imgOn = diretorioImagem + imagemclicado;		

		if(document.images[botao].src == imgOn && parent.fPrincipal.document.getElementById("divMenu").style.visibility == 'visible'){
			parent.fPrincipal.document.getElementById("divMenu").style.visibility = 'hidden';

		}
		else {

			setTimeout("SelecionarBotao('" + menuNivel0 + "', '" + imagemclicado + "')", 10);
			parent.fPrincipal.document.getElementById("iFrmMenu").style.height=0;

			if (opcaoAnterior != menuNivel0){
				parent.fPrincipal.document.getElementById("iFrmMenu").src = diretorioInclude + "iZsaIfrmMenu.cfm?pIntCodMenuNivel1=" + menuNivel0 + "&pIntCodMenuNivel2=" + menuNivel1 + "&pIntCodMenuNivel3=" + menuNivel2 + "&pStrCodSessao=" + codigoSessao + "&pIntMenuPreview=" + menuPreview+"&lStrBoxSugestao=" + BoxSugestao+"&pIndLancamento=0";
				top.fMenuInVisivel.opcaoAnterior = menuNivel0;	
			}
		}
			setTimeout('MostrarMenu()', 300);
	}
}

function MostrarMenu(){
	parent.fPrincipal.document.getElementById("divMenu").style.visibility = 'visible';
}

function SelecionarBotao(opcao, imagemclicado){
	var botao = opcao + "BTN";
	document.images[botao].src = diretorioImagem + imagemclicado;
	
	
	var marca = opcao + "MARCA";
	var imgMarca
	
	if (opcao == "9678"){
		imgMarca = "lytMarcaBrd" + opcao + ".gif";
		document.images[marca].src = diretorioImagem + "lytMarcaBrd.gif";}
	else{
		imgMarca = "lytMarca" + opcao + ".gif";
		document.images[marca].src = diretorioImagem + "lytMarca.gif";}
}

function DesativarBotaoAnterior(opcaoAnterior){
	if (opcaoAnterior != null)
		document.images[opcaoAnterior + "BTN"].src = eval("document.frmMenu.hidImagem" + opcaoAnterior).value;

}

function LimparBotoes(){
	var lArrCodigos = document.frmMenu.hidCodigosMenu.value.split(",");
	
	for (var i=0; i < lArrCodigos.length; i++){
		document.images[lArrCodigos[i] + "BTN"].src = eval("document.frmMenu.hidImagem" + lArrCodigos[i]).value;
	}
}

function LimparMarcas(){
	var lArrCodigos = document.frmMenu.hidCodigosMenu.value.split(",");
	
	for (var i=0; i < lArrCodigos.length; i++){
		document.images[lArrCodigos[i] + "MARCA"].src = diretorioImagem + "dot.gif";
	}		
}

//FIM - Scripts Topo		

//INÍCIO - Scripts Colunas
function ChamarPagina(url){
	top.fMenuInVisivel.LimparBotoes();
	top.fMenuInVisivel.LimparMarcas();
	
	top.fPrincipal.document.getElementById("divMenu").style.visibility = 'hidden';
	
	top.fMenuInVisivel.opcaoAnterior = 0;
				
	top.fPrincipal.location.href = url;
}


function DesabilitarDestaque(){
	var objDestaque = document.getElementById("colunaDestaque");
	var objLinha = document.getElementById("colunaLinha");
	var objIFrame1 = document.getElementById("iFrmMenuSub1");
	var objIFrame2 = document.getElementById("iFrmMenuSub2");

	if (objDestaque != null && objDestaque.style.visibility != 'hidden') {
		objDestaque.style.display = 'none';
		objLinha.style.display = '';
		
		objDestaque.innerHTML = "";
		
		objIFrame1.style.width = 150;
		objIFrame2.style.width = 150;
	}
}

function SelMnuMigalha(menuNivel1, menuNivel2, menuNivel3) {
	DesabilitarDestaque()

	if (opcaoAnterior != null){
		td1 = opcaoAnterior + "TD";
 		img1 = opcaoAnterior + "IMG";
		bullet1 = opcaoAnterior + "BUL";

		if (DOM){
			document.getElementById(td1).bgColor = BGNormal;		
		}
		else if (IE4){
			document.all(td1).bgColor = BGNormal;	
		}
		document.images[bullet1].src = diretorioImagem + bulNormal;
		document.images[img1].src = diretorioImagem + imgNormal;
	}
	opcaoAnterior = menuNivel2;
	document.getElementById("iFrmMenuSub1").style.visibility = "visible";
	document.getElementById("iFrmMenuSub2").style.visibility = "visible";

	document.getElementById("iFrmMenuSub1").src = diretorioInclude + "iZsaIfrmMenuSub1.cfm?pIntCodMenuNivel1=" + menuNivel1 + "&pIntCodMenuNivel2=" + menuNivel2 + "&pIntCodMenuNivel3=" + menuNivel3 + "&pStrCodSessao=" + codigoSessao + "&pIntMenuPreview=" + menuPreview+"&lStrBoxSugestao=" + BoxSugestao+"&pIndLancamento="+Lancamentos;
	document.getElementById("iFrmMenuSub2").src = diretorioInclude + "iZsaIfrmMenuSub2.cfm?pIntCodMenuNivel1=" + menuNivel1 + "&pIntCodMenuNivel2=" + menuNivel2 + "&pIntCodMenuNivel3=" + menuNivel3 + "&pStrCodSessao=" + codigoSessao + "&pIntMenuPreview=" + menuPreview+"&lStrBoxSugestao=" + BoxSugestao+"&pIndLancamento="+Lancamentos;

	setTimeout("SelecionarOpcao(" + menuNivel2 + ")", 1);
}

function SelMnuColuna1(menuNivel1, menuNivel2) {
	DesabilitarDestaque()
	
	if (opcaoAnterior != null){
		td1 = opcaoAnterior + "TD";
 		img1 = opcaoAnterior + "IMG";
		bullet1 = opcaoAnterior + "BUL";

		if (DOM){
			document.getElementById(td1).bgColor = BGNormal;		
		}
		else if (IE4){
			document.all(td1).bgColor = BGNormal;	
		}
		document.images[bullet1].src = diretorioImagem + bulNormal;
		document.images[img1].src = diretorioImagem + imgNormal;
	}
	opcaoAnterior = menuNivel2;
	document.getElementById("iFrmMenuSub1").style.visibility = "visible";
	document.getElementById("iFrmMenuSub2").style.visibility = "visible";

	document.getElementById("iFrmMenuSub1").src = diretorioInclude + "iZsaIfrmMenuSub1.cfm?pIntCodMenuNivel1=" + menuNivel1 + "&pIntCodMenuNivel2=" + menuNivel2 + "&pStrCodSessao=" + codigoSessao + "&pIntMenuPreview=" + menuPreview+"&lStrBoxSugestao=" + BoxSugestao+"&pIndLancamento="+Lancamentos;
	document.getElementById("iFrmMenuSub2").src = diretorioInclude + "iZsaIfrmMenuSub2.cfm?pIntCodMenuNivel1=" + menuNivel1 + "&pIntCodMenuNivel2=" + menuNivel2 + "&pStrCodSessao=" + codigoSessao + "&pIntMenuPreview=" + menuPreview+"&lStrBoxSugestao=" + BoxSugestao+"&pIndLancamento="+Lancamentos;
	
	setTimeout("SelecionarOpcao(" + menuNivel2 + ")", 10);
	
	//parent.document.getElementById("iFrmMenu").style.height = document.body.scrollHeight + 5;
}

function SelMnuColuna2(menuNivel1, menuNivel2, menuNivel3) {
	if (opcaoAnterior != null){
		td1 = opcaoAnterior + "TD";
 		img1 = opcaoAnterior + "IMG";
		bullet1 = opcaoAnterior + "BUL";

		if (DOM){
			document.getElementById(td1).bgColor = BGNormal;		
		}
		else if (IE4){
			document.all(td1).bgColor = BGNormal;	
		}
		document.images[bullet1].src = diretorioImagem + bulNormal;
		document.images[img1].src = diretorioImagem + imgNormal;
	}
	opcaoAnterior = menuNivel3;
	
	parent.document.getElementById("iFrmMenuSub2").style.visibility = "visible";

	parent.document.getElementById("iFrmMenuSub2").src = diretorioInclude + "iZsaIfrmMenuSub2.cfm?pIntCodMenuNivel1=" + menuNivel1 + "&pIntCodMenuNivel2=" + menuNivel2 + "&pIntCodMenuNivel3=" + menuNivel3 + "&pStrCodSessao=" + codigoSessao + "&pIntMenuPreview=" + menuPreview+"&lStrBoxSugestao=" + BoxSugestao+"&pIndLancamento="+Lancamentos;
	
	setTimeout("SelecionarOpcao(" + menuNivel3 + ")", 1);

	parent.document.getElementById('iFrmMenuSub1').style.height = document.body.scrollHeight + 5;
	parent.parent.document.getElementById("iFrmMenu").style.height = parent.document.body.scrollHeight + 5;
}

function SelecionarOpcao(menu){
	td = menu + "TD";
		img = menu + "IMG";
	bullet = menu + "BUL";
	
	var objBG;
	if (DOM){
		objBG = document.getElementById(td);	
	}
	else if (IE4){
		objBG = document.all(td);
	}
	
	if (objBG.filters){
		objBG.style.filter = "blendTrans(duration=.7)";
		objBG.filters.BlendTrans.Apply();
		objBG.filters.BlendTrans.Play();
	}
	objBG.bgColor = BGSelecionado;	
	
	document.images[bullet].src = diretorioImagem + bulSelecionada;
	document.images[img].src = diretorioImagem + imgSelecionada;	
}

function AjeitarIFramesColuna1(menuNivel1, menuNivel2, menuNivel3){
	parent.document.getElementById("iFrmMenu").style.height = document.body.scrollHeight;
	

	if (menuNivel2 != 0)
		SelMnuMigalha(menuNivel1, menuNivel2, menuNivel3);		
}

function AjeitarIFramesColuna2(menuNivel1, menuNivel2, menuNivel3){
	if (menuNivel3 != 0)
		SelMnuColuna2(menuNivel1, menuNivel2, menuNivel3);		
/*
	parent.document.getElementById("iFrmMenuSub1").style.height = document.body.scrollHeight;
	parent.parent.document.getElementById("iFrmMenu").style.height = parent.document.body.scrollHeight;


	if (parseInt(parent.document.getElementById("iFrmMenuSub1").style.height) > parseInt(parent.document.getElementById("iFrmMenuSub2").style.height)){
		parent.document.getElementById("iFrmMenuSub2").style.height = parent.document.getElementById("iFrmMenuSub1").style.height;
	}
	else if (parseInt(parent.document.getElementById("iFrmMenuSub1").style.height) < parseInt(parent.document.getElementById("iFrmMenuSub2").style.height)){
		parent.document.getElementById("iFrmMenuSub2").style.height =document.body.scrollHeight;
		
		var valIfrm = 20
		var tam = parseInt(parent.document.body.scrollHeight)
		var diferenca
		
		diferenca = tam - valIfrm
		parent.document.getElementById("iFrmMenuSub2").style.height = diferenca;
	}				
*/
	parent.document.getElementById("iFrmMenuSub1").style.height = document.body.scrollHeight;
	
	parent.parent.document.getElementById("iFrmMenu").style.height = parent.document.body.scrollHeight;
	
	parent.parent.document.getElementById("divMenu").style.height = parent.parent.document.getElementById("iFrmMenu").style.height;

}

function AjeitarIFramesColuna3(){
	/*
	if (parseInt(document.body.scrollHeight) > parseInt(parent.document.getElementById("iFrmMenuSub2").style.height)){
		parent.document.getElementById("iFrmMenuSub2").style.height = document.body.scrollHeight;
		if (parseInt(parent.parent.document.getElementById("iFrmMenu").style.height) > parseInt(parent.document.getElementById("iFrmMenuSub2").style.height)){
			parent.document.getElementById("iFrmMenuSub2").style.height = parent.document.body.scrollHeight;
		}
	}
	if (parseInt(parent.parent.document.getElementById("iFrmMenu").style.height) < document.body.scrollHeight){
		parent.parent.document.getElementById("iFrmMenu").style.height = document.body.scrollHeight;
	}*/
	
	/*parent.document.getElementById("iFrmMenuSub2").style.height = document.body.scrollHeight;*/
	parent.parent.document.getElementById("iFrmMenu").style.height = parent.document.body.scrollHeight;
	
	parent.document.getElementById("iFrmMenuSub2").style.height = parent.document.body.scrollHeight -30;
	
	parent.parent.document.getElementById("divMenu").style.height = parent.parent.document.getElementById("iFrmMenu").style.height;
	
}

//FIM - Scripts Colunas

//INÍCIO - Scripts Frame Principal

function CarregaMenuLayer(){
	if (top.fMenuInVisivel && top.fPrincipal.document.getElementById("divMenu").style.visibility == 'hidden'){
		top.fMenuInVisivel.LimparBotoes();
		top.fMenuInVisivel.LimparMarcas();
		
		top.fMenuInVisivel.opcaoAnterior = null;
	}

	menuTimerScroll = setTimeout("verificarPosicaoMenu()", 100);
	//top.fPrincipal.document.body.onscroll = moverMenu;
}


function escondeMenu(){
	//if(navigator.userAgent.indexOf("MSIE")!=-1){
		menuTimer = setTimeout("fecharFrame()", 50)
	//}
}

function fecharFrame(){
	if (menuTimer != null){
		top.fPrincipal.document.getElementById("divMenu").style.visibility = 'hidden';
		top.fMenuInVisivel.LimparBotoes();
		top.fMenuInVisivel.LimparMarcas();
	}
}

function mantemMenu(){
	//if(navigator.userAgent.indexOf("MSIE")!=-1){
		if (menuTimer != null){
			clearTimeout(menuTimer);
			menuTimer = null;
		}	
	//}
}

function moverMenu(){
	if (top.fPrincipal.document.getElementById("divMenu").style.visibility == 'visible'){
		parent.fPrincipal.document.getElementById("divMenu").style.top = parent.fPrincipal.document.body.scrollTop;
	}
}

function verificarPosicaoMenu(){
	if (parent.fPrincipal.document.getElementById("divMenu").style.top != parent.fPrincipal.document.body.scrollTop){
		moverMenu();
	}
	
	menuTimerScroll = setTimeout("verificarPosicaoMenu()", 100);
}


function MudarClassLink(linkMenu){
	var obj = document.getElementsByTagName("a");
	
	for (var i=0; i < obj.length; i++){
		//alert(obj[i].id);
		if (obj[i].id == 'linkMenu'){
			obj[i].className = 'itemMenu';
		}
	}
	linkMenu.className = 'itemMenuSelecionado';
}

//FIM - Scripts Frame Principal