function GetMiniMap1() {
                try{
                     var latitude =document.getElementById('latitude').value;
                     var longitude=document.getElementById('longitude').value;
                     var map = new VEMap('myMap1');
                        map.SetDashboardSize(VEDashboardSize.Tiny);
                        //map.LoadMap(new VELatLong(latitude,longitude),13,VEMapStyle.Road,1,null,1);
                        var options = new VEMapOptions();   
		        options.EnableBirdseye = false;  
                        map.LoadMap(new VELatLong(latitude,longitude),12,VEMapStyle.Road, 1, null, false, 1, options);
                        var pin = new VEShape(VEShapeType.Pushpin,new VELatLong(latitude,longitude));
                        var customIcon ="<div class='pinStyle2'></div>";
                        pin.SetCustomIcon(customIcon);
                        map.AddShape(pin);

                }
                catch(e){
               //    alert(e.faultCode?e.faultCode:e.message?e.message:e);
                }
}

var map2 = null;
var center2 = null;
var zoom2 = null;

function GetMiniMap4() {
                try{
                     var latitude =document.getElementById('latitude').value;
                     var longitude=document.getElementById('longitude').value;
                     map2 = new VEMap('myMap4');
                     map2.HideDashboard();
                     var options = new VEMapOptions();   
		       map2.LoadMap(new VELatLong(latitude,longitude),12,VEMapStyle.Road, null, null, false, 0, options);
			AddMyControl2();
			map2.ClearInfoBoxStyles();
                     var pin = new VEShape(VEShapeType.Pushpin,new VELatLong(latitude,longitude));
                     var customIcon ="<div class='pinStyle2'></div>";
                     pin.SetCustomIcon(customIcon);
                     map2.AddShape(pin);
			center2=map2.GetCenter();
             	    	zoom2=map2.GetZoomLevel();
                }
                catch(e){
               	//alert(e.faultCode?e.faultCode:e.message?e.message:e);
                }
}

         var map;
	  function GetMap()
         {
         try{

	      var toFrm = document.getElementById('toOrFrm').value;
	      var lati =document.getElementById('latitude').value;
             var longi=document.getElementById('longitude').value;
             map = new VEMap('myMap');
	      map.HideDashboard();
	      //map.onLoadMap = function(){ center=map.GetCenter(); zoom=map.GetZoomLevel();};
             var options = new VEMapOptions();
             map.LoadMap(new VELatLong(lati,longi),12,VEMapStyle.Road, null, null, false, 0, options);
	      //map.LoadMap(new VELatLong(lati,longi),12, 'r', false);
             AddMyControl();
             map.ClearInfoBoxStyles();
             //AddPushpin();
             //map.AttachEvent("onclick",ClickHandler);
             //store the center and zoom for the resetMap function
             GetRouteMap('noReset',toFrm);
	      
	  }catch(e){
		//alert(e.faultCode?e.faultCode:e.message?e.message:e);
	  }
         }



         function GetRouteMap(from,toFrmVal)
         {
	   try{
         	var locations;
		var forAdd1 = toFrmVal;
		var toAdd = "";
		var x1;
	   if( forAdd1 == "buttonTo" || forAdd1 == ""){
              var add1 = document.getElementById('add1').value;
		var cit = document.getElementById('cit').value;
		var st = document.getElementById('st').value;
		var zip = document.getElementById('zip').value;
		//document.getElementById('MSVE_obliqueNotification').style.visibility = "hidden";
		//var toAdd = null;
		//if(add1 != null){
		toAdd = add1 + " " + cit + " " + st + " " + zip;
		//}
		x1 = new VELatLong (document.getElementById('latitude').value, document.getElementById('longitude').value);
	   }
		
		var forAdd2 = toFrmVal;
		var toAdd2 = "";
		var x2;
	  if ( forAdd2 == "buttonFrom"){
              var add2 = document.getElementById('add1').value;
		var cit2 = document.getElementById('cit').value;
		var st2 = document.getElementById('st').value;
		var zip2 = document.getElementById('zip').value;
		
		toAdd2 = add2 + " " + cit2 + " " + st2 + " " + zip2; 
		x2 = new VELatLong (document.getElementById('latitude').value, document.getElementById('longitude').value);
	  }

		var fromAdd = document.getElementById('startingStreet').value;

            
	if(toAdd != ""){
            var stPt = fromAdd;
            //var edPt = toAdd;
		var edPt = x1
	}else{
	     //var stPt = toAdd2;
            var edPt = fromAdd;
	     var stPt = x2
	}
	     var locations;
            locations = new Array(stPt, edPt);
            
            var options = new VERouteOptions;

            // Otherwise what's the point?
            options.DrawRoute      = true;

            // So the map doesn't change:
            options.SetBestMapView = true;

            // Call this function when map route is determined:
            options.RouteCallback  = ShowTurns;
            
            //change color of polyline
            //options.RouteColor = new VEColor(139,0,139,0.5);
            //options.RouteColor = new VEColor(0,0,0,1.0);
            //options.RouteWeight = 6;

            // Show as miles
            if(document.getElementById('distM').checked)
            {
            	options.DistanceUnit   = VERouteDistanceUnit.Mile;
            }else{
            	options.DistanceUnit   = VERouteDistanceUnit.Kilometer;
            }

            // Show the disambiguation dialog
            options.ShowDisambiguation = true;

	     //map.LoadMap();
		
	     if("reset"==from.toLowerCase()){
            	map.GetDirections(locations);
	     }else{
              map.GetDirections(locations, options);
            }
	   }catch(e){
		//alert(e.faultCode?e.faultCode:e.message?e.message:e);
          }
         }

         function ShowTurns(route)
         {
	   try{
            var turns = "<table border='0' width='100%'>";
	     if (route != null) {
               // Unroll route and populate DIV
               var legs          = route.RouteLegs;
               var leg           = null;
               var turnNum       = 0;  // The turn #

               // Get intermediate legs
               for(var i = 0; i < legs.length; i++)
               {
                  // Get this leg so we don't have to derefernce multiple times
                  leg = legs[i];  // Leg is a VERouteLeg object

                  var legNum = i + 1;
                  
                  // Unroll each intermediate leg
                  var turn        = null;  // The itinerary leg
                  var legDistance = null;  // The distance for this leg
                  
                  for(var j = 0; j < leg.Itinerary.Items.length; j ++)
                  {
                     turnNum++;
                     
                     turn = leg.Itinerary.Items[j];  // turn is a VERouteItineraryItem object

                     turns += "<tr><td valign='top' align='left' class='boldRed searchResNCol' style='padding: 0 0 0 13;' width='15'>" + turnNum + ".</td><td valign='top' align='left' class='normal' width='450'>" + turn.Text + "</td><td valign='top' align='left' class='normal' width='15'>&nbsp;&nbsp;</td>" ;

                     legDistance    = turn.Distance;

                     // So we don't show 0.0 for the arrival
                     if(legDistance > 0)
                     {
                        // Round distances to 1/10ths
                        if(document.getElementById('distM').checked)
					{
			  			turns += "<td valign='top' align='right' style='padding:0 31 0 0;' class='normal' width='80'><b> " + legDistance.toFixed(1) + " Mi";
            				}else{
            					turns += "<td valign='top' align='right' style='padding:0 31 0 0;' class='normal' width='80'><b> " + legDistance.toFixed(1) + " Km";
            				}

                        // Append time if found
                        if(turn.Time != null)
                        {
                           turns += "</b></td><td valign='top' align='left' class='normal' width='170'>" + GetTime(turn.Time);
                        }

                        turns += "</td></tr><tr><td colspan='4' style='padding:10 0 0 60;'></td></tr>";
                     }
                  }

                  turns += "</tr></table>";
		    turns += "<table border='0' align='left' width='100%'>"
		    turns += "<tr><td colspan='4'><img src='../images/navigation/spacer.gif' alt='' border='0' width='1' height='10'></td></tr>" 
		    turns += "<tr><td colspan='4' class='divider1'><img src='../images/navigation/spacer.gif' alt='' border='0' width='1' height='1'></td></tr>"
		    turns += "<tr><td colspan='4'><img src='../images/navigation/spacer.gif' alt='' border='0' width='1' height='10'></td></tr>" 
			if(document.getElementById('distM').checked){
		    		turns += "<tr><td align='left' valign='top' class='normal' style='padding: 0 0 0 13;' width='230'><b>Total Est. Distance:</b> " + route.Distance.toFixed(1) + " Mi</td></tr>";
			}else{
		    		turns += "<tr><td align='left' valign='top' class='normal' style='padding: 0 0 0 13;' width='230'><b>Total Est. Distance:</b> " + route.Distance.toFixed(1) + " Km</td></tr>";
			}

		    turns += "<tr><td align='left' valign='top' class='normal' style='padding: 0 0 0 13;' width='270'><b>Total Est. Time:</b> " + GetTime(route.Time) + "</td></tr></table>";


               //}

               // Populate DIV with directions
                  SetDirections(turns);
		    center=map.GetCenter();
             	    zoom=map.GetZoomLevel();
            	}
	         } 
         }catch(e){
		//alert(e.faultCode?e.faultCode:e.message?e.message:e);
 	  }
         }

         function SetDirections(s)
         {
	  try{
            var d = document.getElementById("directions");
            d.innerHTML = s;
	  }catch(e){
		//alert(e.faultCode?e.faultCode:e.message?e.message:e);
	  }
         }

         // time is an integer representing seconds
         // returns a formatted string
         function GetTime(time)
         {
	  try{
            if(time == null)
            {
               return("");
            }

            if(time > 60)
            {                                 // if time == 100
               var seconds = time % 60;       // seconds == 40
               var minutes = time - seconds;  // minutes == 60
               minutes     = minutes / 60;    // minutes == 1


               if(minutes > 60)
               {                                     // if minutes == 100
                  var minLeft = minutes % 60;        // minLeft    == 40
                  var hours   = minutes - minLeft;   // hours      == 60
                  hours       = hours / 60;          // hours      == 1

                  return(hours + " hr(s), " + minLeft + " min(s), " + seconds + " sec(s)");
               }
               else
               {
                  return(minutes + " mins, " + seconds + " secs");
               }
            }
            else
            {
               return(time + " secs");
            }
	  }catch(e){
		//alert(e.faultCode?e.faultCode:e.message?e.message:e);
	  }
         }

function DisposeMap()
         {
	  try{
           var map = null;
            if(map != null)
            {
              map.Dispose();
            }
	  }catch(e){
		//alert(e.faultCode?e.faultCode:e.message?e.message:e);
	  }
         }

	  

