function GetMap(latitude, longitude, zoomlevel, minix, miniy, minisize) {
	map = new VEMap('myMap');
    map.SetDashboardSize(VEDashboardSize.Small);
    map.LoadMap(new VELatLong(latitude, longitude), zoomlevel, 'r', false);
	map.ShowMiniMap(minix, miniy, minisize);
}

function ResetMap(latitude, longitude, zoomlevel, minix, miniy, minisize, title, description) {
	map.SetDashboardSize(VEDashboardSize.Small);
	map.LoadMap(new VELatLong(latitude, longitude), zoomlevel, 'r', false);
	map.ShowMiniMap(minix, miniy, minisize);
	document.getElementById('txtStart').value = "";
	document.getElementById('myDirectionsDiv').innerHTML = "";
	AddPushpin(title, description);
}

function AddPushpin(title, description) {
	var shape = new VEShape(VEShapeType.Pushpin, map.GetCenter());
	shape.SetTitle(title);
	shape.SetDescription(description);
    pinid++;
    map.AddShape(shape);
}

function GetPostcode(latitude, longitude, postcode, arriveat) {
	var PostCode = postcode;
 	if (PostCode != '') {
    	if (checkPostCode (PostCode)) {
    		var origin = checkPostCode (PostCode) + ", UK";
    		map.GetRoute(origin, new VELatLong(latitude, longitude), VEDistanceUnit.Miles, VERouteType.Shortest, onGotRoute);
    	} else {
      		alert('The postcode you entered was not recognised. Please double-check your postcode and try again');
    	}
  	}
}

function FindDir(latitude, longitude, arriveat) { 
	if (checkPostCode(document.getElementById('txtStart').value)) {
   		var PostCode = document.getElementById('txtStart').value;
  		if (PostCode != '') {
    		if (checkPostCode(PostCode)) {
      			var origin = checkPostCode (PostCode) + ", UK";
      			map.GetRoute(origin, new VELatLong(latitude, longitude), VEDistanceUnit.Miles, VERouteType.Shortest, onGotRoute);
    		} else {
      			alert('The postcode you entered was not recognised. Please double-check your postcode and try again');
    		}
  		} else {
    		alert('Please enter a postcode for the beginning of the route.');
  		}
	}
}

function onGotRoute(route) {
	var routeinfo="<br />\n<br />\n<span class=\"subheader\">Route Information</span>\n<br />\n<br />\n";
    routeinfo+="<strong>Total distance: </strong>";
	routeinfo+=   route.Itinerary.Distance+" ";
	routeinfo+=   route.Itinerary.DistanceUnit+"\n<br />\n<br />";
	var steps="<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n<tr>\n<td class=\"route-tbl-hdr\"><center>Step</center></td>\n<td class=\"route-tbl-dir-hdr\">Direction</td>\n<td class=\"route-tbl-hdr\">Distance</td>";
	var len = route.Itinerary.Segments.length;
	
	for (var i =0; i < len; i++) {
		if ((i+1) < len) {
			steps+= "<tr>\n<td><center><strong>" + (i+1) + ".</strong></center></td>\n" + "<td>" + route.Itinerary.Segments[ i ].Instruction + "</td>"
			steps+= "<td>" + route.Itinerary.Segments[ i ].Distance
			steps+= " " + route.Itinerary.DistanceUnit+"</td>\n</tr>\n";
		} else {
			steps+= "<tr>\n<td><center><strong>" + (i+1) + ".</strong></center></td>\n" + "<td>Arrive at " + title +"</td>"
			steps+= "<td>" + route.Itinerary.Segments[ i ].Distance
			steps+= " " + route.Itinerary.DistanceUnit+"</td>\n</tr>\n";
		}
	}
	routeinfo+=steps+"</table>\n<br />\n";
	document.getElementById('myDirectionsDiv').innerHTML = routeinfo;
}