	var directionsPanel;
	var arrayABC = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q');
	routingPoints=new Array();
   	lines=new Array();
	distances=new Array();
	directions = new GDirections();
	var counter = 0;
	var lastPoint;
	var distance=0;
    

	function onGDirectionsLoad(){
	   	var new_dist=directions.getDistance().meters/1000
	   	new_dist=Math.round(new_dist * 1000) / 1000;
	   	distances.push(new_dist);
		distance=distance+new_dist;
		distance=Math.round(distance * 1000) / 1000;
		document.getElementById("distance").value=distance + " km";
		var newPolyline = directions.getPolyline();
    	map.addOverlay(newPolyline);
    	lines.push(newPolyline);

	}
	
	function onMapClick(marker, point) {
	    if (lastPoint) {
	        setDirections(
	                lastPoint.y + "," + lastPoint.x,
	                point.y + "," + point.x,
	                "de");
			var icon = new GIcon(baseIcon);
			icon.iconSize = new GSize(20, 34);
			icon.image = "http://www.google.com/mapfiles/marker" + arrayABC[routingPoints.length] + ".png";
	        var marker=new GMarker(point,icon);
	        map.addOverlay(marker);
	        routingPoints.push(marker);
	    }
	    else {
			var icon = new GIcon(baseIcon);
			icon.iconSize = new GSize(20, 34);
			icon.image = "http://www.google.com/mapfiles/marker" + arrayABC[routingPoints.length] + ".png";
	    	var marker=new GMarker(point,icon);
	        map.addOverlay(marker);
	        routingPoints.push(marker);
	    }
	    lastPoint = point;
	}
	function setDirections(fromAddress, toAddress, locale) {
	    directions.load(
	            "from: " + fromAddress + " to: " + toAddress,
	            {"locale": locale, "getPolyline": true}
	    );
	}
	
	function reset_map(){
		directions = new GDirections();
		GEvent.addListener(directions, "load",onGDirectionsLoad);
		map.clearOverlays();
		distance=0;
		document.getElementById("distance").value="";
		lastPoint=null;
		routingPoints=new Array();
		//alert("reset " + distance);
	}
	function remove_last(){
		if(routingPoints.length > 1){
			var marker=routingPoints.pop();
			map.removeOverlay(marker);
			var line=lines.pop();
			map.removeOverlay(line);
			last_distance=distances.pop();
			distance=Math.round((distance-last_distance)*1000)/1000;
			document.getElementById("distance").value=distance;
			lastPoint=routingPoints[routingPoints.length-1].getPoint();
		}else if(routingPoints.length==1){
			var marker=routingPoints.pop();
			map.removeOverlay(marker);
			document.getElementById("distance").value="";
			lastPoint=null;
		}
	}
	
	
	
	function showAddress(map, geocoder, address) {
	geocoder.getLatLng(
	address,
	function(latlng) {
	if (!latlng) {
	alert(address + " not found");
	} else {
	map.setCenter(latlng, 15);
	var marker = new GMarker(latlng);
	map.addOverlay(marker);
	marker.openInfoWindowHtml(address);
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	}
	}
	);
	}
