/**
 * Masque / affiche un objet
 */
function toggle_display(idname)
{
    obj = fetch_object(idname);
    if (obj)
    {
        if (obj.style.display == "none")
        {
            obj.style.display = "";
        }
        else
        {
            obj.style.display = "none";
        }
    }
    return false;
}

function jol_toggle_class(objid)
{
    // Doit-on ouvrir ou ferme ?
    if (!document.getElementById('titreForum_' + objid)) {
        return;
    }

    var titre = document.getElementById('titreForum_' + objid);
    var open = (titre.className == 'titreForum');

    if (open) {
        titre.className = 'titreForumFerme';
    } else {
        titre.className = 'titreForum';
    }

    if (document.getElementById('td_' + objid)) {
        var td = document.getElementById('td_' + objid);
        if (open) {
            td.className = 'tcat home_forum_ferme';
        } else {
            td.className = 'tcat';
        }
    }

    if (document.getElementById('ombre_' + objid)) {
        var ombre = document.getElementById('ombre_' + objid);
        if (open) {
            ombre.className = 'ombreCachee';
        } else {
            ombre.className = 'ombre1';
        }
    }

    if (document.getElementById('description_' + objid)) {
        var description = document.getElementById('description_' + objid);
        if (open) {
            description.style.display = 'none';
        } else {
            description.style.display = 'block';
        }    
    }

    return false;
}

/**
 *
 */
