function bf_init() {
    var obj = document.getElementsByTagName('input');
    var sel_obj = null;
    var first_obj = null;
    for (var i = 0 ; i < obj.length; i++) {
        if (first_obj == null) first_obj = obj[i];
        if (sel_obj == null && obj[i].value == '') sel_obj = obj[i];
        bf_add_events(obj[i]);
    }

    obj = document.getElementsByTagName('select');
    for (var i = 0 ; i < obj.length; i++) {
        if (first_obj == null) first_obj = obj[i];
        if (sel_obj == null && obj[i].value == '') sel_obj = obj[i];
        bf_add_events(obj[i]);
    }
    obj = document.getElementsByTagName('textarea');
    for (var i = 0 ; i < obj.length; i++) {
        if (first_obj == null) first_obj = obj[i];
        if (sel_obj == null && obj[i].value == '') sel_obj = obj[i];
        bf_add_events(obj[i]);
    }
/*
    if (first_obj != null) {
        if (sel_obj == null) {
            first_obj.focus();
        } else {
            sel_obj.focus();
        }
    }
*/
}


function bf_add_events(obj) {

    if (/checkbox/.test(obj.className)) {
        return;
    }
    
    if (/radio/.test(obj.className)) {
        return;
    }

    if (/ date/.test(obj.className)) {
        Calendar.setup({
        inputField     :    obj.id,
        ifFormat       :    "%d.%m.%Y",
//        ifFormat       :    "%Y-%m-%d",
        button         :    obj.id + "_cal",
        align          :    "Tl",
        singleClick    :    true
        });
    }

    
    if (obj.getAttribute('default')) {
        
        if (obj.value == '') {
            obj.value = obj.getAttribute('default');
        }
    }
        
    obj.onfocus = function() {

        var dflt = obj.getAttribute('default');
        if (dflt) {
            if (this.value == dflt) {
                this.value = '';
            }
        }
        
        if (!obj.getAttribute('noprocess')) {
            this.oldbackground = this.style.backgroundColor;
            this.style.backgroundColor = '#ffffd0';
        }
    }

    obj.onblur = function() {
        
        if (this.value == '') {
            var dflt = obj.getAttribute('default');
            if (dflt) {
                this.value = dflt;
            }
        }

        if (!obj.getAttribute('noprocess')) {
            this.style.backgroundColor = this.oldbackground;
        }
    }
}

function $(x) {
    return document.getElementById(x);
}

function toggle(id_to_hide, id_to_show) {
  $(id_to_hide).style.display = 'none';
  $(id_to_show).style.display = 'block';
}

