/*
	ClusterMarker Version 1.3.2
	
	A marker manager for the Google Maps API
	http://googlemapsapi.martinpearman.co.uk/clustermarker
	
	Copyright Martin Pearman 2008
	Last updated 29th September 2008

	This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

	You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.
	
*/

function ClusterMarker($map, $options){
	this._map=$map;
	this._mapMarkers=[];
	this._iconBounds=[];
	this._clusterMarkers=[];
	this._eventListeners=[];
	if(typeof($options)==='undefined'){
		$options={};
	}
	this.borderPadding=($options.borderPadding)?$options.borderPadding:256;
	this.clusteringEnabled=($options.clusteringEnabled===false)?false:true;
	if($options.clusterMarkerClick){
		this.clusterMarkerClick=$options.clusterMarkerClick;
	}
	if($options.clusterMarkerIcon){
		this.clusterMarkerIcon=$options.clusterMarkerIcon;
	}else{
		this.clusterMarkerIcon=new GIcon();
		this.clusterMarkerIcon.image='./gifs/GMap_multi.png';
		this.clusterMarkerIcon.iconSize=new GSize(18, 32);
		this.clusterMarkerIcon.iconAnchor=new GPoint(9, 32);
		this.clusterMarkerIcon.infoWindowAnchor=new GPoint(9, 32);
		this.clusterMarkerIcon.shadow='./gifs/GMap_shadow.png';
		this.clusterMarkerIcon.shadowSize=new GSize(35, 32);
	}
	this.clusterMarkerTitle=($options.clusterMarkerTitle)?$options.clusterMarkerTitle:'Klicken zum zoomen: %count Marker';
	if($options.fitMapMaxZoom){
		this.fitMapMaxZoom=$options.fitMapMaxZoom;
	}
	this.intersectPadding=($options.intersectPadding)?$options.intersectPadding:0;
	if($options.markers){
		this.addMarkers($options.markers);
	}
	GEvent.bind(this._map, 'moveend', this, this._moveEnd);
	GEvent.bind(this._map, 'zoomend', this, this._zoomEnd);
	GEvent.bind(this._map, 'maptypechanged', this, this._mapTypeChanged);
}

ClusterMarker.prototype.addMarkers=function($markers){
	var i;
	if(!$markers[0]){
		//	assume $markers is an associative array and convert to a numerically indexed array
		var $numArray=[];
		for(i in $markers){
			$numArray.push($markers[i]);
		}
		$markers=$numArray;
	}
	for(i=$markers.length-1; i>=0; i--){
		$markers[i]._isVisible=false;
		$markers[i]._isActive=false;
		$markers[i]._makeVisible=false;
	}
	this._mapMarkers=this._mapMarkers.concat($markers);
};

ClusterMarker.prototype._clusterMarker=function($clusterGroupIndexes){
	function $newClusterMarker($location, $icon, $title){
		return new GMarker($location, {icon:$icon, title:$title});
	}
	var $clusterGroupBounds=new GLatLngBounds(), i, $clusterMarker, $clusteredMarkers=[], $marker, $this=this, $mapMarkers=this._mapMarkers;
	for(i=$clusterGroupIndexes.length-1; i>=0; i--){
		$marker=$mapMarkers[$clusterGroupIndexes[i]];
		$marker.index=$clusterGroupIndexes[i];
		$clusterGroupBounds.extend($marker.getLatLng());
		$clusteredMarkers.push($marker);
	}
	$clusterMarker=$newClusterMarker($clusterGroupBounds.getCenter(), this.clusterMarkerIcon, this.clusterMarkerTitle.replace(/%count/gi, $clusterGroupIndexes.length));
	$clusterMarker.clusterGroupBounds=$clusterGroupBounds;	//	only req'd for default cluster marker click action
	this._eventListeners.push(GEvent.addListener($clusterMarker, 'click', function(){
		$this.clusterMarkerClick({clusterMarker:$clusterMarker, clusteredMarkers:$clusteredMarkers });
	}));
	$clusterMarker._childIndexes=$clusterGroupIndexes;
	for(i=$clusterGroupIndexes.length-1; i>=0; i--){
		$mapMarkers[$clusterGroupIndexes[i]]._parentCluster=$clusterMarker;
	}
	return $clusterMarker;
};

