﻿function AJ() {
    var obj;
    if (window.XMLHttpRequest) {
        obj = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
            obj = new ActiveXObject('MSXML2.XMLHTTP');
        } catch (er) {
            try {
                obj = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (er) {
                obj = false;
            }
        }
    }
    return obj;
}

function checkIfUrlExists(url) {
    var req = AJ(); // XMLHttpRequest object
    try {
        req.open("HEAD", url, false);
        req.send(null);
        return (req.status == 200 ? true : false);
    }
    catch (er) {
        return false;
    }
}


/**
Map
**/
function Map(divMap, divSidePanel, divMeasureInfo, divGPSInfo) {
    // general setup
    this.map = new NSZemljevid(divMap);

    this.panZoomControl = this.map.addPanZoomControl();
    this.moveGauges(false);
    this.map.addHybridControl();
    this.map.addSatelliteControl();
    this.map.enableOverlays({
        weather:true,
        traffic:true,
        mpp:true,
        vrhovi:true,
        cameras:true,
        snow:false
    });
    this.map.addOverviewControl();
    this.map.activateADM({
        proxy: "NajdiProxy.aspx"    //"NajdiProxyService.asmx/Proxy", "http://www.proxyurl.com/service.aspx"
    });
    //this.map.activateAds(["traffic"]);

    /*this.map.addMeasureControl({
        left: 18,
        digits: 2,
        top: 217,
        callbacks: {
            "onMeasure": function(e) {
                map.divMeasureInfo.innerHTML = "Razdalja: " + e.length + " " + e.units + "<br /><span style=\"color:red; font-size:9px;\">Končaj: dvoklik, Izhod: ESC</span>";
            },
            "onChange": function(status) {
                map.divMeasureInfo.innerHTML = "Izberite točke na zemljevidu.";
                map.divMeasureInfo.style.display = status ? "block" : "none";
            }
        }
    });

    this.map.addGPSControl({
        left: 18,
        digits: 6,
        top: 252,
        callbacks: {
            "click": function(coord) {
                map.divGPSInfo.innerHTML = "Zemljepisna dolžina: " + coord.lon + ", širina: " + coord.lat + "<br /><span style=\"color:red; font-size:9px;\">Izhod: ESC</span>";
            },
            "onChange": function onChange(status) {
                map.divGPSInfo.innerHTML = "Izberite točko na zemljevidu.";
                map.divGPSInfo.style.display = status ? "block" : "none";
            }
        }
    });*/

    this.map.addGPSMeasure({
        gpsDigits: 8,
        measureDigits: 2,
        eventListeners: {
            "onGPSClick": function(coord) {
                map.divGPSInfo.innerHTML = "Zemljepisna dolžina: " + coord.lon + ", širina: " + coord.lat + "<br /><span style=\"color:red; font-size:9px;\">Izhod: ESC</span>";
            },
            "onGPSChange": function onChange(o) {
                map.divGPSInfo.innerHTML = "Izberite točko na zemljevidu.";
                map.divGPSInfo.style.display = o.status ? "block" : "none";
            },
            "onMeasure": function(e) {
                map.divMeasureInfo.innerHTML = "Razdalja: " + e.length + " " + e.units + "<br /><span style=\"color:red; font-size:9px;\">Končaj: dvoklik, Izhod: ESC</span>";
            },
            "onMeasureChange": function(o) {
                map.divMeasureInfo.innerHTML = "Izberite točke na zemljevidu.";
                map.divMeasureInfo.style.display = o.status ? "block" : "none";
            }
        }
    });


    // event handling
    this.map.addEventListener("resize", function(e) {
        var newSize = this.computeWindowToFit();
        if (this.isFullscreen) {
            this.divMap.parentNode.style.width = this.divMap.style.width = newSize.w + "px";
            this.divMap.parentNode.style.height = this.divMap.style.height = newSize.h + "px";
            this.map.setSize(newSize);
        } else {
            this.divMap.parentNode.style.width = this.divMap.style.width = newSize.w + "px";
            this.divMap.parentNode.style.height = this.divMap.style.height = this.defaultSize.h + "px";
            this.map.setSize(newSize);
        }
    }, this);

    // custom extensions
    this.hits = new Hits();
    this.path = new Path();

    this.divMap = document.getElementById(divMap);
    this.sidePanel = document.getElementById(divSidePanel);
    this.divMeasureInfo = document.getElementById(divMeasureInfo);
    this.divGPSInfo = document.getElementById(divGPSInfo);

    this.defaultSize = this.map.map.getSize();    // get html container fixed size at init time
    this.isFullscreen = false;

    this.urlQueryString = null;
}

