/* AUTOR: Eduardo Lefevre */ /* DATA: 11/08/99 */ /* Implementa ispunct, isalpha, isdigit */ /* ispunct verifica se o caracter é pontuação ou símbolo digitável (aspa e apostrofe nao podem)*/ /* isalpha verifica se o caracter é uma letra */ /* isdigit verifica se o caracter é um número */ function ispunct(c) { if ((c == '.') || (c == ',') || (c == '-') || (c == '+') || (c == '@') || (c == '_') || (c == '"') || (c == '$') || (c == '#') || (c == '!') || (c == '%') || (c == '&') || (c == '*') || (c == '(') || (c == ')') || (c == '=') || (c == '{') || (c == '}') || (c == '[') || (c == ']') || (c == '/') || (c == '\\') || (c == ':') || (c == ';') || (c == '>') || (c == '<') || (escape(c) == '%20') ) return true; else return false; } function isalpha(c) { if (((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'))) return true; else return false; } function isdigit(c) { if ((c >= '0') && (c <= '9')) return true; else return false; } //Formata Moeda function FormataMoeda(valor, blnUnidade, pzero) { var indPontoDec; // localizacao do ponto decimal var valorLimpo = ""; // valor filtrado (apenas numeros e virgula) var cont = 0; // contador var indPonto = 0; // localizacao do último ponto var indVirgula = 0; // localizacao da última virgula var numero = "0123456789"; // domínio de dígitos válidos var qtPonto = 0; // qtde de pontos de milhar var qtResto = 0; // resto de indPontoDec / 3 var limite = 0; // limite da colocação do ponto de milhar var indzero = pzero; // Indicador se O campo pode ser zero // descobre qual o último separador que está sendo utilizado indVirgula = valor.lastIndexOf(','); indPonto = valor.lastIndexOf('.'); if (indVirgula == indPonto) indPontoDec = -1; else if (indVirgula > indPonto) indPontoDec = indVirgula; else indPontoDec = indPonto; // limpa dígitos não numéricos do valor for (cont=0; cont < valor.length; cont++) { if (numero.indexOf(valor.charAt(cont)) != -1) valorLimpo += valor.charAt(cont); // substitui ponto decimal por vírgula if (cont+1 == indPontoDec) { cont++; valorLimpo += ','; } else if ((cont==0) && (indPontoDec==0)) valorLimpo += ','; } if (valorLimpo.indexOf(",") == -1) valorLimpo += ",00"; if (valorLimpo.indexOf(",") == valorLimpo.length-1) valorLimpo += "00"; if (valorLimpo.indexOf(",") == valorLimpo.length-2) valorLimpo += "0"; // retira zeros à esquerda while (valorLimpo.charAt(0)=='0') valorLimpo = valorLimpo.substring(1, valorLimpo.length); // transforma ",xx" em "0,xx" if (valorLimpo.charAt(0)==',') valorLimpo = '0' + valorLimpo; // coloca separação de milhar indPontoDec = valorLimpo.lastIndexOf(','); qtPonto = Math.floor(indPontoDec/3); qtResto = indPontoDec%3; if (qtResto==0) limite=1; else limite=0; for (cont=qtPonto-1; cont >= limite; cont--) valorLimpo = valorLimpo.substring(0, qtResto + cont*3) + '.' + valorLimpo.substring(qtResto + cont*3, valorLimpo.length); // Se o valor for igual 0,00 coloca o campo vazio if ((valorLimpo == "0,00") && (pzero != "S")) { valorLimpo = ""; } return valorLimpo; } function FormataDecimal(valor, blnUnidade) { var indPontoDec; // localizacao do ponto decimal var valorLimpo = ""; // valor filtrado (apenas numeros e virgula) var cont = 0; // contador var indPonto = 0; // localizacao do último ponto var indVirgula = 0; // localizacao da última virgula var numero = "0123456789"; // domínio de dígitos válidos var qtPonto = 0; // qtde de pontos de milhar var qtResto = 0; // resto de indPontoDec / 3 var limite = 0; // limite da colocação do ponto de milhar /* // descobre qual o último separador que está sendo utilizado indPontoDec = valor.lastIndexOf(','); // limpa dígitos não numéricos do valor for (cont=0; cont < valor.length; cont++) { if (numero.indexOf(valor.charAt(cont)) != -1) valorLimpo += valor.charAt(cont); // substitui ponto decimal por vírgula if (cont+1 == indPontoDec) { cont++; valorLimpo += '.'; } else if ((cont==0) && (indPontoDec==0)) valorLimpo += '.'; } if (valorLimpo.indexOf(".") == -1) valorLimpo += ",00"; if (valorLimpo.indexOf(".") == valorLimpo.length-1) valorLimpo += "00"; if (valorLimpo.indexOf(".") == valorLimpo.length-2) valorLimpo += "0"; // retira zeros à esquerda while (valorLimpo.charAt(0)=='0') valorLimpo = valorLimpo.substring(1, valorLimpo.length); // transforma ",xx" em "0,xx" if (valorLimpo.charAt(0)=='.') valorLimpo = '0' + valorLimpo; */ valorLimpo = valor; return valorLimpo; } function valorsemvirgula(valor) { //formata valor de 100.000,00 p/ 100000.00 temp = "" tamanho = valor.length cont = 1 for (i=0;i="0")&&(c<="9") ) { return false; } if( c!=varFirstChr ) vaCharCPF = true; } if( ! vaCharCPF ) { return false; } soma=0; for ( i=0; i<9; i++ ) { soma += (10-i) * ( eval(s.charAt(i)) ); } digito_verificador = 11-(soma % 11); if ( (soma % 11) < 2 ) digito_verificador = 0; if ( eval(s.charAt(9)) != digito_verificador ) { return false; } soma=0; for ( i=0; i<9; i++ ) { soma += (11-i) * ( eval(s.charAt(i)) ); } soma += 2 * ( eval(s.charAt(9)) ); digito_verificador = 11-(soma % 11); if ( (soma % 11) < 2 ) digito_verificador = 0; if ( eval(s.charAt(10)) != digito_verificador ) { return false; } return true; } function SoNumeros(s) { for (var i=0;i 2) return false; if (!isdigit(c) && (c != "/")) return false; } if (n_barras != 2) return false; if ( (s.indexOf("/") != 2) || (s.lastIndexOf("/") != 5) ) return false; d = s.substring(0, 2)// dia m = s.substring(3, 5)// mes a = s.substring(6, 11)// ano if (m<1 || m>12) return false; if (d<1 || d>31) return false; if ((a + "" + m + "" + d) > (teste_ano + "" + teste_mes + "" + teste_dia)) return false; if (a<1900 || a>3000) return false; if (m==4 || m==6 || m==9 || m==11) { if (d==31) return false; } // Bissexto if (m==2){ var g=parseInt(a/4) if (isNaN(g)) { return false; } if (d > 29){ return false; } if (d==29 && ((a/4)!=parseInt(a/4))){ return false; } } return true; } function DataAdmiss(s) { var i; var c; var n_barras; var data; hoje = new Date() teste_ano = hoje.getYear() teste_dia = hoje.getDate() teste_mes = hoje.getMonth() teste_mes = teste_mes + 1 if (teste_dia < 10) teste_dia = "0" + teste_dia if (teste_mes < 10) teste_mes = "0" + teste_mes if (navigator.appName=='Netscape') teste_ano= 1900 + teste_ano; n_barras = 0; if (s.length != 10) return false; for(i=0; i 2) return false; if (!isdigit(c) && (c != "/")) return false; } if (n_barras != 2) return false; if ( (s.indexOf("/") != 2) || (s.lastIndexOf("/") != 5) ) return false; d = s.substring(0, 2)// dia m = s.substring(3, 5)// mes a = s.substring(6, 11)// ano if (m<1 || m>12) return false; if (d<1 || d>31) return false; if ((a > teste_ano)||((a == teste_ano)&&(m > teste_mes))||((a == teste_ano)&&(m == teste_mes)&&(d > teste_dia))){ return false; } if (a<1900 || a>3000) return false; if (m==4 || m==6 || m==9 || m==11) { if (d==31) return false; } // Bissexto if (m==2){ var g=parseInt(a/4) if (isNaN(g)) { return false; } if (d > 29){ return false; } if (d==29 && ((a/4)!=parseInt(a/4))){ return false; } } return true; } function ValidaData(s) { var i; var c; var n_barras; var data; n_barras = 0; if (s.length != 10) return false; for(i=0; i 2) return false; if (!isdigit(c) && (c != "/")) return false; } if (n_barras != 2) return false; if ( (s.indexOf("/") != 2) || (s.lastIndexOf("/") != 5) ) return false; d = s.substring(0, 2)// dia m = s.substring(3, 5)// mes a = s.substring(6, 11)// ano if (m<1 || m>12) return false; if (d<1 || d>31) return false; if (a<1900 || a>3000) return false; if (m==4 || m==6 || m==9 || m==11) { if (d==31) return false; } // Bissexto if (m==2){ var g=parseInt(a/4) if (isNaN(g)) { return false; } if (d > 29){ return false; } if (d==29 && ((a/4)!=parseInt(a/4))){ return false; } } return true; } function ValidaCEP(s) { var i; var c; var achou; if (s.length != 9) return false; achou = false; for (i=0; i255) { return false; } } return true; } var domainArray=domain.match(domainPat) if (domainArray==null) { return false; } var atomPat=new RegExp(atom,"g") var domArr=domain.match(atomPat) var len=domArr.length if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) { return false; } if (len<2) { var errStr="This address is missing a hostname!" alert(errStr) return false; } return true; } // Obtem valor de um grupo de radio buttons de mesmo nome function ValorRadio(radio) { for (i = 0; i < radio.length; i++) if (radio[i].checked) { return radio[i].value; } return ""; } // Obtem descricao do item selecionado function GetSelectText(sel) { if(sel.selectedIndex >= 0) return sel.options[sel.selectedIndex].text; else return ""; } // Obtem valor do item selecionado function GetSelectValue(sel) { if(sel.selectedIndex >= 0) return sel.options[sel.selectedIndex].value; else return ""; } // Posiciona o select no item cujo valor eh value function PosicionaSelect(select, value) { for (var i=0; i = 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){ if ( tam <= 2 ){ document.FrmCadCli[campo].value = vr ; } if ( (tam > 2) && (tam <= 5) ){ document.FrmCadCli[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; } if ( (tam >= 6) && (tam <= 8) ){ document.FrmCadCli[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; } if ( (tam >= 9) && (tam <= 11) ){ document.FrmCadCli[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) ){ document.FrmCadCli[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) ){ document.FrmCadCli[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 SaltaCampo (campo,prox,tammax,teclapres){ var tecla = teclapres.keyCode; vr = document.FrmCadCli[campo].value; if( tecla == 109 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108 ){ document.FrmCadCli[campo].value = vr.substr( 0, vr.length - 1 ); } else{ vr = vr.replace( "-", "" ); 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 (tecla != 0 && tecla != 9 && tecla != 16 ) if ( tam == tammax ) document.FrmCadCli[prox].focus() ; } } function FormataData(Campo,teclapres) { var tecla = teclapres.keyCode; vr = document.FrmCadCli[Campo].value; vr = vr.replace( ".", "" ); vr = vr.replace( "/", "" ); vr = vr.replace( "/", "" ); tam = vr.length + 1; if ( tecla != 9 && tecla != 8 ){ if ( tam > 2 && tam < 5 ) document.FrmCadCli[Campo].value = vr.substr( 0, tam - 2 ) + '/' + vr.substr( tam - 2, tam ); if ( tam >= 5 && tam <= 10 ) document.FrmCadCli[Campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); } } //Script para validação de CPF function CPF(s) { var varFirstChr = s.charAt(0); var vaCharCPF = false; for ( var i=0; i<=10; i++ ) { var c = s.charAt(i); if( ! (c>="0")&&(c<="9") ) { alert("CPF inválido ! Preencha o CPF corretamente." ); return false; } if( c!=varFirstChr ) vaCharCPF = true; } if( ! vaCharCPF ) { alert("CPF inválido ! Preencha o CPF corretamente." ); return false; } soma=0; for ( i=0; i<9; i++ ) { soma += (10-i) * ( eval(s.charAt(i)) ); } digito_verificador = 11-(soma % 11); if ( (soma % 11) < 2 ) digito_verificador = 0; if ( eval(s.charAt(9)) != digito_verificador ) { alert("CPF inválido ! Preencha o CPF corretamente." ); return false; } soma=0; for ( i=0; i<9; i++ ) { soma += (11-i) * ( eval(s.charAt(i)) ); } soma += 2 * ( eval(s.charAt(9)) ); digito_verificador = 11-(soma % 11); if ( (soma % 11) < 2 ) digito_verificador = 0; if ( eval(s.charAt(10)) != digito_verificador ) { alert("CPF inválido ! Preencha o CPF corretamente." ); return false; } return true; } //Validação de CNPJ (CGC) function CriaArray(n) { this.length=n for (var i=1;i<=n;i++) {this[i]=""} } function CNPJ(form) { with (Math) { w = 0; Resp1 = ""; Resp2 = ""; CGC = form; VtCGC = new CriaArray(CGC.length); for (var i=0;i < CGC.length;i++) { if ((CGC.charAt(i) == "0") || (CGC.charAt(i) == "1") || (CGC.charAt(i) == "2") || (CGC.charAt(i) == "3") || (CGC.charAt(i) == "4") || (CGC.charAt(i) == "5") || (CGC.charAt(i) == "6") || (CGC.charAt(i) == "7") || (CGC.charAt(i) == "8") || (CGC.charAt(i) == "9")) { VtCGC[w]=parseFloat(CGC.charAt(i)); w++; } } Soma1 = (VtCGC[0]*5)+(VtCGC[1]*4)+(VtCGC[2]*3)+(VtCGC[3]*2)+(VtCGC[4]*9)+(VtCGC[5]*8)+(VtCGC[6]*7)+(VtCGC[7]*6)+(VtCGC[8]*5)+(VtCGC[9]*4)+(VtCGC[10]*3)+(VtCGC[11]*2)+0.0001; Divisao1 = Soma1 / 11; RestoParc1 = (Divisao1 - floor(Divisao1))*11; Resto1 = floor(RestoParc1); Soma2 = (VtCGC[0]*6)+(VtCGC[1]*5)+(VtCGC[2]*4)+(VtCGC[3]*3)+(VtCGC[4]*2)+(VtCGC[5]*9)+(VtCGC[6]*8)+(VtCGC[7]*7)+(VtCGC[8]*6)+(VtCGC[9]*5)+(VtCGC[10]*4)+(VtCGC[11]*3)+(VtCGC[12]*2)+0.0001; Divisao2 = Soma2 / 11; RestoParc2 = (Divisao2 - floor(Divisao2))*11; Resto2 = floor(RestoParc2); if (form != "00000000000000") { if (((Resto1 == 0) || (Resto1 == 1)) && (VtCGC[12] == 0)) { Resp1 = "V"; } else { Digito1 = 11 - Resto1; if ((Digito1 == VtCGC[12]) && (Resto1 > 1)) { Resp1 = "V"; } } if (((Resto2 == 0) || (Resto2 == 1)) && (VtCGC[13] == 0)) { Resp2 = "V"; } else { Digito2 = 11 - Resto2; if ((Digito2 == VtCGC[13]) && (Resto2 > 1)) { Resp2 = "V"; } } } if ((Resp1 == "V") && (Resp2 == "V")) { return true; } else { alert("CNPJ Incorreto. Preencha o campo corretamente."); return false; } } } //Validação de ValidaCNPJ (CGC) Sem mensagem de erro function ValidaCNPJ(form) { with (Math) { w = 0; Resp1 = ""; Resp2 = ""; CGC = form; VtCGC = new CriaArray(CGC.length); for (var i=0;i < CGC.length;i++) { if ((CGC.charAt(i) == "0") || (CGC.charAt(i) == "1") || (CGC.charAt(i) == "2") || (CGC.charAt(i) == "3") || (CGC.charAt(i) == "4") || (CGC.charAt(i) == "5") || (CGC.charAt(i) == "6") || (CGC.charAt(i) == "7") || (CGC.charAt(i) == "8") || (CGC.charAt(i) == "9")) { VtCGC[w]=parseFloat(CGC.charAt(i)); w++; } } Soma1 = (VtCGC[0]*5)+(VtCGC[1]*4)+(VtCGC[2]*3)+(VtCGC[3]*2)+(VtCGC[4]*9)+(VtCGC[5]*8)+(VtCGC[6]*7)+(VtCGC[7]*6)+(VtCGC[8]*5)+(VtCGC[9]*4)+(VtCGC[10]*3)+(VtCGC[11]*2)+0.0001; Divisao1 = Soma1 / 11; RestoParc1 = (Divisao1 - floor(Divisao1))*11; Resto1 = floor(RestoParc1); Soma2 = (VtCGC[0]*6)+(VtCGC[1]*5)+(VtCGC[2]*4)+(VtCGC[3]*3)+(VtCGC[4]*2)+(VtCGC[5]*9)+(VtCGC[6]*8)+(VtCGC[7]*7)+(VtCGC[8]*6)+(VtCGC[9]*5)+(VtCGC[10]*4)+(VtCGC[11]*3)+(VtCGC[12]*2)+0.0001; Divisao2 = Soma2 / 11; RestoParc2 = (Divisao2 - floor(Divisao2))*11; Resto2 = floor(RestoParc2); if (((Resto1 == 0) || (Resto1 == 1)) && (VtCGC[12] == 0)) { Resp1 = "V"; } else { Digito1 = 11 - Resto1; if ((Digito1 == VtCGC[12]) && (Resto1 > 1)) { Resp1 = "V"; } } if (((Resto2 == 0) || (Resto2 == 1)) && (VtCGC[13] == 0)) { Resp2 = "V"; } else { Digito2 = 11 - Resto2; if ((Digito2 == VtCGC[13]) && (Resto2 > 1)) { Resp2 = "V"; } } if ((Resp1 == "V") && (Resp2 == "V")) { return true; } else { return false; } } } // POP-UP de alerta (Aguarde. Consultando banco de dados...) //Liga Alerta function alertaon() { /* var alerta = window.open("/tr/econofinance/alerta.htm","alerta","z-lock=yes,fullscreen=yes, dependent=yes, alwaysRaised=yes"); alerta.resizeTo(350, 178); var width = screen.width /2 - 150; var height = screen.height /2 - 87; alerta.moveTo(width,height); */ } //Desliga o Alerta function alertaoff() { /* var alerta = window.open("/tr/econofinance/fechar.htm","alerta","width=110,height=110,fullscreen=yes, screenX=-100, screenY=300"); */ } function trim(campo,caractere){ var str = "" var temp for (var i=0;i0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i var nomeFormulario = "eval(nomeFormulario)"; function InicializarIndices() { if (document.CargaInicial==null) { document.CargaInicial=false; // Seta para só fazer uma vez por documento var ctrlAnterior=null; var IndAnt=0; for ( var i=0; i5 ) return; if ( s=="NE" && QualVersao()>4 ) return; if (ctrl.onkeypress==null) { if (AutoSkip==null) AutoSkip=true; if (Tipo!=null) Tipo.toUpperCase(); ctrl.Tam=Tam; ctrl.Tipo=Tipo; ctrl.AutoSkip=AutoSkip; ctrl.Saltar=false; InicializarIndices(); ctrl.onkeypress=ValidarTecla; if (QualNavegador()=="IE" && QualVersao()==5) ctrl.onkeyup=SaltarCampo; } } function SaltarCampo(ctrl) { if (ctrl==null) ctrl=this; if ( ctrl.AutoSkip && ctrl.Saltar) if (ctrl.Saltar) { ctrl.Saltar=false; if ( ctrl.IndicePosterior != null ) SetarFoco(ctrl.IndicePosterior); } } // Fazer o salto de campo function ValidarTecla (evnt) { var tk; var c; // Recebe a tela pressionada tk = ( (QualNavegador()=="IE") ? event.keyCode : evnt.which); c=String.fromCharCode(tk); c=c.toUpperCase(); // -- Este trecho faz com que o tenha a função de , mas acho inviável, pois não é possível // colocar o foco em campos do Tipo "image", e, neste caso, nunca seria possível fazer a submissão // do formulário // if ( tk == 13 ) // { // this.Saltar=true; // SaltarCampo(this); // return false; // } // Só aceita teclas alfanuméricas. Não aceita teclas de controle if ( tk < 32 ) return true; if ( tk > 127 ) return false; switch ( this.Tipo ) { case "D": if ( c<"0" || c>"9" ) return false; break; case "N": if ( (c<"0" || c>"9") && (c!="." && c!=",") ) return false; if ( (c==",") && ((this.value.search(",")>-1) || (this.value.length==0)) ) return false; if ( (c==".") && (this.value.length==0) ) return false; break; case "C": if ( c<"A" || c>"Z" ) return false; break; default: break; } this.Saltar=(this.value.length==this.Tam-1); if ( ((QualNavegador()=="IE") && QualVersao()<5) || (QualNavegador()!="IE") ) SaltarCampo(this); return true; } function pop_print(){ self.print(); }