function toggle_openinghours() {
	$("#openinghours").toggle();
	if($("#openinghours").is(":visible")) {
		$("#openinghourslink").text(tr['openinghours']);
	}
	else {
		$("#openinghourslink").text(tr['show_openinghours']);
	}
	return false;
}

var LOCATIONS = {};

$.each(LOCATIONS_BY_COUNTRY, function(){
	for (i in this)
		LOCATIONS[this[i].id] = this[i];
});

var map;
var mgr;
var geo;
var geo2;
var possible_location_over_markers = [];
var location_over_marker;


// überprüft, ob punkte ca passen!
function my_points_are_equal(p1, p2)
{
	// distnacefrom: distanz in metern!
	return (p1.distanceFrom(p2) <= 200);
}

var all_markers = new Array();

function init_map()
{
	if (!GBrowserIsCompatible())
		return;

	map = new GMap2(document.getElementById("map"));
	map.addControl(new GLargeMapControl());
	// map.addControl(new GOverviewMapControl());
	map.setCenter(new GLatLng(50, 372), 4);
	map.enableDoubleClickZoom();
	map.enableScrollWheelZoom();
	// map.enableContinuousZoom();
	map.addControl(new GMapTypeControl());
	
	GEvent.addListener(map, 'zoomend', function() {
		setTimeout("update_markers_by_servcices()",1000);
	});
	
	add_markers();
	
	geo = new GClientGeocoder(); 
	
	geo.setBaseCountryCode("at");
	geo2 = new GClientGeocoder(); 
	
	
	// Add possible Overlay markers
	var possibleIcons = [];
	
	var icon = new GIcon();
	icon.image = "/images/logo_20_selected.png";
	icon.iconSize = new GSize(20, 23);
	icon.iconAnchor = new GPoint(16, 16);
	possibleIcons[0] = icon;
	
	var icon = new GIcon();
	icon.image = "/images/logo_30_selected.png";
	icon.iconSize = new GSize(30, 34);
	icon.iconAnchor = new GPoint(16, 16);
	possibleIcons[1] = icon;
	
	var icon = new GIcon();
	icon.image = "/images/logo_40_selected.png";
	icon.iconSize = new GSize(40, 46);
	icon.iconAnchor = new GPoint(16, 16);
	possibleIcons[2] = icon;
	
	for(var i in possibleIcons)
	{
		var marker = new GMarker(new GLatLng(0,0), {icon: possibleIcons[i], zIndexProcess:function(){return 5000;}});
		map.addOverlay(marker);
		marker.hide();
		possible_location_over_markers[i] = marker;
	}
	
	
	
}

