//validarNumeroCaracteres(): bloqueia a digitação em um campo de texto quando ele atinge o tamanho maximo, e mostra os restantes em um span
function validarNumeroCaracteres(campo, maximo, spanId)
{
    if (campo.value.length <= maximo)
	    document.getElementById(spanId).innerHTML = maximo - campo.value.length;
    else
	    campo.value = campo.value.substring(0, maximo);
}

//limparForm()
function limparForm(form , excessoes)
{
    if (!confirm("Tem certeza de que deseja limpar os dados do formulário?"))
        return;
        
    if (!excessoes)
        excessoes = ""
    
    if (typeof(excessoes) == "string")
        excessoes = [excessoes];
    
    if (excessoes.length > 0)
        excessoes = "[name!=" + excessoes.join("][name!=") + "]";
    
    $(form).find("input[type=text]" + excessoes + ", input[type=password]" + excessoes + ", select" + excessoes + ", textarea" + excessoes).val("");
    $(form).find("input[type=radio]" + excessoes + ", input[type=checkbox]" + excessoes).removeAttr("checked");
}

//pulaCampo(): pula para o próximo input
// - form: formulário
// - objeto: objeto atual
function pulaCampo(form, objeto)
{
	if(objeto.value.length == objeto.maxLength)
	{
		var campos = form.elements;
		for(var i = 0; i < campos.length; i++)
		{
			if(objeto.name == campos[i].name)
			{
			    if (form[campos[i+1].name].focus)
			    {
				    form[campos[i+1].name].focus();
				}
			}
		}
	}
}





/* 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;
}


//exibeConteudo(): exibe um conteúdo
function exibirConteudo(id){
	$('#'+id).css('display','block');
}

//OcultarConteudo(): oculta um conteúdo
function ocultarConteudo(id){
	$('#'+id).css('display','none');
}

//variavel que armazena a div visível
var conteudoVisivel = '';

//TrocarConteudo(): troca o conteúdo visivel por outro
//	-id: id do conteúdo a exibir
function trocarConteudo(id){
	if(id != conteudoVisivel){
		if(conteudoVisivel.length > 0) ocultarConteudo(conteudoVisivel);
		
		exibirConteudo(id);
		conteudoVisivel = id;
	}
	else{
		ocultarConteudo(id);
		conteudoVisivel = '';
	}
}

//função faz over e marcação do menu navegação 
function menuSuperior()
{	
	var niveis = location.pathname.split("/");
	var itens = $('#controlaMenuNavegacao ul li a');

	itens.each(function(){
		this.imagem = $(this).find('img');
		this.url_imagem = this.imagem.attr("src");
		this.url_imagem_over = this.imagem.attr('src').substring(0, this.imagem.attr('src').lastIndexOf('.')) + '_over.gif';
	})
	
	itens.hover(
		function(){
			if(!this.marcado)
				this.imagem.attr("src", this.url_imagem_over);
		},
		function(){
			if(!this.marcado)
				this.imagem.attr("src", this.url_imagem);
		}
	);
	
	var item_marcado = $("#" + niveis[1]);
	if(item_marcado.length > 0)
	{
		item_marcado = item_marcado[0];
		item_marcado.marcado = true;
		item_marcado.imagem.attr("src", item_marcado.url_imagem_over);
	}
};