/*****************************MESSAGE ATTENTE********************************/

function MessageAttente() {

    $get('lbl_100').innerHTML = "<div id=DIV_LigneArticleCommentaire></div><div id='DIV2_LigneArticleCommentaire' style='TEXT-ALIGN:CENTER; overflow:hidden'><center><img border='0' src='Image/WEB/loading.gif' class='ImgLoading100' /><br><br>Chargement en cours<br>Merci de patienter.</center></div>";
    showTextLightbox(150, 150, true);

}

/* checked Adresse compte
--------------------------------*/
function CheckAdresse(Adresse1, Adresse2, Adresse3) {
    var mValid = false;
    try {
        if ($('#' + Adresse1).val() != '') { mValid = true; }
        if ($('#' + Adresse2).val() != '') { mValid = true; }
        if ($('#' + Adresse3).val() != '') { mValid = true; }
        return mValid;
    }
    catch (ex) { return false; }
}

/* repositionner titre page
--------------------------------*/
$(document).ready(function () {
    $('#bloc_titre_page').append($('#TitreHead'));
});

/* Fonction de debugage InfoDev
--------------------------------*/
function InfoDev(message, cumul) { if (!$('#InfoDev').length) { $('BODY').append('<div id="InfoDev" style="position: absolute; top:0; left:0; font-size:15px;"></div>'); } cumul ? $('#InfoDev').append("<br>" + message) : $('#InfoDev').html(message); }


/* lihoverFix
--------------------------------*/
$(document).ready(function () {
    $('.lignes li, .vignettes li, #bloc_meilleursVentes li').hover(function () { $(this).addClass("hover"); }, function () { $(this).removeClass("hover"); });
});

/* mini panier
--------------------------------*/
$(document).ready(function () {
    $('.mini_panier li').qtip({
        content: $("#mini_panier_detail", this).html(),
        style: { width: { max: 420}, border: { width: 5, radius: 3, color: '#663300' }},
        position: { corner: { target: 'bottomRight', tooltip: 'topRight' }, adjust: { x: 0, y: 0} },
        hide: { fixed: true }
    });
    $('.mini_panier').hover(function () { //quand on arrive sur la zone on update le panier au cas ou il a ete rempli
        $('.mini_panier li').qtip("api").updateContent($("#mini_panier_detail", this).html());
        if ($("#mini_panier_detail").html().length > 25) { $('.mini_panier li').qtip("api").updateWidth(410); }
    });
});

/* bullesCarousel : le carousel + les bulles
--------------------------------*/
(function ($) {
    $.fn.bullesCarousel = function (options) {

        var defaults = {
            mini: 3, // nb mini d'elements dans le caroussel
            display: 5
        };

        var options = $.extend(defaults, options);
        if ($('.vignettes li', this).length > (options.mini - 1)) {
            /*caroussel*/
            $(this).tinycarousel({ display: options.display });

            /*bulles*/
            $('.vignettes li', this).addClass('vignetteLeft');
            $('.vignettes li:nth-child(5n), .vignettes li:nth-child(5n-1)', this).removeClass('vignetteLeft').addClass('vignetteRight');
            $('.vignettes li.vignetteLeft', this).each(function () {
                $(this).qtip({
                    content: $(".bulle", this).html(),
                    style: { tip: true, border: { width: 5, radius: 3, color: '#663300' }, name: 'light' }, // Give it a crea mstyle to make it stand out
                    position: { corner: { tooltip: 'leftMiddle', target: 'rightMiddle'} },
                    hide: { fixed: true }
                });
            });
            $('li.vignetteRight', this).each(function () {
                $(this).qtip({
                    content: $(".bulle", this).html(),
                    style: { tip: true, border: { width: 5, radius: 3, color: '#663300' }, name: 'light' }, // Give it a crea mstyle to make it stand out
                    position: { corner: { tooltip: 'rightMiddle', target: 'leftMiddle'} },
                    hide: { fixed: true }
                });
            });
        }
        else {
            $(this).hide();
        }
    };
})(jQuery);


