﻿QuebecMap.setupAllMapPointsNow = function() {

    var theString = document.getElementById('ctl00_MainPlaceHolder_hfMapPoints').value;
    var theValues = new Array();
    var parameters = new Array();

    if (theString == null || theString == '') {
        return;
    }

    theString = theString.substr(0, theString.length - 1);
    theValues = theString.split("|");

    for (var i = 0; i < theValues.length; i++) {

        parameters = theValues[i].split("#");

        var latitude = parseFloat(parameters[0]);
        var longitude = parseFloat(parameters[1]);
        var number = parseInt(parameters[2]);
        var type = parameters[3];
        var ClientIDSnippet = parameters[4];
        var CodePostal = parameters[5];

        if (parameters[0] == "" || parameters[1] == "") {
            //return;
            // Il n'y a pas de coordonées, nous allons les récupérer avec le code postal
            var coord = new GLatLng(46.80875, -71.21415);
            var geocoder = new google.maps.ClientGeocoder();

            geocoder.setBaseCountryCode('ca');
            geocoder.getLatLng(CodePostal, function(theCoord) {

                if (theCoord == null) {
                    theCoord = coord;
                }

                QuebecMap.setMapPinNumber(theCoord.lat(), theCoord.lng(), number, type, ClientIDSnippet)

                //QuebecMap.map.setCenter(theCoord, 1);
                //QuebecMap.map.setZoom(11);

            });

        }
        else {
            this.setMapPinNumber(latitude, longitude, number, type, ClientIDSnippet);
            //QuebecMap.map.setCenter(11);
        }

    }
};

QuebecMap.setMapPinNumber = function(Latitude, Longitude, Number, type, ClientIDSnippet) {
    var group;
    var coord = new GLatLng(46.80875, -71.21415);

    if (Latitude != 0) {
        coord = new GLatLng(Latitude, Longitude);
    }

    if (type == 'PointDeDepart') {

        group = "markers";
        if (this.markers[group] == null) {
            this.markers[group] = [];
        }
        //this.markers[group].push(this.createNumberedMarker('search', null, { position: coord, size: [46, 36], shadow: false }, null));
        this.markers[group].push(this.createNumberedMarker('point_fiche_membre', null, { position: coord, size: [46, 36], shadow: false }, null));

        //this.map.setCenter(coord, 1);

    }
    else if (type == 'favoris') {

        group = "mes_favoris";
        if (this.markers[group] == null) {
            this.markers[group] = [];
        }

        this.markers[group].push(this.createNumberedMarker('favoris', null, { position: coord, size: [32, 32], shadow: false }, ClientIDSnippet));
        
    }

}
