
dlat=parseFloat(dlat);
dlng=parseFloat(dlng);
dzoom=parseInt(dzoom);
if(dzoom>10){dzoom=2;}
	  window.onload=Load_Map
	  function pyg_icon(type) {
		var color;
		if ((typeof(type)=="undefined") || (type==null)) { color = "red" } else { color = type }
		var icon = new GIcon();
		icon.image = "http://labs.google.com/ridefinder/images/mm_20_"+ color +".png"; //alert(icon.image);
		icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		icon.iconSize = new GSize(12, 20);
		icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);
		return icon;

	  }

	  	  function switchDisplay(n, force) {
		window.focus();
		if (document.all) {
			detail=eval("document.all."+ n + '');
		} else {
			detail=document.getElementById(n);
		}
		if (detail==null) return false;
		if (force!=null)  {
			detail.style.display=force;
		} else {
			if ((detail.style.display!="block") || (detail.style.display=="")) {
			   detail.style.display="block";
			 } else  {
			   detail.style.display="none";
			}
		}
	  }
	  function SetLatLng() {
		var lat = document.form2.lat.value;
		var lng = document.form2.lng.value;
		map.centerAtLatLng(new GPoint(lng, lat));
		document.location.href = "#top";
	  }

	  function Look_Marker() {
		var j=0;
		var searched = document.form3.nom.value;
		for (j=0; j < markers.length;j++ ) {
			var title=markers[j].getAttribute("title");
			if (title.toLowerCase()==searched.toLowerCase())  {
					 map.centerAndZoom(new GPoint(markers[j].getAttribute("lng"), markers[j].getAttribute("lat")),4);
					 map.setMapType(_SATELLITE_TYPE);
					 document.location.href="#top";
					 return true;
			}
		}
		alert(searched +" Not Found :-(");
	  }
	  function pyg_addNewPoint(lat, lng, title, text, type) {
		var point = new GPoint(lat, lng);
		var icon = pyg_icon(type);
		var marker = new GMarker(point, icon);
		if ( (type=="yellow") || (type=="red") ){
			title = "<a href='/'>"+ title +"</a>";
		}
		var content = '<div align="center"><strong>'+title +'</strong></div>' + '<hr width="100"/><div align="left" style="width: 20em">' + text +'</div>';
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(content);
		  });
		map.addOverlay(marker);
	  }

	  var icon = new GIcon();
	  icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
	  icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	  icon.iconSize = new GSize(12, 20);
	  icon.shadowSize = new GSize(22, 20);
	  icon.iconAnchor = new GPoint(6, 20);
	  icon.infoWindowAnchor = new GPoint(5, 1);

	  var map;

	  var dtypemap = "c";
	  //var dmaptype = "";
	  var markers;
	  var i=0;
	  var timeOut = 10;


	  function Load_Map() {
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
    	map.setCenter(new GLatLng(dlat, dlng), dzoom);
		map.setMapType(G_HYBRID_MAP);

		GEvent.addListener(map, "moveend", function() {
			var center = map.getCenterLatLng();
			var latLngStr = '(' + center.x + ', ' + center.y + ')';
			get_ll();
		});

		GEvent.addListener(map, 'click', function(overlay, point) {
		  if (overlay) {
		  } else if (point) {
			map.centerAtLatLng(point);
			document.form1.point.value = point;
		  }
		});

        var cells = document.getElementsByTagName("table");
        for (var i = 0; i < cells.length; i++) {
          if(cells[i].className=='tborder'){
           var R=cells[i].rows[0];
           var C=R.cells[0];
           if(C.className=='tcat'){
                eTITLE=C;
                sTITLE=C.innerHTML;
                R=cells[i].insertRow(1);
                C=R.insertCell(0);
                C.className="smallfont";
                C.innerHTML='Our divers are plotted as blue pins in the world map. <b>Hover</b> over any pin to see the userīs details (name, location,photo).';
                cells[i].deleteRow(2);

                break;
           }
           }
        }
        var divL0=document.getElementById("divAboveTheMap");
        var lgHT= '<h4 id="Legend" class="tborder"><center>Legend</center><table class="smallfont" width="100%" style="position:relative;top:-10px" cellpadding="0" cellspacing="0"><tr height="20px" style="height:20px">';
        for(li=0;li<TOTALGROUPS;li++){
            var li1=li+1;
            var T1=document.getElementById('listdata0'+li1);
            elementsinlayers[li]=T1.rows.length-1;
            lgHT+='<td width="20%" class="smallfont"><input type="checkbox"  id="ck'+li+'" onClick="showHideLayer('+li+')"/>'+
                    getPNG( 'markers/'+LEGENDMARKERS[li]+'.png')+LEGENDNAMES[li]+'<i>('+elementsinlayers[li]+')</i></td>';
            if(li%5==4){lgHT+='</tr><tr height="20px" style="height:20px">';}
        }
        divL0.innerHTML=lgHT+'</tr></table></h4>';

        divL0.style.display='block';
        var divL1 = document.createElement("div");
        divL1.id="legend1";
        document.getElementById("divLegend").appendChild(divL1);
        divL1.style.border = "0px solid #C00" ;
        divL1.style.top="-10px";
        divL1.innerHTML='<div class="smallfont" style="float:right">map redesign: <a href="mailto:marcelmateescu@yahoo.com" >Marcel Mateescu</a></div>';
        window.location.hash='Legend';
	  }

