var milesgie = new Array();

var mlats =  
[29961645,29975285,29988938,
29997044,29999120,30000672,30002609,
30005595,30009352,30012594,30018536,
30024723,30030253,30036313,
30042230,30049159,30056340,30063912,
30071660,30079298,30087087,
30095276,30102880,
30110452,30117558,
30125296,30132746,30140221,
30146222,30144645,
30142730,30144220,30146427,
30148679,30151318,30155374,30156170,
30160394,30164234,30167946,
30170250,30173578,30174986,30177802,
30179594,30183434,30187658,
30191370,30193674,30197898,30204042,
30211962,30219458,30227526,
30235103,30244981,30253157,
30262840,30271517,30277961,30278041,
30278910,30279203,30279409,
30279299,30279501,30279837,30280034,
30280055,30281244,30282012,

30282652,30283548,30284060,30285060,
30285733,30286165,30286652,
30287060,30287529,30288145,
30288719,30286636,30288130,30288377,
30288607,30288142,30287100,
30287307,30281868,30276300,30271055,
30265815,30262289,30260139,
30258183,30254601,30252054,30250502,
30249670,30249350,30249354,
30248249,30248390,30248390,30248710,
30249414,30251910,30254569,
30255823,30257276,30258500,30260180,
30261392,30263020,30264353,30265818,
30267011,30268972,30274881,
30280586,30286848,30292365,30289606,
30285352,30280621,30276564,
30271942,30267775,30263408,30258391,
30261692,30268172,30274533,
30280416,30283827,30283670,30284146,
30284064,30284119,30284393,
30284354,30284544,30284371,30282737,
30279626,30278435,30278922,
30279441,30279712,30279905,30288859,
30297408,30301319,
30301259,30300973,
30305748,30304922,30309129,
30317417,30311383,
30304172,30305899,30308101,30312395,
30312863,30306283,30306985,
30318256,30321265,30323160,30326717,
30331732,30333856,30331773,
30330854,30330052,30333781,30335303,
30337031,30338766,30340191,
30344065,30351734,30354723,
30358060,30361908,30365167,30368226,
30371207,30375976,30380767,
30383527,30384843,30387498,30389697,
30391388,30393415,30395034,
30396555,30397903,30396359,30398615,
30396368,30396721,30397180,
30400506,30405784,30407340,30405552,
30405955,30407404,30401188,
30401777,30399913,30400371,30400660,
30401063,30404569,30411049,
30417923,30423856,30431644,
30429855,30431863,30432041,
30432927,30432973,30434262,30434967,

30435406,
30436805,30438987,30441456,30443157,
30444517,30446120,30446454,
30437400,30427929,30418804,30410822,
30402452,30396353,30389377,
30384195,30378563,30366918,30356767,
30354062,30351793,30349463,
30340624,30328472,30316442,30311356,
30311694,30318628,30323880,30319382,30314621,30314231,30315052,
30304920,30293784,
30282989,30273419,30266589,
30263279,30259724,30256135,
30251147,30240133,
30227786,30214802,30202492,30189895,
30175243,

30170434,30162890,
30156101,30149479,30143735,30135484,
30127710,30123146,30120586,
30109322,30100293,30105107,30104826,
30104138,30095026,30083189,
30073830,30061506,30046922,30033963,
30025605,30022780,30032251,
30043555,30047812,30042863,30034224,
30024820,30013778];

