// JavaScript Document


var gmarkers = [];
var htmls = [];
var to_htmls = [];
var from_htmls = [];
var i=0;

//Create our "tiny" marker icon
var icon = new GIcon();
icon.image = "/Heathrow/Markers/trpDot.png";
icon.shadow = "/Heathrow/Markers/flag-shadow.png";
icon.iconSize = new GSize(25, 25);
icon.shadowSize = new GSize(40, 30);
icon.iconAnchor = new GPoint(6, 10);
icon.infoWindowAnchor = new GPoint(5, 1);

// A function to create the marker and set up the event window
function createMarker(point,name,html) {
	var marker = new GMarker(point, icon);
	//var marker = new GMarker(point);

	// The info window version with the "to here" form open
	to_htmls[i] = html + '' +
	'<br />Enter Postcode:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
	'<span class="SubscribeLeft" style="width:70px;" ><input type="text" name="saddr" id="saddr" value="" style="width:70px;" /></span>' +
	'<span class="SubscribeLeft" style="width:90px;"><input value="Get Directions" type="SUBMIT" class="submit" style="width:90px; margin:0;" ></span><br />' +
	'<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() + '"/>' +
	'</form>';

	// The inactive version of the direction info
	html = html + '<br><a href="javascript:tohere('+i+')">Find directions To here</a><br><br>';

	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
	});
	gmarkers[i] = marker;
	htmls[i] = html;
	i++;
	return marker;
}

// functions that open the directions forms
function tohere(i) {
	gmarkers[i].openInfoWindowHtml(to_htmls[i]);
}

function fromhere(i) {
	gmarkers[i].openInfoWindowHtml(from_htmls[i]);
}

// Display the map, with some controls and set the initial location 
var map = new GMap2(document.getElementById(DivName));
map.addControl(new GSmallMapControl());
map.setCenter(new GLatLng(Latitude,Longitude), ZoomLevel);
//map.enableDoubleClickZoom();
//map.enableDragging();
//map.enableContinuousZoom();
//map.enableScrollWheelZoom();

var point = new GLatLng(Latitude,Longitude);
var marker = createMarker(point,'DAF Address','<strong>'+ DealerName + '</strong>')
map.addOverlay(marker);
