



	var PARAM_ID_MAGASIN = "idMagasin";
	var SEARCH_SHOP_CODE = "searchShopCode";
	var SEARCH_REGION_CODE = "rc";
	var SEARCH_CP = "searchCP";
	var SEARCH_BY_CP_FORM_CENTER = "searchByCpForm_center";
	var SEARCH_BY_CP_FORM = "searchByCpForm";

	var NB_STORES = 8;
	var NB_STORES_BULLE_GENERALE = 3;
	var NB_STORES_LISTE = 6;
	var DEFAULT_CATEGORIE = "Magasin"; // arbitrairement on aliment la categorie 

	function loadListeMagasins3Col(id_list_element, codePostal){
		var codeDpt = "";
		var codeRegion = "";
		if (codePostal != ""){
			codeDpt = codePostal.substring(0,2);
			if (codeDpt == "97") {
				codeDpt = codePostal.substring(0,3);
			}
			codeRegion = departements[codeDpt].codeRegion;
		}

		var liste_magasins = "<ul>";

		// affichage de la liste des magasins au-dessous de la carte
		var nbStores = 0;

		if (codeRegion != "") {
			for (var j in regions[codeRegion].departements) {
				var newCodePostal = (regions[codeRegion].departements)[j];

//				for (var i in storesMap) {
for(var j = 0; j < storesIdsByCP.length; j++) {
i = storesIdsByCP[j];
					var cp = storesMap[i].codePostal;
					var ville = storesMap[i].ville;
					if (cp.substring(0, newCodePostal.length) == newCodePostal) {
						liste_magasins += "<li id='store_" + nbStores + "'><a href=\"" + storesMap[i].url  + "\">" + cp + " - " + ville + "</a></li>";
						nbStores ++;
					}
				}
			}
		} else {
				
//			for (var i in storesMap) {
for(var j = 0; j < storesIdsByCP.length; j++) {
i = storesIdsByCP[j];
				var cp = storesMap[i].codePostal;
				var ville = storesMap[i].ville;

				liste_magasins += "<li id='store_" + nbStores + "'><a href=\"" + storesMap[i].url + "\">" + cp + " - " + ville + "</a></li>";
				nbStores ++;
			}
		}

		var cut1 = Math.ceil(nbStores/3);
		var cut2 = 2*cut1;
		tailIndex = liste_magasins.indexOf("<li id='store_" + cut2+ "'>",0);
		var liste_magasins2 = "";
		var liste3Col = "";
		if(tailIndex > -1) {
			headStr =  liste_magasins.substring(0,tailIndex);
			insertStr = "</ul><ul class='last'>";
			tailStr = liste_magasins.substring(tailIndex);
			liste_magasins2 = headStr + insertStr + tailStr;
			
		} else {
			liste_magasins2 = liste_magasins;
		}

		tailIndex2 = liste_magasins2.indexOf("<li id='store_" + cut1 + "'>",0);
		if(tailIndex2 > -1) {
			headStr2 =  liste_magasins2.substring(0,tailIndex2);
			if(tailIndex > -1) {
				insertStr2 = "</ul><ul>";
			} else {
				insertStr2 = "</ul><ul class='last'>";
			}
			tailStr2 = liste_magasins2.substring(tailIndex2);
			liste3Col  = headStr2 + insertStr2 + tailStr2;
		} else {
			liste3Col  = liste_magasins2;
		}

		if (nbStores > 0) {
			document.getElementById(id_list_element).innerHTML = liste3Col + "</ul>" ;
		} else {
			document.getElementById(id_list_element).innerHTML = "Aucun magasin" ;
		}
	}

	// Focus "bulle" magasin + zoom sur la carte
	function openBubble(index, bubblesArray, markersArray, aMap){
		aMap.setCenter(new google.maps.LatLng(storesMap[index].lat, storesMap[index].lng));
		bubblesArray[index].open(aMap,markersArray[index]);
		aMap.setZoom(14);
	}

	/*
	 * Fonction d'affichage des marqueurs 
	 * http://www.weboblog.fr/zoom-automatique-fitbounds-v3
	 */
	function afficherMagasinsProches(map, results, latCodePostal, lngCodePostal){

		var nearestStores = getNearestStores(NB_STORES, latCodePostal, lngCodePostal);
		var messageD = "";
		var latlng = new google.maps.LatLng(latCodePostal, lngCodePostal);

		// repositionnement de la carte
		// Declaration de l'objet qui definira les limites de la map */ 
		var bounds = new google.maps.LatLngBounds();
		for (var i = 0; i < nearestStores.length; i++) {
			var latLngI = new google.maps.LatLng(storesMap[nearestStores[i]].lat,
					storesMap[nearestStores[i]].lng);
			bounds.extend(latLngI);
		}
		/* Ici, on ajuste le zoom de la map en fonction des limites  */ 
		map.fitBounds(bounds);

		// mettre la bulle centrale
		var contentInfoWindow = "<div><div style=\"text-align:left;\">" 
				+ "Magasins Lapeyre les plus proches de chez vous</div>"
				+ "<div><ul style=\"text-align:left;list-style-type:disc;list-style-position: inside ;\">";
		for (var i = 0; i < NB_STORES_BULLE_GENERALE; i++) {
			var idElement = "dist" + i;
			contentInfoWindow += "<li><a href=\"" 
					+ "http://www.lapeyrepro.com/nos-magasins/fichemagasin.html?" 
					+ PARAM_ID_MAGASIN + "=" + nearestStores[i] + "\">" 
					+ storesMap[nearestStores[i]].libelleComplet + "<\a>" 
					+ "<span id=\"" + idElement + "\"> (calcul distance)</span></li>"

			// remplir la bulle centrale avec les NB_STORES distances.
			var request = {
				origin: results[0].geometry.location,
				destination: new google.maps.LatLng(storesMap[nearestStores[i]].lat, 
						storesMap[nearestStores[i]].lng),
				travelMode: google.maps.DirectionsTravelMode.DRIVING
			}; 
		}
		contentInfoWindow += "</ul></div></div>";

		var infoWindow = new google.maps.InfoWindow({ 
			position: map.getCenter(), 
			content: contentInfoWindow
		});
		infoWindow.open(map);

		for (var i = 0; i < NB_STORES_BULLE_GENERALE; i++) {
			var idElement = "dist" + i;
			directionsService.route(request, function(response, status) {
				if (status == google.maps.DirectionsStatus.OK) {
					//calcul de distance	
					var total = 0;
					var myRoute = response.routes[0];
					for (j = 0; j < myRoute.legs.length; j++) {
						total += myRoute.legs[j].distance.value;
					}
					var dist = " (" + Math.floor(total / 1000) + " km)";
					document.getElementById(idElement).innerHTML = dist;
				}
			});
		}

		return true;
	}

	function getCategorie(idMagasin) {

		var categorie = storesMap[idMagasin].categorie;
		if (categorie == "") {
			categorie = DEFAULT_CATEGORIE;
		}
		return categorie;
	}

	var jours = Array("", "lun", "mar", "mer", "jeu", "ven", "sam", "dim");
	/*
	 * Mise en forme des horaires d'ouverture
	 * Ex :
	 *     "2:10:00:19:00,3:10:00:19:00,4:10:00:19:00,5:10:00:19:00,6:10:00:19:00,7:10:00:19:00"
	 * ->
	 *     "<dl><dt>mar</dt><dd>10:00-19:00</dd><dt>mer</dt><dd>10:00-19:00</dd><dt>jeu</dt>
	 *	<dd>10:00-19:00</dd><dt>ven</dt><dd>10:00-19:00</dd><dt>sam</dt><dd>10:00-19:00</dd>
	 *	<dt>dim</dt><dd>10:00-19:00</dd></dl>"
	 */
	function formaterHoraires(hrs){
		if (hrs==""){
			return "";
		}
		var html = "<dl>";
		var dd = hrs.split(',');
		for(var d=0;d<dd.length;d++){
			var fields = dd[d].split(':');
			var day = fields[0];
			var start = fields[1] + ":" + fields[2];
			var end = fields[3] + ":" + fields[4];
			html += "<dt>" + jours[day] + "</dt><dd>" + start + '-' + end + "</dd>";
		}
		html += "</dl>";
		return html;
	}


	/*************************************************************
	 * LES FONCTIONS POUR LE CALCUL ET L'AFFICHAGE DE DISTANCE
	 *************************************************************/

	/*
	 * Liste des ids des magasins les plus proches.
	 *
	 */
	function getNearestStores(numStores, latMagasin, lngMagasin) {

		var distancesCarres = new Array();
		var nearestStores = new Array();

		// calcul de carre de distance entre le point d'interet et tous les magasins
		for (var i in storesMap) {
			distancesCarres[i] = [Math.pow(latMagasin - storesMap[i].lat,2) 
				+ Math.pow(lngMagasin - storesMap[i].lng,2),i];
		}

		// trie ascendant des distances 
		distancesCarres.sort(function(a,b){return a[0] - b[0]});

		// recuperation des n magasins les plus proches
		// ne pas prendre en compte le magasin mÃªme
		// prendre en compte uniquement les magasins sur le mÃªme continent
		var j = 0;
		var i = 0;
		while ((i < distancesCarres.length) && (j < numStores)) {
			if ((distancesCarres[i][0] > 0) && (distancesCarres[i][0] < 400)) {
				nearestStores[j] = distancesCarres[i][1];
				j++;
			}
			i++;
		}
		return nearestStores;
	}

	/*
	 * Liste des 3 magasins les plus proches
	 * sous la forme 
	 * <ul>
	 *   <li> <a href="ficheMagasin.html">[CP] [categorie] [societe]</a> </li>
	 * </ul>
	 */
	function showNearestStores(indexStore) {
		var formatedStoresList = "";
		var nearestStores = getNearestStores(3, storesMap[indexStore].lat, storesMap[indexStore].lng);

		if (nearestStores != null && nearestStores.length > 0) {
			formatedStoresList  = "<ul>";
			for (var i = 0; i < nearestStores.length; i++) {
				formatedStoresList  += "<li><a href=\"http://www.lapeyrepro.com/nos-magasins/fichemagasin.html?" 
					+ PARAM_ID_MAGASIN + "=" + nearestStores[i] + "\">" + " " 
					+ storesMap[nearestStores[i]].codePostal + " " 
					+ storesMap[nearestStores[i]].libelleComplet + "<\a></li>";
			}
			formatedStoresList  += "</ul>";
		}

		if (formatedStoresList == "") {
			formatedStoresList = "<ul><li>Aucun magasin trouv&eacute;</li></ul>";
		}

		return formatedStoresList;
	}


	/*************************************************************
	 * LES FONCTIONS D'AFFICHAGE GOOGLE MAPS 
	 *************************************************************/

	/*
	 * Ajouter la bulle
	 */
	function attacherBulle(marker, bubble, map){
		google.maps.event.addListener(marker, 'click', function() { bubble.open(map,marker); });
	}

	/*
	 * Ajouter l'url cliquable
	 */
	function attacherUrl(marker,urlMagasin){
		google.maps.event.addListener(marker, 'click', function() { location.href=urlMagasin });
	}


	/*************************************************************
	 * LES FONCTIONS D'AFFICHAGE DE REGION 
	 *************************************************************/

	function getRegionId(codePostal){
		if (!validerCodePostal(codePostal)) {
			return null;
		}
		if (codePostal.substring(0,2) == "97") {
			return departements[codePostal.substring(0,3)].codeRegion;
		} else {
			return departements[codePostal.substring(0,2)].codeRegion;
		}
	}

	function getRegionMagasinIds(codeRegion) {
		var magasinIds =  new Array(); 
		var departementsIds = regions[codeRegion].departements;
		for (var i in storesMap) {
			for (var j = 0 ; j < departementsIds.length; j++) {
				if(codePostal.substring(0, 2) == "97") {
					if(storesMap[i].codePostal.substring(0,3) == departementsIds[j]) {
						magasinIds.push(i);
					}
				} else if(storesMap[i].codePostal.substring(0,2) == departementsIds[j]) {
					magasinIds.push(i);
				}
			}
		}  
		return magasinIds;
	}
 
	/*************************************************************
	 * INITIALISATION DES DONNEES 
	 *************************************************************/
	function initDataStore(idMagasin){
		document.getElementById("categorie").innerHTML = getCategorie(idMagasin);
		document.getElementById("societe").innerHTML = storesMap[idMagasin].nom;
		document.getElementById("chapeau").innerHTML = "Lorem ipsum dolor sit amet, consectetuer adipisci";
		document.getElementById("adresse").innerHTML = storesMap[idMagasin].addresse1 
			+ "<br>" + storesMap[idMagasin].addresse2 ;
		document.getElementById("cp").innerHTML = storesMap[idMagasin].codePostal;
		document.getElementById("ville").innerHTML = storesMap[idMagasin].ville;

		// Tel
		document.getElementById("tel").innerHTML = "";
		if (storesMap[idMagasin].telPrincipal != "") {
			document.getElementById("tel").innerHTML = "<br>Tel : " + storesMap[idMagasin].telPrincipal;
		}

		// Fax
		document.getElementById("fax").innerHTML = "";
		if (storesMap[idMagasin].telecopieur) {
			document.getElementById("fax").innerHTML = "<br>Fax : " + storesMap[idMagasin].telecopieur;
		}

		// Email
		document.getElementById("email").innerHTML = "";
		if (storesMap[idMagasin].email){
			document.getElementById("email").innerHTML = "<br>Email : " + storesMap[idMagasin].email;
		}

		// Bus
		document.getElementById("bus").innerHTML = "";
		if (storesMap[idMagasin].bus) {
			document.getElementById("bus").innerHTML = "<br>Bus : " + storesMap[idMagasin].bus;
		}

		// Metro
		document.getElementById("metro").innerHTML = "";
		if (storesMap[idMagasin].metro) {
			document.getElementById("metro").innerHTML = "<br>Metro : " + storesMap[idMagasin].metro;
		}

		// Auto
		document.getElementById("auto").innerHTML = "";
		if (storesMap[idMagasin].auto){
			document.getElementById("auto").innerHTML = "<br>En voiture : " + storesMap[idMagasin].auto;
		}

		document.getElementById("horaires").innerHTML =  formaterHoraires(storesMap[idMagasin].heures);
		if (storesMap[idMagasin].joursFeries != "") {
			document.getElementById("jours_feries").innerHTML = "Ouverture exceptionnelle<br>" + storesMap[idMagasin].joursFeries;
		} else {
			document.getElementById("jours_feries").innerHTML = ""; 
		}
		document.getElementById("actus").innerHTML = "Actus";
	}

	/*************************************************************
	 * FONCTION DE VALIDATION
	 *************************************************************/

	function validateSearchByCP(){
		if(!validerCodePostal(document.getElementById(SEARCH_SHOP_CODE).value)) {
                        if(document.getElementById("debug_error") != null)
			    document.getElementById("debug_error").innerHTML = "Veuillez saisir un code postal."; 
			return false; 
		}
		return true; 
	}

	/*
	 * Fonction de validation de formulaire de recherche par CP
	 * Nombre de 5 chiffres ou 2 chiffres
	 *
	 * codePostal String  code postal saisi dans le formulaire de recherche
	 */
	function validerCodePostal(codePostal){
		var pattern=/^(((0[1-9])|([1-8][0-9])|(9[0-8]))([0-9]{3})?)$/;
		return (pattern.exec(codePostal)!=null)
	}

	function estCodePostalDomTom(codePostal){
                // 971xx Guadeloupe
                // 972xx Martinique
                // 973xx Guyane
                // 974xx La RÃ©union
		var pattern=/^97[1234]([0-9][0-9])?$/;
		return (pattern.exec(codePostal)!=null)
	}

	function estCodePostalDomTomAvecMagasin(codePostal){
                // 971xx Guadeloupe
                // 972xx Martinique
                // 974xx La RÃ©union
		var pattern=/^97[124]([0-9][0-9])?$/;
		return (pattern.exec(codePostal)!=null)
	}

	function onblurInputCP(idElement){
		if(document.getElementById(idElement).value == '') {
			document.getElementById(idElement).value = document.getElementById(idElement).title;
		}
	}

	function onfocusInputCP(idElement) {
		if(document.getElementById(idElement).value == document.getElementById(idElement).title) {
			document.getElementById(idElement).value = '';
		}
	}

	function validateAndSubmitSearchByCP(idInputElement, idFormElement) {
		if( validerCodePostal( document.getElementById(idInputElement).value)) {
			document.getElementById(idFormElement).submit();
		}
	}

	function onsubmitValidate(idElement) {
		if(validerCodePostal(document.getElementById(idElement).value)) {
			return true; 
		} else {
			if(document.getElementById(idElement).value == "") {
				alert("Veuillez saisir un code postal."); 
				return false; 
			} else {
				alert("Veuillez saisir un code postal valide."); 
				return false; 
			}
		}
	}

	/*************************************************************
	 * IMPRESSION DES CARTES 
	 *************************************************************/

	function openPrintPopup(idMagasin) {
		my_window= window.open ("http://www.lapeyrepro.com/nos-magasins/popups/impressionfichemagasin.html?idMagasin=" + idMagasin ,   
			"my_window","menubar=1,resizable=1,width=460,height=600,screenX=100,screenY=100,scrollbars=yes");
	}


	/*************************************************************
	 * CALCUL D'ITINERAIRE
	 *************************************************************/

	function openItinerairePopup(idMagasin) {
		my_window= window.open ("http://www.lapeyrepro.com/nos-magasins/popups/itineraire.html?idMagasin=" + idMagasin ,   
			"my_window","menubar=1,resizable=1,width=500,height=600,screenX=100,screenY=100,scrollbars=yes"); 
	}

	/*************************************************************
	 * CHARGEMENTS DES CARTES
	 *************************************************************/

	function loadListesMagasins(selectShopList){
		var elSel = document.getElementById(selectShopList);
		if (elSel != null) {

			// Initialisation de la liste des magasins
//			for (var i in storesMap) {
for(var j = 0; j < storesIdsByCP.length; j++) {
i = storesIdsByCP[j];

				var elSel = document.getElementById(selectShopList);
				var elOptNew = document.createElement('option');

				elOptNew.text = "[ " + 
					storesMap[i].codePostal + " " + 
					storesMap[i].ville + " ] "  + 
					storesMap[i].nom;

				elOptNew.value = i;

				try {
					// standards compliant; doesn't work in IE
					elSel.add(elOptNew, null); 

				} catch(ex) {
					// IE only
					elSel.add(elOptNew); 
				}
			}
		}
	}

	function loadCartesTousMagasins(){

		// affichage de la liste des magasins au-dessous de la carte
		liste_magasins = "<ul>";

		var NB_STORES = 0;
		for (var i in storesMap) {
			// trouve aucune facon propre d'avoir le
			// nombre d'elements d'un tableau associatif
			NB_STORES++;
		}
		var cut1 = Math.ceil(NB_STORES/3);
		var cut2 = 2*cut1;
		var nbitems = 0;

//		for (var i in storesMap) {
for(var j = 0; j < storesIdsByCP.length; j++) {
i = storesIdsByCP[j];
			var cp = storesMap[i].codePostal;
			var ville = storesMap[i].ville;

			//var ville = storesMap[i].ville.substring(0,10);  
			// troncage arbitraire a 10 caracteres, pour affichage sur 3 colonnes
			liste_magasins = liste_magasins + "<li>"
				+ "<a href=\"#\" onclick=\"openBubble(" + i + ", bubbles, markers, map1);\">" 
				+ cp + " " + ville + "</a></li>";
			nbitems++;
			if(nbitems==cut1 || nbitems==cut2)
				liste_magasins += "</ul><ul>";
		}

		liste_magasins += "</ul>";
		document.getElementById("liste_magasin").innerHTML = liste_magasins;
	}

	/*
	 * Afficher la carte
	 */
	function init_print_popup(canvas_source_id, canvas_destination_id){
		var contents = window.opener.document.getElementById(canvas_source_id);
		document.getElementById(canvas_destination_id).innerHTML = contents.innerHTML;
		window.print();
	}

	/****************************************************************************
	   * Chargement des cartes et des listes de selection des magasins
	   ***************************************************************************/
		function loadListeMagasins(id_clic_deroule_element){

		var liste_magasins = "";
 
//		for (var i in storesMap) {
for(var j = 0; j < storesIdsByCP.length; j++) {
i = storesIdsByCP[j];
			var cp = storesMap[i].codePostal;
			var ville = storesMap[i].ville;
			liste_magasins += "<li><a href=\"" + storesMap[i].url + "\">" + cp + " " + ville + "</a></li>";
		}

		document.getElementById(id_clic_deroule_element).innerHTML = liste_magasins;

	}


	function derouler (element) {

		var lien = document.getElementById(element);
		var list_deroul = document.getElementById(element + "_deroule");

		lien.onclick = function() {
			return false;
		}

		lien.onmouseover = function(){			
			list_deroul.style.display='block';
		}

		lien.onmouseout = function(){			
			list_deroul.style.display='none';
		}

		list_deroul.onmouseover = function(){			
			this.style.display='block';
		}

		list_deroul.onmouseout = function(){			
			this.style.display='none';
		}
	}


	// Ajoute le 17/1/2010 par vadel
	function getTheParameter(paramName) {

		// http://www.ehow.com/how_7473948_url-parameters.html
		//create possible combinations including the parameter name
		var searchChars = "[\\?&]"+paramName+"=([^&#]*)";

		//create a regular expression
		var regularExp = new RegExp(searchChars);

		//look for the regular expression in the current browser location
		var searchResults = regularExp.exec(window.location.href);

		if(searchResults!=null) 
			return searchResults[1];
		else 
			return ""; 
	}




