﻿var global = this;
global.eval();

function JSCallReal(IDModule, stringAction, stringNouveauContexte, stringParam) {
    try {
        stringParam = stringParam.replace("&", " ");
        var csAncienContexte = document.getElementById('H_MEM_CONTEXTE').value;
        document.getElementById('H_MEM_CONTEXTE').value = stringNouveauContexte;

        PageMethods.AjaxAction(IDModule, stringAction, stringNouveauContexte, csAncienContexte, stringParam, OnSucceeded_JSCall, OnFailed_JSCall);

        //pour le popup d'image
        initLightbox();

        // preparer le tracking ajax au cas ou pas de Href
        try {
            if (IDModule == '001') {
                if (!$('AjaxTrackkerValue')) { $$('body')[0].insert(new Element('div', { id: 'AjaxTrackkerValue', style: 'display:none' })); }
                $('AjaxTrackkerValue').innerHTML = 'JSCall_' + 'IDModule=' + IDModule + '&Action=' + stringAction + '&Contexte=' + stringNouveauContexte + '&Param=' + stringParam;

                if (typeof cachebulle == "function") cachebulle();
            }
        }
        catch (e) { }

    }
    catch (e) {
        //alert(e.message);
    }
}

var valHistory;
function JSCall(IDModule, stringAction, stringNouveauContexte, stringParam) {
    try {
        if (IDModule == "001") { $get('lbl_' + IDModule).innerHTML = "<center><img border='0' src='Image/WEB/loading.gif' class='ImgLoading001' /></center>"; }
        else if ((IDModule == "101") || (IDModule == "100")) { $get('lbl_' + IDModule).innerHTML = "<center><img border='0' src='Image/WEB/loading100.gif' class='ImgLoading100' /></center>"; }
        else { $get('lbl_' + IDModule).innerHTML = "<center><img border='0' src='Image/WEB/loadingTous.gif' class='ImgLoadingTous' /></center>"; }


        // Set a history point in client script.
        var val = IDModule + "~" + stringAction + "~" + stringNouveauContexte + "~" + stringParam;
        valHistory = val;

        //$get("div2").innerHTML = "JSCall " + val;

        var csAncienContexte = document.getElementById('H_MEM_CONTEXTE').value;

        //if ((csAncienContexte.length == 0) || (stringNouveauContexte == csAncienContexte))
        //{
        var tableau = valHistory.split('~');
        var ChaineParam = tableau[tableau.length - 1];

        if (IDModule == '001') {
            try {
                //#001~~View~ViewKey:VueWebKey_CatalogueTheme|IDCatalogueTheme:74|TitrePage:Téléphonie » Oreillettes Bluetooth|WithOnglet:1
                tableau = ChaineParam.split('|');
                var Titre = "";
                var ViewKey = "";
                var ID = "";
                var PageStatique = "";
                for (i = 0; i <= tableau.length - 1; i = i + 1) {
                    if (tableau[i].substr(0, ('TitrePage').length) == "TitrePage") {
                        Titre = tableau[i].replace("TitrePage:", "");
                        //ChangeTitle(Titre);
                    }
                    else if (tableau[i].substr(0, ('ViewKey').length) == "ViewKey") {
                        ViewKey = tableau[i].replace("ViewKey:", "");
                    }
                    else if (tableau[i].substr(0, ('IDCatalogueTheme').length) == "IDCatalogueTheme") {
                        ID = tableau[i].replace("IDCatalogueTheme:", "");
                    }
                    else if (tableau[i].substr(0, ('IDArticle').length) == "IDArticle") {
                        ID = tableau[i].replace("IDArticle:", "");
                    }
                    else if (tableau[i].substr(0, ('MaskKey').length) == "MaskKey") {
                        PageStatique = "oui";
                        ID = tableau[i].replace("MaskKey:", "");
                    }
                }
                tmp = "";
                for (var i = 0; i < Titre.length; i++) {
                    tmp = tmp + Titre.charAt(i);
                    if (Titre.charAt(i) == " ") {
                        tmp = tmp.replace(" ", "-");
                    }
                }
                Titre = tmp;
                if (ViewKey == "VueWebKey_CatalogueTheme") {
                    valHistory = "CT-" + ID + "-" + Titre;
                }
                else if (ViewKey == "VueWebKey_Article_Popup") {
                    if (tableau.length < 4) {
                        valHistory = "A-" + ID + "-" + Titre;
                    }
                }
                else if (PageStatique == "oui") {
                    valHistory = "PS-" + ID + "-" + Titre;
                }
                //Sys.Application.get_history().addHistoryPoint({pageClientState: valHistory});         

                //Retrouver Href
                try {
                    var tableau = stringParam.split('|');
                    var Href = "";

                    for (i = 0; i <= tableau.length - 1; i = i + 1) { if (tableau[i].substr(0, ('Href').length) == "Href") { Href = tableau[i].replace("Href:", ""); } }

                    //enlever adresse du site de href
                    if (Href != "") {
                        var tableau = Href.split('/');
                        Href = "";
                        for (i = 3; i <= tableau.length - 1; i = i + 1) { Href += "/"; Href += tableau[i]; }
                    }
                    if (!$('HrefTrackkerValue')) { $$('body')[0].insert(new Element('div', { id: 'HrefTrackkerValue', style: 'display:none' })); }
                    $('HrefTrackkerValue').innerHTML = Href;

                    //-----
                } catch (ex) { }
                if (IDModule == '001' && stringNouveauContexte != "Identification") {
                    if (csAncienContexte == "Identification") {
                        JSCallReal(IDModule, stringAction, stringNouveauContexte, stringParam);
                    }

                    var regFI = new RegExp("FI_", "g");
                    var regFU = new RegExp("FU_", "g");
                    var regIDFiltre = new RegExp("IDFiltre", "g");
                    var regActionPrep = new RegExp("ActionPrepVueWeb_", "g");
                    var regOnglet = new RegExp("\\u007cOnglet", "g"); // le \\u0007c représente le pipe

                    if (stringParam.match(regFI) || stringParam.match(regFU) || stringParam.match(regIDFiltre) || stringParam.match(regActionPrep) || stringParam.match(regOnglet)) {
                        JSCallReal(IDModule, stringAction, stringNouveauContexte, stringParam);
                    }
                    else {
                        if (location.hash == '#' + valHistory) {
                            JSCallReal(IDModule, stringAction, stringNouveauContexte, stringParam);
                        }
                        location.hash = "#" + valHistory;
                        if ((BrowserDetect.browser == "Safari") || (BrowserDetect.browser == "Chrome") || (BrowserDetect.browser == "Mozilla")) {
                            JSCallReal(IDModule, stringAction, stringNouveauContexte, stringParam);
                        }
                    }
                }
                else {
                    JSCallReal(IDModule, stringAction, stringNouveauContexte, stringParam);
                }
                if ((stringNouveauContexte != "Popup") && (stringNouveauContexte != "")) {
                    document.getElementById('CSSSupp').href = '/CSS/' + stringNouveauContexte + '.css';
                }
                //return false;

            }
            catch (e) {
                //alert(e.message);
            }
        }
        else {
            JSCallReal(IDModule, stringAction, stringNouveauContexte, stringParam);
        }

    }
    catch (e) {
        //alert(e.message);
    }
}

