﻿/*
Function for setting up a physical map with all Lapperre offices
*/
var address;

function initOfficesMap() {

    var geocoder;   

    if (GBrowserIsCompatible())
    {
        gmap = new GMap2(document.getElementById("gmap"));
        gmap.setUIToDefault();
        // Set default map type and fill list of available maptypes
        gmap.removeMapType(G_SATELLITE_MAP);
        gmap.removeMapType(G_HYBRID_MAP);
        gmap.setMapType(G_PHYSICAL_MAP);

        gmap.setCenter(new GLatLng(50.643454, 4.363632), 8);        
        gmap.enableScrollWheelZoom();
        addPoints();
        showLocation();            
    }
};

/*
Function for setting up a normal roadmap showing the head office of Lapperre
*/
function initRoadmap() {
    if (GBrowserIsCompatible()) {
        gmap = new GMap2(document.getElementById("gmap"));
        gmap.setUIToDefault();
        // Set default map type and fill list of available maptypes
        gmap.removeMapType(G_SATELLITE_MAP);
        gmap.removeMapType(G_HYBRID_MAP);
        gmap.setMapType(G_NORMAL_MAP);

        gmap.setCenter(new GLatLng(50.870000, 4.275000), 14);
        gmap.enableScrollWheelZoom();
        addPoints();           
    }
};



function addAddressToMap(response) {
      
    if (!response || response.Status.code != 200) {
        gmap.setCenter(new GLatLng(50.643454, 4.363632), 8);
        alert('address not found'); 
    } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
        if (gmap == null) { gmap = new GMap2(document.getElementById("gmap")); }
        gmap.setCenter(point, 11);
        //alert(place.address);
    }
}

function showLocation() {

    if (address != null)  {        
        geocoder = new GClientGeocoder();
        geocoder.getLocations(address, addAddressToMap);
    }
}
