﻿var map; var mapcanvas = null; var mapwidth = null; var mapheight = null; var Bounds = null; var Geocoder = null; var Geofence = null; var BaseGeofence = null; var Report = false; var FleetReport = false; var MoveListener = null; var overmap = null; var LandmarkManager; var AddressMarker; var ShowLandmarks = true; var UnitManager; var OverManager; var UnitMarkers = new Array(); var LandmarkMarkers = new Array(); var SelectedInfoWindow = null; var whtml = null; var UpdateTimer = null; var SelectedUnit = null; var FollowUnit = null; var TrackPan = null; var GeofenceMode = false; var Menus = new Array(); var ControlLeader = "TravlMaster_BodyContent_";
var unitAddress = null;
var trafficOverlay = null;
var UnitUpdated = false;
Menus[0] = new TravlMenu(false, ControlLeader + 'pnlSubMenuUnits');
Menus[1] = new TravlMenu(false, ControlLeader + 'pnlSubMenuLocations');
Menus[2] = new TravlMenu(false, ControlLeader + 'pnlSubMenuLocationsAddressContainer');
Menus[3] = new TravlMenu(false, ControlLeader + 'pnlSubMenuLocationsLandmark');
Menus[4] = new TravlMenu(false, ControlLeader + 'pnlSubMenuUnitSettings');
Menus[5] = new TravlMenu(false, ControlLeader + 'pnlSubMenuMapSettings');
Menus[6] = new TravlMenu(false, ControlLeader + 'pnlSubMenuMapSettingsSize');
Menus[7] = new TravlMenu(false, ControlLeader + 'pnlSubMenuMapSettingsTimeZone');
Menus[8] = new TravlMenu(false, ControlLeader + 'pnlSubMenuGeofence');
Menus[9] = new TravlMenu(false, ControlLeader + 'tblMapSubMenuGeofenceInfo');
Menus[10] = new TravlMenu(false, ControlLeader + 'btnDeleteGeofence');
Menus[11] = new TravlMenu(false, ControlLeader + 'pnlSubMenuUnitsTable');
Menus[12] = new TravlMenu(false, ControlLeader + 'tblUnitSettings');
var settings9 = { tl: { radius: 9 }, tr: { radius: 9 }, bl: { radius: 9 }, br: { radius: 9 }, antiAlias: true, autoPad: true, validTags: ["div"] }; var settings6bottom = { tl: { radius: 0 }, tr: { radius: 0 }, bl: { radius: 6 }, br: { radius: 6 }, antiAlias: true, autoPad: true, validTags: ["div"] }; var settings6 = { tl: { radius: 6 }, tr: { radius: 6 }, bl: { radius: 6 }, br: { radius: 6 }, antiAlias: true, autoPad: false, validTags: ["div", "span"] }; var settings8 = { tl: { radius: 8 }, tr: { radius: 8 }, bl: { radius: 8 }, br: { radius: 8 }, antiAlias: true, autoPad: true, validTags: ["div"] }; var settings5 = { tl: { radius: 5 }, tr: { radius: 5 }, bl: { radius: 5 }, br: { radius: 5 }, antiAlias: true, autoPad: true, validTags: ["div", "span", "table"] }; var settings15 = { tl: { radius: 15 }, tr: { radius: 15 }, bl: { radius: 15 }, br: { radius: 15 }, antiAlias: true, autoPad: true, validTags: ["div"] }; var settings12 = { tl: { radius: 12 }, tr: { radius: 12 }, bl: { radius: 12 }, br: { radius: 12 }, antiAlias: true, autoPad: true, validTags: ["div"] }; var settings10 = { tl: { radius: 10 }, tr: { radius: 10 }, bl: { radius: 10 }, br: { radius: 10 }, antiAlias: true, autoPad: true, validTags: ["div", "span"] };
function TravlMenu(open, extender) { this.Open = open; this.Extender = extender; return this; }
window.onunload = function () { if (map != null) GUnload(); }
window.onload = function () {
    var unitSettings = document.getElementById(ControlLeader + "tblUnitSettings"); if (unitSettings != null) unitSettings.style.visibility = "hidden"; if (document.getElementById(ControlLeader + "pnlMap") != null || document.getElementById(ControlLeader + "pnlReportMap") != null) {
        if (GBrowserIsCompatible()) {
            mapcanvas = document.getElementById(ControlLeader + "pnlMap"); if (mapcanvas == null) { mapcanvas = document.getElementById(ControlLeader + "pnlReportMap"); Report = true; } map = new GMap2(mapcanvas);
            map.addMapType(G_HYBRID_MAP); map.addMapType(G_SATELLITE_MAP); map.addMapType(G_PHYSICAL_MAP); map.addControl(new GLargeMapControl3D()); var mapControl = new GHierarchicalMapTypeControl(); mapControl.clearRelationships(); map.enableScrollWheelZoom(); map.enableContinuousZoom(); /* map.addControl(mapControl); */if (!Report || Report) { map.addControl(new TrafficControl({ showTraffic: true, showTrafficKey: true })); } Bounds = new GLatLngBounds(); Geocoder = new GClientGeocoder(); GEvent.addListener(map, "zoomend", function (oldLevel, newLevel) { map.getCurrentMapType().getMaxZoomAtLatLng(map.getCenter(), function (response) { if (response && response['status'] == G_GEO_SUCCESS && response['zoom'] < newLevel) { map.setCenter(map.getCenter(), response['zoom']); } }); if (SelectedUnit != null) { SelectPoint(SelectedUnit + 1, true); } }); GEvent.addListener(map, "maptypechanged", function () { map.getCurrentMapType().getMaxZoomAtLatLng(map.getCenter(), function (response) { if (response && response['status'] == G_GEO_SUCCESS && response['zoom'] < map.getZoom()) { map.setCenter(map.getCenter(), response['zoom']); } }); }); if (!Report) { GEvent.addListener(map, "singlerightclick", function (point, src, overlay) { if (!overlay) { var latlng = map.fromContainerPixelToLatLng(point); var whtml = "<input id=\"hiddenLandmarkLocation\" type=\"hidden\" value=\"" + latlng.lat() + "_:_" + latlng.lng() + "\">"; whtml += "<input id=\"hiddenLandmarkDescription\" type=\"hidden\" value=\"" + latlng.lat() + ", " + latlng.lng() + "\">"; whtml += "<input id=\"txtLandmarkName\" type=\"text\" value=\"Landmark Name\" maxlength=\"20\">"; whtml += "<br />"; whtml += "<input type=\"submit\" class=\"MenuButton\" value=\"Save Landmark\" onclick=\"SaveLandmark(); return false;\">"; MoveListener = GEvent.bind(map, "moveend", this, function () { this.openInfoWindowHtml(latlng, whtml); GEvent.removeListener(MoveListener) }); this.panTo(latlng); } }); } map.setCenter(new GLatLng(35.4683341083781, -82.5808576198583), 13); SizeMap(); if (!Report) { LandmarkManager = new MarkerManager(map, { trackMarkers: false }); } if (UnitManager == null) UnitManager = new MarkerManager(map, { trackMarkers: true }); UnitManager = new MarkerClusterer(map, null, { gridSize: 15 }); /* map.setUIToDefault(); */
        }
    } if (!Report) FollowUnit = setInterval('TrackUnit()', 2500); var bnr = document.getElementById("TravlMaster_pnlBanner"); var mnu = document.getElementById("TravlMaster_MenuBarPanel"); var bdy = document.getElementById("TravlMaster_BodyPanel"); bnr.style.visibility = "visible"; mnu.style.visibility = "visible"; bdy.style.visibility = "visible";
}
function CreateGeofence() { var sv = document.getElementById(ControlLeader + "btnSaveGeofence"); sv.style.visibility = "visible"; var el = document.getElementById(ControlLeader + "btnRevertGeofence"); el.value = "Cancel"; el.style.visibility = "visible"; var gd = document.getElementById(ControlLeader + "btnDeleteGeofence"); gd.style.visibility = "hidden"; var gn = document.getElementById(ControlLeader + "txtGeofenceName"); gn.value = ""; gn.style.visibility = "visible"; if (Geofence != null) { Geofence.disableEditing(); map.removeOverlay(Geofence); } Geofence = new GPolygon(new Array(), "#0000FF", 1, 0.75, "#0000FF", 0.25); Geofence.id = "00000000-0000-0000-0000-000000000000"; map.addOverlay(Geofence); Geofence.enableDrawing(); GEvent.addListener(Geofence, "endline", function () { GEvent.addListener(Geofence, "mouseover", function () { this.enableEditing(); }); GEvent.addListener(Geofence, "mouseout", function () { this.disableEditing(); }); GEvent.addListener(Geofence, "click", function (latlng, index) { if (typeof index == "number") { this.deleteVertex(index); } }); this.complete = true; }); }
function ShowUnitsMenu() { ShowHideMenus([ControlLeader + 'pnlSubMenuUnits', ControlLeader + 'pnlSubMenuUnitsTable']); }
function ShowLocationsMenu() { ShowHideMenus([ControlLeader + 'pnlSubMenuLocations']); }
function ShowLocationsAddressMenu() { ShowHideMenus([ControlLeader + 'pnlSubMenuLocationsAddressContainer'], [ControlLeader + 'pnlSubMenuLocations']); }
function ShowLocationsLandmarkMenu() { ShowHideMenus([ControlLeader + 'pnlSubMenuLocationsAddress'], [ControlLeader + 'pnlSubMenuLocations', ControlLeader + 'pnlSubMenuLocationsLandmark']); }
function ShowUnitSettingsMenu() { ShowHideMenus([ControlLeader + 'pnlSubMenuUnitSettings', ControlLeader + 'tblUnitSettings']); }
function ShowMapSettingsMenu() { ShowHideMenus([ControlLeader + 'pnlSubMenuMapSettings']); }
function ShowMapSizeMenu() { ShowHideMenus([ControlLeader + 'pnlSubMenuMapSettingsSize']); }
function ShowGeofenceMenu() { ShowHideMenus([ControlLeader + 'pnlSubMenuGeofence']); }
function ShowTimeZoneMenu() { ShowHideMenus([ControlLeader + 'pnlSubMenuMapSettingsTimeZone']); }
function PanToLandmark() { var el = document.getElementById(ControlLeader + 'LandmarksDropdown'); var landmarkinfo = document.getElementById(ControlLeader + 'LandmarkLocation-' + el.value); if (landmarkinfo == null) { alert("You must select a landmark first."); return; } var position = landmarkinfo.value.split(':'); TridentMap.PanToWorldCoordinate(position[0], position[1]); }
function GotoLandmark() { var ddl = document.getElementById(ControlLeader + "ddlLandmarks"); for (var i = 0; i < LandmarkMarkers.length; i++) { if (LandmarkMarkers[i].id == ddl.value) { map.panTo(LandmarkMarkers[i].position); break; } } }
function MapUpdate(timestamp) { var lmu = document.getElementById(ControlLeader + "cellMapUpdate"); lmu.innerHTML = timestamp; }
function ShowHideLandmarks(el) { ShowLandmarks = !ShowLandmarks; if (el == null) { return; } if (ShowLandmarks) { el.value = "Hide Landmarks"; LandmarkManager.addMarkers(LandmarkMarkers, 0); LandmarkManager.refresh(); /* for (var i = 0; i < LandmarkMarkers.length; i++) { LandmarkManager.addMarker(LandmarkMarkers[i], 0); }*/ } else { el.value = "Show Landmarks"; LandmarkManager.clearMarkers(); } }
function SelectFleet(key) {
    UnitManager.clearMarkers();
    if (UnitMarkers[(key)].length > 0) {
        UnitManager.addMarkers(UnitMarkers[(key)], 0);
    }
    UnitManager.resetViewport(true);
}
function SelectPoint(key, nopan) {
    var marker = UnitManager.getMarker(key);

    if (marker) {
        SelectedUnit = key;
        if (map.getCenter() != marker.position) {
            if (!nopan) {
                //map.panTo(UnitMarkers[SelectedUnit].position);
                map.panTo(marker.position, 20);
                ShowHidePoints(nopan);
            }
            /*
            MoveListener = GEvent.bind(map, "moveend", this, function() {
            ShowHidePoints(nopan);
            //setTimeout("ShowHidePoints(" + nopan + ");", 10);
            GEvent.removeListener(MoveListener);
            });
            */
        }
        else {
            ShowHidePoints(nopan);
            //setTimeout("ShowHidePoints(" + nopan + ");", 10);
        }
    }
}
function ShowHidePoints(nopan) {
    if (SelectedUnit != null) {
        var markers = UnitManager.getMarkers();

        for (var i = 0; i < markers.length; i++) {
            if (i != SelectedUnit) {
                markers[i].marker.closeInfoWindow();
            }
        }

        markers = null;

        var marker = UnitManager.getMarker(SelectedUnit);

        map.openInfoWindow(marker.position, marker.infoDiv);

        if (!nopan) {
            Geocoder.getLocations(marker.position, AddAddressFromPoint);
        }
        else {
            var elAdd = document.getElementById(SelectedUnit + "-addressinfo");

            if (elAdd != null) {
                elAdd.innerHTML = unitAddress;
            }
        }
    }
}
function GetAddressFromPoint(response) {
    if (!response || response.Status.code != 200) {
    }
    else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
        var address = "";
        if (place.AddressDetails.Country == null) {
            address = place.address;
        }
        else {
            var adminarea = place.AddressDetails.Country.AdministrativeArea;
            if (adminarea != null) {
                if (adminarea.Locality != null) {
                    if (adminarea.Locality.Thoroughfare != null) {
                        address += adminarea.Locality.Thoroughfare.ThoroughfareName + "<br />";
                    }
                    address += adminarea.Locality.LocalityName + ", ";
                    address += adminarea.AdministrativeAreaName;
                    if (adminarea.Locality != null) {
                        if (adminarea.Locality.PostalCode != null) {
                            address += "  " + adminarea.Locality.PostalCode.PostalCodeNumber;
                        }
                    }
                    html = address;
                }
                else {
                    html = place.address;
                }
            }
        }
        var coords = response.name.split(",");
        var foundunit = false;
        var markers = UnitManager.getMarkers();
        for (var i = 0; i < markers.length; i++) {
            if (markers[i].marker.position.lat().toFixed(6) == coords[0] && markers[i].marker.position.lng().toFixed(6) == coords[1]) {
                markers[i].marker.address = html;
                var ai = document.getElementById(markers[i].id + "-addressinfo");
                if (ai != null) {
                    ai.innerHTML = markers[i].address;
                }
                foundunit = true;
                break;
            }
        }
        for (var i = 0; i < LandmarkMarkers.length; i++) {
            if (LandmarkMarkers[i].position.lat().toFixed(6) == coords[0] && LandmarkMarkers[i].position.lng().toFixed(6) == coords[1]) {
                LandmarkMarkers[i].address = html;
                var ai = document.getElementById(LandmarkMarkers[i].id + "-addressinfo");
                if (ai != null) {
                    ai.innerHTML = LandmarkMarkers[i].address;
                }
                foundunit = true;
                break;
            }
        }
    }
}
function AddAddressFromPoint(response) {
    var marker = UnitManager.getMarker(SelectedUnit);//  UnitMarkers[SelectedUnit];
    whtml = "Point: " + (SelectedUnit + 1) + "<br />";
    whtml += marker.alias + " [" + marker.hsid + "-" + marker.min + "]<br />";
    whtml += marker.timestamp + "<br />";
    whtml += "Direction: " + ConvertDirection(marker.heading) + "<br />";
    whtml += "<br />";
    whtml += "<span id='" + marker.id + "-addressinfo'>";
    if (!response || response.Status.code != 200) {
        var head = document.getElementById(ControlLeader + "lblAlertHeading");
        var txt = document.getElementById(ControlLeader + "lblAlertText");
        var btn = document.getElementById(ControlLeader + "btnAlert");
        if (Report) {
            var elAdd = document.getElementById(marker.id + "-addressinfo");

            if (elAdd != null) {
                elAdd.innerHTML = "No detailed address information is available.";
            }
        }
        whtml += "No detailed address information is available.";
    }
    else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
        var address = "";
        if (place.AddressDetails.Country == null) {
            address = place.address;
        }
        else {
            var adminarea = place.AddressDetails.Country.AdministrativeArea;
            if (adminarea != null) {
                if (adminarea.Locality != null) {
                    if (adminarea.Locality.Thoroughfare != null) {
                        address += adminarea.Locality.Thoroughfare.ThoroughfareName + "<br />";
                    }
                    address += adminarea.Locality.LocalityName + ", ";
                    address += adminarea.AdministrativeAreaName;
                    if (adminarea.Locality != null) {
                        if (adminarea.Locality.PostalCode != null) {
                            address += "  " + adminarea.Locality.PostalCode.PostalCodeNumber;
                        }
                    }
                }
                else {
                }
            }
        }
        var elAdd = document.getElementById(marker.id + "-addressinfo");

        if (elAdd != null) {
            elAdd.innerHTML = place.address;
        }

        whtml += place.address; whtml += "</span>";
    }
    if (!Report) {
        var marker = UnitManager.getMarker(SelectedUnit);

        marker.openInfoWindowHtml(whtml);
    }
}
function SelectUnit(el) {
    SelectedUnit = el.id;
    var chk = document.getElementById(ControlLeader + "chkFollowUnit");
    if (chk.checked) {
        if (SelectedUnit != null) {
            map.disableDragging();
        }
    }
    else {
        map.enableDragging();
    }
    var lmu = document.getElementById(ControlLeader + "tblUnitInfo");
    lmu.style.visibility = "visible";
    var lus = document.getElementById(ControlLeader + "cellUnit");
    lus.innerHTML = el.innerHTML;
    MoveListener = GEvent.bind(map, "moveend", this, function () {
        GEvent.removeListener(MoveListener)
    });
    var marker = UnitManager.getMarker(SelectedUnit);
    PanToUnit(SelectedUnit);
    UnitManager.resetViewport(true);
    ShowHideMenus();
}
function ShowUnitSettings(speedlimit, speedunits, geofence, alertrecipients) { var spdLimit = document.getElementById(ControlLeader + "txtUnitSettingsSpeedLimit"); var spdUnits = document.getElementById(ControlLeader + "ddlUnitSettingsSpeedUnit"); var geo = document.getElementById(ControlLeader + "ddlUnitSettingsGeofence"); var alrt = document.getElementById(ControlLeader + "txtUnitSettingsAlertRecipients"); spdLimit.value = speedlimit; for (var i = 0; i < spdUnits.options.length; i++) { if (spdUnits.options[i].text == spdUnits) { spdUnits.options[i].selected = true; break; } } for (var i = 0; i < geo.options.length; i++) { if (geo.options[i].value == geofence) { geo.options[i].selected = true; break; } } alrt.value = alertrecipients; var subMenu = document.getElementById(ControlLeader + "pnlSubMenu"); if (subMenu != null) { var tmp = document.getElementById(ControlLeader + "tblUnitSettings"); tmp.style.visibility = subMenu.style.visibility; } }
function EditUnit(el) { var sel = document.getElementById(ControlLeader + "fieldShowUnitSettings"); for (var i = 0; i < el.options.length; i++) { if (el.options[i].selected) { var tmp = document.getElementById(ControlLeader + "tblUnitSettings"); tmp.style.visibility = 'hidden'; sel.value = el.options[i].value; __doPostBack(ControlLeader + 'fieldShowUnitSettings', 'OnValueChanged'); } } }
function EditedUnit(heading, text, button) { ShowAlert(heading, text, button); }
function UpdatedTimeZone(heading, text, button) { ShowAlert(heading, text, button); }
function TrackUnit() {
    if (map == null) {
        return;
    }
    if (!GeofenceMode) {
        var chk = document.getElementById(ControlLeader + "chkFollowUnit");
        if (chk.checked) {
            map.disableDragging();
            PanToUnit(SelectedUnit);
        }
        else {
        }
    }

    if (UnitUpdated) {
        UnitManager.resetViewport(true);
    }
}
function PanToUnit(guid) {
    var marker = UnitManager.getMarker(guid);

    if (marker) {
        var lur = document.getElementById(ControlLeader + "cellUnitUpdate");
        if (marker.position.lat() != 0 && marker.position.lng() != 0) {
            map.panTo(marker.position);
            lur.innerHTML = marker.timestamp;
            lur.style.color = "";
        }
        else {
            lur.innerHTML = "No Valid Report";
            lur.style.color = "Salmon";
        }
    }
}
function UpdateUnitSettings() { var uus = document.getElementById(ControlLeader + "fieldUpdateUnitSettings"); var sus = document.getElementById(ControlLeader + "fieldShowUnitSettings"); var spdLimit = document.getElementById(ControlLeader + "txtUnitSettingsSpeedLimit"); var spdUnits = document.getElementById(ControlLeader + "ddlUnitSettingsSpeedUnit"); var geo = document.getElementById(ControlLeader + "ddlUnitSettingsGeofence"); var alrt = document.getElementById(ControlLeader + "txtUnitSettingsAlertRecipients"); uus.value = sus.value + "_:_" + spdLimit.value + "_:_" + spdUnits.value + "_:_" + geo.value + "_:_" + alrt.value; __doPostBack(ControlLeader + 'fieldUpdateUnitSettings', 'OnValueChanged'); }
function ConvertDirection(heading) { if (heading == 0) { return "N"; } else if (heading == 360) { return "N"; } else if (heading == 45) { return "NE"; } else if (heading == 90) { return "E"; } else if (heading == 135) { return "SE"; } else if (heading == 180) { return "S"; } else if (heading == 225) { return "SW"; } else if (heading == 270) { return "W"; } else if (heading == 315) { return "NE"; } else if (heading < 45) { return "NNE"; } else if (heading < 90) { return "ENE"; } else if (heading < 135) { return "ESE"; } else if (heading < 180) { return "SSE"; } else if (heading < 225) { return "SSW"; } else if (heading < 270) { return "WSW"; } else if (heading < 315) { return "WNW"; } else if (heading < 360) { return "NNW"; } }
function SetMarkerOrder(marker, b) {
    var ret = 200;

    if (SelectedInfoWindow == marker.id) {
        ret = 500;
    }
    else if (SelectedUnit == marker.id) {
        ret = 400;
    }
    else if (marker.inrange) {
        ret = 300;
    }

    return ret;
}
function SetLandmarkMarkerOrder(marker, b) {
    return 100;
}
function ReverseGeocode(latitude, longitude) { Geocoder.getLocations(new GLatLng(latitude, longitude), GetAddressFromPoint); }
function UpdateUnit(guid, hsid, id, alias, geofence, infence, speedlimit, inrange, heading, speed, longitude, latitude, imageinfo, timestamp, pan) {
    if (map == null || UnitManager == null) {
        setTimeout("UpdateUnit('" + guid + "', '" + hsid + "', '" + id + "', '" + alias + "', '" + geofence + "', '" + infence + "', '" + speedlimit + "', '" + inrange + "', '" + heading + "', '" + speed + "', '" + longitude + "', '" + latitude + "', '" + imageinfo + "', '" + timestamp + "', " + pan + ")", 50);
        //UpdateUnit(guid, hsid, id, alias, geofence, infence, speedlimit, inrange, heading, speed, longitude, latitude, imageinfo, timestamp, pan);
        return;
    }

    if (pan > 0) {
        pan = true;
    }
    else {
        pan = false;
    }

    alias = alias.replace("%^%", "'");
    var imageDetails = imageinfo.split("_$_");
    var imageInfo = imageDetails[2].split("-");
    var imgOpacity = 100;
    if (inrange == "0") {
        imgOpacity = 25;
    }
    var unitIcon = new GIcon(G_DEFAULT_ICON);
    unitIcon.shadow = "";
    unitIcon.iconSize = new GSize(imageDetails[0], imageDetails[1]);
    unitIcon.iconAnchor = new GPoint(imageDetails[0] / 2, imageDetails[1] / 2);
    unitIcon.infoWindowAnchor = new GPoint(imageDetails[0] / 2, imageDetails[1] / 2);
    unitIcon.image = window.location.protocol + "//" + window.location.host + imageDetails[2];
    markerOptions = { icon: unitIcon, zIndexProcess: SetMarkerOrder };
    var position = new GLatLng(latitude, longitude);
    var marker = new GMarker(position, markerOptions);
    marker.id = guid;
    marker.alias = alias;
    marker.hsid = hsid;
    marker.min = id;
    marker.heading = heading;
    marker.image = window.location.protocol + "//" + window.location.host + imageDetails[2]; // imageInfo[1];
    marker.timestamp = timestamp;
    marker.position = position;
    marker.speed = speed;
    if (inrange == "0") {
        marker.inrange = false;
    }
    else {
        marker.inrange = true;
    }

    var div = document.createElement("div");
    div.id = "UNITLABEL-" + guid;

    var table = "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
    table += "<tr>";
    table += "<td>" + marker.alias + "</td>";
    table += "</tr>";
    table += "<tr>";
    table += "<td>" + ConvertDirection(marker.heading) + " @ " + marker.speed + "</td>";
    table += "</tr>";
    table += "</table>";

    div.innerHTML = marker.alias;
    div.innerHTML += "</br>";
    div.innerHTML += ConvertDirection(marker.heading) + " @ " + marker.speed;
    div.innerHTML = table;

    marker.labelDiv = div;

    var foundMarker = false;

    var markers = UnitManager.getMarkers();

    for (var i = 0; i < markers.length; i++) {
        if (markers[i].marker.id == guid) {
            foundMarker = true;
            if (position.lat() != 0 && position.lng() != 0) {
                markers[i].marker.alias = alias;
                markers[i].marker.hsid = hsid;
                markers[i].marker.min = id;
                markers[i].marker.heading = heading;
                markers[i].marker.timestamp = timestamp;
                if (markers[i].marker.position != position) {
                    markers[i].marker.setLatLng(position);
                }
                markers[i].marker.position = position;
                markers[i].marker.speed = speed;
                if (inrange == "0") {
                    markers[i].marker.inrange = false;
                }
                else {
                    markers[i].marker.inrange = true;
                }

                if (markers[i].marker.getIcon().image != marker.image) {
                    markers[i].marker.setImage(marker.image);
                }
                markers[i].marker.isUpdated = true;
                markers[i].marker.labelDiv = marker.labelDiv;
            }
        }
    }
    if (!foundMarker) {
        if (position.lat() != 0 && position.lng() != 0) {
            UnitManager.addMarker(marker);
        }
    }

    var selectwindow = SelectedInfoWindow;
    UnitUpdated = true;
    marker.address = "Latitude: " + marker.position.lat() + "<br />";
    marker.address += "Longitude: " + marker.position.lng();
    if (marker.position.lat() != 0 && marker.position.lng() != 0) {
        ReverseGeocode(marker.position.lat(), marker.position.lng());
    }
    if (selectwindow == marker.id) {
        var ihtml = marker.alias + " [" + marker.hsid + "-" + marker.min + "]<br />";
        ihtml += marker.timestamp + "<br />";
        ihtml += "Direction: " + ConvertDirection(marker.heading) + "<br />";
        ihtml += "Speed: " + marker.speed + "<br />";
        ihtml += "<br />";
        ihtml += "<span id='" + marker.id + "-addressinfo'>";
        ihtml += marker.address;
        ihtml += "</span>";
        map.openInfoWindowHtml(marker.position, ihtml, { noCloseOnClick: true, onCloseFn: function () { SelectedInfoWindow = null; } });
        SelectedInfoWindow = marker.id;
    }
    if (Report || pan) {
        if (position.lat() != 0 && position.lng() != 0) {
            Bounds.extend(position);
            var newzoom = map.getBoundsZoomLevel(Bounds);
            var newcenter = Bounds.getCenter();
            map.setCenter(newcenter, newzoom);
            map.savePosition();
        }
    }
    if (!Report) {
        GEvent.addListener(marker, "click", function () {
            if (SelectedInfoWindow != this.id) {
                var ihtml = this.alias + " [" + this.hsid + "-" + this.min + "]<br />";
                ihtml += this.timestamp + "<br />";
                ihtml += "Direction: " + ConvertDirection(this.heading) + "<br />";
                ihtml += "Speed: " + this.speed + "<br />";
                ihtml += "<br />";
                ihtml += "<span id='" + marker.id + "-addressinfo'>";
                ihtml += this.address;
                ihtml += "</span>";
                map.openInfoWindowHtml(this.position, ihtml, { noCloseOnClick: true, onCloseFn: function () { SelectedInfoWindow = null; } });
                SelectedInfoWindow = this.id;
                //UnitManager.removeMarker(this);
                //UnitManager.addMarker(this, 0);
            }
        });
        GEvent.addListener(marker, "dblclick", function (latlng) {
            if (latlng) {
                if (SelectedInfoWindow == this.id) {
                    map.closeInfoWindow();
                }
                map.zoomIn();
                map.setCenter(latlng);
            }
        });
        var chk = document.getElementById(ControlLeader + "chkFollowUnit");
        if (SelectedUnit == guid && chk.checked && !GeofenceMode) {
            PanToUnit(guid);
        }
        else {
            if (SelectedUnit == guid) {
                var lur = document.getElementById(ControlLeader + "cellUnitUpdate");
                if (position.lat() != 0 && position.lng() != 0) {
                    lur.innerHTML = timestamp;
                    lur.style.color = "";
                }
                else {
                    lur.innerHTML = "No Valid Report";
                    lur.style.color = "Salmon";
                }
            }
        }
        var unitsTable = document.getElementById(ControlLeader + "tblSubMenuUnits");
        var bodyTable = unitsTable.getElementsByTagName("tbody");
        var tableBody = document.createElement("tbody");
        if (bodyTable.length > 0) {
            tableBody = bodyTable[0];
        }
        var unitsRows = unitsTable.getElementsByTagName("tr");
        var found = false;
        for (var ii = 0; ii < unitsRows.length; ii++) {
            var rowId = unitsRows[ii].id.split("_");
            if (rowId[1] == guid) {
                found = true;
                var cells = unitsRows[ii].getElementsByTagName("td");
                cells[0].innerHTML = alias;
                var newImg = cells[1].getElementsByTagName("img");
                newImg[0].src = unitIcon.image;
                newImg[0].style.filter = "alpha(opacity=" + imgOpacity + ")";
                newImg[0].style.opacity = imgOpacity / 100;
                var geoImage = cells[2].getElementsByTagName("img");
                if (geoImage.length > 0) {
                    if (geofence == 0) {
                        cells[2].removeChild(geoImage[0]);
                    }
                }
                else {
                    if (geofence > 0) {
                        var geofenceImage = document.createElement("img");
                        geofenceImage.src = "/images/geofence.png";
                        cells[2].appendChild(geofenceImage);
                    }
                }
                var speedImage = cells[3].getElementsByTagName("img");
                if (speedImage.length > 0) {
                    if (speedlimit == 0) {
                        cells[3].removeChild(speedImage[0]);
                    }
                }
                else {
                    if (speedlimit > 0) {
                        var speedlimitImage = document.createElement("img");
                        speedlimitImage.src = "/images/speedlimit.png";
                        cells[3].appendChild(speedlimitImage);
                    }
                }
            }
        }
        if (!found) {
            var row = document.createElement("tr");
            row.id = "UNITROW_" + guid;
            row.className = "UnitListRow";
            var aliasCell = document.createElement("td");
            aliasCell.id = guid;
            aliasCell.className = "UnitListAliasCell";
            aliasCell.innerHTML = alias.replace("&", "&amp;");
            aliasCell.onclick = function () { SelectUnit(this); };
            var vehicleimageCell = document.createElement("td");
            vehicleimageCell.onclick = function () { SelectUnit(aliasCell) };
            vehicleimageCell.className = "UnitListVehicleImageCell";
            var vehicleimageImage = document.createElement("img");
            vehicleimageImage.src = unitIcon.image;
            vehicleimageImage.style.filter = "alpha(opacity=" + imgOpacity + ")";
            vehicleimageImage.style.opacity = imgOpacity / 100;
            vehicleimageCell.appendChild(vehicleimageImage);
            var geofenceCell = document.createElement("td");
            geofenceCell.onclick = function () { SelectUnit(aliasCell) };
            if (geofence > 0) {
                var geofenceImage = document.createElement("img");
                geofenceImage.src = "/images/geofence.png";
                geofenceCell.appendChild(geofenceImage);
            }
            geofenceCell.className = "UnitListGeofenceCell";
            var speedlimitCell = document.createElement("td");
            speedlimitCell.onclick = function () { SelectUnit(aliasCell) };
            if (speedlimit > 0) {
                var speedlimitImage = document.createElement("img");
                speedlimitImage.src = "/images/speedlimit.png";
                speedlimitCell.appendChild(speedlimitImage);
            }
            speedlimitCell.className = "UnitListSpeedLimitCell";
            var infoCell = document.createElement("td");
            infoCell.className = "UnitListInfoCell";
            //infoCell.innerHTML = "Alert Message Here";
            row.appendChild(aliasCell);
            row.appendChild(vehicleimageCell);
            row.appendChild(geofenceCell);
            row.appendChild(speedlimitCell);
            row.appendChild(infoCell);
            tableBody.appendChild(row);
        }
        if (bodyTable.length == 0) {
            unitsTable.appendChild(tableBody);
        }
        UpdateDropdownOption(ControlLeader + "ddlUnitSettingsUnits", alias, guid);
        var sel = document.getElementById(ControlLeader + "ddlUnitSettingsUnits");
        var selu = document.getElementById(ControlLeader + "fieldShowUnitSettings");
        if (selu.value == "") {
            EditUnit(sel);
        }
    }
}
function UpdateUnitIcons() {
    var markers = UnitManager.getMarkers();
    for (var i = 0; i < markers.length; i++) {
        markers[i].setImage(markers[i].icon);
    }
}
function PanTo(latitude, longitude) { TrackPan = new GLatLng(latitude, longitude); map.panTo(new GLatLng(latitude, longitude)); }
function UpdateFleetUnits(fleetInfo) {
    if (map == null) {
        setTimeout("UpdateFleetUnits('" + fleetInfo + "')", 25);
        return;
    }
    FleetReport = true;
    var fleetData = fleetInfo.split("_!_");
    for (var f = 0; f < fleetData.length; f++) {
        var unitInfo = fleetData[f].split("_#_");
        var tempArray = new Array();
        for (var i = 0; i < unitInfo.length; i++) {
            if (unitInfo[i] != "") {
                var unitDetails = unitInfo[i].split("_^_");
                var unitPosition = unitDetails[1].split(",");
                var imageDetails = unitDetails[2].split("_$_");
                var unitIcon = new GIcon(G_DEFAULT_ICON);
                unitIcon.shadow = "";
                unitIcon.iconSize = new GSize(imageDetails[0], imageDetails[1]);
                unitIcon.iconAnchor = new GPoint(imageDetails[0] / 2, imageDetails[1] / 2);
                unitIcon.infoWindowAnchor = new GPoint(imageDetails[0] / 2, imageDetails[1] / 2);
                unitIcon.image = window.location.protocol + "//" + window.location.host + imageDetails[2].replace("markers/", "markers/transparent-");
                markerOptions = { icon: unitIcon };
                var position = new GLatLng(unitPosition[0], unitPosition[1]);
                var marker = new GMarker(position, markerOptions);
                marker.id = unitDetails[0];
                marker.image = window.location.protocol + "//" + window.location.host + imageDetails[2];
                marker.position = position;
                var foundMarker = false;
                tempArray.push(marker);
                GEvent.addListener(marker, "mouseover", function () {
                    this.setImage(this.image);
                });
                GEvent.addListener(marker, "mouseout", function () {
                    if ((this.id - 1) != SelectedUnit) {
                        this.setImage(this.image.replace("markers/", "markers/transparent-"));
                    }
                });
                Bounds.extend(position);
            }
        }
        UnitMarkers.push(tempArray);
        var newzoom = map.getBoundsZoomLevel(Bounds);
        var newcenter = Bounds.getCenter();
        map.setCenter(newcenter, newzoom);
        map.savePosition();
    }
}
function UpdateUnitsBatch(args) {
    if (map == null || UnitManager == null) {
        setTimeout("UpdateUnitsBatch('" + args + "');", 25);
        return;
    }

    var splitGroups = args.split("@@@@@");

    for (var i = 0; i < splitGroups.length; i++) {
        var splitArgs = splitGroups[i].split("^$^");

        var ii = 0;

        if (splitArgs.length > 1) {
            UpdateUnit(splitArgs[ii], splitArgs[++ii], splitArgs[++ii], splitArgs[++ii], splitArgs[++ii], splitArgs[++ii], splitArgs[++ii], splitArgs[++ii], splitArgs[++ii], splitArgs[++ii], splitArgs[++ii], splitArgs[++ii], splitArgs[++ii], splitArgs[++ii], splitArgs[++ii]);
        }

        ii = null;

        splitArgs = null;
    }

    splitGroups = null;
}
function UpdateLandmarksBatch(args) {
    if (map == null) {
        setTimeout("UpdateLandmarksBatch('" + args + "');", 25);
        return;
    }

    var splitGroups = args.split("@@@@@");

    for (var i = 0; i < splitGroups.length; i++) {
        var splitArgs = splitGroups[i].split("^$^");

        var ii = 0;

        if (splitArgs.length > 1) {
            UpdateLandmark(splitArgs[ii], splitArgs[++ii], splitArgs[++ii], splitArgs[++ii], splitArgs[++ii], 0);
        }

        ii = null;

        splitArgs = null;
    }

    splitGroups = null;
}
function UpdateGeofencesBatch(args) {
    if (map == null) {
        setTimeout("UpdateGeofencesBatch('" + args + "');", 25);
        return;
    }

    var splitGroups = args.split("@@@@@");

    for (var i = 0; i < splitGroups.length; i++) {
        var splitArgs = splitGroups[i].split("^$^");

        var ii = 0;

        if (splitArgs.length > 1) {
            UpdateGeofence(splitArgs[ii], splitArgs[++ii]);
        }

        ii = null;

        splitArgs = null;
    }

    splitGroups = null;
}
function UpdateUnits(unitsInfo) {
    if (map == null) {
        setTimeout("UpdateUnits('" + unitsInfo + "')", 25);
        return;
    } var unitInfo = unitsInfo.split("_#_");
    for (var i = 0; i < unitInfo.length; i++) {
        var unitDetails = unitInfo[i].split("_^_");
        var unitPosition = unitDetails[1].split(",");
        var imageDetails = unitDetails[2].split("_$_");
        var unitIcon = new GIcon(G_DEFAULT_ICON);
        unitIcon.shadow = "";
        unitIcon.iconSize = new GSize(imageDetails[0], imageDetails[1]);
        unitIcon.iconAnchor = new GPoint(imageDetails[0] / 2, imageDetails[1] / 2);
        unitIcon.infoWindowAnchor = new GPoint(imageDetails[0] / 2, imageDetails[1] / 2);
        unitIcon.image = window.location.protocol + "//" + window.location.host + imageDetails[2].replace("markers/", "markers/transparent-");
        markerOptions = { icon: unitIcon };
        var position = new GLatLng(unitPosition[0], unitPosition[1]);
        var marker = new GMarker(position, markerOptions);
        marker.hsid = unitDetails[3];
        marker.min = unitDetails[4];
        marker.alias = unitDetails[5];
        marker.heading = unitDetails[6];
        marker.timestamp = unitDetails[7];
        marker.id = unitDetails[0];
        marker.image = imageDetails[2];
        marker.position = position;
        marker.infoDiv = "Point: " + marker.id + "<br />";
        marker.infoDiv += marker.alias + " [" + marker.hsid + "-" + marker.min + "]<br />";
        marker.infoDiv += marker.timestamp + "<br />";
        marker.infoDiv += "Direction: " + ConvertDirection(marker.heading) + "<br />";
        marker.infoDiv += "<br />";
        marker.infoDiv += "<span id='" + marker.id + "-addressinfo'>";
        marker.infoDiv += "</span>";
        var foundMarker = false;
        //UnitMarkers.push(marker);
        UnitManager.addMarker(marker);
        GEvent.addListener(marker, "click", function () {
            var el = document.getElementById(ControlLeader + "gridReport");
            var className = "ReportDisplayAlternatingRowStyle";
            for (var ii = 1; ii < el.rows.length; ii++) {
                el.rows[ii].className = className;
                if (className == "ReportDisplayRowStyle") {
                    className = "ReportDisplayAlternatingRowStyle";
                }
                else {
                    className = "ReportDisplayRowStyle";
                }
                el.rows[ii].className = className;
                var cols = el.rows[ii].getElementsByTagName("TD");
                if (cols[0].innerHTML == this.id) {
                    el.rows[ii].className = "ReportDisplaySelectedRowStyle";
                }
            }
            SelectPoint(this.id);
        });
        /*
        GEvent.addListener(marker, "mouseover", function() {
        this.setImage(this.image);
        });
        GEvent.addListener(marker, "mouseout", function() {
        if ((this.id - 1) != SelectedUnit) {
        this.setImage(this.image.replace("markers/", "markers/transparent-"));
        }
        });
        */
        Bounds.extend(position);
    }
    //UnitManager.addMarkers(UnitMarkers, 0);
    var newzoom = map.getBoundsZoomLevel(Bounds);
    var newcenter = Bounds.getCenter();
    map.setCenter(newcenter, newzoom);
    map.savePosition();
    //UnitManager.resetViewport(true);
}
function RemoveLandmark(guid) { if (map == null) { setTimeout("RemoveLandmark('" + guid + "')", 50); return; } var removeId; for (var i = LandmarkMarkers.length - 1; i >= 0; i--) { if (LandmarkMarkers[i].id == guid) { removeId = i; LandmarkManager.removeMarker(LandmarkMarkers[i]); var sel = document.getElementById(ControlLeader + "ddlLandmarks"); for (var ii = sel.options.length - 1; ii >= 0; ii--) { var found = false; if (sel.options[ii] != null) { if (sel.options[ii].value == guid) { found = true; } } if (found) { sel.remove(ii); } } } } if (removeId != null) { LandmarkMarkers.splice(removeId, 1); } }
function UpdateLandmark(guid, alias, description, longitude, latitude, pan) {
    if (map == null) {
        setTimeout("UpdateLandmark(\"" + guid + "\", \"" + alias + "\", \"" + description + "\", \"" + longitude + "\", \"" + latitude + "\", " + pan + ")", 50);
        return;
    }
    if (pan > 0) {
        pan = true;
    }
    else {
        pan = false;
    }
    alias = alias.replace("%^%", "'");
    var position = new GLatLng(latitude, longitude);
    markerOptions = { zIndexProcess: SetLandmarkMarkerOrder };
    var marker = new GMarker(position, markerOptions);
    marker.id = guid;
    marker.alias = alias;
    marker.position = position;
    marker.address = "Latitude: " + latitude + "<br />";
    marker.address += "Longitude: " + longitude + "<br />";
    if (marker.position.lat() != 0 && marker.position.lng() != 0) {
        ReverseGeocode(marker.position.lat(), marker.position.lng());
    }
    var foundMarker = false;
    for (var i = 0; i < LandmarkMarkers.length; i++) {
        if (LandmarkMarkers[i].id == guid) {
            foundMarker = true;
            LandmarkMarkers[i].alias = alias;
            LandmarkMarkers[i].position = position;
            LandmarkMarkers[i].setLatLng(position);
        }
    }
    if (!foundMarker) {
        LandmarkMarkers.push(marker);
        LandmarkManager.addMarker(marker, 0);
    }
    GEvent.addListener(marker, "click", function (latlng) {
        if (latlng) {
            var ihtml = marker.alias + "<br />";
            ihtml += "<br />";
            ihtml += "<span id='" + marker.id + "-addressinfo'>";
            ihtml += marker.address; ihtml += "</span>";
            map.openInfoWindowHtml(this.position, ihtml,
             { pixelOffset: new GSize(0, -20)
             });
        }
    });
    GEvent.addListener(marker, "dblclick", function (latlng) {
        if (latlng) {
            map.zoomIn(); map.setCenter(latlng);
        }
    });
    UpdateDropdownOption(ControlLeader + "ddlLandmarks", alias, guid);
    var sel = document.getElementById(ControlLeader + "ddlLandmarks");
}
function LandmarkSaved(heading, text, button, timestamp) { ShowAlert(heading, text, button); UpdateMap(timestamp); }
function LandmarkDeleted(heading, text, button, timestamp) { ShowAlert(heading, text, button); UpdateMap(timestamp); }
function GotoAddressFail(heading, text, button, timestamp) { ShowAlert(heading, text, button); UpdateMap(timestamp); }
function GotoAddress() {
    var street = document.getElementById(ControlLeader + "txtLocationsAddress");
    var city = document.getElementById(ControlLeader + "txtLocationsCity");
    var country = document.getElementById(ControlLeader + "ddlLocationsCountry");
    var state = document.getElementById(ControlLeader + "ddlLocationsState");
    var zip = document.getElementById(ControlLeader + "txtLocationsZip");

    var address = street.value + ", " + city.value + "," + ((country.value == "US") ? (state.value + " ") : " ") + zip.value + ", " + country.value;
    Geocoder.getLocations(address, addAddressToMap);
}
function addAddressToMap(response) {
    if (!response || response.Status.code != 200) {
        ShowAlert("FAILURE!", "Unable to locate address provided.  Please try again.", "OK");
    }
    else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
        if (AddressMarker != null) {
            map.removeOverlay(AddressMarker);
        }
        AddressMarker = new GMarker(point);
        map.addOverlay(AddressMarker);
        var address = "";
        if (place.AddressDetails.Country == null) {
            address = place.address;
        }
        else {
            var adminarea = place.AddressDetails.Country.AdministrativeArea;
            if (adminarea != null) {
                if (adminarea.Locality != null) {
                    if (adminarea.Locality.Thoroughfare != null) {
                        address += adminarea.Locality.Thoroughfare.ThoroughfareName + "<br />";
                    }
                    address += " " + adminarea.Locality.LocalityName + ",";
                    address += " " + adminarea.AdministrativeAreaName;
                    if (adminarea.Locality != null) {
                        if (adminarea.Locality.PostalCode != null) {
                            address += "  " + adminarea.Locality.PostalCode.PostalCodeNumber;
                        }
                    }
                }
                else {
                    address = place.address;
                }
            }
        }
        var elAddy = document.getElementById(ControlLeader + "txtLocationsAddress");
        var whtml = "<input id=\"hiddenLandmarkLocation\" type=\"hidden\" value=\"" + place.Point.coordinates[1] + "_:_" + place.Point.coordinates[0] + "\">";
        whtml += "<input id=\"hiddenLandmarkDescription\" type=\"hidden\" value=\"" + address + "\">";
        whtml += "<input id=\"txtLandmarkName\" type=\"text\" value=\"" + ((elAddy.value == "") ? "Landmark Name" : elAddy.value) + "\" maxlength=\"20\">";
        whtml += "<br />";
        whtml += "<input type=\"submit\" class=\"MenuButton\" value=\"Save Landmark\" onclick=\"SaveLandmark(); return false;\">";
        whtml += "<br />";
        whtml += "<br />";
        whtml += address;
        whtml += "<br />";
        whtml += "<br />";
        whtml += "Nearest Units:<br />";
        var unitDist = new Array();
        var markers = UnitManager.getMarkers();
        for (var i = 0; i < markers.length; i++) {
            unitDist.push({ Marker: markers[i].marker });
        }

        for (var ii = 0; ii < unitDist.length; ii++) {
            if (unitDist[ii].Marker.getLatLng().lat() != 0 && unitDist[ii].Marker.getLatLng().lng() != 0) {
                unitDist[ii].crowDist = unitDist[ii].Marker.getLatLng().distanceFrom(point);
            }
            else {
                unitDist[ii].crowDist = 12345678901234567890;
            }
        }

        unitDist.sort(function (a, b) { return (a.crowDist - b.crowDist) });

        for (var iii = 0; iii < unitDist.length; iii++) {
            if (iii < 3) {
                whtml += unitDist[iii].Marker.alias + " [" + unitDist[iii].Marker.hsid + "-" + unitDist[iii].Marker.min + "]: " + (unitDist[iii].crowDist * 0.000621371192).toFixed(3) + " miles";
                whtml += "<br />";
            }
            else {
                break;
            }
        }

        MoveListener = GEvent.bind(map, "moveend", this, function () {
            AddressMarker.openInfoWindowHtml(whtml);
            GEvent.removeListener(MoveListener)
        });
        map.panTo(point);
    }
}
function ShowAlert(heading, text, button) { var hed = document.getElementById(ControlLeader + "lblAlertHeading"); var txt = document.getElementById(ControlLeader + "lblAlertText"); var btn = document.getElementById(ControlLeader + "btnAlert"); hed.innerHTML = heading; txt.innerHTML = text; btn.value = button; var alt = document.getElementById(ControlLeader + "pnlAlert"); if (alt != null) { alt.style.visibility = "visible"; } $find("AlertPopup").show(); btn.focus(); }
function SaveLandmark() { var loc = document.getElementById("hiddenLandmarkLocation"); var des = document.getElementById("hiddenLandmarkDescription"); var name = document.getElementById("txtLandmarkName"); var el = document.getElementById(ControlLeader + "fieldSaveLandmark"); el.value = loc.value + "_:_" + name.value + "_:_" + des.value; __doPostBack(ControlLeader + 'fieldSaveLandmark', 'OnValueChanged'); }
function DeleteLandmark() { var ddl = document.getElementById(ControlLeader + "ddlLandmarks"); var el = document.getElementById(ControlLeader + "fieldDeleteLandmark"); el.value = ddl.value; __doPostBack(ControlLeader + 'fieldDeleteLandmark', 'OnValueChanged'); }
function SavedLandmark(heading, text, button) { ShowAlert(heading, text, button); if (heading.indexOf("SUCCESS") != -1) { if (AddressMarker != null) { map.removeOverlay(AddressMarker); } map.closeInfoWindow(); } }
function UpdateDropdownOption(dropdown, text, value) { var sel = document.getElementById(dropdown); var found = false; for (var i = 0; i < sel.options.length; i++) { if (sel.options[i].value == value) { sel.options[i].text = text; found = true; break; } } if (!found) { var optn = document.createElement("OPTION"); optn.text = text; optn.value = value; sel.options.add(optn); } }
function RemoveGeofence(guid) { var sel = document.getElementById(ControlLeader + "ddlUnitSettingsGeofence"); var el = document.getElementById(ControlLeader + "ddlGeofenceList"); for (var i = sel.options.length - 1; i >= 0; i--) { var found = false; if (sel.options[i] != null) { if (sel.options[i].value == guid) { found = true; } } if (found) { sel.remove(i); } } var isSelected = false; for (var i = el.options.length - 1; i >= 0; i--) { var found = false; if (el.options[i] != null) { if (el.options[i].value == guid) { isSelected = el.options[i].selected; found = true; } } if (found) { el.remove(i); } } if (isSelected) { DisplayGeofence(); } }
function UpdateGeofence(guid, alias) {alias = alias.replace("%^%", "'");  UpdateDropdownOption(ControlLeader + "ddlUnitSettingsGeofence", alias, guid); UpdateDropdownOption(ControlLeader + "ddlGeofenceList", alias, guid); }
function DeleteGeofencePrompt() { var el = document.getElementById(ControlLeader + "ddlGeofenceList"); var geoName = ""; var geoGuid = ""; for (var i = 0; i < el.options.length; i++) { if (el.options[i].selected) { geoGuid = el.options[i].value; geoName = el.options[i].text; break; } } ShowConfirmation("CONFIRM", "Are you sure you want to delete the geofence: " + geoName, "Yes", "No", function () { DeleteGeofence(geoGuid); return false; }); }
function DeleteGeofence(guid) { var el = document.getElementById(ControlLeader + "fieldDeleteGeofence"); el.value = guid; __doPostBack(ControlLeader + 'fieldDeleteGeofence', 'OnValueChanged'); $find("ConfirmationPopup").hide(); }
function DeletedGeofence(heading, text, button) { ShowAlert(heading, text, button); }
function ShowConfirmation(heading, text, yesbutton, nobutton, yesaction) { var lblHead = document.getElementById(ControlLeader + "lblConfirmationHeading"); var lblText = document.getElementById(ControlLeader + "lblConfirmationText"); var btnYes = document.getElementById(ControlLeader + "btnConfirmationYes"); var btnNo = document.getElementById(ControlLeader + "btnConfirmationNo"); lblHead.innerHTML = heading; lblText.innerHTML = text; btnYes.value = yesbutton; btnYes.onclick = yesaction; btnNo.value = nobutton; var alt = document.getElementById(ControlLeader + "pnlConfirmation"); if (alt != null) alt.style.visibility = "visible"; $find("ConfirmationPopup").show(); }
function SaveGeofence() { var gn = document.getElementById(ControlLeader + "txtGeofenceName"); if (!Geofence.complete) { ShowAlert("INFORMATION!", "You must complete drawing the geofence.  Please try again.", "OK"); return; } var tmp = gn.value; while (tmp.indexOf(" ") != -1) { tmp = tmp.replace(" ", ""); } if (tmp == "") { ShowAlert("INFORMATION!", "You must specify a name for the geofence.  Please try again.", "OK"); return; } var test = Geofence.id; test += "_$_"; test += gn.value; test += "_$_"; for (var i = 0; i < Geofence.getVertexCount() - 1; i++) { if (i > 0) { test += "_^_"; } test += Geofence.getVertex(i).lat() + "," + Geofence.getVertex(i).lng(); } var sg = document.getElementById(ControlLeader + "fieldSaveGeofence"); sg.value = test; __doPostBack(ControlLeader + "fieldSaveGeofence", "OnValueChanged"); }
function SavedGeofence(guid, heading, text, button, update) { ShowAlert(heading, text, button); var el = document.getElementById(ControlLeader + "ddlGeofenceList"); for (var i = 0; i < el.options.length; i++) { if (el.options[i].value == guid) { el.options[i].selected = true; break; } } if (update == "true") { var gi = document.getElementById(ControlLeader + "tblMapSubMenuGeofenceInfo"); gi.style.visibility = "visible"; } else { DisplayGeofence(); } }
function RevertGeofence() { if (Geofence != null) { Geofence.disableEditing(); map.removeOverlay(Geofence); } if (BaseGeofence != null) { var latlonArray = new Array(); for (var i = 0; i < BaseGeofence.getVertexCount(); i++) { latlonArray.push(BaseGeofence.getVertex(i)); } Geofence = new GPolygon(latlonArray, "#0000FF", 1, 0.75, "#0000FF", 0.25); Geofence.id = BaseGeofence.id; Geofence.complete = true; Geofence.alias = BaseGeofence.alias; GEvent.addListener(Geofence, "mouseover", function () { Geofence.enableEditing(); }); GEvent.addListener(Geofence, "mouseout", function () { Geofence.disableEditing(); }); GEvent.addListener(Geofence, "click", function (latlng, index) { if (typeof index == "number") { Geofence.deleteVertex(index); } }); var gr = document.getElementById(ControlLeader + "btnRevertGeofence"); gr.value = "Revert"; var gn = document.getElementById(ControlLeader + "txtGeofenceName"); gn.value = Geofence.alias; map.addOverlay(Geofence); } else { var sv = document.getElementById(ControlLeader + "btnSaveGeofence"); sv.style.visibility = "hidden"; var gfr = document.getElementById(ControlLeader + "btnRevertGeofence"); gfr.value = "Revert"; gfr.style.visibility = "hidden"; var gfn = document.getElementById(ControlLeader + "txtGeofenceName"); gfn.value = ""; gfn.style.visibility = "hidden"; var gfd = document.getElementById(ControlLeader + "btnDeleteGeofence"); gfd.style.visibility = "hidden"; } }
function ShowGeofence(guid, alias, points) { if (map == null) { setTimeout("ShowGeofence(\"" + guid + "\", \"" + alias + "\", \"" + points + "\")", 25); return; } else { var areas = points.split("_&_"); for (var ii = 0; ii < areas.length; ii++) { var point = areas[ii].split("_^_"); if (point.length > 0) { var latlonArray = new Array(); if (Geofence != null) { map.removeOverlay(Geofence); } var bounds = new GLatLngBounds(); for (var i = 0; i < point.length; i++) { var position = point[i].split(","); var thisPoint = new GLatLng(position[0], position[1]); latlonArray.push(thisPoint); if (i != (point.length - 1)) { if (!Report) { bounds.extend(thisPoint); } else { Bounds.extend(thisPoint); } } } if (!Report) { var newzoom = map.getBoundsZoomLevel(bounds); var newcenter = bounds.getCenter(); map.setCenter(newcenter, newzoom); } else { var newzoom = map.getBoundsZoomLevel(Bounds); var newcenter = Bounds.getCenter(); map.setCenter(newcenter, newzoom); } var firstGeofence = false; if (Geofence == null) { firstGeofence = true; } if (!firstGeofence) { Geofence.disableEditing(); map.removeOverlay(Geofence); } BaseGeofence = new GPolygon(latlonArray, "#0000FF", 1, .75, "#0000FF", 0.25); Geofence = new GPolygon(latlonArray, "#0000FF", 1, .75, "#0000FF", 0.25); if (!Report) { GEvent.addListener(Geofence, "mouseover", function () { Geofence.enableEditing(); }); GEvent.addListener(Geofence, "mouseout", function () { Geofence.disableEditing(); }); GEvent.addListener(Geofence, "click", function (latlng, index) { if (typeof index == "number") { Geofence.deleteVertex(index); } }); } BaseGeofence.id = guid; BaseGeofence.alias = alias; Geofence.id = guid; Geofence.alias = alias; Geofence.complete = true; map.addOverlay(Geofence); if (!Report) { var gr = document.getElementById(ControlLeader + "btnRevertGeofence"); gr.value = "Revert"; var gd = document.getElementById(ControlLeader + "btnDeleteGeofence"); gd.style.visibility = "visible"; var gn = document.getElementById(ControlLeader + "txtGeofenceName"); gn.value = Geofence.alias; var gi = document.getElementById(ControlLeader + "tblMapSubMenuGeofenceInfo"); gi.style.visibility = "visible"; var el = document.getElementById(ControlLeader + "ddlGeofenceList"); for (var i = 0; i < el.options.length; i++) { if (el.options[i].value == guid) { el.options[i].selected = true; break; } } } } } } }
function DisplayGeofence() { var el = document.getElementById(ControlLeader + "ddlGeofenceList"); if (el.value != "") { var gi = document.getElementById(ControlLeader + "tblMapSubMenuGeofenceInfo"); var sg = document.getElementById(ControlLeader + "fieldShowGeofence"); gi.style.visibility = "hidden"; for (var i = 0; i < el.options.length; i++) { if (el.options[i].selected) { sg.value = el.options[i].value; break; } } __doPostBack(ControlLeader + "fieldShowGeofence", "OnValueChanged"); } else { var msg = document.getElementById(ControlLeader + "tblMapSubMenuGeofenceInfo"); msg.style.visibility = "hidden"; if (Geofence != null) { Geofence.disableEditing(); map.removeOverlay(Geofence); } } }
function ModifyGeofence() { var eg = document.getElementById("EditGeofence"); var sg = document.getElementById("SelectedGeofence"); eg.value = ""; eg.value = sg.value; __doPostBack('EditGeofence', 'OnValueChanged'); }
function MapClicked() { if (!GeofenceMode) { ShowHideMenus(); } }
function SetTrackMode(el) { if (el.checked) { if (SelectedUnit != null) { map.disableDragging(); PanToUnit(SelectedUnit); } } else { map.enableDragging(); } }
function SetMapSize(el) { var dimensions = el.id.split("x"); set_cookie('MapSize', el.id.replace(ControlLeader + "rdo", "")); SizeMap(); }
function SizeMap() {
    if (map == null) {
        setTimeout("SizeMap()", 10);
        return;
    }
    var size = get_cookie("MapSize");
    if (Report) {
        size = "468x538";
    }
    if (size == null) {
        set_cookie("MapSize", "1236x617");
        setTimeout("SizeMap();", 10);
        return;
    }
    var chk = document.getElementById(ControlLeader + "rdo" + size);
    if (chk != null) {
        chk.checked = true;
    }
    var mapdiv = document.getElementById(ControlLeader + "pnlMapContainer");
    var trafficdiv = document.getElementById(ControlLeader + "pnlToggleTraffic");
    var mapinfo = document.getElementById(ControlLeader + "pnlMapInfo");
    var dimensions = size.split("x");
    var mapmove = false;
    var resize = false;
    var justHeight = false;
    if (mapcanvas.style.top != "0px") {
        mapcanvas.style.top = "0px";
        mapmove = true;
    }
    if (mapcanvas.style.width != dimensions[0] + "px" && mapcanvas.style.height != dimensions[1] + "px") {
        resize = true;
    }
    else if (mapcanvas.style.width == dimensions[0] + "px" && mapcanvas.style.height != dimensions[1] + "px") {
        justHeight = true;
    }
    mapcanvas.style.width = dimensions[0] + "px";
    mapcanvas.style.height = dimensions[1] + "px";
    mapwidth = dimensions[0];
    mapheight = dimensions[1];
    if (trafficdiv != null) {
        trafficdiv.style.left = mapwidth - 300;
    }
    if (mapdiv != null) { mapdiv.style.height = dimensions[1] + "px"; }
    var top = parseInt(dimensions[1]);
    top += 5;
    if (mapinfo != null) {
        mapinfo.style.top = top + "px";
    }
    var center = map.getCenter();
    map.checkResize();
    /* map.panTo(center); */
    if (!Report) {
        if (!justHeight) {
        }
    }
}

