// JavaScript Document var Exito = new function(){ // this.show = function(msj){ $('msjExito').innerHTML = msj; var l = $('capaExito'); l.style.top = (((HScreen() - l.offsetHeight) / 2) + YPos()) + 'px'; l.style.left = (((WScreen() - l.offsetWidth) / 2) + XPos()) + 'px'; l.style.visibility = 'visible'; try{ $('aceptarExito').focus(); }catch(e){ ; } AddEvent(document, 'keypress', escape); AddEvent($('aceptarExito'), 'click', accept); AddEvent($('cerrarExito'), 'click', accept); } this.hide = function(){ RemEvent(document, 'keypress', escape); RemEvent($('aceptarExito'), 'click', accept); RemEvent($('cerrarExito'), 'click', accept); var l = $('capaExito'); l.style.visibility = 'hidden'; l.style.top = '-1000px'; } this.onAccept = null; var accept = function(e){ if(!!e){ StopEvent(e); } this.hide(); if(!!this.onAccept){ this.onAccept(); } }.closure(this); var escape = function(event){ if(event.keyCode == 27){ accept(); } }.closure(this); // } // JavaScript Document var Error = new function(){ // this.show = function(msj){ $('msjError').innerHTML = msj; var l = $('capaError'); l.style.top = (((HScreen() - l.offsetHeight) / 2) + YPos()) + 'px'; l.style.left = (((WScreen() - l.offsetWidth) / 2) + XPos()) + 'px'; l.style.visibility = 'visible'; try{ $('aceptarError').focus(); }catch(e){ ; } AddEvent(document, 'keypress', escape); AddEvent($('aceptarError'), 'click', accept); AddEvent($('cerrarError'), 'click', accept); } this.hide = function(){ RemEvent(document, 'keypress', escape); RemEvent($('aceptarError'), 'click', accept); RemEvent($('cerrarError'), 'click', accept); var l = $('capaError'); l.style.visibility = 'hidden'; l.style.top = '-1000px'; } this.onAccept = null; var accept = function(e){ if(!!e){ StopEvent(e); } this.hide(); if(!!this.onAccept){ this.onAccept(); } }.closure(this); var escape = function(event){ if(event.keyCode == 27){ accept(); } }.closure(this); // } // JavaScript Document function form(nombre, archivo){ var error = $('error' + nombre); var loader = $('loader' + nombre); var enviando = false; var errores = 0; var aCampos = new Array(); var aValidar = new Array(); var aLimpiar = new Array(); var req = new Request(); var elemento = false; this.moreInfo = ''; // this.onSuccess = null; this.onError = null; this.onSend = null; // req.listener = function(){ var d = req.respuestaXML; block(false); if(!!loader){ loader.style.display = 'none'; } if(!d){ alert(req.respuestaHTML); } else if(d.getAttribute('exito') == 'si'){ if(!this.onSuccess){ block(true); Exito.onAccept = onAccept; Exito.show(d.firstChild.data); } else{ this.onSuccess(d); } } else{ if(!this.onError){ block(true); Error.onAccept = onAccept; Error.show(d.firstChild.data); } else{ this.onError(d); } } }.closure(this); this.pedirExterno = function(archivo,valor){ req.pedir(archivo,valor); } this.onAccept = function(){ onAccept(); } var onAccept = function(){ clean(); block(false); }.closure(this); this.addField = function(campo, nombre, expresion, clear){ var o = {'c':campo, 'n':nombre}; // aCampos.push(o); if(expresion){ campo.expresion = expresion; campo.inputError = inputError; if(campo.tagName.toLowerCase() != 'select')campo.onblur = funcVal.closure(campo); else campo.onchange = funcVal.closure(campo); // aValidar.push(aCampos.length - 1); } if(clear){ aLimpiar.push(aCampos.length - 1); } return aCampos.length-1; } var clean = function(){ var i = null; // for(i in aLimpiar){ aCampos[aLimpiar[i]]['c'].value = ''; } for(i in aCampos){ inputError(aCampos[i]['c'], false); } errores = 0; showError(); } this.enter = function(event){ if(event.keyCode == 13){ this.send(); } }.closure(this); this.send = function(event,sinBlock){ var v = '', i = null; if(!!event){ StopEvent(event); } if(!!this.onSend){ this.onSend(); } // if(enviando){ return false; } else if(validate()){ return false; } // block(true); if(!!loader){ loader.style.display = 'block'; } // for(i in aCampos){ v += aCampos[i]['n'] + SEP_IGUAL + trim(aCampos[i]['c'].value) + SEP_AND; } if(this.moreInfo != ''){ v += this.moreInfo; } // req.pedir(DIR_ROOT + 'requests/' + archivo + '.php', v); return true; }.closure(this); var inputError = function(c, b){ errores += (b)? 1:0; c.className = (b)? 'inputError':''; }.closure(this); var showError = function(){ error.style.display = (errores > 0)? 'block':'none'; } var funcVal = function(){ this.value = trim(this.value); if(this.value.search(this.expresion) == 0 && !this.errorDesactivado){ this.inputError(this, false); } else{ this.inputError(this, true); } } var validate = function(){ var i = null, c; // errores = 0; for(i in aValidar){ c = aCampos[aValidar[i]]['c']; if(!c.disabled){ if(c.tagName.toLowerCase() != 'select')c.onblur(); else c.onchange(); } } showError(); return (errores > 0); } this.unblock = function(){ var i = null; enviando = false; for(i in aCampos){ aCampos[i]['c'].disabled = false; } } var block = function(b){ var i = null; // enviando = b; for(i in aCampos){ aCampos[i]['c'].disabled = b; } } } var oEncuesta = new function(){ //A var agregarEncuesta = function(idEncuesta,tipoEncuesta){ ENCUESTAS[idEncuesta] = new Object(); ENCUESTAS[idEncuesta].tipo = tipoEncuesta; ENCUESTAS[idEncuesta].preguntas = new Array(); ENCUESTAS[idEncuesta].idEncuesta = idEncuesta; } var agregarPregunta = function(idEncuesta,idPregunta,tipoRespuesta){ ENCUESTAS[idEncuesta].preguntas[idPregunta] = new Object(); ENCUESTAS[idEncuesta].preguntas[idPregunta].tipoRespuesta = tipoRespuesta; ENCUESTAS[idEncuesta].preguntas[idPregunta].error = $('errorPregunta' + idPregunta); ENCUESTAS[idEncuesta].preguntas[idPregunta].fieldset = $('fieldEncuesta' + idPregunta); switch(tipoRespuesta){ case 'si/no': ENCUESTAS[idEncuesta].preguntas[idPregunta].si = $('siNoSi'+idPregunta); ENCUESTAS[idEncuesta].preguntas[idPregunta].no = $('siNoNo'+idPregunta); break; case 'opcionSimpleSelect': ENCUESTAS[idEncuesta].preguntas[idPregunta].selectRespuesta = $('select' + idPregunta); break; case 'texto': ENCUESTAS[idEncuesta].preguntas[idPregunta].texto = $('texto' + idPregunta); break; case 'textoEmail': ENCUESTAS[idEncuesta].preguntas[idPregunta].texto = $('texto' + idPregunta); break; case 'textoNumero': ENCUESTAS[idEncuesta].preguntas[idPregunta].texto = $('texto' + idPregunta); break; case 'textoLargo': ENCUESTAS[idEncuesta].preguntas[idPregunta].texto = $('texto' + idPregunta); break; default: ENCUESTAS[idEncuesta].preguntas[idPregunta].opciones = new Array(); break; } } var agregarOpcion = function(idEncuesta,idPregunta,idOpcion){ ENCUESTAS[idEncuesta].preguntas[idPregunta].opciones[idOpcion] = $('opcion' + idPregunta + '-' + idOpcion); } //C var cargarDesdeXml = function(idEncuesta,xml){ var i,j; for(i=0;i