// This is the callback function
// that process the page method call 
// return value.
function OnSucceeded_JSCall(result) {
    try {
        nettoyageFont();
        var Tab = result.split('~#~');

        if (Tab[0] == "reloadpage") {
            window.location = Tab[1];
            return false;
        }
        else {
            // ZONE CENTRALE
            if (Tab[0] == "001") {
                try {
                    if ($('HrefTrackkerValue').innerHTML.length > 0) { pageTracker._trackPageview($('HrefTrackkerValue').innerHTML); } else { pageTracker._trackPageview($('AjaxTrackkerValue').innerHTML); }
                } catch (err) { }
            }
            // MINI PANIER
            else if (Tab[0] == "005") {
                if (Tab[1].match(/ArticleAjoutPanier:True_/g)) { Tab[1] = Tab[1].replace(/ArticleAjoutPanier:True_/g, ''); afficheCenterLoading(); }
                else if (Tab[1].match(/ArticleAjoutPanier:False_/g)) { Tab[1] = Tab[1].replace(/ArticleAjoutPanier:False_/g, ''); ArticleAjoutPanierFalse(); }
                else if (Tab[1].match(/CouponAjoutPanier:True_/g)) { Tab[1] = Tab[1].replace(/CouponAjoutPanier:True_/g, ''); window.location = 'panier-affichage.aspx'; }
                else if (Tab[1].match(/CouponAjoutPanier:False_/g)) { Tab[1] = Tab[1].replace(/CouponAjoutPanier:False_/g, ''); window.location = 'panier-affichage.aspx'; }
                else if (Tab[1].match(/AjoutPanierExpress:True_/g)) { Tab[1] = Tab[1].replace(/ArticleAjoutPanierExpress:True_/g, ''); ArticleAjoutPanierExpressTrue(); }
                else if (Tab[1].match(/AjoutPanierExpress:False_/g)) { Tab[1] = Tab[1].replace(/ArticleAjoutPanierExpress:False_/g, ''); ArticleAjoutPanierExpressFalse(); }
                else if (Tab[1].match(/ChangeActionCo:True_/g)) { Tab[1] = Tab[1].replace(/ChangeActionCo:True_/g, ''); window.location = 'panier-affichage.aspx'; }
                else if (Tab[1].match(/ChangeActionCo:False_/g)) { Tab[1] = Tab[1].replace(/ChangeActionCo:False_/g, ''); window.location = 'panier-affichage.aspx'; }
                else if (Tab[1].match(/PointCadeauAjoutPanier:True_/g)) { Tab[1] = Tab[1].replace(/PointCadeauAjoutPanier:True_/g, ''); PointCadeauAjoutPanierTrue(); }
                else if (Tab[1].match(/PointCadeauAjoutPanier:False_/g)) {
                    Tab[1] = Tab[1].replace(/PointCadeauAjoutPanier:False_/g, '');
                    var Tmp = Tab[1].split('|#|');
                    PointCadeauAjoutPanierFalse(Tmp[0], Tmp[1]); //Indique a l'utilistaeur le pb

                    if (Tab[1].match(/PTS_KDO_INSUFFISANT/g)) Tmp = Tab[1].split('PTS_KDO_INSUFFISANT');
                    else if (Tab[1].match(/PTS_KDO_ARTICLE_NON_COMMANDABLE/g)) Tmp = Tab[1].split('PTS_KDO_ARTICLE_NON_COMMANDABLE');
                    else Tmp = Tab[1].split('PTS_KDO_NON_CONNECTE');
                    Tab[1] = Tmp[0];
                }
            }
            // COMPARATEUR
            else if (Tab[0] == "050") {
                if (Tab[1].match(/AjoutComparateur:True_/g)) { Tab[1] = Tab[1].replace(/AjoutComparateur:True_/g, ''); if (Tab[1] == "0" || Tab[1] == "1") { JSCall('100', '', '', 'MaskKey:PopupAjoutComparateurTrueNonCliquable'); } else { JSCall('100', '', '', 'MaskKey:PopupAjoutComparateurTrueCliquable'); } AfficheMenuComparateur(Tab[1]); }
                else if (Tab[1].match(/AjoutComparateur:False_/g)) { Tab[1] = Tab[1].replace(/AjoutComparateur:False_/g, ''); JSCall('100', '', '', 'MaskKey:PopupAjoutComparateurFalse'); AfficheMenuComparateur(Tab[1]); }
                else if (Tab[1].match(/SupprimeComparateur:True_/g)) { Tab[1] = Tab[1].replace(/SupprimeComparateur:True_/g, ''); if (Tab[1] == "0" || Tab[1] == "1") { window.location.href = '/'; } else { window.location.href = '/PS-comparateur.aspx'; } }
                else if (Tab[1].match(/VideComparateur:True_/g)) { Tab[1] = Tab[1].replace(/VideComparateur:True_/g, ''); window.location.href = '/'; }
            }
            // LISTE DE SOUHAITS
            else if (Tab[0] == "051") {
                if (Tab[1].match(/AjoutListeSouhaits:True_/g)) { Tab[1] = Tab[1].replace(/AjoutListeSouhaits:True_/g, ''); JSCall('100', '', '', 'MaskKey:PopupAjoutListeSouhaitsTrue'); }
                else if (Tab[1].match(/AjoutListeSouhaits:False_/g)) { Tab[1] = Tab[1].replace(/AjoutListeSouhaits:False_/g, ''); JSCall('100', '', '', 'MaskKey:PopupAjoutListeSouhaitsFalse'); }
                else if (Tab[1].match(/EnleveListeSouhaits:True_/g)) { Tab[1] = Tab[1].replace(/EnleveListeSouhaits:True_/g, ''); JSCall('100', '', '', 'MaskKey:PopupEnleveListeSouhaitsTrue'); }
                else if (Tab[1].match(/EnleveListeSouhaits:False_/g)) { Tab[1] = Tab[1].replace(/EnleveListeSouhaits:False_/g, ''); JSCall('100', '', '', 'MaskKey:PopupEnleveListeSouhaitsFalse'); }
                else if (Tab[1].match(/SupprimeListeSouhaits:True_/g)) { Tab[1] = Tab[1].replace(/SupprimeListeSouhaits:True_/g, ''); window.location.href = '/compte-liste.aspx'; }
                else if (Tab[1].match(/SupprimeListeSouhaits:False_/g)) { Tab[1] = Tab[1].replace(/SupprimeListeSouhaits:False_/g, ''); window.location.href = '/compte-liste.aspx'; }
                else if (Tab[1].match(/VideListeSouhaits:True_/g)) { Tab[1] = Tab[1].replace(/VideListeSouhaits:True_/g, ''); window.location.href = '/compte-accueil.aspx'; }
                else if (Tab[1].match(/VideListeSouhaits:False_/g)) { Tab[1] = Tab[1].replace(/VideListeSouhaits:False_/g, ''); window.location.href = '/compte-accueil.aspx'; }
            }

            try {
                document.getElementById("lbl_" + Tab[0]).innerHTML = Tab[1];
            } catch (exception) { }


            if (Tab[0] != "026") { JSCallReal('026', '', document.getElementById('H_MEM_CONTEXTE').value, ''); ChangeTitle(Tab[3]); }



            //executer scripts de la page
            if ((Tab[0] == "001") || (Tab[0] == "001_789") || (Tab[0] == "101") || (Tab[0] == "100") || (Tab[0] == "024")) {
                var c = document.getElementById('lbl_' + Tab[0]);
                var allscript = c.getElementsByTagName('script');
                for (var i = 0; i < allscript.length; i++) {
                    global.eval(allscript[i].text);
                }
            }

        }
    }
    catch (e) {
        //alert(result);
        //alert(e.message);
    }
}

