function TV2_BrowserDetector() {
    this.name=navigator.appName+" "+navigator.appVersion;
    this.ver=navigator.appVersion.substring(0,1);
    this.ua=navigator.userAgent;
    this.isPhoe=(this.ua.indexOf('Phoenix')>-1);
    this.isNS=(!this.isPhoe&&(this.name.indexOf('Netscape')>-1));
    this.isNS4=!!document.layers;
    this.isGecko=(this.ua.indexOf('Gecko')>-1);
    this.isKHTML=(this.ua.indexOf('KHTML')>-1);
    this.isOpera=(this.ua.indexOf('Opera')>-1);
    this.isIE=(this.name.indexOf('MSIE')>-1 && !this.isOpera);
    this.IEVer=(this.isIE?parseFloat(this.ua.substr(this.ua.indexOf('MSIE')+5,3)):"na");
    this.isIE6=(this.isIE && this.IEVer>=6);
    if (this.isIE) this.ver=this.IEVer;
    this.isKonq=(this.ua.indexOf('Konqueror')>-1);    
    this.onWin=(this.ua.indexOf('Windows')>-1 ? true : (this.ua.indexOf('WinNT')>-1));
    this.onWinCE=(this.name.indexOf('Windows CE')>-1);
    this.onWinXP=(this.ua.indexOf('NT 5.1')>-1?true:(this.ua.indexOf('Windows XP')>-1));
    this.onMac=(this.name.indexOf('Mac')>-1);
    this.onLinux=(this.ua.indexOf('Linux')>-1);
    this.isIE6XP=(this.isIE6 && this.onWinXP);
    this.isSP2=(this.onWinXP && this.ua.indexOf('SV1')>-1);
    this.srSize=window.screen;
    if ((typeof(this.srSize)!="undefined")&&(this.srSize!=null)) {
        this.srW=this.srSize.width; 
        this.srH=this.srSize.height;
        this.srCD=this.srSize.colorDepth;
        if (this.isNS&&(this.ver>=4)) this.srCD=this.srSize.pixelDepth;
    } else {
        this.srW=this.srH=this.srCD="na";
    }   
    this.compat=document.compatMode=="CSS1Compat";
    this.dom=!!document.getElementById;
    this.java=navigator.javaEnabled();
    this.cookie=(!this.isPhoe&&(typeof(navigator.cookieEnabled)!='undefined'))?navigator.cookieEnabled:"na";
    var d=new Date();
    this.timezone=d.getTimezoneOffset()/-60;
    this.lang=(((this.isNS&&this.ver>=4)||this.isOpera)?navigator.language:((this.isIE&&this.ver>=4)?navigator.userLanguage:"na"));
    this.refURL=escape(document.referrer);
    this.refURL=(this.refURL.length>=252?this.refURL.substring(0,252)+"...":this.refURL);
    this.conn=this.home="na";
    this.getConn=BrowserDetector_getConn;
    this.isHome=BrowserDetector_isHome;
}
function BrowserDetector_getConn() {
    if (typeof(document.body)!="undefined") {
        if (this.isIE&&this.ver>=5&&!this.onMac&&!this.isOpera) {
            document.body.addBehavior("#default#clientCaps");
            this.conn=document.body.connectionType;
        }
    }
    return this.conn;
}
function BrowserDetector_isHome() {
    if (typeof(document.body)!="undefined") {
        if (this.isIE&&this.ver>=5&&!this.onMac&&!this.isOpera) {
            document.body.addBehavior("#default#homePage");
            this.home=document.body.isHomePage(location.href);
        }
    }
    return this.home;
}

var fd_reqVer = 8;
if (typeof(reqFlashVer)=="number") fd_reqVer = reqFlashVer;
var fd_minVer = 5;
var fd_maxVer = 9;
for (var i = fd_minVer; i<=fd_maxVer; i++) eval('var fd_flash' + i + 'Installed = false;');
var fd_ver = 0;
var fd_ok = false;
var fd_isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var fd_isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;
if (fd_isIE && fd_isWin) {
    for (var i = fd_maxVer; i>=fd_minVer; i--) {
        document.write('<SCR' + 'IPT LANGUAGE="VBScript"\> \n');
        document.write('on error resume next \n');
        document.write('fd_flash' + i + 'Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.' + i + '"))) \n');
        document.write('</SCR' + 'IPT\> \n');
        if (eval('fd_flash' + i + 'Installed')) i = 0;
    }
}
function fd_detect() {
    if (navigator.plugins) {
        if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
            var fd_ver2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
            var fd_desc = navigator.plugins["Shockwave Flash" + fd_ver2].description;
            var fd_verNum = parseInt(fd_desc.charAt(fd_desc.indexOf(".")-1));
            for (var i = fd_minVer; i<=fd_maxVer; i++) eval('fd_flash' + i + 'Installed = (fd_verNum==i);');
            eval('fd_flash' + fd_maxVer + 'Installed = (fd_verNum >= fd_maxVer);');
        }
    }
    for (var i = fd_minVer; i<=fd_maxVer; i++) if (eval('fd_flash' + i + 'Installed==true')) fd_ver = i;
    if (navigator.userAgent.indexOf("WebTV") != -1) fd_ver = 3;
    if (fd_ver >= fd_reqVer) fd_ok = true;
}

