
function    GMap_JSON_Array ( arr )
{
   var res   = '';
   for  (  var i = 0;  i < arr.length;  ++ i  )
   {
         var   value =  arr [ i ];
         res  +=  (  (res=='') ? '' : ','  )  +  GMap_JSON ( value );
   }
   return   '[' + res + ']';
}


function    GMap_JSON_Object ( obj )
{
   var res   = '';
   for  (  property  in  obj  )
   {
         var   value =  obj [ property ];
         res  +=  (  (res=='') ? '' : ','  )  +  GMap_JSON ( property )  +  ':'  +  GMap_JSON ( value );
   }
   return   '{' + res + '}';
}


function    GMap_JSON ( src )
{
   var   res   =  '';
   switch  (  typeof ( src )  )
   {
      case  'boolean':     res   =                       String ( src );                                                      break;
      case  'number':      res   =  isFinite ( src )  ?  String ( src )  :  "null";                                       break;
      case  'string':      res   =                          '"' + src + '"';                              break;
      case  'object':      res   =  ( src instanceof Array )  ?  GMap_JSON_Array ( src )  :  GMap_JSON_Object ( src );        break;
      default:             res   =  "null";                                                                               break;
   }
   return   res;
}


function GMap_Coords_GeolocationToPixels ( map_div_id, lat, lng )
{
   var   map         =  $( '#' + map_div_id ).data ( 'map' );
   var   o_Pix       =  $( '#' + map_div_id ).offset();
   var   px2         =  $( '#' + map_div_id ).outerWidth();
   var   py2         =  $( '#' + map_div_id ).outerHeight();
   var   bounds      =  map.getBounds();
   var   ne_coords   =  bounds.getNorthEast();
   var   sw_coords   =  bounds.getSouthWest();
   var   cx1         =  ( lng > ne_coords.lng() )  ?  lng - ne_coords.lng()  :  ne_coords.lng() - lng;
   var   cy1         =  ( lat > ne_coords.lat() )  ?  lat - ne_coords.lat()  :  ne_coords.lat() - lat;
   var   cx2         =  ( sw_coords.lng() > ne_coords.lng() )  ?  sw_coords.lng() - ne_coords.lng()  :  ne_coords.lng() - sw_coords.lng();
   var   cy2         =  ( sw_coords.lat() > ne_coords.lat() )  ?  sw_coords.lat() - ne_coords.lat()  :  ne_coords.lat() - sw_coords.lat();
   o_Pix.left       +=  px2 - parseInt (  ((cx1*px2)/cx2) + ''  );
   o_Pix.top        +=        parseInt (  ((cy1*py2)/cy2) + ''  );

   return   o_Pix;
}


function GMap_InfoString ( str )
{
   return   '<span style="padding-bottom:3px;">' + str + '</span>';
}

function GMap_Bounds ( map )
{
   var   bounds      =  map.getBounds();

   if  (  typeof ( bounds )  ==  'undefined'  )    return   null;
   if  (           bounds    ==  null         )    return   null;

   var   ne_coords   =  bounds.getNorthEast();
   var   sw_coords   =  bounds.getSouthWest();
   var   ne_lat      =  ne_coords.lat();
   var   sw_lat      =  sw_coords.lat();
   var   ne_lng      =  ne_coords.lng();
   var   sw_lng      =  sw_coords.lng();

   return   {  lat_min  :  Math.min ( ne_lat, sw_lat ),
               lng_min  :  Math.min ( ne_lng, sw_lng ),
               lat_max  :  Math.max ( ne_lat, sw_lat ),
               lng_max  :  Math.max ( ne_lng, sw_lng )
            };
}


function GMap_Marker_IsVisible ( marker )
{
   var   map      =  marker.getMap();
   var   bounds   =  map.getBounds();
   var   latLng   =  marker.getPosition();

   return   bounds.contains ( latLng );
}


function GMap_Polygon_IsVisible ( polygon )
{
   var   map      =  polygon.getMap();
   var   bounds   =  GMap_Bounds ( map );

   return   (  ( polygon.lat_min <= bounds.lat_max )  &&  ( polygon.lat_max >= bounds.lat_min )  &&  ( polygon.lng_min <= bounds.lng_max )  &&  ( polygon.lng_max >= bounds.lng_min )  );
}


function GMap_Visibility_Filter ( map_div_id, SrcList )
{
   var   DstList  =  new Array();

   for  (  var i = 0;  i < SrcList.length;  ++i  )
   {
      var   obj   =  SrcList [ i ];

      if  (  obj.IsVisible ()  )
         DstList.push ( obj );
      else
         obj.setMap ( null );
   }

   return   DstList;
}


function GMap_ClearList ( map_div_id, SrcList )
{
   for  (  var i = 0;  i < SrcList.length;  ++i  )
   {
      var   obj   =  SrcList [ i ];

      obj.setMap ( null );
   }

   return   new Array();
}


function GMap_PopupText_Show ( x, y, text, class_name )
{
   $( '#map_popup_text_content_id' ).html ( text );
   $( '#map_popup_text_content_id' ).attr ( 'class', class_name );
   $( '#map_popup_text_div_id'     ).css  ( 'left',  x + 'px' );
   $( '#map_popup_text_div_id'     ).css  ( 'top',   y + 'px' );
   $( '#map_popup_text_div_id'     ).show ();
}


function GMap_PopupText_Hide ()
{
   $( '#map_popup_text_div_id' ).hide();
}


function GMap_InfoWindow_Show ( map_div_id, lat, lng, text )
{
   var   map                  =  $( '#' + map_div_id ).data ( 'map' );
   var   street_view          =  map.getStreetView ();

   street_view.setVisible ( false );

   var   o                    =  GMap_Coords_GeolocationToPixels ( map_div_id, lat, lng );
   var   x                    =  o.left;
   var   y                    =  o.top - 33;
   var   map_div_id_bottom    =  $( '#' + map_div_id ).offset().top  +  $( '#' + map_div_id ).outerHeight();
   var   document_half_width  =  parseInt  (  $(document).width() / 2  );
   var   content_max_width    =  Math.max  (  document_half_width - 30,  300  );
   var   side                 =  ( o.left < document_half_width )  ?  '_lr_'  :  '_rl_';
   var   hide                 =  ( o.left < document_half_width )  ?  '_rl_'  :  '_lr_';

   $( '#' + map_div_id + hide + 'info_div'     ).hide ();

   $( '#' + map_div_id + side + 'info_content' ).css  ( 'max-width', content_max_width + 'px' );
   $( '#' + map_div_id + side + 'info_content' ).html ( text );
   $( '#' + map_div_id + side + 'info_div'     ).show ();

   var   content_height       =  $( '#' + map_div_id + side + 'info_content' ).outerHeight();
   var   content_bottom       =  content_height + y + 10;
   var   t                    =  ( content_bottom > map_div_id_bottom )  ?  content_bottom - map_div_id_bottom  :  10;
         x                   +=  ( o.left < document_half_width )  ?  10  :  - $( '#' + map_div_id + side + 'info_content' ).outerWidth() - 25;
         y                   -=  t;

   $( '#' + map_div_id + side + 'info_div'      ).css ( 'left',        x + 'px' );
   $( '#' + map_div_id + side + 'info_div'      ).css ( 'top',         y + 'px' );
   $( '#' + map_div_id + side + 'info_arrow_td' ).css ( 'padding-top', t + 'px' );
   $( '#' + map_div_id + side + 'info_div'      ).show();

   var   offset   =  $( '#' + map_div_id ).offset();
   if  (  offset.top  <  $( window ).scrollTop()  )
      $( window ).scrollTop ( offset.top );
}


function PropertySearch_InfoWindow_Hide ( map_div_id )
{
   $( '#' + map_div_id + '_lr_info_div' ).hide ();
   $( '#' + map_div_id + '_rl_info_div' ).hide ();
}


function GMap_BoundsToCenter ( map_div_id, lat_min, lng_min, lat_max, lng_max )
{
   var   map      =  $( '#' + map_div_id ).data ( 'map' );

   if  (  map  !=  null  )
   {
      var   sw       =  new google.maps.LatLng ( lat_min, lng_min );
      var   ne       =  new google.maps.LatLng ( lat_max, lng_max );
      var   lat      =  ( lat_max + lat_min )  /  2;
      var   lng      =  ( lng_max + lng_min )  /  2;

      map.fitBounds  (  new google.maps.LatLngBounds ( sw,  ne  )  );
      map.setCenter  (  new google.maps.LatLng       ( lat, lng )  );
   }
}


function GMap_ScrollTop ( map_div_id )
{
   var   offset   =  $( '#' + map_div_id ).offset();
   if  (  offset.top  <  $( window ).scrollTop()  )
      $( window ).scrollTop ( offset.top );
}


function GMap_Neighborhoods_PopupText_Show ( map_div_id, lat, lng, text )
{
   var   o  =  GMap_Coords_GeolocationToPixels ( map_div_id, lat, lng );

   GMap_PopupText_Show  (  o.left + 10,  o.top,  text,  'Map_Popup'  );
}


function GMap_Neighborhoods_MouseOver ( event )
{
   var   map   =  this.getMap();

   if  (  map  !=  null  )
   {
      var   map_div_id     =  map.getDiv().id;
      var   neighborhoods  =  $( '#' + map_div_id ).data ( 'neighborhoods' );
      var   id             =  parseInt ( this.id + '' );
      var   index_this     =  neighborhoods.selected.indexOf ( id );
      var   selected       =  ( index_this >= 0 )  ?  true  :  false;

      this.setOptions 
      (
         {
            strokeColor:   ( selected ? '#1266BB' : '#1266BB' ),
            strokeOpacity: ( selected ? 0.8 : 0.8 ),
            strokeWeight:  ( selected ? 2 : 2 ),
            fillColor:     ( selected ? '#3786DE' : '#8E94FF' ),
            fillOpacity:   ( selected ? 0.4 : 0.3 )
         }
      );

      GMap_Neighborhoods_PopupText_Show ( map_div_id, event.latLng.lat(), event.latLng.lng(), this.name );
   }
}


