

//função que é chamda no onfocus e retorna mensagem na div correspondente ao campo
function informa(Ncampo)
{
var campo=document.getElementById('resposta'+Ncampo);
	//se campo Ncampo = cep retira o hífen
	if(Ncampo == 'razaosocial')
	{
		campo.innerHTML="Informe um nome com mínimo 3 caracteres, não use abreviaturas.";
	}
	if(Ncampo == 'nomefantasia')
	{
		campo.innerHTML="Informe o nome fantasia com mínimo 3 caracteres.";
	}
	if(Ncampo == 'nome')
	{
		campo.innerHTML="Informe um nome com mínimo 3 caracteres, não use apelidos.";
	}
	if(Ncampo == 'sobrenome')
	{
		campo.innerHTML="Escreva o seu sobrenome completo, sem abreviações.";
	}
	if(Ncampo == 'nomemae')
	{
		campo.innerHTML="Informe o nome com mínimo 3 caracteres, não use apelidos e se houver nome do meio coloque-o.";
	}
	if(Ncampo == 'sobrenomemae')
	{
		campo.innerHTML="Escreva o sobrenome completo, sem abreviações.";
	}
	if(Ncampo == 'senha')
	{
		campo.innerHTML="informe senha de 3 a 6 caracteres";
	}
	
	if(Ncampo == 'uf')
	{
		document.getElementById('respostacep').innerHTML="";
	}
	
	if(Ncampo == 'TELsDDD')
	{
		campo.innerHTML="Informe o número de telefone sem o DDD";
	}
	
	if(Ncampo == 'cep')
	{
		if(document.getElementById('uf').value=="selecione")
		{
			campo.innerHTML="selecione o estado antes de informar o CEP";
			return false;
		}else
		campo.innerHTML="somente números, 8 digitos";
	}
	 //se Ncampo = CPF retira os pontos e hífen
	if(Ncampo == 'cpf')
	{
		campo.innerHTML="somente números, sem pontos ou traços";
	}	
	
	//se Ncampo = reg retira hífen
	if(Ncampo == 'rg')
	{
		campo.innerHTML="somente numeros, 10 digitos";
	}
	//se Ncampo = data retira as barras '/'
	if(Ncampo == 'data')
	{
		campo.innerHTML="formato dd/mm/aaaa";
	}
	if(Ncampo == 'email')
		campo.innerHTML="informe o e-mail";
	}



//função que restringe caracteres digitados. Números ou letras
function valida_digitos(Ncampo)
{
		 //caracteres permitidos
		 if(Ncampo=="razaosocial")
		 er=/[0-9]/;
		 if(Ncampo=="nome")
		 er=/[0-9]/;
		 if(Ncampo=="sobrenome")
		 er=/[0-9]/;
		 if(Ncampo=="nomemae")
		 er=/[0-9]/;
		 if(Ncampo=="sobrenomemae")
		 er=/[0-9]/;
		 if(Ncampo=="cep" || Ncampo=="cpf" || Ncampo=="rg" || Ncampo=="telefone")
		 er=/[a-z]/;	 
		 digito=document.getElementById(Ncampo).value;
		 var tempor;
		 
		  for (var i=0;i<digito.length; i++) {
			tempor = digito.substring(i,i+1); 
			//se digitos não igual aos caracteres informado na variavel digitos, então é deletado
			  if (er.test(digito)) {
			  document.getElementById(Ncampo).value=digito.substring(0,digito.length-1);
			 
			 return false;
			  break;
    		}
   		}
 }

//função que retorna o erro na div correspondente ao campo, uando a validação falha
function erro(Ncampo)
{
	//if(Ncampo=="nome")
	//resposta="nome deve ter no minimo 3 caracteres";
	if(Ncampo=="cpf")
	resposta="número de CPF inválido";
	
	/*document.getElementById('resposta'+Ncampo).innerHTML="nome deve ter no minimo 3 caracteres";
	document.getElementById(Ncampo).style.background="red";
	document.getElementById(Ncampo).focus();
	return false;
	}*/
	document.getElementById(Ncampo).style.background="red";
	document.getElementById('resposta'+Ncampo).innerHTML="informe " + Ncampo;
	document.getElementById(Ncampo).focus();
	return false;
}
//função que formata o campo se a validação estiver ok
function ok(Ncampo)
{
	document.getElementById(Ncampo).style.background="#98EE84";
	document.getElementById('resposta'+Ncampo).innerHTML="";
	return true;
}

