// MENU PRINCIPAL
/*
startList = function() {
    if (document.all&&document.getElementById) {
        var navRoot = document.getElementById("fundo_menu_principal");
        var divPrinc = navRoot.getElementsByTagName('div');
        for (i=0; i< divPrinc.length; i++) {
            //node = navRoot.childNodes[i];
            if (divPrinc[i].className == 'nivel-2') {
                divPrinc[i].onmouseover=function() {
                    abreConteudo(this);
	                this.className+="over";
                    
                }
                divPrinc[i].onmouseout=function() {
	                fechaConteudo(this);
	                this.className=this.className.replace("over", "");
	                
                }
            }
        }
    }
}
window.onload = startList;*/

function clickPage(){
	if (cache != null){
		cache[1].style.display = "none";
	}
}
document.onclick = function(){eval(clickPage());}
//window.onclick = function(){eval(clickPage());}

var intervalo;
var cache = null;
var agr;

function abreConteudo(div){
	
	/*if (div.className == 'nivel-1'){
		if (cache != null){
			cache[1].style.display = "none";
		}
	}*/
	if (div.className == 'nivel-2'/* || div.className == 'nivel-2over'*/){
	
		//div.className += "over";
			
		/*if(intervalo){
			clearTimeout(intervalo);
			intervalo = null;
		}*/
		
		if(intervalo == null){
			
			
			
			
			if (!intervalo){
				agr = div.getElementsByTagName('div');
				//agr[1].style.display = "block";
				intervalo = window.setTimeout('AF(agr, "block")',300);
			}
		}
	}
}

function fechaConteudo(div){
	if (div.className == 'nivel-2'/* || div.className == 'nivel-2over'*/){
		//div.className = div.className.replace("over", "");
		
		clearTimeout(intervalo);
		intervalo = null;
		/*if(!intervalo){
			agr = div.getElementsByTagName('div');
			intervalo = window.setTimeout('AF(agr[1],"none")', 1000);
		}*/
	}
}

//intervalo = null;
function AF (elemento, estado){
	if (cache != null){
		//agr = cache.getElementsByTagName('div');
		cache[1].style.display = "none";
	}
	cache = elemento;
	//agr = elemento.getElementsByTagName('div');
	elemento[1].style.display = estado;
	clearTimeout(intervalo);
	intervalo = null;
}


/*var intervalo;
var cache = null;
var agr;
function abreConteudo(div){
	if (div.className == 'nivel-2'){
		
		if(intervalo){
			clearTimeout(intervalo);
			intervalo = null;
		}
		
		if(intervalo == null){
			if (cache != null){
				agr = cache.getElementsByTagName('div');
				agr[1].style.display = "none";
			}
			cache = div;
			agr = div.getElementsByTagName('div');
			
			if (!intervalo){
				agr[1].style.display = "block";
			}
		}
	}
}

function fechaConteudo(div){
	if (div.className == 'nivel-2'){
		
		if(!intervalo){
			agr = div.getElementsByTagName('div');
			intervalo = window.setTimeout('AF(agr[1],"none")', 1000);
		}
	}
}

intervalo = null;
function AF (elemento, estado){
	elemento.style.display = estado;
	clearTimeout(intervalo);
	intervalo = null;
}*/

//########
var linkCache = '';
var validaOnclick = true;

