// JavaScript Document
var gmarkers = [];
var gmarkers2 = [];
var vectorPropiedades = [];
var pagina=0;
var i = 0;
var k = 0;
var map;
var volverBus=0;
var dominioLocal="www.inmoclick.com.ar";
var ultimaProv=0;
var latitudesLoc = [];


function initialize(){
	
	if (GBrowserIsCompatible()) {
      var select_html_prov = '<select onChange="handleSelected(this)"  name="pro_id" id="prov" style="width:118px;background-color:#FFFFFF;">';
      var select_html_loc =  '<select onChange="handleSelected(this)"  name="loc_id" id="loc_id" style="width:118px;background-color:#FFFFFF;"><option value="0">Localidad</option>';
      var select_html_tip =  '<select onChange="handleSelected(this)"  name="tip_id" id="tip_id" style="width:118px;background-color:#FFFFFF;"><option value="0">Inmueble</option>';
      var select_html_con =  '<select onChange="handleSelected(this)"  name="con_id" id="con_id" style="width:118px;background-color:#FFFFFF;"><option value="0">Condicion</option>';
		//mapa
		map = new GMap2(document.getElementById("mapa_buscar"));
		map.setCenter(new GLatLng(-39.3309018, -64.282339), 4);
		map.disableDoubleClickZoom();
   //   map.removeMapType(G_HYBRID_MAP);
        map.removeMapType(G_SATELLITE_MAP);
        map.addControl(new GMapTypeControl());
//      map.addControl(new GLargeMapControl());
		map.addControl(new GSmallMapControl());
		
//      map.addControl(new GScaleControl());
//      map.addControl(new GOverviewMapControl());

		///icono venta
		var baseIconVta = new GIcon();
		baseIconVta.iconSize = new GSize(20, 57);
		baseIconVta.iconAnchor = new GPoint(10, 8);
		baseIconVta.infoWindowAnchor = new GPoint(8, 5);
		baseIconVta.infoShadowAnchor = new GPoint(8, 5);
		baseIconVta.image = "/images/icono_00_vta.png";
		
		//icono alquiler
		var baseIconAlq = new GIcon();
		baseIconAlq.iconSize = new GSize(20, 57);
		baseIconAlq.iconAnchor = new GPoint(10, 8);
		baseIconAlq.infoWindowAnchor = new GPoint(8, 5);
		baseIconAlq.infoShadowAnchor = new GPoint(8, 5);
		baseIconAlq.image = "/images/icono_00_alq.png";
		
		var baseIcon2 = new GIcon();
		baseIcon2.iconSize = new GSize(18, 17);
		baseIcon2.iconAnchor = new GPoint(10, 8);
		baseIcon2.infoWindowAnchor = new GPoint(8, 5);
		baseIcon2.infoShadowAnchor = new GPoint(8, 5);
		baseIcon2.image= "/images/icono_01.gif";
		//funcion de crear iconos

		

      function createMarker(point,name,html,pro_id){
		
      	var letteredIcon = new GIcon(baseIcon2);
		markerOptions = { icon:letteredIcon};
		
		var marker = new GMarker(point, markerOptions);
		marker.tooltip = '<div class="tooltip">'+name+'</div>';
		
        GEvent.addListener(marker, "click", function() {
			
        	
           
				obj_prov=document.getElementById('prov');
	        	
				for(j=0;j<obj_prov.length;j++){
	        		if(obj_prov[j].value==pro_id){
	        			index=j;
	        			break;
	        		}
				}
	        	
				obj_prov[j].selected=index;        	       	
				
				cambiarLocs();
				
				loc=document.getElementById("loc_id");
	            tip=document.getElementById("tip_id");
	            con=document.getElementById("con_id");
	            pre_mi=document.getElementById("pre_min");
	            pre_ma=document.getElementById("pre_max");
	            mon=document.getElementById("pesos");
	            s1=document.getElementById("ser1");
	            s2=document.getElementById("ser2");
	            s3=document.getElementById("ser3");
	            s4=document.getElementById("ser4");
	            cFoto=document.getElementById("conFoto");
	            uSemana=document.getElementById("ultSemana");
	            uMes=document.getElementById("ultMes");
	            
	            //alert(con[con.options.selectedIndex].value)
	        	con_id_=con[con.options.selectedIndex].value;
	        	loc_id_=loc[loc.selectedIndex].value;
	        	tip_id_=tip[tip.selectedIndex].value;
	        	pre_min_=pre_mi[pre_mi.selectedIndex].value;
	        	pre_max_=pre_ma[pre_ma.selectedIndex].value;
	        	
	        	ser1_=s1[s1.selectedIndex].value;
	        	ser2_=s2[s2.selectedIndex].value;
	        	ser3_=s3[s3.selectedIndex].value;
	        	ser4_=s4[s4.selectedIndex].value;
	        	
	        	cFoto_="";
	        	uMes_="";
	        	uSemana_="";
	        	
	        	if(cFoto.checked){
	        		cFoto_=cFoto.value;
	        	}
	        	if(uMes.checked){
	        		uMes_=uMes.value;
	        	}
	        	if(uSemana.checked){
	        		uSemana_=uSemana.value;
	        	}
	        	
	        	if(mon.checked)
	        		pesos_=1;
	        	else
	        		pesos_=2;
         
			
        	/*
            if(loc.selectedIndex>0){
            	loc_id=loc.selectedIndex;
            }
           
            if(tip.selectedIndex > 0){
            	tip_id=tip.selectedIndex;
            }
            if(con.selectedIndex > 0){
            	con_id=con.selectedIndex;
            }
            */
        	//datos de prueba, borrar!		
        	
            
            
        	        	

           marker.openExtInfoWindow(
            	map,
              "custom_info_window_red",
              "<div id='custom_info_window_red_precarga'>cargando...</div>",
              {
                ajaxUrl: "http://"+dominioLocal+"/es/propiedades/infoWindow.html?pro_id="+pro_id+"&loc_id="+loc_id_+"&tip_id="+tip_id_+"&con_id="+con_id_+"&pre_min="+pre_min_+"&pre_max="+pre_max_+"&pesos="+pesos_+"&ser1="+ser1_+"&ser2="+ser2_+"&ser3="+ser3_+"&ser4="+ser4_+"&conFoto="+cFoto_+"&ultSemana="+uSemana_+"&ultMes="+uMes_+"&pro_lat="+marker.getPoint().lat()+"&pro_lng="+marker.getPoint().lng(),
                beakOffset: 3
              }
            ); 
          
		//  map.panTo(new GLatLng(marker.getPoint().lat()+4, marker.getPoint().lng()));
			map.setCenter(marker.getPoint(), 14);
			leerPropiedades();
			
			//acutaliza cuerpo del sitio
	        /*	new Ajax.Updater(
						'cuerpo_principal', 
						'/es/propiedades/consultaGeneral.html?tipoListado=ajax&pro_id='+pro_id+"&con_id="+con_id_+"&tip_id="+tip_id_+"&loc_id="+loc_id_+"&pre_min="+pre_min_+"&pre_max="+pre_max_+"&pesos="+pesos_+"&ser1="+ser1_+"&ser2="+ser2_+"&ser3="+ser3_+"&ser4="+ser4_+"&conFoto="+cFoto_+"&ultSemana="+uSemana_+"&ultMes="+uMes_, 
						{
						 asynchronous:		
										true, 
										evalScripts:false, 
										onComplete:function(request, json)
													{
															Element.hide('cargandoCuerpo');
															Element.show('cuerpo_principal')
													}, 
										onLoading:function(request, json){
															Element.show('cargandoCuerpo');
															Element.hide('cuerpo_principal')
													}
						}
					)
			*/
			
        });
        
        GEvent.addListener(marker, "dragend", function() {
			
        	
            
			obj_prov=document.getElementById('prov');
        	
			for(j=0;j<obj_prov.length;j++){
        		if(obj_prov[j].value==pro_id){
        			index=j;
        			break;
        		}
			}
        	
			obj_prov[j].selected=index;        	       	
			
			loc=document.getElementById("loc_id");
            tip=document.getElementById("tip_id");
            con=document.getElementById("con_id");
            pre_mi=document.getElementById("pre_min");
            pre_ma=document.getElementById("pre_max");
            mon=document.getElementById("pesos");
            s1=document.getElementById("ser1");
            s2=document.getElementById("ser2");
            s3=document.getElementById("ser3");
            s4=document.getElementById("ser4");
            cFoto=document.getElementById("conFoto");
            uSemana=document.getElementById("ultSemana");
            uMes=document.getElementById("ultMes");
            
            //alert(con[con.options.selectedIndex].value)
        	con_id_=con[con.options.selectedIndex].value;
        	loc_id_=loc[loc.selectedIndex].value;
        	tip_id_=tip[tip.selectedIndex].value;
        	pre_min_=pre_mi[pre_mi.selectedIndex].value;
        	pre_max_=pre_ma[pre_ma.selectedIndex].value;
        	
        	ser1_=s1[s1.selectedIndex].value;
        	ser2_=s2[s2.selectedIndex].value;
        	ser3_=s3[s3.selectedIndex].value;
        	ser4_=s4[s4.selectedIndex].value;
        	
        	cFoto_="";
        	uMes_="";
        	uSemana_="";
        	
        	if(cFoto.checked){
        		cFoto_=cFoto.value;
        	}
        	if(uMes.checked){
        		uMes_=uMes.value;
        	}
        	if(uSemana.checked){
        		uSemana_=uSemana.value;
        	}
        	
        	if(mon.checked)
        		pesos_=1;
        	else
        		pesos_=2;
			
        	/*
            if(loc.selectedIndex>0){
            	loc_id=loc.selectedIndex;
            }
           
            if(tip.selectedIndex > 0){
            	tip_id=tip.selectedIndex;
            }
            if(con.selectedIndex > 0){
            	con_id=con.selectedIndex;
            }
            */
        	//datos de prueba, borrar!		
        	
            //posicionar localidad
            
			if(loc_id_>0){
			//centrar por localidad
				if(latitudesLoc[loc_id_]){
					cad=latitudesLoc[loc_id_].split('*');
					marker.setLatLng(new GLatLng(cad[0],cad[1]))
					map.panTo(new GLatLng(cad[0],cad[1]));
					map.setCenter(new GLatLng(cad[0],cad[1]), 14);
				}else{
					map.setCenter(marker.getPoint(), 14);
				}
			}else{
				map.setCenter(marker.getPoint(), 14);
			}
        	
           marker.openExtInfoWindow(
            	map,
              "custom_info_window_red",
              "<div id='custom_info_window_red_precarga'>cargando...</div>",
              {
                ajaxUrl: "http://"+dominioLocal+"/es/propiedades/infoWindow.html?pro_id="+pro_id+"&loc_id="+loc_id_+"&tip_id="+tip_id_+"&con_id="+con_id_+"&pre_min="+pre_min_+"&pre_max="+pre_max_+"&pesos="+pesos_+"&ser1="+ser1_+"&ser2="+ser2_+"&ser3="+ser3_+"&ser4="+ser4_+"&conFoto="+cFoto_+"&ultSemana="+uSemana_+"&ultMes="+uMes_+"&pro_lat="+marker.getPoint().lat()+"&pro_lng="+marker.getPoint().lng(),
                beakOffset: 3
              }
            ); 
           
		//
			leerPropiedades();
			
			//acutaliza cuerpo del sitio
			/*
	        	new Ajax.Updater(
						'cuerpo_principal', 
						'/es/propiedades/consultaGeneral.html?tipoListado=ajax&pro_id='+pro_id+"&con_id="+con_id_+"&tip_id="+tip_id_+"&loc_id="+loc_id_+"&pre_min="+pre_min_+"&pre_max="+pre_max_+"&pesos="+pesos_+"&ser1="+ser1_+"&ser2="+ser2_+"&ser3="+ser3_+"&ser4="+ser4_+"&conFoto="+cFoto_+"&ultSemana="+uSemana_+"&ultMes="+uMes_, 
						{
						 asynchronous:		
										true, 
										evalScripts:false, 
										onComplete:function(request, json)
													{
															Element.hide('cargandoCuerpo');
															Element.show('cuerpo_principal')
													}, 
										onLoading:function(request, json){
															Element.show('cargandoCuerpo');
															Element.hide('cuerpo_principal')
													}
						}
					)
			*/
			
        });
        
        //map.addOverlay(marker);
        GEvent.addListener(marker, "dblclick", function() {
			//readMap('provincias.xml');
        	map.panTo(new GLatLng(marker.getPoint().lat(), marker.getPoint().lng()), map.getZoom()+2);
        });
        GEvent.addListener(marker, "mouseover", function() {
			//marker.setImage("marker.png");
			//marker.openInfoWindowHtml(name);
			showTooltip(marker);
        });
        GEvent.addListener(marker, "mouseout", function() {
			//marker.setImage("coldmarker.png");
			tooltip.style.visibility="hidden"
        });
        gmarkers[i] = marker;
        
        if(pro_id==21){
          cad_selected="selected";	
        }else{
          cad_selected="";		
        }
		select_html_prov += '<option value='+pro_id+' '+cad_selected+'>' + name + '</option>';
        i++;
        return marker;
      }

        function createMarker2(point,prp_id,usr_id,pro_id,prp_desc,con_id) {
			
        	if(con_id==2){	
        		var letteredIcon = new GIcon(baseIconAlq);
        	}else{
        		var letteredIcon = new GIcon(baseIconVta);
        	}
        	
	      	markerOptions = { icon:letteredIcon};
			
			var marker2 = new GMarker(point, markerOptions);
			marker2.tooltip = '<div class="tooltip">'+
			
			prp_desc+'</div>';
			
	        GEvent.addListener(marker2, "click", function() {
				
				
	        	//datos de prueba, borrar!		
	        	
	        //    alert(con[con.options.selectedIndex].value)
	        	
	          marker2.openExtInfoWindow(
	            	map,
	              "custom_info_window_red",
	              "<div id='custom_info_window_red_precarga'>cargando...</div>",
	              {
	                ajaxUrl: "http://"+dominioLocal+"/es/propiedades/infoWindowFicha.html?pro_id="+pro_id+"&loc_id="+loc_id_+"&tip_id="+tip_id_+"&con_id="+con_id_+"&pre_min="+pre_min_+"&pre_max="+pre_max_+"&pesos="+pesos_+"&ser1="+ser1_+"&ser2="+ser2_+"&ser3="+ser3_+"&ser4="+ser4_+"&conFoto="+cFoto_+"&ultSemana="+uSemana_+"&ultMes="+uMes_+"&prp_id="+prp_id+"&usr_id="+usr_id,
	                beakOffset: 3
	              }
	            ); 
	           
			  map.panTo(new GLatLng(marker2.getPoint().lat()+4, marker2.getPoint().lng()));
				map.setCenter(marker2.getPoint());
				
	        });
	        
	        
	        
	        //map.addOverlay(marker);
	        GEvent.addListener(marker2, "dblclick", function() {
				//readMap('provincias.xml');
	        	map.panTo(new GLatLng(marker2.getPoint().lat(), marker2.getPoint().lng()), map.getZoom()+2);
	        });
	        GEvent.addListener(marker2, "mouseover", function() {
				//marker.setImage("marker.png");
				//marker.openInfoWindowHtml(name);
				showTooltip(marker2);
	        });
	        GEvent.addListener(marker2, "mouseout", function() {
				//marker.setImage("coldmarker.png");
				tooltip.style.visibility="hidden"
	        });
	       gmarkers2[k] = marker2;
	       vectorPropiedades[k] = prp_id + '-' + usr_id;
	       k++;
        return marker2;
      }
      
      
      
	/* FUNCIONES DE TOOP TIP */
	function showTooltip(marker) {
		tooltip.innerHTML = marker.tooltip;
		var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom());
		var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
		var anchor=marker.getIcon().iconAnchor;
		var width=marker.getIcon().iconSize.width;
		var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y)); 
		pos.apply(tooltip);
		tooltip.style.visibility="visible";
    }
    function mymouseover(i) {
        showTooltip(gmarkers[i])
    }
    function mymouseout() {
		tooltip.style.visibility="hidden";
    }
	var tooltip = document.createElement("div");
	document.getElementById("mapa_buscar").appendChild(tooltip);
	tooltip.style.visibility="hidden";
    /* FUNCIONES DE TOOP TIP */
	 
      //funcion de carga de XML
	  function readMap(url) {
        var request = GXmlHttp.create();
        request.open("GET", url, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            var xmlDoc = GXml.parse(request.responseText);
            var markers = xmlDoc.documentElement.getElementsByTagName("provincia");
            map.getInfoWindow().hide();
            map.clearOverlays();            
			for (var i = 0; i < markers.length; i++) {
				var lat = parseFloat(markers[i].getAttribute("lat"));
				var lng = parseFloat(markers[i].getAttribute("lng"));
				var point = new GLatLng(lat,lng);
				var html = GXml.value(markers[i].getElementsByTagName("infowindow")[0]);
				var label = markers[i].getAttribute("pro_desc");
				var pro_id = markers[i].getAttribute("pro_id");
				var marker = createMarker(point,label,html,pro_id);
				map.addOverlay(marker);
			}
    	    select_html_prov += '</select>';
	        document.getElementById("selection").innerHTML = select_html_prov;
	        
          }
        }
        request.send(null);
      }
      
       //funcion de carga de XML localidades
	  function readLoc(url) {
        var request = GXmlHttp.create();
        request.open("GET", url, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            var xmlDoc = GXml.parse(request.responseText);
            var locs = xmlDoc.documentElement.getElementsByTagName("localidad");
           // map.getInfoWindow().hide();
           // map.clearOverlays();            
			for (var i = 0; i < locs.length; i++) {
				select_html_loc += '<option value=' + locs[i].getAttribute("loc_id") + '> ' + locs[i].getAttribute("loc_desc") + '</option>';
				latitudesLoc[locs[i].getAttribute("loc_id")]=locs[i].getAttribute("loc_lat")+'*'+locs[i].getAttribute("loc_lng");
			}
    	    select_html_loc += '</select>';
	        document.getElementById("sel_loc").innerHTML = select_html_loc;
	        
          }
        }
        request.send(null);
        
      }
      
       //funcion de carga de XML tipo_const
	  function readTip(url) {
        var request = GXmlHttp.create();
        request.open("GET", url, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            var xmlDoc = GXml.parse(request.responseText);
            var tips = xmlDoc.documentElement.getElementsByTagName("tipo_const");
           // map.getInfoWindow().hide();
           // map.clearOverlays(); 
                
			for (var i = 0; i < tips.length; i++) {
				select_html_tip += '<option value=' + tips[i].getAttribute("tip_id") + '> ' + tips[i].getAttribute("tip_desc") + '</option>';
			}
    	    select_html_tip += '</select>';
    	    
	        document.getElementById("sel_tip").innerHTML = select_html_tip;
	        
          }
        }
        request.send(null);
        
      }
	  
       //funcion de carga de XML tipo_const
	  function readCon(url) {
        var request = GXmlHttp.create();
        request.open("GET", url, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            var xmlDoc = GXml.parse(request.responseText);
            var conds = xmlDoc.documentElement.getElementsByTagName("condicion");
           // map.getInfoWindow().hide();
           // map.clearOverlays();            
			for (var i = 0; i < conds.length; i++) {
				select_html_con += '<option value=' + conds[i].getAttribute("con_id") + '>' + conds[i].getAttribute("con_desc") + '</option>';
			}
    	    select_html_con += '</select>';
	        document.getElementById("sel_con").innerHTML = select_html_con;
	        
          }
        }
        request.send(null);
        
      }
      
      function leerPropiedades() {
      	
      	
      	for(k=0;k < gmarkers2.length;k++){
      		gmarkers2[k].hide();
      	}
      		
      	var request = GXmlHttp.create();
        pro=document.getElementById("prov");
        loc=document.getElementById("loc_id");
        tip=document.getElementById("tip_id");
        con=document.getElementById("con_id");
        pre_mi=document.getElementById("pre_min");
        pre_ma=document.getElementById("pre_max");
        mon=document.getElementById("pesos");
        s1=document.getElementById("ser1");
        s2=document.getElementById("ser2");
        s3=document.getElementById("ser3");
        s4=document.getElementById("ser4");
        cFoto=document.getElementById("conFoto");
        uSemana=document.getElementById("ultSemana");
        uMes=document.getElementById("ultMes");
       
        //alert(con[con.options.selectedIndex].value)
    	con_id_=con[con.options.selectedIndex].value;
    	pro_id_=pro[pro.options.selectedIndex].value;
    	loc_id_=loc[loc.selectedIndex].value;
    	tip_id_=tip[tip.selectedIndex].value;
    	pre_min_=pre_mi[pre_mi.selectedIndex].value;
    	pre_max_=pre_ma[pre_ma.selectedIndex].value;
    	
    	ser1_=s1[s1.selectedIndex].value;
    	ser2_=s2[s2.selectedIndex].value;
    	ser3_=s3[s3.selectedIndex].value;
    	ser4_=s4[s4.selectedIndex].value;
    	
    	cFoto_="";
    	uMes_="";
    	uSemana_="";
    	
    	if(cFoto.checked){
    		cFoto_=cFoto.value;
    	}
    	if(uMes.checked){
    		uMes_=uMes.value;
    	}
    	if(uSemana.checked){
    		uSemana_=uSemana.value;
    	}
    	
    	if(mon.checked)
    		pesos_=1;
    	else
    		pesos_=2;
        
    		
    	dir="/xml_maps/propiedades.xml.php?pro_id="+pro_id_+"&loc_id="+loc_id_+"&tip_id="+tip_id_+"&con_id="+con_id_+"&pre_min="+pre_min_+"&pre_max="+pre_max_+"&pesos="+pesos_+"&ser1="+ser1_+"&ser2="+ser2_+"&ser3="+ser3_+"&ser4="+ser4_+"&conFoto="+cFoto_+"&ultSemana="+uSemana_+"&ultMes="+uMes_;
    //	dir="/xml_maps/propiedades.xml";
        
        request.open("GET", dir, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            var xmlDoc = GXml.parse(request.responseText);
            var markers2 = xmlDoc.documentElement.getElementsByTagName("propiedad");
             
			for (var i = 0; i < markers2.length; i++) {
				
				var lat = parseFloat(markers2[i].getAttribute("prp_lat"));
				var lng = parseFloat(markers2[i].getAttribute("prp_lng"));
				var point = new GLatLng(lat,lng);
				
				var prp_id = markers2[i].getAttribute("prp_id");
				var usr_id = markers2[i].getAttribute("usr_id");
				var pro_id = markers2[i].getAttribute("pro_id");
				var prp_desc = markers2[i].getAttribute("prp_desc");
				var con_id = markers2[i].getAttribute("con_id");
				
				var marker2 = createMarker2(point,prp_id,usr_id,pro_id,prp_desc,con_id);
				map.addOverlay(marker2);
				
			}
    	            
          }
      	}
        request.send(null);
      	
      }
      
      
      readMap('/xml_maps/provincias.xml.php');
	  readLoc('/xml_maps/localidades.xml.php');
	  readTip('/xml_maps/tipo_const.xml.php');
	  readCon('/xml_maps/condiciones.xml.php');
	  
	  
		//eventos del mapa

		GEvent.addListener(map, "moveend", function() {
			var center = map.getCenter();
			//document.getElementById("message").innerHTML = center.toString();
		});
		
	}
}

