var guardaDiv = 'vazia';

function mostradiv(nomeDiv){	

	document.getElementById(guardaDiv).style.display = "none";
	
	//document.getElementById(nomeDiv).style.display = "block";
	
	if(guardaDiv == nomeDiv){
		document.getElementById(nomeDiv).style.display = "none";
		guardaDiv = "vazia";
	}
	
	else{
		document.getElementById(nomeDiv).style.display = "block";
		guardaDiv = nomeDiv;
	}
}

function escondediv(nomeDiv){
	document.getElementById(nomeDiv).style.display = "none";
}

function mostraEsconde(base,id,tag){
	base = document.getElementById(base);
	tgs = base.getElementsByTagName(tag);
		
	for(i=0; i < tgs.length ; i++){
		if(tgs[i].parentNode.id == base.id){
			tgs[i].style.display = 'none';
		}
	}	
	document.getElementById(id).style.display = 'block';
}

//GUARDA AS PASTAS NO ARRAY
niveis = location.href.split("/");

//FUNCAO PAR MOSTRA O MENU LATERAL
function mostraMenu(idPrincipal){
	try{
		var uls = document.getElementById(idPrincipal).getElementsByTagName('ul');
		for(var i=3; i<niveis.length; i++){
			for(var a=0; a<uls.length; a++){
				if(niveis[i] == uls[a].id){
					uls[a].className = "mostra";
				}
				
				var links = uls[a].getElementsByTagName('a');
				for(var b=0; b<links.length; b++){
					
					
					
					if(links[b].id == niveis[i]){
						
						links[b].className = "marcado";
						$(links[b]).parent().addClass("on");
	
						//mantem o tamanho do ultimo item do menu superior
						if(niveis[i] == 'pesquisadores_estudantes'){
							links[b].className = "ultimomarcado";
						}	
						//mantem o tamanho do ultimo item do menu superior
						if(niveis[i] == 'geracao'){
							links[b].className = "ultimomarcado";
						}	
						//mantem o tamanho do ultimo item do menu superior
						if(niveis[i] == 'researchers_students'){
							links[b].className = "ultimomarcado";
						}
						//mantem o tamanho do ultimo item do menu superior
						if(niveis[i] == 'generation'){
							links[b].className = "ultimomarcado";
						}
						//mantem o tamanho do ultimo item do menu superior
						if(niveis[i] == 'sustentabilidade'){
							links[b].className = "ultimomarcado";
						}
						//mantem o tamanho do ultimo item do menu superior
						if(niveis[i] == 'sustainabilityInstitute'){
							links[b].className = "ultimomarcado";
						}				
					}					
					//condicao para mostrar o crosslink de investidores portugues
					if(niveis[i] == 'investidores'){
						document.getElementById('crosslinksInvestidores').className = "mostra";
						document.getElementById('boxCasdastroMenu').className = "esconde";							
					}
					//condicao para mostrar o crosslink de investidores ingles
					if(niveis[i] == 'investor'){
						document.getElementById('crosslinksInvestidoresIngles').className = "mostra";
					}
					
					/*if(niveis[i] == 'english' && uls[a].id == 'investidores'){
						uls[a].className = "esconde";
						document.getElementById('crosslinksInvestidores').className = "esconde";
						document.getElementById('crosslinksInvestidoresIngles').className = "mostra";
						document.getElementById('boxCadastro').className = "esconde";
					}*/
					
					//condicao para mostrar o crosslink de sustentabilidade
					if(niveis[i] == 'sustentabilidade'){
						document.getElementById('crosslinksInvestidoresSustentabilidade').className = "mostra";
					}
					//condicao para mostrar o crosslink de empresa
					if(niveis[i] == 'empresa'){
						document.getElementById('crosslinksInvestidoresEmpresa').className = "mostra";
					}
					if((niveis[i] == 'enernova') && (niveis[7] != null) && (niveis[4] != "english")){
						var earth = document.getElementById('crosslinkGoogleEarth');
						earth.className = "mostra";
						
						if(niveis[7] == 'pch_alegre')
							earth.className = "esconde";
						if(niveis[6] == 'diretoria_conselho')
							earth.className = "esconde";
						else if(niveis[7] == 'pch_fruteiras')
							earth.getElementsByTagName('a')[0].href = "/energia/geracao/localizacao/PCH Fruteiras.kmz";
						else if(niveis[7] == 'pch_jucu')
							earth.getElementsByTagName('a')[0].href = "/energia/geracao/localizacao/PCH Jucu.kmz ";		
						else if(niveis[7] == 'pch_rio_bonito')
							earth.className = "esconde";
						else if(niveis[7] == 'pch_santa_fe')
							earth.getElementsByTagName('a')[0].href = "/energia/geracao/localizacao/PCH Santa Fe.kmz";
						else if(niveis[7] == 'pch_sao_joao')
							earth.className = "esconde";
						else if(niveis[7] == 'pch_vicosa')
							earth.className = "esconde";
						else if(niveis[7] == 'coxim')
							earth.getElementsByTagName('a')[0].href = "/energia/geracao/localizacao/CGH Coxim.kmz";
						else if(niveis[7] == 'pch_costa_rica')
							earth.getElementsByTagName('a')[0].href = "/energia/geracao/localizacao/PCH Costa Rica.kmz";
						else if(niveis[7] == 'pch_paraiso')
							earth.getElementsByTagName('a')[0].href = "/energia/geracao/localizacao/PCH Paraíso.kmz";
						else if(niveis[7] == 'sao_joao_1')
							earth.getElementsByTagName('a')[0].href = "/energia/geracao/localizacao/CGH São João I.kmz";		
						else if(niveis[7] == 'sao_joao_2')
							earth.getElementsByTagName('a')[0].href = "/energia/geracao/localizacao/CGH São João II.kmz";
						else if(niveis[7] == 'uhe_mimoso')
							earth.getElementsByTagName('a')[0].href = "/energia/geracao/localizacao/UHE Mimoso.kmz";
						else if(niveis[7] == 'uhe_suica')
							earth.getElementsByTagName('a')[0].href = "/energia/geracao/localizacao/UHE Suica.kmz";
						else if(niveis[7] == 'horizonte')
							earth.className = "esconde";
						else if(niveis[7] == 'agua_doce')
							earth.className = "esconde";
					}
				}
			}
		}
	}
	catch(e){};
}


