// Cookie functions
// Global var
var gbl_cookie_usr_name = "usr_alert_choice";
var gbl_cookie_usr_value = "noalert";
// Detecting
function detectCookies() {
	// Testing a normal cookie set/gets
	var value_set = "none";
	var value_get;
	// Setting
	insertCookie("trial", value_set, 0);
	// Getting
	value_get = getCookie("trial");
	// Process
	if (value_get != null) {
		return (true);
	} else {
		return (false);
	}
}
// Inserts a cookie
function insertCookie(name, value, expires_date) {
	// Note, expires date must contain a number that indicates the number of days where he cookie will remain on the system
	var cookie_value = escape(value);
	var cookie_expdate = new Date();
	// Date arrangement
	if (cookie_expdate.getMonth() + expires_date > 12) {
		cookie_expdate.setMonth(12);
	} else {
		cookie_expdate.setMonth(cookie_expdate.getMonth() + expires_date);
	}
	// Ready to insert
	document.cookie = name + "=" + cookie_value + "; expires=" + cookie_expdate.toGMTString() + "; path=/; domain=www.dantealighieri.it;";
}
// Gets a cookie
function getCookie(name) {
	var cookie_value = document.cookie;
	var start_point = -1;
	var end_point = -1;
	start_point = cookie_value.indexOf(" " + name + "=");
	// If blank init fails, try this
	if (start_point == -1) {
		start_point = cookie_value.indexOf(name + "=");
	}
	// Check now
	if (start_point == -1) {
		// Nothing to do
		return (null);
	} else {
		// Mitsuketa
		start_point = cookie_value.indexOf("=", start_point); /* In the substring found, from the index found */
		end_point = cookie_value.indexOf(";", start_point); /* Set the end point */
		// If there is no end, the end is the length of the string
		if (end_point == -1) {
			end_point = cookie_value.length;
		}
		// Now extract
		return (unescape(cookie_value.substring(start_point, end_point)));
	}
}
// Specific designed for pages of DanteAlighieri
function warn_cookie() {
	var span = document.getElementById("warn_cookie");
	var imm = document.getElementById("imm_warn_cookie");
	var val = detectCookies();
	switch (val) {
		case true: val = "abilitati"; imm.style.display = "none"; break;
		case false: val = "disabilitati "; imm.style.display = "inline";
	}
	span.firstChild.nodeValue = val;
}