
var cp=new cpaint();cp.set_response_type('JSON');var gRequestId;var gMap;function init(){initMap();gMap=new GMap(document.getElementById('mapContainer'));gMap.addControl(new GLargeMapControl());gMap.centerAndZoom(new GPoint(-80.546,43.472),3);resizeMap();}
function convertFormToArray(fobj){var valueArr=new Array();for(var i=0;i<fobj.elements.length;i++){switch(fobj.elements[i].type){case"text":case"hidden":valueArr[fobj.elements[i].name]=escape(fobj.elements[i].value);break;case"checkbox":if(fobj.elements[i].checked){valueArr[fobj.elements[i].name]="on";}
break;case"select-one":valueArr[fobj.elements[i].name]=fobj.elements[i].options[fobj.elements[i].selectedIndex].value;break;}}
return valueArr;}
function submitRequest(){var criteriaForm=document.getElementById('ochform');var criteriaArr=convertFormToArray(criteriaForm);var criteriaJson=JSON.stringify(criteriaArr);cp.call('housing_query.php','start_request',submitRequestResults,criteriaJson);}
function submitRequestResults(result){if(result){cp.call('housing_query.php','get_cached_housings',processHousingResults,result.data);cp.call('housing_query.php','get_new_housings',processHousingResults,result.data);cp.call('housing_query.php','get_failed_housings',processHousingResults,result.data);}}
function processHousingResults(result){if(result&&result.housing){for(i=0;i<result.housing.length;i++){var marker=createMarker(new GPoint(result.housing[i].attributes.lng,result.housing[i].attributes.lat),result.housing[i].attributes.id,result.housing[i].attributes.address,result.housing[i].attributes.price,result.housing[i].attributes.marker_width);gMap.addOverlay(marker);}}}
function createMarker(point,housing_id,address,price,marker_width){var icon=new GIcon();icon.image='marker_image.php?price='+price;icon.iconSize=new GSize(marker_width,26);icon.shadowSize=new GSize(marker_width,26);icon.iconAnchor=new GPoint(1,26);icon.infoWindowAnchor=new GPoint(1,1);var marker=new GMarker(point,icon);GEvent.addListener(marker,'click',function(){marker.openInfoWindowHtml(getInfoWindowHtml(housing_id,address,price));});return marker;}
function getInfoWindowHtml(housing_id,address,price){var html='';html+='<div class="infowindow">';html+='Address: '+address+'<br />';html+='Price: $'+price+'<br />';html+='<a target="_blank" href="http://peanut.uwaterloo.ca/ochousing2/dresults.asp?rid='+housing_id+'">';html+='&gt;&gt; more info';html+='</a>';html+='</div>';return html;}
function initMap(){var mapDiv=document.getElementById('mapContainer');mapDiv.style.width=window.screen.width+'px';mapDiv.style.height=window.screen.height+'px';}
function resizeMap(){var mapDiv=document.getElementById('mapContainer');mapDiv.style.width=(document.documentElement.clientWidth-380)+'px';mapDiv.style.height=(document.documentElement.clientHeight-120)+'px';}
window.onresize=resizeMap;