// *** ADD MARKERS TO THE MAP *** ///
function add_markers()
{
	mgr = new MarkerManager(map);
	
	// *** COUNTRIES ***
	var icon = new GIcon();
	icon.image = "/images/logo_30.png";
	icon.iconSize = new GSize(30, 34);
	icon.iconAnchor = new GPoint(16, 16);
	icon.infoWindowAnchor = new GPoint(16, 0);

	var markers = [];
	for (var i in COUNTRIES) {
		var country = COUNTRIES[i];
		//alert(country.lat);

		var marker = new GMarker(new GLatLng(country.lat, country.lng), { icon: icon, title: country.name });
		marker.id_country = country.id;
		GEvent.addListener(marker, 'click', country_click); 
		markers.push(marker);
		all_markers.push(marker);
	}
	mgr.addMarkers(markers, 0, 4);
	
	// *** LOCATIONS ***
	var icon = new GIcon();
	icon.image = "/images/logo_20.png";
	icon.iconSize = new GSize(20, 23);
	icon.iconAnchor = new GPoint(16, 16);
	icon.infoWindowAnchor = new GPoint(16, 0);

	var markers = [];
	for (var i in LOCATIONS) {
		var location = LOCATIONS[i];

		var marker = new GMarker(new GLatLng(location.lat, location.lng), { icon: icon, title: location.name });
		marker.id_location = location.id;
		marker.id_country = location.id_country;
		marker.location_i = i;
		marker.services = location.services;
		//marker.info_html = location.info_window;
		
		//if (location.info_window)
			//console.log(location);
		
		GEvent.addListener(marker, 'click', location_click);
		
		if (location.image || location.image2 || location.image3 || location.image_url || location.image_url2 || location.image_url3)
		{
			GEvent.addListener(marker, 'mouseover', function() { 
				var m = this;
				var response = $.ajax({
				  url: "location.php?get=infoWindowHTML&id_location="+m.id_location,
				  cache: false,
				  success: function(html){
				    map.openInfoWindowHtml(m.getLatLng() , html);
				  }
				});
			}); 
			
			GEvent.addListener(marker, 'mouseout', function() { map.closeInfoWindow(); }); 
		}
		//GEvent.addListener(marker, 'mouseover', function() { alert("test"); }); 

		markers.push(marker);
		all_markers.push(marker);
	}
	mgr.addMarkers(markers, 5, 7);

	
	// *** LOCATION DETAILS ***
	var icon = new GIcon();
	icon.image = "/images/logo_30.png";
	icon.iconSize = new GSize(30, 34);
	icon.iconAnchor = new GPoint(16, 16);
	icon.infoWindowAnchor = new GPoint(16, 0);

	var markers = [];
	for (var i in LOCATIONS) {
		var location = LOCATIONS[i];

		var marker = new GMarker(new GLatLng(location.lat, location.lng), { icon: icon, title: location.name });
		marker.id_location = location.id;
		marker.id_country = location.id_country;
		marker.location_i = i;
		marker.services = location.services;
		GEvent.addListener(marker, 'click', location_click); 
		//GEvent.addListener(marker, 'mouseover', function() {map.openInfoWindowHtml("<p>test</p>");}); 
		
		if (location.image || location.image2 || location.image3 || location.image_url || location.image_url2 || location.image_url3)
		{
			GEvent.addListener(marker, 'mouseover', function() { 
				
				var m = this;
						
				var response = $.ajax({
				  url: "location.php?get=infoWindowHTML&id_location="+m.id_location,
				  cache: false,
				  success: function(html){
				    map.openInfoWindowHtml(m.getLatLng() , html);
				  }
				});
			});
			
			GEvent.addListener(marker, 'mouseout', function() { map.closeInfoWindow(); });
		}
		
		markers.push(marker);
		all_markers.push(marker);
	}
	mgr.addMarkers(markers, 8, 9);


	// *** LOCATION DETAILSDETAILS ***
	var icon = new GIcon();
	icon.image = "/images/logo_40.png";
	icon.iconSize = new GSize(40, 46);
	icon.iconAnchor = new GPoint(16, 16);
	icon.infoWindowAnchor = new GPoint(16, 16);

	var markers = [];
	for (var i in LOCATIONS) {
		var location = LOCATIONS[i];

		var marker = new GMarker(new GLatLng(location.lat, location.lng), { icon: icon, title: location.name });
		marker.id_location = location.id;
		marker.id_country = location.id_country;
		marker.location_i = i;
		marker.services = location.services;
		GEvent.addListener(marker, 'click', location_click);
		//GEvent.addListener(marker, 'mouseover', function() {marker.openInfoWindowHtml("<p>test</p>");}); 
		
		if (location.image || location.image2 || location.image3 || location.image_url || location.image_url2 || location.image_url3)
		{
			GEvent.addListener(marker, 'mouseover', function() { 
				
				var m = this;
						
				var response = $.ajax({
				  url: "location.php?get=infoWindowHTML&id_location="+m.id_location,
				  cache: false,
				  success: function(html){
				    map.openInfoWindowHtml(m.getLatLng() , html);
				  }
				});
			});
			
			GEvent.addListener(marker, 'mouseout', function() { map.closeInfoWindow(); });
		}
		
		markers.push(marker);
		all_markers.push(marker);
	}
	mgr.addMarkers(markers, 10);
	
	
	mgr.refresh();
}


