﻿// arrays to hold copies of the markers and html used by the side_bar
// because the function closure trick doesnt work there
var gmarkers = [];
var i = 0;
var bounds = new GLatLngBounds();
var map;
var iLat = 45.996962;
var iLng = -72.421875;
var iNomEtablissement = '';

function CreateMarkerAndPoint(icon) {
    // add the points
    var point = new GLatLng(iLat, iLng);
    var marker = createMarker(point, iNomEtablissement, icon);
    map.addOverlay(marker);
    bounds.extend(point);
    return marker;
}

// A function to create the marker and set up the event window
function createMarker(point, title, icon) {
    
    // use a custom icon with letter A - Z
    //var letter = String.fromCharCode("A".charCodeAt(0) + i);
    var sIcon = "/medias/communs/pushpins/" + icon + ".png"
    var myIcon = new GIcon(G_DEFAULT_ICON, sIcon);
    myIcon.iconSize = new GSize(28, 26);
    myIcon.iconAnchor = new GPoint(0, 26);
    myIcon.shadow = "/medias/communs/pushpins/ombre.png";
    myIcon.shadowSize = new GSize(41, 26);
    myIcon.printImage = sIcon;
    myIcon.mozPrintImage = sIcon;
    var marker = new GMarker(point, { icon: myIcon, title: title });
    // save the info we need to use later for the side_bar
    gmarkers[i] = marker;
    i++;
    return marker;
}

// This function picks up the click and opens the corresponding info window
function myclick(i) { GEvent.trigger(gmarkers[i], "click"); }

function initialize() {
    if (GBrowserIsCompatible()) {
        var mapDiv = document.getElementById("map_canvas");
        map = new GMap2(mapDiv);
        map.addControl(new GSmallZoomControl3D());
        map.addMapType(G_PHYSICAL_MAP);
        var center = new GLatLng(iLat, iLng);
        map.setCenter(center, 9);
        var LogoDiv = mapDiv.firstChild.nextSibling
        var CopyrightDiv = LogoDiv.nextSibling;
        LogoDiv.className = "mapLogo"
        CopyrightDiv.className = "mapCopy";
    }
}

function initializeLatLngValues(lat, lng, NomEtablissement) {
    iLat = lat;
    iLng = lng;
    iNomEtablissement = NomEtablissement;
}


/**** carte interactive *****/

// arrays to hold copies of the markers and html used by the side_bar
// because the function closure trick doesnt work there
var i = 0;
var bounds = new GLatLngBounds();
var map;
function openMapPreserve() {
    var MapCenter = map.getCenter();
    var MapZoom = map.getZoom();
    var MapType = map.getCurrentMapType().getName();
    var SelectSpec = '';
    for (i = 0; i <= checkboxList.length - 1; i++) {
        if (document.getElementById(checkboxList[i]).checked) {
            if (SelectSpec != '') SelectSpec += ","
            SelectSpec += checkboxListValue[i];
        }

    }
    var url = '/vacances-quebec/Popup-cartes.aspx?UILanguageID=<%= UICultureISO %>&SelectSpec=' + SelectSpec + '&zoom=' + MapZoom + "&MapType=" + MapType + "&lat=" + MapCenter.lat() + "&lng=" + MapCenter.lng();
    openMap(url);
}


function openMapPreserveMembre(Lan,SpecSheet,Icon) {
    var MapCenter = map.getCenter();
    var MapZoom = map.getZoom();
    var MapType = map.getCurrentMapType().getName();
    var SelectSpec = SpecSheet;

    var url = '/vacances-forfaits/Popup-cartes-Membre.aspx?UILanguageID=' + Lan + '&SelectSpec=' + SelectSpec + '&Icon=' + Icon + '&zoom=' + MapZoom + "&MapType=" + MapType + "&lat=" + MapCenter.lat() + "&lng=" + MapCenter.lng();
    openMap(url);
}

