function expand(e)
{
    $$('div.expand').each(function(d) {d.hide()});
    $$('a.show').each(function(a) {a.show()});
    var elm = Event.element(e);
    $(elm.name).select('div.expand').each(function(div) 
    {
/*        div.toggle();*/
        if (elm.hasClassName('show')) {
            div.show();
            $$('a[name="' + elm.name + '"].show').each(function(a) {a.hide()});
        }
        else {
            div.hide();
            $$('a[name="' + elm.name + '"].show').each(function(a) {a.show()});
        }
    });
}

function validate(e)
{
    var elm = Event.element(e);
    // check mandatory elements
    $$('#gebedform .mandatory').each(function(i)
    {
        if (i.value.length == 0) {
            i.up('label').addClassName('missing');
            $('validateerror').show();
            Event.stop(e);
            return false;
        }
        else {
            i.up('label').removeClassName('missing');
        }
    });
}

// initialise page
function init()
{
    $$('a.expand').each(function(a) {Event.observe(a, 'click', expand);});
    $$('a.show').each(function(a) {Event.observe(a, 'click', expand);});
    $$('#gebedform').each(function(f) {Event.observe(f, 'submit', validate);});
}

Event.observe(window, 'load', init);
