/* Modernizr 2.0.6 (Custom Build) | MIT & BSD
* Contains: video | touch | teststyles | prefixes
*/
;window.Modernizr=function(a,b,c){function y(a,b){return!!~(""+a).indexOf(b)}function x(a,b){return typeof a===b}function w(a,b){return v(m.join(a+";")+(b||""))}function v(a){j.cssText=a}var d="2.0.6",e={},f=b.documentElement,g=b.head||b.getElementsByTagName("head")[0],h="modernizr",i=b.createElement(h),j=i.style,k,l=Object.prototype.toString,m=" -webkit- -moz- -o- -ms- -khtml- ".split(" "),n={},o={},p={},q=[],r=function(a,c,d,e){var g,i,j,k=b.createElement("div");if(parseInt(d,10))while(d--)j=b.createElement("div"),j.id=e?e[d]:h+(d+1),k.appendChild(j);g=["&shy;","<style>",a,"</style>"].join(""),k.id=h,k.innerHTML+=g,f.appendChild(k),i=c(k,a),k.parentNode.removeChild(k);return!!i},s,t={}.hasOwnProperty,u;!x(t,c)&&!x(t.call,c)?u=function(a,b){return t.call(a,b)}:u=function(a,b){return b in a&&x(a.constructor.prototype[b],c)};var z=function(c,d){var f=c.join(""),g=d.length;r(f,function(c,d){var f=b.styleSheets[b.styleSheets.length-1],h=f.cssRules&&f.cssRules[0]?f.cssRules[0].cssText:f.cssText||"",i=c.childNodes,j={};while(g--)j[i[g].id]=i[g];e.touch="ontouchstart"in a||j.touch.offsetTop===9},g,d)}([,["@media (",m.join("touch-enabled),("),h,")","{#touch{top:9px;position:absolute}}"].join("")],[,"touch"]);n.touch=function(){return e.touch},n.video=function(){var a=b.createElement("video"),c=!1;try{if(c=!!a.canPlayType){c=new Boolean(c),c.ogg=a.canPlayType('video/ogg; codecs="theora"');var d='video/mp4; codecs="avc1.42E01E';c.h264=a.canPlayType(d+'"')||a.canPlayType(d+', mp4a.40.2"'),c.webm=a.canPlayType('video/webm; codecs="vp8, vorbis"')}}catch(e){}return c};for(var A in n)u(n,A)&&(s=A.toLowerCase(),e[s]=n[A](),q.push((e[s]?"":"no-")+s));v(""),i=k=null,e._version=d,e._prefixes=m,e.testStyles=r;return e}(this,this.document);
var PolStartTime=new Date();
// add class to html if touch device
if (Modernizr.touch) {
$p('html').addClass('touch');
}
if (!(Modernizr.touch)) {
/**
* Centering of site
*/
var windowCenter = {
contentWidth:960,
running:true,
leftBannerWidth:0,
rightBannerWidth:0,
currwidth:0,
isTopMonsterPositioned:false,
init : function() {
var self = this;
self.docenter();
$p(window).resize(function(){
if(windowCenter.currwidth != $p(window).width()){
windowCenter.log("resizing");
windowCenter.centerAll(true);
windowCenter.currwidth = $p(window).width();
}
});
},
adjustSkybanner : function(){
this.log("adjust skybanner");
if($p("#rightBanner").length > 0 && $p("#skyRightBanner").length > 0){
var rightbannerOffsetLeft = $p("#rightBanner").offset().left;
$p("#skyRightBanner").css("left",rightbannerOffsetLeft);
}
},
docenter : function() {
this.log("centeringFull");
shift = ($p(window).width() - this.contentWidth) / 2;
windowCenter.fullOffset = this.contentWidth + Math.ceil(Math.abs(shift));
this.log("offset" + this.fullOffset);
if($p("#top-monster").length >0){
windowCenter.positionTopMonster();
}
if (($p("#leftBanner").length == 0) && ($p("#rightBanner").length == 0)&& this.running) {
this.timeOutId=window.setTimeout(function(){windowCenter.docenter();},200);
return;
}
window.clearTimeout(this.timeOutId);
windowCenter.centerAll();
},
stop : function() {
windowCenter.running=false;
windowCenter.positionTopMonster();
// windowCenter.currwidth = 0; /*force to center after loading*/
windowCenter.centerAll(true);
windowCenter.isTopMonsterPositioned=true;
},
centerAll : function(isResize) {
windowCenter.adjustSkybanner();
leftBannerWidth = $p("#leftBanner").width();
$p("#leftBanner object").each(function(){
if ($p(this).width() > leftBannerWidth)
leftBannerWidth = $p(this).width(); 
});
$p("#leftBanner embed").each(function(){
if ($p(this).width() > leftBannerWidth)
leftBannerWidth = $p(this).width(); 
});
rightBannerWidth = $p("#rightBanner").width();
if(windowCenter.running){
this.timeOutId=window.setTimeout(function(){windowCenter.centerAll();},200);	
windowCenter.adjustSkybanner();
}else{
window.clearTimeout(this.timeOutId);
}
if(!isResize && (windowCenter.currwidth == $p(window).width()) && (windowCenter.leftBannerWidth == leftBannerWidth) && (windowCenter.rightBannerWidth == rightBannerWidth)){
return;
}
if($p('body#visual').length>0){
var whiteBorder = 1;
} else {
var whiteBorder = 0; 
}
windowCenter.currwidth = $p(window).width();
windowCenter.positionTopMonster();
windowCenter.leftBannerWidth=leftBannerWidth;
windowCenter.rightBannerWidth=rightBannerWidth;
windowCenter.log("leftBanner:" + leftBannerWidth);
windowCenter.log("rightBanner:" + rightBannerWidth);
var shift = Math.ceil(($p(window).width() - this.contentWidth) / 2);
if(Math.max(leftBannerWidth, rightBannerWidth)<=shift){
this.log("big, shift:" + shift);
$p("#leftBanner").css("right",'');
$p("#leftBanner").css("left", shift-leftBannerWidth + whiteBorder);
$p("#rightBanner").css("left", shift + windowCenter.contentWidth - whiteBorder);
windowCenter.adjustSkybanner();
if(isResize){
this.setContentMarginLeft(shift);
}
return;
}
var pageWidth = $p(window).width();
windowCenter.log("small, shift:" + shift);
if(leftBannerWidth>shift){
windowCenter.log("big left banner");
pageWidth += (leftBannerWidth-shift);
$p("#leftBanner").css("right",'');
$p("#leftBanner").css("left", 0);
contentMargin=leftBannerWidth - Math.ceil(windowCenter.getScrollbarWidth()/2);
}else{
windowCenter.log("small left banner");
contentMargin=shift;
pageWidth += shift;
}
if(rightBannerWidth>shift){
windowCenter.log("big right banner");
pageWidth += Math.round((rightBannerWidth-shift - Math.ceil(windowCenter.getScrollbarWidth()/2)));
}else{
windowCenter.log("small right banner");
pageWidth += shift;
}
$p("#rightBanner").css("left", contentMargin + windowCenter.contentWidth + windowCenter.getScrollbarWidth()/2);
$p('#page').width(pageWidth-windowCenter.getScrollbarWidth());
this.setContentMarginLeft(contentMargin + Math.ceil((windowCenter.getScrollbarWidth()/2)));
window.scrollTo(leftBannerWidth-shift, getScrollXY()[1]);
windowCenter.adjustSkybanner();
},
setContentMarginLeft : function(marginLeft){
$p('#content').css("margin-left", marginLeft);
$p('#polHeaderForPartner').css("margin-left", marginLeft);
$p('#pol-align-partner').css("margin-left", marginLeft);
$p('.center-960').css("margin-left", marginLeft);
// hack for photo-site
if($p('body#visual').length>0){
var w = $p('#page').width() > $p(window).width() ? $p('#page').width() : $p(window).width();
// w = $p(document).width() > w ? $p(document).width() : w;
// var w = $p(window).width();
if(w>0){
$p('#polHeader').width(w);
$p('.pol-footer').width(w);
}
}
},
log : function(msg) {
if (window.console) {
//window.console.log(msg);
}
},
getScrollbarWidth : function() {
if (windowCenter.scrollBarWidth) {
return windowCenter.scrollBarWidth;
}
;
var div, w1, w2;
div = $p('<div style="width:50px;height:50px;overflow:hidden;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div></div>');
// Append our div, do our calculation and then remove it
$p('body').append(div);
w1 = $p('div', div).innerWidth();
div.css('overflow-y', 'scroll');
w2 = $p('div', div).innerWidth();
$p(div).remove();
windowCenter.scrollBarWidth = (w1 - w2);
windowCenter.log("scrollBarWidth:" + windowCenter.scrollBarWidth);
if (windowCenter.scrollBarWidth == 0) {
windowCenter.scrollBarWidth = 16;
}
return windowCenter.scrollBarWidth;
},
positionTopMonster : function(){
if(this.isTopMonsterPositioned){
return;
}
var rightcontent = $p("#rightBanner *").length; 
// var maxwidth = 960;
a = $p("#top-monster").find("div");
a.each(function(i, e){
if(e.id.substring(0,3).toLowerCase() == 'dst'){
//maxwidth = 990;
$p("#top-monster div:first").css('width', 'auto');
}
}); 
// function positiontop()
// {
// var wmon = $p("#top-monster").width();
// var wmin = ((maxwidth - wmon) / 2);
// $p("#top-monster").css("right", wmin);
// }
this.log(rightcontent);
if (rightcontent == 0) { 
$p("#top-monster").removeClass('pol-right');
return;
}
if(($p("#rightBanner object").length>0) || ($p("#rightBanner embed").length>0)){
this.isTopMonsterPositioned=true;
//$p("#top-monster").addClass('pol-right');
return;
} 
if($p("#rightBanner img").length>0) {
var imgtag = $p("#rightBanner img:first").attr('src');
if (imgtag.indexOf("adtech") > 1 && imgtag.indexOf("1x1trans.gif") > 1) {
this.isTopMonsterPositioned=true; 
$p("#top-monster").removeClass('pol-right');
return;
} else if (imgtag.indexOf("1x1trans.gif") < 1 ) {
this.isTopMonsterPositioned=true;
//$p("#top-monster").addClass('pol-right');
} else if (imgtag.indexOf("adtech") < 1) {
this.isTopMonsterPositioned=true;
//$p("#top-monster").addClass('pol-right');
}}
}
};
function getScrollXY() {
//fixes scrolltop problems in Safari on mac - Anders 2010-03-08
var scrOfX = 0, scrOfY = 0;
if( typeof( window.pageYOffset ) == 'number' ) {
//Netscape compliant
scrOfY = window.pageYOffset;
scrOfX = window.pageXOffset;
} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
//DOM compliant
scrOfY = document.body.scrollTop;
scrOfX = document.body.scrollLeft;
} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
//IE6 standards compliant mode
scrOfY = document.documentElement.scrollTop;
scrOfX = document.documentElement.scrollLeft;
}
return [ scrOfX, scrOfY ];
}
windowCenter.init();
$p(window).load(windowCenter.stop);
}
/* common functions, needs know about jquery $p and general plugins */
function openPopup(url, width, height, left, top, opIsResizable, opIsScrolbars) {
var resizable, scrollbars;
resizable = (opIsResizable) ? 'yes' : 'no';
scrollbars = (opIsScrolbars) ? 'yes' : 'no';
window.open(url, '_blank',
'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars='
+ scrollbars + ', resizable=' + resizable
+ ', copyhistory=no, width=' + width + ', height=' + height
+ ', left=' + left + ', top=' + top);
}
/*load page from garnnogle select box */
function loadFromGarnnogle(el) {
var url = $p(el).val();
if (url != '')
window.location.href = url;
}
/*toolbox staff (article view)*/
addthis_pub = 'politiken';
function saveResizing(size){
if($p.cookies.test()) $p.cookies.set('textsize', size ,{hoursToLive:8760});	
}
function loadResizing(){
if($p.cookies.test()){
var size = $p.cookies.get('textsize', {hoursToLive:8760});
if(size) $p('#tbSize' + size).click();
}
}
function initResizingTool(){
$p('#tbSize1').click( function() {
saveResizing(1);
$p("#art-body").addClass("save-resizing-1");
$p("#art-body").removeClass("save-resizing-2");
$p("#art-body").removeClass("save-resizing-3")
// $p("#art-body p:not([class]),#art-body,#art-body
// p.bl-elem").css({"font-size":"14px","line-height":"17px"});
// $p("#art-body
// li:not([class]),#art-body").css({"font-size":"14px","line-height":"17px"});
$p("#tbSize1").removeClass("art-size-1").addClass("art-size-1_active");
$p("#tbSize2").removeClass("art-size-2_active").addClass("art-size-2");
$p("#tbSize3").removeClass("art-size-3_active").addClass("art-size-3");
$p('#art-size').removeClass('c-c00');
$p('.font-resize').css({"font-size":"120%","line-height":"140%"});
$p('.font-resize div.guide-item h3').css({"font-size":"130%","line-height":"140%"});
});
$p('#tbSize2').click( function() {
saveResizing(2);
$p("#art-body").addClass("save-resizing-2");
$p("#art-body").removeClass("save-resizing-1");
$p("#art-body").removeClass("save-resizing-3");
// $p("#art-body p:not([class]),#art-body,#art-body
// p.bl-elem").css({"font-size":"16px","line-height":"19px"});
// $p("#art-body
// li:not([class]),#art-body").css({"font-size":"16px","line-height":"19px"});
$p("#tbSize2").removeClass("art-size-2").addClass("art-size-2_active");
$p("#tbSize1").removeClass("art-size-1_active").addClass("art-size-1");
$p("#tbSize3").removeClass("art-size-3_active").addClass("art-size-3");
$p('#art-size').removeClass('c-c00');
$p('.font-resize').css({"font-size":"125%","line-height":"140%"});
$p('.font-resize div.guide-item h3').css({"font-size":"140%","line-height":"140%"});
});
$p('#tbSize3').click( function() {
saveResizing(3);
$p("#art-body").addClass("save-resizing-3");
$p("#art-body").removeClass("save-resizing-2");
$p("#art-body").removeClass("save-resizing-1");
// $p("#art-body p:not([class]),#art-body,#art-body
// p.bl-elem").css({"font-size":"18px","line-height":"21px"});
// $p("#art-body
// li:not([class]),#art-body").css({"font-size":"18px","line-height":"21px"});
$p("#tbSize3").removeClass("art-size-3").addClass("art-size-3_active");
$p("#tbSize1").removeClass("art-size-1_active").addClass("art-size-1");
$p("#tbSize2").removeClass("art-size-2_active").addClass("art-size-2");
$p('#art-size').removeClass('c-c00');
$p('.font-resize').css({"font-size":"130%","line-height":"140%"});
$p('.font-resize div.guide-item h3').css({"font-size":"150%","line-height":"140%"});
});
$p('#tbSize1,#tbSize2,#tbSize3').hover(function(){
if(!$p(this).is('.art-size-1_active,.art-size-2_active,.art-size-3_active'))
$p('#art-size').addClass('c-c00'); }, function(){$p('#art-size').removeClass('c-c00');});
loadResizing();
}
function setCommentsCount() {
var comCnt = (window.jsonThreadInfo) ? jsonThreadInfo.postings : 0;
var comText = (comCnt == 0) ? 'Kommenter' : ((comCnt == 1) ? '1 kommentar'
: comCnt + ' kommentarer');
$p('#tbComment').html(comText);
}
/*send box*/
var sendBox = {
articleUrl : '',
rubric:'',
init : function(url, rubric) {
var obj = this;
obj.articleUrl = url;
obj.rubric = rubric;
$p('#send_art').click(function(){
if($p(this).hasClass('movetobutton')){// provides fix for z-index bug in ie7
$p('body').prepend($p('#tool-send'));
$p('#tool-send').css({top:$p(this).offset().top,left:$p(this).offset().left-200,zIndex:1000});
}
$p('#send-header').show();
$p('#send-body').show();	
$p('#conf-header').hide();
$p('#conf-body').hide();
$p('#tool-send').show();
});
$p('#send_close').click( function() {
$p('#tool-send').hide();
});
$p('#sendBtn').click( function() {
if (obj.validate())
obj.send();
return false;
});	
},
validate : function() {
var isValid = true, recips = $p('#sendRecipients').val(), sender = $p(
'#sendSender').val();
var emailReg = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var emailsReg = /^(([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+)(,([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+)*$/;
$p('#sendRecipients').each( function() {
$p(this).removeClass('er');
if (!emailsReg.test($p(this).val().replace(/ /g, ''))) {
$p(this).addClass('er');
isValid = false;
}
});
$p('#sendSender').each( function() {
$p(this).removeClass('er');
if (!emailReg.test($p(this).val())) {
$p(this).addClass('er');
isValid = false;
}
});
return isValid;
},
send : function() {
var obj = this;
$p.ajax({contentType: "application/x-www-form-urlencoded;charset=utf-8", url: obj.articleUrl + "?service=send", type:"POST", data:{recipients:$p('#sendRecipients').val(), sender:$p('#sendSender').val(), message:$p('#sendMessage').val()}, success: function(data){
var header = '', message = '';
switch($p.trim(data)){
case '0': header = '';
message = '<p>Du har nu sendt <br/><br/> <span class="c-333"><b>' + obj.rubric + '</b></span></p><p>' + 
'til: ' + $p('#sendRecipients').val().replace(',', '<br/>') + '</p>';
break;
case '1': header = 'Fejl';
message = '<p>Indtast en gyldig email-adresse</p>';
break;
default: header = 'Fejl';
message = '<p>E-mailen blev ikke sendt</p>';	
}
$p('#send-header').hide();
$p('#send-body').hide();	
$p('#conf-header').html(header).show();
$p('#conf-body').html(message).show();	
}});	
}
};
/* mail box */
var mailBox = {
serviceUrl:'',	
formData:{},
init : function(url) {
var obj = this;
obj.serviceUrl=url + '?service=mailer';
$p('#commentSubmit').click(function(){
obj.clearDefaults();
if (obj.validate()) {
obj.send();
} else {
obj.restoreDefaults();
}
});
},
clearDefaults : function() {
if($p('#mailform_body [name=fn]').val() == 'Fornavn*') $p('#mailform_body [name=fn]').val(''); 
if($p('#mailform_body [name=ad]').val() == 'Adresse') $p('#mailform_body [name=ad]').val(''); 
if($p('#mailform_body [name=em]').val() == 'Email*') $p('#mailform_body [name=em]').val(''); 
if($p('#mailform_body [name=ln]').val() == 'Efternavn*') $p('#mailform_body [name=ln]').val(''); 
if($p('#mailform_body [name=ci]').val() == 'By*') $p('#mailform_body [name=ci]').val(''); 
if($p('#mailform_body [name=ph]').val() == 'Tlf') $p('#mailform_body [name=ph]').val(''); 
},
restoreDefaults : function() {
if($p('#mailform_body [name=fn]').val() == '') $p('#mailform_body [name=fn]').val('Fornavn*'); 
if($p('#mailform_body [name=ad]').val() == '') $p('#mailform_body [name=ad]').val('Adresse'); 
if($p('#mailform_body [name=em]').val() == '') $p('#mailform_body [name=em]').val('Email*'); 
if($p('#mailform_body [name=ln]').val() == '') $p('#mailform_body [name=ln]').val('Efternavn*'); 
if($p('#mailform_body [name=ci]').val() == '') $p('#mailform_body [name=ci]').val('By*'); 
if($p('#mailform_body [name=ph]').val() == '') $p('#mailform_body [name=ph]').val('Tlf'); 
},
validate : function() {
$p('#mailform_message').html('');
$p('#mailform_body [name=bo]').removeClass('er');
$p('#mailform_body [name=fn]').removeClass('er');
$p('#mailform_body [name=em]').removeClass('er');
$p('#mailform_body [name=ln]').removeClass('er');
$p('#mailform_body [name=ci]').removeClass('er');
formData = this.formData;
formData.bo = $p.trim($p('#mailform_body [name=bo]').val());
formData.fn = $p.trim($p('#mailform_body [name=fn]').val());
formData.ad = $p.trim($p('#mailform_body [name=ad]').val());
formData.em = $p.trim($p('#mailform_body [name=em]').val());
formData.ln = $p.trim($p('#mailform_body [name=ln]').val());
formData.ci = $p.trim($p('#mailform_body [name=ci]').val());
formData.ph = $p.trim($p('#mailform_body [name=ph]').val());
var isValid = true;
if (formData.bo.length==0) {
$p('#mailform_body [name=bo]').addClass('er');
isValid = false;
}
if (formData.fn.length==0) {
$p('#mailform_body [name=fn]').addClass('er');
isValid = false;
}
if (formData.em.length==0) {
$p('#mailform_body [name=em]').addClass('er');
isValid = false;
}
if (formData.ln.length==0) {
$p('#mailform_body [name=ln]').addClass('er');
isValid = false;
}
if (formData.ci.length==0) {
$p('#mailform_body [name=ci]').addClass('er');
isValid = false;
}
if (isValid==false) {
$p('#mailform_message').html('Et eller flere påkrævede felter markeret med * er ikke udfyldt');
return false;
}
var emailReg = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!emailReg.test(formData.em)) {
$p('#mailform_message').html('Email feltet er ikke korrekt udfyldt');
$p('#mailform_body [name=em]').addClass('er');
return false;
}
return true;
},
send : function () {
$p('#mailform_body').html('<img src="/graphics/ajax/ajax-loader.gif" height="24" width="24" border="0" alt="Afsender E-mail" />');
$p.ajax({
contentType: "application/x-www-form-urlencoded;charset=utf-8", 
url:this.serviceUrl, 
type:"POST", 
data:this.formData, 
success: function(data){
$p('#mailform_body').html('<div>Tak for din E-mail</div>');
},
error: function(xhr) {
$p('#mailform_body').html('<div>Der er sket en fejl: (kode:' + xhr.status + ') ' + xhr.statusText + '</div>');
}
});	
}
};
/* extentions for commentHelper (used for Direkte) */
function preSubmitActionDirekte()
{ 
if($p('#fmCommentForm [name=ad]').val() == 'Adresse')
$p('#fmCommentForm [name=ad]').val(''); 
if($p('#fmCommentForm [name=ph]').val() == 'Tlf')
$p('#fmCommentForm [name=ph]').val(''); 
$p('#fmCommentForm [name=question]').val($p('#fmCommentForm [name=bo]').val());	
$p('#fmCommentForm [name=name]').val($p('#fmCommentForm [name=fn]').val());
$p('#fmCommentForm [name=lastname]').val($p('#fmCommentForm [name=ln]').val());
$p('#fmCommentForm [name=city]').val($p('#fmCommentForm [name=ci]').val());
$p('#fmCommentForm [name=address]').val($p('#fmCommentForm [name=ad]').val());
$p('#fmCommentForm [name=email]').val($p('#fmCommentForm [name=em]').val());
$p('#fmCommentForm [name=phone]').val($p('#fmCommentForm [name=ph]').val());
}
function getPagerItemHtmlDirekte(post, isLast)
{ 
var html = '<div class="auth-line question-icon m-top15"><span class="qu-user">' +
post.firstname + ((post.lastname != '')? ' ' + post.lastname: '') + ((post.city !='')? ', ' + post.city: '') + 
'</span><span class="date">&nbsp;' + getTimeStamp(post.date) + '</span></div>' + 
'<p class="no-border dir-text">' + post.text + '</p>';	
for(var j = 0; j < post.answers.length; j++)	
html += '<div class="auth-line attention-icon"><span class="an-user">' + post.answers[j].replier + '</span><span class="date">&nbsp;' + 
getTimeStamp(post.answers[j].date) + '</span></div><p class="dir-text">' + post.answers[j].text + '</p>';
return html;
}
function getPagerHeaderHtmlDirekte()
{
return '(' + commentHelper.postings.length + ')';
}
var monthsShort = ['JAN','FEB','MAR','APR','MAJ','JUN','JUL','AUG','SEP','OKT','NOV','DEC'];
function getTimeStamp(d)
{
return d.substring(11, 16) + ' ' + parseInt(d.substring(0,2), 10) + '. ' + monthsShort[(parseInt(d.substring(3,5),10) - 1)];
}
/* tjek zone kogebogen search */
function initTjekzoneSearch()
{
$p('#tjek-zone form').submit(function(){
var str =$p('#kogebogenSearchText').val();
if(str && str != 'S\u00F8g p\u00E5 opskrift/ingredienser')
return true;	
return false;
});	
$p('#kogebogenSearchText').keypress(function(event){ 
if(event.which == 13)
$p('#tjek-zone form').submit();	
}).blur(function(){
if($p(this).val() == '') $p(this).val('S\u00F8g p\u00E5 opskrift/ingredienser');
}).focus(function(){
if($p(this).val() == 'S\u00F8g p\u00E5 opskrift/ingredienser') $p(this).val('');
});
}
/* Blue book */
function initBlueBook()
{
$p(function(){	
$p('#blue-book a.tooltip').click(function(e){ 
$p('#blue-book a.tooltip.active').removeClass('active');
$p('#blue-book div.bluebook_content:visible').hide();
$p('#' + $p(this).attr('id').replace('tooltip', 'bluebook')).show();	
$p(this).addClass('active');
e.stopPropagation();
});
});
}
/* extends comment functionality to support recommendations */
var postingRecommender = {
recommended:{},
complained:{},
recurl:'',
comurl:'',
init: function(recurl,comurl){
this.recurl = recurl;	
this.comurl = comurl;
if($p.cookies.test()){
var c = $p.cookies.get('recpostings');
if(c) this.recommended = $p.secureEvalJSON(c);
c = $p.cookies.get('compostings');
if(c) this.complained = $p.secureEvalJSON(c);
}
},
canRecommend:function(postId){
return ($p.cookies.test() && ((this.recommended[postId])? false: true));
},
canComplain:function(postId){
return ($p.cookies.test() && ((this.complained[postId])? false: true));
},
recommend:function(obj, postId){
var o = this;
$p.getScript(o.recurl + '?postid=' + postId, function(){
o.recommended[postId] = 1;
if($p.cookies.test())	
$p.cookies.set('recpostings', $p.compactJSON(o.recommended), {hoursToLive: 8760}); 
/* $p(obj).hide(); */
alert('Tak - anbefaling registreret.');
});
},
complain: function(obj, postId){
var o = this;
$p.getScript(o.comurl + '?pid=' + postId + '&fid=0&eid=0' , function(){
o.complained[postId] = 1;
if($p.cookies.test())	
$p.cookies.set('compostings', $p.compactJSON(o.complained), {hoursToLive: 8760}); 
$p(obj).hide();	
alert('Tak for din klage.\nVi tjekker den tekst, som du har klaget over.\nVenlig hilsen redaktionen p\xE5. Politiken.dk.');
});
}
}
function doSubscription(publicationUrl, sectionId){
var value = $p("#mobileNumberBreaking").attr("value");
if((value==null) || (!/^\d{8}$/.test(value))){
$p("#mobileNumberBreaking").addClass("error");
$p("#mobileNumberBreaking").attr("value","Indtast mobilnr.");
return false;
}
$p("#breakingSmsNumber").html(value);
$p.ajax({
cache:false,
url:(publicationUrl + "?service=post&handler=sms&sectionId=" + sectionId + "&mobileNumber="+value),
dataType:"xml",
success: function(msg){	
if($p('result[handler=sms] output[code=200]',msg).size() != 0){
$p("#breakingSubscribe").attr("style", "display:none");
$p("#breakingSuccessMessage").attr("style", "display:inline");
}else{
$p("#mobileNumberBreaking").addClass("error");
$p("#mobileNumberBreaking").attr("value","Indtast mobilnr.");
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
$p("#mobileNumberBreaking").addClass("error");
$p("#mobileNumberBreaking").attr("value","Indtast mobilnr.");
}
})
}
/* ibyen search */
function initIbyenFreeSearch(id, defaultText)
{
$p('#' + id + ' input[type=text]').focus(function(){
if($p(this).val() == defaultText) $p(this).val('');
}).blur(function(){
if($p(this).val() == '') $p(this).val(defaultText); 
});
$p('#' + id).submit(function(){
var s = $p('#' + id + ' input[type=text]').val();
if(s && s.length >= 3 && s != defaultText)
return true;	
return false;
});
}
function initIbyenCalendarSearch(id, url)
{
searchUrl = url;
$p('#' + id).click(function(){
lcs(this);	
return false;
});
}
function searchRestaurantSelect(el) {
var searchUrl = $p(el).val();
if (searchUrl != '')
window.location.href = searchUrl;
}
/* mobile box */
function submitMobileBox(sectionId){
var handlers = [];	
if($p('#mboxCh1').is(':checked')) handlers.push('smsmobile');
if($p('#mboxCh2').is(':checked')) handlers.push('sms');;
if(handlers.length == 0) return;
var number = $p.trim($p('#mboxMobileNumber').val());
if(!/^\d{8}$/.test(number)){
alert('Indtast venligst et gyldigt mobilnummer');
return;
}
var showAlert = function(){
var msg = '';
switch(handlers.toString()){
case "sms": msg = 'Du er nu tilmeldt breaking news p\u00E5 sms';
break;
case "smsmobile": msg = 'Vi har nu sendt et link til Politikens mobilsite';
break;
case "smsmobile,sms": msg = 'Vi har nu sendt et link til Politikens mobilsite og tilmeldt dig breaking news p\u00E5 sms';
break;	
}
alert(msg);	
};
$p.ajax({
cache:false,
url:'?service=post&handler=' + handlers.toString() +'&sectionId=' + sectionId + '&mobileNumber=' + number,
dataType:'xml',
success: function(result){ 
/*var isOk = true;
$p.each(handlers, function(){
isOk = isOk && ($p('result[handler=' + this + '] output[code=200]',result).size() != 0);	
});	
if(!isOk) return;*/
showAlert();
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
showAlert();
}});	
}
/*it's a hot fix to remove hidden lines. Good solution is to restructure the layout avoiding having line-separator after last element in the group*/
$p(function(){
$p('div.cover-line').prev('div.m-line-ccc,div.solidline-ccc').andSelf().remove();
$p('#frontpage div.deck620 div.bottom-for-top:last-child').css('margin-bottom', '0');
});
function initSlideBox(){
var currentElement = $p(this).parent();
var i =0;
while(!currentElement.is('.expanded,.collapsed') && currentElement.length>0) {currentElement = currentElement.parent();}
var slideBox = $p(this).hasClass('beneath')? currentElement.prev('.slide-down'): currentElement.next('.slide-down');
if(slideBox.size() != 0){	
if(currentElement.hasClass("collapsed")){
slideBox.hide();
} else {
slideBox.show();
}
$p(this).unbind().click(function(){
slideBox.toggle();
currentElement.toggleClass("expanded").toggleClass("collapsed");
return true;});	
}}
$p(document).ready(function(){
$p("a.selector").each(initSlideBox);
});
var sportUpdater = {
ajaxHandlerUrl:'',
requestsQueues:{},
registerRequest:function(updateInterval, action, elemId, params, postFunction){
if(!updateInterval) return;
if(!this.requestsQueues[updateInterval]){
this.requestsQueues[updateInterval] = {timerId:null, requests:{}};
}	
this.requestsQueues[updateInterval].requests[elemId] = {action:action,elemId:elemId,params:params,postFunction:postFunction};
},
unregisterRequest:function(action){
for(var q in this.requestsQueues){
for(var el in this.requestsQueues[q].requests){	
if(this.requestsQueues[q].requests[el].action == action){
delete this.requestsQueues[q].requests[el];
break;
}
}
}
},
hasRequestsInQueues:function(){
for(var q in this.requestsQueues){
for(var el in this.requestsQueues[q].requests){	
return true;
}
}
return false;
},
startUpdate:function(){
for(var updateInterval in this.requestsQueues){
this.requestsQueues[updateInterval].timerId = window.setInterval('sportUpdater.update(' + updateInterval + ')', updateInterval);
}	
},
stopUpdate:function(){
for(var updateInterval in this.requestsQueues){
window.clearInterval(this.requestsQueues[updateInterval].timerId)
this.requestsQueues[updateInterval].timerId = null;
}
},
update:function(updateInterval){
var url = this.ajaxHandlerUrl + '?service=ajax_external_sport&name=ajax_update', cnt = 0;
for(var r in this.requestsQueues[updateInterval].requests){
req = this.requestsQueues[updateInterval].requests[r];
if(req){
url += '&action=' + req.action + '&elemId=' + req.elemId + (req.params? '&' +req.params: '');	
++cnt;
}
}
if(cnt != 0){
url += '&reqCount=' + cnt;	
$p.ajax({url:url,dataType:'html',cache:false,error:function(){},success:function(data){
var html = $p(data);	
for(var r in sportUpdater.requestsQueues[updateInterval].requests){
var res = html.find('#' + r), orig = $p('#' + r);
if(res.size() != 0 && orig.size() != 0){
orig.find('.expanded,.collapsed').each(function(){
if($p(this).attr('id')){
var className = ($p(this).hasClass('expanded'))? 'expanded': 'collapsed';
res.find('#' + $p(this).attr('id') + ':not(.' + className + ')').removeClass('expanded').removeClass('collapsed').addClass(className);
}
});	
orig.html(res.html()).find("a.selector").each(initSlideBox);
if(sportUpdater.requestsQueues[updateInterval].requests[r].postFunction) sportUpdater.requestsQueues[updateInterval].requests[r].postFunction;
}
}	
}});	
}	
}	
};
$p(function(){
if(sportUpdater.hasRequestsInQueues()) 
sportUpdater.startUpdate();
});
function initSquad(selectId, tableId){
$p('#' + selectId).change(function(){
var idx = parseInt($p(this).val());
$p('#' + tableId + ' tr:not(:first-child)').hide()
.removeClass('last').filter('tr:eq(' + (idx - 1) + ')').addClass('last').end()
.filter('tr:lt(' + idx + ')').show();
});
}
function subscribeTableTdForClick(selector){
$p(selector).unbind().click(function(e){
if($p(e.target).is('td')){
var href = $p(e.target).find('a').attr('href');
if(href){
window.location.assign(href);
}
return false;
}
return true;
});
};
var currentMatchesUpdater={
requestsQueue:{},
registerBlock:function(blockId, baseUrl){
currentMatchesUpdater.requestsQueue[blockId]=baseUrl;
currentMatchesUpdater.addHandlersToBlock(blockId, baseUrl);
},
addHandlersToBlock:function(blockId, baseUrl){
currentMatchesUpdater.registerChangeListener(blockId);
subscribeTableTdForClick(blockId + " table td");
},
registerChangeListener:function(blockId){
$p(blockId + " select").change(function(eventObject) {
var additionalParams="";
$p(blockId + " select").each(
function(i){
additionalParams += "&" + this.name + "=" + this.value;
}
);
var baseUrl = currentMatchesUpdater.requestsQueue[blockId];
$p.get(baseUrl + additionalParams, function(data){
$p(blockId).html(data);
currentMatchesUpdater.addHandlersToBlock(blockId, baseUrl);
},"html");
});
}
}
function loadTeamTopScore(baseUrl){
var additionalParams = '';
$p('#team_topscore_unique_tournament select,#team_topscore_type select').each(function(i){
additionalParams += "&" + this.name + "=" + this.value;
});
$p.get(baseUrl + additionalParams, function(data){
$p('#team_topscore_content').html(data);}
,"html");
}
function fillTopStatisticTypes(baseUrl, statTypes){
var prevValue = $p('#team_topscore_type select').val();
var uniqueTourn = $p('#team_topscore_unique_tournament select').val();
$p.each(statTypes, function(){
if(this.id == uniqueTourn){
var html = ''; 
for(var type in this.types){
html += '<option value="' + type + '"' + (!html? ' class="sel-first" selected="selected"': '') + '>' + this.types[type] + '</option>';};
html = '<select name="topscore_type" class="sel-box fl-left w140">' + html + '</select>';
$p('#team_topscore_type').html(html);
if(prevValue && $p('#team_topscore_type select option[value=' + prevValue + ']').size() != 0){
$p('#team_topscore_type select').val(prevValue);
}
$p('#team_topscore_type select').change(function(){
fillTopStatisticTournaments(baseUrl, statTypes);
loadTeamTopScore(baseUrl);
});
return false;
}	
});	
}
function fillTopStatisticTournaments(baseUrl, statTypes){
var statType = $p('#team_topscore_type select').val();
var uniqueTourn = $p('#team_topscore_unique_tournament select').val();
var html = '';
$p.each(statTypes, function(i){
if((!statType) || this.types[statType]){
html += '<option value="' + this.id + '"' + (!html? ' class="sel-first"': '') + '>' + this.name + '</option>';
}
});
html = '<select name="seasonId" class="sel-box fl-left w140">' + html + '</select>';
$p('#team_topscore_unique_tournament').html(html);
if($p('#team_topscore_unique_tournament select option[value=' + uniqueTourn + ']').size() != 0){
$p('#team_topscore_unique_tournament select').val(uniqueTourn);
}
$p('#team_topscore_unique_tournament select').change(function(){
fillTopStatisticTypes(baseUrl, statTypes);
loadTeamTopScore(baseUrl);
});
}
function initTeamTopscore(baseUrl, statTypes){
fillTopStatisticTournaments(baseUrl, statTypes);
fillTopStatisticTypes(baseUrl, statTypes);	
}
function initTournamentTopscore(baseUrl){
$p('#topscore_max_box select,#topscore_type_box select')
.change(function(){
var additionalParams = '';
$p('#topscore_max_box select,#topscore_type_box select').each(function(i){
additionalParams += "&" + this.name + "=" + this.value;
});
$p.get(baseUrl + additionalParams, function(data){
$p('#tournament_topscore_content').html(data);}
,"html");	
});	
}
function initTopscoreSp3(baseUrl){
$p('#topscore_box_sp3 select').change(function(){
var additionalParams = '';
$p('#topscore_box_sp3 select').each(function(i){
additionalParams += "&" + this.name + "=" + this.value;
});
$p.get(baseUrl + additionalParams, function(data){
$p('#topscore_box_sp3_content').html(data);}
,"html");	
});	
}
function loadTeamOverallStatistic(baseUrl){
var additionalParams = '';
$p('#team_overall_statisctic_tournament_box select,#team_overall_statisctic_season_box select').each(function(i){
additionalParams += "&" + this.name + "=" + this.value;
});
$p.get(baseUrl + additionalParams, function(data){
$p('#team_overall_statistic_container').html(data);}
,"html");	
}
function fillTeamOverallStatisticSeasons(baseUrl, selectsJson){
var uniqueTournamentId = $p('#team_overall_statisctic_tournament_box select').val();
$p.each(selectsJson, function(){
if(this.id == uniqueTournamentId){
var seasonId = $p('#team_overall_statisctic_season_box select').val();
$p('#team_overall_statisctic_season_box').empty().append('<select name="seasonId" class="sel-box fl-left"></select>');
$p.each(this.seasons, function(i){
$p('#team_overall_statisctic_season_box select').append('<option value="' + this.id + '"' + (i == 0? ' class="sel-first" selected="selected"': '') + '>' + this.name + '</option>');
});
if(seasonId && $p('#team_overall_statisctic_season_box select option[value=' + seasonId + ']').size() != 0){
$p('#team_overall_statisctic_season_box select').val(seasonId);
}
$p('#team_overall_statisctic_season_box select')
.change(function(){
loadTeamOverallStatistic(baseUrl);
});	
}
});
}
function initTeamOverallStatistic(baseUrl, selectsJson){
$p('#team_overall_statisctic_tournament_box select').change(function(){
fillTeamOverallStatisticSeasons(baseUrl, selectsJson);
loadTeamOverallStatistic(baseUrl);
});
fillTeamOverallStatisticSeasons(baseUrl, selectsJson);
}
function initTournamentOverallStatistic(baseUrl){
$p('#tournament_overall_statisctic_season_box select')
.change(function(){
$p.get(baseUrl + '&seasonId=' + $p(this).val(), function(data){
$p('#tournament_overall_statistic_container').html(data);}
,"html");	
});
}
function loadDefferedIframesInner(){
if(!window.defferedIframes) return;	
for(var id in defferedIframes){
$p('#' + id).attr('src', defferedIframes[id]);	
}
}
function addDefferedIframe(id, url){
if(!window.defferedIframes) window.defferedIframes = {};
defferedIframes[id] = url;
}
function loadDefferedIframes(timeMs){
if(window.defferedIframes){
window.setTimeout("loadDefferedIframesInner();" ,timeMs);
}}
function initTeamstatisticSp3(data){
$p('#teamstatistic_number_sp3 select').change(function(){$p('#teamstatistic_type_sp3 select').change();});
$p('#teamstatistic_type_sp3 select').change(function(){
var type = $p(this).val();	
var showCnt = ($p('#teamstatistic_number_sp3 select').val() == 'top10Teams' && data.length > 10)? 10: data.length;
data.sort(function(a,b){return -(a[type] - b[type]);});
var html = '';
for(var i = 0; i < showCnt; i++){
if (new String(data[i][type]).indexOf(".")==-1 && data[i][type] == parseInt(data[i][type])) {
data[i][type] += '.0';
}
html += '<tr class="clearfix ' + ((i == showCnt - 1)? ' last': '') + '"><td class="num">' + (i + 1) + '</td><td class="team-name"><span><a href="' + data[i].teamUrl + '">' + data[i].teamName + '</a></span></td>';
html += '<td class="right-stat-column c-333"><span class="c-333">' + data[i][type] + (type == 'bp'? '%': '') + '</span></td></tr>';
}	
$p('#teamstatistic_sp3_content>table').html(html);
}).change();
}
function initTournamentTeamstatisticSp3(data){
$p('#tour_teamstatistic_teams_sp3 select').change(function(){
var teamId = $p(this).val();
var stat = data[teamId];
var content = $p('#tour_teamstatistic_sp3_content>table');
if(!stat){content.hide();return false;}	
$p('tr.matches>td:odd', content).text(stat.m);
$p('tr.g>td:odd', content).text(stat.g + ' (' + (1.0 * stat.g / stat.m).toFixed(2) + ')');
$p('tr.cs>td:odd', content).text(stat.cs);
$p('tr.yc>td:odd', content).text(stat.yc + ' (' + (1.0 * stat.yc / stat.m).toFixed(2) + ')');
$p('tr.rc>td:odd', content).text(stat.rc + ' (' + (1.0 * stat.rc / stat.m).toFixed(2) + ')');
if(teamId == 'all'){
$p('tr.bp, tr.shon,tr.shoff,tr.cor,tr.fraw,tr.frcom', content).hide();	
} else {
$p('tr.bp>td:odd', content).text((1.0 * stat.bp /stat.m).toFixed() + '%');
$p('tr.shon>td:odd', content).text(stat.shon + ' (' + (1.0 * stat.shon / stat.m).toFixed(2) + ')');
$p('tr.shoff>td:odd', content).text(stat.shoff + ' (' + (1.0 * stat.shoff / stat.m).toFixed(2) + ')');
$p('tr.cor>td:odd', content).text(stat.cor + ' (' + (1.0 * stat.cor / stat.m).toFixed(2) + ')');
$p('tr.fraw>td:odd', content).text(stat.fraw + ' (' + (1.0 * stat.fraw / stat.m).toFixed(2) + ')');
$p('tr.frcom>td:odd', content).text(stat.frcom + ' (' + (1.0 * stat.frcom / stat.m).toFixed(2) + ')');
$p('tr.bp, tr.shon,tr.shoff,tr.cor,tr.fraw,tr.frcom', content).show();
}
content.show();
}).change();
}
function logMsg(msg)
{
if(window.console)
console.log(msg);
}
//tgt frontpage zone begin
function tgtEventHandler(eventObj){
//remove the two to/from labels
$('MomondoSearchForm').select('div.label').each(function(el){
el.remove();
});
document.getElementsByTagName('body')[0].style.position='relative';
// create new placeholder div#row1 at top of #MomondoSearchForm
$('MomondoSearchForm').insert({'top':new Element('div',{'id':'row1'}).setStyle({'background':'transparent'})});
// move distinationpickers into the new div#row1, add classnames to the
// outer div and value to the inputfields
$('MomondoSearchForm').select('div.airportbox_outer').each(function(el,index){
$('row1').insert({'bottom':el});
index==0?el.addClassName('upper'):el.addClassName('lower');
index==0?el.down(1).value="Jeg vil rejse fra":el.down(1).value="Jeg vil rejse til";
// clear field on focus
Event.observe(el.down(1),'focus',function(event){
el.down(1).value="";
});
});
// create new placeholder div#row2 after #row1
$('row1').insert({'after':new Element('div',{'id':'row2'})});
// create new placeholder div#row3 after #row2
$('row2').insert({'after':new Element('div',{'id':'row3'})});
// move the first two 'div.options' into the new div#row2
$('MomondoSearchForm').select('div.options').each(function(el,index){
if(index<2){
//move to row2
index==0?el.addClassName('upper'):el.addClassName('lower');
$('row2').insert({'bottom':el});
}else{
//move to row3
$('row3').insert({'top':el.down().down()});
$('row3').insert({'bottom':new Element('label',{'for':'MomondoCheckTripTypeReturn'}).update('Retur')});
el.remove();
}
});
// add classname to nested tablecells
$('row2').select('table').each(function(el){
el.select('td').each(function(td,index){
td.addClassName('destcell_'+index);
});
});
// fix the submitbutton
$('MomondoSubmitFlightSearch').up().id="tgtsubmit";
$('MomondoSubmitFlightSearch').remove();
$('tgtsubmit').setStyle({'textAlign':'left'});
$('tgtsubmit').insert({'bottom':new Element('input',{'id':'MomondoSubmitFlightSearch','src':'/graphics/buttons/find_billet.png','type':'image','tabindex':'8','value':'SÃ¸g','onclick':'return false;'}).setStyle({'paddingTop':'15px'})});
$('tgtsubmit').insert({'bottom':new Element('a',{'href':'/turengaartil/hoteller/'}).update('SÃ˜G HOTEL')});
this.searchFlight = new MomondoWhitelabelSearchFlight();
$('MomondoSubmitFlightSearch').observe('click', this.searchFlight.searchClicked.bind(this.searchFlight));
if(typeof return_focus_to == "string"){
//if momondo-call is deferred, return focus to element that trigged load of momondo
window.setTimeout(function() { $(return_focus_to).focus(); }, 10);
}
}
//tgt frontpage zone end
// politiken.dk start page
function browserStartPage() {
var bookmarkUrl = $p("a.pol-bookmark").attr("href");
var bookmarkTitle = $p("a.pol-bookmark").attr("title");
if (window.sidebar) { // For Mozilla Firefox Bookmark
window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
} else if( window.external || document.all) { // For IE Favorite
window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
} else if(window.opera) { // For Opera Browsers
$p("a.pol-bookmark").attr("href",bookmarkUrl);
$p("a.pol-bookmark").attr("title",bookmarkTitle);
$p("a.pol-bookmark").attr("rel","sidebar");
} else { // for other browsers which does not support
alert('Din browser understÃ¸tter ikke denne funktion');
return false;
}
};
// inline lightbox
$p(function() {
$p('img.inlineLightBox').each(function(i,e){
var src = e.src.substring(0,e.src.lastIndexOf('.')-1) + 'a.jpg';
var img = new Image();
img.onload = function(){//if we have the assumed a-version
// get the correct caption
var caption = '&nbsp;';
if($p($p(e).parent()).find('.caption').length>0){
var caption_container = $p(e).parent().find('.caption');
$p(caption_container).addClass('inline-lightbox-caption');
var caption = $p(caption_container).html();
var a = $p('<a/>',{'href':src}).css({'text-decoration':'none'});
$p(a).lightBox({fixedNavigation:false,scaleToWindow:'true',customCaption:caption});
$p(caption_container).wrap(a);
}
// create an anchor as a wrapper, set it's target to the a-version,
// append lightBox-handler to it and wrap the image
var a = $p('<a/>',{'href':src}).css({'display':'block'});
if(caption=='&nbsp;'){
$p(a).addClass('lightBoxIndicator');
}
$p(a).lightBox({fixedNavigation:false,scaleToWindow:'true',customCaption:caption});
$p(e).wrap(a);
};
img.src = src;
});
});
// Set skybanner to fixed position
$p(document).ready(function() {
if ($p('#skyRightBanner').length > 0) {
var bannerSkyPos = $p('#skyRightBanner').position();
var varScrollTop = $p(window).scrollTop();
if (varScrollTop > bannerSkyPos.top - 6) {
$p('#skyRightBanner').css({'position' : 'fixed', 'top' : 6});
} else {
$p('#skyRightBanner').css({'position' : 'absolute', 'top' : bannerSkyPos.top});
}
$p(window).scroll(function() {
var varScrollTop = $p(window).scrollTop();
if (varScrollTop > bannerSkyPos.top - 6){
$p('#skyRightBanner').css({'position' : 'fixed', 'top' : 6});
} else {
$p('#skyRightBanner').css({'position' : 'absolute', 'top' : bannerSkyPos.top});
}
});
}
});
var keyStr = "ABCDEFGHIJKLMNOP" +
"QRSTUVWXYZabcdef" +
"ghijklmnopqrstuv" +
"wxyz0123456789+/" +
"=";
function decode64(input) {
var output = "";
var chr1, chr2, chr3 = "";
var enc1, enc2, enc3, enc4 = "";
var i = 0;
if (!input)
return null;
// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
var base64test = /[^A-Za-z0-9\+\/\=]/g;
if (base64test.exec(input)) {
alert("There were invalid base64 characters in the input text.\n" +
"Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" +
"Expect errors in decoding.");
}
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
do {
enc1 = keyStr.indexOf(input.charAt(i++));
enc2 = keyStr.indexOf(input.charAt(i++));
enc3 = keyStr.indexOf(input.charAt(i++));
enc4 = keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
chr1 = chr2 = chr3 = "";
enc1 = enc2 = enc3 = enc4 = "";
} while (i < input.length);
return unescape(output);
}
window.polId = new function () {
this.getUserFromCookie = function () {
try {
//if(!$p.cookies.test()){ return null; }
var val = $p.cookies.get('polsso.user');
if (!val) { return null; }
val = val.replace(/_/g, "=");
if(window.atob){ return $p.parseJSON(window.atob(val)); }
return $p.parseJSON(decode64(val));
} catch (err) {
$p.cookies.del('polsso.user');
alert('Der er sket en fejl ifbm. dit login.\nDu skal logge ind igen.');
}
return null;
}
this.user=this.getUserFromCookie();
this.getPublicId = function () {
return (this.user.PublicId)?this.user.PublicId:"";
} 
this.isLoggedIn = function () {	
return this.user!= null;
}
this.getUsername = function () {
return this.user.Username;	
} 
this.getTitle = function () {
return (this.user.Title)?this.user.Title:"";	
}
this.getProfileImage = function () {
return (typeof this.user.ImageUrl == 'string' && this.user.ImageUrl.trim().length > 0 ? this.user.ImageUrl : '');
}
this.getFacebookId = function () {
return (this.user.FacebookId)?this.user.FacebookId:"";
} 
this.isRejected = function () {
return this.user.Rejected > new Date().getTime(); 
}
this.rejected = function () {
return this.user.Rejected; 
}
this.rejectedDaysLeft = function () {
return this.isRejected() ? Math.floor((this.user.Rejected - new Date().getTime()) / (1000*60*60*24)) : 0;
}
this.isValidated = function () {
return this.user.validated;
}
this.centerBox = function (boxId) {
var floatLeft = ($p(window).width() - $p(boxId).width())/2 + $p(window).scrollLeft();
var floatTop = ($p(window).height() - $p(boxId).height())/2 + $p(window).scrollTop();
$p(boxId).css({left: floatLeft, top: floatTop})	
}
this.showModal = function (title, iframeSrc, footer, frameWidth, frameHeight, loginHeight, loginWidth, forgotPass, hidden) {
var frameRate = 200;
$p('.forgot-password-link').fadeOut(frameRate);
if ($p("#login-layer").length==0) {
$p("<div id='login-layer'></div>").css({height: $p(document).height(), width: $p(document).width(),opacity:0.9,display:'none'}).appendTo('body').fadeIn(frameRate);
}
if ($p("#login-float").length<=0) {
$p('body').append($p('<div/>',{id:'login-float'}).css({height:0, width:0}));
$p('#login-float').append($p('<div/>',{id:'inner-box'}).css({opacity:0}));
polId.centerBox("#login-float");
var posLeft = $p('#login-float').offset().left - (293/2);
var posTop = $p('#login-float').offset().top - (341/2);
function removebox(){
$p(window).unbind('resize');
$p(window).unbind('scroll');
$p('#login-float').fadeOut(frameRate, function(){
$p('#login-float').remove();
});
$p('#login-layer').fadeOut(frameRate, function(){
$p('#login-layer').remove();
});
if(typeof polId.go_to != 'undefined' && polId.go_to.length != 0){
location.href = polId.go_to;
}
}
var ifm = $p("<iframe/>", {id:'login-frame',frameborder:0, scrolling:'no', src: iframeSrc, ALLOWTRANSPARENCY:"true"});
if(hidden!=null && hidden){
$p('#login-float, #login-layer').css({'display':'none'});
}
ifm.css({width:(frameWidth != '') ? frameWidth : '', height:(frameHeight != '') ? frameHeight : ''});
if (forgotPass == true) {
//var ifm = $p("<iframe/>", {id:'login-frame',frameborder:0, scrolling:'no', src: iframeSrc, ALLOWTRANSPARENCY:"true"});
$p('#inner-box').append("<div id='login-close-button'></div><div id='login-header'><span class='span-title'>" + title + "</span></div>").append(ifm).append(footer);
$p('#login-frame').attr('src', iframeSrc);
$p('.span-title').text(title);
$p('.intro-text').remove();
$p('#login-float').animate({width:loginWidth, left:posLeft, height:loginHeight, top:posTop}, frameRate, function(){
$p('#login-frame').animate({width:frameWidth, height:frameHeight}, frameRate, function() {
$p('#inner-box').animate({opacity:1}, frameRate);
});	
});
$p("#login-close-button, #login-layer").click(removebox);
} else {
$p('#login-float').animate({height:loginHeight, top:posTop, width:loginWidth, left:posLeft}, frameRate, function(){
$p('#inner-box').append("<div id='login-close-button'></div><div id='login-header'><span class='span-title'>" + title + "</span></div>").append(ifm).append(footer);
$p('#inner-box').animate({opacity:1}, frameRate);
$p("#login-close-button, #login-layer").click(removebox);
});
}
$p(window).resize(function() {
polId.centerBox("#login-float");
$p("#login-layer").css({height: $p(document).height(), width: $p(document).width()});
var w = $p(document).width();
var h = $p(document).height();
$p("#login-layer").css({height: h, width: w})
});
$p(window).scroll(function() {
$p("#login-layer").css({height: $p(document).height(), width: $p(document).width()});	
});
} else {
$p('#inner-box').animate({opacity:0}, frameRate, function() {
$p('#login-frame').attr('src', iframeSrc);
$p('.span-title').text(title);
$p('.intro-text').remove();
$p('#login-float').animate({width:loginWidth, left:posLeft, height:loginHeight, top:posTop}, frameRate, function(){
$p('#login-frame').animate({width:frameWidth, height:frameHeight}, frameRate, function() {
$p('#inner-box').animate({opacity:1}, frameRate);
});
});
});
}
}
this.showLoginBox = function (hidden) {
polId.showModal (
"LOG IND", 
location.protocol + "//" + location.hostname + "/sso/rest/api/user/authenticate",
"<a href='#' onclick='javascript:polId.showForgotPassword();return false;' class='forgot-password-link link-cc0000'>Glemt adgangskode</a><div class='clear'></div>",
"",
"",
267,
274,
false,
(hidden != null && hidden) ? true : false
);
}
this.showActivationBox = function (userid, activationcode) {
polId.showModal (
"Vælg adgangskode", 
polId.endpoint + "Activate.aspx?userid=" + userid + "&activationcode=" + activationcode + "&brand=POL&redir=http%3a%2f%2f" + location.hostname + "%2fsso%2frest%2fapi%2fuser%2fauthenticate%3freferer%3dhttps%3a%2f%2f" + location.hostname + "%2fmitpolitiken%2fopretbruger%2ftrin1%2f",
"",
"",
"",
267,
274,
false
);
}
this.showForgotPassword = function () {
polId.showModal (
"Ny adgangskode", 
polId.endpoint + "Account/ResetPassword.aspx?brand=POL",
"", 
300, 
166,
202,
300,
true	
);
}
this.showRequestNewEmail = function () {
polId.showModal (
"Ny email", 
polId.endpoint + "account/RequestUsernameChange.aspx?brand=POL",
"", 
275, 
235,
270,
275,
false	
);	
}
this.showNewEmail = function (userid) {
polId.showModal (
"Ny email", 
polId.endpoint + "account/ChangeEmail.aspx?userid=" + userid + "&brand=POL&redir=http%3a%2f%2f" + location.hostname + "%2fsso%2frest%2fapi%2fuser%2fauthenticate%3freferer%3dhttps%3a%2f%2f" + location.hostname + "%2fmitpolitiken%2f",
"", 
292, 
364,
397,
292,
false	
);
}
this.init = function (endpoint) {
this.endpoint = endpoint;
$p('#userBtn1').jTruncate({ 
length: 30,
minTrail: 0,
moreText: "",
lessText: "",
ellipsisText: "...",
moreAni: "",
lessAni: ""
});
this.headerButtons = function (locationHostName) {
if (polId.isLoggedIn()) {
if (polId.isValidated()) {
if(document.getElementById('userBtn1')){
document.getElementById('userBtn1').href='https://'+ location.hostname +'/mitpolitiken/' + polId.getPublicId() + '/.action';
}
} else {
if(document.getElementById('userBtn1')){
document.getElementById('userBtn1').href='https://'+ location.hostname +'/mitpolitiken/retbruger/';
}
}
if(document.getElementById('userBtn1')){
document.getElementById('userBtn1').innerHTML=polId.getUsername();
}
var reDir = '';
if (location.href.indexOf('/mitpolitiken') != -1) {
reDir = '&redir=http://politiken.dk/';
}
$p('#userBtn2').html('LOG UD').attr('href', 'http://'+ location.hostname +'/sso/rest/api/user/authenticate/logout?tm=' + new Date().getTime() + reDir);	
$p('.log-in-head li').show();
} else {
$p('.log-in-head li').show();
$p('#userBtn2').click(function(e){
polId.showLoginBox();
e.preventDefault();
});
}
}
}
};
var pol = {};
pol.has_voted_on_posting = function(art_id,element_to_hide_by_id,secondary_element_to_remove_by_id){
if($p.cookies.test()){
if($p.cookies.get('pol_voted')){
var votes = $p.cookies.get('pol_voted').split(',');
if ($p.inArray(art_id.toString(),votes) != -1){
if(element_to_hide_by_id && element_to_hide_by_id != ''){
$p('#' + element_to_hide_by_id).hide();	
}
if(secondary_element_to_remove_by_id && secondary_element_to_remove_by_id != ''){
$p('#' + secondary_element_to_remove_by_id).remove();	
}
return true;
}
}
}
return false;
}
pol.register_vote_on_posting = function(art_id,element_to_hide_by_id,secondary_element_to_remove_by_id){
if($p.cookies.test()){
if($p.cookies.get('pol_voted')){
var votes = $p.cookies.get('pol_voted');
votes = votes.split(',');
}else{
var votes = [];
}
votes.push(art_id);
$p.cookies.set('pol_voted', votes, {hoursToLive: 8760});
if(element_to_hide_by_id && element_to_hide_by_id != ''){
$p('#' + element_to_hide_by_id).fadeOut();	
}
if(secondary_element_to_remove_by_id && secondary_element_to_remove_by_id !=''){
$p('#' + secondary_element_to_remove_by_id).remove();	
}
}
}
pol.getUrlParam = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results){
return results[1] || 0; 
}else{
return false;
} 
}
pol.store_alignment = function (art_id,element_to_hide_by_id,secondary_element_to_remove_by_id) {
var f = $p('form',$p('#'+element_to_hide_by_id));
f.submit(function(){
var checked;
$p('input[name="Aligned"]',f).each(function(){
if($p(this).prop('checked')){
checked = true;
}
});
if(!checked){
alert('Du skal vÃ¦lge noget...');
}else{
$p.get(f.attr('action'),$p(f).serialize(),function(response,status,xhr){
if(status=='success'){
pol.register_vote_on_posting(art_id,element_to_hide_by_id,secondary_element_to_remove_by_id);
}
});
}
return false;
});
}
pol.commentconfirm = function(articleId, commentId,commentTitle,commentText,commentRating) {
if((commentTitle == '') || (commentTitle == 'Skriv din overskrift'))
{	
alert("Indtastning af overskrift på kommentar mangler.\n\nPrøv venligst igen.");
return;
}
else if((commentText == '') || (commentText == 'Skriv din kommentar'))
{
alert("Indtastning af kommentar mangler.\n\nPrøv venligst igen.");
return;
}
else if((commentText.length > 1000) || (commentTitle.length > 100) )
{
alert("For mange karakter indtastet. Maksimum for brødtekst er 1000, og overskrift er 100.\n\nPrøv venligst igen.");
return;
}
if(commentRating == undefined || commentRating == null)
commentRating = '';
var w = $p(document).width();
var h = $p(document).height();
var ajax_load = "<img style='position: absolute; left: 37%; top:28%;' src='/graphics/components/lightbox-ico-loading.gif' alt='loading...' />";
var lightoverlay = document.createElement('div');
var wrapper = document.createElement('div');
var ajaxload = document.createElement('div');
lightoverlay.id="lightoverlay";
wrapper.id="wrapper";
ajaxload.id="ajaxload";
$p(lightoverlay).css({opacity:0.8,backgroundColor:'black',width:w,height:h,position:'absolute',top:0,left:0,display:'none',zIndex:9002});
$p(wrapper).css({backgroundColor:'transparent',width:'100%',height:h,position:'absolute',display:'none',top:0,left:0,zIndex:9003});
$p(ajaxload).css({backgroundColor:'#fff',width:'169px',height:'130px',position:'absolute',top:'396px',left:'45%',display:'none',zIndex:9003});
$p('body').append(lightoverlay);
$p('body').append(wrapper);
$p('body').append(ajaxload);
$p(lightoverlay).fadeIn(1500);
$p(ajaxload).html(ajax_load).fadeIn(1000);	
var urlString = "";
if(commentId == null)
urlString = "/template/v2-0/components/article/comments/comment_confirm.jsp?articleId="+articleId+"&text="+commentText+"&title="+commentTitle+"&rating="+commentRating+"&origin="+location.hostname;
else
urlString = "/template/v2-0/components/article/comments/comment_confirm.jsp?articleId="+articleId+"&id="+commentId+"&text="+commentText+"&title="+commentTitle+"&rating="+commentRating+"&origin="+location.hostname;
var imgurl = polId.getProfileImage();
var toReplace = 'http://multimedia.pol.dk/';
if(imgurl.lastIndexOf(toReplace)!=-1){
imgurl = imgurl.replace(toReplace,'httpmultimediapoldk')
}
urlString += '&fullname=' + polId.getUsername() + '&fbid=' + polId.getFacebookId() + '&usertitle=' + polId.getTitle() + '&userProfileImage=' + imgurl;
// get Alignment
if($p('#comment-box-rating-container').length!=0){
$p('input[name="Aligned"]',$p('#comment-box-rating-container')).each(function(){
if($p(this).prop('checked')){
urlString += '&rating=' + $p(this).val();
}
});
}
var encodedUrl = encodeURI(urlString);
var breakRowFixedUrl = encodedUrl.replace(/%0A/g,'<br/>');
$p.ajax({
url: breakRowFixedUrl,
success: function(data) {
$p('body').scrollTop();
$p("#ajaxload").remove();
$p(wrapper).html(data).fadeIn(700,function(){
var h = $p(window).scrollTop() + 10;
$p('#commentconfirmLightbox').css('top',h).show().animate({"width": '620px'},'slow');
$p("#wrapper, .commentconfirm-lightbox-close").click(remove);
$p("#comment_edit_button").click(remove);
$p("#commentconfirmLightbox").click(function(){$p("#wrapper").unbind('click', remove)});
var art_offset_left = $p("#art-view-top").offset().left;
$p(".commentconfirm-lightbox").css("margin-left",art_offset_left);	
});
}
});
$p(window).resize(function() {
var w = $p(window).width();
var h = $p(document).height();
$p(lightoverlay).css({width:w,height:h});
});
function remove(){
$p('#wrapper').fadeOut(700, function(){
$p('#wrapper').remove();
});
$p('#lightoverlay').fadeOut(1000, function(){
$p('#lightoverlay').remove();
});
}
}
//Debate list tab
function debateListTab() {
if (!pol.debateListTabLoaded) {
$p('.seneste-btn').click(function(e){
$p(this).addClass('active');
$p(this).next('.mest-btn').removeClass('active');
$p(this).parent('.sp-debat').children('.seneste').addClass('active-list');
$p(this).parent('.sp-debat').children('.seneste').show();
$p(this).parent('.sp-debat').children('.mest').removeClass('active-list');
$p(this).parent('.sp-debat').children('.mest').hide();
e.preventDefault();
});
$p('.mest-btn').click(function(e){
$p(this).addClass('active');
$p(this).prev('.seneste-btn').removeClass('active');
$p(this).parent('.sp-debat').children('.seneste').removeClass('active-list');
$p(this).parent('.sp-debat').children('.seneste').hide();
$p(this).parent('.sp-debat').children('.mest').addClass('active-list');
$p(this).parent('.sp-debat').children('.mest').show();
e.preventDefault();
});
}
pol.debateListTabLoaded=true
}
pol.charcounter = function(inputId, charSpan, maxChar) {
$p(inputId).live('keyup',function(){
var l = $p(this).val().length;
if(l>maxChar){
$p(this).val($p(this).val().substring(0, maxChar));
$p(charSpan).html('(0 tegn tilbage)');
}else{
$p(charSpan).html('(' + (maxChar-l ) + ' tegn tilbage)');
}
});
}
