/* Minification failed. Returning unminified contents.
(1,1): run-time error CSS1019: Unexpected token, found '/'
(1,2): run-time error CSS1019: Unexpected token, found '/'
(2,8): run-time error CSS1031: Expected selector, found ';'
(2,8): run-time error CSS1025: Expected comma or open brace, found ';'
(3,13): run-time error CSS1031: Expected selector, found '='
(3,13): run-time error CSS1025: Expected comma or open brace, found '='
(3,19): run-time error CSS1019: Unexpected token, found '/'
(3,20): run-time error CSS1019: Unexpected token, found '/'
(4,13): run-time error CSS1031: Expected selector, found '='
(4,13): run-time error CSS1025: Expected comma or open brace, found '='
(5,25): run-time error CSS1031: Expected selector, found '='
(5,25): run-time error CSS1025: Expected comma or open brace, found '='
(6,33): run-time error CSS1031: Expected selector, found ';'
(6,33): run-time error CSS1025: Expected comma or open brace, found ';'
(7,19): run-time error CSS1031: Expected selector, found ';'
(7,19): run-time error CSS1025: Expected comma or open brace, found ';'
(8,1): run-time error CSS1019: Unexpected token, found '/'
(8,2): run-time error CSS1019: Unexpected token, found '/'
(9,17): run-time error CSS1031: Expected selector, found '='
(9,17): run-time error CSS1025: Expected comma or open brace, found '='
(9,72): run-time error CSS1019: Unexpected token, found ';'
(10,12): run-time error CSS1031: Expected selector, found ';'
(10,12): run-time error CSS1025: Expected comma or open brace, found ';'
(11,16): run-time error CSS1031: Expected selector, found ';'
(11,16): run-time error CSS1025: Expected comma or open brace, found ';'
(12,23): run-time error CSS1031: Expected selector, found ';'
(12,23): run-time error CSS1025: Expected comma or open brace, found ';'
(13,18): run-time error CSS1031: Expected selector, found ';'
(13,18): run-time error CSS1025: Expected comma or open brace, found ';'
(14,26): run-time error CSS1031: Expected selector, found ';'
(14,26): run-time error CSS1025: Expected comma or open brace, found ';'
(15,17): run-time error CSS1031: Expected selector, found '='
(15,17): run-time error CSS1025: Expected comma or open brace, found '='
(16,18): run-time error CSS1031: Expected selector, found ';'
(16,18): run-time error CSS1025: Expected comma or open brace, found ';'
(17,8): run-time error CSS1031: Expected selector, found ';'
(17,8): run-time error CSS1025: Expected comma or open brace, found ';'
(18,11): run-time error CSS1031: Expected selector, found ';'
(18,11): run-time error CSS1025: Expected comma or open brace, found ';'
(20,1): run-time error CSS1019: Unexpected token, found '$'
(20,2): run-time error CSS1019: Unexpected token, found '('
(20,3): run-time error CSS1019: Unexpected token, found '".zone-header"'
(20,17): run-time error CSS1019: Unexpected token, found ')'
(20,19): run-time error CSS1030: Expected identifier, found 'css('
(20,19): run-time error CSS1019: Unexpected token, found 'css('
(20,23): run-time error CSS1019: Unexpected token, found '"background-color"'
(20,41): run-time error CSS1019: Unexpected token, found ','
(20,43): run-time error CSS1019: Unexpected token, found '"#00CCCC"'
(20,52): run-time error CSS1019: Unexpected token, found ')'
(20,53): run-time error CSS1019: Unexpected token, found ';'
(21,1): run-time error CSS1019: Unexpected token, found '/'
(21,2): run-time error CSS1019: Unexpected token, found '/'
(22,23): run-time error CSS1031: Expected selector, found ';'
(22,23): run-time error CSS1025: Expected comma or open brace, found ';'
(23,15): run-time error CSS1031: Expected selector, found ';'
(23,15): run-time error CSS1025: Expected comma or open brace, found ';'
(24,15): run-time error CSS1031: Expected selector, found ';'
(24,15): run-time error CSS1025: Expected comma or open brace, found ';'
(25,25): run-time error CSS1031: Expected selector, found '='
(25,25): run-time error CSS1025: Expected comma or open brace, found '='
(26,11): run-time error CSS1031: Expected selector, found ';'
(26,11): run-time error CSS1025: Expected comma or open brace, found ';'
(27,27): run-time error CSS1031: Expected selector, found '='
(27,27): run-time error CSS1025: Expected comma or open brace, found '='
(28,20): run-time error CSS1031: Expected selector, found '='
(28,20): run-time error CSS1025: Expected comma or open brace, found '='
(29,27): run-time error CSS1031: Expected selector, found '='
(29,27): run-time error CSS1025: Expected comma or open brace, found '='
(30,17): run-time error CSS1031: Expected selector, found ';'
(30,17): run-time error CSS1025: Expected comma or open brace, found ';'
(31,17): run-time error CSS1031: Expected selector, found '='
(31,17): run-time error CSS1025: Expected comma or open brace, found '='
(32,18): run-time error CSS1031: Expected selector, found '='
(32,18): run-time error CSS1025: Expected comma or open brace, found '='
(33,39): run-time error CSS1031: Expected selector, found '='
(33,39): run-time error CSS1025: Expected comma or open brace, found '='
(34,35): run-time error CSS1031: Expected selector, found '='
(34,35): run-time error CSS1025: Expected comma or open brace, found '='
(35,15): run-time error CSS1031: Expected selector, found ';'
(35,15): run-time error CSS1025: Expected comma or open brace, found ';'
(36,20): run-time error CSS1031: Expected selector, found ';'
(36,20): run-time error CSS1025: Expected comma or open brace, found ';'
(37,21): run-time error CSS1031: Expected selector, found ';'
(37,21): run-time error CSS1025: Expected comma or open brace, found ';'
(38,13): run-time error CSS1031: Expected selector, found ';'
(38,13): run-time error CSS1025: Expected comma or open brace, found ';'
(39,26): run-time error CSS1031: Expected selector, found ';'
(39,26): run-time error CSS1025: Expected comma or open brace, found ';'
(40,20): run-time error CSS1031: Expected selector, found ';'
(40,20): run-time error CSS1025: Expected comma or open brace, found ';'
(41,25): run-time error CSS1031: Expected selector, found ';'
(41,25): run-time error CSS1025: Expected comma or open brace, found ';'
(42,19): run-time error CSS1031: Expected selector, found '='
(42,19): run-time error CSS1025: Expected comma or open brace, found '='
(43,16): run-time error CSS1031: Expected selector, found '='
(43,16): run-time error CSS1025: Expected comma or open brace, found '='
(44,20): run-time error CSS1031: Expected selector, found '='
(44,20): run-time error CSS1025: Expected comma or open brace, found '='
(45,1): run-time error CSS1019: Unexpected token, found '/'
(45,2): run-time error CSS1019: Unexpected token, found '/'
(46,30): run-time error CSS1031: Expected selector, found '='
(46,30): run-time error CSS1025: Expected comma or open brace, found '='
(47,29): run-time error CSS1031: Expected selector, found '='
(47,29): run-time error CSS1025: Expected comma or open brace, found '='
(48,16): run-time error CSS1031: Expected selector, found '='
(48,16): run-time error CSS1025: Expected comma or open brace, found '='
(49,24): run-time error CSS1031: Expected selector, found '='
(49,24): run-time error CSS1025: Expected comma or open brace, found '='
(50,26): run-time error CSS1031: Expected selector, found ';'
(50,26): run-time error CSS1025: Expected comma or open brace, found ';'
(51,12): run-time error CSS1031: Expected selector, found '='
(51,12): run-time error CSS1025: Expected comma or open brace, found '='
(52,12): run-time error CSS1031: Expected selector, found '='
(52,12): run-time error CSS1025: Expected comma or open brace, found '='
(53,27): run-time error CSS1031: Expected selector, found '='
(53,27): run-time error CSS1025: Expected comma or open brace, found '='
(54,23): run-time error CSS1031: Expected selector, found ';'
(54,23): run-time error CSS1025: Expected comma or open brace, found ';'
(55,30): run-time error CSS1031: Expected selector, found '='
(55,30): run-time error CSS1025: Expected comma or open brace, found '='
(56,25): run-time error CSS1031: Expected selector, found '='
(56,25): run-time error CSS1025: Expected comma or open brace, found '='
(57,20): run-time error CSS1031: Expected selector, found '='
(57,20): run-time error CSS1025: Expected comma or open brace, found '='
(58,28): run-time error CSS1031: Expected selector, found '='
(58,28): run-time error CSS1025: Expected comma or open brace, found '='
(59,25): run-time error CSS1031: Expected selector, found '='
(59,25): run-time error CSS1025: Expected comma or open brace, found '='
(60,27): run-time error CSS1031: Expected selector, found '='
(60,27): run-time error CSS1025: Expected comma or open brace, found '='
(61,25): run-time error CSS1031: Expected selector, found '='
(61,25): run-time error CSS1025: Expected comma or open brace, found '='
(62,33): run-time error CSS1031: Expected selector, found '='
(62,33): run-time error CSS1025: Expected comma or open brace, found '='
(63,1): run-time error CSS1019: Unexpected token, found '/'
(63,2): run-time error CSS1019: Unexpected token, found '/'
(64,13): run-time error CSS1031: Expected selector, found '='
(64,13): run-time error CSS1025: Expected comma or open brace, found '='
(96,133): run-time error CSS1031: Expected selector, found ';'
(96,133): run-time error CSS1025: Expected comma or open brace, found ';'
(98,1): run-time error CSS1019: Unexpected token, found '/'
(98,2): run-time error CSS1019: Unexpected token, found '/'
(98,3): run-time error CSS1019: Unexpected token, found '/'
(101,22): run-time error CSS1031: Expected selector, found '='
(101,22): run-time error CSS1025: Expected comma or open brace, found '='
(157,9): run-time error CSS1031: Expected selector, found '='
(157,9): run-time error CSS1025: Expected comma or open brace, found '='
(161,10): run-time error CSS1031: Expected selector, found 'mapReady('
(161,10): run-time error CSS1025: Expected comma or open brace, found 'mapReady('
(221,1): run-time error CSS1019: Unexpected token, found '/'
(221,2): run-time error CSS1019: Unexpected token, found '/'
(222,10): run-time error CSS1031: Expected selector, found 'graphicsClickHandler('
(222,10): run-time error CSS1025: Expected comma or open brace, found 'graphicsClickHandler('
(251,10): run-time error CSS1031: Expected selector, found 'executeIdentifyTask('
(251,10): run-time error CSS1025: Expected comma or open brace, found 'executeIdentifyTask('
(340,1): run-time error CSS1019: Unexpected token, found '/'
(340,2): run-time error CSS1019: Unexpected token, found '/'
(341,10): run-time error CSS1031: Expected selector, found 'InitializeMap('
(341,10): run-time error CSS1025: Expected comma or open brace, found 'InitializeMap('
(404,10): run-time error CSS1031: Expected selector, found 'InitializeApplication('
(404,10): run-time error CSS1025: Expected comma or open brace, found 'InitializeApplication('
(466,10): run-time error CSS1031: Expected selector, found 'hideMeasurementTool('
(466,10): run-time error CSS1025: Expected comma or open brace, found 'hideMeasurementTool('
(488,10): run-time error CSS1031: Expected selector, found 'disableAddPointFunctionality('
(488,10): run-time error CSS1025: Expected comma or open brace, found 'disableAddPointFunctionality('
(495,10): run-time error CSS1031: Expected selector, found 'enableIdentifyTask('
(495,10): run-time error CSS1025: Expected comma or open brace, found 'enableIdentifyTask('
(502,10): run-time error CSS1031: Expected selector, found 'disableIdentifyTask('
(502,10): run-time error CSS1025: Expected comma or open brace, found 'disableIdentifyTask('
(509,10): run-time error CSS1031: Expected selector, found 'hidePictometryTool('
(509,10): run-time error CSS1025: Expected comma or open brace, found 'hidePictometryTool('
(526,1): run-time error CSS1019: Unexpected token, found '/'
(526,2): run-time error CSS1019: Unexpected token, found '/'
(527,10): run-time error CSS1031: Expected selector, found 'setFeatureLayerBackground('
(527,10): run-time error CSS1025: Expected comma or open brace, found 'setFeatureLayerBackground('
(547,1): run-time error CSS1019: Unexpected token, found '/'
(547,2): run-time error CSS1019: Unexpected token, found '/'
(548,10): run-time error CSS1031: Expected selector, found 'setDraggableInfoWindow('
(548,10): run-time error CSS1025: Expected comma or open brace, found 'setDraggableInfoWindow('
(557,1): run-time error CSS1019: Unexpected token, found '/'
(557,2): run-time error CSS1019: Unexpected token, found '/'
(558,10): run-time error CSS1031: Expected selector, found 'setDraggableInfoWindowUsingPointers('
(558,10): run-time error CSS1025: Expected comma or open brace, found 'setDraggableInfoWindowUsingPointers('
(565,1): run-time error CSS1019: Unexpected token, found '/'
(565,2): run-time error CSS1019: Unexpected token, found '/'
(566,10): run-time error CSS1031: Expected selector, found 'CreateToggle('
(566,10): run-time error CSS1025: Expected comma or open brace, found 'CreateToggle('
(583,10): run-time error CSS1031: Expected selector, found 'ToggleOrtho('
(583,10): run-time error CSS1025: Expected comma or open brace, found 'ToggleOrtho('
(602,1): run-time error CSS1019: Unexpected token, found '/'
(602,2): run-time error CSS1019: Unexpected token, found '/'
(603,10): run-time error CSS1031: Expected selector, found 'CreateScalebar('
(603,10): run-time error CSS1025: Expected comma or open brace, found 'CreateScalebar('
(616,1): run-time error CSS1019: Unexpected token, found '/'
(616,2): run-time error CSS1019: Unexpected token, found '/'
(617,10): run-time error CSS1031: Expected selector, found 'CreateOverviewMap('
(617,10): run-time error CSS1025: Expected comma or open brace, found 'CreateOverviewMap('
(628,1): run-time error CSS1019: Unexpected token, found '/'
(628,2): run-time error CSS1019: Unexpected token, found '/'
(629,10): run-time error CSS1031: Expected selector, found 'CreateHomeButton('
(629,10): run-time error CSS1025: Expected comma or open brace, found 'CreateHomeButton('
(636,1): run-time error CSS1019: Unexpected token, found '/'
(636,2): run-time error CSS1019: Unexpected token, found '/'
(637,10): run-time error CSS1031: Expected selector, found 'CreateMap('
(637,10): run-time error CSS1025: Expected comma or open brace, found 'CreateMap('
(650,1): run-time error CSS1019: Unexpected token, found '/'
(650,2): run-time error CSS1019: Unexpected token, found '/'
(650,48): run-time error CSS1031: Expected selector, found '/'
(650,48): run-time error CSS1025: Expected comma or open brace, found '/'
(668,1): run-time error CSS1019: Unexpected token, found '/'
(668,2): run-time error CSS1019: Unexpected token, found '/'
(670,10): run-time error CSS1031: Expected selector, found 'CreatePopUp('
(670,10): run-time error CSS1025: Expected comma or open brace, found 'CreatePopUp('
(678,1): run-time error CSS1019: Unexpected token, found '/'
(678,2): run-time error CSS1019: Unexpected token, found '/'
(679,10): run-time error CSS1031: Expected selector, found 'CreateMeasurementTools('
(679,10): run-time error CSS1025: Expected comma or open brace, found 'CreateMeasurementTools('
(830,10): run-time error CSS1031: Expected selector, found 'CreateImageryService('
(830,10): run-time error CSS1025: Expected comma or open brace, found 'CreateImageryService('
(922,1): run-time error CSS1019: Unexpected token, found '/'
(922,2): run-time error CSS1019: Unexpected token, found '/'
(922,86): run-time error CSS1031: Expected selector, found '('
(922,86): run-time error CSS1025: Expected comma or open brace, found '('
(1015,92): run-time error CSS1002: Unterminated string: 's use display instead of visibility property to remove entire element
(1051,92): run-time error CSS1002: Unterminated string: 's use display instead of visibility property to remove entire element
(1130,92): run-time error CSS1002: Unterminated string: 's use display instead of visibility property to remove entire element
(1178,92): run-time error CSS1002: Unterminated string: 's use display instead of visibility property to remove entire element
(1225,92): run-time error CSS1002: Unterminated string: 's use display instead of visibility property to remove entire element
(1239,1): run-time error CSS1019: Unexpected token, found '/'
(1239,2): run-time error CSS1019: Unexpected token, found '/'
(1241,10): run-time error CSS1031: Expected selector, found 'Init('
(1241,10): run-time error CSS1025: Expected comma or open brace, found 'Init('
(1244,1): run-time error CSS1019: Unexpected token, found '/'
(1244,2): run-time error CSS1019: Unexpected token, found '/'
(1245,10): run-time error CSS1031: Expected selector, found 'addToTOC('
(1245,10): run-time error CSS1025: Expected comma or open brace, found 'addToTOC('
(1265,10): run-time error CSS1031: Expected selector, found 'buildLayerListRoot('
(1265,10): run-time error CSS1025: Expected comma or open brace, found 'buildLayerListRoot('
(1273,10): run-time error CSS1031: Expected selector, found 'toggleLayer('
(1273,10): run-time error CSS1025: Expected comma or open brace, found 'toggleLayer('
(1285,10): run-time error CSS1031: Expected selector, found 'zoomToLayer('
(1285,10): run-time error CSS1025: Expected comma or open brace, found 'zoomToLayer('
(1291,10): run-time error CSS1031: Expected selector, found 'buildLayerList('
(1291,10): run-time error CSS1025: Expected comma or open brace, found 'buildLayerList('
(1312,10): run-time error CSS1031: Expected selector, found 'createLayerList('
(1312,10): run-time error CSS1025: Expected comma or open brace, found 'createLayerList('
(1586,10): run-time error CSS1031: Expected selector, found 'generateLayerGroupings('
(1586,10): run-time error CSS1025: Expected comma or open brace, found 'generateLayerGroupings('
(1651,10): run-time error CSS1031: Expected selector, found 'createHelpText('
(1651,10): run-time error CSS1025: Expected comma or open brace, found 'createHelpText('
(1764,26): run-time error CSS1031: Expected selector, found '='
(1764,26): run-time error CSS1025: Expected comma or open brace, found '='
(1766,2): run-time error CSS1019: Unexpected token, found ';'
(1769,10): run-time error CSS1031: Expected selector, found 'updateLayerVisibility('
(1769,10): run-time error CSS1025: Expected comma or open brace, found 'updateLayerVisibility('
(1837,10): run-time error CSS1031: Expected selector, found 'toggleService('
(1837,10): run-time error CSS1025: Expected comma or open brace, found 'toggleService('
(1846,1): run-time error CSS1019: Unexpected token, found '/'
(1846,2): run-time error CSS1019: Unexpected token, found '/'
(1847,1): run-time error CSS1031: Expected selector, found '/'
(1847,1): run-time error CSS1025: Expected comma or open brace, found '/'
(1981): run-time error CSS1001: Unterminated comment.
 */
