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() {
	createMap('googlemap');
}

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) {
	
	var myOptions = {
		zoom: 15,
		center: new google.maps.LatLng(53.7439704, 9.6908144),
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	
	google_bounds = new google.maps.LatLngBounds;

	if (google_x || google_y) {
		var lat_lng = new google.maps.LatLng(google_x, google_y);

		var myOptions = {
			zoom: 15,
			center: lat_lng,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
	
		gmap = new google.maps.Map(document.getElementById(div_id), myOptions);
	
		if (google_city) {
			addPoint(lat_lng, -999, 1, google_street, google_city);
		}
	} else {
		gmap = new google.maps.Map(document.getElementById(div_id), myOptions);
	}

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

var google_Coords = new Array();

function addPoint(x, y, directshow, street, city, id) {
	var latlng;

	if (y == -999) 	
		latlng = x;
	else 
		latlng = new google.maps.LatLng(x, y);

	google_bounds.extend(latlng);

	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>';

	var infowindow = new google.maps.InfoWindow({
		content: html
	});
			
	var marker = new google.maps.Marker({
		position: latlng,
		map: gmap
	});
			
	google.maps.event.addListener(marker, 'click', function() {
  	infowindow.open(gmap, marker);
	});
	
	if (directshow == 1)
		setTimeout(function() { infowindow.open(gmap, marker);}, 500);

	if (id) google_Coords[id] = latlng;
}

/* ALT
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;
}
*/