/***************************************************************************************************/
//                            New functions - William Da Cunha - 19/01/2011
/***************************************************************************************************/
var tmpIds = null;
var tmpMap = null;
var tmpOptions = null;
var tmpMarkers = null;
var tmpBubbles = null;

var tmpLat = '';
var tmpLng = '';
var tmpRegion = '';
var tmpMagasin = '';

var gIds = Array();
var gMap = Array();
var gOptions = Array();
var gMarkers = Array();
var gBubbles = Array();
/***************************************************************************************************/
// Affiche la distance obtenu a partir d'une requete pour le div
function afficheDistance(request, divId){
	new google.maps.DirectionsService().route(request, function(response, status) {
		if (status == google.maps.DirectionsStatus.OK) {
			var total = 0;
			var myRoute = response.routes[0];
			for (j = 0; j < myRoute.legs.length; j++) {
				total += myRoute.legs[j].distance.value;
			}
			var dist = " (" + Math.floor(total / 1000) + " km)";
			document.getElementById(divId).innerHTML = dist;
		}
	});
}

function isDomTom(idMag) {
	return ((idMag == 2078) || (idMag == 2079) || (idMag == 2266));
}
/***************************************************************************************************/
function getIdsTousMagasinsFrance() {
	var allId = "";
	for(id in storesMap) {
		allId += "," + id;
	}
	allId = allId.substring(1, allId.length);
	return allId.split(',');
}
function getIdMagasinsFranceWithoutBoutiques() {
	var allId = "";
	for(id in storesMap) {
		if(storesMap[id].categorie.toUpperCase().indexOf('MAGASIN') > -1 ) {
			allId += "," + id;
		}
	}
	allId = allId.substring(1, allId.length);
	return allId.split(',');
}