// *** MAP EVENT HANDLERS ***

function change_country(id_country) {
	var country;

	if (id_country)
		country = COUNTRIES[id_country];

	// karte updaten
	if (!country)
		map.setCenter(new GLatLng(50, 372), 4);
	else
	if (map.getZoom() == 6)
		map.panTo(new GLatLng(country.lat, country.lng));
	else
		map.setCenter(new GLatLng(country.lat, country.lng), 6);
	
	// auswahl updaten
	$("#selectcountry").val(id_country);

	// Stationen anzeigen
	
	if (id_country == "")
	{
		$("#locationheadline").hide();
		$("#selectlocation-container").hide();
	}
	else
	{
		$("#locationheadline").show();
		$("#selectlocation-container").show();
	}
	// services updaten
	
	//immer alle services verstecken
	$('#selectservice div').hide();
	$('#selectservice div').each(function(){
		$(this).removeClass('selected').html($("#selectservice div[rel="+$(this).attr('rel')+"_img2]").html());
	});
		
	if (country)
	{
		// services einblenden, die im land vorhanden sind
		$("#serviceheadline").show();
		$.each(country.services, function(i, v) {
			$('#selectservice div[rel='+v+']').show();
		});
	}
	else
		$("#serviceheadline").hide();
		
	update_locations();
}

function country_click(point) {
	change_country(this.id_country);
}

function location_click(point, id_location, zoom_in) {
	if(this.id_country && this.id_country != $("#selectcountry").val())
		change_country(this.id_country);
		
	if (typeof id_location == 'undefined')
		id_location = this.id_location;
		
	// beim zoom_in, genauere karte zeigen (wenn wer auf die standortliste klickt)
	var zoom = 8;
	if (zoom_in)
		zoom = 10;

	if (map.getZoom() < zoom)
	{
		map.setCenter(point, zoom);
	}
	else
	// standort ist in der mitte (wurde zuvor geklickt) -> zoomen
	if (!zoom_in && my_points_are_equal(map.getCenter(), point))
	{
		// nicht höher als 16 zoomen
		if (map.getZoom() > 16)
			map.setCenter(point);
		else
		{
			map.setCenter(point, Math.min(17, map.getZoom()+2));
		}
	}
	else
		map.panTo(point);
	
	// falls derzeitige location != neuer location ist -> neu laden
	if ($("#LeftArea").attr('id_location') != id_location)
	{
		$("#LeftArea").empty().addClass('loading');
		
		$.get('locations.php',
		{
			get: 'location',
			id_location: id_location
		},
		function(details)
		{
			$("#LeftArea").attr('id_location', id_location);
			$("#LeftArea").removeClass('loading');
			$("#LeftArea").html(details);
		});
	}
	
	mgr.refresh();
}

function list_location_over() {
	
	// Icon auf der Karte drüberlegen
	
	var location_id = $(this).attr("rel");
	var location = LOCATIONS[location_id];

	var zoom = map.getZoom();
	
	if(zoom>=5 && zoom <=7)
	{
		location_over_marker = possible_location_over_markers[0];
	}
	else if(zoom>=8 && zoom <=9)
	{
		location_over_marker = possible_location_over_markers[1];
	}
	else if(zoom>=10)
	{
		location_over_marker = possible_location_over_markers[2];
	}
	else
		return;
	
	location_over_marker.setLatLng(new GLatLng(location.lat,location.lng));
	location_over_marker.show();
}

function list_location_out() {
	location_over_marker.hide();
}
	
