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

function anySelected()
{
    for (i = 0; i < document.list.elements.length; i++) {
        if (document.list.elements[i].checked) return true;
    }
    return false;
}

function chooseAction(whichForm)
{
    if (!anySelected()) {
        window.alert('<?php echo addslashes(_("You must select at least one task first.")) ?>');
    } else {
        if (whichForm == 1) {
            document.list.actionID.value = document.list.action1.options[document.list.action1.selectedIndex].value;
        } else {
            document.list.actionID.value = document.list.action2.options[document.list.action2.selectedIndex].value;
        }
        
        if (document.list.actionID.value == <?php echo NAG_SET_PRIORITY ?>) {
            document.list.priority.value = window.prompt('<?php echo addslashes(_("Please enter the task priority (1-5):")) ?>', '');
            while (document.list.priority.value &&
                   (document.list.priority.value < 1 || document.list.priority.value > 5)) {
                document.list.priority.value = window.prompt('<?php echo addslashes(_("Priorities must be between 1 and 5. Please enter a valid priority:")) ?>', '');
            }
            
            if (!document.list.priority.value || document.list.priority.value == "null") {
                return false;
            }
        } else if (document.list.actionID.value == <?php echo NAG_DELETE_TASKS ?>) {
            if (!window.confirm('<?php echo addslashes(_("Are you sure you want to permanently delete these tasks?")) ?>')) {
                return false;
            }
        }

        document.list.submit();
    }
}

//-->
</script>
