/* DON'T EDIT THIS GENERATED FILE! Changes will be lost. */

var __debug = (+location.port>=8000);
function isString(obj)    { return typeof(obj) == 'string'; }
function isNumber(obj)    { return typeof(obj) == 'number'; }
function isBoolean(obj)   { return typeof(obj) == 'boolean'; }
function isFunction(obj)  { return typeof(obj) == 'function'; }
function isObject(obj)    { return typeof(obj) == 'object' || isFunction(obj); }

function isArray(obj)     { return isObject(obj) && obj instanceof Array; }
function isDate(obj)      { return isObject(obj) && obj instanceof Date; }
function isError(obj)     { return isObject(obj) && obj instanceof Error; }

function isUndefined(obj) { return typeof(obj) == 'undefined'; }
function isNull(obj)      { return obj === null; }
function isNone(obj)      { return isUndefined(obj) || isNull(obj); }
function isSet(obj)       { return !isNone(obj); }

function isTrue(obj)      { return isSet(obj) && !!obj; }
function isFalse(obj)     { return isSet(obj) &&  !obj; }

function isEmpty(obj) {
    switch (typeof(obj)) {
        case 'undefined': return true;
        case 'string':    return obj == '';
        case 'number':    return obj == 0;
        case 'boolean':   return obj == false;
        case 'function':
            for (var i in obj) { if (!(isSet(Function.prototype[i]))) { return false; } }
            return /\(\)\{\}$/.test(obj.toString().replace(/\s/g, ''))
        case 'object':
            if (obj === null) return true;
            var pt = Object.prototype;
            if (isArray(obj)) { pt = Array.prototype; }
            if (isError(obj)) { pt = Error.prototype; }
            for (var i in obj) { if (!(isSet(pt[i]))) return false; }
            return true;
        default:
            return false;
    }
}

if (!isFunction(window.debug)) { function debug() { } }
Object.prototype.defaultIs = function(defaults) {
    for (var i in defaults) {
        if (isUndefined(this[i])) {
            this[i] = defaults[i];
        }
    }
    return this;
}

var UserAgent = new function() {
    this.name        = null;
    this.version     = null;
    this.os          = null;
    this.osId        = null;
    this.engine      = null;
    this.description = navigator.userAgent;
    this.toString    = function() { return '${name} ${version} (${osId}) -- ${engine}'.inReplace(this); }
    this.inName = function(part, caseSensitive) {
        if (isSet(caseSensitive) && caseSensitive) {
            return !!(navigator.userAgent.indexOf(part)+1)
        }
        return !!(navigator.userAgent.toLowerCase().indexOf(part.toLowerCase())+1)
    }
    this.knowsDom  = isSet(document.getElementById);
    this.knowsAjax = this.knowsDom && isSet(document.createElement) && (isSet(window.XMLHttpRequest)||isSet(window.ActiveXObject));
    function AgentObject() {
        this.version = null;
        this.getVersion = function() {
            if (isSet(this.version)) { return this.version; }
            var version = 0;
            for (var i in this) {
                if (isSet(Object.prototype[i]))   { continue; }
                if (isNaN(i) || isFalse(this[i])) { continue; }
                if (i > version) { version = i; }
            }
            this.version = version ? version : null;
            return this.version;
        }
        this.lt  = function(v) { return this.getVersion() <  v; }
        this.lte = function(v) { return this.getVersion() <= v; }
        this.gt  = function(v) { return this.getVersion() >  v; }
        this.gte = function(v) { return this.getVersion() >= v; }
    }
    String.prototype.lt  =
    String.prototype.lte =
    String.prototype.gt  =
    String.prototype.gte = function() { return false; }
    this.getOpera = function() {
        if (isNone(window.opera)) { return ''; }
        var o = new AgentObject();
        o['7.x'] = this.inName('Opera 7.')   || this.inName('Opera/7.');
        o[7.2]   = this.inName('Opera 7.2')  || this.inName('Opera/7.2');
        o[7.23]  = this.inName('Opera 7.23') || this.inName('Opera/7.23');
        o[7.5]   = this.inName('Opera 7.5')  || this.inName('Opera/7.5');
        o[7.54]  = this.inName('Opera 7.54') || this.inName('Opera/7.54');
        o['8.x'] = this.inName('Opera 8.')   || this.inName('Opera/8.');
        o[8]     = this.inName('Opera 8.0')  || this.inName('Opera/8.0');
        o[8.5]   = this.inName('Opera 8.5')  || this.inName('Opera/8.5');
        o[8.54]  = this.inName('Opera 8.54') || this.inName('Opera/8.54');
        o['9.x'] = this.inName('Opera 9.')   || this.inName('Opera/9.');
        o[9]     = this.inName('Opera 9.0')  || this.inName('Opera/9.0');
        this.name    = 'Opera';
        this.version = o.getVersion();
        this.engine  = 'Presto';
        return o;
    }
    this.isOpera = this.getOpera();
    this.getIe = function() {
        if (isNone(document.all) || this.isOpera) { return ''; }
        var o = new AgentObject();
        o['4.x'] = this.inName('MSIE 4.');
        o[4]     = this.inName('MSIE 4.0');
        o['5.x'] = this.inName('MSIE 5.');
        o[5]     = this.inName('MSIE 5.0');
        o[5.1]   = this.inName('MSIE 5.1');
        o[5.2]   = this.inName('MSIE 5.2');
        o[5.5]   = this.inName('MSIE 5.5');
        o['6.x'] = this.inName('MSIE 6.');
        o[6]     = this.inName('MSIE 6.0');
        o['7.x'] = this.inName('MSIE 7.')  && !this.inName('Trident/4.');
        o[7]     = this.inName('MSIE 7.0') && !this.inName('Trident/4.');
        o['8.x'] = this.inName('Trident/4.'); 
        o[8]     = this.inName('Trident/4.0');
        this.name    = 'MSIE';
        this.version = o.getVersion();
        this.engine  = 'Trident';  
        this.knowsAjax = o.gte(6); 
        return o;
    }
    this.isIe = this.getIe();
    this.isKhtml = this.knowsDom && this.inName('khtml');
    this.getSafari = function() {
        if (!this.isKhtml)          { return ''; }
        if (!this.inName('Safari')) { return ''; }
        if (this.inName('Chrome'))  { return ''; }
        var o = new AgentObject();
        o['1.x'] = this.inName('Safari/31'); 
        o[1.3]   = this.inName('Safari/31');
        o['2.x'] = this.inName('Safari/41');
        o[2]     = this.inName('Safari/41');
        o['3.x'] = this.inName('Version/3.');
        o[3]     = this.inName('Version/3.0');
        o[3.1]   = this.inName('Version/3.1');
        o[3.2]   = this.inName('Version/3.2');
        o['4.x'] = this.inName('Version/4.');
        o[4]     = this.inName('Version/4.0');
        this.name    = 'Safari';
        this.version = o.getVersion();
        this.engine  = 'WebKit';
        return o;
    }
    this.isSafari = this.getSafari();
    this.getKonqueror = function() {
        if (!this.isKhtml) { return ''; }
        if (this.isSafari) { return ''; }
        if (this.inName('Chrome'))  { return ''; }
        var o = new AgentObject();
        o['2.x'] = this.inName('Konqueror/2.');
        o[2]     = this.inName('Konqueror/2.0');
        o[2.1]   = this.inName('Konqueror/2.1');
        o[2.2]   = this.inName('Konqueror/2.2');
        o['3.x'] = this.inName('Konqueror/3');
        o[3]     = this.inName('Konqueror/3.0') || this.inName('Konqueror/3;');
        o[3.3]   = this.inName('Konqueror/3.3');
        o[3.4]   = this.inName('Konqueror/3.4');
        o[3.5]   = this.inName('Konqueror/3.5');
        o['4.x'] = this.inName('Konqueror/4.');
        o[4]     = this.inName('Konqueror/4.0');
        o[4.1]   = this.inName('Konqueror/4.1');
        o[4.2]   = this.inName('Konqueror/4.2');
        this.name    = 'Konqueror';
        this.version = o.getVersion();
        this.engine  = 'KHTML';
        return o;
    }
    this.isKonqueror = this.getKonqueror();
    this.getGoogleChrome = function() {
        if (!this.isKhtml)    { return ''; }
        if (this.isSafari)    { return ''; }
        if (this.isKonqueror) { return ''; }
        var o = new AgentObject();
        o['0.x'] = this.inName('Chrome/0.');
        o[0.2]   = this.inName('Chrome/0.2.');
        this.name    = 'Google Chrome';
        this.version = o.getVersion();
        this.engine  = 'WebKit';
        return o;
    }
    this.isGoogleChrome = this.getGoogleChrome();
    this.isGecko = this.knowsDom && !this.isIe && !this.isOpera && !this.isKhtml;
    this.getFirefox = function() {
        if (!this.isGecko)           { return ''; }
        if (!this.inName('Firefox')) { return ''; }
        var o = new AgentObject();
        o['1.x'] = this.inName('Firefox/1.');
        o[1]     = this.inName('Firefox/1.0');
        o[1.5]   = this.inName('Firefox/1.5');
        o['2.x'] = this.inName('Firefox/2.');
        o[2]     = this.inName('Firefox/2.0');
        o['3.x'] = this.inName('Firefox/3.');
        o[3]     = this.inName('Firefox/3.0');
        o[3.5]   = this.inName('Firefox/3.5');
        this.name    = 'Firefox';
        this.version = o.getVersion();
        this.engine  = 'Gecko';
        return o;
    }
    this.isFirefox = this.getFirefox();
    this.getMozilla = function() {
        if (!this.isGecko)  { return ''; }
        if (this.isFirefox) { return ''; }
        var o = new AgentObject();
        o['1.x'] = this.inName('rv:1.');
        o[1]     = this.inName('rv:1.0');
        o[1.1]   = this.inName('rv:1.1');
        o[1.2]   = this.inName('rv:1.2');
        o[1.3]   = this.inName('rv:1.3');
        o[1.4]   = this.inName('rv:1.4');
        o[1.5]   = this.inName('rv:1.5');
        o[1.6]   = this.inName('rv:1.6');
        o[1.7]   = this.inName('rv:1.7');
        o[1.8]   = this.inName('rv:1.8');
        this.name    = 'Mozilla';
        this.version = o.getVersion();
        this.engine  = 'Gecko';
        return o;
    }
    this.isMozilla = this.getMozilla();
    this.getWin = function() {
        if (!this.inName('win')) { return ''; }
        var o = new Object();
        o['95']     = this.inName('Windows 95');
        o['98']     = this.inName('Windows 98');
        o['ce']     = this.inName('Windows CE');
        o['me']     = this.inName('Windows ME');
        o['nt']     = this.inName('Windows NT;')    || this.inName('Windows NT 4.0') || this.inName('Windows NT)');
        o['2000']   = this.inName('Windows NT 5.0') || this.inName('Windows 2000');
        o['xp']     = this.inName('Windows NT 5.1') || this.inName('Windows XP');
        o['xp-sp2'] = this.inName('Windows NT 5.1') && (this.inName('SV1') || this.isIe.gte(7));
        o['s-2003'] = this.inName('Windows NT 5.2');
        o['vista']  = this.inName('Windows NT 6.0') || this.inName('Vista');
        o['win7']   = this.inName('Windows NT 6.1');
        this.os   = 'Windows';
        this.osId = o['95']     ? 'Win95'
                  : o['98']     ? 'Win98'
                  : o['2000']   ? 'Win2000'
                  : o['ce']     ? 'WinCE'
                  : o['me']     ? 'WinME'
                  : o['nt']     ? 'WinNT'
                  : o['xp-sp2'] ? 'WinXP-SP2'
                  : o['xp']     ? 'WinXP'
                  : o['s-2003'] ? 'WinServer2003'
                  : o['vista']  ? 'WinVista'
                  : o['win7']   ? 'Win7'
                  : 'Win';
        return o;
    }
    this.isWin = this.getWin();
    this.getMac = function() {
        if (!this.inName('Mac')) { return ''; }
        if (this.isWin)          { return ''; }
        var o = new Object();
        o['ppc'] = this.inName('PowerPC') || this.inName('PPC');
        o['x']   = this.inName('Mac OS X');
        this.os   = 'MacOS';
        this.osId = o['x']   ? 'MacOSX'
                  : o['ppc'] ? 'MacPPC'
                  : 'MacOS';
        if (this.isIe) { this.engine = 'Tasman'; }
        return o;
    }
    this.isMac = this.getMac();
    this.getLinux = function() {
        if (!this.inName('X11') && !this.inName('Linux')) { return ''; }
        if (this.isWin || this.isMac)                     { return ''; }
        var o = new Object();
        o['suse']  = this.inName('SuSE');
        o['sunos'] = this.inName('SunOS');
        this.os   = 'Linux';
        this.osId = o['suse']  ? 'SuseLinux'
                  : o['sunos'] ? 'SunOS'
                  : 'Linux';
        return o;
    }
    this.isLinux = this.getLinux();
}

