	function SaltaCampo (campo,prox,tammax,teclapres){
		tecla = teclapres.keyCode
		if (teclapres!=8 && teclapres!=9 && teclapres!=16){
			tam = campo.value.length	
			if (tam==tammax){			
				prox.focus();
			}
		}
	}

	function FormataHora(Campo,teclapres){
		tecla = teclapres.keyCode
		vr = Campo.value
		vr = vr.replace(".","")
		vr = vr.replace("-","")
		vr = vr.replace(":","")
		tam = vr.length + 1 
		if (tecla!=9 && tecla!=8 && tecla!=111 && tecla!=223){
			if (Campo.getAttribute("maxlength") == 5){
			if (tam==3)
				Campo.value = vr.substr(0,2) + ':' + vr.substr(5,tam);
			return;
			}
			else{
			if (tam==3)
				Campo.value = vr.substr(0,2) + ':' + vr.substr(5,tam);
			if (tam==5){
				Campo.value = vr.substr(0,2) + ':' + vr.substr(2,2) + ':' + vr.substr(5,tam)}
			}
		}
	}

	function FormataData(Campo,teclapres){
		vr = Campo.value
		vr = vr.replace(".","")
		vr = vr.replace("-","")
		vr = vr.replace("/","")
		tam = vr.length + 1 

		if (teclapres!=9 && teclapres!=8 && teclapres!=111 && teclapres!=223 && teclapres!=47){
			if (tam==3)
				Campo.value = vr.substr(0,2) + '/' + vr.substr(5,tam)
			if (tam==5){
				Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(5,tam)}
		}
	}

	function FormataValor(campo,tammax,teclapres){
		tecla = teclapres.keyCode
		vr = 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) 
		 		campo.value = vr
		 	if ((tam>2) && (tam<=5))
		 		campo.value = vr.substr(0,tam-2) + ',' + vr.substr(tam-2,tam)
		 	if ((tam>=6) && (tam<=8))
		 		campo.value = vr.substr(0,tam-5) + '' + vr.substr(tam-5,3) + ',' + vr.substr(tam-2,tam)
		 	if ((tam>=9) && (tam<=11))
		 		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))
		 		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))
		 		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)
		}		
		
	}

	function FormataCNPJ(Campo,teclapres){
		tecla = teclapres.keyCode
		vr = Campo.value
		vr = vr.replace("-", "")
		vr = vr.replace(".", "")
		vr = vr.replace("/", "")
		tam = vr.length + 1

		if (tecla!=9 && tecla!=8 && tecla!=190 && tecla!=108 && tecla!=109 && tecla!=189 && tecla!=111 && tecla!=223){
			if (tam==3)
				Campo.value = vr.substr(0,2) + '.' + vr.substr(3,tam)
			if (tam==6)
				Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(7,tam)
			if (tam == 10)
				Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(6,3) + '/' + vr.substr(9,tam)
			if (tam == 14)
				Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(6,3) + '/' + vr.substr(9,4) + '-' + vr.substr(14,tam)
		}
	}

	function FormataCEP(Campo,teclapres){
		tecla = teclapres.keyCode
		vr = Campo.value
		vr = vr.replace("-", "")
		tam = vr.length + 1

		if (tecla!=9 && tecla!=8 && tecla!=190 && tecla!=108 && tecla!=109 && tecla!=189 && tecla!=111 && tecla!=223){
			if (tam==6)
				Campo.value = vr.substr(0,5) + '-' + vr.substr(6,tam)
		}
	}

	function ValidaData(Data){
		if (Data.value != "" )	{
			if ((Data.value.indexOf("/") < 2) || (Data.value.indexOf("/",3) < 5)){
				window.alert ('Informe o campo data no padrão dd/mm/aaaa.')
				Data.focus();
				return false;
			} 
			else{	
				arrayData = new Array
				arrayData = Data.value.split("/");
				DataDia = arrayData[0];
				DataMes = arrayData[1];
				DataAno = arrayData[2];

				if (isNaN(DataDia) == true || isNaN(DataMes) == true || isNaN(DataAno) == true){
					alert('Data inválida.')
					Data.value='';
					Data.focus();
					return false;
				}
				if (DataAno > 2050 || DataAno < 1900){
					window.alert ('Ano inválido para o sistema.');
					Data.value='';
					Data.focus();
					return false;
				}
				if (DataMes>12 || DataMes<1){
					window.alert ('Mês da data inválido.')
					Data.value='';
					Data.focus();
					return false;
				}
				if (DataDia>31 || DataMes<1){
					window.alert ('Dia da data inválido.')
					Data.value='';
					Data.focus();
					return false;
				}
				if (DataMes==1){ultdia=31}
				if (DataMes==2){
					if ((DataAno % 4) == 0){
						ultdia=29
					}else{
						ultdia=28
					}
				}
				if (DataMes==3){ultdia=31}
				if (DataMes==4){ultdia=30}
				if (DataMes==5){ultdia=31}
				if (DataMes==6){ultdia=30}
				if (DataMes==7){ultdia=31}
				if (DataMes==8){ultdia=31}
				if (DataMes==9){ultdia=30}
				if (DataMes==10){ultdia=31}
				if (DataMes==11){ultdia=30}
				if (DataMes==12){ultdia=31}
				if (DataDia>ultdia || DataDia == '00'){
					window.alert ('Data inválida')
					Data.value='';
					Data.focus();
					return false;
				}
				return true
			}
		}
		return true
	}

	function FormataTelefone(Campo,teclapres){
		tecla = teclapres.keyCode
		vr = Campo.value
		vr = vr.replace("(", "")
		vr = vr.replace(")", "")
		vr = vr.replace("-", "")
		tam = vr.length

		if (tecla!=9 && tecla!=8 && tecla!=190 && tecla!=108 && tecla!=109 && tecla!=189 && tecla!=111 && tecla!=223){	
			if (tam==0)
				Campo.value = '(' + vr.substr(1,tam)
			if (tam==2)
				Campo.value = '(' + vr.substr(0,2) + ') ' + vr.substr(5,tam)
			if (tam==7)
				Campo.value = '(' + vr.substr(0,2) + ') ' + vr.substr(3,4) + '-' + vr.substr(8,tam)
		}
	}
	function VerifyText( str, chars ){
		var ret = true;
		for (i = 0; i < str.length; i++){
			for (j = 0; j < chars.length; j++){
				if (str.substr(i, 1) == chars.substr(j, 1)) ret = false;
			}
		}
		return ret;
	}

	function ChecaString( controle, chars, msg ){
		if (!VerifyText( controle.value, chars )){
			alert( msg );
			controle.focus();
			controle.select( 0, (controle.value.length - 1) );
		}
	}

	function emailCheck (email){
		/* The following variable tells the rest of the function whether or not	to verify that the address 
		ends in a two-letter country or well-known TLD.  1 means check it, 0 means don't. */
		var checkTLD=1;

		/* The following is the list of known TLDs that an e-mail address must end with. */
		var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

		/* The following pattern is used to check if the entered e-mail address	fits the user@domain format.  
		It also is used to separate the username from the domain. */
		var emailPat=/^(.+)@(.+)$/;

		/* The following string represents the pattern for matching all special	characters.  We don't want 
		to allow special characters in the address. These characters include ( ) < > @ , ; : \ " . [ ] */
		var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

		/* The following string represents the range of characters allowed in a username or domainname.  
		It really states which chars aren't allowed.*/
		var validChars="\[^\\s" + specialChars + "\]";

		/* The following pattern applies if the "user" is a quoted string (in which case, there are no rules 
		about which characters are allowed and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
		is a legal e-mail address. */
		var quotedUser="(\"[^\"]*\")";

		/* The following pattern applies for domains that are IP addresses, rather than symbolic names.  
		E.g. joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required. */
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

		/* The following string represents an atom (basically a series of non-special characters.) */
		var atom=validChars + '+';

		/* The following string represents one word in the typical username. For example, in 
		john.doe@somewhere.com, john and doe are words. Basically, a word is either an atom or quoted string. */
		var word="(" + atom + "|" + quotedUser + ")";

		// The following pattern describes the structure of the user
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

		/* The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, 
		shown above. */
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

		if (email.value!=''){
			/* Finally, let's start trying to figure out if the supplied address is valid. */

			/* Begin with the coarse pattern to simply break up user@domain into different pieces that are 
			easy to analyze. */
			var matchArray=email.value.match(emailPat);

			if (matchArray==null){
				/* Too many/few @'s or something; basically, this address doesn't even fit the general mould of 
				a valid e-mail address. */
				alert("Por favor verifique a digitação de seu Email. Você esqueceu de digitar o @ ou o que vem depois dele.");
				email.focus();
				return false;
			}
			var user=matchArray[1];
			var domain=matchArray[2];

			//Start by checking that only basic ASCII characters are in the strings (0-127).
			for (i=0; i<user.length; i++){
				if (user.charCodeAt(i)>127){
					alert("Por favor verifique a digitação de seu email. O nome do usuário, antes do simbolo @, contém caracteres inválidos como acentos, sinais ou espaços.");
					email.focus();
					return false;
				}
			}
			for (i=0; i<domain.length; i++){
				if (domain.charCodeAt(i)>127) {
					alert("Por favor verifique a digitação do seu email. Parece que há um erro no nome de seu provedor. Verifique se há epaços,acentuação ou você esqueceu de digitar a terminação.");
					email.focus();
					return false;
				}
			}

			// See if "user" is valid 
			if (user.match(userPat)==null){
				// user is not valid
				alert("Por favor verifique seu email. O nome do usuário, antes do simbolo @, contém caracteres inválidos como acentos, sinais ,espaços ou você inseriu um espaço antes de começar a digitar o email.");
				email.focus();
				return false;
			}

			/* if the e-mail address is at an IP address (as opposed to a symbolic
			host name) make sure the IP address is valid. */
			var IPArray=domain.match(ipDomainPat);
			if (IPArray!=null){
			// this is an IP address
				for (var i=1;i<=4;i++) {
					if (IPArray[i]>255) {
						alert("Por favor verifique a digitação de seu email. Este endereço IP é inválido.");
						email.focus();
						return false;
					}
				}
				return true;
			}

			// Domain is symbolic name.  Check if it's valid.
			var atomPat=new RegExp("^" + atom + "$");
			var domArr=domain.split(".");
			var len=domArr.length;
			for (i=0;i<len;i++) {
				if (domArr[i].search(atomPat)==-1) {
					alert("Por favor verifique a digitação do seu email. Parece que há um erro no nome de seu provedor. Verifique se há epaços ou acentuação.");
					email.focus();
					return false;
				}
			}

			/* domain name seems valid, but now make sure that it ends in a
			known top-level domain (like com, edu, gov) or a two-letter word,
			representing country (uk, nl), and that there's a hostname preceding 
			the domain or country. */
			if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1){
				alert("Por favor verifique a digitação do seu email. Parece que há um erro na terminação do domínio.");
				email.focus();
				return false;
			}

			// Make sure there's a host name preceding the domain.
			if (len<2){
				alert("Por favor verifique a digitação do seu email. Está faltando o provedor, depois do @ e antes do .com.br .");
				email.focus();
				return false;
			}
			
			//Verifica a digitação erronea de provedores
			var alerta='Nao';
			if(email.value.indexOf("zipmail.com")>0 && email.value.indexOf("zipmail.com.br") == -1) alerta='Sim';
			if(email.value.indexOf("bol.com")>0 && email.value.indexOf("bol.com.br") == -1) alerta='Sim';
			if(email.value.indexOf("uol.com")>0 && email.value.indexOf("uol.com.br") == -1) alerta='Sim';
			if(email.value.indexOf("zipmeil.com")>0) alerta='Sim';
			if(email.value.indexOf("hotmail.com.br")>0) alerta='Sim';
			if(email.value.indexOf("hotmeil.com")> 0) alerta='Sim';
			if(email.value.indexOf("gmail.com.br")> 0) alerta='Sim';
			if(email.value.indexOf("gmial.com")> 0) alerta='Sim';
			if(email.value.indexOf("gmeil.com") > 0) alerta='Sim';
			if (alerta=='Sim'){
				alert("Por favor verifique a digitação do seu provedor de e-mail.");
				email.focus();
				return false;
			}
			
			// If we've gotten this far, everything's valid!
			return true;
		}
	}
	//  End -->

	function ValidaCNPJ(CNPJ,campo){
		if (CNPJ.length==14){
			CNPJcompleto = CNPJ;
			parte5 = CNPJ.substring(12,14);
		}else{	
			parte1 = CNPJ.substring(0,2);
			parte2 = CNPJ.substring(3,6);
			parte3 = CNPJ.substring(7,10);
			parte4 = CNPJ.substring(11,15);
			parte5 = CNPJ.substring(16,18);
			CNPJcompleto = parte1 + parte2 + parte3 + parte4 + parte5;
		}

		CNPJ1 = CNPJcompleto;
		if(CNPJcompleto=='00000000000000'){
			alert("CNPJ inválido, favor verificar.");
			campo.focus();
			return false;
		}
		CNPJ2 = parte5;
		fluxo = '543298765432';
		SOMA = 0;
		  
		for (i = 0; i <= CNPJ1.length; i++){ 
			SOMA = SOMA + CNPJ1.substring(i, i + 1) * fluxo.substring(i, i + 1);
		}  
		SOMA = SOMA * 10;
		digito1 = (SOMA % 11);
		  
		if (digito1 == 10){
			digito1 = 0;
		}  
		fluxo = '6543298765432';
		CNPJ1 = CNPJ1 + parseInt(digito1);
		SOMA = 0;
		for (i = 0; i <= CNPJ1.length; i++) {
			SOMA = SOMA + CNPJ1.substring(i, i + 1) * fluxo.substring(i, i + 1);
		}  
		SOMA = SOMA * 10;
		digito2 = (SOMA % 11);
		if (digito2 == 10){
			digito2 = 0;
		}  
		if (CNPJ2.substring(0,1) != digito1 || CNPJ2.substring(1,2) != digito2){
			alert("CNPJ inválido, favor verificar.");
			campo.focus();
			return false;
		}else{
		    return true;
		}	    
	}
	
	function FormataCPF(Campo,teclapres){
		//alert(entrou);
		tecla = teclapres.keyCode
		vr = Campo.value
		vr = vr.replace("-","")
		vr = vr.replace(".","")
		vr = vr.replace("/","")
		tam = vr.length + 1

		if (tecla!=9 && tecla!=8 && tecla!=190 && tecla!=108 && tecla!=109 && tecla!=189){
			if (tam==4)
				Campo.value = vr.substr(0,3) + '.' + vr.substr(4,tam)
			if (tam==7)
				Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam)
			if (tam==11)
				Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(7,3) + '-' + vr.substr(10,tam)
		}
	}
	
	function ValidaCPF(cpf){
		var CPF, numeros, digitos, soma, i, resultado, digitos_iguais;
		CPF=cpf.value;
		CPF=CPF.replace(".","");
		CPF=CPF.replace(".","");
		CPF=CPF.replace("-","");
		digitos_iguais = 1;
		if (CPF.length < 11){
		    alert("CPF inválido, favor verificar.");
		    cpf.focus();
			return false;
		}else{
		    for (i = 0; i < CPF.length - 1; i++){
			    if (CPF.charAt(i) != CPF.charAt(i + 1)){
				    digitos_iguais = 0;
				    break;
			    }
			}
		    if (CPF!='00000000001'){
		        if (!digitos_iguais){
			        numeros = CPF.substring(0,9);
			        digitos = CPF.substring(9);
                    soma = 0;
                    for (i = 10; i > 1; i--)
				        soma += numeros.charAt(10 - i) * i;
                    resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
                    if (resultado != digitos.charAt(0)){
				        alert("CPF inválido, favor verificar.");
				        cpf.focus();
				        return false;
			        }
			        numeros = CPF.substring(0,10);
                    soma = 0;
			        for (i = 11; i > 1; i--)
				        soma += numeros.charAt(11 - i) * i;
                    resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
                    if (resultado != digitos.charAt(1)){
				        alert("CPF inválido, favor verificar.");
				        cpf.focus();
				        return false;
			        }
			        return true;
		        }else{
			        alert("CPF inválido, favor verificar.");
			        cpf.focus();
			        return false;
		        }
		    }
		}
	}