function GMap_Neighborhoods_MouseOut ( event )
{
   var   map   =  this.getMap();

   if  (  map  !=  null  )
   {
      var   map_div_id     =  map.getDiv().id;
      var   neighborhoods  =  $( '#' + map_div_id ).data ( 'neighborhoods' );
      var   id             =  parseInt ( this.id + '' );
      var   index_this     =  neighborhoods.selected.indexOf ( id );
      var   selected       =  ( index_this >= 0 )  ?  true  :  false;

      this.setOptions
      (
         {
            strokeColor:   ( selected ? '#1266BB' : '#1266BB' ),
            strokeOpacity: ( selected ? 0.8 : 0.8 ),
            strokeWeight:  ( selected ? 2 : 2 ),
            fillColor:     ( selected ? '#3786DE' : '#0000FF' ),
            fillOpacity:   ( selected ? 0.2 : 0.0 )
         }
      );
   }

   GMap_PopupText_Hide ();
}


function GMap_Neighborhoods_MarkerByID ( map_div_id, marker_id )
{
   var   neighborhoods  =  $( '#' + map_div_id ).data ( 'neighborhoods' );
   var   result         =  null;

   for  (  var  i = 0;  i < neighborhoods.list.length;  ++ i  )
   {
      var   marker   =  neighborhoods.list [ i ];

      if  (  marker_id  ==  marker.id  )
      {
         result   =  marker;
         break;
      }
   }

   return   result;
}


function GMap_Neighborhoods_InformationLine ( map_div_id )
{
   var   neighborhoods  =  $( '#' + map_div_id ).data ( 'neighborhoods' );
   var   listings       =  $( '#' + map_div_id ).data ( 'listings'      );

   var   spacer         =  "<img src='4a_layout/spacer.gif' border='0' width='1' height='1' alt=''>";
   var   info           =  '';

   if  (  neighborhoods.selected_bounds.length  >  0  )
   {
      for  (  var j = 0;  j < neighborhoods.selected_bounds.length;  ++ j  )
      {
         var   polygon  =  neighborhoods.selected_bounds [ j ];

         info +=  (  ( info == '' )  ?  ''  :  ',&nbsp;'  )      +
                  '<a href="javascript:GMap_BoundsToCenter(\'' + map_div_id      + '\',' +
                                                                   polygon.lat_min + ',' +
                                                                   polygon.lng_min + ',' +
                                                                   polygon.lat_max + ',' +
                                                                   polygon.lng_max + ');" class="nei_anchor">' + polygon.name + '</a>' +
                  '&nbsp;' +
                  '<a href="javascript:GMap_Neighborhoods_Toggle(\'' + map_div_id + '\',' + polygon.id + ',true);" class="nei_anchor" title="Unselect">' +
                     '<img src="images/gmap/nei_close.png" style="vertical-align:bottom;" border="0" width="11" height="13" alt="Unselect">' +
                  '</a>' ;
      }
   }
   else
   {
      var   hide  =  $( '#' + map_div_id + '_hide_grid__form [name="hng"]' ).is( ':checked' );

      info  =  (  hide  ||  ( neighborhoods.list.length == 0 )  )    ?    spacer    :    neighborhoods.information_text;

      if  (  ( ! hide )  &&  ( neighborhoods.list.length == 0 )  )
         $( '#' + map_div_id + '_hide_grid__div' ).hide();
      else
         $( '#' + map_div_id + '_hide_grid__div' ).show();

      var   select_html    =  $( '#' + map_div_id + '_search__form [ident="neigbourhood_select"]' ).html ();

      if  (  ( ! hide )  &&  ( select_html != '' )  )
      {
         $( '#' + map_div_id + '_search__form [ident="neigbourhood_select"]' ).show();
         $( '#' + map_div_id + '_search__form [ident="neigbourhood_prompt"]' ).show();
      }
      else
      {
         $( '#' + map_div_id + '_search__form [ident="neigbourhood_select"]' ).hide();
         $( '#' + map_div_id + '_search__form [ident="neigbourhood_prompt"]' ).hide();
      }
   }

   if  (  neighborhoods.information_div_id  !=  ''  )
      $( '#' + neighborhoods.information_div_id ).html (  GMap_InfoString ( info )  );
}


function GMap_Neighborhoods_Toggle ( map_div_id, this_id, refresh )
{
   var   settings       =  $( '#' + map_div_id ).data ( 'settings'      );
   var   listings       =  $( '#' + map_div_id ).data ( 'listings'      );
   var   neighborhoods  =  $( '#' + map_div_id ).data ( 'neighborhoods' );
   var   id             =  parseInt ( this_id + '' );
   var   index_this     =  neighborhoods.selected.indexOf ( id );
   var   selected       =  ( index_this >= 0 )  ?  true  :  false;

   var   this_obj       =  GMap_Neighborhoods_MarkerByID ( map_div_id, id );

   if ( selected )
   {
      var   head                       =  neighborhoods.selected.slice ( 0, index_this );
      var   tail                       =  neighborhoods.selected.slice ( index_this + 1 );
      neighborhoods.selected           =  head.concat ( tail );

      var   head_bounds                =  neighborhoods.selected_bounds.slice ( 0, index_this );
      var   tail_bounds                =  neighborhoods.selected_bounds.slice ( index_this + 1 );
      neighborhoods.selected_bounds    =  head_bounds.concat ( tail_bounds );
   }
   else
   {
      $( '#' + map_div_id + '_search__form [name="street"]' ).attr( 'selectedIndex', 0 );

      listings.street   =  '';

      $( '#' + map_div_id ).data ( 'listings', listings );

      if  (  neighborhoods.selected.length  >=  5  )
      {
         var   marker_id   =  neighborhoods.selected [ 0 ];
         var   marker      =  GMap_Neighborhoods_MarkerByID ( map_div_id, marker_id );

         if  (  marker  !=  null  )
         {
            marker.setOptions
            (
               {
                  strokeColor:   '#1266BB',
                  strokeOpacity: 0.8,
                  strokeWeight:  2,
                  fillColor:     '#0000FF',
                  fillOpacity:   0.0
               }
            );
         }

         neighborhoods.selected           =  neighborhoods.selected       .slice ( 1 );
         neighborhoods.selected_bounds    =  neighborhoods.selected_bounds.slice ( 1 );
      }

      var   bounds   =  {  id:      this_obj.id,
                           name:    this_obj.name,
                           lat_min: this_obj.lat_min,
                           lng_min: this_obj.lng_min,
                           lat_max: this_obj.lat_max,
                           lng_max: this_obj.lng_max
                        };

      neighborhoods.selected       .push ( id     );
      neighborhoods.selected_bounds.push ( bounds );
   }

   selected    =  selected  ?  false  :  true;

   if  (  this_obj  !=  null  )
   {
      this_obj.setOptions
      (
         {
            strokeColor:   ( selected ? '#1266BB' : '#1266BB' ),
            strokeOpacity: ( selected ? 0.8 : 0.8 ),
            strokeWeight:  ( selected ? 2 : 2 ),
            fillColor:     ( selected ? '#3786DE' : '#0000FF' ),
            fillOpacity:   ( selected ? 0.2 : 0.0 )
         }
      );
   }

   $( '#' + map_div_id ).data ( 'neighborhoods', neighborhoods );

   GMap_Neighborhoods_InformationLine ( map_div_id );

   if  (  refresh  &&  ( settings.show.neighborhoods == 4 )  )
      PropertySearch_Refresh ( map_div_id );

   if  (  typeof ( neighborhoods.callback )  ==  'function'  )
      neighborhoods.callback ( map_div_id );
}


function GMap_Neighborhoods_Click ( event )
{
   var   map   =  this.getMap();

   if  (  map  !=  null  )
   {
      var   map_div_id     =  map.getDiv().id;
      var   neighborhoods  =  $( '#' + map_div_id ).data ( 'neighborhoods' );

      neighborhoods.timeout   =  setTimeout ( 'GMap_Neighborhoods_Toggle("'+map_div_id+'","'+this.id+'",true)', 500 );

      $( '#' + map_div_id ).data ( 'neighborhoods', neighborhoods );
   }
}


function GMap_Neighborhoods_DoubleClick ( event )
{
   var   map   =  this.getMap();

   if  (  map  !=  null  )
   {
      var   map_div_id     =  map.getDiv().id;
      var   neighborhoods  =  $( '#' + map_div_id ).data ( 'neighborhoods' );

      clearTimeout ( neighborhoods.timeout );
   }
}


function GMap_Neighborhoods_Reload ( map_div_id, addition, bounds )
{
   var   map               =  $( '#' + map_div_id ).data ( 'map'           );
   var   neighborhoods     =  $( '#' + map_div_id ).data ( 'neighborhoods' );

   neighborhoods.list      =  GMap_Visibility_Filter ( map_div_id, neighborhoods.list );
   neighborhoods.bounds    =  bounds;

   for  (  var j = 0;  j < addition.length;  ++ j  )
   {
      var   item        =  addition [ j ];
      var   id          =  parseInt ( item.id + '' );
      var   selected    =  (  neighborhoods.selected.indexOf ( id )  >=  0  )  ?  true  :  false;
      var   paths       =  new Array ();

      for  (  var k = 0;  k < item.polygon.length;  ++ k  )
      {
         var   point    =  item.polygon [ k ];

         paths.push  (  new google.maps.LatLng ( point.lat, point.lng )  );
      }

      var   options     =
      {
            map:           map,
            paths:         new google.maps.MVCArray ( paths ),
            strokeColor:   ( selected ? '#1266BB' : '#1266BB' ),
            strokeOpacity: ( selected ? 0.8  :  0.8  ),
            strokeWeight:  ( selected ? 2  :  2  ),
            fillColor:     ( selected ? '#3786DE' : '#0000FF' ),
            fillOpacity:   ( selected ? 0.2  :  0.0  ),
            zIndex:        item.zorder,
            lat_min:       item.lat_min,
            lng_min:       item.lng_min,
            lat_max:       item.lat_max,
            lng_max:       item.lng_max,
            border:        item.border,
            id:                 id,
            name:          item.name
      };

      var   polygon     =  new google.maps.Polygon ( options );

      google.maps.event.addListener ( polygon, 'mouseover', GMap_Neighborhoods_MouseOver   );
      google.maps.event.addListener ( polygon, 'mousemove', GMap_Neighborhoods_MouseOver   );
      google.maps.event.addListener ( polygon, 'mouseout',  GMap_Neighborhoods_MouseOut    );
      google.maps.event.addListener ( polygon, 'click',     GMap_Neighborhoods_Click       );
      google.maps.event.addListener ( polygon, 'dblclick',  GMap_Neighborhoods_DoubleClick );

      neighborhoods.list.push ( polygon );
   }

   $( '#' + map_div_id ).data ( 'neighborhoods', neighborhoods );

   GMap_Neighborhoods_InformationLine ( map_div_id );
}


