//Server instances should be loaded with the "layers" parameter (i.e., LAYERS=xxxxx) and the bbox parameter (i.e., BBOX=xx,xx,xx,xx) left off intentionally.
function doTimeMaps()
{
		var thisSvalue = top.get_cookie("sval");
		var thisTimestrStart = top.showclock2(thisSvalue);
		var thisTimestr = thisTimestrStart.replace(" ","T");
		var time = "&TIME="+thisTimestr;
		getTimeMaps(time);
}

function imgHeight()
		{
			var sheight = screen.height;
			sheight =  parseInt(sheight-(0.54427*sheight));//sheight - parseInt(0.17145*sheight); //580
			if (screen.height==1024) 
				{	
					sheight=sheight;
				}
			//alert(sheight);	
			return sheight;
		}
		
		
function imgWidth()
		{
			var sheight2 = screen.height;
			sheight2 =  parseInt(sheight2-(0.54427*sheight2));//sheight - parseInt(0.17145*sheight); //580
			if (screen.height==1024) 
				{	
					sheight2=sheight2;
				}
			var swidth = sheight2;
			swidth = parseInt(swidth*2); //876
			//alert(swidth);
			return swidth;
		}
		

var MapWidth = imgWidth();
var MapHeight = imgHeight();

 // record the server name	
 // var server = "http://mitch.csi.lsu.edu/wmsconnector/com.esri.wms.Esrimap?VERSION=1.1.1&REQUEST=GetMap&SERVICE=wms&FORMAT=image/png&TRANSPARENT=true&SRS=EPSG:NONE&WIDTH="+MapWidth+"&HEIGHT="+MapHeight+"&LAYERS=1,2,3,4,5,6&ServiceName=latlon";
var server = "http://arcims.coastmap.com/wmsconnector/com.esri.wms.Esrimap?VERSION=1.1.1&REQUEST=GetMap&SERVICE=wms&FORMAT=image/png&TRANSPARENT=true&SRS=EPSG:NONE&WIDTH="+MapWidth+"&HEIGHT="+MapHeight+"&LAYERS=1,2,3,4,5,6&ServiceName=ASAlatlon";

//alert(server);
var bbox = "";
//FYI - the LSU server is using the "servicename" parameter to differentiate between models. The LSU server is unique in this fashion.
var serviceName = "";

// second server instance
var server1 = "http://24.249.210.120/wms/wms_svr7.asp?REQUEST=GetMap&SERVICE=wms&version=1.1.1&WIDTH="+MapWidth+"&HEIGHT="+MapHeight+"&FORMAT=image/png&BGCOLOR=0xD0D0D0&SRS=EPSG:4326&TRANSPARENT=true";
var layerName1 = "";
var time1 = "";

// third server instance
var server2 = "http://www.metoc.gov.au:8080/wmsconnector/com.esri.wms.Esrimap/wms_mcsst?version=1.1.1&REQUEST=GetMap&SERVICE=OGC:WMS&WIDTH="+MapWidth+"&HEIGHT="+MapHeight+"&FORMAT=image/png&BGCOLOR=0xD0D0D0&SRS=EPSG:4326&TRANSPARENT=true";
var layerName2 = "";
   
// forth server instance
var server3 = "http://24.249.210.120/wms/wms_svr7.asp?REQUEST=GetMap&SERVICE=wms&version=1.1.1&WIDTH="+MapWidth+"&HEIGHT="+MapHeight+"&FORMAT=image/png&BGCOLOR=0xD0D0D0&SRS=EPSG:4326&TRANSPARENT=true";
var layerName3 = "";
var time3 = "";

// forth server instance
var server4 = "http://24.249.210.120/wms/wms_svr7.asp?request=GetMap&service=WMS&version=1.1.1&srs=EPSG:4326&format=image/png&styles=1,4&WIDTH="+MapWidth+"&HEIGHT="+MapHeight;
var layerName4 = "";
var time4 = "";

// fifth server instance
var server5 = "http://maps.customweather.com/image?request=GetMap&service=WMS&version=1.1.1&srs=EPSG:4326&format=image/png&transparent=true&&styles=simple&WIDTH="+MapWidth+"&HEIGHT="+MapHeight+"&layers=conditions";
var layerName5 = "";

// sixth server instance
var server6 = "http://24.249.210.120/wms/wms_svr7.asp?request=GetMap&service=WMS&version=1.1.1&srs=EPSG:4326&format=image/png&styles=1,4&WIDTH="+MapWidth+"&HEIGHT="+MapHeight;
var layerName6 = "";
var time6 = "";

// seventh server instance
var server7 = "http://24.249.210.120/wms/wms_svr7.asp?request=GetMap&service=WMS&version=1.1.1&srs=EPSG:4326&format=image/png&styles=1,4&WIDTH="+MapWidth+"&HEIGHT="+MapHeight;
var layerName7 = "";
var time7 = "";

// seventh server instance
var server8 = "http://24.249.210.120/wms/wms_svr7.asp?request=GetMap&service=WMS&version=1.1.1&srs=EPSG:4326&format=image/png&styles=1,4&WIDTH="+MapWidth+"&HEIGHT="+MapHeight;
var layerName8 = "";
var time8 = "";