function encodeUtf8(value, skipSzlig) {
    var c, s;
    var result = '';
    var i = 0;
    while (i < value.length) {
        c = value.charCodeAt(i++);
        if (c >= 0xDC00 && c < 0xE000) continue;
        if (c >= 0xD800 && c < 0xDC00) {
            if (i >= value.length) continue;
            s = value.charCodeAt(i++);
            if (s < 0xDC00 || c >= 0xDE00) continue;
            c = ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
        }
        if (skipSzlig && c == 'ß'.charCodeAt(0)) { result += String.fromCharCode(c); }
        else if (c < 0x80)    result += String.fromCharCode(c);
        else if (c < 0x800)   result += String.fromCharCode(0xC0+(c>>6),  0x80+(c&0x3F));
        else if (c < 0x10000) result += String.fromCharCode(0xE0+(c>>12), 0x80+(c>>6&0x3F),  0x80+(c&0x3F));
        else                  result += String.fromCharCode(0xF0+(c>>18), 0x80+(c>>12&0x3F), 0x80+(c>>6&0x3F), 0x80+(c&0x3F));
    }
    return result;
}
function encodeCharCode(charCode) {
    return '%' + charCode.toString(16).toUpperCase();
}
if (!isFunction(encodeURIComponent)) {
    function encodeURIComponent(value) {
        if (!isString(value)) { value = new String(value); }
        var allowedUriChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-';
        var result = '';
        value = encodeUtf8(value);
        for (var i=0; i<value.length; i++) {
            result += allowedUriChars.indexOf(value.charAt(i)) < 0
                    ? encodeCharCode(value.charCodeAt(i))
                    : value.charAt(i);
        }
        return result;
    }
}

function form2utf8(form) {
    for (var f=0; f<form.elements.length; f++) {
        if (form.elements[f].value) {
            form.elements[f].value = encodeUtf8(form.elements[f].value, true);
        }
    }
}

GC = {
    __garbage: new Array(),
    add: function(obj) {
        GC.__garbage.push(obj);
    },
    unload: function() {
        for (var i=0; i<GC.__garbage.length; i++) {
            GC.clear(GC.__garbage[i]);
            GC.__garbage[i] = null;
        }
    },
    clear: function(obj) {
        if (isSet(obj) && isFunction(obj.unload)) {
            obj.unload();
        }
        for (var x in obj) {
            if (!(isSet(Object.prototype[x]))) {
                if (isSet(obj[x]) && isFunction(obj[x].unload)) {
                    obj[x].unload();
                }
                obj[x] = null;
            }
        }
    }
}
isFunction(window.addOnunload) ? window.addOnunload(GC.unload) : window.onunload = GC.unload;

function go(url, win) {
    if (!isEmpty(win)) {
        window.open(url, win);
    } else { // neccessary since Firefox 3.0.13 / 3.5.2
        if (UserAgent.isFirefox && isFunction(document.documentElement.onclick)) {
            document.documentElement.onclick = function(o) { return function(event) {
                if (o) { o(event); }
                location.href = url;
            }}(document.documentElement.onclick);
            return false;
        } else {
            location.href = url;
        }
    }
    return false;
}