function GMap_Utilities_ShowInfo ( marker )
{
   var   map         =  marker.getMap();
   var   map_div_id  =  map.getDiv().id;
   var   latLng      =  marker.getPosition();
   var   text        =  "<table border='0' cellspacing='0' cellpadding='0' class='Utilities_Info_TABLE'><tr><td class='prop_search_text1'>"+marker.website+"</td></tr>"+((marker.address!='')?"<tr><td class='prop_search_text1'>"+marker.address+"</td></tr>":'')+((marker.phone!='')?"<tr><td class='prop_search_text1'>"+marker.phone+"</td></tr>":'')+"</table>";
   GMap_InfoWindow_Show ( map_div_id, latLng.lat(), latLng.lng(), text );
}


function GMap_Utilities_MouseClick ( event )
{
   GMap_Utilities_ShowInfo ( this );
}


function GMap_Utilities_MouseClick_OnTable ( map_div_id, index )
{
   var   utilities   =  $( '#' + map_div_id ).data ( 'utilities' );
   var   marker      =  utilities.list [ index ];

   GMap_Utilities_ShowInfo ( marker );
}


function GMap_Utilities_Compare ( a, b )
{
   var   nameA    =  a.name.toLowerCase();
   var   nameB    =  b.name.toLowerCase();

   return   ( nameA == nameB )  ?  0  :  ( (nameA<nameB) ? -1 : 1 );
}


function GMap_Utilities_TableUpdate ( map_div_id )
{
   var   map         =  $( '#' + map_div_id ).data ( 'map'       );
   var   utilities   =  $( '#' + map_div_id ).data ( 'utilities' );
   var   text_info   =  '';
   var   spacer      =  "<img src='4a_layout/spacer.gif' border='0' width='1' height='1' alt=''>";
   var   text        =  spacer;

   if  (  utilities.selected.length  ==  0  )
      text_info   =  'You can select up to 3 neighborhood feature icons';

   else  if  (  utilities.list.length  ==  0  )
      text_info   =  ( map.getZoom() < 13 )
                  ?  'Zoom in to display neighborhood feature icons'
                  :  'Area shown on the map does not contain selected neighborhood feature icons'
                  ;

   else
   {
      if  (  utilities.results_div_id  !=  ''  )
      {
         utilities.list.sort ( GMap_Utilities_Compare );

         text  =  "<table border='0' cellspacing='0' cellpadding='0' width='100%' class='Utilities_Table_TABLE'><tr><td class='Utilities_Table_Header_TD'>"+text+"</td><td class='Utilities_Table_Header_TD'>Name</td><td class='Utilities_Table_Header_TD'>Address</td><td class='Utilities_Table_Header_TD' width='95'>Phone</td></tr>";

         for  (  var i = 0;  i < utilities.list.length;  ++ i  )
         {
            var   marker   =  utilities.list [ i ];
            var   icon     =  marker.getIcon();
            var   image    =  "<a href='javascript:GMap_Utilities_MouseClick_OnTable(\""+map_div_id+"\","+i+");' title='Locate' class='Utilities_Table_Link_A'><img src='"+icon.url+"' border='0' width='24' height='24' alt='Locate'></a>";
            var   name     =  ( marker.name    == '' )  ?  spacer  :  marker.name;
            var   address  =  ( marker.address == '' )  ?  spacer  :  marker.address;
            var   phone    =  ( marker.phone   == '' )  ?  spacer  :  marker.phone;
            var   website  =  ( marker.website == '' )  ?  spacer  :  marker.website;

            text          +=  "<tr><td class='Utilities_Table_Details_TD'>"+image+"</td><td class='Utilities_Table_Details_TD'>"+website+"</td><td class='Utilities_Table_Details_TD'>"+address+"</td><td class='Utilities_Table_Details_TD'>"+phone+"</td></tr>";
         }

         text    +=  '</table>';

      }

      text_info   =  'You can select up to 3 neighborhood feature icons';
   }

   if  (  utilities.results_div_id  !=  ''  )
      $( '#' + utilities.results_div_id ).html ( text );

   if  (  utilities.information_div_id  !=  ''  )
      $( '#' + utilities.information_div_id ).html (  GMap_InfoString ( text_info )  );
}


function GMap_Utilities_CleanList ( SrcList, type_id )
{
   var   DstList  =  new Array();

   for  (  var i = 0;  i < SrcList.length;  ++i  )
   {
      var   obj   =  SrcList [ i ];

      if  (  ( type_id < 0 )  ||  ( type_id == obj.type_id )  )
         obj.setMap ( null );
      else
         DstList.push ( obj );
   }

   return   DstList;
}


function GMap_Utilities_Reload ( map_div_id, addition, bounds )
{
   var   map         =  $( '#' + map_div_id ).data ( 'map'       );
   var   utilities   =  $( '#' + map_div_id ).data ( 'utilities' );

   if    (    (  typeof ( addition )  !=  'object'  )    ||    ( addition == null )    )
   {
      utilities.list    =  GMap_Utilities_CleanList ( utilities.list, -1 );
      utilities.bounds  =  null;

      if  (  utilities.information_div_id  !=  ''  )
         $( '#' + utilities.information_div_id ).html (  GMap_InfoString ( 'Zoom in to display neighborhood feature icons' )  );

      if  (  utilities.results_div_id  !=  ''  )
         $( '#' + utilities.results_div_id ).html ( "<img src='4a_layout/spacer.gif' border='0' width='1' height='1' alt=''>" );
   }

   else
   {
      utilities.list    =  GMap_Visibility_Filter ( map_div_id, utilities.list );
      utilities.bounds  =  bounds;

      for  (  var j = 0;  j < addition.length;  ++ j  )
      {
         var   item     =  addition [ j ];
         var   marker   =  new google.maps.Marker
         (
            {
               map:        map,
               flat:       true,
               icon:       new google.maps.MarkerImage  (  'images/gmap/UtilitiesIcons/' + item.type_id + '.png',  new google.maps.Size ( 24,24 )  ),
               position:   new google.maps.LatLng ( item.lat, item.lng ),
               visible:    true,
               type_id:    item.type_id,
               type:       item.type,
               name:       item.name,
               address:    item.address,
               phone:      item.phone,
               website:    item.website
            }
         );

         google.maps.event.addListener ( marker, 'click', GMap_Utilities_MouseClick );

         utilities.list.push ( marker );
      }

      GMap_Utilities_TableUpdate ( map_div_id );
   }

   $( '#' + map_div_id ).data ( 'utilities', utilities );
}


function GMap_Utilities_ToggleType ( map_div_id, type_id )
{
   var   map         =  $( '#' + map_div_id ).data ( 'map'       );
   var   utilities   =  $( '#' + map_div_id ).data ( 'utilities' );
   var   id          =  parseInt ( type_id + '' );
   var   index_this  =  utilities.selected.indexOf ( id );
   var   selected    =  ( index_this >= 0 )  ?  true  :  false;

   GMap_ScrollTop ( map_div_id );

   if ( selected )
   {
      PropertySearch_InfoWindow_Hide ( map_div_id );

      var   head           =  utilities.selected.slice ( 0, index_this );
      var   tail           =  utilities.selected.slice ( index_this + 1 );
      utilities.selected   =  head.concat ( tail );

      $( 'img[div_id="' + map_div_id + '"][type_id="' + type_id + '"]' ).attr (  'src',  'images/gmap/UtilitiesIcons/' + type_id + '.png'  );

      utilities.list    =  GMap_Utilities_CleanList ( utilities.list, id );
                           GMap_Utilities_TableUpdate ( map_div_id );

      $( '#' + map_div_id ).data ( 'utilities', utilities );
   }
   else
   {
      if  (  utilities.selected.length  >=  3  )
      {
         var   type_id_remove    =  utilities.selected [ 0 ];

         utilities.selected      =  utilities.selected.slice ( 1 );
         utilities.list          =  GMap_Utilities_CleanList ( utilities.list, type_id_remove );

         $( 'img[div_id="' + map_div_id + '"][type_id="' + type_id_remove + '"]' ).attr (  'src',  'images/gmap/UtilitiesIcons/' + type_id_remove + '.png'  );
      }

      utilities.selected.push ( id );

      $( 'img[div_id="' + map_div_id + '"][type_id="' + type_id + '"]' ).attr (  'src',  'images/gmap/UtilitiesIcons/' + type_id + '_c.png'  );

      $( '#' + map_div_id ).data ( 'utilities', utilities );

      if  (   map.getZoom()  <  13  )
      {
         if  (  utilities.information_div_id  !=  ''  )
            $( '#' + utilities.information_div_id ).html (  GMap_InfoString ( 'Zoom in to display neighborhood feature icons' )  );

         if  (  utilities.results_div_id  !=  ''  )
            $( '#' + utilities.results_div_id ).html ( "<img src='4a_layout/spacer.gif' border='0' width='1' height='1' alt=''>" );
      }
      else
      {
         var   request  =  {  utilities:  {  bounds: null,  selected: new Array()  }  };
         request.utilities.selected [ 0 ]    =  id;

         GMap_Reload ( map_div_id, request );
      }
   }

   PropertySearch_ShowLink ( map_div_id );
}