//Dwayne Change Small Edit
var map;
var tocHTML = ""; //used to update the toc
var visible = [];
var transparencyLayerID = "";
var identifyTask, identifyParams;
var doidentifyTask;
//Measurement variables
var measurement = "", locationBtn = "", distanceBtn = "", areaBtn = "";;
var checked;
var drawToolbar;
var attributeInspector;
var updateFeature;
var multiUnitFeatureLayer;
var environment = 1;
var PictometryURL;
var IPA;
var legend;

$(".zone-header").css("background-color", "#00CCCC");
// variable to set toggle between measurement and infowindow
var GeometryServiceURL;
var parcelsURL;
var featureURL;
var propertyDescription = new Object;
var UiUrls;
var isFeatureLayerClicked = true;
var tempBuildingID = "";
var isTempBuildingDeleted = false;
var pointDrawEnd;
var featureType = "";
var legendLayers = [];
var countParcelCountForSingleBuilding = 0;
var parcelFeatureArrayForBuilding = [];
var ladbslayer;
var annotationLayer;
var overviewMapDijit;
var scalebar;
var residentialClickEvent;
var multiClickEvent;
var commercialClickEvent;
var methaneLayers = [];
var roadLayers = [];
var hillsideLayers = [];
//Commenting for production release
var isAddGradingPointClicked = false;
var isSelectedParcelClicked = false;
var gradingPIN = "";
var lastSelectedParcel = "";
var gradingPointQuickView;
var pointX = "";
var pointY = "";
var gradingPointParcelIDs = "";
var selectFeaturePoint;
var addedGradingPointFeature = "";
var isGradingPointAdded = false;
var isIdentifyTask = false;
var deleteExistingBuilding = false;
var isGradingPointAdded = false;
var isGradingPointDeleted = false;
var gradingLogPointData = "";
var isGradingPointAlreadyExists = false;
// Patty specified scales at which map is visible in webLods
var webLods = [
//{ "level" : 0, "resolution" : 156543.033928, "scale" : 591657527.591555 },
//{ "level" : 1, "resolution" : 78271.5169639999, "scale" : 295828763.795777 },
//{ "level" : 2, "resolution" : 39135.7584820001, "scale" : 147914381.897889 },  
//{ "level" : 3, "resolution" : 19567.8792409999, "scale" : 73957190.948944 },
//{ "level" : 4, "resolution" : 9783.93962049996, "scale" : 36978595.474472 },
//{ "level" : 5, "resolution" : 4891.96981024998, "scale" : 18489297.737236 },
{ "level": 6, "resolution": 2445.98490512499, "scale": 9244648.868618 },
{ "level": 7, "resolution": 1222.99245256249, "scale": 4622324.434309 },
{ "level": 8, "resolution": 611.49622628138, "scale": 2311162.217155 },
{ "level": 9, "resolution": 305.748113140558, "scale": 1155581.108577 },
{ "level": 10, "resolution": 152.874056570411, "scale": 577790.554289 },
{ "level": 11, "resolution": 76.4370282850732, "scale": 288895.277144 },
{ "level": 12, "resolution": 38.2185141425366, "scale": 144447.638572 },
{ "level": 13, "resolution": 19.1092570712683, "scale": 72223.819286 },
{ "level": 14, "resolution": 9.55462853563415, "scale": 36111.909643 },
{ "level": 15, "resolution": 4.77731426794937, "scale": 18055.954822 },
{ "level": 16, "resolution": 2.38865713397468, "scale": 9027.977411 },
{ "level": 17, "resolution": 1.19432856685505, "scale": 4513.988705 },
{ "level": 18, "resolution": 0.597164283559817, "scale": 2256.994353 },
{ "level": 19, "resolution": 0.298582141647617, "scale": 1128.497176 },
{ "level": 20, "resolution": 0.149291, "scale": 564.24855 },
{ "level": 21, "resolution": 0.0746455, "scale": 282.12427 }
];


