
    //variables globales
    var map;
    var centrox_markers,centroy_markers,zoom_markers=0; 
    var url = url_datos_json();
    var http_request = new XMLHttpRequest(); 
    var mOferta;
    var mEmpresas;
    var mParcelas;
    var parcela_destacada=null;
    var mParcelaDestacada;
    
    //var marker_destacado;
    var the_object=null;
    var evento_zoom=true;
    //var id_destacado;
    var centrar=0;
    
    //para checkear o no los markers
    var haySuelo=false;
    var hayPabellon=false;
    var hayOficina=false;
    var hayEmpresas=false;  
    var hayParcelas=false;
    
    var idioma = "es"; //idioma en el que se visiona la web
    
    var estilowkt = {
	        strokeColor:"#000000",
	        fillColor:'#FFFFCC',
	        strokeWidth:1,
            fillOpacity:0.6
        };
    var vWKT= new OpenLayers.Layer.Vector('TH',{style: estilowkt});
    
    function onFeatureSelect()
	{
	alert ('');
	}
	function onFeatureUnselect()
	{
	alert ('');
	}
	//alert ("prueba IE");
	//alert(url);
	jQuery.ajax({
		url: url,
		crossDomain:true,
		dataType: 'json',
		data: the_object,	
		error: function () {  
			alert("Espere por favor a que se carguen las chinchetas en el mapa");
			$('#cargando-markers').hide();
		},

		success: function(data){
			the_object=data;
			carga_markers();
			$('#cargando-markers').hide();
				
	        }
	});

