// form validation
// (c) 2008 Loco (Loohuis Consulting), http://www.loohuis-consulting.nl/
// This work is licensed under a 
// Creative Commons Attribution-Share Alike 3.0 Netherlands License
// see http://www.loohuis-consulting.nl/development/cc-by-sa.php

document.observe('dom:loaded', function()
{
    if ($('naam'))
        $('naam').focus();
    if ($('inschrijving'))
        $('inschrijving').observe('submit', validate);
});

function validate(e)
{
    var elm = Event.element(e);

    // check mandatory elements
    var inputs = $$('.mandatory');
    var incomplete = false;
    inputs.each(function(i)
    {
        if (i.value.length == 0 || (i.getAttribute('type').toLowerCase() == 'checkbox' && i.checked == false)) {
            incomplete = true;
            i.up('li').addClassName('incomplete');
        }
        else
            i.up('li').removeClassName('incomplete');
    });
    if (incomplete) {
        $('validateerror').update('Vul a.u.b. de ontbrekende gegevens in.');
        $('validateerror').show();
        Event.stop(e);
    }
    else {
        // apparently input is ok
        $('validateerror').hide();
        elm.opslaan.name = 'register';
    }
}