var Map, InfoTemplate, FindTask, FindParameters, Locator, Extent, OverviewMap, HomeButton, LocateButton, InfoTemplate, SimpleMarkerSymbol, Graphic, ArcGISTiledMapServiceLayer,
  ArcGISDynamicMapServiceLayer, FeatureLayer,
  ImageParameters, BasemapGallery, arcgisUtils, BasemapToggle,
  Geocoder, SimpleFillSymbol, SimpleLineSymbol, identifyTask, identifyParameters, Popup, Color, dom, registry,
  arrayUtils, connect, DataGrid, ItemFileReadStore, Button, parser, isSatteliteViewActive,
  arrayUtils, Color, domConstruct, Scalebar, parser, Query, QueryTask, ParcelGraphicLayer, BorderContainer, ContentPane, TitlePane, highlightBOEParcel, highlightBOEParcelParameters, Legend, Draw,
  AttributeInspector, DojoOn, BuildingSearchFindParameters, BuildingSearchFindTask, ParcelSearchFindParameters, ParcelSearchFindTask;

/// Esri control specify here


var mapfunctionality = [
  "esri/map",
  "esri/InfoTemplate",
  "esri/tasks/FindTask",
  "esri/tasks/FindParameters",
  "esri/tasks/locator",
  "esri/geometry/Extent",
  "esri/dijit/OverviewMap",
  "esri/dijit/HomeButton",
  "dojo/keys",
  "esri/config",
  "esri/sniff",
  "esri/dijit/Measurement",
  "esri/tasks/GeometryService",
  "esri/dijit/LocateButton",
  "esri/InfoTemplate",
  "esri/symbols/SimpleMarkerSymbol",
  "esri/graphic",
  "esri/layers/ArcGISTiledMapServiceLayer",
  "esri/layers/ArcGISDynamicMapServiceLayer",
  "esri/layers/FeatureLayer",
  "esri/layers/ImageParameters",
  "esri/dijit/BasemapGallery",
  "esri/arcgis/utils",
  "esri/dijit/BasemapToggle",
  "esri/dijit/Geocoder",
  "esri/symbols/SimpleFillSymbol",
  "esri/symbols/SimpleLineSymbol",
  "esri/tasks/IdentifyTask",
  "esri/tasks/IdentifyParameters",
  "esri/dijit/Popup",
  "esri/Color",
  "dojo/dom",
  "dijit/registry",
  "dojo/_base/array",
  "dojo/_base/connect",
  "dojox/grid/DataGrid",
  "dojo/data/ItemFileReadStore",
  "dijit/form/Button",
  "dojo/parser",
  "dojo/dom-construct",
  "esri/dijit/Scalebar",
  "esri/tasks/query",
  "esri/tasks/QueryTask",
  "dijit/layout/BorderContainer",
  "dijit/layout/ContentPane",
  "dijit/TitlePane",
  "esri/graphic",
  "esri/dijit/Legend",
  "esri/toolbars/draw",
  "esri/dijit/AttributeInspector",
  "dojo/on",
  "dojo/domReady!"
];


var txt = "IDIS";

/* Identify functioanlity start here*/

function mapReady() {
    /*Parameters for parcel and building identify*/
    identifyParams = new IdentifyParameters();
    identifyParams.tolerance = 2;
    identifyParams.returnGeometry = true;
    //Commenting for production release
    if (App != "Grading") {
    
        //identifyParams.layerIds = (IsRequestFromPCIS == true ? [3, 4, 1] : [1, 3, 4]);//[3, 4, 1];  /*  layers 4 for building and 1 for parcel to be select */
        identifyParams.layerIds = (IsRequestFromPCIS == true ? [3, 1] : [1, 3]);
    } else {
        //identifyParams.layerIds = [1, 3, 4];
        identifyParams.layerIds = [1, 3];
    }
    identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_TOP;
    identifyParams.width = map.width;
    identifyParams.height = map.height;

    // We are using these parameters to highlight features on address search
    highlightBOEParcelParameters = new IdentifyParameters();
    highlightBOEParcelParameters.tolerance = 2;
    highlightBOEParcelParameters.returnGeometry = true;
    highlightBOEParcelParameters.layerIds = [1]; /* layer number 6 to be select after address search i.e BOE parcel */
    highlightBOEParcelParameters.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
    highlightBOEParcelParameters.width = map.width;
    highlightBOEParcelParameters.height = map.height;

    /*Adding click event for identifying building and parcel layer on the map*/
    doidentifyTask = map.on("click", executeIdentifyTask);

    /*Creating identify task for building and parcel layer*/
    identifyTask = new IdentifyTask(parcelsURL);

    //code added to highlight parcel on address search
    highlightBOEParcel = new IdentifyTask(parcelsURL);

    /*Setting parameters for building search from PCIS URL*/
    BuildingSearchFindParameters = new FindParameters();
    BuildingSearchFindParameters.returnGeometry = true;
    //BuildingSearchFindParameters.layerIds = [4];
    BuildingSearchFindParameters.layerIds = [3];
    BuildingSearchFindParameters.searchFields = ["BLD_ID"];
    BuildingSearchFindParameters.outSpatialReference = map.spatialReference;
    //Setting the below parameter for getting the exact search result
    BuildingSearchFindParameters.contains = false;

    /*Setting parameters for parcel search from PCIS URL*/
    ParcelSearchFindParameters = new FindParameters();
    ParcelSearchFindParameters.returnGeometry = true;
    ParcelSearchFindParameters.layerIds = [1];
    ParcelSearchFindParameters.searchFields = ["PIN"];
    ParcelSearchFindParameters.outSpatialReference = map.spatialReference;
    ParcelSearchFindParameters.contains = false;
    setTimeout(structuralInventory, 1000);
    //Commenting for production release
    map.graphics.on("click", graphicsClickHandler);


}

//Commenting for production release
function graphicsClickHandler(evt) {    
    if (App == "Grading" && evt.graphic.attributes != undefined) {        
        //isSelectedParcelClicked = true;        
        //Check if selected graphic/parcel is already selected or not
        if ($.inArray(evt.graphic.attributes.PIN, gradingParcels) !== -1 && isAddGradingPointClicked == false) {
            //is in array
            //remove the element from the gradingParcels array 
            gradingParcels.splice($.inArray(evt.graphic.attributes.PIN, gradingParcels), 1);
            //hide the graphics
            evt.graphic.hide();
            if (graphicsArray.length > 0) {
                for (i = 0; i <= graphicsArray.length - 1; i++) {
                    map.graphics.remove(graphicsArray[i]);
                }
            }

            graphicsArray.length = 0;
            hideSlidingWindow('divParcelQuckiView');
        }
        else {
            //is not in array
            gradingPIN = evt.graphic.attributes.PIN;
            isSelectedParcelClicked = true;
        }
    }
    $("#selectedParcelCount").html(gradingParcels.length);
}

/*Patty set identify task*/
function executeIdentifyTask(event) {

    var graphic = event.graphic;
    /*If value is false then show the InfoWindow else do not show the InfoWindow*/
    /*The value of variable checked is set on clicking the measurement options (area, distance, location) in the function CreateMeasurementTools()*/
    if (doIdentify && graphic == undefined) {
        if (checked != true) {
            identifyParams.geometry = event.mapPoint;
            identifyParams.mapExtent = map.extent;
            map.infoWindow.hide();
            var deferred = identifyTask
              .execute(identifyParams)
              .addCallback(function (response) {
                  /* response is an array of identify result objects
                   Let's return an array of features.*/
                  return arrayUtils.map(response, function (result) {
                      var feature = result.feature;
                      var layerName = result.layerName;

                      feature.attributes.layerName = layerName;
                      //Commenting for production release
                      if (App != "Grading") {
                          map.graphics.clear();
                      }
                      isIdentifyTask = true;
                      $("div.title").html("");
                      /*Set identify fields for buildings*/
                      if (layerName === 'Building Outlines') {
                          /***Added following line of code for removing the (1 of 2) text displaying in info window for multiple building features **/
                          //$("div.title").replaceWith("<div class='title'><b>Building Quick View</b><br></div>");
                          /******Adding building feature to array for showing mulitple parcel information for multiple parcels and one building scenario*****/
                          parcelFeatureArrayForBuilding.push(feature);

                          /********If one building and one parcel then show building quick view as well as parcel quick view for internal user********/
                          if (countParcelCountForSingleBuilding == 0) {
                              /*Set the building quick view template by using following function. This function is present in Common.js file*/
                              showBuildingQuickViewDetail(feature);
                              //feature.setInfoTemplate(buildingTemplate);                             
                              /*Set the parcel quick view template by using following function.  This function is present in Common.js file*/
                              showParcelQuickViewDetail(feature, false);


                          }
                              /********If one building and multiple parcel then show building quick view 
                              as well as parcel quick view with multiple parcels for internal user********/
                          else {
                              /*Set the parcel quick view template by using following function.  This function is present in Common.js file*/
                              showParcelQuickViewDetail(parcelFeatureArrayForBuilding, false);

                          }
                          
                          $('#buildingContent').html(buildingHtmlTemplate);
                          
                          $('#parcelContent').html(parcelTemplate);
                          openBuildingAccordion();

                          if ($('#collapseTwo').css('display') == 'block') {
                              $("#collapseTwo").scrollTop(function () { return this.scrollHeight; });
                          }

                          countParcelCountForSingleBuilding++;

                      }
                          /* Set identify fields for BOE parcels*/
                      else if (layerName === 'Property Lines') {

                          openParcelAccordion();
                          
                          /*Set the parcel quick view template by using following function.  This function is present in Common.js file*/
                          showParcelQuickViewDetail(feature, false);
                          $('#parcelContent').html(parcelTemplate);
                          $('#divBuildingQuickView').css("display", "none");
                          $('#buildingContent').html("");

                      }

                      return feature;
                  });
              });
        }
    }

    countParcelCountForSingleBuilding = 0;
    parcelFeatureArrayForBuilding.length = 0;


}


