﻿
function showShips(obj) {
  // grab the code of the selected line and show the possible ships.  Hide all others.
  var _line;
  _line = obj.options[obj.selectedIndex].value;
  if (_line == -1) { _line = "Any"; }
  if (_line != "") {
    // step through all the select boxes for cities
    for (var e = 0; e < obj.form.elements.length; e++) 
    {
      if (obj.form.elements[e].name == ("selShip" + _line)) 
      {
        obj.form.elements[e].style.display = "inline";
        obj.form.elements[e].style.opacity = 0;
        obj.form.elements[e].selectedIndex = 0;
        document.getElementById("selectselShip" + _line).style.display = "inline";
      }
      else if (obj.form.elements[e].name.substr(0, 7) == "selShip") 
      {
        if (obj.form.elements[e].style.display == "inline") 
        {
          obj.form.elements[e].selectedIndex = 0;
        }
        obj.form.elements[e].style.display = "none";
        document.getElementById("select" + obj.form.elements[e].name).style.display = "none";
      }
    }
  } 
  // clear the ship value
  document.getElementById("hfShipID").value = "-1";
  //alert(_line);
}

function filterShips(obj) {
  //alert("filterShips: " + document.getElementById("hfShipID").value);
  // Grab the ships drop down, clear all options and rewrite for this line
  var _line;
  _line = obj.options[obj.selectedIndex].value;
  var _ddlShip;
  _ddlShip = document.getElementById("ddlShip");
  // Clear options
  _ddlShip.options.length = 0;
  var _newOpt;
  // Add the Any option
  _newOpt = new Option("Any", "-1", false, false);
  _ddlShip.options[_ddlShip.options.length] = _newOpt;
  // Step through the array of ship information and build options out of those on this line
  for (var s = 0; s < aShips.length; s++) {
    if ((_line == -1) || (_line == aShips[s].lineID.toString())) {
      //alert(document.getElementById("hfShipID").value + " :: " + aShips[s].shipID.toString())
      if (document.getElementById("hfShipID").value == aShips[s].shipID.toString()) {
        _newOpt = new Option(aShips[s].name, aShips[s].shipID, true, true);
      } else {
        _newOpt = new Option(aShips[s].name, aShips[s].shipID, false, false);
      }
      _ddlShip.options[_ddlShip.options.length] = _newOpt;
    }
  }
  // clear the ship value
  //document.getElementById("hfShipID").value = "-1";
  // fire the onchange event handler, to update clever formatted boxes
  _ddlShip.onchange();
}

function selectShip(obj) {
  //alert("selectShip: " + document.getElementById("hfShipID").value);
  // grab the selected ship  code
  var _ship;
  _ship = obj.options[obj.selectedIndex].value;
  // set the hidden field value
  document.getElementById("hfShipID").value = _ship;
}

function selectPage(pageNo) {
  // set the hidden field and submit the form
  document.getElementById("hfPage").value = pageNo;
  document.forms[0].submit();
}
