﻿Type.registerNamespace('ActiveBets');
/*******************  ActiveBets.Bet  ***********************/

/*******************  ActiveBets.AcceptStatus  ***********************/
ActiveBets.AcceptStatus = function() {
    throw Error.invalidOperation();
}
ActiveBets.AcceptStatus.prototype = {
    Success: 0x00,
    Validate: 0x01,
    MaxBalanceExceed: 0x04,
    Internal: 0x10
}
ActiveBets.AcceptStatus.registerEnum("ActiveBets.AcceptStatus", true);

/*******************  ActiveBets.BetTypes  ***********************/
ActiveBets.BetTypes = function() {
    throw Error.invalidOperation();
}
ActiveBets.BetTypes.prototype = {
    Single: 0x00,
    Combi: 0x01,
    System: 0x02
}
ActiveBets.BetTypes.registerEnum("ActiveBets.BetTypes", true);

/*******************  ActiveBets.OddKinds  ***********************/
ActiveBets.OddKinds = function() {
    throw Error.invalidOperation();
}
ActiveBets.OddKinds.prototype = {
    LineOdd: 0x00,
    CustomOdd: 0x01,
    LongtermOdd: 0x02
}
ActiveBets.OddKinds.registerEnum("ActiveBets.OddKinds", true);

/*******************  ActiveBets.ValidationError  ***********************/
ActiveBets.ValidationError = function() {
    throw Error.invalidOperation();
}
ActiveBets.ValidationError.prototype = {
    OK: 0,
    OddNotExists: 1,
    EventBlocked: 2,
    EventDateChanged: 4,
    OddFactorChanged: 8,
    EventRefund: 16,
    IncorrectStake: 32,
    EventStarted: 64,
    OddFactorExceed: 128,
    PossibleWinExceed: 256
}
ActiveBets.ValidationError.registerEnum("ActiveBets.ValidationError", true);

