<script language="JavaScript" type="text/javascript">
<!--

var editURL = '<?php echo str_replace('&amp;', '&', Horde::addParameter(Horde::url($registry->getParam('webroot', 'horde') . '/shares/edit.php?app=mnemo'), 'share', '@ID@')) ?>';
var cancelSubmit = false;
var fields = new Array();
<?php foreach ($personal_notepads as $id => $notepads): ?>
fields['<?php echo addslashes($id) ?>'] = new Array(
        "<?php echo addslashes($notepads->getShareName()) ?>",
        "<?php echo preg_replace('(\r\n|\n|\r)', '\n', addslashes($notepads->getDescription())) ?>",
        "<?php echo addslashes($notepads->getType()) ?>");
<?php endforeach; ?>

function newChoice()
{
    var action = document.shares.share.options[document.shares.share.selectedIndex].value;
    if (action == -1) {
        document.shares.save.value = '<?php echo _("Create") ?>';
        document.shares.reset();
        clearForm();
    } else {
        document.shares.save.value = '<?php echo _("Change") ?>';
        updateForm(action);
    }
}

function newType()
{
    var id = document.shares.share.options[document.shares.share.selectedIndex].value;
    var type = document.shares.type.options[document.shares.type.selectedIndex].value;

    // Don't show the access/permission button when creating a new
    // share.
    if (id != -1) {
        if (type == 1) {
            document.shares.accesslist.value = '<?php echo _("Permissions") ?>';
            document.shares.accesslist.style.visibility = 'visible';
        } else {
            document.shares.accesslist.style.visibility = 'hidden';
        }
    }
}   

function updateForm(share)
{
    document.shares.edit_share.value = share;
    document.shares.id.value = fields[share][0];
    document.shares.description.value = fields[share][1];
    document.shares.type.selectedIndex = 0;
    for (var i = 0; i < document.shares.type.length; i++) {
        if (document.shares.type[i].value == fields[share][2]) {
            document.shares.type.selectedIndex = i;
            break;
        }
    }
    newType();
}

function clearForm()
{
    document.shares.edit_share.value = '';
    document.shares.id.value = '';
    document.shares.description.value = '';
    document.shares.type.selectedIndex = 0;
    document.shares.accesslist.style.visibility = 'hidden';
    cancelSubmit = true;
}

function checkSubmit()
{
    cancel = cancelSubmit;
    cancelSubmit = false;
<?php if ($browser->getBrowser() == 'msie' && $browser->getMajor() >= 4): ?>
    window.event.returnValue = !cancel;
<?php endif; ?>
    return !cancel;
}

//-->
</script>
