function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) { endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));
}

// primary function to retrieve cookie by name

function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) { return getCookieVal(j); }
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	
	return "";
}

function setStyleHome(){
	style = "Home";

	//alert(style);
	
	if (navigator.userAgent.indexOf("MSIE") != -1) {
		var cssFile = "IE6.css";
	}
	else{var cssFile = ".css"}
	
	//alert(navigator.userAgent);
	
	//alert(style+cssFile);
	
	document.getElementById("defaultStyle").href = style + cssFile;	
			
	return;
}

function setStyle(dir){
	var skin = getCookie("skin"); if (skin) { style = unescape(skin); } else { style = "Invernale"; }
	
	//alert(style);
	
	if (navigator.userAgent.indexOf("MSIE") != -1) {
		document.getElementById("defaultStyle").disabled= false;
		document.getElementById("defaultStyleSafari").disabled= true;
	}
	else{document.getElementById("defaultStyle").disabled= true;
	document.getElementById("defaultStyleSafari").disabled= false;}	
	
	return;
}

function setStyleSheet(){
	popup = document.getElementById("stili");
	sel = popup.selectedIndex;
	val = popup.options[sel].value;
	
	// setto lo stile a seconda del browser
	if (navigator.userAgent.indexOf("MSIE") != -1){
		var cssFile = "IE6.css";
	}
	else{var cssFile = ".css"}
	cssFile = ".css";
	
	alert(val+cssFile);
	document.getElementById("defaultStyle").href = val + cssFile;
	
	createCookie("skin", val, 365);
	
}

function createStylesPopup(){
	
	popup = document.getElementById("stili");
	popup.length = 3;
	popup.options[2].text = "Spartano";
	popup.options[2].value = "old";
	
	var skin = getCookie("skin"); if (skin) { stileAttivo = unescape(skin); } else { stileAttivo = "Classico"; }
	
	for(i=0;i<popup.length;i++){
		if (popup.options[i].value == stileAttivo) {popup.selectedIndex = i; break;}
	}
	
}


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;
}

loadedStyle = "true";

stile=setStyle();