/*******************  ActiveBets.BaseBet  ***********************/
ActiveBets.BaseBet = function() {
    this.Id = null;
    this.Limits = new ActiveBets.Limit();
    this.Amount = 0.0;
    this.OddFactor = 0.0;
    this.ErrorCode = ActiveBets.ValidationError.OK;

    this._bonus = 0.0;

    this.row = null;
    this.td_factor = null;
    this.tb_amount = null;
    this.td_limit = null;

    this.tr_error = null;
    this.td_error = null;

    this.card = $find('BettingsCard');
}
ActiveBets.BaseBet.prototype = {

    equals_by_id: function(id) {
        return this.Id == id;
    },

    get_factor: function() {
        return Math.abs(this.OddFactor);
    },
    set_factor: function(value) {
        this.OddFactor = value;
    },

    get_factor_desc: function() {
        if (ActiveBets.App.get_oddFormat() == "US")
            return String.format("{0}", this.card.get_odd_factor(this.OddFactor));
        else if (ActiveBets.App.get_oddFormat() == "UK")
            return String.format("{0}", this.card.get_odd_factor(this.OddFactor));
        else
            return String.format("{0:n2}", Number(this.OddFactor));
    },

    is_have_stake: function() {
        return this.Amount > 0.0;
    },

    get_amount: function(value) {
        return this.Amount;
    },
    set_amount: function(amount) {
        this.Amount = amount;
    },

    is_have_bonus: function() {
        return this._bonus > 0.0;
    },
    get_bonus: function() {
        return this._bonus;
    },
    set_bonus: function(bonus) {
        this._bonus = bonus;
    },

    get_row: function() {
        return this.row;
    },
    set_row: function(row) {
        this.row = row;
    },

    get_possible_win: function() {
        return this.Amount * this.OddFactor * (this.is_have_bonus() ? 1 + (this.get_bonus() / 100) : 1);
    },

    set_td_factor: function(value) {
        this.td_factor = value;
    },

    set_td_factor_innerHTML: function(value) {
        if (this.td_factor != null)
            this.td_factor.innerHTML = value;
    },

    set_tb_amount: function(tb_amount) {
        this.tb_amount = tb_amount;
        this.tb_amount.value = String.localeFormat("{0:N}", this.get_amount());
    },

    set_tb_amount_value: function(value) {
        if (this.tb_amount != null)
            this.tb_amount.value = String.localeFormat("{0:N}", value);
    },

    // region [ Limits ]
    get_limits: function() {
        return this.Limits;
    },
    set_limits: function(minPay, maxPay) {
        this.Limits.set_min_pay(minPay);
        this.Limits.set_max_pay(maxPay);
    },
    get_td_limit: function(td_limit) {
        return this.td_limit;
    },
    set_td_limit: function(td_limit) {
        this.td_limit = td_limit;
        this.show_limits();
    },
    get_min_pay: function() {
        return this.get_limits().get_min_pay();
    },
    get_max_pay: function() {
        if (this.get_limits().get_max_pay() == null)
            return null;
        if (this.BetType == ActiveBets.BetTypes.Single)
            return Math.round(this.get_limits().get_max_pay() / (this.get_factor() - 1));
        else
            return this.get_limits().get_max_pay();
    },
    show_limits: function(is_visible) {
        this.td_limit.innerHTML = is_visible ? this.limit_string() : '&nbsp;';
    },
    limit_string: function() {
        if (this.get_min_pay() == null && this.get_max_pay() == null)
            return Res.NoLimit;
        else if (this.get_min_pay() == null)
            return String.format('* - {0}', this.get_max_pay());
        else if (this.get_max_pay() == null)
            return String.format('{0} - *', this.get_min_pay());
        else
            return String.format('{0} - {1}', this.get_min_pay(), this.get_max_pay());
    },

    // endregion
    get_errorCode: function() {
        return this.ErrorCode;
    },
    set_errorCode: function(value) {
        this.ErrorCode = value;
    },
    // region [ tb_amount event handlers ]
    tb_amount_focus: function(e) {
        this.tb_amount.select();
    },
    // endregion

    check_limits: function() {
        if (this.get_min_pay() != null && this.get_amount() < this.get_min_pay() && this.get_amount() != 0) {
            var amount = this.get_min_pay();
            this.set_amount(amount);
            this.set_tb_amount_value(amount);
            this.set_errorCode(this.get_errorCode() | ActiveBets.ValidationError.IncorrectStake);
            this.card.update_bet(this);

            return false;
        }

        if (this.get_max_pay() != null && this.get_amount() > this.get_max_pay() && this.get_amount() != 0) {
            var amount = this.get_max_pay();
            this.set_amount(amount);
            this.set_tb_amount_value(amount);
            this.set_errorCode(this.get_errorCode() | ActiveBets.ValidationError.IncorrectStake);
            this.card.update_bet(this);

            return false;
        }
        return true;
    },

    _get_formated_value: function(value) {
        if (value.indexOf('-') >= 0)
            value = value.replace('-', '');

        if (value.indexOf(",") > 0) {
            value = value.replace(".", "");
        }
        //        value = value.replace(Sys.CultureInfo.CurrenctCulture.numberFormat.NumberGroupSeparator, '');

        return value.replace(",", ".");
    },

    set_td_error: function(value) {
        this.td_error = value;
    },

    set_tr_error: function(value) {
        this.tr_error = value;
    },

    set_error: function(value) {
        this.td_error.innerHTML = value;
        this.tr_error.style.display = '';
    },

    clear_error: function() {
        this.td_error.innerHTML = '';
        this.tr_error.style.display = 'none';
    }
}
ActiveBets.BaseBet.registerClass("ActiveBets.BaseBet");