Smart_ObjectLoader = {
    print  : function(html) {
        document.write(html);
    }
}
function getCookie(name) {
    var index = document.cookie.indexOf(name + "=");
    if (index == -1) return null;
    index += name.length + 1;
    var endval = document.cookie.indexOf(";", index);
    if (endval == -1) return unescape(document.cookie.substring(index))
    else return unescape(document.cookie.substring(index, endval));
}
function getCookieExpire(duration){
    var expireDay = new Date();
    expireDay.setTime(expireDay.valueOf()+duration*24*60*60*1000);
    return expireDay.toUTCString();
}
function setCookie(name,value,duration,domain,path){
    if (typeof(domain)=='undefined') domain = '.tv2.dk';
    if (typeof(path)=='undefined') path = '/';
    var cookiestr = name+'='+escape(value)+';';
    if (duration!=null) cookiestr += 'expires='+getCookieExpire(duration)+';';
    cookiestr += 'path='+path+';domain='+domain+';';
    document.cookie = cookiestr;
}

fd_detect();
var browser=new TV2_BrowserDetector();
var thisURL=location.href;
var thisURLesc=escape(thisURL);
if (!browser.onMac && !browser.compat) {
        if (browser.isIE && browser.IEVer<6) {
        document.write('<link rel="stylesheet" type="text/css" media="screen" href="http://common.tv2.dk/css/fix.ie5.css" />');
    }
}
if (window.OAS_listpos) {
if (!document.getElementById&&document.all) document.getElementById=function(id) { return document.all[id]; }
function OAS_listpos_remove(pos) {
  posarray = OAS_listpos.split(',');
  listpos = '';
  found = false;
  for(i=0; i<posarray.length; i++) if(posarray[i]!=pos) listpos += ',' + posarray[i]; else found = true;
  OAS_listpos = listpos.substring(1);
  return found;
}
function OAS_listpos_add(pos) {
  if(OAS_listpos.length>0) OAS_listpos += ",";
  OAS_listpos += pos;
}
OAS_url='http://banner.webdmz.tv2.dk/RealMedia/ads/';
OAS_testsite = location.href.indexOf('.test3.') != -1;
if(!window.OAS_sitepage) OAS_sitepage = (OAS_testsite)?'bannertest.tv2.dk/':(window.location.hostname + window.location.pathname)
if (!window.OAS_query) OAS_query='';
if (!window.OAS_target) OAS_target='_blank';
OAS_rand = new String(Math.random()).substring(2,11);
// Følgende bruges på *.test.tv2.dk til at teste for om alle positionerne bliver trukket
OAS_posarray = OAS_listpos.split(",");
if(OAS_testsite) setTimeout('OAS_Test()', 7000)
//OAS-stunt nu vil alle sider ligge i directory /oas/
OAS_sitepage = OAS_sitepage.replace(/\//, "/oas/");
// strip out -dyn / -static
var r = /^([^.]+)-(dyn|static)(\.[^\/]*tv2.dk\/.*)$/.exec(OAS_sitepage);
if (r) OAS_sitepage = r[1]+r[3];
// strip www.
var r = /^www\.(.*)$/.exec(OAS_sitepage);
if (r) OAS_sitepage = r[1];
document.write('<'+'script type="text/javascript" src="'+OAS_url+'adstream_mjx.ads/'+OAS_sitepage+'/1'+OAS_rand+'@'+OAS_listpos+'?'+OAS_query+'"><\/'+'script>');
function OAS_Test() {
    if(window.OAS_posarray) {
        pos = ''
        for(i=0; i<OAS_posarray.length; i++)
            if(OAS_posarray[i] != '') pos += "," + OAS_posarray[i]
        if(pos != '')
            alert('BANNERFEJL:\nOAS_listpos indeholder positioner som ikke er blevet hentet. Da der tælles eksponeringer for alle de positioner som er indeholdt i OAS_listpos er det vigtigt at de vises!\n\nFølgende positioner er hentet: ['+OAS_listpos+']\nFølgende positioner er ikke vist: ['+pos.substr(1)+']')
        else if(!OAS_testsite)
            alert('Bannerne på denne side bliver kaldt korrekt')
    }
}
function OAS_AdText() {
    window.document.write('<div class="tv2adtext">Annoncer:<div class="hr"></div></div>');
}
function OAS_InternAdText() {
    window.document.write('<div class="tv2adtext">TV 2 tjenester:<div class="hr"></div></div>');
}
function OAS_CheckPos(pos) {
    if(window.OAS_posarray) 
        for(i=0; i<OAS_posarray.length; i++) if (OAS_posarray[i] == pos && OAS_posarray[i] != '') return true;
    return false;
}
function OAS_AD(pos) {
    if(window.OAS_posarray)
        for(i=0; i<OAS_posarray.length; i++) if(OAS_posarray[i]==pos) OAS_posarray[i] = '';
    if (window.OAS_RICH) OAS_RICH(pos); else {}
}
function OAS_Link(track, url) {
    if(!window.track) return url;
    track = OAS_url + 'click_lx.ads/' + track;
    qmark = url.indexOf('?');
    if(qmark != -1) {
        query = url.substring(qmark);
        url = url.substring(7, qmark );
    }
    return track + ((window.query)?query:'') + ((url.length>0)?((window.query)?'&':'?')+'_RM_REDIR_='+url:'') + ((window.query)?'?__QUERY__':'');
}
function OAS_Submit(track, form) {
    var url = form.action;
    url += (url.indexOf('?') == -1) ? '?' : '&';
    for (var i = 0; i < form.elements.length; i++) {
        var v = null;
        var e = form.elements[i];
        if (e.type == 'checkbox' || e.type == 'radio') {
            if (e.checked) {
                v = e.value;
            }
        } else if (e.type == 'select-one') {
            if (e.selectedIndex != -1 && e.options[e.selectedIndex]) {
                v = e.options[e.selectedIndex].value;
            }
        } else {
            v = e.value;
        }
        if (typeof v != 'object' && e.name && !e.disabled) {
            url += e.name + '=' + escape(v) + '&';
        }
    }
    url = url.substr(0, url.length - 1);
    window.open(OAS_Link(track, url), form.target ? form.target : OAS_target);
    return false;
}
}

var tv2navigation=new function() {
    this.channels=this.bottomElements=this.portals=this.breadcrumb=this.section=new Array();
    this.curUrl=document.location.href;
    this.channelUrl='http://tv2.dk/';
    this.tabs=false;
    this.emptyBanner='http://banner.webdmz.tv2.dk/RealMedia/ads/Creatives/default/empty.gif';
    this.writeTopBegin=function(channel, channelUrl) {
        this.channelUrl=channelUrl;
        html='<div id="tv2'+channel+'"><div id="tv2top"><ul class="tv2channel"><li class="tv2logo"><a href="http://tv2.dk/?top"><span class="tv2alt">TV&nbsp;2</span></a></li>';
        for (var i=0;i<this.channels.length;i+=3) {
            html+='<li class="tv2'+this.channels[i]+'"><a href="'+this.channels[i+1].formatStatstag('channel')+'"><span class="tv2alt">'+this.channels[i+2]+'</span></a></li>';
        }
        html+='<li class="tv2search"><form action="http://google.tv2.dk/soeg.php" method="get" target="_top" name="tv2search"><input type="hidden" name="omraade" value="tv2.dk" /><table border="0" cellspacing="0" cellpadding="0"><tr><td><input type="text" name="q" size="11" class="tv2query" /></td><td width="5">&nbsp;</td><td><input type="submit" value="S&oslash;g" class="tv2submit" /></td></tr></table></form></li></ul>';
        document.write(html);
    }
    this.writeTopEnd=function() { document.write('</div>'); }
    this.writeBottom=function() { 
        this.renderBreadcrumb(this.breadcrumb);
        this.renderSection(this.section);
        if (this.tabs) this.tabs=new TV2_Tabs();
        var html='<div id="tv2bottom"><ul>';
        for (var i=0;i<this.bottomElements.length;i+=2) {
            html+='<li><a href="'+this.bottomElements[i].formatStatstag('bottom')+'"><span class="tv2alt">'+this.bottomElements[i+1]+'</span></a></li>';
        }
        html+='<li class="tv2valus"><a href="http://www.valus.dk/" target="_blank"><span class="tv2alt">Valus</span></a></li></ul></div></div>';
        html+='<div id="tv2bottombg"></div>';
        document.write(html);
    }
    this.writePortal=function(portal, selectedPortal) {
        if (selectedPortal=='') selectedPortal=this.curUrl;
        var bestMatch=0;
        var selectedItem='';
        for (var i=0;i<portal.length;i+=2) {
            if ((portal[i].length>=bestMatch) && (selectedPortal.indexOf(portal[i])!=-1)) {
                bestMatch=portal[i].length;
                selectedItem=portal[i];
            }
        }
        var html='<ul class="tv2portal"><li class="tv2first"><a href="'+this.channelUrl.formatStatstag('portal')+'"><span class="tv2alt">Forsiden</span></a></li>';
        for (var i=0;i<portal.length;i+=2) {
            if (portal[i]) {
                var classstr='p'+(i/2);
                if (portal[i]==selectedItem) classstr+=' tv2selected';
                html+='<li><a href="'+portal[i].formatStatstag('portal')+'" class="'+classstr+'"><span class="tv2alt">'+portal[i+1]+'</span></a></li>';
            }
        }
        html+='</ul>';
        document.write(html);
    }
    this.writeBreadcrumbBox=function() { document.write('<div id="tv2breadcrumbbox"><ul class="tv2breadcrumb" id="tv2crumbs"></ul><ul class="tv2section" id="tv2sections"></ul></div>'); }
    this.renderSection=function(section) {
        var contentObj=this.$('tv2sections');
        if (section.length>0 && section[0]!='' && contentObj) {
            var items=new Array();
            for (var i=0;i<section.length;i+=2) items[items.length]='<li><a href="'+section[i].formatStatstag('section')+'">'+section[i+1]+'</a></li>';
            contentObj.innerHTML+=items.join('<li>|</li>')+'<li class="tv2first">Aktuelt:</li>'; 
        }
    }
    this.addToBreadcrumb=function(crumb) { 
        if (crumb[0].charAt(0)=='/') this.breadcrumb=this.breadcrumb.concat(new Array(document.location.hostname+crumb[0],crumb[1]));
        else this.breadcrumb=this.breadcrumb.concat(crumb); 
    }
    this.renderBreadcrumb=function(crumbs) {
        crumbs=new Array(this.channelUrl,this.channelUrl.substring(0,this.channelUrl.indexOf('.dk')+3)).concat(crumbs);
        var contentObj=this.$('tv2crumbs');
        if (contentObj) {
            var items=new Array();
            for (var i=0;i<crumbs.length;i+=2) items=items.concat('<li><a href="'+crumbs[i].formatStatstag('breadcrumb')+'">'+crumbs[i+1]+'</a></li>');
            contentObj.innerHTML+='<li class="tv2first">Her er du:</li>'+items.join('<li>&#187;</li>'); 
        }
    }
    this.writeCrossPromo=function() {
        document.writeln('<h1 class="tv2header">Se&nbsp;ogs&aring;</h1>');
if(window.OAS_AD) {
if (OAS_CheckPos('cross1')) OAS_AD('cross1');
if (OAS_CheckPos('cross2')) OAS_AD('cross2');
}
document.writeln('<scr'+'ipt type="text/javascript" src="http://common.tv2.dk/js/contentbox.js"></scr'+'ipt>');
    }
    this.writeLeaderBoard=function() { this.writeBanner('Leaderboard', false); }
    this.writeContentSquare=function() { this.writeBanner('Rektangel_Forsid', false); }
    this.writeBanner=function(pos, id) { if(window.OAS_AD && OAS_CheckPos(pos)) OAS_AD(pos); if(id) this.hideBanner(id); }
    this.hideBanner=function(id) { 
        var bannerObj=this.$(id);
        if (bannerObj && bannerObj.childNodes[1] && bannerObj.childNodes[1].innerHTML.indexOf(this.emptyBanner)!=-1) bannerObj.style.display='none';
    }
    String.prototype.formatStatstag=function(tag) {
        if (this.indexOf('javascript:')==-1) {
            var url=(this.indexOf('://')!=-1)?this.substring(this.indexOf('://')+3):this;
            var exclude=new Array('folkeborsen.tv2.dk');
            for (var i=0;i<exclude.length;i++) if (url.indexOf(exclude[i])!=-1) return ('http://'+url);
            return ('http://'+url+((url.indexOf('?')!=-1)? '&amp;' : '?')+tag);
        }
        return this;
    }
    this.$=function(id) {
        if (document.getElementById) return document.getElementById(id);
        else if (document.all) return document.all[id];
        else return false;
    }
}

function TV2_Tabs() {
    var tabContainers = document.getElementsByTagName('UL');
    for (var i=0; i<tabContainers.length; i++) { 
        if (tabContainers[i].className=='tv2tabs') { 
            var tab = tabContainers[i];
            var links=tab.getElementsByTagName('A');
            for (var j=0;j<links.length;j++) {
                if (links[j].className=='selected') {
                    var content = document.getElementById(links[j].hash.substring(1));
                    content.style.display='block';
                }
                links[j].onclick=function() {
                    this.blur();
                    var alltabs=this.parentNode.parentNode.getElementsByTagName('LI');
                    for (var k=0;k<alltabs.length;k++) {
                        var link = alltabs[k].getElementsByTagName('A').item(0);
                        if (link.hash!=this.hash) {
                            var content = document.getElementById(link.hash.substring(1));
                            content.style.display='none';
                            alltabs[k].className = '';
                        } else {
                            alltabs[k].className = link.className = 'selected';
                        }
                    }
                    var content = document.getElementById(this.hash.substring(1));
                    if (content.style.display!='block') content.style.display='block';
                    return false; 
                }
            }
        }
    }
    this.changeTab=function(container, tab) {
        var container=document.getElementById(container);
        var tabContainers = container.getElementsByTagName('UL');
        for(var i = 0; i < tabContainers.length; i++){
            if(tabContainers[i].className == 'tv2tabs'){
                var tabs = container.getElementsByTagName('LI');
                for(var x = 0; x < tabs.length; x++){
                    var a = tabs[x].getElementsByTagName('A');
                    if(a[0].innerHTML == tab){
                        tabs[x].className = 'selected';
                        a[0].className = 'selected';
                        var content = document.getElementById(a[0].hash.substring(1));
                        content.style.display='block';
                    }else{
                        tabs[x].className = '';
                        a[0].className = '';
                        var content = document.getElementById(a[0].hash.substring(1));
                        content.style.display='none';
                    }
                }
            }
            break;
        }
        return;
    }
}

function TV2_Sputnik_open(url) {
    if (typeof(url)=='undefined') url = 'http://tv.sputnik.dk/';
    var w=window.screen.width;
    var h=window.screen.height;
    var param = 'height='+h+', width='+w+', location=no, menubar=no, resizable=no, titlebar=yes, toolbar=no, status=yes, directories=no, channelmode=no, scrollbars=no';
    if (browser.isIE && (window.navigator.userAgent.indexOf('SV1') == -1)) param += ', left=0, top=0'; // normal ie's must use left=0, top=0
    window.open(url, 'SputnikWindow', param).focus();
}

function TV2_Galleri_open(url) {
    if (typeof(url)=='undefined') url = 'http://galleri.tv2.dk/';
    var w=855; var h=700;
    var l=Math.floor(window.screen.width/2 - w/2);
    var t=Math.floor(window.screen.height/2 - h/2);
    var param = 'height='+h+', width='+w+', top='+t+', left='+l+', location=no, menubar=no, resizable=no, titlebar=yes, toolbar=no, status=no, directories=no, channelmode=no, scrollbars=no';
    window.open(url, 'GalleriWindow', param).focus();
}
function tv2_vipchat_popup() {
    var w=700; var h=550;
    var l=Math.floor(window.screen.width/2 - w/2);
    var t=Math.floor(window.screen.height/2 - h/2);
    window.open("http://irc.tv2.dk/livechat/index.php","tv2vipchat","resizable=no,toolbar=no,scrollbars=no,menubar=no,status=yes,directories=no,width="+w+",height="+h+",left="+l+",top="+t).focus();
}
function TV2_Konsol_Open() { TV2_Sputnik_open(); }
function TV2_Konsol_PlayClip(clipNodeId, channelNodeId) { TV2_Konsol_Open(); }
function TV2_Konsol_OpenChannel(channelNodeId) { TV2_Konsol_Open(); }
function TV2_Konsol_PlayLive() {
    if (typeof(browser)=="undefined" || browser.isIE) TV2_Konsol_Open();
    else document.location.href = 'http://video.tv2.dk/files/wmv/tv2live.asx';
}
var OAS_kagenavn = '';
function OAS_getCookie() {}
function OAS_setCookie() {}
function OAS_annoy() {}
function OAS_annoyed() {}
var OAS_timeout_sky = null;
var OAS_timeout_steps = 0;
var OAS_timeout_offset = 0;
function OAS_updateSkyskaber() {}
function OAS_delayedSkyUpdate() {}
function OAS_initSkyskaber() {}


