/*
	Descrição: ICN - Instituto da Conservação da Natureza
	Autor: Innovagency.com - David Moisés Lages
*/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function showSection(id) {
  var divs = document.getElementsByTagName("div");
  for (var i=0; i<divs.length; i++ ) {
    if (divs[i].className.indexOf("section") == -1) continue;
    if (divs[i].getAttribute("id") != id) {
      divs[i].style.display = "none";
    } else {
      divs[i].style.display = "block";
    }
  }
}

function prepareInternalList() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("listDiv")) return false;
  var nav = document.getElementById("listDiv");
  var links = nav.getElementsByTagName("a");
  for (var i=0; i<links.length; i++ ) {
    var sectionId = links[i].getAttribute("href").split("#")[1];
    if (!document.getElementById(sectionId)) continue;
    document.getElementById(sectionId).style.display = "none";
    links[i].destination = sectionId;
    links[i].onclick = function() {
      showSection(this.destination);
      return false;
    }
  }
}

function showSectionPesq(id) {
  var divs = document.getElementsByTagName("div");
  for (var i=0; i<divs.length; i++ ) {
    if (divs[i].className.indexOf("section") == -1) continue;
    if (divs[i].getAttribute("id") != id) {
      divs[i].style.position = "absolute"; //Martelada By: David Moisés Lages
      divs[i].style.display = "none";
    } else {
      divs[i].style.position = "absolute"; //Martelada By: David Moisés Lages
      divs[i].style.display = "block";
    }
  }
}

function prepareInternalPesq() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("botPesquisa")) return false;
  document.getElementById("botPesquisa").style.display = "block"; //Martelada By: David Moisés Lages
  var nav = document.getElementById("botPesquisa");
  var links = nav.getElementsByTagName("a");
  for (var i=0; i<links.length; i++ ) {
    var sectionId = links[i].getAttribute("href").split("#")[1];
    if (!document.getElementById(sectionId)) continue;
    document.getElementById(sectionId).style.position = "absolute"; //Martelada By: David Moisés Lages
    document.getElementById(sectionId).style.display = "none";
    links[i].destination = sectionId;
    links[i].onclick = function() {
      showSectionPesq(this.destination);
      return false;
    }
  }
}

function prepareInternalPesqClose() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("botFechar")) return false;
  var nav = document.getElementById("botFechar");
  var links = nav.getElementsByTagName("a");
  for (var i=0; i<links.length; i++ ) {
    var sectionId = links[i].getAttribute("href").split("#")[1];
    if (!document.getElementById(sectionId)) continue;
    document.getElementById(sectionId).style.display = "none";
    links[i].destination = sectionId;
    links[i].onclick = function() {
      document.getElementById(sectionId).style.display = "none"; //Martelada By: David Moisés Lages
      return false;
    }
  }
}

addLoadEvent(prepareInternalList);
addLoadEvent(prepareInternalPesq);
addLoadEvent(prepareInternalPesqClose);