//var landServer = "http://www2.demis.nl/mapserver/wms.asp?VERSION=1.1.0&REQUEST=GetMap&SRS=EPSG:4326&WIDTH="+MapWidth+"&HEIGHT="+MapHeight+"&LAYERS=Countries,Topography,Hillshading,Builtup+areas,Coastlines,Waterbodies,Inundated,Rivers,Streams,Railroads,Highways,Roads,Trails,Borders,Cities,Settlements,Spot+elevations,Airports,Ocean+features&FORMAT=image/gif&transparent=true&bbox="
//
////var landServer = "http://24.249.210.116/wmsconnector/com.esri.wms.Esrimap?VERSION=1.1.1&ServiceName=ASAWorld&REQUEST=GetMap&SERVICE=wms&FORMAT=image/png&BGCOLOR=0xD0D0D0&SRS=EPSG:NONE&LAYERS=0&TRANSPARENT=true&bbox=";
//
///*"http://mitch.csi.lsu.edu/wmsconnector/com.esri.wms.Esrimap?VERSION=1.1.1&ServiceName=land&REQUEST=GetMap&SERVICE=wms&WIDTH="+MapWidth+"&HEIGHT="+MapHeight+"&FORMAT=image/png&BGCOLOR=0xD0D0D0&SRS=EPSG:4326&LAYERS=101,103,104&TRANSPARENT=true&bbox=";
//
//*/
////var bathServer = "http://seamap.env.duke.edu/ogc/?VERSION=1.1.0&REQUEST=GetMap&SRS=EPSG:4326&WIDTH="+MapWidth+"&HEIGHT="+MapHeight+"&LAYERS=bath&FORMAT=image/gif&transparent=true&bbox=";
//
//var bathServer = "http://www2.demis.nl/mapserver/wms.asp?VERSION=1.1.0&REQUEST=GetMap&SRS=EPSG:4326&WIDTH="+MapWidth+"&HEIGHT="+MapHeight+"&LAYERS=Bathymetry&FORMAT=image/gif&transparent=true&bbox=";

var landServer ="http://www2.demis.nl/wms/wms.ashx?Service=WMS&WMS=WorldMap&VERSION=1.1.0&REQUEST=GetMap&SRS=EPSG:4326&WIDTH="+MapWidth+"&HEIGHT="+MapHeight+"&LAYERS=Countries,Topography,Hillshading,Coastlines,Waterbodies&FORMAT=image/gif&transparent=true&bbox=";

var bathServer ="http://www2.demis.nl/wms/wms.ashx?Service=WMS&WMS=WorldMap&VERSION=1.1.0&REQUEST=GetMap&SRS=EPSG:4326&WIDTH="+MapWidth+"&HEIGHT="+MapHeight+"&LAYERS=Bathymetry,Ocean+features&FORMAT=image/gif&transparent=true&bbox=";


 
// coordinates of the extent: top, left, bottom, right
var NorthAmer_Extent = new Array(65,-145,5,-25);
var Mississippi_Extent = new Array(30,-90.5,28.8,-89);
var Tampa_Extent = new Array(28.09,-83.41,27.29,-81.83);
var Miami_Extent = new Array(25.92,-80.64,25.37,-79.52);
var Chespeake_Extent = new Array(39.56,-78.07,36.77,-72.44);
var GulfMaine_Extent = new Array(46.12,-73.41,39.32,-59.77);
var GulfMexico_Extent = new Array(32.05,-102.02,18.62,-75.05);
var UNCADCIRC_Extent = new Array(46.5,-98,8,-49.875);
var CharlotteHarbor_Extent = new Array(26.9,-82.5,26.3,-81.75);
var NarraBay_Extent = new Array(41.78,-71.7,41.35,-70.85);
var LISound_Extent = new Array(41.57,-74.18,40.4,-71.82);
var NewYorkHarbor_Extent = new Array(41.01,-74.63,40.12,-72.85);
var Mediter_Extent = new Array(51.23,-5.84,28.17,41.31);
var Indian_Extent = new Array(29.84,22.01,-26.79,136.82);
var WestPac_Extent = new Array(45.16,68.18,-9.48,179.75);
var SouthPac_Extent = new Array(6.63,-179.33,-77.83,-6.88);
var NorthPac_Extent = new Array(61.57,-179.99,10.53,-78.62);
var NorthAtlan_Extent = new Array(66.47,-87.74,12.52,21.79);
var SouthAtlan_Extent = new Array(10.03,-70.61,-44.08,39.07);
var Africa_Extent = new Array(40.39,-45.98,-39.88,117.14);
var Australia_Extent = new Array(-4.98,91.06,-49.69,179.14);

// Global vars to save the rectangle the mouse draw		
var rectLeft=0;
var rectTop=0;
var rectRight=0;
var rectBottom=0;        
	    
// Global vars to save the coordinates of the map		
var mapLeft=0;
var mapTop=0;
var mapRight=0;
var mapBottom=0;

// Global vars to save the coordinates of the map to request server
var newMapLeft;
var newMapRight;
var newMapTop;
var newMapBottom;

