﻿var FONT_SIZE_COOKIE_NAME = "font_size";
var DEFAULT_FONT_SIZE = "small";
var PRINT_WINDOW_NAME = "printPreview";
var CSS_LOCAL_STYLESHEET = null;
function createLocalStyleSheet()
{
    var head = document.getElementsByTagName( "head" )[0];
    var element = document.createElement( "style" );
    element["type"]="text/css";
    element["title"]="cssLocalStyleSheet";
    head.appendChild( element );
    for( var i = document.styleSheets.length - 1; i >= 0; i-- )
    {
        if( document.styleSheets[i].title == "cssLocalStyleSheet" )
        {
            CSS_LOCAL_STYLESHEET = document.styleSheets[i];
            break;
        }
    }
}
// size = { "small" | "medium" | "large" }
function setFont( size )
{
    if( !CSS_LOCAL_STYLESHEET )
    {
        createLocalStyleSheet();
    }
    if( CSS_LOCAL_STYLESHEET )
    {
        if( CSS_LOCAL_STYLESHEET.addRule ) //IE
        {
            CSS_LOCAL_STYLESHEET.addRule( "body", "font-size:" + size );
        }
        else //FF
        {
            CSS_LOCAL_STYLESHEET.insertRule( "body{font-size:" + size + ";}", CSS_LOCAL_STYLESHEET.cssRules.length );
        }
    }
}
function changeFont( size )
{
    setFont( size );
    createCookie( FONT_SIZE_COOKIE_NAME, size, 365 );
}
function setFontBasedOnCookie()
{
    setFont( typeof(readCookie)=="function" ? readCookie( FONT_SIZE_COOKIE_NAME ) || DEFAULT_FONT_SIZE : DEFAULT_FONT_SIZE );
}
function printPreview()
{
    popUpWindow( location.href, 0, 0, 740, 800, PRINT_WINDOW_NAME );
}
if( window.name != PRINT_WINDOW_NAME )
{
    setFontBasedOnCookie();
}
else
{
    var printCss = "/css/print.css";
    if( typeof( _PCRI_domain ) != "undefined" && _PCRI_domain.length > 0 )
    {
        printCss = 
            ( window.location.protocol == "https:" ? "https://" : "http://" )+ 
            _PCRI_domain + 
            printCss;
    }
    appendStyleSheet( printCss  );
}