// Global variable for functionality
function InitializeMap(
  _Map, _InfoTemplate, _FindTask, _FindParameters, _Locator, _Extent, _OverviewMap, _HomeButton, _keys, _esriConfig, _has, _Measurement, _GeometryService, _LocateButton, _InfoTemplate, _SimpleMarkerSymbol, _Graphic, _ArcGISTiledMapServiceLayer,
  _ArcGISDynamicMapServiceLayer, _FeatureLayer,
  _ImageParameters, _BasemapGallery, _arcgisUtils, _BasemapToggle,
  _Geocoder, _SimpleFillSymbol, _SimpleLineSymbol, _IdentifyTask, _IdentifyParameters, _Popup, _Color, _dom, _registry, _arrayUtils, _connect, _DataGrid,
  _ItemFileReadStore, _Button, _parser, _domConstruct, _Scalebar, _Query, _QueryTask, _BorderContainer, _ContentPane, _TitlePane, _Graphic, _Legend, _Draw, _AttributeInspector, _DojoOn
) {
    //taking local scope and making it global scope
    //this is allowing us to refactor our methods
    Map = _Map;
    InfoTemplate = _InfoTemplate;
    FindTask = _FindTask;
    FindParameters = _FindParameters;
    Locator = _Locator;
    Extent = _Extent;
    OverviewMap = _OverviewMap;
    HomeButton = _HomeButton;
    keys = _keys;
    esriConfig = _esriConfig;
    has = _has;
    Measurement = _Measurement;
    GeometryService = _GeometryService;
    LocateButton = _LocateButton;
    InfoTemplate = _InfoTemplate;
    SimpleMarkerSymbol = _SimpleMarkerSymbol;
    Graphic = _Graphic;
    ArcGISTiledMapServiceLayer = _ArcGISTiledMapServiceLayer;
    ArcGISDynamicMapServiceLayer = _ArcGISDynamicMapServiceLayer;
    FeatureLayer = _FeatureLayer;
    ImageParameters = _ImageParameters;
    BasemapGallery = _BasemapGallery;
    arcgisUtils = _arcgisUtils;
    BasemapToggle = _BasemapToggle;
    Geocoder = _Geocoder;
    SimpleFillSymbol = _SimpleFillSymbol;
    SimpleLineSymbol = _SimpleLineSymbol;
    IdentifyTask = _IdentifyTask;
    IdentifyParameters = _IdentifyParameters;
    Popup = _Popup;
    Color = _Color;
    dom = _dom;
    registry = _registry;
    arrayUtils = _arrayUtils;
    connect = _connect;
    DataGrid = _DataGrid;
    ItemFileReadStore = _ItemFileReadStore;
    Button = _Button;
    parser = _parser;
    domConstruct = _domConstruct;
    Scalebar = _Scalebar;
    Query = _Query;
    QueryTask = _QueryTask;
    BorderContainer = _BorderContainer;
    ContentPane = _ContentPane;
    TitlePane = _TitlePane;
    Graphic = _Graphic;
    Legend = _Legend;
    Draw = _Draw;
    AttributeInspector = _AttributeInspector;
    DojoOn = _DojoOn;
    getUiUrl();
}

function InitializeApplication() {
    GeometryServiceURL = getUrlByName("js_geometryUrl");
    parcelsURL = getUrlByName("js_parcelsUrl");
    featureURL = getUrlByName("js_featureUrl");
    $('head').append('<link rel="stylesheet" href="' + getUrlByName("js_css_Esri_claro") + '" type="text/css"/>');
    //$('head').append('<link rel="stylesheet" href="' + getUrlByName("js_css_Esri_Esri") + '" type="text/css"/>');
    $('head').append('<script src="' + getUrlByName("js_pictometryScriptUrl") + '"/>');

    map = CreateMap();


    //Base map toggle
    CreateToggle();

    // Scale bar
    CreateScalebar();

    // Overview Map Starts
    //CreateOverviewMap();

    // Home Button and Locate Button Starts here
    CreateHomeButton();

    // Address Search Starts Here
    CreateGeocoder();

    // Create service for LARIAC Imagery
    CreateImageryService();

    // Create tools for measurement
    CreateMeasurementTools();

    //This function provides the adding and editing functionality for the feature layers (Residential, MultiApt and Commercial)
    AddEditFeatureLayers();

    //Listent for infoWindow onHide event
    dojo.connect(map.infoWindow, "onHide", function () {        
        map.graphics.clear(); hideSlidingWindow('divParcelQuckiView'); $('#parcelContent').html("");
        $('#lnkReportButtons').html("");
        $("#btnDeleteBuilding").attr("disabled", "disabled");
        updateFeature = "";
    });

    //dojo.connect(window, "onresize", function () {
    //    map.reposition();
    //});

    //makes draggable info window 
    setDraggableInfoWindow();

    //makes draggable info window  using pointers
    setDraggableInfoWindowUsingPointers();

    //set feature layer backgroun style to blank based on building types (Residential, MultiApt, Commercial)
    setFeatureLayerBackground();

    //Hide measurement functionality
    hideMeasurementTool();

}

/********Function for hiding the measurement tool functionality******/
function hideMeasurementTool() {
    $("#divMeasurementMessage").css("display", "none");
    $("#divMeasurementMessage").html("");
    
    //Commenting for production release
    if (App != "Grading") {
        /*Clear all the graphics present on the Map*/
        if (map.graphics != null) {
            map.graphics.clear();
        }
    }
        $("#lnkMeasurement").css("background", "#22415d");
        $("#lnkMeasurement").css("border", "");        
    /*Hide and deactivate measurement functionality*/
    $("#measurement").css('visibility', 'hidden');
    measurement.deactivate();
    measurement.hide();


}

/************************Function to disable add new point functionality*********************************/
function disableAddPointFunctionality() {
    //Set Feature layer click event flag to true
    isFeatureLayerClicked = true;
    drawToolbar.deactivate();
}

/**********Function to enable the identify task functionality***********/
function enableIdentifyTask() {
    /*enable identify task functionality*/
    doIdentify = true;
    doidentifyTask = map.on("click", executeIdentifyTask);
}

/**********Function to disable the identify task functionality***********/
function disableIdentifyTask() {
    /* Disable Identify Task functionality*/
    doIdentify = false;
    dojo.disconnect(doidentifyTask);
}

/********Function for hiding the pictometry tool functionality******/
function hidePictometryTool() {
    $("#divPictometryMessage").css("display", "none");
    //set pictometry flag to true
    isPictometryClicked = true;
    /*Clear all the graphics present on the Map*/
    if (map.graphics != null) {
        map.graphics.clear();
    }
    /*Hide and deactivate pictometry functionality*/
    $('#pictometry').css('display', 'none');
    $("#lnkPictometry").removeClass("active");
    dojo.disconnect(PictometryHandler);


}


//Sets the blank background to the feature layer buttons
function setFeatureLayerBackground() {
    var buildgType = getURLVars()["bldgType"] !== undefined ? getURLVars()["bldgType"] : '';
    if (buildgType.toLowerCase() == "r") {
        $('.residStyle').css('background', '');
        doIdentify = true;
        isFeatureLayerClicked = true;
    }

    if (buildgType.toLowerCase() == "m") {
        $('.multiStyle').css('background', '');
        doIdentify = true;
        isFeatureLayerClicked = true;
    }
    if (buildgType.toLowerCase() == "c") {
        $('.commStyle').css('background', '');
        doIdentify = true;
        isFeatureLayerClicked = true;
    }
}

//makes draggable info window
function setDraggableInfoWindow() {
    if ($(".esriPopup").css('visibility') === "visible") {
        $('.esriPopupWrapper').css('cursor', 'move');
        $(".esriPopup").draggable({ handle: ".esriPopupWrapper" });
        $('div').removeClass('pointer bottom');
        $('div').removeClass('outerPointer left');
    }
}

//makes draggable info window with pointer
function setDraggableInfoWindowUsingPointers() {
    if ($(".esriPopup").css('visibility') === "visible") {
        $('.titlePane').css('cursor', 'move');
        $(".esriPopup").draggable({ handle: ".titlePane" });

    }
}
// Function to toggle between satellite and ArcGIS streets
function CreateToggle() {

    var toggle = new BasemapToggle({
        map: map,
        basemap: "satellite"
    }, "BasemapToggle");

    toggle.startup();

    $('.toggleButton').click(ToggleOrtho);
}


/*START*/
/*Following code is for toggle between street and ortho/Sattelite*/


function ToggleOrtho() {
    var layername;
    var layername2;
    if (!isSatteliteViewActive) {
        layername = map.layerIds[2];
        layername2 = map.layerIds[1];
        isSatteliteViewActive = true;
    } else {
        layername = map.layerIds[1];
        layername2 = map.layerIds[2];
        isSatteliteViewActive = false;
    }
    toggleService(layername);
    toggleService(layername2);


}


// Adding scale bar
function CreateScalebar() {

    scalebar = new Scalebar({
        map: map,
        // "dual" displays both miles and kilmometers
        // "english" is the default, which displays miles
        // use "metric" for kilometers
        scalebarUnit: "dual",
        scalebarStyle: "",
        attachTo: "bottom-center"
    });
}

// Overview map minimized in bottom left corner of map
function CreateOverviewMap() {

    overviewMapDijit = new OverviewMap({
        map: map,
        visible: false,
        attachTo: "bottom-left"
    });

    overviewMapDijit.startup();
}

//Prakash created home button
function CreateHomeButton() {
    var home = new HomeButton({
        map: map
    }, "HomeButton");

    home.startup();
}
// Map Initialize here and add zoom scale
function CreateMap() {
    var newMap = new Map("map", {
        basemap: "streets",
        center: [-118.35, 34.05],
        lods: webLods,
        zoom: 4,
        infoWindow: CreatePopUp()
    });

    newMap.on("load", mapReady);
    //Patty removed called to getPictometryURL from this location on 9/23/14
    return newMap;
}
// Built from Esri sample developers.arcgis.com/javascript/jssamples/util_coordinate_converter.html
function ConvertCoords(x, y, inSR) {
    var geometryService = new esri.tasks.GeometryService(GeometryServiceURL);

    var outSR = new esri.SpatialReference({
        wkid: 4326
    });
    var inputpoint = new esri.geometry.Point(x, y, inSR);
    var PrjParams = new esri.tasks.ProjectParameters();
    PrjParams.geometries = [inputpoint];
    PrjParams.outSR = outSR;

    geometryService.project(PrjParams, function (outputpoint) {

        IPA.setLocation(outputpoint[0].y, outputpoint[0].x, 20);

    });
}
// Identify popups and graphics starts here

function CreatePopUp() {
    return new Popup({
        fillSymbol: new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
         new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
           new Color([255, 0, 0]), 2), new Color([255, 255, 0, 0.25]))
    }, domConstruct.create("div"));
}

