function afterInitTable() {
    $('table').treegrid({
        treeColumn: 2
    });
}

var dlg = null;

function selectAll(radio, cb) {
    cb.removeAttr('checked');
    $('input.permission').each(function(i, e) { $(e).attr('checked', false); });
    radio.each(function(i, e) { $(e).attr('checked', true); });
    return false;
}

function editField(id) {
    var url = id ? 'userfield.ivp/view/' + id : 'userfield.ivp/create';
    dlg = openDialog(url, 'field', { width: 800, height: 490 });
    dlg.callback = function () { updateFields(); }
    return false;
}

function updateFields() {
    $('#tableholder').load(base + 'userfield.ivp/list', { reset: true }, function () {
        initTable();
    });
}

function loadFields(reload) {    
    setTab('fields');
    if (reload || !$.trim($('#tableholder').html())) {
        updateFields();
    }
    return false;
}

function updateDesigner() {       
    $('#designer').load(base + 'userdesignerfield.ivp/list .designerfield', { reset: true }, function() {
        initDesigner();
    });
}

function loadDesigner(reload) {
    setTab('designer');
    if (reload || !$.trim($('#designer').html())) {
        updateDesigner();
    }
    return false;
}


function selectAllcb(checked) {
    alert(checked);
}

function rowChecked(val, check) {
    var $checkbox = $('#id' + val);
    
    if ($checkbox.attr('field-type') == 'ElementGroup') {
        var $trs = $('input.rowid[field-path^="' + $checkbox.attr('field-path') + '"]').closest('tr');
        if (check) {
            alert('Будут удалены все элементы выбранной группы');
            $trs.addClass('selected');
        }
        else {
            $trs.removeClass('selected');
        }
    }
}