PageSourceSearch

https://panel.lucushost.com/templates/orderforms/lucushost_v15/js/global.js

js lucushost.com collected 2026-09-24 20:39:17 UTC 11,024 bytes, 252 lines download raw bytes

1var nif_primera_validacion=false;
2
3function formValidationCustom(value, validator, field) {
4    //console.log(field.attr("id"));
5    value=value.trim();
6    if(value=='')
7        return {valid: false,message: 'Escribe tu '+field.attr("placeholder")+'.'};
8    switch(field.attr("id")) {
9        case "newEmail": //new email
10            if(value.match(/^[^@\s]+@([^@\s]+\.)+[^@\s]+$/)){
11                $.post("/app/order/async/customer/checkEmailAvailable","email="+value,function(data){
12                    if(data.success && field.val().trim()==data.email.trim() && !data.available){
13                    	validator.updateStatus(field,'INVALID','callback')
14                            	 .updateMessage(field,'callback',(data.error!='')?data.error:field.attr("placeholder")+' no válido.');
15                    }
16                });
17                return true;
18            }
19            break;
20        case "nif":
21            if(field.closest('form').find('select[name=country]  option:selected').val()=='ES'){
22                var cifRexp = /^([ABCDEFGHJKLMNPQRSUVW])(\-)?(\d{7})([0-9A-J])$/;
23                var validChars = 'TRWAGMYFPDXBNJZSQVHLCKET';
24                var nifRexp = /^[0-9]{8}[TRWAGMYFPDXBNJZSQVHLCKET]{1}$/i;
25                var nieRexp = /^[XYZ]{1}[0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKET]{1}$/i;
26                var str = value.toString().toUpperCase();
27                var tipo_empresa=$('#customertype').val();
28                if(tipo_empresa != 'Empresa'){
29                    if (nifRexp.test(value) || nieRexp.test(value)){
30                        var nie = str
31                            .replace(/^[X]/, '0')
32                            .replace(/^[Y]/, '1')
33                            .replace(/^[Z]/, '2');
34                        var letter = str.substr(-1);
35                        var charIndex = parseInt(nie.substr(0, 8)) % 23;
36                        if (validChars.charAt(charIndex) === letter){
37                            nif_primera_validacion=true;
38                            var nombre_completo=$('#firstname').val()+' '+$('#lastname').val();
39                            validar_identificacion_fiscal(nombre_completo,value,field,'nif');
40                        } 
41                    }
42                    nif_primera_validacion=true;
43                    return {valid: false,message: 'Documento no válido.'};
44                }else{
45                    if(cifRexp.test(value)){
46                        nif_primera_validacion=true;
47                        var nombre_completo=$('#companyname').val();
48                        if(nombre_completo == ''){
49                            return {valid: false,message: 'Debes introducir un nombre de Empresa.'}; 
50                        }
51                        validar_identificacion_fiscal(nombre_completo,value,field,'cif');
52                    }
53                    nif_primera_validacion=true;
54                    return {valid: false,message: 'Documento no válido.'};    
55                }
56            }
57            return true;
58            break;
59        case "phonenumber":
60            var numbersRexp = /^(\d+)$/;
61            if(!numbersRexp.test(value))
62                return {valid: false,message: 'Solo se aceptan números.'}; 
63            if(field.closest('form').find('select[name=country]  option:selected').val()!='ES')
64                return true;
65            var phoneRexp = /^(9|8|7|6)(\d{8})$/;
66            if(phoneRexp.test(value))
67                return true;
68            break;
69        case "password":
70            var msg='';
71            if (value.length < 8)
72                msg+="8 o mas caracteres.<br>";
73            if (value === value.toLowerCase())
74                msg+="Al menos una letra mayúscula.<br>";
75            if (value === value.toUpperCase())
76                msg+="Al menos una letra minúscula.<br>";
77            if (value.search(/[0-9]/) < 0) 
78                msg+="Al menos un número.<br>";
79            return (msg=='')?true: {valid: false,message: "<div style='text-align:left'>Requisitos:<br>"+msg+"</div>"}; 
80        case "firstname":
81        	validator.updateStatus(field.closest('form').find('select[id=customertype]'),'VALID');
82        	validator.updateStatus(field.closest('form').find('select[id=country]'),'VALID');
83        	return true;
84    } 
85    return {valid: false,message: field.attr("placeholder")+' no válido.'};
86}
87jQuery(document).ready(function() {
88    jQuery('form#form_order input[type="submit"]').click(function(e){
89        var radioaccounts=$('div.bloc-cart-accounts input[type=radio]');
90        if(radioaccounts.length && !radioaccounts.filter(":checked").length)
91        {
92            $('div.bloc-cart-accounts small.help-block.hidden').removeClass('hidden');
93        }
94    });
95    jQuery('form#form_order').submit(function( e ) {
96        var submitButton=jQuery(this).find('input[type=submit]');
97        submitButton.attr('disabled','disabled');
98        jQuery(this).find('.clear-cart').hide();
99        submitButton.attr('value',submitButton.attr('data-process'));
100    });
101    jQuery.xhrPool = [];
102    jQuery.xhrPool.abortAll = function() {
103        $(this).each(function(i, jqXHR) {
104            jqXHR.abort();
105            $.xhrPool.splice(i, 1);
106        });
107    }
108    jQuery.ajaxSetup({
109        beforeSend: function(jqXHR) { jQuery("body").css("cursor", "progress");$.xhrPool.push(jqXHR); },
110        complete: function(jqXHR) {
111            jQuery("body").css("cursor", "default");
112            var i = $.xhrPool.indexOf(jqXHR);
113            if (i > -1) $.xhrPool.splice(i, 1);
114        }
115    });
116    
117    // Selects
118    var selects = jQuery('select.gcselect');
119    selects.easyDropDown({cutOff: 5,wrapperClass: 'metro'});
120    
121    //footer buttons on modal login
122    jQuery('header a[data-toggle="tab"][aria-controls="login"]').on('shown.bs.tab', function (e) {
123        jQuery('header .modal-footer a[href=#signin]').show();
124        jQuery('header .modal-footer a[href=#login]').hide();
125    });
126    jQuery('header a[data-toggle="tab"][aria-controls="signin"]').on('shown.bs.tab', function (e) {
127        jQuery('header .modal-footer a[href=#signin]').hide();
128        jQuery('header .modal-footer a[href=#login]').show();
129    });
130    jQuery('header .modal-footer a[href=#signin]').click(function(e){
131        e.preventDefault();
132        jQuery('#modal-login .tabs-modal a[href=#signin]').tab('show');
133    });
134    jQuery('header .modal-footer a[href=#login]').click(function(e){
135        e.preventDefault();
136        jQuery('#modal-login .tabs-modal a[href=#login]').tab('show');
137    });
138    jQuery('form[id^=modal_user]').on('keypress', 'input[type=text],select', function (e) {
139                if (e.which == 13) {
140			        e.preventDefault();
141                    return true;
142			        /*
143                    var $canfocus = $(':focusable');
144			        var index = $canfocus.index(this) + 1;
145			        if (index >= $canfocus.length) index = 0;
146			        $canfocus.eq(index).focus();
147                    */
148			    }
149			}).submit(function(e){
150                e.preventDefault();
151            }).on('success.form.fv', function(e) {
152                e.preventDefault();
153                var form = jQuery(this);
154                form.find(".alert").remove();
155                var action =form.find("input[type=hidden][name=action]").val();
156                jQuery.post('/app/order/async/customer/'+action, form.serialize()).done(
157                    function(data) {
158                        var msg='';
159                        var redirect=false;
160                        if(data.success){
161                        	if(data.dologin){
162                        		redirect=true;
163                        		window.location=data.dologin;
164                        	}
165                        	else if(data.error!='')
166                        		msg=data.error;
167                        }
168                        if(!redirect){
169	                        msg=(msg!='')?msg:'Error, inténtalo de nuevo o ponte en contacto con soporte técnico';
170							var h3=form.find("h3").first();
171							h3.first().after('<div class="alert alert-danger text-center" role="alert">'+msg+'</div>');
172							h3.closest('div.modal-login').animate({ scrollTop: 0 }, "slow");
173						}
174                    }
175                );
176            });
177    jQuery('form[id^=modal_user]').formValidation();
178    jQuery('#configure_domains').formValidation('validate');
179    jQuery('#product-configuration-form').formValidation();
180    jQuery('input#email').on('copy paste cut drop',function(){
181        return false;
182    });
183    jQuery('input#email2').on('copy paste cut drop',function(){
184        return false;
185    });
186    
187    
188    jQuery('#myTab').tabCollapse();
189    
190    //logout
191    jQuery('header #logout').click(function(e){
192        jQuery.ajax({
193            url: '/logout.php',
194            cache: false
195        }).done(function( html ) {
196            window.location = window.location.href.split("#")[0];
197        });
198    });
199
200    //Si se cambia el nombre volvemos a comprobar y validamos de nuevo el campo nif
201    $('#firstname,#lastname').blur(function () {
202        var validator = $('#modal_user_registration').data('formValidation');
203        if($(this).val() == ''){
204             return;
205        }
206        if(nif_primera_validacion){
207            var nombre_completo=$('#firstname').val()+' '+$('#lastname').val();
208            var value = $('#nif').val();
209            validar_identificacion_fiscal(nombre_completo,value,$('#nif'),'nif');
210        }
211    });
212
213    //Si se cambia el tipo de cliente, reseteamos el campo nif para obligar a validar de nuevo
214    $('#customertype').change(function () { 
215        var validator = $('#modal_user_registration').data('formValidation');
216        $('#nif').val('');
217        validator.updateStatus($('#nif'),'NOT_VALIDATED','callback');
218    });
219
220    
221});
222
223function scrollToElement(element,speed){
224    //console.log(element);
225    if(element.offset()){
226        $('html, body').animate({ scrollTop: element.offset().top}, speed);
227    }
228    return true;
229}
230
231function validar_identificacion_fiscal(nombre,nif,field,tipo){
232    const respuesta = fetch("/index.php?m=validador_fiscal&validar-tax-id=", {
233        method: "POST",
234        headers: { "Content-Type": "application/x-www-form-urlencoded" },
235        body: new URLSearchParams({nif:nif,razon_social:nombre})
236    });
237    var validator = $('#modal_user_registration').data('formValidation');
238    respuesta.then(respuesta=>respuesta.json()).then(respuesta=>{
239        if(respuesta){
240            validator.updateStatus(field,'VALID','callback');
241        }else{
242            validator.updateStatus(field,'INVALID','callback')
243            if(tipo=='nif'){
244                validator.updateMessage(field,'callback','Verifica tu NIF, Nombre y Apellidos que sean los correctos.')
245            }else{
246                validator.updateStatus(field,'INVALID','callback').updateMessage(field,'callback','Verifica que el CIF introducido sea correcto.')
247            }
248        }
249    }).catch(()=>{
250        validator.updateStatus(field,'VALID','callback');
251    });
252}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.