function mostrarError(mostrarError, inputId, errorId) { var element = document.getElementById(inputId); var errorElement = document.getElementById(errorId); if (mostrarError) { errorElement.style.display = "block"; element.classList.add("form-input-error-border"); element.classList.remove("form-input"); } else { errorElement.style.display = "none"; element.classList.add("form-input"); element.classList.remove("form-input-error-border"); } } function validarRegistro() { var nombre = document.getElementById("nombre").value; if (!nombre) { mostrarError(true, "nombre", "errorNombre"); return false; } else { mostrarError(false, "nombre", "errorNombre"); } var apellido = document.getElementById("apellido").value; if (!apellido) { mostrarError(true, "apellido", "errorApellido"); return false; } else { mostrarError(false, "apellido", "errorApellido"); } if ($("#tipoDocumento").val() == '1') { if(!validarCedula($("#documento").val())) { mostrarError(true, "documento", "errorDoc"); return false; } else { mostrarError(false, "documento", "errorDoc"); } } else { if ($("#paisPasaporte").val() == 'null') { mostrarError(true, "paisPasaporte", "errorPais"); return false; } else { mostrarError(false, "paisPasporte", "errorPais"); } } if (!validarFecha()){ mostrarError(true, "fechaNacimiento", "errorFecha"); return false; } else { mostrarError(false, "fechaNacimiento", "errorFecha"); } if (!validarEmail($("#email").val())) { mostrarError(true, "email", "errorMail"); return false; } else { mostrarError(false, "email", "errorMail"); } if (!validarPasswords($("#pwd").val().trim(), $("#pwd2").val().trim())) { mostrarError(true, "pwd", "errorPasswords"); mostrarError(true, "pwd2", "errorPasswords"); return false; } else { mostrarError(false, "pwd", "errorPasswords"); mostrarError(false, "pwd2", "errorPasswords"); } if (!validarTerminos()){ mostrarError(true, "terminos", "errorTerminos"); return false; } return true; /*$("#errorDoc").hide(); $("#errorPais").hide(); $("#errorMail").hide(); $("#errorPasswords").hide(); $("#errorTerminos").hide(); $("#errorFecha").hide(); if($("#tipoDocumento").val() == '1') { if(!validarCedula($("#documento").val())) { $("#errorDoc").show(); $("#infoError").hide(); return false; } } else { if($("#paisPasaporte").val() == 'null') { $("#errorPais").show(); $("#infoError").hide(); return false; } } if(!validarEmail($("#email").val())) { $("#errorMail").show(); $("#infoError").hide(); return false; } if(!validarPasswords($("#pwd").val().trim(), $("#pwd2").val().trim())) { $("#errorPasswords").show(); $("#infoError").hide(); return false; } if(!validarFecha()){ $("#errorFecha").show(); $("#infoError").hide(); return false; } if(!validarTerminos()){ $("#errorTerminos").show(); $("#infoError").hide(); return false; } //if(validarCaptcha()) return true; */ } function addInputListener(id, eventType, callback) { var element = document.getElementById(id); if (element) { element.addEventListener(eventType, callback); } } function removeErrorOnInput(id, errorId) { return function() { mostrarError(false, id, errorId); }; } // registro.jsp addInputListener("nombre", "input", removeErrorOnInput("nombre", "errorNombre")); addInputListener("apellido", "input", removeErrorOnInput("apellido", "errorApellido")); addInputListener("documento", "input", removeErrorOnInput("documento", "errorDoc")); addInputListener("tipoDocumento", "change", removeErrorOnInput("documento", "errorDoc")); addInputListener("paisPasaporte", "change", removeErrorOnInput("paisPasaporte", "errorPais")); addInputListener("fechaNacimiento", "input", removeErrorOnInput("fechaNacimiento", "errorFecha")); addInputListener("email", "input", removeErrorOnInput("email", "errorMail")); addInputListener("pwd", "input", function() { mostrarError(false, "pwd", "errorPasswords"); mostrarError(false, "pwd2", "errorPasswords"); }); addInputListener("pwd2", "input", function() { mostrarError(false, "pwd", "errorPasswords"); mostrarError(false, "pwd2", "errorPasswords"); }); addInputListener("currentPwd", "input", removeErrorOnInput("currentPwd", "errorPasswords")); // addInputListener("terminos", "change", removeErrorOnInput("terminos", "errorTerminos")); // editar-perfil.jsp addInputListener("givenName", "input", removeErrorOnInput("givenName", "errorGivenName")); addInputListener("sn", "input", removeErrorOnInput("sn", "errorSn")); addInputListener("email", "input", removeErrorOnInput("email", "errorEmail")); addInputListener("telefono", "input", removeErrorOnInput("telefono", "errorTel")); addInputListener("fechaNacimiento", "input", removeErrorOnInput("fechaNacimiento", "errorFechaNacimiento")); addInputListener("emailodocumento", "input", removeErrorOnInput("emailodocumento", "errorEmailodocumento")); function validarModificar() { var givenName = document.getElementById("givenName").value; if (!givenName) { mostrarError(true, "givenName", "errorGivenName"); return false; } else { mostrarError(false, "givenName", "errorGivenName"); } var sn = document.getElementById("sn").value; if (!sn) { mostrarError(true, "sn", "errorSn"); return false; } else { mostrarError(false, "sn", "errorSn"); } if (!validarEmail($("#email").val())) { mostrarError(true, "email", "errorEmail"); return false; } else { mostrarError(false, "email", "errorEmail"); } if ($("#tipoDocumento").val() == '1') { if(!validarCedula($("#documento").val())) { mostrarError(true, "documento", "errorDoc"); return false; } else { mostrarError(false, "documento", "errorDoc"); } } else { if ($("#paisPasaporte").val() == 'null') { mostrarError(true, "paisPasaporte", "errorPais"); return false; } else { mostrarError(false, "paisPasporte", "errorPais"); } } var telefono = document.getElementById("telefono").value; if (!sn) { mostrarError(true, "telefono", "errorTel"); return false; } else { mostrarError(false, "telefono", "errorTel"); } var fechaNacimiento = document.getElementById("fechaNacimiento").value; if (!fechaNacimiento) { mostrarError(true, "fechaNacimiento", "errorFechaNacimiento"); return false; } else { if(!validarFecha()){ mostrarError(true, "fechaNacimiento", "errorFechaNacimiento"); return false; } mostrarError(false, "fechaNacimiento", "errorFechaNacimiento"); } return true; } function validarResetPassword() { if(!validarPasswords($("#pwd").val().trim(), $("#pwd2").val().trim())) { mostrarError(true, "pwd", "errorPasswords"); mostrarError(true, "pwd2", "errorPasswords"); return false; } else { mostrarError(false, "pwd", "errorPasswords"); mostrarError(false, "pwd2", "errorPasswords"); } return true; } function validarEmail(email) { var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; return emailPattern.test(email); } function validarPasswords(pwd1, pwd2) { if(pwd1 == "" || pwd2 == "") return false; if(pwd1 != pwd2) return false; return true; } function validarCaptcha() { if(grecaptcha.getResponse().length == 0) { mostrarMsj('Es necesario validar captcha'); return false; } return true; } function validarArchivo() { if($("#archivo").val().trim()=="") { mostrarMsj('Seleccione archivo'); return false; } //$("#button").attr("disabled","disabled"); setTimeout(function() { grisarBoton($("#button")); }, 1); return true; } function validoActualizar() { setTimeout(function() { grisarBoton($("#buttonAct"));}, 1); return true; } function grisarBoton(boton) { boton.attr("disabled","disabled"); return true; } /*** CEDULA ***/ function validarCedula(ci) { ci = limpiarCedula(ci); var dig = ci[ci.length - 1]; ci = ci.replace(/[0-9]$/, ''); return (dig == digitoVerificador(ci)); } function limpiarCedula(ci){ return ci.replace(/\D/g, ''); } function digitoVerificador(ci) { var a = 0; var i = 0; if(ci.length <= 6) { for(i = ci.length; i < 7; i++) { ci = '0' + ci; } } for(i = 0; i < 7; i++) { a += (parseInt("2987634"[i]) * parseInt(ci[i])) % 10; } if(a % 10 === 0) { return 0; } else { return 10 - a % 10; } } function ciSoloNumero(evt) { if($("#tipoDocumento").val() == '1') { var charCode = (evt.which) ? evt.which : evt.keyCode if (charCode > 31 && (charCode < 48 || charCode > 57)) return false; } return true; } function validarFecha(){ var currentDate = document.getElementById("fechaNacimiento").value; if(currentDate==""){ return false; } var date = new Date(currentDate); // Verificar fecha futura const today = new Date(); if (date >= today) { return false; } // Verificar edad mínima y máxima const minAge = 0; const maxAge = 100; const age = today.getFullYear() - date.getFullYear(); const monthDiff = today.getMonth() - date.getMonth(); const dayDiff = today.getDate() - date.getDate(); if ( age < minAge || (age === minAge && monthDiff < 0) || (age === minAge && monthDiff === 0 && dayDiff < 0) ) { return false; } if ( age > maxAge || (age === maxAge && monthDiff > 0) || (age === maxAge && monthDiff === 0 && dayDiff > 0) ) { return false; } return true; } function validarTerminos(){ return $("#terminos").prop("checked"); } function changeTipoDocumento() { if($("#tipoDocumento").val() == '2' || $("#tipoDocumento").val() == '3') { //El tipo "Otro" pas� a tener pa�s $("#paisPasaporteDiv").show(); } else { $("#paisPasaporteDiv").hide(); } }