$(function(){ }) function getParameterByName(name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, '\\$&'); var regex = new RegExp('[?&]' + name + '(=([^]*)|&|#|$)'), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, ' ')); } function getParameterByNameTrack(name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, '\\$&'); var regex = new RegExp('[?&]' + name + '(=([^]*)|&|#|$)'), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, ' ')); } function setFomsParam(name, value) { $("form").each(function () { $(this).append(''); }); } $(function () { if ($("input[name='institucion_id']").val() == 1) { $("#boton_anterior").appendTo("#paso_2_fieldset"); } $("#codigo_captador").blur(function () { if ($(this).val().length == 4) { $("option[value='Cta. Cte. Bancaria']").hide(); $("option[value='Cuenta Vista']").hide(); $("option[value='Cuenta Rut']").hide(); $("#monto_seleccionado option[value='3000']").hide(); $("#monto_seleccionado option[value='5000']").hide(); } else { $("option[value='Cta. Cte. Bancaria']").show(); $("option[value='Cuenta Vista']").show(); $("option[value='Cuenta Rut']").show(); $("#monto_seleccionado option[value='3000']").show(); $("#monto_seleccionado option[value='5000']").show(); } }); if (getParameterByName("utm_source")) { console.log(" file: Js.js:71 ~ getParameterByName(utm_source):", getParameterByName("utm_source")) localStorage.setItem('utm_source', getParameterByName("utm_source")); setFomsParam("utm_source", localStorage.getItem('utm_source')); } else { if (localStorage.getItem('utm_source')) { setFomsParam("utm_source", localStorage.getItem('utm_source')); } } if (getParameterByName("utm_medium")) { localStorage.setItem('utm_medium', getParameterByName("utm_medium")) setFomsParam("utm_medium", localStorage.getItem('utm_medium')); } else { if (localStorage.getItem('utm_medium')) { setFomsParam("utm_medium", localStorage.getItem('utm_medium')); } } if (getParameterByName("utm_campaign")) { localStorage.setItem('utm_campaign', getParameterByName("utm_campaign")) setFomsParam("utm_campaign", localStorage.getItem('utm_campaign')); } else { if (localStorage.getItem('utm_campaign')) { setFomsParam("utm_campaign", localStorage.getItem('utm_campaign')); } } if (getParameterByName("utm_id")) { localStorage.setItem('utm_id', getParameterByName("utm_id")) setFomsParam("utm_id", localStorage.getItem('utm_id')); } else { if (localStorage.getItem('utm_id')) { setFomsParam("utm_id", localStorage.getItem('utm_id')); } } if (getParameterByName("utm_term")) { localStorage.setItem('utm_term', getParameterByName("utm_term")) setFomsParam("utm_term", localStorage.getItem('utm_term')); } else { if (localStorage.getItem('utm_term')) { setFomsParam("utm_term", localStorage.getItem('utm_term')); } } if (getParameterByName("utm_content")) { localStorage.setItem('utm_content', getParameterByName("utm_content")) setFomsParam("utm_content", localStorage.getItem('utm_content')); } else { if (localStorage.getItem('utm_content')) { setFomsParam("utm_content", localStorage.getItem('utm_content')); } } var _cid_ = getParameterByName('_cid_'); if (_cid_ != null) { $.ajax({ type: 'POST', url: 'https://haztesocio.ayudabomberos.cl', data: { "_ajax_": 'getCID', "_cid_": _cid_ }, dataType: 'jsonp', success: function (dataSet) { //alert($("#comuna_region option[value='"+dataSet.comuna+"']").val()); $("input[name='crm_contacto[nombre]']").val(dataSet.nombre); $("input[name='crm_contacto[app]']").val(dataSet.app); $("input[name='crm_contacto[rut]']").val(dataSet.rut); $("input[name='crm_contacto[email]']").val(dataSet.email); $("input[name='crm_contacto[celular]']").val(dataSet.celular); $("#consulta_id").val(dataSet.consulta_id); $("input[name='contacto_id']").val(dataSet.contacto_id); $("#comuna_region option[value='" + dataSet.comuna + "']").prop('selected', "true"); var title = $("select[name='crm_contacto[comuna]']").val(dataSet.comuna); $("select[name='crm_contacto[comuna]']").change(); } }); } }); $(function () { $("#msform .dirigir_a").click(function () { $('select[name="crm_contacto[comuna]"]').removeClass("hide").change(); }); $("#msform select[name='crm_contacto[comuna]']").change(function () { if ($(this).val() == "") { return false; } $.post('https://haztesocio.ayudabomberos.cl', { "_ajax_": 'getCondicionesNew', "comuna_id": $(this).val(), }, function (dataSet) { var payku = false; $('#MedioPago').find('option').remove(); var option = ''; $('#Medio_Pago').html(""); $("input[name='institucion_id']").val(dataSet.institucion_id); $("#priva2").html(Base64.decode(dataSet.legal)); $.each(dataSet.mdp, function (i, val) { if (val == "Payku") { option += ''; } else { option += ''; } }); $("#test_ab").remove(); var test_ab = ""; if (dataSet.test_ab != "") { test_ab = ''; } $("#msform").append(test_ab); $("#MedioPago").html(option); $("#MedioPago").change(); if ($(".dirigir_a:checked").val() == 1) { $("#institucion_id").replaceWith(Base64.decode(dataSet.papi)) } else if ($(".dirigir_a:checked").val() == 2) { $("#institucion_id").replaceWith(Base64.decode(dataSet.child)) } }, "jsonp"); }); $("#textp_tipo_pago").blur(function () { if ($("#modal-toku").is(":visible")) { // Si ya está abierto el modal, no volver a cargar return false; } $("#msform .submit").prop("disabled", true); $("#msform .submit").val("Validando"); var obj = $(this) $.post("https://haztesocio.ayudabomberos.cl", { "_ajax_": "validarTipoPago", "tipo": $("#msform #tipo_pago").val(), "rut": $("#msform input[name='crm_contacto[rut]']").val(), "numero": obj.val() }, function (e) { if (e == false) { alert($("#MedioPago").val() + " inválida."); obj.val("") } $(".submit").prop("disabled", false); $(".submit").val("Enviar"); }, "jsonp"); }); if (getParameterByName("vid")) { $.cookie('vid', getParameterByName("vid")); } if ($.cookie('vid') != undefined && $.cookie('vid') != "") { $("#msform").append(''); } if (getParameterByName("uid")) { $.cookie('uid', getParameterByName("uid")); } if ($.cookie('uid') != undefined && $.cookie('uid') != "") { $("#msform").append(''); } if ($('#msform input[name="institucion_id"]').val() == 34) { $("option[value='Cta. Cte. Bancaria']").remove(); // } //GRACIAS alertify.genericDialog || alertify.dialog('genericDialog', function () { return { main: function (content) { this.setContent(content); }, setup: function () { return { focus: { element: function () { return this.elements.body.querySelector(this.get('selector')); }, select: true }, options: { basic: true, maximizable: false, resizable: false, padding: false } }; }, settings: { selector: undefined } }; }); //FIN GRACIAS /*PASOS FORM*/ var current_fs, next_fs, previous_fs; //fieldsets var left, opacity, scale; //fieldset properties which we will animate var animating; //flag to prevent quick multi-click glitches $("#msform .next").click(function () { if (!validarNumeroCelular($("#telefono").val())) { alert("El número de teléfono es incorrecto"); $("#telefono").val(""); $("#telefono").focus(); return false; } if (animating) return false; animating = true; var obliga = Array(); var valid = true; var paso = 0; var siguiente = $(this).attr("id"); if (siguiente == "siguiente_al_baso_dos") { $("#msform #paso_1_fieldset").find(".required").each(function () { paso = 10; if ($(this).attr("type") == "checkbox") { //alert($(this).prop("checked")); if (!$(this).prop("checked")) { animating = false; valid = false; obliga.push($(this).attr("placeholder")); } } else { if ($(this).val() == "") { animating = false; valid = false; obliga.push($(this).attr("placeholder")); } } if ($(this).hasClass("email")) { if (!/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test($(this).val())) { $(this).val(""); $(this).focus(); alert("Debe ingresar un email Válido, ej: micorreo@miempresa.com"); obliga.push("E-Mail"); valid = false; animating = false; } } }); } if (siguiente == "siguiente_al_paso_tres") { $("#msform #paso_2_fieldset").find(".required").each(function () { paso = 10; if ($(this).attr("type") == "checkbox") { //alert($(this).prop("checked")); if (!$(this).prop("checked")) { animating = false; valid = false; obliga.push($(this).attr("placeholder")); } } else { if ($(this).val() == "") { animating = false; valid = false; obliga.push($(this).attr("placeholder")); } } }); } obliga = obliga.join(", "); if (valid == false) { alert("Los siguientes campos son obligatorios : " + obliga); return false; } if (paso == 10) { $.post("https://santiago.ayudabomberos.cl/?paso=10", $("#msform").serializeArray(), function (e) { $("input[name='consulta_id']").val(e.consulta_id); $("#consulta_id").val(e.consulta_id); }, "jsonp"); } current_fs = $(this).parent(); next_fs = $(this).parent().next(); //activate next step on progressbar using the index of next_fs $("#msform #progressbar li").eq($("fieldset").index(next_fs)).addClass("active"); //show the next fieldset next_fs.show(); //hide the current fieldset with style current_fs.animate({ opacity: 0 }, { step: function (now, mx) { //as the opacity of current_fs reduces to 0 - stored in "now" //1. scale current_fs down to 80% scale = 1 - (1 - now) * 0.2; //2. bring next_fs from the right(50%) left = (now * 50) + "%"; //3. increase opacity of next_fs to 1 as it moves in opacity = 1 - now; current_fs.css({ 'transform': 'scale(' + scale + ')', 'position': 'absolute' }); next_fs.css({ 'left': left, 'opacity': opacity }); }, duration: 800, complete: function () { current_fs.hide(); animating = false; }, //this comes from the custom easing plugin easing: 'easeInOutBack' }); }); $(".previous").click(function () { if (animating) return false; animating = true; current_fs = $(this).parent().parent(); previous_fs = $(this).parent().prev(); //de-activate current step on progressbar $("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active"); //show the previous fieldset previous_fs.show(); //hide the current fieldset with style current_fs.animate({ opacity: 0 }, { step: function (now, mx) { //as the opacity of current_fs reduces to 0 - stored in "now" //1. scale previous_fs from 80% to 100% scale = 0.8 + (1 - now) * 0.2; //2. take current_fs to the right(50%) - from 0% left = ((1 - now) * 50) + "%"; //3. increase opacity of previous_fs to 1 as it moves in opacity = 1 - now; current_fs.css({ 'left': left }); previous_fs.css({ 'transform': 'scale(' + scale + ')', 'opacity': opacity }); }, duration: 800, complete: function () { current_fs.hide(); var paso3 = $("#paso_3_fieldset").attr("id"); let backgroundColor = $("#embed_form_wp").data("estilo"); if ($("#paso_3_fieldset").attr("id") != "paso_3_fieldset") { $("#paso_1_fieldset").css("position", "none"); $("#paso_1_fieldset").removeAttr("style"); if (backgroundColor) { $("#msform #paso_1_fieldset, #paso_2_fieldset").css("background-color", backgroundColor); } } animating = false; }, //this comes from the custom easing plugin easing: 'easeInOutBack' }); }); /*FIN*/ document.getElementById('telefono').addEventListener('input', function (e) { var numero = e.target.value.replace(/\D/g, ''); // Elimina caracteres no numéricos // Asegúrate de que el número comience con 9 if (numero.length > 0 && numero[0] !== '9') { numero = '9' + numero; } // Limitar la longitud a 9 dígitos numero = numero.substring(0, 9); var numeroFormateado = ''; // Aplicar la máscara mientras el usuario escribe for (let i = 0; i < numero.length; i++) { if (i === 1 || i === 5) { numeroFormateado += ' '; // Añade un espacio después del primer y quinto dígito } numeroFormateado += numero[i]; } e.target.value = numeroFormateado; }); function validarNumeroCelular(numero) { // Limpiar el número para remover caracteres no numéricos var numeroLimpio = numero.replace(/[^0-9]/g, ''); // La expresión regular para un número de celular chileno sin el código de país var regex = /^9\d{8}$/; return regex.test(numeroLimpio); } function aplicarMascaraCelularChileno(input) { var numero = input.replace(/\D/g, '').substring(0, 9); // Elimina caracteres no numéricos y limita a 9 dígitos var partes = []; if (numero.length > 4) { partes.push(numero.substring(0, 1)); partes.push(numero.substring(1, 5)); partes.push(numero.substring(5, 9)); } else if (numero.length > 1) { partes.push(numero.substring(0, 1)); partes.push(numero.substring(1, 5)); } else { partes.push(numero); } return partes.join(' '); } function checkPhoneNumber(id) { var phoneValue = $("#" + id).val(); //get current field value var phoneLength = $("#" + id).val().length; //get current field value length if (phoneLength == 1) { //if current length is 3, then insert a hyphen phoneValue += "-"; } else if (phoneLength == 6) { //if current length is 7, then insert a hyphen phoneValue += "-"; } //check is_digit for new character; if not, then use substr to get rid of it var tempValue = phoneValue.replace(/-/g, ""); //assign tempValue with phoneValue, which performs global string replacement (replace "-" with nothing) if (is_digit(tempValue) == false) { //check if all input characters are digits phoneValue = (phoneValue.substr(0, phoneLength - 1)); //if not, then use substr to get rid of the last entered character } //limit the phone value to 12 character if (phoneLength > 11) { phoneValue = (phoneValue.substr(0, 11)); //if field value length is greater than 12, then use substr to get rid of last character } $("#" + id).val(phoneValue); } function is_digit(input) { if (isNaN(input)) { return false; } else { return true; } } $("#msform").submit(function (e) { e.preventDefault(); var obliga = Array(); var valid = true; var formSerialize = $(this).serializeArray(); if ($("#MedioPago").val() == "Cta. Cte. Bancaria") { var rut = $("input[name='crm_contacto[rut]']").val(); var cuenta = $("#textp_tipo_pago").val(); rut = rut.split(".").join(""); rut = rut.split("-").join(""); cuenta = cuenta.split(".").join(""); cuenta = cuenta.split("-").join(""); //se quita validacion el 22 de 09 de 2020, RI. /* if(rut.indexOf(cuenta,0)>=0) { alert("Favor ingresar Cuenta Corriente, no podemos procesar una Cuenta Rut."); return false; }*/ } if (!validarNumeroCelular($("#telefono").val())) { alert("El número de teléfono es incorrecto"); $("#telefono").val() return false; } var fieldset = "paso_2_fieldset"; if ($("#paso_3_fieldset").attr("id") == "paso_3_fieldset") { fieldset = "paso_3_fieldset"; } $("#msform #" + fieldset).find(".required").each(function () { if ($(this).val() == "") { animating = false; valid = false; obliga.push($(this).attr("placeholder")); } }); obliga = obliga.join(", "); if (valid == false) { alert("Los siguientes campos son obligatorios : " + obliga); return false; } if ($("#MedioPago").val() == "Cuenta Bancaria Online") { let rut = $("input[name='crm_contacto[rut]']").val(); let monto = ($("#monto_seleccionado").val() == 'Otro') ? $("monto_otro").val() : $("#monto_seleccionado").val(); let institucionId = $("input[name='institucion_id']").val(); let dataForm = { "_ajax_": 'saveCustomerToku', "government_id": rut.toUpperCase(), "mail": $("input[name='crm_contacto[email]']").val(), "name": $("input[name='crm_contacto[nombre]']").val() + ' ' + $("input[name='crm_contacto[app]']").val(), "phone_number": $("input[name='crm_contacto[celular]']").val(), "consulta_id": $("#consulta_id").val(), "institucion_id": institucionId, "monto_pago": monto, }; let montoFormateado = new Intl.NumberFormat('es-CL', { style: 'currency', currency: 'CLP' }).format(monto); $(".monto_cbo").html(montoFormateado); $.post("https://santiago.ayudabomberos.cl", dataForm, function (resp) { if (resp.response) { // $("#msform").hide(); var modales = $('#modals').clone(); $('#modals').remove(); $('body').append(modales); $("#modal-backdrop").css("display", "block"); $("#modal-toku").css("display", "block"); // $('#modal-toku').modal('show'); // $('#modal-toku').modal({backdrop: 'static', keyboard: false, show: true}); $("#body-modaltoku").html('