function linkMenu(linkDestinoO){

	var linkDestino = linkDestinoO

	if (linkCache == linkDestino){
		validaOnclick = true;
	}
	if (validaOnclick){

		
		
		var url = window.location.href;
		var nohttp = url.split('//')[1];
		var hostPort = nohttp.split('/')[0];
		
		
		//var urlOrigem = nohttp.substring(nohttp.indexOf('/'),nohttp.length);			
		// Redirecionar Link do Menu
		// Relacoes com Investidores.
		
		validaOnclick = false;
		
		if (linkDestino == '/live/institucional/pagina-inicial/credito-consignado.html' && linkCache != '/live/institucional/pagina-inicial.html' ){
			window.open('http://paravoce.bancopine.com.br/live/para-voce/pagina-inicial.html');
			//window.location.href = 'http://' + hostPort + urlOrigem;
			//validaOnclick = true;
			window.location.reload();
		
		}else if (linkDestino == '/live/institucional/pagina-inicial/relacoes-com-investidores.html' && linkCache != '/live/institucional/pagina-inicial.html'){
			window.open('http://ri.bancopine.com.br/');
			//window.location.href = 'http://' + hostPort + urlOrigem;
			//validaOnclick = true;
			window.location.reload();
			
					
		/*}else if (linkDestino == '/live/institucional/pagina-inicial/empresas/seja-nosso-cliente.html' || linkDestino == '/live/institucional/pagina-inicial/investimentos/seja-nosso-cliente.html'){
			window.location.href = 'http://' + hostPort + '/live/institucional/pagina-inicial/atendimento/seja-nosso-cliente.html';
		}else if (linkDestino == '/live/institucional/pagina-inicial/empresas/fale-conosco.html' || linkDestino == '/live/institucional/pagina-inicial/investimentos/fale-conosco.html'){
			window.location.href = 'http://' + hostPort + '/live/institucional/pagina-inicial/atendimento/fale-conosco.html';
		*/
		}else if (linkDestino == '/live/institucional/pagina-inicial/institucional.html'){
			window.location.href = 'http://' + hostPort + '/live/institucional/pagina-inicial/institucional/perfil.html';
		}else if (linkDestino == '/live/institucional/pagina-inicial/empresas.html'){
			window.location.href = 'http://' + hostPort + '/live/institucional/pagina-inicial/empresas/produtos.html';
		}else if (linkDestino == '/live/institucional/pagina-inicial/investimentos.html'){
			window.location.href = 'http://' + hostPort + '/live/institucional/pagina-inicial/investimentos/produtos.html';
		}else if (linkDestino == '/live/institucional/pagina-inicial/atendimento.html'){
			window.location.href = 'http://' + hostPort + '/live/institucional/pagina-inicial/atendimento/fale-conosco.html';
		}else if (linkDestino == '/live/institucional/pagina-inicial/recursos-humanos.html'){
			window.location.href = 'http://' + hostPort + '/live/institucional/pagina-inicial/recursos-humanos/praticas-de-rh.html';
		}else if (linkDestino == '/live/institucional/pagina-inicial/analise-economica.html'){
			window.location.href = 'http://' + hostPort + '/live/institucional/pagina-inicial/institucional/pine-news/analise-economica.html';
			
		}else if (linkDestino == '/live/institucional/pagina-inicial/institucional/rating.html'){
			window.location.href = 'http://ri.bancopine.com.br/bancopine/web/conteudo_pt.asp?idioma=0&amp;tipo=932&amp;submenu=3&amp;img=903&amp;conta=28';
			
		//Site ingles
		}else if (linkDestino == '/live/institucional-ing/home/investor-relations.html'){
			window.open('http://ir.bancopine.com.br/bancopine/web/default_en.asp?idioma=1&conta=44');
			window.location.reload();
			
		}else if (linkDestino == '/live/institucional-ing/home/investments.html'){
			window.location.href = 'http://' + hostPort + '/live/institucional-ing/home/investments/products.html';
		}else if (linkDestino == '/live/institucional-ing/home/institutional.html'){
			window.location.href = 'http://' + hostPort + '/live/institucional-ing/home/institutional/profile.html';	
		}else if (linkDestino == '/live/institucional-ing/home/companies.html'){
			window.location.href = 'http://' + hostPort + '/live/institucional-ing/home/companies/products.html';	
		}else if (linkDestino == '/live/institucional-ing/home/attendance.html'){
			window.location.href = 'http://' + hostPort + '/live/institucional-ing/home/attendance/contact-us.html';	
			
		}else if (linkCache == '/live/institucional/pagina-inicial/credito-consignado.html' || linkCache == '/live/institucional/pagina-inicial/relacoes-com-investidores.html' || linkCache == '/live/institucional/pagina-inicial.html' ){
			validaOnclick = true;
			//alert('foi');
			window.location.reload();

			
		//}else if (linkCache == '/live/institucional/pagina-inicial/credito-consignado.html' && linkDestino == '/live/institucional/pagina-inicial.html'){
			
		} else {
			window.location.href = 'http://' + hostPort + linkDestino;
		}
		
		linkCache = linkDestino;
	}/*else if ((linkDestino == '/live/institucional/pagina-inicial.html' || linkDestino == '/live/institucional-ing/home.html') && 
		(linkCache == '/live/institucional/pagina-inicial/relacoes-com-investidores.html' || linkCache == '/live/institucional/pagina-inicial/credito-consignado.html')){
			validaOnclick = true;
	}*/
}


