//verifica o navegador
var IE = (navigator.userAgent.indexOf('MSIE') > -1);

//variavel que vai armazenar o item do menu do topo que fica marcado
var l;
//overLi(): atribui um over as lis de uma id
//	id: id com as li's
function overLi(idMenu){
	//armazena os items de 1º nivel do menu
	var itens = document.getElementById(idMenu).childNodes;
	for(var i = 0; i < itens.length; i ++){
		if(itens[i].nodeType == 1){//1 = node de tag html
			itens[i].onmouseover =  function(){
				//verifica se a class ja nao foi trocada, e o item do menu nao é o item marcado
				if(this.className.indexOf('Over') == -1 && this.id != primeiroNivel){
					this.className += 'Over';
					//verifica se tem algum item marcado
					try{
						if(l){
							//se tiver, verifica se o item atual é diferente do marcado
							if(this.id != l){
								//se for diferente, esconde a ul do item marcado
								l.getElementsByTagName('ul')[0].style.display = 'none';
							}
						}
					}
					catch(e){};
				}
			}
			itens[i].onmouseout = function(){
				// verifica se nao é o item marcado
				if(this.id != primeiroNivel){
					// se nao for tira o over
					this.className = this.className.replace('Over', '');
					//verifca se tem segundo nivel
					try{
						if(l){
							//se tiver mostra o segundo nivel do item marcado
							l.getElementsByTagName('ul')[0].style.display = 'block';
						}
					}
					catch(e){}
				}
			}
		}
	}
	// armazena as id's que serao marcadas de acordo com a url
	var primeiroNivel = location.href.split('/')[3];
	var segundoNivel = location.href.split('/')[4];
	var menuLateral = location.href.split('/')[5];
	menuLateral = 'lateral_'+menuLateral;
	//verifica se nao esta na home
	if(primeiroNivel != 'index.asp' && primeiroNivel != ''){
		try{
			l = document.getElementById(primeiroNivel);
			// se nao tiver marca o primeiro nivel do menu
			l.className += 'Over';
		}
		catch(e){};
	}
	//verifica se esta na pagina de segundo nivel
	if(document.getElementById(segundoNivel)){
		//se tiver marca o menu
		document.getElementById(segundoNivel).className = 'segundoNivelMarcado';
	}
	//verifica se possui menu lateral
	if(document.getElementById(menuLateral)){
		//se tiver marca o menu, obs.: para o menu marcar é necessario inserir uma id no menu lateral com 'lateral_'+ o nome da sua pagina
		document.getElementById(menuLateral).className = 'menuLateralMarcado';
	}
}

//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;
}

//trocarConteudoClique(): troca um conteudo visível por outro. caso clique no conteudo que ja esteje visivel, esconde ele
//	-id: id do conteudo a trocar
function trocarConteudoClique(id){	
	if(visivel.length > 0) 		
		esconderConteudo(visivel);
	if(visivel != id){
		mostrarConteudo(id);
		visivel = id;
	}else{
		visivel = '';
	}
}

//linkCombo(): linka um combo
//	- idCombo: id do combo a linkar
function linkCombo(idCombo){
	location.href = document.getElementById(idCombo).value;
}

//marcarCombo(): marca um combo, caso algum dos seus options contenham a url no seu value
//	- idCombo: id do combo a marcar
function marcarCombo(idCombo){	
	var opts = document.form[idCombo].options;	
	for(var i = 0; i < opts.length; i ++){		
		if(location.href.indexOf(opts[i].value) > -1){
			opts[i].selected = true;
			break;
		}
	}
}


//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);
}

//função para limpar o form
function resetarForm(){
	if (!confirm("Deseja realmente limpar todos os dados do formulário?")) return;
	var campos = document.getElementById('form').elements;	
	for (var i = 0; i < campos.length; i++) {
		if((campos[i].type.toUpperCase() == "TEXT") || (campos[i].type.toUpperCase() == "TEXTAREA"))
			campos[i].value = "";
		if(campos[i].type.toUpperCase() == "CHECKBOX")
			campos[i].checked = false;
		if(campos[i].type.toUpperCase() == "SELECT-ONE")
			campos[i].value = "";
		if(campos[i].type.toUpperCase() == "PASSWORD")
			campos[i].value = "";
		if(campos[i].type.toUpperCase() == "FILE"){
			campos[i].value = "";
			if (IE)
				campos[i].outerHTML = campos[i].outerHTML
		}
	}
}

/* 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;
}