/* Par contexte
--------------------------------*/

$(document).ready(function () {
    var contexte = $("#H_MEM_CONTEXTE").val();
    switch (contexte) {

        case "Accueil": /*############################ CONTEXTE ACCUEIL ###################################*/
            /******Caroussel******/

            $("#slide_AccueilFocus").bullesCarousel({ mini: 3 }); //mini: 3 articles minimumus

            break;
        case "View": /*############################### CONTEXTE VIEW ######################################*/

            /******Infobule sur bouton panier inactif ou choix taille ******/
            $('#bloc_DA_acheter .ajout_panier_disable, #bloc_list_article .ajout_panier_disable').each(function () {
                $(this).qtip({
                    content: 'Cet article est actuellement indisponible',
                    style: { tip: true, border: { radius: 5 }, name: 'dark' }, // Give it a crea mstyle to make it stand out
                    position: { corner: { tooltip: 'bottomMiddle', target: 'topMiddle'} }
                });
            });
            if ($('#bloc_DA_vignettes li').length < 2) { $('#bloc_DA_vignettes').remove(); }
            if ($('#bloc_noeud_description span').length) { if ($('#bloc_noeud_description span').html().length < 3) { $('#bloc_noeud_description').remove(); } }
            /****** Boite à onglets ******/

            $("#bloc_DA_onglet_content .bloc div[id^='sub_'] > div[id^='lbl_'] > div[id^='lbl_']").each(function (i) { if ($(this).html().length < 3) { $(this).parent().parent().remove(); } }); //enlever contenus vides
            $("#bloc_DA_onglet_content .bloc").each(function (i) { if ($(this).html().length < 5) { $("#bloc_DA_onglet_menu li:eq(" + i + ")").addClass("delete"); $(this).remove(); } });
            $("#bloc_DA_onglet_menu li.delete").each(function () { $(this).remove(); });
            $("#bloc_DA_onglet_menu").facileTabs({ targetElements: ".bloc" });    //lancer boite à onglets

            /******Caroussel******/

            $('#slide_listes .titre').html('S&eacute;lection ' + $('#bloc_noeud_titre h2').html());
            $("#slide_listes").bullesCarousel({ mini: 3 });
            $("#slide_fils").bullesCarousel({ mini: 1 });
            $("#slide_freres").bullesCarousel({ mini: 1 });

            $("#bloc_DA_vignettes").tinycarousel({ display: 3, viewport: '#detailArticl_Galr', overview: '#detailArticl_Galr ul' });
            $('#bloc_DA_photos a').hover(function () { $('#bloc_DA_photos .zoom').show(); }, function () { $('#bloc_DA_photos .zoom').hide(); });


            /****** images en grand sur hover ******/
            $('img[tooltip]').each(function () {
                $(this).qtip({
                    content: '<img src="I-Moyenne-' + $(this).attr('tooltip') + '-.net.jpg" />', // Use the tooltip attribute of the element for the content
                    position: { corner: { tooltip: 'leftMiddle', target: 'rightMiddle'} },
                    style: { tip: true, name: 'light', width: 250 }
                });
            });
            /******* enlever txt RESUME si vide*******/
            $('.lignes .text_court').each(function () {
                if ($('.txt', this).html().length < 3) { $(this).hide(); }
            });

            break;
        case "PageStatique": /*####################### CONTEXTE PAGES SATTIQUES ###########################*/
            $("#slide_panier").bullesCarousel({ mini: 3 }); //mini: 3 articles minimumus
			
			/****** ps faq ******/
            $('.question').click(function () {
                //var $tab1 = $(this).parent().parent().parent().parent('#suivi_commande_liste');
                $(this).next('.reponse').slideToggle('slow');
                return false;
            });

            break
        case "Identification": /*##################### CONTEXTE IDENTIFICATION ############################*/



            /****** suivi commande ******/
            var $numSuiviCommandes = 0;
            $('#suivi-commandes tr').each(function () {
                if ($(this).hasClass('ligne-exp')) $numSuiviCommandes = 0;
                else {
                    $numSuiviCommandes += 1;
                    if ($numSuiviCommandes / 2 != Math.round($numSuiviCommandes / 2)) $(this).addClass('impair')
                }
            });

            $('#suivi-commandes .sc_detail_tab:first').slideToggle('slow').prev('.commande').toggleClass('open');
            $('#suivi-commandes .commande').click(function () {
                if ($(this).next('.sc_detail_tab').is(':hidden')) $('#suivi-commandes .sc_detail_tab:visible').slideToggle('slow').prev().removeClass('open');
                $(this).toggleClass('open').next('.sc_detail_tab').slideToggle('slow');
                return false;
            });

            /****** login (nouveau et ancien compte) ******/
            if ($('#r_compte_old').attr('checked') == true) {
                $('#div_compte_new').hide(); $('#a_compte_old').addClass('checked');
            }
            else {
                $('#div_compte_old').hide(); $('#a_compte_new').addClass('checked');
            }

            $('#a_compte_old').click(function () {
                $('#r_compte_old').attr('checked', 'checked');
                $('#r_compte_new').removeAttr('checked');
                $('#a_compte_old').addClass('checked');
                $('#a_compte_new').removeClass('checked');
                $('#div_compte_new').fadeOut('slow');
                $('#div_compte_old').fadeIn('slow');
            });

            $('#a_compte_new').click(function () {
                $('#r_compte_old').removeAttr('checked');
                $('#r_compte_new').attr('checked', 'checked');
                $('#a_compte_old').removeClass('checked');
                $('#a_compte_new').addClass('checked');
                $('#div_compte_old').fadeOut('slow');
                $('#div_compte_new').fadeIn('slow');
            });


            break
        case "AfficheResultatRechercheAvancee": /*#### CONTEXTE RECHERCHE #################################*/

            /******Caroussel******/
            $("#slide_panier").bullesCarousel({ mini: 3 }); //mini: 3 articles minimumus

            /******* enlever txt RESUME si vide*******/
            $('.lignes .text_court').each(function () {
                if ($('.txt', this).html().length < 3) { $(this).hide(); }
            });

            $(' #bloc_list_article .ajout_panier_disable').each(function () {
                $(this).qtip({
                    content: 'Cet article est actuellement indisponible',
                    style: { tip: true, border: { radius: 5 }, name: 'dark' }, // Give it a crea mstyle to make it stand out
                    position: { corner: { tooltip: 'bottomMiddle', target: 'topMiddle'} }
                });
            });

            break
        case "ValidationPanier": /*################### CONTEXTE PANIER ####################################*/

            /******Point Relais ******/
            $(document).ready(function () {
                $('#gk_listerelais .horaire').each(function (i) {
                    $(this).qtip({
                        content: "<div class='BulleKiala'>" + $('#gk_listerelais p').eq(i).html() + "</div>",
                        show: 'mouseover',
                        hide: 'mouseout',
                        position: { corner: { tooltip: 'bottomMiddle', target: 'topMiddle'} },
                        style: { border: { width: 2, radius: 5, color: '#BAB3B3' }, tip: true, width: '400' }
                    });
                    $(this).click(function () { return false });
                });
            });

            /******Caroussel******/
            $("#slide_panier").bullesCarousel({ mini: 3 }); //mini: 3 articles minimumus


            break
        default: /*################################## AUTRES #############################################*/

    }
});