ClusterMarker.prototype.clusterMarkerClick=function($args){
	this._map.setCenter($args.clusterMarker.getLatLng(), this._map.getBoundsZoomLevel($args.clusterMarker.clusterGroupBounds));
};

ClusterMarker.prototype._filterActiveMapMarkers=function(){
	var $borderPadding=this.borderPadding, $mapZoomLevel=this._map.getZoom(), $mapProjection=this._map.getCurrentMapType().getProjection(), $mapPointSw, $activeAreaPointSw, $activeAreaLatLngSw, $mapPointNe, $activeAreaPointNe, $activeAreaLatLngNe, $activeAreaBounds=this._map.getBounds(), i, $marker, $uncachedIconBoundsIndexes=[], $oldState, $mapMarkers=this._mapMarkers, $iconBounds=this._iconBounds;
	if($borderPadding){
		$mapPointSw=$mapProjection.fromLatLngToPixel($activeAreaBounds.getSouthWest(), $mapZoomLevel);
		$activeAreaPointSw=new GPoint($mapPointSw.x-$borderPadding, $mapPointSw.y+$borderPadding);
		$activeAreaLatLngSw=$mapProjection.fromPixelToLatLng($activeAreaPointSw, $mapZoomLevel);
		$mapPointNe=$mapProjection.fromLatLngToPixel($activeAreaBounds.getNorthEast(), $mapZoomLevel);
		$activeAreaPointNe=new GPoint($mapPointNe.x+$borderPadding, $mapPointNe.y-$borderPadding);
		$activeAreaLatLngNe=$mapProjection.fromPixelToLatLng($activeAreaPointNe, $mapZoomLevel);
		$activeAreaBounds.extend($activeAreaLatLngSw);
		$activeAreaBounds.extend($activeAreaLatLngNe);
	}
	this._activeMarkersChanged=false;
	if(typeof($iconBounds[$mapZoomLevel])==='undefined'){
		//	no iconBounds cached for this zoom level
		//	no need to check for existence of individual iconBounds elements
		this._iconBounds[$mapZoomLevel]=[];
		this._activeMarkersChanged=true;	//	force refresh(true) as zoomed to uncached zoom level
		for(i=$mapMarkers.length-1; i>=0; i--){
			$marker=$mapMarkers[i];
			$marker._isActive=$activeAreaBounds.containsLatLng($marker.getLatLng())?true:false;
			$marker._makeVisible=$marker._isActive;
			if($marker._isActive){
				$uncachedIconBoundsIndexes.push(i);
			}
		}
	}else{
		//	icondBounds array exists for this zoom level
		//	check for existence of individual iconBounds elements
		for(i=$mapMarkers.length-1; i>=0; i--){
			$marker=$mapMarkers[i];
			$oldState=$marker._isActive;
			$marker._isActive=$activeAreaBounds.containsLatLng($marker.getLatLng())?true:false;
			$marker._makeVisible=$marker._isActive;
			if(!this._activeMarkersChanged && $oldState!==$marker._isActive){
				this._activeMarkersChanged=true;
			}
			if($marker._isActive && typeof($iconBounds[$mapZoomLevel][i])==='undefined'){
				$uncachedIconBoundsIndexes.push(i);
			}
		}
	}
	return $uncachedIconBoundsIndexes;
};