function getIdsTousMagasins971() {
	return storesIds971;
}

function getIdsTousMagasins972() {
	return storesIds972;
}

function getIdsTousMagasins974() {
	return storesIds974;
}

function getIdsMonMagasin() {
	if(tmpMagasin == "") {
                if(document.getElementById("debug_error") != null)
		    document.getElementById("debug_error").innerHTML = "Ce magasin n'existe pas;";
	}
	return new Array(tmpMagasin);
}

function getIdsRegion() {
	var magasinIds =  new Array(); 
	var departementsIds = regions[tmpRegion].departements;
	for (var i in storesMap) {
		if(getRegionId(storesMap[i].codePostal) == tmpRegion) {
			magasinIds.push(i);
		}
	}  
	return magasinIds;
}

function getIdsEmpty() {
	return new Array();
}
/***************************************************************************************************/
function getOptionsTousMagasinsFrance(idsMag, lat, lng) {
	var mapCenter;

	mapCenter  = new google.maps.LatLng( 46.721252,2.509024);
	
	var myOptions = {
		zoom: 5,
		center: mapCenter,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		scaleControl: true,
		navigationControl: true,
		disableDefaultUI: true,
		navigationControlOptions: {
			style: google.maps.NavigationControlStyle.ZOOM_PAN
		}
	};
	return myOptions;
}