// static fields and methods
Map.markerContent = "";

Map.showMarkerPopup = function(hitType, hitId) {
    TisSearch.FindOKx(hitType, hitId, Map.fillMarkerPopupCallback);
}

Map.fillMarkerPopupCallback = function(result) {
    if (result == null) {
        if (map != null && map.urlQueryString != null && map.urlQueryString.parameters != null && map.urlQueryString.parameters.n != null) {
            // content from URL if available (map instance must exist too)
            result = new Object();
            result.presentation = new Object();
            result.presentation.cloudType = "HIT";
            result.presentation.id = "";
            result.presentation.logo = null;
            result.presentation.info = decodeURI(map.urlQueryString.parameters.n).replace(/\|/g, "<br />");     // extract url query string parameter as content
            result.presentation.promotionImage = null;
            result.presentation.promotion = null;
            result.presentation.contacts = null;
            result.presentation.activities = null;
            result.presentation.tool1 = null;
            result.presentation.tool2 = null;
            result.presentation.tool3 = null;
            result.presentation.tool4 = null;
            result.presentation.tool5 = null;
        } else {
            // nothing to display at all
            Map.markerContent = "";
            return;
        }
    }

    if (result.presentation.cloudType == "")
        result.presentation.cloudType = "HIT";

    if (result.presentation.cloudType == "HIT") {
        Map.markerContent = "<div style=\"font-family: Arial; font-size: 11px; color: rgb(0, 0, 0); width: 260px;\"><div style=\"padding: 10px 0px 10px 12px;\">";
        //Map.markerContent += result.presentation.cloudType;
        //Map.markerContent += result.presentation.id;

        if (!stringIsNullOrEmpty(result.presentation.logo)) {
            if (checkIfUrlExists(glbMapServerBaseURL + "/_uploads/logos/" + result.presentation.logo + ".jpg"))
                Map.markerContent += "<img style=\"padding:0px 3px 3px 0px;\" src=\"" + glbMapServerBaseURL + "/_uploads/logos/" + result.presentation.logo + ".jpg\" />";
            else
                Map.markerContent += "<img style=\"padding:0px 3px 3px 0px;\" src=\"" + glbMapServerBaseURL + "/logo/" + result.presentation.logo + ".gif\" />";
        }

        Map.markerContent += !stringIsNullOrEmpty(result.presentation.info) ? "<p style=\"padding:0; margin:0;\">" + result.presentation.info + "</p>" : "";

        if (!stringIsNullOrEmpty(result.presentation.promotionImage)) {
            if (checkIfUrlExists(glbMapServerBaseURL + "/_uploads/logos/" + result.presentation.promotionImage + ".jpg"))
                Map.markerContent += "<br /><img style=\"padding:0px 5px 3px 0px;\" src=\"" + glbMapServerBaseURL + "/_uploads/logos/" + result.presentation.promotionImage + ".jpg\" alt=\"\" />";
            else
                Map.markerContent += "<br /><img style=\"padding:0px 5px 3px 0px;\" src=\"" + glbMapServerBaseURL + "/logo/" + result.presentation.promotionImage + ".gif\" alt=\"\" />";
        }

        Map.markerContent += !stringIsNullOrEmpty(result.presentation.promotion) ? (stringIsNullOrEmpty(result.presentation.promotionImage) ? "<br />" : "") + result.presentation.promotion + "<br />" : "";
        Map.markerContent += !stringIsNullOrEmpty(result.presentation.contacts) ? "<br />" + result.presentation.contacts.replace(/<\/li>/g, "<br />").replace(/<li>/g, "") + "<hr style=\"border:none; border-top:solid 1px #c0c0c0;  margin:9px 0px 2px 0px;\" />" : "";
        Map.markerContent += !stringIsNullOrEmpty(result.presentation.activities) ? "<ul style=\"list-style:none; padding:3px 0px; margin:0;\">" + result.presentation.activities.replace(/<li>/g, "<li>-&nbsp;") + "</ul>" : "";
        Map.markerContent += !stringIsNullOrEmpty(result.presentation.tool1) ? "<a href=\"" + result.presentation.tool1 + "\" title=\"Začetna točka\"><img style=\"margin:5px 5px 0px 0px; float:none;\" src=\"_Images/mtool1.gif\" /></a>" : "";
        Map.markerContent += !stringIsNullOrEmpty(result.presentation.tool2) ? "<a href=\"" + result.presentation.tool2 + "\" title=\"Končna točka\"><img style=\"margin:5px 5px 0px 0px; float:none;\" src=\"_Images/mtool2.gif\" /></a>" : "";
        Map.markerContent += !stringIsNullOrEmpty(result.presentation.tool3) && (glbUserType.toUpperCase().match(/[IE]/)) ? "<a href=\"" + result.presentation.tool3 + "\" title=\"Pošlji e-pošto\"><img style=\"margin:5px 5px 0px 0px; float:none;\" src=\"_Images/mtool3.gif\" /></a>" : "";
        Map.markerContent += !stringIsNullOrEmpty(result.presentation.tool4) && (glbUserType.toUpperCase().match(/[IE]/)) ? "<a href=\"" + result.presentation.tool4 + "\" title=\"Natisni\"><img style=\"margin:5px 5px 0px 0px; float:none;\" src=\"_Images/mtool4.gif\" /></a>" : "";
        Map.markerContent += !stringIsNullOrEmpty(result.presentation.tool5) ? "<a href=\"" + result.presentation.tool5 + "\" title=\"Shrani v MojTis\"><img style=\"margin:5px 5px 0px 0px; float:none;\" src=\"_Images/mtool5.gif\" /></a>" : "";
        Map.markerContent += "</div></div>";
    } else {
        Map.markerContent = "<div style=\"font-family:Arial;font-size:11px;color:#000000;width:400px;\"><div style=\"padding:12px;\">";

        Map.markerContent += "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tbody><tr>";
        if (!stringIsNullOrEmpty(result.presentation.logo)) {
            if (checkIfUrlExists(glbMapServerBaseURL + "/_uploads/logos/" + result.presentation.logo + ".jpg"))
                Map.markerContent += "<td width=\"160\" valign=\"top\" align=\"left\" style=\"padding-right:10px;width:160px;\"><a href=\"" + result.miniTisRecord.www + "\" target=\"_blank\" title=\"" + result.miniTisRecord.www + "\"><img border=\"0\" src=\"" + glbMapServerBaseURL + "/_uploads/logos/" + result.presentation.logo + ".jpg\" /></a></td>";
            else
                Map.markerContent += "<td width=\"160\" valign=\"top\" align=\"left\" style=\"padding-right:10px;width:160px;\"><a href=\"" + result.miniTisRecord.www + "\" target=\"_blank\" title=\"" + result.miniTisRecord.www + "\"><img border=\"0\" src=\"" + glbMapServerBaseURL + "/logo/" + result.presentation.logo + ".gif\" /></a></td>";
        }

        Map.markerContent += "<td valign=\"top\" align=\"left\">";
        Map.markerContent += !stringIsNullOrEmpty(result.presentation.info) ? result.presentation.info : "";
        Map.markerContent += !stringIsNullOrEmpty(result.presentation.contacts) ? result.presentation.contacts : "";
        Map.markerContent += "</td>"

        Map.markerContent += "</tr><tr><td colspan=\"2\"><div style=\"margin:5px 0; line-height:2px; height:2px; overflow:hidden; background-color:#d7dde5;\"></div></td></tr><tr><td width=\"400\" valign=\"top\" colspan=\"2\">";

        if (!stringIsNullOrEmpty(result.presentation.promotionImage)) {
            if (checkIfUrlExists(glbMapServerBaseURL + "/_uploads/logos/" + result.presentation.promotionImage + ".jpg"))
                Map.markerContent += "<a href=\"" + result.miniTisRecord.www + "\" target=\"_blank\" title=\"" + result.miniTisRecord.www + "\" style=\"float:left;padding-right:10px;\"><img border=\"0\" src=\"" + glbMapServerBaseURL + "/_uploads/logos/" + result.presentation.promotionImage + ".jpg\" /></a>";
            else
                Map.markerContent += "<a href=\"" + result.miniTisRecord.www + "\" target=\"_blank\" title=\"" + result.miniTisRecord.www + "\" style=\"float:left;padding-right:10px;\"><img border=\"0\" src=\"" + glbMapServerBaseURL + "/logo/" + result.presentation.promotionImage + ".gif\" /></a>";
        }

        Map.markerContent += !stringIsNullOrEmpty(result.presentation.promotion) ? result.presentation.promotion : "";
        Map.markerContent += "<div style=\"clear:both;\"></div></td></tr><tr><td colspan=\"2\"><div style=\"margin:5px 0; line-height:2px; height:2px; overflow:hidden; background-color:#d7dde5;\"></div></td></tr></tbody></table>";

        Map.markerContent += !stringIsNullOrEmpty(result.presentation.activities) ? "<div style=\"float:none; padding:0;\"><ul style=\"padding-left:0 ;margin:0; list-style:none outside none;\">" + result.presentation.activities + "</ul></div>" : "";

        Map.markerContent += "<div style=\"clear:both;\"></div><div style=\"margin:5px 0 0 0;line-height:2px;height:2px;overflow:hidden;background-color:#d7dde5;\"></div><div style=\"padding:8px 0 ;\">";
        Map.markerContent += "<a href=\"javascript:void(0);\" onclick=\"map.map.setCenter(new NSZemljevid.GK(" + result.miniTisRecord.x + "," + result.miniTisRecord.y + "), 12); map.map.setZoom(12); return false;\" style=\"color:#4963AD;padding: 4px 0 4px 30px;background:url(http://www.najdi.si/api/images/zoom-tool.png) no-repeat 0 0;\">približaj</a>";
        Map.markerContent += !stringIsNullOrEmpty(result.presentation.tool1) ? "<a href=\"" + result.presentation.tool1 + "\" title=\"Začetna točka\"><img style=\"margin:5px 5px 0px 0px; float:none;\" src=\"_Images/mtool1.gif\" /></a>" : "";
        Map.markerContent += !stringIsNullOrEmpty(result.presentation.tool2) ? "<a href=\"" + result.presentation.tool2 + "\" title=\"Končna točka\"><img style=\"margin:5px 5px 0px 0px; float:none;\" src=\"_Images/mtool2.gif\" /></a>" : "";
        Map.markerContent += !stringIsNullOrEmpty(result.presentation.tool3) && (glbUserType.toUpperCase().match(/[IE]/)) ? "<a href=\"" + result.presentation.tool3 + "\" title=\"Pošlji e-pošto\"><img style=\"margin:5px 5px 0px 0px; float:none;\" src=\"_Images/mtool3.gif\" /></a>" : "";
        Map.markerContent += !stringIsNullOrEmpty(result.presentation.tool4) && (glbUserType.toUpperCase().match(/[IE]/)) ? "<a href=\"" + result.presentation.tool4 + "\" title=\"Natisni\"><img style=\"margin:5px 5px 0px 0px; float:none;\" src=\"_Images/mtool4.gif\" /></a>" : "";
        Map.markerContent += !stringIsNullOrEmpty(result.presentation.tool5) ? "<a href=\"" + result.presentation.tool5 + "\" title=\"Shrani v MojTis\"><img style=\"margin:5px 5px 0px 0px; float:none;\" src=\"_Images/mtool5.gif\" /></a>" : "";
        Map.markerContent += "</div></div><p style=\"line-height:5px;margin:0;padding:0;\">&nbsp;</p></div>";
    }

    var markers = map.map.getMarkers();
    for (var i = 0; i < markers.length; i++) {
        if (markers[i].options.hit.id == result.presentation.id) {
            markers[i].openPopup(Map.markerContent);
            break;
        }
    }
}

