// $Id: hide-foreign.js 24593 2008-08-31 10:47:51Z vinc17/vin $

var langattr, lang;
var show = document.createElement("a");
var hide = document.createElement("a");

window.onload = function(e)
{
  langattr = "xml:lang";
  lang = document.documentElement.getAttribute(langattr);
  if (lang == "" || lang == null)  // Hack for Opera.
    {
      langattr = "lang";
      lang = document.documentElement.getAttribute(langattr);
    }

  var showattr = document.createAttribute("href");
  var hideattr = document.createAttribute("href");
  var showtxt, hidetxt;
  if (lang == "en")
    {
      showtxt = document.createTextNode("Show all items");
      hidetxt = document.createTextNode(
        "Hide items that are not in English");
    }
  if (lang == "fr")
    {
      showtxt = document.createTextNode("Montrer toutes les entrées");
      hidetxt = document.createTextNode(
       "Cacher les entrées qui ne sont pas en français");
    }
  showattr.nodeValue = "javascript:showAll()";
  hideattr.nodeValue = "javascript:hideForeign()";
  show.setAttributeNode(showattr);
  hide.setAttributeNode(hideattr);
  show.appendChild(showtxt);
  hide.appendChild(hidetxt);
  replaceChild(hide);
}

function replaceChild(node)
{
  var elem = document.getElementById("show-hide");
  elem.removeChild(elem.firstChild);
  elem.appendChild(node);
}

function hideForeign()
{
  var topc = document.getElementById("top").childNodes;
  for (var i = 0; topc[i]; i++)
    {
      if (topc[i].nodeType == 1 &&
          topc[i].getAttribute("class") &&
          topc[i].getAttribute("class").substring(0,5) == "clear" &&
          topc[i].getAttribute(langattr) &&
          topc[i].getAttribute(langattr) != lang)
        {
          topc[i].style.display = "none";
        }
    }
  replaceChild(show);
}

function showAll()
{
  var divs = document.getElementsByTagName("div");
  for (var i = 0; divs[i]; i++)
    {
      divs[i].style.display = "block";
    }
  replaceChild(hide);
}
