var APF={log:function(A){}};APF.Namespace={register:function(D){var C=D.split(".");var A=window;for(var B=0;B<C.length;B++){if(typeof A[C[B]]=="undefined"){A[C[B]]=new Object()}A=A[C[B]]}}};APF.Namespace.register("Office.MapFindding");Office.MapFindding.FinddingCanvas=Class.create({initialize:function(D,B,F){this.defaultKey="请输入写字楼名称关键字";this.systemError="系统出现错误……";this.isKeySearch=false;this.allowQueryBounds=true;this.returningToSavedPosition=false;this.canvas=$(D+"_canvas");this.canvasId=D+"_canvas";this.tradeType=B;this.container=$("container");this.headerHeight=$("header").getHeight();this.latlng=new GLatLng(F.lat,F.lng);this.clonelatlng=new GLatLng(F.lat,F.lng);this.zoom=F.zoom;this.searchZoom=F.searchZoom;this.cityId=F.cityId;this.cityNameZh=F.name;this.filters={district:0,bizDistrict:0,priceIndex:0,areaIndex:0,kw:''};var G=document.location.hash.substring(1).toQueryParams();if(G){if(G.d&&G.d!="0"){this.filters.district=G.d;this.setFilter($("select_district"),G.d);var C="/bizD.ashx?p1="+G.d;new Ajax.Updater("select_bizDistrict",C,{method:"get",asynchronous:false,onFailure:function(transport){this.divTopTip.update(this.systemError)},onComplete:function(){$("select_bizDistrict").disabled=false}})}if(G.bd){this.filters.bizDistrict=G.bd;this.setFilter($("select_bizDistrict"),G.bd);if(G.bd!="0"){$("select_bizDistrict").disabled=false}}if(G.pi){this.filters.priceIndex=G.pi;this.setFilter($("select_priceIndex"),G.pi)}if(G.ai){this.filters.areaIndex=G.ai;this.setFilter($("select_areaIndex"),G.ai)}if(G.kw){this.filters.kw=G.kw;$("map_keywords").value=G.kw}else{if(G.l1&&G.l2&&G.l3){this.latlng=new GLatLng(G.l1,G.l2);this.zoom=G.l3}if(G.d&&G.d!="0"){var A=$("select_district_"+G.d).readAttribute("lat");var E=$("select_district_"+G.d).readAttribute("lng");this.latlng=new GLatLng(A,E)}if(G.bd&&G.bd!="0"){var A=$("select_bizDistrict_"+G.bd).readAttribute("lat");var E=$("select_bizDistrict_"+G.bd).readAttribute("lng");this.latlng=new GLatLng(A,E)}}}this.clonefilters={latlng:new GLatLng(0,0),zoom:this.zoom,district:this.filters.district,bizDistrict:this.filters.bizDistrict,priceIndex:this.filters.priceIndex,areaIndex:this.filters.areaIndex,kw:''};this.mapMarkers=new Hash();document.observe("map:searchBounds",function(H){this.clonefilters.kw='';this.allowQueryBounds=true;this.query()}.bind(this));document.observe("map:pan",function(I){this.clonefilters.kw='';this.allowQueryBounds=true;this.latlng=new GLatLng(I.memo.lat,I.memo.lng);if(this.zoom!=14){this.zoom=14;this.map.setCenter(this.latlng,this.zoom)}else{this.map.panTo(this.latlng)}}.bind(this));document.observe("set:district",function(H){this.isKeySearch=false;this.filters.district=H.memo.value;this.filters.bizDistrict=0;this.closeExtWin()}.bind(this));document.observe("set:bizDistrict",function(H){this.isKeySearch=false;this.filters.bizDistrict=H.memo.value;this.closeExtWin()}.bind(this));document.observe("set:priceIndex",function(H){this.isKeySearch=false;this.filters.priceIndex=H.memo.value;this.closeExtWin()}.bind(this));document.observe("set:areaIndex",function(H){this.isKeySearch=false;this.filters.areaIndex=H.memo.value;this.closeExtWin()}.bind(this));document.observe("update:extInfo",function(H){this.updateMapFinddingCanvasExtInfoWindow(H.memo.offinfoId,H.memo.page,H.memo.order)}.bind(this));document.observe("map:drawCanvas",function(){this.drawCanvas()}.bind(this));document.observe("set:keywords",function(H){this.closeExtWin();$('officeNameList').setStyle({display:'none'});if(H.memo.value.strip()==''||H.memo.value.strip()==this.defaultKey){alert(this.defaultKey);obj.value='';obj.focus();return}this.isKeySearch=true;Element.fire(this.canvasId,"map:searchBounds")}.bind(this));document.observe("get:officeName",function(H){var p=$H({p1:this.cityId,p2:this.tradeType,p3:H.memo.value}).toQueryString();var url='/searchOffice.ashx?'+p;new Ajax.Request(url,{method:"get",asynchronous:true,onFailure:function(transport){this.divTopTip.update(this.systemError)}.bind(this),onSuccess:function(transport){var script=transport.responseText;if(!script){return}this.searchOfficeList=new Hash();eval(script);var liTemplate=new Template('<li id="s_#{id}" onmouseover="this.className=\'cur\'" onmouseout="this.className=\'\'">#{name}</li>');var html='';$('officeNameList').update();this.searchOfficeList.each(function(B){html+=liTemplate.evaluate(B.value);$('officeNameList').update(html)}.bind(this));$('officeNameList').setStyle({display:'block'});this.searchOfficeList.each(function(B){if(this.searchOfficeList.get(B.key)!=undefined&&$('s_'+B.key)!=null){Event.observe('s_'+B.key,'mousedown',function(){$('map_keywords').value=B.value.name;$('officeNameList').setStyle({display:'none'})}.bind(this))}}.bind(this))}.bind(this)})}.bind(this));document.observe("move:officeName",function(H){var obj=$('officeNameList');var len=obj.getElementsByTagName("li").length;if(len<1){return}$('officeNameList').setStyle({display:'block'});var j=(H.memo.direction==0?0:len-1);for(var i=0;i<len;i++){if(obj.getElementsByTagName("li")[i].className!=""){obj.getElementsByTagName("li")[i].className="";if(H.memo.direction==0)j=(i+1<len?i+1:0);else j=(i-1<0?len-1:i-1)}}obj.getElementsByTagName("li")[j].className="cur";$("map_keywords").value=obj.getElementsByTagName("li")[j].innerHTML;$("map_keywords").focus()}.bind(this));this.resResultErr=$("mapFinddingFilter_Err");this.divTopTip=$(D+"_toptip");this.divTopTip.setOpacity(0.7);this.splitLine=350;this.minHeight=370;this.minWidth=800;this.maxMarkersNum=50},drawCanvas:function(){var B=this.getCanvasHeight()+"px";var A=this.getViewportWidth();if(A<this.minWidth){this.container.setStyle({width:"800px"});$("webnav").setStyle({width:"670px"})}else{this.container.setStyle({width:"auto"});$("webnav").setStyle({width:document.body.offsetWidth-350+"px"})}this.canvas.setStyle({height:B});$("right_canvas").setStyle({marginLeft:$("left_canvas").offsetWidth+20+"px"});$("serach_list").setStyle({height:this.canvas.offsetHeight-153+"px"})},getCanvasHeight:function(){var D=35;var A=0;var B=this.getViewportHeight();var C=B-this.headerHeight-D+A;if(!Element.visible("header")){C=B-D}if(C<this.minHeight){C=this.minHeight}return C},getViewportHeight:function(){return document.viewport.getHeight()},getViewportWidth:function(){return document.viewport.getWidth()},setFilter:function(A,B){if(A==undefined){return}for(i=0;i<A.options.length;i++){if(parseInt(A.options[i].value,10)==parseInt(B,10)){A.options[i].selected=true;break}}},getFilter:function(A){if(A==undefined){return 0}for(i=0;i<A.options.length;i++){if(A.options[i].selected){return parseInt(A.options[i].value,10);break}}},closeExtWin:function(){this.map.closeExtInfoWindow()},drawMap:function(){var A=new GMap2(this.canvas);A.enableScrollWheelZoom();A.enableGoogleBar();A.addControl(new GLargeMapControl3D());A.addControl(new GOverviewMapControl());A.addControl(new GMapTypeControl());G_NORMAL_MAP.getMinimumResolution=function(){return 12};G_NORMAL_MAP.getMaximumResolution=function(){return 19};G_SATELLITE_MAP.getMinimumResolution=function(){return 12};G_SATELLITE_MAP.getMaximumResolution=function(){return 19};G_HYBRID_MAP.getMinimumResolution=function(){return 12};G_HYBRID_MAP.getMaximumResolution=function(){return 19};this.map=A;this.zoom=parseInt(this.zoom,10);this.map.setCenter(this.latlng,this.zoom);GEvent.addListener(A,"dragstart",function(){this.closeExtWin();this.divOfficeName.hide();this.allowQueryBounds=false}.bind(this));GEvent.addListener(A,"dragend",function(){this.allowQueryBounds=true}.bind(this));GEvent.addListener(A,"zoomstart",function(){this.closeExtWin();this.divOfficeName.hide();this.allowQueryBounds=false}.bind(this));GEvent.addListener(A,"zoomend",function(){this.allowQueryBounds=true;this.zoom=this.map.getZoom()}.bind(this));GEvent.addListener(A,"movestart",function(){this.divOfficeName.hide();this.allowQueryBounds=false}.bind(this));GEvent.addListener(A,"moveend",function(){this.allowQueryBounds=true;if($("mapFinddingCanvasExtInfoWindow_contents")==null){this.latlng=this.map.getCenter()}this.query()}.bind(this));GEvent.addListener(A,"extinfowindowopen",function(){this.allowQueryBounds=false}.bind(this));GEvent.addListener(A,"extinfowindowclose",function(){this.allowQueryBounds=true;this.map.returnToSavedPosition()}.bind(this));this.divOfficeName=$(document.createElement("div"));this.divOfficeName.setStyle({display:"none",whiteSpace:"nowrap"});Element.insert(A.getPane(G_MAP_MARKER_PANE),this.divOfficeName);this.markerManager=new MarkerManager(this.map)},setKeyWord:function(k){this.filters.kw=escape(k)},setBounds:function(){this.bounds=this.getBounds()},getBounds:function(){var F=80;var H=this.map.fromContainerPixelToLatLng(new GPoint(F,F));var E=this.map.fromContainerPixelToLatLng(new GPoint(this.canvas.getWidth()-F/2,this.canvas.getHeight()-F/2));var B=E.lat().toFixed(3);var A=H.lat().toFixed(3);var G=H.lng().toFixed(3);var C=E.lng().toFixed(3);var D={slatFrom:B,slatTo:A,slngFrom:G,slngTo:C};return D},queryBounds:function(){if(!this.allowQueryBounds){return}this.setKeyWord('');this.setBounds();this.showTopTipAndMarkers()},queryKeyWord:function(){if(!this.allowQueryBounds){return}this.setKeyWord($('map_keywords').value.strip());if(this.clonefilters){var clone=this.clonefilters;var original=this.filters;if(clone.kw!=original.kw){clone.kw=original.kw}else{this.setLableMarkerZindex();if($("mapFinddingCanvasExtInfoWindow_contents")==null){this.map.savePosition()}return}}this.bounds={slatFrom:0,slatTo:0,slngFrom:0,slngTo:0};this.filters.district=0;this.filters.piece=0;this.filters.areaIndex=0;this.filters.priceIndex=0;this.setFilter($("select_district"),0);$("select_bizDistrict").update('<option value="0">选择商圈</option>');$("select_bizDistrict").disabled=true;this.setFilter($("select_priceIndex"),0);if($("select_areaIndex")){this.setFilter($("select_areaIndex"),0)}this.showTopTipAndMarkers()},query:function(){if(this.isKeySearch){this.queryKeyWord()}else{if(this.check()){this.queryBounds()}else{this.setLableMarkerZindex()}}},check:function(){var ischange=false;if(this.clonefilters){var clone=this.clonefilters;var original=this.filters;if(clone.latlng.lat()!=this.latlng.lat()){clone.latlng=this.latlng;ischange=true}if(clone.latlng.lng()!=this.latlng.lng()){clone.latlng=this.latlng;ischange=true}if(clone.zoom!=this.zoom){clone.zoom=this.zoom;ischange=true}if(clone.district!=original.district){clone.district=original.district;ischange=true}if(clone.bizDistrict!=original.bizDistrict){clone.bizDistrict=original.bizDistrict;ischange=true}if(clone.priceIndex!=original.priceIndex){clone.priceIndex=original.priceIndex;ischange=true}if(clone.areaIndex!=original.areaIndex){clone.areaIndex=original.areaIndex;ischange=true}}return ischange},showTopTipAndMarkers:function(){this.divTopTip.update("正在为您查找，请稍候……");this.showTopTip();this.updateLocationHref();var url=this.buildUrl(0,0,0);new Ajax.Request(url,{method:"get",asynchronous:true,onFailure:function(transport){this.divTopTip.update(this.systemError)}.bind(this),onSuccess:function(transport){var script=transport.responseText;this.metaMarkers=new Hash();eval(script);this.drawMarkers();this.setLableMarkerZindex();if(this.markersNum==this.maxMarkersNum){this.divTopTip.update("找到超过"+this.maxMarkersNum+"个写字楼，您可以调整筛选条件，或者放大视图试试。")}else{if(this.markersNum==0){this.divTopTip.update("没有找到任何写字楼，您可以调整筛选条件，或者缩小视图试试。")}else{this.divTopTip.update("找到"+this.markersNum+"个写字楼，您可以调整筛选条件，或者放大视图试试。")}}this.map.savePosition();if(this.isKeySearch&&this.metaMarkers){var values=this.metaMarkers.values();var center=new GLatLng(values[0].lat,values[0].lng);this.map.setCenter(center,this.searchZoom)}}.bind(this)})},showTopTip:function(){this.divTopTip.setStyle({display:"block"})},hideTopTip:function(){this.divTopTip.setStyle({display:"none"})},buildUrl:function(D,E,B){var A=$H({p1:this.bounds.slatFrom,p2:this.bounds.slatTo,p3:this.bounds.slngFrom,p4:this.bounds.slngTo,p5:this.tradeType,p6:D,p7:E,p8:B,p9:this.cityId,p10:this.filters.district,p11:this.filters.bizDistrict,p12:this.filters.areaIndex,p13:this.filters.priceIndex,p14:this.filters.kw}).toQueryString();var C="/search.ashx?"+A;return C},drawMarkers:function(){this.mapMarkers.each(function(B){if(this.metaMarkers.get(B.key)==undefined){this.markerManager.removeMarker(this.mapMarkers.get(B.key));this.mapMarkers.unset(B.key)}}.bind(this));var A=0;this.metaMarkers.each(function(B){if(this.mapMarkers.get(B.key)!=undefined&&this.mapMarkers.get(B.key).propNum!=B.value.num){this.markerManager.removeMarker(this.mapMarkers.get(B.key));this.mapMarkers.unset(B.key)}if(this.mapMarkers.get(B.key)==undefined){var L=this.createMarker(B.value);this.mapMarkers.set(B.key,L);this.markerManager.addMarker(L,0)}}.bind(this));var liTemplate=new Template('<li><img src="#{imgUrl}" alt="#{name}" /><label><b id="b_#{id}" title="点三角 查看&lt;#{name}&gt;">&nbsp;</b><a href="#{offUrl}" title="#{name}" target="_blank">#{shortname}</a></label><span>#{num}套 #{avgPrice}</span></li>');var html='';$('list').update();this.metaMarkers.each(function(B){B.value.shortname=B.value.name.truncate(10,'..');html+=liTemplate.evaluate(B.value);$('list').update(html)}.bind(this));this.metaMarkers.each(function(B){window.setTimeout(function(){if(this.mapMarkers.get(B.key)!=undefined&&$('b_'+B.key)!=null){Event.observe('b_'+B.key,"click",function(){var offinfoId=B.key;var name=B.value.name;var marker=this.mapMarkers.get(B.key);marker.openExtInfoWindow(this.map,"mapFinddingCanvasExtInfoWindow","<div>"+name+"</div><div>loading...</div>");this.updateMapFinddingCanvasExtInfoWindow(offinfoId,1,0)}.bind(this))}}.bind(this),A*10)}.bind(this))},createMarker:function(C){var B=new GIcon();if(C.chargeId=='96'){B.image="/css/images/lable_normal_40x30.png"}else if(C.chargeId=='97'){B.image="/css/images/lable_normal_40x30_n97.png"}B.iconSize=new GSize(40,34);B.iconAnchor=new GPoint(25,40);B.infoWindowAnchor=new GPoint(20,0);var D=new GLatLng(C.lat,C.lng);var A;if(C.chargeId=='97'){A=new LabeledMarker(D,{icon:B,labelText:C.name,labelClass:"mapFinddingCanvasLabelStyle2",labelOffset:new GSize(-25,-40)})}else{A=new LabeledMarker(D,{icon:B,labelText:"<span>"+C.num+"</span>套",labelClass:"mapFinddingCanvasLabelStyle",labelOffset:new GSize(-25,-40)})}A.propNum=C.num;A.chargeId=C.chargeId;A.Name=C.name;A.disableDragging();GEvent.addListener(A,"mouseover",function(){var E=this.map.fromLatLngToDivPixel(A.getLatLng());this.drawOfficeName(E.y,E.x,C.name);this.hoverMarker(A,true)}.bind(this));GEvent.addListener(A,"mouseout",function(){this.divOfficeName.hide();this.hoverMarker(A,false)}.bind(this));GEvent.addListener(A,"click",function(){this.divOfficeName.hide();this.hoverMarker(A,false);this.allowQueryBounds=false;A.openExtInfoWindow(this.map,"mapFinddingCanvasExtInfoWindow","<div>"+C.name+"</div><div>loading...</div>");this.updateMapFinddingCanvasExtInfoWindow(C.id,1,0)}.bind(this));return A},hoverMarker:function(B,A){if(A){B.setImage("/css/images/lable_hover_40x30.png");if(B.chargeId=='97'){B.div_.className="mapFinddingCanvasLabelStyle";B.labelText_="<span>"+B.propNum+"</span>套";B.div_.innerHTML=B.labelText_}var D=GOverlay.getZIndex(-90);B.div_.style.zIndex=D;this.divOfficeName.style.zIndex=D+1;try{B.yr.style.zIndex=D}catch(C){}this.map.disableDragging()}else{var D=GOverlay.getZIndex(B.getLatLng().lat());if(B.chargeId=='96'){B.setImage("/css/images/lable_normal_40x30.png")}else if(B.chargeId=='97'){B.div_.className="mapFinddingCanvasLabelStyle2";B.setImage("/css/images/lable_normal_40x30_n97.png");B.labelText_=B.Name;B.div_.innerHTML=B.labelText_;D="0"}try{B.yr.style.zIndex=D;B.div_.style.zIndex=D}catch(C){}this.map.enableDragging()}},setLableMarkerZindex:function(){this.mapMarkers.each(function(B){window.setTimeout(function(){if(this.mapMarkers.get(B.key)!=undefined){var L=this.mapMarkers.get(B.key);if(L.chargeId=='97'){this.hoverMarker(L,false)}}}.bind(this),10)}.bind(this))},updateMapFinddingCanvasExtInfoWindow:function(C,D,A){var B=this.buildUrl(C,D,A);new Ajax.Request(B,{method:"get",onFailure:function(transport){this.divTopTip.update(this.systemError)}.bind(this),onSuccess:function(K){$("mapFinddingCanvasExtInfoWindow_contents").update(K.responseText);this.map.getExtInfoWindow().resize();var oi='offInfo';var hn='houseNum';var ag='avgPrice';var pn="page_next";var pp="page_prev";var so="select_order";if(this.metaMarkers.get(C)!=undefined){var obj=this.metaMarkers.get(C);if($(oi)){$(oi).update("<a target='_blank' href='"+obj.offUrl+"'>"+obj.name+"</a>")}if($(hn)){$(hn).update("找到<span>"+obj.num+"套</span>写字间符合要求")}if($(ag)){$(ag).update("均价：￥<span>"+obj.avgPrice+"</span>")}var page_prev1="<span>&lt;&lt;上一页</span>";var page_prev2="<a href='javascript:;' id='page_prev'>&lt;&lt;上一页</a>";var page_next1="<span>下一页&gt;&gt;</span>";var page_next2="<a href='javascript:;' id='page_next'>下一页&gt;&gt;</a>";var myTemplate=new Template('#{page_prev}<span>第#{pageIndex}/#{pageCount}页</span>#{page_next}');var show={page_prev:'The Simpsons',page_next:'Matt Groening',pageIndex:1,pageCount:1};var pageCount=Math.ceil(obj.num/6);show.pageIndex=D;show.pageCount=pageCount;if(D==1){if(pageCount==1){show.page_prev=page_prev1;show.page_next=page_next1}else{show.page_prev=page_prev1;show.page_next=page_next2}}else if(D>1&&D<pageCount){show.page_prev=page_prev2;show.page_next=page_next2}else if(D==pageCount){show.page_prev=page_prev2;show.page_next=page_next1}$('page').update(myTemplate.evaluate(show))}var H=$(pn);var J=$(pp);var G=$(so);if(H){Event.observe(pn,"click",function(){H.fire("update:extInfo",{offinfoId:C,page:D+1,order:A})})}if(J){Event.observe(pp,"click",function(){J.fire("update:extInfo",{offinfoId:C,page:D-1,order:A})})}if(G){this.setFilter(G,A);Event.observe(so,"change",function(){A=G.value;G.fire("update:extInfo",{offinfoId:C,page:1,order:A})})}}.bind(this)})},drawOfficeName:function(D,C,B){this.divOfficeName.update(B);this.divOfficeName.className="mapFinddingCanvasCommNameRight";this.divOfficeName.setStyle({top:D-40+"px",left:C+10+"px",display:"block"});return;if(C>this.splitLine){var A=this.divOfficeName.getWidth();this.divOfficeName.className="mapFinddingCanvasCommNameLeft";this.divOfficeName.setStyle({top:D-40+"px",left:C-20-A+"px",display:"block"})}else{this.divOfficeName.className="mapFinddingCanvasCommNameRight";this.divOfficeName.setStyle({top:D-40+"px",left:C+20+"px",display:"block"})}},updateLocationHref:function(){var B=document.location.hash.substring(1).toQueryParams();var C=this.map.getCenter();var A=this.map.getZoom();upparams={};upparams.l1=C.lat();upparams.l2=C.lng();upparams.l3=A;B.kw="";upparams.d=this.filters.district;upparams.bd=this.filters.bizDistrict;upparams.pi=this.filters.priceIndex;upparams.ai=this.filters.areaIndex;document.location.hash=Object.toQueryString(upparams)},showResultErr:function(){this.resResultErr.setStyle({display:"block"})},hideResultErr:function(){this.resResultErr.setStyle({display:"none"})}});