﻿function loadMap(lat, lng, customTitle, setMarker, zoom) {
    if (!lat || !lng || (lat==0 && lng==0)) {
        lat = 56.2559809;
        lng = 10.7016160;
    }
//    if (!customTitle) customTitle = "København";
    var customLatlng = new google.maps.LatLng(lat, lng);
    var customOptions = {
        zoom: zoom,
        center: customLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        mapTypeControl: false
    }
    var customMap = new google.maps.Map(document.getElementById("map_canvas"), customOptions);

    if (setMarker) {
        var customMarker = new google.maps.Marker({
            position: customLatlng,
            map: customMap,
            visible: true,
            title: customTitle
        });
    }
//    customLatlng = new google.maps.LatLng(57.427712, 9.767757);
//    var customMarker1 = new google.maps.Marker({
//        position: customLatlng,
//        map: customMap,
//        visible: true,
//        title: "Test"
//    });

    return customMap;
}

function createMarkerOnMap(lat, lng, customTitle, customDescription, custommap, image, zInd) {

    if (!customTitle) customTitle = "";
    if (!zInd) zInd = 1;
   // var image = 'Content/Images/warehouse.png';
    var location = new google.maps.LatLng(lat, lng);
    var marker = new google.maps.Marker({
        position: location,
        title: customTitle,
        icon: image,
        zIndex: zInd
    });
    if (customDescription) {
        var infowindow = new google.maps.InfoWindow({
            content: customDescription,
            maxWidth: 150
        });
        google.maps.event.addListener(marker, 'click', function () {
            infowindow.open(custommap, marker);
        });
    }
    showOverlayOnMap(marker, custommap);
}

function showOverlayOnMap(marker, map) {
    if(marker && map) marker.setMap(map);
}

// Removes the overlays from the map, but keeps them in the array
function clearOverlays(markersArray) {
    if (markersArray) {
        for (i in markersArray) {
            markersArray[i].setMap(null);
        }
    }
}

// Shows any overlays currently in the array
function showOverlaysOnMap(markersArray, map) {
    if (markersArray) {
        for (i in markersArray) {
            markersArray[i].setMap(map);
        }
    }
}

// Deletes all markers in the array by removing references to them
function deleteOverlays(markersArray) {
    clearOverlays(markersArray);
    if (markersArray) markersArray.length = 0;
}
