<div class="form_wrapper">
    <form method="post">
        <input type="hidden" name="action" value="coach_create">

        <div>
            <label class="desc" id="title1" for="ua_name">Név:</label>
            <div><input type="text" name="ua_name" id="ua_name" required></div>
        </div>

        <div>
            <label class="desc" id="title1" for="ua_can_login">Be tud lépni:</label>
            <div><input type="checkbox" name="ua_can_login" id="ua_can_login"></div>
        </div>

        <div id="password" class="admin_area">
            <label class="desc" for="ua_password">Jelszó:</label>
            <div><input type="text" name="ua_password" id="ua_password"></div>
        </div>
        <div class="admin_area">
            <label>Jogosultságok:</label>
            <table id="authorities">
                {foreach $a_array as $a}
                    <tr id="a_{$a->get_a_id()}">
                        <td><label for="authority_{$a->get_a_id()}">{$a->get_a_title()}</label></td>
                        <td><input class="authorities" value="{$a->get_a_id()}" type="checkbox" name="authorities[]" id="authority_{$a->get_a_id()}"></td>
                    </tr>
                {/foreach}
            </table>
        </div>

        <div>
            <div>
                <input class="button black" type="submit" value="Létrehozás">
            </div>
        </div>

    </form>
</div>

<script type="text/javascript">
    $(document).ready(function() {
        $(".admin_area").hide();
    });

    $('#ua_can_login').click(function() {
        $(".admin_area").toggle(this.checked);
        if ($('#ua_password').attr('required')) {
            $('#ua_password').removeAttr('required');
        } else {
            $('#ua_password').attr('required', 'required');
        }
    });

    $('.authorities').on('change', function () {
        if ($('#authority_1').is(':checked')) {
            $('.authorities').each(function (k,v) {
                if ($(v).val() > 1) {
                    $(this).prop('checked', false);
                    $(this).prop('disabled', true);
                }
            });
        }
        else {
            $('.authorities').each(function (k,v) {
                if ($(v).val() > 1) {
                    $(this).removeAttr('disabled');
                }
            });
        }
    });
</script>
