function showLayer(lyr)
  {
   var layer = null;

   if (typeof lyr == "string")
     { layer = document.getElementById(lyr); }
   else
     { layer = lyr; }

   if (layer.style.display.equalsIgnoreCase("none"))
     { show(layer.id); }
   else
     { hide(layer.id); }
  }

function showFilters()
  { showLayer("lyrFilter"); }

function emptyTable(table)
  {
   var tbl = null;

   if ((typeof table) == "string")
     { tbl = document.getElementById(table); }
   else
     { tbl = table; }

   while (tbl.rows.length > 0)
     { tbl.deleteRow(0); }
  }

function emptySelect(slc)
  {
   var select = null;

   if ((typeof slc) == "string")
     { slc = document.getElementById(slc); }
   else
     { select = slc; }

   while (select.options.length > 0)
     { select.options[0] = null; }
  }

function goTo(url)
  { parent.window.location.href = url; }

function reloadPage()
  { parent.window.location.reload(); }

function selectClient(path)
  { popup((typeof path != "undefined" ? path : "") + "/Clients.selectFromPopup.mtw", 750, 550); }

function selectEquipment(path, clientId)
  { popup((typeof path != "undefined" ? path : "") + "/Equipments.selectFromPopup.mtw?client.id=" + clientId, 650, 382); }

function popup(url, width, height)
  { window.open(url, '', 'width= ' + width + ", height= " + height + ", resizable=1, scrollbars=1"); }

function hideHeaderMenu()
  { hide("headerMenu"); }

function hideFooterMenu()
  { hide("footerMenu"); }

function hideMenus()
  {
   hideHeaderMenu();
   hideFooterMenu();
  }

function tryCreateDataTable(table)
  {
   try
     { DataTableUtils.simpleHTMLTable2DataTable(document.getElementById(table)); }
   catch (e)
     { alert(e); }
  }

function submitForm(form)
  { document.getElementById(form).submit(); }

function linkedTabListener(evt)
  {
   var tab = evt.getTab();
   var fldLink = document.getElementById(tab.id + "-link");

   if (!fldLink)
     { return; }

   var url = fldLink.value;
   var destinyTab = document.getElementById(tab.id + "-destiny").value;

   if ((typeof destinyTab) != "undefined")
     {
      var firstParam = true;

      if (url.indexOf("?") == -1)
        { url += "?"; }
      else
        { url += "&"; }

      url += "orgDitchnetTabPaneId=" + destinyTab;
     }

   goTo(url);
  }

function checkTabLink()
  {
   var linkedTab = request.getParameter("orgDitchnetTabPaneId");

   if (linkedTab == null)
     { return; }

   var tabContainer = document.getElementById(linkedTab + "-tab").parentNode.parentNode;
   var name  = "org.ditchnet.jsp.tabs:" + tabContainer.id;
   org.ditchnet.util.Cookie.addPageCookie(new org.ditchnet.util.Cookie(name, 0));
  }

window.setTimeout(checkTabLink, 100);