

            function formatZahl(zahl, k, fix) {
                if(!k) k = 0;
                var neu = '';
                var dec_point = '.';
                var thousands_sep = ',';
                var f = Math.pow(10, k);
                zahl = '' + parseInt(zahl * f + (.5 * (zahl > 0 ? 1 : -1)) ) / f ;
                var idx = zahl.indexOf('.');
                if(fix)    {
                    zahl += (idx == -1 ? '.' : '' ) + f.toString().substring(1);
                }
                var sign = zahl < 0;
                if(sign) zahl = zahl.substring(1);
                idx = zahl.indexOf('.');
                if( idx == -1) idx = zahl.length;
                else neu = dec_point + zahl.substr(idx + 1, k);
                while(idx > 0)    {
                    if(idx - 3 > 0)
                    neu = thousands_sep + zahl.substring( idx - 3, idx) + neu;
                    else
                    neu = zahl.substring(0, idx) + neu;
                    idx -= 3;
                }
                return (sign ? '-' : '') + neu;
            }

if (!window.console) {
    if (!window.console || !console.firebug) {
        var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
        "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

        window.console = {};
        for (var i = 0; i < names.length; ++i) {
            window.console[names[i]] = function() {};
        }
    }
}

Ajax.Responders.register({
    onCreate: function() {
        if(Ajax.activeRequestCount > 0) {
            $$('a', '.icon', 'div').each(function(element){
                element.style.cursor = 'wait';
            });
        }
    },
    onComplete: function() {
        if(Ajax.activeRequestCount <= 0){
            $$('a', '.icon', 'div').each(function(element){
                element.style.cursor = '';
            });
        }
    }
});

var App = {};
App.redirect = function(location) {
    window.location = location;
};

App.getId = function (element, prefix) {
    return $(element).id.substring(prefix.length);
};

App.trim = function(s) {
    return s.replace(/^\s+|\s+$/, '');
};

App.setBookmark = function bookmark(url,title){
    if((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
        window.external.AddFavorite(url,title);
    }
    else if (navigator.appName == "Netscape") {
        window.sidebar.addPanel(title,url,"");
    }
    else {
        alert("Press CTRL-D (Netscape), CTRL-T (Opera) or CTRL-D (Safari) to bookmark this page.");
    }
};



App.Form = Class.create();
App.Form.prototype = {

    initialize: function(form_id, options) {
        
        this.form_id = form_id;
        this.form    = $(form_id);
        
        this.option = {
            linkSubmit:     false,
            normalSubmit:   true,
            validation:     false,
            type:           'normal'    // normal | inline
        };
        Object.extend(this.option, options || {});

        if(this.option.linkSubmit) {
            $(this.option.linkSubmit).href = 'javascript:void(0);';
            Event.observe(this.option.linkSubmit, "click", this.linkSubmit.bindAsEventListener(this));
        }
        else {
            Event.observe(this.form, "submit", this.onSubmit.bindAsEventListener(this));
        }
        
        if(this.option.validation == true) {
            this.Validation = new App.Validate(this, this.option);
        }
    },
    
    linkSubmit: function(event) {

        if(this.option.validation == true) {
            var Validation = new App.Validate(this, this.option);
            if(Validation.validate() == false) {
                return;
            }
        }
        
        if(this.option.normalSubmit == false)
            this.form.request({
                method: 'post',
                onSuccess:  function(response) {
                    var json = response.responseText.evalJSON();
                    for(var i in json) $(i).update(json[i]);
                }
            });
        else {
           this.form.submit();
        }
    },
    
    onSubmit: function(event) {
    
        if(this.option.validation == true) {
            var Validation = new App.Validate(this, this.option);
            if(Validation.validate() == false) {
                return;
            }
        }
        this.form.submit();
    }

};
