// ===================================================================
// Author: OA Solutions
// ===================================================================

// HISTORY
// ------------------------------------------------------------------
// March 2005: Created
/* 

DESCRIPTION: This library lets you check that the user has selected
        specified checkboxes, generating an alert message and preventing
        form submission if no checkbox has been selected

COMPATIBILITY: Should work on all Javascript-compliant browsers.

USAGE:
// Place in the 'Onsubmit' event of the form as onsubmit ="return checkme();"
        or onsubmit ="return checkselection();"
*/

// This function verifies that the user has checked off the copyright
// terms.  If not, outputs a prompt and prevents form submission.
function checkme() {
        missinginfo = "";
        // test if agreement checkbox checked
    if (!document.form1.agree.checked) {
        missinginfo += "\nYou must agree to the copyright terms";
    }
    // If copyright terms not agreed, output prompt and prevent form
    // submission
    if (missinginfo != "") {
        missinginfo = "" +
        missinginfo + "\nif you wish to proceed.";
        alert(missinginfo);
        return false;
    }
    else { 
        return true;
    }
}

// This function verifies that the user has checked off at least one
// exam.  If not, outputs a prompt and prevents form submission.
function checkselection() {
        missinginfo = "";
        formElements = document.form1.elements
        
        checkedCount = 0;
        // iterate though array of form elements and count all
        // checked checkboxes
        for (i=0;i<formElements.length;i++)
        {
                var formElement = formElements[i];
                if(formElement.type == 'checkbox' && formElement.checked)
                {
                        checkedCount++;
                }
        }
        
    // If no checkboxes checked, output prompt and prevent form
    // submission
    if (checkedCount == 0) {
        missinginfo += "\nYou must select an exam.";
    } 
    if (missinginfo != "") {
        missinginfo = "" +
        missinginfo + "\nPlease select an exam and resubmit.";
        alert(missinginfo);
        return false;
    }
    else { 
        return true;
    }
}

