//*********************************************************************************
// Title: 				getCookieValue
// Desc: 				Get cookie values for a given cookie
// Created : 			July 31, 2002
// Last Modified: 		Sept 23, 2002
// Accepts:				cookieName - Name of the cookie.
// Returns:				The cookie value(s).
//*********************************************************************************
function getCookieValue(cookieName){
	var cookieValue = document.cookie;
	var cookieStartsAt = cookieValue.indexOf(" " + cookieName + "=");
	
	// check if cookie exists.  If cookie does not exist, do a second check at the beginning of the string
	if (cookieStartsAt == -1){
		cookieStartsAt = cookieValue.indexOf(cookieName + "=");
	}
	
	if (cookieStartsAt == -1){
		// coookie really does not exist
		cookieValue = null;
	}else{
		cookieStartsAt = cookieValue.indexOf("=", cookieStartsAt) + 1;
		var cookieEndsAt = cookieValue.indexOf(";", cookieStartsAt);
		if (cookieEndsAt == -1){
			// cookie is the last one in the string
			cookieEndsAt = cookieValue.length;
		}
		cookieValue = unescape(cookieValue.substring(cookieStartsAt, cookieEndsAt));
	}
	return cookieValue;
}

//*********************************************************************************
// Title: 				setCookie
// Desc: 				Get cookie values for a given cookie
// Created : 			July 31, 2002
// Last Modified: 		Sept 23, 2002
// Accepts:				cookieName - Name of the cookie.
// 						cookieValue - Cookie value(s).
// 						cookiePath - Path cookie is valid for.
// 						cookieExpires - Expriy date/time of the cookie.
// Returns:				
//*********************************************************************************
function setCookie(cookieName, cookieValue, cookiePath, cookieExpires){
	cookieValue = escape(cookieValue);
	
	if (cookieExpires == ""){
		var nowDate = new Date();
		nowDate.setMonth(nowDate.getMonth() + 1);
		cookieExpires = nowDate.toGMTString();
	}
	
	if (cookiePath != ""){
		cookiePath = ";Path=" + cookiePath;
	}
	
	document.cookie = cookieName + "=" + cookieValue + ";expires=" + cookieExpires + cookiePath;
}