﻿<!-- 	Funções JS Vs 1.3	 -->

//FORMATA MASCARA DE ENTRADA EM CAMPOS PARA QUALQUER VALOR DEFINIDO (Ncampo = string, tipo = string (numero ou texto))
function mascara(campo, mask, evt) {
 
 if(document.all) { // Internet Explorer
    key = evt.keyCode; }
    else{ // Nestcape
       key = evt.which;
     }

if (key == 8) {
return true;
}

 string = campo.value;  
 i = string.length;

 if (i < mask.length) {
  if (mask.charAt(i) == '?') {
       return (key > 47 && key < 58);
      } else {
       if (mask.charAt(i) == '!') {  return true;  }
   for (c = i; c < mask.length; c++) {
         if (mask.charAt(c) != '?' && mask.charAt(c) != '!')
         campo.value = campo.value + mask.charAt(c);
      else if (mask.charAt(c) == '!'){
                return true;
       } else {
         return (key > 47 && key < 58);
          }
       }
    }
  } else return false;
}

//VALIDAÇÃO DE TIPO DE CATACTERIES, SÓ PERMITE O TIPO ESCOLHIDO, NUMÉRICOS OU TEXTO(Ncampo = string, tipo = string (numero ou texto))
function valida_digitos(Ncampo,tipo)
{
		 //caracteres permitidos
		 if(tipo=="texto")
		 	er=/[0-9]/;
		 if(tipo=="numero")
		 	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;
    		}
   		}
 }

//VALIDAÇÃO DE CPF (Ncampo = string)
 function validar_CPF(Ncampo)   
{   	
		erro = new String;   
  		cpf=document.getElementById(Ncampo);
		init_cpf=cpf.value
        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 = init_cpf;
		return true;       
}

//FORMATAÇÃO DE CAMPOS DO TIPO MÁSCARA DE ENTRADA (Ncampo = string - cep, rg, data ou cpf)
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;
			}
					
	}
	
	if(Ncampo=='cnpj')
	{	
		if(document.getElementById(Ncampo).value.length==2)
		{	
			var str = document.getElementById(Ncampo).value.substring(0,2);
			document.getElementById(Ncampo).value = str+".";
		}
		if(document.getElementById(Ncampo).value.length==6)
		{	
			var str = document.getElementById(Ncampo).value.substring(0,6);
			document.getElementById(Ncampo).value = str+".";
		}
		if(document.getElementById(Ncampo).value.length==10)
		{	
			var str = document.getElementById(Ncampo).value.substring(0,10);
			document.getElementById(Ncampo).value = str+"/";
		}
		if(document.getElementById(Ncampo).value.length==15)
		{	
			var str = document.getElementById(Ncampo).value.substring(0,15);
			document.getElementById(Ncampo).value = str+"-";
		}
	}
}

//FUNCAO REPLACE ALL 
String.prototype.replaceAll = function(de, para){
    var str = this;
    var pos = str.indexOf(de);
    while (pos > -1){
		str = str.replace(de, para);
		pos = str.indexOf(de);
	}
    return (str);
}

// VALIDAÇÃO DE EMAIL (Ncampo = string)
function validaEmail(Ncampo){ 
		var email=document.getElementById(Ncampo).value; 
		if (email != ""){
	        var filtro=/^.+@.+\..{2,3}$/;
    	    if (filtro.test(email) == false){
        	alert("O email informado nao é válido");
			document.getElementById(Ncampo).style.border='2px solid #900'
			document.getElementById(Ncampo).focus()	
    	    }
		else {
			document.getElementById(Ncampo).style.border='1px solid #CCC'
			}
		}
return false;
}

// VALIDAÇÃO DE LOGIN COM NO MÍNIMO 5 CARACTÉRIES (Ncampo = string)
function validaLogin(Ncampo){
	login=document.getElementById(Ncampo);
	if (login.value != ""){
		if (login.value.length < 5){
			alert("Login deve ter pelo menos 5 caractéries");
			login.focus();
			login.value="";
		}
	}
}