//init del mapa openlayers
function init(){

	var str="";
	var myScales = [1000, 5000, 10000, 20000, 50000, 100000, 250000, 400000];
	//var bounds = new OpenLayers.Bounds(455353,4759003,560000,4811786);
	//VARIACIÓN DE 1588214 unidades en los nuevos bounds.
	var bounds = new OpenLayers.Bounds(-1132861,3170789,2148214,6400000);
	//var boundsBizkaia = new OpenLayers.Bounds(462521,4761250.6,552743.8,4811786);
	var boundsBizkaia = new OpenLayers.Bounds(462521,4758938,552743.8,4811786);
	var options={
		maxExtent: bounds,
		restrictedExtent:boundsBizkaia,
		maxResolution:1000,
		projection:"EPSG:23030",
		units:"m",
		scales: myScales		
		};
		
	map= new OpenLayers.Map('map',options);
    map.addLayer (vWKT);
	var vector_sel;	
		

	//obtener idioma de la web
	if (window.location.href.indexOf("?q=eu") != -1)
	{
		idioma = "eu";
	}
    if (window.location.href.indexOf("?q=en") != -1)
	{
		idioma = "en";
	}
	

//raton sobre un icono de empresa y guarda cual es el objeto vector
function mouse_over(feature)
{
document.body.style.cursor ="pointer";
vector_sel = feature;
vector_sel.onScreen = false;
}
//raton sale del icono de empresa
function mouse_out()
{
document.body.style.cursor ="default";
vector_sel = null;

}
	
	var select;		
	
	//evento click para recuperar informacion de empresas cuando se ha pulsado sobre un icono
	OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {                
                defaultHandlerOptions: {
                    'single': true,
                    'double': false,
                    'pixelTolerance': 0,
                    'stopSingle': false,
                    'stopDouble': false
                },
 
                initialize: function(options) {
                    this.handlerOptions = OpenLayers.Util.extend(
                        {}, this.defaultHandlerOptions
                    );
                    OpenLayers.Control.prototype.initialize.apply(
                        this, arguments
                    ); 
                    this.handler = new OpenLayers.Handler.Click(
                        this, {
                            'click': this.trigger
                        }, this.handlerOptions
                    );
                }, 
 
                trigger: function(e) {
		
			if (document.body.style.cursor == "pointer")
			{	
				//para cargar los bocadillos que muestran la info en el punto pulsado
				
				
				if (hayEmpresas == true)
				{					
				carga_info_empresa(vector_sel.geometry.getBounds().getCenterLonLat().lon, 
				                           vector_sel.geometry.getBounds().getCenterLonLat().lat,
								the_object);
				}
				else
				{		
                    if(hayParcelas == true){
                        //En las parcelas no se muestra un bocadillo sino que directamete se muestra la ficha de parcela
                        var id_clickado="";
                        for(i=0;i<the_object.item.length;i++)
		                {		
			                if(the_object.item[i].Lon == vector_sel.geometry.getBounds().getCenterLonLat().lon   && the_object.item[i].Lat ==   vector_sel.geometry.getBounds().getCenterLonLat().lat )
			                {
                            
                                vWKT.destroyFeatures();
                                var th = the_object.item[i].wkt;
                                features = new OpenLayers.Format.WKT().read(th);
                                vWKT.addFeatures(features);
                                
                            
				                id_clickado=the_object.item[i].vid;
                                 if(parcela_destacada==null){ mParcelaDestacada=new OpenLayers.Layer.Markers( "ParcelaDestacada" );map.addLayer(mParcelaDestacada);}
                                else{mParcelaDestacada.clearMarkers();}
                                var size = new OpenLayers.Size(16,16);
                                var offset = new OpenLayers.Pixel(-8,-8);
                                var icon = new OpenLayers.Icon('img/parcela_destacada.png',size,offset);
    		                    parcela_destacada= new OpenLayers.Marker(new OpenLayers.LonLat(the_object.item[i].Lon,the_object.item[i].Lat),icon.clone());
                                mParcelaDestacada.addMarker(parcela_destacada);
                            
                                
			                }
		
		                }
                        cargarUrlParcela(id_clickado);
                       
                    }
                    else{                      
					    carga_info_oferta(vector_sel.geometry.getBounds().getCenterLonLat().lon, 
				                           vector_sel.geometry.getBounds().getCenterLonLat().lat,
								the_object);
                    }
				}
			}
                }
 
            });

	var click = new OpenLayers.Control.Click();
	
	
	 
	var myStyles = new OpenLayers.StyleMap({
                "default": new OpenLayers.Style({
				externalGraphic: "img/1-6.png",
				    graphicWidth: 30,
                                     graphicHeight: 30,
                                     graphicXOffset: -15,		
				    graphicYOffset: -30	}) ,
		"seleccionado": new OpenLayers.Style({
				externalGraphic: "img/1-6.png",
				    graphicWidth: 30,
                                     graphicHeight: 30,
                                     graphicXOffset: -15,		
				    graphicYOffset: -30	})    				    
				    
            });	
	
	//capa vectorial del empresas si estamos en la busqueda de empresas
	if(url.indexOf("empresas")>=0){	
		      mEmpresas=new OpenLayers.Layer.Vector("Empresas",{styleMap: myStyles});	     
		     //comportamiento de acuerdo a la posicion del raton respecto a los iconos de empresas
		     select = new OpenLayers.Control.SelectFeature(mEmpresas, 
				{
					hover:true,
					onSelect: mouse_over,
					onUnselect: mouse_out			
				}
			);
			//añade al mapa el control de seleccion y lo activa
			     map.addControl(select);
			     select.activate();    
			//añade el evento de click cuando hay empresas
			map.addControl(click);
			click.activate();
			//añade la capa vectorial al mapa
			map.addLayer(mEmpresas);
	}
    else{
        if(url.indexOf("parcelas")>=0){	
            mParcelas=new OpenLayers.Layer.Vector("Parcelas",{styleMap: myStyles});	     
		     //comportamiento de acuerdo a la posicion del raton respecto a los iconos de empresas
		     select = new OpenLayers.Control.SelectFeature(mParcelas, 
				{
					hover:true,
					onSelect: mouse_over,
					onUnselect: mouse_out			
				}
			);
			//añade al mapa el control de seleccion y lo activa
			     map.addControl(select);
			     select.activate();    
			//añade el evento de click cuando hay empresas
			map.addControl(click);
			click.activate();
			//añade la capa vectorial al mapa
			map.addLayer(mParcelas);
        }
	    else{
		    mOferta=new OpenLayers.Layer.Vector("Oferta",{styleMap: myStyles});	     
		     //comportamiento de acuerdo a la posicion del raton respecto a los iconos de oferta
		     select = new OpenLayers.Control.SelectFeature(mOferta, 
				{
					hover:true,
					onSelect: mouse_over,
					onUnselect: mouse_out			
				}
			);
			//añade al mapa el control de seleccion y lo activa
			map.addControl(select);
			select.activate();    
			//añade el evento de click cuando hay empresas
			map.addControl(click);
			click.activate();
			//añade la capa vectorial al mapa
			map.addLayer(mOferta);			
			
	    }
	}
	//capa para los markers destacados
	//map.addLayer(mDestacado);
	
	//capas WMS cargadas en el mapa	
	layer = new OpenLayers.Layer.WMS("Mapa base",  
	"/tilecache/tilecache.py?", {layers: 'mapaoferta', format: 'image/png'}, { tileSize: new OpenLayers.Size(256,256),
                      buffer: 0 ,'displayInLayerSwitcher':false});  
	map.addLayers([layer]); 
	
	//controles adicionales que se añaden al mapa para la navegacion
	map.addControl(new OpenLayers.Control.PanZoomBar()); 	
	map.addControl(new OpenLayers.Control.MousePosition({numDigits: 0, suffix:' .m ED50 UTM30N',div: document.getElementById("coordenadas")}));
		
	 
	//propiedades del mapa		
	var escalas_overview= [50000000,1500000,1500000,1500000,1500000,1500000,1500000,1500000];
	var bounds_overview = new OpenLayers.Bounds(-1000000,0,10000000,10000000);
	var options_overview={
		projection:"EPSG:23030",
		units:"m",		
		scales: escalas_overview	
	};
	map.addControl(new OpenLayers.Control.OverviewMap({mapOptions: options_overview,div: document.getElementById("mapa_pequena"),size: new OpenLayers.Size(120,95)}));
	
	//se usa una emulacion propia de la leyenda ya que los elementos de tipo feature no los muestra en la leyenda
	//map.addControl(new OpenLayers.Control.LayerSwitcher({div: document.getElementById("leyenda")}));		
	
	
	//Cuando cambia el zoom tenemos que llamar a la url que pinta los markers: NO SE HACE YA QUE DE INICIO SE CARGAN YA TODOS
	 map.events.register("zoomend", map, function() {
		/*if(evento_zoom){
			zoom_markers=map.getZoom();			
			url=url_datos_json();
	
			$.ajax({
				url: url,
				dataType: 'json',
				data: the_object,
				success: function(){
					the_object=data;
					carga_markers();
				}
			});
	
	
	}	*/
	});	
	
	map.zoomToMaxExtent();

} //fin del init


