// 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

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) {
            incomplete = true;
            i.up('tr').addClassName('incomplete');
        }
        else
            i.up('tr').removeClassName('incomplete');
    });
    if (incomplete) {
        Element.update('validateerror', 'Vul a.u.b. de ontbrekende gegevens in.');
        Element.show('validateerror');
        Event.stop(e);
    }
    // apparently input is ok
    elm.opslaan.name = 'register';
}

// initialise page
function init()
{
    if ($('vrienden')) {
        Event.observe($('vrienden'), 'submit', validate);
    }
}

Event.observe(window, 'load', init);
