// JavaScript Document Function.prototype.closure = function(obj){ // Init object storage. if (!window.__objs){ window.__objs = []; window.__funs = []; } // For symmetry and clarity. var fun = this; // Make sure the object has an id and is stored in the object store. var objId = obj.__objId; if (!objId) __objs[objId = obj.__objId = __objs.length] = obj; // Make sure the function has an id and is stored in the function store. var funId = fun.__funId; if (!funId) __funs[funId = fun.__funId = __funs.length] = fun; // Init closure storage. if (!obj.__closures) obj.__closures = []; // See if we previously created a closure for this object/function pair. var closure = obj.__closures[funId]; if (closure) return closure; // Clear references to keep them out of the closure scope. obj = null; fun = null; // Create the closure, store in cache and return result. var o = __objs[objId].__closures[funId] = function (){ if(!!__funs[funId] && !!__objs[objId]) return __funs[funId].apply(__objs[objId], arguments); else return false; }; o.__funId = funId; return o; }; //window.__objs[obj.__objId] = null; EliminarClosures = function(o){ var i = 0; if(o){ if(o.__objId){ for(i in o.__closures){ delete(window.__funs[i]); delete(o.__closures[i]); } delete(window.__objs[o.__objId]); /*delete(o.__closures); delete(o.__objId);*/ o.__closures = null; o.__objId = null; } } i = null; } var LimpiarClosures = function(){ if(!!Nav && Nav.esMz) window.addEventListener('unload', LimpiarClosures, false); else window.detachEvent("onunload",LimpiarClosures); if(window.__objs){ for(i in window.__objs) EliminarClosures(window.__objs[i]); } window.__objs = []; window.__funs = []; }; Limpiar = function(){ if(!!Nav && Nav.esMz) window.addEventListener('unload', LimpiarClosures, false); else window.attachEvent("onunload", LimpiarClosures); }(); document.LimpiarClosures = LimpiarClosures; // JavaScript Document Request = function(oListener, metodo){ this.pedido = new crearXHR(); this.esperar = true; this.respuestaXML = null; this.respuestaHTML = null; this.archivo=null; this.valores=null; this.listener=oListener; // if(!metodo) this.metodo = 'POST'; else this.metodo = metodo; } Request.prototype.pedir = function(a, v, m){ //inicializamos if(!!a) this.archivo = a; if(!!v) this.valores = v; if(!!m) this.metodo = m; // cancelarPedido(this.pedido); // this.pedido.onreadystatechange = this.procesar.closure(this); // this.pedido.open(this.metodo, this.archivo, true); // this.pedido.setRequestHeader("Content-Type", "text/xml; charset=iso-8859-15"); // if(this.valores) this.pedido.send(this.valores); else this.pedido.send(); } Request.prototype.procesar = function(){ //alert("procesando") //if(this.pedido && this.pedido.readyState) alert(this.pedido.readyState) if(this.pedido && this.pedido.readyState == 4){ //alert(this.pedido.status+this.pedido.statusText+this.pedido.responseText) if(this.pedido.status == 200){ if(this.pedido.responseXML)this.respuestaXML = this.pedido.responseXML.documentElement; this.respuestaHTML = this.pedido.responseText; //alert(this.listener); this.cancelar(); if(this.listener && this.listener.onRequestLoad) this.listener.onRequestLoad(); else if(typeof(this.listener)=='function') this.listener(); } else{ if(this.pedido.status == 12152){//cancelado por el servidor this.esperar = false; this.pedir(); return false; } else{ alert("Error JS Request.procesar(): Status "+this.pedido.status+" "+this.pedido.statusText+" "+this.archivo+" "+this.metodo); this.cancelar(); } } } this.esperar = false; } Request.prototype.cancelar = function(){ cancelarPedido(this.pedido); } /* FUNCION DE CREACION DE XMLHttpRequest */ crearXHR = function(){ var r = null if (window.XMLHttpRequest) r = new XMLHttpRequest() else if(window.ActiveXObject) { var msp = new Array('Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP') for(var i = 0; i < msp.length; i++){ try { r = new ActiveXObject(msp[i]) } catch (e){} } } return r } /* FUNCION DE DETENCION DE XMLHttpRequest */ cancelarPedido = function(reqXHR){ if(reqXHR!=null){ reqXHR.onreadystatechange=new Function()//una funcion vacia... reqXHR.abort() } } // JavaScript Document trim = function(str){ if(str && typeof(str)=='string'){ var i = 0, x = (l = str.length) - 1; while(i0 && str.charAt(x)==" ") x--; str = str.substring(i, x + 1); } return str; }/*//////////// File: Tween.js Creation Date: January 20 2006 Author: Philippe Maegerman Email: mx2004-at-pandora.be Website: http://jsTween.blogspot.com Download: http://cfpim.coffeeflower.com/jsTween/Tween.js *///////////// function Delegate() {} Delegate.create = function (o, f) { var a = new Array() ; var l = arguments.length ; for(var i = 2 ; i < l ; i++) a[i - 2] = arguments[i] ; return function() { var aP = [].concat(arguments, a) ; f.apply(o, aP); } } Tween = function(obj, prop, func, begin, finish, duration, suffixe){ this.init(obj, prop, func, begin, finish, duration, suffixe) } var t = Tween.prototype; t.obj = new Object(); t.prop=''; t.func = function (t, b, c, d) { return c*t/d + b; }; t.begin = 0; t.change = 0; t.prevTime = 0; t.prevPos = 0; t.looping = false; t._duration = 0; t._time = 0; t._pos = 0; t._position = 0; t._startTime = 0; t._finish = 0; t.name = ''; t.suffixe = ''; t._listeners = new Array(); t.setTime = function(t){ this.prevTime = this._time; if (t > this.getDuration()) { if (this.looping) { this.rewind (t - this._duration); this.update(); this.broadcastMessage('onMotionLooped',{target:this,type:'onMotionLooped'}); } else { this._time = this._duration; this.update(); this.stop(); this.broadcastMessage('onMotionFinished',{target:this,type:'onMotionFinished'}); } } else if (t < 0) { this.rewind(); this.update(); } else { this._time = t; this.update(); } } t.getTime = function(){ return this._time; } t.setDuration = function(d){ this._duration = (d == null || d <= 0) ? 100000 : d; } t.getDuration = function(){ return this._duration; } t.setPosition = function(p){ this.prevPos = this._pos; var a = this.suffixe != '' ? this.suffixe : ''; this.obj[this.prop] = Math.round(p) + a; this._pos = p; this.broadcastMessage('onMotionChanged',{target:this,type:'onMotionChanged'}); } t.getPosition = function(t){ if (t == undefined) t = this._time; return this.func(t, this.begin, this.change, this._duration); }; t.setFinish = function(f){ this.change = f - this.begin; }; t.geFinish = function(){ return this.begin + this.change; }; t.init = function(obj, prop, func, begin, finish, duration, suffixe){ if (!arguments.length) return; this._listeners = new Array(); this.addListener(this); if(suffixe) this.suffixe = suffixe; this.obj = obj; this.prop = prop; this.begin = begin; this._pos = begin; this.setDuration(duration); if (func!=null && func!='') { this.func = func; } this.setFinish(finish); } t.start = function(){ this.rewind(); this.startEnterFrame(); this.broadcastMessage('onMotionStarted',{target:this,type:'onMotionStarted'}); //alert('in'); } t.rewind = function(t){ this.stop(); this._time = (t == undefined) ? 0 : t; this.fixTime(); this.update(); } t.fforward = function(){ this._time = this._duration; this.fixTime(); this.update(); } t.update = function(){ this.setPosition(this.getPosition(this._time)); } t.startEnterFrame = function(){ this.stopEnterFrame(); this.isPlaying = true; this.onEnterFrame(); } t.onEnterFrame = function(){ if(this.isPlaying) { this.nextFrame(); setTimeout(Delegate.create(this, this.onEnterFrame), 0); } } t.nextFrame = function(){ this.setTime((this.getTimer() - this._startTime) / 1000); } t.stop = function(){ this.stopEnterFrame(); this.broadcastMessage('onMotionStopped',{target:this,type:'onMotionStopped'}); } t.stopEnterFrame = function(){ this.isPlaying = false; } t.continueTo = function(finish, duration){ this.begin = this._pos; this.setFinish(finish); if (this._duration != undefined) this.setDuration(duration); this.start(); } t.resume = function(){ this.fixTime(); this.startEnterFrame(); this.broadcastMessage('onMotionResumed',{target:this,type:'onMotionResumed'}); } t.yoyo = function (){ this.continueTo(this.begin,this._time); } t.addListener = function(o){ this.removeListener (o); return this._listeners.push(o); } t.removeListener = function(o){ var a = this._listeners; var i = a.length; while (i--) { if (a[i] == o) { a.splice (i, 1); return true; } } return false; } t.broadcastMessage = function(){ var arr = new Array(); for(var i = 0; i < arguments.length; i++){ arr.push(arguments[i]) } var e = arr.shift(); var a = this._listeners; var l = a.length; for (var i=0; i 4){ //cambiamos this.lista.style.height = (this.altoMaximo) + 'px'; this.lista.style.overflowY = 'scroll'; } else{ this.lista.style.height = ''; this.lista.style.overflowY = ''; if(this.lista.style.width!=(this.anchoMaximo+'px')) this.lista.style.width = this.anchoMaximo + 'px'; } } this.crearOpcion = function(texto, oInfo){ var a = document.createElement('div'); this.lista.appendChild(a); var oOpcion = {objeto:a, oInfo:oInfo, pos:this.opciones.length, seleccionado:false}; a.oPadre = this; a.unselectable = true; a.innerHTML = texto; a.className = 'FiltradorOpcionOff'; //a.style.width = this.anchoMaximo+'px'; AddEvent(a, "mouseover", function(){ RemEvent(this.oPadre.input, "blur", fa_1); this.className = 'FiltradorOpcionOn'; }.closure(a)); AddEvent(a, "mouseout", function(){ AddEvent(this.oPadre.input, "blur", fa_1); this.className = 'FiltradorOpcionOff'; }.closure(a)); AddEvent(a, "focus", function(){ RemEvent(this.oPadre.input, "blur", fa_1); this.className = 'FiltradorOpcionOn'; }.closure(a)); AddEvent(a, "blur", function(){ AddEvent(this.oPadre.input, "blur", fa_1); this.className = 'FiltradorOpcionOff'; }.closure(a)); AddEvent(a, "click", function(e){ if(this.seleccionado) return false; this.seleccionado = true; oClase.cancelarSalida(); oClase.seleccionar(this, false); if(Nav.esMz){ event.preventDefault(); event.stopPropagation(); } else{ event.cancelBubble = true; event.returnValue = false; } }.closure(oOpcion)); AddEvent(a, "mouseup", function(e){ if(!!e && Nav.esMz) event = e; if(this.seleccionado) return false; this.seleccionado = true; oClase.cancelarSalida(); oClase.seleccionar(this, false); if(Nav.esMz){ event.preventDefault(); event.stopPropagation(); } else{ event.cancelBubble = true; event.returnValue = false; } }.closure(oOpcion)); AddEvent(a, "keydown", function(){ oClase.detectarTecla() }.closure(a)); this.opciones.push(oOpcion); a = oOpcion = null; } this.crearMsgError = function(){ var a = document.createElement('div'); a.unselectable = true; a.innerHTML = this.msgError; a.className = 'FiltradorError'; this.lista.appendChild(a); } this.seleccionarOpcion = function(valor, campo){ campo = (typeof(campo)=='string')? campo : 'id'; for(var i = 0; i < this.opciones.length; i++){ //alert(this.opciones[i].oInfo[campo]+' '+valor); if(this.opciones[i].oInfo[campo]==valor) return this.seleccionar(this.opciones[i], false); } } this.seleccionar = function(oOpcion, darFocus){ this.input.value = oOpcion.objeto.innerHTML; this.valorBuscado = this.input.value; this.input.oInfo = oOpcion.oInfo; this.opcionElegida = null; this.salir(darFocus); if(this.cuandoSelecciono) this.cuandoSelecciono(oOpcion.oInfo); } this.deseleccionar = function(){ this.input.value = ''; this.input.oInfo = null; this.valorBuscado = '=¿_|+¡-'; this.opcionElegida = null; this.mostrarLista('none'); } // this.iniciarCarga = function(){ this.seleccionarOpcion(this.__dato,this.__campo); this.cuandoAcerto = this.__func; delete(this.__func); delete(this.__dato); delete(this.__campo); } this.iniciar = function(dato, campo){ this.deseleccionar(); this.__func = this.cuandoAcerto; this.__dato = dato; this.__campo = campo; this.cuandoAcerto = this.iniciarCarga; this.enviar(true); } // this.limpiar = function(){ // this.input.oInfo = null; this.opcionElegida = null; //eliminamos todas las opciones cargadas var i = null; var op = null; while(this.opciones.length > 0){ op = this.opciones[this.opciones.length-1]; op.objeto.parentNode.removeChild(op.objeto); this.opciones.pop(); EliminarClosures(op.objeto); EliminarClosures(op); op = null; } //por las dudas while(this.lista.hasChildNodes()){ EliminarClosures(this.lista.firstChild); this.lista.removeChild(this.lista.firstChild); } i = null; } this.controlObligatorio=function(e){ if(!!e && Nav.esMz) event = e; if((this.obligatorio==true || this.input.value!='') && this.opciones.length!=1){ //try{this.input.focus();}catch(e){;}; if(this.lista.style.display!='none') this.mostrarLista('none'); if(Nav.esMz){ event.preventDefault(); event.stopPropagation(); } else{ event.cancelBubble = true; event.returnValue = false; } } } this.inputBlur = function(e){ if(!!e && Nav.esMz) event = e; if((this.obligatorio==true || this.input.value!='') && (this.input.oInfo==null || // this.valorBuscado.substr(0,this.valorBuscado.length)==this.input.value.substr(0,this.input.value.length))){ if(Nav.esMz){ event.preventDefault(); event.stopPropagation(); } else{ event.returnValue = false; event.cancelBubble = true; } this.enviar(); } else{ if(this.input.value==''){ this.deseleccionar(); this.exito = false; } this.salir(false); this.input.oInfo = null; if(this.input.value=='' && this.cuandoFallo) this.cuandoFallo(); } } this.detectarTecla = function(e){ if(!!e && Nav.esMz) event = e; //si es flecha arriba y tuvimos exito en la busqueda if(event.keyCode==38 && this.exito) this.moverArriba(); //si es flecha abajo y tuvimos exito en la busqueda else if(event.keyCode==40 && this.exito) this.moverAbajo(); //si es enter else if(event.keyCode==13 && this.exito && this.opcionElegida!=null){ FireEvent(this.opcionElegida.objeto, 'click'); this.salir(); } else if(event.keyCode==37 && this.exito){ try{this.input.focus();}catch(e){;} this.opcionElegida = null; } if(Nav.esMz){ event.preventDefault(); event.stopPropagation(); } else{ event.returnValue = false; event.cancelBubble = true; } } this.moverAbajo = function(){ var oOpcion = this.opcionElegida; if(oOpcion==null && this.lista.style.display != 'none'){ //le quitamos el evento temporalmente RemEvent(this.input, 'blur', fa_1); // oOpcion = this.opciones[0]; } else if(oOpcion!=null && (this.opcionElegida.pos+1) < this.opciones.length) oOpcion = this.opciones[this.opcionElegida.pos+1]; // if(oOpcion!=null && this.lista.style.display != 'none'){ try{oOpcion.objeto.focus();}catch(e){;} } // this.opcionElegida = oOpcion; } this.moverArriba = function(){ var oOpcion = this.opcionElegida; if(oOpcion==null && this.lista.style.display!='none'){ //le quitamos el evento temporalmente RemEvent(this.input, 'blur', fa_1); oOpcion = this.opciones[0]; } else if(this.opcionElegida.pos-1 >= 0) oOpcion = this.opciones[this.opcionElegida.pos-1]; else if(oOpcion!=null){ //volvemos al input try{this.input.focus();}catch(e){;} oOpcion = null; } if(oOpcion!=null && this.lista.style.display!='none'){ try{oOpcion.objeto.focus();}catch(e){;} } this.opcionElegida = oOpcion; } this.onRequestLoad = function(){ // this.analizarRespuesta(this.req.respuestaXML); this.esperar = false; } this.enviar = function(noDesplegar){ //si no esperamos if(noDesplegar==true) this.noDesplegar = noDesplegar; if(!this.esperar && this.input.value!=this.valorBuscado){ this.esperar = true; this.valorBuscado = this.input.value; this.req.pedir(this.archivoReq, this.postVarName+this.input.value); } /*else if(this.input.value==this.valorBuscado){ this.mostrarLista('block'); this.controlarAlto(); this.controlObligatorio(); }*/ } this.enviarPorAtras = function(v){ this.mostrarLista('none'); this.noDesplegar = true; if(this.esperar) this.req.cancelar(); this.esperar = true; this.req.pedir(this.archivoReq, v); } this.analizarRespuesta= function(oXML){ // if(this.nodoPadre){ var nodoPadre = oXML.ownerDocument.getElementsByTagName(this.nodoPadre); oXML = nodoPadre[0]; } // if(oXML){ //borramos this.limpiar(); //creamos las nuevas opciones for(var i = 0; i < oXML.childNodes.length; i++){ //vemos los atributos var oInfo = new Object; for(var x = 0; x < oXML.childNodes[i].attributes.length; x++) oInfo[oXML.childNodes[i].attributes[x].nodeName] = oXML.childNodes[i].attributes[x].nodeValue; // this.crearOpcion((oXML.childNodes[i].text)? oXML.childNodes[i].text: oXML.childNodes[i].textContent, oInfo); } // if(i>0){ this.exito = true; if(this.opciones.length==1){ this.seleccionar(this.opciones[0], false); this.valorBuscado = this.opciones[0].objeto.innerHTML; } } else{ this.exito = false; this.crearMsgError(); } // this.controlObligatorio(); // if(i!=1 && !this.noDesplegar){ this.mostrarLista('inline'); this.controlarAlto(); } else this.noDesplegar = false; // if(this.exito && this.cuandoAcerto){ if(this.obligatorio && i!=1){ this.input.oInfo = null; if(this.cuandoFallo) this.cuandoFallo(); } else this.cuandoAcerto(); } else if(!this.exito && this.cuandoFallo){ this.input.oInfo = null; this.cuandoFallo(); } } else{ alert(this.req.respuestaHTML); //alert("Error JS Filtrar.analizarRespuesta(): Objeto xml inexistente."); //if(confirm('Debug?')) a = assFiltrador; } } // var fa_1 = fa_2 = fa_3 = fa_4 = fa_5 = fa_6 = fa_7 = null; this.ponerEventos = function(){ AddEvent(this.input, "blur", fa_1 = this.inputBlur.closure(this)); AddEvent(this.input, "focus", fa_2 = function(){ RemEvent(this.input, "blur", fa_1); AddEvent(this.input, "blur", fa_1); }.closure(this)); AddEvent(this.input, "keydown", fa_3 = function(e){ this.filtrar(e) }.closure(this)); AddEvent(this.input, "dblclick", fa_4 = function(e){ this.filtrar(e, true) }.closure(this)); AddEvent(this.lista, "focus", fa_5 = this.cancelarSalida.closure(this)); AddEvent(this.lista, "keydown", fa_6 = this.detectarTecla.closure(this)); AddEvent(this.lista, "blur", fa_7 = this.salir.closure(this)); } this.ponerEventos(); this.quitarEventos = function(){ RemEvent(this.input, "blur", fa_1); RemEvent(this.input, "focus", fa_2); RemEvent(this.input, "keydown", fa_3); RemEvent(this.input, "dblclick", fa_4); RemEvent(this.lista, "focus", fa_5); RemEvent(this.lista, "keydown", fa_6); RemEvent(this.lista, "blur", fa_7); } }