// Custom javascript functions
// Copyright Frédéric Serruys 2010 all rights reserved

// Display a simple textbox
function TextBox(text)
{
	alert(text);
} 

// To be deleted
function Test()
{
	alert("Test of function");
} 

// List of links to be externalized
function ExternalLinks() 
{  
	if (!document.getElementsByTagName) return;  
	var anchors = document.getElementsByTagName("a");  
	for (var i=0; i<anchors.length; i++) 
	{
		var anchor = anchors[i];  
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
		anchor.target = "_blank";
	}
}  
AddLoadEvent(ExternalLinks);

// Add an event to the load sequence (no arguments)
function AddLoadEvent(func) 
{ 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function')
	{ 
		window.onload = func
	} 
	else 
	{ 
		window.onload = function() 
		{
			oldonload();
			func();
		}
	}
}

// Add an event to the unload sequence (no arguments)
function AddUnloadEvent(func) 
{ 
	var oldonunload = window.onunload; 
	if (typeof window.onunload != 'function')
	{ 
		window.onunload = func
	} 
	else 
	{ 
		window.onunload = function() 
		{
			oldonunload();
			func();
		}
	}
}

// Init a google map
function InitMap(id, position, description) 
{		
	var map;
	var MY_MAPTYPE_ID = 'Shaolin';
	var style = 
	[
		{
			featureType: "road",
			elementType: "geometry",
			stylers: 
			[
				{ hue: "#ff0000" },
				{ saturation: 50 },
				{ lightness: -30 },
				{ visibility: "simplified" }
			]
		},
		{
			featureType: "landscape",
			elementType: "geometry",
			stylers: 
			[
				{ hue: "#FFFFFF" },
				{ saturation: 0 },
				{ lightness: 100 }
			]
		}
	];

	var mapOptions = 
	{
		zoom: 15,
		center: position,
		mapTypeControlOptions: 
		{
			mapTypeIds: [google.maps.MapTypeId.ROADMAP, MY_MAPTYPE_ID]
		},
		mapTypeId: MY_MAPTYPE_ID
	};

	map = new google.maps.Map(document.getElementById( id ), mapOptions);
		  
	var styledMapOptions = 
	{
		name: "Shaolin"
	};

	var myMapType = new google.maps.StyledMapType(style, styledMapOptions);
	
	var image = 'pictures/map_marker.png';
	var marker = new google.maps.Marker(
	{
		position: position, 
		map: map, 
		title: description,
		icon: image
	});
  
	map.mapTypes.set(MY_MAPTYPE_ID, myMapType);

	return map;
}

