
function preInitLayout(){layoutSettings.center={onresize:"ResizeMapDims();",contentSelector:'#theMap'};layoutSettings.west={size:260,resizable:false};layoutSettings.east={size:200,resizable:false,contentSelector:'#FocusPropertyList'};layoutSettings.north={resizable:false};layoutSettings.south={resizable:false};}
var subTool=null;var hasBeenNotified4Mile=false;function UpdateRadius(){if($('#SubscriptionOptions span.Radius4 input')[0].checked&&!hasBeenNotified4Mile){alert("You may switch between 2 miles and 4 miles when determining which subscription radius will meet your needs. Once you actually subscribe or upgrade a subscription to a 4 mile radius, you can't go back to 2 miles.");hasBeenNotified4Mile=true;}
if(pluginManager.currentFilterShape){var center=pluginManager.currentFilterShape.Center;if(subTool==pluginManager.VEShapeToolCurrent){subTool.DrawCircle(center);pluginManager.DrawingComplete();}
else{pluginManager.ClearCurrentShape();GlobalLookup.addValue('CurrentShapeTool',subTool);subTool.DrawCircle(center);pluginManager.DrawingComplete();}}}
function UpdateFocusProperty(){debugger;}
var showMapModeSwitch=false;function postInitLayout(){map=new VEMap('center');map.LoadMap(null,null,'r',false,VEMapMode.Mode2D,showMapModeSwitch);map.AttachEvent("onchangeview",EnvelopeChanged);map.AttachEvent("onmouseover",VEMapMouseOver);$('#MSVE_obliqueNotification').html('');subTool=new VEShapeToolSubscription();pluginManager.Initialize(map);pluginManager.AddSubButtonsToToolbar();pluginManager.DontDeleteShapeOnComplete=false;pluginManager.ConfDeleteOnAttach=false;pluginManager.OnClearCurrentShape=ClearArea;InitializeEdit();$('#loadingDiv').hide();}
function InitializeEdit(){if(CurrentRadius.val()!=''){var radio=null;var miles=CurrentRadius.val();if(miles==1){radio=$('#SubscriptionOptions span.Radius1 input')[0];}
else if(miles==2){radio=$('#SubscriptionOptions span.Radius2 input')[0]}
else if(miles==3){radio=$('#SubscriptionOptions span.Radius3 input')[0];}
else if(miles==4){radio=$('#SubscriptionOptions span.Radius4 input')[0];}
else if(miles==5){radio=$('#SubscriptionOptions span.Radius5 input')[0];}
if(radio!=null){radio.checked=true;}}
if(CurrentCenterLat.val()!=''&&CurrentCenterLong.val()!=''){var thecenter=new VELatLong(CurrentCenterLat.val(),CurrentCenterLong.val());pluginManager.ClearCurrentShape();GlobalLookup.addValue('CurrentShapeTool',subTool);subTool.DrawCircle(thecenter);pluginManager.DrawingComplete();}}
var CurrentFProp=null;function BindFocusPropChange(){if(FocusPropertyValue.val()!=''){var theCheck=$('#'+FocusPropertyValue.val());if(theCheck.length==1){theCheck[0].checked=true;HighlightPin(FocusPropertyValue.val());}
else{FocusPropertyValue.val('');}}
$("input[@name='focusProperty']").click(function(){var checked=$("input[@name='focusProperty']:checked")
FocusPropertyValue.val(checked.val());HighlightPin(checked.val())});}
function ClearArea(){$('.PropertyIconInSubscription').removeClass('PropertyIconInSubscription');EnvelopeChanged();}
var envelopeChangeID=0
var needToClearSub=false;function EnvelopeChanged(){var center=map.GetCenter();var extents=map.GetMapView();var ul=extents.TopLeftLatLong
var lat=-1;var lon=-1;var radius=-1;if(pluginManager.currentFilterShape){lat=pluginManager.currentFilterShape.Center.Latitude;lon=pluginManager.currentFilterShape.Center.Longitude;radius=pluginManager.currentFilterShape.Radius;}
if(CurrentRadius&&radius>0){if(IsEdit()&&CurrentRadius.val()>radius){needToClearSub=true;}
CurrentRadius.val(radius);if(IsEdit()&&CurrentCenterLat.val()!=lat){needToClearSub=true;}
CurrentCenterLat.val(lat);if(IsEdit()&&CurrentCenterLong.val()!=lon){needToClearSub=true;}
CurrentCenterLong.val(lon);}
PageMethods.EnvelopeChangeEvent(PropertySearchLoadID,envelopeChangeID++,ul.Longitude,ul.Latitude,center.Longitude,center.Latitude,"",map.GetZoomLevel(),lat,lon,radius,OnEnvelopeChangeCallback);}
function IsEdit(){return SubscriptionIDValue.val()!=undefined&&SubscriptionIDValue.val()!="";}
function OnEnvelopeChangeCallback(result){if(result){if(result.Error){alert(result.Error);}
var lat=-1;var lon=-1;var radius=-1;if(pluginManager.currentFilterShape){lat=pluginManager.currentFilterShape.Center.Latitude;lon=pluginManager.currentFilterShape.Center.Longitude;radius=pluginManager.currentFilterShape.Radius;}
if(result.DoQuery){PageMethods.ExecuteQuery(lat,lon,radius,ExecuteQueryCallbackSuccess,ExecuteQueryCallbackFail)}
else{}
if(result.Script){try{eval(result.Script);}catch(ex){window.alert('OnEnvelopeChangeCallback'+ex);}}}}
function ExecuteQueryCallbackFail(result){alert(result);}
function ExecuteQueryCallbackSuccess(result){if(result){if(result.Error){alert(result.Error);}
if(result.Script){try{eval(result.Script);}catch(ex){window.alert('ExecuteQueryCallback:'+ex);}}}}
function ResizeMapDims(){try{map.Resize(theLayout.panes.center.width(),theLayout.panes.center.height());}
catch(ex){}}
function VESearchKeyDown(ev,searchType,objId){ev=(ev)?ev:((event)?event:null);var k=ev.keyCode;if(k==13){VESearch();return false;}
return true;}
function VESearch(){var search=$('#SearchBoxTable input.SearchBox').val();if(search!=""&&search!="“Street Address” or  “Zip” or “City, State”  or  “County, State” or “State”"){map.Find(null,search,null,null,null,null,null,null,null,null,AddShape);}}
function AddShape(layer,resultsArray,places,hasMore,veErrorMessage){var center=map.GetCenter();if(subTool==pluginManager.VEShapeToolCurrent){subTool.DrawCircle(center);pluginManager.DrawingComplete();}
else{pluginManager.ClearCurrentShape();GlobalLookup.addValue('CurrentShapeTool',subTool);subTool.DrawCircle(center);pluginManager.DrawingComplete();}}
function ShapEditControlUpdateShape(points,type,returnMethod,errorMethod){if(pluginManager.currentFilterShape!=null){map.SetMapView(pluginManager.currentFilterShape.GetPoints());}}
function ShapeLineColor(){return new VEColor(255,0,0,1.0);}
function ShapeFillColor(){return new VEColor(0,128,0,0.25);}
function PushPinsInit(){if(pinHighlightShape!=null){map.DeleteShape(pinHighlightShape);}
if(window.pspage_PushpinLayer){map.DeleteShapeLayer(pspage_PushpinLayer);}
pspage_PushpinLayer=new VEShapeLayer();map.AddShapeLayer(pspage_PushpinLayer);pspage_PushpinList=new Array();}
function PushPinsShow(){pspage_PushpinLayer.AddShape(pspage_PushpinList);}
function AP(theLat,theLon,desc,propName,propNum,propID,inSub){var thelatlon=new VELatLong(theLat,theLon);var shp=new VEShape(VEShapeType.Pushpin,thelatlon);shp.SetTitle(propName);shp.SetDescription(desc);if(inSub){shp.SetCustomIcon('<span class="PropertyIcon PropertyIconInSubscription">'+propNum+'</span>');}
else{shp.SetCustomIcon('<span class="PropertyIcon">'+propNum+'</span>');}
shp.pspageRowID=propNum;shp.PinName="Pin"+propNum;shp.PropertyID=propID;shp.SetDescription('<span ID="'+shp.PinName+'_Content"><img src="Images/spinner.gif" alt="" align="absmiddle" /></span>');pspage_PushpinList[pspage_PushpinList.length]=shp;}
function VEMapMouseOver(e){if(e.elementID){if(openedInfoBox==null){shape=map.GetShapeByID(e.elementID);if(shape.PinName){ShowPushpinHover(shape);}}
else{}}}
var openedInfoBox=null;function ShowPushpinHover(shape){url='PropertyContext.aspx?propertyid='+shape.PropertyID;var aReq=GetRequestObject();if(aReq){aReq.onreadystatechange=function(){var test='test';if(aReq.readyState==4){$('#'+shape.PinName+'_Content').html(aReq.responseText);$('#PropertyContextImage').lightBox();shape.DescLoaded=true;}}
aReq.open("get",url,true);aReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');aReq.send(null);}else{alert('Cannot load XMLHTTP object');}}
var pinHighlightShape=null;function GetPin(propertyid){for(var n=0;n<pspage_PushpinList.length;n++){if(pspage_PushpinList[n].PropertyID==propertyid){return pspage_PushpinList[n];}}
return null;}
function HighlightPin(propertyid){var pin=GetPin(propertyid);if(pin!=null){if(pinHighlightShape!=null){map.DeleteShape(pinHighlightShape);}
var ll=pin.GetPoints()[0];var pixel=map.LatLongToPixel(ll);var arr=new Array();pixel.x=pixel.x-16;pixel.y=pixel.y-16;arr[0]=map.PixelToLatLong(pixel);pixel.y=pixel.y+25;arr[1]=map.PixelToLatLong(pixel);pixel.x=pixel.x+26;arr[2]=map.PixelToLatLong(pixel);pixel.y=pixel.y-25;arr[3]=map.PixelToLatLong(pixel);pixel.x=pixel.x-25;arr[4]=map.PixelToLatLong(pixel);var shape=new VEShape(VEShapeType.Polyline,arr);shape.SetLineColor(new VEColor(255,0,0,1.0));shape.HideIcon(true);shape.SetZIndex(10000,10000);pinHighlightShape=shape;map.AddShape(shape);}}
function ClearPushpins(){if(pinHighlightShape!=null){map.DeleteShape(pinHighlightShape);}
if(pspage_PushpinLayer){map.DeleteShapeLayer(pspage_PushpinLayer);pspage_PushpinLayer=null;pspage_PushpinList=null;}
if(pgpage_CurrentHighlightShape){map.DeleteShape(pgpage_CurrentHighlightShape);pgpage_CurrentHighlightShape=null;}}