//VALIDAÇÃO DE SENHA DE 6 A 16 CARACTÉRIES (Ncampo = string, campo da senha, Ncampo2 = string, campo da confirmação)
function validaSenha(Ncampo){
	senha=document.getElementById(Ncampo);
	if (senha.value != ""){
		if (senha.value.length < 6 || senha.value.length > 16){
			alert("Digite uma senha de 5 a 12 caractéries");
			senha.focus();
			senha.value="";
		}
	}
}

//COMPROVAÇÃO DE SENHA IGUAL EM DOIS CAMPOS (Ncampo = string, campo da senha, Ncampo2 = string, campo da confirmação)
function comprovarSenha(Ncampo,Ncampo2){ 
    senha1 = document.getElementById(Ncampo);
    senha2 = document.getElementById(Ncampo2);
	
	if (senha1.value !="" && senha1.value.length >= 5 && senha1.value.length <= 12){
    	if (senha1.value != senha2.value){
			alert("A senha digitada e a confirmação de senha não conferem!")
			senha1.value="";
			senha2.value=""
			senha1.focus();
		}
	}
}

//SALTAR PARA PRÓXIMO CAMPO AUTOMATICAMENTE (campo = string, max = numero, prox_campo = string)
function nextField(campo, max, prox_campo){
	if (campo.value.length == max){
    	document.getElementById(prox_campo).focus();
    }
}

//VALIDAÇÃO DE FORMULÁRIO (Ncampos = string com os campos separados por vírgula)
function validaForm(Ncampos,tp_msg){
	campos = Ncampos.replace(" ","");
	campos = campos.split(',');
			
	for(var i=0;i<campos.length;i++){
		nCampo = campos[i];
		field = document.getElementById(nCampo);
		tipo = field.type;
		div = document.getElementById('msg_'+nCampo);
		
		if (field.disabled==false){
		
		if (tipo=="text" || tipo=="password" || tipo=="textarea" || tipo=="select-one" || tipo=="select-multiple"){
			if(field.value==""){
				if(tp_msg=='div' || tp_msg==1){
					div.style.display="block";
					field.style.border='2px solid #900';
					//div.style.visibility="visible";
					field.focus
				}else{
					alert("Preencha todos os campos obrigatórios indicados por * (asterisco).");
				}
				field.focus();
				return false;
			}else{
				if(tp_msg=='div' || tp_msg==1){
					div.innerHTML='';
					div.style.display="none";
					field.style.border='1px solid #CCC';
   					//div.style.visibility="hidden";
				}
			}			
		}
				
		if (tipo=='radio' || tipo=='checkbox'){
			radio = document.getElementsByName(nCampo);
			tamanho = radio.length;
			chk = false;
			for(var j=0; j<tamanho; j++){
				if(radio[j].checked==true)
					chk = true;
			}
			if (chk==false){
				div.innerHTML='Selecione uma opção';
				div.style.display="block";
				//div.style.visibility="visible";
				return false;
			}else{
				div.innerHTML='';
				div.style.display="none"; 
   				//div.style.visibility="hidden";
			}
		}
		}
	}	
	return true
}

//LIMITAR NÚMERO DE SELEÇÕES EM LIST MENU (list = string, max = numero)
function limitList(list, max) {
	if (max == 0) return 1;
	var lista   = document.getElementById(list);
	var sel     = lista.selectedIndex;
	var total = 0;
	
	for(i = 0; i < lista.length; i++){
		if (lista.options[i].selected == true){
			if (total >= max) {
				lista.options[i].selected = false;
			}
			total++;
		}
	}
}

//MARCA RADIO BUTTON OU CHECK BOX AO SELECIONAR ITEM EM LIST MENU (list = objeto, radio = objeto, valor = string - opcional)
function selectRadio(list,radio,valor){
	sel = list.selectedIndex;
	if (list[sel].value != ''){
		if (valor != null){
			if (list[sel].value == valor){
				radio.checked = true;
			} else {
				radio.checked = false;
			}
		} else {
			radio.checked = true;
		}
	} else {
		radio.checked = false;
	}
}

