/* DON'T EDIT THIS GENERATED FILE! Changes will be lost. */

AdvConfig.ivwUrl = '//img.web.de/ivw/${type}/webde/homepage/${path}?ts=${now}';
function qs(el) {
    if (!UserAgent.knowsDom) { return true; }
    if (isSet(RegExp)) {
        var mc = 'hp@suche.suche@home';
        if (el.href.match(/[?&]mc=([^&]*)/)) {
            mc = RegExp.$1;
            el.href = el.href.replace(/[?&]mc=([^&]*)/, '');
        }
        var query = encodeURIComponent(document.forms['formSearch'].elements['su'].value);
        if (el.href.match(/[?&]su=/)) {
            el.href = el.href.replace(new RegExp(/su=[^&]*/), 'su='+query+'&mc='+mc);
        } else {
            el.href += ((el.href.indexOf('?') == -1) ? '?' : '&') + 'su='+query+'&mc='+mc;
        }
    }
    var items = el.parentNode.parentNode.getElementsByTagName('li');
    for (var i=0; i<items.length; i++) {
        if (items[i].getElementsByTagName('a')[0]==el) {
            items[i].className += ' active';
        } else {
            items[i].className = items[i].className.replace(/\bactive\b/g, '');
        }
    }
    return false;
}


function setAdvActive(advId) {
    if (!UserAgent.knowsDom) { return false; }
    var el = document.getElementById(advId);
    if (isNone(el)) { return; }
    if (el.getElementsByTagName('div').length == 0) { return false; }
    el.className = el.className.replace(/\bdynamicLoad\b/, '');
}


function addNgUserId() {
    if (isSet(window['UI_nguserid'])) {
        var formIds = ['formLogin', 'formClubLogin'];
        for (var i=0; i<formIds.length; i++) {
            var form = document.getElementById(formIds[i]);
            if (isNone(form)) { continue; }
            if (isNone(form.uinguserid)) {
                var input = UserAgent.isIe
                          ? document.createElement('<input name="uinguserid" type="hidden"/>')
                          : newElement('input', {'name':'uinguserid', 'type':'hidden'});
                form.appendChild(input);
            }
            form.uinguserid.value = UI_nguserid;
        }
    } else {
        window.setTimeout(addNgUserId, 1000);
    }
}

function homepageInit() {
	initSearchBox();
    var c = document.getElementById('contentBoxClub');
    if (isSet(c)) {
        c.className += ' complete';
    }
    var stat = Params.get('status');
    var activate = null;
    if (stat == 'login' && Params.get('mc') == 'freemail@msg@notallowed.hp@home@hinweis') {
        stat = 'session-expired';
    }
    if (isSet(stat)) {
        var msgBox = document.getElementById('msgBox');
        if (isSet(msgBox)) {
            var boxes = getElementsByClassName('modulePart', msgBox, 'div');
            for (var i=0; i<boxes.length; i++) {
                if (!boxes[i].className.split(' ').hasValue('status-'+stat)) { continue; }
                msgBox.style.display = 'block';
                boxes[i].className += ' active';
            }
            if (isSet(document.getElementById('cybercreative'))) {
                var css = newElement('style', {'type': 'text/css'});
                document.getElementsByTagName('head')[0].appendChild(css);
                var lastSheet = document.styleSheets[document.styleSheets.length-1];
                var offset    = msgBox.offsetHeight + 20;
                var cssRules  = [
                    'body, #allServicesLayer, #advCyberCreative .advCyberPart, #advCyberCreativeFullLayer { margin-top: '+offset+'px !important; }',
                    '#navPortal { margin-top: '+(offset+parseInt(getStyle(document.getElementById('navPortal'), 'margin-top')))+'px !important; }',
                ];
                for (var i=0; i<cssRules.length; i++) {
                    var cssRule = cssRules[i];
                    if (isSet(lastSheet.insertRule)) {
                        lastSheet.insertRule(cssRule, lastSheet.cssRules.length);
                    } else {
                        lastSheet.cssText += cssRule;
                    }
                }
            }
        }
    }
    if (stat == 'login-failed') {
        activate = document.getElementById('contentNavFreemail');
        document.body.className += ' loginFailedMessage';
    }
    if (stat == 'session-expired') {
        activate = document.getElementById('contentNavFreemail');
    }
    if (isSet(activate) && isSet(activate.onclick)) {
        activate.ivwCount = false;
        activate.onclick();
    }
    if (UserAgent.knowsDom) {
        window.addOnload(function() {
            var js = document.createElement('script');
            js.setAttribute('type', 'text/javascript');
            js.setAttribute('src',  '//fips.uimserv.net/ngvar.js');
            var head = document.getElementsByTagName('head')[0];
            head.insertBefore(js, head.firstChild);
            window.setTimeout(addNgUserId, 100);
        });
    }
    var visits = Cookies.increase('visits', 0, '1y');
    return;
}

