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;
}

function setFontSize(grande) {
	var body = document.getElementsByTagName('body')[0];
	var percentuale = "75%"; // default
	if (grande == 1) percentuale = "50%";
	if (grande == 2) percentuale = "65%";
	if (grande == 3) percentuale = "75%";
	if (grande == 4) percentuale = "90%";
	if (grande == 5) percentuale = "120%";
	body.style.fontSize = percentuale;
	createCookie('GommaLayoutFontSize',grande,365);
}
function setWindowSize(size) {
	var body = document.getElementById('Contenitore');
	var percentuale = "76%"; // default
	if (size == 1) percentuale = "58%";
	if (size == 2) percentuale = "68%";
	if (size == 3) percentuale = "76%";
	if (size == 4) percentuale = "90%";
	if (size == 5) percentuale = "100%";	
	if (size == 6) percentuale = "500px";
	if (size == 7) percentuale = "620px";
	if (size == 8) percentuale = "760px";
	if (size == 9) percentuale = "900px";
	if (size == 10) percentuale = "1100px";
	body.style.width = percentuale;
	createCookie('GommaLayoutWindowSize',size,365);
}
function setBackgroundColor(color) { 
var body=new Array(); 
body[0]=document.getElementById('SottoMenu'); 
body[1]=document.getElementById('XMenu');
body[2]=document.getElementById('BordinoSopra');
body[3]=document.getElementById('BordinoSotto');
body[4]=document.getElementById('Impostazioni');
var background = "#FF6C6C"; // default 
if (color == 1) background = "#D96482";
if (color == 2) background = "#8E4071"; 
if (color == 3) background = "#E21B75"; 
if (color == 4) background = "#FF6C6C";
if (color == 5) background = "#F0B842";
if (color == 6) background = "#89B3FE";
if (color == 7) background = "#4B86E7";
if (color == 8) background = "#5C74C5";
if (color == 9) background = "#A099FF";
if (color == 10) background = "#52A7AD";
if (color == 11) background = "#66CCCC";
if (color == 12) background = "#D7D8C7";
if (color == 13) background = "#E9D0BA";
if (color == 14) background = "#F9E8C8";
for(i=0;i<body.length;i++){ 
body[i].style.backgroundColor = background;
createCookie('GommaLayoutBackgroundColor',color,365); 
} 
}

function setColoreSfondo(colore) { 
var body=new Array(); 
body[0]=document.getElementById('Xh1'); 
body[1]=document.getElementById('Testata'); 
body[2]=document.getElementById('Xh2');
body[3]=document.getElementById('Menu');
var background = "#FF6C6C"; // default 
if (colore == 1) background = "#D96482";
if (colore == 2) background = "#8E4071"; 
if (colore == 3) background = "#E21B75"; 
if (colore == 4) background = "#FF6C6C";
if (colore == 5) background = "#F0B842";
if (colore == 6) background = "#89B3FE";
if (colore == 7) background = "#4B86E7";
if (colore == 8) background = "#5C74C5";
if (colore == 9) background = "#A099FF";
if (colore == 10) background = "#52A7AD";
if (colore == 11) background = "#66CCCC";
if (colore == 12) background = "#D7D8C7";
if (colore == 13) background = "#E9D0BA";
if (colore == 14) background = "#F9E8C8";
for(i=0;i<body.length;i++){ 
body[i].style.backgroundColor = background;
createCookie('GommaLayoutColoreSfondo',colore,365); 
} 
}


function setCarattere(family) {
	var body = document.getElementsByTagName('body')[0];
	var carattere = "verdana"; // default
	if (family == 1) carattere = "verdana";
	if (family == 2) carattere = "arial";
	if (family == 3) carattere = "courier";
	if (family == 4) carattere = "georgia";
	if (family == 5) carattere = "garamond";
	body.style.fontFamily = carattere;
	createCookie('GommaLayoutCarattere',family,365);
}

function setMostraScelte(display) {
	var body = document.getElementById('Impostazioni');
	var visualizza = "none"; // default
	if (display == 1) visualizza = "none";
	if (display== 2) visualizza = "block";
	body.style.display = visualizza;
	createCookie('GommaLayoutMostraScelte',display,365);
}



window.onload = function() {
	grande = readCookie('GommaLayoutFontSize');
	size = readCookie('GommaLayoutWindowSize');
	color = readCookie('GommaLayoutBackgroundColor');
	colore = readCookie('GommaLayoutColoreSfondo');
	family = readCookie('GommaLayoutCarattere');
	display = readCookie('GommaLayoutMostraScelte');
	setFontSize(size);
	setWindowSize(size);
	setBackgroundColor(color);
	setColoreSfondo(colore);
	setCarattere(family);
	setMostraScelte(display);
}