 
  
var map;
var markers;
var Xpar = "";
var Ypar = "";
var Zpar = "";
var Cpar = "";
var Fpar = "";
var Tpar = "";
var consultaCoord=1;
var coordMax = new OpenLayers.Bounds(258000,4485000,536000,4752000);
var boxes;
var boxesSel;
var bEines;
var click;
var sf;
var vector;
var p23031 = new OpenLayers.Projection('EPSG:23031'); 
var p4326 = new OpenLayers.Projection("EPSG:4326");
var SRS = "EPSG:4326";
var markers;
//var servidor="http://delta.icc.cat/cgi-bin/mapserv?map=/opt/idec/dades/rcc/";
var servidor="/cgi-bin/mapserv?map=/opt/idec/dades/rcc/";
var ruta=document.location.href;

if(ruta.indexOf('localhost')!=-1 || ruta.indexOf('doctorandreu')!=-1 ){
    servidor="http://localhost/cgi-bin/mapserv.exe?map=E:/usuaris/v.pascual/dades/rcc/";
	}
/*
    if(ruta.indexOf('taure')!=-1 || ruta.indexOf('tauredev')!=-1 ){
    servidor="http://doctorandreu/cgi-bin/mapserv.exe?map=E:/usuaris/v.pascual/dades/rcc/";

	}
   
   */ 
//drawbox
 var dbbox = new OpenLayers.StyleMap({
	 "default": new OpenLayers.Style({
                fillOpacity: 0.0,fillColor: "#FFF8AF",strokeColor:"#FFF8AF",strokeWidth:3
            }),
            "select": new OpenLayers.Style({
           	 fillOpacity: 0.0,
                fillColor: "#FFF8AF",
                strokeColor:"#FFF8AF",
                strokeWidth:3
            }),
            
            "temporary": new OpenLayers.Style({
              	 fillOpacity: 0.0,
                 fillColor: "#FFF8AF",
                 strokeColor:"#FFF8AF",
                 strokeWidth:3
             })
        });
 
 
 var lookup = {
                'AJGI-05M': {fillOpacity: 0.3,fillColor: "#FDFF00",strokeColor:"#FBA880",strokeWidth:2},
                'AJGI-2M': {fillOpacity: 0.3,fillColor: "#FDFF00",strokeColor:"#C99C3D",strokeWidth:2},
                'AJBCN-2D': {fillOpacity: 0.3,fillColor: "#FDFF00",strokeColor:"#C99C3D",strokeWidth:2},               
                'CT-1M': {fillOpacity: 0.3,fillColor: "#FDFF00",strokeColor:"#C964B9",strokeWidth:2},
           'Metropolit': {fillOpacity: 0.3,fillColor: "#FDFF00",strokeColor:"#28002F",strokeWidth:2},
                'BT-5M': {fillOpacity: 0.3,fillColor: "#FDFF00",strokeColor:"#0397B5",strokeWidth:2},
                'OF-5M': {fillOpacity: 0.3,fillColor: "#FDFF00",strokeColor:"#0000FF",strokeWidth:2},
                'OI-5M': {fillOpacity: 0.3,fillColor: "#FDFF00",strokeColor:"#6B72BF",strokeWidth:2},
                'BT-25M': {fillOpacity: 0.3,fillColor: "#FDFF00",strokeColor:"#FF0000",strokeWidth:2},
                'OF-25M': {fillOpacity: 0.3,fillColor: "#FDFF00",strokeColor:"#FF831F",strokeWidth:2},
                'OI-25M': {fillOpacity: 0.3,fillColor: "#FDFF00",strokeColor:"#7F1725",strokeWidth:2},
                'BT-50M': {fillOpacity: 0.3,fillColor: "#FDFF00",strokeColor:"#325F00",strokeWidth:2}
            }

 
 //

 
 var stboxes = new OpenLayers.StyleMap({
     "default": new OpenLayers.Style({
    	 fillOpacity: 0.0,
         fillColor: "#FF7200",
         strokeColor:"#FF00E2",
         strokeWidth:4
     }),
     "select": new OpenLayers.Style({
    	 fillOpacity: 0.0,
         fillColor: "#FFDFDF",
         strokeColor:"#FF00E2",
         strokeWidth:4
     })
 });

 
  //stboxes.addUniqueValueRules("default", "nik", lookup);
 
