﻿var map = null;
var findPlaceResults = null;
function GetMap()
{
    map = new VEMap('map'); 
    map.LoadMap()
    map.Find(null, document.getElementById('ctl00_ContentPlaceHolder1_tbFinish').value, null, null, null, null, true, true, null, true, GetCoordinates);
    map.LoadTraffic(true);
    map.HideScalebar();
    map.ShowMiniMap(338, 250);      
    map.ShowTrafficLegend(65,30);
    map.SetTrafficLegendText("Traffic");
    map.AttachEvent("onmousewheel", wheelCallback);
    logoURL = "http://www.myuptownfun.com/logos/customers/120x120/" + document.getElementById('ctl00_ContentPlaceHolder1_hdLogoURL').value
    //if (map.IsBirdseyeAvailable())
    //{
    //map.SetMapStyle(VEMapStyle.Birdseye);
    //}
    //else
    //{
    //map.SetMapStyle(VEMapStyle.Birdseye);
    //}
    //map.AttachEvent("onobliqueenter", OnObliqueEnterHandler);
}
//function OnObliqueEnterHandler()
//{
//if (map.IsBirdseyeAvailable())
//{
   //map.SetMapStyle(VEMapStyle.Birdseye);

   // So we don't repeatedly reset map style
   //map.DetachEvent("onobliqueenter", OnObliqueEnterHandler);
//}
//}
function GetCoordinates(layer, resultsArray, places, hasMore, veErrorMessage)
{
    var icon = new VECustomIconSpecification();
    icon.Image = "http://www.myuptownfun.com/resources/images/icons/cross.png";
    //icon.ImageOffset = new VEPixel(0, -13);
    findPlaceResults = places[0].LatLong;
    var myShape = new VEShape(VEShapeType.Pushpin, findPlaceResults);
    myShape.SetCustomIcon(icon);
    myShape.SetTitle('<div align=center><span style=color:#336699;>' + document.getElementById('ctl00_ContentPlaceHolder1_hdAdvName').value + '</span><br /><img src=' + logoURL + '></div>');
    myShape.SetDescription(document.getElementById('ctl00_ContentPlaceHolder1_hdAddress').value + '<br />' + document.getElementById('ctl00_ContentPlaceHolder1_hdPhone').value);
    //myShape.SetMoreInfoURL("http://msdn.microsoft.com");
    //myShape.SetPhotoURL("http://www.myuptownfun.com/logos/customers/120x120/33-u1.jpg");
    map.AddShape(myShape);     
} 
function wheelCallback(e)
{
     return true;
}
function FindDir()
{
    map = new VEMap('map');
    map.LoadMap();
    var to = document.getElementById('ctl00_ContentPlaceHolder1_tbFinish').value;
    var from = document.getElementById('ctl00_ContentPlaceHolder1_tbStart').value;
    map.GetRoute(from,to,null,null,onGotRoute); 
} 
function onGotRoute(route)
{
    var routeinfo="<p align='center' class='font6'>Total distance: "+route.Itinerary.Distance+" "+route.Itinerary.DistanceUnit+"</p>";
    var steps="<ol>";
    var len = route.Itinerary.Segments.length;
    for(var i = 0; i<len ;i++)
{
    steps+="<li class='font6'>"+route.Itinerary.Segments[i].Instruction+" -- (";
    steps+=route.Itinerary.Segments[i].Distance+") "+route.Itinerary.DistanceUnit+"</li>";
}
    routeinfo+= steps + "</ol>";
    DoAlert(routeinfo);
}
function DoAlert(text)
{
    var d=document.getElementById("alertdiv");
    d.style.visibility="visible";
    document.getElementById("alerttext").innerHTML = text;
}
