var oGMap = null;
var oMarker = null;
var sSearchAddress = "";
var sDisplayAddress = "";
//---------------------------------------------------------------------------------------
function initMap(sStreet, sPostalCode, sCity, trigger, land) {
	if (GBrowserIsCompatible()) {
		oGMap = new GMap2(document.getElementById("map_canvas"));
		oGMap.addControl(new GLargeMapControl());
		oGMap.addControl(new GMapTypeControl());
		oGMap.addControl(new GOverviewMapControl());
		if(!land) {
            land = "Belgium";
		}
		sSearchAddress = sStreet + "," + sCity + ","+land;
		if(!trigger || trigger == '') {
            sDisplayAddress  = "<p><strong>Berlitz " + sCity + "</strong><br />";
			sDisplayAddress += "<br />" + sStreet + "<br />" + sPostalCode + " "+ sCity + "</p>";
		} else {
			sDisplayAddress  = "<p style='font-size:11px;line-height:12px;'><strong>"+trigger+" </strong><br />";
			sDisplayAddress += "<br />" + sStreet + "<br />" + sPostalCode + " "+ sCity + "</p>";
		}
		var oGeocoder = new GClientGeocoder();
		oGeocoder.getLocations(sSearchAddress, addAddressToMap);
	}
}
//---------------------------------------------------------------------------------------
function createMarker(latlng) {
	/*
	var icon = new GIcon();
	icon.image = "http://www.berlitz.de/Berlitz_DE/images/berlitz.png";
	//icon.shadow = "http://www.berlitz.de/Berlitz_DE/images/berlitz.PNG";
	icon.iconSize = new GSize(98, 52);
	//icon.shadowSize = new GSize(66, 33);
	icon.iconAnchor = new GPoint(20, 40);
	icon.infoWindowAnchor = new GPoint(0, 20);
	oMarker = new GMarker(latlng, icon);
	*/
	oMarker = new GMarker(latlng);
	var oInfoWin = oGMap.getInfoWindow();
	GEvent.addListener(oMarker, "click", function() {
		(oInfoWin.isHidden()) ? oMarker.openInfoWindowHtml(sDisplayAddress) : oMarker.closeInfoWindow();
	});
	return oMarker;
}
//---------------------------------------------------------------------------------------
function addAddressToMap(response) {
	if (!response || response.Status.code != 200) {
        alert("Sorry, we were unable to geocode that address: " + sSearchAddress);
	} else {
		place = response.Placemark[0];
		oPoint = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
		oGMap.setCenter(oPoint, 15);
		oGMap.addOverlay(createMarker(oPoint));
		oMarker.openInfoWindowHtml(sDisplayAddress);
	}
}
//---------------------------------------------------------------------------------------
function cleanUp() {
	if (oGMap) {
		GUnload();
	}
}
//---------------------------------------------------------------------------------------
function subform(sStrasse, sPlz, sOrt)
{
	strasse = document.getElementById('strasse').value;
	plz = document.getElementById('plz').value;
	ort = document.getElementById('ort').value;

	if(strasse != "")
	{
		strasse += "+";
	}
	if(plz != "")
	{
		plz += "+";
	}

    document.getElementById('relink').value = "http://maps.google.be/maps?f=d&hl=dk&geocode=&saddr="+strasse+plz+ort+"&daddr="+sStrasse+",+"+sPlz+"+"+sOrt;
	//document.getElementById('strasse').value = document.getElementById('Anfahrt').action;
	//alert(document.getElementById('Anfahrt').action);
	return true;
}
