Umnitsa.Interface.SeminarOrder = function() {

    var $form, addParticipantsCount = 0,
        price = 0, priceDiscount = 0;


    _init_();

    function _init_() {
        $form = $('#seminar-order-form');
        $form.find('.additional-participants .btn').click(addParticipant);
        price = Number($form.find('input[name="price"]').val());
        priceDiscount = Number($form.find('input[name="price_discount"]').val());
        var $apart = $form.find('.a-part');
        addParticipantsCount = $apart.length;
        $apart.find('.min-btn').click(removeParticipantHandler);
        calc();
    }

    function calc() {
        var p = (addParticipantsCount > 0) ? priceDiscount : price
        var total = p * (addParticipantsCount + 1);
        $('#seminar-order-total').html(total.toPrice());
    }

    function addParticipant() {
        addParticipantsCount ++;

        $(document.createElement('div'))
            .addClass('field')
            .addClass('a-part')
            .html('<div class="label">Ф.И.О. участника</div><input type="text" name="participant" />')
            .append(
                $(document.createElement('span'))
                    .addClass('btn min-btn')
                    .click(removeParticipantHandler)
            )
            .insertBefore($form.find('.additional-participants'));
        calc();
    }

    function removeParticipantHandler() {
        $(this).parent().remove();
        addParticipantsCount--;
        calc();
    }
}

