/*-----------------------------------------------------------
    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;
                }
                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.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);
        }
    }
}

function getFormMire(mire)
{
  new Ajax.Updater('formulaireMire', 'pages/modifier_mire.php?mire='+mire);
}

function getFormAdmin(admin, module)
{
  new Ajax.Updater('formulaireAdmin', 'pages/modifier_admin.php?id='+admin+'&module='+module);
}

function exporter(type, file)
{
  document.getElementById('Files'+type).innerHTML = '<table border="0" cellpadding="0" cellspacing="0" class="tableList" style="width:600px;"><tr><th align="center">Fichier</th><th align="center">Taille</th><th align="center">Date de création</th><th align="center">dernier téléchargement</th></tr><tr height="20"><td colspan="4" align="center"><img src="images/loading.gif" alt="génération des fichiers en cours..." /><br />génération des fichiers en cours...<br />Cette opération peut prendre plusieurs minutes suivant le nombre d\'inscrits.</td></tr></table>';

  new Ajax.Updater('Files'+type, 'pages/export_ajax.php?type='+type+'&file='+file);
}

function archiver(type, file)
{
  document.getElementById('Files'+type).innerHTML = '<table border="0" cellpadding="0" cellspacing="0" class="tableList" style="width:600px;"><tr><th align="center">Fichier</th><th align="center">Taille</th><th align="center">Date de création</th><th align="center">dernier téléchargement</th></tr><tr height="20"><td colspan="4" align="center"><img src="images/loading.gif" alt="génération des fichiers en cours..." /><br />génération de l\'archive en cours...<br />Cette opération peut prendre plusieurs minutes suivant le nombre d\'inscrits.</td></tr></table>';

  new Ajax.Updater('Files'+type, 'pages/export_zip.php?type='+type+'&file='+file);
}


var myPopup;
var ww = 100;
var hh = 100;
var step = 15;
function popup(url, titre, width, height, autosize)
{
    option = 'location=no, directories=no, menubar=yes, status=no, scrollbars=yes, resizable=yes';
    
    if (!width) width = ww;
    if (!height) height = hh;
    if (!autosize) autosize = false;
    
    var top = ((screen.height - height) / 2);
    var left = ((screen.width - width) / 2);
    option += ', width='+width+', height='+height+', top='+top+', left='+left;
    
    myPopup = window.open(url, titre, option);
    if (autosize)
	{
	    if (document.all)
		setTimeout("initResizeIE()", 100);
	    else
		myPopup.onload = function(){resize();}
	}
    return (false);
}

function initResizeIE()
{
    myPopup.onload = resize();
}

function resize()
{
    if (myPopup.document.all)
	{
	    x = myPopup.document.body.scrollWidth;
	    ww = (x < (screen.width - step) && x > ww) ? x : ww;
	    x = myPopup.document.body.scrollHeight;
	    hh = (x < (screen.height - step) && x > hh) ? x : hh;
	    //redim();
	}
    else
	{
	    ww = (myPopup.document.width > ww) ? (myPopup.document.width) : ww;
	    hh = (myPopup.document.height > hh) ? (myPopup.document.height) : hh;
	}
    ww = (ww + 25);
    hh = (hh + 95);
    setTimeout("myPopup.window.resizeTo(ww, hh);",100);
    var top = ((screen.height - hh) / 2);
    var left = ((screen.width - ww) / 2);
    myPopup.window.moveTo(left, top);
    
}