// Measurement div starts here
function CreateMeasurementTools() {
    measurement = new Measurement({
        map: map,
        defaultAreaUnit: esri.Units.SQUARE_FEET,
        defaultLengthUnit: esri.Units.FEET,
    }, dom.byId("measurementDiv"));
    measurement.startup();

    //$("#titlePane").draggable({ cursor: "move", containment: "#map" });  

    measurement.on("measure-start", function (evt) {
        $("#divMeasurementMessage").css("display", "block");
        $(document).mousemove(function (e) {
            $("#divMeasurementMessage").css({ left: e.pageX, top: e.pageY });
        });


        if (evt.toolName == "area") {
            $("#divMeasurementMessage").html("Double click to end drawing");
        }
        else if (evt.toolName == "distance") {
            $("#divMeasurementMessage").html("Double click to end line");

        }
        else if (evt.toolName == "location") {
            $("#divMeasurementMessage").html("Click to view Coordinates");
        }
        //var actTool = evt.activeTool;
        //$("#divMeasurementMessage").html("Double click to end drawing");
        //this.setTool(evt.activeTool, false);
    });

    measurement.on("measure-end", function (evt) {
        $("#divMeasurementMessage").css("display", "block");
        //$("#divMeasurementMessage").html("");

        if (evt.toolName == "area") {
            $("#divMeasurementMessage").html("Click to start drawing area");
        }
        else if (evt.toolName == "distance") {
            $("#divMeasurementMessage").html("Click to start line");

        }
        else if (evt.toolName == "location") {
            $("#divMeasurementMessage").html("Click to view Coordinates");
        }

        //var actTool = evt.activeTool;
        //$("#divMeasurementMessage").html("Double click to end drawing");
        //this.setTool(evt.activeTool, false);
    });






    /*START*/
    /*Following code sets the value of the variable named as checked based on the selection and deselection of the measurement options*/
    /* If we select the measurement option area then it sets the value to true. If value is true then do not shows the InfoWindow */
    /* If we deselect the measurement option area then it sets the value to false. If value is false then shows the InfoWindow */
    dojo.connect(measurement.area, "onClick", function () {
        if (this.checked) {

            checked = true;
            $("#divMeasurementMessage").css("display", "block");
            $("#divMeasurementMessage").html("Click to start drawing area");
            $(document).mousemove(function (e) {
                $("#divMeasurementMessage").css({ left: e.pageX, top: e.pageY });
            });

        }
        else {

            checked = false;

            $("#divMeasurementMessage").css("display", "none");
            $("#divMeasurementMessage").html("");
        }
    });

    /* If we select the measurement option distance then it sets the value to true. If value is true then do not shows the InfoWindow */
    /* If we deselect the measurement option distance then it sets the value to false. If value is false then shows the InfoWindow */
    dojo.connect(measurement.distance, "onClick", function () {
        if (this.checked) {

            checked = true;

            $("#divMeasurementMessage").css("display", "block");
            $("#divMeasurementMessage").html("Click to start line");
            $(document).mousemove(function (e) {
                $("#divMeasurementMessage").css({ left: e.pageX, top: e.pageY });
            });

        }
        else {

            checked = false;

            $("#divMeasurementMessage").css("display", "none");
            $("#divMeasurementMessage").html("");
        }
    });

    /*Hide the mouse row on location tool*/
    measurement.on("tool-change", function (evt) {
        if (evt.toolName == "location") {
            $('.esriMeasurementResultTable tr').eq(1).hide();
        }
    });

    /* If we select the measurement option location then it sets the value to true. If value is true then do not shows the InfoWindow */
    /* If we deselect the measurement option location then it sets the value to false. If value is false then shows the InfoWindow */
    dojo.connect(measurement.location, "onClick", function () {
        if (this.checked) {

            checked = true;

            $("#divMeasurementMessage").css("display", "block");
            $("#divMeasurementMessage").html("Click to view Coordinates");
            $(document).mousemove(function (e) {
                $("#divMeasurementMessage").css({ left: e.pageX, top: e.pageY });
            });

        }
        else {

            checked = false;

            $("#divMeasurementMessage").css("display", "none");
            $("#divMeasurementMessage").html("");
        }

    });
    /*END*/

    /*Code or function for deactivating the measurement tool*/
    measurement.deactivate = function () {
        locationBtn = dijit.byId(measurement.location),
            distanceBtn = dijit.byId(measurement.distance),
            areaBtn = dijit.byId(measurement.area)
        this.closeTool();
        locationBtn.setAttribute('checked', false);
        distanceBtn.setAttribute('checked', false);
        areaBtn.setAttribute('checked', false);
        checked = false;
    }
    /*Code for deactivating the measurement tool*/
}


function CreateImageryService() {
    //Use the ImageParameters to set map service layer definitions and map service visible layers before adding to the client map.
    var imageParameters = new ImageParameters();

    //Those array elements correspond to the layer id within the remote ArcGISDynamicMapServiceLayer
    var layerDefs = [];

    imageParameters.layerDefinitions = layerDefs;

    //I want layers to be visible
    imageParameters.layerIds = [];
    imageParameters.layerOption = ImageParameters.LAYER_OPTION_SHOW;
    imageParameters.transparent = true;

    var OrthosLayer = new ArcGISTiledMapServiceLayer(getUrlByName("js_ortho2011Url"), { id: "Orthos", opacity: 0, visible: false });
    map.addLayer(OrthosLayer);
    OrthosLayer.setOpacity(1.0);


    //// Added another tiled map map service layer
    var baseMapLayer = new ArcGISTiledMapServiceLayer(getUrlByName("js_baseMapUrl"), { className: "test", id: "NewName", opacity: 0, visible: true });
    map.addLayer(baseMapLayer);
    baseMapLayer.setOpacity(1.0);

    //legendLayers.push({ layer: baseMapLayer, title: 'City Base Map' });
    var ladbsVisibleLayers = [0,1,2,3,5,7];

    // Modify and Dyanamic Layers
    ladbslayer = new esri.layers.ArcGISDynamicMapServiceLayer(parcelsURL, { id: 'LADBS' });
    ladbslayer.setOpacity(0.90);
    map.addLayer(ladbslayer);
    if (!IsRequestFromPCIS) {
        ladbslayer.setVisibleLayers(ladbsVisibleLayers);
    }
    addToTOC(ladbslayer, true);

    legendLayers.push({ layer: ladbslayer, title: 'LADBS' });

    //Declare or Define editing feature Layer
    searchFeatureLayer = new esri.layers.FeatureLayer(getUrlByName("js_searchFeatureUrl"), {
        id: "BuildingFeature",
        outFields: ["*"]
    });
    //Commenting for production release

    gradingFeatureLayer = new esri.layers.FeatureLayer(getUrlByName("js_gradingFeatureUrl"), {
        id: "GradingFeature",
        outFields: ["*"]
    });

    if (App == "Grading") {
        gradingPointQuickView = dojo.connect(gradingFeatureLayer, "onClick", showGradingFeatureAttributes);

        map.addLayer(gradingFeatureLayer);
    }

    //searchBuildingFeatureUrl = new esri.layers.FeatureLayer(getUrlByName("js_searchBuildingFeatureUrl"), {
    //    id: "SearchBuildingFeature",
    //    outFields: ["*"]
    //});


    bldgType = getURLVars()["bldgType"] !== undefined ? getURLVars()["bldgType"] : '';
    var buildingid = getURLVars()["buildingid"] !== undefined ? getURLVars()["buildingid"] : '';    
    if (bldgType != "" && buildingid != "") {
        //Add feature layer to the Map    
        map.addLayer(searchFeatureLayer);
        addToTOC(searchFeatureLayer, true);
        legendLayers.push({ layer: searchFeatureLayer, title: 'New Features' });

        //map.addLayer(searchBuildingFeatureUrl);
        //addToTOC(searchBuildingFeatureUrl, true);
        //legendLayers.push({ layer: searchBuildingFeatureUrl, title: 'New Building Features' });
    }

    parcelFeatureLayer = new esri.layers.FeatureLayer(getUrlByName("js_parcelsFeatureLayerUrl"), {
        outFields: ["*"]
    });


    // Added another tiled map map service layer
    annotationLayer = new ArcGISTiledMapServiceLayer(getUrlByName("js_annotationUrl"), { id: "Annotation", opacity: 0, visible: true });
    map.addLayer(annotationLayer);
    annotationLayer.setOpacity(1.0);
    addToTOC(annotationLayer, true);

    BuildingSearchFindTask = new FindTask(parcelsURL);
    ParcelSearchFindTask = new FindTask(parcelsURL);

}


