/******************************************************************* * * * Basico.asp - Funções Básicas em JavaScript para uso Geral * * * * V1.5 - Jan/2000 * * * *******************************************************************/ /*-----------------------------------------------------------------* | ContidoNoDominio Retorna True se a String dada só contiver | | caracteres do domínio dado | *-----------------------------------------------------------------*/ function ContidoNoDominio(StrDado, Dominio) { var i, j; if (StrDado == "") return false; for (i=0; i= Dominio.length) return false; } return true } /*-----------------------------------------------------------------* | ContemDominio Retorna True se a String dada contiver algum | | caractere do domínio dado | *-----------------------------------------------------------------*/ function ContemDominio(StrDado, Dominio) { var i, j; if (StrDado != "") { for (i=0; i 0) && (Mes >= 1) && (Mes <= 12)) { // Analisa Dia: if ((Dia >= 1) && (Dia <= DiasMes[Mes - 1])) { // Analisa os casos não-bissextos: if ((Mes == 2) && ((Ano%4 != 0) || (Ano%100 == 0) && (Ano%400 != 0))) { if (Dia <= 28) Result = true; } else { Result = true; } } } } } return Result; } /*-----------------------------------------------------------------* | IsStrHora Retorna True se a String dada for uma data válida | | no formato HH:MM ou HH:MM:SS | *-----------------------------------------------------------------*/ function IsStrHora(Dado) { var Hor, Min, Seg; var Result = false; // Pré-analisa o String: if (Dado != "") { if (((Dado.length == 5) || (Dado.length == 8)) && (Dado.substr(2,1) == ":")) { // Levanta Campos: if (IsStrNum(Dado.substr(0,2))) Hor = Dado.substr(0,2); else Hor = -1; if (IsStrNum(Dado.substr(3,2))) Min = Dado.substr(3,2); else Min = -1; // Analisa a Hora: if ((Hor >= 0) && (Hor <= 23)) { // Analisa o Minuto: if ((Min >= 0) && (Min <= 59)) { // Verifica se tem segundo: if (Dado.length == 8) { // Pré-analisa: if (Dado.substr(5,1) == ":") { // Levanta e verifica segundos: if (IsStrNum(Dado.substr(6,2))) Seg = Dado.substr(6,2); else Seg = -1; if ((Seg >= 0) && (Seg <= 59)) { Result = true; } } } else { Result = true; } } } } } return Result; } /*-----------------------------------------------------------------* | SeparaNomeArq Separa o Nome de Arquivo do Path completo | | | *-----------------------------------------------------------------*/ function SeparaNomeArq(PathDado) { var i if (PathDado.length == 0) return ""; for (i=PathDado.length-1; i>=0; i--) { if (PathDado.substr(i,1) == "\\" || PathDado.substr(i,1) == ":") { return PathDado.substr(i + 1); } } return PathDado; } /*-----------------------------------------------------------------* | StrD Acerta a String na Largura dada com | | Alinhamento à Direita: | *-----------------------------------------------------------------*/ function StrD(Dado, Larg) { var Result; var i; if (Dado.length >= Larg) { Result = Dado.substr(Dado.length - Larg,Larg); } else { Result = ""; for (i=Larg-Dado.length; i>0; i--) { Result = Result + " "; } Result = Result + Dado; } return Result; } /*-----------------------------------------------------------------* | StrE Acerta a String na Largura dada com | | Alinhamento à Esquerda: | *-----------------------------------------------------------------*/ function StrE(Dado, Larg) { var Result; var i; if (Dado.length >= Larg) { Result = Dado.substr(0,Larg); } else { Result = Dado; for (i=Larg-Dado.length; i>0; i--) { Result = Result + " "; } } return Result; } /*-----------------------------------------------------------------* | StrNum Retorna o valor Numérico em String Dado, | | formatado na Largura dada: | *-----------------------------------------------------------------*/ function StrNum(Dado, Larg) { var Result, sDado, i; sDado = Dado.toString(); if (sDado.length >= Larg) { Result = sDado.substr(sDado.length - Larg,Larg); } else { Result = ""; for (i=Larg-sDado.length; i>0; i--) { Result = Result + "0"; } Result = Result + sDado; } return Result; } /*-----------------------------------------------------------------* | PassaDominio Retorna a String dada, somente com os | | caracteres do domínio dado | *-----------------------------------------------------------------*/ function PassaDominio(StrDado, Dominio) { var i, j, c; var Result; Result = ""; for (i=0; i= Dominio.length) { Result = Result + c; } } return Result; } /******************************************************************* * Funções de Filtro para uso com Text-Boxes: * * Utilize-as sob os eventos OnKeyUp e OnChange simultaneamente. * *******************************************************************/ function FiltroNum(Objeto) { Objeto.value = PassaDominio(Objeto.value, "0123456789"); } function FiltroInt(Objeto) { Objeto.value = PassaDominio(Objeto.value, "0123456789+-"); } function FiltroCurr(Objeto) { Objeto.value = PassaDominio(Objeto.value, "0123456789+-,."); } function FiltroFloat(Objeto) { Objeto.value = PassaDominio(Objeto.value, "0123456789+-Ee,."); } function FiltroData(Objeto) { Objeto.value = PassaDominio(Objeto.value, "0123456789/"); } function FiltroHora(Objeto) { Objeto.value = PassaDominio(Objeto.value, "0123456789:"); } function FiltroUp(Objeto) { Objeto.value = Objeto.value.toUpperCase(); } //limita tamanho para textarea //----------------------------------------------------------------------- function fMaxTamCampo(TamMax,ValCampo) { Campo = ValCampo.value TamanhoCampo = Campo.length if (TamanhoCampo > TamMax) { ValorCampo = Campo.substring(0,TamMax) ValCampo.value = ValorCampo alert("O limite máximo do campo é de " +TamMax+ " caracteres.") } } //----------------------------------------------------------------------- function ValidaEMail(EMail) { if (EMail.indexOf("@") < 0) return false; if (EMail.indexOf(".") < 0) return false; if (ContemDominio(EMail, " ;,:/$!#%^&*()+[]{}|\\~`'\"")) return false; return true; } /*-----------------------------------------------------------------* | isNumber Retorna True se o String dada for um número | | com casas decimais dadas. | *-----------------------------------------------------------------*/ function isNumber(sNumero, iDecimais) { var bRet var i bRet = true if (iDecimais > 0) { if (sNumero.length < iDecimais + 2 || (sNumero.indexOf(".", 0) == -1 && sNumero.indexOf(",", 0) == -1)) bRet = false } if (bRet) { i = 0 while(i < sNumero.length && bRet) { if (iDecimais > 0) { if (i == sNumero.length - (iDecimais + 1)) { if (sNumero.charAt(i) != "." && sNumero.charAt(i) != ",") bRet = false } else { if (sNumero.charAt(i) < "0" || sNumero.charAt(i) > "9") bRet = false } } else { if (sNumero.charAt(i) < "0" || sNumero.charAt(i) > "9") bRet = false } i++ } } return bRet } /* Nome........: FmtData Descricao...: Insere a máscara de data no campo Paramentros.: Dado Retorno.....: Retorna o conteúdo formatado em dd/mm/yyyy, não permitindo a digitação de caracteres alfa */ function FmtData_old(Dado) { var Result = Dado; for (i=1; i<=Dado.length; i++) { if (i == 2) { Result = Dado.substr(0, 2) + "/" + Dado.substr(2, i); } if (i >= 4) { Result = Dado.substr(0, 2) + "/" + Dado.substr(2, 2) + "/" + Dado.substr(4, 4); } } return Result; } function FmtData(Dado) { var Result = Dado; var l = Dado.length; if((l > 2) && (l < 5)) { Result = Dado.substr(0, 2) + "/" + Dado.substr(2, 2); } if(l >= 5) { Result = Dado.substr(0, 2) + "/" + Dado.substr(2, 2) + "/" + Dado.substr(4, 4); } return Result; } /* Nome........: FmtDataMesAno Descricao...: Insere a máscara de data no campo Paramentros.: Dado Retorno.....: Retorna o conteúdo formatado em mm/yyyy, não permitindo a digitação de caracteres alfa */ function FmtDataMesAno(Dado) { var Result = Dado; for (i=1; i<=Dado.length; i++) { if (i == 2) { Result = Dado.substr(0, 2) + "/" + Dado.substr(2, i); } if (i > 2) { Result = Dado.substr(0, 2) + "/" + Dado.substr(2, 4); } } return Result; } /* Nome........: FmtHora Descricao...: Insere a máscara de hora no campo Paramentros.: Dado Retorno.....: Retorna o conteúdo formatado em hh:mm, não permitindo a digitação de caracteres alfa */ function FmtHora(Dado) { var Result = Dado; for (i = 1; i <= Dado.length; i++) { // if (i >= 3) // { // Result = Dado.substr(0, 2) + ":" + Dado.substr(2, 2); // } if((i > 2) && (i < 5)) { Result = Dado.substr(0, 2) + ":" + Dado.substr(2, 2); } if(i >= 5) { Result = Dado.substr(0, 2) + ":" + Dado.substr(2, 2) + ":" + Dado.substr(4, 4); } } return Result; } var bPula = true; function fAtuPulaBlur() { bPula = false; } function fAtuPulaKeyPress() { bPula = true; return; } function fPulaCampo(campo1,campo2,iTam,tpcampo) { if(bPula) { if (tpcampo == "data") { Filtro(campo1,'data'); } if (tpcampo == "hora") { Filtro(campo1,'hora'); } if (campo1.value.length >= iTam) { campo2.focus(); } } return; } /*-----------------------------------------------------------------* | CalculaDigitoMod11(Dado, NumDig, LimMult) | | Retorna o(s) NumDig Dígitos de Controle Módulo 11 do | | Dado, limitando o Valor de Multiplicação em LimMult: | | | | Números Comuns:: iDigSaida iCod | | CGC 2 9 | | CPF 2 12 | | C/C,Age - CAIXA 1 9 | | habitação/bloqueto 1 9 | *-----------------------------------------------------------------*/ function CalculaDigitoMod11(Dado, NumDig, LimMult) { var Mult, Soma, i, n; for(n=1; n<=NumDig; n++) { Soma = 0; Mult = 2; for(i=Dado.length-1; i>=0; i--) { Soma += (Mult * parseInt(Dado.charAt(i))); if(++Mult > LimMult) Mult = 2; } Dado += ((Soma * 10) % 11) % 10; } return Dado.substr(Dado.length-NumDig, NumDig); } function CalculaDigitoMod10(sValor) { mult = 2 soma = 0 str = new String() sValor = sZapDummy(sValor) for (t=sValor.length;t>=1;t--) { str = (mult*parseInt(sMid(sValor,t,1))) + str mult-- if (mult<1) mult = 2 } for (t=1;t<=str.length;t++) soma = soma + parseInt(sMid(str,t,1)) soma = soma % 10 if (soma != 0) soma = 10 - soma str = soma //casting return str } function Mod10(valor) { val = valor.substring( 0 , valor.length - 1 ) dig = valor.substring( valor.length - 1 , valor.length ) str = new String fator = 2 soma = 0 for(i = val.length; i > 0; i--) { str = fator * parseInt(val.substring(i, i - 1)) + str fator-- if(fator < 1) fator = 2 } for(i = 0; i < str.length; i++) soma = soma + parseInt(str.charAt(i)) soma = soma % 10 if(soma != 0) soma = 10 - soma str = soma //aqui existe uma espécie de "casting" (conversão) return str == dig } function isBissexto(iAno) { var bRet bRet = false if (iAno % 4 == 0 && (iAno % 100 !=0 || iAno % 400 ==0 )) bRet = true return bRet } function isDate(sData) { var bRet var i bRet = true if (sData.length != 10) bRet = false if (bRet) { i = 0 while (i < sData.length && bRet) { if (i == 2 || i == 5) { if (sData.charAt(i) != "/") bRet = false } else { if (!isNumber(sData.charAt(i), 0)) bRet = false } i++ } } if (bRet) { iDia = parseInt(sData.substring(0, 2), 10) iMes = parseInt(sData.substring(3, 5), 10) iAno = parseInt(sData.substring(6, 10), 10) if (iMes < 1 || iMes > 12) bRet = false if (iAno < 1) bRet = false } if (bRet) { if (iMes == 1 || iMes == 3 || iMes == 5 || iMes == 7 || iMes == 8 || iMes == 10 || iMes == 12) { if (iDia < 1 || iDia > 31) bRet = false } if (iMes == 2) { if (isBissexto(iAno)) { if (iDia < 1 || iDia > 29) bRet = false } else { if (iDia < 1 || iDia > 28) bRet = false } } if (iMes == 4 || iMes == 6 || iMes == 9 || iMes == 11) { if (iDia < 1 || iDia > 30) bRet = false } } return bRet } function sRight(sExpressao,iNumeros) { if (sExpressao.length >= iNumeros ) return sExpressao.substring(sExpressao.length - iNumeros,sExpressao.length) } function sLeft(sExpressao,iNumeros) { if (sExpressao.length >= iNumeros ) return sExpressao.substring(0,iNumeros) } function sMid(sExpressao,iNumeros,iTamanho) { var aux = new String() if ((sExpressao.length >= iNumeros) && (iNumeros >=0) && (iTamanho > 0)) { iNumeros-- aux = sExpressao.substring(iNumeros,iNumeros+iTamanho) } return aux } function sZapDummy(sStringNum) { var sAux = new String() for (t=1;t<=sStringNum.length;t++) if (!isNaN(parseInt(sMid(sStringNum,t,1)))) sAux = sAux + sMid(sStringNum,t,1) return sAux } function Filtro(Objeto,tpCampo) { /* if(window.event.keyCode == 37 || window.event.keyCode == 8 || window.event.keyCode == 36 || window.event.keyCode == 46 || window.event.keyCode == 16 || window.event.keyCode == 9 ) return; if (window.event.keyCode == 111 || window.event.keyCode == 191) { if (tpCampo == "data") { if (Objeto.value.length == 3 || Objeto.value.length == 6) { return } if (Objeto.value.length == 4 || Objeto.value.length == 7) { var newpos = Objeto.value.length - 1 Objeto.value = Objeto.value.substring(0,newpos) return } } } if (window.event.keyCode == 39) { if (tpCampo == "data") { if (Objeto.value.length == 2 || Objeto.value.length == 5) Objeto.value = Objeto.value + "/" } return } if (navigator.appName.substr(0,9) == "Microsoft") { Objeto.value = PassaDominio(Objeto.value, "0123456789"); if (tpCampo == "data") { Objeto.value = FmtData(Objeto.value); } if (tpCampo == "DataMesAno") { Objeto.value = FmtDataMesAno(Objeto.value); } if (tpCampo == "valor") { Objeto.value = FmtCurr(Objeto.value); } if (tpCampo == "hora") { Objeto.value = FmtHora(Objeto.value); } if (tpCampo == "lacre") { Objeto.value = FmtLacre(Objeto.value); } if (tpCampo == "decimal") { Objeto.value = FmtDec(Objeto.value); } } */ Dado = PassaDominio(Objeto.value, "0123456789"); if (tpCampo == "data") { Objeto.value = FmtData(Dado); } if (tpCampo == "DataMesAno") { Objeto.value = FmtDataMesAno(Dado); } if (tpCampo == "valor") { Objeto.value = FmtCurr(Dado); } if (tpCampo == "hora") { Objeto.value = FmtHora(Dado); } if (tpCampo == "lacre") { Objeto.value = FmtLacre(Dado); } if (tpCampo == "decimal") { Objeto.value = FmtDec(Dado); } } function FmtLacre(Dado) { var Result, i; Dado = TiraTracos(Dado); if (Dado.length > 2) { Result = "-" + Dado.substr(Dado.length-2, 2); Result = Dado.substr(0, Dado.length-2) + Result; } else { Result = Dado; } return Result; } function FmtCurr(Dado) { var Result, i; if (Dado.length > 2) { Result = "," + Dado.substr(Dado.length-2, 2); for (i=5; i<=Dado.length; i+=3) { Result = Dado.substr(Dado.length-i, 3) + Result; if (Dado.length > i) Result = "." + Result; } Result = Dado.substr(0, Dado.length-i+3) + Result; } else { Result = Dado; } return Result; } function FmtDec(Dado) { var Result, i; if (Dado.length > 1) { Result = "," + Dado.substr(Dado.length-1, 1); for (i=4; i<=Dado.length; i+=3) { Result = Dado.substr(Dado.length-i, 3) + Result; if (Dado.length > i) Result = "." + Result; } Result = Dado.substr(0, Dado.length-i+3) + Result; } else { Result = Dado; } return Result; } function TiraPontos (NumeroFormatado) { var s s = NumeroFormatado.split ("."); return s.join(""); } function TiraVirgula (NumeroFormatado) { var s s = NumeroFormatado.split (","); return s.join(""); } function TiraTracos (NumeroFormatado) { var s s = NumeroFormatado.split ("-"); return s.join(""); } function TiraBarra (NumeroFormatado) { var s s = NumeroFormatado.split ("/"); return s.join(""); } function printit() { if (window.print) { window.print(); } else { var WebBrowser = ''; document.body.insertAdjacentHTML('beforeEnd', WebBrowser); WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = ""; } } function FiltraTexto(Dado) { var r = '' var asc1 = new String() var asc2 = new String() asc1 = 'áàãäâÁÀÃÄÂéèêëÉÈÊËìíîïÌÍÎÏòóôõöÒÓÔÕÖùúûüÙÚÛÜýÝçÇñÑ' asc2 = 'AAAAAAAAAAEEEEEEEEIIIIIIIIOOOOOOOOOOUUUUUUUUYYCCNN' for(i=0;i<=Dado.length-1;i++) { c = Dado.charAt(i) for(j=0;j<=asc1.length-1;j++) if(Dado.charAt(i) == asc1.charAt(j)) c = asc2.charAt(j) if((c<'0' || c>'9') && (c<'A' || c>'Z') && (c<'a' || c>'z') && (c != ' ') && (c != ',') && (c != '.') && (c != '/')) { return ""; } r = r + c } return r.toUpperCase(); } /*-------------------------------------------- 'nome...: Recarrega combo com valor informado ----------------------------------------------*/ function recCombo(campo,valor) { for (i=0;i < eval(campo + '.options.length') ;i++) { if (eval(campo + '[i].value') == valor) { eval(campo + '.options[i].selected = true'); break; } } return; } /*-----------------------------------------------------------------* 'nome...: RTRIM *-----------------------------------------------------------------*/ function RTrim(StrDado) { TemEspaco = true; sCampo = StrDado if (sCampo != "") { while (TemEspaco) { if (sCampo.substr(sCampo.length - 1,1) == ' ') { sCampo = sCampo.substr(0,sCampo.length - 1); } else { TemEspaco = false; } } } return sCampo; } /*-----------------------------------------------------------------* ' NOVAS FUNCOES *-----------------------------------------------------------------*/ function volta() { top.history.back(); } function maiuscula(str) { aux = str.value.toUpperCase(); str.value = aux; } function minuscula(str) { aux = str.value.toLowerCase(); str.value = aux; } function leftzeros(valor,qtd) { var seq = valor.value.toUpperCase(); if ( seq.length > 0 ) { zeros = ''; dif = qtd - seq.length; for(i=0; i < dif; i++) zeros = zeros + '0'; valor.value = zeros + seq; } } function is_fone(valor){ var cadeia = "Rr-0123456789"; var ok = true; var hifen = 0; var numeros = 0; for (i = 0; i2) { ok=false; } return (ok); } function FormataValor(Obj) { Dado = PassaDominio(Obj.value, "0123456789"); Obj.value = FmtCurr(Dado); } function FormataCNPJ(Obj) { Dado = PassaDominio(Obj.value, "0123456789"); var l = Dado.length; if((l > 2) && (l <= 5)) Dado = Dado.substr(0, 2) + "." + Dado.substr(2, 3); if((l > 5 ) && (l <= 8)) Dado = Dado.substr(0, 2) + "." + Dado.substr(2, 3) + "." + Dado.substr(5, 3) if((l > 8) && (l <= 12)) Dado = Dado.substr(0, 2) + "." + Dado.substr(2, 3) + "." + Dado.substr(5, 3) + "/" + Dado.substr(8, 4) if(l > 12) Dado = Dado.substr(0, 2) + "." + Dado.substr(2, 3) + "." + Dado.substr(5, 3) + "/" + Dado.substr(8, 4) + "-" + Dado.substr(12, 2) Obj.value = Dado; } function FormataCPF(Obj) { Dado = PassaDominio(Obj.value, "0123456789"); var l = Dado.length; if((l > 3) && (l <= 6)) Dado = Dado.substr(0, 3) + "." + Dado.substr(3, 3); if((l > 6 ) && (l <= 9)) Dado = Dado.substr(0, 3) + "." + Dado.substr(3, 3) + "." + Dado.substr(6, 3) if((l > 9) && (l <= 11)) Dado = Dado.substr(0, 3) + "." + Dado.substr(3, 3) + "." + Dado.substr(6, 3) + "-" + Dado.substr(9, 2) Obj.value = Dado; } function CPFvalido(numero) { numero = TiraPontos(TiraTracos(numero)) if (!IsStrNum(numero)) { alert("O campo CPF deve ser númerico."); return (false); } if ((numero.substring(0,11) == "00000000000") || (numero.substring(0,11) == "11111111111") || (numero.substring(0,11) == "22222222222") || (numero.substring(0,11) == "33333333333") || (numero.substring(0,11) == "44444444444") || (numero.substring(0,11) == "55555555555") || (numero.substring(0,11) == "66666666666") || (numero.substring(0,11) == "77777777777") || (numero.substring(0,11) == "88888888888") || (numero.substring(0,11) == "99999999999")) { alert("CPF inválido! Por favor, corrija-o."); return (false); } if (numero.length!=11) { alert("O tamanho correto do CPF é 11 dígitos"); return(false); } if (numero.length==11) { multiplicado = numero.charAt(0) * 1 + numero.charAt(1) * 2 + numero.charAt(2) * 3 + numero.charAt(3) * 4 + numero.charAt(4) * 5 + numero.charAt(5) * 6 + numero.charAt(6) * 7 + numero.charAt(7) * 8 + numero.charAt(8) * 9 ; verificador1 = multiplicado%11 if (verificador1 == 10) verificador1 = 0; multiplicado = numero.charAt(1) * 1 + numero.charAt(2) * 2 + numero.charAt(3) * 3 + numero.charAt(4) * 4 + numero.charAt(5) * 5 + numero.charAt(6) * 6 + numero.charAt(7) * 7 + numero.charAt(8) * 8 + numero.charAt(9) * 9 ; verificador2 = multiplicado%11 if (verificador2 == 10) verificador2 = 0; if ( (verificador1!=numero.charAt(9)) || (verificador2!=numero.charAt(10)) ) { alert("CPF inválido! Por favor, corrija-o."); return (false); } } return (true); } function CNPJvalido(numero) { numero = TiraPontos(TiraTracos(TiraBarra(numero))) if (!IsStrNum(numero)) { alert("O campo CNPJ deve ser númerico!"); return (false); } if (numero.length!=14) { alert("Informe o CNPJ do Fornecedor com 14 dígitos!"); return(false); } if (numero.length==14) { d1 = 0; d4 = 0; x_x = 1; for(conta=0; conta<12; conta++) { d1 = d1 + numero.charAt(conta) * ( (x_x<5 ? 6 : 14) - x_x ); d4 = d4 + numero.charAt(conta) * ( (x_x<6 ? 7 : 15) - x_x ); x_x++; } resto = d1 % 11; digito = resto<2 ? 0 : (11-resto); d4 = d4 + (2 * digito); resto = d4 % 11; if (resto < 2) digito = digito + "0"; else digito = digito + "" + (11 - resto); if (digito != numero.substr(numero.length-2,2)) { alert("CNPJ inválido! Por favor, corrija-o!"); return (false); } } return (true); }