var Params = new function() {
    this.params = {};
    this.init = function() {
        var q = location.search;
        if (q.substr(0,1)=='?') { q = q.substr(1); }
        if (!q) { return; }
        var temp = q.split('&');
        for (var i=0; i<temp.length; i++) {
            var p = temp[i].split('=', 2);
            p[0] = unescape(p[0]);
            p[1] = unescape(p[1]);
            isSet(this.params[p[0]]) ? this.params[p[0]].push(p[1]) : this.params[p[0]] = [p[1]];
        }
    }
    this.init();
    this.get = function(name, defaultValue, forceList) {
        if (isNone(name)) { return this.params; }
        var result = this.params[name];
        if (isNone(result)) { return isTrue(forceList) ? defaultValue.toList() : defaultValue; }
        return isTrue(forceList) ? result.toList() : (result.length==1 ? result[0] : result);
    }
}

function getSizedImgUrl(url, width, height) {
    url = url.replace(/,w=\d+/, ',w='+width).replace(/,h=\d+/, ',h='+height);
    return url;
}

function createIvwPath(segs) {
    if (isString(segs)) { segs = segs.split('/'); }
    var ivwPath = [];
    var replacements = {
        '\xE4': 'ae', '\xF6': 'oe', '\xFC': 'ue',
        '\xC4': 'ae', '\xD6': 'oe', '\xDC': 'ue',
        '\xDF': 'ss'
    }
    var parts = new Array();
    for (var i=0; i<segs.length; i++) {
        var segments = segs[i].split('/');
        for (var j=0; j<segments.length; j++) {
            parts.push(segments[j]);
        }
    }
    for (var i=0; i<parts.length; i++) {
        var part = parts[i].toLowerCase();
        for (var j in replacements) {
            if (isSet(Object.prototype[j])) { continue; }
            part = part.replace(new RegExp('/'+j+'/g'), replacements[j]);
        }
        part = part.replace(/ /g, '_');
        part = part.replace(/\W/g, '');
        ivwPath.push(part.substr(0, 64));
    }
    return ivwPath;
}

function createIvwCounter(path, noPi) {
    path = (isArray(path)) ? path : new Array(path.toString());
    for (var i=0; i<path.length; i++) {
        path[i] = path[i].replace(/[^a-z0-9_]/gi, '').toLowerCase();
    }
    if (!isArray(AdvConfig.ivwUrl)) {
        AdvConfig.ivwUrl = [AdvConfig.ivwUrl];
    }
    for (var i=0; i<AdvConfig.ivwUrl.length; i++) {
        var uri = AdvConfig.ivwUrl[i].inReplace({
            'type': (isTrue(noPi)) ? 'SP' : 'CP',
            'path': path.join('/'),
            'now':  new Date().getTime()
        });
        if (__debug) { debug(uri); }
        else         { (new Image()).src = uri; }
    }
}

function stopEventPropagation(e) {
    if (isSet(e) && isFunction(e.stopPropagation)) {
        e.stopPropagation();
    } else if (isSet(window.event)) {
        window.event.cancelBubble = true;
    }
}

function newElement(name, attr, content) {
    var elem = document.createElement(name);
    if (isSet(attr)) {
        for (var a in attr) {
            if (isNone(Object.prototype[a])) {
                if      (a == 'class') { elem.className     = attr[a]; }
                else if (a == 'style') { elem.style.cssText = attr[a]; }
                else                   { elem[a]            = attr[a]; }
            }
        }
    }
    if (isSet(content)) {
        if (isString(content) && isString(elem.text)) {
            elem.text = content;
        } else {
            elem.appendChild(isString(content) ? document.createTextNode(content) : content);
        }
    }
    return elem;
}

function insertAfter(newElem, elem) {
    if (elem == elem.parentNode.lastChild) {
        return elem.parentNode.appendChild(newElem);
    } else {
        return elem.parentNode.insertBefore(newElem, elem.nextSibling);
    }
}

function getElementsByClassName(className, rootElement, elementName) {
    var allObj;
    var retObj = new Array();
    if (isNone(rootElement)) { rootElement = document; }
    if (isNone(elementName)) { elementName = 'span'; }
    allObj = rootElement.getElementsByTagName(elementName);
    for (i=0; i < allObj.length; i++) {
        if (allObj[i].className.indexOf(className) != -1) {
            if (allObj[i].className.split(' ').hasValue(className)) {
                retObj.push(allObj[i]);
            }
        }
    }
    return retObj;
}

function addClassName(el, className) {
    el.className += ' '+className;
}
function delClassName(el, className) {
    el.className = el.className.replace(new RegExp('\\s*\\b'+className+'\\b'), '');
}

Coords = function(x, y) {
    this.toString = function() { return this.x + 'x' + this.y; }
    this.x = x||0;
    this.y = y||0;
    this.add = function(that) {
        this.x += that.x;
        this.y += that.y;
        return this;
    }
    this.sub = function(that) {
        this.x -= that.x;
        this.y -= that.y;
        return this;
    }
    this.clone = function() {
        return new Coords(this.x, this.y);
    }
}

function getElementPosition(el, relative) {
    var pos = new Coords(el.offsetLeft, el.offsetTop);
    if (isTrue(relative)) { return pos; }
    while (el = el.offsetParent) {
        pos.x += el.offsetParent ? el.offsetLeft : 0;
        pos.y += el.offsetParent ? el.offsetTop  : 0; 
    }
    return pos;
}

function getAbsoluteUrl(uri, baseUri) {
    if (isUndefined(baseUri)) { baseUri = location.href; }
    function getUriParts(uri) {
        var re     = new RegExp('^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?$');
        var result = uri.match(re);
        var parts  = {
            '1': result[2], 'protocol': result[2],
            '2': result[4], 'hostport': result[4],
            '3': result[5], 'path':     result[5],
            '4': result[7], 'query':    result[7],
            '5': result[9], 'fragment': result[9],
            '0': result[0], 'complete': result[0]
        };
        return parts;
    }
    var baseParts = getUriParts(baseUri);
    var newParts  = getUriParts(uri);
    var start = 1;
    for (start=1; start<=5; start++) {
        if (!isEmpty(newParts[start])) { break; }
    }
    for (var i=5; i>=start; i--) {
        if (i==3) {
            if (newParts[i].substring(0, 1) == '/') { baseParts[i] = ''; }
            basePath = baseParts[i].split('/');
            newPath  = newParts[i].split('/');
            basePath.pop();
            for (var j=0; j<newPath.length; j++) {
                if (newPath[j] == '.')  { continue; }
                if (newPath[j] == '..') { basePath.pop(); continue; }
                basePath.push(newPath[j]);
            }
            baseParts[i] = basePath.join('/');
        } else {
            baseParts[i] = newParts[i];
        }
    }
    baseParts[4] = isEmpty(baseParts[4]) ? '' : '?'+baseParts[4];
    baseParts[5] = isEmpty(baseParts[5]) ? '' : '#'+baseParts[5];
    return '${1}://${2}${3}${4}${5}'.inReplace(baseParts);
}

function createQuery(data, qm, rewriteCompat) {
    var parts = new Array();
    for (var i in data) {
        if (isSet(Object.prototype[i])) { continue; }
        if (isNone(data[i]))            { continue; }
        if (!isArray(data[i])) {
            data[i] = new Array(data[i].toString());
        }
        for (var j=0; j<data[i].length; j++) {
            if (isTrue(rewriteCompat)) {
                parts.push(encodeURIComponent(i).replace(/%2F/gi,'/').replace(/%2E/gi,'.')+'='+encodeURIComponent(data[i][j]).replace(/%2F/gi,'/'));
            } else {
                parts.push(encodeURIComponent(i)+'='+encodeURIComponent(data[i][j]));
            }
        }
    }
    return (isTrue(qm) ? '?' : '') + parts.join('&');
}

function clearValue(inp, className) {
    if (inp.value == inp.defaultValue) {
        inp.value = '';
        if (isSet(className)) {
            delClassName(inp, className);
        }
    }
}

function restoreValue(inp, className) {
    if (inp.value == '') {
        inp.value = inp.defaultValue;
        if (isSet(className)) {
            addClassName(inp, className);
        }
    }
}

function propertyCssToJs(name) {
    var temp = name.split('-');
    for (var i=1; i<temp.length; i++) {
        temp[i] = temp[i].ucfirst();
    }
    return temp.join('');
}

function getStyle(obj, property) {
    var style = isSet(window.getComputedStyle)
              ? window.getComputedStyle(obj, '')
              : obj.currentStyle;
    if (!isSet(style))    { return undefined; }
    if (isNone(property)) { return style; }
    propertyName = propertyCssToJs(property);
    return style[propertyName];
}