var mlngs =  
[-90028349,-90022928,-90018118,
-90005789,-89989795,-89971651,-89954997,
-89938181,-89922383,-89905410,-89890221,
-89875184,-89862221,-89847004,
-89831792,-89817376,-89803189,-89788980,
-89774638,-89760151,-89746441,
-89731793,-89717501,
-89703020,-89689280,
-89675097,-89660494,-89646725,
-89630730,-89613762,
-89596914,-89580599,-89564239,
-89548235,-89529621,-89513484,-89498324,
-89485268,-89471700,-89458644,
-89444564,-89433300,-89420244,-89405140,
-89385172,-89366228,-89346516,
-89328084,-89305556,-89285332,-89264852,
-89249748,-89235812,-89222549,
-89208434,-89196698,-89188030,
-89174322,-89161124,-89146894,-89130001,
-89116369,-89099291,-89083763,
-89067970,-89051477,-89035364,-89019156,
-89002778,-88984697,-88964857,

-88939385,-88918009,-88896889,-88876547,
-88860026,-88843744,-88827626,
-88811101,-88794697,-88776992,
-88760543,-88742831,-88725645,-88709581,
-88693015,-88675764,-88659970,
-88643119,-88629152,-88617575,-88600743,
-88584450,-88568552,-88550708,
-88532900,-88515526,-88498263,-88485018,
-88473946,-88460698,-88447838,
-88432009,-88416726,-88403222,-88391190,
-88379926,-88367510,-88354887,
-88337330,-88320165,-88302913,-88285300,
-88268436,-88255188,-88234797,-88217192,
-88200339,-88183011,-88167126,
-88151210,-88135545,-88120600,-88104693,
-88088285,-88071634,-88054206,
-88037858,-88021365,-88005728,-87989429,
-87972233,-87956265,-87940949,
-87925321,-87909594,-87892433,-87875054,
-87857073,-87839769,-87822385,
-87804702,-87787243,-87770686,-87754495,
-87739008,-87721478,-87705043,
-87688265,-87671684,-87654806,-87642251,
-87628821,-87613142,-87596621,-87579618,
-87564185,-87547518,-87532205,
-87518195,-87506184,
-87493202,-87476846,-87460121,-87444553,
-87427583,-87412768,-87396062,
-87386870,-87370591,-87353612,-87337753,
-87322144,-87306639,-87289343,
-87272481,-87255524,-87239389,-87222175,
-87205061,-87187482,-87170524,
-87154140,-87138988,-87122964,
-87106588,-87089376,-87072746,-87055837,
-87038821,-87017264,-86996528,
-86979546,-86962171,-86945226,-86927790,
-86910487,-86893400,-86876128,
-86861589,-86844844,-86828658,-86812464,
-86796441,-86779942,-86763193,
-86749472,-86732469,-86717554,-86701061,
-86684677,-86668746,-86650844,
-86634337,-86616092,-86599698,-86583428,
-86566589,-86551290,-86536890,
-86522292,-86507373,-86490209,
-86474241,-86457809,-86441120,
-86425427,-86409340,-86393083,-86377127,

-86361881,
-86345115,-86327345,-86310416,-86293605,
-86277093,-86259958,-86243008,
-86229203,-86216341,-86202655,-86188144,
-86174120,-86158545,-86143474,
-86127403,-86110500,-86097950,-86086142,
-86070001,-86053275,-86036969,
-86023622,-86015184,-86006142,-85991903,
-85974620,-85960005,-85945616,-85929269,-85913001,-85897107,-85880135,
-85867750,-85856247,
-85845793,-85833364,-85818199,
-85801671,-85785427,-85769858,
-85754588,-85743494,
-85735036,-85726093,-85733319,-85740499,
-85741457,-85726224,-85711847,
-85697317,-85682465,-85667074,-85654243,

-85640738,-85628202,-85615658,
-85610794,-85600032,-85585027,-85567157,
-85549817,-85536020,-85524008,
-85510628,-85500306,-85494896,-85488008,
-85475103,-85458778,-85445953,
-85436643,-85423171,-85407120,-85394837,
-85385142,-85378655];