ClusterMarker.prototype._filterIntersectingMapMarkers=function(){
	var $clusterGroup, i, j, $mapZoomLevel=this._map.getZoom(), $mapMarkers=this._mapMarkers, $iconBounds=this._iconBounds;
	for(i=$mapMarkers.length-1; i>0; i--)
	{
		if($mapMarkers[i]._makeVisible){
			$clusterGroup=[];
			for(j=i-1; j>=0; j--){
				if($mapMarkers[j]._makeVisible && $iconBounds[$mapZoomLevel][i].intersects($iconBounds[$mapZoomLevel][j])){
					$clusterGroup.push(j);
				}
			}
			if($clusterGroup.length!==0){
				$clusterGroup.push(i);
				for(j=$clusterGroup.length-1; j>=0; j--){
					$mapMarkers[$clusterGroup[j]]._makeVisible=false;
				}
				this._clusterMarkers.push(this._clusterMarker($clusterGroup));
			}
		}
	}
};

ClusterMarker.prototype.fitMapToMarkers=function(){
	var $mapMarkers=this._mapMarkers, $markersBounds=new GLatLngBounds(), i;
	for(i=$mapMarkers.length-1; i>=0; i--){
		$markersBounds.extend($mapMarkers[i].getLatLng());
	}
	var $fitMapToMarkersZoom=this._map.getBoundsZoomLevel($markersBounds);
		
	if(this.fitMapMaxZoom && $fitMapToMarkersZoom>this.fitMapMaxZoom){
		$fitMapToMarkersZoom=this.fitMapMaxZoom;
	}
	this._map.setCenter($markersBounds.getCenter(), $fitMapToMarkersZoom-1);
	this.refresh();
};

ClusterMarker.prototype._mapTypeChanged=function(){
	this.refresh(true);
};

ClusterMarker.prototype._moveEnd=function(){
	if(!this._cancelMoveEnd){
		this.refresh();
	}else{
		this._cancelMoveEnd=false;
	}
};

ClusterMarker.prototype._preCacheIconBounds=function($indexes, $mapZoomLevel){
	var $mapProjection=this._map.getCurrentMapType().getProjection(), i, $marker, $iconSize, $iconAnchorPoint, $iconAnchorPointOffset, $iconBoundsPointSw, $iconBoundsPointNe, $iconBoundsLatLngSw, $iconBoundsLatLngNe, $intersectPadding=this.intersectPadding, $mapMarkers=this._mapMarkers;
	for(i=$indexes.length-1; i>=0; i--){
		$marker=$mapMarkers[$indexes[i]];
		$iconSize=$marker.getIcon().iconSize;
		$iconAnchorPoint=$mapProjection.fromLatLngToPixel($marker.getLatLng(), $mapZoomLevel);
		$iconAnchorPointOffset=$marker.getIcon().iconAnchor;
		$iconBoundsPointSw=new GPoint($iconAnchorPoint.x-$iconAnchorPointOffset.x-$intersectPadding, $iconAnchorPoint.y-$iconAnchorPointOffset.y+$iconSize.height+$intersectPadding);
		$iconBoundsPointNe=new GPoint($iconAnchorPoint.x-$iconAnchorPointOffset.x+$iconSize.width+$intersectPadding, $iconAnchorPoint.y-$iconAnchorPointOffset.y-$intersectPadding);
		$iconBoundsLatLngSw=$mapProjection.fromPixelToLatLng($iconBoundsPointSw, $mapZoomLevel);
		$iconBoundsLatLngNe=$mapProjection.fromPixelToLatLng($iconBoundsPointNe, $mapZoomLevel);
		this._iconBounds[$mapZoomLevel][$indexes[i]]=new GLatLngBounds($iconBoundsLatLngSw, $iconBoundsLatLngNe);
	}
};

