/*
 * Anthony DON - 27/11/2007 - version modifiée par Kevin 24.01.2008
 * Taken from : http://wiki.script.aculo.us/scriptaculous/show/Tabs
 */

 
/*-----------------------------------------------------------
    Toggles element's display value
    Input: any number of element id's
    Output: none 
    ---------------------------------------------------------*/
function toggleDisp() {
    for (var i=0;i<arguments.length;i++){
        var d = $(arguments[i]);
        if (d.style.display == 'none')
            d.style.display = 'block';

        else
            d.style.display = 'none';
            
    }
}
/*-----------------------------------------------------------
    Toggles tabs - Closes any open tabs, and then opens current tab
    Input:     		1.The number of the current tab
                    2.The number of tabs
                    3.(optional)The number of the tab to leave open
                    4.(optional)Pass in true or false whether or not to animate the open/close of the tabs
    Output: none 
    ---------------------------------------------------------*/
function toggleTab(num,numelems,opennum,animate) {
    if ($('tabContent'+num).style.display == 'none'){
        for (var i=1;i<=numelems;i++){
            if ((opennum == null) || (opennum != i)){
                var temph = 'tabHeader'+i;
                var h = $(temph);
                if (!h){
                    var h = $('tabHeaderActive');
                    h.id = temph;
                    h.removeClassName('current_tab');	/*Ajout KV*/
            		h.addClassName('inactive_tab');
            		h.descendants().each(function(e){
            			if(e.match('span'))
            			{	e.addClassName('item_bleu'); }
            		});
            		if($('corner_tab'+i))
            		{	$('corner_tab'+i).src = url_img_path+'ongletbout_off.gif';	}
                }
                var tempc = 'tabContent'+i;
                var c = $(tempc);
                if(c.style.display != 'none'){
                    if (animate || typeof animate == 'undefined')
                        Effect.toggle(tempc,'blind',{duration:0.5, queue:{scope:'menus', limit: 3}});
                    else
                        toggleDisp(tempc);
                }
            }
        }
        var h = $('tabHeader'+num);
        if (h) {
            h.id = 'tabHeaderActive';
			h.removeClassName('inactive_tab');
            h.addClassName('current_tab');
            h.descendants().each(function(e){
            			if(e.match('span'))
            			{	e.removeClassName('item_bleu'); }
            });
            if($('corner_tab'+num))
            {	$('corner_tab'+num).src = url_img_path+'ongletbout_on.gif'; }
        }
            
        h.blur();
        var c = $('tabContent'+num);
        if (animate || typeof animate == 'undefined'){
            Effect.toggle('tabContent'+num,'blind',{duration:0.5, queue:{scope:'menus', position:'end', limit: 3}});
        }else{
            toggleDisp('tabContent'+num);
        }
    }
    
    //reconstruit le rapport d'analyse
    if(num == '4' && $('defined_preferences') ) /* condition à la Kevin qui ne fonctionne qu'avec les diagnostics */
    {	refresh_rapport_analyse();		} 
}