function update_markers_by_servcices()
{
	//var locations = LOCATIONS_BY_COUNTRY[id_country];	
	
	//mgr.clearMarkers();
	
	//add_markers();
	//alert("test");
	
	if (map.getZoom() <= 4)
		return;
	
	var services = [];
	$("#selectservice div.selected:visible").each(function(){
		services.push($(this).attr("rel"));
	});
	
	
	
	for (var i=0;i<all_markers.length;i++)
	{
		//console.log(all_markers[i].services);
		var add = true;
		if (typeof(all_markers[i].services) == "undefined")
		{
			add=false;
		}
		else
		{
			for(var j in services)	// Alle Services der Städte
			{
				if (!all_markers[i].services[services[j]])
					add = false;
			}
		}
		
		
		if (add)
			all_markers[i].show();
		else
			all_markers[i].hide();
		
	}
}
	
function update_locations()
{
	var id_country = $("#selectcountry").val();
	
	// locations im country
	var locations = LOCATIONS_BY_COUNTRY[id_country];	

	// services auslesen
	var services = [];
	$("#selectservice div.selected:visible").each(function(){
		services.push($(this).attr("rel"));
	});
	
	var NEWLOCATIONS = {};
	// location ausgabe
	var html = '';
	for(var i in locations)	// Alle Städte im ausgewählten Land
	{
		var add = true;
		for(var j in services)	// Alle Services der Städte
		{
			if (!locations[i]['services'][services[j]])
				add = false;
		}
		
		if(add)
		{
			var joiner="";
			if(locations[i].name!="" && locations[i].zip!="")
				joiner = ", ";
			html += '<a rel="' + locations[i].id + '">' + locations[i].name + joiner + locations[i].zip + '</a>';
		}
	}
	if(!html)
	{
		$("#selectlocation").html('<span>Keine gefunden</span>');
		return;
	}
	else		
		$("#selectlocation").html(html);
	
	
	
	$('#selectlocation a').hover(list_location_over, list_location_out);
	
	$('#selectlocation a').click(function(){
		var location = LOCATIONS[$(this).attr("rel")];
		if (!location)
			return;

		var point = new GLatLng(location.lat, location.lng);

		// klick event aufrufen
		location_click(point, $(this).attr("rel"), true);
	});
	
	
		update_markers_by_servcices();
}


var GDir1;
// onload
$(function(){
	// init google map
	init_map();

	$('#selectcountry').change(function(){
		change_country(this.value);
	}).change();
	
	// beim drüberfahren über die locations, liste nach unten einblenden
	$("#selectlocation-container").hover(function() {
		//alert(this.offsetHeight);
		
		if ($(this).find(".content")[0].offsetHeight > this.offsetHeight)
		{
			$(this).attr("org_height",this.offsetHeight-2);
			
			new_height=$(this).find(".content")[0].offsetHeight;
			
			if (new_height > 300)
				new_height = 300;
			
			$(this).css({ height: new_height });
		}		
	}, function() {
		$(this).css({height: parseInt($(this).attr("org_height"))});
	});
	
	// beim klicken auf einen service
	$("#selectservice div").click(function() {
		if($(this).hasClass("selected"))
		{
			$(this).html($("#selectservice div[rel="+$(this).attr('rel')+"_img2]").html());
			$(this).removeClass("selected");
		}
		else
		{
			$(this).html($("#selectservice div[rel="+$(this).attr('rel')+"_img1]").html());
			$(this).addClass("selected");
		}
		
		update_locations();
		//update_map();
	});
	
	GDir1 = new GDirections(map);
	
});


var from = "";
var to = "";

var src_ok;
var dest_ok;

function route(lat,lng,adresse)
{
	GDir1.clear();
	src_ok = false;
	dest_ok = false;
	setTimeout("show_route_selector("+lat+","+lng+",'"+adresse+"')",500);
	
	//alert(lat);
}

