//<script language="javascript" type="text/javascript">



function addLoadEvent(func) {
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		var oldonload = window.onload;
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function addUnloadEvent(func) {
	if (typeof window.onunload != 'function') {
		window.onunload = func;
	} else {
		var oldonunload = window.onunload;
		window.onunload = function() {
			oldonunload();
			func();
		}
	}
}




// defaults that may be changed by the page
taborder = '123456789'.split('');

groupings = new Array();
groupings[1] = { 'id': 1, 'name': 'VICHY', 'latitude': 46.1253, 'longitude': 3.42377, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[2] = { 'id': 2, 'name': 'DIGNE LES BAINS', 'latitude': 44.0926, 'longitude': 6.2347, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[3] = { 'id': 3, 'name': 'NICE', 'latitude': 43.6997, 'longitude': 7.26858, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[4] = { 'id': 4, 'name': 'AIX EN PROVENCE', 'latitude': 43.5269, 'longitude': 5.44453, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[5] = { 'id': 5, 'name': 'ARLES', 'latitude': 43.676, 'longitude': 4.62622, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[6] = { 'id': 6, 'name': 'MARSEILLE', 'latitude': 43.2948, 'longitude': 5.37875, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[7] = { 'id': 7, 'name': 'CAEN', 'latitude': 49.1847, 'longitude': -0.360146, 'icon_id': 2, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 14 };
groupings[8] = { 'id': 8, 'name': 'DIJON', 'latitude': 47.3231, 'longitude': 5.03535, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[9] = { 'id': 9, 'name': 'BESANCON', 'latitude': 47.2395, 'longitude': 6.02131, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[10] = { 'id': 10, 'name': 'VALENCE', 'latitude': 44.9305, 'longitude': 4.89256, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[11] = { 'id': 11, 'name': 'BREST', 'latitude': 48.3876, 'longitude': -4.48947, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[12] = { 'id': 12, 'name': 'NIMES', 'latitude': 43.8365, 'longitude': 4.35704, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[13] = { 'id': 13, 'name': 'TOULOUSE', 'latitude': 43.6043, 'longitude': 1.44299, 'icon_id': 2, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 12 };
groupings[14] = { 'id': 14, 'name': 'BORDEAUX', 'latitude': 44.8374, 'longitude': -0.576096, 'icon_id': 2, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 12 };
groupings[16] = { 'id': 16, 'name': 'MONTPELLIER', 'latitude': 43.6085, 'longitude': 3.87927, 'icon_id': 2, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 13 };
groupings[17] = { 'id': 17, 'name': 'BEZIERS', 'latitude': 43.3441, 'longitude': 3.21558, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[18] = { 'id': 18, 'name': 'RENNES', 'latitude': 48.1117, 'longitude': -1.68023, 'icon_id': 2, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 12 };
groupings[19] = { 'id': 19, 'name': 'TOURS', 'latitude': 47.3911, 'longitude': 0.688532, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[20] = { 'id': 20, 'name': 'GRENOBLE', 'latitude': 45.1943, 'longitude': 5.73161, 'icon_id': 2, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 13 };
groupings[21] = { 'id': 21, 'name': 'ST PRIEST EN JAREZ', 'latitude': 45.4797, 'longitude': 4.35725, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[22] = { 'id': 22, 'name': 'NANTES', 'latitude': 47.2168, 'longitude': -1.55673, 'icon_id': 2, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 12 };
groupings[23] = { 'id': 23, 'name': 'ORLEANS', 'latitude': 47.8405, 'longitude': 1.93149, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[24] = { 'id': 24, 'name': 'ANGERS', 'latitude': 47.4685, 'longitude': -0.550256, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[25] = { 'id': 25, 'name': 'CHALONS EN CHAMPAGNE', 'latitude': 48.9563, 'longitude': 4.3607, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[26] = { 'id': 26, 'name': 'REIMS', 'latitude': 49.2548, 'longitude': 4.03215, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[27] = { 'id': 27, 'name': 'NANCY', 'latitude': 48.6908, 'longitude': 6.1825, 'icon_id': 2, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 13 };
groupings[29] = { 'id': 29, 'name': 'METZ', 'latitude': 49.119, 'longitude': 6.17167, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[30] = { 'id': 30, 'name': 'LILLE', 'latitude': 50.6372, 'longitude': 3.06302, 'icon_id': 2, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 11 };
groupings[32] = { 'id': 32, 'name': 'LILLE', 'latitude': 50.6294, 'longitude': 3.07731, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[33] = { 'id': 33, 'name': 'COMPIEGNE', 'latitude': 49.4174, 'longitude': 2.8262, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[34] = { 'id': 34, 'name': 'CLERMONT FERRAND', 'latitude': 45.7772, 'longitude': 3.08242, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[35] = { 'id': 35, 'name': 'LESCAR', 'latitude': 43.3299, 'longitude': -0.44716, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[36] = { 'id': 36, 'name': 'PERPIGNAN', 'latitude': 42.6992, 'longitude': 2.89218, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[37] = { 'id': 37, 'name': 'STRASBOURG', 'latitude': 48.5795, 'longitude': 7.76143, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[38] = { 'id': 38, 'name': 'LYON', 'latitude': 45.7673, 'longitude': 4.83433, 'icon_id': 2, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 11 };
groupings[39] = { 'id': 39, 'name': 'VILLEURBANNE', 'latitude': 45.7792, 'longitude': 4.87377, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[42] = { 'id': 42, 'name': 'CHARNAY LES MACON', 'latitude': 46.3086, 'longitude': 4.80923, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[43] = { 'id': 43, 'name': 'LE MANS', 'latitude': 48.0043, 'longitude': 0.19595, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[44] = { 'id': 44, 'name': 'CHAMBERY', 'latitude': 45.5681, 'longitude': 5.92142, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[45] = { 'id': 45, 'name': 'PARIS', 'latitude': 48.8566, 'longitude': 2.35097, 'icon_id': 2, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 10 };
groupings[46] = { 'id': 46, 'name': 'ROUEN', 'latitude': 49.4418, 'longitude': 1.09045, 'icon_id': 2, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 13 };
groupings[50] = { 'id': 50, 'name': 'AMIENS', 'latitude': 49.8931, 'longitude': 2.2978, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[51] = { 'id': 51, 'name': 'TOULON', 'latitude': 43.1251, 'longitude': 5.93145, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[52] = { 'id': 52, 'name': 'AVIGNON', 'latitude': 43.9471, 'longitude': 4.80583, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[53] = { 'id': 53, 'name': 'POITIERS', 'latitude': 46.5804, 'longitude': 0.339164, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[54] = { 'id': 54, 'name': 'LIMOGES', 'latitude': 45.8321, 'longitude': 1.26386, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 9 };
groupings[55] = { 'id': 55, 'name': 'EVRY', 'latitude': 48.6262, 'longitude': 2.43035, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 12 };
groupings[56] = { 'id': 56, 'name': 'ORSAY', 'latitude': 48.7005, 'longitude': 2.1882, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 12 };
groupings[63] = { 'id': 63, 'name': 'CERGY', 'latitude': 49.0367, 'longitude': 2.07938, 'icon_id': 1, 'min_zoomlevel': 0, 'max_zoomlevel': 8, 'click_zoomlevel': 12 };
icons = new Array();
icons[1] = { 'id': 1, 'url': '/img/signleup.png', 'width': 20, 'height': 20, 'shadow_url': null, 'shadow_width': 0, 'shadow_height': 0 };
icons[2] = { 'id': 2, 'url': '/img/multiup.png', 'width': 22, 'height': 21, 'shadow_url': null, 'shadow_width': 0, 'shadow_height': 0 };
icons[3] = { 'id': 3, 'url': '/img/location.png', 'width': 53, 'height': 49, 'shadow_url': null, 'shadow_width': 0, 'shadow_height': 0 };
location_types = new Array();
location_types[1] = { 'id': 1, 'name': 'branch', 'icon_id': 1 };
location_types[2] = { 'id': 2, 'name': 'zoombranch', 'icon_id': 3 };

var locations = [];

var showRepair = true;
var showStore = true;

var highlightRepair = false;
var highlightStore = false;

function initialize_map(latitude, longitude, zoom) {
	if (GBrowserIsCompatible()) {
				GM = new GMap2(document.getElementById("map"));
		GM.setCenter(new GLatLng(latitude, longitude), zoom);

				GM.enableDoubleClickZoom();
		
				GM.enableContinuousZoom();
				

				GM.addControl(new GLargeMapControl());
		GM.addControl(new GMapTypeControl());
		GM.addControl(new GScaleControl());

		//GMMgr = new GMarkerManager(GM, { borderPadding : 0 } );
		GMMgr = new SMarkerManager(GM);

		// ====== Restricting the range of Zoom Levels =====
 	    // Get the list of map types      
 	    var mt = GM.getMapTypes();
	    // Overwrite the getMinimumResolution() and getMaximumResolution() methods
	    for (var i=0; i<mt.length; i++) {
	    					mt[i].getMinimumResolution = function() {return 5;}
				    		    }

				for (var iconid in icons) {
			var icon = icons[iconid];
			var gi = new GIcon();
			gi.image = icon.url;
			gi.iconSize = new GSize(icon.width, icon.height);
			if (icon.shadow_url != null) {
				gi.shadow = icon.shadow_url;
				gi.shadowSize = new GSize(icon.shadow_width, icon.shadow_height);
			}
			gi.iconAnchor = new GPoint(icon.width / 2, icon.height / 2);
			gi.infoWindowAnchor = new GPoint(icon.width / 2, 0);
			icon.gicon = gi;
		}

								for (var grpid in groupings) {
				var grp = groupings[grpid];
				grp.glatlng = new GLatLng(grp.latitude, grp.longitude);
				grp.gmarker = new GMarker(grp.glatlng, {
					'icon': icons[grp.icon_id].gicon,
					'title': grp.name });
				GEvent.addListener(grp.gmarker, "click", curryFunction(function(mygrp) {
					GM.setZoom(mygrp.click_zoomlevel);
					GM.panTo(mygrp.glatlng);
				}, grp));
				GMMgr.addMarker(grp.gmarker, grp.min_zoomlevel, grp.max_zoomlevel);
			}
		
		
		addUnloadEvent(GUnload);
		addUnloadEvent(GMMgr.unload);
		
	} else {
        var header = 'Sorry, this map cannot be displayed.';
        var main   = 'Your browser does not support features required to run the map application.';
        if (document.getElementById) {
            var html = '<h1>' + header + '</h1>';
            html +=    '<p>' + main + '</p>';
            document.getElementById('map').innerHTML = html;
        } else {
            alert(header + '\n' + main);
        }
    }
	
}

function curryFunction() {
	var curriedArgs = [];
	var f = arguments[0];
	for (var i = 1; i < arguments.length; i++) {
		curriedArgs[curriedArgs.length] = arguments[i];
	}
	return function() {
		var newArgs = new Array();
		for (var i = 0; i < curriedArgs.length; i++) {
			newArgs[newArgs.length] = curriedArgs[i];
		}
		for (var i = 0; i < arguments.length; i++) {
			newArgs[newArgs.length] = arguments[i];
		}
		return f.apply(null, newArgs);
	}
}

function createTabs(id) {
	GDownloadUrl("data.php?call=getLocationTabs&q=" + Math.random() + "&id=" + id, function(data, responseCode) {
		//alert(data);
		var xml = GXml.parse(data);
		var tabs = xml.documentElement.getElementsByTagName("tab");
		infoTabs = new Array();
		for (i=0;i < tabs.length;i++) {
		    try {
		        sText = tabs[i].childNodes[0].nodeValue;
		    } catch (e) {
		        sText = '';
		    }
		    infoTabs[i] = new GInfoWindowTab(tabs[i].getAttribute("title"), sText);
		}
				var orderedTabs = new Array();
		for (i = 0; i < taborder.length; i++) {
			var tabnumber = taborder[i] - 1; 			if (tabnumber < infoTabs.length) {
				orderedTabs[orderedTabs.length] = infoTabs[tabnumber];
			}
		}
		
		openInfoWindowTabs(locations[id].gmarker, orderedTabs);
    });
}

function openInfoWindowTabs(gmarker, tabs) {
		try {
		gmarker.openInfoWindowTabs(tabs);
	}
	catch (Exception) {
		window.setTimeout(curryFunction(openInfoWindowTabs, gmarker, tabs), 1);
	}
}

function doPan(id) {
	if (id != '') {
		GM.setZoom(17);
		GM.panTo(locations[id].glatlng);
		        setTimeout(curryFunction(createTabs, id), 1);
	}
}

function doPanGrouping(grouping_id) {
	if (grouping_id != '') {
		var g = groupings[grouping_id];
		GM.setZoom(g.click_zoomlevel);
		GM.panTo(g.glatlng);
	}
}



function addLocation(id, name, latitude, longitude, zoomlevel, location_type_id, maxzoomlevel) {
	if (typeof(locations[id]) != 'undefined') {
		return; 	}
	var l = {
		'id': id,
		'name': name,
		'latitude': latitude,
		'longitude': longitude,
		'zoomlevel': zoomlevel,
		'location_type_id': location_type_id,
		'maxzoomlevel': maxzoomlevel
	};
	locations[id] = l;
	l.type = location_types[location_type_id];
	l.glatlng = new GLatLng(latitude, longitude);
	l.gmarker = new GMarker(l.glatlng, {
		'icon': icons[l.type.icon_id].gicon,
		'title': l.name });
	GEvent.addListener(l.gmarker, 'click', curryFunction(function(l) {
		createTabs(l.id);
	 }, l));
		GMMgr.addMarker(l.gmarker, zoomlevel,maxzoomlevel);
	
}

function showPrintWindow(id) {
	var center = GM.getCenter();
	var zoom = GM.getZoom();
	// PREVIOUS window.open("map-print.php?printstore=" + id + "&lat=" + center.lat() + "&lng=" + center.lng() + "&zoom=" + zoom, "print");
	window.open("map-print.php?printstore=" + id + "&lat=" + center.lat() + "&lng=" + center.lng() + "&zoom=" + zoom, "print");
}

function waitSearch(path){
	path.value = "searching...";
}

//</script>