/*******************  ActiveBets.Bet  ***********************/
ActiveBets.Bet = function() {
    ActiveBets.Bet.initializeBase(this);

    this.BetType = ActiveBets.BetTypes.Single;
    this.OddKind = null;
    this.Id = null;
    this.EventId = null;
    this.EventDate = null;
    this.LeagueId = null;
    this.HomeTeamName = null;
    this.GuestTeamName = null;
    this.OddId = null;
    this.BetTypeCode = null;
    this.BetGroupTypeId = null;
    this.BetTypeId = null;
    this.IsSystemPart = true;
    this.IsBank = false;
    this.ColumnIndex = null;
    this.BetTypeName = null;
    this.EventName = null;
    this.OddPoint = null;
    this.Notes = null;
    this.EC = null;
    this.cb_system = null;
    this.cb_bank = null;
    this.td_desc = null;
    if (arguments.length == 1)
        this._ctor$1.apply(this, arguments);
    else
        this._ctor$0.apply(this, arguments);
}

ActiveBets.Bet.prototype = {
    _ctor$0: function() {
        this.Id = arguments[0];
        this.EventId = arguments[1];
        this.EventDate = arguments[2];
        this.LeagueId = arguments[3];
        this.HomeTeamName = arguments[4];
        this.GuestTeamName = arguments[5];
        this.OddId = arguments[6];
        this.BetTypeCode = arguments[7];
        this.OddFactor = arguments[8];
        this.BetGroupTypeId = arguments[9];
        this.BetTypeId = arguments[10];
        this.IsSystemPart = arguments[11];
        this.Amount = arguments[12];
        this.ColumnIndex = arguments[13];
        this.OddKind = arguments[14];
        this.BetTypeName = arguments[15];
        this.EventName = arguments[16];
        this.OddPoint = arguments[17];
        this.Notes = arguments[18];
        this.IsBank = arguments[19];
        if (arguments.length > 20)
            this.EC = arguments[21];
    },

    _ctor$1: function() {
        var bet = arguments[0];
        //        this.Id = bet.Id;
        this._ctor$0(bet.Id, bet.EventId, bet.EventDate, bet.LeagueId, bet.HomeTeamName, bet.GuestTeamName, bet.OddId, bet.BetTypeCode,
                    bet.OddFactor, bet.BetGroupTypeId, bet.BetTypeId, bet.IsSystemPart, bet.Amount, bet.ColumnIndex, bet.OddKind,
                    bet.BetTypeName, bet.EventName, bet.OddPoint, bet.Notes, bet.IsBank, bet.EC);
    },

    toString: function() {
        if (this.EC != null)
            return String.format("[{0}]{1} - {2}", this.EC, this.HomeTeamName, this.GuestTeamName);
        else
            return String.format("{0} - {1}", this.HomeTeamName, this.GuestTeamName);
    },

    equals: function(oBet) {
        if (oBet.EventId == this.EventId && oBet.BetGroupTypeId == this.BetGroupTypeId) {
            if (this.OddKind == ActiveBets.OddKinds.LineOdd)
                return (this.OddPoint == null || (this.OddPoint != null && oBet.OddPoint == this.OddPoint));
            else if (this.OddKind == ActiveBets.OddKinds.CustomOdd)
                return (oBet.Notes == this.Notes);
            else if (this.OddKind == ActiveBets.OddKinds.LongtermOdd)
                return ((this.HomeTeamName != '' && oBet.HomeTeamName == this.HomeTeamName)
                        || (this.HomeTeamName == '' && oBet.Notes == this.Notes));
        }

        return false;
    },

    equals_by_event: function(oBet) {
        return (this.EventId == oBet.EventId);
    },

    equals_by_event_league: function(oBet) {
        //        if (this.OddKind == ActiveBets.OddKinds.LongtermOdd && oBet.OddKind == ActiveBets.OddKinds.LongtermOdd)
        //            return (this.LeagueId == oBet.LeagueId);
        if (this.OddKind == ActiveBets.OddKinds.LongtermOdd || oBet.OddKind == ActiveBets.OddKinds.LongtermOdd)
            return (this.LeagueId == oBet.LeagueId);
        else
            return (this.EventId == oBet.EventId);
    },

    get_away_team: function() {
        return this.GuestTeamName;
    },

    get_home_team: function() {
        return this.HomeTeamName;
    },

    get_odd_kind: function() { // result - ActiveBets.OddKinds
        return this.OddKind;
    },

    get_event_name: function() {
        switch (this.OddKind) {
            case ActiveBets.OddKinds.LineOdd:
            case ActiveBets.OddKinds.CustomOdd:
                var code = "";

                if (this.EC != null && this.EC != "")
                    code += String.format("[{0}]", this.EC);

                return String.format('{0}{1} - {2}', code, this.HomeTeamName.substr(0, 9).trim(), this.GuestTeamName.substr(0, 9).trim());
                break;
            case ActiveBets.OddKinds.LongtermOdd:
                return this.EventName;
                break;
        }
        return this.EventName;
    },

    get_description: function() {
        switch (this.OddKind) {
            case ActiveBets.OddKinds.LineOdd:
                if (this.OddPoint != null)
                    return String.format('{0} / {1} ({2})', this.BetTypeName, this.BetTypeCode, this.OddPoint);
                else
                    return String.format('{0} / {1}', this.BetTypeName, this.BetTypeCode);
                break;
            case ActiveBets.OddKinds.CustomOdd:
                return String.format('{0} / {1}', this.get_bettype_name(), this.Notes.substr(0, 9).trim());
                break;
            case ActiveBets.OddKinds.LongtermOdd:
                return String.format('{0} / {1}', this.get_bettype_name(), this.HomeTeamName != "" ? this.HomeTeamName.substr(0, 9).trim() : this.Notes.substr(0, 9).trim());
                break;
        }
    },
    get_bettype_name: function() {
        return this.BetTypeName;
    },
    is_have_stake: function() {
        return this.Amount > 0.0;
    },

    remove_click: function(e) {
        this.card.remove_bet(e, this);
    },

    check_click: function(e) {
        this.IsSystemPart = e.target.checked;
        this.card.update_s_p_c();
        //        if (this.IsSystemPart)
        //            this.card.add_sysbet();
        //        else
        this.card.remove_sysbet();

        this.card.update_bet(this);
        this.card.update_sys_bets(this.card.get_sys_count() - 1);
        this.card.update_card();
    },

    bank_click: function(e) {
        this.set_bank(e.target.checked);
    },

    set_bank: function(value) {
        this.IsBank = value;
        this.card.update_b_p_c();

        //        if (this.IsBank)
        this.card.remove_sysbet();
        //        else if (!this.IsBank)
        //            this.card.add_sysbet();

        this.card.update_bet(this);
        this.card.update_sys_bets(this.card.get_sys_count() - 1);
        this.card.update_card();
    },

    show_bank: function(value) {
        this.cb_bank.style.display = value ? '' : 'none';
    },

    set_is_system_part: function(is_system_part) {
        this.cb_system.checked = is_system_part;

        this.IsSystemPart = is_system_part;
        this.card.update_s_p_c();

        //        if (this.IsSystemPart)
        //            this.card.add_sysbet();
        //        else
        this.card.remove_sysbet();

        this.card.update_sys_bets(this.card.get_sys_count() - 1);
        this.card.update_card();
    },

    set_cb_system: function(value) {
        this.cb_system = value;
    },

    set_cb_bank: function(value) {
        this.cb_bank = value;
    },

    set_point: function(value) {
        this.OddPoint = value;
    },

    set_td_desc: function(value) {
        this.td_desc = value;
    },

    set_td_desc_innerHTML: function(value) {
        if (this.td_desc != null)
            this.td_desc.innerHTML = value;
    },

    // region [ tb_stake event handlers ]
    tb_amount_blur: function(e) {
        var value = e.target.value.trim();
        value = this._get_formated_value(value);

        var amount = Number.parseInvariant(value);
        if (isNaN(amount))
            amount = 0.0;

        this.check_limits();
        this.set_tb_amount_value(this.get_amount());

        this.card.update_bet(this);
    },
    tb_amount_changed: function(e) {
        var value = e.target.value.trim();
        value = this._get_formated_value(value);

        var amount = Number.parseInvariant(value);

        if (isNaN(amount))
            amount = 0.0;

        if (amount != this.get_amount()) {
            this.set_amount(amount);
            this.card.update_card();
        }
    },
    // endregion

    check_select_region: function() {
        var obj = document.getElementById(String.localeFormat("lblOddsFactor{0:D}_{1:D}_{2:D}", this.ColumnIndex, this.OddId, this.BetTypeId));
        if (obj != null) {
            obj.className = "tdEventCoef tdOn";
        }
    },

    select_region: function(isSelect) {
        var obj = document.getElementById(String.localeFormat("lblOddsFactor{0:D}_{1:D}_{2:D}", this.ColumnIndex, this.OddId, this.BetTypeId));
        if (obj != null) {
            if (isSelect)
                obj.className = "tdEventCoef tdOn";
            else
                obj.className = "tdEventCoef";
        }
    },

    disable_inputs: function(isEnabled) {
        this.tb_amount.disabled = isEnabled ? true : false;
        this.cb_system.disabled = isEnabled ? true : false;
    }
}
ActiveBets.Bet.registerClass("ActiveBets.Bet", ActiveBets.BaseBet);