function carga_info_oferta(x, y, objeto){
	var i;
	var contenidoPopup = "";
	var parametros;
	var ofertas = 1;
	var tipo ="";
	var visible = true;

	if (objeto.item.length)
	{
		//todos los marker cumpliendo la condicion
		for(i=0;i<objeto.item.length;i++)
		{				
			//inicialmente elemento visible en el mapa y por tanto se carga en el popup
			visible = true;
			
			if(objeto.item[i].Lon == x   && objeto.item[i].Lat ==  y )
			{
				
				//para poner por delante el tipo de oferta para que se sepa de que tipo es cada una cuando hay superposiciones:
				//pone el tipo y pinta el icono de su color
			switch(objeto.item[i].tipo_oferta)
			{
					//OFICINAS
					case "3":
					tipo = "Oficina";
					icono ="img/oficina_icono.gif";
					//controla estado del tipo al que pertenece en la leyenda
					if (!$('#check_oficina').is(':checked') )
					{
						visible = false;
					}
					break;
					//PABELLON
					case "2":
					tipo = "Pabell&oacute;n";
					icono ="img/pabellon_icono.gif";
					//controla estado del tipo al que pertenece en la leyenda
					if (!$('#check_pabellon').is(':checked'))
					{
						visible = false;
					}
					break;
					//SUELO
					case "1":
					tipo = "Suelo";
					icono ="img/suelo_icono.gif";
					//controla estado del tipo al que pertenece en la leyenda
					if (!$('#check_suelo').is(':checked'))
					{
						visible = false;
					}
					break;
			}
				
			//si algun tipo de elemento esta oculto en la leyenda no añade linea al popup
				if (visible == true) //elemento visible en leyenda
				{
					contenidoPopup = contenidoPopup + "<li style='color:#478CD6;padding-left:5px;padding-bottom:3px;border-bottom:1px dotted #478CD6;'><a href='#' style='font-weight:bold;' onclick='cargarUrlOferta(" + objeto.item[i].vid + ");' >" + ofertas + ". <img alt='tipo' src='" + icono + "'> |  REF#" + objeto.item[i].vid + " - " +  objeto.item[i].titulo+  "</a></li>";
					ofertas ++;	
				}
			}
		
		}
			//saca un popup con los nombre de las empresas en esa posicion			
			contenidoPopup = "<ul id ='lista_empresas'>" + contenidoPopup + "</ul>";	
			
			var popup = new OpenLayers.Popup.FramedCloud(
			"Ofertas",
			 new OpenLayers.LonLat(x,y),
			null,			 
			 contenidoPopup,
			 null,
			 true			 
			 );	
			
			if (ofertas ==1)
			{
				ofertas = 2;
			}
			map.addPopup(popup,true);
			popup.setSize(new OpenLayers.Size(375,15*ofertas));			
	}
    
	
}