//função que é chamda no submit, valida os campos em geral, veificandos se estão vazios e os botões de radio e checkbox
function valida_enviar(campo){
	
	d=document.getElementById('uf').value;
	a=document.getElementById(campo);
	b=document.getElementById;
	var conta=0;
	campos=new Array('razaosocial','nome','sobrenome','nomemae','sobrenomemae','senha','cep','cpf','rg','data','TELsDDD','email');
	for(i=0;i<campos.length;i++)
	{	
		if(campos[i]=='razaosocial')
		{
			if(document.getElementById(campos[i]).value.length < 3)
			{
				document.getElementById('resposta'+campos[i]).innerHTML="informe o "+campos[i];
				conta++;
			}	
		}
		if(campos[i]=='nome')
		{
			if(document.getElementById(campos[i]).value.length < 3)
			{
				document.getElementById('resposta'+campos[i]).innerHTML="informe o "+campos[i];
				conta++;
			}	
		}	
		if(campos[i]=='sobrenome')
		{
			if(document.getElementById(campos[i]).value.length < 3)
			{
				document.getElementById('resposta'+campos[i]).innerHTML="informe o "+campos[i];
				conta++;
			}	
		}
		if(campos[i]=='nomemae')
		{
			if(document.getElementById(campos[i]).value.length < 3)
			{
				document.getElementById('resposta'+campos[i]).innerHTML="informe o "+campos[i];
				conta++;
			}	
		}	
		if(campos[i]=='sobrenomemae')
		{
			if(document.getElementById(campos[i]).value.length < 3)
			{
				document.getElementById('resposta'+campos[i]).innerHTML="informe o "+campos[i];
				conta++;
			}	
		}
		if(campos[i]=='TELsDDD')
		{
			if(document.getElementById(campos[i]).value.length < 7)
			{
				document.getElementById('resposta'+campos[i]).innerHTML="informe o "+campos[i];
				conta++;
			}	
		}
		if(campos[i]=='e-mail')
		{
			var er=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/
			//if(!er.test(document.getElementById(campos[i]).value))
			{
				alert("informe o e-mail correto")
				document.getElementById('resposta'+campos[i]).innerHTML="informe o e-mail correto";
				document.getElementById(campos[i]).style.background="red";
				conta++;
			}
		}
			/*if(!er.test(b))
				{	
					return erro(Ncampo);			
				}		
				//se Ncamp
			
			if(document.getElementById(campos[i]).value.length < 3)
			{
				document.getElementById('resposta'+campos[i]).innerHTML="informe o "+campos[i];
				conta++;
			}	
		}*/
		if(document.getElementById(campos[i]).value=="")
		{
			document.getElementById('resposta'+campos[i]).innerHTML="informe "+campos[i];
			conta++;
		}
			
	}			
	
	
	//se  botão radio não selecionado, não passa e retorna alert
	if (campo.sexo[0].checked!=true && campo.sexo[1].checked!=true)
	{ 
			document.getElementById('respostasexo').innerHTML="selecione o sexo";
			conta++;
	}
	
	//se campo select opção=selecione, não passa e retorna alert
	if(d == "selecione")
	{
			document.getElementById('respostauf').innerHTML="selecione o Estado";
			conta++;
	}
	//se campo checkbox não selecionado, não passa e retorna alert
	if (campo.assinar.checked!=true)
	{ 
			document.getElementById('respostaassinar').innerHTML="confirme a informação, clicando na caixa ao lado";
			conta++;
	}
			if(conta==0)
			return true;
			else
			return false;
	//return true;
}	
	


//função que limpa a div correspondente a checkbox, radio e select quando não vazios
function limpaID(ID)
{
document.getElementById('resposta'+ID).innerHTML="";
}