function OnFailed_JSCall(error) {
    // Alert user to the error.
    //alert('La méthode Ajax à causé une erreur : ' + error.get_message());
}


//****************************************************************************************************************************************************
//Code pour l'envoi d'un panier par mail
//****************************************************************************************************************************************************
function AjaxEnvoiMailPanier(csmail) {
    PageMethods.AjaxEnvoiMailPanier(csmail, OnSucceeded_AjaxEnvoiMailPanier, OnFailed_AjaxEnvoiMailPanier);
}

function OnSucceeded_AjaxEnvoiMailPanier(result) {
    alert(result);
}

function OnFailed_AjaxEnvoiMailPanier(error) {
    //alert('La méthode Ajax à causé une erreur : ' + error.get_message());
}
//****************************************************************************************************************************************************
//FIN Code pour l'envoi d'un panier par mail
//****************************************************************************************************************************************************

//****************************************************************************************************************************************************
//Function de controle de saisie d'un controle
//****************************************************************************************************************************************************
//csObjetAControler : nom du contrôle à valider
//csControleRequireField : nom du contrôle à afficher en cas d'échec de la validation
//csExpressionReguliere : expression régulière à utiliser pour valider la saisie
//csControleExpressionReguliereField : nom du contrôle à afficher en cas d'échec de la validation de l'expression régulière
function ValidSaisieDetail(csObjetAControler, csControleRequireField, csExpressionReguliere, csControleExpressionReguliereField) {
    try {
        var bRet = true;
        //si le champ est vide    
        if (document.getElementById(csObjetAControler).value.length == 0) {
            //et qu'on a une expression régulière en plus pour ce champ
            //on masque le texte d'erreur pour l'expression car il n'est pas utile à ce moment
            if (csControleExpressionReguliereField != "") {
                document.getElementById(csControleExpressionReguliereField).style.display = 'none';
            }
            //et on affiche le texte d'erreur pour le champ obligatoire
            document.getElementById(csControleRequireField).style.display = 'block';
            bRet = false;
        }
        //par contre, si le champ n'est pas vide    
        else {
            //on masque le message d'erreur pour Champ obligatoire
            document.getElementById(csControleRequireField).style.display = 'none';
            //si on doit vérifier une expression régulière on le fait
            if (csExpressionReguliere != "") {
                var exp = new RegExp(csExpressionReguliere, "gi"); //gi = recherche toute la chaine sans s'occuper de la casse
                //si le resultat de l'expression régulière est faux
                if (exp.test(document.getElementById(csObjetAControler).value) == false) {
                    //on affiche le message d'erreur pour l'expression régulière
                    document.getElementById(csControleExpressionReguliereField).style.display = 'block';
                    bRet = false;
                }
                //par contre, si le test de l'expression régulière est bon
                else {
                    //on masqe le message d'erreur pour l'expression régulière
                    document.getElementById(csControleExpressionReguliereField).style.display = 'none';
                }
            }
        }
        return bRet;
    }
    catch (e) {
        //alert("Erreur avec les paramètres : " + csObjetAControler + " et " + csControleRequireField + "Détail de l'erreur : " + e.message);   
    }
}
//****************************************************************************************************************************************************
//FIN Function de controle de saisie d'un controle
//****************************************************************************************************************************************************