var selboxes = new OpenLayers.StyleMap({
     fillOpacity: 0.0,
     fillColor: "#FFF8AF",
     //strokeColor:"#FF00E2",
     strokeColor: "#FFF8AF",
     strokeWidth:4
 });
 
		
		OpenLayers.ImgPath = '/idecwebservices/share/javascript/OL/theme/default/img/';

		
		//loadTranslationTable("traduccions.i18n",lang); 
		 
	     
	          
			  var bounds = new OpenLayers.Bounds(258000,4485000,536000,4752000); // Limits 250 000 arrodonits
	          //var resolutions = [1100,550,275,100,50,25,10,5,2,1,0.5]; 
	          var resolutions= [550,275,100,50,25,10,5,2,1,0.5,0.25];
	         
	          function init(){   
	                
                     OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;	        
              OpenLayers.Util.onImageLoadErrorColor="white";
                    
	        // $T('body');
	        	  
	          var options = {
			   maxExtent: bounds,
	         
			    //maxExtent: bounds,
			   	//nuevo
			   	resolutions: [1100,550,275,100,50,25,10,5,2,1,0.5,0.25],
			   	//zoom: -1,
			   	//viejos
			   	//maxResolution: 1100,
			    units: 'm',
			    projection: p23031,
                
			    controls:[]
			    //numZoomLevels: 15
			};
	          
	          
	          
	            //var options = {projection: "EPSG:23031",units: "m",resolutions: resolutions,maxExtent:bounds};
	        map = new OpenLayers.Map('mapa', options);
	 		
	    
	        //keyLegend:'<span class="bt50m">&nbsp;&nbsp;&nbsp;&nbsp;</span>'
		      var bt50m = new rcc.WMS(
			   "Base topogrāfica de Catalunya 1:50 000 (BT-50M) v3.1", 'http://shagrat.icc.es/lizardtech/iserv/ows?',
			    {
				   layers: 'mtc50m,',
				   format:"image/jpeg",
				   exceptions:"application/vnd.ogc.se_xml",
				   bgcolor:'0xFFFFFF', transparent:'true'
				},
		        {keyWFS:'BT-50M MET-15',attribution:'<div class="N_labelLegend">Base topogrāfica de Catalunya 1:50 000 (BT-50M) v3.1</div>',buffer:0, isBaseLayer: false,singleTile:false,opacity:1, visibility: false, group:"Āmbits i disponibilitat de les metadades"}
			  );

		      var bt25m = new  rcc.WMS(
			   "Base topogrāfica de Catalunya 1:25 000 (BT-25M) v1.0", 'http://shagrat.icc.es/lizardtech/iserv/ows?',
			    {
				   layers: 'mtc25m,',				   
				   format:"image/jpeg",
				   exceptions:"application/vnd.ogc.se_xml",
				   bgcolor:'0xFFFFFF', transparent:'true'
				},
		        {keyWFS:'BT-25M',buffer:0, isBaseLayer: false,singleTile:false,opacity:1, visibility: false,
				 attribution: '<div class="N_labelLegend">Base topogrāfica de Catalunya 1:25 000 (BT-25M) v1.0</div>',group:"Āmbits i disponibilitat de les metadades"}
			  );

              var of25m = new  rcc.WMS(
			   "Ortofotomapa de Catalunya 1:25 000 (OF-25M) v6.0", 'http://shagrat.icc.es/lizardtech/iserv/ows?',
			    {
				   layers: 'orto25m,',				   
				   format:"image/jpeg",
				   exceptions:"application/vnd.ogc.se_xml",
				   bgcolor:'0xFFFFFF', transparent:'true'
				},
		        {keyWFS:'OF-25M',buffer:0, isBaseLayer: false,singleTile:false,opacity:1, visibility: false,
					group:"Āmbits i disponibilitat de les metadades",
                    attribution: '<div class="N_labelLegend">Ortofotomapa de Catalunya 1:25 000 (OF-25M) v6.0</div>'}
			  );
              
              var oi25m = new  rcc.WMS(
			   "Ortofoto infraroja de Catalunya 1:25 000 (OI-25M) v2.0", 'http://shagrat.icc.es/lizardtech/iserv/ows?',
			    {
				   layers: 'ortoi25m,',				   
				   format:"image/jpeg",
				   exceptions:"application/vnd.ogc.se_xml",
				   bgcolor:'0xFFFFFF', transparent:'true'
				},
		        {keyWFS:'OI-25M',buffer:0, isBaseLayer: false,singleTile:false,opacity:1, visibility: false,
					group:"Āmbits i disponibilitat de les metadades",
                    attribution: '<div class="N_labelLegend">Ortofoto infraroja de Catalunya 1:25 000 (OI-25M) v2.0</div>'}
			  );
		      
              var of25c = new  rcc.WMS(
			   "Ortofoto de Catalunya 1:2 500 (OF-25C) v3.2", 'http://shagrat.icc.es/lizardtech/iserv/ows?',
			    {
				   layers: 'orto25c,',				   
				   format:"image/jpeg",
				   exceptions:"application/vnd.ogc.se_xml",
				   bgcolor:'0xFFFFFF', transparent:'true'
				},
		        {keyWFS:'OF-25C',buffer:0, isBaseLayer: false,singleTile:false,opacity:1, visibility: false,
					group:"Āmbits i disponibilitat de les metadades",
                    attribution: '<div class="N_labelLegend">Ortofoto de Catalunya 1:2 500 (OF-25C) v3.2</div>'}
			  );
              
              var oi25c = new  rcc.WMS(
			   "Ortofoto infraroja de Catalunya 1:2 500 (OI-25C) v1.1", 'http://shagrat.icc.es/lizardtech/iserv/ows?',
			    {
				   layers: 'ortoi25c,',				   
				   format:"image/jpeg",
				   exceptions:"application/vnd.ogc.se_xml",
				   bgcolor:'0xFFFFFF', transparent:'true'
				},
		        {keyWFS:'OI-25C',buffer:0, isBaseLayer: false,singleTile:false,opacity:1, visibility: false,
					group:"Āmbits i disponibilitat de les metadades",
                    attribution: '<div class="N_labelLegend">Ortofoto infraroja de Catalunya 1:2 500 (OI-25C) v1.1</div>'}
			  );
              
              
              
              
		      var ct1m = new rcc.WMS(
			   "Cartografia topogrāfica 1:1.000 (CT-1M) v2.1", "http://galileo.icc.cat/arcgis/services/icc_ct1m_v_r/MapServer/WMSServer?",
			    {
				   layers: '1,3,4,5,6',				 
				   format:"image/png",
				   exceptions:"application/vnd.ogc.se_xml",
				   bgcolor:'0xFFFFFF', transparent:'true'
				},
		        {keyWFS:'CT-1M',buffer:0, isBaseLayer: false,singleTile:true,opacity:0.7, visibility: false, 
				attribution: '<div class="N_labelLegend">Cartografia topogrāfica 1:1.000 (CT-1M) v2.1</div>',group:"Āmbits i disponibilitat de les metadades"}
			  );

              
                var mmamb = new rcc.WMS(
			   "Mapa Topogrāfic Metropolitā 1:1 000", 'http://cartografia.amb.es/ows/cartografia?',
			    {
				   layers: 'topo1k',				 
				   format:"image/png",
				   exceptions:"application/vnd.ogc.se_xml",
				   bgcolor:'0xFFFFFF', transparent:'true'
				},
		        {keyWFS:'CT-A1M',buffer:0, isBaseLayer: false,singleTile:true,opacity:0.9, visibility: false, 
					group:"Āmbits i disponibilitat de les metadades"}
			  );


              
		      var bt5m = new rcc.WMS(
			 "Base topogrāfica de Catalunya 1:5 000 (BT-5M) v2.0", 'http://shagrat.icc.es/lizardtech/iserv/ows?',
			    {
				  
				   layers: 'mtc5m,',				  
				   format:"image/jpeg",
				   exceptions:"application/vnd.ogc.se_xml",
				   bgcolor:'0xFFFFFF', transparent:'true'
				},
		        {keyWFS:'BT-5M',reproject: false,buffer:0,singleTile:false,opacity:1, isBaseLayer: false, visibility: false,
					group:"Āmbits i disponibilitat de les metadades",attribution: '<div class="N_labelLegend">Base topogrāfica de Catalunya 1:5 000 (BT-5M) v2.0</div>'}
			  );
			  
              
               var bt10m = new rcc.WMS(
			 "Mapa topogrāfic de Catalunya 1:10 000 (MT-10M) v1.0 i v1.1", 'http://shagrat.icc.es/lizardtech/iserv/ows?',
			    {
				  
				   layers: 'mtc10m,',				  
				   format:"image/jpeg",
				   exceptions:"application/vnd.ogc.se_xml",
				   bgcolor:'0xFFFFFF', transparent:'true'
				},
		        {keyWFS:'MT-10M',reproject: false,buffer:0,singleTile:false,opacity:1, isBaseLayer: false, visibility: false,
					group:"Āmbits i disponibilitat de les metadades",attribution: '<div class="N_labelLegend">Mapa topogrāfic de Catalunya 1:10 000 (MT-10M)</div>'}
			  );
			  
              
               var bt250m = new rcc.WMS(
			 "Mapa topogrāfic de Catalunya 1:250 000 versiķ digital", 'http://shagrat.icc.es/lizardtech/iserv/ows?',
			    {
				  
				   layers: 'mtc250m,',				  
				   format:"image/jpeg",
				   exceptions:"application/vnd.ogc.se_xml",
				   bgcolor:'0xFFFFFF', transparent:'true'
				},
		        {keyWFS:'MTC-250M',reproject: false,buffer:0,singleTile:false,opacity:1, isBaseLayer: false, visibility: false,
					group:"Āmbits i disponibilitat de les metadades",attribution: '<div class="N_labelLegend">Mapa topogrāfic de Catalunya 1:250.000 </div>'}
			  );
              
               var bt500m = new rcc.WMS(
			 "Mapa topogrāfic de Catalunya 1:500 000", 'http://shagrat.icc.es/lizardtech/iserv/ows?',
			    {
				  
				   layers: 'mtc500m,',				  
				   format:"image/jpeg",
				   exceptions:"application/vnd.ogc.se_xml",
				   bgcolor:'0xFFFFFF', transparent:'true'
				},
		        {keyWFS:'MTC-500M',reproject: false,buffer:0,singleTile:false,opacity:1, isBaseLayer: false, visibility: false,
					group:"Āmbits i disponibilitat de les metadades",attribution: '<div class="N_labelLegend">Mapa topogrāfic de Catalunya 1:500.000 </div>'}
			  );
              
               var bt1000m = new rcc.WMS(
			 "Mapa topogrāfic de Catalunya 1:1 000 000", 'http://shagrat.icc.es/lizardtech/iserv/ows?',
			    {
				  
				   layers: 'mtc1000m,',				  
				   format:"image/jpeg",
				   exceptions:"application/vnd.ogc.se_xml",
				   bgcolor:'0xFFFFFF', transparent:'true'
				},
		        {keyWFS:'MTC-1000M',reproject: false,buffer:0,singleTile:false,opacity:1, isBaseLayer: false, visibility: false,
					group:"Āmbits i disponibilitat de les metadades",attribution: '<div class="N_labelLegend">Mapa topogrāfic de Catalunya 1:1.000.000</div>'}
			  );
              
              
              
          
               var tall5m = new rcc.WMS(
			 "Talls10M", 'http://galileo.icc.cat/arcgis/services/icc_talls_v_r/MapServer/WMSServer?',
			    {		  
				   layers: '6,8',				  
				   format:"image/png",
				   exceptions:"application/vnd.ogc.se_xml",
				   bgcolor:'0xFFFFFF', transparent:'true'
				},
		        {keyWFS:'MT-10M',reproject: false,buffer:0,singleTile:true,opacity:1, isBaseLayer: false, visibility: false,
					group:"Āmbits i disponibilitat de les metadades"}
			  );
              
              
              
              
              
              
              var tall5m = new rcc.WMS(
			 "Talls5M", 'http://galileo.icc.cat/arcgis/services/icc_talls_v_r/MapServer/WMSServer?',
			    {		  
				   layers: '3,5',				  
				   format:"image/png",
				   exceptions:"application/vnd.ogc.se_xml",
				   bgcolor:'0xFFFFFF', transparent:'true'
				},
		        {keyWFS:'BT-5M OF-5M OI-5M OF-25C OI-25C',reproject: false,buffer:0,singleTile:true,opacity:1, isBaseLayer: false, visibility: false,
					group:"Āmbits i disponibilitat de les metadades"}
			  );
              
              
               var tall25m = new rcc.WMS(
			 "Talls25M", 'http://galileo.icc.cat/arcgis/services/icc_talls_v_r/MapServer/WMSServer?',
			    {		  
				   layers: '9,11',				  
				   format:"image/png",
				   exceptions:"application/vnd.ogc.se_xml",
				   bgcolor:'0xFFFFFF', transparent:'true'
				},
		        {keyWFS:'BT-25M OI-25M OF-25M',reproject: false,buffer:0,singleTile:true,opacity:1, isBaseLayer: false, visibility: false,
					group:"Āmbits i disponibilitat de les metadades"}
			  );
              
              var tall50m = new rcc.WMS(
			 "Talls50M", 'http://galileo.icc.cat/arcgis/services/icc_talls_v_r/MapServer/WMSServer?',
			    {		  
				   layers: '12,15',				  
				   format:"image/png",
				   exceptions:"application/vnd.ogc.se_xml",
				   bgcolor:'0xFFFFFF', transparent:'true'
				},
		        {keyWFS:'BT-50M',reproject: false,buffer:0,singleTile:true,opacity:1, isBaseLayer: false, visibility: false,
					group:"Āmbits i disponibilitat de les metadades"}
			  );
              
		      var of5m = new rcc.WMS(
		 			 "Ortofo de Catalunya 1:5 000 (OF-5M) v5.0 i 6.0", 'http://shagrat.icc.es/lizardtech/iserv/ows?',
		 			    {		 				  
		 				   layers: 'orto5m,',				  
		 				   format:"image/jpeg",
		 				   exceptions:"application/vnd.ogc.se_xml",
		 				   transparent:'false'
		 				},
		 		        {keyWFS:'OF-5M',buffer:0,singleTile:false,opacity:1, isBaseLayer: false, visibility: false, group:"Āmbits i disponibilitat de les metadades",
		 					attribution: '<div class="N_labelLegend">Ortofotomapa de Catalunya 1:5 000 (OF-5M) v5.0</div>'}
		 			  );
		 			  
		       var oi5m = new rcc.WMS(
		 			 "Ortofoto infraroja de Catalunya 1:5 000 (OI-5M) v1.0", 'http://shagrat.icc.es/lizardtech/iserv/ows?',
		 			    {			  
		 				   layers: 'ortoi5m,',				  
		 				   format:"image/jpeg",
		 				   exceptions:"application/vnd.ogc.se_xml",
		 				   bgcolor:'0xFFFFFF', transparent:'true'
		 				},
		 		        {keyWFS:'OI-5M',buffer:0,singleTile:false,opacity:1, isBaseLayer: false, visibility: false,
		 					group:"Āmbits i disponibilitat de les metadades",
                            attribution: '<div class="N_labelLegend">Ortofoto infraroja de Catalunya 1:5 000 (OI-5M) v1.0</div>'}
		 			  );
		 			  
		      /*
	          var mun = new OpenLayers.Layer.WMS(
			   "Límits", "http://galileo.icc.cat/wms/servlet/icc_limadmin_v_r?",
			    {
				 
				   layers: 'Municipis,Comarques',				   
				   format:"image/png",
				   exceptions:"application/vnd.ogc.se_xml",
				   bgcolor:'0xFFFFFF', transparent:'true'
				},
		        {buffer:0, isBaseLayer: false,singleTile:true, visibility: true}
			  );
              */
	          //,displayInLayerSwitcher:false
			vector = new OpenLayers.Layer.Vector("dibuix", {styleMap:dbbox,displayInLayerSwitcher:false});
            markers = new OpenLayers.Layer.Markers( "marca",{displayInLayerSwitcher:false} );				
            boxes  = new  OpenLayers.Layer.Vector( "Boxes", {styleMap:stboxes,displayInLayerSwitcher:false,visibility: true, rendererOptions: {zIndexing: true}});
            //boxesSel  = new OpenLayers.Layer.Vector( "BoxesSel", {styleMap:selboxes,displayInLayerSwitcher:false} );
            
           

           
          
	 var wms = new OpenLayers.Layer.WMS("topo",
		"http://sagitari.icc.cat/tilecache/tilecache.py?",
	    {layers: 'topo', format:"image/jpeg", exceptions:"application/vnd.ogc.se_xml"},
	    {buffer:0,opacity:1, transitionEffect:'resize','displayInLayerSwitcher':false});
	 
	 /*
	 var orto = new OpenLayers.Layer.WMS("orto",
				"http://sagitari.icc.cat/tilecache/tilecache.py?",
			    {layers: 'orto', format:"image/jpeg", exceptions:"application/vnd.ogc.se_xml"},
			    {buffer:0, transitionEffect:'resize','displayInLayerSwitcher':false});
	
	  */        
			  var layers = [wms,ct1m,mmamb,of25c,oi25c,bt5m,of5m,oi5m,bt10m,bt25m,of25m,oi25m,bt50m,bt250m,bt500m,bt1000m,tall5m,tall25m,tall50m,markers,vector,boxes];
			 
			  
			  
			  var eventListeners = {"activate": this.controlActivated, scope:this};
	 		  //var measureOptions = {paneldiv: options.paneldiv, handlerOptions: {freehand: false, persist: true}, eventListeners: eventListeners};
	 		 //var modifyOptions = {eventListeners: eventListeners, mode: OpenLayers.Control.ModifyFeature.RESHAPE | OpenLayers.Control.ModifyFeature.DRAG};
	 
	   	    	

			
			 
			 
	     var overviewMapSize = new OpenLayers.Size(128, 123);
	    var genericMapOptions = {projection: "EPSG:23031", units: 'm', maxExtent: bounds};
		
		var imgRefe = "images/xti.jpeg";
		
		var referencia = new OpenLayers.Layer.Image(
			    "Overview", imgRefe, bounds, overviewMapSize
		);
		
		var overviewOptions = {
			mapOptions: genericMapOptions,
			size: overviewMapSize,
			layers: [referencia]
		}

		// Hack: Mapa de referčncia inamovible
		var ovControl = new OpenLayers.Control.OverviewMap(overviewOptions);
		ovControl.isSuitableOverview = function() { return true; };
		
		bEines= new rcc.NavToolbar(vector);
		
	    map.addControl(ovControl);
	    map.addLayers(layers);    
		map.addControl( new OpenLayers.Control.PanZoom());  
		map.addControl( new OpenLayers.Control.Attribution());
		map.addControl( new OpenLayers.Control.Navigation());
		map.addControl(bEines);
		
		click = new rcc.Click();
        map.addControl(click);
        click.activate();

		
	    map.addControl( new rcc.LayerSwitcher({'div':OpenLayers.Util.getElement('panel'), 'activeColor':'#FFFFFF'}));

		map.zoomTo(1);
		map.events.register("zoomend", map,miraTra );


		
 $('lResultats').style.visibility='hidden';

ajustaMapaIE();
		
}	
function miraTra(){

var qq=document.cercaOculta.productes.value;
var ii=0;
if(qq.contains("CT-1M")){
for (var i=0; i < map.layers.length; i++) {var layer = map.layers[i];	if(layer.isBaseLayer){ii=i;} }


	if(map.getZoom() > 10){map.layers[ii].setOpacity(0);}	
	if(map.getZoom() <= 10){map.layers[ii].setOpacity(0.5);}
	

}

}