// instance fields and methods
Map.prototype = {
    // fields
    map: null,
    panZoomControl: null,
    hits: null,
    path: null,
    divMap: null,
    sidePanel: null,
    divMeasureInfo: null,
    divGPSInfo: null,
    defaultSize: null,
    isFullscreen: false,
    urlQueryString: null,

    // methods
    moveGauges: function(areToolsOpened) {
        var offset = 10;
        if (areToolsOpened)
            offset = 380;

        this.panZoomControl.setPosition(offset, 5);
        // this.map.getControlByClass("Measure").div.style.left = (offset + 13) + "px";
        // this.map.getControlByClass("MousePositionGPS").div.style.left = (offset + 13) + "px";
    },

    /*showCity: function(ddlCityMaps) {
    if (ddlCityMaps.selectedIndex > 0) {
    var coord = ddlCityMaps.options[ddlCityMaps.selectedIndex].value.split(",");
    this.map.setCenter(new NSZemljevid.GK(parseInt(coord[0]), parseInt(coord[1])), parseInt(coord[2]));
    }
    },*/

    toggleSize: function() {
        var center = this.map.getCenter();
        var zoom = this.map.getZoom();
        var maxZoom = (this.map.map.maxZoom != null) ? this.map.map.maxZoom : 11; //this.map.map.numZoomLevels;

        var newSize = this.computeWindowToFit();

        if (this.isFullscreen) {
            this.sidePanel.style.cssText = "";

            if (zoom > 1) {     // if possible zoom out
                this.map.setZoom(zoom - 1);
            }

            //this.divMap.parentNode.style.width = this.divMap.style.width = this.defaultSize.w + "px";     // fixed size window
            this.divMap.parentNode.style.width = this.divMap.style.width = newSize.w + "px";   // variable width only
            this.divMap.parentNode.style.height = this.divMap.style.height = this.defaultSize.h + "px";
            //this.map.setSize(this.defaultSize);
            this.map.setSize({ w: newSize.w, h: this.defaultSize.h });

            // account for slidebar (dis)appearance
            newSize = this.computeWindowToFit();
            this.divMap.parentNode.style.width = this.divMap.style.width = newSize.w + "px";   // variable width only
            this.divMap.parentNode.style.height = this.divMap.style.height = this.defaultSize.h + "px";
            this.map.setSize({ w: newSize.w, h: this.defaultSize.h });
        } else {
            this.sidePanel.style.position = "fixed";
            this.sidePanel.style.zIndex = "10";
            this.sidePanel.parentNode.style.zIndex = "2";
            this.sidePanel.style.top = "0px";
            this.sidePanel.style.left = "0px";
            this.sidePanel.style.backgroundColor = "white";

            if (zoom < maxZoom) {     // if possible zoom in 1 level
                this.map.setZoom(zoom + 1);
            }

            this.divMap.parentNode.style.width = this.divMap.style.width = newSize.w + "px";
            this.divMap.parentNode.style.height = this.divMap.style.height = newSize.h + "px";
            this.map.setSize(newSize);

            // account for slidebar (dis)appearance
            newSize = this.computeWindowToFit();
            this.divMap.parentNode.style.width = this.divMap.style.width = newSize.w + "px";
            this.divMap.parentNode.style.height = this.divMap.style.height = newSize.h + "px";
            this.map.setSize(newSize);
        }

        this.isFullscreen = !this.isFullscreen;
    },

    // handles appearance of scrollbars (should be called only once at the end of page creation)
    rerenderAfterFirstLoad: function() {
        var newSize = { w: this.computeWindowToFit().w, h: this.defaultSize.h };
        this.divMap.parentNode.style.width = this.divMap.style.width = newSize.w + "px";   // variable width only
        this.divMap.parentNode.style.height = this.divMap.style.height = newSize.h + "px";
        this.map.setSize(newSize);

        var zoom = this.map.getZoom();
        this.map.setZoom(zoom + 1);

    },

    computeWindowToFit: function() {
        var width = 0;
        var height = 0;

        width = window.document.body.clientWidth;

        if (window.innerHeight) {
            height = window.innerHeight;
        } else {
            height = (window.document.compatMode == 'CSS1Compat' ? window.document.documentElement.clientHeight : window.document.body.clientHeight);
        }

        //width -= 56;    // mind the sidebar
        height -= 12;   // account for warious "viewer" borders and paddings

        if (width % 2)
            width--;

        if (height % 2)
            height--;

        return ({ w: width, h: height });
    },

    showHit: function(x, y, zoom) {
        this.map.setCenter(new NSZemljevid.GK(x, y), zoom);
    },

    getViewLink: function(publicationIDs, pathIDs) {
        var oTheme = this.getTheme();
        var coords = this.map.getCenter();
        var zoom = this.map.getZoom();
        var url = "dl=1&x=" + coords.x + "&y=" + coords.y + "&zl=" + zoom + "&theme=" + oTheme;

        var hfPathIds = document.getElementById(pathIDs);
        var hfIds = document.getElementById(publicationIDs);

        if (hfPathIds != null) {
            if (hfPathIds.value.toString().length > 0) {
                if (this.path.routeId != null && this.path.routeId != "")
                    url += "&path=1";
                url += "&markers=" + hfPathIds.value.toString();
            }
        } else if ((hfIds != null) && (hfIds.value.toString().length > 0)) {
            url += "&ids=" + hfIds.value.toString();
        }

        window.location = "Page_Map.aspx?" + url;
    },

    mailToMapLink: function() {
        var oTheme = this.getTheme();
        var markers = "";
        for (i = 0; i < this.hits.items.length; i++) {
            if (this.hits.items[i] != 0 && this.hits.items[i] != 0) {
                if (markers != "")
                    markers += ";";
                //markers += this.hits.items[i].x + "," + this.hits.items[i].y + "," + this.hits.items[i].name + "," + this.hits.items[i].id;
                markers += this.hits.items[i].id;
            }
        }

        var coords = this.map.getCenter();
        var zoom = this.map.getZoom();
        var url = "dl=1%26x=" + coords.x + "%26y=" + coords.y + "%26zl=" + zoom + "%26theme=" + oTheme;
        /*if (this.path.routeId != null && this.path.routeId != "")
        url += "%26path=1";
        if (markers != "")
        url += "%26markers=" + markers;*/
        if (markers != "")
            url += "%26ids=" + markers;

        url = encodeURI("http://www.itis.si/Page_Map.aspx?" + url);

        var message = "Spo%9Atovani,%0A%0A" +
                "s klikom na aktivno spletno povezavo " + url +
                " se vam bo odprlo okno spletnega brskalnika z prikazom lokacije telefonskega naro%E8nika," +
                " za katerega obiskovalec Telefonskega imenika Slovenije na spletu www.itis.si meni," +
                " da je za vas zanimiva.%0A%A0%A0%0D_______________________________" +
                "%0ATelefonski imenik Slovenije na spletu%0Awww.itis.si";

        var emailMessage = "mailto:?subject=Prijatelj priporo%E8a ogled!&body=" + message;

        window.location = emailMessage;
    },

    print: function(asPicture) {
        if (asPicture == null)
            asPicture = false;

        var oTheme = this.getTheme();
        var markers = "";
        for (i = 0; i < this.hits.items.length; i++) {
            if (this.hits.items[i] != 0 && this.hits.items[i] != 0) {
                if (markers != "")
                    markers += ";";
                //markers += this.hits.items[i].x + "," + this.hits.items[i].y + "," + this.hits.items[i].name + "," + this.hits.items[i].id;
                markers += this.hits.items[i].x + "," + this.hits.items[i].y;
            }
        }

        var coords = this.map.getCenter();
        var zoom = this.map.map.info.zoomLevelToZoom(this.map.getZoom());
        xwin = window.open("Page_MapPrint.aspx?" + encrypt("size=" + this.map.map.size.w + "&x=" + coords.x + "&y=" + coords.y + "&zoom=" + zoom + "&icons=0&theme=" + oTheme + "&RouteID=" + this.path.routeId + "&markers=" + markers + "&printPicture=" + (asPicture ? 1 : 0)), "mapprint", "toolbar=no,location=no,scrollbars=yes,status=yes,width=980,height=720");
        if (xwin)
            xwin.focus();
    },

    getTheme: function() {
        //var printingThemes = ["NormalView", "OrtophotoView", "HybridView", "RoadMapView"];
        var currentTheme;
        if (this.map.isSatelliteControlActive()) {
            currentTheme = "OrtophotoView";
        } else if (this.map.isHybridControlActive()) {
            currentTheme = "HybridView";
        } else {    //this.map.isStandardControlActive()
            currentTheme = "NormalView";
        }

        return currentTheme;
    },

    setTheme: function(theme) {
        if (theme == "OrtophotoView") {
            this.map.activateSatelliteMap();
        } else if (theme == "HybridView") {
            this.map.activateHybridMap();
        } else {    //"NormalView"
            this.map.activateStandardMap();
        }
    }
}
// Map - end