function addStyleRuleSet(css) {
    if (UserAgent.isIe) { 
        var sheet = document.createStyleSheet();
        var rules = css.split('}');
        for (var i=0; i<rules.length-1; i++) {
            var parts = rules[i].split('{', 2);
            sheet.addRule(parts[0], parts[1]);
        }
    } else {
        var el = newElement('style', {'type':'text/css'}, css);
        document.getElementsByTagName('head')[0].appendChild(el);
    }
}

Cookies = new function() {
    this.jar = {};
    this.encode = function(value) {
        return encodeURIComponent(new String(value));
    }
    this.decode = function(value) {
        return unescape(value);
    }
    this.parse = function() {
        if (!document.cookie) { return; }
        var cookies = document.cookie.split(/;\s*/);
        for (var i=0; i<cookies.length; i++) {
            var cook = cookies[i].split('=', 2);
            this.jar[this.decode(cook[0])] = this.decode(cook[1]);
        }
    }
    this.parse();
    this.get = function(name) {
        return this.jar[name];
    }
    this.getAsString = function(name, def) {
        var value = this.get(name);
        if (isNone(value)) { return def; }
        return isObject(value) && isFunction(value.pickle) ? value.pickle() : value.toString();
    }
    this.getAsInt = function(name, def) {
        var value = parseInt(this.get(name));
        return isNumber(value) && !isNaN(value) ? value : def;
    }
    this.getAsDate = function(name, def) {
        var value = this.get(name);
        value = value.startsWith('new Date') ? eval(value) : new Date(value);
        return isDate(value) ? value : def;
    }
    this.unpickle = function(name) {
        var value = this.get(name);
        if (!isString(value)) { return value; }
        new RegExp(/^new ([a-z]\w+)\(\)\.unpickle\((\{.*\})\)/i).exec(value);
        var objName = RegExp.$1;
        if (!isSet(window[objName]))          { return undefined; }
        if (!isSet(window[objName].unpickle)) { return null; }
        var param = RegExp.$2;
        param = eval('new Object('+param+')');
        var obj = window[objName].unpickle(param);
        this.jar[name] = obj;
        return obj;
    }
    this.set = function(name, value, expires, path, domain, secure) {
        var delim = '; ';
        if (isObject(value)) {
            if (isFunction(value.pickle)) { value = value.pickle(); }
            else                          { value = getValueString(value); }
        }
        var cook  = this.encode(name)+'='+this.encode(value);
        if (isSet(expires)) {
            var date = new Date();
            if (isDate(expires)) { date = expires; }
            if (isString(expires)) {
                var parts = expires.split(' ');
                for (var i=0; i<parts.length; i++) {
                    var part  = parts[i];
                    var value = parseFloat(part.substr(0, part.length-1));
                    switch (part.substr(part.length-1)) {
                        case 'y': date.setTime(date.getTime() + value*365*86400*1000); break;
                        case 'm': date.setTime(date.getTime() + value* 30*86400*1000); break;
                        case 'd': date.setTime(date.getTime() + value*    86400*1000); break;
                        case 'h': date.setTime(date.getTime() + value*     3600*1000); break;
                        case 'i': date.setTime(date.getTime() + value*       60*1000); break;
                        case 's': date.setTime(date.getTime() + value*          1000); break;
                    }
                }
            }
            cook += delim+'expires='+date.toGMTString();
        }
        if (isSet(path))    { cook += delim+'path='+path; }
        if (isSet(domain))  { cook += delim+'domain='+domain; }
        if (isTrue(secure)) { cook += delim+'secure'; }
        document.cookie = cook;
        this.parse();
    }
    this.remove = function(name) {
        if (isEmpty(name)) { return this.edit(); }
        this.set(name, '', '-1d');
        delete this.jar[name];
    }
    this.edit = function() {
        var w = window.open('about:blank', 'cookiesEdit', 'width=200,height=200');
        if (!w || w.closed) { return; }
        var d = w.document;
        d.open();
        d.writeln('<html><head><title>Cookies on '+location.host+'</title></head><body>');
        d.writeln('<form action="javascript:void(0);" onsubmit="opener.Cookies.remove(this.cookies.options[this.cookies.options.selectedIndex].value); self.close(); return false;"><select name="cookies">');
        for (var i in this.jar) {
            if (isSet(Object.prototype[i])) { continue; }
            var value = this.getAsString(i);
            d.writeln('<option value="${name}" title="${value}">${name}</option>'.inReplace({'name':i.encodeHtml(), 'value':value.encodeHtml()}));
        }
        d.writeln('</select><input type="submit" value="Delete Cookie"/></form>');
        d.writeln('</body></html>');
        d.close();
        w.focus();
    }
    this.increase = function(name, def, expires, path, domain, secure) {
        var value = this.getAsInt(name, def) + 1;
        this.set(name, value, expires, path, domain, secure);
        return this.getAsInt(name, def);
    }
    this.show = function() {
        var temp = new Array();
        for (var i in this.jar) {
            if (isSet(Object.prototype[i])) { continue; }
            var value = this.get(i);
            if (isObject(value)) { value = value.pickle(); }
            temp.push(i+': '+value);
        }
        alert(temp.join('\n'));
    }
}
function getValueString(value, instanceName) {
    if (isNone(instanceName)) { instanceName = 'Object'; }
    switch (typeof(value)) {
        case 'undefined':
        case 'number':
        case 'boolean':  return new String(value);
        case 'string':   return '"'+(value.replace('\\', '\\\\').replace('"', '\\"'))+'"';
        case 'function': return 'null'; 
        case 'object':
            if (isNull(value))  { return 'null'; }
            if (isError(value)) { return 'null'; }
            if (isDate(value))  { return 'new Date('+value.getTime()+')'; }
            if (isArray(value)) {
                var temp = new Array();
                for (var i=0; i<value.length; i++) {
                    temp.push(getValueString(value[i]));
                }
                return 'new Array('+temp.join(', ')+')';
            }
            var temp = new Array();
            for (var i in value) {
                if (isSet(Object.prototype[i])) { continue; }
                if (isFunction(value[i]))       { continue; }
                temp.push('${name}: ${value}'.inReplace({'name': getValueString(''+i), 'value': getValueString(value[i])}));
            }
            return 'new '+instanceName+'().unpickle({'+temp.join(', ')+'})';
        default: return 'undefined'; 
    }
}

Object.prototype._pickle = function(instanceName) {
    return getValueString(this, instanceName);
}
Object.prototype.unpickle = function(obj) {
    var result = new this();
    for (var i in obj) {
        if (isSet(Object.prototype[i])) { continue; }
        result[i] = obj[i];
    }
    return result;
}