function CheckMapResize() {
    if (map == null) {
        setTimeout("SizeMap()", 10);
        return;
    }

    if (map.checkResize()) {
    }
}

function HideAllUnits() {
    if (map == null) {
        setTimeout("HideAllUnits()", 25);
        return;
    }
    if (!FleetReport) {
        var markers = UnitManager.getMarkers();
        for (var i = 0; i < markers.length; i++) {
            markers[i].hide();
            markers[i].closeInfoWindow();
        }
        var el = document.getElementById(ControlLeader + "gridReport");
        var className = "ReportDisplayRowStyle";
        for (var i = 1; i < el.rows.length; i++) {
            el.rows[i].className = className;
            if (className == "ReportDisplayRowStyle") {
                className = "ReportDisplayAlternatingRowStyle";
            }
            else {
                className = "ReportDisplayRowStyle";
            }
        }
        SelectedUnit = null;
    }
}
function ShowAllUnits() {
    if (map == null) { setTimeout("ShowAllUnits()", 25); return; } if (!FleetReport) {
        var el = document.getElementById(ControlLeader + "gridReport"); var className = "ReportDisplayRowStyle"; for (var i = 1; i < el.rows.length; i++) { el.rows[i].className = className; if (className == "ReportDisplayRowStyle") { className = "ReportDisplayAlternatingRowStyle"; } else { className = "ReportDisplayRowStyle"; } } SelectedUnit = null;
        MoveListener = GEvent.bind(map, "moveend", this, function () {
            var markers = UnitManager.getMarkers();
            for (var i = 0; i < markers.length; i++) {
                markers[i].closeInfoWindow();
            }

            markers = null;

            var infoWindow = map.getInfoWindow();

            infoWindow.hide();

            GEvent.removeListener(MoveListener)
        });
        map.returnToSavedPosition();
    }
}
function get_cookie(cookie_name) { var results = document.cookie.match(cookie_name + '=(.*?)(;|$)'); if (results) { return (unescape(results[1])); } else { return null; } }
function set_cookie(name, value) { var cookie_string = name + "=" + escape(value); var expires = new Date(2099, 12, 31); cookie_string += "; expires=" + expires.toGMTString(); cookie_string += "; path=/"; document.cookie = cookie_string; }
function ShowHideMenus(auto, open) {
    if (map == null) {
        setTimeout("ShowHideMenus('" + auto + "', '" + open + "')", 25);
        return;
    }
    if (AddressMarker != null) {
        map.removeOverlay(AddressMarker);
    }
    var menuOpen = false;
    var subMenu = document.getElementById(ControlLeader + "pnlSubMenu");
    if (subMenu != null) {
        if (auto || open) {
            subMenu.style.visibility = "visible";
            subMenu.style.display = "block";
        }
        else {
            subMenu.style.visibility = "hidden"; subMenu.style.display = "none";
        }
    }
    var sgf = document.getElementById(ControlLeader + "fieldShowGeofence");
    var gfl = document.getElementById(ControlLeader + "ddlGeofenceList");
    if (sgf != null) {
        var selGeo = sgf.value;
    }
    if (gfl != null) {
        for (var i = 0; i < gfl.options.length; i++) {
            if (gfl.options[i].selected) {
                selGeo = gfl.options[i].value;
            }
        }
    }
    for (var i = 0; i < Menus.length; i++) {
        if (Menus[i] != null) {
            var autoMenu = false;
            var openMenu = false;
            var ii = 0;
            if (auto != null) {
                for (ii = 0; ii < auto.length; ii++) {
                    if (Menus[i].Extender == auto[ii]) {
                        autoMenu = true;
                        break;
                    }
                }
            }
            if (open != null) {
                for (ii = 0; ii < open.length; ii++) {
                    if (Menus[i].Extender == open[ii]) {
                        openMenu = true;
                        break;
                    }
                }
            }
            if (autoMenu) {
                if (Menus[i].Open) {
                    if (document.getElementById(Menus[i].Extender) != null) {
                        document.getElementById(Menus[i].Extender).style.visibility = "hidden";
                    }
                    Menus[i].Open = false;
                    if (Menus[i].Extender == ControlLeader + "pnlSubMenuGeofence") {
                        if (sgf.value != "00000000-0000-0000-0000-000000000000") {
                            sgf.value = "00000000-0000-0000-0000-000000000000";
                        }
                        GeofenceMode = false;
                        SizeMap();
                        DisplayGeofence();
                        if (Geofence != null) {
                            map.removeOverlay(Geofence);
                        }
                    }
                }
                else {
                    if (document.getElementById(Menus[i].Extender) != null) {
                        document.getElementById(Menus[i].Extender).style.visibility = "visible";
                    }
                    Menus[i].Open = true;
                    if (Menus[i].Extender != ControlLeader + "pnlSubMenuUnits" && Menus[i].Extender != ControlLeader + "pnlSubMenuUnitsTable" && Menus[i].Extender != ControlLeader + "pnlSubMenuMapSettings") {
                        menuOpen = true;
                    }
                    if (Menus[i].Extender == ControlLeader + "pnlSubMenuMapSettingsTimeZone") {
                        mapcanvas.style.top = "59px";
                        mapcanvas.style.height = (mapheight - 59) + "px";
                        map.checkResize();
                    }
                    if (Menus[i].Extender == ControlLeader + "pnlSubMenuUnitSettings") {
                        mapcanvas.style.top = "89px";
                        mapcanvas.style.height = (mapheight - 89) + "px";
                        map.checkResize();
                    }
                    if (Menus[i].Extender == ControlLeader + "pnlSubMenuLocations") {
                        mapcanvas.style.top = "59px";
                        mapcanvas.style.height = (mapheight - 59) + "px";
                        map.checkResize();
                    }
                    if (Menus[i].Extender == ControlLeader + "pnlSubMenuGeofence") {
                        GeofenceMode = true;
                        mapcanvas.style.top = "59px";
                        mapcanvas.style.height = (mapheight - 59) + "px";
                        map.checkResize();
                        map.enableDragging();
                        if (sgf.value == "00000000-0000-0000-0000-000000000000") {
                            sgf.value = selGeo;
                        }
                        DisplayGeofence();
                    }
                }
            }
            else if (openMenu) {
                if (document.getElementById(Menus[i].Extender) != null) {
                    document.getElementById(Menus[i].Extender).style.visibility = "visible";
                }
                Menus[i].Open = true;
                if (Menus[i].Extender != ControlLeader + "pnlSubMenuUnits" && Menus[i].Extender != ControlLeader + "pnlSubMenuMapSettings") {
                    menuOpen = true;
                }
            }
            else {
                if (document.getElementById(Menus[i].Extender) != null) {
                    document.getElementById(Menus[i].Extender).style.visibility = "hidden";
                }
                Menus[i].Open = false;
                if (Menus[i].Extender == ControlLeader + "pnlSubMenuGeofence") {
                    GeofenceMode = false;
                    if (sgf != null) {
                        sgf.value = "00000000-0000-0000-0000-000000000000";
                    }
                    if (Geofence != null) {
                        map.removeOverlay(Geofence);
                    }
                    __doPostBack(ControlLeader + 'fieldShowGeofence', 'OnValueChanged');
                }
            }
        }
    }

    if (!menuOpen) {
        SizeMap();
    }
}
function ToggleTraffic() {
    if (map == null) {
        setTimeout("ToggleTraffic()", 25);
        return;
    }

    if (!trafficOverlay) {
        trafficOverlay = new GTrafficOverlay();
        map.addOverlay(trafficOverlay);
    }
    else {
        map.removeOverlay(trafficOverlay);
        trafficOverlay = null;
    }
}
function SelectLocationsCountry(el) {
    var elStateLabel = document.getElementById(ControlLeader + "rowLocationsStateLabel");
    var elStateDropdown = document.getElementById(ControlLeader + "rowLocationsStateDropdown");

    if (el.value == "USA") {
        elStateLabel.style.display = "block";
        elStateDropdown.style.display = "block";
    }
    else {
        elStateLabel.style.display = "none";
        elStateDropdown.style.display = "none";
    }
}
function CloseInfoWindow(selectedInfoWindow) {
    if (SelectedInfoWindow == selectedInfoWindow) {
        map.closeInfoWindow();
    }
}
function RectanglesOverlap(ax, ay, bx, by, cx, cy, dx, dy) {
    if (ax > dx || ay > dy || bx < cx || by < cy) {
        return false;
    }

    if (ax > cx && ax < dx) {
        if (ay > dy || by < cy) {
            return false;
        }
    }

    if (ay > cy && ay < dy) {
        if (ax > dx || bx < cx) {
            return false;
        }
    }

    if (bx > cx && bx < dx) {
        if (by < cy || ay > dy) {
            return false;
        }
    }

    if (by > cy && by < dy) {
        if (bx < cx || ax > dx) {
            return false;
        }
    }

    return true;
}