var jol_bbcodepopup_cache = new Array();
var jol_bbcodepopup_ajax = null;
var jol_bbcodepopup_id = 0;
function jol_bbcodepopup(id)
{   
    jol_bbcodepopup_id = id;
    if (jol_bbcodepopup_ajax == null) {
        jol_bbcodepopup_ajax = new vB_AJAX_Handler(true);
        jol_bbcodepopup_ajax.onreadystatechange(jol_bbcodepopup_ajax_receiver);
    }
    if (jol_bbcodepopup_cache[id]) {
        var item = jol_bbcodepopup_cache[id];
        var obj = fetch_object('overDiv');
        if (obj)
        {
            obj.innerHTML = item;
        }
    } else {
        jol_bbcodepopup_ajax.send('/jol/bbcodepopups/ajax.php', 'id=' + id);
    }
    return false;
}
function jol_bbcodepopup_ajax_receiver()
{
    var id = jol_bbcodepopup_id;
    if (jol_bbcodepopup_ajax.handler.readyState == 4
       && jol_bbcodepopup_ajax.handler.status == 200
       && jol_bbcodepopup_ajax.handler.responseXML)
    {
        var rep = jol_bbcodepopup_ajax.handler.responseXML;
        var group = rep.getElementsByTagName("item")[0];
        var itemId = group.getElementsByTagName('id')[0].firstChild.nodeValue;
        var html = group.getElementsByTagName('html')[0].firstChild.nodeValue;
        jol_bbcodepopup_cache[itemId] = html;
        var obj = fetch_object('overDiv');
        if (obj)
        {
            obj.innerHTML = html;
        }
    }
}
function jol_masquer_habillage(x) {
    var expires = new Date();
    expires.setTime(expires.getTime() + (1000 * 20 * 3600));
    set_cookie("forums_habi", x, expires);
    location.reload();
}
function jol_masquer(x) {
    var alertMsg = (x) ? "Voulez-vous masquer tous les forums sans nouveau message ?\n(cela allègera et accélerera la page d'accueil des forums)" : "Voulez-vous ré-afficher les forums inactifs ?";
    var alert = window.confirm(alertMsg);
    if (!alert) return false;
    expires = new Date();
    expires.setTime(expires.getTime() + (1000 * 86400 * 365));
    set_cookie("cacherInactifs", x, expires);
    location.reload();
}
function jol_ouvrir_tout() {
    var alert = window.confirm("Souhaitez-vous déplier toutes les catégories de forums ?");
    if (!alert) return false;
    expires = new Date();
    expires.setTime(expires.getTime() + (1000 * 86400 * 365));
    set_cookie("vbulletin_collapse", "forumbit_0", expires);
    location.reload();
}
function jol_fermer_tout() {
    var alert = window.confirm("Souhaitez-vous fermer toutes les catégories de forum ?");
    if (!alert) return false;
    var els = document.getElementsByTagName("tbody");
    var ids = new Array;
    var reg = new RegExp("collapseobj_", "");
    for(i=0;i<els.length;i++) {
        el = els[i];
        if (el.hasAttribute("id") && el.id.match(/^collapseobj_forumbit_/)) {
            ids.push(el.id.replace(reg, ""));
        }
    }
    var val = ids.join("\n");
    expires = new Date();
    expires.setTime(expires.getTime() + (1000 * 86400 * 365));
    set_cookie("vbulletin_collapse", val, expires);
    location.reload();
}
function jol_delete_forum(x) {
    if (document.getElementById('a_forumbit_' + x)) {
        var e = document.getElementById('a_forumbit_' + x);
        var nom = e.firstChild.nodeValue;
    } else {
        return false;
    }
    var alert = window.confirm("Attention, vous êtes sur le point de totalement supprimer de la page d'accueil le forum \"" + nom + "\".\nEtes-vous certain de vouloir supprimer ce forum ?\n\n(Si vous souhaitez le faire réapparaitre par la suite, vous devrez cliquer sur les liens \"Faire réapparaître les forums supprimés\" ou \"Réinitialiser l'accueil des forums\")");
    if (!alert) return false;
    if (document.getElementById('table_forumbit_' + x)) {
        var e = document.getElementById('table_forumbit_' + x);
        e.style.display = 'none';
    }
    if (document.getElementById('ombre_forumbit_' + x)) {
        var e = document.getElementById('ombre_forumbit_' + x);
        e.style.display = 'none';
    }
    
    var tmp = new Array();
    var c = fetch_cookie('deleted_forums');
    if (c != null) {
        c = c.split(',');
        for (var i in c) {
            tmp[tmp.length] = c[i];
        }
    }
    tmp[tmp.length] = x;
    expires = new Date();
    expires.setTime(expires.getTime() + (1000 * 86400 * 365));
    set_cookie('deleted_forums', tmp.join(','), expires);
    return false;
}
function jol_undelete_forums() {
    var alert = window.confirm("Confirmez-vous vouloir faire ré-apparaître tous les forums que vous avez supprimé de la page d'accueil ?");
    if (!alert) return false;
    expires = new Date();
    expires.setTime(expires.getTime() + (1000 * 86400 * 365));
    set_cookie('deleted_forums', '-1', expires);
    location.reload();
    return false;
}
function jol_reset_customization() {
    var alert = window.confirm("Confirmez-vous vouloir réinitialiser l'apparence des forums ?");
    if (!alert) return false;
    expires = new Date();
    expires.setTime(expires.getTime() + (1000 * 86400 * 365));
    set_cookie('deleted_forums', '-1', expires);
    set_cookie('vbulletin_collapse', '', expires);
    set_cookie('cacherInactifs', '0', expires);
    set_cookie('list-ul_forumhome', '-1', expires);
    location.reload();
    return false;
}
function supprimerAnnonce(annonceId)
{
    if (!annonceId) return false;

    var annonce = fetch_object('jolAnnonce');
    var cookie = fetch_cookie('jolAnnonce');
    var tmp = new Array();

    if (annonce != null) {
        annonce.style.display = 'none';

        if (cookie != null) {
            cookie = cookie.split(',');
            for (var i in cookie)
            {
                if (cookie[i] != annonceId && cookie[i] != '')
                {
                    tmp[tmp.length] = cookie[i];
                }
            }
        }
        tmp[tmp.length] = annonceId;

        tmp.reverse();
        tmp = tmp.slice(0, 10);
        tmp.reverse();

        expires = new Date();
        expires.setTime(expires.getTime() + (1000 * 86400 * 365));
        set_cookie('jolAnnonce', tmp.join(','), expires);
    }
    return false;
}


/**
 * StyleSwitcher
 */
var jolLoadCss = function(file) {
    var link = document.createElement('link');
    link.href = file;
    link.rel = 'stylesheet';
    link.type = 'text/css';
    link.title = 'Theme';
    document.getElementsByTagName('head')[0].appendChild(link);
};
function jolSetTheme(theme)
{
    var i, a, main;
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
        if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
            if (a.getAttribute("title") == 'Theme') {
                a.parentNode.removeChild(a);
            }
        }
    }

    if (theme) {
        jolLoadCss('http://jolstatic.fr/forums/jol3/css/' + theme + '.css');
        createCookie("style", theme, 365);
    } else {
        createCookie("style", '', -365);
    }
    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 expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
  return null;
}
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) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

/**
 * Ticker
 */
/***********************************************
* Pausing up-down scroller- Â© Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden;"><div class="innerDiv" style="position: absolute; width: 100%;" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}
// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------
pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}
// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------
pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}
// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------
pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}
pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}
// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------
pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}
pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}


