    var map = null;
    var mapCenter = new VELatLong(53.808760650677456, -1.510620117187513);
    var mapZoom = 15;
    var readyToProceed = true;
    var mapPostcode = ''
    
    function loadMap(MapID, mapPcode)
    {
    mapPostcode = mapPcode;
        if (readyToProceed) {
            readyToProceed = false;

            map = new VEMap(MapID);
            map.SetDashboardSize(VEDashboardSize.Small);

            map.LoadMap();
            map.Find('', mapPcode, null,null, null,null,true,true,false, true,AddPostcodePin);        
        }
        else {
            window.setTimeout(function() {
                loadMap(MapID, mapPcode);
            }, 100);
        }
    }
    
//    function getRoute(startPostCode)
//    {
//        var options = new VERouteOptions();
//        options.RouteCallback = onGotRoute;
//        options.RouteOptimize = VERouteOptimize.MinimizeDistance;
//        results = map.GetDirections([document.getElementById('startPCode').value, mapPostcode], options);
//    }
    
    function AddPostcodePin(layer, resultsArray, places, hasMore, veErrorMessage)
    {
               var pin = new VEShape(VEShapeType.Pushpin, places[0].LatLong);
                map.SetCenter(places[0].LatLong);
                map.SetZoomLevel(mapZoom);
                map.AddShape(pin);
                readyToProceed = true;
    }

    function fnFocusClear(oControl, sString)
    {
        if (oControl.value == sString) oControl.value = '';
    }

    function onGotRoute(route)
    {
       // Unroll route
       var legs     = route.RouteLegs;
       var turns    = "<b>Total distance: " + route.Distance.toFixed(1) + " miles</b><br>";
       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) + " miles)<br>";
           }
        }

        document.getElementById('directions').innerHTML = turns;
     }

    
    function addLoadEvent(func) 
    {
      var oldonload = window.onload;
      if (typeof window.onload != 'function') 
      {
        window.onload = func;
      } 
      else
      {
        window.onload = function()
        {
          if (oldonload) 
          {
            oldonload();
          }
          func();
        }
      }
    }

//    function addPostcodeLocation(postcode)
//    {
//        results = map.Find('', postcode, null,null, null,null,true,true,true, true,AddPostcodePin);
//    }

