function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
function openBlank() {
	if ( document.getElementById && document.createTextNode ) {
		var anchors = document.getElementsByTagName('a');
		for ( var i=0; i < anchors.length; i++ ) {
			var classes_array = anchors[i].className.split(' ');
			var isBlank = false;
			var isPopup = false;
			for ( var g = 0; g < classes_array.length; g++ ) {
				if ( classes_array[g] == 'offsite' ) {
					anchors[i].title= anchors[i].title + ' (Ouvrir dans une nouvelle fenetre)';
					anchors[i].onclick = function() {
						var newWin = window.open( this.getAttribute('href'), '_blank', '' );
						newWin.focus();
						return false;
					}
				}
			}
		}
		return true;
	}
	else { return false; }
}
function showSection(id) {
  var divs = document.getElementsByTagName("ul");
  for (var i=0; i<divs.length; i++ ) {
    if (divs[i].className.indexOf("linksection") == -1) continue;
    if (divs[i].getAttribute("id") != id) {
      divs[i].style.display = "none";
    } else {
      divs[i].style.display = "block";
    }
  }
}

function prepareInternalnav() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("showhidelinks")) return false;
  var nav = document.getElementById("showhidelinks");
  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;
    }
  }
}
addLoadEvent(openBlank);
addLoadEvent(prepareInternalnav);