function show_route_selector(lat,lng,adresse)
{
	$("#src_vorschlaege").html('');
	$("#dest_vorschlaege").html('');
	
	var show = function(hash) {
		hash.w.fadeIn();
	};
	var hide = function(hash) {
		hash.o.remove();
		hash.w.fadeOut();
	};		
	
	
	
	html = "";
	
	html = '<div id="Address"><div style="float:left; width:100px; margin-bottom: 5px;"><b>'+tr['startAddress']+': </b></div>';
	html += '<div style="float:left; margin-bottom: 5px;"><input style="width:170px;"  id="entered_src_adress" type="text"></div>';
	html += '<div class="clear"><span>&nbsp;</span></div>'
	html += '<div style="width:300px; margin-bottom: 10px;" id="src_vorschlaege"></div>';
	html += '<div style="float:left; width:100px;"><b>'+tr['destinationAddress']+': </b></div>';
	html += '<div style="float:left;"><input id="entered_dest_adress" style="width:170px;" value="'+adresse+'" type="text"></div>';
	html += '<div class="clear"><span>&nbsp;</span></div>'
	html += '<div style="width:300px" id="dest_vorschlaege"></div>';
	html += '<div style="position: relative; width: 150px; top:10px; left: 100px;"><input onclick="getLocations(\''+lat+'\',\''+lng+'\',\''+adresse+'\');" type="button" value="'+tr['showRoute']+'"></div>';
	html += '</div>';
	
	html += '<div id="RouteInfo"></div>';
	
	if (!$('#PopupEnterAdress').length)
		$('body').append('<div id="PopupEnterAdress" style="" class="jqmWindow"></div>');
	
	
	
	
	$("#PopupEnterAdress").html(html);
	
	$("#src_vorschlaege").hide();
	$("#dest_vorschlaege").hide();
	
	$("#PopupEnterAdress").css('height',"70px");
	$("#PopupEnterAdress").css({'overflow-y':'auto'});
	$("#PopupEnterAdress").css({'overflow':'hidden'});
	
	
	$("#PopupEnterAdress").jqm({modal: false,onShow: show, onHide: hide}).jqmShow();	
}

function send_sms() {
	GDir1.clear();
	setTimeout("show_send_sms()",500);
}

function sms_switchCoords() {
	
	if($j("#Address input.sms_coord:checked").val()=="coord") {
		$j("input.coord[value=coord]").attr("checked",true);
		$j("input.coord[value=degree]").attr("checked",false);
		switchCoords();
	} else {
		$j("input.coord[value=coord]").attr("checked",false);
		$j("input.coord[value=degree]").attr("checked",true);
		switchCoords();
	}
}

function show_send_sms() {
	
	var show = function(hash) {
		hash.w.fadeIn();
	};
	var hide = function(hash) {
		hash.o.remove();
		hash.w.fadeOut();
	};		
	
	var coord_checked = "";
	var degree_checked = "";
	
	if($j("input.coord:checked").val()=="coord") {
		coord_checked = " checked";
	} else {
		degree_checked = " checked";
	}
	
	html = "";
	
	html = '<div id="Address">';
		html += '<div><input type="radio" class="sms_coord" name="sms_coord" value="coord" onclick="sms_switchCoords();"'+coord_checked+'>&nbsp;&nbsp;'+tr['sms_coord']+'</div>';
		html += '<div><input type="radio" class="sms_coord" name="sms_coord" value="degree" onclick="sms_switchCoords();"'+degree_checked+'>&nbsp;&nbsp;'+tr['sms_degree']+'</div>';
		html += '<br />';
		html += '<div style="float:left; width:130px; margin-top: 2px;"><b>'+tr['sms_recipient']+': </b></div>';
		html += '<div style="float:left;"><input style="width:166px;"  id="entered_sms_recipient" type="text"></div>';
		html += '<div class="clear"><span>&nbsp;</span></div>';
		html += '<div>'+tr['for_instance']+' 00436761234567</div>';
		html += '<div style="position: relative; text-align: center; top:21px; left: 0px;"><input onclick="send_sms_real();" type="button" value="'+tr['send_coords']+'"></div>';
	html += '</div>';
	
	html += '<div id="RouteInfo"></div>';
	
	if (!$('#PopupEnterAdress').length)
		$('body').append('<div id="PopupEnterAdress" style="" class="jqmWindow"></div>');
	
	$("#PopupEnterAdress").html(html);
	
	$("#PopupEnterAdress").css('height',"130px");
	$("#PopupEnterAdress").css({'overflow-y':'auto'});
	$("#PopupEnterAdress").css({'overflow':'hidden'});
	
	$("#PopupEnterAdress").jqm({modal: false,onShow: show, onHide: hide}).jqmShow();	
}