function GMap_Utilities_InitControl ( map_div_id )
{
   $( 'img[div_id="'+map_div_id+'"][info_class^="Utilities_Popup_"]' ).mousemove
   (
      function ( e )
      {
         var info_class    =  $( this ).attr( 'info_class' );
         var info_text     =  $( this ).attr( 'info_text'  );

         GMap_PopupText_Show ( e.pageX + 10, e.pageY, info_text, info_class );
      }
   );

   $( 'img[div_id="'+map_div_id+'"][info_class^="Utilities_Popup_"]' ).mouseout
   (
      function ( e )
      {
         GMap_PopupText_Hide ();
      }
   );

   $( 'img[div_id="'+map_div_id+'"][info_class^="Utilities_Popup_"]' ).click
   (
      function ( e )
      {
         var type_id    =  $( this ).attr( 'type_id' );

         GMap_Utilities_ToggleType ( map_div_id, type_id )
      }
   );
}



function GMap_Listings_ShowInfo ( marker )
{
   var   map         =  marker.getMap();
   var   map_div_id  =  map.getDiv().id;
   var   latLng      =  marker.getPosition();

   $.ajax   (  {  url      :  'property_search_listing_info.php',
                  data     :  {  list_id  :  marker.list_id   },
                  async    :  false,
                  success  :  function ( response )
                              {
                                 GMap_InfoWindow_Show ( map_div_id, latLng.lat(), latLng.lng(), response );
                              }
               }
            );
}


function GMap_Listings_ShowInfoByMLS ( map_div_id, MLS, id2 )
{
   var   listings    =  $( '#' + map_div_id ).data ( 'listings' );
         id2         =  parseInt ( id2 + '' );

   for  (  var i = 0;  i < listings.list.length;  ++ i  )
   {
      var   marker   =  listings.list [ i ];
      if    (    ( MLS == marker.MLS )    &&    (  id2  ==  parseInt ( marker.id2 + '' )  )    )
      {
         GMap_Listings_ShowInfo ( marker );
         break;
      }
   }
}


function GMap_Listings_MouseClick ( event )
{
   GMap_Listings_ShowInfo ( this );
}


function PropertySearch_Listings_ShowInfo ( map_div_id, lat, lng, MLS, id2 )
{
   var   map         =  $( '#' + map_div_id ).data ( 'map' );
   var   listings    =  $( '#' + map_div_id ).data ( 'listings' );
   var   bounds      =  map.getBounds();
   var   latLng      =  new google.maps.LatLng ( lat, lng );

   if  (  ( listings.list.length != 0 )  &&  bounds.contains ( latLng )  &&  ( map.getZoom() > 10 )  )
   {
      GMap_Listings_ShowInfoByMLS ( map_div_id, MLS, id2 );
   }
   else
   {
      GMap_ScrollTop ( map_div_id );

      var   listings    =  $( '#' + map_div_id ).data ( 'listings' );

      listings.MLS   =  MLS;
      listings.id2   =  parseInt ( id2 + '' );

      $( '#' + map_div_id ).data ( 'listings', listings );

      map.setCenter  (  new google.maps.LatLng ( lat, lng )  );

      if  (  map.getZoom()  <  14  )
         map.setZoom ( 14 );
   }
}


function PropertySearch_CloseNotice ( map_div_id )
{
   var   listings    =  $( '#' + map_div_id ).data ( 'listings' );

   listings.zoom_notice    =  false;

   if  (  listings.zoom_notice_div_id  !=  ''  )
      $( '#' + listings.zoom_notice_div_id ).hide ();

   $( '#' + map_div_id ).data ( 'listings', listings );
}


function GMap_Listings_Reload ( map_div_id, response_listings, bounds )
{
   var   addition    =  response_listings.map;

   var   map         =  $( '#' + map_div_id ).data ( 'map'      );
   var   listings    =  $( '#' + map_div_id ).data ( 'listings' );

   if    (    (  typeof ( addition )  !=  'object'  )    ||    ( addition == null )    )
   {
      listings.list     =  GMap_ClearList ( map_div_id, listings.list );
      listings.bounds   =  null;

      if  (  listings.found_div_id  !=  ''  )
         $( '#' + listings.found_div_id ).html ( '' );

      if  (  listings.information_div_id  !=  ''  )
      {
         var   zoom     =  (  typeof ( response_listings.zoom )  !=  'undefined'  )  ?  true  :  false;
         var   text1    =  zoom  ?  'Zoom in to display listings'  :  'Too many listings to display on the map (search results provided below)';
         var   text2    =  zoom  ?  'Zoom in by pressing the \"+\" button to display the listings on the map'  :  'Too many listings to display on the map. Zoom in or refine search criteria.';

         $( '#' + listings.information_div_id ).html ( GMap_InfoString ( text1 )  );

         if  (  listings.zoom_notice  )
         {
            $( '#' + listings.zoom_notice_div_id + ' [content="1"]' ).html ( text2 );
            $( '#' + listings.zoom_notice_div_id ).show ();

            var   offset   =  $( '#' + map_div_id ).offset();

            offset.left   +=  (  $( '#' + map_div_id ).outerWidth ()  -  $( '#' + listings.zoom_notice_div_id ).outerWidth ()  )    /    2;
            offset.top    +=  (  $( '#' + map_div_id ).outerHeight()  -  $( '#' + listings.zoom_notice_div_id ).outerHeight()  )    /    2;

            $( '#' + listings.zoom_notice_div_id ).css  (  'left',  parseInt ( offset.left ) + 'px'  );
            $( '#' + listings.zoom_notice_div_id ).css  (  'top',   parseInt ( offset.top  ) + 'px'  );
         }
      }
   }

   else
   {
      listings.list     =  GMap_Visibility_Filter ( map_div_id, listings.list );
      listings.bounds   =  bounds;

      for  (  var j = 0;  j < addition.length;  ++ j  )
      {
         var   item     =  addition [ j ];
         var   marker   =  new google.maps.Marker
         (
            {
               map:        map,
               flat:       true,
               icon:       new google.maps.MarkerImage  (  item.icon,  new google.maps.Size ( 21, 22 )  ),
               position:   new google.maps.LatLng ( item.lat, item.lng ),
               visible:    true,
               list_id:    item.list_id,
               MLS:        item.MLS,
               id2:        item.id2
            }
         );

         google.maps.event.addListener ( marker, 'click', GMap_Listings_MouseClick );

         listings.list.push ( marker );
      }

      var   text  =  ( listings.list.length != 0 )  ?  "<img src='4a_layout/spacer.gif' border='0' width='1' height='1' alt=''>"  :  'Area shown on the map does not contain listings';

      if  (  listings.information_div_id  !=  ''  )
         $( '#' + listings.information_div_id ).html (  GMap_InfoString ( text ) );
   }

   if  (  ( listings.MLS != '' )  ||  ( listings.id2 != 0 )  )
   {
      GMap_Listings_ShowInfoByMLS ( map_div_id, listings.MLS, listings.id2 );

      listings.MLS   =  '';
      listings.id2   =  0;
   }

   $( '#' + map_div_id ).data ( 'listings', listings );
}


function PropertySearch_Refresh ( map_div_id )
{
   var   settings       =  $( '#' + map_div_id ).data ( 'settings' );
   var   listings       =  $( '#' + map_div_id ).data ( 'listings' );
   var   neighborhoods  =  ( settings.show.neighborhoods != 4 )
                        ?  null
                        :  $( '#' + map_div_id ).data ( 'neighborhoods' )
                        ;

   listings.list        =  GMap_ClearList ( map_div_id, listings.list );
   listings.bounds      =  null;

   if  (  listings.found_div_id  !=  ''  )
      $( '#' + listings.found_div_id ).html ( '' );

   var   request        =  {  listings :  {  bounds         :  listings.bounds,
                                             mode           :  settings.mode,
                                             neighborhoods  :  ( neighborhoods ? neighborhoods.selected : null ),
                                             map            :  true,
                                             details        :  settings.details,
                                             property_type  :  $( '#' + map_div_id + '_search__form [name="property_type"]' ).val (),
                                             property_type2 :  $( '#' + map_div_id + '_search__form [name="property_type2"]' ).val (),
                                             price_from     :  $( '#' + map_div_id + '_search__form [name="price_from"]' ).val (),
                                             price_to       :  $( '#' + map_div_id + '_search__form [name="price_to"]' ).val (),
                                             bedrooms       :  $( '#' + map_div_id + '_search__form [name="bedrooms"]' ).val (),
                                             bathrooms      :  $( '#' + map_div_id + '_search__form [name="bathrooms"]' ).val (),
                                             page_size      :  $( '#' + map_div_id + '_search__form [name="page_size"]' ).val (),
                                             page_numb      :  1,
                                             sorting        :  $( '#' + map_div_id + '_search__form [name="sorting"]' ).val (),
                                             commercial     :  $( '#' + map_div_id + '_search__form [name="commercial"]' ).val (),
                                             sid            :  $( '#' + map_div_id + '_search__form [name="sid"]' ).val (),
                                             status         :  $( '#' + map_div_id + '_search__form [name="status"]' ).val (),
                                             office_id      :  $( '#' + map_div_id + '_search__form [name="office_id"]' ).val (),
                                             agent_id       :  $( '#' + map_div_id + '_search__form [name="agent_id"]' ).val ()
                                          }
                           };

   if  (  ! listings.idx_search  )
   {
      request.listings.pr_city   =  $( '#' + map_div_id + '_search__form [name="pr_city"]' ).val ();
      request.listings.street    =  listings.street;
   }

   $( '#' + map_div_id ).data ( 'listings', listings );

   GMap_Reload ( map_div_id, request );
}


function PropertySearch_Refresh2 ( map_div_id )
{
   var   listings    =  $( '#' + map_div_id ).data ( 'listings' );

   $( '#' + map_div_id + '_search__form [name="property_type2"]' ).val ( 0 );

   PropertySearch_Refresh ( map_div_id );
}


