function Site_registerOnLoad(func) {
	var old = window.onload;
	
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			old();
			func();
		}
	}
}

function Site_registerOnUnLoad(func) {
	var old = window.onunload;
	
	if (typeof window.onunload != 'function') {
		window.onunload = func;
	} else {
		window.onunload = function() {
			old();
			func();
		}
	}
}

var gmap = '';

function mapLoad() {
	if (GBrowserIsCompatible()) {
		createMap('googlemap');
	} else {
		alert("Ihr Browser ist nicht kompatibel. Bitte benutzen Sie die aktuellste Version vom Internet Explorer oder vom Mozilla Firefox.");
	}
}

var google_street,google_city,google_x,google_y;

var google_bounds;

function setMapParams(x,y,street,city) {	// city including ZIPcode
	google_street=street;
	google_city=city;
	google_x=x;
	google_y=y;
}

function createMap(div_id) {
	gmap = new GMap2(document.getElementById(div_id));
	gmap.enableScrollWheelZoom();
	
	google_bounds = new GLatLngBounds;
		
	if (google_x || google_y) {
		var lat_lng = new GLatLng(google_x,google_y);
		gmap.setCenter(lat_lng, 15);
		gmap.savePosition();
	
		if (google_city) {
			gmap.openInfoWindowHtml(lat_lng, addPoint(lat_lng, -999, google_street, google_city));
		}
	}	
	gmap.setUIToDefault();

	if (typeof(addMorePoints)=='function') {
		addMorePoints();
		var z = gmap.getBoundsZoomLevel(google_bounds);
		var c = google_bounds.getCenter();
		gmap.setCenter(c, z);
		gmap.savePosition();
	}
}

var google_Coords = new Array();

function addPoint(x,y, street,city, id) {
	if (y == -999) latlng = x;
	else latlng = new GLatLng(x,y);
	google_bounds.extend(latlng);
	
	if (id) google_Coords[id] = latlng;
	
	var mark = new GMarker(latlng);
	gmap.addOverlay(mark);
	var html = 
		  '<div style="font-size:12px; width:220px; line-height:17px; position:relative;">'
		+ '<b style="font-size:16px; line-height:21px; color:#000000;">Adresse:</b><br>'+street+'<br>'+city+'<br><br>Route berechnen: '
		+ '<a target="_blank" title="&ouml;ffnet ein neues Fenster" href="http://maps.google.com/maps?saddr=&daddr='+encodeURIComponent(street)+','+encodeURIComponent(city)+',Germany">Hierher</a> &nbsp;&ndash;&nbsp; '
		+ '<a target="_blank" title="&ouml;ffnet ein neues Fenster" href="http://maps.google.com/maps?daddr=&saddr='+encodeURIComponent(street)+','+encodeURIComponent(city)+',Germany"> von hier'
		+ '</div>';
	GEvent.addListener(mark, 'click', function() { mark.openInfoWindowHtml(html); });

	return html;
}