//função que valida o cep de acorodo com o estado selecionado, é feito um loop e de acorodo com o indice do estado é verificado
//a expressão regular correspondente ao cep no indice
function valida_cep(Ncampo)
{
	var er;
	var cep = document.getElementById(Ncampo).value;
	var uf=new Array('AM','SP','RJ','MS','MG','MT','AC','AL','AP','CE','DF','ES','GO','MA','PA','PE','PI','PR','RN','RO','RR','RS','SC','SE','TO','BA');
	var ers=new Array(/^[6][9][0-8][0-9]{2}-[0-9]{3}$/,/^([1][0-9]{3}|[01][0-9]{4})-[0-9]{3}$/,/^[2][0-8][0-9]{3}-[0-9]{3}$/,
	/^[2][0-8][0-9]{3}-[0-9]{3}$/,/^[2][0-8][0-9]{3}-[0-9]{3}$/,/^[7][8][8][0-9]{2}-[0-9]{3}$/,/^[6][9]{2}[0-9]{2}-[0-9]{3}$/,
	/^[5][7][0-9]{3}-[0-9]{3}$/,/^[6][89][9][0-9]{2}-[0-9]{3}$/,/^[6][0-3][0-9]{3}-[0-9]{3}$/,/^[7][0-3][0-6][0-9]{2}-[0-9]{3}$/,
	/^[2][9][0-9]{3}-[0-9]{3}$/,/^[7][3-6][7-9][0-9]{2}-[0-9]{3}$/,/^[6][5][0-9]{3}-[0-9]{3}$/,/^[6][6-8][0-8][0-9]{2}-[0-9]{3}$/,
	/^[5][0-6][0-9]{2}-[0-9]{3}$/,/^[6][4][0-9]{3}-[0-9]{3}$/,/^[8][0-7][0-9]{3}-[0-9]{3}$/,/^[5][9][0-9]{3}-[0-9]{3}$/,
	/^[7][8][9][0-9]{2}-[0-9]{3}$/,/^[6][9][3][0-9]{2}-[0-9]{3}$/,/^[9][0-9]{4}-[0-9]{3}$/,/^[8][89][0-9]{3}-[0-9]{3}$/,
	/^[4][9][0-9]{3}-[0-9]{3}$/,/^[7][7][0-9]{3}-[0-9]{3}$/,/^[4][0-8][0-9]{3}-[0-9]{3}$/);
	
		
		//document.getElementById('resposta'+Ncampo).innerHTML="";
			
	/*if(document.getElementById('uf').value=="selecione")
	{
		document.getElementById('resposta'+Ncampo).innerHTML="selecione o estado";
		return false;
	}*/
	if(document.getElementById('uf').value=="selecione" && document.getElementById('cep').value!="")
	{
		document.getElementById(Ncampo).style.background="red";
		document.getElementById(Ncampo).innerHTML ="selecione o estado antes de informar o CEP";
		return false;
	}
	
	for(i=0;i<uf.length;i++)
	{	
			if(uf[i]==document.getElementById('uf').value)
			{	
				if(cep!="")
				{	
					er=ers[i];
					if(!er.test(cep))
					{	
						return erro(Ncampo);						
					}		
					else
					{	
						return ok(Ncampo);					
					}
				}
				

		 }	document.getElementById(Ncampo).style.background="#FFFFFF";
			document.getElementById('resposta'+Ncampo).innerHTML="";
	}	
}


//valida os campos
function valida_campos(Ncampo)

{   
		//de acorodo com o campo a var er recebe uma expressão regular que vai vlaidar o campo exceto  CPF,CEP e Data que valida atrave da função
		//validar_CPF()		
			if(Ncampo=="razaosocial")
				var er=/[a-zA-Z]{3,}/;
			if(Ncampo=="senha")
				var er =/^\w{3,6}$/;
			if(Ncampo=="rg")
				var er =/^[0-9]{8}-[0-9]{2}$/;
			if(Ncampo=="TELsDDD")
				var er=/[0-9]{3,}/;		
			if(Ncampo=="nome")
				var er=/[a-zA-Z]{3,}/;
			if(Ncampo=="sobrenome")
				var er=/[a-zA-Z]{3,}/;
				if(Ncampo=="nomemae")
				var er=/[a-zA-Z]{3,}/;
			if(Ncampo=="sobrenomemae")
				var er=/[a-zA-Z]{3,}/;
			if(Ncampo=="email")
				  var er=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/
				
			 b=document.getElementById(Ncampo).value;
			if(b != "")
			{ 
				if(!er.test(b))
				{	
					return erro(Ncampo);			
				}		
				//se Ncampo passar na ER, então é feita a formatação do campo CEP = xxxxx-xxx
				else
				{	
					return ok(Ncampo);					
				}
			}
			document.getElementById(Ncampo).style.background="#FFFFFF";
	 		document.getElementById('resposta'+Ncampo).innerHTML="";
			
}

