	
	// Return the given cookie's value if exists, else - null
	function getCookieValue(cName) {
		var allCookies = document.cookie;
		var cNameEquals = cName + "=";

		var i = allCookies.indexOf(cNameEquals);	// E.G.: search for "cookieName=" and return its index

		if (i != -1) {
			var j = i + cName.length;
			var withoutFirstCookieName = allCookies.substr(j);

			var cookieData;
			var k = withoutFirstCookieName.indexOf(";");

			if (k != -1) 			// There is at least one ";" (more than one cookie)
				cookieData = withoutFirstCookieName.substr(1,k-1);
			else
				cookieData = withoutFirstCookieName.substr(1);

			var cookieDataLen = cookieData.length;
			return cookieData.substr(1,cookieDataLen-2);		// Return the found cookie value (without the quotes)
		}
		else
			return null;		// No cookie found
	}



	// Add a cookie with the given name and value
	function addCookie(cookieName, openingPageId, nExpTimeMin) {
		var exp = new Date();
		if (nExpTimeMin==null)
			nExpTimeMin= 60 * 24 * 300;
		var hourFromNow = exp.getTime() + 1000 * 60 * nExpTimeMin;
		exp.setTime(hourFromNow);

		document.cookie = cookieName + "='" + openingPageId + "'; expires=" + exp.toGMTString();
	}


	// Add a cookie with the given name and value
	function addTempCookie(cookieName, cookieValue) {
		document.cookie = cookieName + "='" + cookieValue + "'";
	}

	
