    //<![CDATA[
    window.onload = onPageLoad;
    //window.onunload = GUnload();  This produces a weird bug in IE 
	var map;
	var c = "";
	var lstart = 0;
	var globgpid = "";
	var gpmarkersonly = "";
	var active_country ="";
	var debug = false;

/**************** Map initialisation**************/
function onPageLoad() 
	{
	    if (GBrowserIsCompatible()) 
	    {
	    	opal = new OpenAtlas();
	    	
	    	//ajax gets connected users list
	        //v2Connected();
	        
	    	var zoominit = 2;
	    	if(fullscreen == true)
	    	{
	    	    zoominit = 2;  
	        	if (window.attachEvent) 
	                window.attachEvent("onresize", function() {this.opal.map.onResize()} );
	        	else 
	        	    window.addEventListener("resize", function() {this.opal.map.onResize()} , false);
	        }
	        
	        opal.map.setCenter(new GLatLng(0, 0), zoominit);
	        
	        AddMapCLickShowLatLong(opal.map);
	        
	        getIcons();
	        if(mapid!=0)
	        	AjaxSetUpCustomMap(mapid);
	        else 
	        	getMarkerByType("",true); 
	        
	        if(globlat!=0 && globlon!=0)
	        	pointAndZoom ( globlat+","+globlon+" is here !!" , globlon, globlat, globzoom );
	    }
	}


function buildQuery(xtype)
	{
		//strreq is the url config passed to data.php to generate all the select markers
		//url passed on 
	   var strreq = "?";
	   var searchcrum = "";
	   if(user){
	       strreq += "user="+user+"&";
	       searchcrum += " Content of Member : "+user;
	   }
	   	if(globtype){
		   strreq += "type="+globtype+"&";
	   	   //if(globtype =="lifepoint" || globtype == "travel")
		   	//	strreq += "gpstruct=linear&gtype=lines&"; 
	   	   searchcrum += (user) ? ", ":"";
	   	   searchcrum += " Content Type : "+globtype;
	   	}
		if(globtime){
			strreq += "time="+globtime+"&";
			searchcrum += (user || globtype) ? ", ":"";
			searchcrum += " Time Line : "+globtime;
		}
		if(globid)
			strreq += "id="+globid+"&";
		if(globgpid){
			strreq += "gpid="+globgpid+"&";
			globgpid = "";
		}
		if(q){
			strreq += "q="+q+"&";
			q="";
		}
		
		if(xtype == "custom"){
			strreq = "?map=custom&type=custom&mapid="+mapid+"&";
			//xtype = "";
		}	
		/*if(opal.mapT.length==0)
			strreq += "map=&";*/
		
		//Shows and allows administration of all points over custom maps
		if(xtype == "admin_custom_map_point"){
			strreq = "?pointadmin=add2custom_map&";
			//xtype = "";
		}	
		
		strreq += page ? "page="+page+"&" : ""; 
		strreq += data ? "data="+data+"&" : "";
		
		return [strreq,searchcrum];
	}

function getMarkerByType(xtype,clear)
	{
		document.getElementById("loadmsgdiv").style.display = "block";
		document.getElementById("loader").style.display = "block";
	   if(clear)
	   {
	   		
	   		//opal.empty(); provoques imagess memory problems??
	   		
	   		//bizarely these objects are not cleaned up in the prototype function
	   		opal.groupT = new Array();
	   		opal.userT = new Array();
	   		opal.map.clearOverlays();
	   }

	    var strreq = buildQuery(xtype);
		opal.searchcrum = strreq[1];
		
		var request = GXmlHttp.create();
		//alert(strreq[0]);
		var dataPath = (globkml)? cpath+"users/"+user+"/file/"+globkml+".xml"
								: cpath+"modules/GMaps/Data/data.php"+strreq[0];
	   //alert(dataPath);
	   request.open("GET", dataPath, true);
	   request.onreadystatechange = function() 
	   {
		   var groups = null;
		   if (request.readyState == 4) 
		   {
		      var xmlDoc = request.responseXML;
		      if(xmlDoc.documentElement.firstChild.nodeName == "markers")
		      	{
		      		//alert((new XMLSerializer()).serializeToString(xmlDoc));
			      	getData(xmlDoc); 	
					opal.Draw();
				}
			  else {
			     	drawXMLData(xmlDoc); 
			  }
			  document.getElementById("loadmsgdiv").style.display = "none";
			  document.getElementById("loader").style.display = "none";
	    	}
	   }
	   request.send(null);   
	   globkml="";
	}

//retreives Markers per type and time,clear cleans or not existing icons
function getMarkerby(id,type,time,clear)
	{
		document.getElementById("loadmsgdiv").style.display = "block";
		document.getElementById("loader").style.display = "block";
		globid = id ? id : "";
		globtype = type ? type : "";
		globtime = time ? time : "";
		
		//draws icons on the map according to type and time
		getMarkerByType('',clear);
		if(globtype)
		{
			hideDiv(['submaptxt','infoviewer']);
			lstart = -10;
			fillSearchTab();
		}
	}
	


