
var BB_POINT_NORMAL="0";var BB_POINT_SOS="1";var BB_POINT_TAG="2";var BB_POINT_LOST="3";var BB_POINT_FIRST="100";var BB_POINT_LAST="200";var BB_POINT_OCCUPIED="300";var STATUS_OFFLINE="0";var STATUS_HASLOCK="1";var STATUS_NOLOCK="2";var STATUS_DISCONNECTED="3";function gotoPoint(index,me)
{alert(index);}
function fill(json)
{Mapper.DeviceCacheManager.Fill(json)}
function quickretrieve(data,status)
{if(status=="success"&&data.devices)
{Mapper.ReceiveByArgs(data);}
else
{if(Mapper.TrackerArgs.AutoRefresh)
Mapper.PrepareNextRefresh();}}
function preparenextrefresh(){Mapper.TrackerArgs.QuickOnly=true;if(!Mapper.RetrieveInProgress)
{Mapper.QuickRetrieve();}}
function retrievebyargs(data)
{Mapper.ReceiveByArgs(data);}
function getdeviceinfo(json,status)
{if(status=="success")
{Mapper.DeviceCacheManager.SelectUnitDirect(json);}}
function getdevicename(imei)
{var device=Mapper.DeviceCacheManager.Find(imei);if(device!=null)
return Mapper.DeviceCacheManager.GetNameFromDevice(device);else
return imei;}
function zindexprocess(_marker,b)
{return GOverlay.getZIndex(_marker.getPoint().lat())+_marker.importance*1000;}
function bb_DeviceCacheManager()
{this.DeviceCache=null;$.getJSON("/server_get_device_list_JSON.php",fill);}
bb_DeviceCacheManager.prototype.Fill=function(json)
{this.DeviceCache=json;this.LoadHtml();}
bb_DeviceCacheManager.prototype.SelectUnitDirect=function(device)
{var display="";display+="<table class=\"register_phone_info\">";display+="<tr><td class=\"label_tag\">";display+="Label:</td><td class=\"label_tag_text\"> "+device.labelname+"";display+="</td></tr>";display+="<tr><td class=\"label_tag\">";display+="Phone Number:</td><td class=\"label_tag_text\">"+device.devicenumber;display+="</td></tr>";display+="<tr><td class=\"label_tag\">";display+="Owner:</td><td class=\"label_tag_text\">"+device.owner;display+="</td></tr>";display+="<tr><td class=\"label_tag\">Signal:</td><td id=\"ph_signal\" class=\"label_tag_text\">";display+="...</td>";display+="</tr>";display+="<tr><td class=\"label_tag\">Battery:</td><td id=\"ph_battery\" class=\"label_tag_text\">";display+="...</td>";display+="</tr>";display+="<tr><td class=\"label_tag\">Last signal at:</td><td id=\"ph_comms\" class=\"label_tag_text\">";display+=device.lastcomms+"</td>";display+="</tr>";display+="";$("div.phone_info_wrapper").html(display);$("div#map_title_content_imei").html("["+this.GetNameFromDevice(device)+"] ");}
bb_DeviceCacheManager.prototype.SelectUnit=function(imei)
{var device=this.Find(imei);if(device!=null)
{this.SelectUnitDirect(device);}
else
$("div.phone_info_wrapper").html("No device selected");}
bb_DeviceCacheManager.prototype.LoadHtml=function()
{var xhtml="";xhtml="";xhtml+=this.CreatePhoneListHTML(this.DeviceCache.owned,"edev.php");xhtml+="<div class=\"clearfix\"></div>";$("#ajax_device_list").html(xhtml);xhtml="";xhtml+=this.CreatePhoneListHTML(this.DeviceCache.tracking,"edev_viewing.php");xhtml+="<div class = \"device_seperator\"></div>";xhtml+="<div class=\"device_add_tracker\">";xhtml+="<form name=\"add_tracker_form\" method=\"post\" onsubmit=\"javascript:doRequestTracker(this); return false;\" action=\"post_request_new_tracker.php\">";xhtml+="Request a number to track: <a class=\"nobdr\" href=\"/help/gps+tracking/8/\"><img src=\"/images/about.png\" alt=\"?\" /></a><input name=\"input_device_number\" type=\"text\" size=\"10\"></input><input name=\"addtracker\" class=\"input_image\" type=\"image\" src=\"/images/bbme-track-button.gif\" alt=\"Add tracker\"></input>";xhtml+="</form></div>";xhtml+="<div class=\"clearfix\"></div>";xhtml+="<div><span class=\"tracker_msg\">&nbsp;</span>";xhtml+="</div>";$("#ajax_tracker_list").html(xhtml);}
bb_DeviceCacheManager.prototype.CreatePhoneListHTML=function(pList,ehref)
{var xhtml="";var atag="";var device;var divid="";var script="";var floatright="right";var userAgent=navigator.userAgent.toLowerCase();if($.browser.msie&&$.browser.version.substring(0,1)=="7")
floatright="";else if($.browser.mozilla){if(navigator.userAgent.toLowerCase().indexOf('firefox')!=-1){userAgent=userAgent.substring(userAgent.indexOf('firefox/')+8);userAgent=userAgent.substring(0,3);if(parseFloat(userAgent)<3.5)
floatright="";}
else{floatright="";}}
for(var i=0;i<pList.length;i++)
{device=pList[i];divid="div"+device.imei;xhtml+="<div id=\""+divid+"\" class=\"layout_device_list\">";xhtml+="<a class=\"nobdr\" onclick=\"javascript:trackme('"+device.imei+"');\" href=\"#\"><img id=\"tl"+device.imei+"\" src=\"/images/lock_open.png\" alt=\"Track\" /></a>";atag=this.GetNameFromDevice(device);xhtml+="<input type=\"checkbox\" name=\"Checkset_imei\" value=\""+device.imei+"\" id=\"chk"+device.imei+"\" onclick=\"javascript:device_visibility('"+device.imei+"');\"><a href = \"#\" onclick=\"javascript:UnitSelected('"+device.imei+"');\">"+atag+"</a></input>";xhtml+='<a class="nobdr" href="" onclick="toggle_deviceInfo(\''+device.imei+'\'); return false;"><img class="'+floatright+'" id="imgInfo'+device.imei+'" src="/images/navigate_open.png" alt="" /></a>';xhtml+="</div>";if(device.line_color)
{script+="$(\"div#"+divid+"\").css(\"background-color\",\""+device.line_color+"\");";}}
if(script.length>0)
xhtml+="<script type=\"text/javascript\">"+script+"</script>";return xhtml;}
bb_DeviceCacheManager.prototype.GetNameFromDevice=function(device)
{var atag="";if(bb_IsDefined(device.labelname))
{atag=device.labelname;}
else if(bb_IsDefined(device.devicenumber))
atag=device.devicenumber;else
atag=device.imei;return atag;}
bb_DeviceCacheManager.prototype.FindInList=function(iList,imei)
{for(var i=0;i<iList.length;i++)
{device=iList[i];if(imei==device.imei)
return i;}
return-1;}
bb_DeviceCacheManager.prototype.Find=function(imei)
{if(!this.IsCached())
{jQuery.getJSON("/server_get_device_status_info.php",{"imei":imei},getdeviceinfo);return null;}
var index=this.FindInList(this.DeviceCache.owned,imei);var display="";if(index>=0)
{return this.DeviceCache.owned[index];}
else
{index=this.FindInList(this.DeviceCache.tracking,imei);if(index>=0)
{return this.DeviceCache.tracking[index];}}
return null;}
bb_DeviceCacheManager.prototype.IsCached=function()
{return(this.DeviceCache!=null);}
bb_Layout.INIT_ZOOM=14;bb_Layout.MIN_ZOOM=1;function bb_Layout(div,bottomDiv)
{var me=this;this.ZoomLevel=bb_Layout.INIT_ZOOM;this.Div_="#"+div;this.BottomDiv_="#"+bottomDiv;try
{if(GBrowserIsCompatible())
{this.Map=new GMap2(document.getElementById(div));this.Map.addControl(new GLargeMapControl());this.Map.addControl(new GMapTypeControl());this.Map.addControl(new GScaleControl());this.Map.addControl(new GOverviewMapControl());this.Map.setCenter(new GLatLng(0,0),1);GEvent.addListener(this.Map,"zoomend",function(oldLevel,newLevel){me.ZoomLevel=newLevel;});this.Map.enableDoubleClickZoom();this.Map.enableContinuousZoom();this.Map.enableScrollWheelZoom();this.Map.enableKeyDragZoom({key:"ctrl",boxStyle:{border:"thin dashed black",backgroundColor:"transparent",opacity:1},paneStyle:{backgroundColor:"gray",opacity:0.1}});}}
catch(oError)
{alert("EXCEPTION: bb_Layout(): "+oError);}}
bb_Layout.prototype.Clear=function()
{this.Map.clearOverlays();}
bb_Layout.prototype.Zoom=function(level)
{this.Map.setZoom(level);}
bb_Layout.prototype.ZoomTo=function(point,zoom)
{zoom=zoom||this.GetZoom();this.Map.setCenter(point,zoom);}
bb_Layout.prototype.GetZoom=function()
{return this.ZoomLevel;}
bb_Layout.prototype.ResetMap=function()
{this.ZoomTo(new GLatLng(0,0),bb_Layout.MIN_ZOOM);}
bb_Layout.prototype.DockFill=function()
{var wHeight=$(window).height();var gmap_element=$(this.Div_);var gmaptop=gmap_element.position().top;var dashboardmin=50;var minBottom=dashboardmin+$(this.BottomDiv_).height();gmap_element.height(wHeight-gmaptop-minBottom);this.Map.checkResize();}
bb_Layout.prototype.panTo=function(point)
{this.Map.panTo(point);}
function bb_MapTrackerArgs(imei)
{this.Imei=imei;this.DateFrom=new Date();this.DateTo=new Date();this.LimitBy=100;this.QuickOnly=false;this.Secondaryimei=[];this.AutoRefresh=true;this.tracker='';this.ShowGeoFences=false;}
bb_MapTrackerArgs.prototype.Serialize=function()
{var rand_no=Math.floor(1000*Math.random());var p="imei="+this.Imei;p+="&r="+rand_no;p+="&tfrom="+this.DateFrom;p+="&tto="+this.DateTo;p+="&limitby="+this.LimitBy;p+="&tracker="+this.tracker;p+="&gf="+this.ShowGeoFences;var si="";jQuery.each(this.Secondaryimei,function(i,field){si+=field.value+"|";});if(si.length>0)
si=si.substring(0,si.length-1);if(si.length>0)
p+="&secimei="+si;else
p+="&secimei="+this.Imei;return p;}
bb_MapTrackerArgs.prototype.Equals=function(args)
{if(args)
{var samedate=(this.DateFrom==args.DateFrom)&&(this.DateTo==args.DateTo);var samelimit=this.LimitBy==args.LimitBy;var samedevicelist=true;var bFound=false;if(this.Secondaryimei.length==args.Secondaryimei.length)
{for(var i=0;i<this.Secondaryimei.length;i++)
{var val=this.Secondaryimei[i].value;for(var j=0;j<args.Secondaryimei.length;j++)
{if(val==args.Secondaryimei[j].value)
{bFound=true;break;}}
if(!bFound)
{samedevicelist=false;break;}}}
else
samedevicelist=false;return samedate&&samelimit&&samedevicelist;}
else
return false;}
function bb_DeviceFetcher(lay)
{this.Layout=lay;this.RefreshTimeoutId=-1;this.TrackerArgs=null;this.MemberData=null;this.Plotter=new bb_MapPlotterManager(this);this.DeviceCacheManager=new bb_DeviceCacheManager();this.RetrieveInProgress=false;this.Layout.Map.addControl(new bb_DashBoardControl(this));}
bb_DeviceFetcher.prototype.Clear=function()
{this.Layout.Clear();}
bb_DeviceFetcher.prototype.LoadProgressBar=function()
{var curtain=$("div#google_progress_div");if(curtain)
{var gmap=$("div"+this.Layout.Div_);var offset=gmap.offset();curtain.attr("className","google_progress_div_visible");curtain.css("width",$(window).width());curtain.css("top",0);curtain.css("left",0);curtain.css("height",$(window).height());}}
bb_DeviceFetcher.prototype.UnLoadProgressBar=function()
{var curtain=$("div#google_progress_div");if(curtain)
curtain.attr("className","google_progress_div_hidden");}
bb_DeviceFetcher.prototype.QuickRetrieve=function()
{$.getJSON("/server_get_phone_coords_JSON.php?"+this.TrackerArgs.Serialize(),quickretrieve);}
bb_DeviceFetcher.prototype.SelectUnit=function(imei)
{this.DeviceCacheManager.SelectUnit(imei);this.Plotter.NewPrimaryImei(imei);var options={tracker:imei};var point=null;if((point=this.Plotter.GetZoomPoint(options))!=null)
this.Layout.panTo(point);}
bb_DeviceFetcher.prototype.TrackMe=function(imei)
{this.TrackerArgs.tracker=imei;this.Plotter.NewTracker(imei);this.GotoMapCenter();}
bb_DeviceFetcher.prototype.RetrieveByArgs=function(args)
{this.TrackerArgs=args;this.DeviceCacheManager.SelectUnit(this.TrackerArgs.Imei);this.LoadProgressBar();this.ResetTimeout();this.RetrieveInProgress=true;this.QuickRetrieve();}
bb_DeviceFetcher.prototype.RetrieveByArgsCached=function(args)
{if(!args.Equals(this.TrackerArgs))
{this.RetrieveByArgs(args);}
else
{this.SelectUnit(args.Imei);}}
bb_DeviceFetcher.prototype.ReceiveByArgs=function(json_data)
{try
{this.MapInfoRefresh();this.Plot(json_data);if(this.TrackerArgs.AutoRefresh)
this.PrepareNextRefresh();}
catch(oError)
{alert("EXCEPTION: ReceiveByArgs(): "+oError);}
finally
{this.UnLoadProgressBar();this.RetrieveInProgress=false;}}
bb_DeviceFetcher.prototype.MapInfoRefresh=function()
{var dte=new Date();var element=$("div#last_update_container");var footer_text="Last plotted at: "+bb_LeadingZeros(dte.getHours(),2,"0")+":"+bb_LeadingZeros(dte.getMinutes(),2,"0");footer_text+=" | Auto refresh enabled: ";footer_text+="<a href=\"#\" onclick=\"toggle_refresh();\">"+this.TrackerArgs.AutoRefresh+"</a>";footer_text+=" | Show Geofences: ";footer_text+="<a href=\"#\" onclick=\"toggle_geofences();\">"+this.TrackerArgs.ShowGeoFences+"</a>";if(element)
element.html(footer_text);}
bb_DeviceFetcher.prototype.Plot=function(data)
{var plotted=this.Plotter.Plot({"primary_imei":this.TrackerArgs.Imei,"tracker":this.TrackerArgs.tracker,"devices":data,"device_name":getdevicename,"geofences":this.TrackerArgs.ShowGeoFences});if(plotted)
{this.Plotter.Refresh();if(this.Plotter.Count()==0)
{this.Layout.ResetMap();}
else if(this.TrackerArgs.QuickOnly)
{if(this.IsBeingTracked(this.TrackerArgs.tracker))
this.GotoMapCenter();}
else
{var options={tracker:this.TrackerArgs.Imei};this.Layout.ZoomTo(this.Plotter.GetZoomPoint(options),bb_Layout.INIT_ZOOM);}}}
bb_DeviceFetcher.prototype.GotoMapCenter=function()
{var point=null;if(this.Plotter.Count()>0&&(point=this.Plotter.GetZoomPoint()))
{this.Layout.panTo(point);}}
bb_DeviceFetcher.prototype.DataHasChanged=function(member_data)
{return true;if(!this.MemberData)
{return true;}
else
{return this.Plotter.IsDataDifferent(member_data.devices);}}
bb_DeviceFetcher.prototype.PrepareNextRefresh=function()
{this.ResetTimeout();var rate=60000;if(this.TrackerArgs.LimitBy==0)
{rate=60000;}
else if(this.TrackerArgs.LimitBy<=5)
{rate=5000;}
else if(this.TrackerArgs.LimitBy<=10)
{rate=15000;}
else if(this.TrackerArgs.LimitBy<=100)
{rate=30000;}
this.RefreshTimeoutId=setTimeout(preparenextrefresh,rate);}
bb_DeviceFetcher.prototype.ResetTimeout=function()
{if(this.RefreshTimeoutId>0)
clearTimeout(this.RefreshTimeoutId);}
bb_DeviceFetcher.prototype.IsBeingTracked=function(imei)
{return this.Plotter.IsInList(imei);}
function bb_DemoDeviceFetcher(lay)
{this.Layout=lay;this.TrackerArgs=null;this.Plotter=new bb_MapPlotterManager(this);}
bb_DemoDeviceFetcher.prototype.RetrieveByArgs=function(args)
{this.TrackerArgs=args;$.getJSON("server_get_phone_coords_JSON.php?"+this.TrackerArgs.Serialize(),retrievebyargs);}
bb_DemoDeviceFetcher.prototype.ReceiveByArgs=function(json_data)
{this.Plotter.Plot({"primary_imei":this.TrackerArgs.Imei,"devices":json_data,"device_name":function(imei)
{return"DEMO UNIT";}});this.Plotter.Refresh();if(this.Plotter.Count()==0)
{this.Layout.ResetMap();}
else
{var options={tracker:this.TrackerArgs.Imei};this.Layout.ZoomTo(this.Plotter.GetZoomPoint(options),bb_Layout.INIT_ZOOM);}}
function bb_IconImage(options)
{this.markerType=options.type||BB_POINT_NORMAL;this.filename=options.filename||"marker_icon_"+this.markerType+".png";var h=options.height||24;var w=options.width||24;var ic=new GIcon();ic.image="/images/"+this.filename;ic.iconSize=new GSize(h,w);ic.iconAnchor=new GPoint(8,16);ic.infoWindowAnchor=new GPoint(10,14);ic.shadow="";this.icon=ic;}
function bb_MapPlotterManager(fetcher)
{this.Devices=null;this.Layout=fetcher.Layout;this.Plotted=new Array();this.PrimaryImei="";this.Tracker="";this.DeviceNameCallBack=null;this.CustomIcons=[];this.CreateCustomIcons({"type":BB_POINT_NORMAL});this.CreateCustomIcons({"type":BB_POINT_SOS});this.CreateCustomIcons({"type":BB_POINT_TAG});this.CreateCustomIcons({"type":BB_POINT_LOST});this.CreateCustomIcons({"type":BB_POINT_FIRST,"height":24,"width":24});this.CreateCustomIcons({"type":BB_POINT_LAST,"height":24,"width":24});this.CreateCustomIcons({"type":BB_POINT_OCCUPIED,"height":24,"width":24});try
{this.Geocoder=new GClientGeocoder();}
catch(oError)
{alert("EXCEPTION: bb_MapPlotterManager(): "+oError);}}
bb_MapPlotterManager.prototype.CreateCustomIcons=function(options)
{this.CustomIcons.push(new bb_IconImage(options));}
bb_MapPlotterManager.prototype.IsInList=function(imei)
{for(var i=0;i<this.Plotted.length;i++)
{if(this.Plotted[i].Imei==imei)
return true;}
return false;}
bb_MapPlotterManager.prototype.IsDataDifferent=function(device_array)
{if(this.Plotted.length==0)
return device_array.length>0;else
{try
{if(this.Plotted.length==device_array.length)
{for(var i=0;i<this.Plotted.length;i++)
{var plot=this.Plotted[i];var device=device_array[i];if(plot.Imei!=device.imei)
{return true;}
else if(plot.Count()>0)
{var p1=plot.Last();if(plot.IsValid(device.points[0]))
{var p2=plot.GetLatLng(device.points[0]);if(!p1.equals(p2))
return true;}
else
return true;}
else if(device.points.length>0)
return true;}}
else
return true;}catch(oError)
{alert("EXCEPTION (IsDataDifferent): "+oError);}
return false;}}
bb_MapPlotterManager.prototype.Clear=function()
{for(var i=0;i<this.Plotted.length;i++)
{this.Plotted[i].MarkerMgr.clearMarkers();}
this.Plotted.length=0;this.Layout.Clear();}
bb_MapPlotterManager.prototype.Refresh=function()
{for(var i=0;i<this.Plotted.length;i++)
{this.Plotted[i].MarkerMgr.refresh();}}
bb_MapPlotterManager.prototype.PeekCount=function(devices)
{var pCount=0;for(var i=0;i<devices.length;i++)
{pCount+=devices[i].pointcount;}
return pCount;}
bb_MapPlotterManager.prototype.Count=function()
{var pCount=0;for(var i=0;i<this.Plotted.length;i++)
{var plot=this.Plotted[i];pCount+=plot.Count();}
return pCount;}
bb_MapPlotterManager.prototype.NewPrimaryImei=function(imei)
{this.PrimaryImei=imei;}
bb_MapPlotterManager.prototype.NewTracker=function(imei)
{this.Tracker=imei;}
bb_MapPlotterManager.prototype.GetZoomPoint=function(options)
{var imei=this.Tracker;if(options)
imei=options.tracker||this.Tracker;var point=null;var pCount=this.Count();for(var i=0;i<this.Plotted.length;i++)
{var plot=this.Plotted[i];if(plot.Count()>0)
{if(plot.Imei==imei)
return plot.Last();}}
return point;}
bb_MapPlotterManager.prototype.iconIsCached=function(filename)
{var len=this.CustomIcons.length;var ic=null;for(var i=0;i<len;i++)
{ic=this.CustomIcons[i];if(ic.filename==filename)
{return true;}}
return false;}
bb_MapPlotterManager.prototype.Plot=function(options)
{this.Clear();this.PrimaryImei=options.primary_imei||"";this.Devices=options.devices.devices||false;this.DeviceNameCallBack=options.device_name;this.Tracker=options.tracker||this.PrimaryImei;var show_geofences=options.geofences||false;var device=null;var plotter=null;if(this.Devices)
{for(var i=0;i<this.Devices.length;i++)
{device=this.Devices[i];if(!this.iconIsCached(device.ic))
{this.CreateCustomIcons({"type":BB_POINT_LAST,"filename":device.ic});}
plotter=new bb_MapPlotter(this.Layout.Map,this.Geocoder,this.CustomIcons);plotter.Plot({"primaryimei":this.PrimaryImei,"device":device,"displayname":this.DeviceNameCallBack(device.imei)});this.Plotted.push(plotter);}
var geofences=options.devices.geofences;if(show_geofences==true&&geofences)
{var drawer=null;for(var n=0;n<geofences.length;n++)
{var geo=geofences[n];if(geo.t==TPOLYGON)
{drawer=new bb_GeoPolygon(this.Layout.Map,{});var v=geo.vertices;for(var i=0;i<v.length;i++)
{drawer.add(v[i].lat,v[i].lng);}}
else
{drawer=new bb_GeoCircle(this.Layout.Map,{radius:geo.r});drawer.add(geo.lat,geo.lng);}
drawer.plot();drawer.unbind();}}
return true;}
else
return false;}
function bb_MapPlotter(map,geocoder,icons)
{this.handlers=[];this.Device=null;this.Imei="";this.DevicedisplayName="";this.GeoCoder=geocoder;this.Map=map;this.RealCount=0;this.MarkerMgr=new MarkerManager(map,{trackMarkers:false});this.CustomIcons=icons;this.OverlaySegments=null;}
bb_MapPlotter.prototype.Redraw=function()
{if(this.OverlaySegments)
this.Map.addOverlay(this.OverlaySegments);}
bb_MapPlotter.prototype.Clear=function()
{if(this.OverlaySegments)
this.Map.removeOverlay(this.OverlaySegments);var len=this.handlers.length;for(var i=0;i<len;i++)
{GEvent.removeListener(this.handlers[i]);}
this.MarkerMgr.clearMarkers();this.handlers.length=0;this.MarkerMgr=null;this.Map=null;}
bb_MapPlotter.prototype.ShowGeoAddress=function(response,overlay,point,devicename,me,index)
{if(!response||response.Status.code!=200)
{overlay.openInfoWindowHtml('<b>Unit:</b> '+devicename+'<br>'+'<b>Receved At:</b> Unknown <br>'+'<b>Address:</b> Unknown');}
else
{place=response.Placemark[0];var haslock=(me.Device.ol==1);var recvtime=point.t;var status='';if(point.isLast)
{status='<b>Status:</b> ';if(me.Device.ol==STATUS_OFFLINE)
{status+='OFFLINE';recvtime=me.Device.lc;}
else if(me.Device.ol==STATUS_HASLOCK)
{status+='HAS LOCK';}
else if(me.Device.ol==STATUS_DISCONNECTED)
{status+='DISCONNECTED';}
else
{status+='NO LOCK';recvtime=me.Device.lc;}}
var altitude="";if(point.alt!=null)
altitude=' <b>Altitude:</b> '+point.alt;var move_links="";overlay.openInfoWindowHtml('<b>Unit:</b> '+devicename+'<br>'+'<b>Received At:</b> '+recvtime+'<br>'+'<b>Address:</b> '+place.address+'<br>'+'<b>Voltage:</b> '+point.v+' <b>Signal:</b> '+point.s+
altitude+'<br />'+
status+'<br />');}}
bb_MapPlotter.prototype.GetGeoAddress=function(marker,latlng,phptime,index)
{var me=this;this.GeoCoder.getLocations(latlng,function(response,overlay){me.ShowGeoAddress(response,marker,phptime,me.DevicedisplayName,me,index);});}
bb_MapPlotter.prototype.IsValid=function(p)
{if(p)
return!isNaN(p.lat)&&!isNaN(p.lng);else
return false;}
bb_MapPlotter.prototype.GetLatLng=function(point)
{return new GLatLng(parseFloat(point.lat),parseFloat(point.lng));}
bb_MapPlotter.prototype.Count=function()
{return this.RealCount;}
bb_MapPlotter.prototype.First=function()
{var point=this.Device.points[Count()-1];return this.GetLatLng(point);}
bb_MapPlotter.prototype.Last=function()
{var point=this.Device.points[0];return this.GetLatLng(point);}
bb_MapPlotter.prototype.Get=function(index)
{if(index>0&&index<this.Device.points.length)
return this.GetLatLng(this.Device.points[index]);}
bb_MapPlotter.prototype.CreatePolyLine=function(latlng_array,color)
{var line_thickness=4;var line_opacity=.75;this.OverlaySegments=new GPolyline(latlng_array,color,line_thickness,line_opacity);return this.OverlaySegments;}
bb_MapPlotter.prototype.CreateMarkerWithHandler=function(coord,marker_type,point,marker_display_text,index)
{var lblclass="";switch(marker_type)
{case BB_POINT_LAST:lblclass="markerLabel";switch(this.Device.ol)
{case STATUS_HASLOCK:lblclass+=" markerhaslock";break;case STATUS_NOLOCK:lblclass+=" markernolock";break;case STATUS_OFFLINE:lblclass+=" markeroffline";break;case STATUS_DISCONNECTED:lblclass+=" markerdisconnected";break;}
break;case BB_POINT_FIRST:lblclass="markerLabel_hidden";break;default:lblclass="markerLabel_small";}
var markerOptions={"icon":this.getIcon(marker_type),"clickable":true,"labelText":marker_display_text,"labelClass":lblclass,"labelOffset":new GSize(15,-30),"zIndexProcess":zindexprocess};var marker=new LabeledMarker(coord,markerOptions);marker.importance=marker_type;var me=this;point.isLast=(marker_type==BB_POINT_LAST);this.handlers.push(GEvent.addListener(marker,"click",function(){me.GetGeoAddress(marker,coord,point,index);}));return marker;}
bb_MapPlotter.prototype.getIcon=function(marker_type)
{var len=this.CustomIcons.length;var icNormal=null;for(var i=0;i<len;i++)
{ic=this.CustomIcons[i];if(marker_type==BB_POINT_LAST)
{if(ic.filename==this.Device.ic)
return ic.icon;else
icNormal=ic.icon;}
else if(ic.markerType==marker_type)
{return ic.icon;}}
if(icNormal==null)
return new bb_IconImage({"type":BB_POINT_NORMAL}).icon;else
return icNormal;}
bb_MapPlotter.prototype.IsImportantPoint=function(point)
{return point.sos!=BB_POINT_NORMAL;}
bb_MapPlotter.prototype.NotWithinRange=function(start_p,end_p,range)
{return end_p.distanceFrom(start_p)>=range;}
bb_MapPlotter.prototype.Plot=function(options,markermgr)
{this.Device=options.device;this.Imei=this.Device.imei;this.DevicedisplayName=options.displayname||this.Imei;var isprimary=((options.primaryimei||"")==this.Imei);var range=options.range||30;try
{var marker=null;var bStartFound=false;var point=null;var sos=BB_POINT_FIRST;var marker_array=[];var marker_bounds_array=[];var line_color='';var start_latlng=null;var end_latlng=null;var not_shown=0;var latlng_array=[];var marker_label="";this.RealCount=0;for(var i=this.Device.points.length-1;i>=0;i--)
{point=this.Device.points[i];line_color=this.Device.line_color;if(this.IsValid(point))
{this.RealCount++;if(start_latlng)
{end_latlng=this.GetLatLng(point);latlng_array.push(end_latlng);if(this.NotWithinRange(start_latlng,end_latlng,range)||i==0||this.IsImportantPoint(point))
{if(i==0)
{sos=BB_POINT_LAST;marker_label=this.DevicedisplayName;}
else
{sos=point.sos;marker_label=(this.Device.points.length-1)-i;}
marker=this.CreateMarkerWithHandler(end_latlng,sos,point,marker_label,i);if(i==0)
{marker_bounds_array.push(marker);}
else
marker_array.push(marker);}
else
not_shown++;start_latlng=end_latlng;}
else
{start_latlng=this.GetLatLng(point);latlng_array.push(start_latlng);if(!bStartFound)
{if(i==0)
{sos=BB_POINT_LAST;marker_label=this.DevicedisplayName;}
else
{sos=BB_POINT_FIRST;marker_label=(this.Device.points.length-1)-i;}
marker=this.CreateMarkerWithHandler(start_latlng,sos,point,marker_label,i);marker_bounds_array.push(marker);bStartFound=true;}}}}
if(latlng_array.length>1)
{this.CreatePolyLine(latlng_array,line_color);this.Redraw();}
this.MarkerMgr.addMarkers(marker_array,15);this.MarkerMgr.addMarkers(marker_bounds_array,1);}
catch(oError)
{alert("EXCEPTION: Plot(): "+oError);}
finally
{this.RealCount-=not_shown;}}
function bb_DashBoardControl(fetcher)
{this.Handle=fetcher;this.ImageRoot="http://www.bigbrotherme.co.nz/images/";}
bb_DashBoardControl.prototype=new GControl();bb_DashBoardControl.prototype.initialize=function(map)
{var me=this;var container=document.createElement("div");container.id="dashboard_control";var refreshDiv=this.CreateButtonElement_('Refresh data points','javascript:DoDataRefresh();','earth_view.png');var centerDiv=this.CreateButtonElement_('Center on selected','javascript:Mapper.GotoMapCenter();','earth_location.png');var lastlocationDiv=this.CreateButtonElement_('Last known location','javascript:GetLastKnownLocation();','earth_find.png');container.appendChild(refreshDiv);container.appendChild(lastlocationDiv);container.appendChild(centerDiv);map.getContainer().appendChild(container);return container;}
bb_DashBoardControl.prototype.getDefaultPosition=function()
{return new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(80,7));}
bb_DashBoardControl.prototype.CreateButtonElement_=function(title,href,src)
{var div_c=document.createElement("div");div_c.className="dash_actions nobdr";div_c.setAttribute('title',title);var linktag=document.createElement("a");linktag.setAttribute('href',"#");linktag.setAttribute('onclick',href);var imgtag=document.createElement("img");imgtag.setAttribute('src',this.ImageRoot+src);imgtag.setAttribute('alt',title);linktag.appendChild(imgtag)
div_c.appendChild(linktag);return div_c;}