// JavaScript Document


function right(e) {
if (navigator.appName == 'Netscape' && 
(e.which == 3 || e.which == 2))
return false;
else if (navigator.appName == 'Microsoft Internet Explorer' && 
(event.button == 2 || event.button == 3)) {
alert("No functionality attached to right click.");
return false;
}
return true;
}



document.onmousedown=right;
document.onmouseup=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
window.onmousedown=right;
window.onmouseup=right;


// Global vars for browser type and version 
var isNav = (navigator.appName.indexOf("Netscape")>=0);
var isNav4 = false;
var isIE4 = false;
var is5up = false;




if (isNav) {			
	if(parseFloat(navigator.appVersion)<5) {
		isNav4=true;
		alert("For optimal results use Internet Explorer 5.0 or higher.");
	} else {
		alert("For optimal results use Internet Explorer 5.0 or higher.");
		is5up = true;
	}
} else if (document.all){
	isIE4=true;
	if (navigator.appVersion.indexOf("MSIE 5")>0 ||navigator.appVersion.indexOf("MSIE 6")>0) {
		isIE4 = false;
		is5up = true;
		//alert("IE5 upper");
	}
}


var XX = -70;
var YY = -70;
var cur_one = "emptycell"
var moving = false;
var xpos1 = 265;
var ypos1 = 125;
var myX = 0;
var myY = 0;

function InitializeMove() {
cur_one = "movmenu";
XX = eval("xpos1");
YY = eval("ypos1");
}

function CaptureMove() {
if (document.layers) document.captureEvents(Event.MOUSEMOVE);
}

function EndMove() {
if (document.layers) document.releaseEvents(Event.MOUSEMOVE);

cur_one = "emptycell"
moving = false;
document.close();
}

function WhileMove() {

  if (document.all) {
    eval(cur_one+".style.left="+myX);
    eval(cur_one+".style.top="+myY);
  }
  
  if (document.layers) {
    eval("document."+cur_one+".left="+myX);
    eval("document."+cur_one+".top="+myY);
  }
}

function MoveHandler(e) {

myX = (document.all) ? event.clientX : e.pageX;
myY = (document.all) ? event.clientY : e.pageY;

  if (!moving) {
    diffX =  XX - myX;
    diffY = YY - myY;
    moving = true;
  if (cur_one == "emptycell") moving = false;
}
myX += diffX;
myY += diffY;

  if (moving) {
    xpos1 = myX;
    ypos1 = myY;
  }

WhileMove();
}

function ClearError() {
return true;
}

if (document.layers) {
document.captureEvents(Event.CLICK);
document.captureEvents(Event.DBLCLICK);
}

document.onmousemove = MoveHandler;
document.onclick = CaptureMove;
document.ondblclick = EndMove;
window.onerror = ClearError;

WhileMove();

//clock functions 
function showclock(i)
  {
    // function returns initial date below, rounded-down to 12am, plus i hours in text format.
    // remove date from within parens to get today's date.
    
	
	var sdate=new Date();
    // round down to 12am
    sdate.setHours(0);
    sdate.setMinutes(0);
    sdate.setSeconds(0);

    // add i hours
    var edate=new Date(sdate.getTime() + i*60*60*1000);

    // format output.  example: 2005-11-28T00:00
    var month=edate.getMonth()+1;
    var day=edate.getDate();
    var year=edate.getYear();
    var hour=edate.getHours();
    if (hour<10) {hour="0" + hour;}
	if (day<10) {day="0" + day;}
	if (month<10) {month="0" + month;}
    var timestr = year + "-" + month + "-" + day + " " + hour + ":00";

    return timestr;
  } 

	
	function showclock2(i)
  {
    // function returns date below, plus i hours in text format.
    
	var newDate=document.getElementById('startTime').value;
	 re = newDate.match(" "); ///T/
	 timetoshow = document.getElementById('startTime').value.split(re);
	 re2 = /-/
	 theDate = timetoshow[0].split(re2);
	 theTime = timetoshow[1];
	 
	 var newDateString = theDate[1]+"/"+theDate[2]+"/"+theDate[0]+" "+theTime+":00";
	 //alert(newDateString);
	 var sdate=new Date(newDateString);

    var edate=new Date(sdate.getTime() + i*60*60*1000);
    var month=edate.getUTCMonth()+1;
    var day=edate.getUTCDate();
    var year=edate.getUTCFullYear();
    var hour=edate.getUTCHours();
    if (hour<10) {hour="0" + hour;}
	if (day<10) {day="0" + day;}
	if (month<10) {month="0" + month;}
    var timestr = year + "-" + month + "-" + day + "T" + hour + ":00";
    return timestr;
  } 
  // this function is used to convert WMS time format into user understandable format
  function UserClock(i)
	{
    
	var newDate=document.getElementById('startTime').value;
	 re = newDate.match(" "); ///T/
	 timetoshow = document.getElementById('startTime').value.split(re);
	 re2 = /-/
	 theDate = timetoshow[0].split(re2);
	 theTime = timetoshow[1];
	 
	 var newDateString = theDate[1]+"/"+theDate[2]+"/"+theDate[0]+" "+theTime+":00";
	
	 var sdate=new Date(newDateString);
        // add i hours
    var edate=new Date(sdate.getTime() + i*60*60*1000);
    var month=edate.getMonth()+1;
    var day=edate.getDate();
    var year=edate.getFullYear();
    var hour=edate.getHours();
    if (hour<10) {hour="0" + hour;}
	if (day<10) {day="0" + day;}
	if (month<10) {month="0" + month;}
    var timestr = year + "-" + month + "-" + day + " " + hour + ":00";
    return timestr;
		
	}
	
