﻿var C6=window,D6=document;var map=null;var geocoder=null;var tooltip;function initialize(){if(GBrowserIsCompatible()){map=new GMap2(D6.getElementById("map_canvas"));map.setCenter(new GLatLng(43.779021,-79.413806),12);map.addControl(new GLargeMapControl());map.addControl(new GMapTypeControl());tooltip = document.createElement("div");document.getElementById("map_canvas").appendChild(tooltip);tooltip.style.visibility="hidden";geocoder=new GClientGeocoder();if (geocoder) {geocoder.getLatLng('yonge and finch, Toronto',function(point) {if (!point) {alert("error when loading google map...");} else {map.setCenter(point, 12);map.panTo(point);}});}}}function showAddress(address,id,title,img){if(geocoder){geocoder.getLatLng(address,function(point){if(!point){var kk=1;}else{/*map.setCenter(point,15);*/var marker=new GMarker(point);map.addOverlay(marker);GEvent.addListener(marker,"click",function(){var myHtml="<a href='"+ "/topic/view/" + id + ".html" + "' target='_blank'>" + title + "</a><br>";myHtml+=address+"<br>";myHtml+= "<img width='200' height='200' src='"+ img + "' />";map.openInfoWindowHtml(point,myHtml);});marker.tooltip = '<div class="tooltip">'+title+'</div>';GEvent.addListener(marker,"mouseover", function() {showTooltip(marker);}); GEvent.addListener(marker, "mouseout", function() {tooltip.style.visibility="hidden";});}});}}var catetory_type=1;function search(){if(D6.getElementById('loading')!=null)D6.getElementById('loading').style.display="block";var area=D6.getElementById('tpc_area').value;var price=D6.getElementById('_price_sale').value;if(catetory_type !=1)price=D6.getElementById('_price_rent').value;pars="m=house_map";pars+="&area="+area+"&price="+price+"&category="+catetory_type;var myAjax=new Ajax.Updater("house_list","/pageManager.php",{method: "get",parameters: pars,evalScripts: true});}var id;var title;var img;var address;function panto(address,id,title,img,hasProvince){geocoder.getLocations(address,function(response){if(!response||response.Status.code!=200){if(hasProvince==true){var ans=C6.confirm('无法找到该地图,查看该房源?');if(ans)C6.open("/topic/view/"+id+".html");return;}address+=",ON";panto(address,id,title,img,true);}else{var place=response.Placemark[0];var latlng=new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);map.setCenter(latlng,15);map.panTo(latlng);var myHtml="<a href='"+"/topic/view/"+id+".html"+"' target='_blank'>"+title+"</a><br>";myHtml+="请点击连接查看详情！<br>";myHtml+="<img width='200' height='200' src='"+img+"'/>";map.openInfoWindowHtml(latlng,myHtml);}});}function moveToMap(response){if(!response||response.Status.code!=200){alert(address+" not found");}else{var place=response.Placemark[0];var latlng=new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);map.setCenter(latlng,15);map.panTo(latlng);var myHtml="<a href='"+"/topic/view/"+id+".html"+"' target='_blank'>"+title+"</a><br>";myHtml+="请点击连接查看详情！<br>";myHtml+="<img width='60' height='60' src='"+img+"'/>";map.openInfoWindowHtml(latlng,myHtml);}}function moveto(latlng){map.panTo(latlng);var myHtml="<a href='"+"/topic/view/"+id+".html"+"' target='_blank'>"+title+"</a><br>";myHtml+=address+"<br>";myHtml+="<img width='60' height='60' src='"+img+"'/>";map.openInfoWindowHtml(latlng,myHtml);}function change_category(catetory){if(catetory==1){catetory_type=1;D6.getElementById('for_sale').innerHTML='买房';D6.getElementById('for_rent').innerHTML='<a href="#" onclick="javascript:change_category(2);" >租房</a>';D6.getElementById('price_sale').style.display='block';D6.getElementById('price_rent').style.display='none';}else{catetory_type=2;D6.getElementById('for_sale').innerHTML='<a href="#" onclick="javascript:change_category(1);" >买房</a>';D6.getElementById('for_rent').innerHTML='租房';D6.getElementById('price_sale').style.display='none';D6.getElementById('price_rent').style.display='block';}}function toggle_locate(){var showing=(D6.getElementById('locate').style.display=='block');if(showing==true){D6.getElementById('locate').style.display='none';D6.getElementById('toggle_link').innerHTML='地图定位';}else{D6.getElementById('locate').style.display='block';D6.getElementById('locate_address').select();D6.getElementById('toggle_link').innerHTML='取消地图定位';}}function locateAddress(){var address=D6.getElementById('locate_address').value;if(geocoder){geocoder.getLatLng(address,function(point){if(!point){alert(address+" not found");}else{map.setCenter(point,16);map.panTo(point);}});}}function showTooltip(marker) {tooltip.innerHTML = marker.tooltip;var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom()); var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());var anchor=marker.getIcon().iconAnchor;var width=marker.getIcon().iconSize.width;var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y));pos.apply(tooltip);tooltip.style.visibility="visible";}function autoSearch(type, area){if(document.getElementById('loading')!=null)document.getElementById('loading').style.display = "block";var price = -1;pars = "m=house_map";	pars += "&area=" + area + "&price=" + price + "&category=" + type;var myAjax= new Ajax.Updater("house_list", "/pageManager.php", {method: "get", parameters: pars, evalScripts: true});}