/*******************  ActiveBets.SCBet  ***********************/
ActiveBets.SCBet = function() {
    ActiveBets.SCBet.initializeBase(this);

    this.BetType = ActiveBets.BetTypes.Combi;
    this.count = 1;
    this.System = 0;

    //#region [ UI ]
    this.text_td = null;
    this.OddFactor = Math.round((this.card.get_combi_factor() * 100)) / 100;
    if (arguments.length != 0)
        this._ctor$0.apply(this, arguments);
}
ActiveBets.SCBet.prototype = {
    _ctor$0: function() {
        this.set_amount(arguments[0].Amount);
        this.set_bonus(arguments[0].Bonus);
    },

    set_factor: function(value) {
        if (this.OddFactor != value) {
            this.OddFactor = value;
            this.card.update_bet(this);
        }
    },

    get_text_td: function(td) {
        return this.text_td;
    },
    set_text_td: function(td) {
        this.text_td = td;
    },

    get_system: function(value) {
        return 1;
    },

    get_sys_count: function() {
        return this.count;
    },
    // region [ tb_amount event handlers ]

    tb_amount_blur: function(e) {
        var value = e.target.value.trim();
        value = this._get_formated_value(value);

        var amount = Number.parseInvariant(value);

        if (isNaN(amount))
            amount = 0.0;

        this.check_limits();
        this.set_tb_amount_value(this.get_amount());

        this.card.update_bet(this);
        this.card.update_card();
    },

    tb_amount_changed: function(e) {
        var value = e.target.value.trim();
        value = this._get_formated_value(value);

        var amount = Number.parseInvariant(value);

        if (isNaN(amount))
            amount = 0.0;

        if (amount != this.get_amount()) {
            this.set_amount(amount);
            this.card.update_card();
        }
    },
    // endregion

    show_bonus: function() {
        if (this.is_have_bonus)
            this.set_td_limit_innerhtml(String.localeFormat("{0}%", this.get_bonus()));
    },

    ui_update: function(text) {
        //        var sys_count = this.get_sys_count();
        //        this.set_factor(Math.round((this.card.get_combi_factor() * 100)) / 100);
        this.text_td.innerHTML = this.get_combi_text();
    },
    update: function() {
        var sys_count = this.get_sys_count();
        this.set_factor(this.card.get_combi_factor());
        this.text_td.innerHTML = this.get_combi_text();
    },

    get_combi_text: function() {
        return String.localeFormat('{0}, <BR />1 {1}@ ({2}{3})', Res.StandartExpress, Res.Bet, this.get_factor_desc(), this._get_bonus_desc());
    },
    _get_bonus_desc: function() {
        if (this.is_have_bonus())
            return String.localeFormat("<span style='color:red'> {0}{1:P}</span>", Res.Bonus, this.get_bonus() / 100);
        return "";
    }
}
ActiveBets.SCBet.registerClass("ActiveBets.SCBet", ActiveBets.BaseBet);