// set the defaultMap address
var emptyImg = new Image();
emptyImg.src = "/images2/pixel.gif"
//defaultMap.src = getDefaultMap();

//legend images
var legendImg = new Array(5);
legendImg[0] = new Image();
legendImg[0].src = "/images2/dirlegend.jpg";  //water direction
legendImg[1] = new Image();
legendImg[1].src = "/images2/knotlegend.jpg";   //water level
legendImg[2] = new Image();
legendImg[2].src = "/images2/spdlegend.jpg";  //water speed
legendImg[3] = new Image();
legendImg[3].src = "/images2/wvlegend.jpg";   //wave height
legendImg[4] = new Image();
legendImg[4].src = "/images2/pixel.gif";   //wave direction  
legendImg[5] = new Image();
legendImg[5].src = "/images2/wplegend.jpg";   //wave period
legendImg[6] = new Image();
legendImg[6].src = "/images2/0.jpg";   //sea surface temp period
legendImg[7] = new Image();
legendImg[7].src = "/images2/Wx_legend.gif";   //sea surface temp period


    //help function to format number for "x" number of trailing decimals
	Number.prototype.Fixed=function(n){
		var t=Math.pow(10,n);
		return Math.round(this*t)/t;
	}


   //calculate the right coord depends on the other coords (DEPRECATED!!!)
   function getRightCoord(top, left, bottom){
    var right=(top-bottom)*iWidth/iHeight+left;	
	return right.Fixed(2);	
   }
     
   //get the default map, run after the map loaded
   //-78.72,36.53,-72.24,39.77
 function getDefaultMap(){
		 mapLeft=-145;
		 mapBottom=5;
		 mapRight=-25;	 
		 mapTop=65;
		// mapRight=getRightCoord(mapTop,mapLeft,mapBottom);	 
		 
    // return server + requestName + serviceName_land + layers_land + "&BBOX=" +bbox + imgWidth + imgHeight + format + transparent +srs;
	
	   initialMap();
   } 
	 
   function controlMap(cmd){

	   if(cmd=="FullExtent"){
		//full extent for chesapeake
		 mapLeft=-179.9;
		 mapBottom=-89;
		 mapRight=179.9;	 
		 mapTop=89;
		// mapRight=getRightCoord(mapTop,mapLeft,mapBottom);	 
	//	 alert(	 mapRight);	 
	   }else if(cmd=="ZOOMIN")
		 getZoomInMapExtent();
	   else if(cmd=="ZOOMOUT")
		 getZoomOutMapExtent();
	   else if(cmd=="PAN")
		 getPanMapExtent(); 	   
   }

   //change the screen position to the map coordinate  (X value)   
   function getXcoord(x){
        var xCoord;  
        var imgW = iWidth;
        xCoord = mapLeft + x * (mapRight-mapLeft)/imgW ;
        return xCoord;
   }
   
   //change the screen position to the map coordinate  (Y value)
   function getYcoord(y){
        var yCord;  
		var imgH = iHeight;
        yCoord =  mapTop + y * (mapBottom-mapTop)/imgH ;
        return yCoord;
   }   
   
   
   // get the map extent after the zoom in
   function getZoomInMapExtent(){

    var rectW = rectRight-rectLeft;
	var rectH = rectBottom-rectTop;
	
	var imgW = iWidth;
	var imgH = iHeight;
	var mapW ;
	var mapH ;
	
    var ratio;      //zoom in ratio
	
	var xCenter;
	var yCenter;
		
	xCenter= getXcoord((rectRight+rectLeft)/2);
	yCenter= getYcoord((rectBottom+rectTop)/2);
	
	if(rectW<10&&rectH<10){
	   ratio=0.5;                   // if just click the mouse or drag a little, do zoom in at a fix ratio
	}else if (imgW/rectW >= imgH/rectH){  		//do zoom in depends on the mouse draw height 	
	   ratio= rectH/imgH;            //zoom in ratio
	}else{
	   ratio= rectW/imgW;            //zoom in ratio
	}
	
	   //caculate the map width and height
	mapW = (mapRight-mapLeft) * ratio;
	mapH = (mapTop-mapBottom) * ratio;
	
	newMapLeft =  xCenter - mapW/2;
	newMapRight = xCenter + mapW/2;
	newMapTop = yCenter + mapH/2 ;
	newMapBottom = yCenter - mapH/2 ;
		
	
	mapLeft = newMapLeft;
	mapRight = newMapRight;
	mapTop = newMapTop;
	mapBottom = newMapBottom;	
   }
   
   
    // get the map extent after the zoom out
    function getZoomOutMapExtent(){

    var rectW = rectRight-rectLeft;
	var rectH = rectBottom-rectTop;
	
	var imgW = iWidth;
	var imgH = iHeight;
	var mapW ;
	var mapH ;
	
	var xCenter;
	var yCenter;
		
    var ratio;      //zoom out ratio
	   	
	xCenter= getXcoord((rectRight+rectLeft)/2);
	yCenter= getYcoord((rectBottom+rectTop)/2);
		
	if(rectW<10&&rectH<10){
	   ratio= 2;                   // if just click the mouse or drag a little, do zoom out at a fix ratio
    }else if (imgW/rectW >= imgH/rectH){  		//do zoom out depends on the mouse draw height 	
	   ratio= imgH/rectH;            //zoom out ratio
	}else{
	   ratio= imgW/rectW;            //zoom out ratio
	}
	
	   //caculate the map width and height
	mapW = (mapRight-mapLeft) * ratio;
	mapH = (mapTop-mapBottom) * ratio;
	
	newMapLeft =  xCenter - mapW/2;
	newMapRight = xCenter + mapW/2;
	newMapTop = yCenter + mapH/2 ;
	newMapBottom = yCenter - mapH/2 ;
		
	mapLeft = newMapLeft;
	mapRight = newMapRight;
	mapTop = newMapTop;
	mapBottom = newMapBottom;
	
   }
   
   
    // get the map extent after the pan
    function getPanMapExtent(){
	
	var xStart;      // pan start point's x value 
	var yStart;      // pan start point's y value 
	
	var xEnd;   // pan end point's x value 
	var yEnd;   // pan end point's y value 
	
   /***********************  WARNING!!!  *********************************************************
	   start point is rectLeft and rectTop (no matter where and which direction you move)
	   end point is is rectRight and rectBottom (no matter where and which direction you move)   	
   ***********************************************************************************************/
	xStart = getXcoord(rectLeft);
	yStart = getYcoord(rectTop);
	
	xEnd = getXcoord(rectRight);
	yEnd = getYcoord(rectBottom);
	
	newMapLeft =  xStart - xEnd + mapLeft;
	newMapRight = xStart - xEnd + mapRight;
	newMapTop = yStart - yEnd + mapTop;
	newMapBottom = yStart - yEnd + mapBottom;
		
	mapLeft = newMapLeft;
	mapRight = newMapRight;
	mapTop = newMapTop;
	mapBottom = newMapBottom;	
   }
   
 
    //get the map extent depends on the area selected
   function changeArea(areaID){
      var id= areaID;
	  
	  if(id==0){
		mapLeft=NorthAmer_Extent[1];  
	    mapBottom=NorthAmer_Extent[2];  
        mapRight=NorthAmer_Extent[3];  
  	    mapTop=NorthAmer_Extent[0];
	  }
	  else if(id==1){
	    mapLeft=Mississippi_Extent[1];  
	    mapBottom=Mississippi_Extent[2];  
        mapRight=Mississippi_Extent[3];  
  	    mapTop=Mississippi_Extent[0];  

	  }else	if(id==2){
	    mapLeft=Tampa_Extent[1];  
	    mapBottom=Tampa_Extent[2];  
        mapRight=Tampa_Extent[3];  
  	    mapTop=Tampa_Extent[0];  
	  }else	if(id==3){
	    mapLeft=Miami_Extent[1];  
	    mapBottom=Miami_Extent[2];  
        mapRight=Miami_Extent[3];  
  	    mapTop=Miami_Extent[0];  
	  }else	if(id==4){
	    mapLeft=Chespeake_Extent[1];  
	    mapBottom=Chespeake_Extent[2];  
        mapRight=Chespeake_Extent[3];  
  	    mapTop=Chespeake_Extent[0];  
	  }else	if(id==5){
	    mapLeft=GulfMaine_Extent[1];  
	    mapBottom=GulfMaine_Extent[2];  
        mapRight=GulfMaine_Extent[3];  
  	    mapTop=GulfMaine_Extent[0];  
	  }else	if(id==6){
	    mapLeft=GulfMexico_Extent[1];  
	    mapBottom=GulfMexico_Extent[2];  
        mapRight=GulfMexico_Extent[3];  
  	    mapTop=GulfMexico_Extent[0];  
	  }else	if(id==7){
	    mapLeft=UNCADCIRC_Extent[1];  
	    mapBottom=UNCADCIRC_Extent[2];  
        mapRight=UNCADCIRC_Extent[3];  
  	    mapTop=UNCADCIRC_Extent[0];  
	  }else	if(id==8){
	    mapLeft=CharlotteHarbor_Extent[1];  
	    mapBottom=CharlotteHarbor_Extent[2];  
        mapRight=CharlotteHarbor_Extent[3];  
  	    mapTop=CharlotteHarbor_Extent[0];  
	  } else	if(id==9){
	    mapLeft=NarraBay_Extent[1];  
	    mapBottom=NarraBay_Extent[2];  
        mapRight=NarraBay_Extent[3];  
  	    mapTop=NarraBay_Extent[0];  
	  } else	if(id==10){
	    mapLeft=LISound_Extent[1];  
	    mapBottom=LISound_Extent[2];  
        mapRight=LISound_Extent[3];  
  	    mapTop=LISound_Extent[0];  
	  } else if(id==11){
	    mapLeft=NewYorkHarbor_Extent[1];  
	    mapBottom=NewYorkHarbor_Extent[2];  
        mapRight=NewYorkHarbor_Extent[3];  
  	    mapTop=NewYorkHarbor_Extent[0];  
	  }   
	  else	if(id==12){
	    mapLeft=Mediter_Extent[1];  
	    mapBottom=Mediter_Extent[2];  
        mapRight=Mediter_Extent[3];  
  	    mapTop=Mediter_Extent[0];  
	  } 
	  else	if(id==13){
	    mapLeft=Indian_Extent[1];  
	    mapBottom=Indian_Extent[2];  
        mapRight=Indian_Extent[3];  
  	    mapTop=Indian_Extent[0];  
	  } 
	  else	if(id==14){
	    mapLeft=WestPac_Extent[1];  
	    mapBottom=WestPac_Extent[2];  
        mapRight=WestPac_Extent[3];  
  	    mapTop=WestPac_Extent[0];  
	  } 
	  else	if(id==15){
	    mapLeft=SouthPac_Extent[1];  
	    mapBottom=SouthPac_Extent[2];  
        mapRight=SouthPac_Extent[3];  
  	    mapTop=SouthPac_Extent[0];  
	  }
	   else	if(id==16){
	    mapLeft=NorthPac_Extent[1];  
	    mapBottom=NorthPac_Extent[2];  
        mapRight=NorthPac_Extent[3];  
  	    mapTop=NorthPac_Extent[0];  
	  }
	  else	if(id==17){
	    mapLeft=NorthAtlan_Extent[1];  
	    mapBottom=NorthAtlan_Extent[2];  
        mapRight=NorthAtlan_Extent[3];  
  	    mapTop=NorthAtlan_Extent[0];  
	  }
	   else	if(id==18){
	    mapLeft=SouthAtlan_Extent[1];  
	    mapBottom=SouthAtlan_Extent[2];  
        mapRight=SouthAtlan_Extent[3];  
  	    mapTop=SouthAtlan_Extent[0];  
	  }
	  else	if(id==19){
	    mapLeft=Africa_Extent[1];  
	    mapBottom=Africa_Extent[2];  
        mapRight=Africa_Extent[3];  
  	    mapTop=Africa_Extent[0];  
	  }
	  else	if(id==20){
	    mapLeft=Australia_Extent[1];  
	    mapBottom=Australia_Extent[2];  
        mapRight=Australia_Extent[3];  
  	    mapTop=Australia_Extent[0];  
	  }
	  //get the map
	  getMap();           
   }     
  
   // change the layer name(time period) of the request string
   function changeTime(time){
   	  layers = "&LAYERS=" + time;
	  getTimeMaps();
   }	
	
	
   
   // test to change the landserver base map of the request string
   function changeLandServer(serverName)
   {   
   	 landServer = serverName; 
	 
	 getLandMap();  	  
 	}
   
      // test to change the overlayServers map of the request string
   function changeOverlayServer(serverName)
   {   
   	 overlayServer = serverName; 
	 
	 getMap();  	  
 	}

 // global change the model name of the request string
 function globalChangeModel(server,layerName,time,layerNumber,isTimeLayer)
 	{  
   
   	var thisSvalue = top.get_cookie("sval");
    //alert(thisSvalue);
	if (thisSvalue == "")
		{
		var thisdate=new Date();
		// format output.  example: 2005-11-28T00:00
		var month=thisdate.getUTCMonth()+1;
		var day=thisdate.getUTCDate();
		var year=thisdate.getUTCFullYear();
		var hour=thisdate.getUTCHours();
		if (hour<10) {hour="0" + hour;}
		if (day<10) {day="0" + day;}
		if (month<10) {month="0" + month;}
		var thisTimestr = year + "-" + month + "-" + day + "T" + hour + ":00";
		//alert("no-timestr"+thisTimestr);
		}
	 else
	 	{
		var thisTimestrStart = top.showclock2(thisSvalue);
		var thisTimestr = thisTimestrStart.replace(" ","T");
		//alert("top.timestr"+thisTimestr);
		}
		
	 //update legend
	 updateLegend(layerName);	
	 
   	 globalServer = server;
	 theLayerName = layerName;
   	 layerName = "&LAYERS=" +layerName; 
	 //alert(theLayerName+"~~~"+layerName);
	 if (isTimeLayer==1) 
	 	{time = "&TIME=" +thisTimestr;}
		
	 else if (isTimeLayer==0)
	 	{time = "";}
		
	 layerNumber = layerNumber;
	 globalGetMap(globalServer,theLayerName,layerName,layerNumber,time);  	  
 	 
   }