function trocarImagem(img){
	imagem = document.getElementById(img);
	imagem.src = imagem.src.substring(0, imagem.src.lastIndexOf('.')) + '_over.gif';
}

function voltarImagem(img){
	imagem = document.getElementById(img);
	imagem.src = imagem.src.substring(0, imagem.src.lastIndexOf('_over')) + '.gif';
}

//mostrarConteudo(): torna um conteudo visível
//	- id: id do conteudo a monstrar
function mostrarConteudo(id){			
	document.getElementById(id).style.display = 'block';
}

//esconderConteudo(): esconde um conteudo
//	- id: id do conteudo a esconder
function esconderConteudo(id){
	document.getElementById(id).style.display = 'none';
}

//trocarConteudo(): troca um conteudo visível por outro
//	-id: id do conteudo a trocar
var visivel = '';
function trocarConteudo(id){
	if(visivel.length > 0) 
		esconderConteudo(visivel);
	mostrarConteudo(id);
	visivel = id;
}
//Redimensiona a div
function exibirConteudo(idConteudo){
	var d = document.getElementById(idConteudo);
	if(d.style.display != 'block'){
		d.style.display = 'block';
		
		if(d.hF)
			d.style.height = d.hF + 'px';
		
		d.hF = d.offsetHeight;
		d.style.height = '1px';
		
		var c = d.innerHTML;
		d.innerHTML = '';					
		expandir(idConteudo, d.hF, escape(c));	
	}			
}

function expandir(id, hF, conteudo){
	var d = document.getElementById(id);
	var h = parseInt(d.style.height);
	if(h < hF){
		d.style.height = (h + 15) + 'px';
		setTimeout('expandir("'+id+'",'+hF+', "'+ conteudo+'")', 1);

	}else{
		d.innerHTML = unescape(conteudo);
	}
}

