//VARIAVEL QUE GUARDA O NOME DAS PASTAS NA URL
var pastas = location.href.split("/");
var local = location.pathname.split("/");
var menuIclass;

// MENU LATERAL 
function mostraMenu(nome){
	try{
		//varialvel que guarda a identidade das uls na id passada por parametro
		identidade = document.getElementById(nome).getElementsByTagName('ul');
		for(var i=3; i < pastas.length; i++){
			for(var a=0; a < identidade.length; a++){
				links = identidade[a].getElementsByTagName('a');
				for(var b=0; b < links.length; b++){
					if(pastas[i] == links[b].id){
						links[b].className = "marcado";
						if(pastas[i] == "pesquisadores_estudantes"){
							links.pesquisadores_estudantes.className = "ultimomarcado";
						}
					}
				}
				
				if(local[local.length - 1] == "menu_iclass.asp"){
					document.getElementById("servicos").className = "";
					break;
				}
				
				if(pastas[i] == identidade[a].id){
					identidade[a].className = "mostra";
				}
				// exibir menus abertos na home
				if(pastas[i] == "" || pastas[i] == "index.asp" || pastas[i] == "mapa_site"){
					document.getElementById('consultas').className = "mostra";
					document.getElementById('servicos2').style.display = "block";
					document.getElementById('utilidades').className = "mostra";
					document.getElementById('agenciaVirtual').className = "mostra";
					
					// mostrar data e esconder ferramentas
					document.getElementById('data').className = "mostra";
					document.getElementById('ferramentas').className = "esconde";
				}					
				if((pastas[i] == "english") && (identidade[a].id == "investidores")){
					identidade[a].className = "esconde";					
				}
				if((pastas[i] == "empresa") && (identidade[a].id == "cross_empresa")){
					identidade[a].className = "mostra";					
				}
				if(pastas[i] == "menu_iclass.asp"){
					document.getElementById('servicos').className = "mostra";
					document.getElementById('clientes_alta_tensao').className = "mostra";
				}
			}	
		}		
	}
	catch(e){}
}


//ABRE
var anterior = "0"

function abre(id){
	try{
		document.getElementById(anterior).className = "esconde";
	}	
	catch(e){}		
	document.getElementById(id).className = "mostra";
	anterior = id;
}

//FECHA
function fecha(id){
	document.getElementById(id).className = "esconde";
}

/*FECHA Div */
function fechaDiv(id){
	document.getElementById(id).style.display = "none";
}


/* 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
	- 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);
}

//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;
}

//FAVORITOS
function favoritos(){	
	url="http://www.escelsa.com.br"
	title="EDP Escelsa - EDP no brasil"	
	if (document.all)	
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "")
}


//FUNCAO POPUP SEM NOVA PAGINA
function mostraPopUp(nome,largura,altura,imagem,scroll){
	var janela = window.open('','popUp','scrollbars='+ scroll +',width='+ largura +',height='+ altura +'');
	janela.document.write('<html><head><title>Escelsa - EDP Energias do Brasil - Geração, Comercialização e Distribuição de Energia Elétrica</title></head><body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0"><img src="' + imagem + '" border="0"></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);
}	


var guarda = "";

//exibir e esconder conteúdo de uma div
function mostraDiv(idDiv){							
	
	var definicao = document.getElementById(idDiv);		
	
	if(guarda == definicao){
		definicao.className = "esconde";
		guarda = "";
	}
		
	else{
		guarda.className = "esconde";
		definicao.className = "mostra";	
		guarda = definicao;	
	}
			
}    

/* 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.linkNome.value = 'Clique aqui'
	document.envieAmigo.url.value = location.href;
	document.envieAmigo.submit();
}

//SUBMETE LOGIN
function doKey($key) {
  if ($key == 13) {
     form1.submit();
   }
 }

 
 //MUDA O 0800

function btAt(){
	try{
		 var caminho = location.search;
		caminho = caminho.split('=')[2];
		caminho = caminho.split('&')[0];

		var iframe = document.getElementById('topoIframe');
		var parametros = ['loginat','consdeb','consfat','histcons','histdem','acertocadat','altdemat','endentregat','vertensaoat','altarifat']
	
	
		for(var a=0; a<parametros.length; a++){
			if(caminho == parametros[a]){
				iframe.src = "http://www.edpescelsa.com.br/energia/includes/topo_iclass.asp"
			}
		}
	}
	catch(e){}
}

window.onload = function(){
	btAt();
}

/* Aviso antecipado */
function SubmeteFormCidade(valor) {
	if(valor != "selecione"){
		location.href = "/energia/utilidades/avisos_antecipados/avisos_antecipados.asp" + valor;
		return false;
	}		
}

/* Select dos anos Avisos Antecipados */
var anterior = "selectAno"
function mudaSelect(nome){
	document.getElementById(anterior).style.display = "none";
	document.getElementById(nome).style.display = "block";
	anterior = nome;
}
		
		
function linkaSelect(endereco){
		location.href = endereco;
}

//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';
}