function saludos(){
	alert('Powered By:\n\tAnalista programador: Javier De Andres González\n\tAnalista programador: Victor Garcia Garcia\n\tDiseñador: Iván Castro Barahona');	
}
/* Simple AJAX Code-Kit (SACK) v1.6.1 */
/* ©2005 Gregory Wild-Smith Modificado por Victor Garcia Garcia*/
/* www.twilightuniverse.com */
/* Software licenced under a modified X11 licence,
   see documentation or authors website for more details */

var iden=0;
function sack(file) {
	this.nombre='ajax'+iden;
	iden++;
	this.xmlhttp = null;
	this.resetData = function() {
		this.method = "POST";
  		this.queryStringSeparator = "?";
		this.argumentSeparator = "&";
		this.URLString = "";
		this.encodeURIString = true;
  		this.execute = false;
  		this.element = null;
		this.elementObj = null;
		this.requestFile = file;
		this.vars = new Object();
		this.responseStatus = new Array(2);
  	};
	this.rescatar_script = function rescatar_script(texto){

		var tscr = texto.getElementsByTagName('script');		
		for(var i=0;i<tscr.length;i++){
			eval(tscr[i].text);
		}

/*		var textoNormal='';	
		var patron = /<script([^]*?)>([^]*?)<\/script>/igm;
		var contenido = /^<script([^]*?)>([^]*?)<\/script>$/igm;	
		var resultado = texto.match(patron);
		if(resultado==null) return;
		for(i=0;i<resultado.length;i++){
			var scr = resultado[i].replace(contenido,'$1');
			var script = resultado[i].replace(contenido,'$2');
			if(scr.indexOf('src="')!=-1){
				var head = document.getElementsByTagName('head').item(0);
				var nuevo = document.createElement('script');
				head.appendChild(nuevo);
				nuevo.outerHTML=resultado[i];
//				alert(nuevo.outerHTML);
			}else{
//				alert('evaluando '+script);
				eval(script);
			}
		}
*/
	}
	this.mostrar=function(texto){
		var self=this;
		if(self.element=='XXdocumentXX'){
			document.write(' '+texto);
			document.close();
		}else if (self.elementObj) {
			elemNodeName = self.elementObj.nodeName;
			elemNodeName=elemNodeName.toLowerCase();
			if (elemNodeName == "input"
			|| elemNodeName == "option"
			|| elemNodeName == "textarea") {
				self.elementObj.value = texto;
			} else if( elemNodeName == "select"){
				self.elementObj.style.visibility='hidden';
				self.elementObj.innerHTML = texto;
				self.elementObj.style.visibility='visible';
			} else {
				self.elementObj.style.visibility='hidden';
				self.elementObj.innerHTML = texto;
				self.elementObj.style.visibility='visible';
				//Proceso de javascript
//				this.rescatar_script(texto);
				this.rescatar_script(self.elementObj);
			}
		}else { alert('No existe elemento '+this.element);}	
	}

	this.resetFunctions = function() {
  		this.onLoading = function (){
			this.mostrar("<p class='ajax'>Enviando petici&oacute;n...</p>",true);
		};
  		this.onLoaded = function (){
			this.mostrar("<p class='ajax'>Petici&oacute;n realizada...</p>",true);
		};
  		this.onInteractive = function (){
			this.mostrar("<p class='ajax'>Obteniendo datos...</p>",true);
		};
  		this.onCompletion =  function (){
			if(this.execute) this.mostrar("<p class='ajax'>Cargado</p>",true);
			this.execute=false;
		};
  		this.onError = function() { 
			this.execute=false;		
			this.mostrar("<p class='ajax'>Error en conexion...</p>",true);
		};
		this.onFail = function() { 
			this.mostrar("<p class='ajax'>Fallo en conexion...</p>",true);
			this.execute=false;		
		};	
		
	};

	this.reset = function() {
		this.resetFunctions();
		this.resetData();
	};

	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}

		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
	};

	this.setVar = function(name, value){
		this.vars[name] = Array(value, false);
		this.agregarParametroHistorial(name,value);
	};
	this.addVar = function(name, value){
		if(this.vars[name]==undefined) this.vars[name] = new Array();
		this.vars[name].push(Array(value, false));
		this.agregarParametroHistorial(name,value);
	};

	this.encVar = function(name, value, returnvars) {
		if (true == returnvars) {
			return Array(encodeURIComponent(name), encodeURIComponent(value));
		} else {
			this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
		}
	}

	this.processURLString = function(string, encode) {
		encoded = encodeURIComponent(this.argumentSeparator);
		regexp = new RegExp(this.argumentSeparator + "|" + encoded);
		varArray = string.split(regexp);
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split("=");
			if (true == encode){
				this.encVar(urlVars[0], urlVars[1]);
			} else {
				if(urlVars[0].indexOf("[]")!=-1) this.addVar(urlVars[0], urlVars[1]);
				else this.setVar(urlVars[0], urlVars[1]);
			}
		}
	}

	this.createURLString = function(urlstring) {
		if (this.encodeURIString && this.URLString.length) {
			this.processURLString(this.URLString, true);
		}

		if (urlstring) {
			if (this.URLString.length) {
				this.URLString += this.argumentSeparator + urlstring;
			} else {
				this.URLString = urlstring;
			}
		}

		// prevents caching of URLString
		this.setVar("rndval", new Date().getTime());

		urlstringtemp = new Array();
		for (key in this.vars) {
			if(key.indexOf('[]')!=-1){
				var valores =this.vars[key]; 
				for (valor in valores) { 
					if (false == valores[valor][1] && true == this.encodeURIString) {
						encoded = this.encVar(key, valores[valor][0], true);
//						delete valores[key];
						if(this.vars[encoded[0]]==undefined) this.vars[encoded[0]]=Array();
						var actual =Array(encoded[1], true);
						this.vars[encoded[0]].push(actual);
						key2 = encoded[0];
						urlstringtemp[urlstringtemp.length] = key2+ "=" + encoded[1];
					}else{
						urlstringtemp[urlstringtemp.length] = key+ "=" + valores[valor][0];
					}
				}
			}else{
				if (false == this.vars[key][1] && true == this.encodeURIString) {
					encoded = this.encVar(key, this.vars[key][0], true);
					delete this.vars[key];
					this.vars[encoded[0]] = Array(encoded[1], true);
					key = encoded[0];
				}
				urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
			}

		}
		if (urlstring){
			this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
		} else {
			this.URLString += urlstringtemp.join(this.argumentSeparator);
		}
	}

	this.runResponse = function() {
		eval(this.response);
	}

	this.runAJAX = function(urlstring) {
		if (this.failed) {
			this.onFail();
		} else {
			this.agregarFicheroHistorial(this.requestFile);
			this.agregarMetodoHistorial(this.method);
			this.historial.push(this.historialActual);
			this.historialActual= new Array();
			this.peticiones++;
			this.createURLString(urlstring);
			if (this.element) {
				if(this.element=='XXdocumentXX') this.elementObj=document;
				else this.elementObj = document.getElementById(this.element);
				if(this.elementObj==null) { alert('No se encuentra destino: '+this.element);}
			}
			if (this.xmlhttp) {
				var self = this;
				if (this.method == "GET") {
					totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
					try {
						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
					} catch (e) { }
					try {
						this.xmlhttp.setRequestHeader("Set-Cookie", document.cookie);
					} catch (e) { }
				}

				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState) {
						case 1:
							self.onLoading();
							break;
						case 2:
							self.onLoaded();
							break;
						case 3:
							self.onInteractive();
							break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;
							if (self.execute) {
								self.runResponse();
							}else self.mostrar(self.response);
							if (self.responseStatus[0] == "200") {
								self.onCompletion();
							} else {
								self.onError();
							}
							self.URLString = "";
							break;
					}
				};
				this.xmlhttp.send(this.URLString);
			}
		}
	};

	this.reset();
	this.createAJAX();
	/*
		Contiene las últimas peticiones
			Y cada posicion es un array con este formato
				0-> Fichero
				1-> Methodo
				2-> Parametros (Un Array de dos dimensiones com parámetros y valores
	*/
	this.historial = new Array(); 
	/* tiene la misma estructura que historial, pero sólo uno*/ 
	this.historialActual = new Array(); 
	this.peticiones=0;
	/* Funcion de uso interno, que agrega un parámetro al historial actual*/
	this.agregarParametroHistorial=function agregarParametroHistorial(name,value){
		if(this.historialActual[2]==undefined){ // No se ha creado aún los arrays de parametros
			this.historialActual[2]= new Array();
		}
		var tam =this.historialActual[2].length;
		this.historialActual[2][tam]= new Array(name,value);
	}
	/* Funcion de uso interno que agrega el método al historial actual*/
	this.agregarMetodoHistorial=function agregarMetodoHistorial(metodo){
		this.historialActual[1]= metodo;
	}
	/* Función de uso interno que agrega el fichero al historial actual*/
	this.agregarFicheroHistorial=function agregarFicheroHistorial(fichero){
		this.historialActual[0]= fichero;
	}
	/* Función pública que retrocede en el historial una posición*/
	this.atras= function atras(){
		if(this.peticiones<=0) return;
		this.historial.pop(); //Sacamos la actual, puesto que volvemos atras
		this.resetData();
		var pos = this.historial.length;
		var fichero = this.historial[pos-1][0];
		var metodo = this.historial[pos-1][1];
		var parametros = this.historial[pos-1][2];
		this.peticiones--;
		this.requestFile = fichero;
		this.method = metodo;
		this.element = 'replaceme';

		for(i=0;i<parametros.length;i++){
			if(parametros[i][0].indexOf("[]")!=-1) this.addVar(parametros[i][0], parametros[i][1]);
			else this.setVar(parametros[i][0], parametros[i][1]);			
		}
		this.runAJAX();
	}
	/* Función publica que refresca la petición actual */
	this.refrescar= function refrescar(){
		if(this.peticiones<=0) return;
		this.resetData();
		var pos = this.historial.length;
		var fichero = this.historial[pos-1][0];
		var metodo = this.historial[pos-1][1];
		var parametros = this.historial[pos-1][2];
		this.peticiones--;
		this.requestFile = fichero;
		this.method = metodo;
		this.element = 'replaceme';
		for(i=0;i<parametros.length;i++){
			if(parametros[i][0].indexOf("[]")!=-1) this.addVar(parametros[i][0], parametros[i][1]);
			else this.setVar(parametros[i][0], parametros[i][1]);			
		}
		this.runAJAX();
	}
	/* Función publica que borra los parámetros de la peticion actual, por si se reutiliza el objeto y no queremos mandar otros parámetros anteriores*/ 
	this.borrarParametros= function borrarParametros(){
		var pos = this.historial.length;
		if(pos>0) this.historial[pos-1][2] = new Array();
		this.vars = new Object();		
	}
	/*  Función publica que conecta a la página indicada, enviando esos parámetros y que se mostrará en el elemento donde*/
	this.conecta=function conecta(pagina,parametros,donde,javascript){
        if(parametros!=undefined && parametros!=null){
		for(i=0;i<parametros.length;i++){
			var parametro=parametros[i];
			if(parametros[i][0].indexOf("[]")!=-1) this.addVar(parametros[i][0], parametros[i][1]);
			else this.setVar(parametros[i][0], parametros[i][1]);			
          }
        }
		this.requestFile = pagina;
		this.method = 'post';
        if(donde==undefined) this.element = 'cuerpo';
        else{
			if(typeof(donde)=='string') this.element = donde;
			else this.element=donde.id;
		}
		if(javascript==true) this.execute=true;
		this.runAJAX();
   }
   /* Funcion publica que envía un formulario, y lo muestra en el elemento donde */
   this.enviarFormulario = function enviarFormulario(formulario,donde){
	   var hayFicheros=false;
	   if(typeof(formulario)=='string') formulario = document.getElementById(formulario);
        var numero =formulario.elements.length;
          for(i=0;i<numero;i++){
            var elem = formulario.elements[i];
            var nombre = elem.nodeName.toLowerCase();
            if(nombre=='input'){
              var tipo = elem.type;
              if(tipo=='text' || tipo=='password' || tipo=='submit' || tipo=='hidden'){
                if(elem.name!=undefined && elem.name!=''){
					if(elem.name.indexOf("[]")!=-1) this.addVar(elem.name, elem.value);
					else this.setVar(elem.name, elem.value);			
				  
                }
              } else if(tipo=='button' || tipo=='reset'){

              } else if(tipo=='file'){
                hayFicheros=true;
                if(elem.name!=undefined && elem.name!=''){
					if(elem.name.indexOf("[]")!=-1) this.addVar(elem.name, elem.value);
					else this.setVar(elem.name, elem.value);			
                }
              } else if(tipo=='checkbox'){
                if(elem.name!=undefined && elem.name!='' && elem.checked==true){
					if(elem.name.indexOf("[]")!=-1) this.addVar(elem.name, elem.value);
					else this.setVar(elem.name, elem.value);			
                }
              }else{
                mostrarElemento(elem);
                return;
              }
            }else if(nombre=='select'){
                if(elem.name!=undefined && elem.name!=''){
					if(elem.name.indexOf("[]")!=-1) this.addVar(elem.name, elem.value);
					else this.setVar(elem.name, elem.value);			
                }
            }else if(nombre=='textarea'){
                if(elem.name!=undefined && elem.name!=''){
					if(elem.name.indexOf("[]")!=-1) this.addVar(elem.name, elem.value);
					else this.setVar(elem.name, elem.value);			
                }
            }
          }
          if(!hayFicheros){
            this.requestFile = formulario.action;
            this.method = formulario.method;
            if(donde==undefined && this.element==undefined) this.element = 'cuerpo';
            else this.element = donde;
            this.runAJAX();
            return false; //Cancelamos el submit real, puesto que lo hemos sustituido
          }else{
            var iframecuerpo=document.getElementById('iframecuerpo');
            if(donde==undefined){
				if(this.element==undefined) donde = 'cuerpo';
				else donde=this.element;
			}
            iframecuerpo.onload=function (){
               var cuerpo=document.getElementById(donde);
               cuerpo.innerHTML=this.contentDocument.body.innerHTML;
			   
            }
            formulario.target='iframecuerpo';
            formulario.submit();			
          }
   }
}
/* PAra mostrar un objeto javascript*/
   function mostrarElemento(elem,corto){
      var res='';
      for(algo in elem){
        try{
          if(!corto) res+=algo+'='+elem[algo]+' <--> ';
          else res+=algo+' ('+typeof(elem[algo])+')<--> ';
        }catch(e){
          res+='Error ('+algo+')';
        }
      }
      alert(res);
    }
/* Representación de una tabla hash en javascript */
function Hash()
{
	this.length = 0;
	this.items = new Array();
	for (var i = 0; i < arguments.length; i += 2) {
		if (typeof(arguments[i + 1]) != 'undefined') {
			this.items[arguments[i]] = arguments[i + 1];
			this.length++;
		}
	}
   
	this.removeItem = function(in_key)
	{
		var tmp_value;
		if (typeof(this.items[in_key]) != 'undefined') {
			this.length--;
			var tmp_value = this.items[in_key];
			delete this.items[in_key];
		}
	   
		return tmp_value;
	}

	this.getItem = function(in_key) {
		return this.items[in_key];
	}

	this.setItem = function(in_key, in_value)
	{
		if (typeof(in_value) != 'undefined') {
			if (typeof(this.items[in_key]) == 'undefined') {
				this.length++;
			}

			this.items[in_key] = in_value;
		}
	   
		return in_value;
	}

	this.hasItem = function(in_key)
	{
		return typeof(this.items[in_key]) != 'undefined';
	}
}

var ajax = new sack();
document.write('<iframe id="iframecuerpo" name="iframecuerpo" width="0" height="0" frameborder="0"></iframe>');	