/**** Panier spécifique CDL ****/
function PanierItemQuantiteAjouter(elmt, valeur) {
    var MonInput = elmt.parentNode.parentNode.getElementsByTagName('input');
    var valeurInput = parseInt(MonInput[0].value);
    if ((valeurInput + valeur) < 0) { } else {
        MonInput[0].value = valeurInput + valeur;
    }
}

function AjaxPanierCDL(fct, params) { PageMethods.Ajax('fct=' + fct + '&params=' + params, OnSucceded_AjaxPanierCDL, OnFailed_AjaxPanierCDL); }
function OnSucceded_AjaxPanierCDL(result) { $('#panierCDL').html(result); }
function OnFailed_AjaxPanierCDL(error) { $('#panierCDL').append(error.get_message()); }

function AjaxNoteDossier() { AjaxPanierCDL('p_note_tous', ''); }
function AjaxNoteLigne(idElement) { AjaxPanierCDL('p_note', idElement); }
function AjaxChangeQuantitePanier() { var mQte = ''; $('.PanierItemQuantite input[type=text]').each(function () { mQte += $(this).attr("id") + ':' + $(this).val() + '|'; }); AjaxPanierCDL("p_qte", mQte); }
function AjaxSupprimeLigne(idElement) { AjaxPanierCDL('p_supprime', idElement); }