function ChangeTitle(TitrePage) {
    var suffixe = "";
    var tableau = TitrePage.split('()');
    if (tableau.length > 1) {
        document.title = (tableau[0] + suffixe);
        $get("TitrePage").innerHTML = tableau[1];
    }
    else {
        document.title = (TitrePage + suffixe);
        $get("TitrePage").innerHTML = TitrePage;
    }
}

function AjaxAjoutPanier(vIDArticle, vCommentaire, vQuantite, vAttente) {
    try {
        try {
            //document.getElementById('DIV_LigneArticleCommentaire').parentNode.innerHTML = '';
            hideLightbox();
        }
        catch (ex1) { }
        //if (vAttente != false) {
        //    $get('lbl_005').innerHTML = "<div id='mp'><center><img border='0' src='Image/WEB/loadingTous.gif' class='ImgLoadingTous' /></center></div>";
        //    $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/loading100.gif' class='ImgLoading100' /></center></div>";
        //    showTextLightbox(80, 80, true);
        //}
        MessageAttente();

        if ((typeof (vCommentaire) != "undefined") && (typeof (vQuantite) != "undefined"))
            JSCallReal('005', 'AjoutPanier', 'View', 'IDArticle:' + vIDArticle + '|LigneArticleCommentaire:' + vCommentaire + '|Quantite:' + vQuantite);
        else if (typeof (vCommentaire) != "undefined")
            JSCallReal('005', 'AjoutPanier', 'View', 'IDArticle:' + vIDArticle + '|LigneArticleCommentaire:' + vCommentaire + '|Quantite:1');
        else if (typeof (vQuantite) != "undefined")
            JSCallReal('005', 'AjoutPanier', 'View', 'IDArticle:' + vIDArticle + '|Quantite:' + vQuantite);
        else
            JSCallReal('005', 'AjoutPanier', 'View', 'IDArticle:' + vIDArticle + '|Quantite:1');
    }
    catch (ex) {
        JSCallReal('005', 'AjoutPanier', 'View', 'IDArticle:' + vIDArticle + '|Quantite:1');
    }
}

