/*
 * Javacript for the 3P product.
 */

cgi = "/cgi-bin/tide-shc.cgi"


var stationListStatus = new Object();
stationListStatus . setTimeoutOn = 0;  // 1 if setTimeout() called in matchStationTZ()
stationListStatus . setTimeoutId = 0;  // id returned by setTimeout()

function initStationListStatus ()    {

    with (document.query.stnnum)    {
            // currentSelected: index of currently selected station
            // mapClicked:      1 if station selected through region map
        stationListStatus . currentSelected = options[options.selectedIndex].value;
        stationListStatus . mapClicked = 0;
        }
    }

 function buildMap (doc)    {
    // Build the image map for region 'num' inside document 'doc'.
	doc.write ('<MAP NAME="rgnmap">\n');
	for (var n = 0; n < stationArr.length; n++)    {
	    var tok = stationArr[n].split("|");
          
              doc.write ('<AREA SHAPE="RECT" COORDS="' + tok[4] + '" ' +  'HREF="#" onClick="selectStationThroughMap(\'' + tok[0] + '\');return(false);" ' + 'alt="' + tok[1] + '">\n');
		   
	    }
	doc.write ("</MAP>\n");
	}

function stationList (doc, language)    {
    // Build a drop down list for all stations of region 'num' inside
    // document 'doc'
    // alert("entering stationlist");

        // The 'onClick()'method works only under IE.
        // Netscape will ignore it. Another technique has to be
        // used in this case (see function matchStationTZ() ).
    doc.write ('\n<select name="stnnum" onChange="document.query.submit()">\n');
	
	

    for (var n = 0; n < stationArr.length; n++)    {
        var tok = stationArr [n] . split ('|');
		doc.write ('<option value=' + tok[0] + '>' + tok[1] + '</option>\n');
	}      
    doc.write ('</select>\n');
    }

function navigateForm(selectValue)
  {
	location.href = '/cgi-bin/tide-shc.cgi?queryType=' + document.query.queryType.value + '&zone=' + document.query.zone.value + '&language=' + document.query.language.value + '&region=' + document.query.region.value + '&stnnum=' + document.query.stnnum.options[selectValue].value;
    return false;
  }
function selectStation(stn, sendQuery)    {
    // Select given station in the form drop-down menu.
	with (document.query.stnnum)    {
        for (var i = 0; i < options.length; i++)    {
           if (stn == 'first' || options[i].value == stn)    {

				document.query.stnnum.selectedIndex = i;

				if (sendQuery == 1)
				{
					navigateForm(i);
				}
				return false;
            }
        }
	}
	//return false;
}

function selectStationThroughMap (stn)    {
    // Select station `stn' and note that the selection occured
    // indirectly through the region map.

    stationListStatus . mapClicked = 1; 
	selectStation (stn, 1);
  
    return false;
    }


// A variable we use to ensure that each error window we create is unique.
var error_count = 0;

// Set this variable to your email address.
var email = "beaulieui@dfo-mpo.gc.ca";

// Define the error handler. It generates an HTML form so
// the user can report the error to the author.
function report_error(msg, url, line)  {

   var w = window.open("",                    // URL (none specified)
                       "error"+error_count++, // Name (force it to be unique)
                       "resizable,status,width=625,height=400"); // Features
   var d = w.document;    // We use this variable to save typing!

   // Output an HTML document, including a form, into the new window.
   d.write('<DIV>');
   d.write('<FONT SIZE=7 FACE="helvetica"><B>');
   d.write('OOPS.... A JavaScript Error Has Occurred!');
   d.write('</B></FONT><BR><HR SIZE=4 WIDTH="80%">');
   d.write('<FORM ACTION="mailto:' + email + '" METHOD=post');
   d.write(' ENCTYPE="text/plain">');
   d.write('<FONT SIZE=3>');
   d.write('<I>Click the "Report Error" button to send a bug report.</I><BR>');
   d.write('<INPUT TYPE="submit" VALUE="Report Error">&nbsp;&nbsp;');
   d.write('<INPUT TYPE="button" VALUE="Dismiss" onClick="self.close()">');
   d.write('</DIV><DIV>');
   d.write('<BR>Your e-mail <I>(optional)</I>: ');
   d.write('<INPUT SIZE=42 NAME="name" VALUE="">');
   d.write('<BR>Error Message: ');
   d.write('<INPUT SIZE=42 NAME="message" VALUE="' + msg + '">');
   d.write('<BR>Document: <INPUT SIZE=42 NAME="url" VALUE="' + url + '">');
   d.write('<BR>Line Number: <INPUT SIZE=42 NAME="line" VALUE="' + line +'">');
   d.write('<BR>User Agent: ');
   d.write('<INPUT SIZE=42 NAME="useragent" VALUE="'+ browser.userAgent + '">');
   d.write('<BR>Browser version: ');
   d.write('<INPUT SIZE=42 NAME="version" VALUE="'+ browser.minor + '">');
   d.write('</DIV></FONT>');
   d.write('</FORM>');
   // Remember to close the document when we're done.
   d.close();

   // Return true from this error handler, so that JavaScript does not
   // display its own error dialog.
   return true;
   }

