/**
 * Creates a cookie with the specified value and expiration.
 *
 * @param   name - the name of the cookie.
 * @param   value - the value of the cookie.
 * @param   days - the expiration date in days from today.
 */
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 var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/**
 * Gets the value of the cookie with the specified name.  If the cookie does not
 * exist, then returns null.
 * 
 * @param   name - the name of the cookie to get.
 * @return  the value of the cookie, or null if it doesn't exist.
 */
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;
}

/**
 * Deletes the specified cookie.
 * 
 * @param   name - the name of the cookie to delete.
 */
function eraseCookie(name) {
	createCookie(name,"",-1);
}