// this function is used to update the start time, current time and end time after user input/editing of the starttime field.

function changeClock()
	{
	 var newDate=document.getElementById('StartTime').value;
	 document.getElementById('dateLabel').value=document.getElementById('StartTime').value;
	 	 
	  re = newDate.match(" ");
	 timetoshow = document.getElementById('StartTime').value.split(re);
	 
	 re2 = /-/;
	 theDate = timetoshow[0].split(re2);
	 theTime = timetoshow[1];
	 
	 var newDateString = theDate[1]+"/"+theDate[2]+"/"+theDate[0]+" "+theTime+":00";
	 
	 //reset ending time
	 var threeDaysOut = parseInt(theDate[2]) +3;
	 if (threeDaysOut <10)
	 	threeDaysOut = "0"+threeDaysOut;
	 var newDateString2 = theDate[0]+"-"+theDate[1]+"-"+threeDaysOut+" "+theTime;
	 document.getElementById('EndTime').value=newDateString2
	
	 var sdate=new Date(newDateString);
 
     var edate=new Date(sdate.getTime() + i*60*60*1000);

    // format output.  example: 2005-11-28T00:00
    var month=edate.getMonth()+1;
    var day=edate.getDate();
    var year=edate.getYear();
    var hour=edate.getHours();
    if (hour<10) {hour="0" + hour;}
	if (day<10) {day="0" + day;}
	if (month<10) {month="0" + month;}
   
	var timestr = year + "-" + month + "-" + day + "T" + hour + ":00";
	
    return timestr;
	
	
	 
	}
// end clock 


function moveTheSlider()
	{
	
	s.setValue(document.getElementById("h-value").value);
	window.onresize = function () 
						{
						s.recalculate();
						};
	}


function updateTime()
{
	var currenthour;
	var timeVariable;
	for(yval=0;yval<72;yval++)
	{
		if(document.getElementById("h-value").value == yval)
		{
//		document.getElementById('dateLabel').value = UserClock(showclock2(yval));
		document.getElementById('dateLabel').value = UserClock(yval);
		}
	}	
}
	
	
function moveTime()
  {
    var currenthour;
	var timeVariable;
	for(yval=0;yval<72;yval++)
	{
		if(document.getElementById("h-value").value == yval)
		{
		
		document.getElementById('dateLabel').value = UserClock(yval);
		var timeVariable = "&TIME="+showclock2(yval);
		frames['mapFrame'].getTimeMaps(timeVariable);
		}
	}
		
  }  
  
 
// animate time steps
function animateTime(thisStep)
  {
	var step = thisStep;
	//a variable that will keep track of the image currently being displayed.
	function slideit()
	{
		if (step<72)
			{
			var timeVariable = "&TIME="+showclock2(step);
			document.getElementById('dateLabel').value = UserClock(step);
			//alert('here');
			s.setValue(step);
			window.onresize = function () 
						{
						s.recalculate();
						};
			frames['mapFrame'].getTimeMaps(timeVariable);
			
			}
		else
			{
			step=2	
			var timeVariable = "&TIME="+showclock2(step);
			document.getElementById('dateLabel').value = UserClock(step);
			frames['mapFrame'].getTimeMaps(timeVariable);
			}
		moveStep(step);
		
		
	}
	slideit();
	

  }
  
function moveStep(step)
  	{
	var step2 = step +1;
	animation=setTimeout('animateTime(' + step2 + ')' ,1000);
	
	}
	
function incrementStep()
		{
			var currentStep = parseInt(document.getElementById("h-value").value);
			//alert(currentStep);
			var timeVariable;
			var newStep = currentStep +1;
			//alert(newStep);	
			if(newStep <72)
				{
					document.getElementById('dateLabel').value = UserClock(newStep);
					document.getElementById("h-value").value = newStep;
					var timeVariable = "&TIME="+showclock2(newStep);
					frames['mapFrame'].getTimeMaps(timeVariable);
				}
			else
				{
					var newStep = 1;
					document.getElementById('dateLabel').value = UserClock(newStep);
					document.getElementById("h-value").value = newStep;
					var timeVariable = "&TIME="+showclock2(newStep);
					frames['mapFrame'].getTimeMaps(timeVariable);
				}
			moveTheSlider();	
		}

function backStep()
		{
			var currentStep = parseInt(document.getElementById("h-value").value);
			//alert(currentStep);
			var timeVariable;
			var newStep = currentStep -1;
			//alert(newStep);	
			if(newStep >0)
				{
					document.getElementById('dateLabel').value = UserClock(newStep);
					document.getElementById("h-value").value = newStep;
					var timeVariable = "&TIME="+showclock2(newStep);
					frames['mapFrame'].getTimeMaps(timeVariable);
				}
			else
				{
					var newStep = 71;
					document.getElementById('dateLabel').value = UserClock(newStep);
					document.getElementById("h-value").value = newStep;
					var timeVariable = "&TIME="+showclock2(newStep);
					frames['mapFrame'].getTimeMaps(timeVariable);
				}
			moveTheSlider();	
		}
		
		