function AjaxAjoutPanierMultiple(vListeArticleEtQuantite) {
    JSCallReal('005', 'AjoutPanierMultiple', 'View', 'ListeArticleEtQuantite:' + vListeArticleEtQuantite);
}

function AjaxAjoutPanierExpress(vIDArticle, vQuantite) {
    try {
        try {
            document.getElementById('retourAjoutPanierExpress').innerHTML = '';
        } catch (ex1) { }
        if (typeof (vQuantite) != "undefined")
            JSCallReal('005', 'AjoutPanierExpress', 'View', 'IDArticle:' + vIDArticle + '|Quantite:' + vQuantite);
        else
            JSCallReal('005', 'AjoutPanierExpress', '', 'IDArticle:' + vIDArticle + '|Quantite:1');
    }
    catch (ex) {
        JSCallReal('005', 'AjoutPanierExpress', '', 'IDArticle:' + vIDArticle + '|Quantite:1');
    }
}

function AjaxAjoutComparateur(vIDArticle) {
    JSCallReal('050', 'AjoutComparateur', 'View', 'IDArticle:' + vIDArticle);
}
function AjaxSupprimeComparateur(vIDArticle) {
    JSCallReal('050', 'SupprimeComparateur', 'View', 'IDArticle:' + vIDArticle);
}
function AjaxVideComparateur() {
    JSCallReal('050', 'VideComparateur', 'View', 'IDArticle:000');
}

function AjaxAjoutListeSouhaits(vIDArticle, vQuantite) {
    if (typeof (vQuantite) != "undefined")
        JSCallReal('051', 'AjoutListeSouhaits', 'View', 'IDArticle:' + vIDArticle + '|Quantite:' + vQuantite);
    else
        JSCallReal('051', 'AjoutListeSouhaits', 'View', 'IDArticle:' + vIDArticle + '|Quantite:1');
}

function AjaxEnleveListeSouhait(vIDArticle, vQuantite) {
    if (typeof (vQuantite) != "undefined")
        JSCallReal('051', 'EnleveListeSouhaits', 'View', 'IDArticle:' + vIDArticle + '|Quantite:' + vQuantite);
    else
        JSCallReal('051', 'EnleveListeSouhaits', 'View', 'IDArticle:' + vIDArticle + '|Quantite:1');
}

function AjusterQuantiteListeSouhaits(vIDArticle, vQuantite, vQuantiteInit) {
    if (typeof (vQuantite) != "undefined") {
        var ajustement = parseInt(vQuantiteInit) - parseInt(vQuantite);
        if (ajustement == parseInt(vQuantiteInit)) { AjaxSupprimeListeSouhaits(vIDArticle, vQuantite) }
        else { AjaxEnleveListeSouhait(vIDArticle, ajustement); }
    }
}

function AjaxSupprimeListeSouhaits(vIDArticle, vQuantite) {
    JSCallReal('051', 'SupprimeListeSouhaits', '', 'IDArticle:' + vIDArticle);
}

function AjaxVideListeSouhaits() {
    JSCallReal('051', 'VideListeSouhaits', '', '');
}

function AjaxAjoutPanierPointCadeau(vIDArticle, vCommentaire, vQuantite, vAttente) {
    try {
        MessageAttente();

        if ((typeof (vCommentaire) != "undefined") && (typeof (vQuantite) != "undefined"))
            JSCallReal('005', 'AjoutPanierPointCadeau', '', 'IDArticle:' + vIDArticle + '|LigneArticleCommentaire:' + vCommentaire + '|Quantite:' + vQuantite);
        else if (typeof (vCommentaire) != "undefined")
            JSCallReal('005', 'AjoutPanierPointCadeau', '', 'IDArticle:' + vIDArticle + '|LigneArticleCommentaire:' + vCommentaire + '|Quantite:1');
        else if (typeof (vQuantite) != "undefined")
            JSCallReal('005', 'AjoutPanierPointCadeau', '', 'IDArticle:' + vIDArticle + '|Quantite:' + vQuantite);
        else
            JSCallReal('005', 'AjoutPanierPointCadeau', '', 'IDArticle:' + vIDArticle + '|Quantite:1');
    }
    catch (ex) {
        JSCallReal('005', 'AjoutPanierPointCadeau', '', 'IDArticle:' + vIDArticle + '|Quantite:1');
    }
}

//*********************Ajout reference ou code barre******************************** 
//*******************Commande avec reference catalogue******************************

function AjaxAjoutPanierReferenceOuCodeBarre(vReference, vQuantite, vAttente) {
    //alert('reference=' + vReference + ' Quantite='+ vQuantite + ' vAttente=' + vAttente);
    //if (vAttente != false) {
    MessageAttente();
    //}

    if (typeof (vQuantite) != "undefined")
        JSCallReal('005', 'AjoutPanierReferenceOuCodeBarre', 'View', 'IDArticle:' + vReference + '|Quantite:' + vQuantite);
    else
        JSCallReal('005', 'AjoutPanierReferenceOuCodeBarre', 'View', 'IDArticle:' + vReference + '|Quantite:1');
}

