function xmlTreeCombo(formElId) {
    var thisRef = this;
    this.id = formElId;
    this.contenedorID = "";
    this.xmlURL = "";
    this.xmlNichoURL = "";     
    this.hayAgrupaciones = 0;       
    this.ancho = 300;
    this.anchoImagen = 17;
    this.altoImagen = 16;
    this.altoDesplegable = 150;
    this.textoDefecto = "&nbsp;";
    this.PathIcoDropDown = "";
    this.PathIcoMas = "";
    this.PathIcoMenos = "";
    this.cssClass = "";
    this.flagOcultaTags = 1;    
    this._xmlhttp = null;
    this._xmlNichohttp = null;
    this._contenedor = null;
    this.setValue = _setValue;
    
    this.render = function(isCallBack)
     {
        
      if (!isCallBack)
       {
            this._contenedor = document.getElementById(this.contenedorID);
            if (this._contenedor == null || this._contenedor.innerHTML == null) {
                alert("xmlTreeCombo: Debe haber un objeto contenedor y debe tener la propiedad innerHTML");
                return;
            }
            if (this.xmlURL == "") {
                alert("xmlTreeCombo: Debe existir una URL para obtener el XML de datos");
                return;    
            }                       
            if (document.all && !window.opera) {
                
		        var xmlClsID = new Array("Msxml2.XMLHTTP.6.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP");
                for(var i=0;i < xmlClsID.length;i++)
                {
                    try {
                        this._xmlhttp = new ActiveXObject(xmlClsID[i]);                            
                        this._xmlNichohttp = new ActiveXObject(xmlClsID[i]);                            
                    } catch(E) {  }    
                }
            } else {
                try {
                    this._xmlhttp = new XMLHttpRequest();
                    this._xmlNichohttp = new XMLHttpRequest();
                } catch(E) {  }
            }
            if (this._xmlhttp == null) {
                alert("xmlTreeCombo: El navegador no posee los parsers XML activados");
            }            
            this._xmlhttp.open("GET",this.xmlURL);
            this._xmlNichohttp.open("GET",this.xmlNichoURL);
            
            
            
            this._xmlhttp.onreadystatechange = function() {
                if ((thisRef._xmlhttp.readyState == 4) && (thisRef._xmlNichohttp.readyState == 4)) {
                    thisRef.render(true);                    
                }
            };
           this._xmlNichohttp.onreadystatechange = function() {
                if ((thisRef._xmlhttp.readyState == 4) && (thisRef._xmlNichohttp.readyState == 4)) {
                    thisRef.render(true);                    
                }
            };            
            
            try
            {            
            this._xmlhttp.send(null);                        
            this._xmlNichohttp.send(null);                        
            }
            catch(e) {    }
       } 
       else
       {            
            var o = document.getElementById("selDestino"); 
            if (o.value=="")
            return;
            desactivarSoloHotel();    
            var codD = o.value.split("#")[0];
            var codA = o.value.split("#")[1];
            var ret = "";
            var tmp = "var o = document.getElementById('" + this.id + "_DVLIST'); if(o.style.display == 'block') {o.style.display = 'none'; showWindowedObjects(true,"+this.flagOcultaTags+"); } else {desactivarSoloHotel();showWindowedObjects(false,"+this.flagOcultaTags+"); o.style.display = 'block'; o.scrollTop = o.getAttribute('sposition'); }";
            ret += "<input type=\"hidden\" name=\"" + this.id + "\" id=\"" + this.id + "\" value=\"\">";
	        ret += "<input type=\"hidden\" name=\"" + this.id + "_descripcion\" id=\"" + this.id + "_descripcion\" value=\"\">";
            ret += "<table id=\"" + this.id + "_MTBL\" class=\"" + this.cssClass + "\" style=\"background-color: #FFFFFF; border: 1px solid #a0a0a0;\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\"><tr>";
            ret += "<td onclick=\"" + tmp + "\" style=\"width:" + this.ancho + "px;\">";
            ret += "<div style=\"width:100%;\" id=\"" + this.id + "_MTD\">" + this.textoDefecto + "</div>";
            ret += "</td>";            
            ret += "<td><img id=\"" + this.id + "_IMGCBO\" onclick=\"" + tmp + "\" width=\"" + this.anchoImagen + "\" height=\"" + this.altoImagen + "\" style=\"cursor: pointer;\" border=\"0\" src=\"" + this.PathIcoDropDown + "\"></td>";
            ret += "</tr></table>";
            ret += "<div sposition=\"0\" id=\"" + this.id + "_DVLIST\"  style=\"padding: 2px; display: block; position: absolute; z-index: 9001; height: " + this.altoDesplegable + "px; width:" + (this.ancho + this.anchoImagen + 5) + "px; background-color: #FFFFFF; border: 1px solid #a0a0a0; border-top: 0px; overflow: auto;\">";
            var niv = -1;
            var t_niv = 0;
            var cod = 0;
            var descripcion = "";
	        var descripcionlarga = "";
            var t_onclick = "";
            var t_mousehandle = "";
            var t_pointer = "";           
           
                         
           /* t_onclick = "document.getElementById('" + this.id + "').value = '"+codA+"';";
	        t_onclick += "document.getElementById('" + this.id + "_descripcion').value = 'Solo Hotel';";
    		t_onclick += "document.getElementById('" + this.id + "_DVLIST').setAttribute('sposition',document.getElementById('" + this.id + "_DVLIST').scrollTop);";
    		t_onclick += "document.getElementById('" + this.id + "_MTD').innerHTML = 'Solo Hotel';";
    		t_onclick += "document.getElementById('" + this.id + "_IMGCBO').onclick();";
    		t_onclick += "activarTdSolohotel();";     		
    		t_onclick += "loadZonas("+codA+");";     		    		
    		t_mousehandle = "onmouseover=\"this.style.background = '#B2B4BF';\" onmouseout=\"this.style.background = '#FFFFFF';\" onclick=\"" + t_onclick + "\"";                
            ret += "<div " + t_mousehandle + " style=\"padding-left: " + ((1 - 1) * 10).toString() + "px; cursor: pointer;\"><input type='hidden' id='"+this.id+"_dl_hotel' value='"+codA+"'><input type='hidden' id='"+this.id+"_d_"+cod+"' value='" + descripcion.replace("'"," ")  + "'><a href=\"javascript:\"><span style=\"font-family:Arial;font-size:12px;font-weight:bold;color:#003366;\" >&nbsp;Solo Hotel</span></a></div>";*/
            if (this._xmlhttp.responseXML == null)
            {
                   this._contenedor.innerHTML =  ret;                   
                   return;
            }
            if (this._xmlhttp.responseXML.documentElement == null)
            {
                this._contenedor.innerHTML =  ret;
                return;
            }
            else
            {
            var prods = this._xmlhttp.responseXML.documentElement.getElementsByTagName("pro");            
            hayAgrupaciones = 1;
            if (this._xmlNichohttp.responseXML == null)
            {
                    
                   hayAgrupaciones = 0;  
            }
            if ((this._xmlNichohttp.responseXML.documentElement == null) && (hayAgrupaciones==1))
            {                
                hayAgrupaciones = 0;
            }
            var agrups  = null;
            if (hayAgrupaciones==1)
            {
                 agrups = this._xmlNichohttp.responseXML.documentElement.getElementsByTagName("eq");
            }        
            var cerrarDiv=0;                
            var nombreGrupo = "";
            var pintadoHF = 0;                    
            for(var i=0;i < prods.length;i++) {
                if (prods[i].hasChildNodes())                
                {
                    /*if (pintadoHF==0)
                    {
                        pintadoHF=1;
                        t_onclick = "";	                    
    		            t_mousehandle = "onmouseover=\"this.style.background = '#B2B4BF';\" onmouseout=\"this.style.background = '#FFFFFF';\" onclick=\"" + t_onclick + "\"";                
                        ret += "<div " + t_mousehandle + " style=\"padding-left: " + ((1 - 1) * 10).toString() + "px; cursor: pointer;\"><input type='hidden' id='"+this.id+"_dl_hotel' value='"+codA+"'><input type='hidden' id='"+this.id+"_d_"+cod+"' value='" + descripcion.replace("'"," ")  + "'><a href=\"javascript:\"><span style=\"font-family:Arial;font-size:12px;font-weight:bold;color:#003366;\" >&nbsp;Hotel+Forfait</span></a></div>";
                    }*/
                    cod = prods[i].getAttribute("cod").replace("'","´");
                    descripcion = prods[i].getAttribute("nom").replace("'","´");                    
                    var nombreNuevoGrupo = "";
                    var cambianombre = false;
                    if (hayAgrupaciones==1)
                    {
                        nombreNuevoGrupo= funNombreGrupo(agrups,descripcion);                        
                        cambianombre=(nombreGrupo!=nombreNuevoGrupo)
                        nombreGrupo = nombreNuevoGrupo                        
                    }
                    if ((cerrarDiv==1) && (cambianombre))
	            	{
	            	    ret += "</div>"
	                }
                    if (cambianombre)
                    {
                        cerrarDiv=1;
                        t_onclick = "if(this.getAttribute('expstate') == 'N') { ";
    		            t_onclick += "this.setAttribute('expstate','E');";
    		            t_onclick += "this.getElementsByTagName('img')[0].src = '" + this.PathIcoMenos + "';";
    		            t_onclick += "document.getElementById('DIVCBO_" + i + "').style.display = 'block';";
    		            t_onclick += "} else {";
    		            t_onclick += "this.setAttribute('expstate','N');";
    		            t_onclick += "this.getElementsByTagName('img')[0].src = '" + this.PathIcoMas + "';";
    		            t_onclick += "document.getElementById('DIVCBO_" + i + "').style.display = 'none';";
    		            t_onclick += "}";
        	            ret += "<div expstate=\"N\" onclick=\"" + t_onclick + "\" style=\"cursor: pointer; padding-left: " + ((2 - 1) * 10).toString() + "px;\"><img src=\"" + this.PathIcoMas + "\"><span style=\"font-family:Arial;font-size:11px;color:#003366;\" >" + nombreGrupo + "</span></div>";
    		            ret += "<div id=\"DIVCBO_" + i + "\" style=\"display: none;\">";
                    }
                    
            		t_onclick = "document.getElementById('" + this.id + "').value = 'P" + cod + "';";//P´+ Código Producto para distinguir de Sólo Hotel
			        t_onclick += "document.getElementById('" + this.id + "_descripcion').value = '" + descripcion + "';";
            		t_onclick += "document.getElementById('" + this.id + "_DVLIST').setAttribute('sposition',document.getElementById('" + this.id + "_DVLIST').scrollTop);";
            		t_onclick += "document.getElementById('" + this.id + "_MTD').innerHTML = '" + descripcion.replace("'"," ") + "';";
            		t_onclick += "document.getElementById('" + this.id + "_IMGCBO').onclick();";
            		t_onclick += "var formAgPaquete= document.getElementById('formBuscadorAgPaquete');";
            		t_onclick += "formAgPaquete.producto.value="+cod+";";
            		t_onclick += "formAgPaquete.submit();";            		
            		t_mousehandle = "onmouseover=\"this.style.background = '#B2B4BF';\" onmouseout=\"this.style.background = '#FFFFFF';\" onclick=\"" + t_onclick + "\"";
	            	ret += "<div " + t_mousehandle + " style=\"padding-left: " + ((3 - 1) * 10).toString() + "px; cursor: pointer;\"><input type='hidden' id='"+this.id+"_dl_"+cod+"' value='" + descripcionlarga.replace("'"," ")  + "'><input type='hidden' id='"+this.id+"_d_"+cod+"' value='" + descripcion.replace("'"," ")  + "'><span style=\"font-family:Arial;font-size:11px;color:#003366;\" >&raquo;&nbsp;" + descripcion + "</span></div>";	            		            	            	
	            	
	            	
           		}
            }
            if (prods.length > 0) ret += "</div>";
            
            //ret += "</div>";
            this._contenedor.innerHTML =  ret;            
            }
            
            }
    };  
}