function GMap_Listings_SetView ( map_div_id )
{
//   GMap_ScrollTop ( map_div_id );

   var   settings       =  $( '#' + map_div_id ).data ( 'settings' );
   var   listings       =  $( '#' + map_div_id ).data ( 'listings' );
   var   neighborhoods  =  ( settings.show.neighborhoods != 4 )
                        ?  null
                        :  $( '#' + map_div_id ).data ( 'neighborhoods' )
                        ;
   var   request        =  {  listings :  {  bounds         :  listings.bounds,
                                             mode           :  settings.mode,
                                             neighborhoods  :  ( neighborhoods ? neighborhoods.selected : null ),
                                             map            :  false,
                                             details        :  true,
                                             property_type  :  $( '#' + map_div_id + '_search__form [name="property_type"]' ).val (),
                                             property_type2 :  $( '#' + map_div_id + '_search__form [name="property_type2"]' ).val (),
                                             price_from     :  $( '#' + map_div_id + '_search__form [name="price_from"]' ).val (),
                                             price_to       :  $( '#' + map_div_id + '_search__form [name="price_to"]' ).val (),
                                             bedrooms       :  $( '#' + map_div_id + '_search__form [name="bedrooms"]' ).val (),
                                             bathrooms      :  $( '#' + map_div_id + '_search__form [name="bathrooms"]' ).val (),
                                             page_size      :  $( '#' + map_div_id + '_search__form [name="page_size"]' ).val (),
                                             page_numb      :  $( '#' + map_div_id + '_search__form [name="page_numb"]' ).val (),
                                             sorting        :  $( '#' + map_div_id + '_search__form [name="sorting"]' ).val (),
                                             commercial     :  $( '#' + map_div_id + '_search__form [name="commercial"]' ).val (),
                                             sid            :  $( '#' + map_div_id + '_search__form [name="sid"]' ).val (),
                                             status         :  $( '#' + map_div_id + '_search__form [name="status"]' ).val (),
                                             office_id      :  $( '#' + map_div_id + '_search__form [name="office_id"]' ).val (),
                                             agent_id       :  $( '#' + map_div_id + '_search__form [name="agent_id"]' ).val ()
                                          }
                           };

   if  (  ! listings.idx_search  )
   {
      request.listings.pr_city   =  $( '#' + map_div_id + '_search__form [name="pr_city"]' ).val ();
      request.listings.street    =  listings.street;
   }

   GMap_Reload ( map_div_id, request );
}


function PropertySearch_Listings_SetPageSize ( map_div_id, page_size )
{
   var   settings    =  $( '#' + map_div_id ).data ( 'settings' );
   var   listings    =  $( '#' + map_div_id ).data ( 'listings' );

   if  (  settings.details  )
   {
      $( '#' + map_div_id + '_search__form [name="page_size"]' ).val ( page_size );
      $( '#' + map_div_id + '_search__form [name="page_numb"]' ).val ( 1 );

      GMap_Listings_SetView ( map_div_id );
   }
}


function PropertySearch_Listings_SetPageNumb ( map_div_id, page_numb )
{
   var   settings    =  $( '#' + map_div_id ).data ( 'settings' );
   var   listings    =  $( '#' + map_div_id ).data ( 'listings' );

   if  (  settings.details  )
   {
      $( '#' + map_div_id + '_search__form [name="page_numb"]' ).val ( page_numb );

      GMap_Listings_SetView ( map_div_id );
   }
}


function PropertySearch_Listings_SetSorting ( map_div_id, sorting )
{
   var   settings    =  $( '#' + map_div_id ).data ( 'settings' );
   var   listings    =  $( '#' + map_div_id ).data ( 'listings' );

   if  (  settings.details  )
   {
      $( '#' + map_div_id + '_search__form [name="page_numb"]' ).val ( 1 );
      $( '#' + map_div_id + '_search__form [name="sorting"]' ).val ( sorting );

      GMap_Listings_SetView ( map_div_id );
   }
}


function PropertySearch_ReloadCities ( map_div_id )
{
   var   map            =  $( '#' + map_div_id ).data ( 'map'           );
   var   neighborhoods  =  $( '#' + map_div_id ).data ( 'neighborhoods' );

   var   province_id    =  $( '#' + map_div_id + '_search__form [name="province"]' ).val ();

   var   boo_map        =  (    (  typeof ( map )  ==  'object'  )    &&    ( map != null )    )    ?    true    :    false;

   var   request        =  {  map_div_id: map_div_id,  province: province_id  };
   var   str            =  GMap_JSON ( request );

   $.ajax   (  {  url      :  'property_search_aux_b1.php',
                  data     :  {  request  :  str   },
                  async    :  false,
                  dataType :  'json',
                  success  :  function ( response )
                              {
                                 $( '#' + map_div_id + '_search__form [name="zoom"]' ).val ( '0' );
                                 $( '#' + map_div_id + '_search__form [name="city"]' ).parent().html ( response.select );
                                 $( '#' + map_div_id + '_search__form [ident="neigbourhood_select"]' ).html ( '' );

                                 if  (  ! boo_map  )
                                 {
                                    if    (    (  typeof ( neighborhoods )  ==  'object'  )    &&    ( neighborhoods != null )    )
                                    {
                                       neighborhoods.selected           =  Array ();
                                       neighborhoods.selected_bounds    =  Array ();

                                       $( '#' + map_div_id ).data ( 'neighborhoods', neighborhoods );
                                    }

                                    GMap_Neighborhoods_InformationLine ( map_div_id );
                                    PropertySearch_ShowLink ( map_div_id );
                                 }
                                 else
                                 {
                                    for  (  var j = neighborhoods.selected.length - 1;  j >= 0;  -- j  )
                                    {
                                       var   id  =  neighborhoods.selected [ j ];
   
                                       GMap_Neighborhoods_Toggle ( map_div_id, id, false );
                                    }

                                    if    (    (  typeof ( response.bounds )  ==  'object'  )    &&    ( response.bounds != null )    )
                                       GMap_BoundsToCenter ( map_div_id, response.bounds.lat_min, response.bounds.lng_min, response.bounds.lat_max, response.bounds.lng_max );
                                    else
                                       GMap_Neighborhoods_InformationLine ( map_div_id );
                                 }
                              }
               }
            );
}


function PropertySearch_ReloadNeighborhoods ( map_div_id )
{
   var   map            =  $( '#' + map_div_id ).data ( 'map'           );
   var   neighborhoods  =  $( '#' + map_div_id ).data ( 'neighborhoods' );

   var   province_id    =  $( '#' + map_div_id + '_search__form [name="province"]' ).val ();
   var   city           =  $( '#' + map_div_id + '_search__form [name="city"]' ).val ();

   var   boo_map        =  (    (  typeof ( map )  ==  'object'  )    &&    ( map != null )    )    ?    true    :    false;

   var   request        =  {  map_div_id: map_div_id,  province: province_id,  city: city,  map: boo_map  };
   var   str            =  GMap_JSON ( request );

   $.ajax   (  {  url      :  'property_search_aux_b1.php',
                  data     :  {  request  :  str   },
                  async    :  false,
                  dataType :  'json',
                  success  :  function ( response )
                              {
                                 $( '#' + map_div_id + '_search__form [name="zoom"]' ).val ( '0' );
                                 $( '#' + map_div_id + '_search__form [ident="neigbourhood_select"]' ).html ( response.select );

                                 if  (  ! boo_map  )
                                 {
                                    if    (    (  typeof ( neighborhoods )  ==  'object'  )    &&    ( neighborhoods != null )    )
                                    {
                                       neighborhoods.selected           =  Array ();
                                       neighborhoods.selected_bounds    =  Array ();

                                       $( '#' + map_div_id ).data ( 'neighborhoods', neighborhoods );
                                    }

                                    GMap_Neighborhoods_InformationLine ( map_div_id );
                                    PropertySearch_ShowLink ( map_div_id );
                                 }
                                 else
                                 {
                                    for  (  var j = neighborhoods.selected.length - 1;  j >= 0;  -- j  )
                                    {
                                       var   id  =  neighborhoods.selected [ j ];
   
                                       GMap_Neighborhoods_Toggle ( map_div_id, id, false );
                                    }

                                    if    (    (  typeof ( response.bounds )  ==  'object'  )    &&    ( response.bounds != null )    )
                                       GMap_BoundsToCenter ( map_div_id, response.bounds.lat_min, response.bounds.lng_min, response.bounds.lat_max, response.bounds.lng_max );
                                    else
                                       GMap_Neighborhoods_InformationLine ( map_div_id );
                                 }
                              }
               }
            );
}


function PropertySearch_ReloadNeighborhoodsAndStreets ( map_div_id, mode )
{
   var   map            =  $( '#' + map_div_id ).data ( 'map'           );
   var   listings       =  $( '#' + map_div_id ).data ( 'listings'      );
   var   neighborhoods  =  $( '#' + map_div_id ).data ( 'neighborhoods' );

   var   pr_city        =  $( '#' + map_div_id + '_search__form [name="pr_city"]' ).val ();
   var   street         =  listings.street;
   var   office_id      =  $( '#' + map_div_id + '_search__form [name="office_id"]' ).val ();
   var   agent_id       =  $( '#' + map_div_id + '_search__form [name="agent_id"]' ).val ();
   var   status         =  $( '#' + map_div_id + '_search__form [name="status"]' ).val ();

   var   boo_map        =  (    (  typeof ( map )  ==  'object'  )    &&    ( map != null )    )    ?    true    :    false;

   var   request        =  {  map_div_id: map_div_id,  mode: mode,  map: boo_map,  pr_city: pr_city,  street: street,  office_id: office_id,  agent_id: agent_id,  status: status  };
   var   str            =  GMap_JSON ( request );

   $.ajax   (  {  url      :  'property_search_aux_b1.php',
                  data     :  {  request  :  str   },
                  async    :  false,
                  dataType :  'json',
                  success  :  function ( response )
                              {
                                 $( '#' + map_div_id + '_search__form [name="zoom"]' ).val ( '0' );
                                 $( '#' + map_div_id + '_search__form [name="street"]' ).parent().html ( response.street );

                                 if  (  $( '#' + map_div_id + '_search__form [name="street"] :selected' ).text()  !=  listings.street  )
                                 {
                                    listings.street   =  '';
                                    $( '#' + map_div_id ).data ( 'listings', listings );
                                 }

                                 $( '#' + map_div_id + '_search__form [ident="neigbourhood_select"]' ).html ( response.select );

                                 if  (  ! boo_map  )
                                 {
                                    if    (    (  typeof ( neighborhoods )  ==  'object'  )    &&    ( neighborhoods != null )    )
                                    {
                                       neighborhoods.selected           =  Array ();
                                       neighborhoods.selected_bounds    =  Array ();

                                       $( '#' + map_div_id ).data ( 'neighborhoods', neighborhoods );
                                    }
   
                                    GMap_Neighborhoods_InformationLine ( map_div_id );
                                    PropertySearch_ShowLink ( map_div_id );
                                 }
                                 else
                                 {
                                    for  (  var j = neighborhoods.selected.length - 1;  j >= 0;  -- j  )
                                    {
                                       var   id  =  neighborhoods.selected [ j ];
   
                                       GMap_Neighborhoods_Toggle ( map_div_id, id, false );
                                    }

                                    if    (    (  typeof ( response.bounds )  ==  'object'  )    &&    ( response.bounds != null )    )
                                       GMap_BoundsToCenter ( map_div_id, response.bounds.lat_min, response.bounds.lng_min, response.bounds.lat_max, response.bounds.lng_max );

                                    PropertySearch_Refresh ( map_div_id );
                                 }
                              }
               }
            );
}


