var milesgiw = new Array();

var mlats =  
[29909639,29895233,29881146,29867288,
29853527,29839172,29827005,29812582,29799051,29785182,
29773161,29764049,29761241,29760178,
29753190,29742161,29731071,
29719413,29707402,29696202,29686338,
29674872,29664129,29656550,
29653471,29649978,29646508,
29645447,29645264,
29644992,29638836,29626449,
29614488,29601688,29589400,29576457,
29563082,29551050,29551718,29554416,
29556699,29557757,29558142,
29559225,29559753,29560666,29560884,
29566417,29573087,29577099,
29575610,29579231,29586768,29595054,
29599220,29604663,29612842,
29606870,29592599,29578640,29565771,
29564001,29555981,29542057,29535310,
29535325,29534951,29535347,
29534902,29534898,29535519,29539331,
29546369,29554012,29560929,
29568796,29576995,29590712,29604250,

29615966,29622577,29623093,
29623964,29623495,29620026,29626518,
29635393,29641070,29639603,
29651572,29665227,29677189,
29684807,29685001,29684464,29688276,
29683069,29673460,29662934,
29655917,29651793,29645946,29643414,
29639649,29639937,29641417,
29642582,29645901,29649931,29654382,
29659329,29667489,29674232,
29681070,29687094,29693356,29699605,
29706068,29713766,29724630,
29734742,29744616,29748951,29759319,
29759896,29759642,29759881,29760568,
29760582,29762949,29767183,
29763733,29763591,29764339,29771772,
29779078,29786262,29800077,
29813897,29827611,29838397,29844714,
29844297,29844513,29844480,
29844634,29843436,29840394,29837850,
29833259,29828570,29823569,
29818728,29813713,29808830,29803816,
29798874,29794042,29788941,
29783131,29781270,
29775424,29780071,29785785,
29791383,29796346,29802123,29807222,29812777,
29821388,29833611,29839444,
29842222,29846666,29851666,29864444,
29875359,29882942,29885245,
29887523,29890422,29892756,29895569,
29898101,29900277,29902777,
29905277,29907777,29910277,29912777,
29916388,29921111,29925530,29930380,
29935406,29940194,29945264,
29952620,29959876,29961952,29965277,
29969722,29972222,29971111,
29966111,29961388,29956388,29951388,
29946111,29941388,29936388,
29931388,29929722,29925277,29926666,
29927777,29928707,29929926,
29931006,29932598,29933958,29934917,
29935865,29934527,29934187,
29939041,29950614,29961788,29972396,
29982777,

29993257,30005630,30020141,30029493,
30037555,30051421,30064320,30076574,30086087,30095116,
30100437,30090118,30078973,
30067867,30058516,30058516,30058516,
30058516,30058838,30058838,
30058677,30058677,30058677,30058355,
30058677,30058677,30058355,
30058677,30058194,30058517,30058839,
30058194,30058194,30058102,
30057872,30053873,30049109,30039359,
30025353,30016872,30007172,29995508,29990681,
29985384,29980557,29975529,29970434,
29959401,29945662,

29933185,29921639,29909721,
29898176,29886723,29875178,
29862794,

29851248,29838862,29826185,
29820482,29815618,29804875,
29792970,29783282,29774242,29765251,
29756361,29747967,29739524,
29730434,29721444,29712304,29703213,
29694123,29688544,29685829,
29680773,29674149,29667499,29660899,
29654249,29647624,29640974,
29634424,29627724,29620900,29614149,29607421,
29598874,29593991,29596622,29589351,29574999,29565802,29563414,
29560557,29549657,29537135,29525517,29519880,29514165,
29508502,29502759,29496990,29491168,
29485478,29479762,29474046,
29468303,29462587,29456791,29449454,29439669,29429939,29420235,
29410612,29400722,29390699,29380677,29371185,29361561,29352522,
29343403,29334230,29325058,29315833,29306608,29294990,29284382,
29287067,29288264,29285791,29283239,29277922,29266995,29255484,
29244291,29234613,29222356,29210259,29202602,29195211,29186676,
29177876,29173463,29166789,29158468,29150359,29141133,29130579,
29120024,29109363,29095724,29081633,29068314,29055100,29041728,
29028036,29015089,29002965,28990816,28981510,28971115,28959816,
28949208,28939610,28929090,28922312,28914484,28905595,28898067,
28898652,28892867,28884441,28876068,28867724,28864688,28860917,
28853226,28845507,28837653,28828273,28813858,28804165,28796977,
28789817,28782385,28775306,28768104,28762094,28763048,28762990,
28755109,28748412,28743469,28739901,28746865,28749060,28748697,
28745702,28741714,28736925,28731945,28727271,28722405,28717100,
28713188,28708437,28702427,28695844,28689147,28682258,28675637,
28669015,28662318,28659933,28655717,28648027,28637436,28632876,
28625453,28623488,28619347,28615016,28610570,28600361,28588187,
28576070,28564106,28552141,28540063,28528061,28518424,28510048,
28501595,28493676,28485949,28477096,28468509,28463472,28458625,
28452977,28447978,28443017,28437635,28432330,28425919,28419427,
28412906,28406340,28399863,28393342,28386733,28380167,28373646,
28366189,28359023,28351968,28344334,28336968,28329401,28321722,
28314533,28306054,28297040,28288071,28278746,28269509,28260140,
28251037,28241934,28232696,28223484,28214354,28203446,28193992,
28185024,28176055,28167005,28157956,28147694,28136382,28125070,
28113596,28102284,28090730,28079094,28067620,28056308,28044754,
28033118,28021644,28010252,28000152,27996112,27992314,27984557,
27972194,27959185,27946904,27934623,27921372,27908283,27895516,
27882265,27872649,27860933,27848328,27835643,27822957,27810352,
27797586,27783770,27769306,27754520,27740461,27725998,27711535,
27697314,27683013,27668872,27654490,27640189,27626614,27613202,
27600031,27586941,27573609,27560923,27547592,27534664,27521332,
27508000,27494587,27481255,27468004,27454672,27441582,27428331,
27415080,27406388,27393184,27379722,27366388,27352777,27339444,
27326201,27312222,27298055,27283888,27269642,27255277,27241120,
27226899,27212597,27198215,27183833,27169127,27154178,27139473,
27124524,27109819,27094870,27079761,27064893,27050592,27035967,
27021505,27006880,26992416,26977953,26963328,26948704,26934240,
26919292,26905556,26891174,26876549,26862167,26847542,26833240,
26818615,26803990,26789447,26775307,26760359,26746057,26731351,
26717130,26702586,26688769,26675033,26661136,26647239,26633260,
26619525,26605304,26591406,26576862,26561995,26547451,26533392,
26519898,26506243,26492669,26479014,26465359,26451784,26438129,
26424393,26410495,26396436,26382215,26369368,26355955,26341653,
26327998,26314342,26300525,26286870,26272649,26258833,26244774,
26230391,26216655,26202838,26189102,26175608,26162518,26149429,
26136501,26123734,26110967,26097797,26085112,26071779,26061195,
26049721,26042125,26034692,26027743,26020956,26014027,26006340,
25998831,25991251,25983707,25976235,25971062,25965889,25960752,
25955363,25950000];