function getOptionsTousMagasinsDomtom(idsMag, lat, lng) {
	var mapCenter;
	if (idsMag != null || idsMag.length > 0 || storesMap[idsMag[0]] === undefined) {
		mapCenter  = new google.maps.LatLng(lat, lng);
	} else {
		mapCenter  = new google.maps.LatLng(storesMap[idsMag[0]].lat, storesMap[idsMag[0]].lng);
	}
	var myOptions = {
		zoom: 8,
		center: mapCenter,
		disableDefaultUI: true,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		mapTypeControl: false
	};
	return myOptions;
}

function getOptionsMonMagasin(idsMag, lat, lng) {
	var mapCenter;

	if (idsMag == null || idsMag.length < 1 ) {
		mapCenter  = new google.maps.LatLng(lat, lng);
	} else {
		mapCenter  = new google.maps.LatLng(storesMap[idsMag[0]].lat, storesMap[idsMag[0]].lng);
	}

	var myOptions = {
		zoom: 13,
		center: mapCenter,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		navigationControl: false,
		scaleControl: false,
		disableDefaultUI: true,
		draggable: false,
		scrollwheel: false,
		disableDoubleClickZoom: true,
		navigationControlOptions: {
			style: google.maps.NavigationControlStyle.ZOOM_PAN
		}
	};
	return myOptions;
}

