// JavaScript Document

function mascaraData(campoData)
{    

var data = campoData.value;  

	if (data.length == 2)
	{                  
		data = data + '/';                  
		document.forms[0].LEI_criada.value = data;      
		return true;                     
	}              
	if (data.length == 5)
	{                  
		data = data + '/';                  
		document.forms[0].LEI_criada.value = data;                  
		return true;              
	} 
	
}

//////// -------------------------------------------------

function Contar(Campo)
{
	document.getElementById("Qtd").innerText = 200-Campo.value.length
	
	if((200-Campo.value.length)==0)
	alert('Atenção, você atingiu o limite máximo de caracteres!');
}

function formatar(src, mask)
{
  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i)
  
if (texto.substring(0,1) != saida)
  {
    src.value += texto.substring(0,1);
  }
}

function tel(objeto)
{ 
   if(objeto.value.length == 0)
     objeto.value = '(' + objeto.value;

   if(objeto.value.length == 3)
      objeto.value = objeto.value + ')';

	if(objeto.value.length == 4)
      objeto.value = objeto.value + ' ';

 	if(objeto.value.length == 9)
     objeto.value = objeto.value + '.';
}

///////////////////////////

function Mascara(tipo, campo, teclaPress) {
    if (window.event)
    {
        var tecla = teclaPress.keyCode;
    } else {
        tecla = teclaPress.which;
    }

    var s = new String(campo.value);
    // Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
    s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');

    tam = s.length + 1;

    if ( tecla != 9 && tecla != 8 ) {
        switch (tipo)
        {
        case 'CPF' :
            if (tam > 3 && tam < 7)
                campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
            if (tam >= 7 && tam < 10)
                campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
            if (tam >= 10 && tam < 12)
                campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
        break;

        case 'CNPJ' :

            if (tam > 2 && tam < 6)
                campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
            if (tam >= 6 && tam < 9)
                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
            if (tam >= 9 && tam < 13)
                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,tam-8);
            if (tam >= 13 && tam < 15)
                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,4)+ '-' + s.substr(12,tam-12);
        break;

        case 'TEL' :
            if (tam > 2 && tam < 4)
                campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
            if (tam >= 7 && tam < 11)
                campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
        break;

        case 'DATA' :
            if (tam > 2 && tam < 4)
                campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
            if (tam > 4 && tam < 11)
                campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
        break;
        
        case 'CEP' :
            if (tam > 5 && tam < 7)
                campo.value = s.substr(0,5) + '-' + s.substr(5, tam);
        break;
        }
    }
}

//--->Função para verificar se o valor digitado é número...<---
function digitos(event){
    if (window.event) {
        // IE
        key = event.keyCode;
    } else if ( event.which ) {
        // netscape
        key = event.which;
    }
    if ( key != 8 || key != 13 || key < 48 || key > 57 )
        return ( ( ( key > 47 ) && ( key < 58 ) ) || ( key == 8 ) || ( key == 13 ) );
    return true;
}

///==================================================

function validaCPF(CLI_cpf)   
{  
  erro = new String;  
  
    if (CLI_cpf.value.length == 11)  
    {     
            CLI_cpf.value = CLI_cpf.value.replace('.', '');  
            CLI_cpf.value = CLI_cpf.value.replace('.', '');  
            CLI_cpf.value = CLI_cpf.value.replace('-', '');  
  
            var nonNumbers = /\D/;  
      
            if (nonNumbers.test(CLI_cpf.value))   
            {  
                    erro = "A verificacao de CPF suporta apenas números!";   
            }  
            else  
            {  
                    if (CLI_cpf.value == "00000000000" ||   
                            CLI_cpf.value == "11111111111" ||   
                            CLI_cpf.value == "22222222222" ||   
                            CLI_cpf.value == "33333333333" ||   
                            CLI_cpf.value == "44444444444" ||   
                            CLI_cpf.value == "55555555555" ||   
                            CLI_cpf.value == "66666666666" ||   
                            CLI_cpf.value == "77777777777" ||   
                            CLI_cpf.value == "88888888888" ||   
                            CLI_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] = CLI_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 ((CLI_cpf.value.charAt(9) != a[9]) || (CLI_cpf.value.charAt(10) != a[10])) {  
                        erro = "Número de CPF inválido.";  
                    }  
            }  
    }  
    else  
    {  
        if(CLI_cpf.value.length == 0)  
            return false  
        else  
            erro = "Número de CPF inválido.";  
    }  
    if (erro.length > 0) {  
            alert(erro);  
            CLI_cpf.focus();  
            return false;  
    }     
    return true;      
}  