/*******************  ActiveBets.SSBet  ***********************/
ActiveBets.SSBet = function() {
    ActiveBets.SSBet.initializeBase(this);

    this.BetType = ActiveBets.BetTypes.System;
    this.System = null;
    this.Stake = 0.0;

    //#region [ UI ]
    this.text_td = null;
    this.tb_stake = null;

    this._ctor$0.apply(this, arguments);
}
ActiveBets.SSBet.prototype = {
    _ctor$0: function() {
        this.System = arguments[0];
        this.Amount = arguments[1];
        this.Stake = this.get_amount() / this.get_sys_count();
    },

    get_text_td: function(td) {
        return this.text_td;
    },

    get_stake: function() {
        return this.Stake;
    },

    get_system: function(value) {
        return this.System;
    },

    get_sys_count: function() {
        return this.card.get_sysbet_count(this.get_system());
    },

    set_stake: function(stake) {
        this.Stake = stake;
    },

    set_tb_stake: function(tb_stake) {
        this.tb_stake = tb_stake;
    },

    set_tb_stake_value: function(value) {
        if (this.tb_stake != null)
            this.tb_stake.value = String.localeFormat("{0:N}", value);
    },

    set_text_td: function(text_td) {
        this.text_td = text_td;
    },

    set_system: function(value) {
        this.System = value;
    },
    // region [ tb_amount event handlers ]

    tb_amount_blur: function(e) {
        var value = e.target.value.trim();
        value = this._get_formated_value(value);

        var amount = Number.parseInvariant(value);
        if (isNaN(amount))
            amount = 0.0;

        this.check_limits();
        this.set_tb_amount_value(this.get_amount());

        //        if (amount != this.get_amount()) {
        var stake = this.get_amount() / this.get_sys_count();
        this.set_stake(stake);
        this.set_tb_stake_value(this.get_stake());

        this.card.update_bet(this);
        this.card.update_card();
        //        }
    },

    tb_amount_changed: function(e) {
        var value = e.target.value.trim();
        value = this._get_formated_value(value);

        var amount = Number.parseInvariant(value);
        if (isNaN(amount))
            amount = 0.0;

        if (amount != this.get_amount()) {
            this.set_amount(amount);
            var stake = this.get_amount() / this.get_sys_count();
            this.set_stake(stake);
            this.set_tb_stake_value(stake);
            this.card.update_card();
        }
    },

    // endregion

    // region [ td_stake event handlers ]
    check_limits: function() {
        if (this.get_limits().get_min_pay() != null && this.get_amount() < this.get_limits().get_min_pay() * this.get_sys_count() && this.get_amount() != 0) {
            var amount = this.get_limits().get_min_pay() * this.get_sys_count();
            this.set_amount(amount);
            this.set_tb_amount_value(amount);
            this.set_errorCode(this.get_errorCode() | ActiveBets.ValidationError.IncorrectStake);
            this.card.update_bet(this);

            return false;
        }

        if (this.get_max_pay() != null && this.get_amount() > this.get_max_pay() && this.get_amount() != 0) {
            var amount = this.get_max_pay();
            this.set_amount(amount);
            this.set_tb_amount_value(amount);
            this.set_errorCode(this.get_errorCode() | ActiveBets.ValidationError.IncorrectStake);
            this.card.update_bet(this);

            return false;
        }
        return true;
    },

    check_stake_limits: function() {
        if (this.get_limits() != null) {
            if (this.get_min_pay() != null && this.get_stake() < this.get_min_pay() && this.get_stake() != 0) {
                var stake = this.get_min_pay();

                this.set_stake(stake);
                var amount = this.get_sys_count() * this.get_stake();
                this.set_amount(amount);

                return false;
            }

            if (this.get_limits().get_max_pay() != null && this.get_stake() * this.get_sys_count() > this.get_limits().get_max_pay() && this.get_stake() != 0) {
                stake = Math.round(this.get_limits().get_max_pay() / this.get_sys_count() * 100) / 100;

                this.set_stake(stake);
                var amount = this.get_sys_count() * this.get_stake();
                this.set_amount(amount);

                return false;
            }
        }

        return true;
    },

    tb_stake_blur: function(e) {
        var value = e.target.value.trim();
        value = this._get_formated_value(value);

        var stake = Number.parseInvariant(value);
        if (isNaN(stake))
            stake = 0.0;

        this.check_stake_limits();
        this.set_tb_stake_value(this.get_stake());

        //        if (stake != this.get_stake()) {
        this.set_tb_amount_value(this.get_amount());

        this.card.update_bet(this);
        this.card.update_card();
        //        }
    },

    tb_stake_changed: function(e) {
        var value = e.target.value.trim();
        value = this._get_formated_value(value);

        var stake = Number.parseInvariant(value);
        if (isNaN(stake))
            stake = 0.0;

        if (stake != this.get_stake()) {
            //            e.target.value = value;
            this.set_stake(stake);

            var amount = this.get_sys_count() * this.Stake;
            this.set_amount(amount);
            this.set_tb_amount_value(amount);

            //            this.card.update_bet(this);
            this.card.update_card();
        }
    },

    tb_stake_focus: function(e) {
        this.tb_stake.select();
    },

    // endregion

    ui_update: function() {
        var sys_count = this.get_sys_count();
        this.set_factor(Math.round(this.card.get_system_factor(this.get_system()) / sys_count * 100) / 100);
        this.text_td.innerHTML = String.format("{0}/{1} ({2} {3:N}) {4} {5} @", this.get_system(), this.card.get_sys_parts_count(), Res.Odd, this.get_factor_desc(), sys_count, Res.Bets);
        if (this.get_limits() != null)
            this.show_limits(ActiveBets.ExtApp.get_bett_slip().get_limits_state());
    },

    update: function() {
        var sys_count = this.get_sys_count();
        this.set_factor(this.card.get_system_factor(this.get_system()) / sys_count);
        this.text_td.innerHTML = String.format("{0}/{1} ({2} {3:N}) {4} {5} @", this.get_system(), this.card.get_sys_parts_count(), Res.Odd, this.get_factor_desc(), sys_count, Res.Bets);
        this.set_stake(this.get_amount() / sys_count);
        this.set_tb_stake_value(this.get_stake());
        this.card.update_bet(this);
    },
    get_system_text: function() {
        var sys_count = this.get_sys_count();
        this.set_factor(Math.round(this.card.get_system_factor(this.get_system()) / sys_count * 100) / 100);
        return String.format("{0}/{1} ({2} {3:N}) {4} {5} @", this.get_system(), this.card.get_sys_parts_count(), Res.Odd, this.get_factor_desc(), sys_count, Res.Bets);
    }
}
ActiveBets.SSBet.registerClass("ActiveBets.SSBet", ActiveBets.BaseBet);
Res={"OddNotExistsError":"Odd not exists.","FactorExceedError":"Odd factor exceeded.","NoLimit":"no lim","LimitError":"Limits: wrong stake","Bet":"Bet","Odd":"Odds","Bonus":"BONUS:","StandartExpress":"Standart express","EventRefundError":"Event refund.","WinExceedError":"Possible win exceeded.","FactorChangedError":"Factor changed.","EventBlockedError":"Event blocked.","EventStartedError":"Event started.","EventDateChangedError":"Event date changed.","Bets":"Bets"};
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();