//This function provides the adding and editing functionality for the feature layers (Residential, MultiApt and Commercial)
function AddEditFeatureLayers() {

    //Attach onClick even handler for editing feature layer (This onclick event is used for layer editing functionality or showing layer attributes in the infowindow)    
    dojo.connect(searchFeatureLayer, "onClick", showFeatureAttributes);
    isClickHereForExistingBldg = true;
    

    //Setup proxy url, value of the proxy url is coming from the web.config file. This url is used for Adding and Editing functionality for the feature layers 
    esriConfig.defaults.io.proxyUrl = getUrlByName("js_proxyUrl");
    esriConfig.defaults.io.alwaysUseProxy = false;
    //If user wants to add new structure on the map then enable the residential link
    PCIS_bld_id = getURLVars()["buildingid"] !== undefined ? getURLVars()["buildingid"] : '';
    bldgType = getURLVars()["bldgType"] !== undefined ? getURLVars()["bldgType"] : '';
    //Get only number part from the PCIS_bld_id
    bldg_ID = parseInt(PCIS_bld_id);

    drawToolbar = new Draw(map);
    //Setting the addpoint tooltip text by default it shows 'Click to add a point'
    esri.bundle.toolbars.draw.addPoint = "Click to add a new building";

    //Commenting for production release
    gradingClickEvent = dojo.connect(dojo.byId("lnkGrading"), "onclick", function () {
        if (isFeatureLayerClicked) {
            isAddGradingPointClicked = true;
            // $("#lnkGrading").addClass("active");           
            doIdentify = false;
            //map.on("click", executeIdentifyTaskForGrading);
            esri.bundle.toolbars.draw.addPoint = "Select a point on the highlighted parcel";
            drawToolbar.activate(esri.toolbars.Draw.POINT);
            pointDrawEnd = dojo.connect(drawToolbar, "onDrawEnd", addGradingFeaturePoint);

            /***********Hide Parcel quick view popup******************/
            hideSlidingWindow('divParcelQuckiView');
            ///***********Hide partial address search popup******************/
            //hideDialog();

            ////Hide measurement functionality
            hideMeasurementTool();
        }
        else {
            doIdentify = true;
            drawToolbar.deactivate();
            // $("#lnkGrading").removeClass("active");

        }
        isFeatureLayerClicked = !isFeatureLayerClicked;
    });

    gradingReselectClickEvent = dojo.connect(dojo.byId("lnkGradingReselect"), "onclick", function () {
        if (map.graphics != null) {
            doIdentify = true;
            gradingParcels.length = 0
            map.graphics.clear();
            hideSlidingWindow('divParcelQuckiView');
            //add a new feature to the feature layer   
            drawToolbar.deactivate();
            dojo.disconnect(pointDrawEnd);
        }
    });

    dojo.connect(dojo.byId("lnkResidential"), "onclick", function () {        
        $("#divPCISQuckiView").css("display", "block");
        bldgType = "R";       
        dojo.disconnect(residentialClickEvent);
        dojo.disconnect(multiClickEvent);
        dojo.disconnect(commercialClickEvent);
        featureType = residentialFeatureType;
        hideSlidingWindow('divParcelQuckiView');
        residentialClickEvent = dojo.connect(dojo.byId("btnClickHereToAddNewBuilding"), "onclick", function () {

            /***Disconnect the Show feature attributes event ***/
            dojo.disconnect(selectFeaturePoint);
            
                doIdentify = false;
                //set pictometry flag to true
                isPictometryClicked = true;
                $("#lnkresidential").addClass("active");
                $("#lnkresidential").removeClass("highlight");
                drawToolbar.activate(esri.toolbars.Draw.POINT);
                pointDrawEnd = dojo.connect(drawToolbar, "onDrawEnd", addFeaturePoint);

                $('.pictoStyle').css('background', '');
                $('.residStyle').css('background', 'url(/StructuralInventory/images/icn_residential_Selected.png)');

                /***********Hide Parcel quick view popup******************/
                hideSlidingWindow('divParcelQuckiView');
                /***********Hide partial address search popup******************/
                hideDialog();

                //Hide measurement functionality
                hideMeasurementTool();
                //Hide and Disconnect the pictometry functionality
                // Let's use display instead of visibility property to remove entire element
                hidePictometryTool();

           
        });
    });

    dojo.connect(dojo.byId("lnkMultiapt"), "onclick", function () {
        $("#divPCISQuckiView").css("display", "block");
        hideSlidingWindow('divParcelQuckiView');
        bldgType = "M";
        featureType = apartmentFeatureType;
        dojo.disconnect(residentialClickEvent);
        dojo.disconnect(multiClickEvent);
        dojo.disconnect(commercialClickEvent);
        
        multiClickEvent = dojo.connect(dojo.byId("btnClickHereToAddNewBuilding"), "onclick", function () {
            /***Disconnect the Show feature attributes event ***/
            dojo.disconnect(selectFeaturePoint);
           
                //set pictometry flag to true
                isPictometryClicked = true;
                doIdentify = false;
                $("#lnkmultiapt").addClass("active");
                $("#lnkmultiapt").removeClass("highlight");
                drawToolbar.activate(esri.toolbars.Draw.POINT);
                pointDrawEnd = dojo.connect(drawToolbar, "onDrawEnd", addFeaturePoint);

                /***********Hide Parcel quick view popup******************/
                hideSlidingWindow('divParcelQuckiView');
                /***********Hide partial address search popup******************/
                hideDialog();

                //Hide measurement functionality
                hideMeasurementTool();
                //Hide and Disconnect the pictometry functionality
                // Let's use display instead of visibility property to remove entire element
                hidePictometryTool();
           
        });
    });

    dojo.connect(dojo.byId("lnkCommercial"), "onclick", function () {
        hideSlidingWindow('divParcelQuckiView');
        $("#divPCISQuckiView").css("display", "block");
        bldgType = "C";
        featureType = commercialFeatureType;
        dojo.disconnect(residentialClickEvent);
        dojo.disconnect(multiClickEvent);
        dojo.disconnect(commercialClickEvent);
        
        commercialClickEvent = dojo.connect(dojo.byId("btnClickHereToAddNewBuilding"), "onclick", function () {
            /***Disconnect the Show feature attributes event ***/
            dojo.disconnect(selectFeaturePoint);

           
                //set pictometry flag to true
                isPictometryClicked = true;
                doIdentify = false;
                drawToolbar.activate(esri.toolbars.Draw.POINT);
                pointDrawEnd = dojo.connect(drawToolbar, "onDrawEnd", addFeaturePoint);
                $("#lnkcommercial").addClass("active");
                $("#lnkcommercial").removeClass("highlight");
                /***********Hide Parcel quick view popup******************/
                hideSlidingWindow('divParcelQuckiView');
                /***********Hide partial address search popup******************/
                hideDialog();


                //Hide measurement functionality
                hideMeasurementTool();
                //Hide and Disconnect the pictometry functionalityis already assigned t
            
        });
    });

    //Residential Feature Layer
    if ((PCIS_bld_id.toLowerCase() == "new" || bldg_ID.toString().length < 12) && bldgType.toLowerCase() == "r") {
        featureType = residentialFeatureType;

        //Show the editing feature layer
        searchFeatureLayer.show();

        $("#lnkresidential").addClass("highlight");
        $("#lnkmultiapt").removeClass("active");
        $("#lnkcommercial").removeClass("active");
        document.getElementById("lnkresidential").style.cursor = "default";
        $('#lnkmultiapt').css('cursor', 'default !important');
        $('#lnkcommercial').css('cursor', 'default !important');
        $('#lnkresidential').css('cursor', 'pointer');

        residentialClickEvent = dojo.connect(dojo.byId("btnClickHereToAddNewBuilding"), "onclick", function () {
            
            /***Disconnect the Show feature attributes event ***/
            dojo.disconnect(selectFeaturePoint);
            if (isFeatureLayerClicked) {
                doIdentify = false;
                //set pictometry flag to true
                isPictometryClicked = true;
                $("#lnkresidential").addClass("active");
                $("#lnkresidential").removeClass("highlight");
                drawToolbar.activate(esri.toolbars.Draw.POINT);
                pointDrawEnd = dojo.connect(drawToolbar, "onDrawEnd", addFeaturePoint);

                $('.pictoStyle').css('background', '');
                $('.residStyle').css('background', 'url(/StructuralInventory/images/icn_residential_Selected.png)');

                /***********Hide Parcel quick view popup******************/
                hideSlidingWindow('divParcelQuckiView');
                /***********Hide partial address search popup******************/
                hideDialog();

                //Hide measurement functionality
                hideMeasurementTool();
                //Hide and Disconnect the pictometry functionality
                // Let's use display instead of visibility property to remove entire element
                hidePictometryTool();

            }
            else {
                doIdentify = true;
                drawToolbar.deactivate();
                $("#lnkresidential").removeClass("active");

            }
            isFeatureLayerClicked = !isFeatureLayerClicked;
        });
    }

    //Multi/Apt Feature Layer
    if ((PCIS_bld_id.toLowerCase() == "new" || bldg_ID.toString().length < 12) && bldgType.toLowerCase() == "m") {
        featureType = apartmentFeatureType;

        //Show the editing feature layer
        searchFeatureLayer.show();

        $("#lnkmultiapt").addClass("highlight");
        $("#lnkresidential").removeClass("active");
        $("#lnkcommercial").removeClass("active");

        $('#lnkmultiapt').css('cursor', 'pointer');


        multiClickEvent = dojo.connect(dojo.byId("btnClickHereToAddNewBuilding"), "onclick", function () {
            /***Disconnect the Show feature attributes event ***/
            dojo.disconnect(selectFeaturePoint);
            if (isFeatureLayerClicked) {
                //set pictometry flag to true
                isPictometryClicked = true;
                doIdentify = false;
                $("#lnkmultiapt").addClass("active");
                $("#lnkmultiapt").removeClass("highlight");
                drawToolbar.activate(esri.toolbars.Draw.POINT);
                pointDrawEnd = dojo.connect(drawToolbar, "onDrawEnd", addFeaturePoint);

                /***********Hide Parcel quick view popup******************/
                hideSlidingWindow('divParcelQuckiView');
                /***********Hide partial address search popup******************/
                hideDialog();

                //Hide measurement functionality
                hideMeasurementTool();
                //Hide and Disconnect the pictometry functionality
                // Let's use display instead of visibility property to remove entire element
                hidePictometryTool();
            }
            else {
                doIdentify = true;
                drawToolbar.deactivate();
                $("#lnkmultiapt").removeClass("active");

            }
            isFeatureLayerClicked = !isFeatureLayerClicked;
        });
    }

    //Commercial Feature Layer
    if ((PCIS_bld_id.toLowerCase() == "new" || bldg_ID.toString().length < 12) && bldgType.toLowerCase() == "c") {
        featureType = commercialFeatureType;
        //Show the editing feature layer
        searchFeatureLayer.show();

        $("#lnkcommercial").addClass("highlight");
        $("#lnkmultiapt").removeClass("active");
        $("#lnkresidential").removeClass("active");


        $('#lnkcommercial').css('cursor', 'pointer');

        commercialClickEvent = dojo.connect(dojo.byId("btnClickHereToAddNewBuilding"), "onclick", function () {
            /***Disconnect the Show feature attributes event ***/            
            dojo.disconnect(selectFeaturePoint);
            
            if (isFeatureLayerClicked) {
                //set pictometry flag to true
                isPictometryClicked = true;
                doIdentify = false;
                drawToolbar.activate(esri.toolbars.Draw.POINT);
                pointDrawEnd = dojo.connect(drawToolbar, "onDrawEnd", addFeaturePoint);
                $("#lnkcommercial").addClass("active");
                $("#lnkcommercial").removeClass("highlight");
                /***********Hide Parcel quick view popup******************/
                hideSlidingWindow('divParcelQuckiView');
                /***********Hide partial address search popup******************/
                hideDialog();


                //Hide measurement functionality
                hideMeasurementTool();
                //Hide and Disconnect the pictometry functionality
                // Let's use display instead of visibility property to remove entire element
                hidePictometryTool();
            }
            else {
                doIdentify = true;
                drawToolbar.deactivate();
                $("#lnkcommercial").removeClass("active");

            }
            isFeatureLayerClicked = !isFeatureLayerClicked;
        });
    }
}

// Start Legend-----

function Init() {
}

//TOC FUNCTIONS
function addToTOC(layer, listLayers) {
    if (listLayers) {
        if (layer.loaded) {
            //buildLayerList(layer);
            createLayerList(layer);
        }
        else {
            dojo.connect(layer, "onLoad", createLayerList);
            //dojo.connect(layer, "onLoad", buildLayerList);
        }
    }
    else {
        if (layer.loaded) {
            buildLayerListRoot(layer);
        }
        else {
            dojo.connect(layer, "onLoad", buildLayerListRoot);
        }
    }
}
function buildLayerListRoot(layer) {

    var currentLayer = layer;

    tocHTML = "<div style='margin:20px 0px 0px 18px;'><input type='checkbox' style='min-height: 0px;' dojotype='dijit.form.CheckBox' class='TOC_Root' " + (currentLayer.visible ? " CHECKED " : "") + " id='" + currentLayer.id + "' onclick=\"toggleService('" + currentLayer.id + "');\" />&nbsp;&nbsp;<label for='" + currentLayer.id + "'>" + currentLayer.id + "</label><br></div>" + tocHTML;

    dojo.byId("toc").innerHTML = tocHTML;
}
function toggleLayer(id) {
    var layerDiv = dojo.byId(id + 'Layers');
    var icon = dojo.byId(id + 'Icon');
    if (layerDiv.style.display == 'block') {
        icon.src = "/StructuralInventory/images/plus.png";
        layerDiv.style.display = 'none';
    }
    else {
        icon.src = "/StructuralInventory/images/minus.png";
        layerDiv.style.display = 'block';
    }
}
function zoomToLayer(id) {
    var layer = map.getLayer(id);
    if (layer != null) {
        map.setExtent(layer.fullExtent);
    }
}
function buildLayerList(layer) {
    var currentLayer = layer;
    var currentHTML = "";
    currentHTML += "<div style='margin:20px 0px 18px 18px;'><img src='/StructuralInventory/images/plus.png' id='" + currentLayer.id + "Icon' onclick=\"toggleLayer('" + currentLayer.id + "')\" >&nbsp;&nbsp;<input type='checkbox' style='min-height: 0px;' dojotype='dijit.form.CheckBox' class='TOC_Root' " + (currentLayer.visible ? " CHECKED " : "") + " id='" + currentLayer.id + "' onclick=\"toggleService('" + currentLayer.id + "');\" />&nbsp;&nbsp;<label for='" + currentLayer.id + "'>" + currentLayer.id + "</label><br></div>";
    var subLayers = currentLayer.layerInfos;

    currentHTML += "<div id='" + currentLayer.id + "Layers' style='display:none;margin:20px 0px 18px 42px;'>";
    for (var i = 0; i < subLayers.length; i++) {
        var currentSubLayer = subLayers[i];
        if (currentSubLayer.defaultVisibility) {
            visible.push(currentSubLayer.id);
        }
        currentHTML += "<input type='checkbox' style='min-height: 0px;' class='" + currentLayer.id + "TOC' " + (currentSubLayer.defaultVisibility ? " CHECKED " : "") + " id='" + currentSubLayer.id + "' onclick=\"updateLayerVisibility('" + currentLayer.id + "','" + currentSubLayer.id + "');\" />&nbsp;&nbsp;<label for='" + currentSubLayer.id + "'>" + currentSubLayer.name + "</label><br>";
    }
    currentHTML += "</div>";
    tocHTML = currentHTML + tocHTML;
    dojo.byId("toc").innerHTML = tocHTML;
}



