/******************************** JavaScript Code ********************************/

/*
   This is a package of JavaScript code, comprising several routines, that accompanies the Sea
   Surface Temperature website. Specifically, the routines in this module control the
   functionality of the SSTMapper applet in the sst_init.pl and sst_express.pl scripts by making
   calls to various methods defined in the applet -- for pre-set and custom zooming, panning,
   brightening/darkening, enhancing, colour optimizing, resetting and showing temperature
   tooltips, and setting/resetting express user preprocessing options for their express image.
*/

/********************************************************************************/

/*
   Relative zoom in/out levels working off the current image in percentages of
   the previous image.
*/
     var zoominLvl0 = 0, zoominLvl1 = 15, zoominLvl2 = 30, zoominLvl3 = 50,
         zoominLvl4 = 60;
     var zoomoutLvl1 = -15, zoomoutLvl2 = -30, zoomoutLvl3 = -100,
         zoomoutLvl4 = -200;

     var zoominIncrement = zoominLvl1;              // Zoom In increment, oval button
     var zoomoutIncrement = zoomoutLvl1;            // Zoom Out increment, oval button
/*
   Relative brightness/darkness levels working off the current image in percentages
   of previous image
*/
     var darkenLvl1 = -10, darkenLvl2 = -20, darkenLvl3 = -30, darkenLvl4 = -40,
         darkenLvl5 = -50, darkenLvl6 = -70, darkenLvl7 = -90;

     var brightenIncrement = 30;                    // Brighten increment, oval button
     var darkenIncrement = -15;                     // Darken increment, oval button
/*
   Miscellaneous variables and presettings.
*/
     var intDirn;
//     var imageProcesses;                            // Count of processes updating image
//     var zoomed;                                    // Image zoomed yet (for temp tooltips)

     var on = 1; off = 0;                           // Switch values
     var tooltipsDisplay = off;
     var decimalDegrees = off;
//     var showLocation = off;

     var htuWindow    = null;                       // Window for 'How_to_use_SST' webpage
     var legendWindow = null;                       // Window to display depths legend
     var infoWindow;

     var testWindow = null;                         // 2px x 2px window for testing popups
     var popupsOK   = false;                        // Preset popup incapable

     var usedImgDown  = new Image(116, 22);
     var usedImgJwg   = new Image(116, 22);
     var usedImgEmail = new Image(116, 22);

     var topLeftX = 550;                            // Bathymetry legend window
     var topLeftY = 20;
     var width    = 230;
     var height   = 350;

//------------------------------------------------------------------------------

     function brightenImage_js(pctBrighten)
     {
/*
     This function organizes display of a brightened or darkened version of the
     currently displayed image by calling the Mapper applet's brighten image method.
*/
//        setImageProcesses();
        document.SSTMapperApplet.brightenImage(pctBrighten);
     }

//------------------------------------------------------------------------------

     function colourOptimize_js()
     {
/*
     This function organizes display of a colour optimized version of the currently
     displayed image by calling the Mapper applet's colourOptimize image method.
*/
//        setImageProcesses();
        document.SSTMapperApplet.colourOptimizeImage();
     }

//------------------------------------------------------------------------------

     function customZoomImage_js()
     {
/*
     This function organizes display of a custom zoomed image. The rectangular area
     selected for zooming has been signified by the user dragging out a rectangle over
     the image viewport of the applet and pressing the custom zoom button on the interface.
*/
        tooltipsDisplay = off;
//        showLocation = off;
//        setImageProcesses();
//        zoomed = 1;                                      // Set zoomed process done
        document.SSTMapperApplet.customZoomImage();
     }

//------------------------------------------------------------------------------

     function deletebox_js()
     {
/*
     This function organizes switching-off of a dragged out rectangle that the Client
     does not wish to follow up. It calls the Mapper applet's refresh method which merely
     repaints the display.
*/
        document.SSTMapperApplet.refresh();
     }

//------------------------------------------------------------------------------

     function enhance_js()
     {
/*
     This function organizes display of an enhanced version of the currently displayed
     image by calling the Mapper applet's enhance image method.
*/
//        setImageProcesses();
        document.SSTMapperApplet.enhanceImage();
     }

