
function showFinalists(num) {
    if (document.getElementById('finalistes-'+num).style.visibility == 'hidden' || document.getElementById('finalistes-'+num).style.visibility == '') {
        document.getElementById('finalistes-'+num).style.visibility = 'visible';
        document.getElementById('finalistes-'+num).style.position = 'relative';
    } else {
        document.getElementById('finalistes-'+num).style.visibility = 'hidden';
        document.getElementById('finalistes-'+num).style.position = 'absolute';

        elm = getElementsByClass('infos');
        for(var i = 0; i < elm.length; i++) {
            elm[i].style.visibility = "hidden";
            elm[i].style.position = "absolute";
        }
    }
}

function showDetails(num1,num2) {
    if (document.getElementById('infos-'+num1+'-'+num2).style.visibility == 'hidden' || document.getElementById('infos-'+num1+'-'+num2).style.visibility == '') {
        document.getElementById('infos-'+num1+'-'+num2).style.visibility = 'visible';
        document.getElementById('infos-'+num1+'-'+num2).style.position = 'relative';
    } else {
        document.getElementById('infos-'+num1+'-'+num2).style.visibility = 'hidden';
        document.getElementById('infos-'+num1+'-'+num2).style.position = 'absolute';
    }
}

function menuDisplay(item) {
    if (document.getElementById('menu-'+item).style.visibility == 'hidden' || document.getElementById('menu-'+item).style.visibility == '') {
        document.getElementById('menu-'+item).style.visibility = 'visible';
        document.getElementById('menu-btn-'+item).style.backgroundPosition = '0 -76px';
    } else {
        document.getElementById('menu-'+item).style.visibility = 'hidden';
        document.getElementById('menu-btn-'+item).style.backgroundPosition = '0 0';
    }
}

function popupCalendar(iDay) {
    if (document.getElementById('popup-'+iDay).style.visibility == 'hidden' || document.getElementById('popup-'+iDay).style.visibility == '') {
        document.getElementById('date-'+iDay).className = 'active';
        document.getElementById('popup-'+iDay).style.visibility = 'visible';
    } else {
        document.getElementById('date-'+iDay).className = '';
        document.getElementById('popup-'+iDay).style.visibility = 'hidden';
    }
}

idLastPicture = 1;
function showPicture(idPicture,nbPictures) {
    document.getElementById('picture-'+idLastPicture).className = 'picture';
    document.getElementById('picture-'+idPicture).className = 'picture picture-active';

    if (document.getElementById('thumbnail-'+idLastPicture) != null) {
        document.getElementById('thumbnail-'+idLastPicture).className = '';
        document.getElementById('thumbnail-'+idPicture).className = 'active';
    }

    document.getElementById('number-'+idLastPicture).className = '';
    document.getElementById('number-'+idPicture).className = 'active';

    idPrevious = idPicture-1;
    if (idPicture == 1) {
        idPrevious = nbPictures;
    }

    idNext = idPicture+1;
    if (idPicture == nbPictures) {
        idNext = 1;
    }

    document.getElementById('previous').innerHTML = '<a href="javascript:showPicture('+idPrevious+','+nbPictures+');"><</a>';
    document.getElementById('next').innerHTML = '<a href="javascript:showPicture('+idNext+','+nbPictures+');">></a>';

    idLastPicture = idPicture;
}

function showCalendar(year,month) {
    try {
        chk = getNewXMLHTTP();
        chk.open("GET", "/scripts/ajax/calendar.php?y="+year+"&m="+month+"&hash="+Math.random(), true);
        chk.onreadystatechange = showCalendar_end;
        chk.send(null);
    } catch(e) {
        //alert("Une erreur s'est produite, veuillez réessayer de nouveau!");
    }
}

function showCalendar_end() {
    if (chk.readyState == 4) {
        if (chk.status == 200) {
            x = chk.responseXML.getElementsByTagName('response');
            code = decodeURIComponent(x[0].getAttribute('calendar'));

            reg = new RegExp('\\+','g');
            code = code.replace(reg,' ') ;

            document.getElementById('module-calendar-month').innerHTML = code;
            //alert(calendar);
        }
    }
}

function getNewXMLHTTP() {
    try {
        return new XMLHttpRequest();
    } catch(e) {
        try {
            var aObj = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                var aObj = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(e) {
                return false;
            }
        }
    }
    return aObj;
}

function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if(node == null) node = document;
    if(tag == null) tag = '*';

    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");

    for(i = 0, j = 0; i < elsLen; i++) {
        if (pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }

    return classElements;
}
