//<![CDATA[
var points = [];
var markers = [];
var counter = 0;
var to_htmls = [];
var from_htmls = [];
var map = null;
function onLoad(name, address, language, lat, lng, att) {

if (GBrowserIsCompatible()) {
		var mapObj = document.getElementById("map");
		if (mapObj != "undefined" && mapObj != null) {
			map = new GMap2(document.getElementById("map"));
//			map.setCenter(new GLatLng(52.519200, 13.375100), 14, G_NORMAL_MAP);
			map.setCenter(new GLatLng(lat, lng), att, G_NORMAL_MAP);
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
//			var point = new GLatLng(52.5192,13.3751);
			var point = new GLatLng(lat,lng);
			var divMarker = '<div id="gmapmarker"><div style="font-family:Verdana;font-size:11px;"><strong>'+address+'<\/strong><\/div><\/div><br/><br/>';
			var navigationTitlesArray = new Array();
			if(language=="de"){
				navigationTitlesArray = ["Route berechne", "Hierher", "Von hier", "Start", "Los!", "Ziel"];
			}else if(language=="mn"){
				navigationTitlesArray = ["Zam zaa", "Iishee yaj hurehiig", "Endees yaj yavahiig", "Ehel", "Ehel!", "Ochih gazar"];
			}else{
//				navigationTitlesArray = ["Calculate route", "to this point", "from this point", "Start address", "calculate route", "Target address"];
				navigationTitlesArray = ["", "Ийшээ очих замын маршрут", "", "Хаанаас ирэх хаягаа оруул", "Зам заа", "Target address"];
			}
			
			var marker = createMarker(point,address,divMarker, 0,"", navigationTitlesArray);
			map.addOverlay(marker);
		}
	} else {
		alert("Entschuldigung, googlemap ist nicht kompatibel mit Ihrem Browser!");
	}
}
function createMarker(point, title, html, n, tooltip, navigationTitlesArray) {

	if(n >= 0) { n = -1; }
	var marker = new GMarker(point,{'title': tooltip});
	var tabFlag = isArray(html);
	if(!tabFlag) { html = [{"contentElem": html}]; }
	to_htmls[counter] = html[0].contentElem + '<br/><br/><form class="gmapDir" id="gmapDirTo" style="white-space: nowrap;" action="http://maps.google.com/maps" method="get" target="_blank">' +
	                     '<span class="gmapDirHead" id="gmapDirHeadTo">'+navigationTitlesArray[0]+': <strong>'+navigationTitlesArray[1]+'</strong> - <a href="javascript:fromhere(' + counter + ')">'+navigationTitlesArray[2]+'</a></span>' +
	                     '<p class="gmapDirItem" id="gmapDirItemTo"><label for="gmapDirSaddr" class="gmapDirLabel" id="gmapDirLabelTo">'+navigationTitlesArray[3]+':<br /></label>' +
	                     '<input type="text" size="16" maxlength="40" name="saddr" class="gmapTextBox" id="gmapDirSaddr" value="" onfocus="this.style.backgroundColor = \'#e0e0e0\';" onblur="this.style.backgroundColor = \'#ffffff\';" />' +
	                     '<span class="gmapDirBtns" id="gmapDirBtnsTo"><input value="'+navigationTitlesArray[4]+'" type="submit" class="gmapDirButton" id="gmapDirButtonTo" /></span></p>' +
	                     '<input type="hidden" name="daddr" value="' +
	                     point.y + ',' + point.x + "(" + title.replace(new RegExp(/"/g),'&quot;') + ")" + '" /></form>';
	                      from_htmls[counter] = html[0].contentElem + '<p /><form class="gmapDir" id="gmapDirFrom" style="white-space: nowrap;" action="http://maps.google.de/maps" method="get" target="_blank">' +
	                     '<span class="gmapDirHead" id="gmapDirHeadFrom">'+navigationTitlesArray[0]+': <a href="javascript:tohere(' + counter + ')">'+navigationTitlesArray[1]+'</a> - <strong>'+navigationTitlesArray[2]+'</strong></span>' +
	                     '<p class="gmapDirItem" id="gmapDirItemFrom"><label for="gmapDirSaddr" class="gmapDirLabel" id="gmapDirLabelFrom">'+navigationTitlesArray[5]+':<br /></label>' +
	                     '<input type="text" size="16" maxlength="40" name="daddr" class="gmapTextBox" id="gmapDirSaddr" value="" onfocus="this.style.backgroundColor = \'#e0e0e0\';" onblur="this.style.backgroundColor = \'#ffffff\';" />' +
	                     '<span class="gmapDirBtns" id="gmapDirBtnsFrom"><input value="'+navigationTitlesArray[4]+'" type="submit" class="gmapDirButton" id="gmapDirButtonFrom" /></span></p>' +
	                     '<input type="hidden" name="saddr" value="' +
	                     point.y + ',' + point.x + encodeURIComponent("(" + title.replace(new RegExp(/"/g),'&quot;') + ")") + '" /></form>';
	                     html[0].contentElem = html[0].contentElem + '<p /><div id="gmapDirHead" class="gmapDir" style="white-space: nowrap;">'+navigationTitlesArray[0]+': <a href="javascript:tohere(' + counter + ')">'+navigationTitlesArray[1]+'</a> - <a href="javascript:fromhere(' + counter + ')">'+navigationTitlesArray[2]+'</a></div>';
	if(!tabFlag) { html = html[0].contentElem; }if(isArray(html)) { GEvent.addListener(marker, "mouseover", function() { marker.openInfoWindowTabsHtml(html); }); }
	else { GEvent.addListener(marker, "mouseover", function() { marker.openInfoWindowHtml(html); }); }
	points[counter] = point;
	markers[counter] = marker;
	counter++;
	return marker;
}
function isArray(a) {return isObject(a) && a.constructor == Array;}
function isObject(a) {return (a && typeof a == 'object') || isFunction(a);}
function isFunction(a) {return typeof a == 'function';}
function showInfoWindow(idx,html) {
map.centerAtLatLng(points[idx]);
markers[idx].openInfoWindowHtml(html);
}
function tohere(idx) {
markers[idx].openInfoWindowHtml(to_htmls[idx]);
}
function fromhere(idx) {
markers[idx].openInfoWindowHtml(from_htmls[idx]);
}
//]]>