function rewindAnimation()
		{
			//alert(currentStep);
			var timeVariable;
			var newStep = 0;
			//alert(newStep);	
			if(newStep <72)
				{
					document.getElementById('dateLabel').value = UserClock(newStep);
					document.getElementById("h-value").value = newStep;
					var timeVariable = "&TIME="+showclock2(newStep);
					frames['mapFrame'].getTimeMaps(timeVariable);
				}
			else
				{
					var newStep = 1;
					document.getElementById('dateLabel').value = UserClock(newStep);
					document.getElementById("h-value").value = newStep;
					var timeVariable = "&TIME="+showclock2(newStep);
					frames['mapFrame'].getTimeMaps(timeVariable);
				}
			moveTheSlider();	
		}
 
	
  //end animation functions
  
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
  {  
    var cookie_string = name + "=" + escape ( value );
    if ( exp_y )
    {    
      var expires = new Date ( exp_y, exp_m, exp_d );
      cookie_string += "; expires=" + expires.toGMTString();
    }
    if ( path )
      cookie_string += "; path=" + escape ( path );
    if ( domain )
      cookie_string += "; domain=" + escape ( domain );
    if ( secure )
      cookie_string += "; secure";
    document.cookie = cookie_string;
  }

  function delete_cookie ( cookie_name )
  {
    var cookie_date = new Date ( );  
    cookie_date.setTime ( cookie_date.getTime() - 1 );
    document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
  }

  function get_cookie ( cookie_name )
  {  
    var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );
    if ( results )
      return ( unescape ( results[1] ) );
    else
      return null;
  }


