var namecookie = "TSfont";

function print_preview() {
	
	var server = location.href.substring(0, location.href.indexOf('/', location.href.indexOf('teliasonera.')));
	var currPage = location.href.substring(location.href.indexOf('/', location.href.indexOf('teliasonera.')));
	
	var fullPath = server + '/print/index.page?pg=' + currPage; 
	var printPreview = window.open(fullPath);
	
	//var body = printPreview.document.getElementsByTagName('body')[0];
	//body.setAttribute('onload', 'window.print()');
}


function getActiveStyleSheet() {
	var i, a;
 	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
  		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) {
  			return a.getAttribute("title");
  		}
  	}
  	return null;
}

function setActiveStyleSheet(title) {
   var i, a, main;
   
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
   	   if(a.getAttribute("rel").indexOf("style") != -1) {
           a.disabled = true;
           if (a.getAttribute("href").indexOf(title) != -1) {
               a.disabled = false;
           }  
       }
   }
   
   setFontCookie(title);
}

function setFontCookie(value){
  var expdate = new Date();
  expdate.setTime(expdate.getTime() + (1000 * 60 * 60 * 24 * 7) );  
  document.cookie = namecookie + "=" + value + "; expires=" + expdate.toGMTString()+"; path=/"; 
}

function getFontCookie(){
  if(document.cookie){
    index = document.cookie.indexOf(namecookie);
      if(index != -1){
        begin = (document.cookie.indexOf("=", index) + 1);
        end = document.cookie.indexOf(";", index);
        if (end == -1){
          end = document.cookie.length;
        }
        value = document.cookie.substring(begin, end);
       
        setActiveStyleSheet(value);
  	  }
	}
}