
	/**
	 * @file Cookie Managment Library [Kitchen]
	 */
	
	/**
	 * Sets/adds a cookie to the document.cookies collection
	 * @param String name The name of the cookie. Required.
	 * @param String value The value of the cookie. Required.
	 * @param String expires An expression, signifying the expires property of the cookie. See <code>dateCalc</code>. Optional.
	 * @param String domain The domain property of the cookie. Optional.
	 * @param Boolean secure The secure property of the cookie. Optional.
	 * @return String The value of the cookie that has just been set.
	 */
	function setCookie(name, value, expires, domain, path, secure)
	{
		var cookie = name + "=" + escape(value);

		if (expires) cookie += "; expires=" + dateCalc(expires);
		if (domain)  cookie += "; domain="  + domain;
		if (path)    cookie += "; path="    + path;
		if (secure)  cookie += "; secure=true";

		document.cookie = cookie;

		return getCookie(name);
	}

	/**
	 * Returns a cookie with the specified name from the document.cookies collection, if present,
	 * and a <code>null</code> if not.
	 * @param String name The name of the cookie. Required.
	 * @return String|null The value of the cookie, if found, and a <code>null</code> otherwise.
	 */
	function getCookie(name)
	{
		var cookies = document.cookie.split("; ");
		for (var i = 0; i < cookies.length; i++)
		{
			var cookieName  = cookies[i].substring(0, cookies[i].indexOf("="));
			var cookieValue = cookies[i].substring(cookies[i].indexOf("=") + 1, cookies[i].length);
			if (cookieName == name)
			{
				if (cookieValue.indexOf("&") != -1)
				{
					var pairs  = strValue.split("&");
					var cookie = new Object();
					for (var i in pairs)
					{
						var arrTemp = pairs[i].split("=");
						cookie[arrTemp[0]] = arrTemp[1];
					}
					return cookie;
				}
				else
					return checkValue(unescape(cookieValue));
			}
		}
		return null;
	}

	/**
	 * Deletes a cookie with the specified name from the document.cookies collection, by setting its expires property
	 * to the current date [expire now].
	 * @param String name The name of the cookie. Required.
	 */
	function deleteCookie(name)
	{
		var objDate = new Date();
		document.cookie = name + "=null; expires=" + objDate.toGMTString();
	}

	function checkValue(strValue)
	{
		var strTest = '' + strValue;
		if (strTest == '' || strTest == 'null' || strTest == 'undefined' || !strTest.match(/[a-zA-Z0-9_]/))  
		{
			return null;
		}
		return strValue;
	}

	function dateCalc(strTime)
	{
		var objDate = new Date();
		var objMult = new Object();
		var intOffset;
		objMult['s'] = 1000*1;
		objMult['m'] = 1000*60;
		objMult['h'] = 1000*60*60;
		objMult['d'] = 1000*60*60*24;
		objMult['M'] = 1000*60*60*24*30;
		objMult['y'] = 1000*60*60*24*365;

		if (!strTime || (strTime == '') || (strTime.toLowerCase() == 'now')) 
		{ // this will set the time calc to now
			intOffset = 0;
		}
		else if ( arrMatches = strTime.match( /^([+-]?(\d+|\d*\.\d*))([mhdMy]?)/ ) ) 
		{ // perform calculation if strTime matches specification
			intOffset = objMult[arrMatches[3]] * arrMatches[2];
		} 
		else 
		{ // otherwise assume that we're providing the date ourselves so just return original
			return strTime;
		}
		objDate.setTime(objDate.getTime() + intOffset);
		return (objDate.toGMTString());
	}