ClusterMarker.prototype.refresh=function($forceFullRefresh){
	var i, $marker, $zoomLevel=this._map.getZoom(), $uncachedIconBoundsIndexes=this._filterActiveMapMarkers();
	if(this._activeMarkersChanged || $forceFullRefresh){
		this._removeClusterMarkers();
		if(this.clusteringEnabled && $zoomLevel<this._map.getCurrentMapType().getMaximumResolution()){
			if($uncachedIconBoundsIndexes.length>0){
				this._preCacheIconBounds($uncachedIconBoundsIndexes, $zoomLevel);
			}
			this._filterIntersectingMapMarkers();
		}
		for(i=this._clusterMarkers.length-1; i>=0; i--){
			this._map.addOverlay(this._clusterMarkers[i]);
		}
		for(i=this._mapMarkers.length-1; i>=0; i--){
			$marker=this._mapMarkers[i];
			if(!$marker._isVisible && $marker._makeVisible){
				this._map.addOverlay($marker);
				$marker._isVisible=true;
			}
			if($marker._isVisible && !$marker._makeVisible){
				this._map.removeOverlay($marker);
				$marker._isVisible=false;
			}
		}
	}
};

ClusterMarker.prototype._removeClusterMarkers=function(){
	var i, j, $map=this._map, $eventListeners=this._eventListeners, $clusterMarkers=this._clusterMarkers, $childIndexes, $mapMarkers=this._mapMarkers;
	for(i=$clusterMarkers.length-1; i>=0; i--){
		$childIndexes=$clusterMarkers[i]._childIndexes;
		for(j=$childIndexes.length-1; j>=0; j--){
			delete $mapMarkers[$childIndexes[j]]._parentCluster;
		}
		$map.removeOverlay($clusterMarkers[i]);
	}
	for(i=$eventListeners.length-1; i>=0; i--){
		GEvent.removeListener($eventListeners[i]);
	}
	this._clusterMarkers=[];
	this._eventListeners=[];
};

ClusterMarker.prototype.removeMarkers=function(){
	var i, $mapMarkers=this._mapMarkers, $map=this._map;
	for(i=$mapMarkers.length-1; i>=0; i--){
		if($mapMarkers[i]._isVisible){
			$map.removeOverlay($mapMarkers[i]);
		}
		delete $mapMarkers[i]._isVisible;
		delete $mapMarkers[i]._isActive;
		delete $mapMarkers[i]._makeVisible;
	}
	this._removeClusterMarkers();
	this._mapMarkers=[];
	this._iconBounds=[];
};

ClusterMarker.prototype.triggerClick=function($index){
	var $marker=this._mapMarkers[$index];
	$mapMaxZoomLevel=this._map.getCurrentMapType().getMaximumResolution();
	if($mapMaxZoomLevel>17)
		$mapMaxZoomLevel=17;
	
	this._map.setCenter($marker.getLatLng(),$mapMaxZoomLevel);
	this._map.closeInfoWindow();
	GEvent.trigger($marker, 'click');
	return;
	
	if($marker._isVisible){
		//	$marker is visible
		GEvent.trigger($marker, 'click');
	}
	else if($marker._isActive){
		//	$marker is clustered
		var $clusteredMarkersIndexes=$marker._parentCluster._childIndexes, $intersectDetected=true, $uncachedIconBoundsIndexes, i, $mapZoomLevel=this._map.getZoom(), $clusteredMarkerIndex, $iconBounds=this._iconBounds, $mapMaxZoomLevel=this._map.getCurrentMapType().getMaximumResolution();

		while($intersectDetected && ($mapZoomLevel<$mapMaxZoomLevel)){
			$intersectDetected=false;
			$mapZoomLevel++;
			if(typeof($iconBounds[$mapZoomLevel])==='undefined'){
				//	no iconBounds cached for this zoom level
				//	no need to check for existence of individual iconBounds elements
				$iconBounds[$mapZoomLevel]=[];
				// need to create cache for all clustered markers at $mapZoomLevel
				this._preCacheIconBounds($clusteredMarkersIndexes, $mapZoomLevel);
			}else{
				//	iconBounds array exists for this zoom level
				//	check for existence of individual iconBounds elements
				$uncachedIconBoundsIndexes=[];
				for(i=$clusteredMarkersIndexes.length-1; i>=0; i--){
					if(typeof($iconBounds[$mapZoomLevel][$clusteredMarkersIndexes[i]])==='undefined'){
						$uncachedIconBoundsIndexes.push($clusteredMarkersIndexes[i]);
					}
				}
				if($uncachedIconBoundsIndexes.length>=1){
					this._preCacheIconBounds($uncachedIconBoundsIndexes, $mapZoomLevel);
				}
			}
			for(i=$clusteredMarkersIndexes.length-1; i>=0; i--){
				$clusteredMarkerIndex=$clusteredMarkersIndexes[i];
				if($clusteredMarkerIndex!==$index && $iconBounds[$mapZoomLevel][$clusteredMarkerIndex].intersects($iconBounds[$mapZoomLevel][$index])){	
					$intersectDetected=true;
					break;
				}
			}
			
		};

		
		this._map.setCenter($marker.getLatLng(), $mapZoomLevel);
		this.triggerClick($index);
	}
	else{
		// $marker is not within active area (map bounds + border padding)
		this._map.setCenter($marker.getLatLng(),16);
		this.triggerClick($index);
	}
};