function  trans23031To4326(x0,y0,x1,y1){
                    var point1 = new OpenLayers.LonLat(x0, y0); 
				    point1 = point1.transform(p23031,p4326);
					var point2 = new OpenLayers.LonLat(x1, y1); 
				    point2 = point2.transform(p23031,p4326);
				    var mbbox = new OpenLayers.Bounds(point1.lon, point1.lat, point2.lon, point2.lat);
                    return mbbox;

}	

function trans4326To23031 (x0,y0,x1,y1){
                    var point1 = new OpenLayers.LonLat(x0, y0); 
				    point1 = point1.transform(p4326,p23031);
					var point2 = new OpenLayers.LonLat(x1, y1); 
				    point2 = point2.transform(p4326,p23031);
                   
				    var mbbox = new OpenLayers.Bounds(point1.lon, point1.lat, point2.lon, point2.lat);
                    return mbbox;

}	

function xurroToBounds(xurro,epsg){

    var bounds;
    var bbox=new Object();
    
    xurro=trim(xurro);
    if(xurro.indexOf(" ")!=-1){xurro=xurro.replace(" ",",");}
   var xurros=new Array();
      
    
  xurros=xurro.split(",");
  
    
        bbox.x0=trim(xurros[0]);
        bbox.y0=xurros[1];
        bbox.x1=xurros[2];
        bbox.y1=xurros[3];
      
        if(epsg=="4326"){
            bounds=trans23031To4326(bbox.x0,bbox.y0,bbox.x1,bbox.y1);
        }else if (epsg=="23031"){
        var cc=bbox.x0;
           var pos=cc.indexOf('.');
        
           if(pos > 3 || pos==-1){ //no val tranformacio
           
           bounds=new OpenLayers.Bounds(bbox.x0,bbox.y0,bbox.x1,bbox.y1);
           }else{
          
        	bounds=trans4326To23031(bbox.x0,bbox.y0,bbox.x1,bbox.y1);
            }
        }else{
            bounds=new OpenLayers.Bounds(bbox.x0,bbox.y0,bbox.x1,bbox.y1);
        }

return bounds;

}