function init()
  {
    var check =get_cookie ("wcheck");
    var currcheck =get_cookie ("currentscheck");
    var zsize = get_cookie("zoomval");
    var svalue = get_cookie("sval");
	
	//strings to carry displaying layer info
	delete_cookie("timeLayers");
	delete_cookie("nonTimeLayers");
	set_cookie("timeLayers","x");
	set_cookie("nonTimeLayers","y");
	
	//alert(get_cookie("timeLayers")+"|"+get_cookie("nonTimeLayers"));
	var imgvalue = ""; //get_cookie("imgvalue");
	var start, end;
    start = showclock(0);
    end = showclock(71);
    document.getElementById('StartTime').value = showclock(0);  //"2005-11-28 "+start+" :00:00";
    document.getElementById('dateLabel').value = showclock(0);  //"2005-11-28 "+start+" :00:00";
    document.getElementById('EndTime').value = showclock(71);  //"2005-11-28 "+ end+" :00:00";
	var thewidth = screen.width;
    var theheight = screen.height;
    //alert(thewidth+" "+theheight);
	setWindowView(thewidth,theheight);
	 
	if(svalue==null){document.getElementById("h-value").value = 0;}

    for(ival=0;ival<72;ival++)
    {	
	if (svalue==ival)
	{
		s.setValue(svalue);
		window.onresize = function () {s.recalculate();};
		moveTime();
	}
    }
	
	
	function setWindowView(swidth,sheight)
   {
	//alert("I am here");	
		document.getElementById('masterTable').style.width= parseInt(swidth-(0.0015625*swidth)) +"px";//1260 20
					
		document.getElementById('masterTable').style.height= parseInt(sheight-(0.244792*sheight)) +"px"; //840 184 
		document.getElementById('contentLayer').style.height=parseInt(sheight-(0.54427*sheight)) +"px"; // 580 43359375 //(sheight-(0.5146484375*sheight)-30) +"px"; //497 527 ) 0.56		
		document.getElementById('mapFrame').style.height= parseInt(sheight-(0.54427*sheight)) +"px";  
		
		var contentHeight = document.getElementById('contentLayer').style.height;
		var contentWidth = document.getElementById('contentLayer').style.width;
		//alert(contentHeight+"here"+contentWidth);
		
		var newContentWidth = parseInt(contentHeight)*2;
		//alert(contentHeight+"here"+newContentWidth);
		
		document.getElementById('contentLayer').style.width= newContentWidth +"px";
		document.getElementById('mapFrame').style.width= newContentWidth +"px"; //900 380
		
		//document.getElementById('contentLayer').style.width= parseInt(swidth-(0.3155*swidth)) +"px";
//		document.getElementById('mapFrame').style.width= parseInt(swidth-(0.3155*swidth)) +"px"; //900 380
		
		//alert(contentHeight+"here"+newContentWidth);
			
			
		document.getElementById('tdTools').style.width= parseInt(swidth-(0.2109375*swidth)) +"px"; //1010 270
		document.getElementById('tdTools').style.height= parseInt(sheight-(0.40104*sheight)) +"px";// 705 319
		//document.getElementById('MainRow').style.height= parseInt(height-(0.4097*height)) +"px"; //1010 270
		
		document.getElementById('navigation').style.height= parseInt(sheight-(0.4140625*sheight)) +"px";// 3115234375705 319
		document.getElementById('leftNavigation').style.height= parseInt(sheight-(0.4140625*sheight)) +"px";// 705 319
						
		document.getElementById('DivEndTime').style.left= parseInt(swidth-(0.14551*swidth)) +"px"; //1080 200 +5  0.15625
		document.getElementById('CurrentTime').style.left= parseInt(swidth-(0.41895*swidth)) +"px"; //680 600 +5
		document.getElementById('Animation').style.left= parseInt(swidth-(0.5605*swidth)) +"px"; //540 740 +5 578125
		document.getElementById('timeControl').style.left= parseInt(swidth-(0.5605*swidth)) +"px"; //540 740 +5
		document.getElementById('DivStartTime').style.left= parseInt(swidth-(0.73632*swidth)) +"px";//280 1000 +30
	
		document.getElementById('DivEndTime').style.top= parseInt(sheight-(0.3815*sheight)) +"px";//(sheight-(0.2896484375*sheight)) +"px"; //625 399
		document.getElementById('timeControl').style.top= parseInt(sheight-(0.3815*sheight)) +"px";//(sheight-(0.2896484375*sheight)) +"px"; //625 399
		document.getElementById('CurrentTime').style.top= parseInt(sheight-(0.3245*sheight)) +"px";//(sheight-(0.24*sheight)) +"px";//655 369
		document.getElementById('Animation').style.top= parseInt(sheight-(0.3245*sheight)) +"px";//(sheight-(0.2603515625*sheight)) +"px";//655 369
		document.getElementById('DivStartTime').style.top= parseInt(sheight-(0.3815*sheight)) +"px";//(sheight-(0.27*sheight)) +"px"; //625 399
					
		document.getElementById('leftNavigation').style.height= (sheight-(0.40104*sheight)) +"px";// 705 319
		//document.getElementById('Header').style.width= (swidth-(0.0015625*swidth)) +"px";//1260 20
		//document.getElementById('navigation').style.width= (sheight-(0.40104*sheight)) +"px";// 705 319		
		
		if (sheight==1024)
		{
			document.getElementById('MainRow').style.height= 715;//parseInt(height-(0.4097*height)) +"px"; //1010 270
			document.getElementById('mapFrame').style.height= parseInt(sheight-(0.54427*sheight)) +"px"; 
			document.getElementById('contentLayer').style.height=parseInt(sheight-(0.54427*sheight)) +"px";
					
			var contentHeight = document.getElementById('contentLayer').style.height;
			var contentWidth = document.getElementById('contentLayer').style.width;
			//alert(contentHeight+"here"+contentWidth);
			
			var newContentWidth = parseInt(contentHeight)*2;
			//alert(contentHeight+"here"+newContentWidth);
			
			document.getElementById('contentLayer').style.width= newContentWidth +"px";
			document.getElementById('mapFrame').style.width= newContentWidth +"px"; //900 380
		
		
			document.getElementById('DivEndTime').style.top= parseInt(sheight-(0.3815*sheight)) +"px";//(sheight-(0.2896484375*sheight)) +"px"; //625 399
			document.getElementById('timeControl').style.top= parseInt(sheight-(0.3815*sheight)) +"px";//(sheight-(0.2896484375*sheight)) +"px"; //625 399
			document.getElementById('CurrentTime').style.top= parseInt(sheight-(0.3245*sheight)) +"px";//(sheight-(0.24*sheight)) +"px";//655 369
			document.getElementById('Animation').style.top= parseInt(sheight-(0.3245*sheight)) +"px";//(sheight-(0.2603515625*sheight)) +"px";//655 369
			document.getElementById('DivStartTime').style.top= parseInt(sheight-(0.3815*sheight)) +"px";
			 
			document.getElementById('DivEndTime').style.left= 1050; //parseInt(swidth-(0.14551*swidth)) +"px"; //1080 200 +5  0.15625
			document.getElementById('leftNavigation').style.height= 705;// 319
			document.getElementById('DivStartTime').style.left= 280;// parseInt(swidth-(0.73632*swidth)) +"px";//280 1000 +30
		}
	}




	
			/* keep image in toolbar stick with cookie parsing */
			switch(imgvalue)
				{
				case "in":
				  SwapImage1()
				  break;
				case "out":
				  SwapImage2()
				  break;
				 case "full":
				  SwapImage3()
				  break;
				 case "recenter":
				  SwapImage4()
				  break;
				 case "query":
				  SwapImage5()
				  break;
				}
				
				/*end set sticky image*/
	
  }


  /*toolbar image swaps */
	function SwapImage1() {
  document.image1.src="images/icon_zoomin2_selected.gif";
  document.image2.src="images/icon_zoomout2.gif";
  document.image3.src="images/icon_full.gif";
  document.image4.src="images/icon_recenter.gif";
  document.image5.src="images/icon_query2.gif";
  document.image6.src="images/weather2.gif";
   set_cookie ("imgvalue", "in");
	}
		function SwapImage2() {
  document.image1.src="images/icon_zoomin2.gif";
  document.image2.src="images/icon_zoomout2_selected.gif";
  document.image3.src="images/icon_full.gif";
  document.image4.src="images/icon_recenter.gif";
  document.image5.src="images/icon_query2.gif";
  document.image6.src="images/weather2.gif";
  set_cookie ("imgvalue", "out");
	}
		function SwapImage3() {
  document.image1.src="images/icon_zoomin2.gif";
  document.image2.src="images/icon_zoomout2.gif";
  document.image3.src="images/icon_full_selected.gif";
  document.image4.src="images/icon_recenter.gif";
  document.image5.src="images/icon_query2.gif";
  document.image6.src="images/weather2.gif";
  set_cookie ("imgvalue", "full");
	}
		function SwapImage4() {
  document.image1.src="images/icon_zoomin2.gif";
  document.image2.src="images/icon_zoomout2.gif";
  document.image3.src="images/icon_full.gif";
  document.image4.src="images/icon_recenter_selected.gif";
  document.image5.src="images/icon_query2.gif";
  document.image6.src="images/weather2.gif";
  set_cookie ("imgvalue", "recenter");
	}
		function SwapImage5() {
  document.image1.src="images/icon_zoomin2.gif";
  document.image2.src="images/icon_zoomout2.gif";
  document.image3.src="images/icon_full.gif";
  document.image4.src="images/icon_recenter.gif";
  document.image5.src="images/icon_query2_selected.gif";
  document.image6.src="images/weather2.gif";
  set_cookie ("imgvalue", "query");
	}
	
			function SwapImage6() {
  document.image1.src="images/icon_zoomin2.gif";
  document.image2.src="images/icon_zoomout2.gif";
  document.image3.src="images/icon_full.gif";
  document.image4.src="images/icon_recenter.gif";
  document.image5.src="images/icon_query2.gif";
  document.image6.src="images/weather2.gif";
  delete_cookie ("imgvalue");
	}
	
				function SwapImage7() {
  document.image1.src="images/icon_zoomin2.gif";
  document.image2.src="images/icon_zoomout2.gif";
  document.image3.src="images/icon_full.gif";
  document.image4.src="images/icon_recenter.gif";
  document.image5.src="images/icon_query2.gif";
  document.image6.src="images/weather2_selected.gif";
  delete_cookie ("imgvalue");
	}
		

