
function addEvent(obj, evType, fn)
{
 if (obj.addEventListener)
 { 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } 
 else if (obj.attachEvent){ 
   var r = obj.attachEvent('on'+evType, fn);
   return r; 
 } 
 else 
 { 
   return false; 
 } 
}

function formatNumber(number)
{
	var str = number + '';
	str = str.replace('.',',');
	return str;
}

function createMarker(lat, lon, showinfo, infotext, titletext, activatelink, href, markerImageUrl, clickMarkers, iconSizeWidth, iconSizeHeight)
{
	var myIcon = new GIcon(G_DEFAULT_ICON);
    myIcon.image = markerImageUrl;
    myIcon.printImage = markerImageUrl;
	if (iconSizeWidth > 0)
	{	
		myIcon.iconSize = new GSize(iconSizeWidth, iconSizeHeight);
		myIcon.iconAnchor = new GPoint( Math.round(iconSizeWidth/2), Math.round(iconSizeHeight/2));
	}
	myIcon.shadowSize = new GSize(0, 0);
	var opt   
	opt = {}   
	opt.icon = myIcon     
	opt.clickable = clickMarkers  
	opt.dragCrossMove = true  
	opt.bouncy=false
	opt.title=titletext

	var marker = new GMarker( new GLatLng(lat, lon), opt );
	if(showinfo)
		marker = activateInfoWindow(marker,infotext);
	if(activatelink)
		marker = activateLink(marker,href);
	return marker;
}

function activateInfoWindow(marker, info) 
{
	GEvent.addListener(marker, 'mouseover', function() { marker.openInfoWindowHtml(info); });
	GEvent.addListener(marker, 'mouseout', function() { marker.closeInfoWindow(); });
	return marker;
}
function activateLink(marker, href) 
{
	GEvent.addListener(marker, 'click', function() { window.location=href });
	return marker;
}

function addMapMarkers(map, arr)
{
	for(var i = 0; i < arr.length; i++)
	{
		map.addOverlay( arr[i] );
	}
}


function initMapWithMarkers(mapid, lat, lng, zoom, markers, smallcontrol, largecontrol, zoomcontrol, scalecontrol, maptypecontrol, overviewmapcontrol)
{
	return function() 
	{
		if (GBrowserIsCompatible()) 
		{
			var map = new GMap2(document.getElementById(mapid));
			var point = new GLatLng(lat, lng);
			map.setCenter(point, zoom);
			addMapMarkers(map, markers);
			if(smallcontrol)
				map.addControl(new GSmallMapControl());
			if(largecontrol)
				map.addControl(new GLargeMapControl());
			if(zoomcontrol)
				map.addControl(new GSmallZoomControl());
			if(scalecontrol)
				map.addControl(new GScaleControl());
			if(maptypecontrol)
				map.addControl(new GMapTypeControl());
			if(overviewmapcontrol)
				map.addControl(new GOverviewMapControl());
			if(typeof(customMapInit) == 'function')
			{
				customMapInit(map);
			}
		}
	}
}