Statistics = function(path) {
    this.values = {};
    this.errors = new Array();
    this.path   = new Array('webde');
    this.setPath = function(path) {
        if (isArray(path)) { this.path = path; }
        else               { this.path = path.split('/'); }
    }
    this.setPath(path);
    this.reset = function() {
        this.values = {};
    }
    this.update = function(values) {
        if (isSet(values)) {
            for (var i=0; i<values.length; i++) {
                this.values[values[i]] = null;
            }
        }
    }
    this.prepare = function() {
        this.reset();
        this.update(arguments);
    }
    this.addError = function(error) {
        this.errors.push(error);
    }
    this.run = function() {
        for (var i in this.values) {
            if (isSet(Object.prototype[i])) { continue; }
            switch (i) {
                case 'flashplug':  this.runFlash(i);      break;
                case 'screen':     this.runResolution(i); break;
                case 'winsize':    this.runWinsize(i);    break;
                case 'scrollbar':  this.runScrollbar(i);  break;
                case 'cookies':    this.runCookies(i);    break;
                case 'popupInTab': this.runPopupInTab(i); break;
                default: this.addError('Unknown: "'+i+'"');
            }
        }
    }
    this.setResult = function(name, value) {
        if (name=='flashplug') { name='flashpdp'; }
        this.values[name] = value;
        (new Image()).src = '//img.web.de/ivw/SP/${path}/${name}/${value}?ts=${now}'.inReplace({
            'path':  this.path.join('/'),
            'name':  name,
            'value': value,
            'now':   (new Date()).getTime()
        });
    }
    this.runFlash = function(name) {
        if (isSet(window.FlashDetection)) {
            if (FlashDetection.installed) {
                this.setResult(name, 'flash'+FlashDetection.version);
            } else {
                this.setResult(name, 'noflash');
            }
        } else {
            this.setResult(name, 'flashnotchecked');
        }
        this.setResult(name, 'gesamt');
    }
    this.runResolution = function(name) {
        var resList    = new Array(800, 1024, 1152, 1280);
        var resolution = 'noscreen';
        var width      = screen.width;
        if (width > resList[resList.length-1]) {
            resolution = 'g' + resList[resList.length-1];
        } else {
            for (var i=0; i<resList.length; i++) {
                if (width <= resList[i]) {
                    resolution = (width < resList[i] ? 'k' : '') + resList[i];
                    break;
                }
            }
        }
        this.setResult(name, resolution);
    }
    this.runWinsize = function(name) {
        var sizes = [1024, 1100, 1150, 1200, 1250, 1280, 1330, 1380, 1430, 1480, 1530, 1580, 1630, 1680]; 
        var width = window.innerWidth  ? window.innerWidth  : (document.documentElement && document.documentElement.offsetWidth  ? document.documentElement.offsetWidth  : 0);
        if (width < sizes[0]) { return this.setResult('winsize3', '0to'+(sizes[0]-1)); }
        for (var i=1; i<sizes.length; i++) {
            if (width < sizes[i]) { return this.setResult('winsize3', sizes[i-1]+'to'+(sizes[i]-1)); }
        }
        return this.setResult('winsize3', sizes[sizes.length-1]+'toinf');
    }
    this.runScrollbar = function(name) {
        if (!isSet(document.documentElement)) { return; }
        document.documentElement.style.overflow = 'hidden';
        var x    = window.innerWidth ? window.innerWidth : (document.documentElement && document.documentElement.offsetWidth ? document.documentElement.offsetWidth : 0);
        document.documentElement.style.overflow = 'auto';
        var sbar = (document.documentElement && document.documentElement.clientWidth) ? x-document.documentElement.clientWidth : 'unknown';
        if (sbar!='unknown' && sbar!=0 && sbar<100) {
            this.setResult(name+'/available', x-sbar);
            this.setResult(name+'/width',     sbar);
        } else {
            this.setResult(name+'/available', 'unknown');
            this.setResult(name+'/width',     'unknown');
        }
    }
    this.runCookies = function(name) {
        var cookies = Cookies.jar;
        var set     = new Array();
        for (var i in cookies) {
            if (isSet(Object.prototype[i])) { continue; }
            set.push(i);
        }
        this.setResult(name+'/NGUserID',   new String(set.hasValue('NGUserID')));
        this.setResult(name+'/accepted',   new String(set.hasValue('visits')));
        this.setResult(name+'/noprevious', new String(!set.hasValue('visits') || parseInt(Cookies.get('visits'))==1));
    }
    this.runPopupInTab = function(name) {
        if (UserAgent.isIe[7]) {
            window['[[Statistics.PopupInTab]]'] = this.executePopupInTab.bind(this, name);
        }
    }
    this.executePopupInTab = function(name, value) {
        this.setResult(name, value);
    }
}

var FlashHelpObject = new function() {
    this.supportedVersion = null;
    this.findVersion = function() {
        if (UserAgent.isIe && UserAgent.isWin) {
            window.flashVersion = 0;
            window.execScript('\
                on error resume next\n\
                temp = false: temp = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))): If temp=true Then flashVersion = 2\n\
                temp = false: temp = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))): If temp=true Then flashVersion = 3\n\
                temp = false: temp = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))): If temp=true Then flashVersion = 4\n\
                temp = false: temp = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))): If temp=true Then flashVersion = 5\n\
                temp = false: temp = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))): If temp=true Then flashVersion = 6\n\
                temp = false: temp = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))): If temp=true Then flashVersion = 7\n\
                temp = false: temp = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))): If temp=true Then flashVersion = 8\n\
                temp = false: temp = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))): If temp=true Then flashVersion = 9\n\
            ', 'VBScript');
        } else if (navigator.plugins) {
            if (navigator.plugins['Shockwave Flash 2.0'] || navigator.plugins['Shockwave Flash']) {
                var isVersion2 = navigator.plugins['Shockwave Flash 2.0'] ? ' 2.0' : '';
                var flashDescription = navigator.plugins['Shockwave Flash' + isVersion2].description;
                window.flashVersion = parseInt(flashDescription.substring(16));
            }
        }
        this.supportedVersion = parseInt(window.flashVersion);
        if (isNaN(this.supportedVersion)) { this.supportedVersion = 0; }
    }
    this.getSupportedVersion = function() {
        if (isNone(this.supportedVersion)) { this.findVersion(); }
        return this.supportedVersion;
    }
    this.versionIsSupported = function(version) {
        return version <= this.getSupportedVersion();
    }
    this.create = function(id, minVersion, flashUrl, clickUrl, imgUrl, width, height, options) {
        options = (options||{}).defaultIs({'wmode':'opaque','onlyIfTrue':function() { return true; }, 'target':'_blank'});
        if (this.versionIsSupported(minVersion) && (flashUrl!='') && options['onlyIfTrue']()) {
            flashUrl = flashUrl + (flashUrl.indexOf('?')+1 ? '&' : '?')+'clicktag='+encodeURIComponent(clickUrl);
            document.writeln('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="'+id+'" width="'+width+'" height="'+height+'">');
            document.writeln('<param name="movie" value="'+flashUrl+'"/>');
            document.writeln('<param name="quality" value="high"/>');
            document.writeln('<param name="wmode" value="'+options['wmode']+'"/>');
            document.writeln('<embed src="'+flashUrl+'" width="'+width+'" height="'+height+'"quality="high" wmode="'+options['wmode']+'" type="application/x-shockwave-flash" pluginspage="www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"/>');
            document.writeln('</object>');
            return true;
        } else {
            if (isSet(clickUrl) && isSet(imgUrl)) {
                document.writeln('<a href="'+clickUrl+'" target="'+options['target']+'"><img src="'+imgUrl+'" alt=""/></a>');
            }
            return false;
        }
    }
    this.rootElement  = document;
    this.flashElement = null;
    this.setElementsVisibility = function(visible, elems, root) {
        if (typeof(elems) == 'string')    { elems = [elems]; }
        if (typeof(root)  == 'undefined') { root  = this.rootElement; }
        var els = [];
        for (var i=0; i<elems.length; i++) {
            var temp = root.getElementsByTagName(elems[i]);
            for (var j=0; j<temp.length; j++) {
                els.push(temp[j]);
            }
        }
        for (var i=0; i<els.length; i++) {
            els[i].style.visibility = visible ? 'visible' : 'hidden';
        }
        return els.length;
    }
    this.bringFlashToFront = function() {
        this.flashElement.style.zIndex = 32000;
    }
    this.bringFlashToBack = function() {
        this.flashElement.style.zIndex = 0;
    }
    this.showSelectBoxes = function()   { return this.setElementsVisibility(true,  'select'); }
    this.hideSelectBoxes = function()   { return this.setElementsVisibility(false, 'select'); }
    this.showFlashElements = function() { return this.setElementsVisibility(true,  ['object', 'embed']); }
    this.hideFlashElements = function() { return this.setElementsVisibility(false, ['object', 'embed']); }
    this.flashShows = function() { this.hideSelectBoxes(); return this.bringFlashToFront(); }
    this.flashHides = function() { this.showSelectBoxes(); return this.bringFlashToBack(); }
}
FlashHelpObject.setInvisible = function(obj, root, iframesAlso) {
    if (isNone(root))        { root        = document.documentElement; }
    if (isNone(iframesAlso)) { iframesAlso = true; }
    var maskings = ['object', 'embed'];
    if (iframesAlso) { maskings.push('iframe'); }
    for (var el=0; el<maskings.length; el++) {
        var os = root.getElementsByTagName(maskings[el]);
        for (var i=0; i<os.length; i++) {
            if (isNone(os[i].disabledBy))        { os[i].disabledBy = []; }
            if (!os[i].disabledBy.hasValue(obj)) { os[i].disabledBy.push(obj); }
            os[i].style.visibility = 'hidden';
        }
    }
}
FlashHelpObject.setVisible = function(obj, root, iframesAlso) {
    if (isNone(root))        { root        = document.documentElement; }
    if (isNone(iframesAlso)) { iframesAlso = true; }
    var maskings = ['object', 'embed'];
    if (iframesAlso) { maskings.push('iframe'); }
    for (var el=0; el<maskings.length; el++) {
        var os = root.getElementsByTagName(maskings[el]);
        for (var i=0; i<os.length; i++) {
            if (isNone(os[i].disabledBy)) { continue; }
            os[i].disabledBy.removeValue(obj);
            if (isEmpty(os[i].disabledBy)) {
                os[i].style.visibility = 'visible';
            }
        }
    }
}
var FlashObject = FlashHelpObject;
var FlashHelp = FlashHelpObject; 