function GMap_FitNeighborhoodBounds  ( map_div_id, id, name, lat_min, lng_min, lat_max, lng_max )
{
   id    =  parseInt ( id + '' );

   var   map            =  $( '#' + map_div_id ).data ( 'map'           );
   var   listings       =  $( '#' + map_div_id ).data ( 'listings'      );
   var   neighborhoods  =  $( '#' + map_div_id ).data ( 'neighborhoods' );
   var   bounds         =  {  id:id,  name:name,  lat_min: lat_min,  lng_min:lng_min,  lat_max:lat_max,  lng_max:lng_max  };

   var   boo_map        =  (    (  typeof ( map )  ==  'object'  )    &&    ( map != null )    )    ?    true    :    false;

   $( '#' + map_div_id + '_search__form [name="street"]' ).attr( 'selectedIndex', 0 );

   listings.street   =  '';

   $( '#' + map_div_id ).data ( 'listings', listings );

   if  (  ! boo_map  )
   {
      if    (    (  typeof ( neighborhoods )  ==  'object'  )    &&    ( neighborhoods != null )    )
      {
         neighborhoods.selected                 =  Array ( 1 );
         neighborhoods.selected_bounds          =  Array ( 1 );

         neighborhoods.selected        [ 0 ]    =  id;
         neighborhoods.selected_bounds [ 0 ]    =  bounds;

         $( '#' + map_div_id ).data ( 'neighborhoods', neighborhoods );
      }

      PropertySearch_ShowLink ( map_div_id );

      return;
   }

   var   index          =  ( id == 0  )    ?    0    :    neighborhoods.selected.indexOf ( id );

   if  (  index  <  0  )
   {
      var   marker   =  GMap_Neighborhoods_MarkerByID ( map_div_id, id );
      if  (  marker  ==  null  )
      {
         if  (  neighborhoods.selected.length  >=  5  )
         {
            neighborhoods.selected           =  neighborhoods.selected       .slice ( 1 );
            neighborhoods.selected_bounds    =  neighborhoods.selected_bounds.slice ( 1 );
         }

         neighborhoods.selected       .push ( id      );
         neighborhoods.selected_bounds.push ( bounds  );

         $( '#' + map_div_id ).data ( 'neighborhoods', neighborhoods );
      }
      else
      {
         GMap_Neighborhoods_Toggle ( map_div_id, id, true );
         return;
      }
   }

   GMap_BoundsToCenter ( map_div_id, lat_min, lng_min, lat_max, lng_max );
   PropertySearch_Refresh ( map_div_id );
}


function PropertySearch_FitNeighborhoodBounds ( map_div_id )
{
   var   bounds      =  $( '#' + map_div_id + '_search__form [name="neighborhood"]' ).val ();
                        $( '#' + map_div_id + '_search__form [name="zoom"]' ).val ( '0' );

   if  (  bounds  !=  ''  )
      setTimeout (  'GMap_FitNeighborhoodBounds("' + map_div_id + '",' + bounds + ')', 10 );
}


function GMap_FitStreetBounds  ( map_div_id, name, lat_min, lng_min, lat_max, lng_max )
{
   id    =  parseInt ( id + '' );

   var   map            =  $( '#' + map_div_id ).data ( 'map'           );
   var   listings       =  $( '#' + map_div_id ).data ( 'listings'      );
   var   neighborhoods  =  $( '#' + map_div_id ).data ( 'neighborhoods' );

   var   boo_map        =  (    (  typeof ( map )  ==  'object'  )    &&    ( map != null )    )    ?    true    :    false;

   listings.street   =  name;

   $( '#' + map_div_id ).data ( 'listings', listings );

   $( '#' + map_div_id + '_search__form [name="neighborhood"]' ).attr( 'selectedIndex', 0 );

   if  (  ! boo_map  )
   {
      if    (    (  typeof ( neighborhoods )  ==  'object'  )    &&    ( neighborhoods != null )    )
      {
         neighborhoods.selected           =  Array ();
         neighborhoods.selected_bounds    =  Array ();

         $( '#' + map_div_id ).data ( 'neighborhoods', neighborhoods );
      }

      PropertySearch_ShowLink ( map_div_id );
   }
   else
   {
      for  (  var j = neighborhoods.selected.length - 1;  j >= 0;  -- j  )
      {
         var   id  =  neighborhoods.selected [ j ];

         GMap_Neighborhoods_Toggle ( map_div_id, id, false );
      }

      GMap_BoundsToCenter ( map_div_id, lat_min, lng_min, lat_max, lng_max );
      PropertySearch_Refresh ( map_div_id );
   }
}


function PropertySearch_FitStreetBounds ( map_div_id )
{
   var   bounds      =  $( '#' + map_div_id + '_search__form [name="street"]' ).val ();
                        $( '#' + map_div_id + '_search__form [name="zoom"]' ).val ( '0' );

   if  (  bounds  !=  ''  )
      setTimeout (  'GMap_FitStreetBounds("' + map_div_id + '",' + bounds + ')', 10 );
}


function PropertySearch_ToggleNeighborhoodsGrid ( map_div_id )
{
   var   listings       =  $( '#' + map_div_id ).data ( 'listings'      );
   var   neighborhoods  =  $( '#' + map_div_id ).data ( 'neighborhoods' );

   var   hide           =  $( '#' + map_div_id + '_hide_grid__form [name="hng"]' ).is( ':checked' );

   if  (  hide  )
   {
      if  (  neighborhoods.selected.length  >  0  )
      {
         for  (  var j = neighborhoods.selected.length - 1;  j >= 0;  -- j  )
         {
            var   id  =  neighborhoods.selected [ j ];

            GMap_Neighborhoods_Toggle ( map_div_id, id, false );
         }

         listings.list     =  GMap_ClearList ( map_div_id, listings.list );
         listings.bounds   =  null;

         $( '#' + map_div_id ).data ( 'listings', listings );

         PropertySearch_Refresh ( map_div_id );
      }

      $( '#' + map_div_id + '_search__form [ident="neigbourhood_select"]' ).hide ();
      $( '#' + map_div_id + '_search__form [ident="neigbourhood_prompt"]' ).hide ();

      neighborhoods.list      =  GMap_ClearList ( map_div_id, neighborhoods.list );
      neighborhoods.bounds    =  null;

      $( '#' + map_div_id ).data ( 'neighborhoods', neighborhoods );

      PropertySearch_ShowLink ( map_div_id );
   }
   else
   {
      neighborhoods.list      =  GMap_ClearList ( map_div_id, neighborhoods.list );
      neighborhoods.bounds    =  null;
      listings.list           =  GMap_ClearList ( map_div_id, listings.list );
      listings.bounds         =  null;

      $( '#' + map_div_id ).data ( 'neighborhoods', neighborhoods );
      $( '#' + map_div_id ).data ( 'listings',      listings      );

      GMap_RelocationListener_Reload ( map_div_id );
   }
}


function GMap_Reload ( map_div_id, request )
{
   var   listings    =  $( '#' + map_div_id ).data ( 'listings'   );
   var   relocation  =  $( '#' + map_div_id ).data ( 'relocation' );
   var   map         =  $( '#' + map_div_id ).data ( 'map'        );

   if  (  map  ==  null  )
   {
      PropertySearch_ShowLink ( map_div_id );
      return;
   }

   GMap_PopupText_Hide ();
   PropertySearch_InfoWindow_Hide ( map_div_id );

   if  (  listings.zoom_notice_div_id  !=  ''  )
   {
      var   hide  =  (  typeof ( request.listings )  !=  'undefined'  )    ?    request.listings.map    :    false;

      if  (  hide  )
         $( '#' + listings.zoom_notice_div_id ).hide ();
   }

   $( '#' + relocation.information_div_id ).show ();

   var   offset   =  $( '#' + map_div_id ).offset();

   offset.left   +=  (  $( '#' + map_div_id ).outerWidth ()  -  $( '#' + relocation.information_div_id ).outerWidth ()  )    /    2;
   offset.top    +=  (  $( '#' + map_div_id ).outerHeight()  -  $( '#' + relocation.information_div_id ).outerHeight()  )    /    2;

   $( '#' + relocation.information_div_id ).css  (  'left',  parseInt ( offset.left ) + 'px'  );
   $( '#' + relocation.information_div_id ).css  (  'top',   parseInt ( offset.top  ) + 'px'  );

   request.bounds       =  GMap_Bounds ( map );
   request.map_div_id   =  map_div_id;

   relocation.request   =  request;

   $( '#' + map_div_id ).data ( 'relocation', relocation );

   setTimeout (  'GMap_Reload_Ajax("'+map_div_id+'")', 10 );
}


