//alert("ici btmap_lib");
try
{
	var result_bool = GBrowserIsCompatible();
} catch(e) { 
	alert("Google Maps not accessible!");
}

// ajout de methode GMAP
GPolyline.Shape = function(point,r1,r2,r3,r4,rotation,vertexCount,colour,weight,opacity,opts,tilt) {
	var rot = -rotation*Math.PI/180;
	var points = [];
	var latConv = point.distanceFrom(new GLatLng(point.lat()+0.1,point.lng()))*10;
	var lngConv = point.distanceFrom(new GLatLng(point.lat(),point.lng()+0.1))*10;
	var step = (360/vertexCount)||10;

	var flop = -1;
	if (tilt) {
		var I1=180/vertexCount;
	} else {
		var  I1=0;
	}
	for(var i=I1; i<=360.001+I1; i+=step) {
		var r1a = flop?r1:r3;
		var r2a = flop?r2:r4;
		flop = -1-flop;
		var y = r1a * Math.cos(i * Math.PI/180);
		var x = r2a * Math.sin(i * Math.PI/180);
		var lng = (x*Math.cos(rot)-y*Math.sin(rot))/lngConv;
		var lat = (y*Math.cos(rot)+x*Math.sin(rot))/latConv;

		points.push(new GLatLng(point.lat()+lat,point.lng()+lng));
	}
	return (new GPolyline(points,colour,weight,opacity,opts))
}