function openMapPreserveMembre(Lan, SpecSheet, Icon, SpecSheetItemCategorie, FK_ContentCategorie, SpecsheetItemSearchCriteria, SpecsheetItemValueSearchCriteria, city, OrderBy) {
    var MapCenter = map.getCenter();
    var MapZoom = map.getZoom();
    var MapType = map.getCurrentMapType().getName();
    var SelectSpec = SpecSheet;

    var url = '/vacances-forfaits/Popup-cartes-Membre.aspx?UILanguageID=' + Lan + '&SelectSpec=' + SelectSpec + '&Icon=' + Icon + '&zoom=' + MapZoom + "&MapType=" + MapType + "&lat=" + MapCenter.lat() + "&lng=" + MapCenter.lng() + "&SpecItemCat=" + SpecSheetItemCategorie + "&FKContentCat=" + FK_ContentCategorie + "&SpecItemSearch=" + SpecsheetItemSearchCriteria + "&SpecItemValueSearch=" + SpecsheetItemValueSearchCriteria + "&city=" + city + "&OrderBy=" + OrderBy;
    openMap(url);
}

function openMapPreserveCircuit(Title,Lan) {
    var MapCenter = map.getCenter();
    var MapZoom = map.getZoom();
    var MapType = map.getCurrentMapType().getName();
    
    var url = '/vacances-forfaits/Popup-cartes-Circuit.aspx?Title=' + Title + '&UILanguageID=' + Lan + '&zoom=' + MapZoom + "&MapType=" + MapType + "&lat=" + MapCenter.lat() + "&lng=" + MapCenter.lng();
    openMap(url);
}


function openMap(url) { window.open(url, "", "width=1000,height=600"); }


function initializeCarteProximite(zoom) {
	if (GBrowserIsCompatible()){
		var mapDiv = document.getElementById("map_canvas");
		map = new GMap2(mapDiv);
		map.addControl(new GLargeMapControl3D());
		map.addControl(new GHierarchicalMapTypeControl());
		map.addMapType(G_PHYSICAL_MAP);
		map.addControl(new GScaleControl());
		var center = new GLatLng(iLat, iLng);
		map.setCenter(center, zoom);
		var LogoDiv = mapDiv.firstChild.nextSibling
		var CopyrightDiv = LogoDiv.nextSibling;
		LogoDiv.className = "mapLogo"
		CopyrightDiv.className = "mapCopy";
	}
}


function initializeMap(zoom) {
    if (GBrowserIsCompatible()) {
        var mapDiv = document.getElementById("mapcanvas");
        map = new GMap2(mapDiv);
        map.addControl(new GLargeMapControl3D());
        map.addControl(new GHierarchicalMapTypeControl());
        map.addMapType(G_PHYSICAL_MAP);
        map.addControl(new GScaleControl());
        var center = new GLatLng(iLat, iLng);
        map.setCenter(center, zoom);
        var LogoDiv = mapDiv.firstChild.nextSibling
        var CopyrightDiv = LogoDiv.nextSibling;
        LogoDiv.className = "mapLogo"
        CopyrightDiv.className = "mapCopy";
    }
}



function SpecSheetOnClick(checkControl, ListPoint) {
    if (checkControl.checked) {
        for (i = 0; i <= ListPoint.length - 1; i++) {
            ListPoint[i].show();
        }
    }
    else {
        for (i = 0; i <= ListPoint.length - 1; i++) {
            ListPoint[i].closeInfoWindow();
            ListPoint[i].hide();
        }
    }
}

function SpecSheetOnClickDynamic(checkControl, geoXml) {    

    if (checkControl.checked) {
        map.addOverlay(geoXml);
    }
    else {
        map.removeOverlay(geoXml);
    }
}

function ShowMembres(ListPoint) {
      for (i = 0; i <= ListPoint.length - 1; i++) {
            ListPoint[i].show();
        }   
}



// This function picks up the click and opens the corresponding info window
function myclick(i) { GEvent.trigger(gmarkers[i], "click"); }
