function ContaCaracteres(){ 
   intCaracteres = 300 - document.contato.comentario.value.length; 
   if (intCaracteres > 0) { 
      document.contato.caracteres.value = intCaracteres; 
      return true; 
   } 
   else { 
      document.contato.caracteres.value = 0; 
      document.contato.comentario.value = document.contato.comentario.value.substr(0,300) 
      return false; 
   } 
} 



function valida_email() {
 var ok = true;
if  (newsletter.email.value.search("@") == -1 || newsletter.email.value.search("[.*]") == -1)
 {
  alert("Por favor, digite o seu endereço de E-mail válido!");
  newsletter.email.focus();
  ok = false;
  return(false);
 }
}




function SomenteNumero(e){ // Números
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}

function makevisible(cur,which){
if (which==0)
cur.filters.alpha.opacity=90
else
cur.filters.alpha.opacity=100
}

function formatar_mascara(src, mascara) {
var campo = src.value.length;
var saida = mascara.substring(0,1);
var texto = mascara.substring(campo);
if(texto.substring(0,1) != saida) {
src.value += texto.substring(0,1);
}
}


function stAba(menu,conteudo)
{
this.menu = menu;
this.conteudo = conteudo;
}

var arAbas = new Array();
arAbas[0] = new stAba('td_cadastro','div_cadastro');
arAbas[1] = new stAba('td_consulta','div_consulta');

function AlternarAbas(menu,conteudo)
{
for (i=0;i<arAbas.length;i++)
{
m = document.getElementById(arAbas[i].menu);
m.className = 'menu';
c = document.getElementById(arAbas[i].conteudo)
c.style.display = 'none';
}
m = document.getElementById(menu)
m.className = 'menu-sel';
c = document.getElementById(conteudo)
c.style.display = '';
}






function enquete(id) {
	var radio = document.frmenquete.enqueteOPC;
	var rvale;
	var theURL;
	for(var i = 0; i < radio.length; i++) {
		if (radio[i].checked == true) { rvale = i; }
	}
	rvale = rvale +1;
	if (!rvale) { 
		alert("Selecione uma opção");
	} else {
		theURL = "resultado_enquete.php?id=" + id + "&opc=" + rvale;
		window.open(theURL,"_blank","resizable=no,toolbar=no,status=no,menubar=no,scrollbars=yes,width=525,height=500");
	}
}					
function enqueteresultado(id) {
		theURL = "resultado_enquete.php?id=" + id;
		window.open(theURL,"_blank","resizable=no,toolbar=no,status=no,menubar=no,scrollbars=yes,width=525,height=500");
}


















function validaCPF(cpf)   
{   
  erro = new String;   
  
    if (cpf.value.length == 11)   
    {     
            cpf.value = cpf.value.replace('.', '');   
            cpf.value = cpf.value.replace('.', '');   
            cpf.value = cpf.value.replace('-', '');   
  
            var nonNumbers = /\D/;   
       
            if (nonNumbers.test(cpf.value))   
            {   
                    erro = "O seu CPF deve ter apenas números!";   
            }   
            else   
            {   
                    if (cpf.value == "00000000000" ||   
                            cpf.value == "11111111111" ||   
                            cpf.value == "22222222222" ||   
                            cpf.value == "33333333333" ||   
                            cpf.value == "44444444444" ||   
                            cpf.value == "55555555555" ||   
                            cpf.value == "66666666666" ||   
                            cpf.value == "77777777777" ||   
                            cpf.value == "88888888888" ||   
                            cpf.value == "99999999999") {   
                               
                            erro = "Número de CPF inválido!"   
                    }   
       
                    var a = [];   
                    var b = new Number;   
                    var c = 11;   
  
                    for (i=0; i<11; i++){   
                            a[i] = cpf.value.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.value.charAt(9) != a[9]) || (cpf.value.charAt(10) != a[10])) {   
                        erro = "Número de CPF inválido!";   
                    }   
            }   
    }   
    else   
    {   
        if(cpf.value.length == 0)   
            return false   
        else   
            erro = "Número de CPF inválido!";   
    }   
    if (erro.length > 0) {   
            alert(erro);   
            cpf.focus();   
            return false;   
    }     
    return true;       
}   
  
//envento onkeyup   
function maskCPF(CPF) {   
    var evt = window.event;   
    kcode=evt.keyCode;   
    if (kcode == 8) return;   
    if (CPF.value.length == 3) { CPF.value = CPF.value + '.'; }   
    if (CPF.value.length == 7) { CPF.value = CPF.value + '.'; }   
    if (CPF.value.length == 11) { CPF.value = CPF.value + '-'; }   
}   
  
// evento onBlur   
function formataCPF(CPF)   
{   
    with (CPF)   
    {   
        value = value.substr(0, 3) + '.' +   
                value.substr(3, 3) + '.' +   
                value.substr(6, 3) + '-' +   
                value.substr(9, 2);   
    }   
}   
function retiraFormatacao(CPF)   
{   
    with (CPF)   
    {   
        value = value.replace (".","");   
        value = value.replace (".","");   
        value = value.replace ("-","");   
        value = value.replace ("/","");   
    }   
}