$(function(){ }) $(function(){ parseoDato(); $("body").on("blur",".email",function(){ 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(""); alert("Email inválido"); } }); $(".largo_minimo").blur(function(){ if($(this).val().length < 3 && $(this).val() != "" ) { alert($(this).attr("placeholder")+" debe tener un largo minimo de 3 caracteres."); $(this).val("") } }); $("#direccion_enel").hide(); $("#comuna_enel").change(function(){ $("#numero_cliente_enel").val(""); $("#direccion_enel").show().val(""); if($(this).val() != "") { var comuna = $(this).val() comuna = comuna.replace(/\s/g,"_"); //https://admin.gestion.bopen.cl/enel/ var options = { //url: "https://json.institucion.cl/enel/"+comuna+".json", //url: "https://admin.gestion.bopen.cl/enel/"+comuna+".json", url : "https://santiago.ayudabomberos.cl/enel/"+comuna+".json", getValue: function(element) { return element.name; }, list: { showAnimation: { type: "fade", //normal|slide|fade time: 100, callback: function() {} }, hideAnimation: { type: "slide", //normal|slide|fade time: 100, callback: function() {} }, onLoadEvent : function(){ }, onChooseEvent: function() { var index = $("#direccion_enel").getSelectedItemData().code; $("#numero_cliente_enel").val(index); }, maxNumberOfElements: 500, match: { enabled: true }, sort: { enabled: true } }, theme: "square" }; $("#direccion_enel").easyAutocomplete(options); } else { $("#direccion_enel").hide(); } }); 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 $("#siguiente_al_baso_dos").click(function(){ obj = $(this) $("#siguiente_al_baso_dos").val("Validando..").attr("disabled",true); $.post("./",{"_ajax_":"validarDoc","rut" : $("[name='crm_contacto[rut]']").val(),"documento" : $("[name='crm_contacto[numero_documento]']").val() },function(data){ $("#siguiente_al_baso_dos").val("Siguiente").attr("disabled",false); //if(1 == 1) { var obliga = Array(); var valid = true; $("#paso_1_fieldset").find(".required").each(function(){ if($(this).val() == "") { animating = ""; valid = false; obliga.push($(this).attr("placeholder")); } }); obliga = obliga.join(", "); if(valid == false) { alert("Los siguientes campos son obligatoros : "+obliga); return false; } $("#monto_seleccionado").change(); current_fs = obj.parent(); next_fs = obj.parent().next(); //activate next step on progressbar using the index of next_fs $("#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' }); } else { alert("Número de documento no valido"); } }); }); $(".previous").click(function(){ if(animating) return false; animating = true; current_fs = $(this).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(); animating = false; }, //this comes from the custom easing plugin easing: 'easeInOutBack' }); }); /*FIN*/ $("#telefono").keyup(function(e){ //the "phoneNumber" can be any other input field ID if(e.keyCode == 8){ //trap the backspace key so that when deleting value, "checkPhoneNumber" will not be called. //do nothing }else{ checkPhoneNumber("telefono"); //call checkPhoneNumber function and put "phoneNumber" field ID as parameter } }); $("#telefono").blur(function(e){ //the "phoneNumber" can be any other input field ID checkPhoneNumber("telefono"); //call checkPhoneNumber function and put "phoneNumber" field ID as parameter }); 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; $("#paso_2_fieldset").find(".required").each(function(){ if($(this).val() == "") { animating = ""; valid = false; obliga.push($(this).attr("placeholder")); } }); obliga = obliga.join(", "); if(valid == false) { alert("Los siguientes campos son obligatoros : "+obliga); return false; } if($("#numero_cliente_enel").val() == "") { alert("La direccion '"+$("#direccion_enel").val()+"' no es válida. Debe seleccionar una dirección de la lista desplegada. "); return false; } $.post("./",$(this).serializeArray(),function(){ $('#loginForm').removeClass("hide"); alertify.genericDialog ( $('#loginForm')[0]).set({onshow:null, onclose:function(){ location.reload();}}); },"jsonp"); return false; }); $(".rut").Rut({ on_error: function(){ alert("Rut no valido"); } }); $(".numero").keydown(function (event) { return NumericField($(this).val(), event, true); }); $("#monto_seleccionado").change(function(){ if($(this).val() == "Otro") { $("#monto_otro").removeClass("hide"); $("#monto_otro").addClass("required") } else { $("#monto_otro").removeClass("required") $("#monto_otro").addClass("hide"); $("#monto_otro").val("") } }); }) var strUserAgent = navigator.userAgent.toLowerCase(); var isIE = strUserAgent.indexOf('msie') > -1; var reKeyboardChars = /[\x03\x08\x09\x0D\x16\x18\x1A\x2E\x23\x24\x25\x26\x27\x28\x2D]/; var reNumber = /^((\d{1,3}\.)*\d{3}|\d*,{0,1}\d+|(\d{1,3}\.)*\d{3},{0,1}\d+|\d*)$/; function NumericField(str, objEvent, isFloat) { oldValue = str; strKey = GetChar(objEvent); if (((objEvent.which) ? objEvent.which : event.keyCode) == 13 || (((objEvent.which) ? objEvent.which : event.keyCode) == 190 && isFloat)) return true; if (!KeyNumber(objEvent) && !reKeyboardChars.test(strKey) && !(objEvent.ctrlKey && reClipboard.test(strKey))) return false; return true; } function KeyNumber(objEvent) { return reNumber.test(GetChar(objEvent)); } function GetChar(objEvent) { var arrKeys = new Array(); arrKeys[96] = '0'; arrKeys[97] = '1'; arrKeys[98] = '2'; arrKeys[99] = '3'; arrKeys[100] = '4'; arrKeys[101] = '5'; arrKeys[102] = '6'; arrKeys[103] = '7'; arrKeys[104] = '8'; arrKeys[105] = '9'; arrKeys[111] = '/'; arrKeys[193] = '/'; iKeyCode = GetKeyCode(objEvent); if (arrKeys[iKeyCode] != null) return arrKeys[iKeyCode]; return String.fromCharCode(iKeyCode); } function GetKeyCode(objEvent) { if (isIE) return objEvent.keyCode; return objEvent.which; }