function queryWinView()
	{
		if (document.getElementById('queryWin').style.visibility=='visible')
		{
		document.getElementById('queryWin').style.visibility='hidden'; 
		}
		else
		if (document.getElementById('queryWin').style.visibility=='hidden')
		{
		document.getElementById('queryWin').style.visibility='visible'; 
		}
	}	

function weatherWinView()
	{
		if (document.getElementById('weatherWin').style.visibility=='visible')
		{
		document.getElementById('weatherWin').style.visibility='hidden'; 
		document.getElementById("theWeatherResponse").style.visibility = 'hidden';
		}
		else
		if (document.getElementById('weatherWin').style.visibility=='hidden')
		{
		document.getElementById('weatherWin').style.visibility='visible'; 
		}
		
	}	
function weatherWinView2(status)
	{
		if (status == 0)
		{
		document.getElementById('getWeather').style.visibility='hidden'; 
		}
		else
		if (status == 1)
		{
		document.getElementById('getWeather').style.visibility='visible'; 
		}
		
	}	
	
function InteroWinView()
	{
		if (document.getElementById('getIntero').style.visibility=='visible')
		{
		document.getElementById('getIntero').style.visibility='hidden'; 
		}
		else
		if (document.getElementById('getIntero').style.visibility=='hidden')
		{
		document.getElementById('getIntero').style.visibility='visible'; 
		}
	}
function InteroWinView2(status)
	{
		//alert("interowin2");
		if (status == 0)
		{
		document.getElementById('getIntero').style.visibility='hidden'; 
		}
		else
		if (status == 1)
		{
		document.getElementById('getIntero').style.visibility='visible'; 
		}
		
	}		
function legendView()
	{
		if (document.getElementById('movmenu').style.visibility=='visible')
		{
		document.getElementById('movmenu').style.visibility='hidden'; 
		}
		else
		if (document.getElementById('movmenu').style.visibility=='hidden')
		{
		document.getElementById('movmenu').style.visibility='visible'; 
		}
	}		
	
function toggleCheckbox(name)
	{
		if (document.getElementById(name).checked=true)
		{
		document.getElementById(name).checked=false; 
		}
		else
		if (document.getElementById(name).checked=false)
		{
		document.getElementById(name).checked=true; 
		}
	}	
	
function viewHelpMenu()
	{
		if (document.getElementById('menuhelp').style.visibility=='visible')
		{
		document.getElementById('menuhelp').style.visibility='hidden'; 
		}
		else
		if (document.getElementById('menuhelp').style.visibility=='hidden')
		{
		document.getElementById('menuhelp').style.visibility='visible'; 
		}
	}	
	
//update the coordinate hint label above the map
function updateQueryLayerHint(hintStr,timeStr){
   var str = hintStr;
   var hintLabel= document.getElementById("queryLayerInfo");
   hintLabel.childNodes[0].nodeValue  = "Time Series Query Layer: "+str+"  "+timeStr;
}

//update the weather hint label above the map
function updateWeatherLayerHint(hintStr,hintStr2){
   var str = hintStr;
   var hintLabel= document.getElementById("weatherLayerInfo");
   hintLabel.childNodes[0].nodeValue  = str+"  "+hintStr2;
  
}

//update the coordinate hint label above the map
function updateInteroLayerHint(hintStr,timeStr){
   //alert("interinfo")
   var str = hintStr;
   var hintLabel= document.getElementById("interoLayerInfo");
   hintLabel.childNodes[0].nodeValue  = "Layer: "+str+"  "+timeStr;
}

