﻿/*Krak*/
/*function ShowZoomLevel() {
    removePopup();
    document.getElementById("HFExtent").value = tc.getMapViewExtent();
    document.getElementById("HFZoomLevel").value = tc.getZoomLevel();
    if (tc.getZoomLevel() < 6) {
        ShowThemes()
    } else {
        tc.removeAllPoi();
        __doPostBack('UpdatePanel1', 'RemoveThemes');
    }
}
function SetCenterCircle() {
    var radius;
    radius = tc.getCircleRadius() / 1.1;
    var top = tc.getCircleCenter().y + radius;
    var bottom = tc.getCircleCenter().y - radius;
    var right = tc.getCircleCenter().x + radius;
    var left = tc.getCircleCenter().x - radius;

    document.getElementById("HFCirclePoints").value = tc.getCircleCenter() + "," + tc.getCircleRadius();

    var ext = new KrakMap.Extent(top, bottom, left, right);
    document.getElementById("HFExtent").value = ext;
    tc.setMapViewExtent(ext);
    tc.removeDrawing();
    __doPostBack('UpdatePanel1', 'CircleDraw');
}*/
function RouteSearch() {

    /*var toolbar;
    toolbar = tc.toolbar;
    var start;
    start = toolbar.routeFrom.val() + " " + toolbar.routeTo.val();
    showFastestRouteOnMap(start, DestCoord, tileClient);
    */
}
function ToggleCategoryVisibility(fCategoryName) {
    var objStyle = eval("document.getElementById('" + fCategoryName + "')");

    if (objStyle != null) {

        if (tc.isPoiCategory(fCategoryName) == true) {
            tc.switchPoiCategoryOff(fCategoryName);
        }
        else {
            tc.switchPoiCategoryOn(fCategoryName);
        }
    }
}
/*
function ShowThemes() {
    if (tc.getZoomLevel() < 6) {
        RestoreCategoryVisibility()
    } else {
        tc.switchPoiCategoryOff("5995");
        tc.switchPoiCategoryOff("15714");
        tc.switchPoiCategoryOff("15729");
        tc.switchPoiCategoryOff("15762");
        tc.switchPoiCategoryOff("15915");
        tc.switchPoiCategoryOff("15954");
        tc.switchPoiCategoryOff("16041");
        tc.switchPoiCategoryOff("16203");
        tc.switchPoiCategoryOff("20307");
    }
}*/

function RestoreCategoryVisibility() {
    if (document.getElementById("Tema_5995").checked == true) {
        tc.switchPoiCategoryOn("5995");
    }
    else {
        tc.switchPoiCategoryOff("5995");
    }

    if (document.getElementById("Tema_15714").checked == true) {
        tc.switchPoiCategoryOn("15714");
    }
    else {
        tc.switchPoiCategoryOff("15714");
    }

    if (document.getElementById("Tema_15729").checked == true) {
        tc.switchPoiCategoryOn("15729");
    }
    else {
        tc.switchPoiCategoryOff("15729");
    }
    if (document.getElementById("Tema_15762").checked == true) {
        tc.switchPoiCategoryOn("15762");
    }
    else {
        tc.switchPoiCategoryOff("15762");
    }
    if (document.getElementById("Tema_15915").checked == true) {
        tc.switchPoiCategoryOn("15915");
    }
    else {
        tc.switchPoiCategoryOff("15915");
    }
    if (document.getElementById("Tema_15954").checked == true) {
        tc.switchPoiCategoryOn("15954");
    }
    else {
        tc.switchPoiCategoryOff("15954");
    }
    if (document.getElementById("Tema_16041").checked == true) {
        tc.switchPoiCategoryOn("16041");
    }
    else {
        tc.switchPoiCategoryOff("16041");
    }
    if (document.getElementById("Tema_16203").checked == true) {
        tc.switchPoiCategoryOn("16203");
    }
    else {
        tc.switchPoiCategoryOff("16203");
    }
    if (document.getElementById("Tema_20307").checked == true) {
        tc.switchPoiCategoryOn("20307");
    }
    else {
        tc.switchPoiCategoryOff("20307");
    }
}
var StartPoi = null;
var DestCoord = null;
function CreatePoisKort(ID, Src, xPos, yPos, theme) {
    var poiDom = document.createElement('img');
    poiDom.id = ID;
    poiDom.src = Src;

    // Add point to map using the API
    var x = Number(xPos.replace(',', '.'));
    var y = Number(yPos.replace(',', '.'));
    var coord = new KrakMap.Coordinate(x, y);
    DestCoord = coord;
    var poi = new KrakMap.Poi(poiDom, coord, theme, 23, 32); // size of gif is 20 pixels square
    StartPoi = poi;
    tc.addPoi(poi);
}
var isPanning = false;
function MouseUp(e) {
    if (isPanning) {
        ShowZoomLevel();
        isPanning = false;
    }
    return true;
}

