	
	// UNIT DE FUNCOES JAVASCRIPT PARA TODAS AS PAGINAS
	window.status = "SISTEMA: LESTCRED SERVICOS LTDA";
	function mOvr(src,clrOver) {
		if (!document.getElementById(src).contains(event.fromElement)) {
			document.getElementById(src).style.cursor = 'hand';
			document.getElementById(src).bgColor = '#FFFFFF';
			document.getElementById(src).children.tags('A')[0].style.color = '#FF0000';
		}
	}
	function mOut(src,clrIn) {
		if (!document.getElementById(src).contains(event.toElement)) {
			document.getElementById(src).style.cursor = 'default';
			document.getElementById(src).bgColor = clrIn;//'#99CCFF';
			document.getElementById(src).children.tags('A')[0].style.color = '#000000';
		}
	}
	function mClk(src) {
		if(event.srcElement.tagName=='TD'){
			document.getElementById(src).children.tags('A')[0].click();
		}
	}
	function mObjOvr(obj,cor){
		document.getElementById(obj).style.background = cor; 
	}
	function mObjOut(obj,cor){
		document.getElementById(obj).style.background = cor;
	}
	
	function nCharEsq(xString,nChar){
		sString = xString;
		for (var i=0; i<nChar;i++){
			sString = "0"+sString;
			//alert(sString);
		}
		nString = sString.substring(sString.length - nChar, sString.length);
		return nString;
		//alert(nString);
	}
	// FUNCOES CPF
	function mascara_cpf(obj, e){
		var keypress = (window.event) ? e.keyCode : e.which;
		if (keypress == 8){
			return true;
		}else{
			so_numero(obj);
			if (obj.value.length < 14){
				if (obj.value.length == 3)
				   obj.value = obj.value + '.';
				if (obj.value.length == 7)
				   obj.value = obj.value + '.';
				if (obj.value.length == 11)
				   obj.value = obj.value + '-';
			}else event.returnValue = false;
		}
	}
	function mascara_cpf1(cpf){
		var mycpf = '';
		mycpf = mycpf + cpf.value;
		if (mycpf.length == 3){
			mycpf = mycpf + '.';
			cpf.value = mycpf;
		}
		if (mycpf.length == 7){
			mycpf = mycpf + '.';
			cpf.value = mycpf;
		}
		if (mycpf.length == 11){
			mycpf = mycpf + '-';
			cpf.value = mycpf;
		}
	}
	function mascara_cpfx(cpfx){
		var mycpfx = '';
		var auxcpf = '';
		mycpfx = cpfx.value;
		if (mycpfx != ''){
			auxcpf = mycpfx.replace('.','');
			auxcpf = auxcpf.replace('.','');
			auxcpf = auxcpf.replace('.','');
			auxcpf = auxcpf.replace('-','');
			mycpflen = auxcpf.length;
			mycpfx = auxcpf.substr(mycpflen-11, 3)+'.'+auxcpf.substr(mycpflen-8, 3)+'.'+auxcpf.substr(mycpflen-5, 3)+'-'+auxcpf.substr(mycpflen-2, 2);
			return cpfx.value = mycpfx;
		}
	}
	function f_cpf(pcpf){
		pcpf = pcpf.replace('.',''); // CPF 000.000.000-00
		pcpf = pcpf.replace('.',''); 
		pcpf = pcpf.replace('-','');
		if (pcpf.length != 11){
			sim=false
		}else{
			sim=true
		}
		//verifica se os numeros digitados são iguais
		if (sim){
			i = 1;
			while(pcpf.charAt(i) == pcpf.charAt(i -1) && i < 10){
			i++;
			}
			if(i == 10) sim=false
			else sim=true
		}
		if (sim){
			for (i=0; i<=(pcpf.length-1) && sim; i++){
				val = pcpf.charAt(i)
				if((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4")&&(
				val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {sim=false}
			}
			if (sim){
				soma = 0
				for (i=0;i<=8;i++){
					val = eval(pcpf.charAt(i))
					soma = soma + (val*(i+1))
				}
				resto = soma % 11
				if (resto>9) dig = resto -10
				else dig = resto
				if (dig != eval(pcpf.charAt(9))) { sim=false }
				else{
					soma = 0
					for (i=0;i<=7;i++){
						val = eval(pcpf.charAt(i+1))
						soma = soma + (val*(i+1))
					}
					soma = soma + (dig * 9)
					resto = soma % 11
					if (resto>9) dig = resto -10
					else dig = resto
					if (dig != eval(pcpf.charAt(10))) { sim = false }
					else sim = true
				}
			}
		}
		if (sim) {
			//alert("CPF Ok");
			return true;
		}
		else {
			return false;
			//alert("CPF inválido");
		}
	}
	function valida_cpf(obj, xDestino, ORI_CAD, COD_GRU){
		if (obj.value != ''){
			if(f_cpf(obj.value)){
				if (xDestino == "DIS"){
					iPrinc.location.href = "iframe-verifica-cpf.php?gCPF="+obj.value+"&gPESSOA=F&ORI_CAD="+ORI_CAD+"&cod_gru="+COD_GRU;
				}
				if (xDestino == "LOJ"){
					iPrinc.location.href = "iframe-verifica-lojas.php?gCPF="+obj.value+"&gPESSOA=F&ORI_CAD="+ORI_CAD;
				}
				if (xDestino == "CAD"){
					iPrinc.location.href = "iframe-verifica-cpf-cadastro.php?gCPF="+obj.value+"&gPESSOA=F&ORI_CAD="+ORI_CAD;
				}
				if (xDestino == "EMP"){
					iPrinc.location.href = "iframe-verifica-empresas.php?gCPF="+obj.value+"&gPESSOA=F&ORI_CAD="+ORI_CAD;
				}
				tbLupa.style.display = '';
			}else{
				alert('Este CPF ['+obj.value+'] não é válido');
				obj.focus();
				obj.value = '';					
				return false;
			}
		}
	}
	//  FIM CPF
	//  FUNCOES CNPJ
	function valida_cnpj(nCNPJ, xDestino, ORI_CAD, COD_GRU){
		if (nCNPJ.value != ''){
			if(v_cnpj(nCNPJ.value)){
				if (xDestino == "DIS"){
					iPrinc.location.href = "iframe-verifica-cpf.php?gCPF="+nCNPJ.value+"&gPESSOA=J&ORI_CAD="+ORI_CAD+"&cod_gru="+COD_GRU;
				}
				if (xDestino == "LOJ"){
					iPrinc.location.href = "iframe-verifica-lojas.php?gCPF="+nCNPJ.value+"&gPESSOA=J&ORI_CAD="+ORI_CAD;
				}
				if (xDestino == "EMP"){
					iPrinc.location.href = "iframe-verifica-empresas.php?gCPF="+nCNPJ.value+"&gPESSOA=J&ORI_CAD="+ORI_CAD;
				}
				tbLupa.style.display = '';
			}else{
				alert('Este CNPJ ['+nCNPJ.value+'] não é válido');
				nCNPJ.focus();
				nCNPJ.value = '';
				return false;
			}
		}
	}
	function v_cnpj(campo) {
		erro = new String;
		if (campo.length == 18){
			//substituir os caracteres que não são números
			if(document.layers && parseInt(navigator.appVersion) == 4){
				x = campo.substring(0,2);
				x += campo.substring (3,6);
				x += campo.substring (7,10);
				x += campo.substring (11,15);
				x += campo.substring (16,18);
				campo = x; 
			} else {
				campo = campo.replace (".","");
				campo = campo.replace (".","");
				campo = campo.replace ("-","");
				campo = campo.replace ("/","");
			}
			var nonNumbers = /\D/;
			if (nonNumbers.test(campo)) erro += "A verificação de CNPJ suporta apenas números! \n\n"; 
			var a = [];
			var b = new Number;
			var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
			for (i=0; i<12; i++){
				a[i] = campo.charAt(i);
				b += a[i] * c[i+1];
			}
			if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
			b = 0;
			for (y=0; y<13; y++) {
				b += (a[y] * c[y]); 
			}
			if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
			if ((campo.charAt(12) != a[12]) || (campo.charAt(13) != a[13])){
				erro +="Dígito verificador com problema!";
			}
			if (erro.length > 0){
				//alert(erro);
				return false;
			}else return true;
		}else{
			//alert('O CNPJ [ '+campo.value+' ] está incorreto.');
			//campo.focus();
			return false;
		}
	}
	
	function mascara_cnpj(obj,e){
		var keypress = (window.event) ? e.keyCode : e.which;
		if (keypress == 8){
			return true;
		}else{
			so_numero(obj);
			if (obj.value.length < 18){
				if (obj.value.length == 2)
				   obj.value = obj.value + '.';
				if (obj.value.length == 6)
				   obj.value = obj.value + '.';
				if (obj.value.length == 10)
				   obj.value = obj.value + '/';
				if (obj.value.length == 15)
				   obj.value = obj.value + '-';
			}else event.returnValue = false;
		}
	}	
	function mascara_cnpjx(cnpjx){
		var mycnpj = '';
		var auxcnpj = '';
		mycnpj = cnpjx.value;
		if (mycnpj != ''){
			auxcnpj = mycnpj.replace('.','');
			auxcnpj = auxcnpj.replace('.','');
			auxcnpj = auxcnpj.replace('.','');
			auxcnpj = auxcnpj.replace('/','');
			auxcnpj = auxcnpj.replace('-','');
			//alert(auxfone);
			mycnpjlen = auxcnpj.length;
			//alert(auxfone.substr(myfonelen-4, 4));
			//142.389.11806
			//01234567000102
			mycnpj = auxcnpj.substr(mycnpjlen-14, 2)+'.'+auxcnpj.substr(mycnpjlen-12, 3)+'.'+auxcnpj.substr(mycnpjlen-9, 3)+'/'+auxcnpj.substr(mycnpjlen-6, 4)+'-'+auxcnpj.substr(mycnpjlen-2, 2);
			cnpjx.value = mycnpj;
			if (!v_cnpj(cnpjx)){ 
				alert('CNPJ ['+mycnpj+'] inválido');
				cnpjx.value = '';
				cnpjx.focus();
				return false;
			}
		}
	}
	//  FIM CNPJ	
	
	function mascara_fone(obj,e){
		so_numero(obj);
		if (navigator.userAgent.indexOf('IE') != -1){
			var keypress = window.event.keyCode;
			if (obj.value.length < 14){
			//alert(obj.value.length);
				if (obj.value.length == 1)
				   obj.value = '(' + obj.value;
				if (obj.value.length == 3)
				   obj.value = obj.value + ') ';
				if (obj.value.length == 9)
				   obj.value = obj.value + '-';
			}else event.returnValue = false;
		}else{
			lineaux = obj.value;
			var keypress = e.which;
			if (keypress == 9)
				return true;
			if ((keypress < 48 || keypress > 57) || obj.value.length >= 14)
				return false;
			if (lineaux.length == 1)
				lineaux = '(';
			if (lineaux.length == 3)
				lineaux = lineaux + ') ';
			if (lineaux.length == 9)
				lineaux = lineaux + '-';
			lineaux = lineaux + (keypress - 48);
			obj.value = lineaux;
			return false;
		}
		return true;
	}
	function mascara_fonex(fonex){
		var myfonex = '';
		var auxfone = '';
		myfonex = '0000000000'+fonex.value;
		if (myfonex != ''){
			auxfone = myfonex.replace('-','');
			auxfone = auxfone.replace(' ','');
			auxfone = auxfone.replace(')','');
			auxfone = auxfone.replace('(','');
			//alert(auxfone);
			myfonelen = auxfone.length;
			//alert(auxfone.substr(myfonelen-4, 4));
			myfonex = '('+auxfone.substr(myfonelen-10, 2)+') '+auxfone.substr(myfonelen-8, 4)+'-'+auxfone.substr(myfonelen-4, 4);
			return fonex.value = myfonex;
		}
	}
	function mascara_cep(obj,e){		
		var keypress = (window.event) ? e.keyCode : e.which;
		if (keypress == 8){
			return true;
		}else{
			so_numero(obj);
			if (obj.value.length < 9){
				if (obj.value.length == 5)
				   obj.value = obj.value + '-';
			}else event.returnValue = false;
		}
	}  
	function mascara_cepx(cepx){
		var mycepx = '';
		var auxcep = '';
		mycepx = cepx.value;
		if (mycepx != ''){
			auxcep = mycepx.replace('-','');
			//alert(auxcep);
			myceplen = auxcep.length;
			//alert(auxfone.substr(myfonelen-4, 4));
			mycepx = auxcep.substr(myceplen-8, 5)+'-'+auxcep.substr(myceplen-3, 3);
			return cepx.value = mycepx;
		}
	}
	function f_ValidaCliCod(nContrato){
		//alert(nClicod);
		if (nContrato != ''){
			fCadastro.txtContCod.value = nCharEsq(nContrato,8);
			tbLupa.style.display = '';
			iPrinc.location.href = "iframe-valida-contrato.php?sOrigem=VALCONT&sContrato="+nContrato;
		}
	}
	function f_SeleciontaPai(cValor){
		//alert(cValor);
		if (cValor != 0){
			Valor = cValor.split("#");
	
			fCadastro.txtContPai.value 		= Valor[0]; // contrato pai
			fCadastro.hidCodPai.value 		= Valor[0]; // Codigo Pai
			fCadastro.txtCodFranq.value 	= Valor[0]; // Codigo de Franquia
			fCadastro.txtNomeDistPai.value 	= Valor[2]; // Nome do Distribuidor Pai
			aMeta = Valor[3]; // Atingiu meta S ou N
			cPaiH = Valor[4]; // Codigo do Pai dos Primeiros
			nPaiH = Valor[5]; // Nome do Pai dos Primeiros
			fCadastro.hidCodHer.value 		= Valor[6]; // Codigo Pai
			tDist = Valor[7]; // Tipo de distribuidor
			fCadastro.hidCodDdr.value 		= Valor[8]; // Codigo Pai
			if ((fCadastro.txtTipDis[0].checked)&&(tDist == 'RV')){
				alert('O Pai selecionado não é um [ DD ]\nEste descendente será gravado como [ RV ]');
			}
			if (tDist == 'RV'){
				fCadastro.txtTipDis[1].checked = true;
			}
			if ((aMeta == 'N')&&(fCadastro.txtTipDis[0].checked)){
				alert('ATÊNÇÃO: \n\n O Distribuidor escolhido não atingiu a meta de subir duas pessoas. \n '
					+'O registro será cadastrado para seu ascendente:\n [ '+nPaiH+' ]');
				fCadastro.txtContPai.value 		= cPaiH;
				fCadastro.hidCodPai.value 		= cPaiH;
				fCadastro.txtNomeDistPai.value 	= nPaiH;
				fCadastro.hidCodDdr.value 		= cPaiH;				
			}
			//fCadastro.txtContCod.focus();
			fCadastro.CPF_CNPJ.focus();
			iframeCombo.style.display 		= 'none';
			fCadastro.txtComboNome.value 	= '0';
			return true;
		}else{
			fCadastro.txtContPai.value 		= ''; // contrato pai
			fCadastro.txtCodFranq.value 	= ''; // Codigo de Franquia
			fCadastro.txtNomeDistPai.value 	= ''; // Nome do Distribuidor Pai
			//fCadastro.hidCadPor.value 		= ''; // Codigo Pai
			top.iframeCombo.style.display 	= '';
			fCadastro.txtComboNome.focus();
			alert('Escolha um distribuidor.');
			return false;
		}
	}
	function abre_janela(wLink, wNome, wW, wH, wS){
		s = ",width="+wW+",height="+wH+",scrollbars="+wS;
		xWindow = window;		
		xWindow = window.open( wLink , wNome, "fullscreen=0,toolbar=0,location=0,directories=0,status=1,menubar=0,resizable=1,modal=yes"+s);
		var xLargura = window.screen.width;
		var xAltura = window.screen.height;
		var Esquerda = ((xLargura / 4) - (wW / 4));
		var Topo = ((xAltura / 4) - (wH / 4));
		xWindow.moveTo(Esquerda, Topo);
		xWindow.focus();
		return xWindow;
	}
	
	function abre_janela_menu(wLink, wNome, wW, wH, wS){
		s = ",width="+wW+",height="+wH+",scrollbars="+wS;
		xWindow = window;		
		xWindow = window.open( wLink , wNome, "fullscreen=0,toolbar=0,location=0,directories=0,status=1,menubar=1,resizable=0,modal=yes"+s);
		var xLargura = window.screen.width;
		var xAltura = window.screen.height;
		var Esquerda = ((xLargura / 4) - (wW / 4));
		var Topo = ((xAltura / 4) - (wH / 4));
		xWindow.moveTo(Esquerda, Topo);
		xWindow.focus();
		return xWindow;
	}
	
	function abre_janela_externa(wLink, wNome, wW, wH, wS){
		s = ",width="+wW+",height="+wH+",scrollbars="+wS;
		xWindow = window;
		var xLargura = window.screen.width;
		var xAltura = window.screen.height;
		var Esquerda = 2;//;((xLargura / 5) - (wW / 5));
		var Topo = 2;//((xAltura / 5) - (wH / 5));		
		xWindow = window.open( wLink , wNome, "fullscreen=0,toolbar=0,location=0,directories=0,status=1,menubar=0,resizable=1,modal=yes"+s);
		//xWindow.moveTo(Esquerda, Topo);
		xWindow.focus();
		return xWindow;
	}	

	function pega_dist(pagina){
		xNome = fCadastro.txtNomeDistPai.value; 
		var nItens = fCadastro.txtComboNome.options.length;
		if (!xNome == ''){ 
			for (var j = nItens; j > 0; j--){
			//alert(nItens);
				//fCadastro.txtComboNome.options.remove(j);
				fCadastro.txtComboNome.options[j] = null;
			}
			//alert('iframe-pega-distribuidores.php?sOrigem=PEGADIST&sNomeDist='+fCadastro.txtNomeDistPai.value);
			tbLupa.style.display = '';
			iPrinc.location.href = 'iframe-pega-distribuidores.php?sOrigem=PEGADIST&sNomeDist='+xNome;
			return true;
		}else{
			//alert('Por favor, coloque ao menos uma parte do nome do distribuidor Pai');
			//fCadastro.txtNomeDistPai.focus();
			return false;
		}
	}
	function mascara_data(obj){
		if (navigator.userAgent.indexOf('IE') != -1){
			var keypress = window.event.keyCode;
			if (keypress == 8){
				return true;
			}else{
				so_numero(obj);
				if(obj.value.length == 2 || obj.value.length == 5){
					obj.value += '/'; 
					return false;
				}else event.returnValue = false;
			}
		}else{
			//var keypress = e.which;
			if (keypress == 8){
				return true;
			}else{
				so_numero(obj);
				if(obj.value.length == 2 || obj.value.length == 5){
					obj.value += '/'; 
					return false;
				}else event.returnValue = false;
			}
		}
	}
	function valida_data(campo){
		if (campo.value != ''){
			DataOk = 'S';
			barras = campo.value.split('/');
			if (barras.length == 3){
				dia = barras[0];
				mes = barras[1];
				ano = barras[2];
				resultado = contadia(mes,dia,ano);
				if (!resultado) {
					campo.select();
					return false;
				}else return DataOk;
			}else{
				alert('Por favor coloque uma data válida !');
				campo.select();
				return false;
			}
		}
	}
	function contadia(nMes,nDias,nAno){
		if((nMes == 1) && (nDias < 1 || nDias > 31)){
			alert('Mes de Janeiro possue 31 dias.');
			return false; 
		}else{
			if((nMes == 2) && (nDias < 1 || nDias > 29)){
				alert('Mes de Fevereiro possue 28 ou 29 dias.');
				return false; 
			}else{
				if((nMes == 3) && (nDias < 1 || nDias > 31)){
					alert('Mes de Março possue 31 dias.');
					return false; 
				}else{
					if((nMes == 4) && (nDias < 1 || nDias > 30)){
						alert('Mes de Abril possue 30 dias.');
						return false; 
					}else{
						if((nMes == 5) && (nDias < 1 || nDias > 31)){
							alert('Mes de Maio possue 31 dias.');
							return false; 
						}else{
							if((nMes == 6) && (nDias < 1 || nDias > 30)){
								alert('Mes de Junho possue 30 dias.');
								return false; 
							}else{
								if((nMes == 7) && (nDias < 1 || nDias > 31)){
									alert('Mes de Julho possue 31 dias.');
									return false; 
								}else{
									if((nMes == 8) && (nDias < 1 || nDias > 31)){
										alert('Mes de Agosto possue 31 dias.');
										return false; 
									}else{
										if((nMes == 9) && (nDias < 1 || nDias > 30)){
											alert('Mes de Setembro possue 30 dias.');
											return false; 
										}else{
											if((nMes == 10) && (nDias < 1 || nDias > 31)){
												alert('Mes de Outubro possue 31 dias.');
												return false; 
											}else{
												if((nMes == 11) && (nDias < 1 || nDias > 30)){
													alert('Mes de Novembro possue 30 dias.');
													return false; 
												}else{
													if((nMes == 12) && (nDias < 1 || nDias > 31)){
														alert('Mes de Dezembro possue 31 dias.');
														return false; 
													}else{
														if (nMes < 1 || nMes > 12){
															alert('O número de Mês deve estar entre 1 e 12.');
														}else{
															if (ano.length != 4){
																	alert('O formato do Ano é de 4 dígitos.');
															}else{
															return true;
															}  // Ano
														}  // Mes
													}  // 01
												}  // 02
											}  // 03
										}  // 04
									}  // 05
								}  // 06
							}  // 07
						}  // 08
					}  // 09
				} // 10
			} // 11
		} // 12
	}
	function JanelaMasterFocus(){
		if(confirm('Deseja fechar esta janela ?')){
			window.close();
			window.opener.focus();
			//return true;
		}
	}
	// Verifica se ja exite o valor na base de dados 
	function valida_campo(xTabela, xTabCam, xForCam){
		if (xForCam.value != ""){
			tbLupa.style.display = '';
			iPrinc.location.href='cl-adm-verifica-duplicidade.php?'
				+'sOrigem=VALIDA'
				+'&sTabela='+xTabela
				+'&sTabCam='+xTabCam
				+'&sNomCam='+xForCam.name
				+'&sForCam='+xForCam.name
				+'&sValCam='+xForCam.value;
		}
	}
	// Verifica se é numero
	function so_numero(nCampo){
		nCampo.style.background='#FFFFFF';
		var nAux = '';
		nAux = nAux + nCampo.value;
		//nAux = nValor.value;
		if ((nAux != '')&&(isNaN(nAux.substr(nAux.length-1,1)))){
			alert('Digite somente números neste campo !'
				+'\n\nPara CPF utilize o formato [ 12345678900 ] '
				+'\nPara CNPF utilize o formato [ 12345678912345 ] '
				+'\nPara Data utilize o formato [ 01012001 ] '
				+'\nPara CEP utilize o formato [ 00000000 ] '
				+'\nPara Endereço utilize o [ COMPLEMENTO ] '
				+'\nPara Telefone utilize o formato [ 0012345678 ] ');
			nCampo.value = '';
			nCampo.focus();
			nCampo.style.background='#FFCCCC';
			return false;
		}
	}
	// Verifica se é numero
	function valor_moeda(nCampo){
		nCampo.style.background='#FFFFFF';
		var nAux = '';
		nAux = nAux + nCampo.value;
		if ((nAux != '')&&((isNaN(nAux.substr(nAux.length-1,1)))&&(nAux.substr(nAux.length-1,1)!=','))){
			alert('O formato para este campo é 1000,00');
			nCampo.value = '';
			nCampo.focus();
			nCampo.style.background='#FFCCCC';
			return false;
		}
	}
	function check_data(field){ 
		var checkstr = "0123456789";	var DateField = field;	var Datevalue = ""; 
		var DateTemp = "";				var seperator = "/";	var day; 
		var month;						var year;				var leap = 0; 
		var err = 0;					var i;					err = 0; 
		
		field.style.background='#FFFFFF';
		DateValue = DateField.value; 
		if (DateField.value == '') 
			return false;
		for (var i = 0; i < DateValue.length; i++) { /* Deleta todos os caracteres exceto 0..9 */
			if (checkstr.indexOf(DateValue.substr(i,1)) >= 0)
				DateTemp = DateTemp + DateValue.substr(i,1); 
		} 
		DateValue = DateTemp; 
		/* Sempre modifica a data para 8 digitos*/ 
		/* Se o ano for digitado com 2 digitos assume 20xx */ 
		if (DateValue.length == 6) 
			DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); 
		if (DateValue.length != 8)	err = 1;
		/* ano é considerado inválido se for = 0000 */ 
		year = DateValue.substr(4,4); 
		if (year == 0)	err = 1; 
		/* Validação do Mês */ 
		month = DateValue.substr(2,2); 
		if ((month < 1) || (month > 12)) err = 1; 
		/* Validação do Dia */ 
		day = DateValue.substr(0,2); 
		if (day < 1) err = 1; 
		/* Validação do ano bissexto referente ao mês de fevereiro */ 
		if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0))	leap = 1; 
		if ((month == 2) && (leap == 1) && (day > 29))	err = 1; 
		if ((month == 2) && (leap != 1) && (day > 28))	err = 1; 
		/* Validação dos outros meses */ 
		if ((day > 31) && ((month == "01") 
			|| (month == "03") || (month == "05") 
			|| (month == "07") || (month == "08") 
			|| (month == "10") || (month == "12"))) err = 1; 
		if ((day > 30) && ((month == "04") 
			|| (month == "06") || (month == "09") 
			|| (month == "11"))) err = 1; 
		/* Se não houver erro escreve a data completa no campo input com os separadores (ex. 07/01/2004) */ 
		if (err == 0) 
			DateField.value = day + seperator + month + seperator + year; 
		else { 
			/* Escreve mensagem de erro se err != 0 */
			field.style.background='#FFCCCC';
			alert("Data incorreta, por favor coloque uma data valida!"
				+"\nEx. 01/01/2001"); 
			DateField.select(); 
			DateField.focus(); 
			return false; 
		} 
	}
	document.onmousemove = function eStatus(){
		try{
			x = document.elementFromPoint(event.clientX, event.clientY);
			if (x.title != "")
				window.status = x.title;
			//else window.status = 'SISTEMA: LESTCRED SERVICOS LTDA';
		}catch(e){
			//window.status = 'SISTEMA: LESTCRED SERVICOS LTDA';
		}	
	}
	
	function jImprime(xLink, xTitulo, xW, xH){
		j = window.open(xLink , xTitulo, 'width='+xW+', height='+xH+', menubar=yes,resizable=yes');
		j.moveTo(2,2);
	}

	function mascara_cartaox(cartaox){
		var mycartaox = '';
		var auxcartao = '';
		mycartaox = cartaox.value;
		if (mycartaox != ''){
			auxcartao = mycartaox.replace('.','');
			auxcartao = auxcartao.replace('.','');
			auxcartao = auxcartao.replace('.','');
			auxcartao = auxcartao.replace('.','');
			mycartaolen = auxcartao.length;
			mycartaox = auxcartao.substr(mycartaolen-16, 4)
				+'.'+auxcartao.substr(mycartaolen-12, 4)
				+'.'+auxcartao.substr(mycartaolen-8, 4)
				+'.'+auxcartao.substr(mycartaolen-4, 4);
			return cartaox.value = mycartaox;
		}
	}
	
	String.prototype.trim = function(){
		return this.replace(/^\s*/, "").replace(/\s*$/, "");
	}
	
	function cIdade(data, dataHoje, xCPF){
	    if ((xCPF.value != '103.975.526-70')&&(xCPF.value != '113.383.927-43')){
			x = data.value.split('/');
			h = dataHoje.split('/');
		
			if(x[0] > 31 || x[1] > 12 || x[2] > h[2]){
				alert('Data de Nascimento invalida');
				data.focus();
				return false;
			}
		
			anosProvisorio = h[2] - x[2];
		
			if(h[1] < x[1]){
				anosProvisorio -= 1;
			}else{ 
				if(h[1] == x[1]){
					if(h[0] < x[0]){
						anosProvisorio -= 1;
					}
				}
			}
			if (anosProvisorio < 18){
				alert('A IDADE MINIMA PARA SER UM CONSULTOR ELLOCARD É DE 18 ANOS');
				data.focus();
				data.value = "";
				return false;
			}else return true;
		}
	}
	// FUNCOES PARA O TOOLTIP
	/**
	*
	* Javascript Tooltip
	*
	* @author Rogerio Alencar Lino Filho
	* @url http://rogeriolino.wordpress.com
	*
	*/
	/* Configuração */
	var id = "minhaTooltip";
	var background = "#000000";
	var border = "1px solid #999999";
	var display = "none";
	var font = "10px Verdana, Arial, Sans-serif";
	var color = "#ffffff";
	var marginX = 13; //distancia do mouse em x
	var marginY = 5; //distancia do mouse em y
	var opacity = 90; // 0 a 100
	var padding = "2px 5px";
	var position = "absolute";
	var _x = -10;
	var _y = -10;
	//
	function setPos(event) {
		if (document.all) {//IE
			_x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
			_y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
			_x += (window.event.clientX+marginX);
			_y += (window.event.clientY+marginY);
		} else {//Good Browsers
			_x = (event.pageX+marginX);
			_y = (event.pageY+marginY);
		}
	}
	//
	function showTip(text) {
		var t = document.getElementById(id);
		t.style.display = "block";
		document.onmousemove = function(event) {
			setPos(event);
			t.innerHTML = text;
			t.style.left = _x+"px";
			t.style.top = _y+"px";
		}
	}
	//
	function hideTip() {
		var t = document.getElementById(id).style;
		t.display = "none";
	}
	//
	function tooltip(elemento) {
		var body = document.getElementsByTagName("body");
		body = body[0];
		body.innerHTML += "<div id='"+id+"'></div>";
		var t = document.getElementById(id).style;
		t.background = background;
		t.border = border;
		t.display = display;
		t.font = font;
		t.color = color;
		t.opacity = opacity/100;
		t.filter = "alpha(opacity="+opacity+")";
		t.padding = padding;
		t.position = position;
		var links = document.getElementsByTagName(elemento);
		for (i=0; i<links.length; i++) {
			var title = links[i].getAttribute("title");
			links[i].setAttribute("class", "imagem-link");
			if (title) {
				links[i].setAttribute("tptitle", title);
				links[i].removeAttribute("title");
				links[i].onmouseover = function() { showTip(this.getAttribute("tptitle")+"<br />"); }
			} else {
				//links[i].onmouseover = function() { showTip(this.href); }
			}
			links[i].onmouseout = function() { hideTip(); }
		}
	}
	//
	//window.onload = function() {
	//	tooltip();
	//}
	// FIM DO TOOLTIP