//function populateXML()
//{
//   var message;
//   var objDOMatt;
//   var layernode;
//   
//   if(req.responseXML != null)
//   {
//    var xml_doc = new ActiveXObject("MSXML2.DOMDocument");
//    xml_doc.async= false; 
//    //var newText = window.frames.weatherFrame.document;
//    alert("here");
//    //xml_doc.loadXML(frames["weatherFrame"].innerText);
//    xml_doc.loadXML(req.responseText);
//	alert(xml_doc);
//    //xml_doc.setProperty("SelectionLanguage", "XPath");
//    
//    var theTimeNode = xml_doc.childNodes[1].childNodes[1].childNodes[1].selectNodes("//time-layout[layout-key='k-p12h-n4-3']/start-valid-time");
//    var message = "";
//    var length = theTimeNode.length;
//           for (i=0; i<length; i++)
//           {
//             var theAtts = theTimeNode[i].attributes;
//             for (j=0; j<theAtts.length; j++)
//             {
//                var theValue = theAtts[j].value;
//                var thisSpan = "xmlResponse_Period"+[i];
//                var xmlLabel= document.getElementById(thisSpan);
//                xmlLabel.childNodes[0].nodeValue  = theValue;
//             }
//                                      
//           }
//      
//      var theHighNode = xml_doc.childNodes[1].childNodes[1].childNodes[1].selectNodes("//parameters/temperature[name='Daily Maximum Temperature']/value");
//      var message = "";
//      var length2 = theHighNode.length;
//               for (i=0; i<length2; i++)
//               {
//                    var theValue = theHighNode[i].text;
//                    var thisSpan = "xmlResponse_High"+[i];
//                    var xmlLabel= document.getElementById(thisSpan);
//                    xmlLabel.childNodes[0].nodeValue  = theValue;
//                 
//                                          
//               }   
//      var theLowNode = xml_doc.childNodes[1].childNodes[1].childNodes[1].selectNodes("//parameters/temperature[name='Daily Minimum Temperature']/value");
//      var message = "";
//      var length3 = theLowNode.length;
//               for (i=0; i<length3; i++)
//               {
//                    var theValue = theLowNode[i].text;
//                    var thisSpan = "xmlResponse_Low"+[i];
//                    var xmlLabel= document.getElementById(thisSpan);
//                    xmlLabel.childNodes[0].nodeValue  = theValue;
//                 
//                                          
//               }           
//           
//      var thePrecipNode = xml_doc.childNodes[1].childNodes[1].childNodes[1].selectNodes("//parameters/probability-of-precipitation/value");
//      var message = "";
//      var length3 = thePrecipNode.length;
//               for (i=0; i<length3; i++)
//               {
//                    var theValue = thePrecipNode[i].text;
//                    var thisSpan = "xmlResponse_Precip"+[i];
//                    var xmlLabel= document.getElementById(thisSpan);
//                    xmlLabel.childNodes[0].nodeValue  = theValue +"%";
//                                          
//               }   
//      var theWeatherNode = xml_doc.childNodes[1].childNodes[1].childNodes[1].selectNodes("//parameters/weather/weather-conditions");
//      var message = "";
//      //alert(theWeatherNode.length);
//      var length4 = theWeatherNode.length;
//           for (i=0; i<length4; i++)
//           {
//               var theAtts2 = theWeatherNode[i].attributes;
//               //alert(theAtts2.length);
//               for (k=0; k<theAtts2.length; k++)
//                 {
//                    var theValue = theAtts2[k].value;
//                    var thisSpan = "xmlResponse_weather"+[i];
//                    var xmlLabel= document.getElementById(thisSpan);
//                    xmlLabel.childNodes[0].nodeValue  = theValue;
//                 }          
//           }
//           
//      var theImageNode = xml_doc.childNodes[1].childNodes[1].childNodes[1].selectNodes("//parameters/conditions-icon/icon-link");
//      var message = "";
//      var length5 = theImageNode.length;
//               for (i=0; i<length5; i++)
//               {
//                    var theValue = theImageNode[i].text;
//                    var thisSpan = "xmlImage"+[i];
//                    var theSource = document.getElementById(thisSpan).src;
//                    document.getElementById(thisSpan).src = theValue;
//                    //alert(theSource);                     
//               }   
//           
//   }
//}		


//function callback() 
//{
//    if (req.readyState != 4)
//    {
//        //alert("loading");
//        frames["mapFrame"].showLayer("loadingLay");
//	    var the_timeout = setTimeout('frames["mapFrame"].hideLoading();', 5000);
//    }
//    
//    if (req.readyState == 4) 
//    {
//        if (req.status == 200) 
//        {
//            // update the HTML DOM based on whether or not message is valid
//            frames["mapFrame"].hideLoading("loadingLay");
//            alert("it's back");
//            populateXML();
////            document.getElementById("queryLayerInfo").style.visibility = "visible";
////			weatherWinView();
//        }
//    }
//}

function popQueryWindow(xPos,yPos)
		{
			var theActiveQueryLayer = get_cookie("theQueryLayer");
			var theX=xPos;
			var theY=yPos;
			//alert(xPos+','+yPos+','+theActiveQueryLayer);
			var timeVariable;
			for(yval=0;yval<72;yval++)
			{
				if(document.getElementById("h-value").value == yval)
				{
				var timeVariable = "&TIME="+showclock2(yval);
				var sendTime = showclock2(yval);
				}
			} 
			var requestString = "wfs/asa_wfs_interogate.asp?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&srs=EPSG:4326&BBOX=";
			var queryLayerString = "&TYPENAME="+theActiveQueryLayer+timeVariable;
			var bbox =  theX+','+theY+','+theX+','+theY;
			
			var queryRequestURL = requestString +bbox +queryLayerString;
			//alert(queryRequestURL);
			//document.getElementById("queryImage").src = queryImageURL;
			//updateInteroLayerHint(theActiveQueryLayer,theCoords);
			InteroWinView2(1);
			updateInteroLayerHint(theActiveQueryLayer,sendTime);
			frames["mapFrame"].showLayer("loadingLay");
		    var the_timeout = setTimeout('frames["mapFrame"].hideLoading();', 3000);
			document.getElementById('InteroFrame').src = queryRequestURL;
			
//			var url = queryRequestURL;
//            if (window.XMLHttpRequest) 
//                {
//                req = new XMLHttpRequest();
//                }
//            else if (window.ActiveXObject) 
//                {
//                req = new ActiveXObject("Microsoft.XMLHTTP");
//                }
//           
//            req.open("POST", url, true);
//            req.onreadystatechange = callback;
//            req.send(null);
//            return req.responseXML;

//			updateInteroLayerHint(theActiveQueryLayer,timeVariable);
//			InteroWinView(theX,theY,theActiveQueryLayer);
			
		}

