﻿

var map;

function pageLoad(sender, args) {
    if (!args.get_isPartialLoad()) {
        //  create and the map
        map = new VEMap('myMap');
        //  put the dashboard into tiny mode
        map.SetDashboardSize(VEDashboardSize.Tiny);
    }
}

function setMapOfferData(title, description) {
    document.getElementById("ctl00_MainContent_offerTitle").value = title;
    document.getElementById("ctl00_MainContent_offerDescription").value = description;
}

function showMap(place) {
    //  show the popup
    $get('ctl00_MainContent_btnShowPopup').click();

    var selMode = VEMapMode.Mode2D;
    var zoom = 10;
    var latLon = new VELatLong(40.26, -3.46);
    var fixed = 0;

    //  relaod the map
    map.LoadMap(latLon, zoom, 'r', fixed, selMode, null);

    map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);

    map.Find(null,    // what
              place, // where
              null,    // VEFindType (always VEFindType.Businesses)
              null,    // VEShapeLayer (base by default)
              null,    // start index for results (0 by default)
              1,    // max number of results (default is 10)
              false,    // show results? (default is true)
              null,    // create pushpin for what results? (ignored since what is null)
              null,    // use default disambiguation? (default is true)
              true,    // set best map view? (default is true)
              GeocodeCallback);  // call back function       

}

function GeocodeCallback(shapeLayer, findResults, places, moreResults, errorMsg) {
    // if there are no results, display any error message and return
    if (places == null) {
        return;
    }

    var bestPlace = places[0];

    // Add pushpin to the *best* place
    var location = bestPlace.LatLong;

    var newShape = new VEShape(VEShapeType.Pushpin, location);

    newShape.SetCustomIcon("<div class='pinStyle1'></div>");

    var desc = "Latitude: " + location.Latitude + "<br>Longitude:" + location.Longitude;
    //newShape.SetDescription(desc);
    newShape.SetDescription(document.getElementById("ctl00_MainContent_offerDescription").value);
    newShape.SetTitle(document.getElementById("ctl00_MainContent_offerTitle").value);
    map.AddShape(newShape);
}

function ShowModalPopup() {
    $find("ModalBehaviour").show();
}

function HideModalPopup() {
    $find("ModalBehaviour").hide();
}
        