function funNombreGrupo(nodes,descripcion)
{
    for(var i=0;i < nodes.length;i++)
    {
        texte = nodes[i].getAttribute("text");
        if (descripcion.indexOf(texte)==0)
        {
            return nodes[i].getAttribute("cat");
        }
    }
    return "";
}


function showWindowedObjects(show,flagOcultaTags) {
    if (flagOcultaTags == 1)
    {
	    if (document.all && !window.opera) {
		    var windowedObjectTags = new Array("SELECT", "OBJECT","APPLET","EMBED","IFRAME");
		    var windowedObjects = new Array();
		    var j=0;
		    for (var i = 0; i < windowedObjectTags.length; i++) {
			    var tmpTags = document.all.tags(windowedObjectTags[i]);
			    if (tmpTags.length > 0) {
				    for (var k=0; k < tmpTags.length; k++) {
					    windowedObjects[j++] = tmpTags[k];
				    }
			    }
		    }
		    for (var i = 0; i < windowedObjects.length; i++) {
			    windowedObjects[i].visBackup = "";
			    if (!show)
				    windowedObjects[i].visBackup = (windowedObjects[i].style.visibility == null) ? "visible" : windowedObjects[i].style.visibility;
				    windowedObjects[i].style.visibility = (show) ? windowedObjects[i].visBackup : "hidden";
		    }
	    }
	}
}

function _setValue(val)
{
	var coda = eval("document.getElementById('" + this.id + "')");
	var desVal = eval("document.getElementById('"+this.id+"_dl_"+val+"')");
	var descripcionlarga = eval("document.getElementById('" + this.id + "_descripcion')");
	var desCorta =  eval("document.getElementById('"+this.id+"_d_"+val+"')");
	var descripcionCorta = eval("document.getElementById('" + this.id + "_MTD') ");
	coda.value = val;
	descripcionlarga.value = desVal.value;
	descripcionCorta.innerHTML = desCorta.value;
}