function onFeatureSelect(feature){

	var ia=feature.attributes.ia;
	
	sf.unselectAll();
	sf.select(feature);
	
var ob=splitX(ia,'#');
	
    ia="#"+ob[1]+".";
	
	jQuery(oTable.fnSettings().aoData).each(function (){
		jQuery(this.nTr).removeClass('row_selected');
	});
	
	var aTrs = oTable.fnGetNodes();
	   
     for ( var i=0 ; i < aTrs.length ; i++ ){
     
      var dd=oTable.fnGetData(i);
      
      var ii=dd[6]+".";
    
      	if ( ii.indexOf(ia)!=-1 ){               		
			jQuery(aTrs[i]).addClass('row_selected');         
	}          
    }
	
}
function netejaCapa(capa){



if(capa=="boxes"){

	
if(boxes){

                /*
                        sf=map.getControlsByClass('OpenLayers.Control.SelectFeature');
                      
                        for(k=0; k < sf.length;k++){
                        	map.removeControl(sf[k]);
                        }

*/                        
                        if(map.getLayersByName('Boxes')){
                        	
                        	map.removeLayer(boxes,false);
                        }
                        
                       
                       boxes  = new OpenLayers.Layer.Vector( "Boxes", {styleMap:stboxes,displayInLayerSwitcher:false,visibility: true} );
                     

                       map.addLayer(boxes);
                      boxes.setZIndex(500);
                      //sf = new OpenLayers.Control.SelectFeature(boxes,{clickFeature: onFeatureSelect, multiple: false, hover: false});
//sf = new OpenLayers.Control.SelectFeature(boxes,{ multiple: false, hover: false});
                        //map.addControl(sf);
                        //sf.activate();
                        
                        }
  }                    



if(capa=="vector"){

	if(vector){
/*
 if(map.getLayersByName('dibuix')){map.removeLayer(vector,false); }
    vector = new OpenLayers.Layer.Vector("dibuix", {styleMap:dbbox,displayInLayerSwitcher:false});
    map.addLayer(vector);
	*/                       
	                
var layerMarked = map.getLayersByName("dibuix")[0];

	if(layerMarked != null){ 
    
    //layerMarked.destroy();
    
    if (layerMarked.features.length >= 1){layerMarked.destroyFeatures();}
   
 }
    
    //vector = new OpenLayers.Layer.Vector("dibuix", {styleMap:dbbox,displayInLayerSwitcher:false});
    //map.addLayer(vector);   

          
	          
              
              
              }
	
	
	
	
	
	
	  }      


if(capa=="marca"){

	// Es detecta si s'ha creat la marca
	var layerMarked = map.getLayersByName("marca")[0];
	
	if(layerMarked != null) layerMarked.destroy();
	var markers = new OpenLayers.Layer.Markers( "marca",{displayInLayerSwitcher:false} );
	
    
    map.addLayer(markers);
	 

     }      






}