function send_sms_real() {
	var msg = 'M-OIL ';
	
	msg += $j("#station_name").html()+";";
	
	if($j("input.coord:checked").val()=="coord") {
		msg += $j("#coordContent").html();
	} else {
		msg += $j("#degreeContent").html();
	}
	
	msg += ";";
	msg += $j("#station_street").html()+";"+$j("#station_zip").html();
	
	$.post(
		"/send_sms.php",
		{"recipient":$j("#entered_sms_recipient").val(),"message":msg},
		function(data) {
			alert(data);
			$("#PopupEnterAdress").jqmHide();
		}
	);
}

var dest;
var src;

var from;
var to;

function getLocations(dest_lat,dest_lng,adresse)
{
	from = '';
	
	var search = $("#entered_src_adress").val();
	to = adresse;
	
	geo.getLocations(search, function (result)
  {
  	//alert(result.Placemark.length);
  	
  	if (result.Status.code == G_GEO_SUCCESS) {
	
	  	if (result.Placemark.length > 1)
	  	{
	  		src_ok = false;
	  		
	  		var html = "<b>"+tr['didYouMean']+":</b>";
	  		
	  		for (var i=0; i<result.Placemark.length; i++) {
	  			//alert(result.Placemark[i].address);
	  			var p = result.Placemark[i].Point.coordinates;
	  			//alert(p[0]);

	  			html += "<br>"+(i+1)+": <a  href=\"javascript:void(0);\" onclick=\"$('#entered_src_adress').val('"+result.Placemark[i].address+"');";
	  			
	  			html += "\" >"+ result.Placemark[i].address+"<\/a>";

				}
				
				$("#src_vorschlaege").html(html);
				$("#src_vorschlaege").show();
				$("#PopupEnterAdress").animate({height: $("#Address").height()+15});
	  	}
	  	else
	  	{
	  		var p = result.Placemark[0].Point.coordinates;
        //place(p[1],p[0]);
        src = new GLatLng(p[1],p[0]);
        
        from = result.Placemark[0].address;
        
        $('#entered_src_adress').val(from);
        
        src_ok = true;
        setRoute();
	  	}
	  }
  });
  
  var search = $("#entered_dest_adress").val();
  
  geo2.getLocations(search, function (result)
  {
  	//alert(result.Placemark.length);
  	
  	if (result.Status.code == G_GEO_SUCCESS) {
	
	  	if (result.Placemark.length > 1)
	  	{
	  		dest_ok = false;
	  		var html = "<br><b>"+tr['didYouMean']+":</b>";
	  		
	  		for (var i=0; i<result.Placemark.length; i++) {
	  			//alert(result.Placemark[i].address);
	  			var p = result.Placemark[i].Point.coordinates;

	  			//html += "<br>"+(i+1)+": <a href='javascript:setRoute("+dest_lat+", "+dest_lng+", " +p[1]+","+p[0]+")'>"+ result.Placemark[i].address+"<\/a>";
	  			html += "<br>"+(i+1)+": <a href=\"javascript:void(0);\" onclick=\"$('#entered_dest_adress').val('"+result.Placemark[i].address+"');";
	  			html += "\" >"+ result.Placemark[i].address+"<\/a>";


				}
				
				$("#dest_vorschlaege").html(html+"<br><br>");
				$("#dest_vorschlaege").show();
	  	}
	  	else
	  	{
	  		var p = result.Placemark[0].Point.coordinates;
        //place(p[1],p[0]);
				//setRoute(dest_lat,dest_lng,p[1],p[0]);
				to = result.Placemark[0].address
				
				dest = new GLatLng(p[1],p[0]);
				
				$('#entered_dest_adress').val(to);
				
				dest_ok = true;
        setRoute();
				
				
	  	}
	  }
	  else
	  {
	  	dest = new GLatLng(dest_lat,dest_lng); 
	  	dest_ok = true;
	  	//alert(src_ok);
      
      setRoute();
	  }
  });

}

