﻿var GM_object;
var map;
function GM_commands() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        
        // -- GoogleMaps Control --
        map.addControl(new GSmallMapControl());
        //sb.AppendLine("map.addControl(new GMapTypeControl());");
        // ------------------------

        function GM_Class() {
            // -- Configuration des Markers --
            this.icon_ag = new GIcon();
            this.icon_ag.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png';
            this.icon_ag.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
            this.icon_ag.iconSize = new GSize(12, 20);
            this.icon_ag.shadowSize = new GSize(22, 20);
            this.icon_ag.iconAnchor = new GPoint(6, 20);
            this.icon_ag.infoWindowAnchor = new GPoint(5, 1);
            this.icon = new GIcon();
            this.icon.image = 'http://www.mondialrelay.com/img/gmaps_pr02.png';
            this.icon.shadow = 'http://www.mondialrelay.com/img/gmaps_pr01.png';
            this.icon.iconSize = new GSize(24, 30);
            this.icon.shadowSize = new GSize(1, 1);
            this.icon.iconAnchor = new GPoint(12, 30);
            this.icon.infoWindowAnchor = new GPoint(10, 1);
            // -------------------------------

            // -- Fonction PopUp --
            function MM_openBrWindow(theURL,winName,features) { newwin=window.open(theURL,winName,features); newwin.focus(); }
            // --------------------

            // -- Fonctions de création des Markers --
            function Marker_Create(point, libelle, icon) {
                var marker = new GMarker(point, icon);
                if (libelle == "") {} else {
                    GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(libelle); } );
                }
                return marker;
            };
            function MarkerAdv_Create(point, idrelais, icon) {
                var marker = new GMarker(point, icon);
                if (idrelais == "0") {} else {
                    GEvent.addListener(marker, "click", function() { MM_openBrWindow('popup_pointrelais.aspx?id='+idrelais+'&select=1', 'gm_mr_relais', 'scrollbars=no,width=790,height=530,top=10,left=10'); } );
                }
                return marker;
            };
            // ---------------------------------------

            // -- Google Maps GeoCoders --
            this.GeoPoint_MarkAdv = function(point, idrelais, icon) {
                map.setCenter(point, 12);
                map.addOverlay(MarkerAdv_Create(point, idrelais, icon));
            };
            this.GeoPoint_MarkAdv2 = function(point, idrelais, icon, zoom) {
                map.setCenter(point, zoom);
                map.addOverlay(MarkerAdv_Create(point, idrelais, icon));
            };
            this.Address_Center = function(address) {
                var geocoder = new GClientGeocoder();
                if (geocoder) { geocoder.getLatLng(address, function (point) { if (point) { map.setCenter(point, 12); } }); }
            };
            this.Address_Pick = function(address, icon) {
                var geocoder = new GClientGeocoder();
                if (geocoder) { geocoder.getLatLng(address, function (point) { if (point) { map.setCenter(point, 12); map.addOverlay(Marker_Create(point, "You are here.", icon)); } else { alert("'" + address + "' has not been found."); } } ); }
            };
            this.Address_MarkAdv = function(address, idrelais, icon) {
                var geocoder = new GClientGeocoder();
                if (geocoder) { geocoder.getLatLng(address, function (point) { if (point) { map.setCenter(point, 12); map.addOverlay(MarkerAdv_Create(point, idrelais, icon)); } } ); }
            };
            // ---------------------------
        }
        GM_object = new GM_Class();
    }
}
