PageSourceSearch

https://risaraldaemprende.com/Javascript/Varios/Funciones.js?v=1.1.3

js risaraldaemprende.com collected 2026-10-03 18:35:37 UTC 19,190 bytes, 717 lines download raw bytes

1
2function pharis_util_log(mensaje)
3{
4    alert(mensaje);
5}
6
7function pharis_util_mensaje(mensaje)
8{
9    Mensaje(mensaje);
10}
11
12function pharis_util_cerrarmensaje(tiempo)
13{
14    CerrarMensaje(tiempo);
15}
16
17/*
18 Consulta un JSON en una url remota
19 elemento: Selector del desplegable a cargar, object o string. ej: $("#iddesplegable") ó "#iddesplegable"
20 id: Id del desplegable a cargar, string (atributo sólo para compatibilidad con anteriores versiones, seguir usando 'elemento')
21 url: Url de donde se obtendrán las opciones para el desplegable
22 variables: Variables para enviar
23 finalizar: funcion a ejecutar al finalizar la peticion, envía como primer parametro los datos
24 */
25function pharis_ajax_desplegable(config)
26{
27    var elemento = config.elemento;
28    
29    if (typeof(elemento) == "undefined" || elemento === ""){
30        
31        if(typeof(config.id) == "undefined" || config.id == "")
32            return false;
33            
34        if (!document.getElementById(config.id))
35        {
36            pharis_util_log("No existe un desplegable con el siguiente identificador ")
37            return false;
38        }
39
40        elemento = $("#"+config.id)
41        
42    }else if (typeof(elemento) == "string") {
43        elemento = $(elemento);
44    }
45    
46    config.type = "POST";
47    config.dataType = "json";
48    config.data = config.variables;
49
50    if (config.etiqueta_seleccione == undefined)
51        config.etiqueta_seleccione = "Seleccione...";
52
53    if (config.seleccione == undefined)
54        config.seleccione = true;
55
56    if (config.mostrarmensaje == undefined)
57        config.mostrarmensaje = true;
58    
59    if (config.mensaje == undefined)
60        config.mensaje = "Cargando...";
61
62    if (config.asincrono != undefined)
63        config.async = config.asincrono;
64
65    config.success = function (datos) {
66        
67        if (config.mostrarmensaje)
68            pharis_util_cerrarmensaje(0);
69
70        if (datos.length == 0)
71            return;
72
73        var i = 0;
74        var campoid;
75        var campotexto;
76
77        for (var key in datos[0]) {
78            if (i == 0)
79                campoid = key;
80
81            if (i == 1)
82                campotexto = key;
83
84            if (i > 1)
85                break;
86
87            i++;
88        }
89
90        $.each(datos, function (i, item) {
91            var valorid = eval('item.' + campoid);
92            var valortexto = eval('item.' + campotexto);
93            elemento.append('<option value="' + valorid + '">' + valortexto + '</option>');
94        });
95
96        if (config.finalizar != undefined)
97            config.finalizar.call(datos);
98
99    };
100
101    elemento.html("")
102
103    if (config.seleccione == true)
104        elemento.append('<option value="desplegable_sin_valor">' + config.etiqueta_seleccione + '</option>')
105
106    if (config.mostrarmensaje)
107        pharis_util_mensaje(config.mensaje)
108    
109    $.ajax(config);
110}
111
112
113function getElementsByClass(searchClass, node, tag)
114{
115    var classElements = [];
116
117    if (node === null ) {
118        node = document;
119    }
120
121    if ( tag === null ) {
122        tag = '*';
123    }
124
125    var els = node.getElementsByTagName(tag);
126    var elsLen = els.length;
127    var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
128
129    j = 0;
130
131    for (var i = 0; i < elsLen; i++) {
132        if (pattern.test(els[i].className)) {
133            classElements[j] = els[i];
134            j++;
135        }
136    }
137
138    return classElements;
139}
140
141function insertAfter(newElement, targetElement) {
142    var parent = targetElement.parentNode;
143
144    if (parent.lastChild == targetElement) {
145        parent.appendChild(newElement);
146    } else {
147        parent.insertBefore(newElement, targetElement.nextSibling);
148    }
149}
150
151function IntercambiarDisplay(objeto) {
152    if (document.getElementById(objeto)) {
153        if (document.getElementById(objeto).style.display == "none") {
154            document.getElementById(objeto).style.display = "";
155        } else {
156            document.getElementById(objeto).style.display = "none";
157        }
158    }
159}
160
161function MostrarOcultar(objeto) {
162    if (document.getElementById(objeto)) {
163        if (document.getElementById(objeto).style.visibility == "hidden" || document.getElementById(objeto).style.visibility === "") {
164            document.getElementById(objeto).style.visibility = "visible";
165            document.getElementById(objeto).style.display = "block";
166        } else {
167            document.getElementById(objeto).style.visibility = "hidden";
168            document.getElementById(objeto).style.display = "none";
169        }
170    }
171}
172
173function  ImprimirPropiedades(obj, objName) {
174    var output = "" ;
175
176    for (var prop in obj)    {
177        output += objName + "." + prop + " = " + obj[prop] + "<br>";
178    }
179
180    document.write(output);
181    return output ;
182}
183
184function FechaHora() {
185    var Digital = new Date();
186    var horas = Digital.getHours();
187    var minutos = Digital.getMinutes();
188    var segundos = Digital.getSeconds();
189    var dia = Digital.getDay();
190    var mes = Digital.getMonth();
191    var ano = Digital.getYear();
192
193    var fh = ano + "" + mes + dia + horas + "" + minutos + segundos;
194
195    return fh;
196}
197
198function FormatearCodigo(num, n, f, r) {
199    return n = new Array((++n, f ? (f = (num + "").length) < n ? n - f : 0 : n)).join(0), r ? num + n : n + num;
200}
201
202
203function DesplegableXml(iddesplegable, xml, campoid, camponombre)
204{
205    var id;
206    var nombre;
207    var rows = xml.getElementsByTagName("row");
208    var tamano = rows.length;
209    var desplegable = document.getElementById(iddesplegable);
210    desplegable.length = null;
211
212
213    for(var i = 0; i < tamano; i++) {
214        if (rows[i].nodeType == 1) {
215            for (j = 0; j < rows[i].childNodes.length; j++) {
216                if (rows[i].childNodes[j].nodeType == 1) {
217                    if (rows[i].childNodes[j].nodeName == campoid) {
218                        try{
219                            id = rows[i].childNodes[j].firstChild.nodeValue;
220                        } catch(e) {
221                           id = "";
222                        }
223                    }
224
225                    if (rows[i].childNodes[j].nodeName == camponombre ) {
226                        try {
227                            nombre = rows[i].childNodes[j].firstChild.nodeValue;
228                        } catch(e) {
229                           nombre = "";
230                        }
231                    }
232                }
233            }
234
235            var opcion = document.createElement("option");
236            var label = document.createTextNode(nombre);
237
238            opcion.appendChild(label);
239            opcion.setAttribute("value",id);
240            desplegable.appendChild(opcion);
241        }
242    }
243}
244
245function DesplegableCargando(iddesplegable) {
246    var desplegable = document.getElementById(iddesplegable);
247    desplegable.length = null;
248
249    var opcion = new Option("Cargando...", "desplegable_sin_valor","","");
250    desplegable.appendChild(opcion);
251}
252
253function FormatearNumero(num) {
254    var numero = new FormatoNumero();
255    numero.sepmiles = ',';
256    numero.dec = 2;
257    numero.miles = true;
258    numero.valor = num;
259    return numero.formato();
260}
261
262function getMensaje(codigomensaje) {
263    return MENSAJES[codigomensaje];
264}
265
266function getParametro(nombreparametro) {
267    return PARAMETROS[nombreparametro];
268}
269
270function ConfirmarAccion(text) {
271    text = text ? text: MENSAJES["PREGUNTARBORRAR"]; //Por defecto es confirmar borrar
272
273    if (confirm(text)) {
274        return true;
275    }
276
277    return false;
278}
279
280function Mensaje(text, tipo, confirmar, titulo) {
281    titulo = titulo ? titulo:'';
282
283    if (tipo !== undefined && tipo !== "") {
284        tipo = tipo.toLowerCase();
285    }
286
287    if (confirmar === undefined || confirmar !== true)
288        confirmar = false;
289
290    if (tipo == "ok" || tipo == "confirmacion") {
291        tipo = "success";
292    }
293
294    if (tipo === undefined || (tipo != "warning" && tipo != "error" && tipo != "success" && tipo != "info" && tipo != "input")) {
295        tipo = null;
296    }
297
298    swal({
299        title: titulo,
300        text: text,
301        allowOutsideClick: true,
302        showConfirmButton: confirmar,
303        type: tipo,
304        html: true
305    });
306}
307
308function CerrarMensaje(tiempo) {
309    if (typeof(tiempo) === "undefined" || tiempo === null) {
310        tiempo = 3000;
311    } else {
312        tiempo = tiempo * 1000;
313    }
314
315    //Esconder mensajes de estado
316    setTimeout(TemporizadorLimpiarMensajes, tiempo);
317}
318
319function TemporizadorLimpiarMensajes() {
320//    $("#mensajeestado").fadeOut("normal");
321    swal.close();
322}
323
324function strtoint(str) {
325    return  parseInt(str_replace([","], "", str));
326}
327
328function number_format(number, decimals, dec_point, thousands_sep) {
329    var n = !isFinite(+number) ? 0 : +number,
330        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
331        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
332        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
333        s = '',
334        toFixedFix = function (n, prec) {
335            var k = Math.pow(10, prec);
336            return '' + Math.round(n * k) / k;
337        };
338
339    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
340    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
341
342    if (s[0].length > 3) {
343        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
344    }
345
346    if ((s[1] || '').length < prec) {
347        s[1] = s[1] || '';
348        s[1] += new Array(prec - s[1].length + 1).join('0');
349    }    return s.join(dec);
350}
351
352function str_replace (search, replace, subject, count) {
353    f = [].concat(search),
354        r = [].concat(replace),
355        s = subject,
356        ra = r instanceof Array,
357        sa = s instanceof Array;
358
359    s = [].concat(s);
360
361    if (count) {
362        this.window[count] = 0;
363    }
364
365    for (i=0, sl=s.length; i < sl; i++) {
366        if (s[i] === '') {
367            continue;
368        }
369
370        for (j = 0, fl = f.length; j < fl; j++) {
371            temp = s[i]+'';
372            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
373            s[i] = (temp).split(f[j]).join(repl);
374
375            if (count && s[i] !== temp) {
376                this.window[count] += (temp.length-s[i].length)/f[j].length;
377            }
378        }
379    }
380
381    return sa ? s : s[0];
382}
383
384function trim (str, charlist) {
385    str += '';
386
387    if (!charlist) {
388        whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
389    } else {
390        // preg_quote custom list
391        charlist += '';
392        whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '$1');
393    }
394
395    l = str.length;
396
397    for (i = 0; i < l; i++) {
398        if (whitespace.indexOf(str.charAt(i)) === -1) {
399            str = str.substring(i);
400            break;
401        }
402    }
403
404    l = str.length;
405
406    for (i = l - 1; i >= 0; i--) {
407        if (whitespace.indexOf(str.charAt(i)) === -1) {
408            str = str.substring(0, i + 1);
409            break;
410        }
411    }
412
413    return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
414}
415
416
417$.extend($.expr[':'], {
418    'containsi': function(elem, i, match, array) {
419        return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
420  }
421});
422
423$.fn.serializeObject = function() {
424    var o = {};
425    var a = this.serializeArray();
426
427    $.each(a, function() {
428        if (o[this.name]) {
429            if (!o[this.name].push) {
430                o[this.name] = [o[this.name]];
431            }
432            o[this.name].push(this.value || '');
433        } else {
434            o[this.name] = this.value || '';
435        }
436    });
437    return o;
438};
439
440function IconoPMapa(marcado) {
441    var icon = new GIcon();
442
443    if (marcado == 1) {
444        icon.image ="http://labs.google.com/ridefinder/images/mm_20_green.png";
445    } else if(marcado == 2) {
446        icon.image = "../Imagenes/Sistema/mm_20_blue.png";
447    } else {
448        icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
449    }
450
451    icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
452    icon.iconSize = new GSize(12, 20);
453    icon.shadowSize = new GSize(22, 20);
454    icon.iconAnchor = new GPoint(6, 20);
455    icon.infoWindowAnchor = new GPoint(0, -5);
456
457    return icon;
458}
459
460
461function nMostrar(numero) {
462    return number_format(numero, 2, ".", ",");
463}
464
465function nMostrarEntero(numero) {
466    return number_format(numero, 0, ".", ",");
467}
468
469function nOperar(numero) {
470    return dec(parseFloat(str_replace([","], "", numero)) + 0, 4);
471}
472
473
474function nRedondear(numero) {
475    return dec(numero, 2);
476}
477
478function dec(fl, d) {
479    var p = Math.pow(10, d);
480    return Math.round(fl*p)/p;
481}
482
483function CompararHoras(sHora1, sHora2) {
484    var arHora1 = sHora1.split(":");
485    var arHora2 = sHora2.split(":");
486
487    // Obtener horas y minutos (hora 1)
488    var hh1 = parseInt(arHora1[0],10);
489    var mm1 = parseInt(arHora1[1],10);
490
491    // Obtener horas y minutos (hora 2)
492    var hh2 = parseInt(arHora2[0],10);
493    var mm2 = parseInt(arHora2[1],10);
494
495    // Comparar
496    if (hh1 < hh2 || (hh1 == hh2 && mm1 < mm2)) {
497        return -1;
498    } else if (hh1 > hh2 || (hh1 == hh2 && mm1 > mm2)) {
499        return 1;
500    } else {
501        return 0;
502    }
503}
504
505function blinkObjeto(objeto, claseOn, claseOff, blinkTimer) {
506    if (blinkTimer != "") {
507        clearInterval(blinkTimer);
508    }
509
510    blinkTimer = setInterval(blinkRotate, 500, objeto, claseOn,claseOff);
511    return blinkTimer;
512}
513
514function unblinkObjeto(objeto, claseOn, claseOff, blinkTimer) {
515    if(blinkTimer != "") {
516        clearInterval(blinkTimer);
517    }
518
519    $(objeto).removeClass(claseOn);
520    $(objeto).addClass(claseOff);
521}
522
523function blinkRotate(objeto, claseOn, claseOff) {
524    if ($(objeto).hasClass(claseOn) ) {
525        $(objeto).removeClass(claseOn);
526        $(objeto).addClass(claseOff);
527    } else {
528        $(objeto).removeClass(claseOff);
529        $(objeto).addClass(claseOn);
530    } /**/
531
532}
533
534/*function Cargando(mensajecargando, elementocargando, tipocargando, css) {
535    if (typeof css != 'object') {
536        css = {};
537    }
538
539    if (typeof(tipocargando) == "undefined" || tipocargando === "") {
540        tipocargando = "2";
541    }
542
543    if (typeof(mensajecargando) == "undefined" || mensajecargando === false) {
544        mensajecargando = MENSAJES.AJAX_CARGANDO;
545    } else if(mensajecargando === "")
546        mensajecargando = "&nbsp;";
547
548    if (typeof(elementocargando) == "undefined" || elementocargando === "") {
549        elementocargando = "body";
550    }
551
552    // Fusionar el arreglo de estilos con el que haya podido llegar
553    var cssBlock = {border: 'none'};
554    $.extend(cssBlock, css);
555
556    $(""+elementocargando).block({
557        message: '<div class="cargando'+tipocargando+'">'+mensajecargando+'</div>',
558        css: cssBlock,
559        overlayCSS: { backgroundColor:'#fff'}
560    });
561}*/
562
563function Cargando(mensajecargando, elementocargando, tipocargando, css, mostrarimagen, reducido)
564{
565    if (typeof(mensajecargando) == "undefined" || mensajecargando === false) {
566        mensajecargando = MENSAJES.AJAX_CARGANDO;
567    } else if(mensajecargando === "")
568        mensajecargando = "&nbsp;";
569
570    if (typeof(elementocargando) == "undefined" || elementocargando === "") {
571        elementocargando = "body";
572    }
573    
574    if (elementocargando == "body"){
575        var clase_cargando = "cargando_body";
576    }
577    else{
578        var clase_cargando = "";
579    }
580    
581    if(reducido){
582        var clase_reducido="reducido";
583    }
584    else{
585        var clase_reducido="";
586    }
587    
588    if (typeof(elementocargando) == "string") {
589        elementocargando = $(elementocargando);
590    }
591    
592    if (typeof(tipocargando) == "undefined" || tipocargando === "") {
593        tipocargando = "2";
594    }
595    
596    if (typeof css != 'object') {
597        css = {};
598    }
599    
600    if (typeof(mostrarimagen) == "undefined" || mostrarimagen === "" || typeof(mostrarimagen) != "boolean" ) {
601        mostrarimagen = true;
602    }
603    
604    var divImagen = '';
605    var claseCont = '';
606    if(mostrarimagen){
607        divImagen = '<div class="loader" id="loader">...</div><img class="img-responsive" src="'+_RUTA+'/Imagenes/Template/logo-cargando.png" srcset="'+_RUTA+'/Imagenes/Template/2x/logo-cargando.png 2x" />';
608        claseCont = 'imag';
609    }
610
611    // Fusionar el arreglo de estilos con el que haya podido llegar
612    var cssBlock = {border: 'none'};
613    $.extend(cssBlock, css);
614
615    //Si ya esta abierto el mismo elemento no volverlo a abrir
616    if(elementocargando.data('blockUI.isBlocked')){
617        if( $(".blockMsg .ctn p", elementocargando).html() == mensajecargando )
618            return true
619    }
620
621    elementocargando.block({
622//        message: '<div class="cargando'+tipocargando+'">'+mensajecargando+'...</div>',
623        message: '<div class="cargando-container '+claseCont+' '+clase_cargando+' '+clase_reducido+' ">'+
624                        '<div class="ctn-loader">'+
625                            '<div class="ctn">'+
626                                divImagen + 
627                                '<p>'+mensajecargando+'</p>'+
628                            '</div>'+
629                        '</div>'+
630                    
631                '</div>',
632        css: cssBlock,
633        overlayCSS: {backgroundColor:'#fff'},
634        baseZ: 9999
635    });
636}
637
638
639function CerrarCargando(elementocargando) {
640    if (typeof(elementocargando) == "undefined" || elementocargando === "") {
641        elementocargando = "body";
642    }
643    
644    if (typeof(elementocargando) == "string") {
645        elementocargando = $(elementocargando);
646    }
647    
648    elementocargando.unblock();
649}
650
651function ph_etiqueta(etiqueta) {
652    return etiqueta;
653}
654
655function bytesToString(bytes, decimals) {
656    if (bytes === 0) {
657        return '0B';
658    }
659
660    bytes = Math.abs(bytes);
661
662    if (decimals !== 0 ) {
663        decimals = decimals || 2;
664    }
665
666    decimals = Math.abs(decimals);
667
668    var unitMultiple = 1024;
669
670    var unitNames = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
671    var unitChanges = Math.floor(Math.log(bytes) / Math.log(unitMultiple));
672
673    return parseFloat((bytes / Math.pow(unitMultiple, unitChanges)).toFixed(decimals)) + ' ' + unitNames[unitChanges];
674}
675
676/* Funcion split mejorada con el parametro limit, 
677  * en la función nativa de Js el limit corta el array omitiendo el resto de elementos. 
678  * Ej:
679  * > var a = 'elem1.elem2.elem3';
680  * > a.split('.', 1);
681  * < ['elem1'] //Lo que devuelve el split nativo
682  * > split(a,'.',1)
683  * < ['elem1', 'elem2.elem3'] //Lo que devuelve esta función.
684  */
685function split(str, separator, limit) {
686    str = str.split(separator);
687
688    if(str.length > limit) {
689        var ret = str.splice(0, limit);
690        ret.push(str.join(separator));
691
692        return ret;
693    }
694
695    return str;
696}
697
698//Detectar si un elemento es visible dentro del viewport
699function visibleEnPantalla(obj){
700    if (typeof(obj) == "undefined" || obj === "") {
701        return false;
702    }
703    
704    if (typeof(obj) == "string") {
705        obj = $(obj);
706    }
707    
708    var elementTop = obj.offset().top;
709    var elementBottom = elementTop + obj.outerHeight();
710
711    var viewportTop = $(window).scrollTop();
712    var viewportBottom = viewportTop + $(window).innerHeight();
713
714    return elementBottom > viewportTop && elementTop < viewportBottom;
715    
716    
717}

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.