// FIM MENU PRINCIPAL

// MENU INTERNO ###################


var nivel = 0;
var menuAbert = null;
var menuAvertDiv =null;

function processMenuInterno(){

	var menuContainer = document.getElementById('fundo_menu_interno');
	
	//primeiro esconde tudo
	if (menuContainer != null){
		var divs = menuContainer.getElementsByTagName('div');
		var path = window.location.pathname;
		var links = menuContainer.getElementsByTagName('a');
		var theNode = null;
		
		theNode = getMenuNode(path,links);
				
		if(theNode==null){
			var parts=path.split('/');
			var lastPart=parts[parts.length-1];
			var idx=path.indexOf(lastPart);
			var upperPath=path.substring(0,idx-1)+'.html';
			theNode = getMenuNode(upperPath,links);
		}
		
		/*### Para trazer o menu de Institucional na pagina de detalhes da news ###*/
		if (path == '/live/institucional-ing/home/institutional/pine-news/news.html'){
			theNode = getMenuNode('/live/institucional-ing/home/institutional.html',links);
		}
		
		/* ### URL Plugin de Indices  ###*/
		if (path.indexOf('/institucional/pagina-inicial/investimentos/indices.html')>0){
			theNode = getMenuNode('/live/institucional/pagina-inicial/investimentos/indices.html',links);
		}
		if (path.indexOf('/institucional-ing/home/investments/index.html')>0){
			theNode = getMenuNode('/live/institucional-ing/home/investments/index.html',links);
		}
		
		/* ### URL Plugin de Seja Nosso Cliente  ###*/
		if (path.indexOf('/institucional/pagina-inicial/atendimento/seja-nosso-cliente.html')>0){
			theNode = getMenuNode('/live/institucional/pagina-inicial/atendimento/seja-nosso-cliente.html',links);
		}
		
		if(theNode==null){
			divs[0].style.display = 'none';
			return;
		}
		
		menuContainer.innerHTML = theNode.innerHTML;
		theNode = getMenuNode(path,links);
		divs = menuContainer.getElementsByTagName('div');
				
		/* Funcao para montar o menu 'show' para menu fechado e 'hide' para aberto */
		menuSet(menuContainer,'hide');
		/* Funcao para fechar os divs de 3 nivel */
		//fechaAgr3(divs);
		
		
		/*if (nivel == '2'){
			menuSet(menuContainer,'show');
			fechaAgr3(divs);
			
		} else if (nivel == '3'){
			menuSet(menuContainer,'show');
			fechaAgr3(divs);
			
			menuAvertDiv = menuAbert.getElementsByTagName('div');
			menuAvertDiv[1].style.display='';
			menuSet(menuAbert,'hide');
			
		} else */
		if (nivel == '4'){
			
			menuAvertDiv = menuAbert.getElementsByTagName('div');
			if(menuAvertDiv.length > 1 && menuAvertDiv[1]){
				menuAvertDiv[1].style.display='';
				menuSet(menuAbert,'hide');
			}
			//menuSetAberto(menuAbert);
		
		}
	}
}

function getMenuNode(path,links){
	var theNode=null;
	var menuN3 = null;
    
	for(var i=0;i<links.length;i++){
		if(links[i].href.indexOf(path)>-1 && links[i].parentNode.id.indexOf('div-')>-1){
			if(links[i].parentNode.className=='nivel-2'){
				theNode=links[i].parentNode;
				//nivel = '2';
			}	
			if(links[i].parentNode.className=='nivel-3'){
				theNode=links[i].parentNode.parentNode.parentNode;
				links[i].style.cssText = 'text-decoration:underline; font-weight:bold; color:#90182b;';
				//nivel = '2';
				
				menuN3 = links[i].parentNode.getElementsByTagName('div');
				menuAbert = links[i].parentNode;
				
				for(var x=0; x<menuN3.length; x++){
					if(menuN3[x].className=='nivel-4'){
						nivel = '4';
					}
				}
			}	
            if(links[i].parentNode.className=='nivel-4'){
				theNode=links[i].parentNode.parentNode.parentNode.parentNode.parentNode;
				links[i].style.cssText = 'text-decoration:underline; font-weight:bold; color:#90182b;';
				menuAbert = links[i].parentNode.parentNode.parentNode;
				nivel = '4';
			}
		}
	}
	return theNode;
}

