﻿// JScript File

// arrays to hold copies of the markers and html used by the side_bar
var gmarkers = [];
var i = 0;
var linkid = "activite"+i;
var lastlinkid="";
var bounds = new GLatLngBounds();
var map;

var mapProximite;
var boundsProximite = new GLatLngBounds();

var htmls = [];
var to_htmls = [];
var from_htmls = [];

function CreateMarkerAndPoint2(Lat,Lng,name,URL,html,languageView, extranet)
{
	// add the points  
	var bounds = new GLatLngBounds();
	var LinkIDCreate="activite"+i;  
	var LinkIDCreate2=i;
	var point = new GLatLng(Lat,Lng);
	var marker = createMarker(point,name,html,languageView, extranet, URL);
	map.addOverlay(marker);
	bounds.extend(point);
}

function CreateMarkerAndPoint3(Lat, Lng, name, URL, html, languageView, icon)
{
	// add the points  
	var bounds = new GLatLngBounds();
	
	var LinkIDCreate="activite"+i;  
	var LinkIDCreate2=i;
	var point = new GLatLng(Lat,Lng);
	
	var marker = createMarker3(point,name,html,languageView, icon);
	map.addOverlay(marker);
	bounds.extend(point);
}

function CreateMarkerAndPointPlanned(Lat, Lng, name, url, html, languageView, image, Type, ID) {
	
	// add the points  
	var bounds = new GLatLngBounds();
	
	var point = new GLatLng(Lat,Lng);
	var marker = createMarkerPlanned(point, name, url, html, languageView, image, Type, ID);
	map.addOverlay(marker);
	bounds.extend(point);
}

function CreateMarkerAndPointBigMap(Lat, Lng, name, html, languageView) {
	
	// add the points  
	var bounds = new GLatLngBounds();
	
	var point = new GLatLng(Lat,Lng);
	var marker = CreateMarkerBigMap(point, name, html, languageView);
	map.addOverlay(marker);
	bounds.extend(point);
}

function createMarker3(point,name,html,languageView, icon) {
	// use a custom icon with letter A - Z
	//var letter = String.fromCharCode("A".charCodeAt(0) + i);
	var myIcon;
	
	if(icon) {
		var myIcon = new GIcon(G_DEFAULT_ICON, "/images/pict/" + icon);
		myIcon.printImage = "/images/pict/" + icon;
		myIcon.mozPrintImage = "/images/pict/" + icon;
		myIcon.iconSize=new GSize(30,30);
		myIcon.iconAnchor=new GPoint(0,30);
		myIcon.shadow="/images/pushpins/map/ombre.png";
		myIcon.shadowSize=new GSize(30,30);
	} else {
		myIcon = new GIcon(G_DEFAULT_ICON, "/images/pushpins/map/" + "fleche_brune" + ".png");
		myIcon.printImage = "/images/pushpins/map/" + "fleche_brune" + ".png";
		myIcon.mozPrintImage = "/images/pushpins/map/" + "fleche_brune" + ".png";
		myIcon.shadow="/images/pushpins/map/fleche_shadow.png";
		myIcon.iconSize=new GSize(28,28);
		myIcon.iconAnchor=new GPoint(0,28);
		myIcon.shadowSize=new GSize(28,28);
	}
	
	var marker = new GMarker(point, {icon:myIcon,title: name});
	
	return marker;
}

// A function to create the marker and set up the event window
function createMarker(point,name,html,languageView, extranet, url) {
	// use a custom icon with letter A - Z
	//var letter = String.fromCharCode("A".charCodeAt(0) + i);
	var previous = "";
	if(extranet==1) {
		previous = "../";
	}
	if (i<=20){
	    var myIcon = new GIcon(G_DEFAULT_ICON, previous + "/images/pushpins/map/" + (i+1) + ".png");
	    myIcon.printImage = previous + "/images/pushpins/map/" + (i+1) + ".png";
	    myIcon.mozPrintImage = previous + "/images/pushpins/map/" + (i+1) + ".png";
	} else {
	    var myIcon = new GIcon(G_DEFAULT_ICON, previous + "/medias/communs/pushpins/map/default.png");
	    myIcon.printImage = previous + "/images/pushpins/map/default.png";
	    myIcon.mozPrintImage = previous + "/images/pushpins/map/default.png";
	}
	myIcon.iconSize=new GSize(21,21);
    myIcon.iconAnchor=new GPoint(0,21);
    myIcon.shadow="/images/pushpins/map/ombre.png";
    myIcon.shadowSize=new GSize(27,28);
	
	var marker = new GMarker(point, {icon:myIcon,title: name});
	if(url != "") {
		GEvent.addListener(marker, "click", function() {
			document.location.href=url;
		});
	}
	// save the info we need to use later for the side_bar
	gmarkers[i] = marker;
	htmls[i] = html;
	i++;
	return marker;
}