//DESMARCAR TODOS OS RADIOS DE UM GRUPO (radio = objeto)
function desmarcarRadios(radio){
	tamanho = radio.length
	for (var i=0; i<tamanho; i++){
		radio[i].checked=false
	}
}

//MARCAR TODOS OS RADIOS DE UM GRUPO (radio = objeto)
function desmarcarRadios(radio){
	tamanho = radio.length
	for (var i=0; i<tamanho; i++){
		radio[i].checked=true
	}
}

//DESMARCAR TODOS OS RADIOS DE UM GRUPO SEGUNDO UM VALOR SELECIONADO EM LIST MENU(radio = objeto, list = obejto, valor = string)
function listDesmarcarRadios(radio, list, valor){
	tamanho = radio.length;
	sel = list.selectedIndex;
	val = list.options[sel].value;
	if (val == valor){
		for (var i=0; i<tamanho; i++){
			radio[i].checked=false
		}
	}
}

//MARCAR TODOS OS RADIOS DE UM GRUPO SEGUNDO UM VALOR SELECIONADO EM LIST MENU(radio = objeto, list = obejto, valor = string)
function listDesmarcarRadios(radio, list, valor){
	tamanho = radio.length;
	sel = list.selectedIndex;
	val = list.options[sel].value;
	if (val == valor){
		for (var i=0; i<tamanho; i++){
			radio[i].checked=true
		}
	}
}

//DESABILITA GRUPO DE RADIOS (radio = objeto)
function desabilitarRadio(radio){
	tamanho = radio.length
	for (var i=0; i<tamanho; i++){
		radio[i].disabled=true
	}
}

//HABILITA GRUPO DE RADIOS (radio = objeto)
function habilitarRadio(radio){
	tamanho = radio.length
	for (var i=0; i<tamanho; i++){
		radio[i].disabled=false
	}
}

//DESABILITA GRUPO DE RADIOS CONFORME VALOR SELECIONADO EM LIST MENU (radio = objeto, list = objeto, valor = string)
function listDesabilitarRadio(radio, list, valor){
	tamanho = radio.length
	sel = list.selectedIndex;
	val = list.options[sel].value;
	if (val == valor){
		for (var i=0; i<tamanho; i++){
			radio[i].disabled=true
		}
	} else {
		for (var i=0; i<tamanho; i++){
			radio[i].disabled=false
		}
	} 
}

//HABILITAR GRUPO DE RADIOS CONFORME VALOR SELECIONADO EM LIST MENU (radio = objeto, list = objeto, valor = string)
function habilitarRadio(radio, list, valor){
	tamanho = radio.length
	sel = list.selectedIndex;
	val = list.options[sel].value;
	if (val == valor){
		for (var i=0; i<tamanho; i++){
			radio[i].disabled=false
		}
	}else {
		for (var i=0; i<tamanho; i++){
			radio[i].disabled=true
		}
	} 
}

//ROLAR PARA O TOPO DA PÁGINA
function scrollTopPosition(){
	return (is.ie)?d.body.scrollTop:pageYOffset;
}

//MAXIMIZAR JANELA DO NAVEGADOR
function maximizar(){
	window.moveTo(0,0);
	if (document.all) {
		top.window.resizeTo(screen.availWidth,screen.availHeight);
	}
	else if (document.layers||document.getElementById) {
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
			top.window.outerHeight = screen.availHeight;top.window.outerWidth = screen.availWidth;
		}
	}
}

//NÃO PERMITIR ABRIR EM IFRAME
function noIframe(url){
	if (top.location != self.location){
		if (url == null || url == "")
			top.location = self.location;
		else
			window.open(url);
	}
}

//IMPRIMIR A PÁGINA
function DoPrinting(){
if (!window.print){
alert("Use o Netscape  ou Internet Explorer \n nas versões 4.0 ou superior!")
return
}
window.print()
}

//MUDAR COR DA CÉLULA AO PASSAR COM O MOUSE (obj = objeto, celula que irá mudar podendo ser usado this - cor_entrada = string)
function mudaCor(obj,cor_entrada) { 
    obj.bgColor=cor_entrada;obj.style.cursor="hand"; 
} 
function voltaCor(obj,cor_default) { 
    obj.bgColor=cor_default;obj.style.cursor="default"; 
} 

