/* FUNCIONES PARA OBTENER VARIABLES CON AJAX */ /* codigo obtenido de http://www.ajaxhispano.com/tutorial-manual-ajax-ejemplos-metodo-GET-POST-principiantes.html bajo la licencia GNU/GPL */ function creaAjax(){ var objetoAjax=false; try { /*Para navegadores distintos a internet explorer*/ objetoAjax = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { /*Para explorer*/ objetoAjax = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { objetoAjax = false; } } if (!objetoAjax && typeof XMLHttpRequest!='undefined') { objetoAjax = new XMLHttpRequest(); } return objetoAjax; } /** ENFOCA EN EL CAMPO ENVAIDO **/ function foco(elemento) { elemento.focus(); if (elemento.type == 'text') { //elemento.select(); } } /**VALIDA QUE LE DIGITEN VALOR, SI fl_cero ES TRUE TAMBIÉN VALIDA QUE NO LE DIGITEN CERO**/ function valida(campo,mensaje,fl_cero) { if (campo.value==='') { foco(campo); mensaje_dj('ERROR',mensaje,'OK','ERROR','',campo); return false; } if (fl_cero) { if (campo.value=='0') { foco(campo); mensaje_dj('ERROR',mensaje,'OK','ERROR','',campo); //mensaje_nv('ERROR',mensaje,Ext.MessageBox.OK,Ext.MessageBox.ERROR,'',campo) return false; } } return true; } /** FUNCION PARA VALIDAR LOS CAMPOS MAIL O CORREO **/ function valida_correo(campo) { var cad=campo.value; if (cad!='') { if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(cad)){ return true; } else { mensaje_dj('ERROR','El Correo Eléctronico Digitado no es Valido.','OK','ERROR','',campo); return false; } } return true; }//cierra funcion /************************************************************** Máscara de entrada. Script creado por Tunait! (21/12/2004) Si quieres usar este script en tu sitio eres libre de hacerlo con la condición de que permanezcan intactas estas líneas, osea, los créditos. No autorizo a distribuír el código en sitios de script sin previa autorización Si quieres distribuírlo, por favor, contacta conmigo. Ver condiciones de uso en http://javascript.tunait.com/ tunait@yahoo.com ****************************************************************/ var patron = new Array(2,2,4) var patron2 = new Array(1,3,3,3,3) function mascara(d,sep,pat,nums){ if(d.valant != d.value){ val = d.value largo = val.length val = val.split(sep) val2 = '' for(r=0;r< val.length;r++) { val2 += val[r] } if(nums){ for(z=0;z< val2.length;z++){ if(isNaN(val2.charAt(z))&&val2.charAt(z)!='.'&&val2.charAt(z)!=','&&val2.charAt(z)!='-'&&val2.charAt(z)!=':'){ letra = new RegExp(val2.charAt(z),"g") val2 = val2.replace(letra,"") } } } val = '' val3 = new Array() for(s=0; s< pat.length; s++){ val3[s] = val2.substring(0,pat[s]) val2 = val2.substr(pat[s]) } for(q=0;q< val3.length; q++){ if(q ==0){ val = val3[q] } else { if(val3[q] != ""){ val += sep + val3[q] } } } d.value = val d.valant = val } } /**************** la siguiente función fue obtenida de http://www.forosdelweb.com/f13/validar-solo-numeros-no-permitir-copy-paste-369421 */ function validarNum(e) { tecla = (document.all) ? e.keyCode : e.which; if (tecla == 8) return true; patron = /\d/; te = String.fromCharCode(tecla); return patron.test(te); } /********************************* FIN DE LA FUNCION *********************************************************************************/ function nombre_format(campo, nombre){ campo.value = nombre.value; formatNumber(campo,',',''); } function accion_forma(form, accion){ form.action=accion; } function select (valor,select) { var combo = select.options.length; for (var i=0;i< combo;i++) { if (valor==select.options[i].value) { select.selectedIndex = i; } } } function seleccionar (valor,select) { var combo = select.options.length; for (var i=0;i< combo;i++) { if (valor==select.options[i].value) { select.selectedIndex = i; } } } function object() { var peticion = false; var testPasado = false; try { peticion = new XMLHttpRequest(); } catch (trymicrosoft) { try { peticion = new ActiveXObject("Msxml2.XMLHTTP"); } catch (othermicrosoft) { try { peticion = new ActiveXObject("Microsoft.XMLHTTP"); } catch (failed) { peticion = false; } } } if (!peticion) alert("ERROR AL INICIALIZAR!"); return peticion; } function cambio (campo,valor) { var combo = campo.options.length; valor=unformatNumber(valor); for (var i=0;i 1 ? 'x' + splitStr[1] : ''; var regx = /(\d+)(\d{3})/; if (campo.value != ''&&campo.value != '-') { while (regx.test(splitLeft)) { splitLeft = splitLeft.replace(regx, '$1' + sep + '$2'); } campo.value = prefix + splitLeft + splitRight; } } function unformatNumber(num) { return num.replace(/([^0-9\-\.])/g,'')*1; } /*************FUNCION PARA BUSCAR UN VALOR EN ARREGLO RETORNA -1 SI NO ENCUENTRA EL VALOR************/ function buscar_valor(arreglo,valor) { for (var i=0;i< arreglo.length;i++) { if (valor==arreglo[i]) { return i; break; } } return -1; } /*************FUNCION PARA MOVER AL FINAL UN VALOR EN UN ARREGLO**********/ Array.prototype.moverAlFinal = function(b,ini) { var yo = this; var longitudArray = yo.length; if (b == ini) { return yo.rotarI(); } else { if (b < (yo.length - 1)) { principio = yo.slice(0, b); fin = yo.slice(b, longitudArray).rotarI(); yo = principio.concat(fin); return principio.concat(fin); } else { return yo; } } } /*************FUNCION PARA ROTAR A LA IZQUIERDA UN VALOR EN UN ARREGLO**********/ Array.prototype.rotarI = function() { var yo = this; var primero = yo.shift(); yo[yo.length] = primero; return yo; } /*************FUNCION PARA DETERMINAR LA SEGURIDAD DE UNA CONTRASEÑA**********/ function seguridad_clave(clave){ var seguridad = 0; if (clave.length!=0){ if (tiene_numeros(clave) && tiene_letras(clave)) seguridad += 30; if (tiene_minusculas(clave) && tiene_mayusculas(clave)) seguridad += 30; if (clave.length >= 4 && clave.length <= 5){ seguridad += 10; } else { if (clave.length >= 6 && clave.length <= 8){ seguridad += 30; } else { if (clave.length > 8) seguridad += 40; } } } return seguridad } /*************FUNCION PARA DETERMINAR SI TEXTO TIENE NUMEROS**********/ function tiene_numeros(texto){ var numeros="0123456789"; for (i = 0; i < texto.length; i++) { if (numeros.indexOf(texto.charAt(i), 0) != -1) return true; } return false; } /*************FUNCION PARA DETERMINAR SI TEXTO TIENE LETRAS**********/ function tiene_letras(texto){ var letras="abcdefghyjklmnñopqrstuvwxyz"; texto = texto.toLowerCase(); for(i=0; i< texto.length; i++){ if (letras.indexOf(texto.charAt(i), 0) != -1) { return true; } } return false; } /*************FUNCION PARA DETERMINAR SI TEXTO TIENE LETRAS MINISCULAS**********/ function tiene_minusculas(texto){ var letras="abcdefghyjklmnñopqrstuvwxyz"; for(i=0; i< texto.length; i++){ if (letras.indexOf(texto.charAt(i),0)!=-1) return true; } return false; } /*************FUNCION PARA DETERMINAR SI TEXTO TIENE LETRAS MAYUSCULAS**********/ function tiene_mayusculas(texto){ var letras="abcdefghyjklmnñopqrstuvwxyz"; letras=letras.toUpperCase(); for(i=0; i< texto.length; i++){ if (letras.indexOf(texto.charAt(i),0)!=-1) return 1; } return 0; } /*************FUNCION PARA VERIFICAR QUE SEA NUMERICO UN CAMPO**********/ function es_numero(campo){ if (isNaN(campo.value)) { alert('..:: Valor Digitado No Es Numerico ::..'); campo.value=''; } } /***FUNCIÓN PARA MOSTRAR MENSAJES*/ function mensaje_nv(titulo,mensaje,boton,icono,pagina,formulario,vl_envia) { Ext.MessageBox.show({ title: titulo, msg: mensaje, buttons: boton, icon: icono, fn: showResult }); function showResult(btn){ if (pagina == '-2') { var valor = Ext.example.devuelve('{0}', btn); formulario.sino.value = valor; if (vl_envia == valor) { for (i = 0; i < formulario.elements.length; i++) { if (formulario.elements[i].disabled) formulario.elements[i].disabled = false; } formulario.submit(); } } else if (pagina == '-3') { var valor = Ext.example.devuelve('{0}', btn); if (valor=='yes') { Ext.example.redirecciona(vl_envia); } else { Ext.example.redirecciona(formulario); } } else { //Ext.example.redirecciona(pagina); if (pagina!=''&&pagina!='-5') formulario.submit(); else if (pagina!='-5') foco(formulario); } }; } /***FUNCIÓN PARA MOSTRAR MENSAJES CON DOJO*/ function mensaje_dj(titulo,mensaje,boton,icono,pagina,formulario,pag_cancela,menu_cancela) { var fl=true; dojo.require("dijit.Dialog"); dojo.require("dijit.form.Button"); if (dijit.byId('mensaje_dj')) dijit.byId('mensaje_dj').destroy(); if (dijit.byId('cb_mensaje_dj')) dijit.byId('cb_mensaje_dj').destroy(); if (dijit.byId('cb_cancela_dj')) dijit.byId('cb_cancela_dj').destroy(); var dialog = new dijit.Dialog({id:"mensaje_dj", title:titulo, style:"width: 300px;"}); content='
'+mensaje+'
'; if (boton=='OK') { if (pagina!=''&&pagina!='-5') { content+=''; } else { content+=''; content+=''; } content+='
'; dialog.setContent(content); dialog.startup(); dialog.show(); return dialog; } function cargar(id_nv,order_by,id_ord_nv,tot,mensaje) { for (i=1;i<=tot;i++) { var man=document.getElementById(id_nv.substr(0,id_nv.lastIndexOf('_')+1)+i.toString() ); if (id_nv == id_nv.substr(0,id_nv.lastIndexOf('_')+1) + i.toString()) { if (order_by == 'asc') man.setAttribute("class", "encabezado_asc"); else man.setAttribute("class", "encabezado_desc"); man.innerHTML='   '; } else { man.innerHTML=''; } } man=document.getElementById(id_ord_nv); man.setAttribute("class","encabezado_ord"); if (mensaje!='') mensaje_dj('ERROR',mensaje,'OK','ERROR','',''); //inicio(); } /****FUNCIÓN PARA CARGAR DATOS EN UN DIV*/ function cargardatos (url) { //alert(url); var peticion=false; peticion=object(); var element=document.getElementById('datos'); element.innerHTML='
Procesando Datos, Por Favor Espere...
'; var ancho=screen.width-110; var alto=screen.height-300; var atributo="overflow:auto; width: "+ancho.toString()+"px; height: "+alto.toString()+"px;border: double; border-color: blue;"; element.setAttribute("style",atributo); peticion.open("GET",url); peticion.onreadystatechange = function(){ if (peticion.readyState == 4) { element.innerHTML = peticion.responseText; } } peticion.send(null); document.getElementById('argumentos').setAttribute("style", "display: none;"); } function cargar_url (id,url) { //alert(url); var peticion=false; peticion=object(); var element=document.getElementById(id); element.innerHTML='
Procesando Datos, Por Favor Espere...
'; peticion.open("GET",url); peticion.onreadystatechange = function(){ if (peticion.readyState == 4) { element.innerHTML = peticion.responseText; } } peticion.send(null); } function cargardatos1 (url) { //alert(url); var peticion=false; peticion=object(); var element=document.getElementById('datos1'); element.innerHTML='
Procesando Datos, Por Favor Espere...
'; /*var ancho=screen.width-110; var alto=screen.height-400; var atributo="overflow:auto; width: "+ancho.toString()+"px; height: "+alto.toString()+"px;border: double; border-color: blue;"; element.setAttribute("style",atributo);*/ peticion.open("GET",url); peticion.onreadystatechange = function(){ if (peticion.readyState == 4) { element.innerHTML = peticion.responseText; } } peticion.send(null); document.getElementById('argumentos').setAttribute("style", "display: none;"); } /*****FUNCION PARA MOSTRAR U OCULTAR ARGUMENTOS DE CONSULTA*/ function ver_argumento() { if (document.getElementById('argumentos').getAttribute("style")=="display: none;") { document.getElementById('argumentos').setAttribute("style","display: block;"); } else { document.getElementById('argumentos').setAttribute("style","display: none;"); } } /*****FUNCION PARA MOSTRAR U OCULTAR labels y submenus de busqueda de operador en Descuentos aplicados*/ function mostrar_noms(id) { if (document.getElementById(id).getAttribute("style")=="display: none;") { document.getElementById(id).setAttribute("style","display: block;"); } else { document.getElementById(id).setAttribute("style","display: none;"); } } /*****FUNCION PARA MOSTRAR U OCULTAR labels y submenus de busqueda añadiendole el estilo*/ function mostrar_noms_style(id,estilo) { if (document.getElementById(id).getAttribute("style")=="display: none;"+estilo) { document.getElementById(id).setAttribute("style","display: block;"+estilo); } else { document.getElementById(id).setAttribute("style","display: none;"+estilo); } } /*****FUNCION PARA MOSTRAR U OCULTAR labels y submenus de busqueda de operador en Descuentos aplicados dependiendo de un id*/ function mostrar_nomsid(id,valor) { if(valor=='op5'){ if (document.getElementById(id).getAttribute("style")=="display: none;") { document.getElementById(id).setAttribute("style","display: block;"); } else { document.getElementById(id).setAttribute("style","display: none;"); } }else{ if (document.getElementById(id).getAttribute("style")=="display: block;") { document.getElementById(id).setAttribute("style","display: none;"); } else { document.getElementById(id).setAttribute("style","display: none;"); } } } /*****FUNCION PARA MOSTRAR U OCULTAR MENU*/ function ver_menu() { if (document.getElementById('menu_izq').getAttribute("class")=="oculto") { document.getElementById('menu_izq').setAttribute("class","visible"); } else { document.getElementById('menu_izq').setAttribute("class","oculto"); } Effect.toggle('menu_der','appear'); return false; } /****FUNCION PARA VALIDAR FECHA*/ function validar_fecha(fecha) { var fc=new Array(); var hr=new Array(); var fc_hora=new Array(); if (fecha.value!='') { fc_hora=fecha.value.split(' '); fc=fc_hora[0].split('/'); if (fc_hora.length==2) hr=fc_hora[1].split(':'); if (fc[2]=='') { mensaje_dj('ERROR','Año Invalido, Por Favor Verificar.','OK','ERROR','',fecha); return false; } if (parseFloat(fc[2])<=999||parseFloat(fc[2])>9999) { mensaje_dj('ERROR','Año Invalido, Por Favor Verificar.','OK','ERROR','',fecha); return false; } if (fc[1]=='') { mensaje_dj('ERROR','Mes Invalido, Por Favor Verificar.','OK','ERROR','',fecha); return false; } if (parseFloat(fc[1])<=0||parseFloat(fc[1])>12) { mensaje_dj('ERROR','Mes Invalido, Por Favor Verificar.','OK','ERROR','',fecha); return false; } if (fc[0]=='') { mensaje_dj('ERROR','Día Invalido, Por Favor Verificar.','OK','ERROR','',fecha); return false; } if (parseFloat(fc[0])<=0||parseFloat(fc[0])>31) { mensaje_dj('ERROR','Día Invalido, Por Favor Verificar.','OK','ERROR','',fecha); return false; } if (parseFloat(fc[1])==2) { if (parseFloat(fc[2])%4==0) { if (parseFloat(fc[0])>29) { mensaje_dj('ERROR','Día Invalido, Por Favor Verificar.','OK','ERROR','',fecha); return false; } } else { if (parseFloat(fc[0])>28) { mensaje_dj('ERROR','Día Invalido, Por Favor Verificar.','OK','ERROR','',fecha); return false; } } } else if (parseFloat(fc[1])==4||parseFloat(fc[1])==6||parseFloat(fc[1])==9||parseFloat(fc[1])==11) { if (parseInt(fc[0])>30) { mensaje_dj('ERROR','Día Invalido, Por Favor Verificar.','OK','ERROR','',fecha); return false; } } if (hr.length>0) { for (i=0;i< hr.length;i++) { switch (i) { case 0: if (parseInt(hr[0])< 0||parseInt(hr[0])>23) { mensaje_dj('ERROR','Hora Invalida, Por Favor Verificar.','OK','ERROR','',fecha); return false; } break; case 1: if (parseInt(hr[1])<0||parseInt(hr[1])>59) { mensaje_dj('ERROR','Minuto Invalido, Por Favor Verificar.','OK','ERROR','',fecha); return false; } break; case 2: if (parseInt(hr[2])<0||parseInt(hr[2])>59) { mensaje_dj('ERROR','Segundo Invalido, Por Favor Verificar','OK','ERROR','',fecha); return false; } break; } } } } return true; } /****FUNCION PARA DAR FORMATO DE FECHA Y HORA DD/MM/AAAA HH:MM*/ function format_fec(campo,fl_hora) { var fc_hora=new Array(); var fecha=''; var hora=''; if (campo.value != '') { fecha = campo.value.replace(/([^0-9])/g, ''); hora = fecha.substr(8); fecha = fecha.substr(0, 8); fecha = fecha.substr(0, 2) + '/' + fecha.substr(2, 2) + '/' + fecha.substr(4, 4); switch (fl_hora) { case 'N': campo.value = fecha; if (dijit.byId(campo.id)) dijit.byId(campo.id).set('value',fecha); break; case 'H': switch (hora.length) { case 0: hora = '00'; break; case 1: hora = '0' + hora; break; default: hora = hora.substr(0, 2); break; } campo.value = fecha + ' ' + hora; if (dijit.byId(campo.id)) dijit.byId(campo.id).set('value',fecha+' '+hora); break; case 'M': switch (hora.length) { case 0: hora = '00:00'; break; case 1: hora = '0' + hora + ':00'; break; case 2: hora += ':00'; break; case 3: hora = hora.substr(0, 2) + ':0' + hora.substr(2); break; default: hora = hora.substr(0, 2) + ':' + hora.substr(2, 2); break; } campo.value = fecha + ' ' + hora; if (dijit.byId(campo.id)) dijit.byId(campo.id).set('value',fecha+' '+hora); break; case 'S': switch (hora.length) { case 0: hora = '00:00:00'; break; case 1: hora = '0' + hora + ':00:00'; break; case 2: hora += ':00:00'; break; case 3: hora = hora.substr(0, 2) + ':0' + hora.substr(2) + ':00'; break; case 4: hora = hora.substr(0, 2) + ':' + hora.substr(2) + ':00'; break; case 5: hora = hora.substr(0, 2) + ':' + hora.substr(2, 2) + ':0' + hora.substr(4); break; default: hora = hora.substr(0, 2) + ':' + hora.substr(2, 2) + ':' + hora.substr(4, 2); break; } campo.value = fecha + ' ' + hora; if (dijit.byId(campo.id)) dijit.byId(campo.id).set('value',fecha+' '+hora); break; } } } /******FUNCION PARA CAMBIAR DE FORMATO LAS FECHAS 'DD/MM/YYYY' A 'YYYY-MM-DD'*/ function format_fc(fecha) { if (fecha!='') { var fc_hora = new Array(); fc_hora=fecha.split(' '); fecha=fc_hora[0]; var a_fecha = new Array(); a_fecha=fecha.split('/'); if (fc_hora.length==1) { return a_fecha[2]+'-'+a_fecha[1]+'-'+a_fecha[0]; } else { return a_fecha[2]+'-'+a_fecha[1]+'-'+a_fecha[0]+' '+fc_hora[1]; } } else { return ''; } } /******FUNCION PARA CAMBIAR DE FORMATO LAS FECHAS 'YYYY-MM-DD' A 'DD/MM/YYYY'*/ function format_cf(fecha) { if (fecha!='') { var fc_hora = new Array(); fc_hora=fecha.split(' '); fecha=fc_hora[0]; var a_fecha = new Array(); a_fecha=fecha.split('-'); if (fc_hora.length==1) { return a_fecha[2]+'/'+a_fecha[1]+'/'+a_fecha[0]; } else { return a_fecha[2]+'/'+a_fecha[1]+'/'+a_fecha[0]+' '+fc_hora[1]; } } else { return ''; } } /** * CONVIERTE FORMATO DE FECHA Y HORA YYYY-MM-DD HH:MM:SS A DD/MM/YYYY HH:MM:SS AM/PM * @param Fecha y hora en Formato YYYY-MM-DD HH:MM:SS * @return Fecha y hora en Formato DD/MM/YYYY HH:MM:SS AM/PM * @author Ing. Juan Carlos Medina Hernández */ function format_am_pm(fecha) { var fecha_hora=new Array(),fc=new Array(),hora=new Array(); var fc_hora='',ampm='', fecha_hora=fecha.split(' '); fc=fecha_hora[0].split('-'); hora=fecha_hora[1].split(':'); fc_hora=fc[2]+'/'+fc[1]+'/'+fc[0]+' '; if (parseFloat(hora[0])<12) { ampm='AM'; } else { ampm='PM'; } if (parseFloat(hora[0])>=13) hora[0]=(parseFloat(hora[0])-12).toString(); if (hora[0].length==1) hora[0]='0'+hora[0]; fc_hora+=hora[0]+':'+hora[1]+':'+hora[2]+' '+ampm; return fc_hora; } /*****FUNCION PARA VALIDAR LONGITUD DE UN CAMPO*/ function valida_longitud(campo,longitud) { if (campo.value.length>longitud) { mensaje_dj('ERROR','Longitud del Campo Excedio el Máximo Permitido que es '+ longitud + ' Caracteres.','OK','ERROR','',''); foco(campo); return false; } return true; } /****FUNCION PARA COLOCAR CANTIDAD DE CARACTERES DIGITADOS*/ function cant_caracteres(campo,id,longitud) { document.getElementById(id).innerHTML='('+campo.value.length+'/'+longitud+')'; if (campo.value.length>longitud) { document.getElementById(id).setAttribute("class","caract_mal"); } else { document.getElementById(id).setAttribute("class","caract_bien"); } } /***FUNCION PARA VALIDAR QUE SUBAN SOLO ARCHIVOS DE IMAGENES*/ function validar_foto(form) { archivo=form.f_imagen.value; extension=(archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); if(extension!='') { if(extension=='.jpg'||extension=='.JPG'||extension=='.gif'||extension=='.GIF'||extension=='.PNG'||extension=='.png'|| extension=='.bmp'||extension=='.BMP'||extension=='.jpeg'||extension=='.JPEG') { return true; } else { mensaje_dj('ERROR','Tipo De Archivo No Valido.','OK','ERROR','',''); return false; } } return true; } /****FUNCION PARA COMPLETAR EL NOMBRE*/ function com_nombres(t1,t2,t3,t4,campo) { var nombre=''; nombre=t1; if (t2!='') nombre+=' '+t2; if (t3!='') nombre+=' '+t3; if (t4!='') nombre+=' '+t4; campo.value=nombre; } /**FUNCION PARA SERILIZAR VALORES COMO PHP*/ function serialize (mixed_value) { // http://kevin.vanzonneveld.net // + original by: Arpad Ray (mailto:arpad@php.net) // + improved by: Dino // + bugfixed by: Andrej Pavlovic // + bugfixed by: Garagoth // + input by: DtTvB (http://dt.in.th/2008-09-16.string-length-in-bytes.html) // + bugfixed by: Russell Walker (http://www.nbill.co.uk/) // + bugfixed by: Jamie Beck (http://www.terabit.ca/) // % note: We feel the main purpose of this function should be to ease the transport of data between php & js // % note: Aiming for PHP-compatibility, we have to translate objects to arrays // * example 1: serialize(['Kevin', 'van', 'Zonneveld']); // * returns 1: 'a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}' // * example 2: serialize({firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'}); // * returns 2: 'a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}' var _getType = function (inp) { var type = typeof inp, match; var key; if (type == 'object' && !inp) { return 'null'; } if (type == "object") { if (!inp.constructor) { return 'object'; } var cons = inp.constructor.toString(); match = cons.match(/(\w+)\(/); if (match) { cons = match[1].toLowerCase(); } var types = ["boolean", "number", "string", "array"]; for (key in types) { if (cons == types[key]) { type = types[key]; break; } } } return type; }; var type = _getType(mixed_value); var val, ktype = ''; switch (type) { case "function": val = ""; break; case "boolean": val = "b:" + (mixed_value ? "1" : "0"); break; case "number": val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value; break; case "string": val = "s:" + encodeURIComponent(mixed_value).replace(/%../g, 'x').length + ":\"" + mixed_value + "\""; break; case "array": case "object": val = "a"; /* if (type == "object") { var objname = mixed_value.constructor.toString().match(/(\w+)\(\)/); if (objname == undefined) { return; } objname[1] = this.serialize(objname[1]); val = "O" + objname[1].substring(1, objname[1].length - 1); } */ var count = 0; var vals = ""; var okey; var key; for (key in mixed_value) { ktype = _getType(mixed_value[key]); if (ktype == "function") { continue; } okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key); vals += this.serialize(okey) +this.serialize(mixed_value[key]); count++; } val += ":" + count + ":{" + vals + "}"; break; case "undefined": // Fall-through default: // if the JS object has a property which contains a null value, the string cannot be unserialized by PHP val = "N"; break; } if (type != "object" && type != "array") { val += ";"; } return val; } /**DESERIALIZAR VALORES COMO PHP*/ function unserialize (data) { // http://kevin.vanzonneveld.net // + original by: Arpad Ray (mailto:arpad@php.net) // + improved by: Pedro Tainha (http://www.pedrotainha.com) // + bugfixed by: dptr1988 // + revised by: d3x // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + input by: Brett Zamir (http://brett-zamir.me) // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + improved by: Chris // + improved by: James // % note: We feel the main purpose of this function should be to ease the transport of data between php & js // % note: Aiming for PHP-compatibility, we have to translate objects to arrays // * example 1: unserialize('a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}'); // * returns 1: ['Kevin', 'van', 'Zonneveld'] // * example 2: unserialize('a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}'); // * returns 2: {firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'} var error = function (type, msg, filename, line){ throw new this.window[type](msg, filename, line); }; var read_until= function (data, offset, stopchr){ var buf = []; var chr = data.slice(offset, offset + 1); var i = 2; while (chr != stopchr) { if ((i+offset) > data.length) { error('Error', 'Invalid'); } buf.push(chr); chr = data.slice(offset + (i - 1),offset + i); i += 1; } return [buf.length, buf.join('')]; }; var read_chrs = function (data, offset, length){ var buf; buf = []; for (var i = 0;i < length;i++){ var chr = data.slice(offset + (i - 1),offset + i); buf.push(chr); } return [buf.length, buf.join('')]; }; var _unserialize = function (data, offset){ var readdata; var readData; var chrs = 0; var ccount; var stringlength; var keyandchrs; var keys; if (!offset) { offset = 0; } var dtype = (data.slice(offset, offset + 1)).toLowerCase(); var dataoffset = offset + 2; var typeconvert = new Function('x', 'return x'); switch (dtype){ case 'i': typeconvert = function (x) { return parseInt(x, 10); }; readData = read_until(data, dataoffset, ';'); chrs = readData[0]; readdata = readData[1]; dataoffset += chrs + 1; break; case 'b': typeconvert = function (x) { return parseInt(x, 10) !== 0; }; readData = read_until(data, dataoffset, ';'); chrs = readData[0]; readdata = readData[1]; dataoffset += chrs + 1; break; case 'd': typeconvert = function (x) { return parseFloat(x); }; readData = read_until(data, dataoffset, ';'); chrs = readData[0]; readdata = readData[1]; dataoffset += chrs + 1; break; case 'n': readdata = null; break; case 's': ccount = read_until(data, dataoffset, ':'); chrs = ccount[0]; stringlength = ccount[1]; dataoffset += chrs + 2; readData = read_chrs(data, dataoffset+1, parseInt(stringlength, 10)); chrs = readData[0]; readdata = readData[1]; dataoffset += chrs + 2; if (chrs != parseInt(stringlength, 10) && chrs != readdata.length){ error('SyntaxError', 'String length mismatch'); } break; case 'a': readdata = {}; keyandchrs = read_until(data, dataoffset, ':'); chrs = keyandchrs[0]; keys = keyandchrs[1]; dataoffset += chrs + 2; for (var i = 0; i < parseInt(keys, 10); i++){ var kprops = _unserialize(data, dataoffset); var kchrs = kprops[1]; var key = kprops[2]; dataoffset += kchrs; var vprops = _unserialize(data, dataoffset); var vchrs = vprops[1]; var value = vprops[2]; dataoffset += vchrs; readdata[key] = value; } dataoffset += 1; break; default: error('SyntaxError', 'Unknown / Unhandled data type(s): ' + dtype); break; } return [dtype, dataoffset - offset, typeconvert(readdata)]; }; return _unserialize((data+''), 0)[2]; } /**REDONDEAR UN VALOR A UNA CANTIDAD DE DECIMALES*/ function redondear(cantidad, decimales) { var cantidad = parseFloat(cantidad); var decimales = parseFloat(decimales); decimales = (!decimales ? 2 : decimales); return Math.round(cantidad * Math.pow(10, decimales)) / Math.pow(10, decimales);0 } /** codigo generado para eliminar filas de una tabla*/ function eliminar_fila(id_tabla,id_fila) { var fila=document.getElementById(id_fila); var tabla=document.getElementById(id_tabla); tabla.removeChild(fila); // REMUEVE LA FILA } /** funcion cambiar valor de boton*/ function cmvalue2() { var btn2 = document.getElementById("btn2"); if(btn2.value == "+") { btn2.value = "-"; btn2.innerHTML="-"; } else { btn2.value = "+"; btn2.innerHTML="+"; } } function cmvalue() { var btn = document.getElementById("btn"); if(btn.value == "+") { btn.value = "-"; btn.innerHTML="-"; } else { btn.value = "+"; btn.innerHTML="+"; } } /**MOSTRAR EN UNA CAPA DETALLE DEL NIT SELECCIONADO*/ function detalle_nit (nit,e) { var ok=true; var peticion = false; peticion=object(); /** UBICACION DE LA CAPA*/ var y=e.clientY; var div=document.getElementById('DivMover'); div.style.left='10%'; div.style.visibility= "visible"; var url='../includes/graf_dir_detallado.php?documento='+nit+'&'+param(); peticion.open("GET",url); peticion.onreadystatechange=function(){ if (peticion.readyState==4) { div.innerHTML=peticion.responseText; } } peticion.send(null); document.getElementById('opaco').setAttribute("style","opacity: 0.5"); } /**HACER VISIBLE O NO UNA CAPA*/ function capa(accion,elemento) { //alert("Por aqui"); var div=document.getElementById(elemento); if (accion == '1') { div.style.visibility = "visible"; document.getElementById('opaco').setAttribute("style","opacity: 0.5"); } else { div.style.visibility = "hidden"; document.getElementById('opaco').setAttribute("style","opacity: "); } } /**MOSTRAR EN UNA CAPA DETALLE DEL NIT SELECCIONADO*/ function fecha_actual () { var ok=true; var peticion=false; var datos=new Array(); peticion=object(); /** UBICACION DE LA CAPA*/ var url='../includes/fecha_actual.php?'+param(); peticion.open("GET",url); peticion.onreadystatechange=function(){ if (peticion.readyState==4) { datos=peticion.responseText.split('-'); var fecha=new Date(datos[0],datos[1],datos[2],datos[3],datos[4],datos[5]); alert(fecha); return fecha; } } peticion.send(null); } /**MOSTRAR CONSULTA AVANZADA*/ function mostrar_fc(id_tabla,boton) { if (document.getElementById(id_tabla).style.display=="none") { document.getElementById(id_tabla).style.display="block"; } else { document.getElementById(id_tabla).style.display="none"; } if (boton.value=='+') { boton.value='-'; } else { boton.value='+'; } } /**CAMBIAR NOMBRE A CAMPO DE FECHA*/ function nm_fecha(campo,id_fecha,nm_campo,id_t_hasta,id_fc_hasta,id_tabla,boton,t_hasta) { document.getElementById(id_fecha).innerHTML=nm_campo+campo.id; if (campo.value!='7') { document.getElementById(id_t_hasta).style.visibility="collapse"; document.getElementById(id_fc_hasta).style.visibility="collapse"; t_hasta.value=''; } else { document.getElementById(id_t_hasta).style.visibility="visible"; document.getElementById(id_fc_hasta).style.visibility="visible"; } mostrar_fc(id_tabla,boton); } function param() { return "usuario=&modulo=&mod="; } /**MANEJO DE PESTAÑAS EN LOS FORMULARIO**/ function ver_pesta(tot,no_id,id_pes,id_tab,background) { document.getElementById(id_tab+no_id.toString()).style.display=''; if (background=='') { document.getElementById(id_pes+no_id.toString()).style.background='url(../imagenes/fn_formulario.png)'; } else { document.getElementById(id_pes+no_id.toString()).style.background=background; } document.getElementById(id_pes+no_id.toString()).setAttribute("class","actual"); for (var i=0;i<=tot;i++) { if (i!=no_id) { document.getElementById(id_pes+i.toString()).style.background='url(../imagenes/fn_boton_pes.png)'; document.getElementById(id_tab+i.toString()).style.display='none'; document.getElementById(id_pes+i.toString()).setAttribute("class","boton_pes"); } } } /**VUELVE EDITABLE UN TEXTO**/ function editable(campo,id,flag) { if (flag==1) { campo.setAttribute("style","display: block;"); foco(campo); document.getElementById(id).style.display='none'; } else { campo.setAttribute("style","display: none;"); document.getElementById(id).style.display='block'; } } /**CAMBIA EL TEXTO CUANDO DIGITAN UN CAMPO**/ function cambio_editable(campo,id){ if(campo.type!='select-one'){ document.getElementById(id).innerHTML=campo.value.toUpperCase(); }else{ document.getElementById(id).innerHTML=campo.options[campo.selectedIndex].text; } } /**NAVEGA CON LAS FLECHAS DE ARRIBA Y ABAJO POR EL FORMULARIO*/ function nav_formulario (campo_ant,campo_sig,evt) { var keyCode =document.layers ? evt.which :document.all ? event.keyCode :document.getElementById ? evt.keyCode : 0; if (keyCode==40) foco(campo_sig); if (keyCode==38) foco(campo_ant); } /**CERRAR CON ESC**/ function cerrar_esc (evt,pagina) { var keyCode =document.layers ? evt.which :document.all ? event.keyCode :document.getElementById ? evt.keyCode : 0; var r=''; if (keyCode==27) location=pagina; } function cambio_lis(campo,dato){ var datos=new Array(); var peticion=false; peticion=object(); var fragment_url='../includes/datos_personas.php?documento='+dato+'&'+param(); //abrimos la url peticion.open("GET",fragment_url); peticion.onreadystatechange=function(){ if (peticion.readyState==4) { if (peticion.responseText != '') { datos=peticion.responseText.split('@@'); campo.value=datos[3]; } } } peticion.send(null); } /**CREAR ATUOCOMPLENTAR**/ function creaAutocompletar(id_campo,id_div,datos){ new Autocompleter.Local(id_campo,id_div,datos,{tokens: new Array(',','\n'), fullSearch: true,partialSearch: true, choices:datos.length}); } function getDateInfo(date, wantsClassName) { var as_number = Calendar.dateToInt(date); if (String(as_number).indexOf("0308") == 4) { // my birthday :-p return { klass: "birthday", tooltip: "Happy birthday dear me!" }; } if (as_number >= 20090518 && as_number <= 20090524) return { klass : "highlight2", tooltip : "
%Y/%m/%d (%A)" + "
In the green week
" // formatted by printDate }; return DATE_INFO[as_number]; }; function cargar_ciudad(objeto,tipo,codigo,id_combo) { objeto.url="../stores/ciudades.php?tipo="+tipo+"&codigo="+codigo; objeto.close(); //dijit.byId(id_combo).set('value',''); } function cargar_ciudad_t(objeto,tipo,codigo,todos) { objeto.url="../stores/ciudades.php?tipo="+tipo+"&codigo="+codigo+"&todos="+todos; objeto.close(); //dijit.byId(id_combo).set('value',''); } function ar_sql_ar_javascript(a_sql) { var a_javascript=new Array(); a_sql=a_sql.substr(a_sql.indexOf('{')+1); a_sql=a_sql.replace('}',''); if (a_sql.length>0) a_javascript=a_sql.split(','); for (i=0;i','ª','©','®'], ['#Ntilde;','#ntilde;','#Aacute;','#aacute;','#Eacute;','#eacute;','#Iacute;','#iacute;','#Oacute;','#oacute;','#Uacute;','#uacute;', '#ordm;','#lt;','#gt;','#ordf;','#copy;','#reg;'],texto); } /** * * REEMPLAZA CARACTERES ESPECIALES POR SU RESPECTIVA NOTACIÓN EN HTML. * @param Texto a Reemplazar * @return Texto reemplazado * @author Ing. Juan Carlos Medina Hernández. */ function reemp_carac_esp_html(texto) { return str_replace(['Ñ','ñ','Á','á','É','é','Í','í','Ó','ó','Ú','ú','º','<','>','ª','©','®'], ['Ñ','ñ','Á','á','É','é','Í','í','Ó','ó','Ú','ú', 'º','<','>','ª','©','®'], texto); } /** * * REEMPLAZA NOTACIÓN EN HTML POR CARACTERES ESPECIALES. * @param Texto a Reemplazar * @return Texto reemplazado * @author Ing. Juan Carlos Medina Hernández. */ function reemp_html_carac_esp(texto) { return str_replace(['Ñ','ñ','Á','á','É','é','Í','í','Ó','ó', 'Ú','ú','º','<','>','ª','©','®'],['Ñ','ñ','Á','á','É','é','Í','í','Ó','ó','Ú','ú','º','<','>', 'ª','©','®'],texto); } function retorna_num(valor) { var numero= new Array(); numero=valor.split(''); var fl_num=false; var vl_num=''; for (i=0;i=1)&&!fl_num) fl_num=true; if (fl_num) vl_num+=numero[i]; } if (vl_num=='') vl_num='0'; return vl_num; } /** * BORRAR ESPACIOS EN BLANCO * @param Texto a reemplazar. * @return Texto Reemplazado * @author Ing. Juan Carlos Medina Hernández */ function quitar_espacios_blanco(texto) { var texto_a=new Array(); texto=trim(texto); texto_a=str_word_count(texto, 1); texto=implode(' ', texto_a); return texto; } /** * ELIMINA UNA FILA HIPOTESIS DE AGENTE EN VICITMAS * @param Numero de vicitima * @param Numero de fila. */ function el_hipotesis_v(no_vic,no_hipo) { document.getElementById('tr_hipo_v_'+no_vic+'_'+no_hipo).style.display='none'; document.getElementById('v_filas_hip_v_'+no_vic+'_'+no_hipo).value='N'; } /** * CREAR UN SALTO DE LINEA EN HTML * @param String a cambiar. * @return String con salto de linea html */ function salto_linea_html(valor) { if (valor!=''&&valor!=null) return str_replace(array('@@','||'),array('<','>'),valor); else return ''; } function ad_hipotesis_v(no_vic) { var fila_hipo=0; var inner=''; fila_hipo=parseInt(document.getElementById('h_filas_hip_v_'+no_vic).value)+1; document.getElementById('h_filas_hip_v_'+no_vic).value=fila_hipo.toString(); var tbody=document.getElementById('hipotesis_v_'+no_vic); var tr=document.createElement("tr"); tr.setAttribute("id","tr_hipo_v_"+no_vic+"_"+fila_hipo.toString()); tbody.appendChild(tr); var td=document.createElement("td"); td.setAttribute("align","center"); td.setAttribute("id","texto_mayus"); tr.appendChild(td); var campo=document.createElement("input"); campo.setAttribute("name","v_filas_hip_v_"+no_vic+"_"+fila_hipo.toString()); campo.setAttribute("id","v_filas_hip_v_"+no_vic+"_"+fila_hipo.toString()); campo.setAttribute("value","S"); campo.setAttribute("type","hidden"); td.appendChild(campo); var onchan=function anonymous() { dijit.byId('s_hipotesis_v_'+no_vic+'_'+fila_hipo.toString()).set('value',dijit.byId('t_hipotesis_v_'+no_vic+'_'+fila_hipo.toString()).value); }; var campo_dojo=new dijit.form.ValidationTextBox({name:"t_hipotesis_v_"+no_vic+"_"+fila_hipo.toString(), id:"t_hipotesis_v_"+no_vic+"_"+fila_hipo.toString(),style:"width: 5em;",maxLength:"5",onChange:onchan,tooltipPosition:"above, below", promptMessage:"Digite el código de la hipótesis de agente.",trim:true}); td.appendChild(campo_dojo.domNode); var td=document.createElement("td"); td.setAttribute("align","center"); td.setAttribute("id","texto_mayus"); tr.appendChild(td); var store=new dojo.data.ItemFileReadStore({jsId:'s_hipotesis_v_'+no_vic+'_'+fila_hipo.toString()+'_store', url:'../stores/parametros.php?tabla=HPTAC',urlPreventCache:false,clearOnClose:true}); onchan=function anonymous() { document.getElementById('t_hipotesis_v_'+no_vic+'_'+fila_hipo.toString()).value=arguments[0]; }; campo_dojo=new dijit.form.FilteringSelect({name:'s_hipotesis_v_'+no_vic+'_'+fila_hipo.toString(), id:'s_hipotesis_v_'+no_vic+'_'+fila_hipo.toString(),style:"width: 350px;", placeHolder:"Seleccione la hipótesis de agente",promptMessage:"Seleccione la hipótesis de agente.",required:true,store:store, searchAttr:"name",highlightMatch:"all",queryExpr:"*${0}*",autoComplete:false,pageSize:"20",tooltipPosition:"above,below", onChange:onchan}); td.appendChild(campo_dojo.domNode); td=document.createElement("td"); td.setAttribute("align","center"); tr.appendChild(td); campo_dojo=new dijit.form.Textarea({name:'t_obs_hipotesis_v_'+no_vic+'_'+fila_hipo.toString(), id:'t_obs_hipotesis_v_'+no_vic+'_'+fila_hipo.toString(),trim:true}); td.appendChild(campo_dojo.domNode); new dijit.Tooltip({connectId:'t_obs_hipotesis_v_'+no_vic+'_'+fila_hipo.toString(),id:'t_obs_hipotesis_v_'+no_vic+'_'+fila_hipo.toString()+ "_tooltip",position:"above, below",label:"Digite la descripción detallada de la hipótesis de agente."}); td=document.createElement("td"); td.setAttribute("align","center"); tr.appendChild(td); var onclic=function anonymous() { ad_hipotesis_v(no_vic);}; campo_dojo=new dijit.form.Button({name:"b_add_hip_v_"+no_vic+"_"+fila_hipo.toString(),id:"b_add_hip_v_"+no_vic+"_"+fila_hipo.toString(), onClick:onclic,type:"button",label:"+"}); td.appendChild(campo_dojo.domNode); new dijit.Tooltip({connectId:'b_add_hip_v_'+no_vic+'_'+fila_hipo.toString(),id:'b_add_hip_v_'+no_vic+'_'+fila_hipo.toString()+ "_tooltip",position:"above, below",label:"Adicionar una fila para hipótesis de agente."}); onclic=function anonymous() { el_hipotesis_v(no_vic,fila_hipo.toString());}; campo_dojo=new dijit.form.Button({name:"b_elim_hipo_v_"+no_vic+"_"+fila_hipo.toString(),id:"b_elim_hipo_v_"+no_vic+"_"+fila_hipo.toString(), onClick:onclic,type:"button",label:"-"}); td.appendChild(campo_dojo.domNode); new dijit.Tooltip({connectId:'b_elim_hipo_v_'+no_vic+'_'+fila_hipo.toString(),id:'b_elim_hipo_v_'+no_vic+'_'+fila_hipo.toString()+ "_tooltip",position:"above, below",label:"Eliminar una fila para hipótesis de agente."}); }