﻿// shop types:
//  23 - profile NL
//  24 - profile BE
//  29 - james
//  27 - ABC
//  28 - 123
//  35 - Passion Pneu
//  36 - Banden De Conde
//  42 - Ruitschade

var map = null;
var directions = null;
var currentLocation = null;
MapDistance = null;
function load(lat, lng) {
    try {
        if (GBrowserIsCompatible() && lat != "0" && lng != "0") {

            map = new GMap2(document.getElementById("map"));

            var point = new GLatLng(lat, lng);
            map.setCenter(point, 16);
            map.enableScrollWheelZoom();

            var zoom = new GSmallMapControl();
            map.addControl(zoom);

            var mapControl = new GMapTypeControl();
            map.addControl(mapControl);
        }
    }
    catch (exception) {
        //alert(exception);
    }
}

function loadWithZoom(lat, lng,zoomLevel) {
    try {
        if (GBrowserIsCompatible() && lat != "0" && lng != "0") {

            map = new GMap2(document.getElementById("map"));

            var point = new GLatLng(lat, lng);
            map.setCenter(point, 16);
            map.enableScrollWheelZoom();

            var zoom = new GSmallMapControl();
            map.addControl(zoom);

            var mapControl = new GMapTypeControl();
            map.addControl(mapControl);

            map.setZoom(zoomLevel);

        }
    }
    catch (exception) {
        //alert(exception);
    }
}
function getRoadDistance(fromLat, fromLng, toLat, toLng) {
    var directions2 = new GDirections();
    GEvent.addListener(directions2, "load", function() { distLoad(directions2); });
    if (directions2 != null) {
        var a = "Your location@" + fromLng + "," + fromLat;
        var b = "Destination@" + toLng + "," + toLat;
        var qry = "from: " + a + " to: " + b;
        directions2.load(qry, { getPolyline: true, getSteps: true });
        return 1;
    }
    return -1;
}

function distLoad(dir) {
    MapDistance = dir.getDistance().meters;
}

function loadDirections(control) {
    directions = new GDirections(map, document.getElementById(control));
}

function loadRoute(fromLat, fromLng, toLat, toLng, locale) {
    if (directions != null) {
        var a = "Uw lokatie@" + fromLng + "," + fromLat;
        var b = "Bestemming@" + toLng + "," + toLat;
        var qry = "from: " + a + " to: " + b;
        directions.load(qry, { getPolyline: true, "locale": locale });
    }
}
function handleNoFlash(errorCode) {
    if (errorCode == 603) {
        alert("Error: Flash doesn't appear to be supported by your browser");
        return;
    }
}


function addShop(lat, lng, shopName, shopAddress, shopNumber, postcode, shopCity, phone, shopLink, selected, type) {
    if (lat != 0) {
        var iconOptions = {};
        iconOptions.width = 32;
        iconOptions.height = 32;
        if (selected == true) {
            iconOptions.primaryColor = "#00CCCC";
        }
        else {
            iconOptions.primaryColor = "#000CCC";
        }
        iconOptions.cornerColor = "#FFFFFF";
        iconOptions.strokeColor = "#000000";
        var icon = MapIconMaker.createMarkerIcon(iconOptions);

        var iconPT = new GIcon();
        iconPT.image = _siteRoot + "/JS/Images/PTCBaloon.png";
        iconPT.shadow = _siteRoot + "/JS/Images/PTCBaloonShadow.png";
        iconPT.iconSize = new GSize(25, 41);
        iconPT.shadowSize = new GSize(30, 12);
        iconPT.iconAnchor = new GPoint(12, 40);
        iconPT.infoWindowAnchor = new GPoint(12, 0);

        var iconPTSmall = new GIcon();
        var shop_type = "";
        if (type == 23 || type == 24) {
            shop_type = "Profile Tyrecenter";
            iconPTSmall.image = _siteRoot + "/JS/Images/ProfileBaloonSmall.png";
        }
        else if (type == 27) {
            shop_type = "abc Autoservice";
            iconPTSmall.image = _siteRoot + "/JS/Images/ABCBaloonSmall.png";
        }
        else if (type == 28) {
            shop_type = "JAMES Lease Service ";
            iconPTSmall.image = _siteRoot + "/JS/Images/JamesBaloonSmall.png";
        }
        else if (type == 29) {
            shop_type = "JAMES Auto <span style='font-family:Times New Roman'>&amp;</span> Service";
            iconPTSmall.image = _siteRoot + "/JS/Images/JamesBaloonSmall.png";
        }
        else if (type == 35) {
            iconPTSmall.image = _siteRoot + "/JS/Images/PassionBaloonSmall.png";
        }
        else if (type == 36) {
            iconPTSmall.image = _siteRoot + "/JS/Images/DecondeBaloonSmall.png";
        }
//        else if (type == 40) {
//            shop_type = "Autoschade Herstel";
//            iconPTSmall.image = _siteRoot + "/JS/Images/AutoglazBaloonSmall.png";
//        }
        else if (type == 42) {
           
            shop_type = "Autoglaz ";
             iconPTSmall.image = _siteRoot + "/JS/Images/autoglaazBaloon.png";
            }

        iconPTSmall.shadow = _siteRoot + "/JS/Images/PTCBaloonShadow.png";
        iconPTSmall.iconSize = new GSize(35, 41);
        iconPTSmall.shadowSize = new GSize(30, 12);
        iconPTSmall.iconAnchor = new GPoint(18, 41);
        iconPTSmall.infoWindowAnchor = new GPoint(2, 0);

        var point = new GLatLng(lat, lng);
        var marker;
        if (selected == true)
            marker = new GMarker(point, iconPT);
        else
            marker = new GMarker(point, iconPTSmall);

        var shopInfo = '<div><div style="font-size:14px;">' + shop_type + '  <b>' + shopName + '</b></div>';
        shopInfo += '<div style="font-size:11px">' + shopAddress +' ' + shopNumber + '</div>';
        shopInfo += '<div style="font-size:11px"><b>' + postcode + ' ' + shopCity + '</b></div>';
        shopInfo += '<div style="font-size:11px">' + phone + '</div></div>';
        //if (selected == false) {
        //    shopInfo += '<div style="font-size:11px"><a href="' + shopLink + '">Go to shop</a></div></div>';
        //}
        if (map != null) {
            map.addOverlay(marker);
        }
        //marker.openInfoWindowHtml(shopInfo);

        GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(shopInfo); });
    }
}

function addPosition(lat, lng, text, postcode) {
    if (lat != 0) {
        var point = new GLatLng(lat, lng);
        var marker = new GMarker(point);
        var shopInfo = '<div><div style="font-size:14px;"><b>' + text + '</b></div>';
        shopInfo += '<div style="font-size:11px"><b>' + postcode + '</b></div></div>';
        if (map != null) {
            map.addOverlay(marker);
        }
        //marker.openInfoWindowHtml(shopInfo);
        currentLocation = new GLatLng(lat, lng);
        GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(shopInfo); });
    }
}