ClusterMarker.prototype._zoomEnd=function(){
	this._cancelMoveEnd=true;
	this.refresh(true);
};

/*	Google Maps API HtmlControl v1.1.2
	based on code posted on Google Maps API discussion group
	last updated/modified by Martin Pearman 20th August 2008
	
	http://googlemapsapi.martinpearman.co.uk/htmlcontrol
	
	This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

	You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

function HtmlControl(html, options){
	this.html=html;
	this.isVisible=true;
	this.isPrintable=false;	
	this.isSelectable=false;
	if(options){
		this.isVisible=(options.visible===false)?false:true;
		this.isPrintable=(options.printable===true)?true:false;
		this.isSelectable=(options.selectable===true)?true:false;
	}
}

HtmlControl.prototype=new GControl();

HtmlControl.prototype.initialize=function(map){
	this.div=document.createElement('div');
	this.div.innerHTML=this.html;
	this.setVisible(this.isVisible);
	map.getContainer().appendChild(this.div);
	return this.div;
};

HtmlControl.prototype.getDefaultPosition=function(){
	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7,7));
};

HtmlControl.prototype.selectable=function(){
	return this.isSelectable;
};

HtmlControl.prototype.printable=function(){
	return this.isPrintable;
};

HtmlControl.prototype.setVisible=function(bool){
	this.div.style.display=bool ? '':'none';
	this.isVisible=bool;
};

HtmlControl.prototype.visible=function(){
	return this.isVisible;
}
	

/*
 * 
 */
var map = null;
var geocoder = null;
var status = 0;

function togglemap () {
	if(status==1) {
		GUnload();
		document.getElementById('map_canvas').style.display='none';
		document.getElementById('form_canvas').style.display='none';
		document.getElementById('maphr_t').style.display='none';
		document.getElementById('maphr_b').style.display='none';
		document.getElementById('toggleshowkarte').innerHTML='einblenden';
		status=0;
	} else {
		document.getElementById('map_canvas').style.display='';
		document.getElementById('form_canvas').style.display='';
		document.getElementById('maphr_t').style.display='';
		document.getElementById('maphr_b').style.display='';
		document.getElementById('toggleshowkarte').innerHTML='ausblenden';
		status=1;
		if(!document.getElementById('inadress').value) {
			if(document.getElementById('inort').value) {
				document.getElementById('inadress').value=document.getElementById('inort').value;
			}
		} 

		initialize();
		if(document.getElementById('mapcoord').value!='') {
			var arr = new Array();
			arr = document.getElementById('mapcoord').value.split(", ");
			showMarker(new GLatLng(parseFloat(arr[0].replace('(','')), parseFloat(arr[1].replace(')',''))));
		}
		else if (document.getElementById('inadress').value) {
			showAddress(document.getElementById('inadress').value);
			init_tmp='';
		}
		update_hidden_coord();
		
	}
}

