  var xmouse, ymouse, xfrom, yfrom, xabs, yabs, xdrag, ydrag, x, y, x1, y1
  var xmin, ymin, xmax, ymax, mapwidth, mapheight, i, size, xdisplaymouse, ydisplaymouse
  var lastbutton, mousebutton, dragmode, usrdata, usrarray
  var ogcurl, ogcparts, prefwindow, prefform
  var msgwindow, shiplat, shiplon, shipdate, shipname, shipspeed, distance, totdist
  var frcstquery, satquery, satwindow, forecastwindow, distwindow, strdist
  var lDb_R, lDb_deltaLat, lDb_deltaLon, lDb_a, lDb_c, wpt, tothour, waypoint, urlname
  var lat = new Array()
  var lon = new Array()
  var distquery = new Array()
  var disttime = new Array()
  
  // netscape only object variables
  var maplayerobj, boxleftobj, boxrightobj, boxtopobj, boxbottomobj, pinobj
  
  function init() // initialise on document load event
    {
    window.name = 'main'
    urlname = document.URL
    // set active button
    document.mapper.reset()
    if (document.mapper.operation.value == "zoomall")
      button("zoomin")
    else
      button(document.mapper.operation.value)
	
    // get global variables from form
    xmin=Number(document.mapper.xmin.value)
    ymin=Number(document.mapper.ymin.value)
    xmax=Number(document.mapper.xmax.value)
    ymax=Number(document.mapper.ymax.value)
    mapwidth=Number(document.mapper.mapwidth.value)
    mapheight=Number(document.mapper.mapheight.value)
    size=document.mapper.size.value
    x1=Number(document.mapper.x1.value)
    y1=Number(document.mapper.y1.value)
    }
    
  function button(name)
    {
    lastbutton=document.images[document.mapper.operation.value]
    if (lastbutton != null) lastbutton.src = 'images/' + lastbutton.name + '.gif'
    if (document.images[name] == null) name='zoomin'
    document.images[name].src = 'images/' + name + 'x.gif'
    document.mapper.operation.value = name
    
    if ((name != 'query') & (msgwindow !=null)) {
      if (msgwindow.closed == false) msgwindow.close()
      msgwindow = null }
      
    if ((name != 'forecast') & (forecastwindow !=null)) {
      if (forecastwindow.closed == false) forecastwindow.close()
      forecastwindow = null }
      
    if ((name != 'satview') & (satwindow !=null)) {
      if (satwindow.closed == false) satwindow.close()
      satwindow = null }
      
    if (name == 'zoomall'){
    SetLayers()}
    
	var FlashMapObj = InternetExplorer ? FlashMap : document.FlashMap;
    if (name == 'weather'){
		FlashMapObj.SetVariable("BuoyMode", "set");
	}else if (name == 'distance'){
		FlashMapObj.SetVariable("BuoyMode", "distance");
    }else{
		FlashMapObj.SetVariable("BuoyMode", "");
    }
    
    lastbutton=name
    return false
    }
  
  function formatnumber(value, decimals)
    {
    usrdata=value.toString(10)
    i=usrdata.indexOf('.')
    if (i == 0) {
      return usrdata }
    else {
      return usrdata.substr(0,i+decimals+1) }
    }
  
  function closemsg()
    { // close the query window if open
    if (msgwindow != null) {
      if (msgwindow.closed == false) msgwindow.close()
      msgwindow = null }
    return true
    }

function formatLatLon(value, lol){
  var sign
  var usrdata
  var i
  if (value < 0 ){
  	if (lol == "lat"){
  	sign = "S"}
  	else{
  	sign = "W"}}
  else{
  	if (lol == "lon"){
  	sign = "E"}
  	else{
  	sign = "N"}}
		
  value = Math.abs(value)
  usrdata=value.toString(10)
  i=usrdata.indexOf('.')
  if (i == 0) {
    return usrdata }
  else {
    return usrdata.substr(0,i+3+1) + sign }
}
    
function PopupWindow(address) {
  popupWin = window.open(address, 
    'open_window',
    'dependent,width=375,height=325,left=0,top=0')
}

function LatLonDist(Lat1, Lon1, Lat2, Lon2){

    lDb_deltaLon = AsRadians(Lon2) - AsRadians(Lon1)
    lDb_deltaLat = AsRadians(Lat2) - AsRadians(Lat1)

   lDb_a = Sin2(lDb_deltaLat / 2) + (Math.cos(AsRadians(Lat1)) * Math.cos(AsRadians(Lat2)) * Sin2(lDb_deltaLon / 2))
    
    lDb_c = 2 * Math.asin(Math.min(1, Math.sqrt(lDb_a)))

    return 3362 * lDb_c
}

function AsRadians(pDb_Degrees){
    return pDb_Degrees * (3.14159265358979 / 180)
}

function Sin2(X){
    return (1 - Math.cos(2 * X)) / 2
}

function PostForm(){
for (var i = 0; i < window.document.forms[0].layers.length; i++){
	if (window.document.forms[0].layers[i].checked){
	window.opener.document.mapper.layers[i].value = window.document.forms[0].layers[i].value}
	else{
	window.opener.document.mapper.layers[i].value =  "" }}
if (window.document.forms[0].mapsize.checked)
window.opener.document.mapper.size.value = "full"
else{
window.opener.document.mapper.size.value = "small"}
window.opener.document.mapper.update.value = "Update";
window.opener.document.mapper.clientwidth.value =  window.screen.availWidth;
window.opener.document.mapper.clientheight.value = window.screen.availHeight;
window.opener.document.mapper.submit(); 
self.close();}

