function showRoute()
{
	document.getElementById("routepanel").innerHTML="";
	rMap = new GMap2(document.getElementById("map_canvas"));
	var routePanel = document.getElementById("routepanel");
	var addressTo = document.getElementById("endaddress").value;
	var addressFrom = document.getElementById("startaddress").value;

	if(addressFrom != "" && addressTo != "")
	{
		if(addressTo != "" && addressTo != "Address")
		{
			showRoutePanel();
			var totalRoute = "from:" + addressFrom + " to: " + addressTo;
			directions = new GDirections(rMap, routePanel);
			GEvent.addListener(directions, "error", handleErrors);
			directions.load(totalRoute);
		}
		else
		{
			alert("Please enter an address.");
		}
	}
	else
	{
		alert("Sorry, target address is not available.");
	}
}


function loadMap(){ 
	if(GBrowserIsCompatible()) {
	    var map = new GMap2(document.getElementById("map_canvas"));
	    var marker = new GMarker(new GLatLng(47.260812,11.398447));
	    var html = '<div class="bubble"><strong>Billard - at Charly\'s Friends</strong><p>Adamgasse 23<br />Innsbruck</p></div>';
	    map.addOverlay(marker);
	    marker.openInfoWindowHtml(html);
	    map.setCenter(new GLatLng(47.260812,11.398447), 16);
	    map.setUIToDefault();
	}
}


function showRoutePanel()
{
	$('#routepanel').animate({height: 250},'slow');
	$('#directionsform').slideUp();
	$('#closebutton').slideDown();
}

function hideRoutePanel()
{
	$("#routepanel").slideUp();
	$('#closebutton').slideUp();
	$('#directionsform').slideDown();
	loadMap();
}


function handleErrors(){
	if (directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	{
		alert("Diese Adresse konnte nicht gefunden werden.\nEntschuldigung!\nBitte probieren Sie eine andere.");
	}
	else if (directions.getStatus().code == G_GEO_SERVER_ERROR)
	{
		alert("Unbekannter Fehler.\nDOH!");
	}
	else if (directions.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: " + directions.getStatus().code);
	}
	else if (directions.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: " + directions.getStatus().code);
	}
	else if (directions.getStatus().code == G_GEO_BAD_REQUEST)
	{
		alert("Die Adresse konnte nicht richtig aufgelöst werden.\nEntschuldigung!");
	}
	else 
	{
		alert("Unbekannter Fehler.\nDoh!");
	}
}