//------------------------------------------------------------------------------

     function newBrightenLevel(lightenDarken)
     {
/*
     Incremenatlly brightens or darkens the displayed image by a fixed amount.
*/
        if(lightenDarken == "brighten")          // Wants to increment brightening
        {
           brightenImage_js(brightenIncrement);
        }
        else                                     // Wants to increment darkening
        {
           brightenImage_js(darkenIncrement);
        }
     }

//------------------------------------------------------------------------------

     function newZoomLevel(inOut)
     {
/*
     Incremenatlly zooms in or out of the displayed image by a fixed amount.
*/
        if(inOut == "in")                        // Wants to increment zoom in
        {
           zoomImage_js(zoominIncrement);
        }
        else                                     // Wants to increment zoom out
        {
           zoomImage_js(zoomoutIncrement);
        }
     }

//------------------------------------------------------------------------------

     function oops_js()
     {
/*
     This function allows the client to undo the processing operation that they
     have just completed, so as to restore the image as it was before they started
     the operation.
*/
//        if(imageProcesses >= 1)                    // Image processes defined?
//        {
//           setImageProcesses();                    // Yes: bump count for this process
        document.SSTMapperApplet.oopsImage();
//        }
//        else                                       // Not defined: go back a page
//        {
//           history.back();
//        }
     }

//------------------------------------------------------------------------------

     function openHTUWindow()
     {
/*
        Used in popup mode. Opens a new browser window, with printing option, to
        display either the hardcopy product selection page
*/
        var contentFile = "../pro_how_to_use_05.html#express";
        var topLeftX = 40, topLeftY = 40, width = 700, height = 400;

        if(htuWindow)                                          // How to use window minimised?
        {                                                      // Yes, clear it, won't display
           htuWindow.close();
           htuWindow = null;
        }

        htuWindow = window.open(contentFile,"htuWindow","left="+topLeftX+",top="+topLeftY+
                  ",toolbar=yes,resizable=yes,scrollbars=yes,width="+width+",height="+height);
     }

//------------------------------------------------------------------------------

     function panImage_js(strDirn)
     {
/*
     This function organizes display of a panned image by calling the DisplayImage
     applet's pan method. It also sets the tooltips display status to off to
     reflect what has happened in the Mapper applet.
*/
        if(strDirn == "N")
        {
           intDirn = 1;
        }
        else if(strDirn == "NE")
        {
           intDirn = 2;
        }
        else if(strDirn == "E")
        {
           intDirn = 3;
        }
        else if(strDirn == "SE")
        {
           intDirn = 4;
        }
        else if(strDirn == "S")
        {
           intDirn = 5;
        }
        else if(strDirn == "SW")
        {
           intDirn = 6;
        }
        else if(strDirn == "W")
        {
           intDirn = 7;
        }
        else if(strDirn == "NW")
        {
           intDirn = 8;
        }

        tooltipsDisplay = off;
//        showLocation = off;
//        setImageProcesses();
        document.SSTMapperApplet.panImage(intDirn);
    }

//------------------------------------------------------------------------------

     function reset_js()
     {
/*
     This function organizes resetting of the currently displayed image to be the
     image that was initially loaded from the thumbnails page, a sort of re-display
     of the inventory image. It calls the Mapper applet's reset method.
*/
//        setImageProcesses();
        document.SSTMapperApplet.resetImage();
     }

//------------------------------------------------------------------------------

     function setExpressLimits_js(setCancel)
     {
/*
     This function organizes setting or cancelling of the geographical limits of an
     express user's area of interest. Argument 'setCancel' will be set to 1 or 0 for
     a 'set' or 'cancel' operation respectively.
*/
        document.SSTMapperApplet.setExpressLimits(setCancel);
     }