function GMap_Reload_Ajax ( map_div_id )
{
   PropertySearch_ShowLink ( map_div_id );

   var   listings    =  $( '#' + map_div_id ).data ( 'listings'   );
   var   relocation  =  $( '#' + map_div_id ).data ( 'relocation' );

   if  (  typeof ( relocation.request.listings )  !=  'undefined'  )
   {
      relocation.request.listings.count   =  0;

      for  (  var i = 0;  i < listings.list.length;  ++i  )
      {
         var   obj   =  listings.list [ i ];

         if  (  obj.IsVisible ()  )
            ++ relocation.request.listings.count;
      }
   }

   var   str         =  GMap_JSON ( relocation.request );

   $.ajax   (  {  url      :  'property_search_responder_b1.php',
                  data     :  {  request  :  str   },
                  async    :  true,
                  dataType :  'json',
                  success  :  function ( response )
                              {
                                 var   listings    =  $( '#' + map_div_id ).data ( 'listings'  );

                                 if     (  typeof ( response.neighborhoods      )  !=  'undefined'  )    GMap_Neighborhoods_Reload( map_div_id, response.neighborhoods, response.bounds );
                                 else
                                    GMap_Neighborhoods_InformationLine ( map_div_id );

                                 if     (  typeof ( response.utilities          )  !=  'undefined'  )    GMap_Utilities_Reload    ( map_div_id, response.utilities,     response.bounds );
                                 if     (  typeof ( response.listings           )  !=  'undefined'  )
                                 {
                                    if  (  typeof ( response.listings.map       )  !=  'undefined'  )    GMap_Listings_Reload     ( map_div_id, response.listings,      response.bounds );

                                    if  (  typeof ( response.listings.found     )  !=  'undefined'  )    $( '#' + listings.found_div_id     ).html ( response.listings.found     );
                                    if  (  typeof ( response.listings.favorites )  !=  'undefined'  )    $( '#' + listings.favorites_div_id ).html ( response.listings.favorites );
                                    if  (  typeof ( response.listings.recent    )  !=  'undefined'  )    $( '#' + listings.recent_div_id    ).html ( response.listings.recent    );
                                 }
                              },
                  complete :  function ( jqXHR, textStatus )
                              {
                                 relocation.reloading    =  false;
                                 $( '#' + relocation.information_div_id ).hide ();
                                 $( '#' + map_div_id ).data ( 'relocation', relocation );
                              }
               }
            );
}


function GMap_Click ( event )
{
   var   map_div_id  =  this.getDiv().id;

   GMap_PopupText_Hide ();
   PropertySearch_InfoWindow_Hide ( map_div_id );
}


function GMap_RelocationListener_Callback ( event )
{
   var   map_div_id  =  this.getDiv().id;
   var   relocation  =  $( '#' + map_div_id ).data ( 'relocation' );

   if ( relocation.timeout != 0 )
      clearTimeout ( relocation.timeout );

   relocation.timeout   =  setTimeout (  'GMap_RelocationListener_Reload("'+map_div_id+'")',  500  );

   $( '#' + map_div_id ).data ( 'relocation', relocation );
}


function GMap_RelocationListener_Reload ( map_div_id )
{
   var   settings    =  $( '#' + map_div_id ).data ( 'settings'   );
   var   relocation  =  $( '#' + map_div_id ).data ( 'relocation' );
   var   map         =  $( '#' + map_div_id ).data ( 'map'        );
   var   listings    =  $( '#' + map_div_id ).data ( 'listings'   );
   var   request     =  {};

   if  (  relocation.reloading  )
   {
      setTimeout ( 'GMap_RelocationListener_Reload("'+map_div_id+'")', 100 );
      return;
   }

   relocation.timeout      = 0;
   relocation.reloading    =  true;

   $( '#' + map_div_id ).data ( 'relocation', relocation );

   var   hide  =  $( '#' + map_div_id + '_hide_grid__form [name="hng"]' ).is( ':checked' );

   if  (  ( settings.show.neighborhoods !=  0 )  &&  ( ! hide )  )
   {
      var   neighborhoods  =  $( '#' + map_div_id ).data ( 'neighborhoods' );

      if  (  map.getZoom()  <  10  )
      {
         neighborhoods.list      =  GMap_ClearList ( map_div_id, neighborhoods.list );
         neighborhoods.bounds    =  null;

         $( '#' + map_div_id ).data ( 'neighborhoods', neighborhoods );
      }
      else
      {
         request.neighborhoods   =  {  bounds   :  neighborhoods.bounds  };
      }
   }

   if  (  settings.show.utilities  )
   {
      var   utilities      =  $( '#' + map_div_id ).data ( 'utilities' );

      if  (  utilities.results_div_id  !=  ''  )
         $( '#' + utilities.results_div_id ).html ( "<img src='4a_layout/spacer.gif' border='0' width='1' height='1' alt=''>" );

      if  (  map.getZoom()  <  13  )
      {
         utilities.list    =  GMap_Utilities_CleanList ( utilities.list, -1 );
         utilities.bounds  =  null;

         if  (  utilities.information_div_id  !=  ''  )
            $( '#' + utilities.information_div_id ).html (  GMap_InfoString ( 'Zoom in to display neighborhood feature icons' )  );

         $( '#' + map_div_id ).data ( 'utilities', utilities );
      }
      else
      {
         if  (  utilities.selected.length  >  0  )
            request.utilities    =  {  bounds   :  utilities.bounds,    selected :  utilities.selected   };
         else  if  (  utilities.information_div_id  !=  ''  )
            $( '#' + utilities.information_div_id ).html (  GMap_InfoString ( 'You can select up to 3 neighborhood feature icons' )  );
      }
   }

   var   neighborhoods_list   =  null;
   var   settings_details     =  settings.details;

   if  ( settings.show.neighborhoods == 4 )
   {
      var   neighborhoods  =  $( '#' + map_div_id ).data ( 'neighborhoods' );

      neighborhoods_list   =  neighborhoods.selected;
      settings_details     =  (  ( listings.list.length > 0 )  &&  ( neighborhoods_list.length > 0 )  )    ?    false    :    settings_details;
   }

   request.listings  =  {  bounds         :  listings.bounds,
                           mode           :  settings.mode,
                           neighborhoods  :  neighborhoods_list,
                           map            :  true,
                           details        :  settings_details,
                           property_type  :  $( '#' + map_div_id + '_search__form [name="property_type"]' ).val (),
                           property_type2 :  $( '#' + map_div_id + '_search__form [name="property_type2"]' ).val (),
                           price_from     :  $( '#' + map_div_id + '_search__form [name="price_from"]' ).val (),
                           price_to       :  $( '#' + map_div_id + '_search__form [name="price_to"]' ).val (),
                           bedrooms       :  $( '#' + map_div_id + '_search__form [name="bedrooms"]' ).val (),
                           bathrooms      :  $( '#' + map_div_id + '_search__form [name="bathrooms"]' ).val (),
                           page_size      :  $( '#' + map_div_id + '_search__form [name="page_size"]' ).val (),
                           page_numb      :  1,
                           sorting        :  $( '#' + map_div_id + '_search__form [name="sorting"]' ).val (),
                           commercial     :  $( '#' + map_div_id + '_search__form [name="commercial"]' ).val (),
                           sid            :  $( '#' + map_div_id + '_search__form [name="sid"]' ).val (),
                           status         :  $( '#' + map_div_id + '_search__form [name="status"]' ).val (),
                           office_id      :  $( '#' + map_div_id + '_search__form [name="office_id"]' ).val (),
                           agent_id       :  $( '#' + map_div_id + '_search__form [name="agent_id"]' ).val ()
                        };

   if  (  ! listings.idx_search  )
   {
      request.listings.pr_city   =  $( '#' + map_div_id + '_search__form [name="pr_city"]' ).val ();
      request.listings.street    =  listings.street;
   }

   GMap_Reload ( map_div_id, request );
}


function PropertySearch_FormSubmit ( map_div_id, unselect_street )
{
   if  (  unselect_street  )
      $( '#' + map_div_id + '_search__form [name="street"]' ).attr( 'selectedIndex', 0 );
   else
      $( '#' + map_div_id + '_search__form [name="neighborhood"]' ).attr( 'selectedIndex', 0 );

   $( '#' + map_div_id + '_search__form' ).submit();
}