function place(lat,lng) {
  var point = new GLatLng(lat,lng);
  //map.setCenter(point,14); 
  map.addOverlay(new GMarker(point));
}

var routing = false;
function setRoute()
{
	if(!src_ok || !dest_ok || routing) {
		return;
	}
	
	src_ok = false;
	dest_ok = false;
	routing = true;
	
	//GDir1 = new GDirections(map);
	//GDir1.clear();
	
	//var dest = new GLatLng(dest_lat,dest_lng);
	//var src = new GLatLng(src_lat, src_lng);
	//alert(my_locale);
	
	//GDir1.loadFromWaypoints([$("#entered_src_adress").val(), $("#entered_dest_adress").val()], {getPolyline:true,"getSteps":true});
	
	GDir1.loadFromWaypoints([src, dest], {"getPolyline":true, "getSteps":true, "locale":site_language});
	//GDir1.load("from: " +$("#entered_src_adress").val()+ " to: " +$("#entered_dest_adress").val(), {getPolyline:true,"getSteps":true});
	
	GEvent.addListener(route,"loaded",createRouteLoaded()); 
}

function createRouteLoaded()
{
	//alert(this);
	
	//$("#RouteInfo").html(GDir1.getSummaryHtml());
	
	//$("#PopupEnterAdress").jqmHide();
	
	//$('#PopupEnterAdress').remove();
	
	//alert(GDir1.getSummaryHtml());
	
	//var beschreibung = GDir1.getSummaryHtml()+"<br><br>";
	
	
	//var zaehler=GDir1.getRoute(0).getNumSteps();
	

	/* var zusammen=""; // "1.	Start:	"+start+"<br>\n"+"<br>\n";
	
	for (k=0; k<zaehler; k++)
	{
		zusammen=zusammen+(counter)+"."+"	"+gdir.getRoute(0).getStep(k).getDescriptionHtml()+"	"+gdir.getRoute(0).getStep(k).getDistance().html+"<br>\n"+"<br>\n";
		counter=counter+1;
	} */
	
	
	//$("#RouteInfo").html(beschreibung);
	setTimeout("setRouteInfo()",800);
	//setRouteInfo();
	//alert(zusammen) */
	
	//zusammen=zusammen+(counter+1)+".	Ziel:	"+ziel;	
}

