function URLEncode(str)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";
	var encoded = "";
	for (var i = 0; i < str.length; i++ ) 
	{
		var ch = str.charAt(i);
		if (ch == " ") {
			encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
			encoded += ch;
		} else {
			var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
				alert( "Unicode Character '" 
						+ ch 
						+ "' cannot be encoded using standard URL encoding.\n" +
						  "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}
function loadMap() 
{
	var html = '<p><strong>KRC Genk - Cristal Arena<\/strong><br\/>Stadionplein 4, B-3600 Genk<\/p><p>Routeplanner -- Vertrek :<br /><input type="text" id="start" style="width:250px;" \/><br\/><span>bv. Groenplein 1, 3500 Hasselt, Belgium<\/span><\/p><p><input type="button" onclick="getRoute()" value="Plan route" /><\/p>';
			   
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map") );
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(51.005114, 5.533054), 13, G_NORMAL_MAP);
		//map.setCenter(new GLatLng(51.005114, 5.533054), 15, G_HYBRID_MAP);
		// Place a marker in the center of the map and open the info window automatically
		var marker = new GMarker(map.getCenter());
		GEvent.addListener(marker, "click", function() {
		  marker.openInfoWindowHtml(html);
		});
		map.addOverlay(marker);
		marker.openInfoWindowHtml(html);
	}
}
function getRoute()
{
	var daddr = 'Stadionplein 4,+3600+Genk,+Belgium';
	var saddr = URLEncode(document.getElementById("start").value);
	window.open('http://maps.google.com/maps?saddr='+saddr+'&daddr='+daddr, '_blank');
}
