// =================================================
// This function saves a value in a specified cookie
// =================================================
function setCookieValue(key, value)
{
	// Definir la date d'expiration du cookie (dans un an)
	var now = new Date();
	var expirationDate = new Date(now.getFullYear()+1, now.getMonth(), now.getDate());
	expirationDate = expirationDate.toGMTString();
	
	// Sauvegarder le cookie
	document.cookie = key + "=" + value + ";expires=" + expirationDate + ";path=/;";
}

// =================================================
// This function returns the value of a cookie
// =================================================
function getCookieValue(key)
{
	var returnedValue = "";

	// The index of the requested key in the cookie
	var cookieKeyBegining = document.cookie.indexOf(key);

	// The requested cookie key exists
	if (cookieKeyBegining != -1)
	{ 
		// Find the begining and the ending of the cookie value
		var cookieValueBegining = document.cookie.indexOf("=", cookieKeyBegining) + 1;
		var cookieValueEnding = document.cookie.indexOf(";", cookieValueBegining);

		// Return the value only if it exists for the specified key
		if (cookieValueBegining != cookieValueEnding)
		{ 
			if (cookieValueEnding != -1) // La valeur demandée n'est pas la dernière du cookie
				returnedValue = document.cookie.substring(cookieValueBegining, cookieValueEnding);
			else // La valeur demandée est la dernière du cookie (pas de ; à la fin)
				returnedValue = document.cookie.substring(cookieValueBegining);
		}
	}

	return returnedValue;
}