var route_info = "";
function setRouteInfo()
{
	if(!GDir1.getNumRoutes()) {
		var message = tr['couldntFindRoute'];
		message = message.replace(/\%1/, '\n'+from+'\n').replace(/\%2/, '\n'+to+'\n');
		var parts = message.split('\n');
		
		for(var i in parts) {
			parts[i] = parts[i].replace(/^\s*|\s*$/g, "");
		}
		alert(parts.join("\n"));
		routing = false;
		return;
	}
	
	var zaehler=GDir1.getRoute(0).getNumSteps();
	
	var zusammen = "<b style=\"color: #0169B2; font-size: 13px;\">"+tr['route']+":</b> <br><br>"+tr['from']+" <b>"+from+"</b> <br>"+tr['to']+" <b>"+to+"</b><br><br>";
	
	
	
	zusammen += "1.	<b>"+tr['start']+":	</b>"+from+"<br>\n"+"<br>\n";
	var counter = 2;
	
	for (k=0; k<zaehler; k++)
	{
		zusammen=zusammen+(counter)+"."+"	"+GDir1.getRoute(0).getStep(k).getDescriptionHtml()+"	"+GDir1.getRoute(0).getStep(k).getDistance().html+"<br>\n"+"<br>\n";
		counter=counter+1;
	} 
	
	zusammen += (counter++)+".	<b>"+tr['destination']+":</b>	"+to+"<br>\n"+"<br><br>\n";
	
	zusammen += "<b>"+tr['total']+":</b> "+GDir1.getSummaryHtml()+"<br><br>\n";
	
	route_info = zusammen;
	
	print_btn = '<a href="javascript:void(0);" onclick="print_route();" style="display:block; height:10px; width: 100px; position: absolute; top:10px; right:-30px;">'+tr['print']+'</a>';
	
	$("#PopupEnterAdress").css({'height':300,'overflow-y':'scroll', 'overflow-x':'hidden'});
	$("#PopupEnterAdress").html(zusammen+print_btn);
	//alert(zusammen);
	
	routing = false;
}

function print_route()
{
	
	if (!$("#print_route").length)
		$('body').append('<div id="print_route"></div>');
		
	$("#print_route").html(route_info);
	
	window.print();
		
	/* var baseUrl = "http://maps.google.com/staticmap?";
	var poly = GDir1.getPolyline();

	var params = []; var markersArray = []; 
	markersArray.push(poly.getVertex(0).toUrlValue(5) + ",greena"); 
	markersArray.push(poly.getVertex(poly.getVertexCount()-1).toUrlValue(5) + 
	",greenb"); 
	
	//params.push("markers=" + markersArray.join("|"));

	var polyParams = "rgba:0x0000FF80,weight:5|";
   var polyLatLngs = [];
   for (var j = 0; j < poly.getVertexCount(); j++) {
     polyLatLngs.push(poly.getVertex(j).lat().toFixed(5) + "," + poly.getVertex(j).lng().toFixed(5));
   }
   params.push("path=" + polyParams + polyLatLngs.join("|"));
   params.push("size=300x300");
   params.push("key=ABQIAAAApqGS4b3xYWRGbSJt_atFjhRzqMrAZz4Km9dQe_nb6xavGQfrNBQ0fA_0V7eW0lKJA66qcrl4xOLK5w");

   baseUrl += params.join("&");

   var extraParams = [];
   extraParams.push("center=" + map.getCenter().lat().toFixed(6) + "," + map.getCenter().lng().toFixed(6));
   extraParams.push("zoom=" + map.getZoom());
   //addImg(baseUrl + "&" + extraParams.join("&"), "staticMapOverviewIMG");

	var img_url = baseUrl + "&" + extraParams.join("&");
	
	alert(img_url); */
	
	
	/* MeinFenster = window.open("/empty.htm", "Routenbeschreibung", "width=600,height=800,left=100,top=200,scrollbars=yes");
	with(MeinFenster){
		document.writeln('<HTML><HEAD><TITLE>Die Routenbeschreibung</TITLE><link rel="stylesheet" type="text/css" href="/site.css" /><link rel="stylesheet" type="text/css" href="/css/styles.css" /></HEAD>');
		document.writeln('<body style="background-color:white; ">');
		//document.writeln($("#map").html());
		document.writeln(route_info);
		document.writeln('</body></HTML>');
		print();
	} */

}

function switchCoords() {	
	if($j('#LeftArea input[name=coord]:checked').val()=="coord") {
		$j("#coordContent").css("display","block");
		$j("#degreeContent").css("display","none");
	} else {
		$j("#coordContent").css("display","none");
		$j("#degreeContent").css("display","block");
	}
}

$(document).unload(GUnload);
