function CheckFormulaireRecherche( texte , formulaire){
     var recherche = formulaire.q;
     if( recherche.value != texte && recherche.value !='' ) {
         return true;
     }
     return false;
} 

function CheckFormulaireAbonnement( formulaire , msg){
     var choix = formulaire.ContentObjectID;
     var count = formulaire.ContentObjectID.length;
     for( i = 0 ; i<count ; i++) {
        if( choix[i].checked ) {
         return true;
        }
     }
     alert( msg );
     return false;
}

/* 
 * Permet de cacher les dépêches supplémentaires
 */
function affichageDepeches( limiteAffichage ) {
    /* On recupere la liste des depeches */    
    $(".bloc-depeche").each(function( index ) {
        if( index > limiteAffichage-1 ) {
            $(this).hide();
        }
    });
    if( $(".bloc-depeche").size() > limiteAffichage ) {
        $( ".navigation-depeches div").show();
        //$( ".navigation-depeches div").fadeOut('slow');
    }
}


/* 
 * Permet de défiler les dépêches 
 */
function scrollDepeches( event, direction, limite ) {
    var timing = 1400;
    if( event ) {
        event.preventDefault();
    }
    var depeche = $(".bloc-depeche");
    /*
     *     On récupère le premier/denier element visible
     *  On récupère le prochain élément visible
     */
    if( direction == 'bas' ) {
        var elmt = depeche.filter(":visible:first");    // le premier élément visible
        var incoming = depeche.filter(":visible:last").next('.bloc-depeche'); // le prochain élément caché
    } else    if( direction == 'scroll' ) {
        var elmt = depeche.filter(":visible:first");    // le premier élément visible
        var incoming = depeche.filter(":visible:last").next('.bloc-depeche'); // le prochain élément caché
    } else  {
        var elmt = depeche.filter(":visible:last");        // le dernier élément visible
        var incoming = depeche.filter(":visible:first").prev('.bloc-depeche');
    }
    /*
     * Si toutes les depeches ont été parcouru 
     * donc on récupère soit la première dépèche, soit la dernière que l on insère au bon endroit.
     */
    if(!incoming.size()) {
        //elmt.hide();
        elmt.animate({
            opacity: 'toggle',
            height: 'toggle'
          }, timing ,'linear' , function() {
            // Animation complete.
          });
        if( direction == 'scroll') {
            incoming = depeche.filter(":first");
            incoming.insertAfter( depeche.filter(':visible:last')).animate({
                opacity: 'toggle',
                height: 'toggle'
              }, timing ,'linear' , function() {
                // Animation complete.
              });
        } else if( direction == 'bas') {
                incoming = depeche.filter(":first");
                incoming.insertAfter( depeche.filter(':visible:last')).animate({
                    opacity: 'toggle',
                    height: 'toggle'
                }, timing ,'linear' , function() {
                    // Animation complete.
                });
        } else {
            // haut
            incoming = depeche.filter(":last");
            incoming.insertBefore( depeche.filter(':visible:first')).animate({
                opacity: 'toggle',
                height: 'toggle'
              }, timing ,'linear' , function() {
                // Animation complete.
              });
        }
    } else {
        elmt.animate({
            opacity: 'toggle',
            height: 'toggle'
          }, timing ,'linear' , function() {
            // Animation complete.
          });
        incoming.animate({
            opacity: 'toggle',
            height: 'toggle'
          },  timing ,'linear' , function() {
            // Animation complete.
          });
            
        //elmt.hide();
        //incoming.show();
    }
}

/* 
 * Scroll auto des depeches 
 */

function autoRotateDepeches( direction, arret ) {
    $("#hautDepeche").click( function() {
        arret = 1;
    });
    $("#basDepeche").click( function() { 
        arret = 1;
    });
    if( arret == 0 ) {
        scrollDepeches( null, 'scroll' );
        setTimeout( 'autoRotateDepeches( "scroll" , arret)', '4000');
    }
}


/* 
 * Affiche uniquement le nombre d images souhaités 
 */
function affichesGalerie( limiteAffichage ) {
    var galerie = $(".liste_image");
    
    if( galerie.length > limiteAffichage ) {
        /*$('#hautGalerie').show();*/
        $('#basGalerie').show();
        
        /* On recupere la liste des depeches */    
        $(".liste_image").each(function( index ) {
            if( index > limiteAffichage-1 ) {
                $(this).hide();
            }
        });
    }
}

function scrollGalerie(event, direction, limite ) {
    if( event ) {
        event.preventDefault();
    }
    var galerie = $(".liste_image");
    var first = galerie.filter(":first");
    var last = galerie.filter(":last");
    
    if( direction == 'bas' ) {
        var elmt = galerie.filter(":visible:first");    // le premier élément visible
        var incoming = galerie.filter(":visible:last").next('.liste_image'); // le prochain élément caché
        
        if( elmt.next('.liste_image').index() != first.index() ) { $('#hautGalerie').show(); } 
        if( incoming.index() == last.index() ) { $('#basGalerie').hide(); }
        
    } else {
        var elmt = galerie.filter(":visible:last");        // le dernier élément visible
        var incoming = galerie.filter(":visible:first").prev('.liste_image');
        
        if( incoming.index() == first.index() ) { $('#hautGalerie').hide(); }
        if( elmt.next('.liste_image').index() != last.index() ) { $('#basGalerie').show(); }
    }
    
    if(incoming.size()!=0) {
        elmt.hide();
        incoming.show();
    }
    
    /*
     * on vérifie le nombre d élément affiché
     * et on cache ceux en trop ci necessaire.
     */
    var nbrAffiche = galerie.filter(":visible").length;
    var diff = nbrAffiche-limite-1;
    if( nbrAffiche-1 > limite ) {
        if( direction == 'bas' ) {
            for( i=0; i<=diff; i++) {
                galerie.filter(":visible:first").hide();
            }
        } else {
            for( i=0; i<diff; i++) {
                galerie.filter(":visible:last").hide();
            }
        }
    }
}
