function cookiejar (jarname) {
	this.jar = "";
	this.jarname = jarname;
	this.expiration = 1 * 365 * 24 * 60 * 60 * 1000;
	this.divider = "#";
	this.divider2 = ":";
	this.path = null;
	this.domain = null;
	this.secure = false;

	this.doesExist = c_doesExist;	
	this.delCookie = c_delCookie;
	this.setCookie = c_setCookie;
	this.getCookie = c_getCookie;
	this.read	= c_read;
	this.write = c_write;
	this.reset = c_reset;
	this.setExpiration = c_setExpiration;
	
	this.read();
}

function c_doesExist(c_id) {	
	if (c_id == "") return false;
	return this.jar.indexOf(escape(c_id) + this.divider2);
}

function c_delCookie(c_id) {	
	exists = this.doesExist(c_id);
	if (exists == -1) return false;
	
	var end = this.jar.indexOf(this.divider,exists);
	if (end == -1)
		end = this.jar.length
	else
		end;

	this.jar = this.jar.substring(0,exists-1) + this.jar.substring(end,this.jar.length);
		
	return true;
}
		
		
function c_setCookie(c_id, c_value) {	
	this.delCookie(c_id);
	this.jar += this.divider + escape(c_id) + this.divider2 + escape(c_value) ;
	return true;
}

function c_getCookie(c_id) {	
	exists = this.doesExist(c_id);
	if (exists == -1) return null;
	
	tempjar = this.jar.substring(exists,this.jar.length);

	var end = tempjar.indexOf(this.divider);
	if (end == -1)
		end = tempjar.length
	
	tempjar = tempjar.substring(0,end);

	var tempArr = tempjar.split(this.divider2);

	if (unescape(tempArr[0]) != c_id)
		return null;

	return unescape(tempArr[1]);		
}

function c_read() {
  var dc = document.cookie;
  var prefix = this.jarname + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return "";
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  this.jar =  unescape(dc.substring(begin + prefix.length, end));

  return true;
}

function c_reset() {
	this.jar = "";
	this.write();
}


function c_write() {
	var dateObj = new Date();
	dateObj.setTime(dateObj.getTime() + this.expiration);

	var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
       dateObj.setTime(dateObj.getTime() - skew);

	document.cookie = this.jarname + "=" + escape(this.jar) +
				"; expires=" + dateObj.toGMTString() + 
				  ((this.path == null)   ? "" : "; path=" + this.path) +
				  ((this.domain == null) ? "" : "; domain=" + this.domain) +
				  ((this.secure) ? "; secure" : "");

	return true;
}

function c_setExpiration(years, days, mins, secs, mill) {
	 this.expiration = (years * 365 * 60 * 60 * 1000) +
	  				   (days * 60 * 60 * 1000) +
					   (mins * 60 * 1000 ) +
					   (secs * 1000) + mill;
}