// A function to create the marker and set up the event window
function createMarkerPlanned(point, name, url, html, languageView, image, Type, ID) {
	var myIcon = new GIcon(G_DEFAULT_ICON, "/images/pict/" + image);
	myIcon.printImage = "/images/pict/" + image;
	myIcon.mozPrintImage = "/images/pict/" + image;
	
	myIcon.iconSize=new GSize(30,30);
    myIcon.iconAnchor=new GPoint(0,30);
    myIcon.shadow="/images/pushpins/map/ombre.png";
    myIcon.shadowSize=new GSize(30,30);

	var marker = new GMarker(point, {icon:myIcon,title: name});
	
	html = getnerateHtmlPopup2(point, name, url, html, languageView, Type, ID);  
    
    GEvent.addListener(marker, "click", function() {
      marker.openInfoWindowHtml(html);
    });
    
	// save the info we need to use later for the side_bar
	gmarkers[i] = marker;
	htmls[i] = html;
	i++;
	return marker;
}

// A function to create the marker and set up the event window
function CreateMarkerBigMap(point, name, html, languageView) {
	var myIcon = new GIcon(G_DEFAULT_ICON, "/images/pushpins/map/" + "fleche_brune" + ".png");
	myIcon.printImage = "/images/pushpins/map/" + "fleche_brune" + ".png";
	myIcon.mozPrintImage = "/images/pushpins/map/" + "fleche_brune" + ".png";

	myIcon.iconSize=new GSize(28,28);
    myIcon.iconAnchor=new GPoint(0,28);
    myIcon.shadow="images/pushpins/map/fleche_shadow.png";
    myIcon.shadowSize=new GSize(28,28);

	var marker = new GMarker(point, {icon:myIcon,title: name});
	
	html = getnerateHtmlPopup(point, name, "", html, languageView);   
    
    GEvent.addListener(marker, "click", function() {
      marker.openInfoWindowHtml(html);
    });
    
	// save the info we need to use later for the side_bar
	gmarkers[i] = marker;
	htmls[i] = html;
	i++;
	return marker;
}


function getnerateHtmlPopup(point, name, url, html, languageView) {
	// The info window version with the "Arriv&eacute;e" form open
	html = "<strong>" + name + "</strong>" + "<br />" + html
	if (languageView=='fr') {
		if(url != "") {
			html += "<a href='" + url + "'>Fiche détaillée</a><br />";
		}
		
	    to_htmls[i] = html + '<br>Directions: <b>Vers ce lieu</b> - <a href="javascript:fromhere(' + i + ')">&Agrave; partir de ce lieu</a>' +
           '<br>Lieu de d&eacute;part:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
           '<input type="text" SIZE=40 MAXLENGTH=200 name="saddr" id="saddr" value="" /><br>' +
           '<INPUT value="Pour s\'y rendre" TYPE="SUBMIT">' +
           '<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() + 
                  // "(" + name + ")" + 
           '"/>';
        // The info window version with the "Arriv&eacute;e" form open
        from_htmls[i] = html + '<br>Directions: <a href="javascript:tohere(' + i + ')">Vers ce lieu</a> - <b>&Agrave; partir de ce lieu</b>' +
           '<br>Lieu d\'arriv&eacute;e:<form action="http://maps.google.com/maps" method="get"" target="_blank">' +
           '<input type="text" SIZE=40 MAXLENGTH=200 name="daddr" id="daddr" value="" /><br>' +
           '<INPUT value="Pour s\'y rendre" TYPE="SUBMIT">' +
           '<input type="hidden" name="saddr" value="' + point.lat() + ',' + point.lng() +
                  // "(" + name + ")" + 
           '"/>';
        // The inactive version of the direction info
        html = html + '<br>Directions: <a href="javascript:tohere('+i+')">Vers ce lieu</a> - <a href="javascript:fromhere('+i+')">&Agrave; partir de ce lieu</a>';
	} else {
		if(url != "") {
			html += "<a href='" + url + "'>Details</a><br />"
		}
	    to_htmls[i] = html + '<br>Directions: <b>End</b> - <a href="javascript:fromhere(' + i + ')">Start</a>' +
           '<br>Start address:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
           '<input type="text" SIZE=40 MAXLENGTH=200 name="saddr" id="saddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() + 
                  // "(" + name + ")" + 
           '"/>';
        // The info window version with the "Arriv&eacute;e" form open
        from_htmls[i] = html + '<br>Directions: <a href="javascript:tohere(' + i + ')">End</a> - <b>Start</b>' +
           '<br>End address:<form action="http://maps.google.com/maps" method="get"" target="_blank">' +
           '<input type="text" SIZE=40 MAXLENGTH=200 name="daddr" id="daddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" name="saddr" value="' + point.lat() + ',' + point.lng() +
                  // "(" + name + ")" + 
           '"/>';
        // The inactive version of the direction info
        html = html + '<br>Directions: <a href="javascript:tohere('+i+')">End</a> - <a href="javascript:fromhere('+i+')">Start</a>';
	}
	return html;
}

