document.addEventListener('DOMContentLoaded', function(e) { LoginRegistration.initComponents(); var today = new Date(); var year = today.getFullYear(); var inicio = (year - 80); var fin = (year - 14); var calinicio = (year - 10); var idioma; inicio = '01/01/' + inicio; fin = '01/01/' + fin; calinicio = '01/01/' + calinicio; idioma= '' var dia = today.getDate(); var mes = today.getMonth()+1; //January is 0! if(dia<10) { dia='0'+dia; } if(mes<10) { mes='0'+mes; } var hoy = dia +'/'+mes+'/'+year; form = document.getElementById('formulario'); formulariotab1 = FormValidation.formValidation( document.getElementById('formulario'), { locale: 'es_ES', localization: FormValidation.locales.es_ES, fields: { tipodocumento: { validators: { notEmpty: { message: 'Campo requerido'} } }, documento: { validators: { notEmpty: { message: 'Campo requerido'}, stringLength: { max: 15, message: 'El número de documento debe contener como máximo 15 caracteres.' }, regexp: {regexp: /^[a-zA-Z0-9]+$/i, message: 'Solo se permiten letras y números en este campo.'} } }, paisdocumento: { validators: { notEmpty: { message: 'Campo requerido'} } }, nombre1: { validators: { notEmpty: { message: 'Campo requerido'}, regexp: {regexp: /^[a-zA-ZñÑüÜ]+$/i, message: 'Solo se permiten letras y una única palabra en este campo.'} } }, nombre2: { validators: { regexp: {regexp: /^[a-zA-Z\sñÑüÜ]+$/i, message: 'Solo se permiten letras en este campo.'} } }, apellido1: { validators: { notEmpty: { message: 'Campo requerido'}, regexp: {regexp: /^[a-zA-ZñÑüÜ]+$/i, message: 'Solo se permiten letras en este campo.'} } }, apellido2: { validators: { regexp: {regexp: /^[a-zA-Z\sñÑüÜ]+$/i, message: 'Solo se permiten letras en este campo.'} } }, fechanacimiento: { validators: { notEmpty: { message: 'Campo requerido'}, date: { message: 'Fecha inválida', format: 'DD/MM/YYYY', min: inicio, max: fin } } }, telefono: { validators: { regexp: {regexp: /^[1-9][0-9]*$/i, message: 'Número de teléfono inválido.' }, stringLength: { min: 7, max: 24, message: 'El número de teléfono debe contener entre 7 y 24 dígitos.' } } }, celular: { validators: { notEmpty: { message: 'Campo requerido'}, regexp: {regexp: /^[1-9][0-9]*$/i, message: 'Número de celular inválido.' }, stringLength: { min: 10, max: 10, message: 'El número celular debe contener 10 dígitos.' } } }, sexo: { validators: { notEmpty: { message: 'Campo requerido'} } }, tipoinscripcion: { validators: { notEmpty: { message: 'Campo requerido'} } }, programa1: { validators: { notEmpty: { message: 'Campo requerido'} } }, programa2: { validators: { } }, periodo: { validators: { notEmpty: { message: 'Campo requerido'} } }, estadocivil: { validators: { notEmpty: { message: 'Campo requerido'} } }, paisnacimiento: { validators: { notEmpty: { message: 'Campo requerido'} } }, departamentonacimiento: { validators: { notEmpty: { message: 'Campo requerido'} } }, municipionacimiento: { validators: { notEmpty: { message: 'Campo requerido'} } }, municipionacimiento2: { validators: { notEmpty: { message: 'Campo requerido'} } }, pais: { validators: { notEmpty: { message: 'Campo requerido'} } }, departamento: { validators: { notEmpty: { message: 'Campo requerido'} } }, municipio: { validators: { notEmpty: { message: 'Campo requerido'} } }, municipio2: { validators: { notEmpty: { message: 'Campo requerido'} } }, direccion: { validators: { notEmpty: { message: 'Campo requerido'}, stringLength: { min: 6, max: 255, message: 'La dirección debe contener al menos 6 caracteres.' } } }, email1: { validators: { notEmpty: { message: 'Campo requerido'}, regexp: {regexp: /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/, message: 'Correo electrónico inválido.' }, } }, email2: { validators: { notEmpty: { message: 'Campo requerido'}, identical: { compare: function() { return form.querySelector('[name="email1"]').value; }, message: 'El correo electrónico tiene que ser igual al anterior.' } } }, password1: { validators: { notEmpty: { message: 'Campo requerido'}, stringLength: { min: 6, message: 'La contraseña debe contener al menos 6 caracteres.' }, regexp: {regexp: /^[a-zA-Z0-9!@#\$%\^\&*\)\(+=._-]+$/i, message: 'Carácter inválido.' } } }, password2: { validators: { notEmpty: { message: 'Campo requerido'}, stringLength: { min: 6, message: 'La contraseña debe contener al menos 6 caracteres.' }, identical: { compare: function() { return form.querySelector('[name="password1"]').value; }, message: 'La confirmación de la contraseña tiene que ser igual a la anterior.' } } }, habeasdata: { validators: { notEmpty: { message: 'Campo requerido'} } } }, plugins: { trigger: new FormValidation.plugins.Trigger(), excluded: new FormValidation.plugins.Excluded(), submitButton: new FormValidation.plugins.SubmitButton(), bootstrap: new FormValidation.plugins.Bootstrap(), defaultSubmit: new FormValidation.plugins.DefaultSubmit(), icon: new FormValidation.plugins.Icon({ valid: 'fa fa-check fv-plugins-icon--valid', invalid: 'fa fa-times fv-plugins-icon--invalid', validating: 'fa fa-refresh' }), transformer: new FormValidation.plugins.Transformer({ nombre1: { notEmpty: function(field, element, validator) { const value = element.value; return value.trim(); }, }, apellido1: { notEmpty: function(field, element, validator) { const value = element.value; return value.trim(); }, }, documento: { notEmpty: function(field, element, validator) { const value = element.value; return value.trim(); }, }, }), } } ) .on('core.form.valid', function() { var form = $('#formulario'); var btn1 = $('.btn-loading'); var btn2 = $('.btn-cancel'); formsubmit(form, btn1, btn2); }); formulariotab2 = FormValidation.formValidation( document.getElementById('formularioInicio'), { locale: 'es_ES', localization: FormValidation.locales.es_ES, fields: { 'usuario': { validators: { notEmpty: { message: 'Campo requerido'}, stringLength: { min: 4, message: 'El usuario debe contener al menos 6 caracteres.' }, } }, 'password': { validators: { notEmpty: { message: 'Campo requerido'}, stringLength: { min: 6, message: 'La contraseña debe contener al menos 6 caracteres.' }, } } }, plugins: { trigger: new FormValidation.plugins.Trigger(), excluded: new FormValidation.plugins.Excluded(), submitButton: new FormValidation.plugins.SubmitButton(), bootstrap: new FormValidation.plugins.Bootstrap(), defaultSubmit: new FormValidation.plugins.DefaultSubmit(), icon: new FormValidation.plugins.Icon({ valid: 'fa fa-check fv-plugins-icon--valid', invalid: 'fa fa-times fv-plugins-icon--invalid', validating: 'fa fa-refresh' }) } } ) .on('core.form.valid', function() { var form = $('#formularioInicio'); var btn1 = $('.btn-ingreso'); var btn2 = $('.btn-registro'); formsubmit(form, btn1, btn2); }); $('.select2-tab1').select2({ dropdownParent: $("#modalTab1"), templateResult: iconFormat, templateSelection: iconFormat, escapeMarkup: function(m) { return m; } }) .on('change', function () { formulariotab1.revalidateField(this.id); }); $('.select2-tab2').select2({ dropdownParent: $("#modalTab2"), templateResult: iconFormat, templateSelection: iconFormat, escapeMarkup: function(m) { return m; } }) .on('change', function () { formulariotab2.revalidateField(this.id); }); // Format icon function iconFormat(icon) { var originalOption = icon.element; if (!icon.id) { return icon.text; } $icon = '' + icon.text; return $icon; } // oculta los dropsdowns de // y municipio si el pais no es colombia $('#pais').change(function () { var tipo = $(this).find(':selected').val(); if (tipo === "COL"){ $("#departamentodiv").show(); $("#municipiodiv").show(); $("#municipio2div").hide(); } else { $("#departamentodiv").hide(); $("#municipiodiv").hide(); $("#municipio2div").show(); } }); $('#departamento').change(function () { var departamento = $(this).find(':selected').val(); $.get('CiudadesDepartamentosServlet', { departamentoNombre: departamento }, function (jsonResponse) { var select = $("#municipio"); select.find('option').remove(); $.each(jsonResponse, function (index, value) { var datos = value.split('*-*'); var id = datos[0]; var nombre = datos[1]; $('