function initHelper(){
	map.setCenter(new GLatLng(51.04139389812637, 10.4150390625), 5);
}

function initialize() {
  if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById("map_canvas"));
	map.setMapType(G_HYBRID_MAP);
	map.enableScrollWheelZoom();

	map.addControl(new GMapTypeControl());
	map.addControl(new GLargeMapControl());
	map.addControl(new GOverviewMapControl  ());

	geocoder = new GClientGeocoder();

	initHelper();

  }
}
/*
var location1, location2;

function mygetlocations () {
	geocoder.getLocations("rostock", function (response) {
		if (!response || response.Status.code != 200){
			alert("Sorry, we were unable to geocode the first address");
		}
		else{ 
			location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
			mycalculateDistance();
		}
	});
}

function mycalculateDistance()
{
	try
	{
		var glatlng1 = new GLatLng(location1.lat, location1.lon);
		var glatlng2 = new GLatLng(location2.lat, location2.lon);
		var miledistance = glatlng1.distanceFrom(glatlng2, 3959).toFixed(1);
		var kmdistance = (miledistance * 1.609344).toFixed(1);
 
		document.getElementById('results').innerHTML = '<strong>Address 1: </strong>' + location1.address + '<br /><strong>Address 2: </strong>' + location2.address + '<br /><strong>Distance: </strong>' + miledistance + ' miles (or ' + kmdistance + ' kilometers)';
	}
	catch (error)
	{
		alert(error);
	}
}
*/

function cbgetLocations (response){
      place = response.Placemark[0];
	  document.getElementById('inadress').value=place.address;
}

function showMarker(point){
	//map.setCenter(point, 13);
	map.setCenter(point, 14);
	var marker = new GMarker(point,{draggable: true});
	GEvent.addListener(marker, "dragstart", function() {
		map.closeInfoWindow();
	});
	
	GEvent.addListener(marker, "dragend", function() {
	  //marker.openInfoWindowHtml("Just bouncing along...");
		document.getElementById('mapcoord').value=marker.getPoint().toString();
		geocoder.getLocations(marker.getPoint(), cbgetLocations);
		update_hidden_coord();
	});
	map.clearOverlays();
	map.addOverlay(marker);
	// marker.openInfoWindowHtml(address);
	document.getElementById('mapcoord').value=marker.getPoint().toString();
}

function showAddress(address) {
  if (geocoder) {
	geocoder.getLatLng(
	  address,
	  function(point) {
		if (!point) {
		  //alert(address + " not found");
			 document.getElementById('mapcoord').value='';
			 map.clearOverlays();
			 initHelper();
			 update_hidden_coord();
		} else {
			showMarker(point);
			update_hidden_coord();
		}
	  }
	);
  }
}

function update_hidden_coord () {
	if(document.getElementById('mapcoord').value!='') {
		document.getElementById('hidden_coord_status').innerHTML='<img src="/gifs/GMap_ok.png" border="0">';
	} else {
		document.getElementById('hidden_coord_status').innerHTML='<img src="/gifs/GMap_frage.png" border="0">';
	}

}