function getOptionsMagasinRegion(idsMag, lat, lng) {
	if(idsMag.length == 1) {
		mapCenter  = new google.maps.LatLng(storesMap[idsMag[0]].lat, storesMap[idsMag[0]].lng);
	} else {
		var mapCenter  = new google.maps.LatLng(lat, lng);
	}
	var myOptions = {
		zoom: 9,
		center: mapCenter,
		disableDefaultUI: true,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		mapTypeControl: false
	};
	return myOptions;
}

function getOptionsEmpty(idsMag, lat, lng) {
	return null;
}

/***************************************************************************************************/
function getBubblesTousMagasinsFranceOld(map, idsMag, idMag) {
	var content = "";
	content += "<div class='infoBulleMagasin'>" + storesMap[idMag].libelleComplet + "<br/><small>";
	content += storesMap[idMag].addresse1;
	content += "<br/>" + storesMap[idMag].addresse2;
	content += "<br/>" + storesMap[idMag].codePostal + " " + storesMap[idMag].ville;
	content += "<br/>" + storesMap[idMag].telPrincipal;
	//2011-01 changement format horaires content += "<br/>" + formaterHoraires(storesMap[idMag].heures);
	content += "<br/>" + storesMap[idMag].ouverturepart;
	content += "<br/><a href=\"http://www.lapeyrepro.com/nos-magasins/fichemagasin.html?";
	content += PARAM_ID_MAGASIN + "=";
	content += idMag + "\">Voir la fiche du magasin</a>";
	content += "</small></div>";
	return content;
}