function PropertySearch_ShowLink ( map_div_id )
{
   var   webpage  =  $( '#' + map_div_id + '_show_link__form' + ' [name="webpage"]' ).val ();

   if  (  typeof ( webpage )  !=  'undefined'  )
   {
      var   map               =  $( '#' + map_div_id ).data ( 'map'           );
      var   settings          =  $( '#' + map_div_id ).data ( 'settings'      );
      var   listings          =  $( '#' + map_div_id ).data ( 'listings'      );
      var   neighborhoods     =  $( '#' + map_div_id ).data ( 'neighborhoods' );
      var   params            =  '';

      var   property_type     =  $( '#' + map_div_id + '_search__form [name="property_type"]' ).val ();
      var   property_type2    =  $( '#' + map_div_id + '_search__form [name="property_type2"]' ).val ();
      var   price_from        =  $( '#' + map_div_id + '_search__form [name="price_from"]' ).val ();
      var   price_to          =  $( '#' + map_div_id + '_search__form [name="price_to"]' ).val ();
      var   bedrooms          =  $( '#' + map_div_id + '_search__form [name="bedrooms"]' ).val ();
      var   bathrooms         =  $( '#' + map_div_id + '_search__form [name="bathrooms"]' ).val ();
      var   page_size         =  $( '#' + map_div_id + '_search__form [name="page_size"]' ).val ();
      var   sorting           =  $( '#' + map_div_id + '_search__form [name="sorting"]' ).val ();
      var   sid               =  $( '#' + map_div_id + '_search__form [name="sid"]' ).val ();
      var   office_id         =  $( '#' + map_div_id + '_search__form [name="office_id"]' ).val ();
      var   agent_id          =  $( '#' + map_div_id + '_search__form [name="agent_id"]' ).val ();

      if  (  property_type   !=   '0'  )        params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'property_type='  +  property_type;
      if  (  property_type2  !=   '0'  )        params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'property_type2='  +  property_type2;
      if  (  price_from      !=   '0'  )        params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'price_from='  +  price_from;
      if  (  price_to        !=   '0'  )        params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'price_to='  +  price_to;
      if  (  bedrooms        !=   '0'  )        params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'bedrooms='  +  bedrooms;
      if  (  bathrooms       !=   '0'  )        params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'bathrooms='  +  bathrooms;
      if  (  page_size       !=  '10'  )        params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'page_size='  +  page_size;
      if  (  sorting         !=   '0'  )        params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'sorting='  +  sorting;
      if  (  office_id       !=   '0'  )        params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'office_id='  +  office_id;
      if  (  agent_id        !=   '0'  )        params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'agent_id='  +  agent_id;

      var   nids  =  '';
      if    (    (  typeof ( map )  ==  'object'  )    &&    ( map != null )    &&    (  typeof ( neighborhoods )  ==  'object'  )    &&    ( neighborhoods != null )    )
      {
         var   count          =  ( neighborhoods == null )  ?  0  :  neighborhoods.selected.length;

         for  (  var i = 0;  i < count;  ++ i  )
            nids  +=  (  ( i == 0 )  ?  ''  :  ','  )  +  neighborhoods.selected [ i ];
      }
      else
      {
         var   w  =                                     $( '#' + map_div_id + '_search__form [ident="neigbourhood_select"]:visible' ).width();
         var   id =  ( w != null )    ?    parseInt  (  $( '#' + map_div_id + '_search__form [name="neighborhood"]'         ).val  ()  +  ''  )    :    0;
         if  (  id != 0  )
            nids  =  id;
      }

      if  (  nids  !=  ''  )
         params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'nids='  +  nids;

      else 
      {
         if  (  sid  ==  ''  )
         {
            if  (  listings.idx_search  )
            {
               var   city  =  $( '#' + map_div_id + '_search__form [name="city"]' ).val ();

               params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'province=' + $( '#' + map_div_id + '_search__form [name="province"]' ).val ();

               if  (  city  !=  ''  )
                  params  +=  '&city=' + city;
            }
            else  
            {
               var   pr_city  =  $( '#' + map_div_id + '_search__form [name="pr_city"]' ).val ();

               if  (  pr_city  !=  '0,'  )
                  params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'pr_city=' + pr_city;
               if  (  listings.street  !=  ''  )
                  params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'street='  + listings.street;
            }

            if  (  map  !=  null  )
            {
               var   bounds   =  GMap_Bounds ( map );
               if  (  bounds  !=  null  )
               {
                  params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'zoom=' + map.getZoom();
                  params  +=  '&lat_min=' + bounds.lat_min + '&lng_min=' + bounds.lng_min + '&lat_max=' + bounds.lat_max + '&lng_max=' + bounds.lng_max;
               }
            }
            else
            {
               var   zoom  =  $( '#' + map_div_id + '_search__form [name="zoom"]' ).val ();
               if    (    (  typeof ( zoom )  !=  'undefined'  )    &&    ( zoom != '0' )    &&    ( zoom != null )    )
               {
                  var   lat_min  =  $( '#' + map_div_id + '_search__form [name="lat_min"]' ).val ();
                  var   lng_min  =  $( '#' + map_div_id + '_search__form [name="lng_min"]' ).val ();
                  var   lat_max  =  $( '#' + map_div_id + '_search__form [name="lat_max"]' ).val ();
                  var   lng_max  =  $( '#' + map_div_id + '_search__form [name="lng_max"]' ).val ();

                  params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'zoom=' + zoom;
                  params  +=  '&lat_min=' + lat_min + '&lng_min=' + lng_min + '&lat_max=' + lat_max + '&lng_max=' + lng_max;
               }
            }
         }
      }

      if  (  sid  !=  ''  )
         params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'sid='  +  sid;

      if  ( settings.show.utilities )
      {
         var   utilities   =  $( '#' + map_div_id ).data ( 'utilities' );

         if  (  utilities.selected.length  >  0  )
         {
            params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'fids=';

            for  (  var i = 0;  i < utilities.selected.length;  ++ i  )
               params  +=  (  ( i == 0 )  ?  ''  :  ','  )  +  utilities.selected [ i ];
         }
      }

      if    (    $( '#' + map_div_id + '_hide_grid__form [name="hng"]' ).is( ':checked' )    )
         params  +=  (  ( params == '' )  ?  '?'  :  '&'  )  +  'hng=1';

      $( '#' + map_div_id + '_show_link__form' + ' [name="link"]' ).val  (         webpage + params );
      $( '#' + map_div_id + '_show_link__form' + ' [link="1"]' ).attr ( 'href', webpage + params );
   }
}

function PropertySearch_CopyLinkAndClose ( map_div_id, name )
{
   var   url   =  $( '#' + map_div_id + '_show_link__form' + ' [name="link"]' ).val ();

   if  (  typeof ( url )  !=  'undefined'  )
   {
      var   arr   =  name.split ( '.' );
      var   str   =  'form[name="' + arr [ 0 ] + '"] input[name="' + arr [ 1 ] + '"]';
      var   val   =  window.opener.$( str ).val ();

      window.opener.$( str ).val ( url );
//      eval ( 'parent.document.' + name + '.value=url;' );
      window.close ( true );
   }
}


function PropertySearch_ShowDetails ( map_div_id, div_to_show )
{
   var   listings    =  $( '#' + map_div_id ).data ( 'listings'  );
   var   utilities   =  $( '#' + map_div_id ).data ( 'utilities' );

   $( '[class="TD_DetailsTab_Selected"]' ).attr ( 'class', 'TD_DetailsTab_NotSelected' );
   $( '[class="A_DetailsTab_Selected"]'  ).attr ( 'class', 'A_DetailsTab_NotSelected'  );

   $( '[ident="td_' + div_to_show + '"]' ).attr ( 'class', 'TD_DetailsTab_Selected' );
   $( '[ident="a_'  + div_to_show + '"]' ).attr ( 'class', 'A_DetailsTab_Selected'  );

                                                                                                $( '#' + listings .found_div_id     ).hide ();
                                                                                                $( '#' + listings .favorites_div_id ).hide ();
                                                                                                $( '#' + listings .recent_div_id    ).hide ();
         if                                         ( utilities.results_div_id != '' )          $( '#' + utilities.results_div_id   ).hide ();

         if  (  ( div_to_show == 'utilities' )  &&  ( utilities.results_div_id != '' )  )       $( '#' + utilities.results_div_id   ).show ();
   else  if     ( div_to_show == 'favorites' )                                                  $( '#' + listings .favorites_div_id ).show ();
   else  if     ( div_to_show == 'recent'    )                                                  $( '#' + listings .recent_div_id    ).show ();
   else                                                                                         $( '#' + listings .found_div_id     ).show ();
}

function    PropertySearch_Init ( settings )
{
   google.maps.Marker .prototype.IsVisible = function()  {  return   GMap_Marker_IsVisible  ( this );   };
   google.maps.Polygon.prototype.IsVisible = function()  {  return   GMap_Polygon_IsVisible ( this );   };

   if  (  ! Array.indexOf  )
   {
	   Array.prototype.indexOf    =  function (obj )
                                    {
                              	      for  (  var i = 0;  i < this.length;  ++ i  )
                                       {
                              	         if  (  this [ i ]  ==  obj  )
                              	            return   i;
                              	      }
                              	      return   -1;
                           	      }
	}

   var   map_div_id  =  settings.map.div_id;

   if  (  settings.show.neighborhoods  !=  0  )
   {
      var   neighborhoods  =  {  list                 :  new Array(),
                                 bounds               :  null,
                                 selected             :  settings.neighborhoods.selected,
                                 selected_bounds      :  settings.neighborhoods.selected_bounds,
                                 information_text     :  settings.neighborhoods.information_text,
                                 information_div_id   :  ( map_div_id + '_neighborhoods_info' ),
                                 timeout              :  0,
                                 callback             :  false
                              };
      $( '#' + map_div_id ).data ( 'neighborhoods', neighborhoods );
   }

   if  (  settings.show.utilities  )
   {
      var   utilities      =  {  list                 :  new Array(),
                                 bounds               :  null,
                                 selected             :  settings.utilities.selected,
                                 information_div_id   :                          map_div_id + '_utilities_info',
                                 results_div_id       :  (  settings.details  ?  map_div_id + '_utilities_results'   :  ''  )
                              };
      $( '#' + map_div_id ).data ( 'utilities', utilities );

      GMap_Utilities_InitControl ( map_div_id );
   }

   var   listings       =  {  list                 :  new Array(),
                              bounds               :  null,
                              zoom_notice          :  true,
                              idx_search           :  (  ( settings.mode == 1 )  ?  true  :  false  ),
                              MLS                  :  '',
                              id2                  :  0,
                              street               :  settings.street,
                              found_div_id         :  (  settings.details  ?  map_div_id + '_listings_found'      :  ''   ),
                              favorites_div_id     :  (  settings.details  ?  map_div_id + '_listings_favorites'  :  ''   ),
                              recent_div_id        :  (  settings.details  ?  map_div_id + '_listings_recent'     :  ''   ),
                              information_div_id   :  (                       map_div_id + '_listings_info'               ),
                              zoom_notice_div_id   :  (                       map_div_id + '_zoom_notice'                 )
                           };
   var   relocation     =  {  timeout              :  0,
                              reloading            :  false,
                              request              :  null,
                              information_div_id   :  ( map_div_id + '_relocation' )
                           };
   var   mapOptions     =  {  zoom                 :  17,
                              center               :  new google.maps.LatLng ( settings.map.lat, settings.map.lng ),
                              mapTypeId            :  google.maps.MapTypeId.ROADMAP
                           };

   var   map            =  new google.maps.Map  (  document.getElementById ( map_div_id ),  mapOptions  );

   $( '#' + map_div_id ).data ( 'settings',   settings   );
   $( '#' + map_div_id ).data ( 'relocation', relocation );
   $( '#' + map_div_id ).data ( 'map',        map        );
   $( '#' + map_div_id ).data ( 'listings',   listings   );

   google.maps.event.addListener ( map, 'click',          GMap_Click                       );
   google.maps.event.addListener ( map, 'bounds_changed', GMap_RelocationListener_Callback );

   if  (  settings.map.zoom  ==  17  )
      GMap_BoundsToCenter ( map_div_id, settings.map.lat_min, settings.map.lng_min, settings.map.lat_max, settings.map.lng_max );
   else
      map.setZoom ( settings.map.zoom );

   GMap_Neighborhoods_InformationLine ( map_div_id );

   var   street_view =  map.getStreetView ();

   google.maps.event.addListener ( street_view, 'visible_changed', function(){PropertySearch_InfoWindow_Hide(map_div_id);} );
   
   setTimeout ( 'PropertySearch_ShowLink("'+map_div_id+'")', 500 );
}
