{include file="public/header" /}
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>权限设置</h3>
                <h5></h5>
            </div>
            {include file="public/admin_items" /}
        </div>
    </div>
    <form method="post" id="add_form">
        <div  class="ncap-form-default">
            <dl>
                <dt>{$Think.lang.admin_index_username}</dt>
                <dd>
                    <input id="admin_name" name="admin_name" value="" class="input-txt" type="text">
                    <span class="err"></span>
                    <p class="notic">{$Think.lang.admin_add_username_tip}</p>
                </dd>
            </dl>
            <dl>
                <dt>{$Think.lang.admin_index_password}</dt>
                <dd>
                    <input id="admin_password" name="admin_password" value="" class="input-txt" type="password">
                    <span class="err"></span>
                    <p class="notic">{$Think.lang.admin_add_password_tip}</p>
                </dd>
            </dl>
            <dl>
                <dt>{$Think.lang.admin_rpassword}</dt>
                <dd>
                    <input id="admin_rpassword" name="admin_rpassword" value="" class="input-txt" type="password">
                    <span class="err"></span>
                    <p class="notic">{$Think.lang.admin_add_password_tip}</p>
                </dd>
            </dl>
            <dl>
                <dt>{$Think.lang.gadmin_name}</dt>
                <dd>
                    <select name="gid">
                        <?php foreach((array)$gadmin as $v){?>
                        <option value="<?php echo $v['gid'];?>"><?php echo $v['gname'];?></option>
                        <?php }?>
                    </select>
                    <span class="err"></span>
                    <p class="notic">{$Think.lang.admin_add_gid_tip}</p>
                </dd>
            </dl>
            <dl>
                <dt></dt>
                <dd><a href="JavaScript:void(0);" class="btn" id="submitBtn">确认提交</a></dd>
            </dl>
        </div>
    </form>
</div>

<script>
//按钮先执行验证再提交表
    $(document).ready(function() {
        //按钮先执行验证再提交表单
        $("#submitBtn").click(function() {
            if ($("#add_form").valid()) {
                $("#add_form").submit();
            }
        });
        $("#add_form").validate({
            errorPlacement: function(error, element) {
                error.appendTo(element.nextAll('span.err'));
            },
            rules: {
                admin_name: {
                    required: true,
                    minlength: 3,
                    maxlength: 20,
                    remote: {
                        url: ADMIN_URL+'/Admin/ajax.html?branch=check_admin_name',
                        type: 'get',
                        data: {
                            admin_name: function() {
                                return $('#admin_name').val();
                            }
                        }
                    }
                },
                admin_password: {
                    required: true,
                    minlength: 6,
                    maxlength: 20
                },
                admin_rpassword: {
                    required: true,
                    equalTo: '#admin_password'
                },
                gid: {
                    required: true
                }
            },
            messages: {
                admin_name: {
                    required: '{$Think.lang.admin_add_username_null}',
                    minlength: '{$Think.lang.admin_add_username_max}',
                    maxlength: '{$Think.lang.admin_add_username_max}',
                    remote: '{$Think.lang.admin_add_admin_not_exists}'
                },
                admin_password: {
                    required: '{$Think.lang.admin_add_password_null}',
                    minlength: '{$Think.lang.admin_add_password_max}',
                    maxlength: '{$Think.lang.admin_add_password_max}'
                },
                admin_rpassword: {
                    required: '{$Think.lang.admin_add_password_null}',
                    equalTo: '{$Think.lang.admin_edit_repeat_error}'
                },
                gid: {
                    required: '{$Think.lang.admin_add_gid_null}',
                }
            }
        });
    });
</script>