﻿function displayHover(mapID, shapeID) {
    hideHover(mapID);
    var theMap = $find(mapID);
    var shape = theMap.GetShapeByID(shapeID);
    if (shape.GetType() == VEShapeType.Pushpin) {
        theMap.ShowInfoBox(shape);
    }
}

function hideHover(mapID) {
    var theMap = $find(mapID);
    theMap.HideInfoBox();
}

function getDrivingDirections(mapID, searchlat, searchlong, storelat, storelong) {
    var theMap = $find(mapID);
    theMap.HideInfoBox();
    var coords = new Array();
    coords = [new VELatLong(searchlat, searchlong), new VELatLong(storelat, storelong)];

    var options = new VERouteOptions;

    // Show as miles, could use VERouteDistanceUnit.Kilometer
    options.DistanceUnit = VERouteDistanceUnit.Mile;
    
    // Otherwise what's the point?
    options.DrawRoute = true;

    // Call this function when map route is determined:
    //options.RouteCallback = ShowTurns;

    // Default route color
    options.RouteColor = new VEColor(0, 169, 235, 0.7);

    // Default is driving, but can change to VERouteMode.Walking
    // If the RouteMode property is set to VERouteMode.Walking, the returned route will contain walking directions in the itinerary 
    // unless the VERouteOptions.UseMWS Property is set to true or the VERouteOptions.UseTraffic Property is set to true, 
    // in which case an empty VERoute object is returned. 
    // An empty VERoute object has no itinerary and the VERoute.Distance Property and VERoute.Time Property are 0.
    options.RouteMode = VERouteMode.Driving;

    // The default value for this property is MinimizeTime
    // If the RouteOptimize property is set to VERouteOptimize.MinimizeTime and 
    // the VERouteOptions.RouteMode Property is set to VERouteMode.Walking, 
    // then an empty VERoute object is returned.
    options.RouteOptimize = VERouteOptimize.MinimizeTime;

    // The default value is 6 pixels.
    options.RouteWeight = 5;

    //The default value is 4
    options.RouteZIndex = 4;

    // So the map doesn't change, the default is true
    options.SetBestMapView = false;

    // Show the disambiguation dialog, the default value is true
    options.ShowDisambiguation = false;

    // The default value is true.
    options.ShowErrorMessages = true;

    // A Boolean value specifying whether to use the MapPoint Web Service to generate the route. 
    // The default value is false.
    options.UseMWS = false;

    // The default value is false, which means the route will be calculated without considering traffic information.
    // If the property UseTraffic is set to true and the VERouteOptions.RouteOptimize property is set to VERouteOptimize.MimimizeTime, 
    // then the route calculation engine considers available traffic information and changes the route accordingly to minimize the route time.
    // If the property UseTraffic is set to true and the VERouteOptions.RouteOptimize property is set to VERouteOptimize.MimimizeDistance, 
    // then the route will not change, but available traffic information will be included in the itinerary.
    // Available traffic information is returned only if the VERouteOptions.RouteMode Property is set to VERouteMode.Driving. 
    // If the UseTraffic property is set to true and the VERouteOptions.RouteMode property is set to VERouteMode.Walking, 
    // then an empty VERoute object is returned. An empty VERoute object has no itinerary and the VERoute.Distance Property and VERoute.Time Property are 0.
    options.UseTraffic = true;
    
    //This method was causing an error: _color is undefined or something like that
    //theMap.GetDirections(coords, options);
    
    theMap.GetDirections(coords, options.DistanceUnit, options.DrawRoute, options.RouteColor, options.RouteOptimize, options.RouteWeight, options.RouteZIndex, options.SetBestMapView, options.ShowDisambiguation, options.ShowErrorMessages, options.UseMWS);
}

function getWalkingDirections(mapID, searchlat, searchlong, storelat, storelong) {
    var theMap = $find(mapID);
    theMap.HideInfoBox();
    var coords = new Array();
    coords = [new VELatLong(searchlat, searchlong), new VELatLong(storelat, storelong)];

    var options = new VERouteOptions;

    // Show as miles, could use VERouteDistanceUnit.Kilometer
    options.DistanceUnit = VERouteDistanceUnit.Mile;

    // Otherwise what's the point?
    options.DrawRoute = true;

    // Call this function when map route is determined:
    //options.RouteCallback = ShowTurns;

    // Default route color
    options.RouteColor = new VEColor(0, 169, 235, 0.7);

    // Default is driving, but can change to VERouteMode.Walking
    // If the RouteMode property is set to VERouteMode.Walking, the returned route will contain walking directions in the itinerary 
    // unless the VERouteOptions.UseMWS Property is set to true or the VERouteOptions.UseTraffic Property is set to true, 
    // in which case an empty VERoute object is returned. 
    // An empty VERoute object has no itinerary and the VERoute.Distance Property and VERoute.Time Property are 0.
    options.RouteMode = VERouteMode.Walking;

    // The default value for this property is MinimizeTime
    // If the RouteOptimize property is set to VERouteOptimize.MinimizeTime and 
    // the VERouteOptions.RouteMode Property is set to VERouteMode.Walking, 
    // then an empty VERoute object is returned.
    options.RouteOptimize = VERouteOptimize.MinimizeDistance;

    // The default value is 6 pixels.
    options.RouteWeight = 5;

    //The default value is 4
    options.RouteZIndex = 4;

    // So the map doesn't change, the default is true
    options.SetBestMapView = false;

    // Show the disambiguation dialog, the default value is true
    options.ShowDisambiguation = false;

    // The default value is true.
    options.ShowErrorMessages = true;

    // A Boolean value specifying whether to use the MapPoint Web Service to generate the route. 
    // The default value is false.
    options.UseMWS = false;

    // The default value is false, which means the route will be calculated without considering traffic information.
    // If the property UseTraffic is set to true and the VERouteOptions.RouteOptimize property is set to VERouteOptimize.MimimizeTime, 
    // then the route calculation engine considers available traffic information and changes the route accordingly to minimize the route time.
    // If the property UseTraffic is set to true and the VERouteOptions.RouteOptimize property is set to VERouteOptimize.MimimizeDistance, 
    // then the route will not change, but available traffic information will be included in the itinerary.
    // Available traffic information is returned only if the VERouteOptions.RouteMode Property is set to VERouteMode.Driving. 
    // If the UseTraffic property is set to true and the VERouteOptions.RouteMode property is set to VERouteMode.Walking, 
    // then an empty VERoute object is returned. An empty VERoute object has no itinerary and the VERoute.Distance Property and VERoute.Time Property are 0.
    options.UseTraffic = false;

    //This method was causing an error: _color is undefined or something like that
    //theMap.GetDirections(coords, options);

    theMap.GetDirections(coords, options.DistanceUnit, options.DrawRoute, options.RouteColor, options.RouteOptimize, options.RouteWeight, options.RouteZIndex, options.SetBestMapView, options.ShowDisambiguation, options.ShowErrorMessages, options.UseMWS);
}