
	
	

	
	function setCoordinates(addressFrom, addressTo) {
		geocoder.getLatLng(addressFrom,function(point1) {
									if (!point1) {
										alert(address + " not found");
									} else {
										from= point1;
			
									}
									});
	  
	    geocoder.getLatLng(addressTo,function(point2) {
									if (!point2) {
										alert(address + " not found");
									} else {
										to= point2;
			
									}
									});
	}
	
	
	
	
	
	function formSubmit() {
		fromAddress=document.getElementById("test1").value;
		toAddress=startpoint;//document.getElementById("test2").value; // startpoint 
		//setCoordinates(fromAddress,toAddress);
			marker.hide();
		calculateRoute();

	}
	
	function calculateRoute()
	{
		
		//gdir.load("from: "+from.x+", "+from.y + " to: " + to.x+", "+to.y);
		gdir.load("from: "+fromAddress+" to: "+toAddress, { "locale": langcode });
	}
	
	
	var geocoder= null;
	var gdir;
	var map=null;
	var from, to;
	var fromAddress, toAddress;
	var langcode ="de_AUT"; // welche Sprache z.B.: en_US
	var marker;
    var startpoint;
	
	
	
	
	
	
	
	
    function initialize(lat, lng) {
      if (GBrowserIsCompatible()) {	    
        startpoint = new GLatLng(lat, lng);//da bei new gehören die firmencoordinatenvariablen hinein
		map = new GMap2(document.getElementById("google_map"));	
		
		map.setCenter(startpoint, 14); 
		
		geocoder = new GClientGeocoder();
		map.addControl(new GLargeMapControl());
		marker = new GMarker(startpoint);
		map.addControl(new GMapTypeControl());
		map.addOverlay(marker);


	
		
		gdir= new GDirections(map,document.getElementById("route"));
		GEvent.addListener(gdir, "error", handleErrors);
		
		//gdir.load("from : 40.712882, -73.967257 to: 41.943181,-87.770677");
		
		
	
		
        
      }
	  else 
		alert("Your Browser is not compatible!");
		
		function handleErrors(){
		 if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		 alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
		 else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
		 alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);

		 else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
		 alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

		 

		 else if (gdir.getStatus().code == G_GEO_BAD_KEY)
		 alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

		 else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
		 alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);

		 else alert("An unknown error occurred.");

		}
    }