function AjaxAjoutPanierCoupon(vReference, vQuantite, vAttente) {
    //alert('reference=' + vReference + ' Quantite='+ vQuantite + ' vAttente=' + vAttente);
    //if (vAttente != false) {
    MessageAttente();
    //}

    if (typeof (vQuantite) != "undefined")
        JSCallReal('005', 'AjoutPanierCoupon', 'View', 'IDArticle:' + vReference + '|Quantite:' + vQuantite);
    else
        JSCallReal('005', 'AjoutPanierCoupon', 'View', 'IDArticle:' + vReference + '|Quantite:1');
}

function AjaxAjoutWebDossierComplet(vIDDossier) {
    try {
        MessageAttente();
        JSCallReal('005', 'AjoutPanierWebDossierComplet', 'View', 'IDDossier:' + vIDDossier);
    }
    catch (ex) {
        JSCallReal('005', 'AjoutPanierWebDossierComplet', 'View', 'IDDossier:' + vIDDossier);
    }
}

function AjaxAjoutDossierComplet(vIDDossier) {
    try {
        MessageAttente();
        JSCallReal('005', 'AjoutPanierDossierComplet', 'View', 'IDDossier:' + vIDDossier);
    }
    catch (ex) {
        JSCallReal('005', 'AjoutPanierDossierComplet', 'View', 'IDDossier:' + vIDDossier);
    }
}

function AjaxSauvegardeDossier(vTypeDossier, vObjet) {
    try {
        MessageAttente();
        JSCallReal('005', 'SauvegardeDossier', '', 'TypeDossier:' + vTypeDossier + '|Objet:' + vObjet.replace("'", "\'"));
    }
    catch (ex) {

        JSCallReal('005', 'SauvegardeDossier', '', 'TypeDossier:' + vTypeDossier + '|Objet:' + vObjet.replace("'", "\'"));
    }
}


function afficheCenterLoading() {
    try {
        //bubble = document.getElementById("lbl_100");
        //bubble.innerHTML =
        //	"<DIV id='DIV_LigneArticleCommentaire' style='DISPLAY: block; HEIGHT: 871px'></DIV><DIV id='DIV2_LigneArticleCommentaire' style='DISPLAY: block; LEFT: 379px; WIDTH: 500px; TOP: 285px; HEIGHT: 300px'>"
        //	+ "essai de texte"
        //	+ "</DIV><IMG id='fermerCommentaire' style='BORDER-RIGHT: 0px; BORDER-TOP: 0px; Z-INDEX: 1001; LEFT: 867px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px; POSITION: absolute; TOP: 285px' src='Image/WEB/close.gif' />";
        //showTextLightbox(500,300);
        JSCall('100', '', 'Popup', 'MaskKey:PopupTerminerCommande');
    }
    catch (ex) {
        //window.status = "Erreur afficheCenterLoading : " + ex.Message;
    }
}

function attentemiseaupanier(ouinon) {
    if (ouinon) {
        bubble = document.getElementById("infobulle");
        bubble.innerHTML = "Veuillez patienter pendant la mise au panier de votre article"
        bubble.style.visibility = "visible";
        bubble.style.display = "block";
        bubble.style.left = mouseposx - 165 + 'px';
        bubble.style.top = mouseposy - 20 - bubble.offsetHeight + 'px';
    }
    else {
        bubble = document.getElementById("infobulle");
        bubble.style.visibility = "hidden";
        bubble.style.display = "none";
    }
}


function hideMessageAjoutPanier(element) {
    hideLightbox();
    //document.getElementById("DIV_LigneArticleCommentaire").parentNode.innerHTML = '';
    //clearTimeout(a);
}
function erreurAjoutPanier() {
    document.getElementById("expressFormMessag").innerHTML = '<b>Vous devez indiquer une référence valide</b>';
}

function ArticleAjoutPanierFalse(idarticle) {
    JSCall('100', '', 'Popup', 'MaskKey:PopupArticleAjoutPanierFalse|IDArticle:' + idarticle);
}

function PointCadeauAjoutPanierTrue(idarticle) {
    JSCall('100', '', 'Popup', 'MaskKey:PopupTerminerCommande|IDArticle:' + idarticle);
}

function PointCadeauAjoutPanierFalse(vMessage, idarticle) {
    if (vMessage.match(/PTS_KDO_INSUFFISANT/g)) JSCall('100', '', 'Popup', 'MaskKey:PopupPointCadeauInsuffisant|IDArticle:' + idarticle);
    else if (vMessage.match(/PTS_KDO_ARTICLE_NON_COMMANDABLE/g)) JSCall('100', '', 'Popup', 'MaskKey:PopupPointCadeauNonCommandable|IDArticle:' + idarticle);
    else JSCall('100', '', 'Popup', 'MaskKey:PopupPointCadeauErreur|IDArticle:' + idarticle);
}

function AfficheChargement() {
    try {
        MessageAttente();
    }
    catch (ex) { }
}


/*function AjaxAjoutPanier(vIDArticle)
{
AjaxAjoutPanier(vIDArticle, "");
}*/