//global get map individually and update the map  
function globalGetMap(globalServer,theLayerName,layerName,layerNumber,time){  
   
		bbox =  mapLeft.Fixed(3) + "," + mapBottom.Fixed(3) + "," + mapRight.Fixed(3) + "," + mapTop.Fixed(3);
		
		var theLayerNumber = layerNumber;
		var layerIdName = "mapLayer" +theLayerNumber;
		var imageIdName = "mapImage" +theLayerNumber;
		
		var globalMapURL = globalServer +layerName + "&BBOX=" +bbox +time +"&width="+MapWidth+"&height="+MapHeight;
		
		showLoading(1);   //show the "loading" label
		globalHideMap(layerIdName);    // hide the model map to void the flash in map load show
		//alert(globalMapURL);
		
		//alert(theLayerName+"~~"+layerIdName +"~~"+ imageIdName);
		if(theLayerName ==""){  //if the model map parameters is not set, use the empty image replace it
		   document.getElementById(imageIdName).src = emptyImg.src;
		}else{		 
		   document.getElementById(imageIdName).src = globalMapURL;
		   //showModelMap();
		}
   }  
 

  /*get the full layered map and update the map  
   function getMapNew()
   		{   
		
		var thisSvalue = top.get_cookie("sval");
        if (thisSvalue == "")
			{
			var thisdate=new Date();
			// format output.  example: 2005-11-28T00:00
			var month=thisdate.getMonth()+1;
			var day=thisdate.getDate();
			var year=thisdate.getYear();
			var hour=thisdate.getHours();
			if (hour<10) {hour="0" + hour;}
			if (day<10) {day="0" + day;}
			if (month<10) {month="0" + month;}
			var thisTimestr = year + "-" + month + "-" + day + "T" + hour + ":00";
			//alert("no-timestr"+thisTimestr);
			}
	 	else
	 		{
			var thisTimestr = top.showclock2(thisSvalue);
			//alert("top.timestr"+thisTimestr);
			}
			
			
   		bbox =  mapLeft.Fixed(3) + "," + mapBottom.Fixed(3) + "," + mapRight.Fixed(3) + "," + mapTop.Fixed(3);
   		
		//static base layers
   		var landMapURL = landServer +bbox;
		
		var bathMapURL = bathServer +bbox;
		
		var gridMapURL =  server +serviceName + "&BBOX=" +bbox;
		
		showLoading(3);   //show the "loading" label	
        		
		document.getElementById("landMapImage").src = landMapURL;
		document.getElementById("gridMapImage").src = gridMapURL;
		document.getElementById("bathMapImage").src = bathMapURL;
		
		//process all additional layers
		//time Varying Layer
   		var getTimeLayers = top.get_cookie ("timeLayers");
		//alert(getTimeLayers);
		var splitTimeLayers = getTimeLayers.split("~");
		var theLength = splitTimeLayers.length;
		//alert(theLength);
		for (i=0; i<splitTimeLayers.length; i++)
			{
			var thisItem = splitTimeLayers[i];
			if (thisItem != "x")
				{
				var layerInfo = thisItem.split("|"); 
				var thisNum = layerInfo[0];
				var thisLayer = "mapLayer"+layerInfo[0];
				var thisImage = "mapImage"+layerInfo[0];
				var thisLayerName = layerInfo[2];
				
				//alert(thisLayer+"~"+thisImage+"~"+thisLayerName+"~"+layerInfo[1]);
				var thisURL = layerInfo[1] +"&layers="+thisLayerName + "&BBOX=" +bbox +"&TIME="+thisTimestr +"&width="+MapWidth+"&height="+MapHeight;
				//alert(thisURL);
				globalHideMap(thisLayer);
				//alert(thisLayerName+thisLayer);
				//set constant variable 
					if(thisLayerName =="")
					{  //if the map parameters is not set, use the empty image replace it
					   document.getElementById(thisImage).src = emptyImg.src;
					}else{		 
					   document.getElementById(thisImage).src = thisURL;
					   globalMapOnShow = true;
					   globalRefreshMap(thisLayer,thisNum);
					}	
				 }
			  }
		
		//non-time Varying Layer
   		var getNonTimeLayers = top.get_cookie ("nonTimeLayers");
		//alert(getTimeLayers);
		var splitNonTimeLayers = getNonTimeLayers.split("~");
		var theLength = splitNonTimeLayers.length;
		//alert(theLength);
		for (i=0; i<splitNonTimeLayers.length; i++)
			{
			var thisItem = splitNonTimeLayers[i];
			if (thisItem != "y")
				{
				var layerInfo = thisItem.split("|"); 
				var thisNum = layerInfo[0];
				var thisLayer = "mapLayer"+layerInfo[0];
				var thisImage = "mapImage"+layerInfo[0];
				var thisLayerName = layerInfo[2];
				
				//alert(thisLayer+"~"+thisImage+"~"+thisLayerName+"~"+layerInfo[1]);
				var thisURL = layerInfo[1] +"&layers="+thisLayerName + "&BBOX=" +bbox +"&width="+MapWidth+"&height="+MapHeight;
				//alert(thisURL);
				globalHideMap(thisLayer);
				//alert(thisLayerName+thisLayer);
				//set constant variable 
					if(thisLayerName =="")
					{  //if the map parameters is not set, use the empty image replace it
					   document.getElementById(thisImage).src = emptyImg.src;
					}else{		 
					   document.getElementById(thisImage).src = thisURL;
					   globalMapOnShow = true;
					   globalRefreshMap(thisLayer,thisNum);
					}	
				 }
			  }
		
   		}

		***************************************************************************************
			                  load map images from server
		***************************************************************************************
*/ 

