//------------------
//jQuery no conflict
//------------------
var J = jQuery.noConflict();


//======================================================================================================
//======================================================================================================
//	CCB Namespace
//	Function called onReady website PAGE
//	To use this, the page must include an input type hidden define like this :
//	<input type="hidden" id="ccbjs" value="myfunctionname" style="display:none" />
//======================================================================================================
var CCB = CCB || {};
J.extend(CCB, {
    debug: false,
    parentselector: "",
    //------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------
    //	CCB.onReady
    //------------------------------------------------------------------------------------------------------
    onReady: function() {
        //Init Shadowbox

        Shadowbox.init({
            onOpen: CCB.ShadowBox.open,
            onClose: CCB.ShadowBox.close,
            onChange: CCB.ShadowBox.change,
            onFinish: CCB.ShadowBox.load
        });
        //Load Layout function
        CCB.Layout.init();
        //Launch CCB JavaScript Namespace Engine
        var ccbjs = J("#ccbjs");
        if (CCB.Page && ccbjs.length > 0) {
            var functions = ccbjs.val().split(" ");
            J.each(functions, function() {
                var func = CCB.Page[this];
                if (typeof (func) == "function") { func.apply(); }
                else if (CCB.debug) { alert("CCB.Page." + this + " don't exist !!!"); }
            });
        }

        //check if the param on url are ok for see a layer.
        var getNameLayer = getUrlVars()["layer"];
        if (getNameLayer == 'newsletter') {
            Shadowbox.open({
                player: "iframe",
                content: '/services/layer_inscription-newsletter.aspx',
                height: 540,
                width: 800
            });
        }
        else if (getNameLayer == 'cadeau') {
            var codeGift = getUrlVars()["codegift"]
            Shadowbox.open({
                player: "iframe",
                content: '/checkout/layer_change_gift.aspx?promocode=' + codeGift,
                height: 350,
                width: 640
            });
        }
        else if (getNameLayer == 'codepromo') {
            Shadowbox.open({
                player: "iframe",
                content: '/services/layer-key-code-capture.aspx',
                height: 455,
                width: 790
            });
        }
        else if (getNameLayer == 'livraison') {
            Shadowbox.open({
                player: "iframe",
                content: '/all_about_ccb/layer_reinsurance_delivery.aspx',
                height: 600,
                width: 594
            });
        }
        else if (getNameLayer == 'echantillons') {
            Shadowbox.open({
                player: "iframe",
                content: '/all_about_ccb/layer_reinsurance_sample.aspx',
                height: 200,
                width: 490
            });
        }
        else if (getNameLayer == 'remboursement') {
            Shadowbox.open({
                player: "iframe",
                content: '/all_about_ccb/layer_reinsurance_repayment.aspx',
                height: 200,
                width: 490
            });
        }
        else if (getNameLayer == 'paiement') {
            Shadowbox.open({
                player: "iframe",
                content: '/all_about_ccb/layer_reinsurance_payment.aspx',
                height: 300,
                width: 490
            });
        }
        else if (getNameLayer == 'estheticienne') {
            Shadowbox.open({
                player: "iframe",
                content: '/services/layer_conseil.aspx',
                height: 288,
                width: 640
            });
        }
        else if (getNameLayer == 'video') {
            Shadowbox.open({
                player: "iframe",
                content: '/animation/2011/A730/video_ipad.aspx',
                height: 533,
                width: 578
            });
        }
        else if (getNameLayer == 'parfum') {
            Shadowbox.open({
                player: "iframe",
                content: '/animation/2011/A765/video_parfum.aspx',
                height: 480,
                width: 640
            });
        }
        else if (getNameLayer == 'cosmence') {
            Shadowbox.open({
                player: "iframe",
                content: '/animation/2011/A755/video_cosmence.aspx',
                height: 480,
                width: 640
            });
        }
        else if (getNameLayer == 'video_rouge_parfait') {
            Shadowbox.open({
                player: "iframe",
                content: '/animation/2011/A780/video_rouge_parfait.aspx',
                height: 480,
                width: 640
            });
        }
        else if (getNameLayer == 'livraison_offerte') {
            Shadowbox.open({
                player: "iframe",
                content: '/animation/2011/A795/layer_livraison_gratuit.aspx',
                height: 550,
                width: 530
            });
        }
        else if (getNameLayer == 'appli_ipad') {
            Shadowbox.open({
                player: "iframe",
                content: '/services/layer_appli_ipad.aspx',
                height: 533,
                width: 578
            });
        }
        else if (getNameLayer == 'kdo_PRM10') {
            Shadowbox.open({
                player: "iframe",
                content: '/animation/2011/A701/PRM10/cadeau.aspx',
                height: 600,
                width: 600
            });
        }
        else if (getNameLayer == 'suivi_commande') {
            Shadowbox.open({
                player: "iframe",
                content: '/customer/layer_log-follow-order.aspx',
                height: 220,
                width: 430
            });
        }
        else {
            //ne rien afficher.
        }
    },
    //------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------
    //	CCB.conciergerie
    //	Function relate to the conciergerie (link javascriptage)
    //------------------------------------------------------------------------------------------------------

    conciergerie: {
        _base16: "0A12B34C56D78E9F",
        encode: function(str) {
            var retour = "";
            for (var i = 0; i < str.length; i++) {
                var cc = str.charCodeAt(i);
                var ch = cc >> 4;
                var cl = cc - (ch * 16);
                retour += this._base16[ch] + this._base16[cl];
            }
            return "concierge" + retour;
        },
        decode: function(str) {
            var retour = "";
            for (var i = 0; i < str.length; i += 2) {
                var ch = this._base16.indexOf(str.charAt(i));
                var cl = this._base16.indexOf(str.charAt(i + 1));
                retour += String.fromCharCode((ch * 16) + cl);
            }
            return retour;
        },
        init: function() {
            var tagsA = J("span[class^=concierge]");
            tagsA.each(function() {
                var attrib = this.className.split(" ");
                var url = CCB.conciergerie.decode(attrib[0].substring(9));
                $this = jQuery(this);
                $this
						.after("<a></a>").next()
						.attr("class", $this.attr("class")).removeClass(attrib[0])
						.attr("id", $this.attr("id"))
						.attr("href", url)
						.html($this.html());
                if ($this.attr("title").length > 0)
                    $this.next().attr("title", $this.attr("title"));
                if ($this.attr("rel") != null && $this.attr("rel").length > 0)
                    $this.next().attr("rel", $this.attr("rel"));
                $this.remove();
                CCB.ShadowBox.clear();
            });
        }
    },
    //------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------
    //	CCB.qas
    //	Function relate to QAS
    //------------------------------------------------------------------------------------------------------
    qas: {
        flagValid: false,     //Temp var = to know if QAS is verified or not (true=> QASValid = Y, false=> QASValid = N)
        eventlist: "", 	      //Temp var = the return of QAS WS (..VerifiedLevel, AddressResList.length, AddressResList[i].Line1/Line2/Line3/Line4/PostCode/City, .get_message())
        htmlselectresult: "", //Temp var = used to build select in case multiple result QAS
        page: {
            formSelector: "",     //var define for a form = the selector of the form
            formType: "",         //var define for a form = the page type where the form is displayed (page or layer)
            formUrl: "",          //var define for a form = the page URL where the form is displayed (ex: "/customer/signed/layer_modify_contact.aspx")
            formUrlWidth: "",     //var define for a form = if the form page type is layer, this is the width of the layer
            formUrlHeight: "",    //var define for a form = if the form page type is layer, this is the heigth of the layer
            formBackToFlag: "",   //var define for a form = flag to know the reason why customer back to form, can be 1)blank= default case, mean customer is not back to form 2)TRUE= customer decide to go back to form manually (click on button) 3)ERROR= when customer decide to choose QAS but at the data register, the WB postback the form with an error (empty field...) 4)ACCOUNT= when customer decide to choose QAS but at the data register, the WB postback with the error "accout still exist" (used when form page is layer)
            formBackDataAjax: "", //var define for a form = used to stock the return of the ajax call customer form in case of error displayed by the webbox after the QAS result (used when form page is layer and when formBackToFlag is "error" or "account")
            successType: "",      //var define for a form = the page type in case of the form is success form (page or layer)
            successUrl: "",       //var define for a form = the page URL in case of the form is success (ex: "/customer/signed/layer_confirm-modify_contact.aspx")
            successUrlWidth: "",  //var define for a form = if the success page is layer, this is the width of the layer
            successUrlHeight: "", //var define for a form = if the success page is layer, this is the heigth of the layer
            ajaxCallUrl: ""       //var define for a form = the page URL of the ajax call to update customer information (can be register, edit...)
        },
        /**
        * CCB.qas.wsQasLoadingScreenStart : display the fader background on the form waiting the QAS return
        */
        wsQasLoadingScreenStart: function() {
            switch (CCB.qas.page.formType) {
                case "layer":
                    CCB.parentselector.find("#qasloading").attr("style", "text-align:center; height:100%; width:100%; position:absolute; padding-top:150px; background-color:#FFFFFF; opacity:0.9; z-index:3000; -ms-filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=90); filter: alpha(opacity=90);").html('<img src="/img/common/general/ico/loading2.gif" /><br>Merci de patienter...');
                    break;
                case "page":
                    J("body").find("#shadowbox_container").css("visibility", "visible");
                    J("body").find("#shadowbox_overlay").attr("style", "background-color: #000000; opacity: 0.8; padding-top:20%; color:white").html('<img src="/img/common/general/ico/loading2.gif" /><br>Merci de patienter...');
                    J("body").find("#shadowbox_nav a").css("display", "none");
                    break;
            }
        },
        /**
        * CCB.qas.wsQasLoadingScreenStop : stop the fader background on the form waiting the QAS return
        */
        wsQasLoadingScreenStop: function() {
            switch (CCB.qas.page.formType) {
                case "layer":
                    CCB.parentselector.find("#qasloading").attr("style", "").html("");
                    //Fix for IE8.The above statement does work for all browsers except IE8.Hence the below statement.                                                 
                    CCB.parentselector.find("#qasloading").removeAttr("style"); 
                    break;
                case "page":
                    J("body").find("#shadowbox_container").css("visibility", "hidden");
                    J("body").find("#shadowbox_overlay").attr("style", "").html("");
                    break;
            }
        },
        /**
        * CCB.qas.wsQasCall : collect the information into the fake form created by CCB.qas.serializeCreateForm() and send them to the QAS WebService
        */
        wsQasCall: function() {
            var theForm = J("#form-to-submit");
            var addressToTest = theForm.find("input[id='static_line3']").val() + "|" + theForm.find("input[id*='address_zip']").val() + "|" + theForm.find("input[id*='address_city']").val();
            CCB.qas.wsQasLoadingScreenStart();
            MicrosoftFrance.MCS.Commerce.WS.AJAXProject.QAS_WebService.VerifyAddressFromInput(addressToTest, CCB.qas.wsQasSuccess, CCB.qas.wsQasError);
        },
        /**
        * CCB.qas.wsQasSuccess : called after the QAS WebService in case of success, QAS object is created (to know the QAS status and the address return by QAS)
        */
        wsQasSuccess: function(e) {
            CCB.qas.wsQasLoadingScreenStop();
            CCB.qas.eventList = e;
            switch (e.VerifiedLevel) {
                case "Error":
                    CCB.qas.serializeUpdateFormQasNoAnswer(0);
                    CCB.qas.customerAjaxUpate();
                    break;
                case "None":
                    CCB.qas.wsQasSuccessLayer("single");
                    break;
                case "InteractionRequired":
                    CCB.qas.wsQasSuccessLayer("single");
                    break;
                case "PremisesPartial":
                    CCB.qas.wsQasSuccessLayer("multiple");
                    break;
                case "StreetPartial":
                    CCB.qas.wsQasSuccessLayer("multiple");
                    break;
                case "Multiple":
                    CCB.qas.wsQasSuccessLayer("multiple");
                    break;
                case "VerifiedAndUpdated":
                    CCB.qas.wsQasSuccessLayer("multiple");
                    break;
                case "Verified":
                    CCB.qas.serializeUpdateFormQasOk(0);
                    CCB.qas.customerAjaxUpate();
                    break;
            }
        },
        /**
        * CCB.qas.wsQasSuccessLayer : in case of QAS status need to display a QAS layer (qas_unknownaddress or qas_multipleaddress)
        */
        wsQasSuccessLayer: function(layerType) {
            switch (layerType) {
                case "single":
                    Shadowbox.open({ content: "/ajax/qas_unknownaddress.aspx", player: "iframe", height: 400, width: 600 });
                    break;
                case "multiple":
                    Shadowbox.open({ content: "/ajax/qas_multipleaddress.aspx", player: "iframe", height: 400, width: 600 });
                    break;
            }
        },
        /**
        * CCB.qas.wsQasError : called after the QAS WebService in case of error, the error is displayed at the top of the form
        */
        wsQasError: function(e) {
            CCB.qas.wsQasLoadingScreenStop();
            CCB.qas.page.formSelector.find("#form-msg").html("Error when calling QAS webmethod: [" + e.get_message() + "]");
            return false;
        },
        /**
        * CCB.qas.serializeCreateForm : called to create the fake form which is necessary to call an ajax customer update
        */
        serializeCreateForm: function(formToSerialize) {
            if (J("body").find("form#form-to-submit").length > 0) {
                CCB.qas.serializeDeleteForm();
            }
            J("body").append('<form id="form-to-submit" style="display:none;"></form>');
            var theForm = J("#form-to-submit");
            theForm.append(formToSerialize.html());

            //Set Value for Chrome and Firefox : remove with jQuery 1.4
            formToSerialize.find("select,textarea,input[type=text],input[type=hidden],input[type=password]").each(function(i, e) {
                theForm.find("select,textarea,input[type=text],input[type=hidden],input[type=password]").eq(i).val(J(e).val());
            });
            formToSerialize.find("input[type=checkbox],input[type=radio]").each(function(i, e) {
                theForm.find("input[type=checkbox],input[type=radio]").eq(i).attr("checked", J(e).attr("checked"));
            });

            theForm.find("input[id*='address_line1']").val("");
            theForm.find("input[id*='address_line2']").val("");
            theForm.find("input[id*='address_line3']").val("");

        },
        /**
        * CCB.qas.serializeDeleteForm : called to delete the fake form (need to be called after all customer procedure update without page refreshing)
        */
        serializeDeleteForm: function() {
            J("#form-to-submit").remove();
        },
        /**
        * CCB.qas.serializeUpdateFormQasOk : update the fake form after the customer select a valid QAS address or after a valid QAS entered by the customer (CCB.qas.flagValid = true mean QASValid = Y)
        */
        serializeUpdateFormQasOk: function(item) {
            var theForm = J("#form-to-submit");
            theForm.find("input[id*='address_line1']").val(CCB.qas.eventList.AddressResList[item].Line2);
            theForm.find("input[id*='address_line2']").val(CCB.qas.eventList.AddressResList[item].Line3);
            theForm.find("input[id*='address_line3']").val(CCB.qas.eventList.AddressResList[item].Line1);
            theForm.find("input[id*='address_zip']").val(CCB.qas.eventList.AddressResList[item].PostCode);
            theForm.find("input[id*='address_city']").val(CCB.qas.eventList.AddressResList[item].City);
            NoAnswer = 0;
            CCB.qas.flagValid = true;
        },
        /**
        * CCB.qas.serializeUpdateFormQasNoAnswer : Upadte With 'N' because The WebService QAS is Nok
        */
        serializeUpdateFormQasNoAnswer: function() {
            var theForm = J("#form-to-submit");
            theForm.find("input[id*='address_line1']").val("");
            theForm.find("input[id*='address_line2']").val("");
            theForm.find("input[id*='address_line3']").val(theForm.find("input[id='static_line3']").val());
            NoAnswer = 1;
            CCB.qas.flagValid = false;
        },
        /**
        * CCB.qas.serializeUpdateFormQasNok : update the fake form after the customer decide to keep his entered address without QAS recognition (CCB.qas.flagValid = false mean QASValid = N)
        */
        serializeUpdateFormQasNok: function() {
            var theForm = J("#form-to-submit");
            theForm.find("input[id*='address_line1']").val("");
            theForm.find("input[id*='address_line2']").val("");
            theForm.find("input[id*='address_line3']").val(theForm.find("input[id='static_line3']").val());
            theForm.find("input[id*='address_country']").val("France");
            NoAnswer = 0;
            CCB.qas.flagValid = false;
        },
        /**
        * CCB.qas.serializeGetDataForm : function to serialize the fake form, just before sending all data serialized to the ajax call customer update
        */
        serializeGetDataForm: function() {
            var dataForm = J("#form-to-submit").serialize();
            return dataForm;
        },
        /**
        * CCB.qas.customerAjaxUpate : call the ajax page to update the customer form
        */
        customerAjaxUpate: function() {
            var dataForm = CCB.qas.serializeGetDataForm();

            /* BEGIN obe.2010.09.22 => fix for /checkout/layer_change_otheraddress.aspx */
            if (CCB.qas.page.formUrl == "/checkout/layer_change_otheraddress.aspx") {
                CCB.qas.page.ajaxCallUrl = CCB.qas.page.ajaxCallUrl + "&edit=true&time=" + Math.round(Math.random() * 1000);
            } else {
                CCB.qas.page.ajaxCallUrl = CCB.qas.page.ajaxCallUrl;
            }
            /* END obe.2010.09.22 => fix for /checkout/layer_change_otheraddress.aspx */


            J.post(CCB.qas.page.ajaxCallUrl, dataForm, function(data) {
                if (data.match('<input type="hidden" id="form-error" value="error" />') != null) {
                    CCB.qas.customerAjaxUpateError(data, "error");
                } else if (data.match('<input type="hidden" id="form-error" value="erroraccount" />') != null) {
                    CCB.qas.customerAjaxUpateError(data, "account");
                } else if ((data.match('<input type="hidden" id="form-success" value="true" />') != null) && ((data.match('<input type="hidden" id="form-error" value="error" />') == null) && (data.match('<input type="hidden" id="form-error" value="erroraccount" />') == null))) {
                    //If data updated success then, update EP QASValid depend on CCB.qas.flagValid and only if we are NOT on the @ delivery form
                    if ((CCB.qas.page.formUrl != "/checkout/layer_change_otheraddress.aspx") || (CCB.qas.page.formUrl != "/all_about_ccb/contact-customer-service.aspx")) {
                        if (CCB.qas.flagValid) {
                            if (CCB.qas.page.formUrl == "/services/catalog-request.aspx") {
                                J("#fakeFormCatalogRequest").append(J(data).filter("FORM").html());
                                var catalogRequestCuid = J("#fakeFormCatalogRequest").find("p#cuid").html();
                                var urlUpdateEP = CCB.Data.Site.Name + "/ajax/extpropupdate.aspx?property=QASValid&value=Y&cuid=" + catalogRequestCuid;
                            }
                            else {
                                var urlUpdateEP = CCB.Data.Site.Name + "/ajax/extpropupdate.aspx?property=QASValid&value=Y";
                            }
                            J.ajax({
                                type: "GET",
                                url: urlUpdateEP,
                                success: function() {
                                    CCB.qas.customerAjaxUpateSuccess();
                                },
                                error: function() {
                                    alert("error when processing!");
                                }
                            });
                        }
                        else {
                            if (NoAnswer == 1) {
                                if (CCB.qas.page.formUrl == "/services/catalog-request.aspx") {
                                    J("#fakeFormCatalogRequest").append(J(data).filter("FORM").html());
                                    var catalogRequestCuid = J("#fakeFormCatalogRequest").find("p#cuid").html();
                                    var urlUpdateEP = CCB.Data.Site.Name + "/ajax/extpropupdate.aspx?property=QASValid&value=N&cuid=" + catalogRequestCuid;
                                }
                                else {
                                    var urlUpdateEP = CCB.Data.Site.Name + "/ajax/extpropupdate.aspx?property=QASValid&value=N";
                                }
                            }
                            else {
                                if (CCB.qas.page.formUrl == "/services/catalog-request.aspx") {
                                    J("#fakeFormCatalogRequest").append(J(data).filter("FORM").html());
                                    var catalogRequestCuid = J("#fakeFormCatalogRequest").find("p#cuid").html();
                                    var urlUpdateEP = CCB.Data.Site.Name + "/ajax/extpropupdate.aspx?property=QASValid&value=C&cuid=" + catalogRequestCuid;
                                }
                                else {
                                    var urlUpdateEP = CCB.Data.Site.Name + "/ajax/extpropupdate.aspx?property=QASValid&value=C";
                                }
                            }
                            J.ajax({
                                type: "GET",
                                url: urlUpdateEP,
                                success: function() {
                                    CCB.qas.customerAjaxUpateSuccess();
                                },
                                error: function() {
                                    alert("error when processing!");
                                }
                            });
                        }
                    }
                }
                /* BEGIN obe.2010.09.22 => */
                else {
                    alert("error on updating data !");
                }
                /* END obe.2010.09.22 => */
            });
        },
        /**
        * CCB.qas.customerAjaxUpateSuccess : if the webbox of the ajax call page to update the customer form return a success
        */
        customerAjaxUpateSuccess: function() {
            CCB.qas.serializeDeleteForm();
            switch (CCB.qas.page.successType) {
                case "layer":
                    Shadowbox.open({ content: CCB.qas.page.successUrl, player: "iframe", height: CCB.qas.page.successUrlHeight, width: CCB.qas.page.successUrlWidth });
                    break;
                case "page":
                    CCB.Services.RedirectTo("parent", CCB.qas.page.successUrl);
                    break;
            }
        },
        /**
        * CCB.qas.customerAjaxUpateError : if the webbox of the ajax call page to update the customer form return an error
        */
        customerAjaxUpateError: function(data, typeError) {
            switch (CCB.qas.page.formType) {
                case "layer":
                    CCB.qas.page.formBackToFlag = typeError;
                    CCB.qas.page.formBackDataAjax = data;
                    Shadowbox.open({ content: CCB.qas.page.formUrl, player: "iframe", height: CCB.qas.page.formUrlHeight, width: CCB.qas.page.formUrlWidth });
                    break;
                case "page":
                    CCB.qas.page.formSelector.children().remove();
                    CCB.qas.page.formSelector.append(J(data).filter("FORM").html());
                    switch (typeError) {
                        case "error":
                            CCB.qas.page.formSelector.find("#form-msg").html(CCB.loctxt.error.checkredfield);
                            break;
                        case "account":
                            CCB.qas.page.formSelector.find("#form-msg").html(CCB.loctxt.error.checkexistingaccount);
                            break;
                    }
                    parent.Shadowbox.close();

                    CCB.Form.displayAddress(CCB.qas.page.formSelector);
                    CCB.Form.init(CCB.qas.page.formSelector);

                    //case of there is input[id$='loginNew']
                    if (CCB.qas.page.formSelector.find("input[id$='loginNew']").length > 0) {
                        CCB.qas.page.formSelector.find("input[id$='email']").blur(function() {
                            CCB.Customer.setLoginWithEmail();
                        });
                    }

                    CCB.qas.page.formSelector.find("#qas-submit").click(function() {
                        var isValidForm = CCB.Form.submitIsValid(CCB.qas.page.formSelector);
                        if (isValidForm) {
                            CCB.qas.serializeCreateForm(CCB.qas.page.formSelector);
                            CCB.qas.wsQasCall();
                        }
                        return false;
                    });


                    break;
            }
            CCB.qas.serializeDeleteForm();
            return false;
        },
        /**
        * CCB.qas.customerBackToForm : after the load of a QAS layer (qas_unknownaddress or qas_multipleaddress), if the customer decide to go back to the form to update some data
        */
        customerBackToForm: function() {
            switch (CCB.qas.page.formType) {
                case "layer":
                    CCB.qas.page.formBackToFlag = true;
                    Shadowbox.open({ content: CCB.qas.page.formUrl, player: "iframe", height: CCB.qas.page.formUrlHeight, width: CCB.qas.page.formUrlWidth });
                    break;
                case "page":
                    parent.Shadowbox.close();
                    parent.document.getElementById("static_line3").focus();
                    break;
            }
        },
        /**
        * CCB.qas.customerBackToFormDataRecovery : if the customer decide to go back to the form to update some data, if the form page is a layer, the data need to be recovered with the fake form
        */
        customerBackToFormDataRecovery: function() {
            var theForm = J("#form-to-submit");
            var formToRecover = CCB.qas.page.formSelector;
            //Set Value for Chrome and Firefox : remove with jQuery 1.4
            theForm.find("select,textarea,input[type=text],input[type=hidden],input[type=password]").each(function(i, e) {
                formToRecover.find("select,textarea,input[type=text],input[type=hidden],input[type=password]").eq(i).val(J(e).val());
            });
            theForm.find("input[type=checkbox],input[type=radio]").each(function(i, e) {
                formToRecover.find("input[type=checkbox],input[type=radio]").eq(i).attr("checked", J(e).attr("checked"));
            });
            CCB.qas.page.formBackToFlag = false;
            CCB.qas.serializeDeleteForm();
        }
    },
    //------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------
    //	CCB.ShadowBox
    //	Function relate to the ShadowBox
    //------------------------------------------------------------------------------------------------------
    ShadowBox: {
        state: false,
        refreshParent: false,
        open: function(element) {
            //alert("Open ShadowBox (step1)");
        },
        close: function(element) {
            //alert("Close ShadowBox");
            CCB.ShadowBox.state = false;
            CCB.Layout.inputTxt = "";
            if (CCB.ShadowBox.refreshParent) {
                parent.location.href = parent.location.href;
            }
        },
        change: function(element) {
            //alert("Change ShadowBox");
        },
        load: function(element) {
            //alert("Load ShadowBox (step2)");
            //J("#shadowbox_content").load(CCB.ShadowBox.loadContent);
            var content = J("#shadowbox_content").contents();
            J("#shadowbox_content").load(CCB.ShadowBox.loadContent);
            CCB.ShadowBox.loadContent();
            CCB.ShadowBox.state = true;
        },
        loadContent: function() {
            //alert("afterload ShadowBox  (step3)");
            //Launch CCB JavaScript Namespace Engine for ShadowBox layer
            var ccblayerjs = J("#shadowbox_content").contents().find("#ccbjs");
            if (CCB.Layer && ccblayerjs.length > 0) {
                var functions = ccblayerjs.val().split(" ");
                J.each(functions, function() {
                    var func = CCB.Layer[this];
                    if (typeof (func) == "function") { func.apply(); }
                    else if (CCB.debug) { /*alert("CCB.Layer." + this + " don't exist !!!");*/ }
                });
            }
            //Init close shadowbox on class btn_class click event
            J("#shadowbox_content").contents().find(".btn_close").click(function() { parent.Shadowbox.close(); });

        },
        clear: function() {
            //Shadowbox.clearCache();  /*=> generate IE6 BUG
            Shadowbox.setup();
        }
    },
    //------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------
    //	CCB.Layout
    //	Function relate to the Layout
    //------------------------------------------------------------------------------------------------------
    Layout: {
        inputTxtDefault: "",
        inputTxt: "",
        //INIT LAYOUT FUNCTION
        init: function() {

            CCB.conciergerie.init();

            //Input focus/blur update default text
            J("input[class*='hideTxt']").focus(function() {
                CCB.Layout.inputTxtDefault = J(this).val();
                J(this).val("");
            });
            J("input[class*='hideTxt']").keyup(function() {
                CCB.Layout.inputTxt = J(this).val();
            });
            J("input[class*='hideTxt']").blur(function() {
                CCB.Layout.inputTxt = J(this).val();
                if (J(this).val() == "") {
                    J(this).val(CCB.Layout.inputTxtDefault);
                }
            });

            //Ajout de la page aux Favoris. AP10022010
            J("#ajqbookmark").click(function(event) {
                event.preventDefault(); // prevent the anchor tag from sending the user off to the link
                var url = this.href;
                var title = J("TITLE").text();
                if (window.sidebar) { // Mozilla Firefox Bookmark
                    window.sidebar.addPanel(title, url, "");
                } else if (window.external) { // IE Favorite
                    window.external.AddFavorite(url, title);
                } else if (window.opera) { // Opera 7+
                    return false; // do nothing - the rel="sidebar" should do the trick
                } else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
                    alert('Malheureusement, ce browser ne supporte pas la fonction de bookmark');
                }
                return false;
            });

            J("input[id*='searchInput']").keyup(function() {			//Init search word
                CCB.loctxt.search.tofind = J(this).val();
            });
            J("a[id*='searchBt']").click(CCB.Services.GoToSearchPage);
            J("input[id*='searchBt']").click(CCB.Services.GoToSearchPage);
            J("a[id*='subprommail']").click(CCB.Services.NewsletterRegister);
            J("a[id*='subkeycode']").click(CCB.Services.KeyCodeLoad);


            // Keycode header field
            J("input[id*='inputsubkeycode']").keyup(function() {
                var keycodefield = J(this).val().toUpperCase().replace(" ", "");
                J(this).val(keycodefield);
            });

            //Find mini basket go to basket
            if (J("#minibasketgotobasket").length >= 1) {
                CCB.Services.RedirectTo("", "/checkout/shopping-card.aspx");
            }

            //Find div btn_panier of mini basket go to basket when user click
            J("#btn_panier").click(function() {
                CCB.Services.RedirectTo("", "/checkout/shopping-card.aspx");
            });

            //Find button "Finaliser votre commande" ;check if OpenSet is valid before go to checkout Identification Page
            J("a[id*='hrefvalidpanier']").click(function() {
                /*
                if (J("#offrespeciale_minipanier").length > 0) {
                Shadowbox.open({
                content: "/catalog/layer_open-set_basketerror.aspx?osid="+J("#opensetid").val(),
                player: "iframe",
                height: 380,
                width: 620
                });
                }
                else
                {CCB.Services.RedirectTo("","/checkout/identification.aspx?successurl=delivery.aspx");}
                */
                CCB.Services.RedirectTo("", "/checkout/identification.aspx?successurl=delivery.aspx");
            });

            //Find promoted price
            var parentselector = J("#col_centrale").contents();
            CCB.Services.PromotedPrice(parentselector);
            //old function : CCB.KeyListener.init();
            CCB.Services.KeyListener.onPage();
        }
    },
    //------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------
    //	CCB.Catalog
    //	Function relate to Catalog
    //------------------------------------------------------------------------------------------------------
    Catalog: {
        Product: {
            updatePrdSelectRef: function(parentselector, varcode) {
                parentselector.find("select#prd_selectref option").each(function() {
                    if (J(this).attr("value").split('#')[1] == varcode) {
                        J(this).attr('selected', 'selected');
                        parentselector.find("span.select_medium").html(J(this).attr("value").split('#')[2] + " " + varcode);
                    }
                    else {
                        J(this).attr('selected', '');
                    }
                });
            },
            updatePrdShade: function(parentselector) {
                parentselector.find("ul.cc_ficheproduit-details-palette a").removeClass("actif");
                parentselector.find("a[id='prd_shade" + CCB.Product.Info.VCode + "']").addClass("actif");
            },
            updatePrdImg: function(parentselector) {
                parentselector.find("#prd_img").attr("src", '/img/products/large/' + CCB.Product.Info.PCode + '_' + CCB.Product.Info.VCode + '_L.jpg');
                parentselector.find("#prd_zoom").attr("href", "/ajax/productzoom.aspx?pcode=" + CCB.Product.Info.PCode + "&varcode=" + CCB.Product.Info.VCode);
                CCB.ShadowBox.clear();
            },
            updatePrdBookmark: function() {
                J("#prd_bookmark").attr("href", '/customer/signed/layer_favoris_add.aspx?varcode=' + CCB.Product.Info.VCode);
                CCB.ShadowBox.clear();
            },
            updatePrdFriend: function() {
                J("#prd_friend").attr("href", '/customer/signed/layer_message_for_friend.aspx?varcode=' + CCB.Product.Info.VCode);
                CCB.ShadowBox.clear();
            },
            updatePrdStock: function(parentselector) {
                if (CCB.Product.Info.VStock > 100)
                    parentselector.find("span#prd_stock").html("Disponibilité : <strong>en stock</strong>");
                else if (CCB.Product.Info.VStock <= 100 && CCB.Product.Info.VStock > 0)
                    parentselector.find("span#prd_stock").html("Disponibilité : <strong>limitée</strong>");
                else
                    parentselector.find("span#prd_stock").html("Disponibilité : <strong>indisponible</strong>");
            },
            updatePrdCapacity: function(parentselector) {



                if (CCB.Product.Info.PEPCoefUM == "" || CCB.Product.Info.PEPCapacity == "" || CCB.Product.Info.PEPUnit == "") {
                    parentselector.find("span#prd_capacityprice").html("");
                }
                else {
                    var MontantMainPrice = CCB.Product.Info.VPriceMain.replace(/,/gi, ".");
                    MontantMainPrice = MontantMainPrice.replace(/\u20AC/gi, "");
                    MontantNewMainPrice = Math.round((parseFloat(MontantMainPrice) * parseFloat(CCB.Product.Info.PEPCoefUM.replace(/,/gi, "."))) * 100) / 100;
                    var MontantNewMainPriceAffich = new String(MontantNewMainPrice);
                    MontantNewMainPriceAffich = MontantNewMainPriceAffich.replace(".", ",");
                    parentselector.find("span#prd_capacityprice").html("Prix au " + CCB.Product.Info.PEPCapacity + CCB.Product.Info.PEPUnit + " : <strong>" + MontantNewMainPriceAffich + " €</strong>");
                }
            },
            updatePrdBtnBasket: function(parentselector) {
                if (CCB.Product.Info.VStock > 0) {
                    if (CCB.ShadowBox.state) {
                        //We are in shadowbox => layer select shade, the href add to basket is simple
                        //parentselector.find("p#prd_btnbasket a").attr("href", "/ajax/addproduct.aspx?varcode="+CCB.Product.Info.VCode+"&qty="+CCB.Product.Info.QtyToAdd).attr("rel", "").html("Ajouter au panier");
                        parentselector.find("p#prd_btnbasket").html("<a title='Ajouter au panier' href='/ajax/addproduct.aspx?varcode=" + CCB.Product.Info.VCode + "&qty=" + CCB.Product.Info.QtyToAdd + "'>Ajouter au panier</a>").fadeIn("slow");
                    }
                    else {
                        //We are in product page => the href add to basket is opened into shadowbox
                        //parentselector.find("p#prd_btnbasket a").attr("href", "/ajax/addproduct.aspx?varcode="+CCB.Product.Info.VCode+"&qty="+CCB.Product.Info.QtyToAdd).attr("rel", "shadowbox;width=622;height=450;title= ;").html("Ajouter au panier");
                        parentselector.find("p#prd_btnbasket").html("<a title='Ajouter au panier' rel='shadowbox;width=622;height=450;title= ' href='/ajax/addproduct.aspx?varcode=" + CCB.Product.Info.VCode + "&qty=" + CCB.Product.Info.QtyToAdd + "'>Ajouter au panier</a>").fadeIn("slow");
                        CCB.ShadowBox.clear();
                    }
                    parentselector.find("p#prd_btnbasket").attr("class", "cc_ficheproduit-ajouterpanier");
                }
                else {
                    parentselector.find("p#prd_btnbasket").html("Produit indisponible").fadeIn("slow");
                    parentselector.find("p#prd_btnbasket").attr("class", "cc_ficheproduit-indisponible-btn");
                }
            },
            updatePrdBtnOpenSet: function(parentselector) {
                parentselector.find("input[id*='opensetvar']").val(CCB.Product.Info.VCode);
                if (CCB.ShadowBox.state) {
                    parentselector.find("p[id*='opensetbtn']").css("visibility", "hidden");
                    if (CCB.Product.Info.VStock > 0) {
                        if (CCB.Product.Info.VOpenSet.length > 0) {
                            CCB.Product.Info.VOpenSet.split("/").each(function(i) {
                                parentselector.find("p[id='opensetbtn" + i + "']").css("visibility", "visible");
                            });
                        }
                    }
                } else {
                    parentselector.find("p[id*='opensetbtn']").css("display", "none");
                    if (CCB.Product.Info.VStock > 0) {
                        if (CCB.Product.Info.VOpenSet.length > 0) {
                            CCB.Product.Info.VOpenSet.split("/").each(function(i) {
                                parentselector.find("p[id='opensetbtn" + i + "']").css("display", "inline");
                            });
                        }
                    }
                }
            },
            updatePrdPrice: function(parentselector) {
                if (CCB.Product.Info.VPriceNew != null && CCB.Product.Info.VPriceNew != "" && CCB.Product.Info.VPriceNew != "0,00 €" && CCB.Product.Info.VPriceNew != CCB.Product.Info.VPriceMain) {
                    //Promo Price
                    if (ComputePromotion(CCB.Product.Info.VPriceUnit, CCB.Product.Info.VPriceNew) == 'Prix special') {
                        parentselector.find("p#prd_pricepromo").attr("class", "cc_ficheproduit-promo").html(ComputePromotion(CCB.Product.Info.VPriceUnit, CCB.Product.Info.VPriceNew));
                    }
                    else {
                        parentselector.find("p#prd_pricepromo").attr("class", "cc_ficheproduit-promo").html("-" + ComputePromotion(CCB.Product.Info.VPriceUnit, CCB.Product.Info.VPriceNew) + "<span>%</span>");
                    }
                    parentselector.find("p#prd_price").attr("class", "cc_ficheproduit-prix").html(CCB.Product.Info.VPriceNew);
                    parentselector.find("p#prd_pricemain").attr("class", "cc_ficheproduit-prixbarre").html(CCB.Product.Info.VPriceUnit);
                    var reduc = parseFloat(CCB.Product.Info.VPriceUnit.replace(",", ".")) - parseFloat(CCB.Product.Info.VPriceNew.replace(",", "."));
                    var affichreduc = (reduc.toFixed(2) + "").replace(".", ",");
                    parentselector.find("p#prd_pricesave").attr("class", "cc_ficheproduit-economie").html("Vous économisez " + affichreduc + " €");
                    var pourcentage = ComputePromotion(CCB.Product.Info.VPriceUnit, CCB.Product.Info.VPriceNew);
                    //alert(pourcentage);
                    if (pourcentage == '95') {
                        parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_65-95');
                    }
                    else if (pourcentage == '90')
                    { parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_65-95'); }
                    else if (pourcentage == '85')
                    { parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_65-95'); }
                    else if (pourcentage == '80')
                    { parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_65-95'); }
                    else if (pourcentage == '75')
                    { parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_65-95'); }
                    else if (pourcentage == '70')
                    { parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_65-95'); }
                    else if (pourcentage == '65')
                    { parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_65-95'); }
                    else if (pourcentage == '60')
                    { parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_60'); }
                    else if (pourcentage == '55')
                    { parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_55'); }
                    else if (pourcentage == '50')
                    { parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_50'); }
                    else if (pourcentage == '45')
                    { parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_45'); }
                    else if (pourcentage == '40')
                    { parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_40'); }
                    else if (pourcentage == '35')
                    { parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_35'); }
                    else if (pourcentage == '30')
                    { parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_30'); }
                    else if (pourcentage == '25')
                    { parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_25'); }
                    else if (pourcentage == '20')
                    { parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_10-15-20'); }
                    else if (pourcentage == '15')
                    { parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_10-15-20'); }
                    else if (pourcentage == '10')
                    { parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_10-15-20'); }
                    else if (pourcentage == '5')
                    { parentselector.find("p[class*='cc_ficheproduit-promo']").removeClass('cc_ficheproduit-promo').addClass('reduc_L_10-15-20'); }

                }
                else if (CCB.Product.Info.PEPBlue == 1) {
                    //Blue Price
                    parentselector.find("p#prd_pricepromo").attr("class", "cc_ficheproduit-nopromo").html("");
                    parentselector.find("p#prd_price").attr("class", "cc_ficheproduit-prixbleu").html(CCB.Product.Info.VPriceMain);
                    parentselector.find("p#prd_pricemain").removeClass().html("");
                    parentselector.find("p#prd_pricesave").removeClass().html("");
                }
                else if (CCB.Product.Info.VOpenSet.length > 0) {
                    //Open set Price
                    parentselector.find("p#prd_pricepromo").attr("class", "cc_ficheproduit-promo_offre").html("Offre<span> spéciale</span>");
                    parentselector.find("p#prd_price").attr("class", "cc_ficheproduit-prix").html(CCB.Product.Info.VPriceMain);
                    parentselector.find("p#prd_pricemain").removeClass().html("");
                    parentselector.find("p#prd_pricesave").removeClass().html("");
                }
                else {
                    //Normal Price
                    parentselector.find("p#prd_pricepromo").attr("class", "cc_ficheproduit-nopromo").html("");
                    parentselector.find("p#prd_price").attr("class", "cc_ficheproduit-prix").html(CCB.Product.Info.VPriceMain);
                    parentselector.find("p#prd_pricemain").removeClass().html("");
                    parentselector.find("p#prd_pricesave").removeClass().html("");
                }
            },
            updateEcoTaxe: function(parentselector) {
                if (CCB.Product.Info.PEPEcoTaxe != "") {
                    parentselector.find("p#prd_ecotaxe").html("Eco-participation : " + CCB.Product.Info.PEPEcoTaxe + " €");
                }
                else {
                    //Pas de Eco-partivcipation
                    parentselector.find("p#prd_ecotaxe").html("&nbsp;");
                }
            },
            updateAssociationInfo: function() {
                J.ajax({
                    type: "GET",
                    url: "/ajax/productassociation.aspx",
                    data: "varcode=" + CCB.Product.Info.VCode, //+"&time"+Math.round(Math.random()*1000), 
                    success: function(msg) {
                        if (msg.length > 0) {
                            J("#slideCrossSelling").css("display", "inline");
                            J('#cc_relationsproduits-xhr').html(msg);

                            //-> DEBUT voir JIRA AICCBFR-91
                            J('#cc_relationsproduits-xhr').find("div[class='rp_resultat']").each(function(i) {
                                if (J(this).find("input").length > 0) {
                                    var fullPrice = J(this).find("input").attr("value").split('#')[0];
                                    var promoPrice = J(this).find("input").attr("value").split('#')[1];
                                    J(this).find("p.rp_promo").html(CCB.Services.ComputeAndDisplayPromotion(fullPrice.StringToCurrency(), promoPrice.StringToCurrency()));
                                    J(this).find("p.rp_economie").html("Vous économisez " + CCB.Services.WriteReduc(fullPrice.StringToCurrency(), promoPrice.StringToCurrency()).CurrencyToString("2", "€"));

                                    var pourcentage = CCB.Services.ComputeAndDisplayPromotion(fullPrice.StringToCurrency(), promoPrice.StringToCurrency());
                                    //alert(pourcentage);
                                    if (pourcentage == '-95<span>%</span>') {
                                        J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_65-95');
                                    }
                                    else if (pourcentage == '-90<span>%</span>')
                                    { J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_65-95'); }
                                    else if (pourcentage == '-85<span>%</span>')
                                    { J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_65-95'); }
                                    else if (pourcentage == '-80<span>%</span>')
                                    { J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_65-95'); }
                                    else if (pourcentage == '-75<span>%</span>')
                                    { J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_65-95'); }
                                    else if (pourcentage == '-70<span>%</span>')
                                    { J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_65-95'); }
                                    else if (pourcentage == '-65<span>%</span>')
                                    { J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_65-95'); }
                                    else if (pourcentage == '-60<span>%</span>')
                                    { J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_60'); }
                                    else if (pourcentage == '-55<span>%</span>')
                                    { J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_55'); }
                                    else if (pourcentage == '-50<span>%</span>')
                                    { J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_50'); }
                                    else if (pourcentage == '-45<span>%</span>')
                                    { J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_45'); }
                                    else if (pourcentage == '-40<span>%</span>')
                                    { J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_40'); }
                                    else if (pourcentage == '-35<span>%</span>')
                                    { J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_35'); }
                                    else if (pourcentage == '-30<span>%</span>')
                                    { J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_30'); }
                                    else if (pourcentage == '-25<span>%</span>')
                                    { J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_25'); }
                                    else if (pourcentage == '-20<span>%</span>')
                                    { J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_10-15-20'); }
                                    else if (pourcentage == '-15<span>%</span>')
                                    { J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_10-15-20'); }
                                    else if (pourcentage == '-10<span>%</span>')
                                    { J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_10-15-20'); }
                                    else if (pourcentage == '-5<span>%</span>')
                                    { J(this).find("p[class*='rp_promo']").removeClass('rp_promo').addClass('rp_reduc_M_10-15-20'); }
                                }
                            });
                            //-> FIN voir JIRA AICCBFR-91

                            //Find and decode hidden link (javascriptage) on "/ajax/productassociation.aspx"
                            J('#cc_relationsproduits-xhr').find("span[class^=concierge]").each(function() {
                                var attrib = this.className.split(" ");
                                var url = CCB.conciergerie.decode(attrib[0].substring(9));
                                $this = jQuery(this);
                                $this
										.after("<a></a>").next()
										.attr("class", $this.attr("class")).removeClass(attrib[0])
										.attr("id", $this.attr("id"))
										.attr("href", url)
										.html($this.html());
                                if ($this.attr("title").length > 0)
                                    $this.next().attr("title", $this.attr("title"));
                                if ($this.attr("rel") != null && $this.attr("rel").length > 0)
                                    $this.next().attr("rel", $this.attr("rel"));
                                $this.remove();
                                CCB.ShadowBox.clear();
                            });


                        }
                        else {
                            J("#slideCrossSelling").css("display", "none");
                            J('#cc_relationsproduits-xhr').html(msg);
                        }
                        CCB.ShadowBox.clear();
                    }
                });
            },
            updateProductInfo: function(parentselector) {
                CCB.Product = CCB.Product || {};
                J.extend(CCB.Product, {
                    Info: {
                        PCode: parentselector.find("select#prd_selectref option:selected").attr("value").split('#')[0],
                        VCode: parentselector.find("select#prd_selectref option:selected").attr("value").split('#')[1],
                        VName: parentselector.find("select#prd_selectref option:selected").attr("value").split('#')[2],
                        VStock: parentselector.find("select#prd_selectref option:selected").attr("value").split('#')[3],
                        VPriceMain: parentselector.find("select#prd_selectref option:selected").attr("value").split('#')[4],
                        VPriceNew: parentselector.find("select#prd_selectref option:selected").attr("value").split('#')[5],
                        VPriceUnit: parentselector.find("select#prd_selectref option:selected").attr("value").split('#')[6],
                        PEPBlue: parentselector.find("select#prd_selectref option:selected").attr("value").split('#')[7],
                        PEPEcoTaxe: parentselector.find("select#prd_selectref option:selected").attr("value").split('#')[8],
                        PEPCoefUM: parentselector.find("select#prd_selectref option:selected").attr("value").split('#')[9],
                        PEPCapacity: parentselector.find("select#prd_selectref option:selected").attr("value").split('#')[10],
                        PEPUnit: parentselector.find("select#prd_selectref option:selected").attr("value").split('#')[11],
                        PEPTopSalesNew: parentselector.find("select#prd_selectref option:selected").attr("value").split('#')[12],
                        PEPTopSales: parentselector.find("select#prd_selectref option:selected").attr("value").split('#')[13],
                        PEPNew: parentselector.find("select#prd_selectref option:selected").attr("value").split('#')[14],
                        VEPNew: parentselector.find("select#prd_selectref option:selected").attr("value").split('#')[15],
                        VOpenSet: (!parentselector.find("select#prd_selectref option:selected").attr("value").split('#')[16]) ? "" : parentselector.find("select#prd_selectref option:selected").attr("value").split('#')[16],
                        QtyToAdd: parentselector.find("select[id*='prd_selectqty']").val()
                    }
                });
            }
        }
    },
    //------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------
    //	CCB.Customer
    //	Function relate to Customer
    //------------------------------------------------------------------------------------------------------
    Customer: {
        setLoginWithEmail: function() {
            if (CCB.ShadowBox.state) {
                var parentselector = J("#shadowbox_content").contents();
                parentselector.find("input[id$='loginNew']").val(parentselector.find("input[id$='email']").val());
            } else {
                J("input[id$='loginNew']").val(J("input[id$='email']").val());
            }
        }
    },
    //------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------
    //	CCB.Form
    //	Function relate to Form
    //------------------------------------------------------------------------------------------------------
    Form: {
        /**
        * CCB.Form.init : Validate a form on the ready page, display red cross is field is wrong, or green ico is field is correct ; set focus, blur and keyup field function
        * @param parentselector : This is the selector contain the form to valid (can be a div inside a simple html page or a div containt layer iframe shadowbox)
        */
        init: function(parentselector) {
            CCB.Form.checkCityList(parentselector);
            parentselector.find("input.validate").each(function(i) {
                var obj = J(this);
                var isError = CCB.Form.checkblank(obj.val());
                if (!isError) {
                    var userFieldPos = CCB.Form.SearchFieldPosition(obj);
                    if (userFieldPos == 2 || userFieldPos == 3 || userFieldPos == 4 || userFieldPos == 17 || userFieldPos == 19) {
                        isError = CCB.Form.checkSpecialField(parentselector, obj, userFieldPos);
                    }
                    else {
                        isError = (!obj.val().match(CCB.locexpusein.field.user[userFieldPos])) ? true : false;
                    }
                }
                CCB.Form.displayFormValidateInfo(obj, isError);
            });

            CCB.Form.setRedBorder();
            parentselector.find("input[id*='lname']").focus();

            parentselector.find("input.validate").focus(function() {
                CCB.Form.fieldFocus(parentselector, J(this));
            });
            parentselector.find("input.validate").keyup(function() {
                CCB.Form.fieldKeyup(parentselector, J(this));
            });
            parentselector.find("input.validate").blur(function() {
                CCB.Form.fieldBlur(parentselector, J(this));
            });

        },
        /**
        * CCB.Form.fieldFocus : on focus field, if tooltip is displayed > remove it
        * @param parentselector : Selector contain the form to valid
        * @param obj : current field
        */
        fieldFocus: function(parentselector, obj) {
            if (CCB.ShadowBox.state) {
                var myIdDivError = parentselector.find("div#Error_" + obj.attr("id"));
            }
            else {
                var myIdDivError = J("div#Error_" + obj.attr("id"));
            }
            if (myIdDivError.length > 0) {
                CCB.Form.removeToolTip(myIdDivError);
            }
        },
        /**
        * CCB.Form.fieldKeyup : on keyup field, if length field > 1, check if error and display red cross (field wrong) or green ico (field correct)
        * @param parentselector : Selector contain the form to valid
        * @param obj : current field
        */
        fieldKeyup: function(parentselector, obj) {
            var isError = false;
            if (obj.val().length > 1) {
                var userFieldPos = CCB.Form.SearchFieldPosition(obj);

                if (userFieldPos == 2 || userFieldPos == 3 || userFieldPos == 4 || userFieldPos == 17 || userFieldPos == 19) {
                    isError = CCB.Form.checkSpecialField(parentselector, obj, userFieldPos);
                }
                else { //Cas ok
                    isError = (!obj.val().match(CCB.locexpusein.field.user[userFieldPos])) ? true : false;
                }
                CCB.Form.displayFormValidateInfo(obj, isError);
            }
        },
        /**
        * CCB.Form.fieldBlur : on blur field, if length field > 1, check if error and display red cross and tooltip (field wrong) or green ico (field correct)
        * @param parentselector : Selector contain the form to valid
        * @param obj : current field
        */
        fieldBlur: function(parentselector, obj) {
            var isError = false;
            if (obj.val().length >= 1) {
                var userFieldPos = CCB.Form.SearchFieldPosition(obj);
                if (userFieldPos == 2 || userFieldPos == 3 || userFieldPos == 4 || userFieldPos == 17 || userFieldPos == 19) {
                    isError = CCB.Form.checkSpecialField(parentselector, obj, userFieldPos);
                }
                else {
                    isError = (!obj.val().match(CCB.locexpusein.field.user[userFieldPos])) ? true : false;
                }
                if (userFieldPos == 2 || userFieldPos == 3 || userFieldPos == 4)
                    CCB.Form.displayFormValidateInfo(obj, isError);
                else
                    CCB.Form.displayFormValidateInfo(obj, isError, userFieldPos, true);
            }
            else {
                CCB.Form.setRedCross(obj);
            }
        },
        /**
        * CCB.Form.submitIsValid : on submit form, check all field (with class="validate"), if wrong => display red cross and tooltip, if correct => display green ico
        * @param parentselector : Selector contain the form to valid
        * @return isValid : TRUE if no field error was found, FALSE if at least one error was found
        */
        submitIsValid: function(parentselector) {
            var isValid = true;
            var isErrorBirthDate = false;

            //1.remove all tooltip error
            if (CCB.ShadowBox.state) {
                var myIdDivError = parentselector.find("div[id*='Error_']");
            }
            else {
                var myIdDivError = J("body").find("div[id*='Error_']");
            }
            if (myIdDivError.length > 0) {
                CCB.Form.removeToolTip(myIdDivError);
            }


            //2. Loop to check all input with class .validate
            parentselector.find("input.validate").each(function(i) {
                var obj = J(this);
                var isError = CCB.Form.checkblank(obj.val()); //true if blank field
                var userFieldPos = CCB.Form.SearchFieldPosition(obj);

                if (userFieldPos == 14) {	//field address_city (if webbox found multiple city for specific zip code then a select is displayed
                    if (parentselector.find("select[id*='customer_citylist']").css("display") == "none") {
                        if (isError) {
                            CCB.Form.setToolTip(obj, CCB.loctxt.field.blank);
                            CCB.Form.setRedCross(obj);
                        }
                        else {
                            isError = (!obj.val().match(CCB.locexpusein.field.user[userFieldPos])) ? true : false;
                            CCB.Form.displayFormValidateInfo(obj, isError, userFieldPos, true);
                        }
                    }
                    else {
                        objList = parentselector.find("input[id*='address_city']");
                        isError = (objList.val() == "") ? true : false;
                        if (isError) {
                            CCB.Form.setToolTip(obj, CCB.loctxt.field.blank);
                            CCB.Form.setRedCross(obj);
                        }
                        else {
                            CCB.Form.setGreenCross(objList);
                        }
                    }
                }
                else if (isError) {
                    CCB.Form.setToolTip(obj, CCB.loctxt.field.blank);
                    CCB.Form.setRedCross(obj);
                }
                else {
                    if (userFieldPos == 2 || userFieldPos == 3 || userFieldPos == 4) { //field birthdate
                        isError = CCB.Form.checkSpecialField(parentselector, obj, userFieldPos);
                        if (isError) {
                            isErrorBirthDate = true;
                        }
                        CCB.Form.displayFormValidateInfo(parentselector.find("input[id*='birthday']"), isErrorBirthDate, "2", true);
                    }
                    else if (userFieldPos == 17 || userFieldPos == 19) { //field specific
                        isError = CCB.Form.checkSpecialField(parentselector, obj, userFieldPos);
                        CCB.Form.displayFormValidateInfo(obj, isError, userFieldPos, true);
                    }
                    else {//field normal (check corresponding regex)
                        isError = (!obj.val().match(CCB.locexpusein.field.user[userFieldPos])) ? true : false;
                        CCB.Form.displayFormValidateInfo(obj, isError, userFieldPos, true);
                    }
                }

                //if isError is true, then generic var isValid (form) is false			
                if (isError)
                    isValid = false;
            });
            //Specific case in delivery post 24 :
            if ((parentselector.find("input#checklaposte24").length > 0) || (parentselector.find("input#otherposte24").length > 0)) {
                isError = CCB.Form.prohibitedDeliveryZip(parentselector.find("input[id*='address_zip']"));
                if (isValid && isError) {
                    isValid = false;
                }
            }
            //3. if isValid (form) is false, return false
            return isValid;
        },
        /**
        * Get the birthdate from the 3 birth field (year, month, day)
        * @param parentselector : This is the selector contain the form to valid (can be a div inside a simple html page or a div containt layer iframe shadowbox)
        * @param obj : This is the object field
        * @param userFieldPos : Position of the field selected (corresponding the array CCB.locvar.field.used (ccb.loc.js))
        * @param showToolTip : Boolean to know if tooltip have to be displayed
        * @return isValidSpecial
        */
        checkSpecialField: function(parentselector, obj, userFieldPos) {
            var isError = false;
            var isErrorDay = false;
            var isErrorMonth = false;
            var isErrorYear = false;
            switch (userFieldPos) {
                case 2: 	//birthdate day
                    var myBirthDay = CCB.Form.getBirthDay();
                    isError = ((myBirthDay >= 1) && (myBirthDay <= 31)) ? false : true;
                    isErrorDay = ((myBirthDay >= 1) && (myBirthDay <= 31)) ? false : true;
                    break;
                case 3: 	//birthdate month
                    var myBirthMonth = CCB.Form.getBirthMonth();
                    isError = ((myBirthMonth >= 1) && (myBirthMonth <= 12)) ? false : true;
                    isErrorMonth = ((myBirthMonth >= 1) && (myBirthMonth <= 12)) ? false : true;
                    break;
                case 4: 	//birthdate year
                    var myBirthYear = CCB.Form.getBirthYear();
                    isError = ((myBirthYear >= 1920) && (myBirthYear <= 2000)) ? false : true;
                    isErrorYear = ((myBirthYear >= 1920) && (myBirthYear <= 2000)) ? false : true;
                    break;
                case 17: 	//ad_form > search footer
                    var mail1 = parentselector.find("input[id*='email']").val();
                    isError = (mail1 == obj.val()) ? false : true;
                    break;
                case 19: 	//smd_box > newsletter footer
                    var pass1 = parentselector.find("input[id*='password']").val();
                    isError = (pass1 == obj.val()) ? false : true;
                    break;
            }
            if ((isErrorDay == true) || (isErrorMonth == true) || (isErrorYear == true)) {
                return true;
            }
            else {
                return isError;
            }
        },
        /**
        * CCB.Form.displayFormValidateInfo : display the form javascript validation info (cross, tooltip)
        * @param obj : This is the object field
        * @param isError : Boolean to know if the field is wrong (true) or not (false)
        * @param userFieldPos : Position of the field selected (corresponding the array CCB.locvar.field.used (ccb.loc.js))
        * @param showToolTip : Boolean to know if tooltip have to be displayed
        */
        displayFormValidateInfo: function(obj, isError, userFieldPos, showToolTip) {
            if (isError) {
                CCB.Form.setRedCross(obj);
                if (showToolTip)
                    CCB.Form.setToolTip(obj, CCB.loctxt.field.user[userFieldPos]);
            } else {
                CCB.Form.setGreenCross(obj);
            }
        },
        /**
        * CCB.Form.checkblank :check if field value is blank (remove space before check)
        * @param input : value of the field input
        * @return boolean : false if field value is empty, true if field value is not empty
        */
        checkblank: function(input) {
            return (input.replace(/^\s*|\s*$/g, '') == '') ? true : false;
        },
        /**
        * CCB.Form.checkregex : check if field value match with a regex
        * @param input : value of the field input
        * @param regex : value of the regex
        * @return boolean : true if field value match with regex if not false
        */
        checkregex: function(input, regex) {
            return (!input.match(regex)) ? false : true;
        },
        /**
        * CCB.Form.SearchFieldPosition : search the corresponding position of a field from array CCB.locvar.field.user (ccb.loc.js)
        * @param obj : the field object
        * @return myPosition : the position of the field into array CCB.locvar.field.user (ccb.loc.js)
        */
        SearchFieldPosition: function(obj) {
            var myId = obj.attr("id");
            var myPosition;
            J.each(CCB.locvar.field.user, function(i) {
                if (myId.match(this)) {
                    //check specific user field case
                    switch (i) {
                        case 16: 	//as "email_conf" (CCB.locvar.field.user[17]) contain "email" (CCB.locvar.field.user[16])
                            if (myId.match(CCB.locvar.field.user[i + 1]))
                                i = i + 1;
                        case 18: 	//s "password_conf" (CCB.locvar.field.user[19]) contain "password" (CCB.locvar.field.user[18])
                            if (myId.match(CCB.locvar.field.user[i + 1]))
                                i = i + 1;
                            break;
                    }
                    myPosition = i;
                }
            });
            return myPosition;
        },
        /**
        * CCB.Form.getBirthDate : Get the birthdate from the 3 birth field (year, month, day)
        * @return myBirthDate : This is the birthdate
        */
        getBirthDate: function() {
            var myBirthDate;
            if (CCB.ShadowBox.state) {
                var parentselector = J("#shadowbox_content").contents();
                myBirthDate = parentselector.find("input[id*='birthyear']").val() + "-" + parentselector.find("input[id*='birthmonth']").val() + "-" + parentselector.find("input[id*='birthday']").val();
            }
            else {
                myBirthDate = J("input[id*='birthyear']").val() + "-" + J("input[id*='birthmonth']").val() + "-" + J("input[id*='birthday']").val();
            }
            return myBirthDate;
        },
        getBirthDay: function() {
            var myBirthDay;
            if (CCB.ShadowBox.state) {
                var parentselector = J("#shadowbox_content").contents();
                myBirthDay = parentselector.find("input[id*='birthday']").val();
            }
            else {
                myBirthDay = J("input[id*='birthday']").val();
            }
            return myBirthDay;
        },
        getBirthMonth: function() {
            var myBirthMonth;
            if (CCB.ShadowBox.state) {
                var parentselector = J("#shadowbox_content").contents();
                myBirthMonth = parentselector.find("input[id*='birthmonth']").val();
            }
            else {
                myBirthMonth = J("input[id*='birthmonth']").val();
            }
            return myBirthMonth;
        },
        getBirthYear: function() {
            var myBirthYear;
            if (CCB.ShadowBox.state) {
                var parentselector = J("#shadowbox_content").contents();
                myBirthYear = parentselector.find("input[id*='birthyear']").val();
            }
            else {
                myBirthYear = J("input[id*='birthyear']").val();
            }
            return myBirthYear;
        },

        /**
        * CCB.Form.setToolTip : Display a tooltip on a wrong field (the tooltip can be displayed on a normal field page or on a shadowbox field layer)
        * @param obj : This is the object field
        * @param msg : This is the message to display
        */
        setToolTip: function(obj, msg) {
            var myId = obj.attr("id");
            if (CCB.ShadowBox.state) {
                var parentselector = J("#shadowbox_content").contents();
                var myIdDivError = parentselector.find("div#Error_" + myId);
                if (myIdDivError.length == 0) {
                    //ToolTip construction in SHADOWBOX LAYER
                    parentselector.find("body").append('<div class="formError blackPopup" id="Error_' + myId + '"></div>');
                    parentselector.find("div#Error_" + myId).css("opacity", "0");
                    parentselector.find("div#Error_" + myId).append('<div class="formErrorContent"></div>');
                    parentselector.find("div#Error_" + myId + " div.formErrorContent").html(msg);
                    parentselector.find("div#Error_" + myId + " div.formErrorContent").append('<img src="/img/common/customer/close.png">');
                    parentselector.find("div#Error_" + myId).append('<div class="formErrorArrow"></div>');
                    parentselector.find("div#Error_" + myId + " div.formErrorArrow").html('<div class="line10"><!-- --></div><div class="line9"><!-- --></div><div class="line8"><!-- --></div><div class="line7"><!-- --></div><div class="line6"><!-- --></div><div class="line5"><!-- --></div><div class="line4"><!-- --></div><div class="line3"><!-- --></div><div class="line2"><!-- --></div><div class="line1"><!-- --></div>');

                    //ToolTip Positionning
                    var objPos = CCB.Services.findPos(obj.get(0));
                    var inputWidth = parentselector.find("#" + myId).width();
                    var inputHeight = parentselector.find("#" + myId).height();
                    var tooltipWidth = parentselector.find("div#Error_" + myId).width();
                    var tooltipHeigth = parentselector.find("div#Error_" + myId).height();
                    var curtop = objPos.y - tooltipHeigth - 3;
                    var curleft = objPos.x;
                    parentselector.find("div#Error_" + myId).css("top", curtop).css("left", curleft).animate({ opacity: '0.87' });
                }
                CCB.Form.closeToolTip();
            } else {
                //ToolTip construction in NORMAL PAGE
                var myIdDivError = J("div#Error_" + myId);
                if (myIdDivError.length == 0) {
                    J("body").append('<div class="formError blackPopup" id="Error_' + myId + '"></div>');
                    J("div#Error_" + myId).css("opacity", "0");
                    J("div#Error_" + myId).append('<div class="formErrorContent"></div>');
                    J("div#Error_" + myId + " div.formErrorContent").html(msg);
                    J("div#Error_" + myId + " div.formErrorContent").append('<img src="/img/common/customer/close.png">');
                    J("div#Error_" + myId).append('<div class="formErrorArrow"></div>');
                    J("div#Error_" + myId + " div.formErrorArrow").html('<div class="line10"><!-- --></div><div class="line9"><!-- --></div><div class="line8"><!-- --></div><div class="line7"><!-- --></div><div class="line6"><!-- --></div><div class="line5"><!-- --></div><div class="line4"><!-- --></div><div class="line3"><!-- --></div><div class="line2"><!-- --></div><div class="line1"><!-- --></div>');

                    //ToolTip Positionning
                    var objPos = CCB.Services.findPos(obj.get(0));
                    var inputWidth = J("#" + myId).width();
                    var inputHeight = J("#" + myId).height();
                    var tooltipWidth = J("div#Error_" + myId).width();
                    var tooltipHeigth = J("div#Error_" + myId).height();
                    var curtop = objPos.y - tooltipHeigth - 3;
                    var curleft = objPos.x;
                    J("div#Error_" + myId).css("top", curtop).css("left", curleft).animate({ opacity: '0.87' });
                }
                CCB.Form.closeToolTip();
            }
        },
        /**
        * CCB.Form.closeToolTip : Close tooltip from a wrong field by clicking on the div tooltip
        */
        closeToolTip: function() {
            if (CCB.ShadowBox.state) {
                var parentselector = J("#shadowbox_content").contents();
                parentselector.find("div.formErrorContent").click(function() {
                    CCB.Form.removeToolTip(J(this).parent(".formError"));
                });
            } else {
                J("div.formErrorContent").click(function() {
                    CCB.Form.removeToolTip(J(this).parent(".formError"));
                });
            }
        },
        /**
        * CCB.Form.removeToolTip : Remove tooltip from a wrong field
        * @param obj : This is the object field
        */
        removeToolTip: function(obj) {
            obj.remove();
        },
        /**
        * CCB.Form.setRedCross : Set red cross next to a wrong field
        * @param obj : This is the object field
        */
        setRedCross: function(obj) {
            if (obj.siblings("span.true").length > 0) {
                obj.siblings("span.true").attr("class", "false");
            }
            else {
                obj.parent().siblings("span.true").attr("class", "false");
            }
        },
        /**
        * CCB.Form.setGreenCross : Set green cross next to a valid field
        * @param obj : This is the object field
        */
        setGreenCross: function(obj) {
            if (obj.siblings("span.false").length > 0) {
                obj.siblings("span.false").attr("class", "true");
            }
            else {
                obj.parent().siblings("span.false").attr("class", "true");
            }
        },
        /**
        * CCB.Form.setRedBorder : Set red border onfocus of input type text
        */
        setRedBorder: function() {
            if (CCB.ShadowBox.state) {
                var parentselector = J("#shadowbox_content").contents();
                parentselector.find(":text").focus(function() {
                    J(this).attr("style", "border:1px solid #ff0000");
                });
                parentselector.find(":text").blur(function() {
                    J(this).attr("style", "border:1px solid #000000");
                });
            } else {
                J(":text").focus(function() {
                    J(this).attr("style", "border:1px solid #ff0000");
                });
                J(":text").blur(function() {
                    J(this).attr("style", "border:1px solid #000000");
                });
            }
        },
        /**
        * CCB.Form.checkTypeVoie : Check if field customer_address_option value is AUTRE, if yes, then field customer_address_other is enabled
        * @param parentselector : This is the selector contain the form to valid (can be a div inside a simple html page or a div containt layer iframe shadowbox)
        * WARNING : not used with QAS
        */
        checkTypeVoie: function(parentselector) {
            var myTypeVoie = parentselector.find("input[id$='address_line2']").val();

            if (myTypeVoie.length > 0) {
                var findTypeVoie = false;
                var optionSelectTypeVoie = parentselector.find("select[id$='customer_address_option'] option");

                optionSelectTypeVoie.each(function(i) {
                    if (myTypeVoie == J(this).attr("value")) {
                        J(this).attr("selected", "selected");
                        J.each(CCB.locvar.field.typevoie, function() {
                            if (myTypeVoie == this) {
                                findTypeVoie = true;
                            }
                        });
                    }
                    if ((optionSelectTypeVoie.length == i + 1) && (!findTypeVoie)) {
                        J(this).attr("selected", "selected");
                        parentselector.find("input[id$='customer_address_other']").attr("disabled", "").val(myTypeVoie);
                    }
                });
            }

            //On change Select Type de Voie, if AUTRE, enabler customer_address_other fake field, else, update customer_address_line2 with the value of the option selected
            parentselector.find("select[id$='customer_address_option']").change(function() {
                if (J(this).val() == "AUTRE") {
                    parentselector.find("input[id$='customer_address_other']").attr("disabled", "");
                }
                else {
                    parentselector.find("input[id$='customer_address_other']").val("").attr("disabled", "disabled");
                    parentselector.find("input[id$='address_line2']").val(J(this).val());
                }
            });

            //Update customer_address_line2 field with the value of the customer_address_other fake field
            parentselector.find("input[id$='customer_address_other']").keyup(function() {
                parentselector.find("input[id$='address_line2']").val(J(this).val());
            });
        },
        /**
        * CCB.Form.checkCityList : Check if the select field customer_citylist contain some <option>, if not, then the city field is address_city
        * @param parentselector : This is the selector contain the form to valid (can be a div inside a simple html page or a div containt layer iframe shadowbox)
        * WARNING : not used with QAS
        */
        checkCityList: function(parentselector) {
            var myCityList = parentselector.find("select[id*='customer_citylist']");
            var myCityInput = parentselector.find("input[id*='address_city']");
            if (myCityList.find("option").length > 0) {
                myCityList.css("display", "block");
                myCityInput.css("display", "none");
                myCityList.change(function() {
                    if (J(this).val() == "Sélectionnez") {
                        CCB.Form.setToolTip(myCityList, CCB.loctxt.field.blank);
                        CCB.Form.setRedCross(myCityList);
                    } else {
                        CCB.Form.setGreenCross(myCityList);
                        if (CCB.ShadowBox.state) {
                            var myIdDivError = parentselector.find("div#Error_" + myCityList.attr("id"));
                        }
                        else {
                            var myIdDivError = J("div#Error_" + myCityList.attr("id"));
                        }
                        if (myIdDivError.length > 0) {
                            CCB.Form.removeToolTip(myIdDivError);
                        }
                    }
                });
            }
            else {
                myCityList.css("display", "none");
                myCityInput.css("display", "block");
            }
        },
        /**
        * CCB.Form.prohibitedDeliveryZip : Check if the prohibited delivery zip is not entered by the user (military area = 00, corse area = "20")
        * @param obj : The zip field object
        */
        prohibitedDeliveryZip: function(obj) {
            var isError = "";
            var postcodebegin = obj.val().substr(0, 2);
            if (postcodebegin == "00" || postcodebegin == "20") {
                CCB.Form.setToolTip(obj, CCB.loctxt.error.deliveryprohibitedzip);
                CCB.Form.setRedCross(obj);
                isError = true;
            }
            else {
                CCB.Form.setGreenCross(obj);
                isError = false;
            }
            return isError;
        },
        /**
        * CCB.Form.displayAddress : displayAddress : display the static address field with the 3 dynamic one (WB) customer_address_line1 (number), customer_address_line2 (type), customer_address_line3 (name)
        * @param parentselector : This is the selector contain the form to valid (can be a div inside a simple html page or a div containt layer iframe shadowbox)
        */
        displayAddress: function(parentselector) {
        parentselector.find("input[id='static_line3']").val(J.trim(parentselector.find("input[id*='address_line1']").val() + " " + parentselector.find("input[id*='address_line2']").val() + " " + parentselector.find("input[id*='address_line3']").val()));
        }
    },
    //------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------
    //	CCB.Minibag
    //	Function relate to the MiniBasket
    //------------------------------------------------------------------------------------------------------
    Minibag: {
        refreshBag: function() {
            J("#panier_open").load("/ajax/refreshminibasketdetail.aspx", CCB.Minibag.afterRefreshBag);
        },
        afterRefreshBag: function() {
            J.getScript("/js/gen.functions_panier.js");
            CCB.conciergerie.init();
        }
    },
    //------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------
    //	CCB.Services
    //	Function generic
    //------------------------------------------------------------------------------------------------------
    Services: {
        KeyListener: {
            onPage: function() {
                J('#global').bind('keypress', function(e) {
                    var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
                    var target = e.target.tagName.toLowerCase();
                    if (key === 13 && target === 'input') {
                        e.preventDefault();
                        J.each(CCB.locvar.field.enterkey, function(i) {
                            if ((J(e.target).parent("." + this).length > 0) || J(e.target).parent().parent("." + this).length > 0) {
                                switch (i) {
                                    case 0: 	//nh_newsletter > newsletter header
                                        CCB.Services.NewsletterRegister();
                                        return false;
                                    case 1: 	//nh_offre > key code header
                                        CCB.Services.KeyCodeLoad();
                                        return false;
                                        break;
                                    case 2: 	//ns_form > search header
                                        CCB.Services.GoToSearchPage();
                                        return false;
                                        break;
                                    case 3: 	//ad_form > search footer
                                        CCB.Services.GoToSearchPage();
                                        return false;
                                        break;
                                    case 4: 	//smd_box > newsletter footer
                                        CCB.Services.NewsletterRegister();
                                        return false;
                                        break;
                                    case 5: 	//cd_content > key code page basket right nav
                                        CCB.Services.KeyCodeLoad();
                                        return false;
                                        break;
                                    case 6: 	//cc_panier-gauche > key code page express add to basket
                                        J("input[id*='redeembutton']").click();
                                        return false;
                                        break;
                                    case 7: 	//cc_tunnel-identification-formconnexion > checkout identification page login box
                                        J("#cc_tunnel-identification-form").html("");
                                        CCB.Services.RedirectTo("", J("p.cc_tunnel_login-submit").find("a[id*='submit']").attr("href"));
                                        //J("p.cc_tunnel_login-submit").find("a[id*='submit']").click();
                                        //return false;
                                        return false;
                                        break;
                                    case 8: 	//box_offre > key code page bienvenue
                                        CCB.Services.KeyCodeLoad();
                                        break;
                                    case 9: 	//cc_point_relais-input"
                                        J("a[id*='cctunnelrelaissubmit']").attr("href", "/services/find-relay.aspx?zipcode=" + J("input[id*='customerzip']").val());
                                        CCB.Services.RedirectTo("", J("a[id*='cctunnelrelaissubmit']").attr("href"));
                                        break;
                                    case 10: //cc_recherche_mdr 
                                        CCB.Services.GoToSearchPage();
                                        return false;
                                        break;
                                }
                            }
                        });
                    }
                }); //bind
            },
            onLayer: function(ccbjslayer) {
                J("#shadowbox_content").contents().bind('keypress', function(e) {
                    var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
                    var target = e.target.tagName.toLowerCase();
                    if (key === 13 && target === 'input') {
                        e.preventDefault();
                        switch (ccbjslayer) {
                            case "keycodecapture":
                                var myLink = J("#shadowbox_content").contents().find("a[id*='submitkc']");
                                J("#shadowbox_content").contents().find("input[id*='__EVENTTARGET']").val(myLink.attr("href").split("'")[1]);
                                J("#shadowbox_content").contents().find("form#aspnetForm").submit();
                                break;
                            case "customeridentification":
                                var myLink = J("#shadowbox_content").contents().find("#cc_tunnel-identification-form").find("a[id*='submit']");
                                J("#shadowbox_content").contents().find("input[id*='__EVENTTARGET']").val(myLink.attr("href").split("'")[1]);
                                J("#shadowbox_content").contents().find("form#aspnetForm").submit();
                                //J("#shadowbox_content").contents().find("#cc_tunnel-identification-form").find("a[id*='submit']").click();
                                break;
                            case "orderidentification":
                                var myLink = J("#shadowbox_content").contents().find("#cc_tunnel-identification-form").find("a[id*='submit']");
                                J("#shadowbox_content").contents().find("input[id*='__EVENTTARGET']").val(myLink.attr("href").split("'")[1]);
                                J("#shadowbox_content").contents().find("form#aspnetForm").submit();
                                //J("#shadowbox_content").contents().find("#cc_tunnel-identification-form").find("a[id*='submit']").click();
                                break;
                            case "customerlostpwd":
                                var myLink = J("#shadowbox_content").contents().find("#cc_tunnel-identification-form").find("a[id*='submit']");
                                J("#shadowbox_content").contents().find("input[id*='__EVENTTARGET']").val(myLink.attr("href").split("'")[1]);
                                J("#shadowbox_content").contents().find("form#aspnetForm").submit();
                                J("#shadowbox_content").contents().find("#cc_tunnel-identification-form").find("a[id*='submit']").click();
                                break;
                            case "newsletterinscription":
                                var jScript = J("#shadowbox_content").contents().find("#cc_newsletter-inscrip").find("a[id*='submit']").attr("href");
                                eval(jScript);
                                //CCB.Services.NewsletterRegister();
                                break;
                            case "customermailpwd":
                                var myLink = J("#shadowbox_content").contents().find("#cc_tunnel-identification-form").find("a[id*='submit']");
                                J("#shadowbox_content").contents().find("input[id*='__EVENTTARGET']").val(myLink.attr("href").split("'")[1]);
                                J("#shadowbox_content").contents().find("form#aspnetForm").submit();
                                //J("#shadowbox_content").contents().find("#cc_tunnel-identification-form").find("a[id*='submit']").click();
                                break;
                            case "customernewsletter":
                                var myLink = J("#shadowbox_content").contents().find("#cc_espace-client-newsletter-form").find("a[id*='submit']");
                                J("#shadowbox_content").contents().find("input[id*='__EVENTTARGET']").val(myLink.attr("href").split("'")[1]);
                                J("#shadowbox_content").contents().find("form#aspnetForm").submit();
                                //J("#shadowbox_content").contents().find("#cc_tunnel-identification-form").find("a[id*='submit']").click();
                                break;
                            case "customerupdate":
                                var isValidForm = CCB.Form.submitIsValid(CCB.parentselector);
                                //2. si TRUE : CHECK QAS
                                if (isValidForm) {
                                    CCB.qas.serializeCreateForm(CCB.qas.page.formSelector);
                                    CCB.qas.wsQasCall();
                                }
                                break;
                        }


                    }
                });
            }
        },
        RedirectTo: function(target, url) {
            if (target == "parent")
                parent.location.href = url;
            else
                location.href = url;
        },
        NewsletterRegister: function() {
            //var email = J("input[id='input" + J(this).attr("id") + "']").val();
            var email = CCB.Layout.inputTxt;
            var regex = CCB.locexp.regex.email;
            if (CCB.Form.checkblank(email)) {
                CCB.Layer.error(CCB.locexp.errortype.blank);
                return false;
            }
            else if (!CCB.Form.checkregex(email, regex)) {
                CCB.Layer.error(CCB.locexp.errortype.invalid);
                return false;
            }
            else {
                CCB.Layer.newsletter(email);
                return false;
            }
        },
        KeyCodeLoad: function() {
            //var keycode = J("input[id='input" + J(this).attr("id") + "']").val();
            var keycode = CCB.Layout.inputTxt;
            var regex = CCB.locexp.regex.keycode;
            if (CCB.Form.checkblank(keycode)) {
                CCB.Layer.error(CCB.locexp.errortype.blank);
                return false;
            }
            else {
                CCB.Layer.keycode(keycode);
                return false;
            }
        },
        GoToSearchPage: function() {
            if ((CCB.Form.checkblank(CCB.loctxt.search.tofind)) || (CCB.loctxt.search.tofind == CCB.loctxt.search.init)) {
                CCB.Layer.error(CCB.locexp.errortype.blank);
                return false;
            }
            else {
                window.location = "/search/search.aspx?search=" + CCB.loctxt.search.tofind + "&pagelevel=*:8&page=1";
                return false;
            }
        },
        //findPos : function to find an element position
        findPos: function(obj) {
            var curleft = obj.offsetLeft || 0;
            var curtop = obj.offsetTop || 0;
            while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
            }
            return { x: curleft, y: curtop };
        },
        CheckDeliveryZipCode: function(zipcode) {
            if (zipcode != null && zipcode.length > 1) {
                var zipzone = zipcode.substr(0, 2);
                if ((zipzone != "00") && (zipzone != "20"))
                    return true;
            }
            return false;
        },
        CheckDeliveryPhone: function(phone) {
            if (phone.length == 10) {
                var prefix = phone.substring(0, 2);
                if ((prefix == "01") || (prefix == "02") || (prefix == "03") || (prefix == "04") || (prefix == "04") || (prefix == "05") || (prefix == "06") || (prefix == "09")) {
                    return true;
                }
            }
            return false;
        },
        convertStringToCurrency: function() {
            var toConvert = this.replace(/,/gi, ".");
            toConvert = toConvert.replace(/\u20AC/gi, "");
            toConvert = toConvert.trim();
            return parseFloat(toConvert);
        },
        convertCurrencyToString: function(precision, symbole) {
            var toConvert = Math.round(parseFloat(this) * 100) / 100
            toConvert = toConvert.toFixed(precision);
            var convertedString = new String(toConvert);
            convertedString = convertedString.replace(".", ",");
            convertedString = convertedString + " " + symbole;
            return convertedString;
        },
        ComputeAndDisplayPromotion: function(FullPrice, PromoPrice) {
            //calcule pour reduction offer display product et crossselling
            if (FullPrice != null && PromoPrice != null) {

                percent = (PromoPrice * 100) / FullPrice;
                percent = 100 - percent;
                percent = Math.round(percent);

                if (percent >= 95) {
                    percent = 95;
                } else if ((percent >= 90) && (percent < 95)) {
                    percent = 90
                } else if ((percent >= 85) && (percent < 90)) {
                    percent = 85
                } else if ((percent >= 80) && (percent < 85)) {
                    percent = 80
                } else if ((percent >= 75) && (percent < 80)) {
                    percent = 75
                } else if ((percent >= 70) && (percent < 75)) {
                    percent = 70
                } else if ((percent >= 65) && (percent < 70)) {
                    percent = 65
                } else if ((percent >= 60) && (percent < 65)) {
                    percent = 60
                } else if ((percent >= 55) && (percent < 60)) {
                    percent = 55
                } else if ((percent >= 50) && (percent < 55)) {
                    percent = 50;
                } else if ((percent >= 45) && (percent < 50)) {
                    percent = 45
                } else if ((percent >= 40) && (percent < 45)) {
                    percent = 40
                } else if ((percent >= 35) && (percent < 40)) {
                    percent = 35
                } else if ((percent >= 30) && (percent < 35)) {
                    percent = 30
                } else if ((percent >= 25) && (percent < 30)) {
                    percent = 25
                } else if ((percent >= 20) && (percent < 25)) {
                    percent = 20
                } else if ((percent >= 15) && (percent < 20)) {
                    percent = 15
                } else if ((percent >= 10) && (percent < 15)) {
                    percent = 10
                } else if ((percent >= 5) && (percent < 10)) {
                    percent = 5
                }
                return (-percent + "").replace(".", ",") + "<span>%</span>";
            }
        },

        WriteReduc: function(FullPrice, PromoPrice) {
            var reduc = FullPrice - PromoPrice;
            return (reduc.toFixed(2));
        },

        Checkshipcarrierinfo: function() {

            MtRelayRL = J("input[id='ShipCarrierRelayRL']").val();
            MontantRelayRL = MtRelayRL.StringToCurrency();
            MtLaPosteCOCost = J("input[id='ShipCarrierLaPosteCO']").val();
            MontantLaPosteCOCost = MtLaPosteCOCost.StringToCurrency();

            MontantTotalLaPosteCOCost = MontantLaPosteCOCost - MontantRelayRL;
            //MontantTotalAffichLaPosteCOCost = Math.round(MontantTotalLaPosteCOCost*100)/100;
            var MtTotalAffichLaPosteCOCost = Math.round(MontantTotalLaPosteCOCost * 100) / 100;
            if (MtTotalAffichLaPosteCOCost == "0") {
                MontantTotalAffichLaPosteCOCost = CCB.loctxt.userform.delivery.withoutsupplement;
                MontantTotalAffichLaPosteCOCostDelivery = CCB.loctxt.userform.delivery.withoutsupplementdelivery;
            }
            else {
                MontantTotalAffichLaPosteCOCost = CCB.loctxt.userform.delivery.withsupplement + MtTotalAffichLaPosteCOCost + " €";
                MontantTotalAffichLaPosteCOCostDelivery = CCB.loctxt.userform.delivery.withsupplementdelivery + MtTotalAffichLaPosteCOCost + " €";
            }

            MtLaPoste24Cost = J("input[id='ShipCarrierLaPoste24']").val();
            MontantLaPoste24Cost = MtLaPoste24Cost.StringToCurrency();
            MontantTotalLaPoste24Cost = MontantLaPoste24Cost - MontantRelayRL;
            MontantTotalAffichLaPoste24Cost = Math.round(MontantTotalLaPoste24Cost * 100) / 100;
        },

        PromotedPrice: function(parentselector) {

            var promoprdbox = parentselector.find("div[class*='resultat']");
            var promoprdbasket = parentselector.find("td[class='tab_3']");

            if (promoprdbox.length > 0) {
                J.each(promoprdbox, function() {
                    if (J(this).find("input[class='promotedprice']").length > 0) {
                        var fullPrice = J(this).find("input[class='promotedprice']").attr("value").split('#')[0];
                        var promoPrice = J(this).find("input[class='promotedprice']").attr("value").split('#')[1];
                        J(this).find("p[class*='promo']").html(CCB.Services.ComputeAndDisplayPromotion(fullPrice.StringToCurrency(), promoPrice.StringToCurrency()));
                        J(this).find("p[class*='economie']").html("Vous économisez " + CCB.Services.WriteReduc(fullPrice.StringToCurrency(), promoPrice.StringToCurrency()).CurrencyToString("2", "€"));

                        var pourcentage = CCB.Services.ComputeAndDisplayPromotion(fullPrice.StringToCurrency(), promoPrice.StringToCurrency());

                        //alert(pourcentage);
                        if (pourcentage == 'Prix special') {
                            J(this).find("p[class*='promo']").removeClass('promo').addClass('reduc_M_speciale');
                            J(this).find("p[class*='rs_promo']").removeClass('rs_promo').addClass('reduc_M_speciale');
                        }
                        else if (pourcentage == '-60<span>%</span>') {
                            J(this).find("p[class*='promo']").removeClass('promo').addClass('reduc_M_60');
                            J(this).find("p[class*='rs_promo']").removeClass('rs_promo').addClass('reduc_M_60');
                        }
                        else if (pourcentage == '-55<span>%</span>') {
                            J(this).find("p[class*='promo']").removeClass('promo').addClass('reduc_M_55');
                            J(this).find("p[class*='rs_promo']").removeClass('rs_promo').addClass('reduc_M_55');
                        }
                        else if (pourcentage == '-50<span>%</span>') {
                            J(this).find("p[class*='promo']").removeClass('promo').addClass('reduc_M_50');
                            J(this).find("p[class*='promo']").removeClass('rs_promo').addClass('reduc_M_50');
                        }
                        else if (pourcentage == '-45<span>%</span>') {
                            J(this).find("p[class*='promo']").removeClass('promo').addClass('reduc_M_45');
                            J(this).find("p[class*='rs_promo']").removeClass('rs_promo').addClass('reduc_M_45');
                        }
                        else if (pourcentage == '-40<span>%</span>') {
                            J(this).find("p[class*='promo']").removeClass('promo').addClass('reduc_M_40');
                            J(this).find("p[class*='rs_promo']").removeClass('rs_promo').addClass('reduc_M_40');
                        }
                        else if (pourcentage == '-35<span>%</span>') {
                            J(this).find("p[class*='promo']").removeClass('promo').addClass('reduc_M_35');
                            J(this).find("p[class*='rs_promo']").removeClass('rs_promo').addClass('reduc_M_35');
                        }
                        else if (pourcentage == '-30<span>%</span>') {
                            J(this).find("p[class*='promo']").removeClass('promo').addClass('reduc_M_30');
                            J(this).find("p[class*='rs_promo']").removeClass('rs_promo').addClass('reduc_M_30');
                        }
                        else if (pourcentage == '-25<span>%</span>') {
                            J(this).find("p[class*='promo']").removeClass('promo').addClass('reduc_M_25');
                            J(this).find("p[class*='rs_promo']").removeClass('rs_promo').addClass('reduc_M_25');
                        }
                        else {
                            J(this).find("p[class*='promo']").removeClass('promo').addClass('reduc_M_10-15-20');
                            J(this).find("p[class*='rs_promo']").removeClass('rs_promo').addClass('reduc_M_10-15-20');
                        }
                    }
                });
            }

            if (promoprdbasket.length > 0) {
                promoprdbasket.each(function() {
                    if (J(this).find("input[class='promotedprice']").length > 0) {
                        var fullPrice = J(this).find("input[class='promotedprice']").attr("value").split('#')[0];
                        var promoPrice = J(this).find("input[class='promotedprice']").attr("value").split('#')[1];
                        J(this).find("p[class*='promo']").html(CCB.Services.ComputeAndDisplayPromotion(fullPrice.StringToCurrency(), promoPrice.StringToCurrency()));
                    }
                });
            }
        }
    }
});

String.prototype.CurrencyToString = CCB.Services.convertCurrencyToString;
String.prototype.StringToCurrency = CCB.Services.convertStringToCurrency;

//======================================================================================================
//======================================================================================================
//	CCB.Page
//	Function called onReady website PAGE
//	To use this, the page must include an input type hidden define like this :
//	<input type="hidden" id="ccbjs" value="myfunctionname" style="display:none" />
//======================================================================================================
CCB.Page = CCB.Page || {};
J.extend(CCB.Page, {
  productpage: function () {

    // Open open set Layer if just added an open set
    var parentselector = J("#cc_ficheproduit-separateur").contents();
    //parentselector.find("span#opensetspan").text(parentselector.find("input#opensettext").val());
    if (parentselector.find("label[id*=FailureAddOpenSet]").length > 0) {
      Shadowbox.open({
        content: "/catalog/layer_open-set_error.aspx?osid=" + parentselector.find("input#opensetiderror").val(),
        player: "iframe",
        height: 200,
        width: 605
      });
    }
    if (parentselector.find("input#opensetaddsuccess").length > 0) {
      //alert("opensetaddsuccess value : "+parentselector.find("input#opensetaddsuccess").val());
      Shadowbox.open({
        content: "/catalog/layer_open-set.aspx?osid=" + parentselector.find("input#opensetaddsuccess").val(),
        player: "iframe",
        height: 650,
        width: 805
      });
    }

    // Init product page
    if (J("#centre").contents().find("select#prd_selectref").length > 0) {
      CCB.Catalog.Product.updateProductInfo(parentselector);
      CCB.Catalog.Product.updatePrdPrice(parentselector);
      CCB.Catalog.Product.updatePrdCapacity(parentselector);
      CCB.Catalog.Product.updateEcoTaxe(parentselector);
      CCB.Catalog.Product.updatePrdStock(parentselector);
      CCB.Catalog.Product.updatePrdBtnBasket(parentselector);
      CCB.Catalog.Product.updatePrdBookmark();
      CCB.Catalog.Product.updatePrdFriend();
      CCB.Catalog.Product.updateAssociationInfo();
      CCB.Catalog.Product.updatePrdBtnOpenSet(parentselector);

      /*
      // J("div#openset_btn").load("/ajax/openset_btn.aspx?varcode="+CCB.Product.Info.VCode);        
      J.ajax({
      type: "GET",
      //url: "/ajax/openset_btn.aspx",
      url: "/ajax/openset_btn.aspx",
      data: "varcode=" + CCB.Product.Info.VCode, //+"&time"+Math.round(Math.random()*1000), 
      success: function(msg) {
      if (msg.length > 0) {
      J('div#openset_btn').html(msg);
      }
      else {
      alert("error ajax")
      }
      }
      });
      */
    }

    // On select variant change
    J("select#prd_selectref").change(function () {
      CCB.Catalog.Product.updateProductInfo(parentselector);
      CCB.Catalog.Product.updatePrdShade(parentselector);
      CCB.Catalog.Product.updatePrdPrice(parentselector);
      CCB.Catalog.Product.updatePrdImg(parentselector);
      CCB.Catalog.Product.updateEcoTaxe(parentselector);
      CCB.Catalog.Product.updatePrdStock(parentselector);
      CCB.Catalog.Product.updatePrdBtnBasket(parentselector);
      CCB.Catalog.Product.updateAssociationInfo();
      CCB.Catalog.Product.updatePrdBtnOpenSet(parentselector);
    });

    // On select quantity change J("select#prd_selectqty")  
    J("select[id*='prd_selectqty']").change(function () {
      CCB.Catalog.Product.updateProductInfo(parentselector);
      CCB.Catalog.Product.updatePrdBtnBasket(parentselector);
    });

    // On image shade click change
    J("a[id*='prd_shade']").click(function () {
      J("ul.cc_ficheproduit-details-palette a").removeClass("actif");
      J(this).addClass("actif");
      CCB.Catalog.Product.updatePrdSelectRef(parentselector, J(this).attr("id").substr(9, J(this).attr("id").length));
      CCB.Catalog.Product.updateProductInfo(parentselector);
      CCB.Catalog.Product.updatePrdPrice(parentselector);
      CCB.Catalog.Product.updatePrdImg(parentselector);
      CCB.Catalog.Product.updateEcoTaxe(parentselector);
      CCB.Catalog.Product.updatePrdStock(parentselector);
      CCB.Catalog.Product.updatePrdBtnBasket(parentselector);
      CCB.Catalog.Product.updatePrdBtnOpenSet(parentselector);
      CCB.Catalog.Product.updateAssociationInfo();
      return false;
    });


  },
  segmentpage: function () {
    //if 1 creator filter, then don't display it
    var findcreatorfilter = J("#col_centrale").contents().find(".creator_checkbox");
    if (findcreatorfilter.length < 2) {
      findcreatorfilter.css("display", "none");
    }
  },
  subsegmentpage: function () {
    //if 1 creator filter, then don't display it
    var findcreatorfilter = J("#col_centrale").contents().find(".creator_checkbox");
    if (findcreatorfilter.length < 2) {
      findcreatorfilter.css("display", "none");
    }
  },
  newproductpage: function () {
    //if 1 creator filter, then don't display it
    var findcreatorfilter = J("#col_centrale").contents().find(".creator_checkbox");
    if (findcreatorfilter.length < 2) {
      findcreatorfilter.css("display", "none");
    }
  },
  bestratepage: function () {
    //if 1 creator filter, then don't display it
    var findcreatorfilter = J("#col_centrale").contents().find(".creator_checkbox");
    if (findcreatorfilter.length < 2) {
      findcreatorfilter.css("display", "none");
    }
  },
  bestsellerpage: function () {
    //if 1 creator filter, then don't display it
    var findcreatorfilter = J("#col_centrale").contents().find(".creator_checkbox");
    if (findcreatorfilter.length < 2) {
      findcreatorfilter.css("display", "none");
    }
  },
  shoppingcard: function () {
    //If postBack and find input#isopen7 then input#hideopen7 varcode value is openset => open layer select shade
    if (J("input[id='isopen7']").length > 0) {
      Shadowbox.open({
        content: "/catalog/layer_add_shade.aspx?prdcode=" + J("input[id='isopen7']").val().split('#')[0] + "&varcode=" + J("input[id='isopen7']").val().split('#')[1],
        player: "iframe",
        height: 510,
        width: 622
      });
    }

    //Set the CSS border of the PAP if exist  
    if (J("img[class='cc_offrespeciale-img']").length > 0) {
      J("div[class='cc_offrespeciale']").attr("style", "border:1px solid #b2b2b2");
    }

    // Fonction : recherche des champs "ItemQuantity" qui sont modifies et execution de la fonction "Click" du bouton "refreshbutton"
    J("select[id*='itemquantity']").change(function () {
	  J("input[id*='refreshbutton']").click();
	});

    // Fonction : recherche le bouton "continuer votre shopping" qui permet de retournee sur la dernière page affichée
    J("a[id*='hrefcontinueshopping']").click(function () {
      window.history.back();
    });

    // Fonction : recherche le bouton "valider votre panier" pour contrôler que la panier n'est pas vide et que l'Offre spéciale est validée afin d'afficher la page d'identification
    J("a[id*='hrefvaliderpanier']").click(function () {
      if (J("#emptyshoppingcart").length > 0) {
        //alert("emptyshoppingcart : "+CCB.locexp.errortype.shoppingcardblank);
        CCB.Layer.error(CCB.locexp.errortype.shoppingcardblank);
      }
      /*
      else if (J("#offrespeciale_minipanier").length > 0) {
      Shadowbox.open({
      content: "/catalog/layer_open-set_basketerror.aspx?osid="+J("#opensetid").val(),
      player: "iframe",
      height: 380,
      width: 620
      });
      }
      */
      else {
        window.location = "/checkout/identification.aspx?successurl=delivery.aspx%3Fconfirm=1";
      }
    });

    //compute ship carrier info
    CCB.Services.Checkshipcarrierinfo();
    //Display text
    J("span[id='LaPosteCOCost']").text(MontantTotalAffichLaPosteCOCost);
    J("span[id='LaPoste24Cost']").text(MontantTotalAffichLaPoste24Cost);
    J("td[id='BasketSubTotal']").text(MontantSubTotalAffich);

    //OpenSet : display detail product on Parent Opent Set Template
    J("tr[class='MultiLineParentTemplate']").each(function () {
      var innerParentChildOpenedSet = "";
      J("tr[class='MultiLineChildOpenedSetTemplate'] td." + J(this).attr("id")).each(function () {
        innerParentChildOpenedSet += "- " + J(this).html() + "<br/>";
      });
      J(this).contents().find("#Child_" + J(this).attr("id")).html(innerParentChildOpenedSet);
    });

    //keycode shopping card field
    J("input[id*='inputsubkeycode_basket']").keyup(function () {
      var keycodefield = J(this).val().toUpperCase().replace(" ", "");
      J(this).val(keycodefield);
    });

    //Find error message page shopping-card
    if (J("span[id*='MaxBasketQtyMessage']").length > 0) {
      //CCB.Layer.errorparam(J("span[id*='MaxBasketQtyMessage']").html());
      CCB.Layer.error(CCB.locexp.errortype.maxbasketqtymessage);
    }
    if (J("span[id*='MaxBasketAmountMessage']").length > 0) {
      CCB.Layer.error(CCB.locexp.errortype.maxbasketamountmessage);
    }
    if (J("span[id*='ProductCodeEmptyMessage']").length > 0) {
		/* Popup Erratum pour code produit non existant dans SM */
		/*Valeurproductcode = J("input[id*='productcode']").val();
		if(Valeurproductcode == "949000" || Valeurproductcode == "839803"){
				Shadowbox.open({
				content: "/checkout/layer_bbouche_test.aspx",
				player: "iframe",
				height: 250,
				width: 430
			  });
		}else{
			CCB.Layer.error(CCB.locexp.errortype.productemptymessage);
		}*/
	  CCB.Layer.error(CCB.locexp.errortype.productemptymessage);
      //CCB.Layer.errorparam(J("span[id*='MaxBasketQtyMessage']").html());
    }
    if (J("span[id*='MaxBasketItemQtyMessage']").length > 0) {
      CCB.Layer.error(CCB.locexp.errortype.maxbasketitemqtymessage);
    }
    if (J("span[id*='OutOfStockMessage']").length > 0) {
      CCB.Layer.error(CCB.locexp.errortype.outofstockmessage);
    }
  },

  checkoutlogin: function () {
    //compute ship carrier info
    CCB.Services.Checkshipcarrierinfo();
    //Display text
    J("span[id='LaPosteCOCost']").text(MontantTotalAffichLaPosteCOCost);
    J("span[id='LaPoste24Cost']").text(MontantTotalAffichLaPoste24Cost);

    J("#cc_tunnel-identification-login").find("a[id*='submit']").click(function () {
      J("#cc_tunnel-identification-form div:first-child").find("input").remove();
    });

    /*  [QAS functionnality] */
    var parentselector = J("#cc_tunnel-identification-compte");
    CCB.parentselector = parentselector;
    CCB.qas.page.formSelector = parentselector.find("#cc_tunnel-identification-form");
    CCB.qas.page.formType = "page";
    CCB.qas.page.formUrl = "/checkout/identification.aspx";
    CCB.qas.page.formUrlWidth = "";
    CCB.qas.page.formUrlHeight = "";
    CCB.qas.page.successType = "page";
    CCB.qas.page.successUrl = "/checkout/delivery.aspx?confirm=1"; 
    CCB.qas.page.successUrlWidth = "";
    CCB.qas.page.successUrlHeight = "";
    CCB.qas.page.ajaxCallUrl = CCB.Data.Site.Name + "/ajax/qas-register.aspx";

    //Display User form
    J.get(CCB.qas.page.ajaxCallUrl + "?time" + Math.round(Math.random() * 1000), function (data) {
      //if come from QAS layer back to form (or error webbox)
      switch (CCB.qas.page.formBackToFlag) {
        case true:
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(data).filter("FORM").html());
          CCB.qas.customerBackToFormDataRecovery();
          break;
        case "error":
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(CCB.qas.page.formBackDataAjax).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          CCB.qas.page.formSelector.find("#form-msg").html(CCB.loctxt.error.checkredfield);
          break;
        case "account":
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(CCB.qas.page.formBackDataAjax).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          CCB.qas.page.formSelector.find("#form-msg").html(CCB.loctxt.error.checkexistingaccount);
          break;
        default:
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(data).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          break;
      }

      //SPECIFIC > update ccb newsletter checkbox
      CCB.qas.page.formSelector.find("input[id$='question1']").attr("checked", "checked");

      CCB.qas.page.formSelector.fadeIn("slow");
      CCB.Form.init(CCB.parentselector);

      //SPECIFIC > FORM CREATE ACCOUNT - check to update login field with email field
      parentselector.find("input[id$='email']").blur(function () {
        CCB.Customer.setLoginWithEmail();
      });

	  
      //Submit User form
      parentselector.find("#qas-submit").click(function () {
        //1. CHECK JS validation
        var isValidForm = CCB.Form.submitIsValid(CCB.parentselector);

        //2. si TRUE : CHECK QAS
        if (isValidForm) {
          CCB.qas.serializeCreateForm(CCB.qas.page.formSelector);
          CCB.qas.wsQasCall();
        }
        return false;
      });

    });
    /*  [/QAS functionnality] */
},
concourscheckoutlogin: function() {
    //compute ship carrier info
    CCB.Services.Checkshipcarrierinfo();
    //CCB.Services.KeyListener.onLayer("checkoutlogin");
    //Display text
    J("span[id='LaPosteCOCost']").text(MontantTotalAffichLaPosteCOCost);
    J("span[id='LaPoste24Cost']").text(MontantTotalAffichLaPoste24Cost);

    J("#cc_tunnel-identification-login").find("a[id*='submit']").click(function() {
        J("#cc_tunnel-identification-form div:first-child").find("input").remove();
    });

    /*  [QAS functionnality] */
    var parentselector = J("#cc_tunnel-identification-compte");
    CCB.parentselector = parentselector;
    CCB.qas.page.formSelector = parentselector.find("#cc_tunnel-identification-form");
    CCB.qas.page.formType = "page";
    CCB.qas.page.formUrl = "/concours/jeu_maurice/page_jeu_identification.aspx";
    CCB.qas.page.formUrlWidth = "";
    CCB.qas.page.formUrlHeight = "";
    CCB.qas.page.successType = "page";
    CCB.qas.page.successUrl = "/concours/jeu_maurice/page_jeu_confirmation.aspx?value=1";
    CCB.qas.page.successUrlWidth = "";
    CCB.qas.page.successUrlHeight = "";
    CCB.qas.page.ajaxCallUrl = CCB.Data.Site.Name + "/ajax/qas-register.aspx";

    //initially used window.pathname...it works well in production.Problem comes with integation since it include contentmanager/aspent.
    //hence using window.location and CCB.Data.Site.Name.If it is not hitting ,please take care of case sensitivity
    switch (window.location.toString().toLowerCase()) {
        case CCB.Data.Site.Name.toLowerCase() + "/concours/jeu_maurice/page_jeu_identification.aspx":
            CCB.qas.page.formUrl = "/concours/jeu_maurice/page_jeu_identification.aspx";
            CCB.qas.page.successUrl = "/concours/jeu_maurice/page_jeu_confirmation.aspx?value=1";
            break;
        case CCB.Data.Site.Name.toLowerCase() + "/concours/jeu_bora_bora/page_jeu_identification.aspx":
            CCB.qas.page.formUrl = "/concours/jeu_bora_bora/page_jeu_identification.aspx";
            CCB.qas.page.successUrl = "/concours/jeu_bora_bora/page_jeu_confirmation.aspx?value=1";
            break;
	    case CCB.Data.Site.Name.toLowerCase() + "/concours/jeu_bali/page_jeu_identification.aspx":
            CCB.qas.page.formUrl = "/concours/jeu_bali/page_jeu_identification.aspx";
            CCB.qas.page.successUrl = "/concours/jeu_bali/page_jeu_confirmation.aspx?value=1";
            break;	
    }

    //Display User form
    J.get(CCB.qas.page.ajaxCallUrl + "?time" + Math.round(Math.random() * 1000), function(data) {
        //if come from QAS layer back to form (or error webbox)
        switch (CCB.qas.page.formBackToFlag) {
            case true:
                CCB.qas.page.formSelector.html("").css("display", "none").append(J(data).filter("FORM").html());
                CCB.qas.customerBackToFormDataRecovery();
                break;
            case "error":
                CCB.qas.page.formSelector.html("").css("display", "none").append(J(CCB.qas.page.formBackDataAjax).filter("FORM").html());
                CCB.Form.displayAddress(CCB.parentselector);
                CCB.qas.page.formSelector.find("#form-msg").html(CCB.loctxt.error.checkredfield);
                break;
            case "account":
                CCB.qas.page.formSelector.html("").css("display", "none").append(J(CCB.qas.page.formBackDataAjax).filter("FORM").html());
                CCB.Form.displayAddress(CCB.parentselector);
                CCB.qas.page.formSelector.find("#form-msg").html(CCB.loctxt.error.checkexistingaccount);
                break;
            default:
                CCB.qas.page.formSelector.html("").css("display", "none").append(J(data).filter("FORM").html());
                CCB.Form.displayAddress(CCB.parentselector);
                break;
        }

        //SPECIFIC > update ccb newsletter checkbox
        CCB.qas.page.formSelector.find("input[id$='ep0cbNewsletter']").attr("checked", "checked");

        CCB.qas.page.formSelector.fadeIn("slow");
        CCB.Form.init(CCB.parentselector);

        //SPECIFIC > FORM CREATE ACCOUNT - check to update login field with email field
        parentselector.find("input[id$='email']").blur(function() {
            CCB.Customer.setLoginWithEmail();
        });


        //Submit User form
        parentselector.find("#qas-submit").click(function() {
            //1. CHECK JS validation
            var isValidForm = CCB.Form.submitIsValid(CCB.parentselector);

            //2. si TRUE : CHECK QAS
            if (isValidForm) {
                CCB.qas.serializeCreateForm(CCB.qas.page.formSelector);
                CCB.qas.wsQasCall();
            }
            return false;
        });

    });
    /*  [/QAS functionnality] */
},
  checkoutdelivery: function () {
    //compute ship carrier info
    CCB.Services.Checkshipcarrierinfo();
    // Fonction : affichage du montant 48heure
    J("span[id='LaPosteCOCost']").text(MontantTotalAffichLaPosteCOCost);
    J("font[id='LaPosteCODelivery']").text(MontantTotalAffichLaPosteCOCostDelivery);
    // Fonction : affichage du montant 24heure
    J("span[id='LaPoste24Cost']").text(MontantTotalAffichLaPoste24Cost);
    J("font[id='LaPoste24CostDelivery']").text(MontantTotalAffichLaPoste24Cost);

    var scrollTo = J("input#parameter-sc").val();
    switch (scrollTo) {
      case "LAPOSTECO":
        J("#cc_tunnel-mode-livraison-colissimo").scroll();
        break;
      case "LAPOSTE24":
        J("#cc_tunel_livraison_logo-chronopost").scroll();
        break;
      case "GIFT":
        J("#cc_tunnel-mode-livraison-cadeau").scroll();
        break;
      default:
        break;
    }

  },
  checkoutpayment: function () {
	
	J("a[id*='submitproperty']").click(function(){
		Shadowbox.open({
			content: "Merci de patienter",
			player: "html",
			height: 250,
			width: 430
		  });
	});
	
	J("sips_submit_button").click(function(){
		alert('test');
	});
  
    //OpenSet : display detail product on Parent Opent Set Template
    J("tr[class='MultiLineParentTemplate']").each(function () {
      var innerParentChildOpenedSet = "";
      J("tr[class='MultiLineChildOpenedSetTemplate'] td." + J(this).attr("id")).each(function () {
        innerParentChildOpenedSet += "- " + J(this).html() + "<br/>";
      });
      J(this).contents().find("#Child_" + J(this).attr("id")).html(innerParentChildOpenedSet);
    });
  },
  checkoutconfirmation: function () {
    //OpenSet : display detail product on Parent Opent Set Template
    J("tr[class='MultiLineParentTemplate']").each(function () {
      var innerParentChildOpenedSet = "";
      J("tr[class='MultiLineChildOpenedSetTemplate'] td." + J(this).attr("id")).each(function () {
        innerParentChildOpenedSet += "- " + J(this).html() + "<br/>";
      });
      J(this).contents().find("#Child_" + J(this).attr("id")).html(innerParentChildOpenedSet);
    });
  },
  catalogrequest: function () {
    /*  [QAS functionnality] */
    var parentselector = J("#cc-catalogue-form").contents();
    CCB.parentselector = parentselector;
    CCB.qas.page.formSelector = parentselector.find("#cc_tunnel-identification-form");
    CCB.qas.page.formType = "page";
    CCB.qas.page.formUrl = "/services/catalog-request.aspx";
    CCB.qas.page.formUrlWidth = "";
    CCB.qas.page.formUrlHeight = "";
    CCB.qas.page.successType = "page";
    CCB.qas.page.successUrl = "/services/confirm_catalog-request.aspx";
    CCB.qas.page.successUrlWidth = "";
    CCB.qas.page.successUrlHeight = "";
    CCB.qas.page.ajaxCallUrl = "/ajax/qas-catalogrequest.aspx";

    //Display User form
    J.get(CCB.qas.page.ajaxCallUrl + "?time" + Math.round(Math.random() * 1000), function (data) {
      //if come from QAS layer back to form (or error webbox)
      switch (CCB.qas.page.formBackToFlag) {
        case true:
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(data).filter("FORM").html());
          CCB.qas.customerBackToFormDataRecovery();
          break;
        case "error":
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(CCB.qas.page.formBackDataAjax).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          CCB.qas.page.formSelector.find("#form-msg").html(CCB.loctxt.error.checkredfield);
          break;
        default:
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(data).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          break;
      }
      CCB.qas.page.formSelector.fadeIn("slow");
      CCB.Form.init(CCB.parentselector);

      //Submit User form
      CCB.parentselector.find("#qas-submit").click(function () {
        //1. CHECK JS validation
        var isValidForm = CCB.Form.submitIsValid(CCB.parentselector);

        //2. si TRUE : CHECK QAS
        if (isValidForm) {
          CCB.qas.serializeCreateForm(CCB.qas.page.formSelector);
          CCB.qas.wsQasCall();
        }
        return false;
      });

    });
    /*  [/QAS functionnality] */
  },
  contactcustomerservice: function () {
    /*  [QAS functionnality] */
    var parentselector = J("#col_centrale").contents();
    CCB.parentselector = parentselector;
    CCB.qas.page.formSelector = parentselector.find("#cc-aide-bloc-02");
    CCB.qas.page.formType = "page";
    CCB.qas.page.formUrl = "/all_about_ccb/contact-customer-service.aspx";
    CCB.qas.page.formUrlWidth = "";
    CCB.qas.page.formUrlHeight = "";
    CCB.qas.page.successType = "page";
    CCB.qas.page.successUrl = "/all_about_ccb/contact-customer-service-confirmation.aspx";
    CCB.qas.page.successUrlWidth = "";
    CCB.qas.page.successUrlHeight = "";
    CCB.qas.page.ajaxCallUrl = "/ajax/qas-contactus.aspx";

    //Display User form
    J.get(CCB.qas.page.ajaxCallUrl + "?time" + Math.round(Math.random() * 1000), function (data) {
      //if come from QAS layer back to form (or error webbox)
      switch (CCB.qas.page.formBackToFlag) {
        case true:
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(data).filter("FORM").html());
          CCB.qas.customerBackToFormDataRecovery();
          break;
        case "error":
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(CCB.qas.page.formBackDataAjax).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          CCB.qas.page.formSelector.find("#form-msg").html(CCB.loctxt.error.checkredfield);
          break;
        default:
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(data).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          break;
      }
      CCB.qas.page.formSelector.fadeIn("slow");
      CCB.Form.init(CCB.parentselector);

      //SPECIFIC > update contact us subject and mailto
      J('input[name=FAQ]').click(function () {
        J('input[id*=mail_subject]').attr('value', J(this).val().split('#')[0]);
        J('input[id*=mail_subsubject]').attr('value', '###' + J(this).val().split('#')[1]);
        J('input[id*=mailto]').attr('value', J(this).val().split('#')[1]);
        CCB.qas.page.formSelector.find("#form-msg-subject").html("");
      });

      //SPECIFIC > remove error msg for textarea on blur
      J("textarea[id*='mail_body']").focus(function () {
        CCB.qas.page.formSelector.find("#form-msg-textarea").html("");
      });

      //SPECIFIC > if postback, update subject radio button with the  input hidden mail_subject
      var postbacksubject = J('input[id*=mail_subject]').val() + "#" + J('input[id*=mailto]').val();
      if (postbacksubject != "#") {
        J('input[name=FAQ]').each(function () {
          if (J(this).val() == postbacksubject) {
            J(this).attr("checked", "checked");
          }
        });
      }

      //Submit User form (SPECIFIC)
      CCB.parentselector.find("#qas-submit").click(function () {
        CCB.qas.page.formSelector.find("#form-msg").html("");
        var isValidSubject = false;
        var isValidMsg = true;

        //1. CHECK JS validation
        var isValidForm = CCB.Form.submitIsValid(CCB.parentselector);

        //Verif objet du message
        J('input[name=FAQ]').each(function () {
          if (J(this).attr("checked")) {
            isValidSubject = true;
          }
        });

        //Verif message
        if (J("textarea[id*='mail_body']").val() == "") {
          var isValidMsg = false;
        }

        if ((!isValidSubject) || (!isValidSubject))
          isValidForm = false;

        //2. si TRUE : CHECK QAS
        if (isValidForm) {
          CCB.qas.serializeCreateForm(CCB.qas.page.formSelector);
          CCB.qas.wsQasCall();
        } else {
          CCB.qas.page.formSelector.find("#form-msg").html("Au moins une information saisie n'est pas correcte. Merci de vérifier les zones affichées en rouge.").scroll();
          if (!isValidSubject)
            CCB.qas.page.formSelector.find("#form-msg-subject").html("<img src='/img/common/checkout/identification/cross_false.gif' /> Veuillez saisir un sujet !");
          if (!isValidMsg)
            CCB.qas.page.formSelector.find("#form-msg-textarea").html("<img src='/img/common/checkout/identification/cross_false.gif' /> Veuillez saisir un message !");
        }
        return false;
      });

    });
    /*  [QAS functionnality] */
  },
  
contactiris: function () {
	
	
/*  [QAS functionnality] */
    var parentselector = J("#col_centrale").contents();
    CCB.parentselector = parentselector;
    CCB.qas.page.formSelector = parentselector.find("#cc-aide-bloc-02");
    CCB.qas.page.formType = "page";
    CCB.qas.page.formUrl = "/all_about_ccb/contact-iris.aspx";
    CCB.qas.page.formUrlWidth = "";
    CCB.qas.page.formUrlHeight = "";
    CCB.qas.page.successType = "page";
    CCB.qas.page.successUrl = "/all_about_ccb/contact-iris-confirmation.aspx";
    CCB.qas.page.successUrlWidth = "";
    CCB.qas.page.successUrlHeight = "";
    CCB.qas.page.ajaxCallUrl = "/ajax/qas-contact-iris.aspx";
	
	J('input[name=FAQ]').attr("checked","checked"); 
	//alert(resp);
	
    //Display User form
    J.get(CCB.qas.page.ajaxCallUrl + "?time" + Math.round(Math.random() * 1000), function (data) {
      //if come from QAS layer back to form (or error webbox)
      switch (CCB.qas.page.formBackToFlag) {
        case true:
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(data).filter("FORM").html());
          CCB.qas.customerBackToFormDataRecovery();
          break;
        case "error":
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(CCB.qas.page.formBackDataAjax).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          CCB.qas.page.formSelector.find("#form-msg").html(CCB.loctxt.error.checkredfield);
          break;
        default:
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(data).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          break;
      }
      CCB.qas.page.formSelector.fadeIn("slow");
      CCB.Form.init(CCB.parentselector);

      //SPECIFIC > update contact us subject and mailto
        J('input[id*=mail_subject]').attr('value', J('input[name=FAQ]').val().split('#')[0]);
        J('input[id*=mail_subsubject]').attr('value', '###' + J('input[name=FAQ]').val().split('#')[1]);
        J('input[id*=mailto]').attr('value', J('input[name=FAQ]').val().split('#')[1]);
        CCB.qas.page.formSelector.find("#form-msg-subject").html("");

      //SPECIFIC > remove error msg for textarea on blur
      J("textarea[id*='mail_body']").focus(function () {
        CCB.qas.page.formSelector.find("#form-msg-textarea").html("");
      });

      //SPECIFIC > if postback, update subject radio button with the  input hidden mail_subject
      var postbacksubject = J('input[id*=mail_subject]').val() + "#" + J('input[id*=mailto]').val();
      if (postbacksubject != "#") {
        J('input[name=FAQ]').each(function () {
          if (J(this).val() == postbacksubject) {
            J(this).attr("checked", "checked");
          }
        });
      }

      //Submit User form (SPECIFIC)
      CCB.parentselector.find("#qas-submit").click(function () {
        CCB.qas.page.formSelector.find("#form-msg").html("");
        var isValidSubject = false;
        var isValidMsg = false;

        //1. CHECK JS validation
        var isValidForm = CCB.Form.submitIsValid(CCB.parentselector);

        //Verif objet du message
        J('input[name=FAQ]').each(function () {
          if (J(this).attr("checked")) {
            isValidSubject = true;
          }
        });

        //Verif message
        if (J("textarea[id*='mail_body']").val() == "") {
          var isValidMsg = false;
        }

        if ((!isValidSubject) || (!isValidSubject))
          isValidForm = false;
		  
		
        //2. si TRUE : CHECK QAS
        if (isValidForm) {
          CCB.qas.serializeCreateForm(CCB.qas.page.formSelector);
          CCB.qas.wsQasCall();
        } else {
          CCB.qas.page.formSelector.find("#form-msg").html("Au moins une information saisie n'est pas correcte. Merci de vérifier les zones affichées en rouge.").scroll();
          if (!isValidSubject)
            CCB.qas.page.formSelector.find("#form-msg-subject").html("<img src='/img/common/checkout/identification/cross_false.gif' /> Veuillez saisir un sujet !");
          if (!isValidMsg)
            CCB.qas.page.formSelector.find("#form-msg-textarea").html("<img src='/img/common/checkout/identification/cross_false.gif' /> Veuillez saisir un message !");
        }
        return false;
      });
	
	J('textarea[name*=mail_body]').html(resp);
	
    });
    /*  [QAS functionnality] */	 
	
  }
});


//======================================================================================================
//======================================================================================================
//	CCB.Layer
//	Function called onReady website LAYER
//	To use this, the layer must include an input type hidden define like this :
//	<input type="hidden" id="ccbjs" value="myfunctionname" style="display:none" />
//======================================================================================================
CCB.Layer = CCB.Layer || {};
J.extend(CCB.Layer, {
  addproduct: function () {

    parent.Shadowbox.dynamicResize(622, 450);
    if (CCB.Data.Page.Name == "shopping-card.aspx") {
      CCB.ShadowBox.refreshParent = "true";
    }
    var length = J("#shadowbox_content").contents().find("#addtobagsuccess").length;
    if (length > 0) {
      J("#mini_basket").load("/ajax/refreshminibasket.aspx", CCB.Minibag.refreshBag);

      //Find promoted price
      var parentselector = J("#shadowbox_content").contents();
      CCB.Services.PromotedPrice(parentselector);
    }
    else if (CCB.debug) {
      alert("failed");
    } 
  },
  customerregister: function () {
    parent.Shadowbox.dynamicResize(880, 600);
    /*  [QAS functionnality] */
    var parentselector = J("#shadowbox_content").contents();
    CCB.parentselector = parentselector;
    CCB.qas.page.formSelector = parentselector.find("#cc_tunnel-identification-form");
    CCB.qas.page.formType = "layer";
    CCB.qas.page.formUrl = "/customer/personal_inscription.aspx"; //877x670
    CCB.qas.page.formUrlWidth = "880";
    CCB.qas.page.formUrlHeight = "600";
    CCB.qas.page.successType = "layer";
    CCB.qas.page.successUrl = "/customer/personal_inscription_conf.aspx"; //860x100
    CCB.qas.page.successUrlWidth = "600";
    CCB.qas.page.successUrlHeight = "200";
    CCB.qas.page.ajaxCallUrl = CCB.Data.Site.Name + "/ajax/qas-register.aspx";

    //Display User form
    J.get(CCB.qas.page.ajaxCallUrl + "?time" + Math.round(Math.random() * 1000), function (data) {
      //if come from QAS layer back to form (or error webbox)
      switch (CCB.qas.page.formBackToFlag) {
        case true:
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(data).filter("FORM").html());
          CCB.qas.customerBackToFormDataRecovery();
          break;
        case "error":
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(CCB.qas.page.formBackDataAjax).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          CCB.qas.page.formSelector.find("#form-msg").html(CCB.loctxt.error.checkredfield);
          break;
        case "account":
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(CCB.qas.page.formBackDataAjax).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          CCB.qas.page.formSelector.find("#form-msg").html(CCB.loctxt.error.checkexistingaccount);
          break;
        default:
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(data).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          break;
      }
      CCB.qas.page.formSelector.fadeIn("slow");
      CCB.Form.init(CCB.parentselector);

      //SPECIFIC > FORM CREATE ACCOUNT - check to update login field with email field
      parentselector.find("input[id$='email']").blur(function () {
        CCB.Customer.setLoginWithEmail();
      });

      //Submit User form
      parentselector.find("#qas-submit").click(function () {
        //1. CHECK JS validation
        var isValidForm = CCB.Form.submitIsValid(CCB.parentselector);

        //2. si TRUE : CHECK QAS
        if (isValidForm) {
          CCB.qas.serializeCreateForm(CCB.qas.page.formSelector);
          CCB.qas.wsQasCall();
        }
        return false;
      });
    });
    /*  [/QAS functionnality] */
  },
  customerregisterconf: function () {
    parent.Shadowbox.dynamicResize(600, 200);
    window.setTimeout(CCB.Services.RedirectTo("parent", "/customer/signed/myaccount_homepage.aspx", 2000));
  },
  customeridentification: function () {
  parent.Shadowbox.dynamicResize(440, 300);
  CCB.Services.KeyListener.onLayer("customeridentification");
  },
    confirmnewsletter: function () {
    parent.Shadowbox.dynamicResize(512, 330);
  },
  orderidentification: function () {
  parent.Shadowbox.dynamicResize(450, 315);
  CCB.Services.KeyListener.onLayer("orderidentification");
  },

  customerlostpwd: function () {
  parent.Shadowbox.dynamicResize(430, 250);
  CCB.Services.KeyListener.onLayer("customerlostpwd");
},
newsletterinscription: function() {
    CCB.Services.KeyListener.onLayer("newsletterinscription");
},
  customerupdate: function () {
  parent.Shadowbox.dynamicResize(877, 670);
  CCB.Services.KeyListener.onLayer("customerupdate");
    /*  [QAS functionnality] */
    var parentselector = J("#shadowbox_content").contents();
    CCB.parentselector = parentselector;
    CCB.qas.page.formSelector = parentselector.find("#cc_tunnel-identification-form");
    CCB.qas.page.formType = "layer";
    	CCB.qas.page.formUrl = CCB.Data.Site.Name + "/customer/signed/layer_modify_contact.aspx"; //877x670
    CCB.qas.page.formUrlWidth = "877";
    CCB.qas.page.formUrlHeight = "670";
    CCB.qas.page.successType = "layer";
    	CCB.qas.page.successUrl = CCB.Data.Site.Name + "/customer/signed/layer_confirm-modify_contact.aspx"; //860x100
    CCB.qas.page.successUrlWidth = "860";
    CCB.qas.page.successUrlHeight = "100";
    	CCB.qas.page.ajaxCallUrl = CCB.Data.Site.Name + "/ajax/qas-edit.aspx";

    //Display User form
    J.get(CCB.qas.page.ajaxCallUrl + "?time" + Math.round(Math.random() * 1000), function (data) {
      //if come from QAS layer back to form (or error webbox)
      switch (CCB.qas.page.formBackToFlag) {
        case true:
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(data).filter("FORM").html());
          CCB.qas.customerBackToFormDataRecovery();
          break;
        case "error":
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(CCB.qas.page.formBackDataAjax).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          CCB.qas.page.formSelector.find("#form-msg").html(CCB.loctxt.error.checkredfield);
          break;
        case "account":
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(CCB.qas.page.formBackDataAjax).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          CCB.qas.page.formSelector.find("#form-msg").html(CCB.loctxt.error.checkexistingaccount);
          break;
        default:
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(data).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          break;
      }
      CCB.qas.page.formSelector.fadeIn("slow");
      CCB.Form.init(CCB.parentselector);

      //Submit User form
      parentselector.find("#qas-submit").click(function () {
        //1. CHECK JS validation
        var isValidForm = CCB.Form.submitIsValid(CCB.parentselector);

        //2. si TRUE : CHECK QAS
        if (isValidForm) {
          CCB.qas.serializeCreateForm(CCB.qas.page.formSelector);
          CCB.qas.wsQasCall();
        }
        return false;
      });
    });
    /*  [/QAS functionnality] */
  },
  customerupdateconfirm: function () {
    parent.Shadowbox.dynamicResize(860, 100);
  },
  customermailpwd: function () {
  parent.Shadowbox.dynamicResize(425, 430);
  CCB.Services.KeyListener.onLayer("customermailpwd");
    var parentselector = J("#shadowbox_content").contents();

    //FORM CREATE ACCOUNT - check to update login field with email field
    parentselector.find("input[id$='email']").blur(function () {
      CCB.Customer.setLoginWithEmail();
    });
    CCB.Form.init(parentselector);

    parentselector.find("a[id*='submit']").click(function () {
      var isValidForm = CCB.Form.submitIsValid(parentselector);
      if (!isValidForm) {
        return false;
      }
    });
  },
  customermailpwdconfirm: function () {
    parent.Shadowbox.dynamicResize(425, 100);
  },
  customernewsletter: function () {
  parent.Shadowbox.dynamicResize(600, 280);
  CCB.Services.KeyListener.onLayer("customernewsletter");
  },
  /**
  * CCB.Layer.deliverymyaddr :
  */
  deliverymyaddr: function () {
    parent.Shadowbox.dynamicResize(600, 545);
    /*  [QAS functionnality] */
    var parentselector = J("#shadowbox_content").contents();
    CCB.parentselector = parentselector;

    var postType = CCB.parentselector.find("#param-sc").val();
    var checkAddress = CCB.parentselector.find("#param-chk").val();
    switch (postType) {
      case "LAPOSTECO":
        CCB.qas.page.successUrl = "/checkout/delivery.aspx?sc=LAPOSTECO";
        CCB.qas.page.ajaxCallUrl = "/ajax/qas-myaddr-eco.aspx?sc=" + postType + "&chk=" + checkAddress;
        break;
      case "LAPOSTE24":
        CCB.qas.page.successUrl = "/checkout/delivery.aspx?sc=LAPOSTE24";
        CCB.qas.page.ajaxCallUrl = "/ajax/qas-myaddr-24.aspx?sc=" + postType + "&chk=" + checkAddress;
        break;
    }
    CCB.qas.page.formSelector = parentselector.find("#cc_livraison_colissimo-form");
    CCB.qas.page.formType = "layer";
    CCB.qas.page.formUrl = "/checkout/layer_change_myaddress.aspx";
    CCB.qas.page.formUrlWidth = "600";
    CCB.qas.page.formUrlHeight = "545";
    CCB.qas.page.successType = "page";
    CCB.qas.page.successUrlWidth = "";
    CCB.qas.page.successUrlHeight = "";

    //Display User form
    J.get(CCB.qas.page.ajaxCallUrl + "&time=" + Math.round(Math.random() * 1000), function (data) {
      //if come from QAS layer back to form (or error webbox)
      switch (CCB.qas.page.formBackToFlag) {
        case true:
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(data).filter("FORM").html());
          CCB.qas.customerBackToFormDataRecovery();
          break;
        case "error":
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(CCB.qas.page.formBackDataAjax).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          CCB.qas.page.formSelector.find("#form-msg").html(CCB.loctxt.error.checkredfield);
          break;
        default:
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(data).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          break;
      }
      CCB.qas.page.formSelector.fadeIn("slow");
      CCB.Form.init(CCB.parentselector);

      CCB.parentselector.find(".btn_close").click(function () { parent.Shadowbox.close(); });

      //SPECIFIC > In case of poste 24, check if prohibited zip entered
      CCB.parentselector.find("input[id*='address_zip']").blur(function () {
        if (CCB.parentselector.find("input#checklaposte24").length > 0) {
          var errorZip = CCB.Form.prohibitedDeliveryZip(CCB.parentselector.find("input[id*='address_zip']"));
        }
      });

      //SPECIFIC > if URL parameter chk=1
      if (CCB.parentselector.find("input[id='checklaposte24']").val() == 1) {
        CCB.parentselector.find("p#txtlaposte24 span.important").attr("style", "");
        CCB.parentselector.find("input[id*='address_zip']").css("border", "#FF0000 solid 1px");
        CCB.parentselector.find("input[id*='phone']").css("border", "#FF0000 solid 1px");
      }

      CCB.parentselector.find("#qas-submit").click(function () {
        //1. CHECK JS validation
        var isValidForm = CCB.Form.submitIsValid(CCB.parentselector);

        //2. si TRUE : CHECK QAS
        if (isValidForm) {
          CCB.qas.serializeCreateForm(CCB.qas.page.formSelector);
          CCB.qas.wsQasCall();
        }
        return false;
      });

    });
    /*  [/QAS functionnality] */

  },
  /**
  * CCB.Layer.deliveryotheraddr : used for layer \checkout\layer_change_otheraddress.html
  */
  deliveryotheraddr: function () {
    parent.Shadowbox.dynamicResize(600, 575);
    /*  [QAS functionnality] */
    var parentselector = J("#shadowbox_content").contents();
    CCB.parentselector = parentselector;

    //must check in which case we are to define generic variable : LAPOSTECO or LAPOSTE24 and if GIFT
    var postType = CCB.parentselector.find("#param-sc").val();
    var isGift = CCB.parentselector.find("#param-gift").val();
    switch (postType) {
      case "LAPOSTECO":
        if (isGift == "1") {
          CCB.qas.page.successUrl = "/checkout/payment.aspx?sc=GIFT";
        } else {
          CCB.qas.page.successUrl = "/checkout/payment.aspx?sc=LAPOSTECO";
        }
        CCB.qas.page.ajaxCallUrl = "/ajax/qas-otheraddr-eco.aspx?sc=" + postType + "&gift=" + isGift;
        break;
      case "LAPOSTE24":
        if (isGift == "1") {
          CCB.qas.page.successUrl = "/checkout/payment.aspx?sc=GIFT";
        } else {
          CCB.qas.page.successUrl = "/checkout/payment.aspx?sc=LAPOSTE24";
        }
        CCB.qas.page.ajaxCallUrl = "/ajax/qas-otheraddr-24.aspx?sc=" + postType + "&gift=" + isGift;
        break;
    }
    CCB.qas.page.formSelector = parentselector.find("#cc_livraison_colissimo-form");
    CCB.qas.page.formType = "layer";
    CCB.qas.page.formUrl = "/checkout/layer_change_otheraddress.aspx";
    CCB.qas.page.formUrlWidth = "600";
    CCB.qas.page.formUrlHeight = "575";
    CCB.qas.page.successType = "page";
    CCB.qas.page.successUrlHeight = "";
    CCB.qas.page.successUrlWidth = "";

    //Display User form
    /* BEGIN obe.2010.09.22 => fix for /checkout/layer_change_otheraddress.aspx => add "&edit=false" to the AjaxCallUrl  */
    J.get(CCB.qas.page.ajaxCallUrl + "&edit=false&time=" + Math.round(Math.random() * 1000), function (data) {
      //must check if come from QAS layer back to form (or error webbox)
      switch (CCB.qas.page.formBackToFlag) {
        case true:
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(data).filter("FORM").html());
          CCB.qas.customerBackToFormDataRecovery();
          break;
        case "error":
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(CCB.qas.page.formBackDataAjax).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          CCB.qas.page.formSelector.find("#form-msg").html(CCB.loctxt.error.checkredfield);
          break;
        default:
          CCB.qas.page.formSelector.html("").css("display", "none").append(J(data).filter("FORM").html());
          CCB.Form.displayAddress(CCB.parentselector);
          break;
      }
      CCB.Layer.deliveryDisplayExistingAddress();
      CCB.Layer.deliveryotheraddrInit();
    });

    //Submit click button
    CCB.parentselector.find("#qas-submit").click(function () {
      //1. CHECK JS validation
      var isValidForm = CCB.Form.submitIsValid(CCB.qas.page.formSelector);

      //2. si TRUE : CHECK QAS
      if (isValidForm) {
        CCB.qas.serializeCreateForm(CCB.qas.page.formSelector);
        CCB.qas.wsQasCall();
      }
      return false;
    });
    /*  [QAS functionnality] */
  },
  /**
  *  CCB.Layer.deliveryDisplayExistingAddress : sub function of CCB.Layer.deliveryotheraddr : used for layer \checkout\layer_change_otheraddress.html
  */
  deliveryDisplayExistingAddress: function () {
    CCB.qas.page.formSelector.find("select[id*='ChoiceCtrlId']").change(function () {
      CCB.qas.wsQasLoadingScreenStart();
      // je suis dans le cas ou je souhaite afficher une @ de livraison existante
      // je dois donc appeler en AJAX la page form delivery (création du fake form) en lui passant uniquement le nom de l'@ à afficher (et en vidant tous les autres champs du form delivery)
      CCB.qas.serializeCreateForm(CCB.qas.page.formSelector);
      var theForm = J("#form-to-submit div.formAjaxDelivery");
      theForm.find("select,textarea,input[type=text],input[type=hidden],input[type=password]").each(function () {
        J(this).val("");
      });
      theForm.find("input[type=checkbox],input[type=radio]").each(function () {
        J(this).removeAttr("checked");
      });

      //Serialize data fake form
      var dataForm = J("#form-to-submit").serialize();

      J.post(CCB.qas.page.ajaxCallUrl + "&time=" + Math.round(Math.random() * 1000), dataForm, function (data) {
        CCB.parentselector.find("#cc_tunnel-livraison-adresse_temp").html("").append(J(data).filter("FORM").html());

        //update real form
        var theForm = CCB.qas.page.formSelector.find("div.formAjaxDelivery");
        var secondForm = CCB.parentselector.find("#cc_tunnel-livraison-adresse_temp div.formAjaxDelivery");

        secondForm.find("select,textarea,input[type=text],input[type=hidden],input[type=password]").each(function (i, e) {
          theForm.find("select,textarea,input[type=text],input[type=hidden],input[type=password]").eq(i).val(J(e).val());
        });
        secondForm.find("input[type=checkbox],input[type=radio]").each(function (i, e) {
          theForm.find("input[type=checkbox],input[type=radio]").eq(i).attr("checked", J(e).attr("checked"));
        });

        CCB.Form.displayAddress(CCB.parentselector);
        CCB.qas.wsQasLoadingScreenStop();
      }); ;

      return false;
    });
  },
  /**
  *  CCB.Layer.deliveryotheraddrInit : sub function of CCB.Layer.deliveryotheraddr : used for layer \checkout\layer_change_otheraddress.html
  */
  deliveryotheraddrInit: function () {

    CCB.qas.page.formSelector.fadeIn("slow");
    CCB.Form.init(CCB.parentselector);
    //CCB.Form.displayAddress(CCB.parentselector);

    //In case of poste 24, check if prohibited zip entered
    CCB.parentselector.find("input[id*='address_zip']").blur(function () {
      if (CCB.parentselector.find("input#checklaposte24").length > 0) {
        var errorZip = CCB.Form.prohibitedDeliveryZip(CCB.parentselector.find("input[id*='address_zip']"));
      }
    });
  },
  /**
  *  CCB.Layer.keycode :
  */
  keycode: function (keycode) {
    Shadowbox.open({
      //content: "/services/layer_key-code.aspx?step=valid&keycode=" + keycode,
      content: "/services/layer_redirect.aspx?keycode=" + keycode,
      player: "iframe",
      height: 250,
      width: 430
    });
  },
  /**
  *  CCB.Layer.keycodelayer :
  */
  keycodelayer: function () {
    if (J("#shadowbox_content").contents().find("#success").length > 0) {
      CCB.ShadowBox.refreshParent = true;
    }
  },
  /**
  *  CCB.Layer.keycodeinitlayer :
  */
  keycodeinitlayer: function () {
    CCB.ShadowBox.refreshParent = true;
  },
  /**
  *  CCB.Layer.keycodecapture :
  */
  keycodecapture: function () {
    //keycode layer more about key code field
    J("#shadowbox_content").contents().find("input[id*='keycode']").keyup(function () {
      var keycodefield = J(this).val().toUpperCase().replace(" ", "");
      J(this).val(keycodefield);
    });
    CCB.Services.KeyListener.onLayer("keycodecapture");
    /**
    *  CCB.Layer.forfriendlayer :
    */
  },
  forfriendlayer: function () {
    parent.Shadowbox.dynamicResize(600, 370);
    J("#shadowbox_content").contents().find("#Url").attr("value", parent.location.href);
  },
  /**
  *  CCB.Layer.newsletter :
  */
  newsletter: function (email) {
    Shadowbox.open({
      content: "/services/layer_confirmation-newsletter.aspx?PromEmail=" + email + "&PromEmailAction=add",
      player: "iframe",
      height: 500,
      width: 570
    });
  },
  error: function (type) {
    Shadowbox.open({
      content: "/services/layer_error.aspx?errortype=" + type,
      player: "iframe",
      height: 250,
      width: 430
    });
  },
  errorparam: function (text) {
    //alert("errorparam avec text : "+text);
    Shadowbox.open({
      content: "/services/layer_error.aspx?errortype=" + text,
      player: "iframe",
      height: 250,
      width: 430
    });
  },
  errorlayer: function () {
    parent.Shadowbox.dynamicResize(430, 250);
  },
  invalid: function () {
    J("#shadowbox_content").contents().find("h1#errorheader").html(CCB.loctxt.error.invalidformatheader);
    J("#shadowbox_content").contents().find("p#errormsg").html(CCB.loctxt.error.invalidformat);
  },
  blank: function () {
    J("#shadowbox_content").contents().find("p#errormsg").html(CCB.loctxt.error.blankinput);
  },
  shoppingcardblank: function () {
    J("#shadowbox_content").contents().find("p#errormsg").html(CCB.loctxt.error.shoppingcardblank);
  },
  maxbasketqtymessage: function () {
    J("#shadowbox_content").contents().find("p#errormsg").html(CCB.loctxt.error.maxbasketqtymessage);
  },
  maxbasketamountmessage: function () {
    J("#shadowbox_content").contents().find("p#errormsg").html(CCB.loctxt.error.maxbasketamountmessage);
  },
  productemptymessage: function () {
    J("#shadowbox_content").contents().find("p#errormsg").html(CCB.loctxt.error.productemptymessage);
  },
  maxbasketitemqtymessage: function () {
    J("#shadowbox_content").contents().find("p#errormsg").html(CCB.loctxt.error.maxbasketitemqtymessage);
  },
  outofstockmessage: function () {
    J("#shadowbox_content").contents().find("p#errormsg").html(CCB.loctxt.error.outofstockmessage);
  },
  reviewall: function () {
    parent.Shadowbox.dynamicResize(640, 650);
  },
  reviewid: function () {
    parent.Shadowbox.dynamicResize(680, 340);
  },
  reviewadd: function () {
    parent.Shadowbox.dynamicResize(685, 510);
    var $prdcodeinput = J("#shadowbox_content").contents().find("input[id*='f1prdcode']");
    if ($prdcodeinput.length <= 0) {
      J("#shadowbox_content").contents().find("div#prdcodeid").html("<span style='color:#FF0000'>Aucun produit séléctionné !</span>");
    }
  },
  reviewaddconf: function () {
    parent.Shadowbox.dynamicResize(680, 250);
  },
  reviewcharte: function () {
    parent.Shadowbox.dynamicResize(680, 455);
  },
  productlayershade: function () {
    parent.Shadowbox.dynamicResize(622, 510);
    //alert("CCB.Layer.productlayershade");

    var parentselector = J("#shadowbox_content").contents();
    parentselector.find("p.cc_ficheproduit-interaction").css("display", "none");

    if (parentselector.find("select#prd_selectref").length > 0) {
      CCB.Catalog.Product.updateProductInfo(parentselector);
      CCB.Catalog.Product.updatePrdPrice(parentselector);
      CCB.Catalog.Product.updatePrdCapacity(parentselector);
      CCB.Catalog.Product.updateEcoTaxe(parentselector);
      CCB.Catalog.Product.updatePrdStock(parentselector);
      CCB.Catalog.Product.updatePrdBtnBasket(parentselector);
      CCB.Catalog.Product.updatePrdBtnOpenSet(parentselector);
      //CCB.Catalog.Product.updatePrdBookmark(parentselector);
      //CCB.Catalog.Product.updatePrdFriend(parentselector);
    }

    parentselector.find("select#prd_selectref").change(function () {
      CCB.Catalog.Product.updateProductInfo(parentselector);
      CCB.Catalog.Product.updatePrdShade(parentselector);
      CCB.Catalog.Product.updatePrdPrice(parentselector);
      CCB.Catalog.Product.updatePrdImg(parentselector);
      CCB.Catalog.Product.updateEcoTaxe(parentselector);
      CCB.Catalog.Product.updatePrdBtnBasket(parentselector);
      CCB.Catalog.Product.updatePrdBtnOpenSet(parentselector);
    });

    parentselector.find("select[id*='prd_selectqty']").change(function () {
      CCB.Catalog.Product.updateProductInfo(parentselector);
      CCB.Catalog.Product.updatePrdBtnBasket(parentselector);
    });

    parentselector.find("a[id*='prd_shade']").click(function () {
      parentselector.find("ul.cc_ficheproduit-details-palette a").removeClass("actif");
      J(this).addClass("actif");
      CCB.Catalog.Product.updatePrdSelectRef(parentselector, J(this).attr("id").substr(9, J(this).attr("id").length));
      CCB.Catalog.Product.updateProductInfo(parentselector);
      CCB.Catalog.Product.updatePrdPrice(parentselector);
      CCB.Catalog.Product.updatePrdImg(parentselector);
      CCB.Catalog.Product.updateEcoTaxe(parentselector);
      CCB.Catalog.Product.updatePrdBtnBasket(parentselector);
      CCB.Catalog.Product.updatePrdBtnOpenSet(parentselector);
      return false;
    });

    if (parentselector.find("label[id*=FailureAddOpenSet]").length > 0) {
      Shadowbox.open({
        content: "/catalog/layer_open-set_error.aspx?osid=" + parentselector.find("input#opensetiderror").val(),
        player: "iframe",
        height: 200,
        width: 605
      });
    }
    //parentselector.find("span#opensetspan").text(parentselector.find("input#opensettext").val());
    if (parentselector.find("input#opensetaddsuccess").length > 0) {
      Shadowbox.open({
        content: "/catalog/layer_open-set.aspx?osid=" + parentselector.find("input#opensetaddsuccess").val(),
        player: "iframe",
        height: 650,
        width: 805
      });
    }

    if (parentselector.find("input[id='displaytaille']").length > 0) {
      parentselector.find("div.cc_layer-top h1").html(CCB.loctxt.generic.layershadetitlesize);
    }

  },
  productzoom: function () {
    parent.Shadowbox.dynamicResize(480, 510);
  },
  productbookmark: function () {
    parent.Shadowbox.dynamicResize(430, 150);
  },
  productlookdynamic: function () {
    parent.Shadowbox.dynamicResize(670, 700);
    //Find promoted price
    var parentselector = J("#shadowbox_content").contents();
    CCB.Services.PromotedPrice(parentselector);
  },
  opensetlayer: function () {
    parent.Shadowbox.dynamicResize(805, 600);
    var parentselector = J("#shadowbox_content").contents();
    CCB.ShadowBox.refreshParent = true;
    parentselector.find("a#hrefshopping").click(function () {
      CCB.Services.RedirectTo("", window.parent.location.href);
    });
    //saveamount
  },
  /**
  *  CCB.Layer.qasunknownaddress : \ajax\qas_unknownaddress.html
  */
  qasunknownaddress: function () {
    parent.Shadowbox.dynamicResize(600, 420);
    var parentselector = J("#shadowbox_content").contents();
    CCB.parentselector = parentselector;

    //display user address
    var theForm = J("#form-to-submit");
    parentselector.find("#customerstaticaddressline").html(theForm.find("input[id='static_line3']").val());
    parentselector.find("#customerstaticzip").html(theForm.find("input[id*='address_zip']").val());
    parentselector.find("#customerstaticcity").html(theForm.find("input[id*='address_city']").val());

    //When User click on the VALID btn
    parentselector.find("a[id*='submit']").click(function () {
      switch (parentselector.find("input[name='choixaddress']:checked").val()) {
        case "continue":
          CCB.qas.serializeUpdateFormQasNok();
          CCB.qas.customerAjaxUpate();
          break;
        case "modify":
		  //alert('test');
          CCB.qas.customerBackToForm();
          break;
      }
    });
  },
  /**
  *  CCB.Layer.qasmultipleaddress : \ajax\qas_multipleaddress.html
  */
  qasmultipleaddress: function () {
    parent.Shadowbox.dynamicResize(600, 420);
    var parentselector = J("#shadowbox_content").contents();
    CCB.parentselector = parentselector;

    //display user address
    var theForm = J("#form-to-submit");
    parentselector.find("#customerstaticaddressline").html(theForm.find("input[id='static_line3']").val());
    parentselector.find("#customerstaticzip").html(theForm.find("input[id*='address_zip']").val());
    parentselector.find("#customerstaticcity").html(theForm.find("input[id*='address_city']").val());

    //Build the SELECT for QAS RESULT
    CCB.qas.htmlselectresult = "<select>";
    for (var i = 0; i < CCB.qas.eventList.AddressResList.length; i++) {
      CCB.qas.htmlselectresult = CCB.qas.htmlselectresult + "<option>" + CCB.qas.eventList.AddressResList[i].Line2 + " " + CCB.qas.eventList.AddressResList[i].Line3 + " " +
			                    CCB.qas.eventList.AddressResList[i].Line1 + " " + CCB.qas.eventList.AddressResList[i].PostCode + " " +
			                    CCB.qas.eventList.AddressResList[i].City + " " + CCB.qas.eventList.AddressResList[i].Country + "</option>";
    }
    CCB.qas.htmlselectresult = CCB.qas.htmlselectresult + "</select>";

    //And display it
    parentselector.find("#address-suggested").html(CCB.qas.htmlselectresult);

    //When User click on the VALID btn
    parentselector.find("a[id*='submit']").click(function () {
      switch (parentselector.find("input[name='choixaddress']:checked").val()) {
        case "selectlist":
          CCB.qas.serializeUpdateFormQasOk(parentselector.find("#address-suggested select").attr("selectedIndex"));
          CCB.qas.customerAjaxUpate();
          break;
        case "continue":
          CCB.qas.serializeUpdateFormQasNok();
          CCB.qas.customerAjaxUpate();
          break;
        case "modify":
          CCB.qas.customerBackToForm();
          break;
      }
    });
  }
});
(function(a){a.flexslider=function(c,b){var d=c;d.init=function(){d.vars=a.extend({},a.flexslider.defaults,b);d.data("flexslider",true);d.container=a(".slides",d);d.slides=a(".slides > li",d);d.count=d.slides.length;d.animating=false;d.currentSlide=d.vars.slideToStart;d.eventType=("ontouchstart" in document.documentElement)?"touchstart":"click";if(d.vars.controlsContainer!=""){d.controlsContainer=a(d.vars.controlsContainer).eq(a(".slides").index(d.container));d.containerExists=d.controlsContainer.length>0}if(d.vars.manualControls!=""){if(d.containerExists){d.manualControls=a(d.vars.manualControls,d.controlsContainer)}else{d.manualControls=a(d.vars.manualControls,d)}d.manualExists=d.manualControls.length>0}if(d.vars.randomize&&d.count>1){d.slides.sort(function(){return(Math.round(Math.random())-0.5)});d.container.empty().append(d.slides)}if(d.vars.animation.toLowerCase()=="slide"&&d.count>1){d.css({overflow:"hidden"});d.container.append(d.slides.filter(":first").clone().addClass("clone")).prepend(d.slides.filter(":last").clone().addClass("clone"));d.container.width(((d.count+2)*d.width())+2000);d.newSlides=a(".slides > li",d);setTimeout(function(){d.newSlides.width(d.width()).css({"float":"left"}).show()},100);d.container.css({marginLeft:(-1*(d.currentSlide+1))*d.width()+"px"})}else{d.slides.hide().eq(d.currentSlide).fadeIn(400)}if(d.vars.controlNav&&d.count>1){if(d.manualExists){d.controlNav=d.manualControls}else{var e=a('<ol class="flex-control-nav"></ol>');var f=1;for(var g=0;g<d.count;g++){e.append("<li><a>"+f+"</a></li>");f++}if(d.containerExists){a(d.controlsContainer).append(e);d.controlNav=a(".flex-control-nav li a",d.controlsContainer)}else{d.append(e);d.controlNav=a(".flex-control-nav li a",d)}}d.controlNav.eq(d.currentSlide).addClass("active");d.controlNav.bind(d.eventType,function(i){i.preventDefault();if(!(a(this).hasClass("active")||d.animating)){d.controlNav.removeClass("active");a(this).addClass("active");var h=d.controlNav.index(a(this));d.flexAnimate(h);if(d.vars.pauseOnAction){clearInterval(d.animatedSlides)}}})}if(d.vars.directionNav&&d.count>1){if(d.containerExists){a(d.controlsContainer).append(a('<ul class="flex-direction-nav"><li><a class="prev" href="#">'+d.vars.prevText+'</a></li><li><a class="next" href="#">'+d.vars.nextText+"</a></li></ul>"));d.directionNav=a(".flex-direction-nav li a",d.controlsContainer)}else{d.append(a('<ul class="flex-direction-nav"><li><a class="prev" href="#">'+d.vars.prevText+'</a></li><li><a class="next" href="#">'+d.vars.nextText+"</a></li></ul>"));d.directionNav=a(".flex-direction-nav li a",d)}d.directionNav.bind(d.eventType,function(h){h.preventDefault();if(d.animating){return}else{if(a(this).hasClass("next")){var i=(d.currentSlide==d.count-1)?0:d.currentSlide+1}else{var i=(d.currentSlide==0)?d.count-1:d.currentSlide-1}if(d.vars.controlNav){d.controlNav.removeClass("active");d.controlNav.eq(i).addClass("active")}d.flexAnimate(i);if(d.vars.pauseOnAction){clearInterval(d.animatedSlides)}}})}if(d.vars.keyboardNav&&d.count>1&&a("ul.slides").length==1){a(document).keyup(function(h){if(d.animating){return}else{if(h.keyCode!=39&&h.keyCode!=37){return}else{if(h.keyCode==39){var i=(d.currentSlide==d.count-1)?0:d.currentSlide+1}else{if(h.keyCode==37){var i=(d.currentSlide==0)?d.count-1:d.currentSlide-1}}if(d.vars.controlNav){d.controlNav.removeClass("active");d.controlNav.eq(i).addClass("active")}d.flexAnimate(i);if(d.vars.pauseOnAction){clearInterval(d.animatedSlides)}}}})}if(d.vars.slideshow){d.animatedSlides;if(d.vars.pauseOnHover&&d.vars.slideshow){d.hover(function(){clearInterval(d.animatedSlides)},function(){d.animatedSlides=setInterval(d.animateSlides,d.vars.slideshowSpeed)})}if(d.count>1){d.animatedSlides=setInterval(d.animateSlides,d.vars.slideshowSpeed)}}if(d.vars.touchSwipe&&"ontouchstart" in document.documentElement&&d.count>1){d.each(function(){var h,i=20;isMoving=false;function l(){this.removeEventListener("touchmove",j);h=null;isMoving=false}function j(p){if(isMoving){var m=p.touches[0].pageX,n=h-m;if(Math.abs(n)>=i){l();if(n>0){var o=(d.currentSlide==d.count-1)?0:d.currentSlide+1}else{var o=(d.currentSlide==0)?d.count-1:d.currentSlide-1}if(d.vars.controlNav){d.controlNav.removeClass("active");d.controlNav.eq(o).addClass("active")}d.flexAnimate(o);if(d.vars.pauseOnAction){clearInterval(d.animatedSlides)}}}}function k(m){if(m.touches.length==1){h=m.touches[0].pageX;isMoving=true;this.addEventListener("touchmove",j,false)}}if("ontouchstart" in document.documentElement){this.addEventListener("touchstart",k,false)}})}if(d.vars.animation.toLowerCase()=="slide"&&d.count>1){d.sliderTimer;a(window).resize(function(){d.newSlides.width(d.width());d.container.width(((d.count+2)*d.width())+2000);clearTimeout(d.sliderTimer);d.sliderTimer=setTimeout(function(){d.flexAnimate(d.currentSlide)},300)})}};d.flexAnimate=function(e){if(!d.animating){d.animating=true;if(d.vars.animation.toLowerCase()=="slide"){if(d.currentSlide==0&&e==d.count-1){d.container.animate({marginLeft:"0px"},d.vars.animationDuration,function(){d.container.css({marginLeft:(-1*d.count)*d.slides.filter(":first").width()+"px"});d.animating=false;d.currentSlide=e})}else{if(d.currentSlide==d.count-1&&e==0){d.container.animate({marginLeft:(-1*(d.count+1))*d.slides.filter(":first").width()+"px"},d.vars.animationDuration,function(){d.container.css({marginLeft:-1*d.slides.filter(":first").width()+"px"});d.animating=false;d.currentSlide=e})}else{d.container.animate({marginLeft:(-1*(e+1))*d.slides.filter(":first").width()+"px"},d.vars.animationDuration,function(){d.animating=false;d.currentSlide=e})}}}else{d.css({minHeight:d.slides.eq(d.currentSlide).height()});d.slides.eq(d.currentSlide).fadeOut(d.vars.animationDuration,function(){d.slides.eq(e).fadeIn(d.vars.animationDuration,function(){d.animating=false;d.currentSlide=e});d.css({minHeight:"inherit"})})}}};d.animateSlides=function(){if(d.animating){return}else{var e=(d.currentSlide==d.count-1)?0:d.currentSlide+1;if(d.vars.controlNav){d.controlNav.removeClass("active");d.controlNav.eq(e).addClass("active")}d.flexAnimate(e)}};d.init()};a.flexslider.defaults={animation:"fade",slideshow:true,slideshowSpeed:7000,animationDuration:500,directionNav:true,controlNav:true,keyboardNav:true,touchSwipe:true,prevText:"Previous",nextText:"Next",randomize:false,slideToStart:0,pauseOnAction:true,pauseOnHover:false,controlsContainer:"",manualControls:""};a.fn.flexslider=function(b){return this.each(function(){if(a(this).data("flexslider")!=true){new a.flexslider(a(this),b)}})}})(jQuery);
//jQuery FlexSlider v1.6
//---------------------
//On DOM Ready Let's Go
//---------------------
J(CCB.onReady);

