﻿
function reverse()
{
	var to = document.getElementById("textbox_to_address").value;
	var from = document.getElementById("textbox_from_address").value;
	
	if (document.getElementById("textbox_to_address").readOnly)
	{
		document.getElementById("textbox_from_address").readOnly = true;
		document.getElementById("textbox_to_address").readOnly = false;
		document.getElementById("tofrom").innerHTML = "from";
	}
	else
	{
		document.getElementById("textbox_from_address").readOnly = false;
		document.getElementById("textbox_to_address").readOnly = true;
		document.getElementById("tofrom").innerHTML = "to";
	}
	
	document.getElementById("textbox_to_address").value = from;
	document.getElementById("textbox_from_address").value = to;
}

function MyHandleTokenError()
{
	alert("Map token is invalid.");
}
function MyHandleTokenExpire()
{
	alert("Map token has expired.");
}
	
function AddPin(map, title, description)
{
	//map.ClearInfoBoxStyles();
	
	//pin icon
	var icon = "/images/map/arrow-lg.gif";
	
	//pin
	var pin = new VECustomIconSpecification();
	pin.Image = icon;
	pin.TextContent = " ";
	pin.ImageOffset = new VEPixel(1, -2);
	
	//add pin to map
	shape = new VEShape(VEShapeType.Pushpin, map.GetCenter());
	shape.SetCustomIcon(pin);
	shape.SetTitle(title);
	shape.SetDescription(description);
	map.AddShape(shape);
}

function Zoom(map, level)
{
	map.SetZoomLevel(level);
}






function querySt(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {
			if (ft[1].length > 0) {
				return ft[1];
			}
		}
	}
}




	
/// <reference path="VeJavaScriptIntellisenseHelper.js" />

/// http://msdn.microsoft.com/en-us/library/bb412551.aspx
/// http://msdn.microsoft.com/en-us/library/cc161074.aspx

function InitMap(mapDiv)
{
    /// <summary>Default map initialization method.</summary>
    /// <param name="mapDiv" type="String">The element housing the map.</param>

    map = new VEMap(mapDiv);

    map.SetDashboardSize(VEDashboardSize.Tiny);
    map.LoadMap();

    AddLogos(mapDiv);
}

function InitMapWithAddr(mapDiv, address)
{
    /// <summary>Map with an address pinned method.</summary>
    /// <param name="mapDiv" type="String">The element housing the map.</param>
    /// <param name="address" type="String">The address to find.</param>

    HideMap(mapDiv);
    
    map = new VEMap(mapDiv);

    map.SetDashboardSize(VEDashboardSize.Tiny);
    map.LoadMap();
    
    FindAddress(map, address, FindCallback);
}

function InitMapWithLatLong(mapDiv, latitude, longitude)
{
    /// <summary>Map with a lat/long point pinned.</summary>
    /// <param name="mapDiv" type="String">The element housing the map.</param>
    /// <param name="latitude" type="Number">The latitude to center on.</param>
    /// <param name="longitude" type="Number">The longitude to center on.</param>

    var latLon = new VELatLong(latitude, longitude);

    map = new VEMap(mapDiv);
    map.SetDashboardSize(VEDashboardSize.Tiny);
    map.LoadMap(latLon, 15);

    AddPushpin(map, latLon.Latitude, latLon.Longitude, "", "Testing.1.2.3.", "/resources/images/local.com.pushpin.gif");

    AddLogos(mapDiv);
}

function AddLogos(mapDiv, veDiv, localDiv)
{
    /// <summary>Adds a smaller MSVE logo and a Local.com logo to the bottom of the map.</summary>
    /// <param name="mapDiv" type="String">The element housing the map.</param>

    var veLogoEl    = document.getElementById(veDiv);
    var localLogoEl = document.getElementById(localDiv); 
    var mapEl       = document.getElementById(mapDiv);

    // Append the logos to the map element.
    mapEl.appendChild(veLogoEl);
    mapEl.appendChild(localLogoEl);
    
    // Show the logo divs.
    veLogoEl.style.display    = "";
    localLogoEl.style.display = "";
}

function FindAddress(map, address, callback)
{
    /// <summary>Finds an address and calls the callback function.</summary>
    /// <param name="map" type="VEMap">The VEMap object.</param>
    /// <param name="address" type="String">The address to find.</param>
    /// <param name="callback">The callback function to call.</param>

    map.Find(null, address, null, null, null, null, true, false, false, false, callback);
}

function FindCallback(shape, results, place)
{
    map.Clear();

    var latlong = place[0].LatLong;
    var content = "FindCallBack";  // This would be the markup containing the custom InfoBox.

    AddPushpin(map, latlong.Latitude, latlong.Longitude, "Latitude: " + latlong.Latitude + " - Longitude: " + latlong.Longitude, content, "/resources/images/local.com.pushpin.gif");
    
    AddLogos("vemDefault");

    map.SetCenterAndZoom(latlong, 15);

    ShowMap("vemDefault");    
}

function ShowMap(mapDiv)
{
    var mapEl = document.getElementById(mapDiv).style.visibility = "visible";
}

function HideMap(mapDiv)
{
    var mapEl = document.getElementById(mapDiv).style.visibility = "hidden";
}

function AddPushpin(map, latitude, longitude, title, description, icon)
{
    /// <summary>Adds a pushpin to the map.</summary>
    /// <param name="map" type="VEMap">The VEMap object.</param>
    /// <param name="latlong" type="VELatLong">The VELatLong object containing latitude and longitude.</param>
    /// <param name="title" type="String">The title of the pushpin.</param>
    /// <param name="description" type="String">The text or markup to contain within the pushpin flyout.</param>

    var latlong = new VELatLong(latitude, longitude);
    var shape   = new VEShape(VEShapeType.Pushpin, latlong);

    map.ClearInfoBoxStyles();

    shape.SetTitle(title);
    shape.SetDescription(description);

    if (icon)
    {
        shape.SetCustomIcon(icon);
    }

    map.AddShape(shape);
}