document.onmouseup = MouseUp;
function MapMoved() {

    isPanning = true;
}
function CreateTheme(id, src, title, address, zip, city, xPos, yPos, theme) {
    var poiDom = document.createElement('img');
    poiDom.id = id;
    poiDom.src = src;
    poiDom.desc = createCallOutContentTheme(title, address, zip, city);
    poiDom.popupWidth = 250;
    poiDom.popupHeight = 115;

    poiDom.onclick = poiThemeClick;
    poiDom.style.cursor = 'hand';

    // Add point to map using the API
    var x = Number(xPos.replace(',', '.'));
    var y = Number(yPos.replace(',', '.'));
    var coord = new KrakMap.Coordinate(x, y);
    var poi = new KrakMap.Poi(poiDom, coord, theme, 20, 20); // size of gif is 20 pixels square
    tc.addPoi(poi);
}

function CreateThemeArray(ID, Src, title, address, zip, city, xPos, yPos, theme) {

    var pois = new Array();
    for (var i = 0; i < ID.length; i++) {
        var poiDom = document.createElement('img');
        poiDom.id = ID[i];
        poiDom.src = "gfx/krak/temakort/poi_theme_" + Src[i] + ".gif";
        poiDom.desc = createCallOutContentTheme(title[i], address[i], zip[i], city[i]);

        poiDom.popupWidth = 250;
        poiDom.popupHeight = 115;

        poiDom.onclick = poiThemeClick;
        poiDom.style.cursor = 'hand';

        var x = Number(xPos[i].replace(',', '.'));
        var y = Number(yPos[i].replace(',', '.'));
        var coord = new KrakMap.Coordinate(x, y);
        var poi = new KrakMap.Poi(poiDom, coord, theme[i], 20, 20); // size of gif is 20 pixels square
        pois[i] = poi;
    }
    // Add point to map using the API
    tc.addPoi(pois);
}
function removePopup() {
    $('#pUp').remove();
    $('#pUpRids').remove();
}
function createCallOutContentTheme(title, address, zip, city) {

    var html = '<table class="PopUpHeader" width="250" border="0" cellspacing="0" cellpadding="0">';
    html += '<tr>';
    html += '<td width="10" height="30">&nbsp;</td>'
    html += '<td width="204" height="30" class="PopUpHeader">' + title + '</td>';
    html += '<td width="17" height="30"><img src="gfx/krak/popup/BSMV_luk.png" alt="luk" onclick="removePopup()"/></td>';
    html += '<td width="10" height="30">&nbsp;</td>'
    html += '</tr>';
    html += '<tr>';
    html += '<td height="8"></td>';
    html += '<td height="8" colspan="2" valign="top">&nbsp;</td>';
    html += '<td height="8"></td>';
    html += '</tr>';
    html += '<tr>';
    html += '<td width="10" height="160">&nbsp;</td>';
    html += '<td colspan="2" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="10">';
    html += '<tr>';
    html += '<td width="51%" valign="top"><span class="PopUpTxt"><strong>Adresse</strong><br />';
    html += address + '<br />';
    html += zip + ' ' + city + '</td>';
    html += '</tr>';
    html += '</table></td>';
    html += '<td width="10">&nbsp;</td>';
    html += '</tr>';
    html += '</table>';

    return (html);
}
function poiThemeClick(evt) {
    // Handle the non-standard IE event model ...
    var target = (evt && evt.target) ? evt.target : window.event.srcElement;

    // Only show one popup at a time
    removePopup();

    // Width and height must be > 0
    var popupWidth = Math.max(0, this.popupWidth);
    var popupHeight = Math.max(0, this.popupHeight);

    var left = Number(target.style.left.replace('px', '')) + 26;
    var top = Number(target.style.top.replace('px', ''));
    // These are needed because the POI layer doesn't have the
    // same origin as the map layer.
    var deltaX = Number(tc.getMousePosition().x - left);
    var deltaY = Number(tc.getMousePosition().y - top);

    // Create the popup div tag
    var popdiv = document.createElement('div');
    popdiv.id = 'pUp';

    // Auto-resize if height is zero
    if (popupHeight > 0) {
        popdiv.style.height = popupHeight + 'px';
        popdiv.style.width = popupWidth + 'px';
    }
    else {
        popdiv.style.width = popupWidth + 'px';
    }

    popdiv.style.left = (window.event.clientX + document.documentElement.scrollLeft) + 'px';
    popdiv.style.top = (window.event.clientY + document.documentElement.scrollTop) + 'px';

    //popdiv.innerHTML += '<p>' + this.desc + '</p>';
    popdiv.innerHTML += this.desc;
    // Launch the popup, close it by clicking on the close image
    document.body.appendChild(popdiv);
    popdiv.focus();
}

