/*****************************DESINSCRIPTION NEWSLETTER********************************/


/*****************************VALIDATION FORMULAIRES PAGES STATIQUES********************************/
$(document).ready(function() {
			$("#form1").validationEngine()
		});

/*****************************AFFINAGE DETAIL********************************/

function Affin_ListeDeroulAction(id) {
    document.location.href = $('#' + id).val();
}

/*****************************MESSAGE ATTENTE********************************/

function MessageAttente() {
    $.colorbox({
        html: '<div class="MessageAttente">' + $("#myloading").html() + '<br>Chargement en cours. Merci de patienter</div>',
        initialWidth: 50,
        initialHeight: 50,
        width: 200,
        overlayClose: false,
        escKey: false,
        onLoad: function () {
            $('#cboxClose').hide(); 
        }
    });
}


/******************************* COLONNES EGALES */
/*
$(document).ready(function () {
$('#content .col2-1, #content .col2-2').equalHeightColumns();
});
*/

function hauteurEgale(group) {
    tallest = 0;
    group.each(function () {
        thisHeight = $(this).height();
        if (thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}


Usage:
$(document).ready(function () {
    hauteurEgale($(".column"));
	
});




/* 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'));
});

/* caroussel popup article
--------------------------------*/
//$("#slide_popup").tinycarousel({ display: 5 }); // VOIR SI CHARGE APRES AJAX


/* 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 () {
$('#bloc_list_article li, .bloc_DA_sell ul li, #menu_Catalogue1 li, #bloc_list_noeuds_fils li').hover(function() { $(this).addClass("sfhover"); }, function() { $(this).removeClass("sfhover"); });
});

/* colorbox 
--------------------------------*/

function showTextLightbox(largeurBox, hauteurBox, pasDeCroixFermer) {
    $.colorbox({
        html: $('#DIV2_LigneArticleCommentaire').html(),
        onCleanup: function() { $('#DIV2_LigneArticleCommentaire').remove(); }
    });
}
function hideLightbox() { $.colorbox.close(); }

/* mini panier
--------------------------------*/
$(document).ready(function() {
$('#mini_panier').qtip({
        content: $("#mini_panier_detail", this).html(),
        style: { width: { max: 420} },
        position: { corner: { target: 'bottomRight', tooltip: 'topRight' }, adjust: { x:10, y: -5} },
        hide: { fixed: true }
    });
    $('#bloc_panier').hover(function() { //quand on arrive sur la zone on update le panier au cas ou il a ete rempli
        $('#mini_panier').qtip("api").updateContent($("#mini_panier_detail", this).html());
        if ($("#mini_panier_detail").html().length > 25) { $('#lbl_005').qtip("api").updateWidth(410); }
    });
});


/* Fonction ShowBlocIdentification
--------------------------------*/
function ShowBlocIdentification(montrer) {
    var cacher = '';
    (montrer == 'old') ? cacher = 'new' : cacher = 'old';  
    $('#r_compte_' + montrer).attr('checked', 'checked');
    $('#r_compte_' + cacher).removeAttr('checked');
    $('#a_compte_' + montrer).addClass('checked');
    $('#a_compte_' + cacher).removeClass('checked');
    $('#div_compte_' + cacher).fadeOut('slow');
    $('#div_compte_' + montrer).fadeIn('slow');
}

/* desincription newsletter
--------------------------------*/
$(document).ready(function () { $('.desinscription_newsletter a').colorbox({ iframe: true, innerWidth: 450, innerHeight: 250 }); });

/* Par contexte
--------------------------------*/

$(document).ready(function () {
    var contexte = $("#H_MEM_CONTEXTE").val();
    switch (contexte) {

        case "Accueil": /*############################ CONTEXTE ACCUEIL ###################################*/

            /****** boite a onglets ******/
            $("#bloc_accueil_onglet_menu").facileTabs({ targetElements: ".bloc" });

            /******Caroussel******/
            $('#AccueilSlide').tinycarousel({ pager: true, display: 1, interval: true });

            break;
        case "View": /*############################### CONTEXTE VIEW ######################################*/

            /******Infobule sur bouton panier inactif ou choix taille ******/
            $('.ajout_panier span[tooltip], .ajout_liste_cadeau a[tooltip], .ajout_panier_disable[tooltip]').each(function () {
                $(this).qtip({
                    content: $(this).attr('tooltip'), // Use the tooltip attribute of the element for the content
                    style: { tip: true, border: { radius: 5 }, name: 'dark' }, // Give it a crea mstyle to make it stand out
                    position: { corner: { tooltip: 'bottomMiddle', target: 'topMiddle'} }
                });
            });
			
			/******Slide du noeud******/
            $('#bloc_slide').tinycarousel({ pager: false, display: 1, interval: true });

            /****** Boite à onglets ******/

            $("#bloc_DA_onglet_content1").each(function (i) { if ($(this).html().length < 3) { $(this).parent().remove(); } }); //enlever contenus vides
            $("#bloc_DA_onglet_content2").each(function (i) { if ($(this).html().length < 32) { $(this).parent().remove(); } }); //enlever contenus vides
             

            /******Caroussel******/
            $("#slide_fils").tinycarousel({ display: 5 });
            $("#slide_freres").tinycarousel({ display: 5 });
            $("#slide_cousins").tinycarousel({ display: 5 });
            $("#bloc_DA_vignettes").tinycarousel({ display: 3, viewport: '#detailArticl_Galr', overview: '#detailArticl_Galr ul' });
			
			/***** Video ******/
			
            $('.Video').click(function () {

                $('body').append('<div id="video"></div>');
                var flashVideo = $(this).attr('rel');

                $.colorbox({
                    inline: true,
                    href: "#video",
                    initialWidth: 50,
                    innerWidth: 660,
                    innerHeight: 390,
                    onCleanup: function () { $('#video').remove(); }
                });

                jwplayer("video").setup({
                    autostart: true,
                    controlbar: "none",
                    file: "/File.aspx?FileName=" + flashVideo,
                    flashplayer: "/flash/player.swf", volume: 80, width: 660, height: 390
                });

                return false;
            });


            /****** zoom ICI et zoom XL ******/
            lancerGallery();

            break;
        case "PageStatique": /*####################### CONTEXTE PAGES SATTIQUES ###########################*/

        

                $("ul.notes-echelle").addClass("js");
                $("ul.notes-echelle li").addClass("note-off");

                $("ul.notes-echelle input").focus(function () {
		            $(this).parents("ul.notes-echelle").find("li").removeClass("note-focus");
		            $(this).parent("li").addClass("note-focus");
		            $(this).parent("li").nextAll("li").addClass("note-off");
		            $(this).parent("li").prevAll("li").removeClass("note-off");
		            $(this).parent("li").removeClass("note-off");
		        }).blur(function () {
		            $(this).parents("ul.notes-echelle").find("li").removeClass("note-focus");
		            if ($(this).parents("ul.notes-echelle").find("li input:checked").length == 0) {
		                $(this).parents("ul.notes-echelle").find("li").addClass("note-off");
		            }
		        }).click(function () {
		            $(this).parents("ul.notes-echelle").find("li").removeClass("note-checked");
		            $(this).parent("li").addClass("note-checked");
		            $('#FORM_NOTE').val($(this).val());
		        });

                $("ul.notes-echelle li").mouseover(function () {
                    $(this).nextAll("li").addClass("note-off");
                    $(this).prevAll("li").removeClass("note-off");
                    $(this).removeClass("note-off");
                });

                $("ul.notes-echelle").mouseout(function () {
                    $(this).children("li").addClass("note-off");
                    $(this).find("li input:checked").parent("li").trigger("mouseover");
                });

                $("ul.notes-echelle input:checked").parent("li").trigger("mouseover");
                $("ul.notes-echelle input:checked").trigger("click");
				
				/*
				$('.button1').click(function () {
                $(this).removeClass('button1').addClass('button2');
                return false;
				});
				*/

       

            break
        case "Identification": /*##################### CONTEXTE IDENTIFICATION ############################*/

            /****** suivi commande ******/
            $('.sc_detail').click(function () {
                var $tab1 = $(this).parent().parent().parent().parent('#suivi_commande_liste');
                $tab1.next('.sc_detail_tab').slideToggle('slow');
                return false;
            });
			
			/****** suivi devis ******/
            $('.sd_detail').click(function () {
                var $tab1 = $(this).parent().parent().parent().parent('#suivi_devis_liste');
                $tab1.next('.sd_detail_tab').slideToggle('slow');
                return false;
            });

            /****** sauvegarde panier ******/
            
            $('.sv_detail').click(function () {
                var $tab1 = $(this).parent().parent().parent().parent('#sauvegarde_panier_liste');
                $tab1.next('.sv_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 () { ShowBlocIdentification('old') });
            $('#a_compte_new').click(function () { ShowBlocIdentification('new') });

            /****** liste de souhaits ******/
            $('#bloc_list_souhaits .commentaire .txt').each(function () {
                if ($(this).html().length < 2) { $(this).html('<span class="AjouterCommentaire">Ajouter un commentaire....</span>'); }
            });
            $('#bloc_list_souhaits .enlever').each(function (i) {
                $(this).qtip({
                    content: "supprimer de la liste",
                    show: 'mouseover',
                    hide: 'mouseout',
                    position: { corner: { tooltip: 'bottomMiddle', target: 'topMiddle'} },
                    style: { border: { width: 2, radius: 5, color: '#333' }, tip: true, background: '#333', color: '#fff' }
                });
            });

            /******Infobule sur bouton panier inactif ou choix taille ******/
            $('.ajout_panier_disable[tooltip]').each(function () {
                $(this).qtip({
                    content: $(this).attr('tooltip'), // Use the tooltip attribute of the element for the content
                    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 "AfficheResultatRechercheAvancee": /*#### CONTEXTE RECHERCHE #################################*/

            /******Caroussel******/
            $("#slide_panier").tinycarousel({ display: 5 });


            break
        case "ValidationPanier": /*################### CONTEXTE PANIER ####################################*/

            /******Point Relais Horaires ******/
            $(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 });
                });
            });

            /******Liste point relais Kiala deplacement******/
            $(document).ready(function () {

                if ($('#KIALA')) {

                    $('#grille_kiala').insertAfter('#KIALA');
                }

                if ($('#SOCOLISSIMO')) {
                    $('#info_socolissimo').insertAfter('#SOCOLISSIMO');
                    $('#btn_socolissimo').insertAfter('#SOCOLISSIMO');
                }

            });

            /******Caroussel******/
            $("#slide_panier").tinycarousel({ display: 5 });


            break
        default: /*################################## AUTRES #############################################*/

    }
});


/* liste de souhaits
--------------------------------*/
function OnSucceeded_AjaxAjoutCommentaireWebLigne(result) {
    var Tab = result.split('~#~');
    var mParamRetour = Tab[0];
    var mResult = Tab[1];
    if (mResult != '') { document.getElementById('commentaire_commentaire_' + mParamRetour).innerHTML = mResult; } else { document.getElementById('commentaire_commentaire_' + mParamRetour).innerHTML = '<span class="AjouterCommentaire">Ajouter un commentaire....</span>' }
    document.getElementById('commentaire_modification_' + mParamRetour).style.display = 'none';
    document.getElementById('commentaire_commentaire_' + mParamRetour).style.display = 'block';
}

function OnFailed_AjaxAjoutCommentaireWebLigne(error) {
    //alert('La méthode Ajax à causé une erreur : ' + error.get_message());
}

/******message lien entete******/
$(document).ready(function() {
$('#lien-general-liste[tooltip]').each(function() {
        $(this).qtip({
            content: $(this).attr('tooltip'), // Use the tooltip attribute of the element for the content
            style: { tip: true, border: { radius: 5 }, name: 'dark' }, // Give it a crea mstyle to make it stand out
            position: { corner: { tooltip: 'bottomMiddle', target: 'topMiddle'} }
        });
    });
});

/*************************************************************************/
function OnSucceeded_AjaxEnvoiMail(result) {
    var Tab = result.split('~#~');
    var mParamRetour = Tab[0];
    var mResult = Tab[1];
    if (mParamRetour == "DEVIS") {
        document.getElementById('form_demande_form').style.display = 'none';
        document.getElementById('form_demande_ok').style.display = 'block';
    }
}

function OnFailed_AjaxEnvoiMail(error) {
    alert('La méthode Ajax à causé une erreur : ' + error.get_message());
}



      