function JSClear(IDModule) {
    try {
        var Tab = IDModule.split('|');
        for (i = 0; i < Tab.length; i++) {
            $get("lbl_" + Tab[i]).innerHTML = "";
        }
    }
    catch (e) {
        //alert(e.message);
    }
}
//****************************************************************************************************************************************************
/**Effet sur les images**/
//****************************************************************************************************************************************************
function MM_swapImgRestore() {
    //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_preloadImages() {
    //v3.0
    var d = document;
    if (d.images) {
        if (!d.MM_p) {
            d.MM_p = new Array();
        }

        var i;
        var j = d.MM_p.length;
        var a = MM_preloadImages.arguments;

        for (i = 0; i < a.length; i++) {
            if (a[i].indexOf("#") != 0) {
                d.MM_p[j] = new Image;
                d.MM_p[j++].src = a[i];
            }
        }
    }
}

function MM_findObj(n, d) {
    //v4.01
    var p;
    var i;
    var x;

    if (!d) {
        d = document;
    }
    if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) {
        x = d.all[n];
    }
    for (i = 0; !x && i < d.forms.length; i++) {
        x = d.forms[i][n];
    }
    for (i = 0; !x && d.layers && i < d.layers.length; i++) {
        x = MM_findObj(n, d.layers[i].document);
    }
    if (!x && d.getElementById) {
        x = d.getElementById(n);
    }
    return x;
}

function MM_swapImage() {
    //v3.0
    var i;
    var j = 0;
    var x;
    var a = MM_swapImage.arguments;

    document.MM_sr = new Array;

    for (i = 0; i < (a.length - 2); i += 3) {
        if ((x = MM_findObj(a[i])) != null) {
            document.MM_sr[j++] = x;
            if (!x.oSrc) {
                x.oSrc = x.src;
                x.src = a[i + 2];
            }
        }
    }
}
//****************************************************************************************************************************************************
/**FIN Effet sur les images**/
//****************************************************************************************************************************************************


//****************************************************************************************************************************************************
/**Renvoi la touche qui a été pressée**/
//****************************************************************************************************************************************************
function TouchePressee(evenement) {
    var touche = window.event ? evenement.keyCode : evenement.which;
    return touche;
}
//****************************************************************************************************************************************************
/**FIN Renvoi la touche qui a été pressée**/
//****************************************************************************************************************************************************


function PageQuery(q) {
    if (q.length > 1) this.q = q.substring(1, q.length);
    else this.q = null;
    this.keyValuePairs = new Array();
    if (q) {
        for (var i = 0; i < this.q.split("&").length; i++) {
            this.keyValuePairs[i] = this.q.split("&")[i];
        }
    }
    this.getKeyValuePairs = function () { return this.keyValuePairs; }
    this.getValue = function (s) {
        for (var j = 0; j < this.keyValuePairs.length; j++) {
            if (this.keyValuePairs[j].split("=")[0] == s)
                return this.keyValuePairs[j].split("=")[1];
        }
        return false;
    }
    this.getParameters = function () {
        var a = new Array(this.getLength());
        for (var j = 0; j < this.keyValuePairs.length; j++) {
            a[j] = this.keyValuePairs[j].split("=")[0];
        }
        return a;
    }
    this.getLength = function () { return this.keyValuePairs.length; }
}
function queryString(key) {
    var page = new PageQuery(window.location.search);
    return unescape(page.getValue(key));
}
function displayItem(key) {
    if (queryString(key) == 'false') {
        document.write("you didn't enter a ?name=value querystring item.");
    } else {
        document.write(queryString(key));
    }
}



function ismaxlength(obj) {
    var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : ""
    if (obj.getAttribute && obj.value.length > mlength)
        obj.value = obj.value.substring(0, mlength)
}




//http://www.quirksmode.org/js/detect.html
var BrowserDetect = {
    init: function () {
        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
        this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
        this.OS = this.searchString(this.dataOS) || "an unknown OS";
    },
    searchString: function (data) {
        for (var i = 0; i < data.length; i++) {
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
            }
            else if (dataProp)
                return data[i].identity;
        }
    },
    searchVersion: function (dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1) return;
        return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
    },
    dataBrowser: [
		{
		    string: navigator.userAgent,
		    subString: "Chrome",
		    identity: "Chrome"
		},
		{ string: navigator.userAgent,
		    subString: "OmniWeb",
		    versionSearch: "OmniWeb/",
		    identity: "OmniWeb"
		},
		{
		    string: navigator.vendor,
		    subString: "Apple",
		    identity: "Safari",
		    versionSearch: "Version"
		},
		{
		    prop: window.opera,
		    identity: "Opera"
		},
		{
		    string: navigator.vendor,
		    subString: "iCab",
		    identity: "iCab"
		},
		{
		    string: navigator.vendor,
		    subString: "KDE",
		    identity: "Konqueror"
		},
		{
		    string: navigator.userAgent,
		    subString: "Firefox",
		    identity: "Firefox"
		},
		{
		    string: navigator.vendor,
		    subString: "Camino",
		    identity: "Camino"
		},
		{		// for newer Netscapes (6+)
		    string: navigator.userAgent,
		    subString: "Netscape",
		    identity: "Netscape"
		},
		{
		    string: navigator.userAgent,
		    subString: "MSIE",
		    identity: "Explorer",
		    versionSearch: "MSIE"
		},
		{
		    string: navigator.userAgent,
		    subString: "Gecko",
		    identity: "Mozilla",
		    versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
		    string: navigator.userAgent,
		    subString: "Mozilla",
		    identity: "Netscape",
		    versionSearch: "Mozilla"
		}
	],
    dataOS: [
		{
		    string: navigator.platform,
		    subString: "Win",
		    identity: "Windows"
		},
		{
		    string: navigator.platform,
		    subString: "Mac",
		    identity: "Mac"
		},
		{
		    string: navigator.userAgent,
		    subString: "iPhone",
		    identity: "iPhone/iPod"
		},
		{
		    string: navigator.platform,
		    subString: "Linux",
		    identity: "Linux"
		}
	]

};
BrowserDetect.init();