var speeds = [6,7,8,9,10,11,12,13,14,15,16,18,20,23,26,30,36,45,60,90,180];
var spdvals = [29,26,23,20,18,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1];

	var poiprev = 0;
	var map = null;
	var msg = null;
	var ZL = null;
	var center = null;
	var cspd = 0;
	var minmapsz = VEMiniMapSize.Large;
        var pixX = 0;
        var pixY = 0;
        var mmile = 0;
        var miltxt= 0;
        var maxsmile = 0;
        var savmile = 0;
        var nxtmile = 0;        
        var milbeg = 0;
        var milend = 0;
        var mlat = 0;
        var mlng = 0;
        var mlat2 = 0;
        var mlng2 = 0;
        var latLong = null;
        var latLong2 = null;
        var pixel2 = null;
        var idir = 1;
        var ispd = 6;
        var timerxa = 0;
        var timerxc = 0;
        var cruiseflag = 0;
        var slowscroll = 0;
        var zzl = null;
        var pixcx = 0;
        var pixcy = 0;
        var sly = 0;
        var slyd = 0;
        var slx = 0;
        var slxd = 0;
        var xi = 0;
        var yi = 0;
	var incr = 0;
	var nincr = 0;  // number of increments/mile
	var ctr = 0;  //  increment counter
	var tms = 0;  // increment time in milliseconds
	var ntrval = 0;
	
	
	function removeOptions(optionMenu)
	{
	  optionMenu.options.length = 0;
	}
	
	function addOpts(optionList, valueList, optionMenu)
	{
	 var i=0; var j=-1;
	 removeOptions(optionMenu);  // clear out the options
	 for (i=0; i < optionList.length; i++)
	    {
	     j++ 
	     optionMenu[j] = new Option(optionList[i], valueList[i]);
	    }
	}	

	function addOptions(optionList, optionMenu)
	{
	 var i=0; var j=-1;
	 removeOptions(optionMenu);  // clear out the options
	 for (i=0; i < optionList.length; i++)
	    {
 
	     j++ 
	     optionMenu[j] = new Option(optionList[i]);
    
	    }
	}

	function includechange()
	{
	 var i=0; var j=-1;
	 for (i=0; i < 307; i++)
	  {
	   j++
	   milesgie[j] = i;
	  }
	 addOptions(milesgie,document.myform2.mile);
	 addOpts(speeds,spdvals,document.myform2.txtMapSpd);	 
	}

        function preloadOpts()
        {
	      includechange();      
	}

	function UpdateInfo(e)
	{
	        var center = map.GetCenter();
		var ZL = e.zoomLevel;
		document.getElementById("info").innerHTML =
			'GULF INTRACOASTAL WATERWAY EAST:  Latitude = ' + 
			center.Latitude + 
			', Longitude = ' 
			+ center.Longitude + 
			', Zoom=' + 
			ZL ;
                if (ZL != zzl) {
                   if (cruiseflag == 0) {
	               clearInterval(timerxc);
	               return;
	           } else {
//	           zzlL = zzl;
	           zzl = ZL;
	           clearInterval(timerxc);
	           
	           nincrL = nincr;
	           ctrL = ctr;
	           ntrvalL = ntrval;
//	           slyL = sly;
//	           slxL = slx;
	           
                  var pixelc = map.LatLongToPixel(map.GetCenter(), zzl);   // get pixcels at new map center
//         pinfo += " Map center pixel coordinates are : (" + pixelc.x + ", " + pixelc.y + ")\n\n";
                  pixcx = pixelc.x;
                  pixcy = pixelc.y;

                  pixel2 = map.LatLongToPixel(latLong2, zzl);
//         var pinfo2 = "Nxt mile pixel coordinates are : (" + pixel2.x + ", " + pixel2.y + ")\n\n";
//         alert(pinfo2);
         
                  slyd = (pixel2.y - pixcy);  //  recompute pixel differences
                  slxd = (pixel2.x - pixcx);
                 
                 if (zzl > 11) {
                    nincr = Math.round(Math.pow(2,(zzl - 12)) * 10);
                 } else {
                    nincr = Math.round(10 / (Math.pow(2,(12 - zzl))));
                 }   
                 if (zzl > 10) {
                    tms = 4000 / (Math.pow(2,(zzl - 11)));
                 } else {   
                    tms = Math.pow(2,(11 - zzl)) * 4000;
                 }   
               
//               alert(nincr + ", " + tms);                  

                  ntrval = ispd * tms;   // tms changed, so recompute intraval
                  
                  sly = slyd / nincr;
                  slx = slxd / nincr;                   
//                  alert ("old ctr= " + ctrL + " ntrv= " + ntrvalL); 
                  ctrratio = ctrL / nincrL;   // ctr completion ratio to next mile
                  ctr = (1 - ctrratio) * nincr;    // set ctr's remaining pans for current mile
//                  alert ("new timer" + ctrratio + " ctr= " + ctr + " ntrv= " + ntrval);
                  timerxc = setInterval("slowIncr(ctr++)", ntrval);
                  }
	        }			
	}
	
	 function UpdateInfo2(e)
	 {
	        if (cruiseflag == 1) {
	            if (idir == 1) {
                       appmile = mmile + (Math.round((ctr/nincr) * 10) / 10);
	               Amile = ', Mile = ' + appmile;
	            } else {
                       appmile = mmile - (Math.round((ctr/nincr) * 10) / 10);
	               Amile = ', Mile = ' + appmile;
	            }   
	        } else {
	            Amile = '';
	        }
	        center = map.GetCenter();
		ZL = e.zoomLevel;
        	document.getElementById("info").innerHTML =
			'GULF INTRACOASTAL WATERWAY EAST:  Latitude = ' + 
			center.Latitude + 
			', Longitude = ' 
			+ center.Longitude + 
			', Zoom=' + ZL +
			Amile;
	 }	
	
         function GetPixel()
         {
            var pinfo = "";
            // Get pixel info about center of the map
            var pixelI = map.LatLongToPixel(map.GetCenter(), map.GetZoomLevel());
            pinfo += "Map center pixel coordinates are : (" + pixelI.x + ", " + pixelI.y + ")\n\n";
            pixX = pixelI.x;
            pixY = pixelI.y;            
            pinfopix = "pixX = " + pixX + "\n\n";
//            alert(pinfo);
//            alert(pinfopix);
         }  	
	
         function PixelClick2(e)
         {
            var x = e.mapX;
            var y = e.mapY;
            pixel2 = new VEPixel(x, y);
            var LL2 = map.PixelToLatLong(pixel2);
            info2.innerHTML =  LL2 + "<br />";            
//            info2.innerHTML = "LatLong: " + LL2;
//            info2.innerHTML = "Pixel X: " + x + " | Pixel Y: " + y + "<br /> LatLong: " + LL2; 
            map.FindLocations(LL2, GetResults);
         }

         function PixelClick(e)
         {
   	    var x = e.mapX;
      	    var y = e.mapY;
      	    pixel = new VEPixel(x, y);
      	    LL = map.PixelToLatLong(pixel);

            map.FindLocations(LL, GetResults);

         }


         function GetResults(locations)
         {
            if(locations)
            {
	       for(var i=0;i<locations.length;i++)
               {
                   info2.innerHTML+=locations[i].Name + "<br />";
               }
            }
            else
            {
                 info2.innerHTML+='No address found.'; 
            } 
         }
         
	function OnPageLoad()
	{
                preloadOpts()

                map = new VEMap('myMap');
            
                map.SetDashboardSize(VEDashboardSize.Normal);
            
                map.LoadMap(new VELatLong(29.961645, -90.028349), 14 ,'h' ,false);
                
                map.ShowDashboard();                
            
//                map.AttachEvent("onclick", PixelClick);
            
		map.AttachEvent("onendpan", UpdateInfo2);
			
		map.AttachEvent("onendzoom", UpdateInfo) ;
		
                map.AttachEvent("onclick", PixelClick2);
	}
	
	function HideMiniMap()
	{
	        map.HideMiniMap();
	}
	         
	function ShowMiniMap()
	{
	    if (map.GetMapMode() == VEMapMode.Mode3D)
	       {
	          map.SetMapMode(VEMapMode.Mode2D);
	       }
	          GetPixel();
                  var minileft = Math.round(pixX + pixX - 191);
//		alert(minileft);    
	          map.ShowMiniMap(minileft, 0, minmapsz);            
        }
        
	function DoNavcht()
	{
	   if (mmile >= 25) 
	    {
	      alert('No Chart Available')
	      return;
	    } 
	    else 
	    {
	      var i=0;
	      for (i=0; i < chtmix.length; i++) {
	         if (mmile < chtmix[i]) {
	             zchtno = i + 1;
	             zchtlink = 'http://b02.s3.amazonaws.com/chtpics/BigSandy/chart' + zchtno + '.pdf';
//	             zchtlink = 'http://www.lrp.usace.army.mil/navchart/al/chart' + zchtno + '.pdf';
//	             alert (zchtlink);
	             javascript: secondwindow = open(zchtlink, 'navcht', 'scrollbars=yes');
	             return;
	         }    
	      }
            }  
	}
	
        function DoAIS() {
            var vcenter = map.GetCenter();
            vclat = vcenter.Latitude;
            vclng = vcenter.Longitude;
            
            zaislink = '../bhais.php?zalat=' + vclat + '&zalng=' + vclng;
//	      alert (zaislink);
            javascript: secondwindow = open(zaislink, 'VEmain', 'scrollbars=yes');            
        }     		
	
      function SlowScroll()   //  hopefully, nearly pixcel by pixcel
      {
         if (cruiseflag == 1) {
            return(alert("already cruising!"));
         }   
         cruiseflag = 1;      
         slowscroll = 1;
         savmile = 0;
         
         mlat2 = 0;
         mlng2 = 0;
         latLong2 = null;
         pixcel2 = null;

         var numdirs = document.myform2.txtMapDir.length;
         for (var di = 0; di < numdirs; di++)
         {
            if (document.myform2.txtMapDir[di].checked) {
              idir = document.myform2.txtMapDir[di].value;
            }
         }   

//        alert(idir);
         milbeg = parseInt (document.getElementById('txtMilBeg').value);
         milend = parseInt (document.getElementById('txtMilEnd').value);
         
         if ((milbeg > 306) || (milbeg < 0)) {
             EndContinuous();
             return(alert("Mile Entry Error, must be > 0 and < 307"));
         }
         if ((milend > 306) || (milend < 0)) {
             EndContinuous();
             return(alert("Mile Entry Error, must be > 0 and < 307"));
         }
         
         if ((idir == 1) && (milend < milbeg)) { 
             EndContinuous();
             return(alert("End mile must be greater than start mile \n when going East")); 
         }
         if ((idir == 2) && (milend > milbeg)) {
             EndContinuous(); 
             return(alert("End mile must be less than start mile \n when going West"));  
         } 
         
//       alert (milbeg);  
         if (idir == 1) {
            maxsmile = 306;
          } else {
            maxsmile = 0;
         }
         
         mmile = milbeg;
         miltxt = milbeg;
         ctr = .0005; nincr = 20;   // this is to stop a divide by zero in Amile
         milehit(mmile, miltxt);
         
//         var dlat = center.Latitude - mlat;
//         var dlng = center.Longitude - mlng;
//         alert(dlat + ", " + dlng);
         
         map.SetCenter(latLong);
         
         zzl = map.GetZoomLevel();  // get current zoom level
//         var pinfo = "Zoom= " + zzl; 
         var pixelc = map.LatLongToPixel(map.GetCenter(), zzl);   // get pixcels at map center
//         pinfo += " Map center pixel coordinates are : (" + pixelc.x + ", " + pixelc.y + ")\n\n";
         pixcx = pixelc.x;
         pixcy = pixelc.y;
//         alert(pinfo);

         nincr = 2.5;      // default settings for zoom levels < 11
         tms = 8000;
         
         
//         alert (nincr + ", " + tms);
//         var nincr3 = 0;
//         var tms3 = 0;

         if (zzl > 11) {
            nincr = Math.round(Math.pow(2,(zzl - 12)) * 10);
         } else {
            nincr = Math.round(10 / (Math.pow(2,(12 - zzl))));
         }   
         if (zzl > 10) {
            tms = 4000 / (Math.pow(2,(zzl - 11)));
         } else {   
            tms = Math.pow(2,(11 - zzl)) * 4000;
         }   

//         alert(nincr + ", " + tms3);
         
         cspd = 180 / ispd;
         ntrval = ispd * tms;

//         alert (cspd + ", " + ntrval);
         nextMile();
         
         ctr = 0;
         timerxc = setInterval("slowIncr(ctr++)", ntrval);
      } 

    
     function slowIncr(ctr)
     { 
//     alert("slictr= " + ctr + " nincr= " + nincr + " ntrvl= " + ntrval); 
         if (ctr < nincr) {
//            yi = Math.round(pixcy + (sly * incr));
//            xi = Math.round(pixcx + (slx * incr));

//            if (zzlL != zzl) {
//                yi = Math.round(pixcy + 
            yi = Math.round(pixcy + (sly));
            xi = Math.round(pixcx + (slx));
//            alert(xi + ", " + yi + ", " + ctr);
            pixeli = new VEPixel(xi, yi);
            LLi = map.PixelToLatLong(pixeli);
//            alert(pixeli.x + ", " + pixeli.y);
//            alert(LLi);
//            alert(incr);

//            map.SetCenter(LLi);
              map.PanToLatLong(LLi);
//            map.Pan(xi,yi);
         } else {
            mmile = nxtmile;
            miltxt = nxtmile;
            milehit(mmile, miltxt);
//         alert("slowIncr,savmile= " + savmile);             
            if (idir == 1) {
                if (savmile == maxsmile) {
//                  alert(savmile);
                   EndContinuous();
                } else {
                   if (mmile == milend) {
                      EndContinuous();
                   } else {
                      nextMile();
                   }   
                }   
            } else {
              if (idir == 2) {
                  if (savmile == maxsmile) {
                     EndContinuous();
                  } else {
                     if (mmile == milend) {
                        EndContinuous();                 
                     } else {
                        nextMile();
                     }   
                  }
              }
            }
         }
      }
      
      function nextMile()
      {
         if (idir == 1) {
               nxtmile = mmile + 1;
         } else {
               nxtmile = mmile - 1;
         }                
//        alert ("nextMile, nxtmile= " + nxtmile);
         mlat2  = mlats[nxtmile] / 1000000;
         mlng2  = mlngs[nxtmile] / 1000000;
         latLong2 = new VELatLong(mlat2,mlng2);
         pixel2 = map.LatLongToPixel(latLong2, zzl);
//         var pinfo2 = "Nxt mile pixel coordinates are : (" + pixel2.x + ", " + pixel2.y + ")\n\n";
//         alert(pinfo2);
       
         slyd = (pixel2.y - pixcy);
         slxd = (pixel2.x - pixcx);
         sly = slyd / nincr;
         slx = slxd / nincr;
         incr = 1;
         ctr = 0;      
      }
      
      function EndContinuous()
      {
         if (cruiseflag == 1) {
            clearInterval(timerxc);
            cruiseflag = 0;
//            zzl = ZL;
//            ntrval = 0;
//            ctr = nincr;
//            savmile == maxsmile;
//            mmile == milend;
//            map.EndPan(e);
            msg = "End of Cruise";
         } else {
            msg = "press Start to Cruise";
         }   
         alert(msg);
//         clearInterval(timerxa); 
         clearInterval(timerxc);         
         cruiseflag = 0;
         slowscroll = 0;
//         ctr = 0;
//         nincr = 0;
//         ntrval = 0;
//         sly = 0;
//         slx = 0;
         cspd = 0;
         poiprev = savmile;
//         map.EndPan();
//         NextPoint();
      }		
        
        function DoInfo() {
            var vcenter = map.GetCenter();
            vclat = vcenter.Latitude;
            vclng = vcenter.Longitude;
            
	      zlink = 'http://maps.live.com/default.aspx?v=2&lvl=14&style=h&cp=' + vclat + '~' + vclng;
//	      alert (zlink);
              javascript: secondwindow = open(zlink, 'VEmain', 'scrollbars=yes');            
            
//        http://maps.live.com/default.aspx?v=2&lvl=14&style=h&cp=25.783538~-80.183171
        }
	
         function AddShapes(mmile)
         {
            if ((cruiseflag == 1) && (slowscroll == 0)) {
              if (idir == 1) {
               mmile = mmile-1;
               miltxt = miltxt-1;
               savmile = mmile;
              } else {
                  mmile = mmile + 1;
		  miltxt = miltxt + 1;
                  savmile = mmile;
              }    
            }
          
//            latLongcnt = new VELatLong(mlat, mlng);
            pin02 = new VEShape(VEShapeType.Pushpin, latLong);         
            pin02.SetTitle("<font color='blue'> Gulf Intracoastal Waterway East </font>");
            pin02.SetDescription("<font color='blue'> Mile " + mmile + "</font>");            
            pin02.SetCustomIcon("<span style='width:30px; height:15px; font-family:Arial,sans-serif; font-weight:bold; font-size:8pt;" +
               "color:white; overflow:hidden; text-align:center; border:1px solid #FF0000; background-color:blue'>" +
                miltxt + "</span>");
            map.AddShape(pin02);
            if ((cruiseflag == 1) && (slowscroll == 0)) {
               if (idir == 1) {
                  mmile = mmile+1;
                  miltxt = miltxt+1;
               } else { 
                  mmile = mmile-1;
                  miltxt = miltxt-1;
               }   
            }              
         } 	


        function markmile()
	{
	 AddShapes(mmile);	
	}

	function milehit(mmile, miltxt)
	{
        mlat  = mlats[mmile] / 1000000;
        mlng  = mlngs[mmile] / 1000000;        
        latLong = new VELatLong(mlat,mlng);
        savmile = mmile;        
        map.PanToLatLong(latLong);        
        markmile(mmile);
        if (cruiseflag == 1) {
           dist = Math.abs(savmile - milbeg);
        } else {
           dist = Math.abs(mmile - poiprev);
        }        
//        dist = Math.abs(mmile - poiprev)
        document.myform2.distnm.value = Math.round(0.86898 * dist);
        document.myform2.distsm.value =  dist;
        document.myform2.distkm.value = Math.round(1.609344 * dist);
	poiprev = mmile;         
//        document.myform2.mile.value = "9999";
	}

        function spdchange()
        {
            if (cruiseflag == 1) {
               return(alert("Cannot change speed or direction in middle of a cruise \n-- must stop and restart to change"));
            }        
             ispd =  document.myform2.txtMapSpd.value; 
//             alert(ispd); 
        }  
	
	function milechange()
	{
            if (cruiseflag == 1) {
               return(alert("You are cruising - must stop cruise to use this function"));
            }	
             var k; 
	     var hitval=" "; 
	     for (k=0; k < document.myform2.mile.options.length; k++)
	     {
	       if (document.myform2.mile.options[k].selected)
	       {
	         mmile = k;
	         miltxt = document.myform2.mile[k].text;
                 milehit(mmile, miltxt);  
 	       }
             }
        } 


