﻿var map = null;
var location1;

function GetMap() {
    map = new VEMap('mymapdiv');
    map.LoadMap(new VELatLong(53.39948880287169, -3.0179286639589326), 7, 'r', false);
    location1 = AddPin(new VELatLong(53.39948880287169, -3.0179286639589326), "Scantec", "Tel: 0151 666 8999<br/>Email: info@scantec.co.uk");
}
function GetDirections() {
    document.getElementById("divShowDirections").innerHTML = "Calculating Route, Please Wait...";
    var options = new VERouteOptions();
    options.RouteCallback = onGotRoute;
    var postcode = document.getElementById("postcode").value;
    map.GetDirections([postcode, new VELatLong(53.39948880287169, -3.0179286639589326)], options);
}
function onGotRoute(route) {
    // Unroll route
    var legs = route.RouteLegs;
    var turns = "<p>Total distance: " + route.Distance.toFixed(1) + " mi</p>";
    var numTurns = 0;
    var leg = null;
    // Get intermediate legs
    for (var i = 0; i < legs.length; i++) {
        // Get this leg so we don't have to derefernce multiple times
        leg = legs[i];  // Leg is a VERouteLeg object
        // Unroll each intermediate leg
        var turn = null;  // The itinerary leg
        for (var j = 0; j < leg.Itinerary.Items.length; j++) {
            turn = leg.Itinerary.Items[j];  // turn is a VERouteItineraryItem object
            numTurns++;
            turns += numTurns + ".\t" + turn.Text + " (" + turn.Distance.toFixed(1) + " mi)<br />";
        }
    }
    document.getElementById("divShowDirections").innerHTML = turns.replace("\n", "<br/>");
}
function AddPin(point, title, description) {
    var pin = map.AddPushpin(point);
    pin.SetTitle(title);
    pin.SetDescription(description);
    return pin;
}
function SelectLocation(location) {
    var pin = map.AddPushpin(point);
    pin.SetTitle(title);
    pin.SetDescription(description);
    return pin;
}

$(function() {
    GetMap();
});