//function que valida, data pelo formato xx/xx/xxxx e verifica se a data existe
function validar_Data(Ncampo){

var er = /^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[1-2][0-9]\d{2})$/;
b=document.getElementById(Ncampo).value;
document.getElementById(Ncampo).style.background="#FFFFFF";
document.getElementById('resposta'+Ncampo).innerHTML="";
if(b!=""){
if(er.test(b)){

var dia = b.substring(0,2);
var mes = b.substring(3,5);
var ano = b.substring(6,10);
	
	if(ano < 1940)
	{
		alert("O ano especificado não é valido");
		document.getElementById(Ncampo).style.background="red";
		//document.getElementById('resposta'+Ncampo).innerHTML="O ano especificado não é válido";
		document.getElementById(Ncampo).focus();
		return false;
	}
	
		if((mes==04 || mes==06 || mes==09 || mes==11) && (dia > 30)){
			document.getElementById(Ncampo).style.background="red";
			alert("O mês especificado contém no máximo 30 dias");
			//document.getElementById('resposta'+Ncampo).innerHTML="O mês especificado contém no máximo 30 dias";
			document.getElementById(Ncampo).focus();
			return false;
		} else
		{
		if(ano%4!=0 && mes==02 && dia>28){
			document.getElementById(Ncampo).style.background="red";
			alert("Data incorreta!! O mês especificado contém no máximo 28 dias.");
			//document.getElementById('resposta'+Ncampo).innerHTML="Data incorreta!! O mês especificado contém no máximo 28 dias.";
			document.getElementById(Ncampo).focus();
			return false;
		} else{
		if(ano%4==0 && mes==02 && dia>29){
			document.getElementById(Ncampo).style.background="red";
			alert("Data incorreta!! O mês especificado contém no máximo 29 dias");
			//document.getElementById('resposta'+Ncampo).innerHTML="Data incorreta!! O mês especificado contém no máximo 29 dias";
			document.getElementById(Ncampo).focus();
			return false;
		} else{ 
		//alert ("Data correta!");
		return ok(Ncampo);
		}}}} else {
			document.getElementById(Ncampo).style.background="red";
			//alert("Formato inválido de data");
			document.getElementById('resposta'+Ncampo).innerHTML="Formato inválido de data";
			document.getElementById(Ncampo).focus();
			return false;
		}
		}
		document.getElementById(Ncampo).style.background="#FFFFFF";
		document.getElementById('resposta'+Ncampo).innerHTML="";
}




//função que valida o cpf
function validar_CPF(Ncampo)   
{   	
		erro = new String;   
  		cpf=document.getElementById(Ncampo);
        if (cpf.value.length == 14)   
   		 {     
				cpf.value = cpf.value.replace('.', '');   
				cpf.value = cpf.value.replace('.', '');   
				cpf.value = cpf.value.replace('-', ''); 
	  
				var nonNumbers = /\D/;   
				
				if (nonNumbers.test(cpf.value))   
				{   
						erro = "A verificacao de CPF suporta 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 1!"   
								//document.getElementById(Ncampo).value = cpf.value;
						}   
						
						
						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.";  
							//document.getElementById(Ncampo).value = cpf.value; 
						}   
				}   
		}   
		else   
		{   
			if(cpf.value.length == 0)  
			{
				document.getElementById('resposta'+Ncampo).innerHTML="";
				document.getElementById(Ncampo).style.background="#FFFFFF" 
				return false;   
			}
			else   
				erro = "Número de CPF inválido.";   
		}   
		if (erro.length > 0) {   
				alert(erro);   

				if (cpf.value.length == 11)   
				{     
					str = cpf.value;
					str2 = cpf.value.substring(0,3);
					str3 = cpf.value.substring(3,6);
					str4 = cpf.value.substring(6,9);
					str5 = cpf.value.substring(9,12);
					result=str.replace(str,str2+'.');
					result2=str.replace(str,str3+'.');
					result3=str.replace(str,str4+'-');
					document.getElementById(Ncampo).value = result + result2 + result3 + str5;
					document.getElementById(Ncampo).style.background="red";
					document.getElementById(Ncampo).focus(); 
					return false;   
				}				
			
				document.getElementById(Ncampo).value = cpf.value;
				document.getElementById(Ncampo).style.background="red";
				document.getElementById(Ncampo).focus(); 
				return false;   
		}     
		document.getElementById(Ncampo).style.background="#98EE84";
		document.getElementById('resposta'+Ncampo).innerHTML="";
		str = cpf.value;
		str2 = cpf.value.substring(0,3);
		str3 = cpf.value.substring(3,6);
		str4 = cpf.value.substring(6,9);
		str5 = cpf.value.substring(9,12);
		result=str.replace(str,str2+'.');
		result2=str.replace(str,str3+'.');
		result3=str.replace(str,str4+'-');
		document.getElementById(Ncampo).value = result + result2 + result3 + str5;
		return true;       
}   