/*function menuSetAberto(theNodeAberto){
	
	try{
		var linkImg = theNodeAberto.childNodes[1].getElementsByTagName('a');
	}catch(e){
		alert('aqui');
	}
	
	try{
		linkImg[0].setAttribute("name","hide");
	}catch(e){
		alert('aqui2');
	}
	
	try{
		var imgBto = linkImg[0].getElementsByTagName('img');
		imgBto[0].setAttribute("src","/live/images/0fdfa42c68b043799af723eff6cb1dfc.gif");
		imgBto[0].setAttribute("width","9");
		imgBto[0].setAttribute("height","15");
	}catch(e){
		alert('aqui3');
	}
			
}*/

function  menuSet(theNode,estado){
	
	var segNode = theNode.getElementsByTagName('div');
	var par = null;
	//var n3Node = null; 
	//var st = null;
	var linkB = null;

	for(var x=0; x < segNode.length; x++){
		if (segNode[x].className.indexOf('nivel-4')>-1 ){ /*&& par == null*/
					
			par = segNode[x].parentNode.parentNode.getElementsByTagName('div');
			
			//var divF = document.createElement("div");
			var linkAg = document.createElement("a");
			var atribImg = document.createElement("img");

			
			if (estado == 'show'){
				linkAg.setAttribute("name","show");
				atribImg.setAttribute("src","/live/images/b06605ab67c348e0abd2a9e12a83975c.jpg");
				atribImg.setAttribute("width","9");
				atribImg.setAttribute("height","9");
			}
			else if (estado == 'hide'){
				par[0].innerHTML = ''
				linkAg.setAttribute("name","hide");
				atribImg.setAttribute("src","/live/images/0fdfa42c68b043799af723eff6cb1dfc.gif");
				atribImg.setAttribute("width","9");
				atribImg.setAttribute("height","15");
			}

			linkAg.setAttribute("id","menu_interno_hide");
			
			linkAg.onclick = function(){ eval(hideMenuSet(this)); }
			//linkAg.setAttribute("onclick","menuSet(this);");
			
			linkAg.appendChild(atribImg);
			//divF.appendChild(linkAg);
			
						
			if (par[0].innerHTML == ''){
			
				par[0].appendChild(linkAg);
			}
				
			
			
			
			
			/*linkAg.setAttribute("id","menu_interno_hide");
			linkAg.appendChild(atribImg);
			divF.appendChild(linkAg);
			par[0].innerHTML = divF.innerHTML;
			linkB = par[0].getElementsByTagName('a');
			linkB[0].onclick = function(){ eval(hideMenuSet(this)); }
			*/
		}
	}
			

	/*		
	for(var i=0; i<segNode.length; i++){

		if(segNode[i].className.indexOf('nivel-3')>-1){
			n3Node = segNode[i].getElementsByTagName('div');
			
			for(var x=0; x < n3Node.length; x++){
				if (n3Node[x].className.indexOf('nivel-4')>-1){
					st = true;
				}
			}

			if (st == true){
				
				var par = segNode[i].getElementsByTagName('div');
				//var idagr = par.item(5).id;
				//var idagr = par[1].id;

				var linkAg = document.createElement("a");
				var atribImg = document.createElement("img");

				if (estado == 'show'){
					linkAg.setAttribute("name","show");
					atribImg.setAttribute("src","/live/images/b06605ab67c348e0abd2a9e12a83975c.jpg");
				}
				else if (estado == 'hide'){
					linkAg.setAttribute("name","hide");
					atribImg.setAttribute("src","/live/images/49a9e5bfc36f4d739fa7eec59a28f677.jpg");
				}

				linkAg.setAttribute("id","menu_interno_hide");
				linkAg.onclick = function(){ eval(hideMenuSet(this)); }
				
				atribImg.setAttribute("width","9");
				atribImg.setAttribute("height","9");

				linkAg.appendChild(atribImg);
				par[0].appendChild(linkAg);
			}
			st = false;
		}
	}*/
}