GPolyline.Circle = function(point,radius,colour,weight,opacity,opts) {
	//var nb_point = Math.round(radius/1000); // optimisation du nombre de points => non depend aussi du zoom
	return GPolyline.Shape(point,radius,radius,radius,radius,0,50,colour,weight,opacity,opts)
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//	Librairie by AFG
//		    © 2008
//
/////////////////////////////////////////////////////////////////////	Debut de la pseudo classe	//////////////////////////////////////////////////////////////////////////////////
var tbMap = function(div_id_map) {
	this.div_map = document.getElementById(div_id_map);
	this.bt_map = null;
	this.bt_div_infos = null;
	this.bt_div_infos_id = null;
	this.bt_markers = new Array();
	this.bt_icons = new Array();
	this.bt_types = new Array();
	this.bt_categories = new Array();
	this.bt_groups = new Array();
	this.res_url = '';
	this.callback = null;
	this.callback_args =null;
	this.curzoom = 7;
	this.wi_loading_content ="...";
	this.errorFct = null;
	this.polygon = null;
	
	this.lockWiOpened = false;
	
	this.loadonlyonfirstsearch = false;
	this.firstgetpassed = false;
	
	this.continuousZoom = false;
	this.mouseScrollZoom = false;
	this.smallMapControl = false;
	this.largeMapControl = false;
	this.mapTypeControl = false;
	this.overviewMapControl = false;
	// Taille MAX utile pour IE6 en pixel
	this.googleInfoWindowWidth = 500;
}

tbMap.prototype = {
	/*  DEBUT --------------------- PARTIE SPECIFIQUE A GMAP --------------------- */
	loadMap : function() {
		if (this.isBrowserCompatible()) {
			if (false == this.loadonlyonfirstsearch) {
				this.initMap();
			}
		}
	},
	initMap : function() {
		if (this.isBrowserCompatible()) { 
		
			this.bt_map = new GMap2(this.div_map);
			this.setDefaultCenter();
			this.setContinuousZoom(this.continuousZoom);
			this.setMouseScrollZoom(this.mouseScrollZoom);
			if (true == this.smallMapControl) {
				this.addSmallMapControl();
			}
			if (true == this.largeMapControl) {
				this.addLargeMapControl();
			}
			if (true == this.mapTypeControl) {
				this.addMapTypeControl();
			}
			if (true == this.overviewMapControl) {
				this.addOverviewMapControl();
			}
		}
	},
	onLoadRes : function() {
		if (this.isBrowserCompatible()) {
			if (true == this.loadonlyonfirstsearch && false == this.firstgetpassed) {
				this.initMap();
			}
			this.firstgetpassed = true;
		}
	},
	isBrowserCompatible: function() {
		var result_bool=false;
		try
		{
			result_bool = GBrowserIsCompatible();
		} catch(e) {}
		return result_bool;
	},
	setShowOnlyOnFisrtSearch : function(bool) {
		this.loadonlyonfirstsearch=bool;
	},
	setContinuousZoom : function(bool) {
		this.continuousZoom = bool;
		if (this.isBrowserCompatible()) {
			if (this.bt_map) {
				if (bool) this.bt_map.enableContinuousZoom();
				else this.bt_map.disableContinuousZoom();
			}
		}
	},
	setMouseScrollZoom : function(bool) {
		this.mouseScrollZoom = bool;
		if (this.isBrowserCompatible()) {
			if (this.bt_map) {
				if (bool) this.bt_map.enableScrollWheelZoom();
				else this.bt_map.disableScrollWheelZoom();
			}
		}
	},
	setDefaultCenter : function() {
		if (this.isBrowserCompatible()) {
			if (this.bt_map) 
				this.bt_map.setCenter(new GLatLng(48.180739,-2.757568),7); // centre bretagne par defaut
		}
	},
	setCenter : function(lat,lng,zoom) {
		this.curzoom = parseInt(zoom);
		if (this.isBrowserCompatible()) {
			if (this.bt_map) 
				this.bt_map.setCenter(new GLatLng(lat, lng), this.curzoom);
		}
	},
	
	setGoogleInfoWindowWidth : function (value) {
		this.googleInfoWindowWidth = value;
	},
	
	// Controle des deplacement sur la carte et zoom
	addSmallMapControl : function() {
		this.smallMapControl = true;
		if (this.isBrowserCompatible()) {
			if (this.bt_map) {
				this.bt_map.addControl(new GSmallMapControl());
			}
		}
	},
	
	addLargeMapControl : function() {
		this.largeMapControl = true;
		if (this.isBrowserCompatible()) {
			if (this.bt_map) {
				this.bt_map.addControl(new GLargeMapControl());
			}
		}
	},
	// Controle Type de VUE GOOGLE (Satelite, Carte ou Carte + Satelite)
	addMapTypeControl : function() {
		this.mapTypeControl = true;
		if (this.isBrowserCompatible()) {
			if (this.bt_map) 
				this.bt_map.addControl(new GMapTypeControl());
		}
	},
	addOverviewMapControl : function() {
		this.overviewMapControl = true;
		if (this.isBrowserCompatible()) {
			if (this.bt_map) 
				this.bt_map.addControl(new GOverviewMapControl());
		}
	},
	addDynWI : function(newmarker,type,indexM) {
		if (this.isBrowserCompatible()) {
			var obj = this;
			GEvent.addListener(newmarker, "click", function() {btmapu_showWIOfMarkerThis(obj,newmarker,type,indexM);});
		}
	},
	
	getAttribute : function(node,attributename) {
		result = null;
		attr = node.attributes;
		if (null != attr ) {
			for (iAttr=0,iAttrMax=attr.length; iAttr< iAttrMax;iAttr++) {
				if (attributename == attr[iAttr].nodeName) {result=attr[iAttr].nodeValue;break;}
			}
		}
		return result;
	},
	getClassName : function(node) {
		return this.getAttribute(node,'class');
	},
	getTitle : function(node) {
		return this.getAttribute(node,'title');
	},
	getGInfoWindowTab : function(tab_title,tab_node) {
		tab_res = null;
		if (window.ActiveXObject) {// IE 
			//alert('text='+this.getTextFromNode(tab_node, true));
			//alert('text='+tab_node.text);
			tab_res = new GInfoWindowTab(tab_title,tab_node.text);
		} else { // FF ...
			tab_res = new GInfoWindowTab(tab_title,tab_node);
		}
		return tab_res;
	},
	
	getNodeValue : function(nodes) {
		if ((nodes.length>0) && nodes[0] && nodes[0].firstChild && nodes[0].firstChild.nodeValue)
		   return nodes[0].firstChild.nodeValue;
	},

	
	openWI : function(marker_inf,content) {
		if (this.isBrowserCompatible()) {
			marker = marker_inf['marker'];
			
			if (marker && this.bt_map) {
				var point = marker.getPoint(); 
				var point_ori = this.bt_map.getCenter();
				
				var wiok = false; /* devient true si le contenu est ok */
				
				/* si un contenu est passe en parametre */
				if (content) {
					xml = this.parseXml(content);
					tabs = null;
					nbTab = 0;
					
					try {
						if (null != xml) { 
							/*   un div conteneur doit avoir comme id  "wi_tabs"   */
							xml_tabs = xml.getElementsByTagName("wi_tabs")[0];
							/* si le contenu contient des onglets */
							if (xml_tabs) {
								tabs_nodes = xml_tabs.getElementsByTagName("wi_tab");
								if (null != tabs_nodes && tabs_nodes.length > 0) {
									
									for (var itab = 0,itab_max=tabs_nodes.length; itab < itab_max; itab++) {
										var ctab =tabs_nodes[itab]; /*   l'id de chaque onglet (DIV) doit suivre la syntaxe wi_tab<0...10> : par exemple : "wi_tab0 ... wi_tab10"   */
										var tabLabel = this.getNodeValue(ctab.getElementsByTagName("label"));
										var tabHtml = this.getNodeValue(ctab.getElementsByTagName("contents"));
										
										if (null == tabHtml || '' == tabHtml) {
											try {
												var tabHtmlUrl = this.getNodeValue(ctab.getElementsByTagName("url_contents"));
												//alert("tabHtmlUrl="+tabHtmlUrl);
												var ar_xhr = new Ajax_request(tabHtmlUrl,{method:'get', onSuccess:function(xhr){},async:false});
												tabHtml = ar_xhr.responseText;
												//alert("tabHtml="+tabHtml);
											}catch(err){}
										}
										
										if (null != ctab && null != tabLabel && null != tabHtml) {
											if (null == tabs) tabs = new Array();
											tabs[nbTab] = new Array();
											tabs[nbTab]['label'] = tabLabel;
											tabs[nbTab]['html'] = tabHtml;
											nbTab++;
										}
									}
								}
							}
						}
					}catch(err){}
					if (null != tabs && tabs.length > 0) {
						marker_inf['wi_content_tabs'] = tabs; /* on sauvegarde les onglets */
					}
				} // fin recup onglet
					
				try {
					if (!content) content = marker_inf['wi_content'];
					var tabs = marker_inf['wi_content_tabs']; /* on recupere les onglets */
					if (null != tabs && tabs.length > 0) {
				        var tabs_param = new Array();
				        for (var itabn=0; itabn<tabs.length; itabn++) {
							tabLabel=tabs[itabn]['label'];
							tabHtml =tabs[itabn]['html'];
							if ((itabn==0) && (tabs.length > 2)){ //  adjust the width so that the info window is large enough for this many tabs
								//tabHtml = '<div style="width-min:'+tabs.length*100+'px">' + tabHtml + '</div>';
							}
							tabs_param.push(new GInfoWindowTab(tabLabel,tabHtml));
							//g_wi_tab = this.getGInfoWindowTab(tabs[itabn]['title'],tabs[itabn]['node']); => pbm style + pbm IE
							//tabs_param.push(g_wi_tab);
				        }
						try {
							//this.bt_map.closeInfoWindow() ;
							this.centerMapForOpenWi(point,point_ori);
							// marker.openInfoWindowTabsHtml(tabs_param);
							/** TAILLE LIMITE DES BULLES SOUS GOOGLE 'maxWidth:this.googleInfoWindowWidth = 500' **/
							if (this.googleInfoWindowWidth) {										 
								marker.openInfoWindowTabsHtml(tabs_param, {maxWidth:this.googleInfoWindowWidth });	
							}
							else {
								marker.openInfoWindowTabsHtml(tabs_param);
							}
							wiok = true;
						}catch(err){
							alert('error gmap : err='+err+', '+this.getTextFromNode(err, true));
						}
					} 
				}catch(err){}
				
				if (false == wiok) {
					this.bt_map.openInfoWindowHtml(point,content,{suppressMapPan:true});
					this.centerMapForOpenWi(point,point_ori);
				}
				
			}
		}
	},

	centerMapForOpenWi : function(point_dest,point_ori) {
		if (false == this.lockWiOpened) {
			//Save the event so i can refer to it later
			var map = this.bt_map;
			var myBtMap = this;
			var param_point_ori = point_ori;
			
			// center le map
			var myEvent = GEvent.addListener(map, "infowindowopen",
			function() {
				map.setCenter(param_point_ori);
				//map.savePosition();
				//Got this code from Mike:
				function subGPoints(a,b) {
					//returns the distance in pixels between point a and b
					return new GPoint(a.x-b.x, a.y-b.y);
				}
				//Pixel distance to the center of the map
				var CDivPixel = map.fromLatLngToDivPixel(param_point_ori);
				//Pixel distance from the marker point
				var pointDivPixel = map.fromLatLngToDivPixel(point_dest);
				
				//Difference between the above mentioned distances
				var fromCenter = subGPoints(pointDivPixel, CDivPixel);
				//Pan to the corrected location (the -40 and +215 sizes are the distances from my marker to the center of the infowindow
				this.panBy(new GSize(-fromCenter.x-40,-fromCenter.y+175))
				//Solution to fix Flash
				//document.getElementById("flashcontent").innerHTML=flashval;
				//Remove the event (never found any support for this, but it works! )
				GEvent.removeListener(myEvent);
			}  ); 
			
			var myEventClose = GEvent.addListener(map, "infowindowclose",
			function() {
				myBtMap.lockWiOpened = false;
				GEvent.removeListener(myEventClose);
			});
		}
		//this.bt_map.setCenter(point, this.curzoom);
		//var obj = this;
		//if (!document.all)  setTimeout(function(thisObj) { thisObj.bt_map.setCenter(marker.getLatLng(), thisObj.curzoom); }, 100, this);
	},
	
	filterRadius : function (lat,lng,rad) {
		var center_rep = new GLatLng(parseFloat(lat), parseFloat(lng));
		var rad_metters = rad*1000*1.609344;
		try { /* ajout du cercle */
			if (null != this.polygon) this.bt_map.removeOverlay(this.polygon);
			this.polygon = GPolyline.Circle(center_rep,rad_metters,"#111155",2); /*  */
			this.bt_map.addOverlay(this.polygon);
		}catch(e) {}
		
		//alert("lat="+lat+", lng="+lng+", rad="+rad);
		for (var itype in this.bt_markers) {
			for (var indM in this.bt_markers[itype]) {
				var marker = this.bt_markers[itype][indM]['marker'];
				var dist = center_rep.distanceFrom(marker.getLatLng()); /* distance in meters */
				if (dist > rad_metters) marker.hide();
				else  marker.show();
			}
		}
	},

	/*  FIN --------------------- PARTIE SPECIFIQUE A GMAP --------------------- */

	setWILoadingContent :  function (content) {
		this.wi_loading_content = content;
	},

	getRes :  function (div_id_infos,url,callback,callback_args) {
		if (this.bt_map) this.bt_map.closeInfoWindow();
		this.bt_div_infos = document.getElementById(div_id_infos);
		this.bt_div_infos_id = div_id_infos;
		this.res_url = url;
		this.callback = callback;
		this.callback_args = callback_args;
		//setTimeout('btmapu_showWaitInDiv(\''+div_id_infos+'\',true)',0);
		this.setDefaultCenter();
		var obj = this;
		if (document.all) obj.processRes();
		else setTimeout(function(thisObj) { thisObj.processRes(); }, 10, this);
	},

	processRes : function () {
		//récupere l'ID de la branche selectionne
		
		var url = this.res_url;
		//alert('url='+url);
		var processRes_obj = this;
		new Ajax_request(
			url,
			{
				method:'get',
				params:'',
				onSuccess:function(xhr) { btmapu_succesResThis(processRes_obj,xhr);},
				async:true
			}
		);			
		//this.res_url='';	
	},
	getTextFromNode : function(oNode, deep){
		var s = "";
		try {
		    var nodes = oNode.childNodes;
		    for(var i=0; i < nodes.length; i++){
		        var node = nodes[i];
		        var nodeType = node.nodeType;
		        if(nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE){
		            s += node.data;
		        }else if(deep == true
		                    && (nodeType == Node.ELEMENT_NODE
		                        || nodeType == Node.DOCUMENT_NODE
		                        || nodeType == Node.DOCUMENT_FRAGMENT_NODE)){
		            s += this.getTextFromNode(node, true);
		        };
		    };
		}catch(err){};
	    return s;
	},
	parseXml : function (content) {
		res_xml = null;
		try {
			if (window.ActiveXObject) {
				//alert('IE');
				res_xml = new ActiveXObject("Microsoft.XMLDOM");
				res_xml.async="false";
				res_xml.loadXML(content);
			} else {
				//alert('FF');
				var parser=new DOMParser();
				res_xml = parser.parseFromString(content,"text/xml");
			}
		} catch(e) { 
		
		}
		return res_xml;
	},
	succesRes : function (xhr) {
		try {
			var res_xml=xhr.responseXML;
			var parseErrorText = '';
			//alert('url='+this.res_url+', xhr.responseXML='+xhr.responseXML+', xhr.responseText ='+xhr.responseText)
			//this.debug('url='+this.res_url);
			
			this.onLoadRes(); /* replace la carte ... */
			
			if (xhr.responseText) {
				res_xml = this.parseXml(xhr.responseText);
			}
			
			if (!res_xml) {this.error('erreur : this='+this+'\n, res_xml='+res_xml+', \nxhr.responseText ='+xhr.responseText);return false;}
			
			if(res_xml.documentElement.tagName == "parsererror"){
	            parseErrorText = '\n erreur : '+res_xml.documentElement.firstChild.data;
	            parseErrorText += '\n ligne : '+res_xml.documentElement.firstChild.nextSibling.firstChild.data;
	        } else if(res_xml.getElementsByTagName("parsererror").length > 0){
	            var parsererror = res_xml.getElementsByTagName("parsererror")[0];
	            parseErrorText = this.getTextFromNode(parsererror, true);
	        } else if(res_xml.parseError && res_xml.parseError.errorCode != 0){
	            parseErrorText = 'parse unknown error';
	        };
			
			if (res_xml) res_xml=res_xml.getElementsByTagName('response')[0];
			
			if (!res_xml) {this.error('erreur : this='+this+'\n, res_xml='+res_xml+', \nxhr.responseText ='+xhr.responseText+', \n'+parseErrorText);return false;}
			
			if (res_xml) {
				// traitement des types
				var types_root = res_xml.getElementsByTagName("types");
				if (types_root) {
					for (var itypes = 0,itypesr_max = types_root.length; itypes < itypesr_max; itypes++) {
						var types = types_root[itypes].getElementsByTagName("type");
						for (var itype = 0,itypes_max = types.length; itype < itypes_max; itype++) {
							var type_inf = types[itype];
							var type_id = type_inf.getAttribute("id");
							if (type_id) {
								this.deleteMarkersForType(type_id);
								if (!this.bt_types) this.bt_types = new Array();
								this.bt_types[type_id]= new Array(); // on remplace l'ancien icone
								if (!this.bt_types[type_id]['lib']) this.bt_types[type_id]['lib'] = type_inf.getAttribute("lib");
								var wi_url_base = type_inf.getAttribute("wi_url_base");
								if (wi_url_base) this.bt_types[type_id]['wi_url_base'] = wi_url_base; // info window
								// init des categories au cas ou
								if ((null != type_inf.getAttribute("icon_id")) && ('' != type_inf.getAttribute("icon_id"))) 
									this.initCatWithType(type_inf);
							} else {
								this.error( 'id missing for a type!');
							}
						}
					}
				}
				
				// traitement des icones
				var icons_root = res_xml.getElementsByTagName("icons");
				if (icons_root) {
					for (var iicons = 0,iiconsr_max=icons_root.length; iicons < iiconsr_max; iicons++) {
						var icons = icons_root[iicons].getElementsByTagName("icon");
						for (var iicon = 0,iicons_max=icons.length; iicon < iicons_max; iicon++) {
							var icon_inf = icons[iicon];
							var icon_id = icon_inf.getAttribute("id");
							if (icon_id) {
								var icon = this.parseIcon(icon_inf);
								// enregistre dans
								if (!this.bt_icons) this.bt_icons = new Array();
								this.bt_icons[icon_id]= new Array(); // on remplace l'ancien icone
								this.bt_icons[icon_id]['icon'] = icon;
							} else {
								this.error( 'id missing for an icon!');
							}
						}
					}
				}
				
				// traitement des categories (sous division de type)
				var cats_root = res_xml.getElementsByTagName("categories");
				if (cats_root) {
					for (var icats = 0,icatsr_max=cats_root.length; icats < icatsr_max; icats++) {
						var cats = cats_root[icats].getElementsByTagName("category");
						for (var icat = 0,icats_max=cats.length; icat < icats_max; icat++) {
							var cat_inf = cats[icat];
							var cat_type = cat_inf.getAttribute("type");
							var cat_id = cat_inf.getAttribute("id");
							if (cat_type && cat_id) {
								if (!this.bt_categories) this.bt_categories = new Array();
								if (!this.bt_categories[cat_type]) this.bt_categories[cat_type]= new Array(); // on remplace l'ancienne
								/*if (!this.bt_categories[cat_type][cat_id]) */
									this.bt_categories[cat_type][cat_id] = new Array();
								/*if (!this.bt_categories[cat_type][cat_id]['lib']) */
									this.bt_categories[cat_type][cat_id]['lib'] = cat_inf.getAttribute("lib");
								if (cat_inf.getAttribute("icon_id")) this.bt_categories[cat_type][cat_id]['icon_id'] = cat_inf.getAttribute("icon_id");
							} else {
								this.error( 'id missing for a category!');
							}
						}
					}
				}
				
				
				// traitement des markers
				var markers_root = res_xml.getElementsByTagName("markers");
				if (markers_root) {
					for (var imarkers = 0,imarkersr_max=markers_root.length; imarkers < imarkersr_max; imarkers++) {
						var markers = markers_root[imarkers].getElementsByTagName("marker");
						for (var imarker = 0,imarkers_max=markers.length; imarker < imarkers_max; imarker++) {
							var marker_inf = markers[imarker];
							var type = marker_inf.getAttribute("type");
							if (type) {
								var indexM = imarker; //par defaut
								var point = new GLatLng(parseFloat(marker_inf.getAttribute("lat")),
														parseFloat(marker_inf.getAttribute("lng")));
								var icon_id = marker_inf.getAttribute("icon_id");
								if (icon_id && this.bt_icons[icon_id]) var newmarker = new GMarker(point,this.bt_icons[icon_id]['icon']);
								else var newmarker = new GMarker(point);
								if (!this.bt_markers[type]) this.bt_markers[type] = new Array();
								if (marker_inf.getAttribute("id")) {indexM = marker_inf.getAttribute("id");}
								this.bt_markers[type][indexM]= new Array();
								// on rempli les infos
								if (marker_inf.getAttribute("id")) {this.bt_markers[type][indexM]['id'] = marker_inf.getAttribute("id");}
								this.bt_markers[type][indexM]['marker'] = newmarker;
								//info window (cf. champ wi_url_base du type)
								if (marker_inf.getAttribute("wia")) {
									var wia = marker_inf.getAttribute("wia");
									var wia_bool = ((("yes" == wia) || ("oui" == wia)) ? true : false);
									this.bt_markers[type][indexM]['wia'] = wia_bool;
									if (wia_bool) {this.addDynWI(newmarker,type,indexM);}
								}
								this.bt_map.addOverlay(newmarker);
								if (!this.bt_types[type]) {this.bt_types[type]  = new Array();}
								if (!this.bt_types[type]['markers']) {this.bt_types[type]['markers'] = this.bt_markers[type];}
							} else {
								this.error( 'type missing for a marker!');
							}
						}
					}
				}
				
				// traitement des groupes 
				var grps_root = res_xml.getElementsByTagName("groups");
				if (grps_root) {
					for (var igrps = 0,igrpsr_max=grps_root.length; igrps < igrpsr_max; igrps++) {
						var grps = grps_root[igrps].getElementsByTagName("group");
						for (var igrp = 0,igrps_max=grps.length; igrp < igrps_max; igrp++) {
							var grp_inf = grps[igrp];
							var grp_id = grp_inf.getAttribute("id");
							if (grp_id) {
								if (!this.bt_groups) this.bt_groups = new Array();
								if (!this.bt_groups[grp_id]) this.bt_groups[grp_id]= new Array(); // on remplace l'ancienne
								if (!this.bt_groups[grp_id]['items']) this.bt_groups[grp_id]['items']= new Array();
								if (!this.bt_groups[grp_id]['lib']) this.bt_groups[grp_id]['lib'] = grp_inf.getAttribute("lib");
								var items = grp_inf.getElementsByTagName("item");
								for (var iitem = 0,iitems_max=items.length; iitem < iitems_max; iitem++) {
									var item_inf = items[iitem];
									var itName = item_inf.getAttribute("name");
									if (itName) {
										if (!this.bt_groups[grp_id]['items'][itName]) {
											this.bt_groups[grp_id]['items'][itName]= new Array();
											this.bt_groups[grp_id]['items'][itName]['lib']=itName;
											this.bt_groups[grp_id]['items'][itName]['lat']=item_inf.getAttribute("lat");
											this.bt_groups[grp_id]['items'][itName]['lng']=item_inf.getAttribute("lng");
											this.bt_groups[grp_id]['items'][itName]['zoom']=item_inf.getAttribute("zoom");
											this.bt_groups[grp_id]['items'][itName]['id']=item_inf.getAttribute("id");
										}
										if (!this.bt_groups[grp_id]['items'][itName]['res_count']) this.bt_groups[grp_id]['items'][itName]['res_count']= new Array();
										var res_counts = item_inf.getAttribute("res_count");
										var reg_types=new RegExp("[,]+", "g");
										var res_counts_s = res_counts.split(reg_types);
										for (var ityp = 0,ityp_max=res_counts_s.length; ityp < ityp_max; ityp++) {
											var reg_v=new RegExp("[\:]+", "g");
											var res_count = res_counts_s[ityp].split(reg_v);
											this.bt_groups[grp_id]['items'][itName]['res_count'][res_count[0]] = parseInt(res_count[1]);
										}
									}
								}
							} else {
								this.error( 'id missing for a group!');
							}
						}
					}
				}
			} else {
				try {this.error("Erreur de syntaxe dans la reponse du serveur!",xhr.responseText);} catch(e) { }
			}
		} catch(e) { }
		// appel de la callback
		if (null != this.callback) {
			if (this.callback_args)
				this.callback(this.callback_args,this);
			else
				this.callback(this);
		}
		this.callback = null;
	},

	initCatWithType : function (type_inf){
		var type_id =type_inf.getAttribute("id");
		if (!this.bt_categories[type_id]) this.bt_categories[type_id]= new Array();
		if ('' != type_inf.getAttribute("icon_id")) {
			this.bt_categories[type_id][0] = new Array();
			 this.bt_categories[type_id][0]['lib'] = type_inf.getAttribute("lib");
			 this.bt_categories[type_id][0]['icon_id'] = type_inf.getAttribute("icon_id");
		}
	},

	parseIcon : function (icon_inf){
		var icon = new GIcon();
		if (icon_inf.getAttribute("image")) icon.image = icon_inf.getAttribute("image");
		if (icon_inf.getAttribute("iconSize_w")) icon.iconSize = new GSize(icon_inf.getAttribute("iconSize_w"),icon_inf.getAttribute("iconSize_h"));
		if (icon_inf.getAttribute("shadow")) icon.shadow = icon_inf.getAttribute("shadow");
		if (icon_inf.getAttribute("shadowSize_w")) icon.shadowSize = new GSize(icon_inf.getAttribute("shadowSize_w"),icon_inf.getAttribute("shadowSize_h"));
		if (icon_inf.getAttribute("iconAnchor_x")) icon.iconAnchor = new GPoint(icon_inf.getAttribute("iconAnchor_x"),icon_inf.getAttribute("iconAnchor_y"));
		if (icon_inf.getAttribute("infoWindowAnchor_x")) icon.infoWindowAnchor = new GPoint(icon_inf.getAttribute("infoWindowAnchor_x"),icon_inf.getAttribute("infoWindowAnchor_y"));
		return icon;
	},

	deleteDatas : function (type){
		this.deleteMarkersForType(type);
		this.deleteCatForType(type);
		this.deleteGroupsDatasForType(type);
	},

	deleteCatForType : function (type){
		if (type && this.bt_categories && this.bt_categories[type]) {
			this.bt_categories[type]= new Array();
		}
	},

	deleteGroupsDatasForType : function (type){
		if (type && this.bt_groups) {
			for(grp_id in this.bt_groups) {
				var cgroup = this.bt_groups[grp_id];
				var items = cgroup['items'];
				var nb_items = btmapu_getAALength(items);
				if ( nb_items > 0) {
					for (iit in items) {
						if ((items[iit]['res_count']) && (items[iit]['res_count'][type])) {
							items[iit]['res_count'][type]=0;
						}
					}
				}
			}
		}
	},

	deleteMarkersForType : function (type){
		if (type && this.bt_markers && this.bt_markers[type]) {
			this.deleteMarkers(this.bt_markers[type]);
			this.bt_markers[type]= new Array();
		}
	},

	deleteMarkers : function (markers){
		if (markers) {
			for (var imarker = 0,imarker_max=markers.length; imarker < imarker_max; imarker++) {
				if (markers[imarker]['marker']) this.bt_map.removeOverlay(markers[imarker]['marker']);
			}	
		}
	},

	clearMap : function (){
		if (this.bt_map) {
			this.bt_map.closeInfoWindow();
			this.bt_map.clearOverlays();
		}
		this.bt_markers = new Array();
		this.bt_icons = new Array();
		this.bt_types = new Array();
		this.bt_categories = new Array();
		this.bt_groups = new Array();
	},
	close : function() {
		//alert ('begin CLOSE MAP this.bt_map='+this.bt_map);
		try {
			if (this.bt_map) {
				this.bt_map.closeInfoWindow();
			}
		} catch(err) {
			alert('error gmap : err='+err+', '+this.getTextFromNode(err, true));
		}
		//alert ('end CLOSE MAP');
	},
	getLegend : function () {
		var result = new Array();
		for(type in this.bt_categories) {
			if (0 != this.bt_categories[type].lenght) {
				for(cat_id in this.bt_categories[type]) {
					var cat = this.bt_categories[type][cat_id];
					iconIDOfCat = cat['icon_id'];
					if (iconIDOfCat && this.bt_icons[iconIDOfCat]) {
						if (!result[iconIDOfCat]) { // icone non enregistre dans result
							result[iconIDOfCat]= new Array();
							result[iconIDOfCat]['image']= new Array();
							result[iconIDOfCat]['image']['src'] = this.bt_icons[iconIDOfCat]['icon'].image;
							result[iconIDOfCat]['image']['width'] = this.bt_icons[iconIDOfCat]['icon'].iconSize.width;
							result[iconIDOfCat]['image']['height'] = this.bt_icons[iconIDOfCat]['icon'].iconSize.height;
						}
						if (!result[iconIDOfCat]['cats']) result[iconIDOfCat]['cats'] = new Array();
						result[iconIDOfCat]['cats'].push(cat['lib']);
					}
				}
			} else {/* rien */}
		}
		
		return result;
	},

	getGroups : function () {return this.bt_groups;},

	hideOrShowMarkersOfType : function (type){
		var markers = this.bt_markers[type];
		if (markers) {
			for (var imarker = 0,imarker_max=markers.length; imarker < imarker_max; imarker++) {
				if (markers[imarker]['marker']) {
					var marker = markers[imarker]['marker'];
					if (marker.isHidden()) marker.show();
					else marker.hide();
				}
			}
		}
	},

	showWIOfMarker : function (marker,type,marker_id) {
		var marker_inf = this.bt_markers[type][marker_id];
		var type_inf = this.bt_types[type];
		if (marker_inf && type_inf) {
			if (!(marker_inf['wi_content']) && !(marker_inf['wi_content_tabs'])) {
				this.openWI(marker_inf,this.wi_loading_content);
				if ((marker_inf['id']) && (true == marker_inf['wia']) && (type_inf['wi_url_base'])) {
					var url_req =  type_inf['wi_url_base']+'&type='+type+'&id='+marker_inf['id'];
					var objTBMap = this;
					ar = new Ajax_request(url_req,{method:'get', onSuccess:function(xhr){btmapu_showWIOfMarker_CB(xhr,objTBMap,marker_inf);},
					async:true});
					/*content = ar.responseText;
					if ((null != content) && ('' != content)) {
						marker_inf['wi_content']=content;
						this.openWI(marker_inf['marker'],marker_inf['wi_content']);
					}*/
				}
			} else {
				this.openWI(marker_inf);
			}
		}
	},
	
	
	
	setErrorAction : function (function_CB) {
		this.errorFct = function_CB;
	},
	
	error : function (args) {
		if (this.errorFct) this.errorFct(args)
		//else alert(args);
	},
	
	debug : function (args) {
		var win = window.open("", "win", "width=300,height=200"); // a window object
		with (win.document) {
			open("text/html", "replace");
			var sMarkup = "<HTML><HEAD><TITLE>New Document</TITLE></HEAD>";
			sMarkup += "<BODY>"+args+"<p><A HREF='javascript:window.close();'>Return</A></BODY></HTML>";
			write(sMarkup);
			close();
		}
		//alert(args);
	}
} // fin de la classe
	
// fonctions externes utiles a la classe btMap

btmapu_succesResThis = function(obj,xhr) {
	obj.succesRes(xhr);
}
btmapu_showWIOfMarkerThis = function (obj,marker,type,marker_id) {
	obj.showWIOfMarker(marker,type,marker_id);
}
btmapu_showWIOfMarker_CB = function(xhr,objTBMap,marker_inf) {
	var content = xhr.responseText;
	if ((null != content) && ('' != content)) {
		marker_inf['wi_content']=content;
		objTBMap.openWI(marker_inf,marker_inf['wi_content']);
	}
}
btmapu_getAALength = function(assocArray) {
	var result=0;
	for (i in assocArray) {result++;}
	return result;
}
btmapu_showWaitInDiv = function(id_div,msg) {
	div_obj = document.getElementById(id_div);
	if (div_obj) {
		div_obj.innerHTML = "<span class='wait'></span><img src='ico_loading_blue.gif'/>";
	}
}


/* 
Fonction non utilisee : celle-ci pose un probleme sous IE6 pour le site bons plans
btmapu_unescapeHTML = function(content)
{

        // Tout ce qui est de la forme &#123;
        var replace = function($0, $1)
        {
                return unescape("%"+parseInt($1, 10).toString(16));
        };
        content = content.replace(new RegExp("&#([0-9]+);", "g"), replace);
        
        //content = this._lt(content);
        //content = this._gt(content);
        //content = this._amp(content);
        //content = this._nbsp(content);
        content = content.replace(/&quot;/g, "\"");
        
        content = content.replace(/&iexcl;/g, "¡");
        content = content.replace(/&cent;/g, "¢");
        content = content.replace(/&curren;/g, "¤");
        content = content.replace(/&yen;/g, "¥");
        content = content.replace(/&brvbar;/g, "¦");
        content = content.replace(/&sect;/g, "§");
        content = content.replace(/&uml;/g, "¨");
        content = content.replace(/&copy;/g, "©");
        content = content.replace(/&ordf;/g, "ª");
        content = content.replace(/&laquo;/g, "«");
        content = content.replace(/&not;/g, "¬");
        content = content.replace(/&shy;/g, "­");
        content = content.replace(/&reg;/g, "®");
        content = content.replace(/&macr;/g, "¯");

        content = content.replace(/&deg;/g, "°");
        content = content.replace(/&plusmn;/g, "±");
        content = content.replace(/&sup2;/g, "²");
        content = content.replace(/&sup3;/g, "³");
        content = content.replace(/&acute;/g, "´");
        content = content.replace(/&micro;/g, "µ");
        content = content.replace(/&para;/g, "¶");
        content = content.replace(/&middot;/g, "·");
        content = content.replace(/&cedil;/g, "¸");
        content = content.replace(/&sup1;/g, "¹");
        content = content.replace(/&ordm;/g, "º");
        content = content.replace(/&raquo;/g, "»");
        content = content.replace(/&frac14;/g, "¼");
        content = content.replace(/&frac12;/g, "½");
        content = content.replace(/&frac34;/g, "¾");
        content = content.replace(/&iquest;/g, "¿");
        
       // POSE des problemes sous IE6 depuis cette ligne
        content = content.replace(/&Agrave;/g, "À"); 
        content = content.replace(/&Aacute;/g, "Á"); 
        content = content.replace(/&Acirc;/g, "Â"); 
        content = content.replace(/&Atilde;/g, "Ã");
        content = content.replace(/&Auml;/g, "Ä");
        content = content.replace(/&Aring;/g, "Å");
        content = content.replace(/&AElig;/g, "Æ");
        content = content.replace(/&Ccedil;/g, "Ç");
        content = content.replace(/&Egrave;/g, "È");
        content = content.replace(/&Eacute;/g, "É");
        content = content.replace(/&Ecirc;/g, "Ê");
        content = content.replace(/&Euml;/g, "Ë");
        content = content.replace(/&Igrave;/g, "Ì");
        content = content.replace(/&Iacute;/g, "Í");
        content = content.replace(/&Icirc;/g, "Î");
        content = content.replace(/&Iuml;/g, "Ï");
       
        content = content.replace(/&ETH;/g, "Ð");
        content = content.replace(/&Ntilde;/g, "Ñ");
        content = content.replace(/&Ograve;/g, "Ò");
        content = content.replace(/&Oacute;/g, "Ó");
        content = content.replace(/&Ocirc;/g, "Ô");
        content = content.replace(/&Otilde;/g, "Õ");
        content = content.replace(/&Ouml;/g, "Ö");
        content = content.replace(/&times;/g, "×");
        content = content.replace(/&Oslash;/g, "Ø");
        content = content.replace(/&Ugrave;/g, "Ù");
        content = content.replace(/&Uacute;/g, "Ú");
        content = content.replace(/&Ucirc;/g, "Û");
        content = content.replace(/&Uuml;/g, "Ü");
        content = content.replace(/&Yacute;/g, "Ý");
        content = content.replace(/&THORN;/g, "Þ");
        content = content.replace(/&szlig;/g, "ß");
        
        content = content.replace(/&agrave;/g, "à");
        content = content.replace(/&aacute;/g, "á");
        content = content.replace(/&acirc;/g, "â");
        content = content.replace(/&atilde;/g, "ã");
        content = content.replace(/&auml;/g, "ä");
        content = content.replace(/&aring;/g, "å");
        content = content.replace(/&aelig;/g, "æ");
        content = content.replace(/&ccedil;/g, "ç");
        content = content.replace(/&egrave;/g, "è");
        content = content.replace(/&eacute;/g, "é");
        content = content.replace(/&ecirc;/g, "ê");
        content = content.replace(/&euml;/g, "ë");
        content = content.replace(/&igrave;/g, "ì");
        content = content.replace(/&iacute;/g, "í");
        content = content.replace(/&icirc;/g, "î");
        content = content.replace(/&iuml;/g, "ï");
        
        content = content.replace(/&eth;/g, "ð");
        content = content.replace(/&ntilde;/g, "ñ");
        content = content.replace(/&ograve;/g, "ò");
        content = content.replace(/&oacute;/g, "ó");
        content = content.replace(/&ocirc;/g, "ô");
        content = content.replace(/&otilde;/g, "õ");
        content = content.replace(/&ouml;/g, "ö");
        content = content.replace(/&divide;/g, "÷");
        content = content.replace(/&oslash;/g, "ø");
        content = content.replace(/&ugrave;/g, "ù");
        content = content.replace(/&uacute;/g, "ú");
        content = content.replace(/&ucirc;/g, "û");
        content = content.replace(/&uuml;/g, "ü");
        content = content.replace(/&yacute;/g, "ý");
        content = content.replace(/&thorn;/g, "þ");
        content = content.replace(/&yuml;/g, "ÿ");
        content = content.replace(/&euro;/g, "€"); 
        
        return content;
};
*/

//alert("fin btmap_lib");