	function frmField(obj,format){				
		str = new String(obj.value);
		frm = new String(format);	
				
		out = '';		
		pic = '';
		for(i=0;i<str.length;i++){			
			if(str.charAt(i)>='0' && str.charAt(i)<='9'){
				out += str.charAt(i);
			}else{
				pic += str.charAt(i);
			}
		}
		
		if(!isNaN(out)){
			str = out;
		
			out = '';		
			j=1;		
			for(i=0;i<=frm.length;i++){
				if(frm.charAt(frm.length-i)==' ' && j<=str.length){
					out = str.charAt(str.length-j++) + out;				
				}
				else{				
					//if(pic.indexOf(frm.charAt(frm.length-i))!=-1){ 
						out = frm.charAt(frm.length-i) + out;			
					//}
				}
			}			
					
			obj.value = out.toString(out,2,true);
		}else{
			out = str.toString(str,2,true);
		}		
		return true;
	}
	
	
	function isDate(date) {

		var i;
		var cont;
		var str = new String(date);
		var len = str.length;
		
		var sMonth = new String();
		var sDay = new String();
		var sYear = new String();
		var iMonth;
		var iDay;
		var iYear;
		var bBissexto = false;
		var foundnumber = false;
		
		for (i = 0, cont = 0 ; i < len; i++) {
						
			if (str.substr(i, 1) == '/') {
			
				if (cont == 2) {
				
					return false;
				}
				
				cont++;
				foundnumber = false;
				continue;
			}
			
			
			//eliminates '0'(zeros) from leftside
			
			if (!(foundnumber)){

				if (str.substr(i, 1) == '0') {
				
					continue;
				}
				  
				else {
					foundnumber = true;
				}
			}
			
			
			if (cont == 1) {

					sMonth += str.substr(i, 1);
			}
			else if (cont == 0) {
			
					sDay += str.substr(i, 1);
			}
			else if (cont == 2) {
			
					sYear += str.substr(i, 1);
			}
		}
		
		
		if (sYear.length != 4) {
		
			return false;
		}
		
		if (cont < 2) {
		
			return false;
		}
		
		for (i = 0; i < sMonth.length; i++) {
		
			if ((sMonth.substr(i, 1) < '0') || (sMonth.substr(i, 1) > '9')) {
			
				return false;
			}
		}

		for (i = 0; i < sDay.length; i++) {
		
			if ((sDay.substr(i, 1) < '0') || (sDay.substr(i, 1) > '9')) {
			
				return false;
			}
		}

		for (i = 0; i < sYear.length; i++) {
		
			if ((sYear.substr(i, 1) < '0') || (sYear.substr(i, 1) > '9')) {
			
				return false;
			}
		}


		iMonth = parseInt(sMonth);
		iDay   = parseInt(sDay);
		iYear  = parseInt(sYear);
		
		if (isNaN(iMonth) || isNaN(iDay) || isNaN(iYear)) {
		    
		    return false;
		}

		
		bBissexto = ((iYear % 4) == 0) ? true : false;
			
		if ((iMonth < 1) || (iMonth > 12)) {
				
			return false;
		}
			
		if (iDay < 1) {
				
			return false;
		}
			
		if (iMonth == 2) {
			
			if (bBissexto) {
				
				if (iDay > 29) {
						
					return false;
				}
			}
			else {
					
				if (iDay > 28) {
					
					return false;
				}
			}
		}
			
		if ((iMonth ==  1) ||
		    (iMonth ==  3) ||
		    (iMonth ==  5) ||
		    (iMonth ==  7) ||
		    (iMonth ==  8) ||
		    (iMonth == 10) ||
		    (iMonth == 12)) {
			
			if (iDay > 31) {
				
				return false;
			}
		}
			
		if ((iMonth ==  4) ||
		    (iMonth ==  6) ||
		    (iMonth ==  9) ||
		    (iMonth == 11)) {
			
			if (iDay > 30) {
				
				return false;
			}
		}
			
		return true;
	}
	
	//função que força o input para números
	function keyNumber(e) {
		//Variável que diz se é ou não Internet Explorer
		var ie = (document.all)?true:false;

		//Seta os inputs possíveis
		var strValid = "1234567890" + String.fromCharCode(8) + String.fromCharCode(13); //mais o backspace;
		
		//Busca a tecla
		if (ie) {
			var Key = String.fromCharCode(window.event.keyCode);
			event.cancelBubble = true;
		} else {
			var Key = String.fromCharCode(e.which);
		}
		
		//Verifica se a tecla é válida
		var ret = (strValid.indexOf(Key) != -1)
		
		//Retorna a função
		if (ie) {
			event.returnValue = ret;
		} else {
			return ret;
		}
	}
	

	//função que força o input para textos
	function keyText(e) {
		//Variável que diz se é ou não Internet Explorer
		var ie = (document.all)?true:false;

		//Seta os inputs possíveis
		var strValid = "ABCÇDEFGHIJKLMNOPQRSTUVXZYWabcçdefghijklmnopqrstuvxzyw!@#$%&*()-_=+]}[{/?~^´`;:.>,<áàÁÀóòÓÒíìÍÌéèÉÈúùÚÙãâÃÂõÕôÔÊêüÜëË" + String.fromCharCode(39) + String.fromCharCode(34) + String.fromCharCode(32) + String.fromCharCode(13); //mais o backspace;
		
		//Busca a tecla
		if (ie) {
			var Key = String.fromCharCode(window.event.keyCode);
			event.cancelBubble = true;
		} else {
			var Key = String.fromCharCode(e.which);
		}
		
		//Verifica se a tecla é válida
		var ret = (strValid.indexOf(Key) != -1)
		
		//Retorna a função
		if (ie) {
			event.returnValue = ret;
		} else {
			return ret;
		}
	}

	//função que força o input para números e/ou vírgulas
	function keyFloat(e) {
		//Variável que diz se é ou não Internet Explorer
		var ie = (document.all)?true:false;

		//Seta os inputs possíveis
		var strValid = "1234567890."; //mais o backspace;
		
		//Busca a tecla
		if (ie) {
			var Key = String.fromCharCode(window.event.keyCode);
			event.cancelBubble = true;
		} else {
			var Key = String.fromCharCode(e.which);
		}
		
		//Verifica se a tecla é válida
		var ret = (strValid.indexOf(Key) != -1)
		
		//Retorna a função
		if (ie) {
			event.returnValue = ret;
		} else {
			return ret;
		}
	}
	


	//função que força o input para números, espaço, parênteses e hífen
	function KeyNumber_Blank_Parenteses(e) {
		//Variável que diz se é ou não Internet Explorer
		var ie = (document.all)?true:false;

		//Seta os inputs possíveis
		var strValid = "1234567890" + String.fromCharCode(8) + String.fromCharCode(13) + String.fromCharCode(32) + String.fromCharCode(40) + String.fromCharCode(41) + String.fromCharCode(45); //mais o backspace;
		
		//Busca a tecla
		if (ie) {
			var Key = String.fromCharCode(window.event.keyCode);
			event.cancelBubble = true;
		} else {
			var Key = String.fromCharCode(e.which);
		}
		
		//Verifica se a tecla é válida
		var ret = (strValid.indexOf(Key) != -1)
		
		//Retorna a função
		if (ie) {
			event.returnValue = ret;
		} else {
			return ret;
		}
	}
	
	
	function verificaCpf(campo) {
	var CPF = campo; // Recebe o valor digitado no campo
	
	// Aqui começa a checagem do CPF
	var POSICAO, I, SOMA, DV, DV_INFORMADO;
	var DIGITO = new Array(10);
	DV_INFORMADO = CPF.substr(9, 2); // Retira os dois últimos dígitos do número informado
	
	// Desemembra o número do CPF na array DIGITO
	for (I=0; I<=8; I++) {
	  DIGITO[I] = CPF.substr( I, 1);
	}
	
	// Calcula o valor do 10º dígito da verificação
	POSICAO = 10;
	SOMA = 0;
	   for (I=0; I<=8; I++) {
	      SOMA = SOMA + DIGITO[I] * POSICAO;
	      POSICAO = POSICAO - 1;
	   }
	DIGITO[9] = SOMA % 11;
	   if (DIGITO[9] < 2) {
	        DIGITO[9] = 0;
	}
	   else{
	       DIGITO[9] = 11 - DIGITO[9];
	}
	
	// Calcula o valor do 11º dígito da verificação
	POSICAO = 11;
	SOMA = 0;
	   for (I=0; I<=9; I++) {
	      SOMA = SOMA + DIGITO[I] * POSICAO;
	      POSICAO = POSICAO - 1;
	   }
	DIGITO[10] = SOMA % 11;
	   if (DIGITO[10] < 2) {
	        DIGITO[10] = 0;
	   }
	   else {
	        DIGITO[10] = 11 - DIGITO[10];
	   }
	
	// Verifica se os valores dos dígitos verificadores conferem
	DV = DIGITO[9] * 10 + DIGITO[10];
	   if (DV != DV_INFORMADO)
	      return false;
	   else
	   	return true;
	}
	
function formataValor(campo,tammax,teclapres,f) {
	var tecla = teclapres.keyCode;
	vr = f[campo].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 = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		f[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		f[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		f[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		f[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		f[campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		f[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}		
	
}