function obteCapesActives(){
	var cape = new Array();
	for (var i=0; i < map.layers.length; i++) {
		var layer = map.layers[i];
		
		if (layer.getVisibility()){
			if (layer.CLASS_NAME == "rcc.WMS"){
				
				cape.push(layer.keyWFS);
				
			}
			}
			}
	
	return cape;
	
}


function activaCapesMapa(nick){



	for (var i=0; i < map.layers.length; i++) {
		var layer = map.layers[i];	

      if(layer.isBaseLayer){map.layers[i].setOpacity(0.5);}
  
			if (layer.CLASS_NAME == "rcc.WMS"){
           
            var key=layer.keyWFS;
			var nouNick=obteKey(nick);	
      
				if (key.contains(nouNick.key)){

									map.layers[i].setVisibility(true);
									if(document.all){
										var dd=map.getExtent();
										map.zoomToExtent(dd);
									}
								
						
				}else{
				map.layers[i].setVisibility(false);
				}
			}
			}
	//alert(2);
	//window.status="capaactiva";
}

function desactivaCapesMapa(){
	for (var i=0; i < map.layers.length; i++) {
   
    var layer = map.layers[i];		
 if(layer.isBaseLayer){
   map.layers[i].setOpacity(1);
 }
			if (layer.CLASS_NAME == "rcc.WMS"){map.layers[i].setVisibility(false);}
    
    }
}

