﻿var map = null;
var numberOfResults = 1;
var showResult = true;
var createResult = true;
var centerLatLng = null;
var disambiguation = false;

window.onload = function()
{
    //Get the Address from id'd elements on the page
    var address = document.getElementById("Address").innerHTML;
    var postcode = document.getElementById("Postcode").innerHTML;
    document.getElementById("Postcode").style.display = "none";
    GetMap();
    FindLoc(address, postcode);
};


function callback(a, b, foundPlaces, d, e) {
    centerLatLng = map.GetCenter();
    map.SetCenterAndZoom(centerLatLng, 15);
    var place = null;
    var shape = null;
    //Check we found atleast 1 place
    //If we did stick the pin in
    if (foundPlaces.length >= 1) {
        //Get the first place found
        place = foundPlaces[0];
        //Create a Shape (Pushpin)
        shape = new VEShape(VEShapeType.Pushpin, place.LatLong);
        map.AddShape(shape);
    }
}

function GetMap() {
    map = new VEMap('map');
    map.SetDashboardSize(VEDashboardSize.Tiny);
    map.LoadMap(null, 15, VEMapStyle.Road, false, VEMapMode.Mode2D, false, 0, null);
}
function FindLoc(address, postcode) {
    try {
        map.Find(null, address + ", " + postcode + ",UK", null, null, 0, numberOfResults, showResult, createResult, disambiguation, true, callback);
    }
    catch (e) {
        alert(e.message);
    }
}