//------------------------------------------------------------------------------

     function setImageProcesses()
     {
/*
     This function keeps a count of the number of processes that cause the image in the
     applet viewport to be updated. The purpose of the count is to prevent certain
     processes happening if the count is 1: no temperature tooltips (image is the initial
     inventory image which has too much data); no oops activity (no previous .alg file to
     work with). When the page loads, imageProcesses is undefined
*/
//        if(imageProcesses >= 1)
//        {
//           ++imageProcesses;
//        }
//        else
//        {
//           imageProcesses = 1;
//        }
     }

//------------------------------------------------------------------------------

     function setProcessOption_js(option)
     {
/*
     This function organizes setting or cancelling of an express user's preprocessing
     option. Values of 'option' of 1, 2, 3 refer to options colour balance, enhancement,
     and fast images.
*/
        document.SSTMapperApplet.setProcessOption(option);
     }

//------------------------------------------------------------------------------

     function showDepths_js()
     {
/*
     This function toggles the display of sea depth contours on the currently displayed
     image in the Mapper applet. It does so by calling the Mapper applet's depthsImage()
     method.
*/
        document.SSTMapperApplet.depthsImage();
     }

//------------------------------------------------------------------------------

     function showTemperatures_js()
     {
/*
     This function calls the Mapper applet's show tooltips temperature function.
     That function arranges for a grid of temperature cells to be generated so
     that the user can move the mouse over the displayed image and observe the
     underlying cell temperatures in a tooltip. This process should not be done if
     the user still has the inventory image displayed without zooming in on it. So
     check that a zoom process has been undertaken or whether the user is an express
     user with limits preset (implied zoom).
*/
        var operation_status;

        if(tooltipsDisplay == on)                        // Switch tooltips off
        {
           tooltipsDisplay = off;
           operation_status = document.SSTMapperApplet.showTemperatures(tooltipsDisplay);
           if(operation_status == 0)                     // Error image displayed: illegal op
           {
               tooltipsDisplay = on;                     // Revert flag
           }
//           showLocation = off;
        }
        else if(tooltipsDisplay == off)                  // Switch tooltips on
        {
           tooltipsDisplay = on;
           operation_status = document.SSTMapperApplet.showTemperatures(tooltipsDisplay);

           if(operation_status == 0)                     // No tooltips yet: image too big ...
           {                                             // ...  or error image displayed
               tooltipsDisplay = off;                    // Revert flag
           }
//           else                                          // Tool tips OK
//           {
//              showLocation = off;                        // Mouse location off
//           }
        }
     }

//------------------------------------------------------------------------------

     function showTowns_js()
     {
/*
     This function toggles the display of towns on the currently displayed image in the
     Mapper applet. It does so by calling the Mapper applet's townsImage() method.
*/
        document.SSTMapperApplet.townsImage();
     }

//------------------------------------------------------------------------------

     function switchLabelUnits_js()
     {
/*
     This function calls the Mapper applet's change-display-units-for-geog-labels
     function. Labels can be displayed in either degrees, minutes and seconds
     (default format) or decimals of degrees. This function toggles between them.
*/
        document.SSTMapperApplet.switchLabelUnits();
     }

//------------------------------------------------------------------------------

     function whereAmI_js()
     {
/*
     This function toggles display of the location of the mouse cursor in the mapper
     applet. As the cursor is moved over the image viewport, so the geographic location
     of the mouse will appear in the labels at the bottom of the viewport provided this
     function is enabled. Enabling/disabling is performed by toggling of the GUI inter-
     face button 'Where am I'.
*/
        document.SSTMapperApplet.whereAmI();
     }

//------------------------------------------------------------------------------

     function getUsedImages(downloadImgName, jwgImgName, emailImgName)
     {
/*
     Called by the 'onload' event of the 'make_world_file.pl' script to pre-load images when that
     page loads. The images may be used as part of the button functionality of that page. They
     provide a greying-out capability to indicate an operation has been made
*/
        usedImgDown.src  = downloadImgName;
        usedImgJwg.src   = jwgImgName;
        usedImgEmail.src = emailImgName;
     }