function homepageDidLogin() {
    var logins = Cookies.increase('logins', 0, '1y');
}



MoveinData = function() {
    this.viewed = 0;
    this.closed = false;
    this.latest = null;
    this.pickle = function() { return this._pickle('MoveinData'); }
}
function homepageMoveinClose() {
    var data = Cookies.unpickle('moveinBrowser');
    if (isNone(data)) { return; }
    data.closed = true;
    Cookies.set('moveinBrowser', data, '3m');
}
function homepageMoveinAllowed() {
    if (!UserAgent.knowsAjax || !UserAgent.isWin || UserAgent.isIe.gte(8) || UserAgent.isFirefox.gte(3.5)) { return false; }
    if (UserAgent.isSafari)                                                                              { return false; }
    //if (isSet(document.getElementById('buster')))                                                        { return false; }
    if (isSet(document.getElementById('sitebar')))                                                       { return false; }
    if (isSet(document.getElementById('cybercreative')))                                                 { return false; }
    if (isSet(window.advNoTopper) && isTrue(window.advNoTopper))                                         { return false; }
    var now  = new Date();
    var date = now.getFullYear()+'.'+('0'+(now.getMonth()+1)).substr(('0'+(now.getMonth()+1)).length-2)+'.'+('0'+now.getDate()).substr(('0'+now.getDate()).length-2);
    if (date>='2007.05.01' && date<='2007.05.07') { return false; }
    if (date>='2007.05.28' && date<='2007.06.04') { return false; }
    return true;
}

function homepageMovein() {
    if (!homepageMoveinAllowed()) { return; }
    var data = Cookies.unpickle('moveinBrowser');
    if (isSet(data)) {
        if (data.override)       { return; }
    } else {
        data = new MoveinData();
    }
    var body = document.getElementsByTagName('body')[0];
    var el   = newElement('div', {'id':'advMovein'});
    var ua   = (UserAgent.isIe && (UserAgent.isWin['xp-sp2']||UserAgent.isWin['vista']||UserAgent.isIe[7]) && !UserAgent.isIe[8]) ? 'IE' : 'Firefox';
    var uri  = (ua == 'IE') ? '/movein_ie.htm' : '/movein_ff.htm';
    var obj  = new LayerAjaxObject(el, uri, new HtmlRenderer({'postRendering':new Array(createCloseButton)}), new HtmlOutput(), new MoveinEffect(el, {'nextObjId':'container', 'checkBuster':true, 'steps':UserAgent.isGecko||UserAgent.isOpera?8:15, 'timeout':0}), {'module':'advTopper', 'closerId':'advMoveinClose', 'postClose': homepageMoveinClose, 'loadingMessage':''});
    body.insertBefore(el, body.firstChild);
    obj.register(el);
    el.getText = (ua == 'IE')
               ? function() { return 'browser/ie'; }
               : function() { return 'browser/mff'; }
    data.latest = new Date();
    data.viewed++;
    Cookies.set('moveinBrowser', data, '3m');
    obj.activate();
}

window.addOnload(homepageMovein);

function activateIframe(obj) {
    var content = getCorrespondingContent(obj);
    var undduIframe = content.getElementsByTagName('iframe')[0];
    if (undduIframe.title) {
        undduIframe.src   = undduIframe.title;
        undduIframe.title = '';
    }
}

popit_checkUrl = function(url) {
    var isFreeMailer = function() {
        return popit.getNgCount('frm') && !popit.getNgCount('clbmem');
    }
    var usesTabbedBrowsing = function() {
        return popit.getNgCount('tabber');
    }
    if (usesTabbedBrowsing()) { return false; }
    if (url == null)          { return true; }
    if (['games.web.de', 'handyshop.web.de', 'kino.web.de', 'kleinanzeigen.web.de', 'magazine.web.de', 'musik.web.de', 'r.web.de', 'route.web.de', 'tv.web.de', 'web.de', 'wetter.web.de', 'www.web.de'].hasValue(url.host)) { return true; }
    if (url.host == 'login.web.de') { return isFreeMailer(); }
    return false;
}

