(function ($) {
    $(document).ready(function () {
        var aclGroup = $('div.acl-sort-container').sortable({
            aclGroup: 'acl-sort-container',
            containerSelector: 'div.acl-sort-container',
            itemPath: '> .acl-sort-path',
            itemSelector: 'div.acl-sort-selector',
            placeholder: '<div class="acl-sort-placeholderer"/>',
            onDrop: function ($item, container, _super) {
                var list = new Array(0);
                $.each(aclGroup.sortable('serialize'), function (i, v) {
                   $.each(v, function (j, w) {
                      list.push(w.name);
                   });
                } );
                $('input[type="hidden"][name="gatewayfieldssort"]').val(list.join(','));
                _super($item, container);
            }
        });
        var $validator = $("#gatewayAddForm").validate({
            highlight: function (input) {
                $(input).parents('.form-group').addClass('has-error');
            },
            unhighlight: function (input) {
                $(input).parents('.form-group').removeClass('has-error');
            },
            errorPlacement: function (error, element) {
                $(element).parents('.form-group').append(error);
            }
        });
        $validator.showErrors(gatewayError);
    });
}(jQuery));