function getBubblesTousMagasinsFrance(map, idsMag, idMag) {
	var content = "";
	content += "<div class='infoBulleMagasin'>" + storesMap[idMag].libelleComplet + "<br/><small>";
	content += storesMap[idMag].addresse1;
	content += "<br/>" + storesMap[idMag].addresse2;
	content += "<br/>" + storesMap[idMag].codePostal + " " + storesMap[idMag].ville;
	content += "<br/>" + storesMap[idMag].telPrincipal;
	//2011-01 changement format horaires content += "<br/>" + formaterHoraires(storesMap[idMag].heures);
	content += "<br/>" + storesMap[idMag].ouverturepart;
	content += "<br/><a href=\"" + storesMap[idMag].url  + "\">Voir la fiche du magasin</a>";
	content += "</small></div>";
	return content;
}

function getBubblesAchatsFrance(map, idsMag, idMag) {
	var content = "";
	content += "<div class='infoBulleMagasin'>" + storesMap[idMag].libelleComplet + "<br/><small>";
	content += storesMap[idMag].addresse1;
	content += "<br/>" + storesMap[idMag].addresse2;
	content += "<br/>" + storesMap[idMag].codePostal + " " + storesMap[idMag].ville;
	content += "<br/>" + storesMap[idMag].telPrincipal;
	//2011-01 changement format horaires content += "<br/>" + formaterHoraires(storesMap[idMag].heures);
	content += "<br/>" + storesMap[idMag].ouverturepart;
	content += "<br/>";
	content += "<a onclick='javascript:serviceChoisirEnlevement(function() {";

	content += 		"serviceChoisirMagasin(" + idMag + ", 0, function(){";
	content += 			"window.location.href = \"http://www.lapeyrepro.com/achats/retraitchargement.html?";

	content += 			"&codelieuWeb=" + idMag + "\";";
	content += 		"});";
	content += "});";
	content += "' href='#'>Choisir ce magasin</a>";
	content += "</small></div>";
	return content;
}

