<script language="JavaScript" type="text/javascript">
<!--
<?php if (isset($js_right)): ?>
var users = new Array(<?php echo $js_user ?>);

<?php foreach ($js_right as $key => $val): ?>
var <?php echo $key ?> = new Array(<?php echo $val ?>);
<?php endforeach; ?>
<?php endif; ?>

function selectRule(num)
{
<?php if ($canEdit): ?>
    if (num == <?php echo count($curr_acl) ?>) {
        resetForm();
    } else {
        document.acl.share_user.value = users[num];  
        document.acl.share_user.disabled = true;
<?php if (!empty($js_right)): ?>
<?php foreach ($js_right as $key => $val): ?>
        if (<?php echo $key ?>[num] > 0) {
            document.acl.elements['acl[<?php echo $key ?>]'].checked = true;
        } else {
            document.acl.elements['acl[<?php echo $key ?>]'].checked = false;
        }
<?php endforeach; ?>
<?php endif; ?>
        document.acl.actionID.value = 'imp_acl_edit';
        document.acl.fbutton.value = '<?php echo addslashes(_("Modify")) ?>';
    }
<?php endif; ?>
}

function resetForm()
{
    document.acl.reset();
    document.acl.share_user.disabled = false;
    document.acl.actionID.value = 'imp_acl_set';
    document.acl.fbutton.value = '<?php echo addslashes(_("Create")) ?>';
    if (document.acl.number) {
        for (var i = 0; i < document.acl.number.length -1 ; i++) {
            document.acl.number[i].checked = false;
        }
    }
}

var loading;
function ACLFolderChange(clear)
{
    if (document.folders.folder[document.folders.folder.selectedIndex].value != '') {
        if (loading == null || clear != null) {
            loading = true; 
            disableButtons(); 
            document.folders.submit();
        }
    }
}

function disableButtons() {
    if (document.acl.fbutton) {
        document.acl.fbutton.disabled = true;
    }
    if (document.acl.resetbut) {
        document.acl.resetbut.disabled = true;
    }    
    if (document.acl.back) {
        document.acl.back.disabled = true;
    }    
    if (document.acl.number) {
        for (var i = 0; i < document.acl.number.length; i++) {
            document.acl.number[i].disabled = true;
        }
    }
    return true;
}


// -->
</script>
