
// (c) 2001 - 2006, EIKONA Medien GmbH, it.x informationssysteme gmbh, Mosaiq-Media GmbH, Alle Rechte vorbehalten.

	var map = false;
	var routenplaner;
	var str_fehler_msg;
	var str_routenplaner_id;
	var int_zoom = 10;
	var marker = [];
  	
  	/**
    *	Google Maps karte anzeigen
    */
  	function anzeigen_karte(str_map_id, array_koordinaten, adresse, int_zoom, int_control, control_type, scale_control, zoom_control, overview_control)
  		{
  		if (GBrowserIsCompatible()) 
    		{
      		var str_map_container = document.getElementById(str_map_id);
	   		if (str_map_container)
	   			{
	   			map = new GMap2(str_map_container);				
   				if(document.getElementById("route_ziel"))
   					{
   					document.getElementById("route_ziel").value = adresse;
   					}
				// Steuerelemente
	      		steuerelemente(int_control, control_type, scale_control, zoom_control, overview_control);
				map.setCenter(new GLatLng(array_koordinaten[0],array_koordinaten[1]), int_zoom);
				}
    		}
  		} // anzeigen_karte
  		
    /**
    *	Icons Anzeigen
    */
	function anzeigen_icon(array_koordinaten, str_bild, int_breite, int_hoehe, ausrichtung_x, ausrichtung_y, adresse, system_id, titel)
		{
	  	if(str_bild == "portal/landkarte/pics/" || str_bild == "" )
	    	{
	    	str_bild = "portal/landkarte/pics/pin_red.png";
	    	ausrichtung_y = "unten";
	    	ausrichtung_x = "mitte";
	    	int_breite = 24;
	    	int_hoehe = 17;
	    	}
	    
	    // Icon einbindung
    	var icon = new GIcon();
		icon.image = str_bild;
		icon.iconSize = new GSize(int_breite, int_hoehe);
		
		if(ausrichtung_x == "links")
			position_x = 0;
		else if(ausrichtung_x == "mitte")
			position_x = int_breite / 2;
		else if(ausrichtung_x == "rechts")
			position_x = int_breite;
		
		if(ausrichtung_y == "oben")
			position_y = 0;
		else if(ausrichtung_y == "mitte")
			position_y = int_hoehe / 2;
		else if(ausrichtung_y == "unten")
			position_y = int_hoehe ;

		icon.iconAnchor = new GPoint(position_x, position_y);
		//icon.infoWindowAnchor = new GPoint(position_x, position_y);
				
    	var marker = new GMarker(new GLatLng(array_koordinaten[0], array_koordinaten[1]), {title:titel, icon:icon});
    	marker.id = system_id;
    	map.addOverlay(marker);
    	/*
    	GEvent.addListener
    	(marker, "click",
	    	function()
	    		{
	    		marker.openInfoWindowHtml(kopiere_inhalt_infowindow(system_id));
	    		if(document.getElementById("route_ziel"))
   					{
   					document.getElementById("route_ziel").value = adresse;
   					}
	    		}
	    );*/
	  	}//anzeigen_icon

	/**
    *	Zentrieren in Karte für Sidebar Navi
    */
  	function zentrieren(array_koordinaten, adresse, system_id)
	  	{
	  	if(document.getElementById("route_ziel"))
			{
			document.getElementById("route_ziel").value = adresse;
			}
	  	map.setCenter(new GLatLng(array_koordinaten[0],array_koordinaten[1]), 15)
	  	map.openInfoWindowHtml(new GLatLng(array_koordinaten[0],array_koordinaten[1]), kopiere_inhalt_infowindow(system_id));
	  	}//zentrieren

	/**
    * Laden des Inhalts, der im Infowindow angezeigt werden soll aus
    * dem Element <div id="id_content_xxx"> das in der HTML Seite
    * vorhanden sein muss.
    */
	function kopiere_inhalt_infowindow(system_id)
		{
		if(document.getElementById('id_content_'+system_id))
			return document.getElementById('id_content_'+system_id).innerHTML;
		else
			return '';
		} // kopiere_inhalt_infowindow()

  	/**
    *	Routenplanung durchführen
    */
  	function routenplaner_start(str_map_id, str_planer_id, str_sprache_kuerzel, str_fehler_message, start, ziel)
  		{
  		// Die Karte muss dafür schon vorhanden sein
  		if (map != false)
  			{
  			// Ergebnisfeld zurücksetzen
  			document.getElementById(str_planer_id + "_ergebnis").innerHTML = "";
  			
  			// Routenplanerobjekt erstellen
	      	routenplaner = new GDirections(map, document.getElementById(str_planer_id + "_ergebnis"));
	      	
	      	GEvent.addListener(routenplaner, "error", routenplaner_handleErrors);
	      	
	      	// Strecke ermitteln
	      	routenplaner.load("from: " + start + " to: " + ziel, { "locale": str_sprache_kuerzel} );
	      	
	      	// Ergebnisfeld einblenden
	      	document.getElementById(str_planer_id + "_ergebnis").style.display = "block";
					
	      	// Fehlermeldung und ID speichern
	      	str_fehler_msg = str_fehler_message;
	      	str_routenplaner_id = str_planer_id;
  			}
  		
  		} // routenplaner_start
  		
  	function koordinaten_abschicken()
  		{
  		document.forms.umkreisfinder.submit();
  		}

/**
    *	Routenplanung durchführen
    */
  	function koordinaten_ermitteln()
  		{
  		
  		var start_x, start_y;
		start = document.getElementById("umkreis_start").value;

		var geocoder = new GClientGeocoder();
		geocoder.getLatLng(start,
		function(point)
			{
			if (!point)
				{
				alert(start + ' not found');
				return false;
				}
			else
				{   			
				document.getElementById("umkreis_start_x").value = point.lat();
				document.getElementById("umkreis_start_y").value = point.lng();
				koordinaten_abschicken();			
				}
			}
		);
		return false;
					
  		} // entfernung


	function steuerelemente(int_control, control_type, scale_control, zoom_control, overview_control)
		{
  		// Zoomleiste
  		if (int_control == 1)
  			{
  			map.addControl(new GSmallMapControl());
  			}
  		else if(int_control == 2)
  			{
  			map.addControl(new GLargeMapControl());
  			}
  		if(control_type)
  			{
  			map.addControl(new GMapTypeControl());
			}
  		// Kartenskalierung	
  		if(scale_control)
  			{
  			map.addControl(new GScaleControl());
  			}
		// kleine Karte
		if(overview_control)
  			{
			map.addControl(new GOverviewMapControl());
			}
		// Zoom kleine Karte
  		if(zoom_control)
  			{
			map.addControl(new GSmallZoomControl());
			}
		}
	

	/**
    *	Google Maps karte mit Routenplanung anzeigen
    */
  	function anzeigen_karte_routenplaner(str_map_id, int_control, control_type, scale_control, zoom_control, overview_control)
  		{
    	if (GBrowserIsCompatible()) 
    		{
	      	var str_map_container = document.getElementById(str_map_id);
		   	if (str_map_container)
		   		{
		   		map = new GMap2(str_map_container);
				// Steuerelemente
	      		steuerelemente(int_control, control_type, scale_control, zoom_control, overview_control);
				}
    		}
  		} // anzeigen_karte_routenplaner

  	/**
    *	Fehler bei der Routenplanung handeln
    */
  	function routenplaner_handleErrors()
  		{
  		document.getElementById(str_routenplaner_id + "_ergebnis").style.display = "none";
		alert (str_fehler_msg);
  		} // routenplaner_handleErrors