function popWeatherWindow(xPos,yPos)
		{
			
			var timeVariable;
			var sdate=new Date();
            // round down to 12am
            sdate.setMinutes(0);
            sdate.setSeconds(0);

            // add i hours
            var edate=new Date(sdate.getTime());
			// format output.  example: 2005-11-28T00:00
            var month=edate.getMonth()+1;
            var day=edate.getDate();
            var year=edate.getYear();
            
	        if (day<10) {day="0" + day;}
	        if (month<10) {month="0" + month;}
            var timestr = year + "-" + month + "-" + day;
			
			var timeVariable = "&startDate="+timestr;
						
			var requestString = "http://www.weather.gov/forecasts/xml/SOAP_server/ndfdSOAPclientByDay.php?format=12+hourly&numDays=2&Submit=Submit";
			
			var bbox =  "&lat="+yPos+"&lon="+xPos;
			
			var theCoords = xPos+", "+yPos;
			var queryRequestURL = requestString +bbox + timeVariable;
			//alert("getWeather.aspx?URL="+queryRequestURL);
			//document.getElementById("queryImage").src = queryImageURL;
			updateWeatherLayerHint('',theCoords);
			weatherWinView2(1);
			frames["mapFrame"].showLayer("loadingLay");
		    var the_timeout = setTimeout('frames["mapFrame"].hideLoading();', 3000);
			document.getElementById('weatherFrame').src = "http://24.249.210.120/netMapserver/getWeather.aspx?URL="+queryRequestURL;

			
			
			
//			//AJAX
//			var url = queryRequestURL;
//            if (window.XMLHttpRequest) 
//                {
//                req = new XMLHttpRequest();
//                }
//           else if (window.ActiveXObject) 
//                {
//                req = new ActiveXObject("Microsoft.XMLHTTP");
//                }
//           
//            req.open("POST", url, true);
//            req.onreadystatechange = callback;
//            req.send(null);
//            return req.responseXML;


			
			//updateQueryLayerHint('Weather Request',queryImageURL);
			//queryWinView(xPos,yPos,'Weather Request');
			
			
			
		}
	
	
function adjustQuery(name)
	{
	var theActiveQueryLayer = name;
	//alert(theActiveQueryLayer);
	set_cookie("theQueryLayer",name);
	}
	
	
<!--
// change the map control command
function changeCmd(comstr){
	var cmdvalue = comstr;
	
	if(cmdvalue == "FullExtent"){
		  frames["mapFrame"].cmdValue = cmdvalue;
		  frames["mapFrame"].refreshMap();	  
	}else{
		  frames["mapFrame"].cmdValue = cmdvalue;		  
	}
	return false;
	}

// parse the map url and get the model value and time value to show on hint label
function getHint(modelMapURL){
	var str = modelMapURL;
	var reg =  /&ServiceName=(\w+).*&LAYERS=(\d+)&/;
	//alert(str);
	reg.exec(str);
	
	var model = RegExp.$1;
	var timeStep = RegExp.$2;
	
    //alert(model +"\n"+ timeStep);
	// update the model hint, show the model names on label
	updateModelHint(model);
	// update the time hint, show the time of map on label
    updateTimehint(timeStep);
}


// update the model name hint on label
function updateModelHint(name){ 
      var hintLabel= document.getElementById("modelhint");		  
      switch(name)
	  		{
               case "adcircdir":              	             
         	             hintLabel.childNodes[0].nodeValue = "ADCIRC current direction";
         	             break;
              }
  }


//update the time hint label and show time step of the map
function updateTimehint(time){

    var time= time/100;  //delete 2 zeros;
    var str;
	var timems;
	var now=new Date();
	var newdate=new Date();
	
	if(time>=48){
	   time -= 48; 
	   timems=now.getTime()+(2*24*60*60*1000); //day after tomorrow
	   newdate.setTime(timems);
	   str = (newdate.getMonth()+1)+"/"+newdate.getDate()+"/"+newdate.getYear();
	   str = "Date: " + str + " Time: " + time + ":00 UTC"
	}else if(time>=24){
	   time -=24;	   
       timems=now.getTime()+(1*24*60*60*1000); //tomorrow
	   newdate.setTime(timems);
	   str = (newdate.getMonth()+1)+"/"+newdate.getDate()+"/"+newdate.getYear();
	   str = "Date: " + str + "  Time: " + time + ":00 UTC";  
	}else{
       timems=now.getTime();                //today
	   newdate.setTime(timems);
	   str = (newdate.getMonth()+1)+"/"+newdate.getDate()+"/"+newdate.getYear();
	   str = "Date: " + str + " Time: " + time + ":00 UTC"
	}
	
	 var hintLabel= document.getElementById("timehint");
	 //hintLabel.childNodes[0].nodeValue = str;	
}

//update the coordinate hint label above the map
function updateCoordHint(hintStr){
   var str = hintStr;
   var hintLabel= document.getElementById("coordhint");
   hintLabel.childNodes[0].nodeValue  = str;
}


//show the selected sub list of the menu
function showSubList(srcObj, name){
     var objs;
	 if(document.all)      // if is IE
	   objs = document.all;
	 else                  //Mozilla or netscape
	   objs= document.getElementsByName("modelType");     
	   
	 for(var i=0; i<objs.length; i++)       
	   // highlight the menu head
	   if(objs[i].className == "modelType"){
	     if(objs[i]== srcObj) 
	   	   objs[i].style.background= "#CCCCFF";	 
		 else
  	   	   objs[i].style.background= "";	 
	   }
	   // show the submenu
	   else if(objs[i].className == "submenu"){
	      if(objs[i] == document.getElementById(name))
		     objs[i].style.display = "block";
		  else
		     objs[i].style.display = "none";
	   }	   
}


// change the layer and update the map
function globalShowModel(e, server, name, number){
    // if aEvent is null, means the Internet Explorer event model, 
    // so get window.event. 
	//alert(e);
    var aEvent = e ? e : window.event; 
		
    var srcObj = (aEvent.target) ? aEvent.target : aEvent.srcElement;	    

    if(srcObj.tagName=="SPAN"){	 
       var layerName = name;	
	   var layerNumber = number;
	   var serverName = server;	
	   var theTime = document.getElementById('datelabel').value;
	   var theTimeVar = theTime.replace(" ","T");
	   frames["mapFrame"].globalMapOnShow(layerNumber)= true;  	 
       frames["mapFrame"].globalRefreshMap(layerNumber);  
	   frames["mapFrame"].globalChangeModel(serverName3,layerName,theTimeVar,layerNumber);
	
	}
}	