function showHideLayer(layer){
  if(plotted[layer]==0){
    plotted[layer]=1;
    var li1=layer+1;
    var lag=layer*1000;
    var frun="plotGrid2(document.getElementById('listdata0"+li1+"'),"+lag+",2,1,'markers/"+LEGENDMARKERS[layer]+".png','',1,0,1);eTITLE.innerHTML=sTITLE;";
    setTimeout(frun,100);
    return;
  }
  var stare='none';
  if(document.getElementById('ck'+layer).checked){stare='block';}
  for(i=1;i<=elementsinlayers[layer];i++){
    var indx=layer*1000+i;
    try{
        document.getElementById('divMMMarker'+indx).style.display=stare;
    }catch(e){
//      alert(e+indx);
    }
  }
}

function inside(mytitle,mytext,id,color,uid){
 var s= '';
 var destid=parseInt(id);
 if(id<1000){
    var  t=document.getElementById('listdata01');
    var R=t.rows[destid];
    var C=R.cells[0];
    var destin=parseInt(C.innerHTML);
   s = s + '<a href="http://www.rebreatherworld.com/destinations/'+destin+'.html" title="click to dive to this destination">';
 }
 s = s + '<center><font color='+color+'><b>'+mytitle+'</b></center><br>'+mytext+'</font>';
 if(id>=1000){
    s = s + '<br><center><img src="http://www.rebreatherworld.com/image.php?u='+uid+'"/></center>';
 }
 else {
   s = s + '</a>';
 }

 s = s + '<br><table border="0"><tr><td align="left" width="90%"><a align="right" href="javascript:zoomMeUp('+id+');"><i>ZOOM TO ME</i></a></td><td align="right"><a href="javascript:map.disableInfoWindow();map.enableInfoWindow();">[X]</a></td></tr></table>';
 return s;
}
function MMMmouseover(callerID){
    var K=allMMMmarkers[callerID].intCOORDS;
    if(theHint!=false){
        map.removeOverlay(theHint);
    }
    theHint = new MMMhint(K);
    map.addOverlay(theHint);
    document.getElementById('MMMhint').style.display = 'block';
    document.getElementById('MMMhint').style.cssText+="color:#FFF;background-color:#00D;filter:alpha(opacity=75);-moz-opacity:.75;opacity:.75";
    var  indx = callerID % 1000;
    var  layer= parseInt(callerID / 1000);
    var  t=document.getElementById('listdata0'+parseInt(layer+1));
    var R=t.rows[indx];
    var C=R.cells[3];
    var mytitle=unescape(C.innerHTML);
        C=R.cells[4];
    var mytext=unescape(C.innerHTML);
        C=R.cells[0];
    var uid=C.innerHTML;

    document.getElementById('MMMhint').innerHTML=inside(mytitle,mytext,callerID,'#FFFFFF',uid);
}

function MMMmouseout(callerID){
  if(theHint){
	document.getElementById('MMMhint').style.display = 'none';
	map.removeOverlay(theHint);
  }
  theHint=false;
}

function MMMmouseclick(callerID){
    var  indx = callerID % 1000;
    var  layer= parseInt(callerID / 1000);
    var  t=document.getElementById('listdata0'+parseInt(layer+1));
    var R=t.rows[indx];
    var C=R.cells[3];
    var mytitle=unescape(C.innerHTML);
        C=R.cells[4];
    var mytext=unescape(C.innerHTML);
        C=R.cells[0];
    var uid=C.innerHTML;
	map.openInfoWindowHtml (allMMMmarkers[callerID].intCOORDS,inside(mytitle,mytext,callerID,'#440000',uid));
}

function zoomMeUp(callerId){
    var K=allMMMmarkers[callerId].intCOORDS;
    map.setCenter(K,8);
}
	function get_ll() {
		var zoom = map.getZoomLevel();
		var loc = map.getCenterLatLng();
		var mylink = "?lat="+ loc.y + "&lng=" + loc.x +"&zoom=" + zoom + "";
		//alert("Vous pourrez copier/coller le lien apparaissant dans votre barre d'adresse "+mylink);
		document.getElementById('mylinkv').value="VBGooglemap.php"+mylink;
		//document.location.href=mylink ;
		document.getElementById('latbox').value= loc.y;
		document.getElementById('lngbox').value= loc.x;
		document.getElementById('zoombox').value= zoom;
	  }
	  	  function switchDisplay(n, force) {
		window.focus();
		if (document.all) {
			detail=eval("document.all."+ n + '');
		} else {
			detail=document.getElementById(n);
		}
		if (detail==null) return false;
		if (force!=null)  {
			detail.style.display=force;
		} else {
			if ((detail.style.display!="block") || (detail.style.display=="")) {
			   detail.style.display="block";
			 } else  {
			   detail.style.display="none";
			}
		}
	  }
	  function SetLatLng() {
		var lat = document.form2.lat.value;
		var lng = document.form2.lng.value;
		map.centerAtLatLng(new GPoint(lng, lat));
		document.location.href = "#top";
	  }

	  function Look_Marker() {
		var j=0;
		var searched = document.form3.nom.value;
		for (j=0; j < markers.length;j++ ) {
			var title=markers[j].getAttribute("title");
			if (title.toLowerCase()==searched.toLowerCase())  {
					 map.centerAndZoom(new GPoint(markers[j].getAttribute("lng"), markers[j].getAttribute("lat")),4);
					 map.setMapType(_SATELLITE_TYPE);
					 document.location.href="#top";
					 return true;
			}
		}
		alert(searched +" Not Found :-(");
	  }

	  function mapOne() {
		//document.getElementById('counter').innerHTML = i + " / " + markers.length;
		if ( i < markers.length ) {
		  pyg_addNewPoint(parseFloat(markers[i].getAttribute("lng")), parseFloat(markers[i].getAttribute("lat")), markers[i].getAttribute("title"),  markers[i].getAttribute("text"), markers[i].getAttribute("type"));
		  i++;
		  window.setTimeout(mapOne,timeOut);
		}
		//else {
		// document.getElementById('loading').style.visibility='hidden';
		//}
	  }