function ocultarConteudo(idConteudo){
	var d = document.getElementById(idConteudo);
	
	d.style.height = d.hF + 'px';
	
	var c = d.innerHTML;
	d.innerHTML = '';
	
	diminuir(idConteudo, escape(c));
}

function diminuir(id, conteudo){
	var d = document.getElementById(id);
	var h = parseInt(d.style.height);
	if(h > 20){
		d.style.height = (h - 20) + 'px';
		setTimeout("diminuir('"+id+"', '"+conteudo+"')", 1);
	}else{
		d.style.display = 'none';
		d.style.height = d.hF + 'px';
		d.innerHTML = unescape(conteudo);		
	}
}

function mostraPopUp(nome,largura,altura){
	var janela = window.open('','flash','width='+ largura +',height='+ altura +'');
	janela.document.write('<html><head><title>Foster Flashs Cases</title></head><body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0"><table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%"><tr valign="middle"><td align="center"><object type="application/x-shockwave-flash" data="'+ nome +'.swf" width="'+ largura +'" height="'+ altura +'" id="VideoPlayback"> <param name="movie" value="'+ nome +'.swf" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="scale" value="exactfit" /><param name="wmode" value="transparent" /><param name="FlashVars" value="playerMode=embedded" /></object></td></tr></table></body></html>');	
}


//abrirPopup(): abre uma popup
//	- url: caminho da janela a abrir
//	- width: width da popup
//	- height: height da popup
//  - scroll(opcional): se a pop-up terá scroll
function abrirPopup(url, width, height,scroll){
	var parametro = 'width=' + width + ', height=' + height;
	if(scroll)
		parametro += ', scrollbars =' + scroll;	
	window.open(url, '', parametro);
}		

/* funcoes para linkar e sinalizar combos */
function envieTopo(){
	if (document.title.indexOf('#') > - 1){
		document.envieAmigo.linkNome.value = document.title.substring(document.title.lastIndexOf("- ") + 1, document.title.indexOf('#'));
	}
	else{			
		document.envieAmigo.linkNome.value = document.title.substring(document.title.lastIndexOf("- ") + 1);
		
	}	
	document.envieAmigo.url.value = location.href;
	document.envieAmigo.submit();
}


/* Retira a borda dos flashes
Copyright 2006 Adobe Systems, Inc. All rights reserved.
Versão compacta, alterada por Renato Herculano
	- src, width e height são obrigatórios
	- nomeId = nome da id onde o flash sera exibido
	- os demais parametros são opcionais
*/
function flash(src, width, height, id, flashVars, wmode, menu, scale){
	var ret = GetArguments(src, width, height, id, flashVars, wmode, menu, scale);
	var str = '<object ';
	for (var i in ret.objAttrs)
		str += i + '="' + ret.objAttrs[i] + '" ';
		str += '>';
	for (var i in ret.params)
		str += '<param name="' + i + '" value="' + ret.params[i] + '" /> ';
		str += '</object>';
	document.write(str);
	
}

function flashs(nomeId,src, width, height, id, flashVars, wmode, menu, scale){
	var ret = GetArguments(src, width, height, id, flashVars, wmode, menu, scale);
	var str = '<object ';
	for (var i in ret.objAttrs)
		str += i + '="' + ret.objAttrs[i] + '" ';
	str += '>';
	for (var i in ret.params)
		str += '<param name="' + i + '" value="' + ret.params[i] + '" /> ';
	str += '</object>';
	document.getElementById(nomeId).innerHTML = str;
}

//GetArguments(): função auxiliar para retirar a borda dos flashes
//	- retorna os argumentos da tag object e os parametros
function GetArguments(src, w, h, id, flashVars, wmode, menu, scale){
	var ret = new Object();
	ret.params = new Object();
	ret.objAttrs = new Object();

	ret.objAttrs['data'] = ret.params['movie'] = src;
	ret.objAttrs['width'] = w;
	ret.objAttrs['height'] = h;
	ret.params['quality'] = 'high';
	ret.objAttrs['type'] = 'application/x-shockwave-flash';
	ret.params['menu'] = 'false';
	
	if(id) ret.objAttrs['id'] = id;

	if(flashVars) ret.params['flashVars'] = flashVars;
	
	ret.params['wmode'] = (wmode)? wmode : 'transparent';
	ret.params['scale'] = (scale)? scale : 'exactfit';
	ret.params['menu'] = (menu)? menu : 'false';
	
	return ret;
}