function EnregistreCommentaire() { $('#p_commentaire_msg').html(''); PageMethods.Ajax('fct=commentaire&commentaire=' + $('#p_commentaire').val(), OnSucceeded_AjaxEnregistreCommentaire, OnFailed_AjaxEnregistreCommentaire); }
function OnSucceeded_AjaxEnregistreCommentaire() { $('#p_commentaire_msg').html('Commentaire enregistr&eacute; !'); }
function OnFailed_AjaxEnregistreCommentaire() { $('#p_commentaire_msg').html('Commentaire non enregistr&eacute; !'); }



/**** Compte spécifique CDL ****/
function AjaxCompteCDL(fct, params) { PageMethods.Ajax('fct=' + fct + '&params=' + params, OnSucceeded_Notes, OnFailed_Notes); }
function OnSucceeded_Notes(result) { $('.fiche').html(result); }
function OnFailed_Notes(error) { $('.fiche').append(error.get_message()); }

function AjaxFacturesAvoirs() {
    $('.fiche').html('<center><img src="/Image/WEB/loading.gif" alt="veuillez patienter" /></center>');
    $('#WUC_Fiche1_MenuMonCompte ul li').each(function () { $(this).removeClass('selected'); });
    $('#WUC_Fiche1_MenuMonCompte ul li a').each(function () { $(this).removeClass('selected'); });
    $('#FacturesAvoirs').addClass('selected');
    $('#FacturesAvoirs a').addClass('selected');
    AjaxCompteCDL('c_factures_avoirs', '');
}
function AjaxNotesAttente() {
    $('.fiche').html('<center><img src="/Image/WEB/loading.gif" alt="veuillez patienter" /></center>');
    $('#WUC_Fiche1_MenuMonCompte ul li').each(function () { $(this).removeClass('selected'); });
    $('#WUC_Fiche1_MenuMonCompte ul li a').each(function () { $(this).removeClass('selected'); });
    $('#NotesAttente').addClass('selected');
    $('#NotesAttente a').addClass('selected');
    AjaxCompteCDL('c_notes_attente', '');
}
function AjaxNotesReservation() {
    $('.fiche').html('<center><img src="/Image/WEB/loading.gif" alt="veuillez patienter" /></center>');
    $('#WUC_Fiche1_MenuMonCompte ul li').each(function () { $(this).removeClass('selected'); });
    $('#WUC_Fiche1_MenuMonCompte ul li a').each(function () { $(this).removeClass('selected'); });
    $('#NotesReservation').addClass('selected');
    $('#NotesReservation a').addClass('selected');
    AjaxCompteCDL('c_notes_reservation', '');
}

function AjaxDemandeExpeditionBanc() { PageMethods.Ajax('fct=c_notes_demande_expedition', OnSucceded_AjaxDemandeExpeditionBanc, OnFailed_AjaxDemandeExpeditionBanc); }
function OnSucceded_AjaxDemandeExpeditionBanc(result) { alert(result); }
function OnFailed_AjaxDemandeExpeditionBanc(error) { alert(error.get_message()); }

