var seeBuoy = "";
var oldGroup = "";
var seeHelp = "";

function buoyInfo(which,left_offset) {
	//moveIt(which);
	if (document.layers) { //ancient Netscape script
		//go to anchor
	} else if (document.getElementById) { //modern browser script
		var myBuoy = document.getElementById(which);
		if (seeBuoy!="") {
			var oldBuoy = document.getElementById(seeBuoy);
			oldBuoy.style.display = "none";
		} 
		if (oldGroup!="") {
			oldGroup.style.display = "none";
		}
		myBuoy.style.display= "block";
                myBuoy.style.left = left_offset + "px";
	} else if (document.all) { //ancient IE script
		if (seeBuoy!="") {
			oldBuoy = seeBuoy;
			oldBuoy.style.display = "none";
		}
		var myBuoy = document.all[which];
		var q = myBuoy.style.display;
		if (q=="block") {
			myBuoy.style.display = "none";
                        myBuoy.style.left = left_offset + "px";
		} else {
			myBuoy.style.display = "block";
                        myBuoy.style.left = left_offset + "px";
		}
	}
	seeBuoy = which;
}

function hideInfo() {
	if (seeBuoy!="") {
		var oldBuoy = document.getElementById(seeBuoy);
		oldBuoy.style.display = "none";
	}
	document.getElementById('data').style.display = "none";
	
}

function hideInfoG() { // no longer used, using hideBox() instead
	if (oldGroup!="") {
		oldGroup.style.display = "none";
	} else {
		var oldBuoy = document.getElementById(seeBuoy);
		oldBuoy.style.display = "none";
	}
}
function hideBox(which) { //for tides page
	var box = document.getElementById(which);
	box.style.display = "none";
}
function showBox(which) { //for tides page
	var box = document.getElementById(which);
	//if (box.style.display == "none") {
		box.style.display = "block";
	//} 
}
	

// use to display stations which are grouped
function buoyInfoG(which) {
	if (document.getElementById) { //modern browser script
		var myBuoy = document.getElementById(which);
		if (seeBuoy.substring(0,5) != "group") {
			var oldBuoy = document.getElementById(seeBuoy);
			oldBuoy.style.display = "none";
		} else {
			oldGroup = document.getElementById(seeBuoy);
		}
		myBuoy.style.display= "block";
	}
	seeBuoy = which;
}


var detect = navigator.userAgent.toLowerCase();
var version = parseInt(navigator.appVersion);
function checkIt(string) {
	place = detect.indexOf(string) + 1;
	return place;
}

//function to change background map

function switchMap(arg1,fc) {
        var fc_extra = '';
        if (fc == 1) {
          fc_extra = '_FC';
        }

	var myform = document.forms.switcher;
	var mapImg = document.images["basemap"];
	var legImg = document.images["legend"];
        if(arg1 == "tides"){
          var whichMap = "tides";
        } else {
	  var allbkgs = myform.background.length;
	  for (i=0;i<allbkgs;i++) {
		if (myform.background[i].checked==true) {
			var whichMap = myform.background[i].value;
		}
	  }
        }
	/* radio gone
	if (myform.radio.checked==true) {
		var radio = true;
	} else {	
		var radio = false;
	} */
// correct image switching script
  	var myMap = whichMap + fc_extra;
	
	for (i=0;i<myform.places.length;i++) {
		if (myform.places[i].checked==true) {
			var places = myform.places[i].value;
			myMap = myMap+places;
		}
	}

        anim = '';
        ext  = 'png';
        if (myMap.indexOf('loop') != -1) {
          myMap = myMap.replace(/_loop/,"");
          anim = '_anim';
          ext  = 'gif';
        }

	mapImg.src = "./maps_out/" + arg1 + "/OBS_" + myMap + anim + '.' +ext;

// add the legend 
	if (legImg) {
		if (whichMap=="sst") {
			legImg.src = "images/sst_legend.png";
		} else if (whichMap.indexOf('radar') != -1) {
			legImg.src = "images/radar_legend.png";
		} else if (whichMap=='air_pressure') {
			legImg.src = "images/wind_barb_key.png";
		} else {
			legImg.src = "images/blank.gif";
		}	
	}
}