//função que formata os campos - auto completa os campos cep,cpf,rg e data
function formata(Ncampo)
{
	var campo=document.getElementById(Ncampo).value;
	var str;
	var str2;
	var str3;

	if(Ncampo=='cep')
	{	
		if(campo.length==5)
		{	
			var str = campo.substring(0,5);
			document.getElementById(Ncampo).value = str+"-";
		}
	}
	if(Ncampo=='rg')
	{	
		if(document.getElementById(Ncampo).value.length==8)
		{	
			var str = document.getElementById(Ncampo).value.substring(0,8);
			document.getElementById(Ncampo).value = str+"-";
		}
	}
	
	if(Ncampo=='data')
	{	
		if(document.getElementById(Ncampo).value.length==2)
		{	
			var str = document.getElementById(Ncampo).value.substring(0,2);
			pt1=document.getElementById(Ncampo).value = str+"/";
		}
		if(document.getElementById(Ncampo).value.length==5)
		{	
			var str2 = document.getElementById(Ncampo).value.substring(3,5);
			pt2=document.getElementById(Ncampo).value = pt1+str2+"/";
		}
	}
	
	if(Ncampo=="cpf")
	{
		if(document.getElementById(Ncampo).value.length==3)
			{
				
				valor=document.getElementById(Ncampo).value;
				str = document.getElementById(Ncampo).value.substring(0,3);
				result=valor.replace(valor,str+'.');
				document.getElementById(Ncampo).value = result;
			}
		if(document.getElementById(Ncampo).value.length==7)
			{
				valor1=document.getElementById(Ncampo).value;
				str2 = document.getElementById(Ncampo).value.substring(4,8);
				result2=valor1.replace(valor1,str2+'.');
				document.getElementById(Ncampo).value = result + result2;
			}
		if(document.getElementById(Ncampo).value.length==11)
			{
				valor2=document.getElementById(Ncampo).value;
				str3 = document.getElementById(Ncampo).value.substring(8,11);

				result3=document.getElementById(Ncampo).value = result + result2 + str3 + "-";
			}
		if(document.getElementById(Ncampo).value.length==15)
			{
				valor3=document.getElementById(Ncampo).value;
				str3 = document.getElementById(Ncampo).value.substring(12,15);
				result4=valor3.replace(valor3,str3);
				document.getElementById(Ncampo).value = result + result2 + result3 + result4;
			}
					
	}
	
}

/// CNPJ

function ValidaCNPJ(cnpj) {

  var i = 0;
  var l = 0;
  var strNum = "";
  var strMul = "6543298765432";
  var character = "";
  var iValido = 1;
  var iSoma = 0;
  var strNum_base = "";
  var iLenNum_base = 0;
  var iLenMul = 0;
  var iSoma = 0;
  var strNum_base = 0;
  var iLenNum_base = 0;

  if (cnpj == "")
    return ("Preencha o campo CNPJ.");

  l = cnpj.length;
  for (i = 0; i < l; i++) {
    caracter = cnpj.substring(i,i+1)
    if ((caracter >= '0') && (caracter <= '9'))
       strNum = strNum + caracter;
  };

  if(strNum.length != 14)
    return ("CNPJ deve conter 14 caracteres.");

  strNum_base = strNum.substring(0,12);
  iLenNum_base = strNum_base.length - 1;
  iLenMul = strMul.length - 1;
  for(i = 0;i < 12; i++)
    iSoma = iSoma +
            parseInt(strNum_base.substring((iLenNum_base-i),(iLenNum_base-i)+1),10) *
            parseInt(strMul.substring((iLenMul-i),(iLenMul-i)+1),10);

  iSoma = 11 - (iSoma - Math.floor(iSoma/11) * 11);
  if(iSoma == 11 || iSoma == 10)
    iSoma = 0;

  strNum_base = strNum_base + iSoma;
  iSoma = 0;
  iLenNum_base = strNum_base.length - 1
  for(i = 0; i < 13; i++)
    iSoma = iSoma +
            parseInt(strNum_base.substring((iLenNum_base-i),(iLenNum_base-i)+1),10) *
            parseInt(strMul.substring((iLenMul-i),(iLenMul-i)+1),10)

  iSoma = 11 - (iSoma - Math.floor(iSoma/11) * 11);
  if(iSoma == 11 || iSoma == 10)
    iSoma = 0;
  strNum_base = strNum_base + iSoma;
  if(strNum != strNum_base)
    return ("CNPJ inválido.");

 	return ("CNPJ válido.");

}

//--->Função para a formatação dos campos...<---
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 'TELsDDD' :
            if (tam >= 9 && tam < 14)
                campo.value = + s.substr(0,4) + '.'+s.substr(4,tam-4);
        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;
}