function volverBusqueda(pro_vb,pro_lat,pro_lng,loc_vb,tip_vb,con_vb,pre_min_vb,pre_max_vb,pesos_vb,ser1_vb,ser2_vb,ser3_vb,ser4_vb,cFoto_vb,uMes_vb,uSemana_vb,prp_dom_vb){
	volverBus=1;
	
	
	if (GBrowserIsCompatible()) {
      var select_html_prov = '<select onChange="handleSelected(this)"  name="pro_id" id="prov" style="width:118px;background-color:#FFFFFF;">';
      var select_html_loc =  '<select onChange="handleSelected(this)"  name="loc_id" id="loc_id" style="width:118px;background-color:#FFFFFF;"><option value="0">Localidad</option>';
      var select_html_tip =  '<select onChange="handleSelected(this)"  name="tip_id" id="tip_id" style="width:118px;background-color:#FFFFFF;"><option value="0">Inmueble</option>';
      var select_html_con =  '<select onChange="handleSelected(this)"  name="con_id" id="con_id" style="width:118px;background-color:#FFFFFF;"><option value="0">Condicion</option>';
		//mapa
		map = new GMap2(document.getElementById("mapa_buscar"));
		map.setCenter(new GLatLng(pro_lat, pro_lng), 14);
		map.disableDoubleClickZoom();
   //   map.removeMapType(G_HYBRID_MAP);
        map.removeMapType(G_SATELLITE_MAP);
        map.addControl(new GMapTypeControl());
//      map.addControl(new GLargeMapControl());
		map.addControl(new GSmallMapControl());
		
//      map.addControl(new GScaleControl());
//      map.addControl(new GOverviewMapControl());

		///icono venta
		var baseIconVta = new GIcon();
		baseIconVta.iconSize = new GSize(20, 57);
		baseIconVta.iconAnchor = new GPoint(10, 8);
		baseIconVta.infoWindowAnchor = new GPoint(8, 5);
		baseIconVta.infoShadowAnchor = new GPoint(8, 5);
		baseIconVta.image = "/images/icono_00_vta.png";
		
		//icono alquiler
		var baseIconAlq = new GIcon();
		baseIconAlq.iconSize = new GSize(20, 57);
		baseIconAlq.iconAnchor = new GPoint(10, 8);
		baseIconAlq.infoWindowAnchor = new GPoint(8, 5);
		baseIconAlq.infoShadowAnchor = new GPoint(8, 5);
		baseIconAlq.image = "/images/icono_00_alq.png";
		
		
		
		var baseIcon2 = new GIcon();
		baseIcon2.iconSize = new GSize(18, 17);
		baseIcon2.iconAnchor = new GPoint(10, 8);
		baseIcon2.infoWindowAnchor = new GPoint(8, 5);
		baseIcon2.infoShadowAnchor = new GPoint(8, 5);
		baseIcon2.image= "/images/icono_01.gif";
	
		//funcion de crear iconos
		//**********************************************
		//***CREAMOS MARKER PRINCIPAL CON LA VENTANA****
		//**********************************************
		
		var letteredIcon = new GIcon(baseIcon2);
		markerOptions = { icon:letteredIcon};
		var marker = new GMarker( new GLatLng(pro_lat,pro_lng) , markerOptions);
		marker.tooltip = '<div class="tooltip">Ver Inmuebles</div>';
		
		
	        
	     GEvent.addListener(marker, "click", function() {
			
        	
            
			obj_prov=document.getElementById('prov');
        	
			for(j=0;j<obj_prov.length;j++){
        		if(obj_prov[j].value==pro_vb){
        			index=j;
        			break;
        		}
			}
        	
			obj_prov[j].selected=index;        	       	
			
			if(ultimaProv==0){
				ultimaProv=pro_vb;
			}
			
			cambiarLocs();
			
			//loc=document.getElementById("loc_id");
            tip=document.getElementById("tip_id");
            con=document.getElementById("con_id");
            pre_mi=document.getElementById("pre_min");
            pre_ma=document.getElementById("pre_max");
            mon=document.getElementById("pesos");
            mon2=document.getElementById("pesos2");
            
            s1=document.getElementById("ser1");
            s2=document.getElementById("ser2");
            s3=document.getElementById("ser3");
            s4=document.getElementById("ser4");
            cFoto=document.getElementById("conFoto");
            uSemana=document.getElementById("ultSemana");
            uMes=document.getElementById("ultMes");
            
            //alert(con[con.options.selectedIndex].value)
        	con_id_=con[con.options.selectedIndex].value;
        	loc_id_=0;
        	tip_id_=tip[tip.selectedIndex].value;
        	pre_min_=pre_mi[pre_mi.selectedIndex].value;
        	pre_max_=pre_ma[pre_ma.selectedIndex].value;
        	
        	ser1_=s1[s1.selectedIndex].value;
        	ser2_=s2[s2.selectedIndex].value;
        	ser3_=s3[s3.selectedIndex].value;
        	ser4_=s4[s4.selectedIndex].value;
        	
        	cFoto_="";
        	uMes_="";
        	uSemana_="";
        	
        	if(cFoto.checked){
        		cFoto_=cFoto.value;
        	}
        	if(uMes.checked){
        		uMes_=uMes.value;
        	}
        	if(uSemana.checked){
        		uSemana_=uSemana.value;
        	}
        	
        	if(mon.checked)
        		pesos_=1;
        	else if(mon2.checked)
        		pesos_=2;
			else
				pesos_="";
        	
           marker.openExtInfoWindow(
            	map,
              "custom_info_window_red",
              "<div id='custom_info_window_red_precarga'>cargando...</div>",
              {
                ajaxUrl: "http://"+dominioLocal+"/es/propiedades/infoWindow.html?pro_id="+ultimaProv+"&loc_id="+loc_id_+"&tip_id="+tip_id_+"&con_id="+con_id_+"&pre_min="+pre_min_+"&pre_max="+pre_max_+"&pesos="+pesos_+"&ser1="+ser1_+"&ser2="+ser2_+"&ser3="+ser3_+"&ser4="+ser4_+"&conFoto="+cFoto_+"&ultSemana="+uSemana_+"&ultMes="+uMes_+"&pro_lat="+marker.getPoint().lat()+"&pro_lng="+marker.getPoint().lng()+"&prp_dom="+prp_dom_vb,
                beakOffset: 3
              }
            ); 
           
			map.setCenter(marker.getPoint(), 14);
			leerPropiedades();
			
		 });

		 GEvent.addListener(marker, "dragend", function() {
			
        	
            
			obj_prov=document.getElementById('prov');
        	
			for(j=0;j<obj_prov.length;j++){
        		if(obj_prov[j].value==pro_vb){
        			index=j;
        			break;
        		}
			}
        	
			if(ultimaProv==0){
				ultimaProv=pro_vb;
			}
			
			obj_prov[j].selected=index;        	       	
			
			loc=document.getElementById("loc_id");
            tip=document.getElementById("tip_id");
            con=document.getElementById("con_id");
            pre_mi=document.getElementById("pre_min");
            pre_ma=document.getElementById("pre_max");
            mon=document.getElementById("pesos");
            mon2=document.getElementById("pesos2");
            
            s1=document.getElementById("ser1");
            s2=document.getElementById("ser2");
            s3=document.getElementById("ser3");
            s4=document.getElementById("ser4");
            cFoto=document.getElementById("conFoto");
            uSemana=document.getElementById("ultSemana");
            uMes=document.getElementById("ultMes");
            
            //alert(con[con.options.selectedIndex].value)
        	con_id_=con[con.options.selectedIndex].value;
        	loc_id_=loc[loc.selectedIndex].value;
        	tip_id_=tip[tip.selectedIndex].value;
        	pre_min_=pre_mi[pre_mi.selectedIndex].value;
        	pre_max_=pre_ma[pre_ma.selectedIndex].value;
        	
        	ser1_=s1[s1.selectedIndex].value;
        	ser2_=s2[s2.selectedIndex].value;
        	ser3_=s3[s3.selectedIndex].value;
        	ser4_=s4[s4.selectedIndex].value;
        	
        	cFoto_="";
        	uMes_="";
        	uSemana_="";
        	
        	if(cFoto.checked){
        		cFoto_=cFoto.value;
        	}
        	if(uMes.checked){
        		uMes_=uMes.value;
        	}
        	if(uSemana.checked){
        		uSemana_=uSemana.value;
        	}
        	
        	if(mon.checked)
        		pesos_=1;
        	else if(mon2.checked)
        		pesos_=2;
			else
				pesos_="";
        	
           marker.openExtInfoWindow(
            	map,
              "custom_info_window_red",
              "<div id='custom_info_window_red_precarga'>cargando...</div>",
              {
                ajaxUrl: "http://"+dominioLocal+"/es/propiedades/infoWindow.html?pro_id="+ultimaProv+"&loc_id="+loc_id_+"&tip_id="+tip_id_+"&con_id="+con_id_+"&pre_min="+pre_min_+"&pre_max="+pre_max_+"&pesos="+pesos_+"&ser1="+ser1_+"&ser2="+ser2_+"&ser3="+ser3_+"&ser4="+ser4_+"&conFoto="+cFoto_+"&ultSemana="+uSemana_+"&ultMes="+uMes_+"&base="+pagina+"&pro_lat="+marker.getPoint().lat()+"&pro_lng="+marker.getPoint().lng()+"&prp_dom="+prp_dom_vb,
                beakOffset: 3
              }
            ); 
           
			if(loc_id_>0){
			//centrar por localidad
				if(latitudesLoc[loc_id_]){
					cad=latitudesLoc[loc_id_].split('*');
					marker.setLatLng(new GLatLng(cad[0],cad[1]))
					map.panTo(new GLatLng(cad[0],cad[1]));
					map.setCenter(new GLatLng(cad[0],cad[1]), 14);
				}else{
					map.setCenter(marker.getPoint(), 14);
				}
			}else{
				map.setCenter(marker.getPoint(), 14);
			}
			leerPropiedades();
			
        });     
        
        GEvent.addListener(marker, "mouseover", function() {
			//marker.setImage("marker.png");
			//marker.openInfoWindowHtml(name);
			showTooltip(marker);
        });
        GEvent.addListener(marker, "mouseout", function() {
			//marker.setImage("coldmarker.png");
			tooltip.style.visibility="hidden"
        });
        
        map.addOverlay(marker);
		
        gmarkers[0]=marker;
     
	    marker.openExtInfoWindow(
            	map,
              "custom_info_window_red",
              "<div id='custom_info_window_red_precarga'>cargando...</div>",
              {
                ajaxUrl: "http://"+dominioLocal+"/es/propiedades/infoWindow.html?pro_id="+pro_vb+"&loc_id="+loc_vb+"&con_id="+con_vb+"&tip_id="+tip_vb+"&pre_min="+pre_min_vb+"&pre_max="+pre_max_vb+"&pesos="+pesos_vb+"&ser1="+ser1_vb+"&ser2="+ser2_vb+"&ser3="+ser3_vb+"&ser4="+ser4_vb+"&cFoto="+cFoto_vb+"&ultSemana="+uSemana_vb+"&ultMes="+uMes_vb+"&pro_lat="+pro_lat+"&pro_lng="+pro_lng+"&prp_dom="+prp_dom_vb,
                beakOffset: 3
              }
            );
		//**********************************************
		//****************** FINAL  ********************
		//**********************************************
		
     function createMarker2(point,prp_id,usr_id,pro_id,prp_desc,con_id) {
		
        	
	      	if(con_id==2){	
        		var letteredIcon = new GIcon(baseIconAlq);
        	}else if(con_id==1){
        		var letteredIcon = new GIcon(baseIconVta);
        	}
			markerOptions = { icon:letteredIcon};
			
			var marker2 = new GMarker(point, markerOptions);
			marker2.tooltip = '<div class="tooltip">'+
			
			prp_desc+'</div>';
			
	        GEvent.addListener(marker2, "click", function() {
			obj_prov=document.getElementById('prov');
        	
			for(j=0;j<obj_prov.length;j++){
        		if(obj_prov[j].value==pro_vb){
        			index=j;
        			break;
        		}
			}
        	
			obj_prov[j].selected=index;        	       	
			
			loc=document.getElementById("loc_id");
            tip=document.getElementById("tip_id");
            con=document.getElementById("con_id");
            pre_mi=document.getElementById("pre_min");
            pre_ma=document.getElementById("pre_max");
            mon=document.getElementById("pesos");
            mon2=document.getElementById("pesos2");
            
            s1=document.getElementById("ser1");
            s2=document.getElementById("ser2");
            s3=document.getElementById("ser3");
            s4=document.getElementById("ser4");
            cFoto=document.getElementById("conFoto");
            uSemana=document.getElementById("ultSemana");
            uMes=document.getElementById("ultMes");
            
            //alert(con[con.options.selectedIndex].value)
        	con_id_=con[con.options.selectedIndex].value;
        	loc_id_=loc[loc.selectedIndex].value;
        	tip_id_=tip[tip.selectedIndex].value;
        	pre_min_=pre_mi[pre_mi.selectedIndex].value;
        	pre_max_=pre_ma[pre_ma.selectedIndex].value;
        	
        	ser1_=s1[s1.selectedIndex].value;
        	ser2_=s2[s2.selectedIndex].value;
        	ser3_=s3[s3.selectedIndex].value;
        	ser4_=s4[s4.selectedIndex].value;
        	
        	cFoto_="";
        	uMes_="";
        	uSemana_="";
        	
        	if(cFoto.checked){
        		cFoto_=cFoto.value;
        	}
        	if(uMes.checked){
        		uMes_=uMes.value;
        	}
        	if(uSemana.checked){
        		uSemana_=uSemana.value;
        	}
        	
        	if(mon.checked)
        		pesos_=1;
        	else if(mon2.checked)
        		pesos_=2;
			else
				pesos_="";	
					        	
	          marker2.openExtInfoWindow(
	            	map,
	              "custom_info_window_red",
	              "<div id='custom_info_window_red_precarga'>cargando...</div>",
	              {
	                ajaxUrl: "http://"+dominioLocal+"/es/propiedades/infoWindowFicha.html?pro_id="+pro_vb+"&loc_id="+loc_vb+"&con_id="+con_vb+"&tip_id="+tip_vb+"&pre_min="+pre_min_vb+"&pre_max="+pre_max_vb+"&pesos="+pesos_vb+"&ser1="+ser1_vb+"&ser2="+ser2_vb+"&ser3="+ser3_vb+"&ser4="+ser4_vb+"&cFoto="+cFoto_vb+"&ultSemana="+uSemana_vb+"&ultMes="+uMes_vb+"&pro_lat="+pro_lat+"&pro_lng="+pro_lng+"&prp_dom="+prp_dom_vb+"&prp_id="+prp_id+"&usr_id="+usr_id,
	                beakOffset: 3
	              }
	            ); 
	           
			//  map.panTo(new GLatLng(marker.getPoint().lat()+4, marker.getPoint().lng()));
				map.setCenter(marker2.getPoint(), 14);
				
	        });
	        
	        
	        
	        //map.addOverlay(marker);
	        GEvent.addListener(marker2, "dblclick", function() {
				//readMap('provincias.xml');
	        	map.panTo(new GLatLng(marker2.getPoint().lat(), marker2.getPoint().lng()), map.getZoom()+2);
	        });
	        GEvent.addListener(marker2, "mouseover", function() {
				//marker.setImage("marker.png");
				//marker.openInfoWindowHtml(name);
				showTooltip(marker2);
	        });
	        GEvent.addListener(marker2, "mouseout", function() {
				//marker.setImage("coldmarker.png");
				tooltip.style.visibility="hidden"
	        });
	       gmarkers2[k] = marker2;
	       vectorPropiedades[k] = prp_id + '-' + usr_id;
	       k++;
        return marker2;
      }

      
      
   
	
	function showTooltip(marker) {
		tooltip.innerHTML = marker.tooltip;
		var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom());
		var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
		var anchor=marker.getIcon().iconAnchor;
		var width=marker.getIcon().iconSize.width;
		var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y)); 
		pos.apply(tooltip);
		tooltip.style.visibility="visible";
    }
    function mymouseover(i) {
        showTooltip(gmarkers[i])
    }
    function mymouseout() {
		tooltip.style.visibility="hidden";
    }
	var tooltip = document.createElement("div");
	document.getElementById("mapa_buscar").appendChild(tooltip);
	tooltip.style.visibility="hidden";

	 
      //funcion de carga de XML
	  function readMap(url) {
        var request = GXmlHttp.create();
        request.open("GET", url, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            var xmlDoc = GXml.parse(request.responseText);
            var markers = xmlDoc.documentElement.getElementsByTagName("provincia");
            map.getInfoWindow().hide();
            //map.clearOverlays();            
			for (var i = 0; i < markers.length; i++) {
				/*
				var lat = parseFloat(markers[i].getAttribute("lat"));
				var lng = parseFloat(markers[i].getAttribute("lng"));
				var point = new GLatLng(lat,lng);
				var html = GXml.value(markers[i].getElementsByTagName("infowindow")[0]);
				var label = markers[i].getAttribute("pro_desc");*/
				 pro_id = markers[i].getAttribute("pro_id");
				
				  if(pro_id==pro_vb){
				      cad_selected="selected";	
				  }else{
				      cad_selected="";		
				  }
				
				select_html_prov += '<option value=' + markers[i].getAttribute("pro_id") + ' '+cad_selected+'> ' + markers[i].getAttribute("pro_desc") + '</option>';
			}
    	    select_html_prov += '</select>';
	        document.getElementById("selection").innerHTML = select_html_prov;
	        
          }
        }
        request.send(null);
      }
      
       //funcion de carga de XML localidades
	  function readLoc(url) {
        var request = GXmlHttp.create();
        request.open("GET", url, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
          	var xmlDoc = GXml.parse(request.responseText);
            var locs = xmlDoc.documentElement.getElementsByTagName("localidad");
             map.getInfoWindow().hide();
            
			for (var i = 0; i < locs.length; i++) {
				
				if(loc_vb==locs[i].getAttribute("loc_id")){
					select_html_loc += '<option value=' + locs[i].getAttribute("loc_id") + ' selected> ' + locs[i].getAttribute("loc_desc") + '</option>';					
				}else{
					select_html_loc += '<option value=' + locs[i].getAttribute("loc_id") + '> ' + locs[i].getAttribute("loc_desc") + '</option>';
				}
				latitudesLoc[locs[i].getAttribute("loc_id")]=locs[i].getAttribute("loc_lat")+'*'+locs[i].getAttribute("loc_lng");
					
			}
    	    select_html_loc += '</select>';
	        document.getElementById("sel_loc").innerHTML = select_html_loc;
	        
          }
        }
        request.send(null);
        
      }
      
       //funcion de carga de XML tipo_const
	  function readTip(url) {
        var request = GXmlHttp.create();
        request.open("GET", url, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            var xmlDoc = GXml.parse(request.responseText);
            var tips = xmlDoc.documentElement.getElementsByTagName("tipo_const");
           // map.getInfoWindow().hide();
           // map.clearOverlays(); 
                
			for (var i = 0; i < tips.length; i++) {
				if(tip_vb==tips[i].getAttribute("tip_id")){
					select_html_tip += '<option value=' + tips[i].getAttribute("tip_id") + ' selected> ' + tips[i].getAttribute("tip_desc") + '</option>';
				}else{
					select_html_tip += '<option value=' + tips[i].getAttribute("tip_id") + '> ' + tips[i].getAttribute("tip_desc") + '</option>';					
				}			
			}
    	    select_html_tip += '</select>';
    	    
	        document.getElementById("sel_tip").innerHTML = select_html_tip;
	        
          }
        }
        request.send(null);
        
      }
	  
       //funcion de carga de XML tipo_const
	  function readCon(url) {
        var request = GXmlHttp.create();
        request.open("GET", url, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            var xmlDoc = GXml.parse(request.responseText);
            var conds = xmlDoc.documentElement.getElementsByTagName("condicion");
           // map.getInfoWindow().hide();
           // map.clearOverlays();            
			for (var i = 0; i < conds.length; i++) {
				if(con_vb==conds[i].getAttribute("con_id")){
					select_html_con += '<option value=' + conds[i].getAttribute("con_id") + ' selected>' + conds[i].getAttribute("con_desc") + '</option>';
				}else{
					select_html_con += '<option value=' + conds[i].getAttribute("con_id") + '>' + conds[i].getAttribute("con_desc") + '</option>';
				}
			}
    	    select_html_con += '</select>';
	        document.getElementById("sel_con").innerHTML = select_html_con;
	        
          }
        }
        request.send(null);
        
      }
      
      readMap('/xml_maps/provincias.xml.php');
	  readLoc('/xml_maps/localidades.xml.php?pro_id='+pro_vb);
	  readTip('/xml_maps/tipo_const.xml.php');
	  readCon('/xml_maps/condiciones.xml.php');
	    
	  //*************************************************************//
	  //*************LECTURA DE PROPIEDADES INICIAL******************
	  //*************************************************************
	  	//alert(document.getElementById("con_id"))
	    var request = GXmlHttp.create();
       
    	dir="/xml_maps/propiedades.xml.php?pro_id="+pro_vb+"&loc_id="+loc_vb+"&con_id="+con_vb+"&tip_id="+tip_vb+"&pre_min="+pre_min_vb+"&pre_max="+pre_max_vb+"&pesos="+pesos_vb+"&ser1="+ser1_vb+"&ser2="+ser2_vb+"&ser3="+ser3_vb+"&ser4="+ser4_vb+"&cFoto="+cFoto_vb+"&ultSemana="+uSemana_vb+"&ultMes="+uMes_vb;
        
        request.open("GET", dir, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            var xmlDoc = GXml.parse(request.responseText);
            var markers2 = xmlDoc.documentElement.getElementsByTagName("propiedad");
             
			for (var i = 0; i < markers2.length; i++) {
				
				var lat = parseFloat(markers2[i].getAttribute("prp_lat"));
				var lng = parseFloat(markers2[i].getAttribute("prp_lng"));
				var point = new GLatLng(lat,lng);
				
				var prp_id = markers2[i].getAttribute("prp_id");
				var usr_id = markers2[i].getAttribute("usr_id");
				var pro_id = markers2[i].getAttribute("pro_id");
				var prp_desc = markers2[i].getAttribute("prp_desc");
				var con_id = markers2[i].getAttribute("con_id");
				
				var marker2 = createMarker2(point,prp_id,usr_id,pro_id,prp_desc,con_id);
				map.addOverlay(marker2);
				
			}
    	            
          }
      	}
        request.send(null);
	
	  
	  
	   //*************************************************************//
	  //*************FIN LECTURA DE PROPIEDADES INICIAL******************
	  //*************************************************************
      
	  function leerPropiedades() {
      	
      	for(k=0;k < gmarkers2.length;k++){
      		gmarkers2[k].hide();
      	}
      		
      	var request = GXmlHttp.create();
        pro=document.getElementById("prov");
        loc=document.getElementById("loc_id");
        tip=document.getElementById("tip_id");
        con=document.getElementById("con_id");
        pre_mi=document.getElementById("pre_min");
        pre_ma=document.getElementById("pre_max");
        mon=document.getElementById("pesos");
        s1=document.getElementById("ser1");
        s2=document.getElementById("ser2");
        s3=document.getElementById("ser3");
        s4=document.getElementById("ser4");
        cFoto=document.getElementById("conFoto");
        uSemana=document.getElementById("ultSemana");
        uMes=document.getElementById("ultMes");
       
        //alert(con[con.options.selectedIndex].value)
    	con_id_=con[con.options.selectedIndex].value;
    	pro_id_=pro[pro.options.selectedIndex].value;
    	loc_id_=loc[loc.selectedIndex].value;
    	tip_id_=tip[tip.selectedIndex].value;
    	pre_min_=pre_mi[pre_mi.selectedIndex].value;
    	pre_max_=pre_ma[pre_ma.selectedIndex].value;
    	
    	ser1_=s1[s1.selectedIndex].value;
    	ser2_=s2[s2.selectedIndex].value;
    	ser3_=s3[s3.selectedIndex].value;
    	ser4_=s4[s4.selectedIndex].value;
    	
    	cFoto_="";
    	uMes_="";
    	uSemana_="";
    	
    	if(cFoto.checked){
    		cFoto_=cFoto.value;
    	}
    	if(uMes.checked){
    		uMes_=uMes.value;
    	}
    	if(uSemana.checked){
    		uSemana_=uSemana.value;
    	}
    	
    	if(mon.checked)
    		pesos_=1;
    	else
    		pesos_=2;
        
    	
    		
    	dir="/xml_maps/propiedades.xml.php?pro_id="+pro_id_+"&loc_id="+loc_id_+"&tip_id="+tip_id_+"&con_id="+con_id_+"&pre_min="+pre_min_+"&pre_max="+pre_max_+"&pesos="+pesos_+"&ser1="+ser1_+"&ser2="+ser2_+"&ser3="+ser3_+"&ser4="+ser4_+"&conFoto="+cFoto_+"&ultSemana="+uSemana_+"&ultMes="+uMes_;
        
        request.open("GET", dir, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            var xmlDoc = GXml.parse(request.responseText);
            var markers2 = xmlDoc.documentElement.getElementsByTagName("propiedad");
             
			for (var i = 0; i < markers2.length; i++) {
				
				var lat = parseFloat(markers2[i].getAttribute("prp_lat"));
				var lng = parseFloat(markers2[i].getAttribute("prp_lng"));
				var point = new GLatLng(lat,lng);
				
				var prp_id = markers2[i].getAttribute("prp_id");
				var usr_id = markers2[i].getAttribute("usr_id");
				var pro_id = markers2[i].getAttribute("pro_id");
				var prp_desc = markers2[i].getAttribute("prp_desc");
				var con_id = markers2[i].getAttribute("con_id");
				
				
				var marker2 = createMarker2(point,prp_id,usr_id,pro_id,prp_desc,con_id);
				map.addOverlay(marker2);
				
			}
    	            
          }
      	}
        request.send(null);
      	
      }
     
	  
	  
		//eventos del mapa

		GEvent.addListener(map, "moveend", function() {
			var center = map.getCenter();
			//document.getElementById("message").innerHTML = center.toString();
		});
		
	 
	
	}
}

	  //funcion para eventos ajenos al mapa
      function handleSelected(obj){
      	
      		prov_id=document.getElementById("prov");
      		
      		
       		if(obj.name=='con_id'){
      			cambiarPrecios();
      		}
      		
      		if(prov_id.selectedIndex>=0)	
	        {
	          if(!volverBus){	
		          if(obj.name=='pro_id'){
		          	GEvent.trigger(gmarkers[prov_id.selectedIndex],"click");
		          }else{
		          	GEvent.trigger(gmarkers[prov_id.selectedIndex],"dragend");
		          }
	          }else{
	          		ultimaProv=prov_id[prov_id.selectedIndex].value;
		          if(obj.name=='pro_id'){
		           	GEvent.trigger(gmarkers[0],"click");
		          }else{
		          
		          	GEvent.trigger(gmarkers[0],"dragend");
		          }
	          	
	          }    
		          
	        }
	        else 
	        {
	          map.closeInfoWindow();
	        }
	        
	        //leer todas las variables
	        
	        loc=document.getElementById("loc_id");
            tip=document.getElementById("tip_id");
            con=document.getElementById("con_id");
            pre_mi=document.getElementById("pre_min");
            pre_ma=document.getElementById("pre_max");
            mon=document.getElementById("pesos");
            s1=document.getElementById("ser1");
            s2=document.getElementById("ser2");
            s3=document.getElementById("ser3");
            s4=document.getElementById("ser4");
            cFoto=document.getElementById("conFoto");
            uSemana=document.getElementById("ultSemana");
            uMes=document.getElementById("ultMes");
            
            //alert(con[con.options.selectedIndex].value)
        	con_id_=con[con.options.selectedIndex].value;
        	loc_id_=loc[loc.selectedIndex].value;
        	tip_id_=tip[tip.selectedIndex].value;
        	pre_min_=pre_mi[pre_mi.selectedIndex].value;
        	pre_max_=pre_ma[pre_ma.selectedIndex].value;
        	
        	ser1_=s1[s1.selectedIndex].value;
        	ser2_=s2[s2.selectedIndex].value;
        	ser3_=s3[s3.selectedIndex].value;
        	ser4_=s4[s4.selectedIndex].value;
        	
        	cFoto_="";
        	uMes_="";
        	uSemana_="";
        	
        	if(cFoto.checked){
        		cFoto_=cFoto.value;
        	}
        	if(uMes.checked){
        		uMes_=uMes.value;
        	}
        	if(uSemana.checked){
        		uSemana_=uSemana.value;
        	}
        	
        	if(mon.checked)
        		pesos_=1;
        	else
        		pesos_=2;
	        
	        	//acutaliza cuerpo del sitio
	        /*	new Ajax.Updater(
						'cuerpo_principal', 
						'/es/propiedades/consultaGeneral.html?tipoListado=ajax', 
						{
						 asynchronous:		
										true, 
										evalScripts:false, 
										onComplete:function(request, json)
													{
															Element.hide('cargandoCuerpo');
															Element.show('cuerpo_principal')
													}, 
										onLoading:function(request, json){
															Element.show('cargandoCuerpo');
															Element.hide('cuerpo_principal')
													}
						}
					)
    */
      }
      
      
      
      
      function cambiarLocs(){
      	obj=document.getElementById("prov");
      	lc=document.getElementById("loc_id");
      	new Ajax.Updater(
						'sel_loc', 
						'/es/localidades/selectLocalidadesMap.html?loc_id='+lc[lc.selectedIndex].value+'&pro_id='+obj[obj.selectedIndex].value, 
						{
						 asynchronous:		
										false, 
										evalScripts:false, 
										onComplete:function(request, json)
													{
															Element.hide('cargandoLoc');
															Element.show('sel_loc')
													}, 
										onLoading:function(request, json){
															Element.show('cargandoLoc');
															Element.hide('sel_loc')
													}
						}
					)
      	
      }
      
       function cambiarPrecios(){
      	obj=document.getElementById("con_id");
      	new Ajax.Updater(
						'preciosBuscadorSimple', 
						'/es/propiedades/traerPrecios.html?con_id='+obj[obj.selectedIndex].value, 
						{
						 asynchronous:false, 
										evalScripts:false, 
										onComplete:function(request, json)
													{
															Element.hide('cargandoPreciosBuscadorSimple');
															Element.show('preciosBuscadorSimple')
													}, 
										onLoading:function(request, json){
															Element.show('cargandoPreciosBuscadorSimple');
															Element.hide('preciosBuscadorSimple')
													}
						}
					)
      	
      }
      
      function reubicarPropiedad(lat,lng){
		map.setCenter(new GLatLng(lat, lng), 4);
	 }
	 
	 function chequearMarkers(prp_id,usr_id,pag){
	 	indice=0;
	 	for(i=0;i<vectorPropiedades.length;i++){
	 		if(vectorPropiedades[i]==prp_id + '-' + usr_id){
	 			indice=i;
	 			break;
	 		}
	 	}
	 	
	 	if(indice!=0){
	 		pagina=pag;
	 		GEvent.trigger(gmarkers2[indice],"click");
	 	}else{
	 		return 1;
	 	}
	 }
	 
	
	 
      