/*************************************************** *** Biblioteca de Funcoes Javascript *** Author: Washington Tavares *** Date: 13/03/2003 *** Project: Site Smiles ***************************************************/ /*----------------------- **** Variaveis Globais **** -----------------------*/ var isNN = (navigator.appName.indexOf("Netscape")!=-1); /*----------------------- **** Funcoes de Data **** -----------------------*/ /********************************* *** function ComparaDatas() *** args: string dataInicio, string dataFinal, int tipoComparacao, String msg *** return: boolean *** Author: Washington Tavares *** Date: 13/03/2003 *** Desc: Comparacao entre duas Datas verificando *** se o inicio é menor que o final. *********************************/ function ComparaDatas(dataInicio, dataFinal, tipoCamparacao, msg) { } /********************************* *** function VerificaDataMinima() *** args: String dataInicio, Int tempoMinimo, String msg *** return: boolean *** Author: Washington Tavares *** Date: 13/03/2003 *** Desc: Checagem se a data inicial é *** anterior ao tempo especificado. *********************************/ function VerificaDataMinima(dataInicio, tempoMinimo, msg) { } /********************************* *** function ValidaData() *** args: String data *** return: boolean *** Author: Washington Tavares *** Date: 13/03/2003 *** Desc: Valida Formato da Data *********************************/ function ValidaData(cData, msg) { if (cData.value=="") { return false; } msgCheck = false; (msg == '') ? msgCheck = true : msgCheck = false; var data; data = LimpaCampo(cData.value,10); var tam = data.length; if (tam == 6) { // Formato MM/AAAA var ano = data.substr (2,4); var mes = data.substr (0,2) if (ano < 1900) { if (msgCheck) alert(msg); cData.value = ""; cData.focus(); return(false); } if (mes <1 || mes > 12) { if (msgCheck) alert(msg); cData.value = ""; cData.focus(); return(false); } else { return true; } } else if (tam == 8) { //FORMATO DD/MM/AAAA var ano = data.substr (4,4); var dia = data.substr(0,2) var mes = data.substr (2,2) switch (mes){ case '01': if (dia > 31){ if (msgCheck) alert(msg); cData.value = ""; cData.focus(); return(false); } break; case '02': if (dia > 29){ if (msgCheck) alert(msg); cData.value = ""; cData.focus(); return(false); } break; case '03': if (dia > 31){ if (msgCheck) alert(msg); cData.value = ""; cData.focus(); return(false); } break; case '04': if (dia > 30){ if (msgCheck) alert(msg); cData.value = ""; cData.focus(); return(false); } break; case '05': if (dia > 31){ if (msgCheck) alert(msg); cData.value = ""; cData.focus(); return(false); } break; case '06': if (dia > 30) { if (msgCheck) alert(msg); cData.value = ""; cData.focus(); return(false); } break; case '07': if (dia > 31){ if (msgCheck) alert(msg); cData.value = ""; cData.focus(); return(false); } break; case '08': if (dia > 31){ if (msgCheck) alert(msg); cData.value = ""; cData.focus(); return(false); } break; case '09': if (dia > 30){ if (msgCheck) alert(msg); cData.value = ""; cData.focus(); return(false); } break; case '10': if (dia > 31){ if (msgCheck) alert(msg); cData.value = ""; cData.focus(); return(false); } break; case '11': if (dia > 30) { if (msgCheck) alert(msg); cData.value = ""; cData.focus(); return(false); } break; case '12': if (dia > 31){ if (msgCheck) alert(msg); cData.value = ""; cData.focus(); return(false); } break; default: if (msgCheck) alert(msg); cData.value = ""; cData.focus(); return(false); break; } return(true); } else { if (msgCheck) alert(msg); cData.value = ""; cData.focus(); return false; } } /********************************* *** function ValidaDataFuturo() *** args: String data, String msg *** return: boolean *** Author: Washington Tavares *** Date: 13/03/2003 *** Desc: Verifica se a data é maior que hoje. *********************************/ function ValidaDataFuturo(cData, msg) { showMsg=false; (msg == '') ? showMsg = false : showMsg = true; var data; var dataLocal = new Date(); data = LimpaCampo(cData.value,10); var tam = data.length; if (tam == 6) { // Formato: MM/AAAA var diaForm = 0 var mesForm = parseInt(data.substr (0,2)); var anoForm = parseInt(data.substr (2,4)); } else if (tam == 8 ) { // Formato: MM/AAAA var diaForm = parseInt(data.substr(0,2)); var mesForm = parseInt(data.substr (2,2)); var anoForm = parseInt(data.substr (4,4)); } else { // Formato Errado cData.value = ""; cData.focus(); return false; } var diaLocal = dataLocal.getDate(); var mesLocal = dataLocal.getMonth()+1; var anoLocal = dataLocal.getFullYear(); if (parseInt(anoForm)>parseInt(anoLocal)) { if (showMsg) alert(msg); cData.value = ""; cData.focus(); return false; } else if (anoForm==anoLocal) { if (mesForm>mesLocal) { if (showMsg) alert(msg); cData.value = ""; cData.focus(); return false; } else if (mesForm==mesLocal) { if (diaForm!=0) { if (diaForm>=diaLocal) { if (showMsg) alert(msg); cData.value = ""; cData.focus(); return false; } else{ return true; } } } else { return true; } } return true; } /********************************* *** function FormataData() *** args: String campo, event teclaPres, String msg *** return: boolean *** Author: Washington Tavares *** Date: 13/03/2003 *** Desc: Formatação automática de data (DD/MM/YYYY). *********************************/ function FormataData(Campo, teclaPres, msg){ var tecla = teclaPres.keyCode; var vr = new String(Campo.value); vr = vr.replace("/", ""); vr = vr.replace("/", ""); tam = vr.length + 1; if (tecla != 9 && tecla != 8){ if (tam > 2 && tam < 5) Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam); if (tam >= 5 && tam <=10) Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(4,4); } } /********************************* *** function FormataData2() somente mes e ano *** args: String campo, event teclaPres, String msg *** return: boolean *** Author: Washington Tavares *** Date: 13/03/2003 *** Desc: Formatação automática de data (MM/YYYY). *********************************/ function FormataData2(Campo, teclaPres, msg){ var tecla = teclaPres.keyCode; var vr = new String(Campo.value); vr = vr.replace("/", ""); // vr = vr.replace("/", ""); tam = vr.length + 1; if (tecla != 9 && tecla != 8){ if (tam > 2 ) Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam); if ( tam <=7) Campo.value = vr.substr(0,2) + '/' + vr.substr(2,4); } } /*----------------------------- **** Funcoes de Formulário **** -----------------------------*/ /********************************* *** function VerificaInteiro() *** args: String Nome Form, String Element Name, String Msg Error *** return: boolean *** Author: Washington Tavares *** Date: 01/04/2003 *** Desc: Verificacao de preenchimento Elemento de form somente com inteiros *********************************/ function VerificaInteiro(FormName,TextName,Msg1) { var checkOK = "0123456789"; var checkStr = document.forms[FormName].elements[TextName].value; var Temp = document.forms[FormName].elements[TextName]; var allValid = true; for (i = 0; i < checkStr.length; i++) { ch = checkStr.charAt(i); for (j = 0; j < checkOK.length; j++) if (ch == checkOK.charAt(j)) break; if (j == checkOK.length) { allValid = false; break; } } if (!allValid) { alert(Msg1); Temp.focus(); Temp.value = ""; return (false); } else { return(true); } } /********************************* *** function VerificaInteiro2() *********************************/ function VerificaInteiro2(elmt) { var checkOK = "0123456789"; var checkStr = elmt.value; var allValid = true; for (i = 0; i < checkStr.length; i++) { ch = checkStr.charAt(i); for (j = 0; j < checkOK.length; j++) if (ch == checkOK.charAt(j)) break; if (j == checkOK.length) { allValid = false; break; } } if (!allValid) { return false; } else { return true; } } /********************************* *** function VerificaTexto() *** args: String Element *** return: boolean *** Author: Washington Tavares *** Date: 01/04/2003 *** Desc: Verificacao de preenchimento Elemento de form somente com texto espaco e ponto *********************************/ function VerificaTexto2(elmt) { var varStr = elmt.value; var varRet = true; var validChars = "abcdefghijklmnopqrstuvwxyz. áàâäãéèëêíìïîóòöôõúùüûçñ"; for (i = 0; i < varStr.length; i++) { var varChar = varStr.charAt(i); if (validChars.indexOf(varChar.toLowerCase()) == -1 ) { return false; } } return true; } /********************************* *** function VerificaVazio() *** args: String Nome Form, String Element Name, String Msg Error *** return: boolean *** Author: Washington Tavares *** Date: 01/04/2003 *** Desc: Verificacao de Elemento sem preenchimento *********************************/ function VerificaVazio(FormName,TextName,Msg) { var Temp = document.forms[FormName].elements[TextName]; var checkStr = document.forms[FormName].elements[TextName].value; if (checkStr.length < 1) { alert(Msg); Temp.focus(); return (false); } else { return(true); } } /********************************* *** function VerificaVazio() *********************************/ function VerificaVazio2(elmt) { try { var checkStr = elmt.value; } catch(err) { return(true); } if (checkStr.length < 1) { return (false); } else { return(true); } } /********************************* *** function VerificaSelect2() *** args: String String Element *** return: boolean *** Author: Washington Tavares *** Date: 09/06/2003 *** Desc: Verificacao de selecao de combo ou lista modo simples *********************************/ function VerificaSelect2(elmt) { var selIdx = elmt.selectedIndex; var selValue = elmt.value; if (selValue == '') { return false; } else if (selIdx == -1) { return false; } return true; } /********************************* *** function VerificaRadio2() *** args: String String Element *** return: boolean *** Author: Washington Tavares *** Date: 09/06/2003 *** Desc: Verificacao de selecao de radio modo simples *********************************/ function VerificaRadio2(elmt) { for (i=0; i < elmt.length; i++) { if (elmt[i].checked) { return true; } } return false; } function VerificaTamanho(elmt, size) { varValue = elmt.value; strValue = new String(varValue); tamValue = strValue.length; if (tamValue 0) { // Nome contem numeros return false; } if (varNome.length<2) { return false; } if (!VerificaTexto2(elmt)) { return false; } return true; } function VerificaSobrenome(elmt) { varNome = new String(elmt.value); verString = LimpaCampo(varNome, 10); verString = verString.length; if (verString > 0) { // Nome contem numeros return false; } if (!VerificaTexto2(elmt)) { return false; } return true; } //onKeyUp="return autoTab(this, 3, event);" function autoTab(input,len, e) { var keyCode = (isNN) ? e.which : e.keyCode; var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46]; if(input.value.length >= len && !containsElement(filter,keyCode)) { input.value = input.value.slice(0, len); input.form[(getIndex(input)+1) % input.form.length].focus(); } function containsElement(arr, ele) { var found = false, index = 0; while(!found && index < arr.length) if(arr[index] == ele) found = true; else index++; return found; } function getIndex(input) { var index = -1, i = 0, found = false; while (i < input.form.length && index == -1) if (input.form[i] == input)index = i; else i++; return index; } return true; } /********************************* *** function FormataCPF() *** args: String campo, event teclaPres *** return: boolean *** Author: Washington Tavares *** Date: 01/04/2003 *** Desc: Formatação automática de CPF (999.999.999-99). *********************************/ function FormataCPF(Campo, teclapres){ var tecla = teclapres.keyCode; var vr = new String(Campo.value); vr = vr.replace(".", ""); vr = vr.replace(".", ""); vr = vr.replace("-", ""); tam = vr.length + 1; if (tecla != 9 && tecla != 8){ if (tam > 3 && tam < 7) Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam); if (tam >= 7 && tam <10) Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6); if (tam >= 10 && tam < 12) Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9); } } /********************************* *** function VerificaCPF() *** args: String Valor do Campo *** return: boolean *** Author: Washington Tavares *** Date: 01/04/2003 *** Desc: Formatação automática de CPF (999.999.999-99). *********************************/ function VerificaCPF(valor) { primeiro=valor.substr(1,1); falso=true; size=valor.length; if (size!=11){ return false; } size--; for (i=2; i-1;pos=pos-1) { soma = soma + (parseInt(str.charAt(pos)) * ind); ind++; if(str.length>11) { if(ind>9) ind=2; } } resto = soma - (Math.floor(soma / 11) * 11); if(resto < 2) { return 0 } else { return 11 - resto } } ///////////////////////////////////////////////////////////////// function LimpaCampo(sValor,iBase){ var tam = sValor.length var saida = new String for (i=0;i