//------------------------------------------------------------------------------

     function usedImage(whichImage)
     {
/*
     Depending on the button clicked in the calling script 'make_world_file.pl', this function will
     substitute a greyed-out version of the image used as the button to indicate that that action
     has already taken place.
*/
        if(whichImage == "download")
        {
           document.downloadImgDown.src = usedImgDown.src;
        }
        else if(whichImage == "jgw")
        {
           document.downloadImgJgw.src = usedImgJwg.src;
        }
        else if(whichImage == "email")
        {
           document.downloadImgEmail.src = usedImgEmail.src;
        }
     }

//------------------------------------------------------------------------------

     function delay(delay_ms)
     {
/*
     Enables a delay of 'delay_ms' to be inserted into operations.
*/
        var future, limit, future_ms, limit_ms;

        limit    = new Date();
        limit_ms = limit.getTime() + delay_ms;

        do
        {
           future = new Date();
           future_ms = future.getTime();
        }  while ((limit_ms - future_ms) > 0);
     }

//------------------------------------------------------------------------------

     function zoomImage_js(pctZoom)
     {
/*
     This function organizes display of a zoomed image by calling the Mapper
     applet's zoom method. It also sets the tooltips display status to off to
     reflect what has happened in the Mapper applet.
*/
        tooltipsDisplay = off;
//        showLocation = off;

//        setImageProcesses();
//        zoomed = 1;                                        // Set zoomed process done
        document.SSTMapperApplet.zoomImage(pctZoom);
     }

//------------------------------------------------------------------------------

     function submitGfaaOption()
     {
/*
     This function ensures that if one of the SST radio button options is set (the GFAA checkbox
     will not be checked otherwise the radio buttons will be in a disabled state), then the submit
     button for the GFAA form is effectively disabled. The SST radio button options can only
     be submitted with the submit button that controls those opttions. It does this by returning
     false to the GFAA form event handler, effectively disabling the button.
*/
        var numberRadios = document.orderForm.sstoption.length;   // # Radio buttons

        for(i = 0; i < numberRadios; ++i)                         // Find any active radio button
        {
           if(document.orderForm.sstoption[i].checked)            // Checked?
           {                                                      // Yes, wrong
              return false;
           }
        }

        if(!document.getElementById("gfaa").checked)               // GFAA member
        {
           return false;
        }

        return true;
     }

//------------------------------------------------------------------------------

     function setRadioButtonStatus()
     {
/*
     This function ensures that if the GFAA member checkbox is checked in the 'order_form.pl'
     script, then the SST radio button options are automatically disabled and that any radio
     button that is set is cleared. The radio button options are for non-GFAA members.
*/
        var numberRadios = document.orderForm.sstoption.length;   // # Radio buttons

        if(document.getElementById("gfaa").checked)               // GFAA member
        {
           for(i = 0; i < numberRadios; ++i)                      // Find any active radio button
           {
              if(document.orderForm.sstoption[i].checked)         // Checked?
              {                                                   // Yes, clear it
                 document.orderForm.sstoption[i].checked = false;
              }

              document.orderForm.sstoption[i].disabled = true;    // Disable control
           }
        }
        else                                                      // Not GFAA member
        {
           for(i = 0; i < numberRadios; ++i)                      // Enable the radio buttons
           {
              document.orderForm.sstoption[i].disabled = false;
           }
        }
     }

//------------------------------------------------------------------------------

     function submitSstOption()
     {
/*
     This function ensures that if the GFAA member checkbox is checked in the 'order_form.pl'
     script, then the user cannot submit the GFAA member form with the submit button that controls
     the SST radio button options which are for non-GFAA members. It does this by returning false
     to the options form event handler, effectively disabling the button.
*/
        if(document.getElementById("gfaa").checked)               // GFAA member
        {
           return false;
        }

        return true;
     }