//recupera las empresas asentadas en el elemento vector clickado
function carga_info_empresa(x,y,objeto, modulos)
{
	var i;
	var empresas
	var contenidoPopup = "";
	var parametros;
	var empresas = 1;

	
	
	if (objeto.item.length)
	{
		//todos los marker cumpliendo la condicion
		for(i=0;i<objeto.item.length;i++)
		{		
			if(objeto.item[i].Lon_emp == x   && objeto.item[i].Lat_emp ==  y )
			{
				contenidoPopup = contenidoPopup + "<li style='color:#478CD6;padding-left:5px;padding-bottom:3px;border-bottom:1px dotted #478CD6;'><a href='#' style='font-weight:bold;' onclick='cargarUrlEmpresa(\"" + objeto.item[i].vid + "\",\"" + objeto.item[i].id_foto + "\");' >" + empresas + ".  " + objeto.item[i].razon_social + "</a></li>";
				empresas ++;	
			}
		
		}
			//saca un popup con los nombre de las empresas en esa posicion			
			contenidoPopup = "<ul id ='lista_empresas'>" + contenidoPopup + "</ul>";		
			
			var popup = new OpenLayers.Popup.FramedCloud(
			"Empresas",
			 new OpenLayers.LonLat(x,y),
			null,			 
			 contenidoPopup,
			 null,
			 true			 
			 );	
			
			if (empresas ==1)
			{
				empresas = 2;
			}
			if (modulos > 1)
			{
			map.addPopup(popup,false); //false permite tener varios popups abiertos a la vez, necesario cuando hay mas de un edificio
			}else
			{
				map.addPopup(popup,true); 
			}
			popup.setSize(new OpenLayers.Size(260,15*empresas));			
		/*}
		else
		{
			alert ("Aumente el nivel de zoom para realizar consultas de empresas sobre el mapa.");
		}*/
	}
    
}

function mostrardiv() {
	div = document.getElementById('mapa_pequena');
	if(div.style.display == 'none')
		div.style.display = '';
	else
		div.style.display='none';
}