function initialMap()
	{
	   		bbox =  mapLeft.Fixed(3) + "," + mapBottom.Fixed(3) + "," + mapRight.Fixed(3) + "," + mapTop.Fixed(3);
   		
		//static base layers
   		var landMapURL = landServer +bbox+"&width="+MapWidth+"&height="+MapHeight;
		
		var bathMapURL = bathServer +bbox+"&width="+MapWidth+"&height="+MapHeight;
		
		var gridMapURL =  server +serviceName + "&BBOX=" +bbox+"&width="+MapWidth+"&height="+MapHeight;
		
		showLoading(3);   //show the "loading" label	
        		
		document.getElementById("landMapImage").src = landMapURL;
		document.getElementById("gridMapImage").src = gridMapURL;
		document.getElementById("bathMapImage").src = bathMapURL;
		  		
				//hide all layers not visible on start
				globalHideMap("mapLayer1");
		        globalHideMap("mapLayer2");
		        globalHideMap("mapLayer3");   
		        globalHideMap("mapLayer4");
		        globalHideMap("mapLayer5");
		        globalHideMap("mapLayer6");
		        globalHideMap("mapLayer7"); 
		        globalHideMap("mapLayer8");
		        globalHideMap("mapLayer9");
			    globalHideMap("mapLayer10");
			    globalHideMap("mapLayer11");
		        globalHideMap("mapLayer12");
		        globalHideMap("mapLayer13");   
		        globalHideMap("mapLayer14");
		        globalHideMap("mapLayer15");
		        globalHideMap("mapLayer16");
		        globalHideMap("mapLayer17");   
		        globalHideMap("mapLayer18");
				globalHideMap("mapLayer19");
				globalHideMap("mapLayer20");
				globalHideMap("mapLayer21");
				globalHideMap("mapLayer22");
				globalHideMap("mapLayer23");
				globalHideMap("mapLayer24");
				
				
	}
   //get the full layered map and update the map  
