/* patched by Flurin Juvalta (fjuvalta@gmx.net) { */
// get base url:

var _requires = [];
require = function(libraryName) {
    if(_requires.indexOf(libraryName)!=-1) return;
    if(!Prototype.baseURL)
        $$('head script[src]').findAll(function(s) {
            return s.src.match(/prototype\.js$/);
        }).each(function(s) {
            Prototype.baseURL = s.src.replace(/prototype\.js$/,'');
        });
    // inserting via DOM fails in Safari 2.0, so brute force approach
    document.write('<script type="text/javascript" src="'+Prototype.baseURL+libraryName+'"><\/script>');
   _requires.push(libraryName);
}


document.getHeight = function() {
     return Math.max(
            Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
            Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
            Math.max(document.body.clientHeight, document.documentElement.clientHeight)
        );
}
document.getWidth = function() {
     return Math.max(
            Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
            Math.max(document.body.offsetWidth, document.documentElement.offsetWidth),
            Math.max(document.body.clientWidth, document.documentElement.clientWidth)
        );
}

Date.prototype.toDBFormat = function() {
    var m = this.getMonth() + 1;
    var d = this.getDate();
    return this.getFullYear() + (m<10?'-0':'-') + m + (d<10?'-0':'-') + d;
};

Date.prototype.toEUFormat = function() {
    var m = this.getMonth() + 1;
    var d = this.getDate();
    return (d<10?'0':'') + d + (m<10?'.0':'.') + m + '.' + this.getFullYear();
};

Date.prototype.toUSFormat = function() {
    var m = this.getMonth() + 1;
    var d = this.getDate();
    return (m < 10 ? '0' : '') + m + (d < 10 ? '/0' : '/') + d + "/" +  d_date.getFullYear();
}


Element.updateWhenLoaded = function(element, content) {
    new PeriodicalExecuter(function(pe) {
        if ($(element)) {
            pe.stop();
            $(element).update(content);
        }
    }, 0.05);
}
/* } */

function $T(element, pattern) {
  if (!(element = $(element))) return new Template('');
  pattern = pattern || Barolino.templatePattern;
  return new Template(element.innerHTML, pattern);
}