//------------------------------------------------------------------------------

     function checkCheckboxSelected(chkboxArray, question_number, user_type)
     {
/*
     This function checks whether a selection has been made in the checkbox set passed in to the
     routine. If not, a message is displayed to the user to this effect.
*/
        var numberChkBoxes = chkboxArray.length;               // Number of checkboxes
        var option_selected = false;                           // No radio selected yet

        for(i = 0; i < numberChkBoxes; ++i)                    // Find any active checkbox
        {
           if(chkboxArray[i].checked)                          // Selected?
           {
              option_selected = true;                          // Yes, set question answered
              break;
           }
        }

        if(!option_selected)                                   // No selection, message out
        {
           if(user_type == 1)                                  // Anonymous user
           {
              alert("\nYou must answer all questions 1 to 12 and 14.\nYou have not selected at least " +
                    "one response to\nquestion " + question_number + ". Please do so in order to " +
                    "continue .....\n\n");
           }
           else                                                // Registered user
           {
              alert("\nYou must answer all questions 1 to 12. You\nhave not selected at least " +
                    "one response to\nquestion " + question_number + ". Please do so in order to " +
                    "continue .....\n\n");
           }
        }

        return option_selected;
     }

//------------------------------------------------------------------------------

     function checkRadioSelected(radioArray, question_number, user_type)
     {
/*
     This function checks whether a selection has been made in the radio button set passed in
     to the routine. If not, a message is displayed to the user to this effect.
*/
        var numberRadios = radioArray.length;                  // Number of radio buttons
        var option_selected = false;                           // No radio selected yet

        for(i = 0; i < numberRadios; ++i)                      // Find any active radio button
        {
           if(radioArray[i].checked)                           // Selected?
           {
              option_selected = true;                          // Yes, set question answered
              break;
           }
        }

        if(!option_selected)                                   // No selection, message out
        {
           if(user_type == 1)                                  // Anonymous user
           {
              alert("\nYou must answer all questions 1 to 12 and 14.\nYou have not selected a " +
                    "response to question " + question_number + ".\nPlease do so in order to " +
                    "continue .....\n\n");
           }
           else                                                // Registered user
           {
              alert("\nYou must answer all questions 1 to 12. You\nhave not selected a response " +
                    "to question " + question_number + ".\nPlease do so in order to " +
                    "continue .....\n\n");
           }
        }

        return option_selected;
     }

//------------------------------------------------------------------------------

     function checkTextArea(txtArea, question_number, user_type)
     {
/*
     This function checks whether the textarea passed in has had some comments added to it. If
     not, a message is displayed to the user to this effect.
*/
        var txtAreaText, txtAreaLength;
        var commented = false;                                       // No comments added yet

        if((txtArea.value == "") || (txtArea.value == "undefined"))  // No comments
        {
           if(user_type == 1)                                        // Anonymous user
           {
              alert("\nYou must answer all questions 1 to 12 and 14.\nYou have not selected a " +
                    "response to question " + question_number + ".\nPlease do so in order to " +
                    "continue .....\n\n");
           }
           else                                                      // Registered user
           {
              alert("\nYou must answer all questions 1 to 12. You\nhave not entered a response " +
                    "to question " + question_number + ".\nPlease do so in order to " +
                    "continue .....\n\n");
           }
        }
        else
        {
           txtAreaText   = new String(txtArea.value);
           txtAreaLength = txtAreaText.length;
           if(txtAreaLength > 0)
           {
              for(i = 0; i < txtAreaLength - 1; ++i)
              {
                 if(txtAreaText.charAt(i) != " ")
                 {
                    commented = true;                        // Comments have been added
                    break;
                 }
              }

              if(!commented)
              {
                 if(user_type == 1)                          // Anonymous user
                 {
                    alert("\nYou must answer all questions 1 to 12 and 14. You\nhave entered a " +
                          "blank response to question " + question_number + ". Please\nenter a " +
                          "comment so that you can continue .....\n\n")
                 }
                 else                                        // Registered user
                 {
                    alert("\nYou must answer all questions 1 to 12. You have\n entered a blank " +
                          "response to question " + question_number + ". Please\nenter a comment " +
                          "so that you can continue .....\n\n")
                 }
              }
           }
           else                                              // Empty: logic trap, picked above?
           {
              if(user_type == 1)                             // Anonymous user
              {
                 alert("\nYou must answer all questions 1 to 12 and 14.\nYou have not entered a " +
                       "response to question " + question_number + ".\nPlease do so in order to " +
                       "continue .....\n\n")
              }
              else                                           // Registered user
              {
                 alert("\nYou must answer all questions 1 to 12. You\nhave not entered a response " +
                       "to question " + question_number + ".\nPlease do so in order to " +
                       "continue .....\n\n")
              }
           }
        }

        return commented;
     }

