function tgl(oid) {
    var o = document.getElementById(oid);
    
    if(o.style.display == 'block') {
        o.style.display = 'none';
    }
    else {
        o.style.display = 'block';
    }
}

function on(obj) {
    obj.style.background = '#c8c8c8';
}

function off(obj) {
    obj.style.background = 'white';
}

function onHandle(obj) {
    var o = document.getElementById('stField');
    o.readOnly = true;
    o.value = obj.innerHTML;
    document.getElementById('opts').style.display = 'none';
    
}

function fsubmit() {
    document.getElementById('fdform').submit();
}

// multipleselect

limit = 31;

document.observe('dom:loaded',function(){

        //complex example, note how we need to pass in different CSS selectors because of the complex HTML structure
        var select_multiple_two = new Control.SelectMultiple('select_multiple_two','select_multiple_two_options',{
                checkboxSelector: 'table.select_multiple_table tr td input[type=checkbox]',
                nameSelector: 'table.select_multiple_table tr td.select_multiple_name',
                afterChange: function(){
                        if(select_multiple_two && select_multiple_two.setSelectedRows)
                                select_multiple_two.setSelectedRows();
                }
        });

        //adds and removes highlighting from table rows
        select_multiple_two.setSelectedRows = function(){
                        if( this.numberOfCheckedBoxes < limit ) {
                                this.checkboxes.each(function(checkbox){
                                        checkbox.disabled=false;
                                        var tr = $(checkbox.parentNode.parentNode);
                                        tr.removeClassName('selected');
                                if(checkbox.checked)
                                        tr.addClassName('selected');
                                });
                        }
                        if( this.numberOfCheckedBoxes >= limit ) {
                                this.checkboxes.each(function(checkbox) {
                                        if(!checkbox.checked) {
                                                checkbox.disabled=true;
                                        } else {
                                                var tr = $(checkbox.parentNode.parentNode);
                                                tr.removeClassName('selected');
                                                tr.addClassName('selected');
                                        }
                                })
                        };
        }.bind(select_multiple_two);

        select_multiple_two.checkboxes.each(function(checkbox){
                $(checkbox).observe('click',select_multiple_two.setSelectedRows);
        });
        select_multiple_two.setSelectedRows();

        //link open and closing
        $('select_multiple_two_open').observe('click',function(event){
                $(this.select).style.visibility = 'hidden';
                new Effect.BlindDown(this.container,{
                        duration: 0.3
                });
                Event.stop(event);
                return false;
        }.bindAsEventListener(select_multiple_two));
        $('select_multiple_two_close').observe('click',function(event){
                $(this.select).style.visibility = 'visible';
                new Effect.BlindUp(this.container,{
                        duration: 0.3
                });
                Event.stop(event);
                return false;
        }.bindAsEventListener(select_multiple_two));		

});