/*******
Map hits
*******/
function Hits() {
    this.items = new Array();
}

Hits.prototype = {
    // fields
    items: null,

    // methods
    add: function(type, id, x, y, name) {
        this.items.push({ type: type, id: id, x: x, y: y, name: name });
    },

    clear: function() {
        this.items = new Array();
    },

    markAll: function(nsMapRef) {
        // reverse display but not numbering order (keeps priorities)
        for (var i = (this.items.length - 1); i >= 0; i--) {
            if (this.items[i].x == 0 && this.items[i].y == 0)   // skip unknown coordinates
                continue;
            
            var gk = new NSZemljevid.GK(this.items[i].x, this.items[i].y);
            var icon = new NSZemljevid.Icon(/*this.hits.items.type*/NS_RED_ICON, i + 1);
            var marker = new NSZemljevid.Marker(gk, { icon: icon, hit: this.items[i] });

            marker.addEventListener("click", function(marker) {
                var hit = marker.options.hit;
                Map.showMarkerPopup(hit.type, hit.id);
            });
            nsMapRef.addMarker(marker);
        }
    }
}
// Map hits - end


/*******
Map path
*******/
function Path() {
    this.routeId = "";
    this.points = new Array();
    this.options = {
        style: {
            strokeColor: "#ff0000",
            strokeWidth: 5,
            strokeOpacity: .6
        }
    };
}

