		var loadingid = 0;
		var IdBuscador = 0;
		var ElementosPrincipal = new Array();
		var ElementosBusqueda = new Array();
		var ArrayCodisABuscar = new Array();
		
		function rellenarEstadistica(nom, Extra)
		{
			var fie = document.getElementById("jsfie").value;
			var idioma = document.getElementById("jsidioma").value;
			var stridioma;
			var strNom;
			var strExtra;
			if(idioma == 1) stridioma = "cat"
			else stridioma = "cas"
			
			if(Extra != "") strExtra = fie + "|" + Extra;
			else strExtra = fie;
			
			if(document.getElementById("jsIdTipusEnt").value == 2)
				strNom = "BancsDeEntitats-" + nom;
			else
				strNom = "BancsDeEmpreses-" + nom;
			estadistiques(strNom,stridioma,strExtra,document.location.href);
			
			//si la crida ve per una descarrega de banc
			if (nom == "DescarregaBanc")
			{nom = "Descargas banco precios FIE IdEmp=";
			GAnalytics(nom + Extra);_gaq.push(['_trackEvent', 'Descargas banco precios FIE', Extra]);}//alert(nom + Extra);Treure
			
			else if ((nom == "MostraElement") || (nom == "Cercador") || (nom == "ClickArbol"))
			{	
			Extra = document.getElementById("jsIdEnt").value;
			strNom = strNom + " IdEmp=" + Extra;
			estadistiquesGoogle(strNom);}//alert(strNom);Treure
			
			else
			{
			strNom = strNom + " IdEmp=" + Extra;
			estadistiquesGoogle(strNom);}//alert(strNom);Treure
			
		}
						
		function centerTopW(w_alt){
			// Calcula la posició de la finestra centrada a la pantalla pel Top
			var winH;
			winH = window.screen.height;
			winH = (winH - w_alt)/2;
			return(winH);
		}
		function centerLeftW(w_ample){
			// calcula la posició de la finestra centrada a la pantalla per l'esquerra
			var winW;
			winW = window.screen.width;
			winW = (winW - w_ample)/2;
			return(winW);
		}
		function MostrarElement(codi, Banc, IdFie, Cual, Idioma)
		{
			var Ori = document.getElementById("jsOri").value;
			var str = "Concepto.aspx?codi=" + encodeURIComponent(codi) + "&banc=" + Banc + "&IdFie=" + IdFie + "&idioma=" + Idioma + "&cual=" + Cual + "&Ori=" + Ori;
			var top = centerTopW(580)-15;
			var left = centerLeftW(950);
			var strExtra = codi + '|' + Cual;
			rellenarEstadistica('MostraElement',strExtra);
			strComObrir = "width=950,height=580,top=" + top + ",left=" + left + ",scrollbars=no,location=no,resizable=no,titlebar=no,toolbar=no,status=no" //status=no
			window.open(str,"",strComObrir,"");
		}
		function MostrarFormularioConsulta(t, idioma)
		{   
			if(idioma == "cat")
				var str = "/noumetabase2.c/NoTrobat.aspx?T=" + t;
			else
				var str = "/noumetabase2.e/NoTrobat.aspx?T=" + t;
			var top = centerTopW(250) -15;
			var left = centerLeftW(500);
			strComObrir = "width=500,height=250,top=" + top + ",left=" + left + ",scrollbars=no,location=no,resizable=no,titlebar=no,toolbar=no,status=no" //status=no
			window.open(str,"",strComObrir,"");
		}
		function cargarPanel(id)
		{
			return;
		}
		function TancarFlotant()
		{
			document.getElementById("cortina4").style["visibility"] = "hidden";
			document.getElementById("cortina2").style["visibility"] = "hidden";
			document.getElementById("plec").style["visibility"] = "hidden";
			document.getElementById("plec2").style["visibility"] = "hidden";
			document.getElementById("interior").innerHTML = "";
			ElementosBusqueda = "";
			document.getElementById("Aproposit").innerHTML = "";
			document.getElementById("Aproposit").style["display"] = "block";
			loadingid = 0;
			IdBuscador = 0;			
		}
		function MostrarInfoBanco(IdEnt, IdFie, Idioma, Ambit)
		{
			document.getElementById("plec2").style["top"] = document.getElementById("supracontent").offsetTop + 50;
			document.getElementById("plec2").style["marginTop"] = 0;
			rellenarEstadistica('MostrarInfoBanc',IdEnt);
			metaEntitats.Arbre.InfoBanc(IdEnt, IdFie, Idioma, Ambit, MostrarInfoBanco_callback);
		}
		function MostrarInfoBanco_callback(res)
		{
			var info = res.value;
			document.getElementById("interiorTitol2").innerHTML = info.Titulo;
			document.getElementById("interior2").innerHTML = info.TextoContenido;
			document.getElementById("cortina4").style["visibility"] = "visible";
			document.getElementById("plec2").style["visibility"] = "visible";
		}
		function MostrarCarregant(toogle)
		{
			if(toogle == 0)
			{
				Reposicionar();
				
				if(loadingid == 0)
				{
					document.getElementById("cortina").style['visibility'] = "visible";
					document.getElementById("loading").style['visibility'] = "visible";
				}else{
					document.getElementById("cortina_bis").style['visibility'] = "visible";
					document.getElementById("loading2").style['visibility'] = "visible";
				}
			}
			else
			{
				if(loadingid == 0)
				{
					document.getElementById("cortina").style['visibility'] = "hidden";
					document.getElementById("loading").style['visibility'] = "hidden";
				}else{
					document.getElementById("cortina_bis").style['visibility'] = "hidden";
					document.getElementById("loading2").style['visibility'] = "hidden";
				}
			}
		}
		function Reposicionar()
		{
			var WinW;
			var WinH;
			if (window.document.body && typeof(window.document.body.clientWidth) == 'number')
			{
				// Gecko 1.0 (Netscape 7) and Internet Explorer 5+
				WinW = window.document.body.clientWidth;  
				WinH = window.document.body.clientHeight;
			}
			else if (typeof(window.innerWidth) == 'number')
			{
				// Navigator 4.x, Netscape 6.x, CompuServe 7 and Opera
				WinW = window.innerWidth;
				WinH = window.innerHeight;
			}		
			
			if((WinW - 110) > 100)
			{
				document.getElementById("loading").style["left"] = (WinW - 110);
			}
		}
		function Init()
		{
			Reposicionar();
			window.onresize = register;
			var ident = document.getElementById("jsIdEnt").value;
			rellenarEstadistica('ConsultaBanc',ident);
		}
		function register(e)
		{
			if (!e) e = window.event;
			Reposicionar();
			return true;
		}
		function Buscar()
		{
			var paraula;
			if(IdBuscador == 1)
			{
				var noubuscador = document.getElementById("txtbuscar2");
				if(noubuscador)
				{
					if(document.getElementById("txtbuscar2").value != "")
					{
						paraula = document.getElementById("txtbuscar2").value;
						document.getElementById("txtbuscar").value = paraula;
					}
					else
					{
						paraula = document.getElementById("txtbuscar").value;
					}
				}
				else
				{
					paraula = document.getElementById("txtbuscar").value;
				}
				IdBuscador = 0;
			}
			else
			{
				paraula = document.getElementById("txtbuscar").value;
			}
			if(paraula == "") return;
			var fie = document.getElementById("jsfie").value;
			var relacio = document.getElementById("jsrelacio").value;
			var idioma = document.getElementById("jsidioma").value;
			var ambito = document.getElementById("jsambit").value;
			var ident = document.getElementById("jsIdEnt").value;
			MostrarCarregant(0);
			document.getElementById("Aproposit").style["display"] = "none";
			rellenarEstadistica('Cercador',paraula);
			metaEntitats.Arbre.BuscarTexto(paraula, relacio, fie, ident, idioma,ambito, MostrarResultado_callback);
		}
		function MostrarResultado_callback(res)
		{
			MostrarCarregant(1);
			loadingid = 1;
		    //if (res.error != null) { 
				// Display error message 
			//	alert(res.error.Message); 
			//} else { 
				// No error occured on server 
				var arr = new Array();  // Create a new array object 
				var tipo;
				arr = eval(res.value);  // Take our server response (an arry as a string) and use eval on it 
				var tipo = arr[0];
				if(tipo == 0)
				{
					var aproposito = arr[2];
					if(aproposito != "")
					{
						document.getElementById("Aproposit").innerHTML = arr[3];
						document.getElementById("proposito").innerHTML = aproposito;
					}else
						document.getElementById("Aproposit").innerHTML = "";	
				}
				else
				{
					document.getElementById("Aproposit").innerHTML = "";
					IdBuscador = 1;
				}
				document.getElementById("interior").innerHTML = arr[1];
				if(ob_cuantosHijo(document.getElementById("interior")) < 2)
				{
					//MostrarCarregant(0);
					setTimeout('LlamarHijos(document.getElementById("interior"))',100);
				}
			//}
			document.getElementById("cortina2").style["visibility"] = "visible";
			document.getElementById("plec").style["visibility"] = "visible";
			document.getElementById("Aproposit").style["display"] = "block";
			//MostrarCarregant(0);
		}
		function MoreElementsBanc(tipo, id, id_pare, pagina, IdBanc, IdEnt, IdFie, Ambit, Idioma, idcons, numeles, numelestotal)
		{
			var IdTipusEntitat = document.getElementById("jsIdTipusEnt").value;
			MostrarCarregant(0);
			rellenarEstadistica('ObtenirMesElements',IdEnt);
			ObtenerMasElementos(tipo,id, id_pare, pagina, IdBanc, IdEnt, IdFie, Ambit, Idioma,idcons,numeles,numelestotal,IdTipusEntitat);
		}
		function MoreElements(tipo, id, id_pare, pagina, IdEnt, IdFie, Ambit, Idioma, idcons, numeles, numelestotal)
		{
			MostrarCarregant(0);
			rellenarEstadistica('ObtenirElementsBanc',IdEnt);
			ObtenerElementosBanco(tipo,id, id_pare, pagina, IdEnt, IdFie, Ambit, Idioma,idcons,numeles,numelestotal);
		}
		function MuestraAproposit()
		{
			document.getElementById("cortina3").style["visibility"] = "visible";
			document.getElementById("proposito").style["visibility"] = "visible";
			document.getElementById("formulari").style["visibility"] = "visible";
		}
		function TancarAproposito()
		{
			document.getElementById("cortina3").style["visibility"] = "hidden";
			document.getElementById("proposito").style["visibility"] = "hidden";
			document.getElementById("formulari").style["visibility"] = "hidden";
		}
		function Descarga()
		{
			document.getElementById("plec2").style["top"] = document.getElementById("supracontent").offsetTop + 50;
			document.getElementById("plec2").style["marginTop"] = 0;
			var IdFie = document.getElementById("jsfie").value;
			var Idioma = document.getElementById("jsidioma").value;
			var IdEnt = document.getElementById("jsIdEnt").value;
			MostrarCarregant(0);
			//rellenarEstadistica('DescarregaBanc','');			
			rellenarEstadistica('DescarregaBanc',IdEnt);
			metaEntitats.Arbre.DescargarBanco(IdEnt, IdFie, Idioma, DescargarBanco_callback);
			
			//alert(document.getElementById("jsIdTipusEnt").value);
			//var wHeight = 565;
			//var wWidth = 800;
			//var Idioma_js = document.getElementById("jsidioma").value;
			//var IdBanc = document.getElementById("jsIdBanc").value;
			//var IdEmpresa = document.getElementById("jsnomentitat").value;
			//var idid = document.getElementById("jsidioma").value - 1;
			//var V = 'N';
			//if(Idioma_js == 1)
			//	var str = "/noudownloads.c/detall.asp?idbanc=" + IdBanc + "&zona=0"; //float.asp?IdBanc=" + IdBanc + "&IdEmpresa=" + escape(IdEmpresa) + "&Idioma=" + idid + "&TipusBancs=1&Visual=" + V;
			//else
			//	var str = "/noudownloads.e/detall.asp?idbanc=" + IdBanc + "&zona=0";
				//var str = "/noudownloads.c/float.asp?IdBanc=" + IdBanc + "&IdEmpresa=" + escape(IdEmpresa) + "&Idioma=" + idid + "&TipusBancs=1&Visual=" + V;
			//var str = "http://localhost/downloads/float.asp?IdBanc=" + IdBanc + "&IdEmpresa=" + escape(IdEmpresa) + "&Idioma=" + idid + "&TipusBancs=1&Visual=" + V;
			//var str2 = "scrollbars=no, height=" + wHeight + ", width=" + wWidth + ", top=" + centerTopW(wHeight) + ", left=" + centerLeftW(wWidth) + ", location=no, menubar=no, resizable=no,titlebar=no, toolbar=no, maximizable=no";
			//alert(str);
			//window.open(str, "", str2)
		}
		function  DescargarBanco_callback(res)
		{
			MostrarCarregant(1);
			loadingid = 1;
			var info = res.value;
			if(info.Tipo == 0) {
				if (info.TextoContenido.substr(0,3) == "www") {
					var strf = "http://" + info.TextoContenido;
				} else {
					var strf = "/downloads/" + info.TextoContenido;
				}
				var str2 = "scrollbars=no, height=1, width=1, top=10000, left=0, location=no, menubar=no, resizable=no,titlebar=no, toolbar=no, maximizable=no";
				//var idObj = window.open(strf, "",str2);
				var ster = "<a href='" + strf + "' id='pepe'></a>";
				
				document.getElementById("midesc").innerHTML = ster;
				
				
				document.location.href = document.getElementById("pepe");
			} else {
				document.getElementById("interiorTitol2").innerHTML = info.Titulo;
				document.getElementById("interior2").innerHTML = info.TextoContenido;
				document.getElementById("cortina4").style["visibility"] = "visible";
				document.getElementById("plec2").style["visibility"] = "visible";
			}
		}
		
		function CambiarAmbito()
		{
			var fie = document.getElementById("jsfie").value;
			var idioma = document.getElementById("jsidioma").value;
			var ambito = document.getElementById("AmbitPreus").value;
			var ambitocook = Galeta.LeerValor(Galeta.LeerCookie(Galeta.DefinirNombre(fie)),"AmbitPreu");
			var IdEntitat = Galeta.LeerValor(Galeta.LeerCookie(Galeta.DefinirNombre(fie)),"IdEntitat");
			if(ambito != ambitocook)
			{
				rellenarEstadistica('CanviAmbit',IdEntitat);
				MostrarCarregant(0);				
				var Arboles = document.getElementsFromElementByTagAndClassName(document, 'div','ob_tree');
				for(k=0;k<Arboles.length;k++)
				{
					var ElemArbol = document.getElementsFromElementByTagAndClassName(Arboles[k], 'span','PrecioId');
					if(Arboles[k].id == "ArbolPrincipal")
					{
						ElementosPrincipal = ElemArbol;
					}
					else
					{
						ElementosBusqueda = ElemArbol;
					}
				}
				if(isArray(ElementosPrincipal))
				{
					for(j=0;j<ElementosPrincipal.length;j++)
					{
						LlenarArrayCodisABuscar(ElementosPrincipal[j].id.substring(14));
						ElementosPrincipal[j].className = "PrecioId active";
					}
				}
				if(isArray(ElementosBusqueda))
				{
					for(j=0;j<ElementosBusqueda.length;j++)
					{
						LlenarArrayCodisABuscar(ElementosBusqueda[j].id.substring(13));
						ElementosBusqueda[j].className = "PrecioId active";
					}
				}
				if(isArray(ArrayCodisABuscar))
				{
					var strCodis = ArrayCodisABuscar.join('|');
				//alert(ArrayCodisABuscar.length);
					metaEntitats.Arbre.CambiarAmbito(fie, ambito, IdEntitat, strCodis, ArrayCodisABuscar.length, CambiarAmbito_callback);
				}
			}
			else
				TancarFlotant();
		}
		
		function isArray(obj) {
			if (obj.constructor.toString().indexOf("Array") == -1)
      			return false;
   			else
				return true;
		}		
		
		function LlenarArrayCodisABuscar(codigo)
		{
			var trobat = false;
			for(l=0;l<ArrayCodisABuscar.length;l++)
			{
				if(ArrayCodisABuscar[l] == codigo)
				{
					trobat = true;
					break;
				}
			}
			if(!trobat)
			{
				ArrayCodisABuscar.splice(ArrayCodisABuscar.length,0, codigo);
			}
		}

		function VaciarArrayCodisABuscar()
		{
			ArrayCodisABuscar.splice(0,ArrayCodisABuscar.length);
		}
		
		function CambiarAmbito_callback(res)
		{
			VaciarArrayCodisABuscar();
			if(res.value != "")
			{
				var arr = new Array();  // Create a new array object 
				arr = eval(res.value);  // Take our server response (an arry as a string) and use eval on it 
				for(i=0;i<arr.length;i++)
				{
					var arr_2 = new Array();
					arr_2 = eval(arr[i]);
					for(j=0;j<ElementosPrincipal.length;j++)
					{
						if(arr_2[0] == ElementosPrincipal[j].id.substring(14))
						{
							ElementosPrincipal[j].innerHTML = arr_2[1];
							ElementosPrincipal[j].className = "PrecioId";
							break;
						}
					}
					
					for(j=0;j<ElementosBusqueda.length;j++)
					{
						if(arr_2[0] == ElementosBusqueda[j].id.substring(13))
						{
							ElementosBusqueda[j].innerHTML = arr_2[1];
							ElementosBusqueda[j].className = "PrecioId";
							break;
						}
					}
				}
			}
			MostrarCarregant(1);
			document.getElementById("SubmitBuscar").focus();
		}
		
		document.getElementsFromElementByTagAndClassName = function (elemento, NameOfTag, NameOfClass) {
			d = elemento.getElementsByTagName(NameOfTag);
			j=0;
			var cl = new Array()
			for(i=0;i<d.length;i++){
				if(d[i].className == NameOfClass){
					cl[j] = d[i];
					j++
				}
			}
			return cl;
		}
		