if (!isFunction(Function.apply)) {
    Function.prototype.apply = function(obj, a) {
        var x = '____apply';
        var result;
        obj[x] = this;
        switch ((a && a.length) || 0) {
            case 0: result = obj[x](); break;
            case 1: result = obj[x](a[0]); break;
            case 2: result = obj[x](a[0], a[1]); break;
            case 3: result = obj[x](a[0], a[1], a[2]); break;
            case 4: result = obj[x](a[0], a[1], a[2], a[3]); break;
            case 5: result = obj[x](a[0], a[1], a[2], a[3], a[4]); break;
            case 6: result = obj[x](a[0], a[1], a[2], a[3], a[4], a[5]); break;
            case 7: result = obj[x](a[0], a[1], a[2], a[3], a[4], a[5], a[6]); break;
            case 8: result = obj[x](a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]); break;
            case 9: result = obj[x](a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]); break;
        }
        return result;
    }
}
if (!isFunction(Array.prototype.pop)) {
    Array.prototype.pop = function() {
        return this.splice(this.length-1, 1)[0];
    }
}
if (!isFunction(Array.prototype.splice)) {
    Array.prototype.splice = function() {
        var a = [], 
            e,      
            i = Math.max(arguments.length-2, 0), 
            k = 0,
            l = this.length,
            n,      
            v,      
            x;      
        var s = Math.max(l, 0);  
        var d = Math.max(Math.min(l, l-s), 0); 
        v = i - d;
        n = l + v;
        while (k < d) {
            e = this[s + k];
            if (!isUndefined(e)) {
                a[k] = e;
            }
            k += 1;
        }
        x = l - s - d;
        if (v < 0) {
            k = s + i;
            while (x) {
                this[k] = this[k - v];
                k += 1;
                x -= 1;
            }
            this.length = n;
        } else if (v > 0) {
            k = 1;
            while (x) {
                this[n - k] = this[l - k];
                k += 1;
                x -= 1;
            }
        }
        for (k = 0; k < i; ++k) {
            this[s + k] = arguments[k + 2];
        }
        return a;
    };
}
if (!isFunction(Array.prototype.push)) {
    Array.prototype.push = function(value) {
        this.splice.apply(this, [this.length, 0].concat(Array.prototype.slice.apply(arguments)));
        return this.length;
    }
}
if (!isFunction(Array.prototype.shift)) {
    Array.prototype.shift = function() {
        return this.splice(0, 1)[0];
    };
}
if (!isFunction(Array.prototype.unshift)) {
    Array.prototype.unshift = function() {
        this.splice.apply(this,
            [0, 0].concat(Array.prototype.slice.apply(arguments)));
        return this.length;
    };
} 
Array.prototype.hasValue = function(value) {
    for (var i=0; i<this.length; i++) {
        if (this[i] == value) { return true; }
    }
    return false;
}
Array.prototype.removeValue = function(value) {
    var deleted = 0;
    for (var i=this.length-1; i>=0; i--) {
        if (this[i] == value) {
            this.splice(i, 1);
            deleted++;
        }
    }
    return deleted;
}
Array.prototype.toList = function() {
    return this;
}
String.prototype.toList = function(sep) {
    return isSet(sep) ? this.split(sep) : new Array(this);
}
Boolean.prototype.toList = function() {
    return [this];
}

Function.prototype.bind = function() {
  var __method = this, args = $A(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat($A(arguments)));
  }
}

Function.prototype.bindAsEventListener = function(object) {
  var __method = this;
  return function(event) {
    return __method.call(object, event || window.event);
  }
}

var $A = Array.from = function(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) {
    return iterable.toArray();
  } else {
    var results = [];
    for (var i = 0; i < iterable.length; i++)
      results.push(iterable[i]);
    return results;
  }
}

String.prototype.trim = function() {
    return this.replace(/^\s+/, '').replace(/\s+$/, '');
}

String.prototype.ucfirst = function() {
    return this.toString().substring(0, 1).toUpperCase() + this.toString().substring(1);
}

String.prototype.startsWith = function(start) {
    return this.toString().substring(0, start.length) == start;
}

String.prototype.endsWith = function(start) {
    return this.toString().substr(this.length-start.length) == start;
}

String.prototype.inReplace = function(values) {
    var text = this.toString();
    for (var i in values) {
        var value = values[i];
        if (isSet(Object.prototype[i]) || (isSet(value) && !isString(value) && !isFunction(value.toString))) { continue; }
        var re = new RegExp('(\\$\\{'+i+'\\})|(\\$'+i+'\\b)', 'g');
        text = text.replace(re, isFunction(value) ? function() { return value(); } : value);
    }
    return text;
}

String.prototype.shorten = function(maxLength, type, ellipsis, minLength) {
    var result = '';
    var text   = this.toString().replace('\n', ' ');;
    if (isNone(ellipsis))  { ellipsis  = ' ...'; }
    if (isNone(minLength)) { minLength = parseInt(maxLength/3); }
    if (type == 'sentence') {
        if (new RegExp('^(.{'+minLength+','+maxLength+'}[.!?:])').test(text)) {
            result = RegExp.$1;
        }
        if (isEmpty(result)) { type = 'word'; }
    }
    if (type == 'word') {
        if (new RegExp('^(.{'+minLength+','+maxLength+'}\\b)').test(text)) {
            result = RegExp.$1;
        }
        if (isEmpty(result)) { type = 'char'; }
    }
    if (type == 'char') {
        result = text.substr(0, maxLength);
    }
    if (result.length < this.length) { result += ellipsis; }
    return result;
}

