	function listbox(name)
		{
		this.name = name;
		this.longitud = 0;
		this.object = null;
		this.load = lst_load;
		this.loadAgrup = lst_loadAgrup;
		this.loadXML = lst_loadXML;
		this.fill = lst_fill;
		this.fillAgr = lst_fillAgr;
		this.setValue = lst_setValue;
		this.setValueStartsWith = lst_setValueStartsWith;
		this.getValue = lst_getValue;
		this.getText = lst_getText;
		this.clear = lst_clear;
		this.clearFrom = lst_clearFrom;
		this.async = false;
		this.xmlDoc = null;
		this.objWait = null;
		this.httpRequest = null;
		this.onreadystatechange = null;
		}
		
	function lst_loadAgrup(xmlPath,tagAgrupElement,nameAgrup,tagElement,nameAttribute,valueAttribute){
	    if (this.objWait!=null){
			this.objWait.style.display = "";
		}
		
		if (typeof XMLHttpRequest != 'undefined') {
		    this.httpRequest = new XMLHttpRequest();
		}
		else
		{
		    this.httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
		 
		if (this.async)
			this.httpRequest.onreadystatechange = new Function(this.name + ".fillAgr('" + tagAgrupElement + "', '" + nameAgrup + "', '" + tagElement + "','" + nameAttribute + "','" + valueAttribute + "')");
		
		 if (this.httpRequest != null) {
		    this.httpRequest.open('GET', xmlPath,false);
		    this.httpRequest.send(null);
		  }
		  
		if (!this.async)
			{
			this.fillAgr(tagAgrupElement,nameAgrup,tagElement,nameAttribute,valueAttribute);
	    }
	}
	
	function lst_fillAgr(tagAgrupElement,nameAgrup,tagElement,nameAttribute,valueAttribute){		    
		if (this.httpRequest.readyState != 4) return;	
		//Vaciamos el objeto. En esta primera versión no se pueden añadir elementos on the fly
		this.object.innerHTML = "";			                		        
		//Cogemos los tags de las agrupaciones
		var rs = this.httpRequest.responseXML.getElementsByTagName(tagAgrupElement);								
		//Recorremos las agrupaciones
        for (var indAgr=0;indAgr<rs.length;indAgr++){
			var nomAgr = rs[indAgr].getAttribute(nameAgrup);			
			if (this.longitud > 0){
			    nomAgr = nomAgr.substring(0, this.longitud);
			}    
			//Creamos la agrupación
			var oGroup = document.createElement('optgroup');
			oGroup.label = nomAgr;									
			//Añadimos las options a la agrupación
			if (rs[indAgr].hasChildNodes){
			    var nodeListOptions = rs[indAgr].selectNodes(tagElement);			    
			    for (indOp=0; indOp<nodeListOptions.length; indOp+=1){
			        var oOption = document.createElement('option');
			        var valor = nodeListOptions[indOp].getAttribute(valueAttribute);
			        var nom = nodeListOptions[indOp].getAttribute(nameAttribute);
			        if (this.longitud > 0){
			            nom = nom.substring(0, this.longitud);
			        }    
                    oOption.value = valor;
                    oOption.innerHTML = nom;
                    oGroup.appendChild(oOption);
			    }
			}						
            this.object.appendChild(oGroup);			
        }
            			    
		if (this.objWait!=null){
			this.objWait.style.display = "none";
		}
		if (this.onreadystatechange!=null){
			eval(this.onreadystatechange);
		}
		
	}
	
	function lst_load(xmlPath,tagElement,nameAttribute,valueAttribute)
	{	    
		if (this.objWait!=null){
			this.objWait.style.display = "";
		}
		
		if (typeof XMLHttpRequest != 'undefined') {
		    this.httpRequest = new XMLHttpRequest();
		}
		else
		{
		    this.httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (this.async)
			this.httpRequest.onreadystatechange = new Function(this.name + ".fill('" + tagElement + "','" + nameAttribute + "','" + valueAttribute + "')");
		
		 if (this.httpRequest != null) {
		    this.httpRequest.open('GET', xmlPath,false);
		    this.httpRequest.send(null);
		  }
		  
		if (!this.async)
			{
			this.fill(tagElement,nameAttribute,valueAttribute);
			}
	}
		
	// FCG 25/06/2009 - Añado parámetro opcional para el valor del atributo id
	function lst_load(xmlPath,tagElement,nameAttribute,valueAttribute,idAttribute)
	{	    
		if (this.objWait!=null){
			this.objWait.style.display = "";
		}
		
		if (typeof XMLHttpRequest != 'undefined') {
		    this.httpRequest = new XMLHttpRequest();
		}
		else
		{
		    this.httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (this.async)
			this.httpRequest.onreadystatechange = new Function(this.name + ".fill('" + tagElement + "','" + nameAttribute + "','" + valueAttribute + "','" + idAttribute + "')");
		
		 if (this.httpRequest != null) {
		    this.httpRequest.open('GET', xmlPath,false);
		    this.httpRequest.send(null);
		  }
		  
		if (!this.async)
			{
			this.fill(tagElement,nameAttribute,valueAttribute,idAttribute);
			}
	}
	
	function lst_loadXML(xml,tagElement,nameAttribute,valueAttribute)
		{
		
		// NO ESTÀ ESTANDARITZAT PERQUE NO ÉS TAN FACIL!!!!!!!!
		
		/*this.xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		this.xmlDoc.async = false;
		if (!this.xmlDoc.loadXML(xml)) return;
		this.fill(tagElement,nameAttribute,valueAttribute);*/
		
		}

	function lst_fill(tagElement,nameAttribute,valueAttribute)
		{
		if (this.httpRequest.readyState != 4) return;
        
        //alert(this.httpRequest.responseXML.xml);
        
		var rs = this.httpRequest.responseXML.getElementsByTagName(tagElement);
		var from = this.object.options.length;

		for (i=from;i<rs.length+from;i++)
			{
			nom = rs[i-from].getAttribute(nameAttribute);
			if (this.longitud > 0)
			    nom = nom.substring(0, this.longitud);
			valor = rs[i-from].getAttribute(valueAttribute);
			if ((nom != null) && (valor != null))
				{
				this.object.options[i]  = new Option(nom, valor, false, false);
				}
			}
			if (this.objWait!=null){
				this.objWait.style.display = "none";
			}
			if (this.onreadystatechange!=null){
				eval(this.onreadystatechange);
			}
		
		}
		
    // FCG 25/06/2009 - Añado parámetro opcional para el valor del atributo id
	function lst_fill(tagElement,nameAttribute,valueAttribute,idAttribute)
		{
		if (this.httpRequest.readyState != 4) return;
        
        //alert(this.httpRequest.responseXML.xml);
        
		var rs = this.httpRequest.responseXML.getElementsByTagName(tagElement);
		var from = this.object.options.length;

		for (i=from;i<rs.length+from;i++)
			{
			nom = rs[i-from].getAttribute(nameAttribute);
			if (this.longitud > 0)
			    nom = nom.substring(0, this.longitud);
			valor = rs[i-from].getAttribute(valueAttribute);
			if (idAttribute != null)
			    id = rs[i-from].getAttribute(idAttribute);
			if ((nom != null) && (valor != null))
				{
				this.object.options[i]  = new Option(nom, valor, false, false);
                if (idAttribute != null)
				    this.object.options[i].id = id;
				}
			}
			if (this.objWait!=null){
				this.objWait.style.display = "none";
			}
			if (this.onreadystatechange!=null){
				eval(this.onreadystatechange);
			}
		
		}
		
	function lst_setValue(value)
		{
		for (i=0;i<this.object.options.length;i++)
			if (this.object.options[i].value==value)
				{
				    try{
				        this.object.options[i].selected = true;
				    }catch(e){}	
				return;
				}
		return;
		}
	// GFA 15/07/2010 - Los destinos de Tren + Hotel son xxxxxxxx#xxxxxxxxxx#xxxxxxxxx y no siempre tenemos la cadena entera
	function lst_setValueStartsWith(value)
		{
		for (i=0;i<this.object.options.length;i++)
			if (this.object.options[i].value.indexOf(value) == 0)
				{
				    try{
				        this.object.options[i].selected = true;
				    }catch(e){}	
				return;
				}
		return;
		}
	function lst_getValue()
		{
		return this.object.options[this.object.options.selectedIndex].value;
		}
	function lst_getText()
		{
		return this.object.options[this.object.options.selectedIndex].text;
		}
	function lst_clear()	
		{		
		return this.object.options.length=0;
		}
	function lst_clearFrom(num)	
		{
		return this.object.options.length=num;
		}

