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

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,query){
	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"));
		
            if(!pro_lat || !pro_lng){
                    pro_lat=-39.3309018;
                    pro_lng=-64.282339;
                    map.setCenter(new GLatLng(pro_lat,pro_lng), 7);
            }else{
                    map.setCenter(new GLatLng(pro_lat,pro_lng), 14);
            }
		
		
            map.disableDoubleClickZoom();
            map.removeMapType(G_SATELLITE_MAP);
            map.addControl(new GMapTypeControl());
	    map.addControl(new GSmallMapControl());

		///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('pro_id_query');
        	
			if(!pro_vb){
				pro_vb=0;
			}
			
			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_d=document.getElementById("pesos_d");
                mon_p=document.getElementById("pesos_p");
            
                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_p.checked)
        		pesos_=1;
        	else if(mon_d.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()+"&query="+query,
                        beakOffset: 3
                      }
                    );
           
        
			map.setCenter(marker.getPoint(), 14);
			leerPropiedades();
			
		 });

		 GEvent.addListener(marker, "dragend", function() {
			
        	
            
			obj_prov=document.getElementById('pro_id_query');
        	
			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_d=document.getElementById("pesos_d");
                        mon_p=document.getElementById("pesos_p");

                        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_p.checked)
                                pesos_=1;
                        else if(mon_d.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()+"&query="+query,
                            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+"&query="+query,
                beakOffset: 3
              }
            );
           
            
		//**********************************************
		//****************** FINAL  ********************
		//**********************************************
		
		//******************** FUNCION CREATE MARKER***************
		/********************************************************
		*******************************/
		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_d=document.getElementById("pesos_d");
	            mon_p=document.getElementById("pesos_p");
	            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");
	            
	        	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_p.checked)
	        		pesos_=1;
	        	else
	        		pesos_=2;
         
           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()+"&query="+query,
                beakOffset: 3
              }
            ); 
          
			map.setCenter(marker.getPoint(), 14);
			leerPropiedades();
			
        });
        
        GEvent.addListener(marker, "dragend", function() {
			
        	
            
			obj_prov=document.getElementById('pro_id_query');
        	
			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_d=document.getElementById("pesos_d");
            mon_p=document.getElementById("pesos_p");
            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_p.checked)
        		pesos_=1;
        	else
        		pesos_=2;
            //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()+"&query="+query,
                beakOffset: 3
              }
            ); 
           
		//
			leerPropiedades();
			
        });
        
        //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="";		
        }
		
        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 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('pro_id_query');
        	
			for(j=0;j<obj_prov.length;j++){
        		if(obj_prov[j].value==pro_id){
        			index=j;
        			break;
        		}
			}
        	
			//alert(pro_id)
			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_d=document.getElementById("pesos_d");
                        mon_p=document.getElementById("pesos_p");

                        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_p.checked)
                                pesos_=1;
                        else if(mon_d.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_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"));
				 point = new GLatLng(lat,lng);
				 html = GXml.value(markers[i].getElementsByTagName("infowindow")[0]);
				 label = markers[i].getAttribute("pro_desc");
				 pro = markers[i].getAttribute("pro_id");
				 marker = createMarker(point,label,html,pro);
				 map.addOverlay(marker);
				// pro_id = markers[i].getAttribute("pro_id");
				
				  if(pro==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="http://"+dominioLocal+"/es/buscar-propiedades.html?tipo_buscador=3&pesos="+pesos_vb+"&pro_id_query="+pro_vb+"&query="+query;
        
        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("pro_id_query");
        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_d=document.getElementById("pesos_d");
        mon_p=document.getElementById("pesos_p");
        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_p.checked)
    		pesos_=1;
    	else
    		pesos_=2;
        
    	
    		
    	dir="http://"+dominioLocal+"/es/buscar-propiedades.html?tipo_buscador=3&pesos="+pesos_vb+"&pro_id_query="+pro_vb+"&query="+query;
        
        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();
		});
		
	 
	 
	}
	
}
//alert("ee"+gmarkers)
	  //funcion para eventos ajenos al mapa
      function handleSelected(obj){
      		
      		prov_id=document.getElementById("pro_id_query");
      		
      		
       		if(obj.name=='con_id'){
      			cambiarPrecios();
      		}
      		
      		
      		
      		if(prov_id.selectedIndex>=0)	
	        {
	    
		          if(obj.name=='pro_id'){
		          
		          	GEvent.trigger(gmarkers[prov_id.selectedIndex],"click");
		          }else{
		          	GEvent.trigger(gmarkers[prov_id.selectedIndex],"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_d=document.getElementById("pesos_d");
            mon_p=document.getElementById("pesos_p");
            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_p.checked)
        		pesos_=1;
        	else
        		pesos_=2;
	        
	        	//acutaliza cuerpo del sitio
	       
      }
      
      
      
      
      function cambiarLocs(){
      	obj=document.getElementById("pro_id_query");
      	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;
	 	}
	 }