function zoom_mapa(id)
{	
	if(!IsNumeric(id)){return;}
	var objeto;
	objeto=the_object;
	if(the_object==null){ return;}
	else{	
	    //alert(the_object);
	    var vid=new Array();
	    j=0;	
	    for(var i=0;i<objeto.item.length;i++){
		    if(objeto.item[i].vid ==  id){
			    vid[j]=i; 
                j++;
		    }
	    }
	    if(vid!=undefined){        
		    xdes_min=objeto.item[vid[0]].Lon;//-size.w;
		    xdes_max=objeto.item[vid[0]].Lon;//+size.w;
		    ydes_min=objeto.item[vid[0]].Lat;//-size.h;
		    ydes_max=objeto.item[vid[0]].Lat;//+size.h;  				
	
            var centrox_markers=(parseFloat(xdes_max)+parseFloat(xdes_min))/2;
	        var centroy_markers=(parseFloat(ydes_max)+parseFloat(ydes_min))/2;
	       /* if (zoom_markers != 5)
	        {
		        zoom_markers = 5;
	        }*/
            map.setCenter(new OpenLayers.LonLat(centrox_markers, centroy_markers), 5);//zoom_markers);
	        carga_info_oferta(objeto.item[vid[0]].Lon,objeto.item[vid[0]].Lat,objeto);	
	    }
	}
    
	
}
	

	


function zoom_mapa_empresa(id){ //para las empresas
	var objeto;
	objeto=the_object;
	if(the_object==null){ return;}
	else{
	//se va a este nivel de zoom para el cual ya se cargan los markers a nivel de empresa, es necesario para que funcione cuando se pulsa sobre
	//una empresa en una situacion de zoom en la que los markers no estan individualizados
	map.zoomTo(6);
	//alert(the_object);
	var vid=new Array();
	var numEdificios = 0;
	j=0;
	//if(the_object==null){ return;}
	
	for(var i=0;i<objeto.item.length;i++)
		{
			if(objeto.item[i].vid ==  id){
				vid[j]=i; //vid contiene los iesimos elementos de lo que devuelve el json y que coinciden con los edificios de la emrpesa
				numEdificios++;
				j++;
		}
	}
	if(vid!=undefined){        
		xdes_min=objeto.item[vid[0]].Lon_emp;//-size.w;
		xdes_max=objeto.item[vid[0]].Lon_emp;//+size.w;
		ydes_min=objeto.item[vid[0]].Lat_emp;//-size.h;
		ydes_max=objeto.item[vid[0]].Lat_emp;//+size.h;  				
	
	var centrox_markers=(parseFloat(xdes_max)+parseFloat(xdes_min))/2;
	var centroy_markers=(parseFloat(ydes_max)+parseFloat(ydes_min))/2;
        //map.setCenter(new OpenLayers.LonLat(centrox_markers, centroy_markers), 6);
	//var bounds_des = new OpenLayers.Bounds(xdes_min,ydes_min,xdes_max,ydes_max);
	//zoom_markers=map.getZoomForExtent(bounds_des);
	if (zoom_markers != 6)//evita el nivel 7 de zoom, lo baja a 6
	{
		zoom_markers = 6;
	}
	
	//alert (centrox_markers + ", " + centroy_markers);
        map.setCenter(new OpenLayers.LonLat(centrox_markers, centroy_markers), zoom_markers);
	
	for (var i=0; i<numEdificios;i++)
	{
		carga_info_empresa(objeto.item[vid[i]].Lon_emp,objeto.item[vid[i]].Lat_emp,objeto, numEdificios);
	}
	
	//TODO: cuando es mas de un edificio que el popup en la empresa indique que hay mas de un edificio
	
	 }
	}
}

