function setCookie(sValore) {

  var sNome = "compare";
  var iGiorni = 3;	

  var dtOggi = new Date()
  var dtExpires = new Date()
  dtExpires.setTime
    (dtOggi.getTime() + 24 * iGiorni * 3600000)
	
	 if (sValore == '0'){	
  		document.cookie = sNome + "=" + "0,0,0" +"; expires=" + dtExpires.toGMTString();
		} else {
	 
	 var valore = getCookie();
	 var valoreSPLIT = valore.split(",");
	 var aa = 0;
	 var nVal = "";

	 	if(valoreSPLIT[0] == 0 ){ 
		nVal = sValore+","+valoreSPLIT[1]+","+valoreSPLIT[2];
		var aa = 1;  
		}
		else if(valoreSPLIT[1] == 0 && aa == 0){ 
		nVal = valoreSPLIT[0]+","+sValore+","+valoreSPLIT[2];
		var aa = 1; 
		}
		else if(valoreSPLIT[2] == 0 && aa == 0){ 
		nVal = valoreSPLIT[0]+","+valoreSPLIT[1]+","+sValore;
		var aa = 1; 
		}
		
		else { 
		nVal = valoreSPLIT[0]+","+valoreSPLIT[1]+","+valoreSPLIT[2];
		alert ("You can compare only 3 products.\nPlease deselect a product to add another.");
		}

	 	document.cookie = sNome + "=" + escape(nVal) +"; expires=" + dtExpires.toGMTString();	
	 
	 }
	 	 
	 var valore2 = getCookie();
	 Compare_div(valore2);
}

function getCookie() {
  var sNome = "compare";
  var asCookies = document.cookie.split(";");
  for (var iCnt = 0; iCnt < asCookies.length; iCnt++)
  {
    var asCookie = asCookies[iCnt].split("=");
    if (sNome == asCookie[0]) { 
      return (unescape(asCookie[1]));
    } else {
		setCookie("0");
	}
  }
  return("");
}

function checkCookie() {
  var sNome = "compare";
  var asCookies = document.cookie.split(";");
  
  alert (asCookies.length);
  
  for (var iCnt = 0; iCnt < asCookies.length; iCnt++)
  {
    var asCookie = asCookies[iCnt].split("=");
    if (sNome == asCookie[0]) { 
      var alfa = (unescape(asCookie[1]));
	  Compare_div(alfa);
    } else {
		setCookie("0");
	}
  }
  return("");
}


function DeleteCookie () {
var sNome = "compare";	
var exp = new Date();
exp.setTime (exp.getTime() - 1);
document.cookie = sNome + "=0,0,0;expires=" + exp.toGMTString();
return "cancellato";
}

function delCookie(sValore) {

  var sNome = "compare";
  var iGiorni = 3;	

  var dtOggi = new Date()
  var dtExpires = new Date()
  dtExpires.setTime
    (dtOggi.getTime() + 24 * iGiorni * 3600000)
	
	 if (sValore == '0'){	
  		document.cookie = sNome + "=" + "0,0,0" +"; expires=" + dtExpires.toGMTString();
		} else {

	 var valore = getCookie();
	 var valoreSPLIT = valore.split(",");
	 var aa = 0;
	 var nVal = "";
 
	 	if(valoreSPLIT[0] == sValore){ 
		nVal = "0,"+valoreSPLIT[1]+","+valoreSPLIT[2];
		var aa = 1;  
		}
		else if(valoreSPLIT[1] == sValore){ 
		nVal = valoreSPLIT[0]+",0,"+valoreSPLIT[2];
		var aa = 1; 
		}
		else if(valoreSPLIT[2] == sValore){ 
		nVal = valoreSPLIT[0]+","+valoreSPLIT[1]+",0";
		var aa = 1; 
		}
		
		else { nVal = valoreSPLIT[0]+","+valoreSPLIT[1]+","+valoreSPLIT[2]; }
		
	 	document.cookie = sNome + "=" + escape(nVal) +"; expires=" + dtExpires.toGMTString();
		
		var valore2 = getCookie();
		
		Compare_div(valore2);
		
	 }
}