WME Place Interface Enhancements

Enhancements to various Place interfaces

Verze ze dne 25. 04. 2017. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         WME Place Interface Enhancements
// @namespace    https://greatest.deepsurf.us/users/30701-justins83-waze
// @version      0.10.00
// @description  Enhancements to various Place interfaces
// @include      https://www.waze.com/editor/*
// @include      https://www.waze.com/*/editor/*
// @include      https://beta.waze.com/*
// @exclude      https://www.waze.com/user/editor*
// @icon         data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAEAAQADAREAAhEBAxEB/8QAHQABAAEFAQEBAAAAAAAAAAAAAAUBAwQGBwIICf/EAEAQAAICAQICBQgHBwQCAwAAAAABAgMEBREGMRIhQVFhBxMUIjJScYEXI0JUkZLBCBVVYpOh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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP//Z
// @author       JustinS83
// @grant        none
// @require      https://greatest.deepsurf.us/scripts/24851-wazewrap/code/WazeWrap.js
// @license      GPLv3
// ==/UserScript==
var UpdateObject, MultiAction;

(function() {
    'use strict';

    var settings = {};
    var placeMenuSelector = "#edit-buttons > div > div.toolbar-button.waze-icon-place.toolbar-submenu.toolbar-group.toolbar-group-venues.ItemInactive > menu";
    var pointStyle = {
			pointRadius: 6,
			fillOpacity: 0,
			strokeColor: '#00ece3',
			strokeWidth: '2',
			strokeLinecap: 'round'
		};
    var layerName = "WME PIE";
    var newPlaceLayer;
    var placementMode = false;
    var drawPoly;
    var resCategory = "RESIDENCE_HOME";
    var PIEPlaceNameLayer;

    function bootstrap(tries) {
        tries = tries || 1;

        if (window.W &&
            window.W.map &&
            window.W.model &&
            window.W.loginManager.user &&
            $) {
            init();
        } else if (tries < 1000) {
            setTimeout(function () {bootstrap(tries++);}, 200);
        }
    }

    bootstrap();

    function init(){
        loadTranslations();


        var $section = $("<div>", {style:"padding:8px 16px", id:"WMEPIESettings"});
        $section.html([
            '<h4><b>' + I18n.t('pie.prefs.title') + '</b></h4>',
            '<div class="controls-container pie-controls-container" id="divAreaPlaceSizeControls">',
            '<div id="divShowAreaPlaceSize" class="controls-container pie-controls-container"><input type="checkbox" id="_cbShowAreaPlaceSize" class="pieSettingsCheckbox" /><label for="_cbShowAreaPlaceSize">' + I18n.t('pie.prefs.ShowAreaPlaceSize') + '</label></div>',
            '<div id="divShowAreaPlaceSizeImperial"class="controls-container pie-controls-container" style="padding-left:20px;"><input type="checkbox" id="_cbShowAreaPlaceSizeImperial" class="pieSettingsCheckbox" disabled /><label for ="_cbShowAreaPlaceSizeImperial">' + I18n.t('pie.prefs.ShowImperial') + '</label></div>',
            '<div id="divShowAreaPlaceSizeMetric" class="controls-container pie-controls-container" style="padding-left:20px;"><input type="checkbox" id="_cbShowAreaPlaceSizeMetric" class="pieSettingsCheckbox" disabled /><label for ="_cbShowAreaPlaceSizeMetric">' + I18n.t('pie.prefs.ShowMetric') + '</label></div>',
            '</div>',
            '<div class="controls-container pie-controls-container" id="divShowLockButtonsRPP" title="' + I18n.t('pie.prefs.ShowRPPLockButtonsTitle') + '"><input type="checkbox" id="_cbShowLockButtonsRPP" class="pieSettingsCheckbox" /><label for="_cbShowLockButtonsRPP">' + I18n.t('pie.prefs.ShowRPPLockButtons') + '</label></div>',
            '<div class="controls-container pie-controls-container" id="divShowPlaceLocatorCrosshair" title="' + I18n.t('pie.prefs.ShowPlaceLocatorCrosshairTitle') + '" ><input type="checkbox" id="_cbShowPlaceLocatorCrosshair" class="pieSettingsCheckbox" /><label for="_cbShowPlaceLocatorCrosshair">' + I18n.t('pie.prefs.ShowPlaceLocatorCrosshair') + '</label></br>',
            '<span class="controls-container pie-controls-container" style="padding-left:30px;" title="' + I18n.t('pie.prefs.ZoomTitle') + '">' + I18n.t('pie.prefs.ShowAreaPlaceSize') + '<select id="piePlaceZoom"><option value="10">10</option><option value="9">9</option><option value="8">8</option><option value="7">7</option><option value="6">6</option><option value="5">5</option><option value="4">4</option><option value="3">3</option><option value="2">2</option><option value="1">1</option><option value="0">0</option></select></span></div>',
            '<div class="controls-container pie-controls-container" id="divShowSearchButton" title="' + I18n.t('pie.prefs.ShowAddressSearchTitle') + '"><input type="checkbox" id="_cbShowSearchButton" class="pieSettingsCheckbox"/><label for="_cbShowSearchButton" style="white-space:pre-line;">' + I18n.t('pie.prefs.ShowAddressSearch') + '</label></div>',
            '<div class="controls-container pie-controls-container" id="divAddPlaceCategoriesButtons"><input type="checkbox" id="_cbAddPlaceCategoriesButtons" class="pieSettingsCheckbox"/><label for="_cbAddPlaceCategoriesButtons" style="white-space:pre-line;">' + I18n.t('pie.prefs.ShowPlaceCategoryButtons') + '</label></div>',
            '<div class="controls-container pie-controls-container" id="divShowParkingLotButton" title="' + I18n.t('pie.prefs.ShowPLAButtonTitle') + '" ><input type="checkbox" id="_cbShowParkingLotButton" class="pieSettingsCheckbox" /><label for="_cbShowParkingLotButton">' + I18n.t('pie.prefs.ShowPLAButton') + '</label></div>',
            '<div class="controls-container pie-controls-container" id="divShowCopyPlaceButton" title="' + I18n.t('pie.prefs.ShowCopyPlaceButtonTitle') + '" ><input type="checkbox" id="_cbShowCopyPlaceButton" class="pieSettingsCheckbox" /><label for="_cbShowCopyPlaceButton">' + I18n.t('pie.prefs.ShowCopyPlaceButton') + '</label></div>',
            '<div class="controls-container pie-controls-container" id="divShowExternalProviderTooltip" title="' + I18n.t('pie.prefs.ShowGPIDTooltipTitle') + '" ><input type="checkbox" id="_cbShowExternalProviderTooltip" class="pieSettingsCheckbox" /><label for="_cbShowExternalProviderTooltip">' + I18n.t('pie.prefs.ShowGPIDTooltip') + '</label></div>',

            '<fieldset id="fieldNewPlaces" style="border: 1px solid silver; padding: 8px; border-radius: 4px;">',
            '<legend style="margin-bottom:0px; border-bottom-style:none;width:auto;"><h4>' + I18n.t('pie.prefs.NewPlaces') + '</h4></legend>',
            '<div id="divEditRPPAfterCreated" class="controls-container pie-controls-container" title="' + I18n.t('pie.prefs.EditRPPAfterCreateTitle') + '"><input type="checkbox" id="_cbEditRPPAfterCreated" class="pieSettingsCheckbox"><label for="_cbEditRPPAfterCreated" style="white-space:pre-line;">' + I18n.t('pie.prefs.EditRPPAfterCreate') + '</label></div>',
            '<div id="divUseStreetFromClosestSeg" class="controls-container pie-controls-container" title="' + I18n.t('pie.prefs.UseStreetFromClosestSegmentTitle') + '"><input type="checkbox" id="_cbUseStreetFromClosestSeg" class="pieSettingsCheckbox"><label for="_cbUseStreetFromClosestSeg" style="white-space:pre-line;">' + I18n.t('pie.prefs.UseStreetFromClosestSegment') + '</label></div>',
            '<div id="divUseCityFromClosestSeg" class="controls-container pie-controls-container" title="' + I18n.t('pie.prefs.UseCityFromClosestSegmentTitle') + '"><input type="checkbox" id="_cbUseCityFromClosestSeg" class="pieSettingsCheckbox"><label for="_cbUseCityFromClosestSeg" style="white-space:pre-line;">' + I18n.t('pie.prefs.UseCityFromClosestSegment') + '</label></div>',
            '<div id="divUseAltCity" class="controls-container pie-controls-container" title="' + I18n.t('pie.prefs.ClosestSegmentAltCityTitle') + '" style="padding-left:20px; word-wrap: break-word;"><input type="checkbox" id="_cbUseAltCity" class="pieSettingsCheckbox"><label for="_cbUseAltCity" style="white-space:pre-line;">' + I18n.t('pie.prefs.ClosestSegmentAltCity') + '</label></div>',
            '<div id="divSkipPLR" class="controls-container pie-controls-container" title="' + I18n.t('pie.prefs.ClosestSegmentIgnorePLRUnnamedPRTitle') + '"><input type="checkbox" id="_cbSkipPLR" class="pieSettingsCheckbox"/><label for="_cbSkipPLR" style="white-space:pre-line;">' + I18n.t('pie.prefs.ClosestSegmentIgnorePLRUnnamedPR') + '</label></div>',
            '<div id="divDefaultLockLevel" class="controls-container pie-controls-container" style="left:8px;" title="' + I18n.t('pie.prefs.LockLevelTitle') + '">' + I18n.t('pie.prefs.LockLevel') + '<select id="pieDefaultLockLevel">' + buildLockLevelsList() + '</select></div>',
            '</fieldset>',

            '<fieldset id="fieldMapMods" style="border: 1px solid silver; padding: 8px; border-radius: 4px;">',
            '<legend style="margin-bottom:0px; border-bottom-style:none;width:auto;"><h4>' + I18n.t('pie.prefs.MapChanges') + '</h4></legend>',
            '<div id="divShowNames" class="controls-container pie-controls-container" title="' + I18n.t('pie.prefs.ShowPlaceNames') + '"><input type="checkbox" id="_cbShowPlaceNames" class="pieSettingsCheckbox" /><label for="_cbShowPlaceNames">' + I18n.t('pie.prefs.ShowPlaceNames') + '</label></div>',
            '<div id="divShowNamesPoint"class="controls-container pie-controls-container" style="padding-left:20px;" title="' + I18n.t('pie.prefs.ShowPointNamesTitle') + '"><input type="checkbox" id="_cbShowPlaceNamesPoint" class="pieSettingsCheckbox" disabled /><label for ="_cbShowPlaceNamesPoint">' + I18n.t('pie.prefs.ShowPointNames') + '</label></div>',
            '<div id="divShowNamesArea"class="controls-container pie-controls-container" style="padding-left:20px;" title="' + I18n.t('pie.prefs.ShowAreaNamesTitle') + '"><input type="checkbox" id="_cbShowPlaceNamesArea" class="pieSettingsCheckbox" disabled /><label for ="_cbShowPlaceNamesArea">' + I18n.t('pie.prefs.ShowAreaNames') + '</label></div>',
            '<div id="divShowNamesPLA"class="controls-container pie-controls-container" style="padding-left:20px;" title="' + I18n.t('pie.prefs.ShowPLANameTitle') + '"><input type="checkbox" id="_cbShowPlaceNamesPLA" class="pieSettingsCheckbox" disabled /><label for ="_cbShowPlaceNamesPLA">' + I18n.t('pie.prefs.ShowPLAName') + '</label></div>',
            '<div id="divShowNamesLock"class="controls-container pie-controls-container" style="padding-left:20px;" title="' + I18n.t('pie.prefs.ShowLockLevelTitle') + '"><input type="checkbox" id="_cbShowPlaceNamesLock" class="pieSettingsCheckbox" disabled /><label for ="_cbShowPlaceNamesLock">' + I18n.t('pie.prefs.ShowLockLevel') + '</label></div>',
            '</fieldset>',
            '<div class="controls-container" id="divPlaceMenuCustomization">',
            '<b>' + I18n.t('pie.prefs.PlaceMenuCustomization') + '</b></br>',
            buildItemOption(1),
            buildItemOption(2),
            buildItemOption(3),
            buildItemOption(4),
            buildItemOption(5),
            buildItemOption(6),
            buildItemOption(7),
            buildItemOption(8),
            buildItemOption(9),
            buildItemOption(10),
            buildItemOption(11),
            '</div>'

        ].join(' '));

        UpdateObject = require("Waze/Action/UpdateObject");
        MultiAction = require("Waze/Action/MultiAction");

        newPlaceLayer = new OL.Layer.Vector(layerName,{displayInLayerSwitcher: false});
		W.map.addLayer(newPlaceLayer);

        var style = new OpenLayers.Style({
            pointRadius: "${pointRadius}",
            label : "${labelText}",
            fontFamily: "Tahoma, Arial, Verdana",
            labelOutlineColor: '#FFEEEE',
            labelOutlineWidth: 2,
            labelAlign: 'cm',
            fontColor: "#301130",
            fontOpacity: 1.0,
            fontSize: "12px",
            labelYOffset: "${yOffset}",
            fontStyle: "${style}",
            pointRadius: 0
        });

        PIEPlaceNameLayer = new OL.Layer.Vector("PIEPlaceNameLayer",{displayInLayerSwitcher: false,
            uniqueName: "__PIEPlaceNameLayer", styleMap: new OL.StyleMap(style)});
        W.map.addLayer(PIEPlaceNameLayer);
        PIEPlaceNameLayer.setVisibility(true);

        injectCss();
        new WazeWrap.Interface.Tab('PIE', $section.html(), init2);
    }

    function buildNewPlaceList(){
        //Clear out the Places menu
        $(placeMenuSelector).empty();
        var cat = "";
        var icon = "";
        var i;
        for(i=0;i<11;i++){
            icon = "";
            cat = $('#pieItem' + (i+1))[0].value;
            icon = $('#pieItem' + (i+1))[0].options[$('#pieItem' + (i+1))[0].selectedIndex].getAttribute("data-icon");
            if(cat !== "PARKING_LOT" && cat !== resCategory)
                $(placeMenuSelector).append('<div class="toolbar-group-item WazeControlDrawFeature ItemInactive" style="' + (icon !== "" ? "padding-left:0px;" : "") + ' height:40px;" id="piePlaceMainItem' + (i+1) + '" data-category="'+ cat + '"><span class="menu-title ' + icon + '" style="font-size:26px;"><span style="font-size:12px;">' + $('#pieItem' + (i+1))[0].options[$('#pieItem' + (i+1))[0].selectedIndex].innerHTML + '</span></span><div class="drawing-controls"><span class="drawing-control polygon secondary-control" id="piePlaceAreaItem' + (i+1) + '" data-category="' + cat + '" title="Place (area)"></span><span class="drawing-control main-control point" id="piePlacePointItem' + (i+1) + '" data-category="' + cat + '" title="Place (point)"></span></div></div>');
            else{
                if(cat === resCategory) //force point
                    $(placeMenuSelector).append('<div class="toolbar-group-item WazeControlDrawFeature ItemInactive" style="padding-left:0px; height:40px;" id="piePlaceMainItem' + (i+1) + '" data-category="'+ cat + '"><span class="menu-title ' + icon + '" style="font-size:26px;"><span style="font-size:12px;">' + $('#pieItem' + (i+1))[0].options[$('#pieItem' + (i+1))[0].selectedIndex].innerHTML + '</span></span></div>');
                else //Parking lot - force area
                    $(placeMenuSelector).append('<div class="toolbar-group-item WazeControlDrawFeature ItemInactive" style="padding-left:1px; height40px;" id="piePlaceAreaItem' + (i+1) + '" data-category="'+ cat + '"><i class="fa fa-product-hunt fa-2x" style="font-size:20px;padding-top:9px;margin-right:5px;"></i><span class="menu-title" style="flex-grow:1;">' + $('#pieItem' + (i+1))[0].options[$('#pieItem' + (i+1))[0].selectedIndex].innerHTML + '</span></div>');
            }
        }

        $('[id^="piePlaceMainItem"]').click(function(e){
            startPlacementMode($('#' + this.id).data("category"), true);
        });

        $('[id^="piePlaceAreaItem"]').click(function(e){
            e.stopPropagation();
            startPlacementMode($('#' + this.id).data("category"), false);
        });
    }

    function init2(){
        //Load settings
        loadSettings();
        //Set up event handlers
        $('#_cbShowAreaPlaceSize').change(function() {
            if(this.checked) {
                attachPlaceSizeHandlers();
                updatePlaceSizeDisplay();
                $('#_cbShowAreaPlaceSizeImperial')[0].disabled = false;
                $('#_cbShowAreaPlaceSizeMetric')[0].disabled = false;
            }
            else
            {
                removePlaceSizeHandlers();
                $('#AreaSize').remove();
                $('#_cbShowAreaPlaceSizeImperial')[0].disabled = true;
                $('#_cbShowAreaPlaceSizeMetric')[0].disabled = true;
            }
        });

        $('#_cbShowPlaceNames').change(function() {
            PIEPlaceNameLayer.setVisibility(this.checked);
            if(this.checked) {
                $('#_cbShowPlaceNamesPoint')[0].disabled = false;
                $('#_cbShowPlaceNamesArea')[0].disabled = false;
                $('#_cbShowPlaceNamesPLA')[0].disabled = false;
                $('#_cbShowPlaceNamesLock')[0].disabled = false;
            }
            else
            {
                $('#_cbShowPlaceNamesPoint')[0].disabled = true;
                $('#_cbShowPlaceNamesArea')[0].disabled = true;
                $('#_cbShowPlaceNamesPLA')[0].disabled = true;
                $('#_cbShowPlaceNamesLock')[0].disabled = true;
            }
            console.log(this.checked);
            DisplayPlaceNames();
        });

        $('[id^="_cbShowPlaceNames"]').change(function(){
            DisplayPlaceNames();
        });

        $('#_cbShowExternalProviderTooltip').change(function(){
            ToggleExternalProvidersCSS(this.checked);
        });

        $('#_cbShowLockButtonsRPP').change(function() {
            if(this.checked)
                attachRPPLockButtonHandlers();
            else
            {
                $('#pieRPPLockButtonsContainer').remove();
                unregisterEvents(addLockButtons);
            }
        });

        $('#_cbShowPlaceLocatorCrosshair').change(function(){
            if(this.checked)
                registerEvents(ShowPlaceLocatorCrosshair);
            else
                unregisterEvents(ShowPlaceLocatorCrosshair);
        });

        $('#_cbShowParkingLotButton').change(function(){
            if(this.checked)
                registerEvents(ShowParkingLotButton);
            else
                unregisterEvents(ShowParkingLotButton);
        });

        $('#_cbShowCopyPlaceButton').change(function(){
            if(this.checked)
                registerEvents(ShowCopyPlaceButton);
            else
                unregisterEvents(ShowCopyPlaceButton);
        });

        $('#_cbShowSearchButton').change(function(){
            if(this.checked)
                registerEvents(ShowSearchButton);
            else
                unregisterEvents(ShowSearchButton);
        });

        $('#_cbAddPlaceCategoriesButtons').change(function(){
            if(this.checked)
                registerEvents(AddPlaceCategoriesButtons);
            else
                unregisterEvents(AddPlaceCategoriesButtons);
        });

        //Load settings to interface
        setChecked('_cbShowAreaPlaceSize', settings.ShowAreaPlaceSize);
        setChecked('_cbShowAreaPlaceSizeImperial', settings.ShowAreaPlaceSizeImperial);
        setChecked('_cbShowAreaPlaceSizeMetric', settings.ShowAreaPlaceSizeMetric);
        setChecked('_cbShowLockButtonsRPP', settings.ShowLockButtonsRPP);
        setChecked('_cbEditRPPAfterCreated', settings.EditRPPAfterCreated);
        setChecked('_cbUseStreetFromClosestSeg', settings.UseStreetFromClosestSeg);
        setChecked('_cbUseCityFromClosestSeg', settings.UseCityFromClosestSeg);
        setChecked('_cbShowPlaceLocatorCrosshair', settings.ShowPlaceLocatorCrosshair);
        setChecked('_cbShowParkingLotButton', settings.ShowParkingLotButton);
        setChecked('_cbShowCopyPlaceButton', settings.ShowCopyPlaceButton);
        setChecked('_cbShowExternalProviderTooltip', settings.ShowExternalProviderTooltip);
        setChecked('_cbUseAltCity', settings.UseAltCity);
        setChecked('_cbShowSearchButton', settings.ShowSearchButton);
        setChecked('_cbAddPlaceCategoriesButtons', settings.AddPlaceCategoriesButtons);
        setChecked('_cbSkipPLR', settings.SkipPLR);
        setChecked('_cbShowPlaceNames', settings.ShowPlaceNames);
        setChecked('_cbShowPlaceNamesPoint', settings.ShowPlaceNamesPoint);
        setChecked('_cbShowPlaceNamesArea', settings.ShowPlaceNamesArea);
        setChecked('_cbShowPlaceNamesPLA', settings.ShowPlaceNamesPLA);
        setChecked('_cbShowPlaceNamesLock', settings.ShowPlaceNamesLock);
        if(settings.ShowPlaceNames){
            $('#_cbShowPlaceNamesPoint')[0].disabled = false;
            $('#_cbShowPlaceNamesArea')[0].disabled = false;
            $('#_cbShowPlaceNamesPLA')[0].disabled = false;
            $('#_cbShowPlaceNamesLock')[0].disabled = false;
        }
        $('#piePlaceZoom')[0].value = settings.PlaceZoom;
        $('#pieDefaultLockLevel')[0].value = settings.DefaultLockLevel;

        if(settings.ShowAreaPlaceSize){
            $('#_cbShowAreaPlaceSizeImperial')[0].disabled = false;
            $('#_cbShowAreaPlaceSizeMetric')[0].disabled = false;
            attachPlaceSizeHandlers();
        }

        if(settings.ShowPlaceLocatorCrosshair){
            registerEvents(ShowPlaceLocatorCrosshair);
            ShowPlaceLocatorCrosshair(); //in case the user opened a PL with a Place selected
        }

        if(settings.ShowParkingLotButton){
            registerEvents(ShowParkingLotButton);
            ShowParkingLotButton(); //in case the user opened a PL with a Place selected
        }

        if(settings.ShowCopyPlaceButton){
            registerEvents(ShowCopyPlaceButton);
            ShowCopyPlaceButton();
        }

        if(settings.ShowExternalProviderTooltip){
            //registerEvents(ShowExternalProviderTooltip);
            //ShowExternalProviderTooltip();

            var observer = new MutationObserver(function(mutations) {
               mutations.forEach(function(mutation) {
                   if ($(mutation.target).hasClass('select2-chosen')) ShowExternalProviderTooltip();
               });
           });

        observer.observe(document.getElementById('edit-panel'), { childList: true, subtree: true });
        }

        if(settings.ShowSearchButton){
            registerEvents(ShowSearchButton);
            ShowSearchButton(); //in case the user opened a PL with a Place selected
        }

        if(settings.AddPlaceCategoriesButtons){
            registerEvents(AddPlaceCategoriesButtons);
            AddPlaceCategoriesButtons();
        }

        if(settings.ShowLockButtonsRPP)
            attachRPPLockButtonHandlers();

        if(settings.ShowExternalProviderTooltip)
            ToggleExternalProvidersCSS(true);

        $('.pieSettingsCheckbox').change(function() {
             var settingName = $(this)[0].id.substr(3);
            settings[settingName] = this.checked;
            saveSettings();
        });

        $('#piePlaceZoom').change(function(){
            var settingName = $(this)[0].id.substr(3);
            settings[settingName] = $(this)[0].value;
            saveSettings();
        });

        $('#pieDefaultLockLevel').change(function(){
            settings[$(this)[0].id.substr(3)] = $(this)[0].value;
            saveSettings();
        });

        var i;
        //Whenever a Place item is changed, read the settings and save to localStorage
        $('[id^="pieItem"]').change(function(){
            for(i=0;i<11;i++){
                settings.NewPlacesList[i] = $('#pieItem'+(i+1))[0].value;
            }
            saveSettings();
            buildNewPlaceList();
        });

        //Load settings into Place Customization list options
        for(i=0; i<11;i++)
            $('#pieItem'+(i+1))[0].value = settings.NewPlacesList[i];

        //Build our new menu
        buildNewPlaceList();

        new WazeWrap.Interface.Shortcut('CreateResidentialPlaceShortcut', 'Creates a resdiential Place point', 'wmepie', 'Place Interface Enhancements', settings.CreateResidentialPlaceShortcut, function(){startPlacementMode(resCategory, true);}, null).add();

        new WazeWrap.Interface.Shortcut('CreateParkingLotShortcut', 'Creates a parking lot Place', 'wmepie', 'Place Interface Enhancements', settings.CreateParkingLotShortcut, function(){startPlacementMode("PARKING_LOT", false);}, null).add();

        window.addEventListener("beforeunload", function() {
            saveSettings();
        }, false);

        //Trim whitespace from start and end of house number field on Places
        W.selectionManager.events.register("selectionchanged", null, function(){
            if(W.selectionManager.selectedItems.length > 0 && W.selectionManager.selectedItems[0].model.type === "venue")
                $('.form-control.house-number').focusout(function(){
                    $('.form-control.house-number')[0].value = $('.form-control.house-number')[0].value.trim();
                });
        });

        //Highlight the categories box when the old hospital category is present
        W.selectionManager.events.register("selectionchanged", null, highlightObsoleteHospitalCategory);
        W.model.actionManager.events.register("afterundoaction",null, highlightObsoleteHospitalCategory);
        W.model.actionManager.events.register("afterclearactions",null, highlightObsoleteHospitalCategory);
        W.model.actionManager.events.register("afteraction",null, highlightObsoleteHospitalCategory);

        W.map.events.register("zoomend", null, DisplayPlaceNames);
        W.map.events.register("changelayer", null, DisplayPlaceNames);
        //map.events.register("mouseout", null, wmepn_showLandmarkNames);
        //Waze.selectionManager.events.register("selectionchanged", null, wmepn_showLandmarkNames);

        //Shamelessly copied from URO+
        var MO_MPLayer = new MutationObserver(MPLayerChanged);
        MO_MPLayer.observe(W.map.problemLayer.div,{childList : true});
    }

    function registerEvents(handler){
        W.selectionManager.events.register("selectionchanged", null, handler);
        W.model.actionManager.events.register("afterundoaction",null, handler);
        W.model.actionManager.events.register("afterclearactions",null, handler);
        W.model.actionManager.events.register("afteraction",null, handler);
    }

    function unregisterEvents(handler){
        W.selectionManager.events.unregister("selectionchanged", null, handler);
        W.model.actionManager.events.unregister("afterundoaction",null, handler);
        W.model.actionManager.events.unregister("afterclearactions",null, handler);
        W.model.actionManager.events.unregister("afteraction",null, handler);
    }

    function ToggleExternalProvidersCSS(truthiness){
        if(truthiness)
            injectCSSWithID('pieExternalProvidersTweaks', '#edit-panel .external-providers-view .select2-container {width:90%; margin-bottom:2px;}');
        else{
            var styles = document.getElementById('pieExternalProvidersTweaks');
            if(styles) styles.parentNode.removeChild(styles);
        }
    }

    function DisplayPlaceNames(){
        PIEPlaceNameLayer.removeAllFeatures();
        var showPoint, showArea, showLock, showNames, showPLA;
        showNames = isChecked('_cbShowPlaceNames');
        showPoint = isChecked('_cbShowPlaceNamesPoint');
        showArea = isChecked('_cbShowPlaceNamesArea');
        showLock = isChecked('_cbShowPlaceNamesLock');
        showPLA = isChecked('_cbShowPlaceNamesPLA');

        if(showNames){
            var isPoint;
            for (var placeID in W.model.venues.objects) {
                var venue = W.model.venues.get(placeID);
                isPoint = venue.geometry.toString().match(/^POINT/);
                if((isPoint && W.map.zoom >= 5) || (!isPoint && W.map.zoom >= 3)){
                    if(WazeWrap.Geometry.isGeometryInMapExtent(venue.geometry)){
                        if( (isPoint && showPoint) || (!isPoint && showArea && venue.attributes.categories[0] !== "PARKING_LOT") || (!isPoint && showPLA && venue.attributes.categories[0] === "PARKING_LOT")){
                            var textLoc;
                            if(isPoint)
                                textLoc = new OpenLayers.Geometry.Point(venue.geometry.x, venue.geometry.y);
                            else
                                textLoc = venue.geometry.getCentroid();
                            var placeName =WordWrap(venue.attributes.name.trim() + (showLock ? ' (L' + (venue.attributes.lockRank + 1) + ')' : ''));
                            if(venue.attributes.categories[0] === "RESIDENCE_HOME")
                                placeName = venue.attributes.houseNumber + (venue.attributes.name.trim() !== '' ? ' - ' + venue.attributes.name : '') + (showLock ? ' (L' + (venue.attributes.lockRank + 1) + ')' : '');
                            var placeNameLabel = new OL.Feature.Vector(textLoc,{display: 'block',labelText: placeName.trim(), yOffset:(isPoint ? -18 - placeName.split("\n").length * 5 : 0)});
                            PIEPlaceNameLayer.addFeatures([placeNameLabel]);
                        }
                    }
                }
            }
        }
    }

    function WordWrap(text){
        var newName = "";

        if(text !== ""){
            var splitName = text.match(/(.{1,35})(?:\s|$)/g);
            for(var i=0;i<splitName.length;i++){
                newName += splitName[i] + (i != splitName.length-1 ? '\n' : '');
            }
        }
        console.log()
        return newName;
    }

    //Shamelessly copied from URO+
    function MPLayerChanged()
    {
        for(var mObj in W.map.problemLayer.markers){
            var mIcon = W.map.problemLayer.markers[mObj].icon.div;
            mIcon.addEventListener("click", MarkerClick, false);
        }
    }

    function MarkerClick()
    {
        var markerType = GetMarkerType(this.className);
        if(markerType !== null){
            var markerID = this.attributes["data-id"].value;
            if(W.map.getLayerByUniqueName("problems").markers[markerID].model.attributes.subType === 71){
                var $PIECreatePLA = $("<div>", {style:"min-height:20px", id:"Wazebar"});
                $PIECreatePLA.html([
                    '<div id="PIECreatePLA">',
                    '<div class="btn btn-block" id="PIECreatePLAButton" style="color: #fff; background-color: #92c2d1; border-color: #78b0bf; margin-top:5px;">Create Suggested PLA</div>',
                    '</div>'
                ].join(' '));

                setTimeout(function(){$('#panel-container > div > div > div.body > div.actions > div > div').append($PIECreatePLA); $('#PIECreatePLAButton').click(function(){createPLAFromMP(markerID);})}, 150);
            }
        }
    }

    //Shamelessly copied from URO+
    function GetMarkerType(className)
    {
        var markerType = null;
        if(className.indexOf('user-generated') !== -1) markerType = 'ur';
        else if(className.indexOf('map-problem') !== -1) markerType = 'mp';
        else if(className.indexOf('place-update') !== -1) markerType = 'pur';
        return markerType;
    }

    function createPLAFromMP(MPID){
        var pos = W.model.problemDetails.objects[MPID].venueGeom;

        var PlaceObject = require("Waze/Feature/Vector/Landmark");
        var AddPlace = require("Waze/Action/AddLandmark");
        var NewPlace = new PlaceObject();

        var points = [];
        var i;
        for(i=0;i<pos.components[0].components.length;i++){
            points.push(new OL.Geometry.Point(pos.components[0].components[i].x, pos.components[0].components[i].y));
        }
        var ring = new OpenLayers.Geometry.LinearRing(points);
        NewPlace.geometry = new OL.Geometry.Polygon([ring]);

        NewPlace.attributes.categories.push("PARKING_LOT");

        W.model.actionManager.add(new AddPlace(NewPlace));
        Waze.selectionManager.select([NewPlace]);
    }

    function highlightObsoleteHospitalCategory(){
        if(W.selectionManager.selectedItems.length > 0 && W.selectionManager.selectedItems[0].model.type === "venue"){
                if(W.selectionManager.selectedItems[0].model.attributes.categories.contains("HOSPITAL_MEDICAL_CARE")){
                    $('.select2-choices').css('animation-iteration-count', 'infinite');
                    $('.select2-choices').attr('title', 'The "Hospital / Medical Care" category is no longer valid.\n\nPlease change it to "Hospital / Urgent Care" or "Doctor / Clinic", whichever is most appropriate');
                    $('.select2-choices').tooltip();
                }
            }
    }

    var newPlaceCategory = "";
    function startPlacementMode(category, isPoint){
        $('#edit-buttons > div > div.toolbar-button.waze-icon-place.toolbar-submenu.toolbar-group.toolbar-group-venues.ItemInactive').removeClass("open");
        newPlaceCategory = category;
        var polyDrawFeatureOptions = {callbacks : {"done": doneHandler}};
        if(isPoint){
            $("#map").on('mousemove', MouseMoveHandler);
            $("#map").click(function(){endPlacementMode(category, isPoint);});
            /*drawPoly = new OpenLayers.Control.DrawFeature(newPlaceLayer, OpenLayers.Handler.Polygon, polyDrawFeatureOptions);
            W.map.addControl(drawPoly);
            drawPoly.activate();*/
        }
        else{
            drawPoly = new OpenLayers.Control.DrawFeature(newPlaceLayer, OpenLayers.Handler.Polygon, polyDrawFeatureOptions);
            W.map.addControl(drawPoly);
            drawPoly.activate();

        }
        document.addEventListener('keyup', keyUpHandler, false);
    }

    var businessPLAPlaceName, businessPLAPlaceAddress;//, businessPLAPlacePhone, businessPLAPlaceURL;
    function startBusinessPLAPlacementMode(){
        var polyDrawFeatureOptions = {callbacks : {"done": doneHandlerBusinessPLAPlace}};
        drawPoly = new OpenLayers.Control.DrawFeature(newPlaceLayer, OpenLayers.Handler.Polygon, polyDrawFeatureOptions);
        W.map.addControl(drawPoly);
        drawPoly.activate();
        document.addEventListener('keyup', keyUpHandler, false);
    }

    function doneHandlerBusinessPLAPlace(geom){
        drawPoly.destroy();
        BusinessPLAMode = false;
        CreateBusinesPLAPlace(geom, businessPLAPlaceName, businessPLAPlaceAddress);//, businessPLAPlacePhone, businessPLAPlaceURL);
    }

    function CreateBusinesPLAPlace(geom, name, address){//, phone, url){
        drawPoly.destroy();

        var PlaceObject = require("Waze/Feature/Vector/Landmark");
        var AddPlace = require("Waze/Action/AddLandmark");
        var multiaction = new MultiAction();
        multiaction.setModel(W.model);

        var NewPlace = new PlaceObject();
        var points = [];
        var i;
        for(i=0;i<geom.components[0].components.length;i++){
            points.push(new OL.Geometry.Point(geom.components[0].components[i].x, geom.components[0].components[i].y));
        }
        var ring = new OpenLayers.Geometry.LinearRing(points);
        NewPlace.geometry = new OL.Geometry.Polygon([ring]);
        NewPlace.attributes.categories.push("PARKING_LOT");

        NewPlace.attributes.lockRank = Number(settings.DefaultLockLevel);
        NewPlace.attributes.name = "Parking - " + name;
        //NewPlace.attributes.phone = phone;
        //NewPlace.attributes.url = url;
        NewPlace.attributes.categoryAttributes.PARKING_LOT = {};
        NewPlace.attributes.categoryAttributes.PARKING_LOT.parkingType = "RESTRICTED";
        NewPlace.attributes.categoryAttributes.PARKING_LOT.lotType = ["STREET_LEVEL"];

        W.model.actionManager.add(new AddPlace(NewPlace));

        if(address){
            var newAttributes, UpdateFeatureAddress = require('Waze/Action/UpdateFeatureAddress');
            newAttributes = {
                countryID: address.country.id,
                stateID: address.state.id,
                emptyCity: address.city.attributes.name ? null : true,
                emptyStreet: address.street.name ? null : true,
                houseNumber: address.houseNumber
            };

                newAttributes.streetName = address.street.name;

                var cityName = address.city.attributes.name;

                if(cityName !== "")
                    newAttributes.emptyCity = null;
                newAttributes.cityName = cityName;

        }
        var UFA = new UpdateFeatureAddress(NewPlace, newAttributes);
        UFA.options.updateHouseNumber = true;
        multiaction.doSubAction(UFA);
        W.model.actionManager.add(multiaction);

        Waze.selectionManager.select([NewPlace]);
    }

    function doneHandler(geom){
        drawPoly.destroy();
        createPlace(geom, newPlaceCategory, false);
    }

    function keyUpHandler(e){
         if (e.keyCode == 27){
             BusinessPLAMode = false;
             disablePlacementMode();
             if(drawPoly !== "undefined")
                 drawPoly.destroy();
         }
        else if(e.keyCode == 90 && e.ctrlKey)
            drawPoly.undo();
        else if(e.keyCode == 89 && e.ctrlKey)
            drawPoly.redo();
        else if(e.keyCode == 13)
            drawPoly.finishSketch();
    }

    function disablePlacementMode(){
        $("#map").off('click');//, endPlacementMode);
        $("#map").off('mousemove', MouseMoveHandler);
        clearLayer();
        document.removeEventListener('keyup', keyUpHandler);
    }

    function endPlacementMode(category, isPoint){
        disablePlacementMode();
        createPlace(getMousePos900913(), category, isPoint);
    }

    function getMousePos900913(){
        var mousePosition = $('.WazeControlMousePosition').text().split(" ");
        return WazeWrap.Geometry.ConvertTo900913(mousePosition[0], mousePosition[1]);
    }

    function MouseMoveHandler(e){
        clearLayer();
		drawCircle(getMousePos900913());
    }

    function clearLayer() {
		var layer = W.map.getLayersByName(layerName)[0];
		layer.removeAllFeatures();
	}

    function drawCircle(e){
        var pointFeature = new OL.Feature.Vector(new OL.Geometry.Point(e.lon, e.lat), {}, pointStyle);
		W.map.getLayersByName(layerName)[0].addFeatures([pointFeature]);
    }

    function createPlace(pos, category, isPoint){
        var PlaceObject = require("Waze/Feature/Vector/Landmark");
        var AddPlace = require("Waze/Action/AddLandmark");
        var multiaction = new MultiAction();
        multiaction.setModel(W.model);

        var NewPlace = new PlaceObject();
        if(isPoint)
            NewPlace.geometry = new OL.Geometry.Point(pos.lon, pos.lat);
        else{
            var points = [];
            var i;
            for(i=0;i<pos.components[0].components.length;i++){
                points.push(new OL.Geometry.Point(pos.components[0].components[i].x, pos.components[0].components[i].y));
            }
            var ring = new OpenLayers.Geometry.LinearRing(points);
            NewPlace.geometry = new OL.Geometry.Polygon([ring]);

        }

        NewPlace.attributes.categories.push(category);
        if(category === resCategory){
            NewPlace._originalResidential = true;
            NewPlace.attributes.residential = true;
        }
        NewPlace.attributes.lockRank = Number(settings.DefaultLockLevel);

        var closestSeg = WazeWrap.Geometry.findClosestSegment(new OL.Geometry.Point(pos.lon, pos.lat), settings.SkipPLR, settings.SkipPLR);

        W.model.actionManager.add(new AddPlace(NewPlace));
        Waze.selectionManager.select([NewPlace]);

        if(closestSeg){ //if we were able to find a segment, try to pull the city and/or street name if the options are enabled
            var newAttributes, UpdateFeatureAddress = require('Waze/Action/UpdateFeatureAddress'), address = closestSeg.getAddress();

            newAttributes = {
                countryID: address.country.id,
                stateID: address.state.id,
                emptyCity: address.city.attributes.name ? null : true,
                emptyStreet: address.street.name ? null : true
            };

            if(settings.UseStreetFromClosestSeg)
                newAttributes.streetName = address.street.name;
            else
                newAttributes.emptyStreet = true;

            if(settings.UseCityFromClosestSeg){
                var cityName = address.city.attributes.name;

                if(settings.UseAltCity && cityName === ""){
                    if(address.altStreets.length > 0){ //segment has alt names
                        for(var j=0;j<closestSeg.attributes.streetIDs.length;j++){
                            var altCity = W.model.cities.get(W.model.streets.get(closestSeg.attributes.streetIDs[j]).cityID).attributes;

                            if(altCity.englishName !== null && altCity.englishName !== "")
                                cityName = altCity.englishName;
                        }
                    }
                }
                if(cityName !== "")
                    newAttributes.emptyCity = null;
                newAttributes.cityName = cityName;
            }
            else
                newAttributes.emptyCity = true;

            multiaction.doSubAction(new UpdateFeatureAddress(NewPlace, newAttributes));
            W.model.actionManager.add(multiaction);
        }
        else
            console.log("WMEPIE - No segment found; cannot set street or city name.");

        if(category === resCategory && settings.EditRPPAfterCreated)
            editRPPAddress();
    }

    function editRPPAddress(rppTries){
        rppTries = rppTries || 1;

        if ($('.edit-button').length > 0) {
            $('.edit-button').trigger("click");
            $('.house-number:first').focus();

        } else if (rppTries < 1000) {
            console.log("not found");
            setTimeout(function () {editRPPAddress(rppTries++);}, 200);
        }
    }

    function buildItemOption(itemNumber){
        var $section = $("<div>", {style:"padding:8px 16px", id:"piePlaceCat" + itemNumber});
        $section.html([
            I18n.t('pie.prefs.Item') + " ",
            itemNumber,
            buildItemList(itemNumber),
            '</br>'
            ].join(' '));

        return $section.html();
    }

    function buildLockLevelsList(){
        var $lockLevels = $("<div>");
        for(var i=0;i<WazeWrap.User.Rank();i++){
            $lockLevels.append("<option value=" + i + ">" + (i+1) + "</option>");
        }
        return $lockLevels.html();
    }

    function attachRPPLockButtonHandlers(){
        $('#pieRPPLockButtonsContainer').remove();
        W.selectionManager.events.register("selectionchanged", null, addLockButtons);
        W.model.actionManager.events.register("afterundoaction",null, addLockButtons);
        W.model.actionManager.events.register("afterclearactions",null, addLockButtons);
        W.model.actionManager.events.register("afteraction",null, addLockButtons);
    }

    function attachPlaceSizeHandlers(){
        W.selectionManager.events.register("selectionchanged", null, updatePlaceSizeDisplay);
        W.model.actionManager.events.register("afteraction",null, updatePlaceSizeDisplay);
        W.model.actionManager.events.register("afterundoaction",null, updatePlaceSizeDisplay);
        W.model.actionManager.events.register("afterclearactions",null, updatePlaceSizeDisplay);
        W.model.actionManager.events.register("noActions",null, noActions);
        updatePlaceSizeDisplay();
    }

    function removePlaceSizeHandlers(){
        W.selectionManager.events.unregister("selectionchanged", null, updatePlaceSizeDisplay);
        W.model.actionManager.events.unregister("afteraction",null, updatePlaceSizeDisplay);
        W.model.actionManager.events.unregister("afterundoaction",null, updatePlaceSizeDisplay);
        W.model.actionManager.events.unregister("afterclearactions",null, updatePlaceSizeDisplay);
        W.model.actionManager.events.unregister("noActions",null, noActions);
    }

    function ShowPlaceLocatorCrosshair(){
        $('#pieCrosshairs').remove();
        if(W.selectionManager.selectedItems.length > 0){
            if(W.selectionManager.selectedItems[0].model.type === "venue"){
                var panelWidth = $('#landmark-edit-general').width();
                var $crosshairs;
                if(W.selectionManager.selectedItems[0].model.attributes.categories.contains("RESIDENCE_HOME")){
                    $('.landmark > .tab-content').css('position', 'relative');
                    $crosshairs = $('<div style="position:absolute; z-index:100; cursor:pointer; top:0; right:0;" id="pieCrosshairs" title="Zoom and center on Place"><i class="fa fa-crosshairs fa-lg" aria-hidden="true"></i></div>');
                    $('.landmark > .tab-content').append($crosshairs);
                }
                else{
                     $crosshairs = $('<div style="float:right; z-index:100; cursor:pointer; top:0; right:0;" id="pieCrosshairs" title="Zoom and center on Place"><i class="fa fa-crosshairs fa-lg" aria-hidden="true"></i></div>');
                    $('#landmark-edit-general > form > div:nth-child(1) > i').after($crosshairs);
                }
                $('#pieCrosshairs').click(function(){
                    CenterOnPlace(W.selectionManager.selectedItems[0].model, settings.PlaceZoom);
                });
            }
        }
    }

    var BusinessPLAMode = false;
    function ShowParkingLotButton(){
        $('#piePLAButton').remove();

        if(W.selectionManager.selectedItems.length > 0){
            if(W.selectionManager.selectedItems[0].model.type === "venue"){
                var $PLAButton;
                if(!(W.selectionManager.selectedItems[0].model.attributes.categories.contains("RESIDENCE_HOME") || W.selectionManager.selectedItems[0].model.attributes.categories.contains("PARKING_LOT"))){
                    $PLAButton = $('<div style="float:right; z-index:100; cursor:pointer; top:0; right:0;" id="piePLAButton" title="Create a Parking Lot Area for this Place"><i class="fa fa-product-hunt fa-lg" aria-hidden="true"></i></div>');
                    $('#landmark-edit-general > form > div:nth-child(1) > i').after($PLAButton);

                    $('#piePLAButton').click(function(){
                        if(!BusinessPLAMode)
                        {
                            BusinessPLAMode = true;
                            businessPLAPlaceName = W.selectionManager.selectedItems[0].model.attributes.name;
                            businessPLAPlaceAddress = W.selectionManager.selectedItems[0].model.getAddress().attributes;
                            //businessPLAPlacePhone = W.selectionManager.selectedItems[0].model.attributes.phone;
                            //businessPLAPlaceURL = W.selectionManager.selectedItems[0].model.attributes.url;
                            startBusinessPLAPlacementMode();
                        }
                    });
                }
            }
        }
    }

    var extProviderTries = 0;
    function ShowExternalProviderTooltip(){
        if(isChecked('_cbShowExternalProviderTooltip'))
            if(W.selectionManager.selectedItems.length > 0 && W.selectionManager.selectedItems[0].model.type === "venue"){
                if($('.select2-container.uuid').length > 0)
                    for(var i=0; i < $('.select2-container.uuid').find('span.select2-chosen').length; i++){
                        extProviderTries = 0;
                        ReadExtProviderText(i, extProviderTries);
                    }
            }
    }

    function ReadExtProviderText(index, extProviderTries){
        var providersList = $('.select2-container.uuid').find('span.select2-chosen');
        if($('.select2-container.uuid').find('span.select2-chosen')[index].innerHTML == "&nbsp;" && extProviderTries <= 20)
            setTimeout(function(){ReadExtProviderText(index, extProviderTries++);}, 50);
        else{
            if($('#' + providersList[index].id).parent().parent().data('original-title') == null){
                $('#' + providersList[index].id).parent().parent().attr('title', $('.select2-container.uuid').find('span.select2-chosen')[index].innerText);
                $('#' + providersList[index].id).parent().parent().tooltip()
            }
            else
                $('#' + providersList[index].id).parent().parent().attr('data-original-title', $('.select2-container.uuid').find('span.select2-chosen')[index].innerText);
        }
    }

    function ShowCopyPlaceButton(){
        $('#pieCopyPlaceButton').remove();

        if(W.selectionManager.selectedItems.length > 0){
            //W.selectionManager.selectedItems[0].model.attributes.id.match(/(\d+\.){2}\d+/)
            if(W.selectionManager.selectedItems[0].model.type === "venue"){// && (typeof W.selectionManager.selectedItems[0].model.attributes.id === "string")){ //id is only a string if the Place has been saved - don't allow copying unsaved Places
                var $PlaceCopyButton;
                if(!W.selectionManager.selectedItems[0].model.attributes.categories.contains("RESIDENCE_HOME")){
                    $PlaceCopyButton = $('<div style="float:right; z-index:100; cursor:pointer; top:0; right:0; margin-left:1px; margin-right:1px;" id="pieCopyPlaceButton" title="Creates a copy of this Place"><i class="fa fa-files-o fa-lg" aria-hidden="true"></i></div>');
                    $('#landmark-edit-general > form > div:nth-child(1) > i').after($PlaceCopyButton);

                    $('#pieCopyPlaceButton').click(function(){
                        var PlaceObject = require("Waze/Feature/Vector/Landmark");
                        var AddPlace = require("Waze/Action/AddLandmark");

                        var NewPlace = new PlaceObject();
                        var oldPlace = W.selectionManager.selectedItems[0].model;

                        NewPlace.attributes.name = oldPlace.attributes.name + " (copy)";
                        NewPlace.attributes.phone = oldPlace.attributes.phone;
                        NewPlace.attributes.url = oldPlace.attributes.url;
                        NewPlace.attributes.categories = oldPlace.attributes.categories.clone();
                        NewPlace.attributes.aliases = oldPlace.attributes.aliases.clone();
                        NewPlace.attributes.description = oldPlace.attributes.description;
                        NewPlace.attributes.houseNumber = oldPlace.attributes.houseNumber;
                        NewPlace.attributes.lockRank = oldPlace.attributes.lockRank;
                        NewPlace.attributes.geometry = oldPlace.attributes.geometry.clone();

                        if(oldPlace.attributes.geometry.toString().match(/^POLYGON/)){
                            var convertedCoords;
                            for(var i=0; i<NewPlace.attributes.geometry.components[0].components.length - 1; i++){
                                convertedCoords = WazeWrap.Geometry.ConvertTo4326(NewPlace.attributes.geometry.components[0].components[i].x, NewPlace.attributes.geometry.components[0].components[i].y);
                                convertedCoords.lon += WazeWrap.Geometry.CalculateLongOffsetGPS(5, convertedCoords.long, convertedCoords.lat);
                                NewPlace.attributes.geometry.components[0].components[i].x = WazeWrap.Geometry.ConvertTo900913(convertedCoords.lon, convertedCoords.lat).lon;
                            }
                        }
                        else{
                            var convertedCoords = WazeWrap.Geometry.ConvertTo4326(oldPlace.attributes.geometry.x, oldPlace.attributes.geometry.y);
                            convertedCoords.lon += WazeWrap.Geometry.CalculateLongOffsetGPS(5, convertedCoords.long, convertedCoords.lat);
                            NewPlace.attributes.geometry.x = WazeWrap.Geometry.ConvertTo900913(convertedCoords.lon, convertedCoords.lat).lon;
                        }

                        NewPlace.attributes.services = oldPlace.attributes.services.clone();
                        NewPlace.attributes.openingHours = oldPlace.attributes.openingHours.clone();
                        NewPlace.attributes.streetID = oldPlace.attributes.streetID;

                        if(NewPlace.attributes.categories.contains("GAS_STATION"))
                            NewPlace.attributes.brand = oldPlace.attributes.brand;

                        if(NewPlace.attributes.categories.contains("PARKING_LOT")){
                            NewPlace.attributes.categoryAttributes.PARKING_LOT = {};
                            var PLAttribute = oldPlace.attributes.categoryAttributes.PARKING_LOT;
                            if(!(PLAttribute.lotType == null))
                                NewPlace.attributes.categoryAttributes.PARKING_LOT.lotType = oldPlace.attributes.categoryAttributes.PARKING_LOT.lotType.clone();
                            if(!(PLAttribute.canExitWhileClosed == null))
                                NewPlace.attributes.categoryAttributes.PARKING_LOT.canExitWhileClosed = oldPlace.attributes.categoryAttributes.PARKING_LOT.canExitWhileClosed;
                            if(!(PLAttribute.costType == null))
                                NewPlace.attributes.categoryAttributes.PARKING_LOT.costType = oldPlace.attributes.categoryAttributes.PARKING_LOT.costType;
                            if(!(PLAttribute.estimatedNumberOfSpots == null))
                                NewPlace.attributes.categoryAttributes.PARKING_LOT.estimatedNumberOfSpots = oldPlace.attributes.categoryAttributes.PARKING_LOT.estimatedNumberOfSpots;
                            if(!(PLAttribute.hasTBR == null))
                                NewPlace.attributes.categoryAttributes.PARKING_LOT.hasTBR = oldPlace.attributes.categoryAttributes.PARKING_LOT.hasTBR;
                            if(!(PLAttribute.lotType == null))
                                NewPlace.attributes.categoryAttributes.PARKING_LOT.lotType = oldPlace.attributes.categoryAttributes.PARKING_LOT.lotType.clone();
                            if(!(PLAttribute.parkingType == null))
                                NewPlace.attributes.categoryAttributes.PARKING_LOT.parkingType = oldPlace.attributes.categoryAttributes.PARKING_LOT.parkingType;
                            if(!(PLAttribute.paymentType == null))
                                NewPlace.attributes.categoryAttributes.PARKING_LOT.paymentType = oldPlace.attributes.categoryAttributes.PARKING_LOT.paymentType.clone();
                        }

                        W.model.actionManager.add(new AddPlace(NewPlace));

                        var newAttributes, UpdateFeatureAddress = require('Waze/Action/UpdateFeatureAddress'), address = oldPlace.getAddress();
                        var MultiAction = require("Waze/Action/MultiAction");
                        var multiaction = new MultiAction();
                        multiaction.setModel(W.model);

                        console.log(address);
                        newAttributes = {
                            countryID: address.attributes.country.id,
                            stateID: address.attributes.state.id,
                            emptyCity: address.attributes.city.attributes.name ? null : true,
                            emptyStreet: address.attributes.street.name ? null : true
                        };

                        newAttributes.streetName = address.attributes.street.name;
                        var cityName = address.attributes.city.attributes.name;

                        if(cityName !== "")
                            newAttributes.emptyCity = null;
                        newAttributes.cityName = cityName;

                        var UFA = new UpdateFeatureAddress(NewPlace, newAttributes);
                        UFA.options.updateHouseNumber = true;
                        multiaction.doSubAction(UFA);
                        W.model.actionManager.add(multiaction);
                        Waze.selectionManager.select([NewPlace]);
                    });
                }
            }
        }
    }

    function ShowSearchButton(){
        $('#pieSearchButton').remove();
        if(W.selectionManager.selectedItems.length > 0){
            if(W.selectionManager.selectedItems[0].model.type === "venue"){
                var $search = $('<div style="float:left; margin-right:5px; position:relative; left:-10px; cursor:pointer;" id="pieSearchButton" title="Fills the search bar with the address"><i class="fa fa-search" aria-hidden="true"></i></div>');
                $('.address-edit-view').before($search);
                $('#pieSearchButton').click(function(){
                    var address = $('.full-address')[0].innerHTML;
                    var noCity = I18n.translations[I18n.currentLocale()].edit.address.no_city;
                    var noStreet = I18n.translations[I18n.currentLocale()].edit.address.no_street;

                    address = address.replace(noCity + ",","");
                    if(address !== I18n.translations[I18n.currentLocale()].edit.landmark.no_address)
                        $('.search-query')[0].value = address;
                });
            }
        }
    }

    function AddPlaceCategoriesButtons(){
        $('#piePlaceCategoriesButtonsContainer').remove();
        if(W.selectionManager.selectedItems.length > 0){
            if(W.selectionManager.selectedItems[0].model.type === "venue"){
                var $container = $('<div>',{id:'piePlaceCategoriesButtonsContainer', style:'white-space: nowrap;'});
                var categoryOptions = $('[id^=pieItem]');

                var $button = $('<div>',{id:'btnPlaceCatClear', title:'Clear current categories', style:'display:inline-block; cursor:pointer'}).click(function() { onPlaceCategoriesButtonsClick(this.id); });
                $button.append('<span class="fa fa-times" style="font-size:20px; color:red;"></span>');
                $container.append($button);

                for(var i=0;i<categoryOptions.length;i++){
                    var name = categoryOptions[i].options[categoryOptions[i].selectedIndex].innerHTML;
                    var icon = categoryOptions[i].options[categoryOptions[i].selectedIndex].getAttribute("data-icon");
                    var divid = 'btnPlaceCat' + categoryOptions[i].value;
                    if(categoryOptions[i].value !== resCategory && categoryOptions[i].value !== "PARKING_LOT"){
                        $button = $('<div>',{id:divid, title:name.replace('&amp;', '&'), style:'display:inline-block; cursor:pointer', 'data-category':categoryOptions[i].value}).click(function() { onPlaceCategoriesButtonsClick(this.id); });
                        $button.append('<span class="'+icon+'" style="font-size:20px;"></span>');

                        $container.append($button);
                    }
                }
            }

            $('.categories.controls').before($container);
        }
    }

    function onPlaceCategoriesButtonsClick(buttonid){
        if(buttonid === "btnPlaceCatClear"){
            var blankCategories = []; //W.selectionManager.selectedItems[0].model.attributes.categories.clone();
            //console.log(blankCategories.length);
            //blankCategories.splice(0, blankCategories.length);
            //console.log(blankCategories);
            W.model.actionManager.add(new UpdateObject(W.selectionManager.selectedItems[0].model, { categories: blankCategories }));
        }
        else{
            var newCategories = W.selectionManager.selectedItems[0].model.attributes.categories.clone();
            //console.log($('#'+buttonid)[0].getAttribute("data-category"));
            newCategories.push($('#'+buttonid)[0].getAttribute("data-category"));
            W.model.actionManager.add(new UpdateObject(W.selectionManager.selectedItems[0].model, {categories: newCategories}));
        }
    }

    function CenterOnPlace(venue, zoom){
        var centroid = venue.geometry.getCentroid();
        W.map.setCenter([centroid.x, centroid.y], zoom);
    }

    function isChecked(checkboxId) {
        return $('#' + checkboxId).is(':checked');
    }

    function setChecked(checkboxId, checked) {
        $('#' + checkboxId).prop('checked', checked);
    }

    function noActions(){
        setTimeout(updatePlaceSizeDisplay, 100 ); //have to put in a delay for when the user uses undo to clear all actions - WME updates on top of my changes otherwise.
    }

    function updatePlaceSizeDisplay(){
        var count = W.selectionManager.selectedItems.length;
        var metersArea = 0;
        var bold = false;
        if(count === 1){
           var venue = W.selectionManager.selectedItems[0];
           var isArea = venue.geometry.toString().match(/^POLYGON/);
           //var isPoint = venue.geometry.toString().match(/^POINT/);

            if(venue.model.type === "venue" && isArea){
                if($('#AreaSize'))
                    $('#AreaSize').remove();
                metersArea = W.selectionManager.selectedItems[0].model.geometry.getGeodesicArea(W.map.getProjectionObject());

                if(metersArea > 0 && isArea){
                    var ftArea = Math.round(metersArea * 10.76391 *100)/100;

                    var list = $('#landmark-edit-general > ul')[0];
                    var newList = document.createElement("UL");
                    newList.id = "AreaSize";

                    var newItem = document.createElement("LI");
                    if(isChecked("_cbShowAreaPlaceSizeMetric")){
                        newItem.innerHTML = "Area: " + metersArea.toFixed(2) + " m<sup>2</sup>";
                        newList.appendChild(newItem);
                    }

                    if(isChecked("_cbShowAreaPlaceSizeImperial")){
                        newItem = document.createElement("LI");
                        newItem.innerHTML = "Area: " + ftArea.toFixed(2) + " ft<sup>2</sup>";
                        newList.appendChild(newItem);
                    }
                    if(metersArea < 500){
                        newItem = document.createElement("LI");
                        newItem.innerHTML = "<span style='color:red; font-weight:bold;'>Places smaller than 500 m<sup>2</sup>/5382 ft<sup>2</sup> will not show in the client</span>";
                        newList.appendChild(newItem);
                    }
                    if(metersArea > 20000){
                        newItem = document.createElement("LI");
                        newItem.innerHTML = "<span style='color:red; font-weight:bold;'>Places larger than 20000 m<sup>2</sup>/215278.2 ft<sup>2</sup> will <i>always</i> show in the client</span>";
                        newList.appendChild(newItem);
                    }
                    if(list.before != null)
                       list.before(newList);
                    else{
                        var parent = $('#landmark-edit-general > ul')[0].parentNode;
                        parent.insertBefore(newList,$('#landmark-edit-general > ul')[0]);
                    }

                    $('#AreaSize').addClass("list-unstyled");
                    $('#AreaSize').addClass("additional-attributes");
                }
            }
        }
    }

    function loadSettings() {
        var loadedSettings = $.parseJSON(localStorage.getItem("WMEPIE_Settings"));
        var defaultSettings = {
            ShowAreaPlaceSize: false,
            ShowAreaPlaceSizeImperial: false,
            ShowAreaPlaceSizeMetric: false,
            ShowLockButtonsRPP: true,
            NewPlacesList: W.Config.venues.categories.clone(),
            EditRPPAfterCreated: false,
            UseStreetFromClosestSeg: false,
            UseCityFromClosestSeg: false,
            ShowPlaceLocatorCrosshair: false,
            PlaceZoom: 6,
            DefaultLockLevel: 0,
            CreateResidentialPlaceShortcut: "A+r",
            CreateParkingLotShortcut: "A+p",
            UseAltCity: false,
            ShowSearchButton: false,
            AddPlaceCategoriesButtons: false,
            SkipPLR: false,
            ShowParkingLotButton: false,
            ShowPlaceNames: false,
            ShowPlaceNamesPoint: false,
            ShowPlaceNamesArea: false,
            ShowPlaceNamesLock: false,
            ShowCopyPlaceButton: false,
            ShowExternalProviderTooltip: false,
            ShowPlaceNamesPLA: false
        };
        settings = loadedSettings ? loadedSettings : defaultSettings;
        for (var prop in defaultSettings) {
            if (!settings.hasOwnProperty(prop))
                settings[prop] = defaultSettings[prop];
        }

        if(settings.ShowAreaPlaceSizeImperial === false && settings.ShowAreaPlaceSizeMetric === false)
            if(Waze.prefs.attributes.isImperial)
                settings.ShowAreaPlaceSizeImperial = true;
            else
                settings.ShowAreaPlaceSizeMetric = true;
    }

     function saveSettings() {
        if (localStorage) {
            var localsettings = {
                ShowAreaPlaceSize: settings.ShowAreaPlaceSize,
                ShowAreaPlaceSizeImperial: settings.ShowAreaPlaceSizeImperial,
                ShowAreaPlaceSizeMetric: settings.ShowAreaPlaceSizeMetric,
                ShowLockButtonsRPP: settings.ShowLockButtonsRPP,
                NewPlacesList: settings.NewPlacesList,
                EditRPPAfterCreated: settings.EditRPPAfterCreated,
                UseStreetFromClosestSeg: settings.UseStreetFromClosestSeg,
                UseCityFromClosestSeg: settings.UseCityFromClosestSeg,
                ShowPlaceLocatorCrosshair: settings.ShowPlaceLocatorCrosshair,
                PlaceZoom: settings.PlaceZoom,
                DefaultLockLevel: settings.DefaultLockLevel,
                CreateResidentialPlaceShortcut: settings.CreateResidentialPlaceShortcut,
                CreateParkingLotShortcut: settings.CreateParkingLotShortcut,
                UseAltCity: settings.UseAltCity,
                ShowSearchButton: settings.ShowSearchButton,
                AddPlaceCategoriesButtons: settings.AddPlaceCategoriesButtons,
                SkipPLR: settings.SkipPLR,
                ShowParkingLotButton: settings.ShowParkingLotButton,
                ShowPlaceNames: settings.ShowPlaceNames,
                ShowPlaceNamesPoint: settings.ShowPlaceNamesPoint,
                ShowPlaceNamesArea: settings.ShowPlaceNamesArea,
                ShowPlaceNamesLock: settings.ShowPlaceNamesLock,
                ShowCopyPlaceButton: settings.ShowCopyPlaceButton,
                ShowExternalProviderTooltip: settings.ShowExternalProviderTooltip,
                ShowPlaceNamesPLA: settings.ShowPlaceNamesPLA
            };

            for (var name in Waze.accelerators.Actions) {
                var TempKeys = "";
                if (Waze.accelerators.Actions[name].group == 'wmepie') {
                    if (Waze.accelerators.Actions[name].shortcut) {
                        if (Waze.accelerators.Actions[name].shortcut.altKey === true) {
                            TempKeys += 'A';
                        }
                        if (Waze.accelerators.Actions[name].shortcut.shiftKey === true) {
                            TempKeys += 'S';
                        }
                        if (Waze.accelerators.Actions[name].shortcut.ctrlKey === true) {
                            TempKeys += 'C';
                        }
                        if (TempKeys !== "") {
                            TempKeys += '+';
                        }
                        if (Waze.accelerators.Actions[name].shortcut.keyCode) {
                            TempKeys += Waze.accelerators.Actions[name].shortcut.keyCode;
                        }
                    } else {
                        TempKeys = "-1";
                    }
                    localsettings[name] = TempKeys;
                }
            }

            localStorage.setItem("WMEPIE_Settings", JSON.stringify(localsettings));
        }
    }

    //Using the same display for lock buttons as ClickSaver (with permission from MapoMatic) - thanks MoM!
    function addLockButtons() {
        if(W.selectionManager.selectedItems.length > 0){
            var item = W.selectionManager.selectedItems[0];
            var isRPP = (item.model.type === "venue" && item.model.attributes.residential === true);

            if(isRPP){
                var attr = item.model.attributes;
                var autoRank = attr.rank;
                var manualRank = attr.lockRank;
                var firstManualRank = manualRank;
                var userRank = WazeWrap.User.Rank() - 1;
                var maxAutoRank = autoRank;
                var disabled = false;

                var $div = $('#pieRPPLockButtonsContainer');
                $div.remove();
                $div = $('<div>',{id:'pieRPPLockButtonsContainer',style:'margin-bottom:5px;'});
                $div.append('<label class="control-label">Lock</label>');
                var btnInfos = [];

                for(var iBtn=0;iBtn<=6;iBtn++){btnInfos.push({r:iBtn,val:iBtn});}
                btnInfos.forEach(function(btnInfo){
                    var selected = (btnInfo.val == manualRank);
                    disabled = userRank < btnInfo.val;
                    if (btnInfo.val !== 6) {
                        $div.append(
                            $('<div>', {
                                class:'btn btn-lh' + (selected ? ' btn-lh-selected':'') + (btnInfo.r < 6 & (userRank < btnInfo.r || disabled) ? ' disabled' : '')
                            })
                            .text(btnInfo.hasOwnProperty('title') ? btnInfo.title : btnInfo.r + 1)
                            .data('val',btnInfo.hasOwnProperty('val') ? btnInfo.val : btnInfo.r + 1)
                            .hover(function() {})
                            .click(function() {
                                if((userRank >= $(this).data('val')) && (btnInfo.r < 6)) {
                                    W.model.actionManager.add(new UpdateObject(item.model,{lockRank:($(this).data('val'))}));
                                    addLockButtons();
                                }
                            })
                        );
                    }
                });
                $('#landmark-edit-general > div.address-edit.side-panel-section').after($div);
            }
        }
    }

    function buildItemList(itemNumber){

        var $places = $("<div>");
        $places.html([
            '<select id="pieItem' + itemNumber + '">',
            '<option value="CAR_SERVICES" data-icon="waze-icon-place-car" style="font-weight:bold;">' + I18n.translations[I18n.currentLocale()].venues.categories.CAR_SERVICES + '</option>',
            '<option value="GAS_STATION" data-icon="waze-icon-place-car">' + I18n.translations[I18n.currentLocale()].venues.categories.GAS_STATION + '</option>',
            '<option value="GARAGE_AUTOMOTIVE_SHOP" data-icon="waze-icon-place-car">' + I18n.translations[I18n.currentLocale()].venues.categories.GARAGE_AUTOMOTIVE_SHOP + '</option>',
            '<option value="CAR_WASH" data-icon="waze-icon-place-car">' + I18n.translations[I18n.currentLocale()].venues.categories.CAR_WASH + '</option>',
            '<option value="CHARGING_STATION" data-icon="waze-icon-place-car">' + I18n.translations[I18n.currentLocale()].venues.categories.CHARGING_STATION + '</option>',
            '<option value="TRANSPORTATION" data-icon="waze-icon-place-transportation" style="font-weight:bold;">' + I18n.translations[I18n.currentLocale()].venues.categories.TRANSPORTATION + '</option>',
            '<option value="AIRPORT" data-icon="waze-icon-place-transportation">' + I18n.translations[I18n.currentLocale()].venues.categories.AIRPORT + '</option>',
            '<option value="BUS_STATION" data-icon="waze-icon-place-transportation">' + I18n.translations[I18n.currentLocale()].venues.categories.BUS_STATION + '</option>',
            '<option value="FERRY_PIER" data-icon="waze-icon-place-transportation">' + I18n.translations[I18n.currentLocale()].venues.categories.FERRY_PIER + '</option>',
            '<option value="SEAPORT_MARINA_HARBOR" data-icon="waze-icon-place-transportation">' + I18n.translations[I18n.currentLocale()].venues.categories.SEAPORT_MARINA_HARBOR + '</option>',
            '<option value="SUBWAY_STATION" data-icon="waze-icon-place-transportation">' + I18n.translations[I18n.currentLocale()].venues.categories.SUBWAY_STATION + '</option>',
            '<option value="TRAIN_STATION" data-icon="waze-icon-place-transportation">' + I18n.translations[I18n.currentLocale()].venues.categories.TRAIN_STATION + '</option>',
            '<option value="BRIDGE" data-icon="waze-icon-place-transportation">' + I18n.translations[I18n.currentLocale()].venues.categories.BRIDGE + '</option>',
            '<option value="TUNNEL" data-icon="waze-icon-place-transportation">' + I18n.translations[I18n.currentLocale()].venues.categories.TUNNEL + '</option>',
            '<option value="TAXI_STATION" data-icon="waze-icon-place-transportation">' + I18n.translations[I18n.currentLocale()].venues.categories.TAXI_STATION + '</option>',
            '<option value="JUNCTION_INTERCHANGE" data-icon="waze-icon-place-transportation">' + I18n.translations[I18n.currentLocale()].venues.categories.JUNCTION_INTERCHANGE + '</option>',
            '<option value="PROFESSIONAL_AND_PUBLIC" data-icon="waze-icon-place-professional" style="font-weight:bold;">' + I18n.translations[I18n.currentLocale()].venues.categories.PROFESSIONAL_AND_PUBLIC + '</option>',
            '<option value="COLLEGE_UNIVERSITY" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.COLLEGE_UNIVERSITY + '</option>',
            '<option value="SCHOOL" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.SCHOOL + '</option>',
            '<option value="CONVENTIONS_EVENT_CENTER" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.CONVENTIONS_EVENT_CENTER + '</option>',
            '<option value="GOVERNMENT" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.GOVERNMENT + '</option>',
            '<option value="LIBRARY" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.LIBRARY + '</option>',
            '<option value="CITY_HALL" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.CITY_HALL + '</option>',
            '<option value="ORGANIZATION_OR_ASSOCIATION" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.ORGANIZATION_OR_ASSOCIATION + '</option>',
            '<option value="PRISON_CORRECTIONAL_FACILITY" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.PRISON_CORRECTIONAL_FACILITY + '</option>',
            '<option value="COURTHOUSE" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.COURTHOUSE + '</option>',
            '<option value="CEMETERY" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.CEMETERY + '</option>',
            '<option value="FIRE_DEPARTMENT" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.FIRE_DEPARTMENT + '</option>',
            '<option value="POLICE_STATION" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.POLICE_STATION + '</option>',
            '<option value="MILITARY" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.MILITARY + '</option>',
            '<option value="HOSPITAL_URGENT_CARE" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.HOSPITAL_URGENT_CARE + '</option>',
            '<option value="DOCTOR_CLINIC" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.DOCTOR_CLINIC + '</option>',
            '<option value="OFFICES" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.OFFICES + '</option>',
            '<option value="POST_OFFICE" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.POST_OFFICE + '</option>',
            '<option value="RELIGIOUS_CENTER" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.RELIGIOUS_CENTER + '</option>',
            '<option value="KINDERGARTEN" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.KINDERGARDEN + '</option>',
            '<option value="FACTORY_INDUSTRIAL" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.FACTORY_INDUSTRIAL + '</option>',
            '<option value="EMBASSY_CONSULATE" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.EMBASSY_CONSULATE + '</option>',
            '<option value="INFORMATION_POINT" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.INFORMATION_POINT + '</option>',
            '<option value="EMERGENCY_SHELTER" data-icon="waze-icon-place-professional">' + I18n.translations[I18n.currentLocale()].venues.categories.EMERGENCY_SHELTER + '</option>',
            '<option value="SHOPPING_AND_SERVICES" data-icon="waze-icon-place-shopping" style="font-weight:bold;">' + I18n.translations[I18n.currentLocale()].venues.categories.SHOPPING_AND_SERVICES + '</option>',
            '<option value="ARTS_AND_CRAFTS" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.ARTS_AND_CRAFTS + '</option>',
            '<option value="BANK_FINANCIAL" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.BANK_FINANCIAL + '</option>',
            '<option value="SPORTING_GOODS" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.SPORTING_GOODS + '</option>',
            '<option value="BOOKSTORE" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.BOOKSTORE + '</option>',
            '<option value="PHOTOGRAPHY" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.PHOTOGRAPHY + '</option>',
            '<option value="CAR_DEALERSHIP" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.CAR_DEALERSHIP + '</option>',
            '<option value="FASHION_AND_CLOTHING" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.FASHION_AND_CLOTHING + '</option>',
            '<option value="CONVENIENCE_STORE" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.CONVENIENCE_STORE + '</option>',
            '<option value="PERSONAL_CARE" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.PERSONAL_CARE + '</option>',
            '<option value="DEPARTMENT_STORE" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.DEPARTMENT_STORE + '</option>',
            '<option value="PHARMACY" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.PHARMACY + '</option>',
            '<option value="ELECTRONICS" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.ELECTRONICS + '</option>',
            '<option value="FLOWERS" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.FLOWERS + '</option>',
            '<option value="FURNITURE_HOME_STORE" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.FURNITURE_HOME_STORE + '</option>',
            '<option value="GIFTS" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.GIFTS + '</option>',
            '<option value="GYM_FITNESS" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.GYM_FITNESS + '</option>',
            '<option value="SWIMMING_POOL" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.SWIMMING_POOL + '</option>',
            '<option value="HARDWARE_STORE" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.HARDWARE_STORE + '</option>',
            '<option value="MARKET" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.MARKET + '</option>',
            '<option value="SUPERMARKET_GROCERY" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.SUPERMARKET_GROCERY + '</option>',
            '<option value="JEWELRY" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.JEWELRY + '</option>',
            '<option value="LAUNDRY_DRY_CLEAN" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.LAUNDRY_DRY_CLEAN + '</option>',
            '<option value="SHOPPING_CENTER" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.SHOPPING_CENTER + '</option>',
            '<option value="MUSIC_STORE" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.MUSIC_STORE + '</option>',
            '<option value="PET_STORE_VETERINARIAN_SERVICES" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.PET_STORE_VETERINARIAN_SERVICES + '</option>',
            '<option value="TOY_STORE" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.TOY_STORE + '</option>',
            '<option value="TRAVEL_AGENCY" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.TRAVEL_AGENCY + '</option>',
            '<option value="ATM" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.ATM + '</option>',
            '<option value="CURRENCY_EXCHANGE" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.CURRENCY_EXCHANGE + '</option>',
            '<option value="CAR_RENTAL" data-icon="waze-icon-place-shopping">' + I18n.translations[I18n.currentLocale()].venues.categories.CAR_RENTAL + '</option>',
            '<option value="FOOD_AND_DRINK" data-icon="waze-icon-place-food-drink" style="font-weight:bold;">' + I18n.translations[I18n.currentLocale()].venues.categories.FOOD_AND_DRINK + '</option>',
            '<option value="RESTAURANT" data-icon="waze-icon-place-food-drink">' + I18n.translations[I18n.currentLocale()].venues.categories.RESTAURANT + '</option>',
            '<option value="BAKERY" data-icon="waze-icon-place-food-drink">' + I18n.translations[I18n.currentLocale()].venues.categories.BAKERY + '</option>',
            '<option value="DESSERT" data-icon="waze-icon-place-food-drink">' + I18n.translations[I18n.currentLocale()].venues.categories.DESSERT + '</option>',
            '<option value="CAFE" data-icon="waze-icon-place-food-drink">' + I18n.translations[I18n.currentLocale()].venues.categories.CAFE + '</option>',
            '<option value="FAST_FOOD" data-icon="waze-icon-place-food-drink">' + I18n.translations[I18n.currentLocale()].venues.categories.FAST_FOOD + '</option>',
            '<option value="FOOD_COURT" data-icon="waze-icon-place-food-drink">' + I18n.translations[I18n.currentLocale()].venues.categories.FOOD_COURT + '</option>',
            '<option value="BAR" data-icon="waze-icon-place-food-drink">' + I18n.translations[I18n.currentLocale()].venues.categories.BAR + '</option>',
            '<option value="ICE_CREAM" data-icon="waze-icon-place-food-drink">' + I18n.translations[I18n.currentLocale()].venues.categories.ICE_CREAM + '</option>',
            '<option value="CULTURE_AND_ENTERTAINEMENT" data-icon="waze-icon-place-culture" style="font-weight:bold;">' + I18n.translations[I18n.currentLocale()].venues.categories.CULTURE_AND_ENTERTAINEMENT + '</option>',
            '<option value="ART_GALLERY" data-icon="waze-icon-place-culture">' + I18n.translations[I18n.currentLocale()].venues.categories.ART_GALLERY + '</option>',
            '<option value="CASINO" data-icon="waze-icon-place-culture">' + I18n.translations[I18n.currentLocale()].venues.categories.CASINO + '</option>',
            '<option value="CLUB" data-icon="waze-icon-place-culture">' + I18n.translations[I18n.currentLocale()].venues.categories.CLUB + '</option>',
            '<option value="TOURIST_ATTRACTION_HISTORIC_SITE" data-icon="waze-icon-place-culture">' + I18n.translations[I18n.currentLocale()].venues.categories.TOURIST_ATTRACTION_HISTORIC_SITE + '</option>',
            '<option value="MOVIE_THEATER" data-icon="waze-icon-place-culture">' + I18n.translations[I18n.currentLocale()].venues.categories.MOVIE_THEATER + '</option>',
            '<option value="MUSEUM" data-icon="waze-icon-place-culture">' + I18n.translations[I18n.currentLocale()].venues.categories.MUSEUM + '</option>',
            '<option value="MUSIC_VENUE" data-icon="waze-icon-place-culture">' + I18n.translations[I18n.currentLocale()].venues.categories.MUSIC_VENUE + '</option>',
            '<option value="PERFORMING_ARTS_VENUE" data-icon="waze-icon-place-culture">' + I18n.translations[I18n.currentLocale()].venues.categories.PERFORMING_ARTS_VENUE + '</option>',
            '<option value="GAME_CLUB" data-icon="waze-icon-place-culture">' + I18n.translations[I18n.currentLocale()].venues.categories.GAME_CLUB + '</option>',
            '<option value="STADIUM_ARENA" data-icon="waze-icon-place-culture">' + I18n.translations[I18n.currentLocale()].venues.categories.STADIUM_ARENA + '</option>',
            '<option value="THEME_PARK" data-icon="waze-icon-place-culture">' + I18n.translations[I18n.currentLocale()].venues.categories.THEME_PARK + '</option>',
            '<option value="ZOO_AQUARIUM" data-icon="waze-icon-place-culture">' + I18n.translations[I18n.currentLocale()].venues.categories.ZOO_AQUARIUM + '</option>',
            '<option value="RACING_TRACK" data-icon="waze-icon-place-culture">' + I18n.translations[I18n.currentLocale()].venues.categories.RACING_TRACK + '</option>',
            '<option value="THEATER" data-icon="waze-icon-place-culture">' + I18n.translations[I18n.currentLocale()].venues.categories.THEATER + '</option>',
            '<option value="OTHER" data-icon="waze-icon-place" style="font-weight:bold;">' + I18n.translations[I18n.currentLocale()].venues.categories.OTHER + '</option>',
            '<option value="CONSTRUCTION_SITE" data-icon="">' + I18n.translations[I18n.currentLocale()].venues.categories.CONSTRUCTION_SITE + '</option>',
            '<option value="LODGING" data-icon="waze-icon-place-lodging" style="font-weight:bold;">' + I18n.translations[I18n.currentLocale()].venues.categories.LODGING + '</option>',
            '<option value="HOTEL" data-icon="waze-icon-place-lodging">' + I18n.translations[I18n.currentLocale()].venues.categories.HOTEL + '</option>',
            '<option value="HOSTEL" data-icon="waze-icon-place-lodging">' + I18n.translations[I18n.currentLocale()].venues.categories.HOSTEL + '</option>',
            '<option value="CAMPING_TRAILER_PARK" data-icon="waze-icon-place-lodging">' + I18n.translations[I18n.currentLocale()].venues.categories.CAMPING_TRAILER_PARK + '</option>',
            '<option value="COTTAGE_CABIN" data-icon="waze-icon-place-lodging">' + I18n.translations[I18n.currentLocale()].venues.categories.COTTAGE_CABIN + '</option>',
            '<option value="BED_AND_BREAKFAST" data-icon="waze-icon-place-lodging">' + I18n.translations[I18n.currentLocale()].venues.categories.BED_AND_BREAKFAST + '</option>',
            '<option value="OUTDOORS" data-icon="waze-icon-place-outdoors" style="font-weight:bold;">' + I18n.translations[I18n.currentLocale()].venues.categories.OUTDOORS + '</option>',
            '<option value="PARK" data-icon="waze-icon-place-outdoors">' + I18n.translations[I18n.currentLocale()].venues.categories.PARK + '</option>',
            '<option value="PLAYGROUND" data-icon="waze-icon-place-outdoors">' + I18n.translations[I18n.currentLocale()].venues.categories.PLAYGROUND + '</option>',
            '<option value="BEACH" data-icon="waze-icon-place-outdoors">' + I18n.translations[I18n.currentLocale()].venues.categories.BEACH + '</option>',
            '<option value="SPORTS_COURT" data-icon="waze-icon-place-outdoors">' + I18n.translations[I18n.currentLocale()].venues.categories.SPORTS_COURT + '</option>',
            '<option value="GOLF_COURSE" data-icon="waze-icon-place-outdoors">' + I18n.translations[I18n.currentLocale()].venues.categories.GOLF_COURSE + '</option>',
            '<option value="PLAZA" data-icon="waze-icon-place-outdoors">' + I18n.translations[I18n.currentLocale()].venues.categories.PLAZA + '</option>',
            '<option value="PROMENADE" data-icon="waze-icon-place-outdoors">' + I18n.translations[I18n.currentLocale()].venues.categories.PROMENADE + '</option>',
            '<option value="POOL" data-icon="waze-icon-place-outdoors">' + I18n.translations[I18n.currentLocale()].venues.categories.POOL + '</option>',
            '<option value="SCENIC_LOOKOUT_VIEWPOINT" data-icon="waze-icon-place-outdoors">' + I18n.translations[I18n.currentLocale()].venues.categories.SCENIC_LOOKOUT_VIEWPOINT + '</option>',
            '<option value="SKI_AREA" data-icon="waze-icon-place-outdoors">' + I18n.translations[I18n.currentLocale()].venues.categories.SKI_AREA + '</option>',
            '<option value="NATURAL_FEATURES" data-icon="waze-icon-place-natural" style="font-weight:bold;">' + I18n.translations[I18n.currentLocale()].venues.categories.NATURAL_FEATURES + '</option>',
            '<option value="ISLAND" data-icon="waze-icon-place-natural">' + I18n.translations[I18n.currentLocale()].venues.categories.ISLAND + '</option>',
            '<option value="SEA_LAKE_POOL" data-icon="waze-icon-place-natural">' + I18n.translations[I18n.currentLocale()].venues.categories.SEA_LAKE_POOL + '</option>',
            '<option value="RIVER_STREAM" data-icon="waze-icon-place-natural">' + I18n.translations[I18n.currentLocale()].venues.categories.RIVER_STREAM + '</option>',
            '<option value="FOREST_GROVE" data-icon="waze-icon-place-natural">' + I18n.translations[I18n.currentLocale()].venues.categories.FOREST_GROVE + '</option>',
            '<option value="FARM" data-icon="waze-icon-place-natural">' + I18n.translations[I18n.currentLocale()].venues.categories.FARM + '</option>',
            '<option value="CANAL" data-icon="waze-icon-place-natural">' + I18n.translations[I18n.currentLocale()].venues.categories.CANAL + '</option>',
            '<option value="SWAMP_MARSH" data-icon="waze-icon-place-natural">' + I18n.translations[I18n.currentLocale()].venues.categories.SWAMP_MARSH + '</option>',
            '<option value="DAM" data-icon="waze-icon-place-natural">' + I18n.translations[I18n.currentLocale()].venues.categories.DAM + '</option>',
            '<option value="PARKING_LOT" style="font-weight:bold;">' + I18n.translations[I18n.currentLocale()].venues.categories.PARKING_LOT + '</option>',
            '<option value="RESIDENCE_HOME" data-icon="waze-icon-house" style="font-weight:bold;">' + I18n.translations[I18n.currentLocale()].venues.categories.RESIDENCE_HOME + '</option>',
            '</select>'
            ].join(' '));

        return $places.html();
    }

    function injectCss() {
        var css =  [
            // Lock button formatting
            '.btn-lh {cursor:pointer;padding:1px 6px;height:22px;border:solid 1px #c1c1c1;margin-right:3px;}',
            '.btn.btn-lh.btn-lh-selected {background-color:#6999ae;color:white}',
            '.btn.btn-lh.btn-lh-selected:hover {color:white}',
            '.btn.btn-lh.disabled {color:#909090;background-color:#f7f7f7;}',
            '.btn.btn-lh.btn-lh-selected.disabled {color:white;background-color:#6999ae;}',
            //Settings Panel
             '#sidebar .controls-container.pie-controls-container {padding: 0px;}',
            '.select2-choices {-webkit-animation-name: oldCategoryDetected; -webkit-animation-duration: 10s; -webkit-animation-iteration-count: 0; animation-name: oldCategoryDetected; animation-duration: 3s; animation-iteration-count: 0;}',
            '@keyframes oldCategoryDetected {0% {border-color:rgb(204, 204, 204); border-width:3px;} 50%  {border-color:red; border-width:3px;} 100% {border-color:rgb(204, 204, 204); border-width:3px;}',

        ].join(' ');
        $('<style type="text/css">' + css + '</style>').appendTo('head');
    }

    function injectCSSWithID(id, css){
        $('<style type="text/css" id=' + id + '>' + css + '</style>').appendTo('head');
    }

    function loadTranslations() {
        setTranslations({
            en: {
                prefs: {
                    title: 'Place Interface Enhancements',
                    ShowAreaPlaceSize: 'Show area Place size',
                    ShowImperial: 'Show imperial',
                    ShowMetric: 'Show metric',
                    ShowRPPLockButtons: 'Show lock buttons for RPPs',
                    ShowRPPLockButtonsTitle: 'Displays lock level buttons for Residential Place Points',
                    ShowPlaceLocatorCrosshair: 'Centers the Place on screen and zooms to the defined level',
                    ShowPlaceLocatorCrosshairTitle: 'Centers the Place on screen and zooms to the defined level',
                    Zoom: 'Zoom',
                    ZoomTitle: 'The zoom level to use when centering on a Place',
                    ShowAddressSearch: 'Show search button next to address',
                    ShowAddressSearchTitle: "Show a magnifying glass next to the Place's address.  Clicking this button will load the address into the search box",
                    ShowPlaceCategoryButtons: 'Add Place category buttons above the categories selection',
                    ShowPLAButton: 'Show parking lot button',
                    ShowPLAButtonTitle: "Starts creation mode for a Parking Lot Area Place and will set the name to match this Place\'s name when complete",
                    ShowCopyPlaceButton: 'Show copy Place button',
                    ShowCopyPlaceButtonTitle: 'Copies the selected Place to a new Place with identical settings',
                    ShowGPIDTooltip: 'Show External Provider tooltip',
                    ShowGPIDTooltipTitle: 'Displays a tooltip with the external provider information',
                    NewPlaces: 'New Places',
                    EditRPPAfterCreate: 'Edit RPP address after created',
                    EditRPPAfterCreateTitle: "Automatically opens the RPP address edit window and focuses on the House Number entry",
                    UseStreetFromClosestSegment: 'Use street name from closest segment',
                    UseStreetFromClosestSegmentTitle: "Pulls the street name from the closest visible segment and inserts into the new Place's address",
                    UseCityFromClosestSegment: 'Use city name from closest segment',
                    UseCityFromClosestSegmentTitle: "Pulls the city name from the closest visible segment and inserts into the new Place's address",
                    ClosestSegmentAltCity: 'When the primary is "No city" look for an alt city',
                    ClosestSegmentAltCityTitle: 'When the primary is \'No city\' try to find an alt street name with a city',
                    ClosestSegmentIgnorePLRUnnamedPR: "Ignore PLRs & unnamed PR when using closest segment's name and city",
                    ClosestSegmentIgnorePLRUnnamedPRTitle: "When looking for the closest segment, PLRs and unnamed PRs will be ignored",
                    LockLevel: 'Lock level',
                    LockLevelTitle: 'The lock level to set automatically when creating new Places',
                    MapChanges: 'Map Changes',
                    ShowPlaceNames: 'Show Place names',
                    ShowPlaceNamesTitle: '',
                    ShowPointNames: 'Show point names',
                    ShowPointNamesTitle: "Will display the Place's name below the Place point",
                    ShowAreaNames: 'Show area names',
                    ShowAreaNamesTitle: "Will display the Place's name in the middle of the Place area",
                    ShowLockLevel: 'Show lock level',
                    ShowLockLevelTitle: "Will display the Place's lock level in the middle of the Place area",
                    ShowPLAName: 'Show PLA name',
                    ShowPLANameTitle: '',
                    Item: 'Item',
                    PlaceMenuCustomization: "Place Menu Customization"
                }
            },
            "es-419": {
                prefs: {
                    title: 'Place Interface Enhancements',
                    ShowAreaPlaceSize: 'Mostrar tamaño del área',
                    ShowImperial: 'Sistema Imperial',
                    ShowMetric: 'Sistema Métrico',
                    ShowRPPLockButtons: 'Mostrar botones de bloqueo para RPPs',
                    ShowRPPLockButtonsTitle: 'Muestra los botones de nivel de bloqueo para lugares residenciales',
                    ShowPlaceLocatorCrosshair: 'Mostrar reticula localizadora del lugar',
                    ShowPlaceLocatorCrosshairTitle: 'Centra el lugar en la pantalla y acercamiento al nivel definido',
                    Zoom: 'Acercamiento',
                    ZoomTitle: 'Nivel de acercamiento a utilizar cuando se centra en un lugar',
                    ShowAddressSearch: 'Mostrar el botón de búsqueda junto a la dirección',
                    ShowAddressSearchTitle: "Muestra una lupa junto a la dirección del lugar. Al hacer clic en este botón, se cargará la dirección en la barra de búsqueda",
                    ShowPlaceCategoryButtons: 'Botones de categorías de lugares',
                    ShowPLAButton: 'Mostrar botón de PLAs',
                    ShowPLAButtonTitle: 'Inicia el modo de creación de un lugar del área de estacionamiento y establecerá el nombre del estacionamiento para que coincida con el nombre del lugar cuando se complete',
                    ShowCopyPlaceButton: 'Mostrar botón de copiado de lugar',
                    ShowCopyPlaceButtonTitle: 'Copia el lugar seleccionado en un lugar nuevo con configuraciones idénticas',
                    ShowGPIDTooltip: 'Mostrar información del proveedor externo',
                    ShowGPIDTooltipTitle: 'Muestra un texto con la información del proveedor externo',
                    NewPlaces: 'Nuevos lugares',
                    EditRPPAfterCreate: 'Editar la dirección del RPP una vez creada',
                    EditRPPAfterCreateTitle: "Automáticamente abre la ventana de edición en la dirección del lugar residencial y se enfoca en el campo de número de casa",
                    UseStreetFromClosestSegment: 'Utilice el nombre de la calle del segmento más cercano',
                    UseStreetFromClosestSegmentTitle: "Extrae el nombre de la calle del segmento visible más cercano y lo agrega en la dirección del nuevo lugar",
                    UseCityFromClosestSegment: 'Usar el nombre de la ciudad del segmento más cercano',
                    UseCityFromClosestSegmentTitle: "Extrae el nombre de la ciudad del segmento visible más cercano y lo agrega en la dirección del nuevo lugar",
                    ClosestSegmentAltCity: 'Cuando la ciudad principal es "Ninguno" busca una ciudad alternativa',
                    ClosestSegmentAltCityTitle: 'Cuando la ciudad principal es "Ninguno" trata de encontrar un nombre de calle alternativo con una ciudad',
                    ClosestSegmentIgnorePLRUnnamedPR: "Ignora los PLR y PR sin nombre cuando utilice el nombre y la ciudad del segmento más cercano",
                    ClosestSegmentIgnorePLRUnnamedPRTitle: "Ignorar segmentos de estacionamiento o privados al buscar el segmento mas cercano",
                    LockLevel: 'Nivel de bloqueo',
                    LockLevelTitle: 'El nivel de bloqueo para establecer automáticamente al crear nuevos lugares',
                    MapChanges: 'Cambios en el mapa',
                    ShowPlaceNames: 'Mostrar nombres de lugares',
                    ShowPlaceNamesTitle: '',
                    ShowPointNames: 'Mostrar nombres de punto',
                    ShowPointNamesTitle: "Muestra el nombre de lugares definidos como punto",
                    ShowAreaNames: 'Mostrar nombres de área',
                    ShowAreaNamesTitle: "Muestra el nombre de lugares definidos como área",
                    ShowLockLevel: 'Mostrar nivel de bloqueo',
                    ShowLockLevelTitle: "Muestra el nivel de bloqueo en el centro del lugar",
                    ShowPLAName: 'Mostrar nombre de PLA',
                    ShowPLANameTitle: 'Muestra el nombre de áreas de estacionamiento (PLAs)',
                    Item: 'Item',
                    PlaceMenuCustomization: "Personalización del menú de lugares"
                }
            }
        });
    }

    function setTranslations(translations) {
        I18n.translations[I18n.currentLocale()].pie = translations.en;
        for (var i = 0; i < Object.keys(translations).length; i++) {
            var locale = Object.keys(translations)[i];
            if (I18n.currentLocale() == locale) {
                I18n.translations[locale].pie.prefs = translations[locale].prefs;
                return;
            }
        }
    }

    function listPlaces(){
        var category = "";
        for(i=0; i<W.Config.venues.categories.length; i++){
            category = W.Config.venues.categories[i];
            console.log(category + " Main");
            var subCategories = W.Config.venues.subcategories[category];
            for(var j=0; j<subCategories.length;j++){
                console.log(subCategories[j]);
            }
        }
    }
})();