function zoom_mapa_parcela(id){ //para las empresas
	var objeto;
	objeto=the_object;
	if(the_object==null){ return;}
	else{
	    map.zoomTo(6);
	    var vid=new Array();
	    var numParcelas = 0;
	    j=0;
        for(var i=0;i<objeto.item.length;i++)
		{
			if(objeto.item[i].vid ==  id){
				vid[j]=i; //vid contiene los iesimos elementos de lo que devuelve el json y que coinciden con los edificios de la emrpesa
				numParcelas++;
				j++;
            }
		}
	}
	if(vid!=undefined){        
    
        //WKT PARA LAS PARCELAS
        vWKT.destroyFeatures();
        var th = objeto.item[vid[0]].wkt;
        features = new OpenLayers.Format.WKT().read(th);
        vWKT.addFeatures(features);
        map.addLayer (vWKT);
        
		xdes_min=objeto.item[vid[0]].Lon;//-size.w;
		xdes_max=objeto.item[vid[0]].Lon;//+size.w;
		ydes_min=objeto.item[vid[0]].Lat;//-size.h;
		ydes_max=objeto.item[vid[0]].Lat;//+size.h;  				
	
	    var centrox_markers=(parseFloat(xdes_max)+parseFloat(xdes_min))/2;
	    var centroy_markers=(parseFloat(ydes_max)+parseFloat(ydes_min))/2;
     	if (zoom_markers != 6)//evita el nivel 7 de zoom, lo baja a 6
	    {
		    zoom_markers = 6;
	    }
	
        map.setCenter(new OpenLayers.LonLat(centrox_markers, centroy_markers), zoom_markers);
	    
	    for(i=0;i<the_object.item.length;i++){
		    if(the_object.item[i].vid ==  id){
                if(parcela_destacada==null){ mParcelaDestacada=new OpenLayers.Layer.Markers( "ParcelaDestacada" );map.addLayer(mParcelaDestacada);}
                else{mParcelaDestacada.clearMarkers();}
                var size = new OpenLayers.Size(16,16);
                var offset = new OpenLayers.Pixel(-8,-8);
                var icon = new OpenLayers.Icon('img/parcela_destacada.png',size,offset);
    		    parcela_destacada= new OpenLayers.Marker(new OpenLayers.LonLat(the_object.item[i].Lon,the_object.item[i].Lat),icon.clone());
                    
                mParcelaDestacada.addMarker(parcela_destacada);
                
            }
	    }
        
              
        
        
	}
}


/*function markerdestacado(id){ //para las ofertas

    if(the_object==null) return;
    mDestacado.clearMarkers();
    var i;
    var size = new OpenLayers.Size(28,20);
    var offset = new OpenLayers.Pixel(-42, -27);
    var icon = new OpenLayers.vector('img/markers/marker_destacado.png',size,offset);
	for(i=0;i<the_object.item.length;i++){
		if(the_object.item[i].vid ==  id){
		marker_destacado = new OpenLayers.Marker(new OpenLayers.LonLat(the_object.item[i].Lon,the_object.item[i].Lat),icon.clone());
		mDestacado.addMarker(marker_destacado);
		id_destacado = id;
		
		}
	}
}*/