//CONFIRMAR EXCLUSÃO DE USUÁRIO (id = string, user = string com nome do usuario a ser excluído)
function excluirUser(id,user){
	if (confirm("Tem certeza que deseja excluir esse usuário?\nEsta operaçao nao poderá ser revertida!")){
		if (user == "<%=DesAdmin%>"){
			alert("O usuário desenvolvedor nao pode ser excluído!")
		}else{
			if (id=="<%=session('UserId')%>"){
				if (confirm("Este usuário está logado no momento.\nExcluílo retornará o sistema a tela de login.")){
					document.location="usuario_deletar.asp?a=del&log=logout&id="+id
				}
			}else{
				document.location="usuario_deletar.asp?a=del&id="+id
			}				
		}
	}
}

//CONFIRMAR EXCLUSÃO DE UM ÚNICO REGISTRO (url = string, endereço da pagina de exclusao com id do registro)
function excluir(url){
	if (confirm("Tem certeza que deseja excluir esse registro?\nEsta operação não poderá ser revertida!")){
		document.location=url
	}				
}

//CONFIRMAR EXCLUSAO DE MULTIPLOS REGISTROS (chkBox = string)
function confirmar(chkBox){
	if (document.getElementById(chkBox).value != "false"){
		if (confirm('Tem certeza que deseja excluir estes registros?')){
			return true;
		}else{
			return false;
		}
	}else{
		alert('Nenhum registro foi selecionado!')
	}
}

//VALIDAÇÃO DE DINHEIRO R$
function FormataReal(nvalor){
nvalor = nvalor.replace(".","");
nvalor = nvalor.replace(",",".");
return nvalor;
}
function FormataValor(objeto,teclapres,tammax,decimais) 
{
	var tecla			= teclapres.keyCode;
	var tamanhoObjeto	= objeto.value.length;
	if ((tecla == 8) && (tamanhoObjeto == tammax))
	{
		tamanhoObjeto = tamanhoObjeto - 1 ;
	}
    if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) && ((tamanhoObjeto+1) <= tammax))
	{
		vr	= objeto.value;
		vr	= vr.replace( "/", "" );
		vr	= vr.replace( "/", "" );
		vr	= vr.replace( ",", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		tam	= vr.length;
		if (tam < tammax && tecla != 8)
		{
			tam = vr.length + 1 ;
		}
		if ((tecla == 8) && (tam > 1))
		{
			tam = tam - 1 ;
			vr = objeto.value;
			vr = vr.replace( "/", "" );
			vr = vr.replace( "/", "" );
			vr = vr.replace( ",", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
		}
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
		{
			if (decimais > 0)
			{
				if ( (tam <= decimais) )
				{ 
					objeto.value = ("0," + vr) ;
				}
				if( (tam == (decimais + 1)) && (tecla == 8))
				{
					objeto.value = vr.substr( 0, (tam - decimais)) + ',' + vr.substr( tam - (decimais), tam ) ;	
				}
				if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) == "0"))
				{
					objeto.value = vr.substr( 1, (tam - (decimais+1))) + ',' + vr.substr( tam - (decimais), tam ) ;
				}
				if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) != "0"))
				{
				    objeto.value = vr.substr( 0, tam - decimais ) + ',' + vr.substr( tam - decimais, tam ) ; 
				}
				if ( (tam >= (decimais + 4)) && (tam <= (decimais + 6)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 3) ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
			 	if ( (tam >= (decimais + 7)) && (tam <= (decimais + 9)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 6) ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
				if ( (tam >= (decimais + 10)) && (tam <= (decimais + 12)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 9) ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
				if ( (tam >= (decimais + 13)) && (tam <= (decimais + 15)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 12) ) + '.' + vr.substr( tam - (decimais + 12), 3 ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
			}
			else if(decimais == 0)
			{
				if ( tam <= 3 )
				{ 
			 		objeto.value = vr ;
				}
				if ( (tam >= 4) && (tam <= 6) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr(0, tam - 3) + '.' + vr.substr( tam - 3, 3 ); 
				}
				if ( (tam >= 7) && (tam <= 9) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
				}
				if ( (tam >= 10) && (tam <= 12) )
				{
			 		if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
				}

				if ( (tam >= 13) && (tam <= 15) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ) ;
				}			
			}
		}
	}
	else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46))
		{
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
}

