﻿Type.registerNamespace("Res.Commerce.Web.Composants.Commandes.V01");
Res.Commerce.Web.Composants.Commandes.V01.SelecteurAvantage = function (element) {
    Res.Commerce.Web.Composants.Commandes.V01.SelecteurAvantage.initializeBase(this, [element]);

    this._modifierButtonId = null;
    this._codeAvantage = null;
    this._saisieAvantageTextboxId = null;
    this._isOffreDuMoment = null;
    this._libelleMasquer = null;
    this._libelleLireLaSuite = null;
};
Res.Commerce.Web.Composants.Commandes.V01.SelecteurAvantage.prototype = {
    initialize: function () {
        Res.Commerce.Web.Composants.Commandes.V01.SelecteurAvantage.callBaseMethod(this, "initialize");
        $("#TogglerCodeAvantage").click(Function.createDelegate(this, this.showCodeAvantage));

        this._modifierButtonClickHandler = Function.createDelegate(this, this._modifierButtonClickHandler);
        $("#" + this._modifierButtonId).click(this._modifierButtonClickHandler);

        var prm = Sys.WebForms.PageRequestManager.getInstance();

        if (!Array.contains(prm._asyncPostBackControlIDs, "SelectedAvantageChanged")) {
            prm._asyncPostBackControlIDs.push("SelectedAvantageChanged");
        }
        if (!Array.contains(prm._asyncPostBackControlClientIDs, "SelectedAvantageChanged")) {
            prm._asyncPostBackControlClientIDs.push("SelectedAvantageChanged");
        }
        if (!this._isOffreDuMoment) {
            this._codeAvantage = "";
            this._modifierButtonClickHandler();
        }
        $("#" + this._saisieAvantageTextboxId).focus(Function.createDelegate(this, this._focusTextBoxHandler));
        $("#" + this._saisieAvantageTextboxId).keypress(Function.createDelegate(this, this._keypressTextBoxHandler));

    },
    showCodeAvantage: function (ev) {
        if ($(ev.target).parent().siblings('.memo_chko_suite').css("display") == "none") {
            $(ev.target).parent().siblings('.memo_chko_suite').css("display", "block");
            $(ev.target).text(this._libelleMasquer);
        }
        else {
            $(ev.target).parent().siblings('.memo_chko_suite').css("display", "none");
            $(ev.target).text(this._libelleLireLaSuite);
        }
    },
    dispose: function () {
        Res.Commerce.Web.Composants.Commandes.V01.SelecteurAvantage.callBaseMethod(this, "dispose");
    },
    saveClientState: function () {
        return null;
    },
    get_ModifierButtonId: function () {
        return this._modifierButtonId;
    },
    set_ModifierButtonId: function (value) {
        this._modifierButtonId = value;
    },
    get_CodeAvantage: function () {
        return this._codeAvantage;
    },
    set_CodeAvantage: function (value) {
        this._codeAvantage = value;
    },
    get_SaisieAvantageTextboxId: function () {
        return this._saisieAvantageTextboxId;
    },
    set_SaisieAvantageTextboxId: function (value) {
        this._saisieAvantageTextboxId = value;
    },
    get_IsOffreDuMoment: function () {
        return this._isOffreDuMoment;
    },
    set_IsOffreDuMoment: function (value) {
        this._isOffreDuMoment = value;
    },
    get_LibelleMasquer: function () {
        return this._libelleMasquer;
    },
    set_LibelleMasquer: function (value) {
        this._libelleMasquer = value;
    },
    get_LibelleLireLaSuite: function () {
        return this._libelleLireLaSuite;
    },
    set_LibelleLireLaSuite: function (value) {
        this._libelleLireLaSuite = value;
    },
    _modifierButtonClickHandler: function () {
        if (this._codeAvantage != $get(this._saisieAvantageTextboxId).value) {
            __doPostBack("SelectedAvantageChanged", $get(this._saisieAvantageTextboxId).value);
        }
    },
    _focusTextBoxHandler: function () {
        var node = $get(this._modifierButtonId);
        var selector = $(node).parent().parent().siblings('.memo_chko_customselect');
        selector.show();
        selector.find('.memo_chko_option').click(function () {
            $(this).siblings('.memo_chko_option').removeClass('memo_chko_option_selected');
            $(this).addClass('memo_chko_option_selected');
        });
    },
    _keypressTextBoxHandler: function (e) {
        var charCode = (e.which) ? e.which : e.keyCode;
        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            return false;
        }

    },
    _blurTextBoxHandler: function () {
        var node = $get(this._modifierButtonId);
        var selector = $(node).parent().parent().siblings('.memo_chko_customselect');
        selector.hide();
    }
};
Res.Commerce.Web.Composants.Commandes.V01.SelecteurAvantage.registerClass("Res.Commerce.Web.Composants.Commandes.V01.SelecteurAvantage", Res.Commerce.Web.Composants.ScriptControlBase);
if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded(); 
