
/**
 * function validate() is passed a form object
 * and it calles function check().
 * check() returns true if all fields that
 * are required are indeed filled in.
 */

function validate( form ) {
        if ( check(form) == true )
                form.submit();
}


/**
 *  function check() is passed a form object and loops over the
 *  elements of the form to see if it can find elements that have a
 *  cascading style sheet "class" attribute called "required". 
 *  It then checks to see whether it is empty or not.
 *  If it is empty the focus is set to the empty field.
 *  The variable "formOke" is set to "false" and the loop is discontinued.
 *  Finally "formOke" which is now "false" is returned to the calling function
 *  indicating that the form may not be submitted
 */

function check( form ) {
        var formOke = true;
        for (i=0; i<form.elements.length; i++) {
                if ( form.elements[i].className == "required" && form.elements[i].value == "" ) {
                        alert( form.elements[i].name + " is een verplicht veld.");
                        form.elements[i].focus();
                        formOke = false;
                        break;
                }
        }
        return formOke;
}