function getMap()
   		{   
		//alert("here");
		var thisSvalue = top.get_cookie("sval");
        if (thisSvalue == "")
			{
			var thisdate=new Date();
			// format output.  example: 2005-11-28T00:00
			var month=thisdate.getMonth()+1;
			var day=thisdate.getDate();
			var year=thisdate.getYear();
			var hour=thisdate.getHours();
			if (hour<10) {hour="0" + hour;}
			if (day<10) {day="0" + day;}
			if (month<10) {month="0" + month;}
			var thisTimestr = year + "-" + month + "-" + day + "T" + hour + ":00";
			//alert("no-timestr"+thisTimestr);
			}
	 	else
	 		{
			var thisTimestr = top.showclock2(thisSvalue);
			//alert("top.timestr"+thisTimestr);
			}
			
			
   		bbox =  mapLeft.Fixed(3) + "," + mapBottom.Fixed(3) + "," + mapRight.Fixed(3) + "," + mapTop.Fixed(3);
   		
		//static base layers
   		var landMapURL = landServer +bbox+"&width="+MapWidth+"&height="+MapHeight;
		//alert(landMapURL);
		var bathMapURL = bathServer +bbox+"&width="+MapWidth+"&height="+MapHeight;
		
		var gridMapURL =  server +serviceName + "&BBOX=" +bbox+"&width="+MapWidth+"&height="+MapHeight;
		
		showLoading(3);   //show the "loading" label	
        		
		document.getElementById("landMapImage").src = landMapURL;
		document.getElementById("gridMapImage").src = gridMapURL;
		document.getElementById("bathMapImage").src = bathMapURL;
		
		
		//process all additional layers
		//time Varying Layer
		
		var getTimeLayers = top.get_cookie("timeLayers");
		var splitTimeLayers = getTimeLayers.split("~");
		var theLength = splitTimeLayers.length;
		
		for (i=0; i<splitTimeLayers.length; i++)
			{
			var thisItem = splitTimeLayers[i];
			//alert(thisItem);
			if (thisItem != "x")
				{
				var layerInfo = thisItem.split("|"); 
				var thisNum = layerInfo[0];
				var thisLayer = "mapLayer"+layerInfo[0];
				var thisImage = "mapImage"+layerInfo[0];
				var thisLayerName = layerInfo[2];
				
				//alert(thisLayer+"~"+thisImage+"~"+thisLayerName+"~"+layerInfo[1]);
				var thisURL = layerInfo[1] +"&layers="+thisLayerName + "&BBOX=" +bbox +"&TIME="+thisTimestr +"&width="+MapWidth+"&height="+MapHeight;
				//alert(thisURL);
				globalHideMap(thisLayer);
				//alert(thisLayerName+thisLayer);
				//set constant variable 
					if(thisLayerName =="")
					{  //if the map parameters is not set, use the empty image replace it
					   document.getElementById(thisImage).src = emptyImg.src;
					}else{		 
					   document.getElementById(thisImage).src = thisURL;
					   globalMapOnShow = true;
					   globalRefreshMap(thisLayer,thisNum);
					}	
				 }
			  }
		   
		//non-time Varying Layer
   		var getNonTimeLayers = top.get_cookie ("nonTimeLayers");
		//alert(getTimeLayers);
		var splitNonTimeLayers = getNonTimeLayers.split("~");
		var theLength = splitNonTimeLayers.length;
		//alert(theLength);
		for (i=0; i<splitNonTimeLayers.length; i++)
			{
			var thisItem = splitNonTimeLayers[i];
			if (thisItem != "y")
				{
				var layerInfo = thisItem.split("|"); 
				var thisNum = layerInfo[0];
				var thisLayer = "mapLayer"+layerInfo[0];
				var thisImage = "mapImage"+layerInfo[0];
				var thisLayerName = layerInfo[2];
				
				//alert(thisLayer+"~"+thisImage+"~"+thisLayerName+"~"+layerInfo[1]);
				var thisURL = layerInfo[1] +"&layers="+thisLayerName + "&BBOX=" +bbox +"&width="+MapWidth+"&height="+MapHeight;
				//alert(thisURL);
				globalHideMap(thisLayer);
				
				//alert(thisLayerName+thisLayer);
				//set constant variable 
					if(thisLayerName =="")
					{  //if the map parameters is not set, use the empty image replace it
					   document.getElementById(thisImage).src = emptyImg.src;
					}else{		 
					   document.getElementById(thisImage).src = thisURL;
					   globalMapOnShow = true;
					   globalRefreshMap(thisLayer,thisNum);
					}	
				 }
			  }
			    
			    globalHideMap("mapLayer1");
		        globalHideMap("mapLayer2");
		        globalHideMap("mapLayer3");   
		        globalHideMap("mapLayer4");
		        globalHideMap("mapLayer5");
		        globalHideMap("mapLayer6");
		        globalHideMap("mapLayer7"); 
		        globalHideMap("mapLayer8");
		        globalHideMap("mapLayer9");
			    globalHideMap("mapLayer10");
			    globalHideMap("mapLayer11");
		        globalHideMap("mapLayer12");
		        globalHideMap("mapLayer13");   
		        globalHideMap("mapLayer14");
		        globalHideMap("mapLayer15");
		        globalHideMap("mapLayer16");
		        globalHideMap("mapLayer17");   
		        globalHideMap("mapLayer18");
				globalHideMap("mapLayer19");
				globalHideMap("mapLayer20");
				globalHideMap("mapLayer21");
				globalHideMap("mapLayer22");
				globalHideMap("mapLayer23");
				globalHideMap("mapLayer24");
				
				
			if(document.all)
					{		//if is IE
						if(document.getElementById("landMapImage").readyState=="complete")
							{
						   alert("complete");
						   hideLoading();
							}
				    }
					else
					{     //if Mozilla
					    loadCounts--;
						if(loadCounts==0)  // if all images loaded
             			    hideLoading();
					}
   		}