//------------------------------------------------------------------------------

     function checkTextBox(txtBox, question_number)
     {
/*
     This function checks whether the text box passed in has had a value entered. If not, a
     message is displayed to the user to this effect. At this stage, the text is an email
     address.
*/
        var txtBoxText, txtBoxLength, regExprTemplate;
        var commented = false;                                       // No comments added yet

        if(txtBox.value == "")                                       // No value entered
        {
           alert("\nYou must answer all questions 1 to 12 and 14.\nYou have not entered a " +
                 "response to question " + question_number + ".\nPlease do so in order to " +
                 "continue .....\n\n");
        }
        else
        {
           txtBoxText   = new String(txtBox.value);
           txtBoxLength = txtBoxText.length;
           if(txtBoxLength > 0)
           {
              for(i = 0; i < txtBoxLength - 1; ++i)
              {
                 if(txtBoxText.charAt(i) != " ")
                 {
                    commented = true;                        // Comments have been added
                    break;
                 }
              }

              if(!commented)
              {
                 alert("\nYou must answer all questions 1 to 12 and 14. You\nhave entered a blank " +
                       "response to question " + question_number + ".\nPlease enter an email " +
                       "address so that you can continue .....\n\n");
              }
           }
           else                                              // Empty: logic trap, picked above?
           {
              alert("\nYou must answer all questions 1 to 12 and 14.\nYou have not entered a " +
                    "response to question " + question_number + ".\nPlease do so in order to " +
                    "continue .....\n\n");
           }
        }

// If a 'comment' has been added (in this case it should be an email address) let's test for a
// valid email

        if(commented)                                        // Something entered
        {
           regExprTemplate = /^ *[a-zA-Z0-9_\-.]+\@[a-zA-Z0-9_\-]+\.[a-zA-Z0-9_\-.]+ *$/;

           if(!regExprTemplate.test(txtBoxText))             // Not valid email
           {
              alert("\nThe Email address that you have entered appears to be\ninvalid. Please " +
                    "try again in order to continue .....\n\n");

              commented = false;
           }
        }

        return commented;
     }

//------------------------------------------------------------------------------

     function submitQuestionnaire(user_type)
     {
/*
     This routine validates the submitted questionnaire to check that all mandatory questions have
     been answered. If not, form submission is cancelled by returning a value of 'false'. Argument
     'user_type' will be set to 0/1 for 'registered_user'/'anonymous_user'.
*/
        var radioArray, txtArea, txtBox, selected, commented;

        radioArray = document.questionForm.q1;                     // Question 1
        selected   = checkRadioSelected(radioArray, 1, user_type);
        if(!selected)
        {
           return false;
        }

        chkboxArray = document.questionForm.q2;                    // Question 2
        selected    = checkCheckboxSelected(chkboxArray, 2, user_type);
        if(!selected)
        {
           return false;
        }

        radioArray = document.questionForm.q3;                     // Question 3
        selected   = checkRadioSelected(radioArray, 3, user_type);
        if(!selected)
        {
           return false;
        }

        radioArray = document.questionForm.q4;                     // Question 4
        selected   = checkRadioSelected(radioArray, 4, user_type);
        if(!selected)
        {
           return false;
        }

        radioArray = document.questionForm.q5;                     // Question 5
        selected   = checkRadioSelected(radioArray, 5, user_type);
        if(!selected)
        {
           return false;
        }

        radioArray = document.questionForm.q6;                     // Question 6
        selected   = checkRadioSelected(radioArray, 6, user_type);
        if(!selected)
        {
           return false;
        }

        radioArray = document.questionForm.q7;                     // Question 7
        selected   = checkRadioSelected(radioArray, 7, user_type);
        if(!selected)
        {
           return false;
        }

        txtArea   = document.questionForm.q8;                      // Question 8
        commented = checkTextArea(txtArea, 8, user_type);
        if(!commented)
        {
           return false;
        }

        txtArea   = document.questionForm.q9;                      // Question 9
        commented = checkTextArea(txtArea, 9, user_type);
        if(!commented)
        {
           return false;
        }

        radioArray = document.questionForm.q10;                    // Question 10
        selected   = checkRadioSelected(radioArray, 10, user_type);
        if(!selected)
        {
           return false;
        }

        txtArea   = document.questionForm.q11;                     // Question 11
        commented = checkTextArea(txtArea, 11, user_type);
        if(!commented)
        {
           return false;
        }

        radioArray = document.questionForm.q12;                    // Question 12
        selected   = checkRadioSelected(radioArray, 12, user_type);
        if(!selected)
        {
           return false;
        }

// Question 14 is mandatory for anonymous users only -- their email address

        if(user_type == 1)                                         // Anonymous user
        {
           txtBox = document.questionForm.q14;                     // Question 14
           commented = checkTextBox(txtBox, 14);
           if(!commented)
           {
              return false;
           }
        }

        return true;
     }