Path.prototype = {
    // fields
    routeId: null,
    points: null,
    options: null,

    // methods
    addPoint: function(x, y) {
        this.points.push(new NSZemljevid.Point(x, y));
    },

    clear: function(nsMapRef) {
        nsMapRef.clearNavigation();
        this.points = new Array();
        this.routeId = "";
    },

    draw: function(nsMapRef) {
        nsMapRef.drawNavigation(this.points, this.options);
    },

    addLocation: function(publicationId, position) {
        document.getElementById(glbrelayedPostbackContextControlId).value = "Add" + position + "Location|" + publicationId;
        relayClick(glbrelayedPostbackTriggerControlId);
    }
}
// Map path - end


/*********
Side panel
*********/
function SidePanel() {
}

SidePanel.toggle = function(sidePanelStateFieldId, sidePanelDivId, mapObj) {
    var sidePanelStateField = window.document.getElementById(sidePanelStateFieldId);
    var sidePanelDiv = window.document.getElementById(sidePanelDivId);

    if (sidePanelStateField.value == "toolbarClosed") {
        sidePanelStateField.value = "toolbarOpened";
        sidePanelDiv.className = sidePanelDiv.className.replace("toolbarClosed", "toolbarOpened");
        mapObj.moveGauges(true);
    } else {
        sidePanelStateField.value = "toolbarClosed";
        sidePanelDiv.className = sidePanelDiv.className.replace("toolbarOpened", "toolbarClosed");
        mapObj.moveGauges(false);
    }
}
// Side panel - end

