/* google map property search */

function google_map_search(map) {
  Element.show('gmap-spinner');
	bounds = map.getBounds();
  $('latitude_min').value  = bounds.getSouthWest().lat();
  $('longitude_min').value = bounds.getSouthWest().lng();
  $('latitude_max').value  = bounds.getNorthEast().lat();
  $('longitude_max').value = bounds.getNorthEast().lng();
  params = Form.serialize('gmap-search-form');
	new Ajax.Request('/properties/google_map_search', {asynchronous:true, evalScripts:true, parameters: params });
}

/* subs */

function center_on_sub(map, lat, lng, lat2, lng2) {
  map.centerAndZoomOnBounds(new GLatLngBounds(new GLatLng(lat, lng), new GLatLng(lat2, lng2)));
  google_map_search(map);
}

function capture_map_bounds(map) {

  // capture the bottom-left and top-right corners of the map
  var bounds = map.getBounds();
  var bottom_left = bounds.getSouthWest();
  var top_right = bounds.getNorthEast();

  // set these in the form for updating
  $('sub_latitude').value = bottom_left.lat();
  $('sub_longitude').value = bottom_left.lng();
  $('sub_latitude_2').value = top_right.lat();
  $('sub_longitude_2').value = top_right.lng();

  // use these for display
  $('bl-lat').innerHTML = bottom_left.lat();
  $('bl-lng').innerHTML = bottom_left.lng();
  $('tr-lat').innerHTML = top_right.lat();
  $('tr-lng').innerHTML = top_right.lng();
}

/* 
  deprecated function 
  only used by turnquist and waterfront 
  use google_map_search instead 
*/

function lreGatherMapSearch(map)
{
  Element.show('gmap-spinner');
  Element.hide('mapSummary');
	bounds = map.getBounds();
	params = location.search.slice(1)+
		'&m_z='+map.getZoom()+
		'&m_a='+map.getCenter().lat()+
		'&m_o='+map.getCenter().lng()+
		'&aa_m='+bounds.getSouthWest().lat()+
		'&ao_m='+bounds.getSouthWest().lng()+
		'&aa_x='+bounds.getNorthEast().lat()+
		'&ao_x='+bounds.getNorthEast().lng()+
		'&'+Form.serialize('lre_filter')
	new Ajax.Request('/property/maps_setbounds', {asynchronous:true, evalScripts:true, parameters: params });
}