function fechaAgr3(divs){
	
	for(var i=0;i<divs.length;i++){
		if(divs[i].className=='clagr-3'){
			divs[i].style.display='none';
		}
	}
}

function hideMenuSet(botao){

	var no = botao.parentNode.parentNode;
	var divs = no.getElementsByTagName('div');
	
	var theAgr = divs[1];
	
	if (botao.name == "show"){
		theAgr.style.display = "";
		botao.name = "hide";
		botao.innerHTML = "<img src='/live/images/0fdfa42c68b043799af723eff6cb1dfc.gif' width='9' height='15'  />";
	}
	else if (botao.name == "hide"){
		theAgr.style.display = "none";
		botao.name = "show";
		botao.innerHTML = "<img src='/live/images/b06605ab67c348e0abd2a9e12a83975c.jpg' width='9' height='9'  />";
	}
}

// FIM MENU INTERNO ###################

/* INTERNET BANK */

function netbanck(){
	var login = window.document.getElementById('login').value;
	
	window.open('https://www.edivan.com.br/dominios/bancopine/login.asp?txtLogin='+login);
	//alert(login);
}

/* FIM INTERNET BANK */


function isNumberKey(evt){
	var charCode = (evt.which) ? evt.which : evt.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57)){
		return false;
	}
	return true;
}

//##############################################################################################################

// define the addEvent(oElement, sEvent, sCmd, bAppend) function
/*
function $addEvent(o, _e, c, _b){
	var e = _e.toLowerCase(), b = (typeof _b == "boolean") ? _b : true, x = (o[e]) ? o[e].toString() : "";
	x = x.substring(x.indexOf("{")+1, x.lastIndexOf("}"));
	x = ((b) ? (x + c) : (c + x)) + "\n";
	return o[e] = (!!window.Event) ? new Function("event", x) : new Function(x);
}

function attachEvent(o,evName,func){
	$addEvent(o, evName, func, true);
}

attachEvent(object,"onkeypress","return filtraTeclaInteiro(this,event);");
*/

//############################## INICIO TRATAMENTO MAPA DO SITE ##############################

function processSiteMap(){

	var siteMapContainer = document.getElementById('mapaSite-1');
	var theLeftMainNode = document.getElementById('mapaDoSiteEsquerdo');
	var theRightMainNode = document.getElementById('mapaDoSiteDireito');

	var browserName = navigator.appName;

	if (browserName=="Netscape") {
		theLeftMainNode.appendChild(siteMapContainer.childNodes[0]);
		theLeftMainNode.appendChild(siteMapContainer.childNodes[0]);
		theLeftMainNode.appendChild(siteMapContainer.childNodes[0]);
		theLeftMainNode.appendChild(siteMapContainer.childNodes[0]);
		theRightMainNode.appendChild(siteMapContainer.childNodes[0]);
		theRightMainNode.appendChild(siteMapContainer.childNodes[0]);
		theRightMainNode.appendChild(siteMapContainer.childNodes[0]);
		theRightMainNode.appendChild(siteMapContainer.childNodes[0]);
	}else {
		if (browserName=="Microsoft Internet Explorer") {
			theLeftMainNode.appendChild(siteMapContainer.childNodes[0]);
			theLeftMainNode.appendChild(siteMapContainer.childNodes[0]);
			theLeftMainNode.appendChild(siteMapContainer.childNodes[0]);
			theRightMainNode.appendChild(siteMapContainer.childNodes[0]);
			theRightMainNode.appendChild(siteMapContainer.childNodes[0]);
			theRightMainNode.appendChild(siteMapContainer.childNodes[0]);
			theRightMainNode.appendChild(siteMapContainer.childNodes[0]);
			theRightMainNode.appendChild(siteMapContainer.childNodes[0]);
		}
	}
}

//############################## TERMINO TRATAMENTO MAPA DO SITE ##############################