/* ############################################################ # SISTEMA DE CONSISTÊNCIA DE FORMULÁRIOS # # Autor : Theo Figueiró Fernandes - theo@2fnet.com.br # Data : 01/03/2005 # Versão : 1.0 # # Todos os direitos reservados # ############################################################ ############################################################ # FUNÇÕES DE APOIO PARA A FUNÇÃO DE CONSISTÊNCIA ############################################################ */ function pegaRadioSelecionado(campo) { if (campo[0]) { for (var i=0; i 0) { alert("Debes completar los siguientes campos:\n\n" + erro); return false; // se todos foram preenchidos, segue } else { // verifica se algum campo foi alterado alterado = false; for (var i = 0; i != mArray.length; i=i+2) { var xValor = mArray[i]; nomeCampo = xValor.substring(2); if (alterado == false) { if (form[nomeCampo].type == "radio" || form[nomeCampo].type == undefined) { if (pegaValorRadioSelecionado(form[nomeCampo]) != eval(form.name+'_'+nomeCampo)) { alterado = true; } } else if (form[nomeCampo].type == "checkbox") { if (form[nomeCampo].checked != eval(form.name+'_'+nomeCampo)) { alterado = true; } } else if (form[nomeCampo].type == "select-one") { var l = form[nomeCampo].selectedIndex; if (form[nomeCampo].options[l].value != eval(form.name+'_'+nomeCampo)) { alterado = true; } } else { if (form[nomeCampo].value != eval(form.name+'_'+nomeCampo)) { alterado = true; } } } } // se algum campo foi alterado, segue apenasConfirmacao = this["dados_"+form.name][7]; if (alterado || apenasConfirmacao == true) { // dá a mensagem pedindo a confirmação da alteração/inclusão msgConfirmado = true; showMsgConf = this["dados_"+form.name][5]; if (showMsgConf == true) { msgConfirmado = confirm('¿Estás seguro?'); } // se tinha que confirmar por mensagem, ou não, e confirmou if (msgConfirmado) { form.action = this["dados_"+form.name][1]; strEncode = this["dados_"+form.name][3]; if (strEncode) { if (form.action.indexOf("?") != -1) { form.action = form.action +'&strEncode='+ strEncode; } else { form.action = form.action +'?strEncode='+ strEncode; } form.encoding = "multipart/form-data"; } return true; // se não confirmou, sai fora } else { return false; } // se nenhum campo foi alterado, sai fora } else { return false; } } } //############################################################ //############################################################ //# FUNÇÕES ADICIONAIS PARA FORMULÁRIOS COM CAMPO DE DATA //############################################################ function preencheMail(campo) { if (!isEmail(campo.value)) { campo.focus(); alert('¡E-mail invalido!'); } } function isEmail(string) { if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true; else return false; } // máscara de campos // uso: onkeydown="FormataCampo(this,event,'##/##/####')" function FormataCampo(Campo,teclapres,mascara, sai) { if (sai == "S" && consistente == "N") { if (obrigatorio == "N" && Campo.value.length > 0) { obrig_fixo = "S"; Consist(Campo.maxLength, Campo); obrig_fixo = "N"; } if (obrigatorio == "S" || Campo.value.length > 0) { if (sai == "S") { if (Campo.value.length != mascara.length) { alert('El campo debe tener el siguiente formato:\n\n '+ mascara); Campo.value = ""; } erro = "S"; return false; } } } if (sai == "S" && obrigatorio == "N" && Campo.value.length > 0) { obrig_fixo = "S"; Consist(Campo.maxLength, Campo); obrig_fixo = "N"; if (consistente == "N") { alert('El campo debe tener el siguiente formato:\n\n '+ mascara); } } strtext = Campo.value; tamtext = strtext.length; tammask = mascara.length; arrmask = new Array(tammask); for (var i = 0 ; i < tammask; i++) { arrmask[i] = mascara.slice(i,i+1) } //alert(teclapres.keyCode ); if (((((arrmask[tamtext] == "#") || (arrmask[tamtext] == "9"))) || (((arrmask[tamtext+1] != "#") || (arrmask[tamtext+1] != "9"))))) { if ((teclapres.keyCode >= 35 && teclapres.keyCode <= 40)||(teclapres.keyCode >= 48 && teclapres.keyCode <= 57)||(teclapres.keyCode >= 96 && teclapres.keyCode <= 105)||(teclapres.keyCode == 8)||(teclapres.keyCode == 9) ||(teclapres.keyCode == 46) ||(teclapres.keyCode == 13)||(teclapres.keyCode == 16)){ Organiza_Casa(Campo,arrmask[tamtext],teclapres.keyCode,strtext) } else { Detona_Event(Campo,strtext) } } else { if ((arrmask[tamtext] == "A")) { charupper = event.valueOf() Detona_Event(Campo,strtext) masktext = strtext + charupper Campo.value = masktext } } } function check_date(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; var strDataMsg = ""; err = 0; DateValue = DateField.value; /* Delete all chars except 0..9 */ for (i = 0; i < DateValue.length; i++) { if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) { DateTemp = DateTemp + DateValue.substr(i,1); } } DateValue = DateTemp; /* Always change date to 8 digits - string*/ /* if year is entered as 2-digit / always assume 20xx */ if (DateValue.length == 6) { DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); } if (DateValue.length != 8) { err = 19; strDataMsg = "La fecha no es válida"; } /* year is wrong if year = 0000 */ year = DateValue.substr(4,4); if (year == 0) { err = 20; strDataMsg = "El año no es válido"; } /* Validation of month*/ month = DateValue.substr(2,2); if ((month < 1) || (month > 12)) { err = 21; strDataMsg = "El mes no es válido"; } /* Validation of day*/ day = DateValue.substr(0,2); if (day < 1) { err = 22; strDataMsg = "El día no es válido"; } /* Validation leap-year / february / day */ if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) { leap = 1; } if ((month == 2) && (leap == 1) && (day > 29)) { err = 23; strDataMsg = "El mes elegido posee 29 días como máximo"; } if ((month == 2) && (leap != 1) && (day > 28)) { err = 24; strDataMsg = "El mes elegido posee 28 días como máximo"; } /* Validation of other months */ if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) { err = 25; strDataMsg = "El mes elegido posee 31 días como máximo"; } if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) { err = 26; strDataMsg = "El mes elegido posee 30 días como máximo"; } /* if 00 ist entered, no error, deleting the entry */ if ((day == 0) && (month == 0) && (year == 00)) { err = 0; day = ""; month = ""; year = ""; seperator = ""; } /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */ if (err == 0) { //DateField.value = day + seperator + month + seperator + year; return true; } else { alert(strDataMsg); DateField.select(); DateField.focus(); return false; } } function soNumeros(e, vir){ var key; var keychar; if (window.event) { key = window.event.keyCode; } else if (e) { key = e.which; } else { return true; } keychar = String.fromCharCode(key); if (!vir) { teclas = "0123456789" } else { teclas = ",0123456789" } // teclas de controle if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) { return true; } else if (((teclas).indexOf(keychar) > -1)) { return true; } else { return false; } } function validaNumeros(campo) { var val = campo.value; val=val.replace(/[\D]/g,''); val=val.replace(/.*(\d{10})$/,'$1'); campo.value = val; } function isNum(passedVal) { passa = true; for (w=0; w "9" && passedVal.charAt(w) != ".") { passa = false; } } return (passa); } function isNumData(passedVal) { passa = true; for (w=0; w "9" && passedVal.charAt(w) != "/") { passa = false; } } return (passa); } function numerico(valor){ for (w=0; w 1) { conta_achados = 0 for (w=0; w