/*
 * $Id:$
 *
 * This is a javascript file used for helping to deal with activities.
 */

function confirmAnswered(f) {
    var index = 0;
    var missing = [];
    while(f['answer[' + index + ']']) {
        var name = "answer[" + index + "]";
        var found = false;
        if(f[name].selectedIndex != undefined) {
            found = f[name].selectedIndex > 0;
        } else  if(f[name].value == undefined) {
            found = $A(f[name]).find(function(box) {
                                         return box.checked;
                                     });
        } else {
            found = f[name].value;
        }
        if(!found) {
            missing.push(index + 1);
        }
        index++;
    }
    if(missing.length > 0) {
        alert("You must fill in answers to question" + (missing.length > 1 ? 's' : '') + 
              ": " + missing.join(', '));
        return false;
    } else {
        return true;
    }
}

function restartActivity(url) {
    if(confirm("Are you sure you want to restart this activity? Your score will be lost")) {
        window.location = url;
    }
}