function getTab(pos) {
    var spotlighttabs = document.getElementById('moduleSpotlight').getElementsByTagName('ol')[0].getElementsByTagName('li');
    if (typeof(pos) == 'number') {
        return spotlighttabs[pos-1];
    } else if (typeof(pos) == 'string') {
        if (pos == 'last') {
            return spotlighttabs[spotlighttabs.length-1];
        } else {
            for (var t=0; t<spotlighttabs.length; t++) {
                if (spotlighttabs[t].innerHTML.replace(/\<[^\>]*\>/g,'') == pos) {
                    return spotlighttabs[t];
                }
            }
        }
    }
    return pos;
}

function getContent(pos) {
    var spotlightcontentchilds = document.getElementById('moduleSpotlight').getElementsByTagName('ol')[1].childNodes;
    var spotlightcontent = [];
    for (var c=0; c<spotlightcontentchilds.length; c++) {
        if (spotlightcontentchilds[c].nodeName && spotlightcontentchilds[c].nodeName.toLowerCase() == 'li') {
            spotlightcontent.push(spotlightcontentchilds[c]);
        }
    }
    if (typeof(pos) == 'number') {
        return spotlightcontent[pos-1];
    } else if (typeof(pos) == 'string') {
        if (pos == 'last') {
            return spotlightcontent[spotlightcontent.length-1];
        } else {
            return getCorrespondingLi(getTab(pos));
        }
    }
}

function replaceTab(newtab, newcontent, oldtab, oldcontent) {
    var spotlight = document.getElementById('moduleSpotlight');
    var spotlighttabs = spotlight.getElementsByTagName('ol')[0];
    var spotlightcontent = spotlight.getElementsByTagName('ol')[1];
    spotlightcontent.replaceChild(newcontent, oldcontent);
    spotlighttabs.replaceChild(newtab, oldtab);
}

function insertTab(newtab, newcontent, pos) {
    var spotlight = document.getElementById('moduleSpotlight');
    var spotlighttabs = spotlight.getElementsByTagName('ol')[0];
    var spotlightcontent = spotlight.getElementsByTagName('ol')[1];
    spotlightcontent.insertBefore(newcontent, getContent(pos));
    spotlighttabs.insertBefore(newtab, getTab(pos));
}

function addSpotlightErotic(data) {
    var newsflash=document.getElementById('moduleSpotlight').getElementsByTagName('ol')[1].getElementsByTagName('li')[0].getElementsByTagName('div')[0];
    var mittagspause = newsflash;
    while (mittagspause = mittagspause.nextSibling) { if (mittagspause.className == 'moduleFooter') {
        mittagspause.style.display = 'none'; mittagspause = false; }
    }
    newsflash.innerHTML += data.teaserline;
    var erotiktab = document.createElement('li');
    var erotikcontent = document.createElement('li');
    if (data.slot) {
        replaceTab(getTab(data.slot), getCorrespondingLi(getTab(data.slot)), getTab('last'), getCorrespondingLi(getTab('last')));
        insertTab(erotiktab, erotikcontent, data.slot);
    } else {
        replaceTab(erotiktab, erotikcontent, getTab('last'), getCorrespondingLi(getTab('last')));
    }
    erotiktab.className = 'erotikFlash';
    erotiktab.innerHTML = '<a href="http://magazine.web.de/de/themen/lifestyle/erotik/index.html"><span>Erotik</span></a>';
    erotikcontent.className = 'teaser erotikFlash';
    setAjaxFunc = function (tab) { return function() {
        var ajaxFunc = new DynAjaxObject(tab, data.contentURL, new HtmlRenderer(), new HtmlOutput(), null, {'module ':'teaser erotikFlash', 'approxHeight':data.contentHeight, 'nedstat':'homepage.startseite.link.content.erotik.reiter'});
        ajaxFunc.register(tab);
    }}(erotiktab);
    ajaxInt = window.setInterval(function() {
        if (window.DynAjaxObject) {
            setAjaxFunc();
            window.clearInterval(ajaxInt);
        }
    }, 245);
}

function spotlightErotic(data) {
    if (window.activateSpotlight && activateSpotlight.stopped !== true) {
        var oldFunc = activateSpotlight.stopLoading;
        activateSpotlight.stopLoading = function() {
            oldFunc();
            addSpotlightErotic(data);
        }
    } else {
        addSpotlightErotic(data);
    }
}

function initSearchBox() {
	var text = document.getElementById('inpSearchText');
	text.className = text.className.replace(/\bempty\b/g, '') + (text.value == '' ? ' empty' : '');
	window.setTimeout(function() {
		var text = document.getElementById('inpSearchText');
		text.className = text.className.replace(/\bempty\b/g, '') + (text.value == '' ? ' empty' : '');
	}, 1000);
}