//get the land map and update the map  
  function getLandMap(){  
   
		bbox =  mapLeft.Fixed(3) + "," + mapBottom.Fixed(3) + "," + mapRight.Fixed(3) + "," + mapTop.Fixed(3);
		var landMapURL = landServer +bbox +"&width="+MapWidth+"&height="+MapHeight;
		document.getElementById("landMapImage").src = landMapURL;
		
  		}
		


     //get the time layered maps and update the maps   
   function getTimeMaps(time){  
   
		bbox =  mapLeft.Fixed(3) + "," + mapBottom.Fixed(3) + "," + mapRight.Fixed(3) + "," + mapTop.Fixed(3);
		
		//process all additional layers
		//time Varying Layer
   		var getTimeLayers = top.get_cookie ("timeLayers");
		//alert(getTimeLayers);
		var splitTimeLayers = getTimeLayers.split("~");
		var theLength = splitTimeLayers.length;
		//alert(theLength);
		for (i=0; i<splitTimeLayers.length; i++)
			{
			var thisItem = splitTimeLayers[i];
			if (thisItem != "x")
				{
				var layerInfo = thisItem.split("|"); 
				var thisNum = layerInfo[0];
				var thisLayer = "mapLayer"+layerInfo[0];
				var thisImage = "mapImage"+layerInfo[0];
				var thisLayerName = layerInfo[2];
				
				//alert(thisLayer+"~"+thisImage+"~"+thisLayerName+"~"+layerInfo[1]);
				var thisURL = layerInfo[1] +"&layers="+thisLayerName + "&BBOX=" +bbox +time +"&width="+MapWidth+"&height="+MapHeight;
				//alert(thisURL);
				globalHideMap(thisLayer);
				//alert(thisLayerName+thisLayer);
				//set constant variable 
					if(thisLayerName =="")
					{  //if the map parameters is not set, use the empty image replace it
					   document.getElementById(thisImage).src = emptyImg.src;
					}else{		 
					   document.getElementById(thisImage).src = thisURL;
					   globalMapOnShow = true;
					   globalRefreshMap(thisLayer,thisNum);
					}	
				 }
			  }
	}
   
// update legend content
  function 	updateLegend(name){ 
	  var legend= top.document.getElementById("legendImage"); 
      switch(name){
   				case "gfs_winds":
                         legend.src= legendImg[1].src;
                         break;	
                case "nam_winds":
                         legend.src= legendImg[1].src;
                         break;	         	 
                case "0":
                         legend.src= legendImg[6].src;
                         break;	
				case "quoddy_currents":
                         legend.src= legendImg[0].src;
                         break;	
                case "asasa_currents":
                         legend.src= legendImg[0].src;
                         break;  
                case "hycom_currents":
                         legend.src= legendImg[0].src;
                         break; 
				case "ncom_currents":
                         legend.src= legendImg[0].src;
                         break;		 
				case "NDFDWX_weather":
                         legend.src= legendImg[7].src;
                         break;		 
           	 }
  }
