var geocoder = null;


//Standardflagge
var icon = new GIcon();
icon.image = "http://www.mobil-reisen.net/_images/flagge.png";
icon.shadow = "http://www.mobil-reisen.net/_images/flaggeSchatten.png";
icon.iconSize = new GSize(40, 50);
icon.shadowSize = new GSize(40, 50);
icon.iconAnchor = new GPoint(0, 50);
icon.infoWindowAnchor = new GPoint(0, 49);

var iconRot = new GIcon();
iconRot.image = "http://www.mobil-reisen.net/_images/flaggeRot.png";
iconRot.shadow = "http://www.mobil-reisen.net/_images/flaggeSchatten.png";
iconRot.iconSize = new GSize(40, 50);
iconRot.shadowSize = new GSize(40, 50);
iconRot.iconAnchor = new GPoint(0, 50);
iconRot.infoWindowAnchor = new GPoint(0, 49);

var iconStellplatz = new GIcon();
iconStellplatz.image = "http://www.mobil-reisen.net/_icons/stellplaetze/1.png";
iconStellplatz.shadow = "http://www.mobil-reisen.net/_icons/stellplaetze/1-schatten.png";
iconStellplatz.iconSize = new GSize(19, 49);
iconStellplatz.shadowSize = new GSize(50, 49);
iconStellplatz.iconAnchor = new GPoint(10, 49);
iconStellplatz.infoWindowAnchor = new GPoint(1, 49);




// A function to create the marker and set up the event window
function createMarker(point,html,icon) {
	// FF 1.5 fix
	var marker = new GMarker(point,icon);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
		refreshsperre = 1;
	});
	GEvent.addListener(marker, "infowindowclose", function() {
		refreshsperre = 0;
	});
	return marker;
}

// A function to create the marker without event window
function createMarkerUnclickable(point,html,icon) {
	// FF 1.5 fix
	var marker = new GMarker(point,icon);
	return marker;
}

//Message for debugging
function writeMessage(html){
	document.getElementById("message").innerHTML = html;
}

function writeAnzahl(anzahl){
	document.getElementById("anzahl").innerHTML = anzahl;
}
		
function eintragen(){
	GEvent.removeListener(poicaller);
	GEvent.addListener(map, "click", function(marker, point) {
	  if (marker) {
		//map.removeOverlay(marker);
	  } else {
		map.clearOverlays();
		marker = new GMarker(point);
		GEvent.addListener(marker, "click", function(){
			var html = '<div id="infowindow">';
			var html = html + 'Stimmt die Position so?<br />';
			var currentZoom = map.getZoom();
			if(currentZoom<=11){
				var html = html + '<p>Vielleicht sollten Sie noch etwas <a href="#" onClick="reinzoomen()">reinzoomen</a>...</p>';
			}
				var html = html + '<p id="maptype">Geb&auml;udegenaue Positionierung geht über die <a href="#" onClick="satview()">Satellitenansicht</a>...</p>';
			var html = html + '<p>Wenn die Position stimmt: <a href="javascript:document.poi_art.submit();">weiter zur Beschreibung Ihres Eintrags.</a></p>';
			var html = html + '</div>';
			marker.openInfoWindowHtml(html);
		});
		map.addOverlay(marker);
		map.panTo(point);
		send_poi_point(point);
	  }
	});		
}

function reinzoomen(){
	map.zoomIn();
			var html = '<div id="infowindow">';
			var html = html + 'Stimmt die Position so?<br />';
	var currentZoom = map.getZoom();
	if(currentZoom<=11){
		var html = html + '<p>Vielleicht sollten Sie noch etwas <a href="#" onClick="reinzoomen()">reinzoomen</a>...</p>';
	}
				var html = html + '<p id="maptype">Geb&auml;udegenaue Positionierung geht über die <a href="#" onClick="satview()">Satellitenansicht</a>...</p>';
			var html = html + '<p>Wenn die Position stimmt: <a href="javascript:document.poi_art.submit();">weiter zur Beschreibung Ihres Eintrags.</a></p>';
			var html = html + '</div>';
	document.getElementById("infowindow").innerHTML = html;
}		

function satview(){
	map.setMapType(G_HYBRID_MAP);
	document.getElementById("maptype").innerHTML = 'Sie k&ouml;nnen mit den Buttons rechts oben jederzeit zwischen Karten- und Satellitenansicht wechseln oder mit den Buttons links ein- und auszoomen.';
}		


var geocoder = new GClientGeocoder();
function showAddress(address) {
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        alert(address + " ist nicht eindeutig. Bitte machen Sie genauere Angaben.");
      } else {
        map.setCenter(point, 13);
 //       var marker = new GMarker(point);
 //       map.addOverlay(marker);
 //       marker.openInfoWindowHtml(address);
      }
    }
  );
}
