﻿/* (c) LoopNet Virtual Earth Map Version 1.0 */
if(!window.sContentProviderUrl){sContentProviderUrl="";}LNJS.__lnve=true;LNJS.LNVE=Class.create();LNJS.LNVE.prototype=(new LNJS.Base()).extend({initialize:function(options){this.__className="LNJS.LNVE";this.options={ZIndex:{ZRS:1000,Z2:1100,Z1:1200},mapInfoJSON:sMapInfoJSON,symbolType:2,mapopt:{container:"MapHolder",opt:{}}}.extend(options||{});if(typeof(HideDashboard)=='undefined')HideDashboard=false;if(typeof(cInitMapStyle)=='undefined')cInitMapStyle="r";if(typeof(UserClickedID)=='undefined')UserClickedID="UserClicked";if(typeof(bPushPinOnClick)=='undefined')bPushPinOnClick=false;if(typeof(sOnClickOpenSite)=='undefined')sOnClickOpenSite="";if(typeof(MainListingPinIsClickable)=='undefined')MainListingPinIsClickable=false;if(typeof(DisableObliqueNotification)=='undefined')DisableObliqueNotification=false;if(typeof(sMapType)=='undefined')sMapType='MLS';this.options.hideMapUI=HideDashboard;this.options.defaultStyle=cInitMapStyle;this.options.userClickedID=UserClickedID;this.options.selectLocation=bPushPinOnClick;this.options.clickGoTo=sOnClickOpenSite;this.options.showMainProfile=MainListingPinIsClickable;this.options.mapType=sMapType.toUpperCase();this.options.disableObliqueNotification=DisableObliqueNotification;if(typeof(dInitLat)!='undefined')this.options.defaultLat=dInitLat;if(typeof(dInitLong)!='undefined')this.options.defaultLon=dInitLong;if(typeof(iInitZoom)!='undefined')this.options.defaultZoom=iInitZoom;if(this.options.mapInfoJSON.length>0){try{eval("this.MapInfo = "+this.options.mapInfoJSON+";");}catch(err){throw this.Err(this.__className+" JSON MapInfo is invalid unable to parse: "+err.message);}}this._mapContainer=$(this.options.mapopt.container);if(!this._mapContainer){throw this.Err(this.__className+" requires a Map Container! element not found: "+this.options.mapopt.container);}Element.setStyle(this._mapContainer,{'width':this.MapInfo.MapWidth+"px",'height':this.MapInfo.MapHeight+"px"});if(this.MapInfo.SymbolType)this.options.symbolType=this.MapInfo.SymbolType;opt=this.options.mapopt.opt;opt.onMapInit=this._onMapLoad.bindAsEventListener(this);opt.zoomlevel=this.MapInfo.MinInitZoomLevel;opt.mapStyle=this.options.defaultStyle;opt.showDashboard=!this.options.hideMapUI;if(this.MapInfo.MapCoordinateList.length>0){opt.latitude=this.MapInfo.MapCoordinateList[0].Latitude;opt.longitude=this.MapInfo.MapCoordinateList[0].Longitude;}if(this.options.hideMapUI){opt.hideCopyright=true;opt.disableLogo=true;opt.showScaleBar=false;}else{opt.disableObliqueNotification=this.options.disableObliqueNotification;}if(this.options.selectLocation===true){opt.obliqueEnabled=false;}if(LNJS.isNull(LNJS.MapManager))throw this.Err(this.__className+" requires LNJS.MapManager!");this.MapMgr=new LNJS.MapManager(this.options.mapopt.container,opt);},dispose:function(){this.options=null;this.MapInfo=null;this._mapContainer=null;this.MapMgr.dispose();},plotCoordinates:function(oMapMgr){oMapMgr.deleteAllShapes();var count=this.MapInfo.MapCoordinateList.length;for(var i=0;i<count;i++){try{oMapCord=this.MapInfo.MapCoordinateList[i];var oLatLon=new VELatLong(oMapCord.Latitude,oMapCord.Longitude);var oPin=new VEShape(VEShapeType.Pushpin,oLatLon);oPin.LN=oMapCord;oPin.orgZIndex=this.getZIndex(this.options.symbolType,i);oPin.SetZIndex(oPin.orgZIndex);if(this.options.symbolType==1){var classname=this._getItemType(oMapCord);var printpin="<img class='printpin' src='"+sContentProviderUrl+"/images/search/map/pins/"+classname+".gif' />";oPin.SetCustomIcon("<div id='p"+oPin.LN.LNID+"' class='pinBox "+classname+"Pin'>"+printpin+"</div>");}else{var icon="<img src='"+sContentProviderUrl+"/images/"+(i+1)+".gif' />";var evnt=(oMapCord.MapHotSpotLink&&oMapCord.MapHotSpotLink.length>0)?" onclick=\"javascript:makePopupProfile('"+oMapCord.MapHotSpotLink+"')\"":"";oPin.SetCustomIcon("<div class='MapPin'"+evnt+">"+icon+"</div>");icon=evnt=null;}oMapCord=null;LNVE.MapMgr.addShape(oPin);}catch(err){LNJS.Trace.error(this.__className+": Error in plotCoordinates: "+err.message);}}},getZIndex:function(st,i){var zIndex=this.options.ZIndex["Z"+st]-i;return zIndex;},_isRS:function(type){return(type||this.options.mapType)=="RS";},_isMLS:function(type){return!((type)?this._isRS(type):this._isRS());},_getItemType:function(p){if(this._isMLS()){if(p.SC)return"showcase";return(p.PL)?"premium":"basic";}else{return"rs-sub";}},_onMapLoad:function(oMapMgr){var delay=(oMapMgr.isBirdsEye())?500:10;this._setupAnalytics(oMapMgr);if(this.options.selectLocation)this._setupSelectLocation(oMapMgr);setTimeout((function(){if(this.MapInfo.MapCoordinateList.length>1){cords=[];len=this.MapInfo.MapCoordinateList.length;for(x=0;x<len;x++){cord=this.MapInfo.MapCoordinateList[x];cords.push(new VELatLong(cord.Latitude,cord.Longitude));cord=null;}oMapMgr.setMapView(cords);cords=null;}if(!oMapMgr.HideAllPins())this.plotCoordinates(oMapMgr);this._saveBounds(oMapMgr);if(this.options.clickGoTo!=''){this.MapClickGoTo=this._mapClickGoTo.bindAsEventListener(this);oMapMgr.attachEvent("onclick",this.MapClickGoTo);}}).bind(this),delay);},_setupSelectLocation:function(oMapMgr){this.SaveLatLon=this._saveLatLon.bindAsEventListener(this);this.MapLatLon=this._trackMapLatLon.bindAsEventListener(this);oMapMgr.attachEvent("onclick",this.SaveLatLon);oMapMgr.attachEvent("onmousemove",this.MapLatLon);},_setupAnalytics:function(oMapMgr){if(!window.oAnalytics&&LNJS.Analytics){window.oAnalytics=new LNJS.Analytics();}if(window.oAnalytics){this.lastMapEvent=null;this.lastZoomLevel=oMapMgr.getZoomLevel();this.ObliqueChange=this._trackObliqueChange.bindAsEventListener(this);this.ChangeView=this._trackChangeView.bindAsEventListener(this);this.StartZoom=this._trackStartZoom.bindAsEventListener(this);this.StartPan=this._trackStartPan.bindAsEventListener(this);this.EndZoom=this._trackEndZoom.bindAsEventListener(this);this.EndPan=this._trackEndPan.bindAsEventListener(this);oMapMgr.attachEvent("onobliquechange",this.ObliqueChange);oMapMgr.attachEvent("onchangeview",this.ChangeView);oMapMgr.attachEvent("onstartzoom",this.StartZoom);oMapMgr.attachEvent("onstartpan",this.StartPan);oMapMgr.attachEvent("onendzoom",this.EndZoom);oMapMgr.attachEvent("onendpan",this.EndPan);}},_trackObliqueChange:function(e){if(!this.lastMapEvent){this.lastMapEvent=e;}else{if(this.lastMapEvent.mapStyle==e.mapStyle&&this.lastMapEvent.birdseyeSceneOrientation!=e.birdseyeSceneOrientation){oAnalytics.LogObliqueMapOrientationChange();this.lastMapEvent=e;}else if(this.lastMapEvent.mapStyle==e.mapStyle&&this.lastMapEvent.birdseyeSceneID!=e.birdseyeSceneID){oAnalytics.LogObliqueMapTileChange();this.lastMapEvent=e;}}this._saveBounds();},_trackChangeView:function(e){if(!this.lastMapEvent){this.lastMapEvent=e;}else{if(this.lastMapEvent.mapStyle!=e.mapStyle){oAnalytics.LogMapStyle(e.mapStyle);this.lastMapEvent=e;}}},_trackStartZoom:function(e){if(!this.lastMapEvent)this.lastMapEvent=e;},_trackStartPan:function(e){if(!this.lastMapEvent)this.lastMapEvent=e;},_trackEndZoom:function(e){if(e.mapStyle=='o'||e.mapStyle=='b'){if(this.lastMapEvent.mapStyle!=e.mapStyle){oAnalytics.LogMapStyle(e.mapStyle);}else if(e.zoomLevel<this.lastZoomLevel){oAnalytics.LogObliqueMapZoomOut();}else{oAnalytics.LogObliqueMapZoomIn();}this.lastMapEvent=e;}else{oAnalytics.LogMapZoom((e.zoomLevel<this.lastZoomLevel));}this._saveBounds();this.lastZoomLevel=e.zoomLevel;},_trackEndPan:function(e){if(e.mapStyle=='o'||e.mapStyle=='b'){oAnalytics.LogObliqueMapPan();}else{oAnalytics.LogMapPan();}this._saveBounds();},_trackMapLatLon:function(e){document.forms[0].veCurrentStyle.value=LNVE.MapMgr.getMapStyle();if(document.forms[0].veCurrentStyle.value!='o'&&document.forms[0].veCurrentStyle.value!='b'){var oLatLon=LNVE.MapMgr.getCenter();document.forms[0].veCenterLat.value=oLatLon.Latitude;document.forms[0].veCenterLong.value=oLatLon.Longitude;document.forms[0].veCurrentZoom.value=LNVE.MapMgr.getZoomLevel();oLatLon=null;}},_mapClickGoTo:function(e){window.location.href=this.options.clickGoTo;},_saveLatLon:function(e){var clickX=e.mapX;var clickY=e.mapY;if(document.all&&document.body){clickX+=document.body.scrollLeft;clickY+=document.body.scrollTop;}var oLatLon=LNVE.MapMgr.pixelToLatLong(new VEPixel(clickX,clickY));LNJS.Trace.info('Latitude/Longitude captured: '+oLatLon.Latitude+'/'+oLatLon.Longitude);document.forms[0].Latitude.value=oLatLon.Latitude;document.forms[0].Longitude.value=oLatLon.Longitude;var oOldPin=LNVE.MapMgr.getShapeByIndex(0);var oPin=new VEShape(VEShapeType.Pushpin,oLatLon);if(this.options.symbolType==1){var classname=this._getItemType(oOldPin.LN);var printpin="<img class='printpin' src='"+sContentProviderUrl+"/images/search/map/pins/"+classname+".gif' />";oPin.SetCustomIcon("<div id='p"+oOldPin.LN.LNID+"'class='pinBox "+classname+"Pin'>"+printpin+"</div>");}oOldPin=null;LNVE.MapMgr.deleteAllShapes();LNVE.MapMgr.addShape(oPin);if(document.forms[0][this.options.userClickedID])document.forms[0][this.options.userClickedID].value='True';},_saveBounds:function(oMapMgr){if(!oMapMgr)oMapMgr=this.MapMgr;if(!oMapMgr)return;if(!oMapMgr.isBirdsEye()){oLatLongRect=oMapMgr.getMapView();document.forms[0].NECornerLatLong.value=oLatLongRect.TopLeftLatLong.Latitude+'|'+oLatLongRect.BottomRightLatLong.Longitude;document.forms[0].SWCornerLatLong.value=oLatLongRect.BottomRightLatLong.Latitude+'|'+oLatLongRect.TopLeftLatLong.Longitude;oLatLongRect=null;}}});LNJS.addObserver({onPageLoad:function(){window.LNVE=new LNJS.LNVE();}});if(Event.observe)Event.observe(window,'unload',Page_Unload,false);function Page_Unload(){if(window.LNVE!=null){window.LNVE.dispose();window.LNVE=null;}}
