// Some portions Copyright (c) 1996-1997 Athenia Associates.
// http://www.webreference.com/js/
// License is granted if and only if this entire
// copyright notice is included. By Tomer Shiran.

function GetJBCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) { endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));
}

function GetJBCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			return GetJBCookieVal (j);
			}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
		}
	return null;
}

function DeleteJBCookie (name,path,domain) {
	if (GetJBCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function SetJBCookie (name,value,expires,path,domain,secure) {
	var curCookie = name + "=";
	curCookie = curCookie + escape(value);
	curCookie = curCookie + ((expires) ? ";expires=" + expires.toGMTString() : "");
	curCookie = curCookie + ((path) ? ";path=" + escape(path) : "");
	curCookie = curCookie + ((domain) ? ";domain=" + escape(domain) : "");
	curCookie = curCookie + ((secure) ? ";secure" : "");
	document.cookie = '' + curCookie;
}