/* Passage de page, liste enseignes */
function init_pages(nb_annonces, idpage, refresh){

    if(refresh == "Y"){
        $("#Pagination").pagination(nb_annonces, {
            items_per_page: 12,
            num_display_entries: 4,
            current_page: idpage,
            num_edge_entries: 1,
            callback: pageselectCallback
        });
    }
    else{
        $("#Pagination").pagination(nb_annonces, {
            items_per_page: 12,
            num_display_entries: 4,
            current_page: 1,
            num_edge_entries: 0
        });
    }

}
function pageselectCallback(page_id){

    $("#contentLoading").ajaxStart(function(){
        $(this).empty().append("<table cellspacing='0'><tr><td style='padding-right: 6px;'><img src='http://www.franchise-magazine.com/include/tools/jquery/loader.gif' alt='' /></td><td>Chargement en cours ...</td></tr></table>");
    }).ajaxStop(function(){
        $(this).empty().append($("#total_annonces").text()+" franchises correspondent à votre recherche");
    });

    $("#liste_annonces").load("http://www.franchise-magazine.com/franchise/liste-"+((page_id)+1)+".html");

    return false;
}
/*****************************/



$(function(){


    /*$('#cocheTout').live('click', function(){
        var cases = $("#search_idactivite").find(':checkbox');
        if(this.checked){
            cases.attr('checked', true);
            $('#cocheText').html('Tout decocher');
        }else{
            cases.attr('checked', false);
            $('#cocheText').html('Cocher tout');
        }
    });*/

    // FRANCE
    $(".search_idactivites, .search_iddepartements").live('click', function(){
        $("#recherche").submit();
    });

    $("#search_idsecteur, #search_idregion, #search_apport, #search_pays").change(function(){
        $("#recherche").submit();
    });

    $("#tri_champs, #tri_ordre").change(function(){
        $("#tri_annonces").submit();
    });


    // VALIDATION MOTEUR DE RECHERCHE
    $("#recherche, #tri_annonces").submit(function(){

        /*$("#contentLoading").ajaxStart(function(){
            $(this).empty().append("<table cellspacing='0'><tr><td style='padding-right: 6px;'><img src='http://www.franchise-magazine.com/include/tools/jquery/loader.gif' alt='' /></td><td>Chargement en cours ...</td></tr></table>");
        }).ajaxStop(function(){
            $(this).empty().append($("#total_annonces").text() + " franchises correspondent à votre recherche");
        });*/

        s = $(this).serialize();

        $.ajax({
            type: "POST",
            data: s,
            url: $(this).attr("action"),
            success: function(retour){
                $("#liste_annonces").empty().append(retour);
            }
        });

        return false;
    });



    /* AFFICHE CONNEXION ESPACE CANDIDAT */
    $("#logon").live('click', function(){
        $("#logbox").slideToggle();
        return false;
    });
    /*********************/


    /* DECONNEXION ESPACE CANDIDAT */
    $("#logoff").live('click', function(){
        $("#espace_cdt").empty().load('http://www.franchise-magazine.com/enseigne/espace_cdt_deco.php?action=deco_cdt');
        return false;
    });
    /*********************/


    /* AFFICHER FORMULAIRE MODIF PROFIL */
    $("#modifier_profil, #ferme_alert_profil").live('click', function(){
        $("#alert_profil").fadeToggle();
        return false;
    });
    /*********************/


    /* AFFICHER SUIVI DES DEMANDES */
    $("#suivre_demandes").live('click', function(){
        $("#liste_demandes").slideToggle();
        return false;
    });
    /*********************/


    /* DEMANDE DE DOC et FORM CONNEXION RAPIDE + CREATION DE COMPTE */
    /*$("#demande_doc").live('click', function(){
        $("#alert_demande").empty().load('http://www.franchise-magazine.com/enseigne/alert_demande.php').fadeToggle();
        return false;
    });*/
    $("#ferme_popup_demande, #ferme_popup_demande_f").live('click', function(){
        $("#alert_demande").fadeToggle();
        return false;
    });
    /*********************/


    /* AFFICHER RECUP MOT DE PASSE */
    $("#pass_perdu, #ferme_alert_pass").live('click', function(){
        $("#alert_pass").fadeToggle();
        return false;
    });
    /*********************/


    /* Affiche une enseigne avec son logo et son nom en dessous */
    $("div[id^='logo_enseigne_']").hover(function(){
        $("#"+(this.id)+" p[id^='nom_enseigne_']").slideToggle('fast');
    });
    /*********************/



    /* FORMULAIRE INSCRIPTION ENSEIGNE */
    $("#affich_form_inscription, #close").live('click', function(){
        $("#form_contact").fadeToggle();
        return false;
    });
    /*********************/


});