//When a search is made the header of each point is listed below the map
function fillSearchTab(dir)
	{
		lstart = (dir<0) ? lstart-10 : lstart+10;
		//get the HTML list according to type and time
		var htmlTabList = ajaxGetHtmlTabList(globtype , globtime, user, page, lstart);
		//replace it in the document 
		document.getElementById("ajaxListWrapper").innerHTML = htmlTabList;
	}

//a multi criteria search values come separated by a space
//we reassemble them sepearted by "," and launch getMarker
function multiSearch(qstr)
{	
	data ="multi";
	// this will get rid of leading spaces 
    while (qstr.substring(0,1) == ' ') 
        qstr = qstr.substring(1, qstr.length);

    // this will get rid of trailing spaces 
    while (qstr.substring(qstr.length-1,qstr.length) == ' ')
        qstr = qstr.substring(0, qstr.length-1);
	
	qT = qstr.split(" ");
	for(ix=0 ; ix < qT.length ; ix++){
		sep = ix!=0 ? ",":"";
		if(qT[ix]!="" || qT[ix]!=" ")
			q = q+sep+qT[ix];
	}
	//draws icons on the map according to type and time
	getMarkerByType('',true);
}
/*
Graphic Elements Declarations
*/
function getIcons()
	{
	   var request = GXmlHttp.create();
	   request.open("GET", cpath+"modules/GMaps/Data/template/icons.php", true);
	   request.onreadystatechange = function() 
	   {
		   if (request.readyState == 4) {
		      buildIcons(request.responseXML);
		   }
	   }
	   request.send(null);  
	}

function buildIcons(iconXML)
	{
		var icons = iconXML.getElementsByTagName("icon");
		for (var ix = 0; ix < icons.length; ix++) 
		{
			var iconNode = icons[ix];
			
			var srckey = iconNode.getAttribute("srckey");
			//we dont build identical icons theyare referenced in the themeT by their srckey name iconT[srckey]
			if(iconT[srckey.substring(0,srckey.indexOf("."))]==null)
			{
				var iconimg = new Image();
			    iconimg.src = iconNode.getAttribute("src");
			    var shadowimg = new Image();
			    shadowimg.src = iconNode.getAttribute("shadowsrc");
			    //var hoverimg = new Image();
			    //hoverimg.src = iconNode.getAttribute("hoversrc"); 
			    
			    //build Gicon
			    var icon = new GIcon();
			    icon.image = iconimg.src;
			    icon.shadow = shadowimg.src;
			    var size = iconNode.getAttribute("size")
			    icon.iconSize = new GSize(size.substring(0,size.indexOf(",")), size.substring(size.indexOf(",")+1));
			    var shadowsize = iconNode.getAttribute("shadowsize")
			    icon.shadowSize = new GSize(shadowsize.substring(0,shadowsize.indexOf(",")), shadowsize.substring(shadowsize.indexOf(",")+1));
			    var anchor = iconNode.getAttribute("anchor")
			    icon.iconAnchor = new GPoint(anchor.substring(0,anchor.indexOf(",")), anchor.substring(anchor.indexOf(",")+1));
				var infoanchor = iconNode.getAttribute("infoanchor")
			    icon.infoWindowAnchor = new GPoint(infoanchor.substring(0,infoanchor.indexOf(",")), infoanchor.substring(infoanchor.indexOf(",")+1));
			    iconT[srckey.substring(0,srckey.indexOf("."))] = icon;
			}
			var themeName = iconNode.getAttribute("name");
			var themeFather = iconNode.getAttribute("father");
			if(themeFather!="icon"){
				themeT[themeFather+"_"+themeName] = srckey.substring(0,srckey.indexOf("."));
				if(!themeClassificationT[themeFather])
					themeClassificationT[themeFather] = [];
				themeClassificationT[themeFather].push(themeName);
			}
		}
		if(debug)alert("iconT : "+ObjToStringClean(iconT));
		if(debug)alert("themeT : "+ObjToStringClean(themeT));
		if(debug)alert("themeClassT : "+ObjToStringClean(themeClassificationT));
		
	}

/*
Adds Zoom on click Event when a marker is clicked, also SHow info Window
*/
function AddMarkerClickListner(marker)
	{
	    GEvent.addListener(marker, "click", function() 
	    {
	        var thisPoint = marker.getPoint();
	        if(clickedMarker == 1)
	        {
	            opal.map.centerAndZoom(new GPoint(thisPoint.x, thisPoint.y), 10);
	            marker.showDetailWin();
	        }
	        else
	        { 
	            opal.map.centerAndZoom(new GPoint(thisPoint.x, thisPoint.y), 15);
	            marker.closeDetailWin();
	        }
	    });
	}

function zoomIn(lon,lat,zoom,type)
{
	opal.map.setCenter(new GLatLng(lat,lon), zoom,type);
}

