<!--
// SCRIPT TO SET UP COOKIE AND CRUMB FUNCTIONS
// (SET, GET & DELETE):
//
// SET, GET & DELETE COOKIE FUNCTIONS:
// Function to create a cookie and set it's value
function setCookie(name, value, expires) {
	document.cookie = escape(name) + "=" + escape(value) + "; path=/" + 
		((expires == null) ? "" : "; expires=" + expires.toGMTString());
}
// Function to retireve a cookie's value
function getCookie(name) {
	var cookiename = name + "=";
	var dc = document.cookie;
	var begin, end;

	if (dc.length > 0) {
		begin = dc.indexOf(cookiename);
		if (begin != -1) {
			begin += cookiename.length;
			end = dc.indexOf(";", begin);
			if (end == -1) {
			end = dc.length;
			}
			return unescape(dc.substring(begin, end));
			}
		}
		return null;
}
// Function to delete a cookie
function deleteCookie(name) {
document.cookie + name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path/";
}
// SET, GET & DELETE CRUMB FUNCTIONS
// Function to set a crumb value in the cookie
function setCrumb(cookie, name, value) {
	var cookievalue = getCookie(cookie);
	var crumbvalue = getCrumb(name);
	var crumbname = name + "=";

	if (crumbvalue != null) {
		var start = cookievalue.indexOf(crumbname);
			if (start != -1) {
			var end = cookievalue.indexOf('|', start);
			setCookie(cookie, cookievalue.substring(0, start) + crumbname + value + '|' + cookievalue.substring(end + 1, cookievalue.length), exp);
			}
	}
	else {
		if (cookievalue != null) {
			cookievalue += crumbname + value + '|';
		}
		else {
			cookievalue = crumbname + value + '|';
		}
		setCookie(cookie, cookievalue, exp);
	}
}

// Function to get a crumb value from the cookie
function getCrumb(cookie, name) {
	var crumbname = name + '=';
	var cookievalue = getCookie(cookie);
	
	if (cookievalue != null) {
		var start = cookievalue.indexOf(crumbname);
		if (start != -1) {
			start += crumbname.length;
			var end = cookievalue.indexOf('|', start);
			if (end != -1) {
				return unescape(cookievalue.substring(start, end));
			}
		}
	}
	return null;
}

// Function to delete a crumb from the cookie
function deleteCrumb(cookie, name) {
	var cookievalue = getCookie(cookie);
	var crumbvalue = getCrumb(name);
	var crumbname = name + "=";

	if (crumbvalue != null) {
		var start = cookievalue.indexOf(crumbname);
		var end = cookievalue.indexOf('|', start);
		setCookie(cookie, cookievalue.substring(0, start) + cookievalue.substring(end + 1, cookievalue.length), exp);
	}
}
// -->