function SetLayers(){
//set the layers object in the form
for (var i = 0; i < window.document.mapper.layers.length; i++){
if (window.document.mapper.layers[i].value.substr(0,6) == "VISSEL"){
window.document.mapper.layers[i].value = window.document.mapper.layers[i].value.substr(6)}
if (window.document.mapper.layers[i].value.substr(0,6) == "VISVIS"){
window.document.mapper.layers[i].value = "" }
}
window.document.mapper.submit()
}

function MapPreferences(){
	mapwidth=Number(document.mapper.mapwidth.value)
	prefwindow = window.open('', 'Preferences', 'width=200,height=450,resizable=yes,scrollbars=yes')
	prefform = '<HTML><head><title>Preferences</title><script language="javascript" src = "scriptsNew.js" >'
	prefform = prefform + '</script></head><BODY>'
	prefform = prefform + '<FORM name="popupform" method = "post" >'
	prefform = prefform + '<p align="center"><h2>Map Preferences</h2></p>'
    prefform = prefform + '<p align="center"><font size = "2"><i>Indicate your map preferences here.</i></font></p>'
	
	for (var i = 0; i < window.document.mapper.layers.length; i++){
	if (window.document.mapper.layers[i].value.substr(0,3) == "VIS"){
	prefform += '<INPUT type=checkbox name=layers value = "' + window.document.mapper.layers[i].value.substr(6) + '"'
		if (window.document.mapper.layers[i].value.substr(3,3) == "SEL") {
		prefform += ' checked'}
	prefform += ' > ' + window.document.mapper.layers[i].value.substr(6) + '<br>'}}
	
	if (size == "small"){
	prefform = prefform + '<INPUT type=checkbox name=mapsize value="full">&nbsp;Full-Sized Map<br>'}
	else {
	prefform = prefform + '<INPUT type=checkbox name=mapsize value="full" checked>&nbsp;Full-Sized Map<br>'
		if(document.cookie.length > 100){
			prefform = prefform + '<a href = "SetCookie.htm" >Set Custom Map Size</a><br>'
		}
	}
	if (document.layers == null) {
    // microsoft version--button doesn't work well in NS
	prefform = prefform + '<br><input type=button value="Update" onClick="javascript:PostForm();">'}
	else {
	prefform = prefform + '<br><a href = "javascript:PostForm();">Click Here to Update</a>'}
		
	prefform = prefform + '</form><p><font face="Verdana, Arial, Helvetica" size="2"><a href="JavaScript:onClick= window.close()">Close Window</A></font></p></body></html>'
	prefwindow.document.write(prefform)
	prefwindow.document.close() 
    prefwindow.focus()
    }

function validatenumber(field) {
var valid = "0123456789."
var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";
}
if (ok == "no") {
alert("Please enter a numeric value in the field");
field.focus();
field.select();
   }
}

function isodatetime() {
var today = new Date();
var year  = today.getYear();
if (year < 2000)  
year = year + 1900;
var month = today.getMonth() + 1;
var day  = today.getDate();
var hour = today.getHours();
var hourUTC = today.getUTCHours();
var diff = hour - hourUTC;
var UTCtoday = new Date();
var UTCyear  = UTCtoday.getUTCFullYear();
if (UTCyear < 2000)  
UTCyear = UTCyear + 1900;
var UTCmonth = UTCtoday.getUTCMonth() + 1;
var UTCday  = UTCtoday.getUTCDate();
var hourdifference = Math.abs(diff);
var minute = today.getMinutes();
var minuteUTC = today.getUTCMinutes();
var minutedifference;
var second = today.getSeconds();
var timezone;
if (minute != minuteUTC && minuteUTC < 30 && diff < 0) { hourdifference--; }
if (minute != minuteUTC && minuteUTC > 30 && diff > 0) { hourdifference--; }
if (minute != minuteUTC) {
minutedifference = ":30";
}
else {
minutedifference = ":00";
}
if (hourdifference < 10) { 
timezone = "0" + hourdifference + minutedifference;
}
else {
timezone = "" + hourdifference + minutedifference;
}
if (diff < 0) {
timezone = "-" + timezone;
}
else {
timezone = "+" + timezone;
}
if (month <= 9) month = "0" + month;
if (day <= 9) day = "0" + day;
if (hour <= 9) hour = "0" + hour;
if (minute <= 9) minute = "0" + minute;
if (minuteUTC <= 9) minuteUTC = "0" + minuteUTC;
if (second <= 9) second = "0" + second;
if (UTCmonth <= 9) UTCmonth = "0" + UTCmonth;
if (UTCday <= 9) UTCday = "0" + UTCday;
if (hourUTC <= 9) hourUTC = "0" + hourUTC;
time = year + "-" + month + "-" + day + "  "
+ hour + ":" + minute + ":" + second + ' ' + timezone + ' (LT)';
document.isoclock.display.value = time;
UTCtime = UTCyear + "-" + UTCmonth + "-" + UTCday + "  "
+ hourUTC + ":" + minuteUTC + ":" + second + ' GMT';
document.isoclock.displayUTC.value = UTCtime;
window.setTimeout("isodatetime();", 500);
}

function PopupBody(Login, Table, ID){
	myWindow = window.open('utilities/ShowBody.asp?Login=' + Login + '&Table=' + Table + '&ID=' + ID, "BodyWindow", 'width=400,height=400, resizable=yes,scrollbars=yes') 
	myWindow.document.close() 
    }

function PopupGeneric(address, winwidth, winheight) {
  myWindow = window.open(address , "GenericWindow", 'width=' + winwidth + ',height=' + winheight + ', resizable=yes,scrollbars=yes') 
  myWindow.document.close() 
}