function carga_markers(){
		if (the_object==null) 
		{
			//$('#cargando-markers').hide();
			return;
		}
		
		var browser=navigator.appName;
		if(browser=="Microsoft Internet Explorer"){
			 var ua = navigator.userAgent;
			var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
			if (re.exec(ua) != null)
			var version = parseFloat( RegExp.$1 );
			if(version <9 /*&& the_object.item.length>50 */){return;}
			
		}
		
		//marker por defecto
		var size = new OpenLayers.Size(30,30);
		var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
		var codigo_mun;
		var xmarker_min,xmarker_max,ymarker_min,ymarker_max;
		xmarker_min =parseInt(the_object.item[0].Lon)-size.w;
		xmarker_max=parseInt(the_object.item[0].Lon)+size.w;
		ymarker_min=parseInt(the_object.item[0].Lat)+size.h;
		ymarker_max=parseInt(the_object.item[0].Lat)+size.h;
	
		//array para los vectores que simulan tipos marker
		var features = [];
	
		
		//eliminamos todos los markers antes de poner los nuevos correspondientes a este zoom
		 if (mEmpresas!=null)	mEmpresas.destroyFeatures(); 
         if (mParcelas!=null)	mParcelas.destroyFeatures(); 
		if (mOferta!=null)	mOferta.destroyFeatures();	
		//para todos los marker que ha devuelto json
		for(i=0;i<the_object.item.length;i++){			
			
			//icono por defecto para los marker que se clona las veces necesarias
			var icono = "";								
			var icon = new OpenLayers.Icon('img/'+the_object.item[i].marker_img,size,offset);
			
			//OFERTA INDUSTRIAL
			if(url.indexOf("empresas")<0 && url.indexOf("parcelas")<0){

				//coordenadas extremas de todos los markers cargados en la pantalla
				if(the_object.item[i].Lon<xmarker_min) 
				{
					xmarker_min=parseInt(the_object.item[i].Lon)-size.w;
				}
				if(the_object.item[i].Lon>xmarker_max)
				{
					xmarker_max=parseInt(the_object.item[i].Lon)+size.w;
				}
				if(the_object.item[i].Lat<ymarker_min) {
					ymarker_min=parseInt(the_object.item[i].Lat)-size.h;
				}
				if(the_object.item[i].Lat>ymarker_max) 
				{
					ymarker_max=parseInt(the_object.item[i].Lat)+size.h;
				}
				
	
				switch(the_object.item[i].tipo_oferta)
				{
					//OFICINAS
					case "3":					
					var feature=new OpenLayers.Feature.Vector(
					new OpenLayers.Geometry.Point(the_object.item[i].Lon, the_object.item[i].Lat), 
					{},
					{externalGraphic: "img/" + the_object.item[i].marker_img,					  
					graphicWidth: 30,
					graphicHeight: 30,
					graphicXOffset: -15,		
					graphicYOffset: -30			
					}
					);					
					hayOficina=true;									
					mOferta.addFeatures(feature);	
					break;
					//PABELLONES
					case "2":
					var feature=new OpenLayers.Feature.Vector(
					new OpenLayers.Geometry.Point(the_object.item[i].Lon, the_object.item[i].Lat), 
					{},
					{externalGraphic: "img/" + the_object.item[i].marker_img,					  
					graphicWidth: 30,
					graphicHeight: 30,
					graphicXOffset: -15,		
					graphicYOffset: -30}
					);
					hayPabellon=true;									
					mOferta.addFeatures(feature);
					break;
					//SUELOS
					case "1":
					var feature=new OpenLayers.Feature.Vector(
					new OpenLayers.Geometry.Point(the_object.item[i].Lon, the_object.item[i].Lat), 
					{},
					{externalGraphic: "img/" + the_object.item[i].marker_img,					  
					graphicWidth: 30,
					graphicHeight: 30,
					graphicXOffset: -15,		
					graphicYOffset: -30}
					);
					haySuelo=true;										
					mOferta.addFeatures(feature);
					break;				
				}	
							
				//actualizarLeyenda();
			}
			
					
            //EMPRESAS 
            if(url.indexOf("empresas")>0 && url.indexOf("parcelas")<0){			
					var feature=new OpenLayers.Feature.Vector(
					new OpenLayers.Geometry.Point(the_object.item[i].Lon, the_object.item[i].Lat), 
					{},
					{externalGraphic: "img/" + the_object.item[i].marker_img,					  
					graphicWidth: 30,
					graphicHeight: 30,
					graphicXOffset: -15,		
					graphicYOffset: -30}
					);				
					
					mEmpresas.addFeatures(feature);
					hayEmpresas=true;					
			}	
            //PARCELAS
            if(url.indexOf("empresas")<0 && url.indexOf("parcelas")>0){			
					var feature=new OpenLayers.Feature.Vector(
					new OpenLayers.Geometry.Point(the_object.item[i].Lon, the_object.item[i].Lat), 
					{},
					{externalGraphic: "img/" + the_object.item[i].marker_img,					  
					graphicWidth: 16,
					graphicHeight: 16,
					graphicXOffset: -8,		
					graphicYOffset: -8}
					);				
					
					mParcelas.addFeatures(feature);
					hayParcelas=true;					
			}	            
		}	
        
		//zoom al extent minimo que contiene todos los marker cargados
		centrox_markers=(parseFloat(xmarker_max)+parseFloat(xmarker_min))/2;
		centroy_markers=(parseFloat(ymarker_max)+parseFloat(ymarker_min))/2;
		var bounds_marker = new OpenLayers.Bounds(xmarker_min,ymarker_min,xmarker_max,ymarker_max);		
		
		zoom_markers=map.getZoomForExtent(bounds_marker);
		//para que no haga zoom excesivo cuando los marker ocupan poco ambito le limito el zoom maximo a nivel 4
		if (zoom_markers > 4)
		{
			zoom_markers = 4;
		}			
			
}


