/*------------------------------------------------------------
	Document  ChangeSizer - copyright 2007 - Gaetano Cafiero.  All rights reserved.
	Based on Text Sizer- Copyright 2003 - Taewook Kang.  All rights reserved.
	Coded by: Gaetano Cafiero 
	
	Please retain this copyright notice in the script.
	License is granted to user to reuse this code on 
	their own website if, and only if, 
	this entire copyright notice is included.
--------------------------------------------------------------*/

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = '; expires='+date.toGMTString();
  }
  else expires = '';
  document.cookie = name+'='+value+expires+'; path=/';
}

function readCookie(name) {
  var nameEQ = name + '=';
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

// Specifica la dimensione di default (a partire da 0!)
var DEFAULT_SIZE = 2;

//Specify spectrum of different font sizes:
var aSize = new Array( '80%', '90%', '100%', '110%', '120%', '140%');

var Size = DEFAULT_SIZE;

function ChangeSize( incSize )
{
	var body = document.getElementsByTagName('body')[0];
	Size += incSize;
  if ( Size < 0 ) Size = 0;
  if ( Size > 5 ) Size = 5;
	body.style.fontSize = aSize[ Size ];
	createCookie('CdPFontSize',Size,365);
}

function ResetSize( )
{
	ChangeSize(DEFAULT_SIZE-Size);
}

function SetSize(sz)
{
	if (sz==null) sz=DEFAULT_SIZE;
	Size = sz;
	ChangeSize( 0 );
}

function InitFontSize()
{
	sz = readCookie('CdPFontSize');
	sz = parseInt(sz);
	if ( isNaN(sz) )
	{
		sz = DEFAULT_SIZE;
	}
	SetSize(sz);
}

function HideWindow()
{
	var body = document.getElementsByTagName('body')[0];
	body.style.visibility = "hidden";
}

function DisplayWindow()
{
	var body = document.getElementsByTagName('body')[0];
	body.style.visibility = "visible";
}


function AddOnload(myfunc)
{
	if (window.addEventListener)
	{
		window.addEventListener('load', myfunc, false);
	}
	else 
	{
		if (window.attachEvent)
		{
			window.attachEvent('onload', myfunc);
		}
	}
}

AddOnload(InitFontSize);
AddOnload(DisplayWindow);