function nettoyageFont() {
    selects = document.getElementsByTagName("font");
    for (i = 0; i != selects.length; i++) {
        selects[i].style.fontSize = "12px";
    }
}

/* RECHERCHE */

function Recherche() {
    try {
        var mRecherche = document.getElementById('ValeurField0').value;
        if (mRecherche != "" && mRecherche != "Recherche...") {
            var reg = new RegExp("[\/&= :|?.]", "g");
            mRecherche = mRecherche.replace(reg, "-");
            mRecherche = mRecherche.replace(/--/g, "-");
            document.location = 'Recherche-' + mRecherche + '.aspx';
        }
    }
    catch (e) {
        //alert(e);
    }
}

function ChangeCodePostalKiala(idTransportGrilleValeur, codePostal) {
    document.location.href = 'Default.aspx?Action=ChangeGrilleTransport&Contexte=ValidationPanier&Param=Transporteur:' + idTransportGrilleValeur + '|CodePostalKiala:' + codePostal;
}


/********************************************************************************************
*       NOUVELLES METHODES AJAX
*********************************************************************************************/

function AjaxAjoutCommentaireWebLigne(vIDArticle, vCommentaire, vParamRetour) {
    PageMethods.AjaxAjoutCommentaireWebLigne(vIDArticle, vCommentaire, vParamRetour, OnSucceeded_AjaxAjoutCommentaireWebLigne, OnFailed_AjaxAjoutCommentaireWebLigne);
}

function AjaxEnvoiMail(vObjet, vCorps, vParamRetour) {
    PageMethods.AjaxEnvoiMail(vObjet, vCorps, vParamRetour, OnSucceeded_AjaxEnvoiMail, OnFailed_AjaxEnvoiMail);
}

/***********************************************
MESSAGE ATTENTE (par deafult , ecrase dans fonction.js)
************************************************/


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);
}


function SoColissimoLiberte() {
    SoColissimoRecherche();
    return false;
}

function SoColissimoRecherche() {
    var adresse = '';
    var typePoints = '';

    if ($('#SoAdresseInput').length > 0)
        adresse = $('#SoAdresseInput').val();
    if ($('#SoCheckCityssimo:checked').length > 0)
        typePoints += 'C';
    if ($('#SoCheckPoste:checked').length > 0)
        typePoints += 'P';
    if ($('#SoCheckCommercant:checked').length > 0)
        typePoints += 'M';

    $.colorbox({
        html: '',
        initialWidth: 50,
        initialHeight: 50,
        maxWidth: '80%',
        maxHeight: '80%',
        onComplete: PageMethods.AjaxSoColissimoRecheche(adresse, typePoints, OnSucceeded_SoColissimoRecherche, OnFailed_SoColissimoRecherche)
    });
}

function SoColissimoSelectionnePointRetrait(identifiantPoint) {
    PageMethods.AjaxSoColissimoSelectionnePointRetrait(identifiantPoint, OnSucceeded_SoColissimoSelectionnePointRetrait, OnFailed_SoColissimoSelectionnePointRetrait);
    return false;
}

/*********************************** AUTO COMPLETION */
function AutoComplete() {
    if ($('#ValeurField0').val().length > 2) {
        PageMethods.AjaxAutoComplete($('#ValeurField0').val(), OnSucceeded_AjaxAutoComplete, OnFailed_AjaxAutoComplete);
    }
    else {
        $('#autocompletediv').html('');
    }
}
function OnSucceeded_AjaxAutoComplete(result) {
    var totopouet = eval(result);
    var autocompletediv = '';
    for (var i = 0; i < totopouet.length; i++)
        autocompletediv += '<li class="' + totopouet[i].TypeObjet + '"><span class="picto"></span><a href="' + totopouet[i].Lien + '">' + totopouet[i].Objet + '</a></li>';
    if (autocompletediv.length != 0) $('#autocompletediv').html('<ul>' + autocompletediv + '</ul>'); else $('#autocompletediv').html('');
}
function OnFailed_AjaxAutoComplete(error) { alert(error.get_message()); }




