﻿// JScript File
var map = null;
var zoomLevel = 16;
var index = 0;
var results = null;
var center = new VELatLong(34.04849484611966, -118.2397985458374);

function GetMap()
{
    map = new VEMap('myMap');
    map.LoadMap(center, zoomLevel);
    map.SetMapMode(VEMapMode.Mode2D);
    map.SetMapStyle(VEMapStyle.Hybrid);
    map.Hide3DNavigationControl();
    AddAllKioskPins();
}

function AddPinByLatLong(latitude, longitude, title, address, index)
{
    map.Clear();
    // Add a new pushpin to the given latitude and longitude
    var latlong = new VELatLong(latitude, longitude);
    try
    {
        var shape = new VEShape(VEShapeType.Pushpin, latlong);
        shape.SetTitle(title);
        shape.SetDescription(address);
        shape.SetCustomIcon("<span style='font-size:12pt; color:black; background-color:#ff5500;'>&nbsp;" + index + "&nbsp;</span>"); 
        map.AddShape(shape);
        map.SetCenter(latlong);
    }
    catch(e)
    {
        alert(e.message);
    }
    AddAllKioskPins();
}

function AddKioskPinByLatLong(latitude, longitude, title, address, index)
{
    // Add a new pushpin to the given latitude and longitude
    var latlong = new VELatLong(latitude, longitude);
    try
    {
        var shape = new VEShape(VEShapeType.Pushpin, latlong);
        shape.SetTitle(title);
        shape.SetDescription(address);
        shape.SetCustomIcon("<span style='font-size:12pt; color:white; background-color:#5555ff;'>&nbsp;" + index + "&nbsp;</span>"); 
        map.AddShape(shape);
    }
    catch(e)
    {
        alert(e.message);
    }
}

function GetRouteMap()
{
    var startAddr = document.getElementById('StartAddress');
    var endAddr = document.getElementById('EndAddress');
    if (startAddr.value != "" && endAddr.value != "")
    {
        var locations = new Array(startAddr.value, endAddr.value);
        var options = new VERouteOptions;
        options.DrawRoute = true;
        options.SetBestMapView = true;
        options.DistanceUnit = VERouteDistanceUnit.Mile;
        options.ShowDisambiguation = true;
        options.RouteOptimize = VERouteOptimize.MinimizeDistance;
        map.GetDirections(locations, options);
    }
}

function ClearAllExceptKiosks()
{
    var startAddr = document.getElementById('StartAddress');
    var endAddr = document.getElementById('EndAddress');    
    startAddr.value = "";
    endAddr.value = "";
    map.DeleteRoute();
    map.Clear();
    map.SetMapMode(VEMapMode.Mode2D);
    map.SetMapStyle(VEMapStyle.Hybrid);
    map.Hide3DNavigationControl();
    AddAllKioskPins();
    map.SetCenterAndZoom(center, zoomLevel);
}

//// Additional Use
//function AddPin()
//{
//    // Add a new pushpin to the center of the map.
//    var center = map.GetCenter();
//    try
//    {
//        var pin = map.AddPushpin(center);
//        pin.SetTitle('Civic Resource Group');
//        pin.SetDescription('915 Wilshire Blvd., Los Angeles, CA 90017<br>Phone');
//    }
//    catch(e)
//    {
//        alert(e.message);
//    }
//}

//function FindLoc(numResults)
//{
//    try
//    {
//        var txtWhat = document.getElementById('txtWhat');
//        var txtWhere = document.getElementById('txtWhere');
//        results = map.Find(txtWhat.value, txtWhere.value, null, null, index, numResults, 
//                            true, true, true, true, MoreResults);
//        index = parseInt(index) + 9;
//    }
//    catch(e)
//    {
//        alert(e.message);
//    }
//}

//function MoreResults(a, b, c, d, e)
//{
//    if(d != false)
//    {
//        var r = "<a href='#' onclick='FindLoc(parseInt(txtNumResults.value));'>Click for More Results</a>";
//        document.getElementById('results').innerHTML = r;
//    }
//    else
//    {
//        index = 0;
//        var txtNumResults = document.getElementById('txtNumResults');
//        number = Number(txtNumResults.value);   
//        document.getElementById('results').innerHTML = "";
//        document.getElementById('results').innerHTML = "No More Results Available";
//    }
//}
//// Additional Use