window.onload = function() {
  alterar_form_idioma();
  incluir_topo();
  alterar_tags();
  return true;
};
window.onscroll = function() {
  var s = document.getElementById("voltar_topo");
  if (s) {
    var pos = get_scroll();
    var o = pos > 10 ? "0.9" : "0.1";
    s.style.opacity = o;
  }
  return true;
}
function get_scroll() {
  var scroll = 0;
  if (typeof(window.pageYOffset) == 'number') {
    scroll = window.pageYOffset;
  } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
    scroll = document.body.scrollTop;
  } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
    scroll = document.documentElement.scrollTop;
  }
  return scroll;
}
function get_height() {
  var h = 0;
  if (typeof(window.innerWidth) == 'number') {
    h = window.innerHeight;
  } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    h = document.documentElement.clientHeight;
  } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
    h = document.body.clientHeight;
  }
  return h;
}
function alterar_form_idioma() {
  var f = document.getElementById("form_idioma");
  if (!f) { return false; }
  var i = f.getElementsByTagName("input").item(0);
  i.style.display = "none";
  var l = f.getElementsByTagName("label").item(0);
  l.style.display = "none";
  var s = f.getElementsByTagName("select").item(0);
  s.onchange = function() {
    s.parentNode.submit();
    return true;
  }
  return true;
}
function incluir_topo() {
  var v = document.createElement("a");
  v.appendChild(document.createTextNode("Topo"));
  v.id = "voltar_topo";
  v.setAttribute("title", "Voltar ao Topo");
  v.className = "voltar_topo";
  v.style.opacity = "0.1";
  v.onclick = function(e) {
    e = e ? e : window.event;
    e.returnValue = false;
    window.scroll(0, 0);
    return false;
  };
  document.getElementById("container").appendChild(v);
  return true;
};
function alterar_tags() {
  var tags = document.getElementsByTagName("*");
  for (var i = 0; i < tags.length; i++) {
    var tag = tags.item(i);
    switch (tag.nodeName.toLowerCase()) {
    case "a":
      if (tag.getAttribute("rel") == "abre_fecha") {
        var id = tag.getAttribute("href").substr(1);
        var div = document.getElementById(id);
        if (div) { 
          div.style.display = "none";
          tag.onclick = function() {
            var id = this.getAttribute("href").substr(1);
            var div = document.getElementById(id);
            div.style.display = (div.style.display == "none") ? "block" : "none";
            return false;
          };
        }
      }
      break;
    }
  }
  return true;
};