function CreateIcon(colour)
{
	var i = new GIcon();
	
	if(colour)
		i.image = m[colour].src;
	else
		i.image = m['marker'].src;
	
	i.shadow = m['shadow'].src;
	
	i.iconSize = new GSize(12, 20);
	i.shadowSize = new GSize(22, 20);
	i.iconAnchor = new GPoint(5, 20);
	i.infoWindowAnchor = new GPoint(8, 1);
	
	return i;
}

function CreatePlaceMarker(icon, e) 
{
	var marker = new GMarker(new GLatLng(e.Latitude, e.Longitude), icon);

	// Show this marker's name in the info window when it is clicked
	var content = '<h1><b>' + e.Name + '</b></h1><p>' + e.Description + '</p>';
	
	GEvent.addListener(marker, "click", function() { ShowKTAInfoWindow(this.getPoint(), content); } );	
	
	return marker;
}

function CreateEstablishmentMarker(icon, e, show) 
{
	var marker = new GMarker(new GLatLng(e[0].Latitude, e[0].Longitude), icon);

	// Show this marker's name in the info window when it is clicked
	var content = new Array('<h1>Postcode <b>' + FormatPostcode(e[0].Postcode) + '</b></h1>');
	
	for(var x=0; x<e.length; x++)
		content[content.length] = '<h2><a href="estdetails.asp?id=' + e[x].ID + '">' + e[x].Name + '</a></h2>';
	
	GEvent.addListener(marker, "click", function() { ShowKTAInfoWindow(this.getPoint(), content.join('')); } );	
	
	if(show) ShowKTAInfoWindow(marker.getPoint(), content.join(''));
	
	return marker;
}

function ShowKTAInfoWindow(point, content)
{
	iw.set(content, point);
	map.panTo(point);
}

// Client side postcode formatter
function FormatPostcode(p)
{
	p = String(p);
	
	var op = p.substring(0, p.length - 3);
	var ip = p.substring(p.length - 3);
	
	return op + ' ' + ip;
}