function getBubblesEmpty(map, idsMag, idMag) {
	return "";
}
/***************************************************************************************************/
function specifIdTousMagasinsFrance(map, options, idsMag, idMag, marker, bubble) {
	attacherBulle(marker, bubble, map);
}

function specifIdTousMagasinsDomtom(map, options, idsMag, idMag, marker, bubble) {
	var urlDomTom = "http://www.lapeyrepro.com/nos-magasins/fichemagasin.html?" + PARAM_ID_MAGASIN + "=" + idMag;
	attacherUrl(marker, urlDomTom);
}

function specifIdAchatDomtom(map, options, idsMag, idMag, marker, bubble) {
/*
	if(getTheParameter("livr") == "1") {
		var urlDomTom = "http://www.lapeyrepro.com/achats/mon-panier.html?idMagasin=" + idMag;
	} else {
		var urlDomTom = "http://www.lapeyrepro.com/achats/retraitchargement.html?idMagasin=" + convertWebToTech(idMag) + "&codelieuWeb=" + idMag;
	}
*/
	var urlDomTom = "http://www.lapeyrepro.com/achats/retraitchargement.html?codelieuWeb=" + idMag;
	attacherUrl(marker, urlDomTom);
}

function specifIdEmpty(map, options, idsMag, idMag, marker, bubble) {
	return;
}
/***************************************************************************************************/
function specifIdsMagasinCP(map, options, idsMag, markers, bubbles) {
	// verification du code postal
	var codePostal = getTheParameter("cp");
	var adresse = "";
	if(codePostal.length == 2) {
		if(typeof(departements[codePostal].defaultCP) == 'undefined') 
			codePostal += "000";
		else
			codePostal = departements[codePostal].defaultCP;
	}
	if(!validerCodePostal(codePostal)) {
                if(document.getElementById("debug_error") != null)
		    document.getElementById("debug_error").innerHTML = "Format de saisi non valide. Veuillez saisir un code postal de 5 chiffres.";
		return;

	}

	var departementCode = codePostal.substring(0,3);
	if (departementCode == "971") {
		adresse = codePostal + " Guadeloupe";
	} else if (departementCode == "972") {
		adresse = codePostal + " Martinique";
	} else if (departementCode == "973") {
		adresse = codePostal + " Guyane";
	} else if (departementCode == "974") {
		adresse = codePostal + " La Reunion";
	} else {
		adresse = codePostal + " FRANCE";
	}



	// Utilisation de l'api google, requete asynchrone
	new google.maps.Geocoder().geocode({address: adresse }, function(results, status) {
		if(status == google.maps.GeocoderStatus.OK) {
			// Recuperation des coordonnees du cp saisi
			var latCP = results[0].geometry.location.lat();
			var lngCP = results[0].geometry.location.lng();
			latlng = new google.maps.LatLng(latCP, lngCP);
			// Recuperation des magasins les plus proches
			var nearestStores = new Array();
			var distancesCarres = new Array();
			for(var i in storesMap) {
				distancesCarres[i] = [Math.pow(latCP - storesMap[i].lat,2) + Math.pow(lngCP - storesMap[i].lng,2), i];

			}

			distancesCarres.sort(function(a,b){return a[0] - b[0]});
			var i = 0;
			var j = 0;
			while ((i < distancesCarres.length) && (j < NB_STORES_BULLE_GENERALE)) {
				dc = distancesCarres[i];
				//if((dc[0] > 0) && (dc[0] < 400)) {
					nearestStores[j] = dc[1];
					j++;
				//}
				i++;
			}

			// Parcours des magasins
			//var bounds = new google.maps.LatLngBounds();
			var contentInfoWindow = "<div>"
			contentInfoWindow += "<div style=\"text-align:left;\">";
			contentInfoWindow += "Magasins Lapeyre les plus proches de chez vous"
			contentInfoWindow += "</div>";
			contentInfoWindow += "<div>";
			contentInfoWindow += "<ul style=\"text-align:left;list-style-type:disc;list-style-position: inside ;\">";
			for(var i = 0; i < nearestStores.length; i++) {
				// Calcul pour le recentrage de la map
				//var latLngI = new google.maps.LatLng(storesMap[nearestStores[i]].lat, storesMap[nearestStores[i]].lng);
				//bounds.extend(latLngI);

				// Creation du texte a afficher
				contentInfoWindow += "<li>";
				contentInfoWindow += "<a href=\"http://www.lapeyrepro.com/nos-magasins/fichemagasin.html?" + PARAM_ID_MAGASIN + "=" + nearestStores[i] + "\">";
				contentInfoWindow += storesMap[nearestStores[i]].libelleComplet;
				contentInfoWindow += "<\a><span id=\"dist" + i + "\"> (calcul distance)</span></li>";

				// Calcul de distance
				var request = {
					origin: results[0].geometry.location,
					destination: new google.maps.LatLng(storesMap[nearestStores[i]].lat, storesMap[nearestStores[i]].lng),
					travelMode: google.maps.DirectionsTravelMode.DRIVING
				};
				afficheDistance(request, "dist" + i);
			}
			contentInfoWindow += "</ul></div></div>";

			// On ajuste la map
			var myOptions = {
				zoom: 9,
				center: latlng,
				disableDefaultUI: true,
				mapTypeId: google.maps.MapTypeId.ROADMAP,
				mapTypeControl: false
			};
//			map.fitBounds(bounds);
			map.setOptions(myOptions);

			// Affichage du texte au milieu de la carte
			var infoWindow = new google.maps.InfoWindow({ 
				position: map.getCenter(), 
				content: contentInfoWindow
			});
			infoWindow.open(map);
		} else {
			// L'api google n'a pas fonctionnee
                        if(document.getElementById("debug_error") != null)
			    document.getElementById("debug_error").innerHTML = codePostal + " not found";
			return "";
		}
	});
}

function specifIdsRegion(map, options, idsMag, markers, bubbles) {
	if(idsMag.length > 1) {
		var bounds = new google.maps.LatLngBounds();
		for(var i = 0; i < idsMag.length; i++) {
			var latLngI = new google.maps.LatLng(storesMap[idsMag[i]].lat, storesMap[idsMag[i]].lng);
			bounds.extend(latLngI);
		}
		map.fitBounds(bounds);
	}
}

function specifIdsEmpty(map, options, idsMag, markers, bubbles) {
	return;
}
/***************************************************************************************************/