function confirm_map () {

	if(document.getElementById('dsvfid').value==''){
		valdsv=confirm('Es wurde noch keine DSV Nummer eingetragen.\nEs wird empfohlen hier eine Angabe zu machen, da wir diese im Hintergrund nutzen.\n[OK] fährt ohne DSV Nummer fort, [Abbrechen] bricht den Speichervorgang ab');
	} else {
		valdsv=1;
	}

	if (valdsv==false) {
		return false;
	}

	if(document.getElementById('mapcoord').value!=''){
		//return 1;
		valmap=1;
	}else {
		//return confirm('Es wurde noch keine Markierung auf der Karte für dieses Event vorgenommen.\n>>OK<< fährt ohne Markierung fohrt, >>Abbrechen<< bricht den Speichervorgang ab');
		valmap=confirm('Es wurde noch keine Markierung auf der Karte für dieses Event vorgenommen.\n[OK] fährt ohne Markierung fort, [Abbrechen] bricht den Speichervorgang ab');
	}

	return (valdsv&&valmap);
		
}


var map, cluster, eventListeners=[], markersArray=[], icon;
var auswstatus=0;

function toggleauswmap (single, id,https,lang) {
	//take care when changing! is used by List and Eventsite...
	//if single==1 --> show single regatta only
	if(!auswstatus) {
		auswstatus=1;
		document.getElementById('contauswmap').style.display='';
		
		if(document.getElementById('contauswmapbel'))
			document.getElementById('contauswmapbel').innerHTML='<br>';
		if(https==false)
			myOnload(single,id);
		else {
			document.getElementById('contauswmap').style.height='';
			document.getElementById('contauswmap').innerHTML="";
			if(lang=="eng") {
				document.getElementById('contauswmap').innerHTML+='We are sorry, but due to technical reasons the map is not available during registration process.';
			}
			else {
				document.getElementById('contauswmap').innerHTML+='Aus technischen Gründen kann Karte nicht immer angezeigt werden,<br>wenn man eingeloggt ist.';
				document.getElementById('contauswmap').innerHTML+='Wir bitten dies zu entschuldigen.';
			}
			//document.getElementById('contauswmap').innerHTML+='</div>';
		}
	}
	else {
		auswstatus=0;
		document.getElementById('contauswmap').style.display='none';
		
		if(document.getElementById('contauswmapbel'))
			document.getElementById('contauswmapbel').innerHTML='';
		if(https==false)
			GUnload();
	}
}

function myCloseInfoWindow () {
	map.closeInfoWindow();
}

function myOnload(single, id) {
	if (GBrowserIsCompatible()) {
		map=new GMap2(document.getElementById('contauswmap'));
		map.setMapType(G_HYBRID_MAP);
		map.enableScrollWheelZoom();

		map.setCenter(new GLatLng(51.04139389812637, 10.4150390625), 5);

		map.addControl(new GMapTypeControl());
		map.addControl(new GLargeMapControl());
		map.addControl(new GOverviewMapControl());

		GEvent.addListener(map, 'zoomend', function() { map.closeInfoWindow(); });

		if(single!='1') {
			var html='<div style="border:solid black 1px; background-color:white; color:black; padding:0px 3px 3px 3px">Clustering: <input type="checkbox" checked="checked" onclick="toggleClustering()" /></div>';
			var control=new HtmlControl(html);
			map.addControl(control, new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(73,7)));
		}

		
		function myClusterClick(args) {
			cluster.defaultClickAction=function(){
				var temp_zoom=map.getBoundsZoomLevel(args.clusterMarker.clusterGroupBounds);
				if(temp_zoom>17)
					temp_zoom=17;
				map.setCenter(args.clusterMarker.getLatLng(), temp_zoom);
				delete cluster.defaultClickAction;
			}
			var html='<div style="height:8em; overflow:auto; width:24em;" align="left"><span class="help"><b>'+args.clusteredMarkers.length+' Events:</b>';
			for (i=0; i<args.clusteredMarkers.length; i++) {
				html+='<br /><a href="javascript:cluster.triggerClick('+args.clusteredMarkers[i].index+')">Zoom in</a> | ';
				html+='<a href="http://maps.google.de/maps?t=h&q='+args.clusteredMarkers[i].getPoint().toString()+'&hl=de" target="_blank"><img src="/gifs/GMap_glogo2.png" border="0"><img src="/gifs/GMap_link.gif" border="0"></a> | '+args.clusteredMarkers[i].getTitle();
			}
			html+='<br />[<a href="javascript:void(0)" onclick="cluster.defaultClickAction()">In dieses Cluster rein zoomen</a>]</span></div>';
			//	args.clusterMarker.openInfoWindowHtml(html);
			map.openInfoWindowHtml(args.clusterMarker.getLatLng(), html);
		}
		
		//	create a ClusterMarker
		//cluster=new ClusterMarker(map, {clusterMarkerTitle:'Click to see info about %count locations' , clusterMarkerClick:myClusterClick });
		cluster=new ClusterMarker(map, {clusterMarkerTitle:'Weitere Infos zu diesem Cluster' , clusterMarkerClick:myClusterClick });
		
		icon=new GIcon();
		icon.shadow='./gifs/GMap_single.png';
		icon.iconSize=new GSize(15, 15);
		icon.iconAnchor=new GPoint(9, 32);
		icon.infoWindowAnchor=new GPoint(9, 32);

		//icon.shadowSize=new GSize(35, 32);
		
		selectExample(single,id);
	}
}