function createLayerList(layer) {
    //if (layer.id == "LADBS") {
    //    methaneLayers.length = 0;        
    //    roadLayers.length = 0;
    //    hillsideLayers.length = 0;
    //    var currentLayer = layer;
    //    var subLayers = currentLayer.layerInfos;

    //    for (var i = 0; i < subLayers.length; i++) {
    //        var currentSubLayer = subLayers[i];

    //        if (currentSubLayer.defaultVisibility) {
    //            visibleLayers.push(currentSubLayer.id);
    //        }

    //        if (currentSubLayer.id == 16 || currentSubLayer.id == 17) {
    //            methaneLayers.push(currentSubLayer);
    //        }

    //        if (currentSubLayer.id == 7) {
    //            roadLayers.push(currentSubLayer);
    //        }

    //        if (currentSubLayer.id == 14 || currentSubLayer.id == 15) {
    //            hillsideLayers.push(currentSubLayer);
    //        }


    //    }
    //}


    //    var currentLayer = layer;
    //    var subLayers = currentLayer.layerInfos;
    //    var currentHTML = "";
    //    var propertyBoundariesLayers = [];
    //    var roads = [];
    //    var censusInformation = [];
    //    var zoning = [];
    //    var sewer = [];
    //    var miscellaneous = [];
    //    var annotationLayer = [];
    //    var divPropertyBoundaries = document.getElementById("divPropertyBoundaries");
    //    var tableProperty = document.createElement('TABLE');
    //    var tableBodyProperty = document.createElement('TBODY');
    //    tableProperty.appendChild(tableBodyProperty);


    //    if (currentLayer.id == "LADBS") {
    //        for (var i = 0; i < subLayers.length; i++) {
    //            var currentSubLayer = subLayers[i];
    //            if (currentSubLayer.defaultVisibility) {
    //                visible.push(currentSubLayer.id);
    //            }

    //            if (currentSubLayer.id == 0 || currentSubLayer.id == 1 || currentSubLayer.id == 2 || currentSubLayer.id == 3 || currentSubLayer.id == 4) {
    //                propertyBoundariesLayers.push(currentSubLayer);
    //            }


    //            if (currentSubLayer.id == 5 || currentSubLayer.id == 6 || currentSubLayer.id == 7) {
    //                roads.push(currentSubLayer);
    //            }

    //            if (currentSubLayer.id == 8) {
    //                censusInformation.push(currentSubLayer);
    //            }


    //            if (currentSubLayer.id == 9) {
    //                zoning.push(currentSubLayer);
    //            }

    //            if (currentSubLayer.id == 10 || currentSubLayer.id == 11 || currentSubLayer.id == 12 || currentSubLayer.id == 13) {
    //                sewer.push(currentSubLayer);
    //            }


    //            if (currentSubLayer.id == 14 || currentSubLayer.id == 15 || currentSubLayer.id == 16 || currentSubLayer.id == 17 || currentSubLayer.id == 18) {
    //                miscellaneous.push(currentSubLayer);
    //            }

    //        }


    //        //Generate layer grouping for Property Boundaries
    //        generateLayerGroupings(currentLayer, propertyBoundariesLayers, tableBodyProperty, "Property Boundaries");
    //        divPropertyBoundaries.appendChild(tableProperty);



    //        var divRoads = document.getElementById("divRoads");

    //        var tableRoads = document.createElement('TABLE');

    //        var tableBodyRoads = document.createElement('TBODY');
    //        tableRoads.appendChild(tableBodyRoads);

    //        //Generate layer grouping for Roads
    //        generateLayerGroupings(currentLayer, roads, tableBodyRoads, "Roads");

    //        ////Generate layer grouping for Census Information
    //        generateLayerGroupings(currentLayer, censusInformation, tableBodyRoads, "Census Information");

    //        divRoads.appendChild(tableRoads);



    //        var divZoning = document.getElementById("divZoning");

    //        var tableZoning = document.createElement('TABLE');

    //        var tableBodyZoning = document.createElement('TBODY');
    //        tableZoning.appendChild(tableBodyZoning);

    //        ////Generate layer grouping for Zoning
    //        generateLayerGroupings(currentLayer, zoning, tableBodyZoning, "Zoning");

    //        ////Generate layer grouping for Sewer
    //        generateLayerGroupings(currentLayer, sewer, tableBodyZoning, "Sewer");
    //        divZoning.appendChild(tableZoning);

    //        var divMisc = document.getElementById("divMisc");

    //        var tableMisc = document.createElement('TABLE');

    //        var tableBodyMisc = document.createElement('TBODY');
    //        tableMisc.appendChild(tableBodyMisc);
    //        ////Generate layer grouping for Miscellaneous
    //        generateLayerGroupings(currentLayer, miscellaneous, tableBodyMisc, "Miscellaneous");
    //        divMisc.appendChild(tableMisc);


    //    }   

    //    if (currentLayer.id == "Annotation") {

    //        var currentSubLayer;
    //        //for (var i = 0; i < subLayers.length; i++) {
    //            var currentSubLayer = subLayers[0];
    //            if (currentSubLayer.defaultVisibility) {
    //                visible.push(currentSubLayer.id);
    //            }            
    //       // }


    //        var tr = document.createElement('TR');
    //        tableBodyProperty.appendChild(tr);

    //        var td = document.createElement('TD');
    //        td.setAttribute("class", "tdLayerClass");
    //        //td.width = '75';
    //        var chkbox = document.createElement('input');
    //        chkbox.type = "checkbox";
    //        chkbox.id = currentSubLayer.id;
    //        chkbox.setAttribute("class", currentLayer.id + "TOC");
    //        chkbox.onclick = new Function("updateLayerVisibility('" + currentLayer.id + "','" + currentSubLayer.id + "');");
    //        chkbox.checked = (currentSubLayer.defaultVisibility ? " CHECKED " : "");

    //        td.appendChild(chkbox);
    //        tr.appendChild(td);

    //        var td1 = document.createElement('TD');
    //        td1.setAttribute("class", "tdLayerClass");
    //        //td1.width = '75';

    //        var label = document.createElement("label");
    //        label.for = currentSubLayer.id;
    //        label.appendChild(document.createTextNode("Lot Numbers & Property Dimensions"));
    //        td1.appendChild(label);

    //        var image = document.createElement("img");
    //        image.setAttribute('src', '/StructuralInventory/Images/help_icon_sm.jpg');
    //        image.setAttribute('alt', 'na');
    //        image.setAttribute('class', 'popoverThis');
    //        image.setAttribute('id', 'imgHelp_' + currentSubLayer.id);
    //        image.setAttribute('data-toggle', 'popover');
    //        image.setAttribute('data-content', ValidationMessages.lotNumberHelpText);
    //        image.setAttribute('data-html', 'true');
    //        image.setAttribute('data-title', '<button type="button" id="close" class="close" onclick="$(\'[data-toggle=&quot;popover&quot;]\').popover(&quot;hide&quot;);">&times;</button>');
    //        image.onclick = function (e) {
    //            $('.popover').not(this).hide();
    //        };

    //        $(document).ready(function () {
    //            $('[data-toggle="popover"]').popover();

    //            $(document).click(function (e) {
    //                if (($('.popover').has(e.target).length == 0) || $(e.target).is('.close')) {
    //                    $('#imgHelp_' + currentSubLayer.id).popover('hide');
    //                }
    //            });
    //        });

    //        td1.appendChild(image);


    //        tr.appendChild(td1);



    //       // divPropertyBoundaries.appendChild(tableProperty);

    //    }

    //    if (currentLayer.id == "BuildingFeature") {

    //        if (currentLayer.defaultVisibility) {
    //            visible.push(currentLayer.id);
    //        }




    //        var tr = document.createElement('TR');
    //        tableBodyProperty.appendChild(tr);

    //        var td = document.createElement('TD');
    //        td.setAttribute("class", "tdLayerClass");
    //        //td.width = '75';
    //        var chkbox = document.createElement('input');
    //        chkbox.type = "checkbox";
    //        chkbox.id = currentLayer.id;
    //        chkbox.setAttribute("class", currentLayer.id + "TOC");
    //        chkbox.onclick = new Function("updateLayerVisibility('" + currentLayer.id + "','" + currentLayer.id + "');");
    //        chkbox.checked = (currentLayer.defaultVisibility ? " CHECKED " : "");

    //        td.appendChild(chkbox);
    //        tr.appendChild(td);

    //        var td1 = document.createElement('TD');
    //        td1.setAttribute("class", "tdLayerClass");
    //        //td1.width = '75';

    //        var label = document.createElement("label");
    //        label.for = currentLayer.id;
    //        label.appendChild(document.createTextNode("Buildings To Be Constructed"));
    //        td1.appendChild(label);

    //        var image = document.createElement("img");
    //        image.setAttribute('src', '/StructuralInventory/Images/help_icon_sm.jpg');
    //        image.setAttribute('alt', 'na');
    //        image.setAttribute('class', 'popoverThis');
    //        image.setAttribute('id', 'imgHelp_' + currentLayer.id);
    //        image.setAttribute('data-toggle', 'popover');
    //        image.setAttribute('data-content', ValidationMessages.buildingToBeConstrHelpText);
    //        image.setAttribute('data-html', 'true');
    //        image.setAttribute('data-title', '<button type="button" id="close" class="close" onclick="$(\'[data-toggle=&quot;popover&quot;]\').popover(&quot;hide&quot;);">&times;</button>');
    //        image.onclick = function (e) {
    //            $('.popover').not(this).hide();
    //        };

    //        $(document).ready(function () {
    //            $('[data-toggle="popover"]').popover();

    //            $(document).click(function (e) {
    //                if (($('.popover').has(e.target).length == 0) || $(e.target).is('.close')) {
    //                    $('#imgHelp_' + currentLayer.id).popover('hide');
    //                }
    //            });
    //        });

    //        td1.appendChild(image);


    //        tr.appendChild(td1);



    //        divPropertyBoundaries.appendChild(tableProperty);

    //    }
}