//llama a la funcion de ajax.js para cargar en enlace en el div
function cargarUrlEmpresa(id,foto)
{
	var url;	
	
	
	url = 'http://www.gislur.com/gislur/pintaempresa.php?q=' + idioma + '&id=' + id + '&idfoto=' + foto;
	cargar_pagina(url,document.getElementById('contenido_ficha'));
	
	//seleccion en la tabla del listado de empresas la fila correspondeinte clicada en el mapa dentro del bocadillo
	seleccionarEmpresaClicadaPopup("id=" + id);
	return false;
}

//llama a la funcion de ajax.js para cargar el enlace de la oferta en su div correspondiente
function cargarUrlOferta(id)
{
	var url;
	url = 'http://www.gislur.com/gislur/pintaoferta.php?q=' + idioma + '&vid=' + id
	cargar_pagina(url,document.getElementById('buscador_ficha'));
	
	//seleccion en la tabla del listado de ofertas la fila correspondeinte clicada en el mapa dentro del bocadillo
	seleccionarOfertaClicadaPopup("REF#" + id);
	
	return false;
}


//llama a la funcion de ajax.js para cargar el enlace de la parcela en su div correspondiente
function cargarUrlParcela(id)
{
	var url;
	url = 'http://www.gislur.com/gislur/pintaparcela.php?q=' + idioma + '&id=' + id
	cargar_pagina(url,document.getElementById('buscador_ficha'));
    seleccionarParcelaClicada("id=" + id);
    
	return false;
}



//actualiza el estado de visibilidad de los marker de oferta segun el estado de la leyenda
//que es desde donde se llama a esta funcion
function actualizarLeyenda(){

	//muestra/oculta los features segun estado de checks de la leyenda	
	

	//para adecuar propiedad display del style css
	if (!$('#check_suelo').is(':checked'))	
	{
		estado_suelo = "none";
	}
	else if ($('#check_suelo').is(':checked'))	
	{
		estado_suelo = "block";
	}
	
	if (!$('#check_pabellon').is(':checked'))	
	{
		estado_pabellon = "none";
	}
	else if ($('#check_pabellon').is(':checked'))	
	{
		estado_pabellon= "block";
	}
	
	if (!$('#check_oficina').is(':checked'))	
	{
		estado_oficina = "none";
	}
	else if ($('#check_oficina').is(':checked'))	
	{
		estado_oficina = "block";
	}	
	
		
	//recorre todos los features y modifica el estado de display de acuerdo al paso previo	
		for (var i=0; i<mOferta.features.length; i ++)
		{
			if (mOferta.features[i].style.externalGraphic.indexOf("img/1") != -1)
			{				
				mOferta.features[i].style.display = estado_suelo;
				mOferta.drawFeature(mOferta.features[i]);
					
			}
			
			if (mOferta.features[i].style.externalGraphic.indexOf("img/2") != -1)
			{				
				mOferta.features[i].style.display = estado_pabellon;
				mOferta.drawFeature(mOferta.features[i]);
					
			}
			
			if (mOferta.features[i].style.externalGraphic.indexOf("img/3") != -1)
			{				
				mOferta.features[i].style.display = estado_oficina;
				mOferta.drawFeature(mOferta.features[i]);					
			}
		}	


	return false;
}

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