function newMarker(markerLocation, title, markerIcon, address) {
	var marker=new GMarker(markerLocation, {title:title, icon:markerIcon});
	//var marker=new GMarker(markerLocation, {title:title});
	eventListeners.push(GEvent.addListener(marker, 'click', function() {
		marker.openInfoWindowHtml('<p>'+title+'</p><p style="font-size:8pt; color:#808080;">'+address+'</p><p><a href="http://maps.google.de/maps?t=h&q='+marker.getPoint().toString()+'&hl=de" target="_blank"><img src="/gifs/GMap_glogo.png" border="0"></a><br><span class="help">(Routenplanung uvm.)</span></p>');
	}));
	return marker;
}

function toggleClustering() {
	cluster.clusteringEnabled=!cluster.clusteringEnabled;
	cluster.refresh(true);
}

function selectExample(single,id){
	processIt=function(file, code){
		if(code===200){
			markersArray=[];
			for(i=eventListeners.length-1; i>=0; i--){
				GEvent.removeListener(eventListeners[i]);
			}
			
			eventListeners=[];

			eval(file);
			
			var marker, newIcon, j=1, title, lat, lng;

			for (var i=0; i<json.length; i++) {
				//newIcon=new GIcon(icon, 'http://www.raceoffice.org/gifs/GMap_single.png');
				newIcon=new GIcon(icon);
				lat=Math.round(json[i].lat*100)/100;
				lng=Math.round(json[i].lng*100)/100;
				//title='id: '+i+', ('+lat+', '+lng+')';
				title='<a href="http://www.raceoffice.org/event.php?eid='+json[i].id+'">';
				title=title+json[i].name+'</a>';
				marker=newMarker(new GLatLng(json[i].lat, json[i].lng), title, newIcon, json[i].address);

				markersArray.push(marker);
				j++;
				if (j>26) {
					j=1;
				}
			}
			
			cluster.removeMarkers();
			cluster.addMarkers(markersArray);
		//	cluster.fitMapToMarkers(); //fit map to selected markers
			cluster.refresh(); // we do a refresh instead of fitmapto markers
			map.savePosition();
			json=[];
		} else {
			GLog.write('Marker data retrieval failed. Error code: '+code);
		}
	};

	if(single=='1'){
		GDownloadUrl('./inc/regatten.map.php?single=1&id='+id+'', processIt);
	}else{
		GDownloadUrl('./inc/regatten.map.php', processIt);
	}
	
	//var json=[]; json[0]={'id':1, 'lat':52.149549, 'lng':1.60221 }; json[1]={'id':2, 'lat':52.7403984069824, 'lng':0.514689087867737 }; json[2]={'id':3, 'lat':52.7369802416371, 'lng':0.518964529037476 }; 
}