function generateLayerGroupings(parentLayer, subLayers, tableBody, groupHeader) {

    for (var i = 0; i < subLayers.length; i++) {
        if (i == 0) {
            var trHeader = document.createElement('TR');
            tableBody.appendChild(trHeader);
            var tdHeader = document.createElement('TD');
            tdHeader.setAttribute("class", "tdLayerHeaderClass");
            tdHeader.setAttribute("colspan", "2");

            var labelHeader = document.createElement("label");
            labelHeader.setAttribute("class", "tdLayerHeaderClass");

            //if (groupHeader == "Property Boundaries") {

            //    var selectAll = document.createElement("a");
            //    selectAll.setAttribute("id", "selectAllLADBS");
            //    selectAll.setAttribute("class", "selectAll");
            //    selectAll.innerHTML = "Select All";
            //    labelHeader.appendChild(document.createTextNode(groupHeader + " "));
            //    labelHeader.appendChild(selectAll);
            //}
            //else {
            labelHeader.appendChild(document.createTextNode(groupHeader));
            //}
            tdHeader.appendChild(labelHeader);
            trHeader.appendChild(tdHeader);
        }

        var currentSubLayer = subLayers[i];
        var tr = document.createElement('TR');
        tableBody.appendChild(tr);

        var td = document.createElement('TD');
        td.setAttribute("class", "tdLayerClass");
        //td.width = '75';
        var chkbox = document.createElement('input');
        chkbox.type = "checkbox";
        chkbox.id = currentSubLayer.id;
        chkbox.setAttribute("class", parentLayer.id + "TOC");
        chkbox.onclick = new Function("updateLayerVisibility('" + parentLayer.id + "','" + currentSubLayer.id + "');");
        chkbox.checked = (currentSubLayer.defaultVisibility ? " CHECKED " : "");

        td.appendChild(chkbox);
        tr.appendChild(td);

        var td1 = document.createElement('TD');
        td1.setAttribute("class", "tdLayerClass");
        //td1.width = '75';

        var label = document.createElement("label");
        label.for = currentSubLayer.id;
        label.appendChild(document.createTextNode(currentSubLayer.name));
        td1.appendChild(label);

        createHelpText(currentSubLayer, td1);


        tr.appendChild(td1);


    }

}

function createHelpText(currentSubLayer, td1) {
    var helpText = "";
    var image = document.createElement("img");
    image.setAttribute('src', '/StructuralInventory/Images/help_icon_sm.jpg');
    image.setAttribute('alt', 'na');
    //image.setAttribute('height', '25px');
    //image.setAttribute('width', '25px');
    image.setAttribute('class', 'popoverThis');


    image.setAttribute('id', 'imgHelp_' + currentSubLayer.id);

    switch (currentSubLayer.id) {
        case 0:
            helpText = ValidationMessages.addressLabelHelpText;
            break;
        case 1:
            helpText = ValidationMessages.propertyLineHelpText;
            break;
        case 2:
            helpText = ValidationMessages.cityBoundaryHelpText;
            break;
        case 3:
            helpText = ValidationMessages.buildingOutlineHelpText;
            break;
        case 4:
            helpText = ValidationMessages.councilDistrictHelpText;
            break;
        case 5:
            helpText = ValidationMessages.cityStreetsHelpText;
            break;
        case 6:
            helpText = ValidationMessages.cityStreetsWidthHelpText;
            break;
        case 7:
            helpText = ValidationMessages.freewaysHelpText;
            break;
        case 8:
            helpText = ValidationMessages.censusTractHelpText;
            break;
        case 9:
            helpText = ValidationMessages.zonesHelpText;
            break;
        case 10:
            helpText = ValidationMessages.sewerLinesHelpText;
            break;
        case 11:
            helpText = ValidationMessages.lateralsHelpText;
            break;
        case 12:
            helpText = ValidationMessages.easementHelpText;
            break;
        case 13:
            helpText = ValidationMessages.flowDirectionHelpText;
            break;
        case 14:
            helpText = ValidationMessages.hillsideOrdinanceHelpText;
            break;
        case 15:
            helpText = ValidationMessages.hillsideGradingHelpText;
            break;
        case 16:
            helpText = ValidationMessages.methaneZoneHelpText;
            break;
        case 17:
            helpText = ValidationMessages.methaneBufferZoneHelpText;
            break;
        case 18:
            helpText = ValidationMessages.countourLinesHelpText;
            break;

    }

    image.setAttribute('data-toggle', 'popover');
    image.setAttribute('data-content', helpText);
    image.setAttribute('data-html', 'true');
    image.setAttribute('data-title', '<button type="button" id="close" class="close" onclick="$(\'[data-toggle=&quot;popover&quot;]\').popover(&quot;hide&quot;);">&times;</button>');

    image.onclick = function (e) {
        $('.popover').not(this).hide();
        //  $(this).popover(popOverSettings);        
        //$('.popoverThis').not(this).popover('hide');
    };

    $(document).ready(function () {
        $('[data-toggle="popover"]').popover();

        $(document).click(function (e) {
            if (($('.popover').has(e.target).length == 0) || $(e.target).is('.close')) {
                $('#imgHelp_' + currentSubLayer.id).popover('hide');
            }
        });
    });

    td1.appendChild(image);


    //$('#imgHelp_' + currentSubLayer.id).popover({
    //    html: true,
    //    title: 'All addresses within the City of Los Angeles.',
    //    content: function () {
    //        return "All addresses within the City of Los Angeles.";
    //    }
    //});





}



Array.prototype.contains = function (element) {
    return this.indexOf(element) > -1;
};


function updateLayerVisibility(serviceID, layerid) {

    var inputs = dojo.query("." + serviceID + "TOC"), input;
    visible = [];
    for (var i = 0, il = inputs.length; i < il; i++) {
        if (inputs[i].checked) {
            visible.push(inputs[i].id);
        }

    }
    var layer = map.getLayer(serviceID);

    layer.setVisibility(true);

    if (serviceID != "Annotation" && serviceID != "BuildingFeature") {

        layer.setVisibleLayers(visible);
    }
    else if (serviceID == "BuildingFeature" || serviceID == "Annotation") {
        if (visible.contains("" + layerid + "")) {
            layer.show();
        }
        else {
            layer.hide();
        }
    }
    else {
        for (var j = 0; j < layer.layerInfos.length; j++) {
            if (visible.contains("" + layer.layerInfos[j].id + "")) {
                layer.layerInfos[j].defaultVisibility = true;
            }
            else {
                layer.layerInfos[j].defaultVisibility = false;
            }

        }

        layer.refresh();

    }



    /******************Ses the visibility of the legends based on layer visibility or selection*************************/
    for (var i = 0; i < legendLayers.length; i++) {

        var leglayer = legendLayers[i];
        if (leglayer.title == serviceID) {
            for (var j = 0; j < leglayer.layer.layerInfos.length; j++) {

                if (visible.contains("" + leglayer.layer.layerInfos[i].id + "")) {
                    leglayer.layer.layerInfos[j].defaultVisibility = true;

                }
                else {
                    leglayer.layer.layerInfos[j].defaultVisibility = false;

                }

            }

        }

    }


}

function toggleService(layerID) {
    var layer = map.getLayer(layerID);
    if (layer.visible) {
        layer.hide();
    }
    else {
        layer.show();
    }
}
//END TOC FUNCTIONS
//**************************************************************
//**************************************************************

dojo.addOnLoad(Init);

// End Legend

window.addEventListener("keydown", keysPressed, false);
window.addEventListener("keyup", keysReleased, false);

var keys = [];

function keysPressed(e) {
    // store an entry for every key pressed
    keys[e.keyCode] = true;

    // Ctrl + Shift + 1
    if (keys[17] && keys[16] && keys[49]) {
        environment = 1;
        $(".zone-header").css("background-color", "#00CCCC");
    }
    // Ctrl + Shift + 2
    if (keys[17] && keys[16] && keys[50]) {
        environment = 2;
        $(".zone-header").css("background-color", "#FF9933");
    }
    // Ctrl + Shift + 1
    if (keys[17] && keys[16] && keys[51]) {
        environment = 3;
        $(".zone-header").css("background-color", "#FFFFFF");
    }

}

function keysReleased(e) {
    // mark keys that were released
    keys[e.keyCode] = false;
}
function loadPictometryHost() {
    IPA = new PictometryHost("pictometry_ipa", PictometryURL);
    IPA.setZoomLevel(20);
    IPA.ready = function () {
        activatePictometry();
    }
    setTimeout(PictInfo, 1000);
}

function PictInfo() {
    var iframe = document.getElementById('pictometry_ipa');
    iframe.setAttribute('src', PictometryURL);

}

//Created this function in improve map load speed
function createLegend() {

    if (legend === undefined) {

        legend = new esri.dijit.Legend({
            map: map,
            layerInfos: legendLayers
        }, "legendDiv");


        legend.startup();
    }
    //if (toc === undefined) {
    //    toc = new Toc({
    //        map: map,
    //        layerInfos: [{
    //            layer: ladbslayer,
    //            title: "LADBS"
    //        }, {
    //            layer: annotationLayer,
    //            title: "Annotation"
    //            //collapsed: false, // whether this root layer should be collapsed initially, default false.
    //            //slider: false // whether to display a transparency slider.
    //        }]
    //    }, 'legendDiv');
    //    toc.startup();
    //}    
    //if (toc === undefined) {
    //    toc = new Toc({
    //        map: map,
    //        layerInfos: legendLayers
    //    }, 'legendDiv');
    //    toc.startup();
    //}
    //var img;
    //url = "http://10.8.35.252:6080/arcgis/rest/services/Map_Viewer_data_TEST/MapServer/legend?f=json&pretty=true";
    //$.ajax({
    //    dataType: "json",
    //    url: url,            
    //    success: function (data) {                

    //        for (var i = 0; i <= 1 ; i++)
    //        {
    
    //            for (var k = 0; k <= data.layers[0].legend.length; k++) {

    //                data.layers[0].legend[0].imageData;
    //                data.layers[0].legend[0].height;
    //                data.layers[0].legend[0].width;
    
    //                img = "<img src='data:image/png;base64,'"+ data.layers[0].legend[0].imageData +"/>";
    //            }

    //        }

    //    }
    //});

    //$("#legendDiv").append(img);

    //var i = 0;
    //if (legend === undefined) {
    //    //if (i > 0) {
    //    //    //legend.destroy();
    //    //    legend.refresh();
    //    //}
    //    //else {
    //        legend = new esri.dijit.Legend({
    //            map: map,                
    //            layerInfos: legendLayers
    //            //respectCurrentMapScale: false
    //        }, "legendDiv");

    //        legend.startup();
    //    //}
    //    //i++;
    //}
    //Add Legendon MAP
}
$(document).ready(function () { require(mapfunctionality, InitializeMap); });
