
	var geocoder, location1, location2, gDir;
 
	function initialize() {
		geocoder = new GClientGeocoder();
		gDir = new GDirections();
		GEvent.addListener(gDir, "load", function() {
			
			//gDir.getRoute(i:1);
			
			var drivingDistanceMiles = gDir.getDistance().meters / 1609.344;
			var dk = gDir.getDistance().meters / 1000;
			
			var distC=Math.ceil(dk*1.06);
			
			var ilosc=gDir.getNumRoutes();
			//distC=ilosc;
			
			
			
			
			var oplata=0;
			
			
			if(distC<21){
				oplata=0;
			}else{
				oplata=(distC/100)*50*2;
				oplata=Math.ceil(oplata);
			}
			
			
			document.getElementById('dyst_koszt').value = distC.toString()+';'+oplata.toString();

	
			document.getElementById('results').innerHTML = '<b><font  size=1 color=white>Dystans do: <i>' + location1.address + '</i> wynosi: ' + distC + ' km<br>Koszt dojazdu: ' + oplata + ' PLN</font></b>';
		});
		
	
	
	
	}
	
	
	
 
function showLocation() {
		geocoder.getLocations(document.forms[0].address.value, function (response) {
			if (!response || response.Status.code != 200)
			{
				alert("Popraw nazwę miejscowości");
				return false;

			}
			else
			{
				location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
				geocoder.getLocations(document.forms[0].address1.value, function (response) {
					if (!response || response.Status.code != 200)
					{
						alert("Popraw nazwę miejscowości");
						return false;
					}
					else
					{
						location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
						gDir.load('from: ' + location1.address + ' to: ' + location2.address);
						return true;
					}
				});
			}
			
			
		});
		
		
		
			
			
		
		
		
	}
