function SwitchTdb(panneau){

	d = document.getElementById('boxstats');
	e = document.getElementById('boxemploi');
	f = document.getElementById('boxagenda');
	g = document.getElementById('boxnomi');
	x = 'box'+panneau;
	z = document.getElementById(x);
	
	d2 = document.getElementById('ongletstats');
	e2 = document.getElementById('ongletemploi');
	f2 = document.getElementById('ongletagenda');
	g2 = document.getElementById('ongletnomi');
	x2 = 'onglet'+panneau;
	z2 = document.getElementById(x2);
	
	g.style.display = "none";
	e.style.display = "none";
	f.style.display = "none";
	d.style.display = "none";	
	
	e2.className = "off";
	f2.className = "off";
	d2.className = "off";
	g2.className = "off";
	
	z.style.display = "block";
	z2.className = "on";
	
	createCookie('tdb_ai',panneau,'30');
	
}


function switchDivs(div1,div2)	{
	d = document.getElementById(div1);
	e = document.getElementById(div2);
	d.style.display= "none";
	e.style.display= "block";
}

function SwitchOn(id)	{
	d = document.getElementById('sous_menu_'+id);
	d.style.display = 'block';
}

function SwitchOff(id)	{
	d = document.getElementById('sous_menu_'+id);
	d.style.display = 'none';
}

// Si on est deja sur la page

function SemiSwitch(id)	{
	d = document.getElementById('sous_menu_'+id);
	d.style.display = 'none';
}

function SwitchLang(url,lang)	{
	if (lang=="fr"){
		document.location=url+"&lang=en";
	} else {
		document.location=url+"&lang=fr";
	}
}
	
function highlight(objet, myClass){ 
	d = document.getElementById(objet);
	if (d) {
  		d.className = myClass;
  	}
}

function depliance(objet){
	d = document.getElementById(objet);
	var etat = d.style.display;
	
	if (etat!='none') {
		d.style.display = 'none';
	} else {
		d.style.display = 'block';
	}
}

function initSwitch(){
	d = document.getElementById("destinataire").value;
	rt = document.getElementById("message_auteur_3");
	a = document.getElementById("message_auteur_2");
	if (d!='3')	{
		rt.style.display = 'none';
		a.style.display = 'block';
	} else {
		a.style.display = 'none';
		rt.style.display = 'block';
	}
}
	

function switchMsg(article,value)	{
	d = document.getElementById("contactauteur");
	d.action = "spip.php?article"+article+"#formulaire_ecrire_auteur_"+value;
	alert(d.action);
}

function confMsg(value)	{
	d = document.getElementById("contactauteur");
	d.action = document.location+"#formulaire_ecrire_auteur_"+value;
	alert(d.action);
}



function switchMsgAuteur() {
	d = document.getElementById("preview");
	var orig = document.getElementById("message");
		if (d) {
			d.style.opacity = 0.5;
			orig.style.opacity = 1;
		}
	}
	
function Popup(url,largeur,hauteur) {
	var where = new String(document.location);
	var recherche = where.indexOf('recherche');
	if (recherche=='-1') {
		var page = url + "?mode=popup";
	} else {
		var page = url + "&mode=popup";
	}
	var dimensions = "width="+largeur+", height="+hauteur+", scrollbars=yes, resizable=yes";
	popup = window.open(page,'ETAI',dimensions);
	popup.opener.name = "opener";
}

function getBack(destination){
	opener.location=destination;
	opener.focus();
	window.close();
}

// Cookie tdb

function getCookieVal (offset) {
      var endstr = document.cookie.indexOf (";", offset);
      if (endstr == -1)
        endstr = document.cookie.length;
      return unescape(document.cookie.substring(offset, endstr));
    }
    
function GetCookie(name) {
      var arg = name + "=";
      var alen = arg.length;
      var clen = document.cookie.length;
      var i = 0;
      while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
          return getCookieVal (j);
    	i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
      }
      return null;
    }

function createCookie(name,value,days){
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "; expires=Thu, 01-Jan-1970 00:00:01 GMT";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0){
			SwitchTdb(c.substring(nameEQ.length,c.length));
		}
	}
	
	return null;
}

function reTweet(titre,url){
	BitlyCB.myShortenCallback = function(data) {
		// this is how to get a result of shortening a single url
		var result;
		for (var r in data.results) {
			result = data.results[r];
			result['longUrl'] = r;
			break;
		}
		var bitly = result['shortUrl'];
		var twitty ='http://twitter.com/home?status='+titre+' - '+bitly;
		document.location = twitty;
	}
	BitlyClient.shorten(url, 'BitlyCB.myShortenCallback');
}