﻿// JScript File
var mapFrom = null;
var mapTo = null;

function initialize_maps() {

    if (mapFrom !=null) {
        mapFrom.Dispose();
    }
    if (mapTo !=null) {
        mapTo.Dispose();
    }
    
    var LA;
    
    LA = new VELatLong(34.0540, -118.2370);
    mapFrom = new VEMap('mapCanvasFrom');
    mapFrom.HideDashboard();
    mapFrom.LoadMap(LA, 14, VEMapStyle.Road, false, VEMapMode.Mode2D, true, 2) ;
    
    LA = new VELatLong(34.0540, -118.2370);
    mapTo = new VEMap('mapCanvasTo');
    mapTo.HideDashboard();
    mapTo.LoadMap(LA, 14, VEMapStyle.Road, false, VEMapMode.Mode2D, true, 2) ;
}

function route_address_click(nameFrom, descriptionFrom, latLongFrom, nameTo, descriptionTo, latLongTo) {
    $find('PopupMapDetails').show();

    initialize_maps();

    var latLong = null;
    var shapeLatLongFrom = null;
    var shapeLatLongTo = null;
    var shape = null;

    // from
    var addrFrom = document.getElementById("spanAddressFrom");
    var descFrom = document.getElementById("spanDescFrom");
    var connFrom = document.getElementById("spanConnFrom");
    var locnameFrom = document.getElementById("spanNameFrom");
    var data = descriptionFrom.split("||");
    addrFrom.innerText = data[0];
    descFrom.innerText = data[1];
    connFrom.innerText = data[2];
    locnameFrom.innerText = nameFrom;

    try {
        latLong = latLongFrom.split(",");
        shapeLatLongFrom = new VELatLong(latLong[0], latLong[1]);
        shape = new VEShape(VEShapeType.Pushpin, shapeLatLongFrom); 
        shape.SetCustomIcon(Master.ImagePath + "flashingbolt_marker.gif");
        mapFrom.AddShape(shape);
        mapFrom.SetCenter(shapeLatLongFrom);
    } catch (e) {
        alert(e.message);
    }
    
    // to
    var addrTo = document.getElementById("spanAddressTo");
    var descTo = document.getElementById("spanDescTo");
    var connTo = document.getElementById("spanConnTo");
    var locnameTo = document.getElementById("spanNameTo");
    
    data = descriptionTo.split("||");
    addrTo.innerText = data[0];
    descTo.innerText = data[1];
    connTo.innerText = data[2];
    locnameTo.innerText = nameTo;

    try {
        latLong = latLongTo.split(",");
        shapeLatLongTo = new VELatLong(latLong[0], latLong[1]);
        shape = new VEShape(VEShapeType.Pushpin, shapeLatLongTo); 
        shape.SetCustomIcon(Master.ImagePath + "flashingbolt_marker.gif");
        mapTo.AddShape(shape);
        mapTo.SetCenter(shapeLatLongTo);
    } 
    catch (e) {
        alert(e.Message);
    }
}

if(typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();