var ie = /MSIE/.test(navigator.userAgent);
var moz = !ie && navigator.product == "Gecko";
var csch = "/";

if (moz) {
    	HTMLElement.prototype.__defineGetter__("children", function() {
			var arr = new Array(), i = 0, l = this.childNodes.length;
			for ( i = 0; i < l; i++ ) {
				if ( this.childNodes[ i ].nodeType == 1 ) {
					arr.push( this.childNodes[ i ] );
				}
			}
			return arr;
		});
		HTMLElement.prototype.__defineGetter__("firstChild", function() {
			var node = this.childNodes[ 0 ];
			while (node.nodeType != 1) node = node.nextSibling;
			return node;
		});
		HTMLElement.prototype.__defineGetter__("lastChild", function() {
			var node = this.childNodes[ this.childNodes.length - 1 ];
			while (node.nodeType != 1) node = node.previousSibling;
			return node;
		});
}      


function Reduc(elmtTitre)
{
	var elmt = elmtTitre.parentNode.parentNode;
	if (elmt.children[0].className == "expand")
	{
		elmt.children[1].className = "contentcollapse";
		elmt.children[0].className = "collapse";
		SetCookie(elmt.id,"collapse");
	}
	else
	{
		elmt.children[1].className = "content";
		elmt.children[0].className = "expand";
		SetCookie(elmt.id,"expand");
	}
}


function expandAlbum(id_alb)
{	
	//var _tabMain = document.getElementById(targetName + 'mainTable');
	var _tab = document.getElementById(id_alb);
	var _img = document.getElementById('img_'+id_alb);
	if(_tab != null)
	{
		if(_tab.style.display == 'inline')
		{
			_tab.style.display = 'none';
			_img.src='../images/album/albumplus.gif';
			_img.alt='afficher les titres';
		}
		else
		{
			_tab.style.display = 'inline';
			_img.src='../images/album/albummoins.gif';
			_img.alt='cacher les titres';
		}
	}
}


function reduit(id_source,id_alb)
{	
	//var _tabMain = document.getElementById(targetName + 'mainTable');
	var _tab = document.getElementById(id_source);
	var _tab2 = document.getElementById(id_alb);
	//var _img = document.getElementById('img_'+id_alb);
	
	if(_tab != null && _tab2 != null)
	{
		
		if (_tab.className == "expand")
		{
			_tab.className = "collapse";
			_tab2.className = "contentcollapse";
			//SetCookie(_tab.id,"collapse");
			EcrireCookie(_tab2.id,'collapse','', '/')
		}
		else
		{
			_tab.className = "expand";
			_tab2.className = "content";
			//SetCookie(_tab.id,"expand");
			EcrireCookie(_tab2.id,'expand','', '/')
		}

	
		/*
		if(_tab.style.display == 'inline')
		{
			_tab.style.display = 'none';
			_img.src='../images/album/albumplus.gif';
			_img.alt='afficher les titres';
		}
		else
		{
			_tab.style.display = 'inline';
			_img.src='../images/album/albummoins.gif';
			_img.alt='cacher les titres';
		}
		
		*/
	}
}


var enablepersist="on" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="no" //Collapse previously open content when opening present? (yes/no)

if (document.getElementById){
	document.write('<style type="text/css">')
	document.write('.switchcontent{display:none;}')
	document.write('</style>')
}

function getElementbyClass(classname){
	ccollect=new Array()
	var inc=0
	var alltags=document.all? document.all : document.getElementsByTagName("*")
	for (i=0; i<alltags.length; i++){
		if (alltags[i].className==classname)
			ccollect[inc++]=alltags[i]
	}
}

function contractcontent(omit){
var inc=0
	while (ccollect[inc]){
		if (ccollect[inc].id!=omit)
		ccollect[inc].style.display="none"
		inc++
	}
}

function expandcontent(cid){
	if (typeof ccollect!="undefined"){
		if (collapseprevious=="yes")
		contractcontent(cid)
		document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
	}
}

function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
	for (i=0; i<selectedComponents.length-1; i++)
	document.getElementById(selectedComponents[i]).style.display="block"
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) { 
			offset += search.length
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
	selectedItem=get_cookie(window.location.pathname)
	return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
	if (ccollect[inc].style.display=="block")
	selectedItem+=ccollect[inc].id+"|"
	inc++
}

document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
getElementbyClass("switchcontent")
	if (enablepersist=="on" && typeof ccollect!="undefined"){
		document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
		firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
		if (!firsttimeload)
		revivecontent()
	}
}


if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate




/****************** COOKIES **********************/



        // Déclaration des variables 'domaine' et 'date d'expiration'
        var pathname=location.pathname;
		
        var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
       	
	    var date_exp = new Date();
		
        date_exp.setTime(date_exp.getTime()+(365*24*3600*1000)); 


        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 SetCookie (name, value) {
	// un cookie a besoin d'un nom, d'une valeur, d'un nom de domaine, d'une date d'expiration
	//
	var argv=SetCookie.arguments;
	var argc=SetCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;

	document.cookie=name+"="+escape(value)+
		((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
		((path==null) ? "" : ("; path="+path))+
		((domain==null) ? "" : ("; domain="+domain))+
		((secure==true) ? "; secure" : "");
	alert	(document.cookie);
}


function EcrireCookie(nom, valeur)
{
	var dateCookie = new Date()
	dateCookie.setMonth(dateCookie.getMonth()+1);        

   var argv=EcrireCookie.arguments;
   var argc=EcrireCookie.arguments.length;
   var expires=(argc > 2) ? argv[2] : null;
   var path=(argc > 3) ? argv[3] : null;
   var domain=(argc > 4) ? argv[4] : null;
   var secure=(argc > 5) ? argv[5] : false;
   document.cookie=nom+"="+escape(valeur)+
      ((expires==null) ? "" : ("; expires="+dateCookie.toGMTString()))+
      ((path==null) ? "" : ("; path="+path))+
      ((domain==null) ? "" : ("; domain="+domain))+
      ((secure==true) ? "; secure" : "");
}

function lireCookie(nom)
{

	var donneesCookie = new String(document.cookie)
	var enteteCookie = nom +"=";

	var debutCookie = donneesCookie.indexOf(enteteCookie)
	//var debutCookie = startCookie + 8;
	var finCookie = donneesCookie.indexOf(";", (debutCookie+8) );
	if (finCookie == -1) { finCookie = donneesCookie.length }
	if (debutCookie != -1){
		return donneesCookie.substring((debutCookie+8), finCookie)
	}
	else{
		return "";
	}
}