//Script para adicionar o site no favoritos do brownser
function favoritos(){	
	url="http://www.energiasdobrasil.com.br"
	title="EDP no brasil"	
	if (document.all)	
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "")
}

var guarda = "1"
var num = 1
function muda(valor){
	//proximo
	if(valor == "+"){
		if(num == 4)	
			num = 0;
		num++
		document.getElementById("_" + guarda).className = "esconde";
		document.getElementById("_" + num).className = "mostra";	
	}
	
	//anteiror
	if(valor == "-"){
		if(num == 1)	
			num = 5
		num--
		document.getElementById("_" + guarda).className = "esconde";
		document.getElementById("_" + num).className = "mostra";	
	}
	
	
	//zoom esqueda
	if(valor == "z1"){
		document.getElementById('ampliada').className = "mostra";
		document.getElementById('imgAmpliada').innerHTML = '<img src="images/' + num + '_1g.gif" alt="manual de identidade energias do brasil" border="0" />'
	}
	//zoom direita
	if(valor == "z2"){
		document.getElementById('ampliada').className = "mostra";
		document.getElementById('imgAmpliada').innerHTML = '<img src="images/' + num + '_2g.gif" alt="manual de identidade energias do brasil" border="0" />'
	}
	//fecha a div{
	if(valor == "f"){
		document.getElementById('ampliada').className = "esconde";
	}
	
	//busca
	if(valor == "b"){
		var numBusca = document.getElementById('inputIrPara').value
		
		//converte a string para inteiro
		parseFloat(numBusca) 
		
		//se for maior que o total nao mostra
		if((numBusca < 5) && (numBusca > 0) ){
			if((numBusca.length == 2) && (numBusca < 10)){
				numBusca = numBusca * 1
			}
			
			document.getElementById("_" + num).className = "esconde";
			document.getElementById("_" + numBusca).className = "mostra";
			num = numBusca;
				
		}
		else{
			alert("Favor digitar um número entre 1 e 4")
		}
	}
	
	//valor na tela
	document.getElementById('input').innerHTML = num
	
	guarda = num;
	
}

/* Usinas Enernova */

function trocaImg(nome){
	document.getElementById('imgUsina').innerHTML = "<img src='images/" + nome + "_g.jpg' alt='' border='0' id='teste' />"
} 

var anterior = "selectUsina"
function mudaSelect(nome){
	document.getElementById(anterior).style.display = "none";
	document.getElementById(nome).style.display = "block";
	anterior = nome;
}
		
function linkaSelect(endereco){
		location.href = endereco;
}

/*fecha Div */
function fechaDiv(nome){
	document.getElementById(nome).style.display = "none";
}
/* FUNÇÃO MOSTRA ESCONDE MENU NO ONMOUSEOVER, ONMOUSEOUT */
function subMenu(identidade){
	var menu = document.getElementById(identidade);
	var lis = menu.getElementsByTagName('li');
	
	for(var i=0; i<lis.length; i++){
		lis[i].onmouseover = function(){
			var uls = this.getElementsByTagName('ul');
			if(uls[0])
				uls[0].style.display = "block";
		}
		lis[i].onmouseout = function(){
			var uls = this.getElementsByTagName('ul');
			if(uls[0])
				uls[0].style.display = "none";
		}
	}
}


try{
	//script faz com que o crosslink Canal de comunicação e denúncia apareça na lateral esquerda da sessão empresa
	var pastas = location.pathname.split("/");
	$(function(){
		if(pastas[2] == "empresa")
			$("#canalComunicacaoDenuncia").removeClass("none");
	});
}
catch(e){}	

