﻿/* ----------------------------

     Utskriftsvänlig layout
     John Modig Productions
     
---------------------------- */

var layout="screen";
var orgLogoHTML="";
var head=document.getElementsByTagName('head')[0];
var relPath="";

var p1=document.createElement("link");
p1.setAttribute('rel','stylesheet');
p1.setAttribute('type','text/css');
p1.setAttribute('id','printStyle');
p1.setAttribute('title','printStyle');
p1.setAttribute('href','css/print.css');
p1.setAttribute('media','screen, print');
head.appendChild(p1);

var p2=document.createElement("link");
p2.setAttribute('rel','stylesheet');
p2.setAttribute('type','text/css');
p2.setAttribute('id','printStyleOverrides');
p2.setAttribute('title','printStyle');
p2.setAttribute('href','css/print_overrides.css');
p2.setAttribute('media','print');
head.appendChild(p2);

var p3=document.createElement("link");
p3.setAttribute('rel','stylesheet');
p3.setAttribute('type','text/css');
p3.setAttribute('id','popupPrintStyle');
p3.setAttribute('title','printStyle');
p3.setAttribute('href','css/print_popup.css');
p3.setAttribute('media','screen, print');
head.appendChild(p3);

for(i=0;(a=document.getElementsByTagName("link")[i]);i++) {
  if(a.getAttribute("title")=="printStyle"){
    a.disabled=true;
  }
}

function changeStyleRelPath(rPath,popup) {
relPath=rPath;
p1.setAttribute('href',relPath+'css/print.css');
p2.setAttribute('href',relPath+'css/print_overrides.css');
p3.setAttribute('href',relPath+'css/print_popup.css');
// popup?
if(!popup){return changeStyle();}
else{return changeStyle(true);}
}

function changeStyle(popup){
var logo=document.getElementById('header');
var i, a;
switch(layout)
{
case "print":
   for(i=0;(a=document.getElementsByTagName("link")[i]);i++) {
     if(a.getAttribute("title")=="printStyle"){
       a.disabled=true;
     }
     else if(a.getAttribute("media").indexOf("screen") != -1){
       a.disabled=false;
     }
   }
document.getElementById('linkPrint').innerHTML="Utskriftsvänlig version";
document.getElementById('linkPrint').setAttribute('title', 'Utskriftsvänlig version');
document.getElementById('content').removeChild(document.getElementById('printFooter'));
logo.innerHTML=orgLogoHTML;
layout="screen";
break
case "screen":
   for(i=0;(a=document.getElementsByTagName("link")[i]);i++) {
     if(a.getAttribute("title")=="printStyle"){
       a.disabled=false;
     }
     else if(a.getAttribute("media").indexOf("screen") != -1){
       a.disabled=true;
     }
   }

// popup?
if(!popup){p3.disabled=true;}
else{p3.disabled=false;}

document.getElementById('linkPrint').innerHTML="Tillbaka till skärmlayout";
document.getElementById('linkPrint').setAttribute('title', 'Tillbaka till skärmlayout');
if(orgLogoHTML==""){orgLogoHTML=logo.innerHTML;}
logo.innerHTML="";
hrLogo = document.createElement("img");
hrLogo.setAttribute("src", relPath+"images/logos/logo_aptit_300dpi.jpg");
hrLogo.setAttribute("alt", "Aptit Stockholm - högupplöst utskriftsvänlig logotyp");
hrLogo.setAttribute("title", "Aptit Stockholm - högupplöst utskriftsvänlig logotyp");
hrLogo.style.width="15cm";
hrLogo.style.height="4.04cm";
hrLogo.style.marginBottom="1cm";
if(logo.className!="empty"){ logo.appendChild(hrLogo); }

d=new Date();
mins=d.getMinutes();
if(mins<10){mins="0"+mins;}
strD=(d.getMonth()+1)+"/"+d.getDate()+"/"+d.getYear()+" "+d.getHours()+":"+mins; 
var printFooter=document.createElement("p");
printFooter.setAttribute("id", "printFooter");
printFooter.style.fontSize="7pt";
printFooter.style.lineHeight="9pt";
document.getElementById('content').appendChild(printFooter);
hrLogo = document.createElement("img");
hrLogo.setAttribute("src", relPath+"images/logos/logo_aptit_300dpi_small.jpg");
hrLogo.setAttribute("alt", "Aptit Stockholm - högupplöst utskriftsvänlig logotyp");
hrLogo.setAttribute("title", "Aptit Stockholm - högupplöst utskriftsvänlig logotyp");
hrLogo.style.width="3.72cm";
hrLogo.style.height="1cm";
hrLogo.style.marginBottom="0.2cm";
if(logo.className=="empty"){ printFooter.appendChild(hrLogo); }
printFooter.innerHTML+="<br />Utskriven: "+strD+".<br />Url: "+location.href+"<br /><br />";
layout="print";
break
}
return false;
}