 google.load("maps", "2");
 var map;
  var icon_l;
 

// Call this function when the page has been loaded
function initialize() 
{
	form = document.getElementById("form");
	map = new google.maps.Map2(document.getElementById("map"));
	  map.setCenter(new google.maps.LatLng(glat, glong), zoom);
	    GEvent.addListener(map,"click", function(overlay,point) {
	    	document.getElementById("glat").value = point.y;
	    	document.getElementById("glong").value = point.x;
	    	showPoint(point.y,point.x);
	    });

	    map.addControl(new GLargeMapControl());
	    map.addControl(new GMapTypeControl());

	icon_l = new GIcon(G_DEFAULT_ICON, site_location+"/images/icon_location.jpg") ;
	the_size = new GSize(27, 23);
	icon_l.iconSize = the_size;
	
	icon_l.shadow  = the_size;

	if(lglat!=0&&lglong!=0)
	{
		showPoint(lglat,lglong);
		
	}

}


function initialize_search() 
{
	
	map = new google.maps.Map2(document.getElementById("map"));
	map.setCenter(new google.maps.LatLng(glat, glong), zoom);
	 

	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	

	icon_l = new GIcon(G_DEFAULT_ICON, site_location+"/images/house_off16.png") ;
	the_size = new GSize(16, 16);
	icon_l.iconSize = the_size;
	
	icon_l.shadow  = the_size;
	
	
	icon_0 = new GIcon(G_DEFAULT_ICON, site_location+"/images/condo_off16.png") ;
	the_size = new GSize(16, 16);
	icon_0.iconSize = the_size;
	
	icon_0.shadow  = the_size;
	
	
	
	icon_l_1 = new GIcon(G_DEFAULT_ICON, site_location+"/images/house_on16.png") ;
	the_size = new GSize(16, 16);
	icon_l_1.iconSize = the_size;
	
	icon_l_1.shadow  = the_size;
	
	
	icon_0_0 = new GIcon(G_DEFAULT_ICON, site_location+"/images/condo_on16.png") ;
	the_size = new GSize(16, 16);
	icon_0_0.iconSize = the_size;
	
	icon_0_0.shadow  = the_size;
	
	
	
	

	if(lglat!=0&&lglong!=0)
	{
		showPoint(lglat,lglong);

		
	}

}

showPoint = function(lat,long){
	if(lat && long){
	  	la = new GLatLng(lat,long);
	    map.clearOverlays();
		
		marker = new GMarker(la, icon_l);
		
    	map.addOverlay(marker);
	}
	
}

function createInfoMarker(point, address,icon_type) {

	if(icon_type==0)
	{
		 var marker = new GMarker(point, icon_0);
	}
	else
	{
  	 var marker = new GMarker(point, icon_l);
	}

   GEvent.addListener(marker, "click",

      function() {

         marker.openInfoWindowHtml(address);

      }

   );
   
  
   
     GEvent.addListener(marker, "mouseover",

      function() {

        
         if(icon_type==0)
			{
				 marker.setImage(site_location+"/images/condo_on16.png");
			}
			else
			{
		  	  marker.setImage(site_location+"/images/house_on16.png");
			}

      }

   );
   
    GEvent.addListener(marker, "mouseout",

      function() {

        
         if(icon_type==0)
			{
				 marker.setImage(site_location+"/images/condo_off16.png");
			}
			else
			{
		  	  marker.setImage(site_location+"/images/house_off16.png");
			}

      }

   );
   

  return marker;

}


showPlace = function(lat,long,address,icon_type){
	if(lat && long){
	  	la = new GLatLng(lat,long);
		var marker = createInfoMarker(la, address,icon_type);
		
    	map.addOverlay(marker);
	}
}

showPlaceAddress = function(list_address,address){

	
	
	geocoder = new GClientGeocoder();
	geocoder.getLatLng(list_address, function (latlng)
   {
	
	lat = latlng.lat();
	long =  latlng.lng();
	global_add_cnt++;
	if(global_add_cnt>1)
	{
		

	if(lat && long){
	  	la = new GLatLng(lat,long);
		var marker = createInfoMarker(la, address_all_listing[global_add_cnt], all_listings_icons[global_add_cnt]);
		
   		map.addOverlay(marker);
  
		/*
    	
    	var url = "../actions.php";
		var pars = "action_list=setting_listing_true_lat_long&lat="+lat+"&long="+long+"&listing_id="+all_listings_ids[global_add_cnt]+"&global_add_cnt="+global_add_cnt+"&address="+address+"&list_address="+list_address;
    	
    	var myAjax = new Ajax.Request( url,

											{
												
											  method: 'get',
											  parameters: pars
											 
											  
											}

								);
			*/	
	}
	}
	
});
	

		

	
}

function setlanglong(latlng)
{
	
	lat = latlng.lat();
	long =  latlng.lng();
	global_add_cnt++;
	if(global_add_cnt>1)
	{
		

	if(lat && long){
	  	la = new GLatLng(lat,long);
		var marker = createInfoMarker(la, address_all_listing[global_add_cnt], all_listings_icons[global_add_cnt]);
		
   		map.addOverlay(marker);
  
	
    	
    	var url = "../actions.php";
		var pars = "action_list=setting_listing_true_lat_long&lat="+lat+"&long="+long+"&listing_id="+all_listings_ids[global_add_cnt]+"&global_add_cnt="+global_add_cnt;
    	
    	var myAjax = new Ajax.Request( url,

											{
												
											  method: 'get',
											  parameters: pars
											 
											  
											}

								);	
	}
	}
	
}


function drawPolyLine(polyline, polygon)
{
	
	map.addOverlay(polyline);
	map.addOverlay(polygon);
	
}






