/*
	Data de creacio: 27/02/2008
	Autors: IT Deusto (M. Molist)
	
	Data d'última modificacio: 01/09/2008
	Autors: IT Deusto (M. Molist)
	
	CSS: Definició d'estils Carrerer
*/



var zonaInfo = new zonaInformacio();

var sTotsLayersVis;

var tipusPOIdestacat;

function zonaInformacio() {
	
	var _llista1Actiu;
	var _llista2Actiu;
	var _llista3Actiu;
	var _llista4Actiu;
	var _llista5Actiu;
	var _llista6Actiu;
	var _llista7Actiu;
	var _llista8Actiu;
	var _llista9Actiu;
	var _llista10Actiu;
	var _llista11Actiu;
	var _llista12Actiu;
	var _llista13Actiu;
	var _llista14Actiu;
	var _llista15Actiu;
	var _llista16Actiu;
	var _llista17Actiu;
	var _llista18Actiu;


	var _maxZoomVis = 3;
	var _maxNumVis = 7;	
	this._pestanyaActiva; /* Adreça:1  Indret:2  Punts Interes:3 */
	//this.canviaPestanya = _canviaPestanya;
	this.mostraPestanya = _mostraPestanya;
	this.desmarcaTotsPI = _desmarcaTotsPI;
	this.mostraLlistaPI = _mostraLlistaPI;
	this.mostraResultatPI = _mostraResultatPI;
	this.capturaEvents = _capturaEvents;
	this.imprimir = _imprimir;
	this.imprimir2 = _imprimir2;
	this.setupEstils = _setupEstils;
	this.mostraInfoPI = _mostraInfoPI;
	this.oculta = _oculta;
	this.mostraPIProp_0_500 = _mostraPIProp_0_500;
	this.mostraPIProp_500_1000 = _mostraPIProp_500_1000;
	this.mostraPIProp_1000_2000 = _mostraPIProp_1000_2000;
	this.mostraPIProp_2000_3000 = _mostraPIProp_2000_3000;
	this.mostraPIProp_3000_5000 = _mostraPIProp_3000_5000;
	this.mostraPIProp_5000_10000 = _mostraPIProp_5000_10000;
	this.zoomXY = _zoomXY;	
	this.actualitzaLlegenda	 = _actualitzaLlegenda;
	this.getnomPI = _getnomPI;
	this.getNameLayer = _getNameLayer;
	this.replaceAll = _replaceAll;
	this.maxZoomVis = _maxZoomVis;
	this.maxNumVis = _maxNumVis;
	this.obtenirNombreVisiblesPI = _obtenirNombreVisiblesPI; 
	this.oculta = _oculta;
	this.IO=_IO;
	function _setupEstils() {
		
		_llista1Actiu = true;
		_llista2Actiu = true;
		_llista3Actiu = true;
		_llista4Actiu = true;
		_llista5Actiu = true;
		_llista6Actiu = true;
		_llista7Actiu = true;
		_llista8Actiu = true;
		_llista9Actiu = true;
		_llista10Actiu = true;
		_llista11Actiu = true;
		_llista12Actiu = true;
		_llista13Actiu = true;
		_llista14Actiu = true;
		_llista15Actiu = true;
		_llista16Actiu = true;
		_llista17Actiu = true;
		_llista18Actiu = true;
		

		document.getElementById("bt_desmarcaTots").style.cursor = "pointer";
		document.getElementById("bt_desmarcaTots2").style.cursor = "pointer";
		document.getElementById("bt_desmarcaTots").disabled = true;
		document.getElementById("bt_desmarcaTots2").disabled = true;
		/*document.getElementById("ll_puntI_1").style.display = "none";
		document.getElementById("ll_puntI_2").style.display = "none";
		document.getElementById("ll_puntI_3").style.display = "none";
		document.getElementById("ll_puntI_4").style.display = "none";
		document.getElementById("ll_puntI_5").style.display = "none";
		document.getElementById("ll_puntI_6").style.display = "none";*/
				
		//document.getElementById("bt_desmarcaTots").style.cursor = "pointer";
		
		/* Dumy */
		var i, id;
		for (i=1;i<=6;i++) {
			//document.getElementById("info_detallPI_"+ i).style.display = "none";
			
		}
	//	_controlNombreVisiblesPI();
				
		var div_col1 = document.getElementById("dv_fColumna1");
		var ul0 = document.createElement("ul");
		ul0.className = "FW_sLlistaComu FW_sLlistaPuntsInteres";	
		ul0.appendChild(nouLI_Categoria("a_llista_1","Administraci&oacute; p&uacute;blica","ll_puntI_1","punt_1"));
		ul0.appendChild(nouLI_Categoria("a_llista_2","Associacionisme. Participaci&oacute;","ll_puntI_2","punt_2"));
		ul0.appendChild(nouLI_Categoria("a_llista_3","Comer&ccedil;. Consum","ll_puntI_3","punt_3"));
		ul0.appendChild(nouLI_Categoria("a_llista_4","Cultura","ll_puntI_4","punt_4"));
		ul0.appendChild(nouLI_Categoria("a_llista_5","Educaci&oacute; i formaci&oacute;","ll_puntI_5","punt_5"));
		ul0.appendChild(nouLI_Categoria("a_llista_6","Emerg&egrave;ncies. Seguretat","ll_puntI_6","punt_6"));
		ul0.appendChild(nouLI_Categoria("a_llista_7","Empresa. Ind&uacute;stria i energia","ll_puntI_7","punt_7"));
		ul0.appendChild(nouLI_Categoria("a_llista_8","Habitatge","ll_puntI_8","punt_8"));
		ul0.appendChild(nouLI_Categoria("a_llista_9","Just&iacute;cia","ll_puntI_9","punt_9"));
		div_col1.appendChild(ul0);
		
		var div_col2 = document.getElementById("dv_fColumna2");
		var ul1 = document.createElement("ul");
		ul1.className = "FW_sLlistaComu FW_sLlistaPuntsInteres";			
		ul1.appendChild(nouLI_Categoria("a_llista_10","LLengua. Comunicaci&oacute;","ll_puntI_10","punt_10"));
		ul1.appendChild(nouLI_Categoria("a_llista_11","Medi ambient","ll_puntI_11","punt_11"));
		ul1.appendChild(nouLI_Categoria("a_llista_12","Mobilitat. Transport","ll_puntI_12","punt_12"));
		ul1.appendChild(nouLI_Categoria("a_llista_13","Salut","ll_puntI_13","punt_13"));
		ul1.appendChild(nouLI_Categoria("a_llista_14","Serveis socials","ll_puntI_14","punt_14"));
		ul1.appendChild(nouLI_Categoria("a_llista_15","Societat, ciutadania i fam&iacute;lia","ll_puntI_15","punt_15"));
		ul1.appendChild(nouLI_Categoria("a_llista_16","Tecnologia. Recerca i innovaci&oacute;","ll_puntI_16","punt_16"));
		ul1.appendChild(nouLI_Categoria("a_llista_17","Treball","ll_puntI_17","punt_17"));
		ul1.appendChild(nouLI_Categoria("a_llista_18","Turisme","ll_puntI_18","punt_18"));
		div_col2.appendChild(ul1);
		
		var args = OpenLayers.Util.getParameters();
			// Punts d'interès (per taula de continguts)
		if (args.capes) 
		{			
			var argcapes = args.capes;
			argcapes = argcapes.toString().toUpperCase();						
			for (i=0;i<acronimPOI.length;i++) {
				if (argcapes.indexOf(acronimPOI[i]) != -1 )
			   	{   	    			    
				    var id = "ch_" + i;			    
				    document.getElementById(id).checked = true;
				    map.getLayersByName(nomPOI[i])[0].setVisibility(true);
				}				
			}
			if (_obtenirNombreVisiblesPI() > 0) 
			{
				document.getElementById("bt_desmarcaTots").disabled = false;
				document.getElementById("bt_desmarcaTots2").disabled = false;	
			}			
		}
		for (var i=1;i<19;i++){
			zonaInfo.mostraLlistaPI("ll_puntI_"+i);
			document.getElementById("punt_"+i).className= "FW_sFletxaPuntsVerm_";
		}
		// texts afegits per l'usuari
		if (args.t)
		{
			var argt = args.t;
			argt += "%";
			var texts = new Array();  
			var texts = argt.split("%");	
			var text_item = new Array(); 
			var xtemp,ytemp,ttemp; 
			for (i=0;i<texts.length-1;i++) {
				text_item = texts[i].split(":");
				if (text_item.length == 3)
				{								
					xtemp = text_item[0];
					ytemp = text_item[1];
					ttemp = text_item[2];
					var tpoint = new OpenLayers.LonLat(xtemp,ytemp);
					var etiqueta = new OpenLayers.Popup.Etiqueta(tpoint, ttemp);				
					var controlTexte = map.getControlsByClass("OpenLayers.Control.Texte")[0];      	
					etiqueta.events.register("clicked", controlTexte, controlTexte.esborra);			
					etiqueta.setBorder("1px");
					etiqueta.autoSize = true;
					etiqueta.minSize = new OpenLayers.Size(15,30);     			        			        							
				        map.addPopup(etiqueta);  				        
	        			controlTexte.etiquetes.push(etiqueta);
	        			if (navigator.userAgent.toLowerCase().indexOf("msie") > -1) 
	        			{	
	        				var size = new OpenLayers.Size(etiqueta.size.w+5,etiqueta.size.h+1);
				        	etiqueta.setSize(size);	
				        }
        			}					
			}			
		}
		// marques afegides per l'usuari
		if (args.m)
		{
			var argm = args.m;
			argm += "%";
			var points = new Array();  
			var points = argm.split("%");	
			var text_item = new Array(); 
			var xtemp,ytemp,controlMarca; 
			for (i=0;i<points.length-1;i++) {
				point_item = points[i].split(":");								
				if (point_item.length == 2)
				{
				xtemp = point_item[0];
				ytemp = point_item[1];							
				var tpoint = new OpenLayers.Geometry.Point(xtemp,ytemp);
				var feature = new OpenLayers.Feature.Vector(tpoint);
				controlMarca = map.getControlsByClass("OpenLayers.Control.Marca")[0];    
	        		controlMarca.layer.addFeatures([feature]);
	        		controlMarca.featureAdded(feature);
	        		}	
			}			
		}		

		// linies afegides per l'usuari
		if (args.l)
		{
			var argl = args.l;
			argl += "%";
			var lines = new Array();  
			var lines = argl.split("%");	
			var point_items = new Array(); 
			var xtemp,ytemp; 				
			for (i=0;i<lines.length-1;i++) {
				if (lines[i] != "")
				{				
					point_items = lines[i].split(",");																						
					var pointList = [];
					var newPoint;
					var point_xy;			
					for(var p=0; p<point_items.length; ++p) {
						point_xy = point_items[p].split(":");
						if (point_xy.length == 2)
						{
						newPoint = new OpenLayers.Geometry.Point(point_xy[0],point_xy[1]);
						pointList.push(newPoint);
						}
					}			
					var lineFeature = new OpenLayers.Feature.Vector(
					new OpenLayers.Geometry.LineString(pointList));											
		        		var controlLinia = map.getControlsByClass("OpenLayers.Control.Linia")[0];        
		        		controlLinia.layer.addFeatures([lineFeature]);
	        		}		
			}
					
		}	

	}
	
        
	function nouA(id,nom,idSpan) {
		var a0 = document.createElement("a");
		a0.id = id;
		a0.href="#FW_contingut2";
		a0.title="";
		var span0=document.createElement("span");
		span0.id=idSpan;
		span0.className="FW_sFletxaPuntsVerm";
		span0.innerHTML=nom;
		a0.appendChild(span0);
	//	a0.innerHTML = span0;
		return a0;
	}	
	function nouLI_Categoria (idA,nom,idUL,idS) {
		var li3 = document.createElement("li");
		li3.className="FW_sMarginBottom5";
		var a3 = nouA(idA,nom,idS);
		var br3=document.createElement("br");
		var ul3 = nouUL(idUL);
		li3.appendChild(a3);
		li3.appendChild(br3);
		li3.appendChild(ul3);
		return li3;
	}	
	function nouUL(id) {
		var ul0 = document.createElement("ul");
		ul0.className = "FW_sLlistaCheck";
		ul0.id = id;
		ul0.style.display="none";
		switch (id) {
			case "ll_puntI_1":	
				ul0.appendChild(nouLI_Capa(0));
				ul0.appendChild(nouLI_Capa(1));
				ul0.appendChild(nouLI_Capa(2));
				break;
			case "ll_puntI_2":	
				ul0.appendChild(nouLI_Capa(3));		
				break;
			case "ll_puntI_3":			
				ul0.appendChild(nouLI_Capa(4));
				break;
			case "ll_puntI_4":			
				ul0.appendChild(nouLI_Capa(5));
				ul0.appendChild(nouLI_Capa(6));
				ul0.appendChild(nouLI_Capa(7));
				ul0.appendChild(nouLI_Capa(8));
				break;				
			case "ll_puntI_5":			
				ul0.appendChild(nouLI_Capa(9));
				ul0.appendChild(nouLI_Capa(10));
				break;
			case "ll_puntI_6":			
				ul0.appendChild(nouLI_Capa(11));
				ul0.appendChild(nouLI_Capa(12));
				break;
			case "ll_puntI_7":			
				ul0.appendChild(nouLI_Capa(13));
				ul0.appendChild(nouLI_Capa(14));
				ul0.appendChild(nouLI_Capa(15));
				ul0.appendChild(nouLI_Capa(16));
				ul0.appendChild(nouLI_Capa(17));				
				break;		
			case "ll_puntI_8":							
				ul0.appendChild(nouLI_Capa(18));
				ul0.appendChild(nouLI_Capa(19));
				break;
			case "ll_puntI_9":			
				ul0.appendChild(nouLI_Capa(20));
				ul0.appendChild(nouLI_Capa(21));
				break;	
			case "ll_puntI_10":			
				ul0.appendChild(nouLI_Capa(22));
				ul0.appendChild(nouLI_Capa(23));
				break;	
			case "ll_puntI_11":			
				ul0.appendChild(nouLI_Capa(24));
				break;	
			case "ll_puntI_12":			
				ul0.appendChild(nouLI_Capa(25));
				break;	
			case "ll_puntI_13":			
				ul0.appendChild(nouLI_Capa(26));
				ul0.appendChild(nouLI_Capa(27));
				ul0.appendChild(nouLI_Capa(28));
				break;	
			case "ll_puntI_14":			
				ul0.appendChild(nouLI_Capa(29));
				ul0.appendChild(nouLI_Capa(30));
				ul0.appendChild(nouLI_Capa(31));
				break;	
			case "ll_puntI_15":			
				ul0.appendChild(nouLI_Capa(32));
				ul0.appendChild(nouLI_Capa(33));
				ul0.appendChild(nouLI_Capa(34));
				ul0.appendChild(nouLI_Capa(35));
				ul0.appendChild(nouLI_Capa(36));				
				break;	
			case "ll_puntI_16":			
				ul0.appendChild(nouLI_Capa(37));
				break;	
			case "ll_puntI_17":			
				ul0.appendChild(nouLI_Capa(38));
				break;	
			case "ll_puntI_18":			
				ul0.appendChild(nouLI_Capa(39));
				ul0.appendChild(nouLI_Capa(40));
				break;	
		}
		return ul0;
	}		
	function nouLI(id,icona,nom) {
		var li0 = document.createElement("li");
		var span0 = document.createElement("span");
		span0.className = "FW_sFormIc";
		var span0 = document.createElement("span");
		span0.className = "FW_sFormIc";
		var input0 = document.createElement("input");
		input0.type = "checkbox";
		input0.value = "";	
		input0.id = id;	
		var img0 = document.createElement("img");
		img0.src = icona;
		img0.alt = "";	
		img0.className = "FW_sImgIcon";				
		var label0 = document.createElement("label");
		// problema a IE7
		//label0.for = id;
		label0.innerHTML = nom;	
		label0.className = "FW_sFormLabel";	
		span0.appendChild(input0);		
		span0.appendChild(img0);
		li0.appendChild(span0);				
		li0.appendChild(label0);		
		return li0;
	}		

	function nouLI_Capa(index) {
		var id = "ch_" + index;
		var icona = 	"img/icones_pi/" + nomPOI[index] + ".gif";
		var nom = descPOI[index];
		var li0 = document.createElement("li");
		var span0 = document.createElement("span");
		span0.className = "FW_sFormIc";
		var span0 = document.createElement("span");
		span0.className = "FW_sFormIc";
		var input0 = document.createElement("input");
		input0.type = "checkbox";
		input0.value = "";	
		input0.id = id;	
		input0.className="FW_sCheckPI";
		var img0 = document.createElement("img");
		img0.src = icona;
		img0.alt = "";	
		img0.className = "FW_sImgIcon";				
		var label0 = document.createElement("label");
		// problema a IE7
		//label0.for = id;
		label0.innerHTML = nom;	
		label0.className = "FW_sFormLabel";
		label0.setAttribute("for",id);
		var br0=document.createElement("br");
		br0.clasName="FW_clear";
		span0.appendChild(input0);		
		span0.appendChild(img0);
		li0.appendChild(span0);				
		li0.appendChild(label0);
		li0.appendChild(br0);
		return li0;
	}		
/*		<ul class="FW_sLlistaCheck" id="ll_puntI_1">										
			<li>
           	<span class="FW_sFormIc">
                   <input type="checkbox" value="" id="ch_11111" class="FW_sCheckPI" />
                   <img class="FW_sImgIcon" src="img/icona_002.gif" alt=""/>
               </span>
               <label for="ch_1" class="FW_sFormLabel">Biblioteques lorem ipsum lorem ipsum lorem ipsum lorem ipsumlorem ipsum lorem ipsum</label>
           </li>																			
		</ul>	*/
	function _imprimir() {		
		var linkStyles = document.getElementsByTagName("link");		
		var head = document.getElementsByTagName("head")[0];		
			
		for(var i=0; i<linkStyles.length; i++){
			if(linkStyles[i].getAttribute("media")=="print"){
				linkStyles[i].parentNode.removeChild(linkStyles[i]);
			}
		}	
			
		var LINK = null;
		if(document.createElement){
			LINK = document.createElement("link");
			LINK.setAttribute("media", "print");
		}		
		
		if (LINK != null) {
			if (navigator.userAgent.toLowerCase().indexOf("msie 6") == -1) {
						LINK.setAttribute("href", "css/carrerer/FW_print_detallPI.css");
					}
					else {
						LINK.setAttribute("href", "css/carrerer/FW_print_detallPI_IE6.css");
					}
			LINK.setAttribute("rel", "stylesheet");
			head.appendChild(LINK);
		}		
		self.print();	
	}
	function _imprimir2() {	
		
		var linkStyles = document.getElementsByTagName("link");		
		var head = document.getElementsByTagName("head")[0];		
			
		for(var i=0; i<linkStyles.length; i++){
			if(linkStyles[i].getAttribute("media")=="print"){
				linkStyles[i].parentNode.removeChild(linkStyles[i]);
			}
		}	
			
		var LINK = null;	
		if(document.createElement){
			LINK = document.createElement("link");
			LINK.setAttribute("media", "print");
			LINK.setAttribute("type", "text/css");
		}		
		
		if (LINK != null) {
					
			if (navigator.userAgent.toLowerCase().indexOf("msie 6") == -1) {
				LINK.setAttribute("href", "css/carrerer/FW_print_detallPImapa.css");
			}
			else {
				LINK.setAttribute("href", "css/carrerer/FW_print_detallPImapa_IE6.css");
			}
			LINK.setAttribute("rel", "stylesheet");
			head.appendChild(LINK);
		}
		self.print();		
	}
		
	function imprSelec(nombre)
{
	//var ficha = document.getElementById(nombre);  
	var ventimp = window.open(' ', 'popimpr');
	ventimp.document.write(document.all[0].innerHTML);
	ventimp.document.close();
	//ventimp.print();
	//ventimp.close();
} 
	
	function _IO(U, V) {    
	var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
    X.open(V ? 'PUT' : 'GET', U, !1);
    X.setRequestHeader('Content-Type', 'text/html')
    X.send(V ? V : '');
	return X.responseText;
}

	function _mostraPestanya(id) {	
	
		if (id == "tab4") 
		// Punts d'interes
		{
			var tab = document.getElementById("tab4");
			eval(tab.data.slice(0,tab.data.indexOf("||")));			
			document.getElementById("dv_propDaqui").style.display = "none";	
			document.getElementById("dv_puntsInteresLlista").style.display = "";
			if (_obtenirNombreVisiblesPI() <= 0) {
				document.getElementById("bt_desmarcaTots").disabled = true;
				document.getElementById("bt_desmarcaTots2").disabled = true;
			}
			else  {
				document.getElementById("bt_desmarcaTots").disabled = false;											
				document.getElementById("bt_desmarcaTots2").disabled = false;
			}
			//document.location.href ="#dv_puntsInteresLlista";	
			return false;
		}
		if (id == "tab5") 
		// Prop d'aqui
		{
			var tab = document.getElementById("tab5");
			eval(tab.data.slice(0,tab.data.indexOf("||")));
			document.getElementById("dv_puntsInteresResultat").style.display = "none";			
			if (_obtenirNombreVisiblesPI() <= 0)
				document.getElementById("dv_propDaqui2").style.display = "";
			else
				document.getElementById("dv_propDaqui2").style.display = "none";			
			if (xyResultatPuntualFilAriadna == 0)
				document.getElementById("dv_propDaqui").style.display = "";	
			else
				document.getElementById("dv_propDaqui").style.display = "none";	
			
			if ((_obtenirNombreVisiblesPI() > 0) && (xyResultatPuntualFilAriadna != 0) )
			{				
				document.getElementById("dv_puntsInteresResultat").style.display = "";	
				_getProp(0,500);			
			}
		}	
		if (id == "tab6") 
		// Llegenda
{	
			//document.getElementById("dv_llegenda_mt10m").style.display = "none";
			//document.getElementById("dv_llegenda_bt5m").style.display = "none";	
			//document.getElementById("dv_llegenda_bt50m").style.display = "none";	
			//document.getElementById("dv_llegenda_bt250m").style.display = "none";
			//document.getElementById("dv_llegenda_bt500m").style.display = "none";
			//document.getElementById("dv_llegenda_bt1000m").style.display = "none";
			//document.getElementById("dv_llegenda_sat250m").style.display = "none";			
			//document.getElementById("dv_llegenda_orto25m").style.display = "none";
			//document.getElementById("dv_llegenda_orto5m").style.display = "none";
			var name = _getNameLayer();			
			switch (name) {
			case "Mapa Topogr&agrave;fic de Catalunya 1:1 000 000":
				document.getElementById("dv_llegenda").innerHTML = this.IO("llegenda/llegenda_bt1000m.html");
				//document.getElementById("dv_llegenda_bt1000m").style.display = "";				
				break;
			case "Mapa Topogr&agrave;fic de Catalunya 1:500 000":
				document.getElementById("dv_llegenda").innerHTML = this.IO("llegenda/llegenda_bt500m.html");
				//document.getElementById("dv_llegenda_bt500m").style.display = "";				
				break;
			case "Mapa Topogr&agrave;fic de Catalunya 1:250 000":
				document.getElementById("dv_llegenda").innerHTML = this.IO("llegenda/llegenda_bt250m.html");
				//document.getElementById("dv_llegenda_bt250m").style.display = "";				
				break;				
			case "Mapa Topogr&agrave;fic de Catalunya 1:50 000":
				document.getElementById("dv_llegenda").innerHTML = this.IO("llegenda/llegenda_bt50m.html");
				//document.getElementById("dv_llegenda_bt50m").style.display = "";				
				break;
			case "Mapa Topogr&agrave;fic de Catalunya 1:10 000":
				document.getElementById("dv_llegenda").innerHTML = this.IO("llegenda/llegenda_mt10m.html");
				//document.getElementById("dv_llegenda_mt10m").style.display = "";				
				break;
			case "Mapa Topogr&agrave;fic de Catalunya 1:5 000":
				document.getElementById("dv_llegenda").innerHTML = this.IO("llegenda/llegenda_bt5m.html");
				//document.getElementById("dv_llegenda_bt5m").style.display = "";				
				break;								
			case "Imatge sat&egrave;l&middot;lit 1:250 000":
				document.getElementById("dv_llegenda").innerHTML = this.IO("llegenda/llegenda_sat250m.html");
				//document.getElementById("dv_llegenda_sat250m").style.display = "";				
				break;
			case "Ortofotoimatge de Catalunya 1:25 000":
				document.getElementById("dv_llegenda").innerHTML = this.IO("llegenda/llegenda_orto25m.html");
				//document.getElementById("dv_llegenda_orto25m").style.display = "";				
				break;
			case "Ortofotoimatge de Catalunya 1:5 000":
				document.getElementById("dv_llegenda").innerHTML = this.IO("llegenda/llegenda_orto5m.html");
				//document.getElementById("dv_llegenda_orto5m").style.display = "";				
				break;
			}	
		}
		if (id == "tab7") 
		// Ajuda
		{
			var tab = document.getElementById("tab7");
			eval(tab.data.slice(0,tab.data.indexOf("||")));
		//	document.getElementById("dv_ajuda").innerHTML = "ajuda.html";
			// example:
			document.getElementById("dv_ajuda").innerHTML = this.IO("ajuda/ajuda.html");
		}		
	}




	function _getNameLayer() {
			var name = "Mapa Topogr&agrave;fic de Catalunya 1:250 000";			
			if (map.baseLayer.name == "Ortofoto")
				var tipus = "foto";
			else
				var tipus = "topo";
			var tzoom = map.getZoom();		
			if (tipus == "topo")
			{
				if (tzoom < 2) 
					name = "Mapa Topogr&agrave;fic de Catalunya 1:1 000 000";
				else
				{
					if (tzoom < 3) 
						name = "Mapa Topogr&agrave;fic de Catalunya 1:500 000";
					else
					{
						if (tzoom < 5) 
							name = "Mapa Topogr&agrave;fic de Catalunya 1:250 000";
						else
						{
							if (tzoom < 7) 
								name = "Mapa Topogr&agrave;fic de Catalunya 1:50 000";
							else
							{
							if (tzoom == 7) 
									name = "Mapa Topogr&agrave;fic de Catalunya 1:10 000";
								else
								{
									if ((tzoom == 8) || (tzoom == 9))
										name = "Mapa Topogr&agrave;fic de Catalunya 1:5 000";
								}
							}
						}
					}
				}
			}		
			if (tipus == "foto")
			{
				if (tzoom < 5) 
					name = "Imatge sat&egrave;l&middot;lit 1:250 000";
				else
				{
					if (tzoom < 7) 
						name = "Ortofotoimatge de Catalunya 1:25 000";
					else
					{					 
							name = "Ortofotoimatge de Catalunya 1:5 000";						
					}
				}
			}			
		return name;
	}
      	
	function _getProp(dist_min,dist_max){
		  var is_active_indica_punt =  map.getControlsByClass("Vissir.ClickIndica")[0].active;
		  if (is_active_indica_punt) return;
		  
		  var params = $H({}); 	         
		  params.set('x',xResultatFilAriadna);
		  params.set('y',yResultatFilAriadna);
		  params.set('dist_min',dist_min);
		  params.set('dist_max',dist_max);
		  
		  sTotsLayersVis = '';

    for(var i=0; i < map.layers.length; i++) {
        var layerEntry = map.layers[i];
        if ((!layerEntry.isBaseLayer) && (layerEntry.displayInLayerSwitcher) && (layerEntry.getVisibility()))  
        	{           	
			temp = layerEntry.name; 			   								
        	if (sTotsLayersVis != '')
        		sTotsLayersVis += ',mob_' + temp + '_g' ; 
        	else
         	sTotsLayersVis += 'mob_' + temp + '_g' ; 
        	}
    }
	sTotsLayersVis = sTotsLayersVis.toLowerCase();
               

	params.set('capes',sTotsLayersVis);

	var nurl = parametres.urlPOIsearch + "getPoisProx";
	//doc(params);
	jsonp(nurl, params, "zonaInfo.mostraPIProp_" + dist_min + "_" + dist_max);	 
}
	
	function _mostraPIProp_0_500(resp) {
		var divtaules = document.getElementById("dv_ZonaTaulesResultat");
		
		while(divtaules.hasChildNodes())
			divtaules.removeChild(divtaules.firstChild);	

		/*if (divtaules != null) {
			var nodePare = divtaules.parentNode;
			nodePare.removeChild(divtaules);
		}*/
		proces_resposta(resp,500);
		_getProp(500,1000);
	}
	
	function _mostraPIProp_500_1000(resp) {
		proces_resposta(resp,1000);
		_getProp(1000,2000);
	}
	function _mostraPIProp_1000_2000(resp) {
		proces_resposta(resp,2000);
		_getProp(2000,3000);
	}
	function _mostraPIProp_2000_3000(resp) {
		proces_resposta(resp,3000);
		//_getProp(2000,3000);
	}
	function _mostraPIProp_3000_5000(resp) {
		var divtaules = document.getElementById("dv_ZonaTaulesResultat");
		
		while(divtaules.hasChildNodes())
			divtaules.removeChild(divtaules.firstChild);	

		proces_resposta(resp,5000);
		_getProp(5000,10000);
	}
	function _mostraPIProp_5000_10000(resp) {
		proces_resposta(resp,10000);
		//_getProp(2000,3000);
	}
	function _getnomPI(taula)
	{
		var nom = taula;
		for (var j=0; j<nomPOI.length; j++)
		{
			nom = nom.replace("mob_" + nomPOI[j] + "_g",descPOI[j]);
		}
		return nom;	
	}
	function proces_resposta(resp,dist) {
		var locs;
		locs = resp;		
		
		var item = document.getElementById("dv_puntsInteresResultatTipus");	
		var temp_sTotsLayersVis = sTotsLayersVis;
		temp_sTotsLayersVis = zonaInfo.getnomPI(sTotsLayersVis);
				
		temp_sTotsLayersVis = _replaceAll(temp_sTotsLayersVis,",","; ");
		
		item.innerHTML = '<span class="FW_sFloatLeft">' + temp_sTotsLayersVis + '</span>';
		
		var divtaules = document.getElementById("dv_ZonaTaulesResultat");

		if (dist == 500)
		{
			div1 = document.createElement("div");
			var temp = document.getElementById("a_FilAriadna3").innerHTML;
			
			if ((temp != "") && (temp != " ")) 
				temp += ". "; 
			else
				temp = "";
			if (document.getElementById("a_FilAriadna2").innerHTML != "")
				temp += document.getElementById("a_FilAriadna2").innerHTML + ". ";; 
			temp += document.getElementById("a_FilAriadna1").innerHTML; 
			if (temp == ". ")
				div1.innerHTML ='Prop de: <span class="FW_sNegreta"> Punt indicat (fora de Catalunya)</span> ';
			else
			{
				//div1.innerHTML ='Prop de: <span class="FW_sNegreta">' + temp + '</span> ';
				var span0 = document.createElement('span');							
				span0.className = "FW_sNegreta";
				span0.innerHTML = "Prop de: ";
				div1.appendChild(span0);
				var a0 = document.createElement('a');							
				a0.setAttribute('href', '#');
				//a0.className = "FW_sLink FW_sLinkNoPrint";
				a0.className = "FW_sLink";
				a0.innerHTML = temp;														
				a0.onclick = function() {			
						map.setCenter(new OpenLayers.LonLat(xResultatFilAriadna,yResultatFilAriadna),6, false, true);								
//						return false;
				};							
				div1.appendChild(a0);
			}
			
			divtaules = document.getElementById("dv_ZonaTaulesResultat");
			//divtaules.className = "FW_SZonaTaulesResultat";
			divtaules.appendChild(div1);
		}
		table1 = document.createElement("table");
		table1.className = "FW_tResultatCercaPI";
		table1.border = "0";
		table1.setAttribute("cellpadding",0);
		table1.setAttribute("cellspacing",0);
		thead1 = document.createElement("thead");
		thead1.className = "FW_tCap";
		tr1 = document.createElement("tr");
		td1 = document.createElement("td");
		td1.className = "FW_tColumna1";
		var distpunt = dist;
		if (distpunt == 1000)  distpunt = "1.000";
		if (distpunt == 2000)  distpunt = "2.000";
		if (distpunt == 3000)  distpunt = "3.000";
		if (distpunt == 5000)  distpunt = "5.000";
		if (distpunt == 10000)  distpunt = "10.000";		
		td1.innerHTML = "A " + distpunt + " metres";
		td2 = document.createElement("td");
		td2.className = "FW_tColumna2";		
		tr1.appendChild(td1);
		tr1.appendChild(td2);
		thead1.appendChild(tr1);
		table1.appendChild(thead1);

		tbody1 = document.createElement("tbody");		
		var llistaTipus = sTotsLayersVis.split(",");	
			
		for (var j=0; j<llistaTipus.length; j++)
		{
			var temp_tipus = llistaTipus[j];
			afegir(temp_tipus,locs,tbody1,dist);		
		}
					
		document.getElementById("dv_puntsInteresResultat").style.display = "";
		document.getElementById("dv_propDaqui").style.display = "none";
		table1.appendChild(tbody1);	
		divtaules.appendChild(table1);	
		
		if (dist == 3000)
		{
		var a0 = document.createElement("a");
		a0.className = "FW_sLink FW_sNegreta FW_sLinkNoPrint";
		a0.href = "#";
		a0.innerHTML = "Punts d'inter&egrave;s m&eacute;s lluny...";
		a0.id = "a_meslluny";
		divtaules.appendChild(a0);
		
		_addEvent(document.getElementById("a_meslluny"), 'click', function () {
				_getProp(3000,5000);
				} );
		//<a href="#FW_contingut2" title="" class="FW_sLink FW_sNegreta">Punts d'inter&egrave;s m&eacute;s lluny...</a>
		}
		if (dist == 10000)
		{
		document.getElementById("tornarPI").style.display="";
		
		}
		else {
			document.getElementById("tornarPI").style.display="none";
		}
//var str1 ='<div class="FW_sMenuSuperior"><span><a onclick="cercadorM.ocultaDescripcio()" href="#" class="FW_sLink" title="">&lt;<span class="FW_sNoUnderline">&nbsp;</span>Torna</a>';	

		if ((dist == 3000) || (dist == 10000)) document.location.href ="#FW_contingut2";	
		
}			
	function afegir(tipus,locs,tbody,dist) {
					var nomtipus = zonaInfo.getnomPI(tipus);
					var sdist;
					switch (dist)
			        {
			            case 500:
				            sdist = " a 500 metres";
				            break;
			            case 1000:
				            sdist = " entre 500 i 1.000 metres";
				            break;
			            case 2000:
				            sdist = " entre 1.000 i 2.000 metres";
				            break;
			            case 3000:
				            sdist = " entre 2.000 i 3.000 metres";
				            break;
				        case 5000:
				            sdist = " entre 3.000 i 5.000 metres";
				            break;
				        case 10000:
				            sdist = " entre 5.000 i 10.000 metres";
				            break;    
				    }
				    
					var tr1 = document.createElement("tr");
					var td1 = document.createElement("td");					
					td1.className = "FW_tColumna1";
					td1.innerHTML = nomtipus;
					tr1.appendChild(td1);
					var td3 = document.createElement("td");
					td3.className = "FW_tColumna2";
							
					var trobat = 0;
					var a0, a1;
					for (var i=0;i<locs.length;i++) 
					{						
						var temp_i = dist +i;
						var loc = null;
						loc = locs[i];
						if (loc.taula == tipus) 
						{	
							trobat++;					
							
							var div1 = document.createElement("div");
							div1.className = "FW_sDetallPI";
							var div2 = document.createElement("div");
							div2.className = "FW_sFloatRight FW_sLinkNoPrint";
							div2.innerHTML = '|&nbsp;&nbsp;';
							var div2a = document.createElement("div");
							div2a.className = "FW_sFloatRight";
							var div2b = document.createElement("div");
							div2b.className = "FW_sFloatRight FW_sLinkNoPrint";
							div2b.innerHTML = '&nbsp;&nbsp;|';

							div2a.appendChild(crearLinkSitua(loc));
							div1.appendChild(div2);
							div1.appendChild(div2a);
							div1.appendChild(div2b);
							
							div1.appendChild(crearLinkMostra(loc.nom,temp_i,tipus));

							var br1 = document.createElement("br");
							div1.appendChild(br1);
							var span1 = document.createElement("span");
							span1.innerHTML = loc.adreca;
							span1.className="FW_sGaleria100Width";
							div1.appendChild(span1);
							var span2 = document.createElement("span");
							span2.id = 'info_detallPI_' + temp_i + tipus;
							span2.style.display = "none";
							span2.innerHTML = loc.cpostal + " " + loc.municipi + "<br />T. " + loc.telefon + "<br /> ";					
							var nstring = '';
							var str1 = trim(loc.web);
	  	  					if ((trim(str1) != "") && (str1.length > 2))								
							{
								nstring += '<a class="FW_sLink FW_sLinkNoPrint" href="' + str1 +'"';
								nstring += 'title="Aquest enlla&ccedil; s&#39;obrir&agrave; en una nova finestra" rel="external" ';
								nstring += 'onclick="return ObrePopUp(event,this,800,600)" onkeypress="return ObrePopUp(event,this,800,600)">';
								nstring += 'Consulteu el web';
								nstring += '</a>';
								nstring += '<a class="FW_sLink FW_sNoUnderline FW_sLinkNoPrint" href="' + str1 +'"';
								nstring += 'title="Aquest enlla&ccedil; s&#39;obrir&agrave; en una nova finestra" rel="external" ';
								nstring += 'onclick="return ObrePopUp(event,this,800,600)" onkeypress="return ObrePopUp(event,this,800,600)">';
								nstring += '<span class="FW_sLinkExtern FW_sPopup"> </span></a>';						
								nstring += '   |';																									
							}	
							var temp_mes_informacio = loc.mesInformacio;
							if (tipus == "mob_centres_ensenyament_g")
								temp_mes_informacio = urlCentresEnsenyament + temp_mes_informacio;
							str1 = trim(temp_mes_informacio);		
							if ( (trim(str1) != "") && (str1.length > 2))
							{									
									//nstring += '   <a class="FW_sLink FW_sLinkNoPrint" id="bt_tornaDetall" title="Mes informaci&oacute;" href="' + temp_mes_informacio + '">M&eacute;s informaci&oacute;</a>';
									nstring += '<a class="FW_sLink FW_sLinkNoPrint" id="bt_tornaDetall" href="' + str1 +'"';
									nstring += 'title="Aquest enlla&ccedil; s&#39;obrir&agrave; en una nova finestra" rel="external" ';
									nstring += 'onclick="return ObrePopUp(event,this,800,600)" onkeypress="return ObrePopUp(event,this,800,600)">';
									nstring += 'M&eacute;s informaci&oacute;';
									nstring += '</a>';
							}		
							span2.innerHTML += nstring;				
							
							div1.appendChild(span2);
							var br2 = document.createElement("br");
							br2.className = "FW_clear";
							div1.appendChild(br2);
							td3.appendChild(div1);															
						}
					}									            				            				            
					if (trobat == 0)
					{
						td3.innerHTML = "No hi ha " + nomtipus + sdist;
						tr1.appendChild(td3);
						tbody.appendChild(tr1);
					}
					else
					{
						tr1.appendChild(td3);
					    tbody.appendChild(tr1);						    						
					}
	
			}
function crearLinkSitua(loc)
{
		var a0 = document.createElement('a');							
		a0.setAttribute('href', '#');
		a0.setAttribute('className', 'FW_sLink FW_sLinkNoPrint');
		a0.setAttribute('class', 'FW_sLink FW_sLinkNoPrint');
		a0.setAttribute('title', '');
		a0.innerHTML = "Situa en el mapa";														
		a0.title = "Situa en el mapa: " + loc.nom;	
		a0.onclick = function() {zonaInfo.zoomXY(loc)};
		return(a0);
}
function crearLinkMostra(nom,temp_i,tipus)
{
		var a1 = document.createElement("a");
		a1.id = "a_puntI_" + temp_i + tipus;
		a1.className = "FW_sLink FW_sBold";
		a1.href = "#FW_contingut2";
		a1.title = "";	
		a1.innerHTML = nom;
		a1.onclick = function() {
					zonaInfo.mostraInfoPI("info_detallPI_" + temp_i + tipus);
					return false;
					} 
		return a1;											
}
//----------------------------  
  function _zoomXY(loc) {
//----------------------------  	
	var bounds = new OpenLayers.Bounds();
	bounds.extend(new OpenLayers.LonLat(xResultatFilAriadna,yResultatFilAriadna));
	bounds.extend(new OpenLayers.LonLat(loc.utmX,loc.utmY));
	var tw = bounds.getWidth()/5;
	var th = bounds.getHeight()/5;
	var tpar = bounds.toArray();
	var tleft = parseInt(tpar[0]-tw);
	var tbottom = parseInt(tpar[1]-th);
	var tright = parseInt(tpar[2]+tw);
	var ttop = parseInt(tpar[3]+th);
	bounds.extend(new OpenLayers.LonLat(tleft,tbottom));
	bounds.extend(new OpenLayers.LonLat(tright,ttop));
	bounds.toBBOX(); 	
	map.zoomToExtent(bounds,false);
	procesFitxa(loc,false);
}	
		
//----------------------------  
  function dump(obj){
//----------------------------  
    var volcat = "<ul>";
    for(var propietat in obj) {
      if (typeof(obj[propietat])=="object") {
        volcat += "<b>" + propietat + "</b><ul>" + dump(obj[propietat]) + "</ul>";
      } else {
        volcat += "<li><i>" + propietat + "</i>: " + obj[propietat] + "</li>";
      }
    }
    return volcat + "</ul>";
  }
  	
	function _desmarcaTotsPI() {		
		var item = document.getElementById("dv_puntsInteresLlista");
		var llistaCheck = item.getElementsByTagName("input");
		var ltemp = llistaCheck.length;

		for (i = 0; i < ltemp; i++) {			
			if (llistaCheck[i].type == "checkbox") {
				llistaCheck[i].checked = false;				
				}
		}
		for (i = 0; i < nomPOI.length; i++) {
			var nLayerIntern = nomPOI[i];
			map.getLayersByName(nLayerIntern)[0].setVisibility(false);
		}
		document.getElementById("bt_desmarcaTots").disabled = true;
		document.getElementById("bt_desmarcaTots2").disabled = true;
		if (layer_marker_maptip) layer_marker_maptip.clearMarkers();
		if (popup_fitxa != null) {                 
                     map.removePopup(popup_fitxa); 
                     popup_fitxa.destroy(); 
                     popup_fitxa = null; 
                } 
		if (layer_marker_mostrarFitxa) layer_marker_mostrarFitxa.clearMarkers();
		//Netegem el punt del mapa de referència
		if (layer_marker_indicaPunt_ref) layer_marker_indicaPunt_ref.clearMarkers();
	}
	
	function _obtenirNombreVisiblesPI() {
		var item = document.getElementById("dv_puntsInteresLlista");
		var llistaCheck = item.getElementsByTagName("input");								
		var tempVis = 0;
	    for(i=0; i < llistaCheck.length; i++) {
	        if (llistaCheck[i].type == "checkbox") {   
	           if (llistaCheck[i].checked) 	                                 	
						tempVis++;
			}
	    }
	    return tempVis;
	}                
	    
	function _controlNombreVisiblesPI() {		
		var tempVis = _obtenirNombreVisiblesPI();		                
	    if (tempVis > _maxNumVis) {	        
	        document.getElementById("FW_msnAvis").style.visibility = "visible";
	    }
	    else
	    {
		    document.getElementById("FW_msnAvis").style.visibility = "hidden";
		}
		if (tempVis <= 0) {
			document.getElementById("bt_desmarcaTots").disabled = true;
			document.getElementById("bt_desmarcaTots2").disabled = true;
		}
		else {
			document.getElementById("bt_desmarcaTots").disabled = false;	
			document.getElementById("bt_desmarcaTots2").disabled = false;
		}
	}	
	
	function _tancaMissatge() {
		if (document.getElementById("missatge") != null)
			document.getElementById("dv_missatge").removeChild(document.getElementById("missatge"));				
	}
	
	function _mostraLlistaPI(id) {
		var item = document.getElementById(id);
		
		if (item != null) {
			if (item.style.display == "none") 
				item.style.display = "";
			else 
				item.style.display = "none";
		}
	}
	
	function _mostraResultatPI() {
		document.location.href = "#FW_bMinwidth";

		/*document.getElementById("dv_puntsInteresResultat").style.display = "";
		//document.getElementById("dv_puntsInteresResultat").style.display = "none";
		document.getElementById("dv_propDaqui").style.display = "none";
		controlLayerSwitcher.pre_updateMap();
		document.location.href = "#idTitol";*/
		
		
	}
	function _mostraInfoPI(id) {
		if(document.getElementById(id).style.display == "none") {
			document.getElementById(id).style.display = "";
		}
		else {
			document.getElementById(id).style.display = "none";
		}		
		return false;
	}	
	
	function _capturaEvents(){
		_addEvent(document.getElementById("bt_desmarcaTots"), 'click', zonaInfo.desmarcaTotsPI);
		_addEvent(document.getElementById("bt_desmarcaTots2"), 'click', zonaInfo.desmarcaTotsPI);
		_addEvent(document.getElementById("bt_mostraPI"), 'click', zonaInfo.mostraResultatPI);
		_addEvent(document.getElementById("bt_mostraPI2"), 'click', zonaInfo.mostraResultatPI);
		_addEvent(document.getElementById("bt_imprimirLlista"), 'click', zonaInfo.imprimir);

		//_addEvent(document.getElementById("bt_actualitzaLlegenda"), 'click', zonaInfo.actualitzaLlegenda);

		
		_addEvent(document.getElementById("a_llista_1"), 'click', function () {
				if(_llista1Actiu == false) {
					zonaInfo.mostraLlistaPI("ll_puntI_1");
					document.getElementById("punt_1").className= "FW_sFletxaPuntsVerm_";
					_llista1Actiu = true;
				}
				else {
					zonaInfo.mostraLlistaPI("ll_puntI_1");
					document.getElementById("punt_1").className= "FW_sFletxaPuntsVerm";
					_llista1Actiu = false;
				}
				return false;
			} );
		
		_addEvent(document.getElementById("a_llista_2"), 'click', function () {
				if(_llista2Actiu == false) {
					zonaInfo.mostraLlistaPI("ll_puntI_2");
					document.getElementById("punt_2").className= "FW_sFletxaPuntsVerm_";
					_llista2Actiu = true;
				}
				else {
					zonaInfo.mostraLlistaPI("ll_puntI_2");
					document.getElementById("punt_2").className= "FW_sFletxaPuntsVerm";
					_llista2Actiu = false;
				}
				return false;
			} );
		_addEvent(document.getElementById("a_llista_3"), 'click', function () {
				if(_llista3Actiu == false) {
					zonaInfo.mostraLlistaPI("ll_puntI_3");
					document.getElementById("punt_3").className= "FW_sFletxaPuntsVerm_";
					_llista3Actiu = true;
				}
				else {
					zonaInfo.mostraLlistaPI("ll_puntI_3");
					document.getElementById("punt_3").className= "FW_sFletxaPuntsVerm";
					_llista3Actiu = false;
				}
				return false;
			} );
		_addEvent(document.getElementById("a_llista_4"), 'click', function () {
				if(_llista4Actiu == false) {
					zonaInfo.mostraLlistaPI("ll_puntI_4");
					document.getElementById("punt_4").className= "FW_sFletxaPuntsVerm_";
					_llista4Actiu = true;
				}
				else {
					zonaInfo.mostraLlistaPI("ll_puntI_4");
					document.getElementById("punt_4").className= "FW_sFletxaPuntsVerm";
					_llista4Actiu = false;
				}																
				return false;
			} );

		_addEvent(document.getElementById("a_llista_5"), 'click', function () {
				if(_llista5Actiu == false) {
					zonaInfo.mostraLlistaPI("ll_puntI_5");
					document.getElementById("punt_5").className= "FW_sFletxaPuntsVerm_";
					_llista5Actiu = true;
				}
				else {
					zonaInfo.mostraLlistaPI("ll_puntI_5");
					document.getElementById("punt_5").className= "FW_sFletxaPuntsVerm";
					_llista5Actiu = false;
				}
				return false;
			} );
			_addEvent(document.getElementById("a_llista_6"), 'click', function () {
				if(_llista6Actiu == false) {
					zonaInfo.mostraLlistaPI("ll_puntI_6");
					document.getElementById("punt_6").className= "FW_sFletxaPuntsVerm_";
					_llista6Actiu = true;
				}
				else {
					zonaInfo.mostraLlistaPI("ll_puntI_6");
					document.getElementById("punt_6").className= "FW_sFletxaPuntsVerm";
					_llista6Actiu = false;
				}
				return false;
			} );
			_addEvent(document.getElementById("a_llista_7"), 'click', function () {
				if(_llista7Actiu == false) {
					zonaInfo.mostraLlistaPI("ll_puntI_7");
					document.getElementById("punt_7").className= "FW_sFletxaPuntsVerm_";
					_llista7Actiu = true;
				}
				else {
					zonaInfo.mostraLlistaPI("ll_puntI_7");
					document.getElementById("punt_7").className= "FW_sFletxaPuntsVerm";
					_llista7Actiu = false;
				}
				return false;
			} );
			_addEvent(document.getElementById("a_llista_8"), 'click', function () {
				if(_llista8Actiu == false) {
					zonaInfo.mostraLlistaPI("ll_puntI_8");
					document.getElementById("punt_8").className= "FW_sFletxaPuntsVerm_";
					_llista8Actiu = true;
				}
				else {
					zonaInfo.mostraLlistaPI("ll_puntI_8");
					document.getElementById("punt_8").className= "FW_sFletxaPuntsVerm";
					_llista8Actiu = false;
				}
				return false;
			} );
			_addEvent(document.getElementById("a_llista_9"), 'click', function () {
				if(_llista9Actiu == false) {
					zonaInfo.mostraLlistaPI("ll_puntI_9");
					document.getElementById("punt_9").className= "FW_sFletxaPuntsVerm_";
					_llista9Actiu = true;
				}
				else {
					zonaInfo.mostraLlistaPI("ll_puntI_9");
					document.getElementById("punt_9").className= "FW_sFletxaPuntsVerm";
					_llista9Actiu = false;
				}
				return false;
			} );
		   _addEvent(document.getElementById("a_llista_10"), 'click', function () {
					if(_llista10Actiu == false) {
					zonaInfo.mostraLlistaPI("ll_puntI_10");
					document.getElementById("punt_10").className= "FW_sFletxaPuntsVerm_";
					_llista10Actiu = true;
				}
				else {
					zonaInfo.mostraLlistaPI("ll_puntI_10");
					document.getElementById("punt_10").className= "FW_sFletxaPuntsVerm";
					_llista10Actiu = false;
				}
				return false;
			} );
			_addEvent(document.getElementById("a_llista_11"), 'click', function () {
				if(_llista11Actiu == false) {
					zonaInfo.mostraLlistaPI("ll_puntI_11");
					document.getElementById("punt_11").className= "FW_sFletxaPuntsVerm_";
					_llista11Actiu = true;
				}
				else {
					zonaInfo.mostraLlistaPI("ll_puntI_11");
					document.getElementById("punt_11").className= "FW_sFletxaPuntsVerm";
					_llista11Actiu = false;
				}
				return false;
			} );
			_addEvent(document.getElementById("a_llista_12"), 'click', function () {
				if(_llista12Actiu == false) {
					zonaInfo.mostraLlistaPI("ll_puntI_12");
					document.getElementById("punt_12").className= "FW_sFletxaPuntsVerm_";
					_llista12Actiu = true;
				}
				else {
					zonaInfo.mostraLlistaPI("ll_puntI_12");
					document.getElementById("punt_12").className= "FW_sFletxaPuntsVerm";
					_llista12Actiu = false;
				}
				return false;
			} );
			_addEvent(document.getElementById("a_llista_13"), 'click', function () {
				if(_llista13Actiu == false) {
					zonaInfo.mostraLlistaPI("ll_puntI_13");
					document.getElementById("punt_13").className= "FW_sFletxaPuntsVerm_";
					_llista13Actiu = true;
				}
				else {
					zonaInfo.mostraLlistaPI("ll_puntI_13");
					document.getElementById("punt_13").className= "FW_sFletxaPuntsVerm";
					_llista13Actiu = false;
				}
				return false;
			} );
			_addEvent(document.getElementById("a_llista_14"), 'click', function () {
				if(_llista14Actiu == false) {
					zonaInfo.mostraLlistaPI("ll_puntI_14");
					document.getElementById("punt_14").className= "FW_sFletxaPuntsVerm_";
					_llista14Actiu = true;
				}
				else {
					zonaInfo.mostraLlistaPI("ll_puntI_14");
					document.getElementById("punt_14").className= "FW_sFletxaPuntsVerm";
					_llista14Actiu = false;
				}
				return false;
			} );
			_addEvent(document.getElementById("a_llista_15"), 'click', function () {
				if(_llista15Actiu == false) {
					zonaInfo.mostraLlistaPI("ll_puntI_15");
					document.getElementById("punt_15").className= "FW_sFletxaPuntsVerm_";
					_llista15Actiu = true;
				}
				else {
					zonaInfo.mostraLlistaPI("ll_puntI_15");
					document.getElementById("punt_15").className= "FW_sFletxaPuntsVerm";
					_llista15Actiu = false;
				}
				return false;
			} );
			_addEvent(document.getElementById("a_llista_16"), 'click', function () {
				if(_llista16Actiu == false) {
					zonaInfo.mostraLlistaPI("ll_puntI_16");
					document.getElementById("punt_16").className= "FW_sFletxaPuntsVerm_";
					_llista16Actiu = true;
				}
				else {
					zonaInfo.mostraLlistaPI("ll_puntI_16");
					document.getElementById("punt_16").className= "FW_sFletxaPuntsVerm";
					_llista16Actiu = false;
				}
				return false;
			} );
			_addEvent(document.getElementById("a_llista_17"), 'click', function () {
				if(_llista17Actiu == false) {
					zonaInfo.mostraLlistaPI("ll_puntI_17");
					document.getElementById("punt_17").className= "FW_sFletxaPuntsVerm_";
					_llista17Actiu = true;
				}
				else {
					zonaInfo.mostraLlistaPI("ll_puntI_17");
					document.getElementById("punt_17").className= "FW_sFletxaPuntsVerm";
					_llista17Actiu = false;
				}
				return false;
			} );
			_addEvent(document.getElementById("a_llista_18"), 'click', function () {
				if(_llista18Actiu == false) {
					zonaInfo.mostraLlistaPI("ll_puntI_18");
					document.getElementById("punt_18").className= "FW_sFletxaPuntsVerm_";
					_llista18Actiu = true;
				}
				else {
					zonaInfo.mostraLlistaPI("ll_puntI_18");
					document.getElementById("punt_18").className= "FW_sFletxaPuntsVerm";
					_llista18Actiu = false;
				}
				return false;
			} );

			_addEvent(document.getElementById("a_torna"), 'click', function () {
				_getProp(0,500);
				} );

		/*aent per a_puntI_1");
		_addEvent(document.getElementById("a_puntI_1"), 'click', function () {
				zonaInfo.mostraInfoPI("info_detallPI_1");
				return false;
			} );*/
		/*_addEvent(document.getElementById("a_puntI_2"), 'click', function () {
				zonaInfo.mostraInfoPI("info_detallPI_2");
				return false;
			} );
		_addEvent(document.getElementById("a_puntI_3"), 'click', function () {
				zonaInfo.mostraInfoPI("info_detallPI_3");
			} );
		_addEvent(document.getElementById("a_puntI_4"), 'click', function () {
				zonaInfo.mostraInfoPI("info_detallPI_4");
				return false;
			} );
		_addEvent(document.getElementById("a_puntI_5"), 'click', function () {
				zonaInfo.mostraInfoPI("info_detallPI_5");
				return false;
			} );
		_addEvent(document.getElementById("a_puntI_6"), 'click', function () {
				zonaInfo.mostraInfoPI("info_detallPI_6");
				return false
			} );*/
		
		for( var i = 0; i < acronimPOI.length; i++) { 					
			var id = i + "";
			var chid = "ch_"+i;
			var nstr = "_addEvent(document.getElementById(\"" + chid + "\"), 'click', function () {					_controlVisiblesPI_array(" + id + ");				} );";
			eval(nstr);
		} 
		
	}
	
	function _addEvent(obj, evType, fn){
		if (obj.addEventListener) {
			obj.addEventListener(evType, fn, false);
			return true;
		}
		else 
			if (obj.attachEvent) {
				return obj.attachEvent("on" + evType, fn);
			}
			else {
				return false;
			}
	}
	

	function _controlVisiblesPI_array(id) {
				var nLayerExtern = "ch_"+id;
				var nLayerIntern = this.nomPOI[id];
				if (document.getElementById(nLayerExtern).checked)
					document.getElementById(nLayerExtern).checked = true;
				else
					document.getElementById(nLayerExtern).checked = false;	
					
				var tempVis = _obtenirNombreVisiblesPI();	
			    if (tempVis > _maxNumVis) {        
					//document.getElementById("FW_msnAvis").style.visibility = "visible";
					if (document.getElementById("avis2")==null)
					{
						var divAvis=document.createElement("div");
						divAvis.id="avis2";
						divAvis.style.display="";
						divAvis.className="FW_sBlocErrors";
						var p=document.createElement("p");
						p.innerHTML="Nom&eacute;s es poden mostrar set tipus de punts d'inter&egrave;s.";
						var divAvis2=document.createElement("div");
						divAvis2.className="FW_sAspatanca";
						divAvis2.innerHTML="<img src=\"img/iconTancar.gif\" title=\"Tanca\" alt=\"Tanca\" onclick=\"zonaInfo.oculta();\" />";
						divAvis.appendChild(p) ;
						divAvis.appendChild(divAvis2);
						(document.getElementById(nLayerExtern).parentNode.parentNode).appendChild(divAvis);
						var brAvis=document.createElement("br");
						brAvis.id="brAvis";
						(document.getElementById(nLayerExtern).parentNode.parentNode).appendChild(brAvis);                                                       
					}
			    }
			    else {
				    //document.getElementById("FW_msnAvis").style.visibility = "hidden";			
					if (document.getElementById("avis2")!=null)
					{
						document.getElementById("avis2").parentNode.removeChild(document.getElementById("avis2"));
						document.getElementById("brAvis").parentNode.removeChild(document.getElementById("brAvis"));
					}
					
				}
				if ((!document.getElementById(nLayerExtern).checked) ||(tempVis > _maxNumVis)) 
				{					
					document.getElementById(nLayerExtern).checked = false;
					map.getLayersByName(nLayerIntern)[0].setVisibility(false);
					if (nLayerIntern==tipusPOIdestacat)
					{
						//Si desmarquem la capa del POI destacat també borrem el POI
						if (layer_marker_maptip) layer_marker_maptip.clearMarkers();
							if (popup_fitxa != null) {                 
								 map.removePopup(popup_fitxa); 
								 popup_fitxa.destroy(); 
								 popup_fitxa = null; 
							 } 
						if (layer_marker_mostrarFitxa) layer_marker_mostrarFitxa.clearMarkers();
					}
				}
				else
					map.getLayersByName(nLayerIntern)[0].setVisibility(true);
				
				if (tempVis > 0)
			    {
			    	if (map.getZoom() < _maxZoomVis) 
			    	{				
						mapa.mostraMissatgeAvis(true,"Feu zoom per visualitzar els punts d'inter&egrave;s seleccionats.",false);										 
			    	}
					document.getElementById("bt_desmarcaTots").disabled = false;
					document.getElementById("bt_desmarcaTots2").disabled = false;
			    }
			    else {
				    document.getElementById("bt_desmarcaTots").disabled = true;
					document.getElementById("bt_desmarcaTots2").disabled = true;
				}
		    					
            return false;
	}	
	function _oculta() {
			document.getElementById("missatge_PI").style.display = "none";
		}
		
	function _actualitzaLlegenda() {		
			zonaInfo.mostraPestanya("tab6");
			document.location.href ="#dv_llegenda";			
		}


	/* codi constructor */


	//----------------------------  
  function jsonp(nurl, nparams, callback_function) {
//----------------------------
    //document.getElementById("espera").style.display = "inline";
	nurl += "?";
	nparams.each(function(item) {
		nurl += item.key + "=" + escape(item.value) + "&";
	});
	var n_uid = (new Date()).getTime();
	delicious_callbacks[n_uid] = function (content) 
	{
	 if (n_uid > tempsDarreraResposta)
	    {
	       tempsDarreraResposta=n_uid;	       
	       //document.getElementById("debug2").innerHTML += n_uid + "(Es processa la resposta)<br>";
	       //_mostraPIProp(content);
	       var nt = "" + callback_function + "(content)";
	       eval(nt);
	       //cercadorM.mostraLocalitzacionsPuntsI(content);
		}
		else
		{
	       //document.getElementById("debug2").innerHTML += n_uid + "(Resposta no processada..................)<br>";			
		}	
	       delete delicious_callbacks[n_uid];
     };
  
	nurl += "jsonp=" +  encodeURIComponent("delicious_callbacks[" + n_uid + "]");
	var scriptElem = document.createElement('script');
	scriptElem.setAttribute('Id', callback_function);
	scriptElem.setAttribute('src', nurl);
	scriptElem.setAttribute('type', 'text/javascript');
	tag = document.getElementById(callback_function);

	if(!tag) {
	  tag = document.getElementsByTagName('head')[0].appendChild(scriptElem);
	} else {
	  document.getElementsByTagName('head')[0].replaceChild(scriptElem, tag);
	}
	eval(callback_function);

  } 
	/* codi constructor */
	
	
	function _replaceAll( text, str1, str2 ){
		var command = "text.replace(/"+str1+"/g,\""+str2+"\")";
		return eval(command);
		}

	
	function _oculta() {
		if (document.getElementById("avis2")!=null)
		{
			document.getElementById("avis2").parentNode.removeChild(document.getElementById("avis2"));
		}
		if (document.getElementById("brAvis")!=null)
		{
			document.getElementById("brAvis").parentNode.removeChild(document.getElementById("brAvis"));
		}
	}
}