// JavaScript Document

	
	function DisableBirdseyePopup()
	{
		document.getElementById("MSVE_obliqueNotifyBeak").style.display = "none";
   	    document.getElementById("MSVE_obliqueNotifyContent").style.display = "none";
	}
	
	function GetDrivingDirections( bReverse, lat, lon )
	{
		var oStreet = document.getElementById("street").value;
		var oCity = document.getElementById("city").value;
		var oState = document.getElementById("state").value;
		var oZip = document.getElementById("zip").value;
		
		var dStreet = document.getElementById("dstreet").value;
		var dCity = document.getElementById("dcity").value;
		var dState = document.getElementById("dstate").value;
		var dZip = document.getElementById("dzip").value;
		
		var oAddress = GetAddressString( oStreet, oCity, oState, oZip );
		//var dAddress = GetAddressString( dStreet, dCity, dState, dZip );
		var dAddress = new VELatLong( lat, lon );
		
		var locations = null;
		if ( bReverse == false )
		{
           locations = new Array( oAddress, dAddress );
		}
		else
		{
			locations = new Array( dAddress, oAddress );
		}
		
		var routeOptions = new VERouteOptions();
		routeOptions.RouteCallback = PrintDrivingDirections;
		
		map.GetDirections( locations, routeOptions );
	}
	
	function PrintDrivingDirections( route )
	{
		var legs = route.RouteLegs;           
		var numTurns = 0;
		var leg = null;
		
		var directionsDiv = document.getElementById("drivingDirections");
		directionsDiv.innerHTML = "<h2>Door-to-Door Directions</h2>";
		
        var table =	document.createElement("table");
		table.setAttribute("id", "directions");
		table.setAttribute("class", "DirectionsTable");
		var tbody = document.createElement("tbody");
		
		var titleRow = document.createElement("tr");
		var routeCell = document.createElement("th");
		routeCell.setAttribute("class", "DirectionsTableInstructionHeader");
		//routeCell.setAttribute("style", "width:80%;line-height:16px;");
		routeCell.innerHTML = "<strong>ROUTE</strong>"
		var distCell = document.createElement("th");
		distCell.setAttribute("class", "DirectionsTableDistanceHeader");
		//distCell.setAttribute("style", "width:20%;line-height:16px;");
		distCell.innerHTML = "<strong>DISTANCE</strong>";
		
		titleRow.appendChild( routeCell );
		titleRow.appendChild( distCell );
		tbody.appendChild( titleRow );
		
		// Get intermediate legs
		for(var i = 0; i < legs.length; i++)
		{
			// Get this leg so we don't have to dereference multiple times               
			leg = legs[i];  // Leg is a VERouteLeg object                                 
			
			// Unroll each intermediate leg               
			var turn = null;  // The itinerary step                                 
			
			for(var j = 0; j < leg.Itinerary.Items.length; j ++)               
			{                  
			   turn = leg.Itinerary.Items[j];  // turn is a VERouteItineraryItem object 
			   
			   var row = document.createElement("tr")
			   var instructionCell = document.createElement("td")
			   
			   
			   
			   if ( numTurns % 2 == 1 )
			      instructionCell.setAttribute("class", "DirectionsTableInstructionCellAlt");
			   else
     		      instructionCell.setAttribute("class", "DirectionsTableInstructionCell");
               
			   if (j > 0)
			   instructionCell.innerHTML = j + '. ' + turn.Text;
			   else
			   instructionCell.innerHTML = turn.Text;
			   
			   row.appendChild( instructionCell );
			   
			   var distanceCell = document.createElement("td");
			   
			   if ( numTurns % 2 == 1 )
			      distanceCell.setAttribute("class", "DirectionsTableDistanceCellAlt");
			   else
			      distanceCell.setAttribute("class", "DirectionsTableDistanceCell");
				  
			   distanceCell.innerHTML = turn.Distance.toFixed(1) + "mi";
			   row.appendChild( distanceCell );
			                   
			   numTurns++;                  
			   tbody.appendChild( row );
			}            
		}            
        table.appendChild(tbody);
		
		//Fix for IE
		if (table.outerHTML )
		    directionsDiv.innerHTML = table.outerHTML
		//Non Microsoft Browsers
		else
		  	directionsDiv.appendChild( table );
			
		var timeDistance = document.getElementById("TimeDistance");
		timeDistance.style.display = "block";
		var estimatedTime = "Estimated Time: " + FormatTime( route.Time );
		var totalDistance = "Total Distance: " + route.Distance.toFixed(2) + " miles";
		var timeDistanceString = "" + estimatedTime + "<br />" + totalDistance;
        timeDistance.innerHTML = timeDistanceString;
	}
	
	function FormatTime( time )
	{
	       var timeString = "";

           var hours = parseInt(time / 3600);
           time = time -  (hours*3600);

           var minutes = parseInt( time / 60 );
           var seconds = time % 60;

           if ( hours > 0 )
              timeString += hours + " h ";
           if ( minutes > 0 )
              timeString += minutes + " m ";
           if ( seconds > 0 )
              timeString += seconds + " s";

           return timeString; 
	}
	
	function GetAddressString(a, c, s, z )
	{
		return a+ "," + c +"," + s + "," +z;
	}
	
	function doPrint()
	{
	    //Enable printing
		var printOpt = new VEPrintOptions(true);
		map.SetPrintOptions(printOpt);
		// Print the map 
		window.print();
	}