function netejaMapaQuiet(){

desactivaCapesMapa();
	destrueixCapa('GML');
	netejaCapa("boxes");
	netejaCapa("marca");
	netejaCapa("vector");

}


function netejaMapa(){
desactivaCapesMapa();
	destrueixCapa('GML');
	netejaCapa("boxes");
	netejaCapa("marca");
	netejaCapa("vector");
	map.zoomToExtent(coordMax);
	map.zoomTo(1);
}

function ajustaMapaIE() {

var mapaH =parseInt($('mapa').style.height);
var marcFix=160;

var marcEsquerra=305;

if(document.all){marcEsquerra=335;}

var suggH=parseInt(document.body.clientHeight-marcEsquerra);



var mapW =document.body.clientWidth;

if($('lEstadistica')){$('lEstadistica').style.height=(document.body.clientHeight - 185)+'px';}

$('tblMain').height=(document.body.clientHeight-10);
$('tblMain').style.height=(document.body.clientHeight-10);

//console.info($('tblMain').style.height);






var fixedH=(suggH -180);

var fixedResults=parseInt(document.body.clientHeight-(parseInt(mapaH + marcFix)));


if($('lResultats')){

$('lResultats').style.height=(document.body.clientHeight - 190)+'px';

if(document.all){

$('lResultats').style.width='100%';
}

//$('lResultats').style.width=$('lEstadistica').style.width;
}


if(fixedResults < 0){fixedResults=150;}

if($('pr_div')){
$('pr_div').style.height=(fixedResults)+"px";

}
//$('cc_div').style.height=fixedResults+"px";
if($('resultGroup_div')){
$('resultGroup_div').style.height=fixedResults+"px";
}
 var ss = document.styleSheets;

        for (var i=0; i< ss.length; i++) {
            var rules = ss[i].cssRules || ss[i].rules;

            for (var j=0; j<rules.length ; j++) {
                if (rules[j].selectorText == ".fixed_height") { rules[j].style.height = suggH +"px";}
                if (rules[j].selectorText == ".intern") { rules[j].style.height = (suggH -30) +"px";}
            }
        }


}
window.onresize = function() {
	ajustaMapaIE();
}