var mlngs =  
[-90083679,-90078698,-90073757,-90068845,
-90064212,-90061398,-90069114,-90071231,-90067821,-90063784,
-90072929,-90087180,-90103632,-90121042,
-90135207,-90138591,-90149054,
-90159088,-90168931,-90178686,-90187929,
-90198342,-90208723,-90222663,
-90239503,-90256869,-90272726,
-90289543,-90306358,
-90322048,-90336066,-90344946,
-90353444,-90362020,-90370084,-90380745,
-90388091,-90397015,-90413444,-90429629,
-90445786,-90461890,-90478877,
-90495536,-90516419,-90532690,-90549007,
-90564104,-90578447,-90593422,
-90609823,-90624806,-90638419,-90651969,
-90667528,-90682867,-90696746,
-90708976,-90711219,-90717644,-90723178,
-90739147,-90751799,-90759360,-90771419,
-90788001,-90804306,-90820868,
-90837704,-90854482,-90870106,-90879175,
-90895422,-90910792,-90927007,
-90943210,-90958659,-90966803,-90975513,

-90986518,-90998413,-91009870,
-91025952,-91041982,-91058338,-91073494,
-91087058,-91101683,-91116258,
-91123927,-91134516,-91144569,
-91158919,-91175352,-91191576,-91206993,
-91220329,-91231650,-91240720,
-91254002,-91269836,-91283621,-91299680,
-91315315,-91333172,-91349961,
-91365722,-91382542,-91398170,-91413967,
-91429267,-91442177,-91457076,
-91471266,-91486327,-91500133,-91514440,
-91529249,-91543292,-91553570,
-91565558,-91576811,-91592513,-91607169,
-91620543,-91638827,-91655396,-91671684,
-91688404,-91704391,-91721066,
-91737075,-91754643,-91771065,-91785055,
-91799027,-91813451,-91817864,
-91824239,-91826855,-91836767,-91850715,
-91867614,-91887090,-91903410,
-91919595,-91937986,-91953780,-91969753,
-91984851,-91999994,-92015192,
-92030459,-92046164,-92061665,-92076789,
-92091950,-92107728,-92122954,
-92140179,-92156442,
-92170975,-92186385,-92202036,
-92217576,-92232387,-92247778,-92263333,-92278055,
-92290833,-92300000,-92315555,
-92333055,-92348611,-92363333,-92369722,
-92381011,-92390760,-92406782,
-92423337,-92440375,-92457011,-92473138,
-92490062,-92506944,-92523333,
-92539722,-92556111,-92571666,-92589444,
-92605000,-92620555,-92636998,-92652657,
-92668314,-92683992,-92699529,
-92713898,-92728095,-92743867,-92763055,
-92778611,-92794444,-92809166,
-92825277,-92840555,-92856388,-92871944,
-92887777,-92903333,-92918888,
-92934444,-92950277,-92966111,-92982500,
-92998888,-93016673,-93032984,
-93049214,-93065187,-93082239,-93098482,
-93114928,-93131985,-93148910,
-93163470,-93173683,-93183758,-93195038,
-93206161,

-93217119,-93226863,-93230214,-93243994,
-93258146,-93262242,-93266711,-93276767,-93290374,-93301922,
-93313498,-93325050,-93336045,
-93346292,-93357472,-93374241,-93391011,
-93408153,-93424923,-93442065,
-93458281,-93475419,-93492557,-93509694,
-93526832,-93543970,-93560735,
-93578245,-93595950,-93612711,-93629100,
-93643998,-93660759,-93677555,
-93694653,-93709187,-93723864,-93736083,
-93739714,-93751709,-93763484,-93772000,-93787794,
-93803355,-93818989,-93834548,-93850179,
-93857862,

-93863634,
-93872444,-93883187,-93894576,
-93904999,-93915420,-93925729,
-93935074,-93946023,-93952911,-93958832,
-93973962,-93989743,-93997120,
-94007164,-94019648,-94032762,-94045818,
-94059102,-94072729,-94086125,
-94099234,-94112284,-94125505,-94138668,
-94151656,-94166679,-94182992,
-94198615,-94213463,-94228226,-94242987,
-94257805,-94272592,-94287351,
-94302050,-94316922,-94331762,-94346478,-94360958,
-94374096,-94386328,-94402146,-94415063,-94415407,-94426045,-94442515,
-94458471,-94469169,-94477880,-94487873,-94503334,-94518702,
-94534129,-94549769,-94565257,-94580743,
-94596075,-94611438,-94626799,
-94642128,-94657489,-94672939,-94687289,-94699932,-94712508,-94724994,
-94737450,-94749900,-94762077,-94774314,-94786916,-94799548,-94812419,
-94825383,-94838223,-94851124,-94864084,-94877348,-94886830,-94897409,
-94913412,-94929414,-94945783,-94962364,-94977177,-94988180,-94998817,
-95009575,-95022069,-95030509,-95038705,-95052840,-95066971,-95080585,
-95093649,-95109178,-95123642,-95137069,-95150738,-95163371,-95174786,
-95186140,-95197431,-95202392,-95206350,-95212770,-95219372,-95225729,
-95231053,-95238503,-95247868,-95257261,-95269844,-95280695,-95290207,
-95301238,-95313300,-95324608,-95339045,-95352902,-95365949,-95379898,
-95394779,-95408694,-95422175,-95435685,-95449164,-95465376,-95481278,
-95495313,-95509130,-95523132,-95535083,-95538082,-95550761,-95565301,
-95579873,-95593946,-95608359,-95623041,-95638039,-95654451,-95670623,
-95684575,-95699353,-95714827,-95730605,-95744815,-95760681,-95777025,
-95793065,-95808974,-95824316,-95839876,-95855390,-95870991,-95886048,
-95901300,-95916637,-95931148,-95945266,-95959863,-95974458,-95988922,
-96003341,-96017759,-96033698,-96048941,-96062792,-96073207,-96088491,
-96101991,-96117751,-96133380,-96149052,-96164810,-96176047,-96184872,
-96193889,-96202994,-96211880,-96220809,-96229824,-96241313,-96254496,
-96268024,-96281768,-96295646,-96309018,-96322259,-96337365,-96353035,
-96367965,-96383460,-96398736,-96414316,-96429895,-96443867,-96458311,
-96472557,-96487107,-96501453,-96516101,-96530749,-96545345,-96559991,
-96574080,-96588344,-96602532,-96616163,-96630148,-96644358,-96658240,
-96671917,-96685139,-96697702,-96710416,-96723331,-96736296,-96749361,
-96762172,-96774880,-96787690,-96800669,-96813461,-96823913,-96836246,
-96849264,-96862329,-96874977,-96887766,-96899268,-96909347,-96919475,
-96929417,-96939265,-96949432,-96959556,-96969586,-96979658,-96989870,
-96999757,-97009968,-97019944,-97031159,-97046898,-97062684,-97076225,
-97084873,-97093888,-97102624,-97111131,-97120232,-97127869,-97135323,
-97142911,-97155300,-97164714,-97172623,-97180803,-97188844,-97197116,
-97204928,-97209586,-97211645,-97213566,-97215483,-97217447,-97219367,
-97222287,-97225711,-97229316,-97232921,-97236433,-97243091,-97250251,
-97257319,-97264113,-97271178,-97277923,-97285033,-97291868,-97299024,
-97305995,-97313056,-97319935,-97326674,-97333642,-97340380,-97347302,
-97354220,-97358888,-97365874,-97372222,-97378611,-97384444,-97390277,
-97396224,-97402222,-97405555,-97408888,-97411780,-97415000,-97418371,
-97421327,-97424462,-97427551,-97430779,-97434186,-97437411,-97440182,
-97441046,-97441910,-97442773,-97443636,-97444590,-97445406,-97446270,
-97447132,-97448130,-97449628,-97451306,-97452938,-97454616,-97456294,
-97457791,-97459331,-97460739,-97462596,-97464227,-97465905,-97467626,
-97469393,-97471160,-97468492,-97465324,-97461931,-97458540,-97455239,
-97452118,-97447551,-97442443,-97437650,-97432634,-97427618,-97422555,
-97417721,-97412705,-97408503,-97407599,-97406740,-97405250,-97402312,
-97396306,-97390256,-97384160,-97378021,-97372016,-97365969,-97359877,
-97353605,-97347199,-97340930,-97334526,-97328708,-97322576,-97316265,
-97310179,-97304006,-97297922,-97291659,-97286207,-97281116,-97275937,
-97270577,-97265579,-97260401,-97255223,-97249326,-97242079,-97234742,
-97227767,-97220523,-97213639,-97206397,-97199244,-97199469,-97209589,
-97207790,-97205328,-97218998,-97232577,-97246340,-97260716,-97274307,
-97287837,-97301487,-97314856,-97328743,-97343669,-97358674,-97373558,
-97388841,-97402500];

	var poiprev = 0;
	var map = null;
	var miltxt= null;
	var minmapsz = VEMiniMapSize.Large;
        var pixX = 0;
        var pixY = 0;
        var mmile = 0;

	function removeOptions(optionMenu)
	{
	  optionMenu.options.length = 0;
	}

	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 < 683; i++)
	  {
	   j++
	   milesgiw[j] = i;
	  }
	 addOptions(milesgiw,document.myform2.mile);
	}

        function preloadOpts()
        {
	      includechange();      
	}

	function UpdateInfo(e)
	{
	        var center = map.GetCenter();
		var ZL = e.zoomLevel;
		document.getElementById("info").innerHTML =
			'GULF INTRACOASTAL WATERWAY WEST:  Latitude = ' + 
			center.Latitude + 
			', Longitude = ' 
			+ center.Longitude + 
			', Zoom=' + 
			ZL ; 
	}
	
         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.909639, -90.083679), 14 ,'h' ,false);
                
                map.ShowDashboard();                
            
//                map.AttachEvent("onclick", PixelClick);
            
		map.AttachEvent("onendpan", UpdateInfo);
			
		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 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(mlat, mlng, mmile)
         {
            latLongcnt = new VELatLong(mlat, mlng);
            pin02 = new VEShape(VEShapeType.Pushpin, latLongcnt);
            pin02.SetTitle("<font color='blue'> Gulf Intracoastal Waterway West </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);
         } 	


        function markmile()
	{
	 AddShapes(mlat,mlng,mmile);	
	}

	function milehit(mmile)
	{
        mlat  = mlats[mmile] / 1000000;
        mlng  = mlngs[mmile] / 1000000;        
        var latLong = new VELatLong(mlat,mlng);
        map.PanToLatLong(latLong);        
        markmile(mlat, mlng, mmile);
        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 milechange()
	{
             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);  
 	       }
             }
        } 