//uncheck all checks
function unCheckAll(obj){
   var objs= document.getElementsByName("dirChecks");
   // erase the highlight we selected before		
   for(var i=0; i<objs.length; i++)       
	  if(objs[i].className == "dirChecks" && objs[i]!=obj){	     
  	      objs[i].checked = false;
	  }
}

// change the area and update the map
function showArea(){
	var areaID = document.getElementById('newRegion').value;
	//alert(areaID);
    frames["mapFrame"].changeArea(areaID);

}


//show or hide land area map
function showLand(obj){
   if(obj.checked)
     frames["mapFrame"].landOnShow = true;  //turn on the land map
   else
     frames["mapFrame"].landOnShow = false;  //turn off the land map
	 
   frames["mapFrame"].refreshLandMap();   //refresh land map
}

//show or hide land area map
function showBath(obj){
   if(obj.checked)
     frames["mapFrame"].bathOnShow = true;  //turn on the bath map
   else
     frames["mapFrame"].bathOnShow = false;  //turn off the bath map
	 
   frames["mapFrame"].refreshBathMap();   //refresh bath map
}

//show or hide grid(longitude and latitude) map
function showGrid(obj){
   if(obj.checked)
     frames["mapFrame"].gridOnShow = true;  //turn on the grid map
   else
     frames["mapFrame"].gridOnShow = false;  //turn off the grid map
	 
   frames["mapFrame"].refreshGridMap();   //refresh grid map
}


//show or hide legend of map
function showLegend(obj){
   if(obj.checked)
     frames["mapFrame"].refreshLegend(true);  //show the legend
   else
     frames["mapFrame"].refreshLegend(false);  //hide the legend
}


//show or hide map
function globalShowMap(obj,layerNumber){
   if(obj.checked)
    frames["mapFrame"].globalMapOnShow(layerNumber) = true;  //turn on the map
   else
    frames["mapFrame"].globalMapOnShow(layerNumber)= false;  //turn off the map
	frames["mapFrame"].hideloading(layerNumber);
   	frames["mapFrame"].globalRefreshMap(layerNumber);   //refresh map
}


/************************************************************
*
*   update the date and time label on page
*
*************************************************************/

//update the label of the date
function updateDateLabel(){
	var now=new Date();
	var newdate=new Date();
     
	var str= new Array();
    // first day
	str[0]= (now.getMonth()+1)+"/"+now.getDate()+"/"+newdate.getYear();
    
	// second day
	var timems=now.getTime()+(1*24*60*60*1000);
	newdate.setTime(timems);
	str[1]= (newdate.getMonth()+1)+"/"+newdate.getDate()+"/"+newdate.getYear();

    //third day
	timems=now.getTime()+(2*24*60*60*1000);
	newdate.setTime(timems);
	str[2]= (newdate.getMonth()+1)+"/"+newdate.getDate()+"/"+newdate.getYear();

	for(var i=0;i<3;i++){
        var hintLabel= document.getElementById("datelabel");
		//alert(hintLabel.childNodes[i].innerHTML);
	    
	}
}






//change the date
var dayIndex = -1;   //default day is yesterday
function changeDate(date){
    dayIndex=date;
}

//show map of different time period
function changeTime(){   
   var obj=document.getElementById("timelist");
   var value = obj.options[obj.selectedIndex].value;
   var time= (dayIndex+1)*24+ Number(value);
   time = time+ "00";
   frames["mapFrame"].changeTime(time);

   // update the time label
   updateTimehint(time);
}




// show the map we choose
document.onclick = function(e){
       // if aEvent is null, means the Internet Explorer event model, 
       // so get window.event. 
       var aEvent = e ? e : window.event; 
		
       var obj = (aEvent.target) ? aEvent.target : aEvent.srcElement;	 
	   var objs= document.getElementsByTagName("SPAN");     //works in IE and Mozilla
		 
	   // select the wave model item in the wave list
       if (obj.className == "modellist"){       	  
		  //var objs= document.getElementsByName("modellist");       //in IE getElementsByName() ONLY works for tags with default defined "name" attribute (cann't get user define "name")
	      // erase the highlight we selected before		
	      for(var i=0; i<objs.length; i++)       
	   	    if(objs[i].className == "selectedModel"){	     
  	   	       objs[i].className= "modellist";	 
		       objs[i].style.background = "";
		   }

	   // highlight the item when mouse clicked		   
	      obj.className = "selectedModel";
	  }
	  
      // select the day item in the days list
      else if (obj.className == "datelist"){
		  //var objs= document.getElementsByName("datelist");       //in IE getElementsByName() ONLY works for tags with default defined "name" attribute (cann't get user define "name")
	      // erase the highlight we selected before		
	      for(var i=0;i<objs.length; i++)       
	   	    if(objs[i].className == "dateselected"){	     
  	   	       objs[i].className= "datelist";	 
		       objs[i].style.background = "";
		   }

	   // highlight the item when mouse clicked		   
	      obj.className = "dateselected";
	  }
     // select the maptool item in the map control menu	  
	  else if(obj.className == "maptool"||obj.className == "maptoolOver"){
	      //var objs= document.getElementsByName("maptools");       //in IE getElementsByName() ONLY works for tags with default defined "name" attribute (cann't get user define "name")
	      // erase the highlight we selected before		
	      for(var i=0;i<objs.length; i++)       
	   	    if(objs[i].className == "maptoolSelected"){	     
  	   	       objs[i].className= "maptool";			   	 
		       //objs[i].style.background = "";
		   }

	   // highlight the item when mouse clicked		   
	      obj.className = "maptoolSelected";
	  }  
}