//ENCRIPTAÇÃO DE SENHA (keyBox = objeto do tipo text)
function encript(keyBox){
	key = keyBox.value	
	if (key != "")
		keyBox.value = hex_md5(key)
}

//ENCRIPTAÇÃO MD5 (Utilize a função encript(keyBox) para senhas ou campos similiares)
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
/*
* Configurable variables. You may need to tweak these to be compatible with
* the server-side, but the defaults work in most cases.
*/
var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */

/*
* These are the functions you'll usually want to call
* They take string arguments and return either hex or base-64 encoded strings
*/
function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }

/*
* Perform a simple self-test to see if the VM is working
*/
function md5_vm_test()
{
  return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
}

/*
* Calculate the MD5 of an array of little-endian words, and a bit length
*/
function core_md5(x, len)
{
  /* append padding */
  x[len >> 5] |= 0x80 << ((len) % 32);
  x[(((len + 64) >>> 9) << 4) + 14] = len;

  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;

    a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
    d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
    c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
    b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
    a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
    d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
    c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
    b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
    a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
    d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
    c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
    b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
    a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
    d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
    c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
    b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);

    a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
    d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
    c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
    b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
    a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
    d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
    c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
    b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
    a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
    d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
    c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
    b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
    a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
    d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
    c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
    b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);

    a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
    d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
    c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
    b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
    a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
    d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
    c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
    b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
    a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
    d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
    c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
    b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
    a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
    d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
    c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
    b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);

    a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
    d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
    c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
    b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
    a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
    d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
    c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
    b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
    a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
    d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
    c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
    b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
    a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
    d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
    c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
    b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);

    a = safe_add(a, olda);
    b = safe_add(b, oldb);
    c = safe_add(c, oldc);
    d = safe_add(d, oldd);
  }
  return Array(a, b, c, d);

}

/*
* These functions implement the four basic operations the algorithm uses.
*/
function md5_cmn(q, a, b, x, s, t)
{
  return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
}
function md5_ff(a, b, c, d, x, s, t)
{
  return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t)
{
  return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t)
{
  return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t)
{
  return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}

/*
* Calculate the HMAC-MD5, of a key and some data
*/
function core_hmac_md5(key, data)
{
  var bkey = str2binl(key);
  if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);

  var ipad = Array(16), opad = Array(16);
  for(var i = 0; i < 16; i++)
  {
    ipad[i] = bkey[i] ^ 0x36363636;
    opad[i] = bkey[i] ^ 0x5C5C5C5C;
  }

  var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
  return core_md5(opad.concat(hash), 512 + 128);
}

/*
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
* to work around bugs in some JS interpreters.
*/
function safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

/*
* Bitwise rotate a 32-bit number to the left.
*/
function bit_rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}

/*
* Convert a string to an array of little-endian words
* If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
*/
function str2binl(str)
{
  var bin = Array();
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < str.length * chrsz; i += chrsz)
    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
  return bin;
}

/*
* Convert an array of little-endian words to a string
*/
function binl2str(bin)
{
  var str = "";
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < bin.length * 32; i += chrsz)
    str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
  return str;
}

/*
* Convert an array of little-endian words to a hex string.
*/
function binl2hex(binarray)
{
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i++)
  {
    str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
           hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
  }
  return str;
}

/*
* Convert an array of little-endian words to a base-64 string
*/
function binl2b64(binarray)
{
  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i += 3)
  {
    var triplet = (((binarray[i   >> 2] >> 8 * ( i   %4)) & 0xFF) << 16)
                | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
                |  ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
    for(var j = 0; j < 4; j++)
    {
      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
    }
  }
  return str;
}

//------------------------------------------------------------------------------------------------------------------------------------------------------------------
-->
