/*
 * date:	2002-10-11
 * info:	http://inspire.server101.com/js/tp/
 * revu par Christophe PORCIELLO : http://www.porciello.com
 */

var tp = [];
var tpl = [];

function DefinirOnglets(i, c) {
if (document.createElement) {
	var e = document.getElementById(i);
	var l = document.createElement('ul');
	var p = document.createElement('div');
	e.className = l.className = p.className = c;

	var a, j, t;
	var nom_page = window.location.pathname;
  nom_page = nom_page.split("/");
  nom_page = nom_page[nom_page.length - 1];
  
  var recup_onglet = "onglet-"+getParameter("onglet");
  
  var existe_onglet = 0;
  
	for (j = 2; j < arguments.length; j++) {
		c = document.getElementById(t = arguments[j]);
		if (t == recup_onglet) {existe_onglet = 1;}
		tp[t] = c.parentNode.removeChild(c);

		a = l.appendChild(document.createElement('li'));
		a.className = c.className;
		tpl[t] = a = a.appendChild(document.createElement('a'));
		//a.setAttribute('href', nom_page+'?'+t.substring(7, t.length));
    a.setAttribute('href', 'javascript:AfficherOnglet(\''+i+'\', \''+t+'\');');
		a.appendChild(document.createTextNode(c.getAttribute('title')));
	}

	p.appendChild(tp[arguments[2]]);
	tpl[arguments[2]].className = 'active';

	while (e.firstChild) e.removeChild(e.firstChild);
	e.appendChild(l);
	e.appendChild(p);	
	
	/////////////////////////////////////////////////

	if(existe_onglet == 1)
	{AfficherOnglet(i, recup_onglet);}

	////////////////////////////////////////////////
	
}}

function AfficherOnglet(e, p) {
	e = document.getElementById(e).lastChild;
	tpl[e.replaceChild(tp[p], e.firstChild).getAttribute('id')].className = null;
	tpl[p].className = 'active';
	tpl[p].blur();
}

/*   ajouté par tichat, pour gérer les paramètres GET ^______^   */

function getParameter(name) {
   var url = window.location.href;
   var paramsStart = url.indexOf("?");

   if(paramsStart != -1){

      var paramString = url.substr(paramsStart + 1);
      var tokenStart = paramString.indexOf(name);

      if(tokenStart != -1){

         paramToEnd = paramString.substr(tokenStart + name.length + 1);
         var delimiterPos = paramToEnd.indexOf("&");

         if(delimiterPos == -1){
            return paramToEnd;
         }
         else {
            return paramToEnd.substr(0, delimiterPos);
         }
      }
   }
}