function getnerateHtmlPopup2(point, name, url, html, languageView, Type, ID) {
	// The info window version with the "Arriv&eacute;e" form open
	html = "<strong>" + name + "</strong>" + "<br />" + html
	if (languageView=='fr') {
		if(url != "") {
			html += "<a target='_blank' href='" + url + "'>Fiche détaillée</a><br />";
		}
		
		if(ID != -1) {
			html += "<a href='javascript:ajouterDestination(" + Type + "," + ID + ");'>Ajouter à mes destinations</a><br />";
		}
	    
	} else {
		if(url != "") {
			url = url.replace("&shy;", "a");
			html += "<a target='_blank' href='" + url + "'>Details</a><br />"
		}	  
		if(ID != -1) {  
			html += "<a href='javascript:ajouterDestination(" + Type + "," + ID + ");'>Add to destinations</a><br />";
		}
	}
	return html;
}



function getElementsByName_iefix(name) {
     var rootList = document.getElementById("escListeAct");
     var elem = rootList.getElementsByTagName("li");
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          //att = elem[i].getAttribute("name");
          att = elem[i].className;
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}

// This function picks up the click and opens the corresponding info window
function myclick(i) {
    gmarkers[i].openInfoWindowHtml(htmls[i]);
    location.href = "#anchorCarte";
}

// functions that open the directions forms
function tohere(i) {
    gmarkers[i].openInfoWindowHtml(to_htmls[i]);
}
function fromhere(i) {
    gmarkers[i].openInfoWindowHtml(from_htmls[i]);
}

function initialize(longitude, lattitude, zoom) {
	if (GBrowserIsCompatible()) {
		var mapDiv = document.getElementById("map_canvas");
		// create the map
		map=new GMap2(mapDiv);
        map.addControl(new GSmallZoomControl());
		map.setCenter(new GLatLng(lattitude,longitude), zoom);
		
		var CopyrightDiv = mapDiv.firstChild.nextSibling;
		CopyrightDiv.style.visibility="hidden";
		
		var CopyrightDiv = CopyrightDiv.nextSibling;
		CopyrightDiv.style.visibility="hidden";
		//CopyrightDiv.className = "hebCarteCopy";
	} else {
		alert("Désolé, Google Maps n'est pas compatible avec ce navigateur \n Sorry, Google Maps is not compatible with this browser");
	}
}


function initializeBigMap(longitude, lattitude, zoom) {
	if (GBrowserIsCompatible()) {
		// create the map
		var mapDiv = document.getElementById("map_canvas");
		map=new GMap2(mapDiv);
		
		map.addControl(new GLargeMapControl());
		map.addControl(new GHierarchicalMapTypeControl());
		map.addMapType(G_PHYSICAL_MAP);
		map.addControl(new  GScaleControl());
		map.setCenter(new GLatLng(lattitude,longitude), zoom);
	} else {
		alert("Désolé, Google Maps n'est pas compatible avec ce navigateur \n Sorry, Google Maps is not compatible with this browser");
	}
}

function refreshPlannedMap() {
	document.PlannedMap.submit();
}


/***********************************************************
Map à proximité
***********************************************************/
function initializeAProximite(longitude, lattitude, zoom) {
	if (GBrowserIsCompatible()) {
		var mapDiv = document.getElementById("map_canvasProximite");
		// create the map
		mapProximite=new GMap2(mapDiv);        
		
		mapProximite.setCenter(new GLatLng(lattitude,longitude), zoom);
		mapProximite.addControl(new GSmallZoomControl());
		
		var CopyrightDiv = mapDiv.firstChild.nextSibling;
		CopyrightDiv.style.visibility="hidden";
		
		var CopyrightDiv = CopyrightDiv.nextSibling;
		CopyrightDiv.style.visibility="hidden";
		//CopyrightDiv.className = "hebCarteCopy";
	} else {
		alert("Désolé, Google Maps n'est pas compatible avec ce navigateur \n Sorry, Google Maps is not compatible with this browser");
	}
}

function CreateMarkerAndPoint3AProximite(Lat, Lng, name, URL, html, languageView, icon)
{
	// add the points  
	var bounds = new GLatLngBounds();
	
	var LinkIDCreate="activite"+i;  
	var LinkIDCreate2=i;
	var point = new GLatLng(Lat,Lng);
	
	var marker = createMarker3(point,name,html,languageView, icon);
	mapProximite.addOverlay(marker);
	boundsProximite.extend(point);
}

function CreateMarkerAndPointPlannedProximite(Lat, Lng, name, url, html, languageView, image, Type, ID) {
	// add the points  
	var bounds = new GLatLngBounds();
	var point = new GLatLng(Lat,Lng);
	ID = -1;
	var marker = createMarkerPlanned(point, name, url, html, languageView, image, Type, ID);
	mapProximite.addOverlay(marker);
	boundsProximite.extend(point);
}