function switchMapHaz() {
	var myform = document.forms.switcher;
	var mapImg = document.images["basemap"];
	var legImg = document.images["legend"];
	if (myform.cities.checked==true) {
		var cities = true;
	} else {	
		var cities = false;
	}
	if (myform.radar.checked==true) {
		var radar = true;
	} else {	
		var radar = false;
	}
	if (myform.radio.checked==true) {
		var radio = true;
	} else {	
		var radio = false;
	}
	
// image switching script for hazards page
	var myMap = "hazards";
	if (radar==true) { myMap = myMap+"_radar"; } 
	if (cities==true) { myMap = myMap+"_cities"; } 
	if (radio==true) { myMap = myMap+"_radio"; } 
	mapImg.src = "./data/maps/"+myMap+".png";
	
// add the legend 
	if (legImg) {
		if (radar==true) {
			legImg.src = "images/radar_legend.png";
		} else {
			legImg.src = "images/blank.gif";
		}	
	}
}

// function to show/hide help info
function helpInfo(whichList) {

	if (document.getElementById) { //modern browser script
		var myList = document.getElementById(whichList);
		var n = myList.selectedIndex;
		var which = "help_"+myList[n].value;
		var myHelp = document.getElementById(which);
		if (seeHelp!="") {
			var oldHelp = document.getElementById(seeHelp);
			oldHelp.style.display = "none";
		} 
		myHelp.style.display= "block";
	} else if (document.all) { //ancient IE script
		var myList = document.all.whichList;
		var n = myList.selectedIndex;
		var which = "help_"+myList[n].value;
		if (seeHelp!="") {
			oldHelp = seeHelp;
			oldHelp.style.display = "none";
		}
		var myHelp = document.all[which];
		var q = myHelp.style.display;
		if (q=="block") {
			myHelp.style.display = "none";
		} else {
			myHelp.style.display = "block";
		}
	}
	seeHelp = which;

}

// Tides page scripts removed

/* show/hide about text on obs page */
function aboutText() {
	var about = document.getElementById("about");
	var aboutPs = about.getElementsByTagName("p");
	for (i=0; i<aboutPs.length; i++) {
		if (aboutPs[i].style.display=="none") {
			aboutPs[i].style.display="block";
		} else if (aboutPs[i].style.display=="block") {
			aboutPs[i].style.display="none";
		} else {
			aboutPs[i].style.display="block";
		}
	}
}

//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest(); //Not IE
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP"); //IE
	} else {
		//Display your error message here.
		//and inform the user they might want to upgrade
		//their browser.
		alert("Your browser doesn't support the XmlHttpRequest object.  Better upgrade to Firefox.");
	}
}
//Get our browser specific XmlHttpRequest object.
var receiveReq = getXmlHttpRequestObject();
//Initiate the asyncronous request.
function getInfo(which) {
	//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
		//Setup the connection as a GET call to the specified html.
		//True explicity sets the request to asyncronous (default).

		receiveReq.open("GET", which, true);

		//Set the function that will be called when the XmlHttpRequest objects state changes.
		receiveReq.onreadystatechange = handleGetInfo;

		//Make the actual request.
		receiveReq.send(null);
	}
}
//Called every time our XmlHttpRequest objects state changes.
function handleGetInfo() {
	//Check to see if the XmlHttpRequests state is finished.
	if (receiveReq.readyState == 4) {
		//Set the contents of our div element to the result of the asyncronous call.
		document.getElementById('data').innerHTML = receiveReq.responseText;
		document.getElementById('data').style.display = "block";
	}
}

function show_help(which) {
	var helpurl = "help.html#" + which;
	window.open(helpurl,"helpwin","height=200, width=300, status=0, location=0, toolbar=0, scrollbars=1");
	
}