function CreateAllPois(ID, Src, xPos, yPos, cat, links, titles) {

    var pois = new Array();
    for (var i = 0; i < ID.length; i++) {
        var poiDom = document.createElement('img');
        poiDom.id = ID[i];
        poiDom.src = Src[i];

        poiDom.popupWidth = 550;
        poiDom.popupHeight = 280;

        //poiDom.onclick = window.open('\'' + links[i] + '\'');
        poiDom.onclick = poiIconClickOpenAlt;
        poiDom.title = titles[i];
        poiDom.alt = links[i];
        poiDom.style.cursor = 'hand';

        var x = Number(xPos[i].replace(',', '.'));
        var y = Number(yPos[i].replace(',', '.'));
        var coord = new KrakMap.Coordinate(x, y);
        var poi = new KrakMap.Poi(poiDom, coord, cat[i], 23, 32); // size of gif is 20 pixels square
        pois[i] = poi;
    }
    // Add point to map using the API
    tc.addPoi(pois);
}

function CreateAllPois_old(ID, Src, xPos, yPos, cat) {

    var pois = new Array();
    for (var i = 0; i < ID.length; i++) 
    {
        var poiDom = document.createElement('img');
        poiDom.id = ID[i];
        poiDom.src = Src[i];
        
        poiDom.popupWidth = 550;
        poiDom.popupHeight = 280;
        poiDom.onclick = poiIconClick;
        poiDom.style.cursor = 'hand';
        
        var x = Number(xPos[i].replace(',', '.'));
        var y = Number(yPos[i].replace(',', '.'));
        var coord = new KrakMap.Coordinate(x, y);
        var poi = new KrakMap.Poi(poiDom, coord, cat[i], 23, 32); // size of gif is 20 pixels square
        pois[i] = poi;
    }
    // Add point to map using the API
    tc.addPoi(pois);
}
function poiIconClickOpenAlt(evt) {
    if (this.alt.trim() != '')
        window.open(this.alt);
}
function poiIconClick(evt) {
    // Handle the non-standard IE event model ...
    var target = (evt && evt.target) ? evt.target : window.event.srcElement;

    // Only show one popup at a time
    removePopup();

    // Width and height must be > 0
    var popupWidth = Math.max(0, this.popupWidth);
    var popupHeight = Math.max(0, this.popupHeight);

    var left = Number(target.style.left.replace('px', '')) + 26;
    var top = Number(target.style.top.replace('px', ''));
    // These are needed because the POI layer doesn't have the
    // same origin as the map layer.
    var deltaX = Number(tc.getMousePosition().x - left);
    var deltaY = Number(tc.getMousePosition().y - top);

    // Create the popup div tag
    //
    // Note:
    // Use the Demo.css style file to change the colors etc of the popup
    var popdiv = document.createElement('div');
    popdiv.id = 'pUp';
    // Auto-resize if height is zero

    if (popupHeight > 0) {
        popdiv.style.height = popupHeight + 'px';
        popdiv.style.width = popupWidth + 'px';
    }
    else {
        popdiv.style.width = popupWidth + 'px';
    }

    if (tc.getZoomLevel() > 5) {
        popdiv.style.left = ((document.body.offsetWidth + document.documentElement.scrollLeft - popupWidth) / 2) + 'px';
        popdiv.style.top = ((document.body.offsetHeight + document.documentElement.scrollTop - popupHeight) / 2) + 'px';
    } else {
        //Centrer på skærmen
        popdiv.style.left = (((document.body.offsetWidth + document.documentElement.scrollLeft) / 2) - 225) + 'px';
        popdiv.style.top = (((document.body.offsetHeight - popupHeight) / 2) + 90) + 'px';
    }

    // Launch the popup, close it by clicking on the close image
    document.body.appendChild(popdiv);
    $("#" + popdiv.id).load("Popup/MapPopup.aspx", { 'key': this.id });
    popdiv.focus();
}
/*Krak*/
