var NomeAtual;
var quantFaq = 3;
	function mostraDiv(NomeDiv){
		for (cont=0;cont<=quantFaq;cont++){
			eval('document.all.menu'+cont+'.style.display = "none"');
		}
		if (NomeAtual!=NomeDiv){
			eval('document.all.menu'+NomeDiv+'.style.display = ""');
			NomeAtual = NomeDiv;
		}else{
			NomeAtual = "";
		}
	}
//MASCARAS DE CAMPOS

function FormataCnpj(campo, teclapres)
			{
				var tecla = teclapres.keyCode;
				var vr = new String(campo.value);
				vr = vr.replace(".", "");
				vr = vr.replace("/", "");  
				vr = vr.replace("-", "");
				tam = vr.length + 1;
				if (tecla != 14)
				{
					if (tam == 3)
						campo.value = vr.substr(0, 2) + '.';
					if (tam == 6)
						campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 5) + '.';
					if (tam == 10)
						campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/';
					if (tam == 15)
						campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/' + vr.substr(9, 4) + '-' + vr.substr(13, 2);
				}
			}

function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}
function itelefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o sexto e o setimo dígitos
    return v
}

function icpf(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}

function icep(v){
    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function icnpj(v){
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hífen depois do bloco de quatro dígitos
    return v
}

// TIRA ESPAÇOS EM BRANCO, DIREITA, ESQUERDA
function Trim(str){
	return LTrim(RTrim(str));
}

function LTrim(str){
	return str.replace(/^\s+/,'')
}

function RTrim(str){
	return str.replace(/\s+$/,'')
}
 
//VALIDA CPF
function remove(str, sub) {
   i = str.indexOf(sub);
   r = "";
   if (i == -1) return str;
   r += str.substring(0,i) + remove(str.substring(i + sub.length), sub);
   return r;
 }

function validaCPF() {
cpf = document.form.cpf.value;
var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;	

if(!filtro.test(cpf)){
	window.alert("Numero de CPF inválido. Tente novamente!");
	document.form.cpf.value = "";
	return false;
}
   
cpf = remove(cpf, ".");
cpf = remove(cpf, "-");
   
erro = new String;
                
if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n";
                
var nonNumbers = /\D/;
if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n";
if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
	erro += "Numero de CPF inválido. Tente novamente!"
}
var a = [];
var b = new Number;
var c = 11;
for (i=0; i<11; i++){
	a[i] = cpf.charAt(i);
	if (i < 9) b += (a[i] * --c);
}
if ((x = b % 11) < 2) { 
	a[9] = 0 
} 
else { 
	a[9] = 11-x 
}
b = 0;
c = 11;
for (y=0; y<10; y++) b += (a[y] * c--);
	if ((x = b % 11) < 2) { 
		a[10] = 0; 
	} 
	else { 
		a[10] = 11-x; 
	}
	if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
		erro +="Numero de CPF inválido. Tente novamente!";
	}
	if (erro.length > 0){
		alert(erro);
		document.form.cpf.value = "";
		return false;
	}
return true;
}

//VALIDA VARIOS COMPOS NO FORM
function validaForm(form){
	for (i=0;i<form.length;i++){
	var obg = form[i].name;
		if (obg!=-1){
			if (Trim(form[i].value) == ""){
				var nome = form[i].name;
				alert("O campo " + nome + " é obrigatório.")
				form[i].focus();
				return false;
			}
		}
	} 
	form.submit();
}

//EXIBE CAIXA DE MENSAGEM
function mensagem(str){
	if (str!=""){
		alert("\n "+str+" ");
		return false;
	}
}

//REDIRECIONADOR
function busca(url,marca){
	this.location.href = url+marca;
}
function Telefone(evt) {
	if(evt.value.length == 1) {
		valor = evt.value;
		evt.value="";
		evt.value += '('+valor;
	}
	if(evt.value.length == 3) {
		evt.value += ') ';
	}
	if(evt.value.length == 9) {
		evt.value += '-';
	}
}	
//VERIFICA SE O EMAIL É VALIDO
function checkEmail(email) {
	if (/^\w+([\-]?\w+)*@\w+([\-]?\w+)*(\.\w{2,3})+$/.test(email.value)){
		return (true);
	}
alert("Esse e-mail não é válido.");
//email.value = "";
email.focus();
return (false);
}

//IMPOSSIBILITA DIGITAR LETRAS
function IsNumber(evt){
	var charCode = (evt.which) ? evt.which : event.keyCode;
	return (charCode>=48 && charCode<=57 || charCode<20);
}

//IMPOSSIBILITA DIGITAR ASPAS SIMPLES
function NoQuote(evt){
	var charCode = (evt.which) ? evt.which : event.keyCode;
	return (charCode!=39 && charCode!=34);
}

//compara senhas
function validasenha() {
	if(document.form.senha.value!=document.form.confsenha.value){ 
		alert ("As Senhas digitadas não combinam. Tente novamente."); 
		document.form.senha.value = "";
		document.form.confsenha.value = "";	
		return false;
	}
return true;
}

//EXIBE IMAGEM NO RODAPÉ
function mouseover(text) {
    window.status = text;
    return true;
}

function mouseout() {
    window.status = '';
    return true;
}

function popup(codigo,y,x){
window.open(codigo,'MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width='+y+',height='+x);
}

function confirmBox(linc,id,cpf){
if(confirm("Tem certeza que deseja excluir este item?")){
	alert("Item excluido");
	location.href=linc+id+"cpf="+cpf+"";
	}
}

//insere texto em textarea
function zeratext(text,idx){
	if(text=="digite seu texto aqui"){
		document.getElementById(idx).value="";	
	}
}

function colocatext(valor,idx){
	if(valor==""){
		document.getElementById(idx).value="digite seu texto aqui";
	}
}


//Redireciona
function vaiurl(acao,url,id){
	location.href = acao+"/?url="+url;	
}


function MM_showHideLayers() { //v9.0
  var i,v,d,obj,args=MM_showHideLayers.arguments;
  
  for (i=0; i<(args.length-2); i+=3)
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { 
  
  v=args[i+2];
    if (obj.style) { 
		obj=obj.style; 
		v=(v=='show')?'visible':(v=='hide')?'hidden':v;
	}	
    obj.visibility=v; 
	}
  for (i=0; i<(args.length-3); i+=6)
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { 
  d=args[i+5];
    if (obj.style) { 
		obj=obj.style; 
		d=(d=='block')?'block':(d=='none')?'none':d;
	}	
    obj.display=d; 
	}
}
