﻿/*
 * Copied from "Beginning JavaScript", 3rd Edition
 * Changed it
 */
function setCookie(cookieName, cookieValue, cookiePath)
{
	cookieValue = encodeURI(cookieValue);
	if (cookiePath != "")
	{
		cookiePath = ";Path=" + cookiePath;
	}
	//alert("setting cookie: " + cookieValue);
	document.cookie = cookieName + "=" + cookieValue + cookiePath;
	//alert("cookie is set: " + cookieValue);
}

/*
 * Copied from "Beginning JavaScript", 3rd Edition
 * Added a comment that can be useful for debugging when commented in.
 */
function getCookieValue(cookieName)
{
	var cookieValue = document.cookie;
	var cookieStartsAt = cookieValue.indexOf(" " + cookieName + "=");
	if (cookieStartsAt == -1)
	{
		cookieStartsAt = cookieValue.indexOf(cookieName + "=");
	}
	if (cookieStartsAt == -1)
	{
		cookieValue = null;
	}
	else
	{
		cookieStartsAt = cookieValue.indexOf("=", cookieStartsAt) + 1;
		var cookieEndsAt = cookieValue.indexOf(";", cookieStartsAt);
		if (cookieEndsAt == -1)
		{
			cookieEndsAt = cookieValue.length;
		}
		cookieValue = decodeURI(cookieValue.substring(cookieStartsAt,
		cookieEndsAt));
	}
	//alert("got cookie: " + cookieValue);
	return cookieValue;
}