//------------------------------------------------------------------------------

     function showCurrents_js()
     {
/*
     This function toggles the display of sea currents on the currently displayed image in the
     SSTMapper applet. It does so by calling the SSTMapper applet's showCurrents() method.
*/
        document.SSTMapperApplet.showCurrents();
     }

//------------------------------------------------------------------------------

     function showMarks_js(which)
     {
/*
     This function toggles the display of marks sites on the currently displayed image in the
     SSTMapper applet. It does so by calling the SSTMapper applet's showMarks() method. The type
     of marks to display is defined by the 'which' argument: 0/1 for SST/track marks
*/
        document.SSTMapperApplet.showMarks(which);
     }

//-------------------------------------------------------------------------------------------

     function depthLegend(contentFile)
     {
/*
     Displays the legend for the bathymetry contours in a popup window if it can be opened.
*/
        var status;

        status = depthWindow(contentFile, topLeftX, topLeftY, width, height);

        return status;
     }

//-------------------------------------------------------------------------------------------

     function depthWindow(contentFile, tlx, tly, w, h)
     {
/*
     Opens a new browser window, with printing option, that displays the colour legend for the different
     bathymetry contours.
*/
        if(legendWindow)                             // Kill window from previous use in case it is minimized
        {
           legendWindow.close();
           legendWindow = null;
        }

        legendWindow = window.open(contentFile,"legendWin","left="+tlx+",top="
                            +tly+",width="+w+",height="+h+",toolbar=no,resizable=no,scrollbars=no");


        if(!legendWindow)                           // No popup window: continue with action in calling script
        {
           return true;
        }

        return false;                               // Popup window opened: cancel action in calling script
     }

//-------------------------------------------------------------------------------------------

     function detectPopupCapability()
     {
/*
     Tests whether a 'popup' window (scripted window) can be opened or not, that is whether a 'popup-blocker'
     is active.
*/
        if(testWindow)                                  // Kill the window from any previous use
        {
          testWindow.close();
          testWindow = null;
        }

        testWindow = window.open("about:blank","","toolbar=no,resizable=no,scrollbars=no,"
                                                     +"left=300,top=300,width=10,height=10");

        if(testWindow)                                 // Opened OK: kill it and set flag
        {
          testWindow.close();
          popupsOK = true;
        }
     }

//-------------------------------------------------------------------------------------------

     function printWindow(contentFile, topLeftX, topLeftY)
     {
/*
     Opens a new browser window, that has a printing option available, with
     the contents of the nominated URL.
*/     

        if(infoWindow)
        {
           infoWindow.close();
           infoWindow = null;
        }

        infoWindow = window.open(contentFile,"infoWindow","left="+topLeftX+",top="
             +topLeftY+",toolbar=yes,resizable=yes,scrollbars=yes,width=760,height=480");
     }
     