String.prototype.encodeHtml = function() {
    var text = this.toString();
    text = text.replace(/&/g, '&amp;'); 
    text = text.replace(/</g, '&lt;');
    text = text.replace(/>/g, '&gt;');
    text = text.replace(/"/g, '&quot;'); // "
    return text;
}

String.prototype.toHtml = function() {
    var el = document.createElement('div');
    el.innerHTML = this.toString();
    if (el.childNodes.length == 1) {
        return el.firstChild;
    }
    if (isFunction(document.createDocumentFragment)) {
        var temp = document.createDocumentFragment();
        while (el.firstChild) {
            temp.appendChild(el.firstChild);
        }
        return temp;
    } else {
        return el;
    }
}

String.prototype.multiply = function(amount) {
    var result = '';
    for (var i=0; i<amount; i++) { result += this.toString(); }
    return result;
}

String.prototype.sprintf = function() {
    var re    = /%([ 0.]|'(.))?(-)?(\d+)?(\.\d+)?([%bcdufosxX])/g;
    var parts = [];
    var part;
    var result = this.toString();
    var args   = 0;
    while (part = re.exec(result)) { parts.push(part); args += part[6]=='%' ? 0 : 1; }
    if (isNone(arguments) || arguments.length!=args) {
        return result;
    }
    for (var i=0; i<parts.length; i++) {
        var padd = parts[i][1]&&parts[i][1][0]=="'" ? parts[i][2]           : parts[i][1]||' ';
        var just = parts[i][3]=='-'                 ? false                 : true;
        var minL = parts[i][4]                      ? parseInt(parts[i][4]) : 0;
        var prec = parts[i][5]                      ? parseInt(parts[i][5].substr(1)) : null;
        var type = parts[i][6];
        var part = arguments[i];
        switch (type) {
            case '%': part = '%';                                                             break;
            case 'b': part = parseInt(part).toString(2);                                      break;
            case 'c': part = String.fromCharCode(parseInt(part));                             break;
            case 'd': part = isNaN(part) ? 0 : parseInt(part);                                break;
            case 'u': part = Math.abs(part);                                                  break;
            case 'f': part = isSet(prec) ? parseFloat(part).toFixed(prec) : parseFloat(part); break;
            case 'o': part = parseInt(part).toString(8);                                      break;
            case 'x': part = parseInt(part).toString(16).toLowerCase();                       break;
            case 'X': part = parseInt(part).toString(16).toUpperCase();                       break;
            case 's':
            default:
                part = part;
        }
        part = ''+part;
        if (part.length < minL+(prec?prec+1:0)) {
            if (just) {
                part = padd.multiply(minL) + part;
                part = part.substr(part.length-minL-(prec?prec+1:0));
            } else {
                part = part + padd.multiply(minL);
                part = part.substr(0, minL);
            }
        }
        result = result.replace('%'+(parts[i][1]||'')+(parts[i][3]||'')+(parts[i][4]||'')+(parts[i][5]||'')+parts[i][6], part);
    }
    return result;
}


AdvServer = function(host, path, secure, paramsAsQuery, includeTile) {
    this.host          = host;
    this.path          = isSet(path)   ? path   : {'extads.web.de':'js.ng', 'adclient.uimserv.net':'js.ng'}[host];
    this.secure        = isSet(secure) ? secure : location.protocol.startsWith('https');
    this.paramsAsQuery = isTrue(paramsAsQuery);
    this.includeTile   = !isFalse(includeTile);
    this.getUrl        = function() {
        return '${prot}://${host}${path}/${qm}'.inReplace({'prot':this.secure?'https':'http', 'host':this.host, 'path':(this.path ? '/'+this.path : ''), 'qm':(this.paramsAsQuery ? '?' : '')});
    }
}
AdvItem = function(type, sizes, styles, params) {
    this.type   = type;
    this.sizes  = isSet(sizes) ? sizes.toList() : null;
    this.styles = isSet(styles) ? styles.toList(',') : new Array();
    this.params = params;
    this.getParams = function(defaults) {
        return this.params.defaultIs({'special':this.type, 'adsize':this.sizes, 'params.styles':this.styles.length?this.styles.join(','):null}).defaultIs(defaults||{});
    }
}
AdvConfig = new function() {
    this.ivwUrl    = '//img.web.de/ivw/${type}/webde/homepage/${path}?ts=${now}';
    this.site      = null;
    this.section   = new Array();
    this.positions = new Object();
    this.params    = new Object();
    this.server    = new AdvServer('adclient.uimserv.net');
    this.tile      = (Math.random()+'012345678910abc').toString().substr(2, 30);
    this.isTest    = location.host.indexOf('.') < 0;
    this.postAds   = [];
    this.init = function(site, section, params) {
        this.site    = site;
        this.section = section.split('/');
        if (isSet(params)) {
            this.params = this.initParams(params.defaultIs(this.params));
        }
    }
    this.setServer = function(server) {
        this.server = isObject(server) ? server : new AdvServer(server);
    }
    this.initParams = function(params) {
        if (isNone(params)) { params = {}; }
        for (var i in params) {
            if (isSet(Object.prototype[i])) { continue; }
            if (isNone(params[i]))          { continue; }
            params[i] = params[i].toList();
        }
        return params;
    }
    this.initFromCopy = function(advConfig) {
        this.site    = advConfig.site;
        this.section = advConfig.section;
        this.params  = advConfig.params;
        this.server  = advConfig.server;
        this.tile    = advConfig.tile;
    }
    this.addPosition = function(name, type, sizes, styles, params) {
        this.positions[name] = new AdvItem(type, sizes, styles, this.initParams(params));
    }
    this.addPostAd = function(name) {
        this.postAds.push(name);
    }
    this.output = function(name) {
        var ad = this.positions[name];
        if (isNone(ad)) { return; }
        var params = ad.getParams(this.params);
        if (this.isTest) {
            params['pageview'] = (isSet(params['pageview']) ? params['pageview'] : new Array());
            if (!params['pageview'].hasValue('test')) { params['pageview'].push('test'); }
        }
        var advUrl = this.server.getUrl() + createQuery({'site':this.site, 'section':this.section.join('/')}, false, true)
                   //+ '&' + createQuery(params, false, true) + (this.server.includeTile ? '&tile='+this.tile+'&transactionID='+this.tile : '');
                   + '&' + createQuery(params, false, true) + (this.server.includeTile ? '&tile='+this.tile : '');
        if (isSet(params['uri'])) { advUrl = params['uri']; }
        //document.write('<a href="${advUrl}">${advUrl}</a><br/>'.inReplace({'advUrl':advUrl}));
        document.writeln('<!-- ${advUrl} -->'.inReplace({'advUrl':advUrl}));
        document.write('<script type="text/javascript" src="${advUrl}"><\/script>'.inReplace({'advUrl': advUrl}));
        return ad;
    }
    this.outputPostAds = function() {
        for (var i=0; i<this.postAds.length; i++) {
            var ad = this.output(this.postAds[i]);
            var id = ad.getParams(this.params)['html.id'];
            if (isNone(id))  { return; }
            if (isArray(id)) { id = id[0]; }
            window.addOnload(function(id) {
                if (!UserAgent.knowsDom) { return; }
                var origin = document.getElementById(id+'Origin');
                var target = document.getElementById(id);
                if (!origin || !target) { return; }
                origin.appendChild(newElement('div', {'class':'hr'}, newElement('hr')));
                for (var i=origin.childNodes.length-1; i>=0; i--) {
                    target.insertBefore(origin.childNodes[i], target.firstChild);
                }
            }.bind(this, id));
        }
    }
}

EventHandler = function(obj, events) {
    this._object     = obj;
    this._events     = new Object();
    this._registered = new Array(); // See constructor below.
    this.registerEvent = function(eName) {
        eName = this.normalizeEventName(eName, true);
        if (!this._registered.hasValue(eName.toLowerCase())) {
            this._registered.push(eName.toLowerCase());
            this['add'+eName]     = new Function('func', "this.addEvent('"+eName+"', func)").bind(this);
            this['remove'+eName]  = new Function('func', "this.removeEvent('"+eName+"', func)").bind(this);
            this['get'+eName+'s'] = new Function('',     "this.getEvents('"+eName+"')").bind(this);
            this['run'+eName+'s'] = new Function('e',    "return this.runEvents('"+eName+"', e)").bind(this);
            this._object['add'+eName]    = this['add'+eName];
            this._object['remove'+eName] = this['remove'+eName];
            this._events[eName.toLowerCase()] = new Array();
            if (isSet(this._object[eName.toLowerCase()])) {
                this['add'+eName](this._object[eName.toLowerCase()].bind(this._object));
            }
            this._object[eName.toLowerCase()] = this['run'+eName+'s'];
        }
    }
    this.normalizeEventName = function(eName, ucfirst) {
        eName = ((eName.substring(0, 2).toLowerCase() == 'on' ? '' : 'on') + eName).toLowerCase();
        return ucfirst ? eName.substring(0,1).toUpperCase()+eName.substr(1) : eName;
    }
    this.getEvents = function(eName) {
        eName = this.normalizeEventName(eName);
        return this._events[eName];
    }
    this.addEvent = function(eName, func) {
        eName = this.normalizeEventName(eName);
        this._events[eName].push(func);
    }
    this.removeEvent = function(eName, func) {
        eName = this.normalizeEventName(eName);
        if (this._events[eName].hasValue(func)) {
            this._events[eName].remove(func);
        }
    }
    this.runEvents = function(eName, e) {
        var events = this.getEvents(eName);
        var result = true;
        for (var i=0; i<events.length; i++) {
            var func = events[i];
            var temp;
            if (isFunction(func)) {
                temp = func(e);
            } else if (isString(func)) {
                temp = eval(func);
            }
            if (temp === false) { result = false; }
        }
        return result;
    }
    this.unload = function() {
        for (var r=0; r<this._registered.length; r++) {
            var name = this._registered[r];
            for (var e=0; e<this._events[name].length; e++) {
                this._events[name][e] = null;
            }
            this._events[name]  = null;
            this._registered[r] = null;
            this._object[name]  = null;
            this._object.registerEvent = null;
            this._object['add'+name.ucfirst()]    = null;
            this._object['remove'+name.ucfirst()] = null;
        }
    }
    // Constructor:
    if (!isArray(events)) {
        events = new Array('load', 'change', 'keydown');
    }
    for (var i=0; i<events.length; i++) {
        this.registerEvent(events[i]);
    }
    this._object.registerEvent = this.registerEvent.bind(this);
    GC.add(this);
}
new EventHandler(window, new Array('load', 'unload'));



function IvwCounter() {
    this.count = function(mcFrom, mcTo) {
        request = new Image();
        rnd = Math.ceil(Math.random()*100000);
        var protocol = location.protocol
        if (protocol == 'file:') {
            protocol = 'http:';
        }
        request.src = protocol+'//r.ui-portal.de/f/' +this.getValidMcPart(mcFrom)+ '/t/' +this.getValidMcPart(mcTo)+ '/p/p.gif?ts=' +rnd;
    }
    this.getValidMcPart = function(mcPart) {
        mcPart = mcPart.split('*')[0];
        mcPart = mcPart.replace('@',   '/');
        mcPart = mcPart.replace('%40', '/');
        parts = mcPart.split('/');
        if (parts[0] == '' )             { parts = parts.slice(1, (parts.length)); }
        if (parts[parts.length-1] == '') { parts = parts.slice(0, (parts.length-1)); }
        if (parts.length == 0)           { parts = new Array('unknown', 'unknown'); }
        if (parts.length == 1)           { parts = new Array(parts[0],  'unknown'); }
        service = parts[0];
        parts = parts.slice(1,parts.length);
        parts[0] = service +'/'+ parts[0];
        if (parts.length > 4) parts = parts.slice(0,4);
        mcPart = parts.join('%40');
        return mcPart;
    }
}


function FormCounter(mcFrom, mcTo, formObj) {
    this.count(mcFrom, mcTo);
    window.setTimeout(function() { this.submit(); }.bind(formObj), 100);
    return false;
}
FormCounter.prototype = new IvwCounter();





var DOMParser; // To satisfy IE 5.0
String.prototype.toDom = function() {
    if (isSet(DOMParser)) {
        return (new DOMParser()).parseFromString(this.toString(), 'text/xml').firstChild;
    } else if (isSet(ActiveXObject)) {
        var domDoc = new ActiveXObject("Msxml2.DOMDocument");
        if(domDoc) {
            domDoc.async = false;
            domDoc.loadXML(this.toString());
            return domDoc.firstChild.nextSibling;
        }
    }
}


/* This section adds a toString()-method to DOM-Objects
*/
var Node; // To satisfy IE 5.0
if (UserAgent.knowsDom && UserAgent.isKhtml) { // To satisfy copulating Safari
    void(document.getElementsByTagName('html')[0].nodeName);
    if (UserAgent.isSafari.lt(3)) {
        void(document.createCDATASection('foo'));
    }
}
if (UserAgent.isGoogleChrome) {
    Element.prototype.toString = function() {
        var text = '<'+this.tagName; // '
        for (var i=0; i<this.attributes.length; i++) {
            var attr = this.attributes.item(i);
            if (!attr.specified) { continue; }
            text += ' '+attr.name+'="'+attr.value.encodeHtml()+'"';
        }
        text += '>'+this.getElementContents()+'</'+this.tagName+'>';
        return text;
    }
    Element.prototype.getElementContents = function() {
        var text = '';
        for (var i=0; i<this.childNodes.length; i++) {
            var child = this.childNodes.item(i);
            text += child.toString();
        }
        return text;
    }
    Text.prototype.toString = function() {
        return this.nodeValue.encodeHtml();
    }
    Comment.prototype.toString = function() {
        return '<!--'+this.nodeValue+'-->';
    }
}
if (isSet(window["[[DOMElement.prototype]]"])) { // To satisfy Safari
    Node             = function() {}
    var Element      = function() {}
    var HTMLElement  = function() {}
    var Text         = function() {}
    var Comment      = function() {}
    var CDATASection = function() {}
    Node.prototype         = window["[[DOMNode.prototype]]"];
    Element.prototype      = window["[[DOMElement.prototype]]"];
    HTMLElement.prototype  = window["[[DOMElement.prototype]]"];
    Text.prototype         = window["[[DOMNode.prototype]]"];
    Comment.prototype      = window["[[DOMText.prototype]]"];
    CDATASection.prototype = window["[[DOMText.prototype]]"];
}
if (isSet(Node)) {
    Node.prototype.toString = function() {
        return this.nodeValue;
    }
    Element.prototype.toString = function() {
        var text = '<'+this.tagName; // '
        for (var i=0; i<this.attributes.length; i++) {
            var attr = this.attributes.item(i);
            if (!attr.specified) { continue; }
            text += ' '+attr.name+'="'+attr.value.encodeHtml()+'"';
        }
        text += '>'+this.getElementContents()+'</'+this.tagName+'>';
        return text;
    }
    HTMLElement.prototype.toString = Element.prototype.toString;
    Element.prototype.getElementContents = function() {
        var text = '';
        for (var i=0; i<this.childNodes.length; i++) {
            var child = this.childNodes.item(i);
            text += child.toString();
        }
        return text;
    }
    Text.prototype.toString = function() {
        return this.nodeValue.encodeHtml();
    }
    Comment.prototype.toString = function() {
        return '<!--'+this.nodeValue+'-->';
    }
    CDATASection.prototype.toString = function() {
        return (this.nodeType==3) // Safari went on a safari and lost its way ...
               ? this.data.encodeHtml()
               : '<![CDATA['+this.nodeValue+']]>';
    }
    Node.prototype.getText = function() {
        if (this.nodeType == 3 || this.nodeType == 4) {
            return this.data;
        }
        var result = '';
        for (var i=0; i<this.childNodes.length; i++) {
            result += this.childNodes[i].getText();
        }
        return result;
    }
}




/*********************
*   Dynamic Loader   *
*********************/
if (UserAgent.knowsDom) {
    var _loadedJsResources = new Array();
    var _runOnAllLoaded    = new Array();
    function loadJs(uri) {
        if (   document.createElement
            && document.getElementsByTagName
            && document.getElementsByTagName('head')
            && document.getElementsByTagName('head')[0]
        ) {
            var js = document.createElement('script');
            js.setAttribute('type', 'text/javascript');
            js.setAttribute('src',  uri);
            var head = document.getElementsByTagName('head')[0];
            head.insertBefore(js, head.firstChild);
        }
    }
    function jsLoaded(name) {
        if (!isLoaded(name)) {
            _loadedJsResources.push(name);
        }
        //alert('Loaded: '+name);
        for (var i=0; i<_runOnAllLoaded.length; i++) {
            var item = _runOnAllLoaded[i];
            for (var j=0; j<item.length; j++) {
                if (isString(item[j]) && !isLoaded(item[j])) { break; }
                if (isFunction(item[j])) {
                    var temp = item[j];
                    _runOnAllLoaded[i] = new Array();
                    temp();
                }
            }
        }
    }
    function isLoaded(name) {
        return _loadedJsResources.hasValue(name);
    }
    function requires() {
        var allLoaded = true;
        for (var i=0; i<arguments.length; i++) {
            var item = arguments[i];
            if (isString(item)) {
                if (!isLoaded(item)) {
                    allLoaded = false;
                    loadJs(getAbsoluteUrl(item, baseScriptUri));
                }
            }
        }
        if (allLoaded) {
            arguments[arguments.length-1]();
        } else {
            _runOnAllLoaded.push(arguments);
            // Opera somehow is _too_ synchronous, so we enforce
            // a what-needs-to-be-executed-check:
            jsLoaded('_');
        }
    }
    var baseScriptUri = location.href;
    var scripts       = document.getElementsByTagName('script');
    var baseUrlTest   = new RegExp(/\/base.js(\?.+)?$/);
    for (var i=scripts.length-1; i>=0; i--) {
        if (baseUrlTest.test('/'+scripts[i].src)) {
            baseScriptUri = getAbsoluteUrl(scripts[i].src);
            if (baseScriptUri.indexOf('?') >= 0) {
                baseScriptUri = baseScriptUri.substr(0, baseScriptUri.indexOf('?'));
            }
            break;
        }
    }
    jsLoaded('base.js');
}

