
﻿
var k_default_icon_color="#CB9D7C";var k_default_icon_label="x";var k_default_icon=MapIconMaker.createFlatIcon({label:k_default_icon_label,labelSize:12,shape:"roundrect",width:20,height:20,primaryColor:k_default_icon_color});var k_default_zoom_level=13;var k_max_points=100;var g_icon_types=new Object();var g_markers_visible=false;var g_city_markers_visible=false;var g_map_bounds;var g_map_center;var g_map_zoom_level;var g_filter=new Object();var g_city_idx=-1;var g_total_postings=0;var g_city_data=null;var g_map_data=null;var g_map;function setdp(id,dp)
{var e=document.getElementById(id);if(e)
{e.style.display=dp;}}
function toggle_inline(id)
{var e=document.getElementById(id);if(e)
{var ds=e.style.display;if(!ds)ds=new String();if(ds.toLowerCase()=="inline")
e.style.display="none";else
e.style.display="inline";}}
function toggle_block(id)
{var e=document.getElementById(id);if(e)
{var ds=e.style.display;if(!ds)ds=new String();if(ds.toLowerCase()=="block")
e.style.display="none";else
e.style.display="block";}}
function msgbox_update(html)
{var e=document.getElementById("msgbox");e.innerHTML=html;}
function show_busy()
{msgbox_update('<img src="/images/busy_icon_1.gif" alt="Working..." align="middle" height="32" width="32"> Working...');}
function markers_clear_all()
{if(g_markers_visible)
{var i;for(i=0;i<g_map_data.points.length;i++)
{if(g_map_data.points[i].marker)
{g_map.removeOverlay(g_map_data.points[i].marker);g_map_data.points[i].marker=null;}}
g_markers_visible=false;}}
function marker_create(idx,pc,params)
{var html;var icn;var icon_color;var icon_label;var icon_title;var marker;var pticon;var rtc;var url;if(g_filter.rtc>0)
rtc=g_filter.rtc;else
rtc=g_map_data.points[idx].postings[0].rtc;if(pc>1)
{icon_title="Multiple Listings";pticon=MapIconMaker.createFlatIcon({label:pc.toString(),shape:"roundrect",width:24,height:24,primaryColor:k_default_icon_color});}
else
{icn=g_icon_types[rtc];if(icn)
{pticon=icn.icon;icon_title=icn.name;}
else
{icon_title="For Rent";pticon=k_default_icon;}}
marker=new GMarker(g_map_data.points[idx].gpt,{icon:pticon,title:icon_title});url='http://www.rentboard.ca/rentals/map/infowindow.aspx?pstuid='+params;if(pc>1)
{html='<div style="height:300px;width:340px;">';}
else
{html='<div style="height:280px;width:340px;">';}
html+='<iframe name="miw" frameborder="0" scrolling="no" height="100%" width="100%" src="'+url+'"></iframe>';html+='</div>';GEvent.addListener(marker,"click",function(){marker.openInfoWindowHtml(html,{disableGoogleLinks:true});});return marker;}
function parse_money(v)
{if(!v)return 0;if(v.length==0)return 0;var valid_chars='1234567890.';var c;var i;var s;s='';for(i=0;i<v.length;i++)
{c=v.charAt(i);if(valid_chars.indexOf(c)>=0)
s+=c;}
if(s.length>0)
{n=parseFloat(s);if(isNaN(n))
return 0;return n;}
return 0;}
function filter_check(i,j)
{if(g_filter.active)
{if(g_filter.rtc>0)
{if(g_map_data.points[i].postings[j].rtc!=g_filter.rtc)return false;}
if((g_map_data.points[i].postings[j].ra<g_filter.price_min)||(g_map_data.points[i].postings[j].ra>g_filter.price_max))return false;if((g_map_data.points[i].postings[j].beds<g_filter.beds_min)||(g_map_data.points[i].postings[j].beds>g_filter.beds_max))return false;if((g_map_data.points[i].postings[j].bath<g_filter.bath_min)||(g_map_data.points[i].postings[j].bath>g_filter.bath_max))return false;if(g_filter.furn>=0)
{if(g_map_data.points[i].postings[j].furn!=g_filter.furn)return false;}
if(g_filter.pets>=0)
{if(g_map_data.points[i].postings[j].pets!=g_filter.pets)return false;}}
return true;}
function filters_reset()
{document.f2.posting_type.selectedIndex=0;document.f2.price_min.value='';document.f2.price_max.value='';document.f2.beds_min.selectedIndex=0;document.f2.beds_max.selectedIndex=0;document.f2.bath_min.selectedIndex=0;document.f2.bath_max.selectedIndex=0;document.f2.furnished[2].checked=true;document.f2.allowpets[2].checked=true;}
function get_filter_values()
{var i;var n;var t;var v;i=document.f2.posting_type.selectedIndex;v=document.f2.posting_type.options[i].value;g_filter.rtc=parseInt(v);g_filter.price_min=parse_money(document.f2.price_min.value);g_filter.price_max=parse_money(document.f2.price_max.value);i=document.f2.beds_min.selectedIndex;v=document.f2.beds_min.options[i].value;g_filter.beds_min=parseInt(v);i=document.f2.beds_max.selectedIndex;v=document.f2.beds_max.options[i].value;g_filter.beds_max=parseInt(v);i=document.f2.bath_min.selectedIndex;v=document.f2.bath_min.options[i].value;g_filter.bath_min=parseFloat(v);i=document.f2.bath_max.selectedIndex;v=document.f2.bath_max.options[i].value;g_filter.bath_max=parseFloat(v);for(i=0;i<document.f2.furnished.length;i++)
{if(document.f2.furnished[i].checked)
{g_filter.furn=document.f2.furnished[i].value;break;}}
for(i=0;i<document.f2.allowpets.length;i++)
{if(document.f2.allowpets[i].checked)
{g_filter.pets=document.f2.allowpets[i].value;break;}}
g_filter.active=false;n=g_filter.rtc+
g_filter.price_min+g_filter.price_max+
g_filter.beds_min+g_filter.beds_max+
g_filter.bath_min+g_filter.bath_max;if(n!=0)
{g_filter.active=true;}
else
{if((g_filter.furn>=0)||(g_filter.pets>=0))
g_filter.active=true;}
if(g_filter.active)
{if((g_filter.price_min==0)&&(g_filter.price_max==0))
g_filter.price_max=999999999.99;if(g_filter.price_min>g_filter.price_max)
{t=g_filter.price_max;g_filter.price_max=g_filter.price_min;g_filter.price_min=t;}
if(g_filter.beds_max==0)
g_filter.beds_max=99;if(g_filter.beds_min>g_filter.beds_max)
{t=g_filter.beds_max;g_filter.beds_max=g_filter.beds_min;g_filter.beds_min=t;}
if(g_filter.bath_max==0)
g_filter.bath_max=99;if(g_filter.bath_min>g_filter.bath_max)
{t=g_filter.bath_max;g_filter.bath_max=g_filter.bath_min;g_filter.bath_min=t;}}}
function points_in_bounds()
{if(!g_map_data)return 0;var i;var j;var n=0;for(i=0;i<g_map_data.points.length;i++)
{if(g_map_bounds.contains(g_map_data.points[i].gpt))
{for(j=0;j<g_map_data.points[i].postings.length;j++)
{if(filter_check(i,j))
n=n+1;}}}
return n;}
function viewport_show_markers()
{if(!g_map_data)return;var i;var hash;var j;var m;var msg;var n;var params;var pc;if(!g_markers_visible)
g_map.closeInfoWindow();get_filter_values();n=points_in_bounds();if(n==0)
{markers_clear_all();msg='No rental listings were found within the map<br>area shown, try:';msg+='<ul>';if(g_filter.active)
{msg+='<li>Changing the filter values</li>';}
msg+='<li>Moving the map to a different area</li>';msg+='<li>Zooming out to expand the search area</li>';msg+='</ul>';msgbox_update(msg);g_map.openInfoWindowHtml(g_map_center,msg,{noCloseOnClick:true});return;}
if(n>k_max_points)
{markers_clear_all();msg='There are '+n+' rental listings within<br>the map area shown:';msg+='<ul><li><b>Zoom In</b> to view listing locations.</li>';msg+='<li>Move the map to a different area</li>';msg+='</ul>';msgbox_update(msg);g_map.openInfoWindowHtml(g_map_center,msg,{noCloseOnClick:true});return;}
for(i=0;i<g_map_data.points.length;i++)
{if(g_map_bounds.contains(g_map_data.points[i].gpt))
{hash='';params='';pc=0;for(j=0;j<g_map_data.points[i].postings.length;j++)
{if(filter_check(i,j))
{hash+=j.toString();pc=pc+1;if(pc>1)params+=',';params+=g_map_data.points[i].postings[j].uid;}}
m=g_map_data.points[i].marker;if(pc>0)
{if(m!=null)
{if(hash!=g_map_data.points[i].hash)
{g_map.removeOverlay(m);g_map_data.points[i].marker=null;m=null;}}
if(!m)
{m=marker_create(i,pc,params);g_map_data.points[i].marker=m;g_map_data.points[i].hash=hash;g_map.addOverlay(m);}}
else
{if(m!=null)
{g_map.removeOverlay(m);g_map_data.points[i].marker=null;}}}
else
{m=g_map_data.points[i].marker;if(m!=null)
{g_map.removeOverlay(m);g_map_data.points[i].marker=null;m=null;}}}
g_markers_visible=true;msg='Total rental listings: '+g_total_postings;msg+='<br>';if(n>1)
{msg+='There are <b>'+n+'</b> rental listings within in the map area shown. ';msg+='Click on a marker to view rental information.';}
else
{msg+='There is <b>one</b> rental listing within the map area shown. Click on a marker to view rental information.';}
msgbox_update(msg);}
function viewport_update()
{if(!g_map_data)return;show_busy();g_map_bounds=g_map.getBounds();g_map_center=g_map_bounds.getCenter();viewport_show_markers();}
function init_viewport()
{var bounds;var i;var j;var n;get_filter_values();bounds=new GLatLngBounds();n=0;for(i=0;i<g_map_data.points.length;i++)
{for(j=0;j<g_map_data.points[i].postings.length;j++)
{if(filter_check(i,j))
{bounds.extend(g_map_data.points[i].gpt);n=n+1;}}}
if(n==0)
{g_map_zoom_level=k_default_zoom_level;}
else if(n==1)
{g_map_center=bounds.getCenter();g_map_zoom_level=k_default_zoom_level;}
else if(n>50)
{g_map_zoom_level=k_default_zoom_level;}
else
{g_map_center=bounds.getCenter();g_map_zoom_level=g_map.getBoundsZoomLevel(bounds);}/*if*/g_map.setCenter(g_map_center,g_map_zoom_level);setdp('mrlink','inline');setdp('fplink','inline');}
function set_rentboard_link(idx)
{var e;var html;html='<a href="http://www.rentboard.ca/rentals/index.aspx?locid=';html+=g_city_data.points[idx].clocid;html+='" target="_top">View All ';html+=g_city_data.points[idx].cname;html+=' Rental Listings</a>';e=document.getElementById("rblink");if(e)
{e.innerHTML=html;setdp('rblink','inline');}}
function load_map_points(response)
{g_total_postings=0;try
{g_map_data=eval(response);}
catch(e)
{g_map_data=null;}
if(!g_map_data)
{msgbox_update('Unable to obtain map data, please try again later.');return;}
if(g_map_data.points.length==0)
{msgbox_update('No rental listings were found at this time, please try again later.');return;}
var i;for(i=0;i<g_map_data.points.length;i++)
{g_map_data.points[i].marker=null;g_map_data.points[i].gpt=new GLatLng(g_map_data.points[i].lat,g_map_data.points[i].lon);g_total_postings=g_total_postings+g_map_data.points[i].postings.length;}
init_viewport();}
function do_filter_update()
{setdp("fpanel","none");do_search();}
function city_zoom(idx)
{var i;var si=-1;show_busy();for(i=0;i<document.f1.city_list.options.length;i++)
{if(document.f1.city_list.options[i].value==idx)
{si=i;break;}}
if(si<0)return;document.f1.city_list.selectedIndex=si;remove_city_markers();do_search();}
function do_search()
{var i=document.f1.city_list.selectedIndex;var v=document.f1.city_list.options[i].value;var idx=parseInt(v);if((idx<0)||(idx>=g_city_data.points.length))
{msgbox_update('<span style="color:#FF0000;font-weight:bold;">Select a City/Town</font>');return;}
show_busy();remove_city_markers();if(g_city_idx==idx)
{viewport_update();return;}
g_city_idx=idx;if(g_map_data)
{markers_clear_all();g_map_data=null;}
set_rentboard_link(idx);var lat=g_city_data.points[idx].lat;var lon=g_city_data.points[idx].lon;g_map_center=new GLatLng(lat,lon);g_map_zoom_level=k_default_zoom_level;url="/rentals/map/map_data.aspx?ac=2&lat="+lat+"&lon="+lon+"&rad=50";GDownloadUrl(url,load_map_points);}
function remove_city_markers()
{if(!g_city_markers_visible)return;if(!g_city_data)return;if(g_city_data.points.length<=0)return;var i;for(i=0;i<g_city_data.points.length;i++)
{if(g_city_data.points[i].marker)
{g_map.removeOverlay(g_city_data.points[i].marker);g_city_data.points[i].marker=null;}}
g_city_markers_visible=false;}
function create_city_marker(idx)
{var marker=new GMarker(g_city_data.points[idx].gpt);var html;html=g_city_data.points[idx].cname+', '+g_city_data.points[idx].pname;html+='<br><br>';html+='<a href="javascript:city_zoom('+idx+');">Show rental listing locations</a>.';GEvent.addListener(marker,"click",function(){marker.openInfoWindowHtml(html);});return marker;}
function show_city_markers()
{if(!g_city_data)return;if(g_city_data.points.length<=0)return;var bounds;var i;var m;var bounds=new GLatLngBounds();for(i=0;i<g_city_data.points.length;i++)
{bounds.extend(g_city_data.points[i].gpt);}
g_map_center=bounds.getCenter();g_map_zoom_level=g_map.getBoundsZoomLevel(bounds);g_map.setCenter(g_map_center,g_map_zoom_level);for(i=0;i<g_city_data.points.length;i++)
{g_city_data.points[i].marker=create_city_marker(i);g_map.addOverlay(g_city_data.points[i].marker);}
g_city_markers_visible=true;msgbox_update("Select a city from the menu below; then click the Search button, or click on a marker in the map.");}
function add_city(selectbox,text,value)
{var opt=document.createElement("option");opt.text='  » '+text;opt.value=value;selectbox.options.add(opt);}
function add_province(selectbox,text)
{var opt=document.createElement("option");opt.text=text;opt.value=-1;selectbox.options.add(opt);}
function load_city_points(response)
{try
{g_city_data=eval(response);}
catch(e)
{g_city_data=null;}
if(!g_city_data)
{msgbox_update("Unable to obtain map data, please try again later.");return;}
if(g_city_data.points.length<=0)
{msgbox_update('Unable to obtain map data, please try again later.');return;}
setdp("mapform","block");var i;var loc_id;var s;loc_id=0;for(i=0;i<g_city_data.points.length;i++)
{g_city_data.points[i].gpt=new GLatLng(g_city_data.points[i].lat,g_city_data.points[i].lon);g_city_data.marker=null;if(loc_id!=g_city_data.points[i].plocid)
{add_province(document.f1.city_list,' ');add_province(document.f1.city_list,g_city_data.points[i].pname.toUpperCase());loc_id=g_city_data.points[i].plocid;}
add_city(document.f1.city_list,g_city_data.points[i].cname,i);}
show_city_markers();}
function load_city_data()
{g_city_data=null;GDownloadUrl("/rentals/map/map_data.aspx?ac=1",load_city_points);}
function init_icon_types()
{g_icon_types[1]={color:"#FF776B",label:"a",name:"Apartment"};g_icon_types[26]={color:"#97EC7D",label:"b",name:"Basement Suite"};g_icon_types[3]={color:"#01BF00",label:"c",name:"Condominum"};g_icon_types[5]={color:"#FDABFF",label:"d",name:"Duplex"};g_icon_types[10]={color:"#6B98FF",label:"h",name:"House"};g_icon_types[18]={color:"#FD8D08",label:"r",name:"Room"};g_icon_types[20]={color:"#C89BFF",label:"s",name:"Suite"};g_icon_types[21]={color:"#BCE3FF",label:"t",name:"Townhouse"};var e;var html;var i;var icon_color;var icon_label;var icon_name;html='<table width="100%" border="0" cellpadding="2" cellspacing="1">';for(i in g_icon_types)
{icon_label=g_icon_types[i].label;icon_color=g_icon_types[i].color;icon_name=g_icon_types[i].name;g_icon_types[i].icon=MapIconMaker.createFlatIcon({label:icon_label,labelSize:12,shape:"roundrect",width:20,height:20,primaryColor:icon_color});html+='<tr><td style="width:100%;background:'+icon_color+';"> - ';html+=icon_label+' - '+icon_name;html+='</td></tr>';}
html+='<tr><td style="width:100%;background:'+k_default_icon_color+';">';html+=' - x - All other property types for rent';html+='</td></tr>';html+='<tr><td style="width:100%;background:'+k_default_icon_color+';">';html+=' - # - Multiple listings at this location';html+='</td></tr>';html+='</table>';e=document.getElementById('legend_content');e.innerHTML=html;}
function map_reset()
{if(!g_city_data)return;show_busy();g_map.closeInfoWindow();setdp("mrlink","none");setdp("fplink","none");setdp("rblink","none");setdp("fpanel","none");setdp("legend","none");markers_clear_all();g_map_data=null;document.f1.city_list.selectedIndex=0;g_city_idx=0;show_city_markers();}
function init_globals()
{g_map=null;try
{if(GBrowserIsCompatible())
g_map=new GMap2(document.getElementById("gmap"));else
g_map=null;}
catch(e)
{g_map=null;}
if(!g_map)
return false;init_icon_types();var point=new GLatLng(55.875311,-109.511719);g_map.setCenter(point,3);var ui=g_map.getDefaultUI();ui.maptypes.satellite=false;ui.maptypes.hybrid=false;ui.maptypes.physical=false;ui.zoom.doubleclick=false;ui.zoom.scrollwheel=false;ui.keyboard=false;g_map.setUI(ui);GEvent.addListener(g_map,"moveend",viewport_update);return true;}
function map_init()
{var ok;show_busy();setdp("mapform","none");ok=init_globals();if(!ok)
{msgbox_update("Sorry - your browser does not support the maps feature.");return;}
load_city_data();}