/*	-------------------------------------------------
	FORMATA LETRAS
	-------------------------------------------------*/
	function formata(tipo,campo)
	{
		switch(tipo)
		{
			case 1: //CAIXA BAIXA - EVENTO: onBlur
			{
				campo.value = campo.value.toLowerCase();
				break;
			}
			case 2://CAIXA ALTA - EVENTO: onBlur
			{
				campo.value = campo.value.toUpperCase();
				break;
			}
		}
	}

/*	-------------------------------------------------
	DATA
	-------------------------------------------------*/
	function mascara_data(obj,tecla)
	{
		nomeObj = obj.name;
		valor = tecla.srcElement.value;
		tam = valor.length;

		//Testa se não foram digitados números
		if (tecla.keyCode < '48' || tecla.keyCode > '58')
		{
			alert('Por favor,\ndigite apenas números!'); 
			tecla.keyCode = '127';
			obj.focus();
		}
		else
		{
			if(tam==2)
			{
				tecla.srcElement.value = valor.substr(0,tam) + '/';
			}
			if(tam==5)
			{
				tecla.srcElement.value = valor.substr(0,tam) + '/';
			}
		}
	}
//adiciona mascara ao CPF
function MascaraCPF(cpf){
    if(mascaraInteiro(cpf)==false){
        event.returnValue = false;
    }    
    return formataCampo(cpf, '000.000.000-00', event);
}
//valida o CPF digitado
function ValidarCPF(Objcpf){
    var cpf = Objcpf.value;
    exp = /\.|\-/g
    cpf = cpf.toString().replace( exp, "" );
    var digitoDigitado = eval(cpf.charAt(9)+cpf.charAt(10));
    var soma1=0, soma2=0;
    var vlr =11;
    
    for(i=0;i<9;i++){
        soma1+=eval(cpf.charAt(i)*(vlr-1));
        soma2+=eval(cpf.charAt(i)*vlr);
        vlr--;
    }    
    soma1 = (((soma1*10)%11)==10 ? 0:((soma1*10)%11));
    soma2=(((soma2+(2*soma1))*10)%11);
    
    var digitoGerado=(soma1*10)+soma2;
    if(digitoGerado!=digitoDigitado)    
        alert('CPF Invalido!');        
}
/*	-------------------------------------------------
	DDD
	-------------------------------------------------*/
	function mascara_ddd(obj,tecla)
	{
		nomeObj = obj.name;
		valor = tecla.srcElement.value;
		tam = valor.length;
		//Testa se não foram digitados números
		 if (tecla.keyCode < '48' || tecla.keyCode > '58')
		{
			alert('Por favor,\ndigite apenas números!'); 
			tecla.keyCode = '127';
			obj.focus();
		}
	}

/*	-------------------------------------------------
	TELEFONE
	-------------------------------------------------*/
	function mascara_tel(obj,tecla)
	{
		nomeObj = obj.name;
		valor = tecla.srcElement.value;
		tam = valor.length;

		//Testa se não foram digitados números
		if (tecla.keyCode < '48' || tecla.keyCode > '58')
		{
			alert('Por favor,\ndigite apenas números!'); 
			tecla.keyCode = '127';
			obj.focus();
		}
		else
		{
			if(tam==4)
			{
			  tecla.srcElement.value = valor.substr(0,tam) + '-';
			}
		}
	}