function openCustomMap(openmapid,lat,lng,maxlat,maxlng,zoom,path,type,strXY)
{
	mapid = openmapid;
	for(var ix = 0 ; ix < opal.mapT.length ; ix++){
		opal.map.removeOverlay(opal.mapT[ix].overlay);
	}
	globzoom = zoom;
	globlat = maxlat + (lat-maxlat)/2;
	globlon = maxlng + (lng-maxlng)/2;
	
	//builb MAp Naming delimitations
	var listxyT_dirty = strXY.split(',');
	globlistxyT = new Array();
	var ctlvls=0;
	var xyix = 0;
	while(xyix < listxyT_dirty.length)
	{
		globlistxyT[ctlvls] = new Array(5);
		for(var ix = 0 ; ix < 5 ; ix++)
		{
			globlistxyT[ctlvls][ix] = listxyT_dirty[xyix];
			xyix++;
		}
		ctlvls++;
	}
	
	//tilepath is a global variable containing the path to the lat / lng relative Tiles
	tilepath = path; 
	
	opal.map.setCenter(new GLatLng(globlat,globlon), zoom,type);
}

/*
*Puts a Marker on the requested point and zooms to it on the request zoom
*/
function pointAndZoom ( name , lon, lat, zoom )
	{
	    var point = new GLatLng(lat,lon);
	    opal.map.setCenter ( point , zoom );
	    opal.marker.setPoint(point);
	    opal.marker.setTooltip( name );
	    SwapGeoLabel(point);
	}
	
function pinpoint ( name , lon, lat,zoom )
	{
		var point = new GLatLng(lat,lon);
	    opal.marker.setTooltip( name );
	    if(opal.marker.onMap == false){
	    	opal.map.addOverlay(opal.marker);
	    	opal.marker.onMap = true;	
	    }
	    opal.marker.setPoint(point);
	    SwapGeoLabel(point);
	}

/*
Adds on click shows Latitude Longitude
*/
function AddMapCLickShowLatLong (map)
	{
	    GEvent.addListener(map, "click", function(overlay, point)
	    {//alert(pdMarkerOpenList.length);
	    	if(pdMarkerExtList.length==0)
	    	{
		        this.panTo(point);
		        SwapGeoLabel(point);
		        if(newMarker)
		        	newMarker.setPoint(point);
		     }
		     //alert(newMarker.getPoint().y+"/"+newMarker.getPoint().x);
	    });
	    
	    //show hide custom map bounds
	    GEvent.addListener(map, "maptypechanged", function(overlay, point)
	    {
	    	if (map.getCurrentMapType().getName() == "CustomLayer"){
	    		onCustomLayer = true;
	    		//DrawMapBounds(true);
	    		if(!standalone){
		    		data = "multi";
		    		getMarkerby("","maps","",false);
	    		}
	    	}
	    	else {
	    		if(onCustomLayer)
	    			getMarkerby("","","",true);
	    		onCustomLayer = false;
	    		//DrawMapBounds(false);
	    	}
	    	
	    });

	   /*
	   could be used to open custom maps automatically but creates ergonomic pb
	   such as loops openCustommaps provocs a move map provoquing an endless loop
	    GEvent.addListener(map, "moveend", function(overlay, point)
	    {
	    	if (map.getCurrentMapType().getName() == "CustomLayer")
	    	{
	    		var resT = inCustomMapBounds();
	    		alert(resT.length);
	    		if( resT.length > 0 ){
	    			for (var ix = 0; ix < resT.length; ix++) 
					{
						openCustomMap(opal.mapT[resT[ix]].id, 
									opal.mapT[resT[ix]].lat, 
									opal.mapT[resT[ix]].long, 
									opal.mapT[resT[ix]].maxlat, 
									opal.mapT[resT[ix]].maxlong, 
									opal.mapT[resT[ix]].zoom, 
									opal.mapT[resT[ix]].path, 
									opal.map.getMapTypes()[2], 
									opal.mapT[resT[ix]].listxy);
					}
				}
	    	}
	    });*/
	}
	/*
function inCustomMapBounds()
	{
		var CustomMapT = new Array();
		for (var ix = 0; ix < opal.mapT.length; ix++) 
		{
			if(opal.map.getZoom() >= opal.mapT[ix].zoom && opal.map.getZoom() <= opal.mapT[ix].maxzoom)
			{
	    		var bounds = opal.map.getBounds();
				var mapBounds = new GBounds([opal.mapT[ix].lat,
										opal.mapT[ix].lon,
										opal.mapT[ix].maxlat,
										opal.mapT[ix].maxlon]);
				
				if(GBounds.intersection(bounds,mapBounds)!=null)
					CustomMapT.push(ix);
			}
		}
		return CustomMapT;
	}*/
/*
Swaps the HTML content of the Label under the map 
*/
function SwapGeoLabel(point)
	{
		var request = GXmlHttp.create();			
	   request.open("GET", cpath+"scripts/DB/getCountry.php?lat="+point.y+"&lon="+point.x, true);
	   request.onreadystatechange = function() 
	   {
		   if (request.readyState == 4) 
		   {
		      active_country = request.responseText;
		           	
		      msg = "Latitude: "+point.y+" Longitude: "+point.x+" Zoom:"+opal.map.getZoom()+", Country : "+active_country;
			  document.getElementById("clickpoint").innerHTML = msg;
		    }
	   }
	   request.send(null);  
	}
	
//]]>
