function CookieJar(sName)
	{
	this.name_cookiejar=sName;
	this.separator_item=";";
	this.separator_keyvalue="=";
	this.cookie_values=null;
	
	// interface
	this.Load=loadvalues; // load values from name_cookiejar
	this.Save=savevalues; // save values from name_cookiejar
	this.Value=getkeyvalue; // sKey
	this.Set=setkeyvalue;   // sKey, sValue	
	
	// Basic functions
	
	this.SetCookie=basicsetcookie; // sName,sValue
	this.GetCookie=basicgetcookie; // sName
	this.getCookieVal=basicgetcookieval; // offset
	
	
function basicgetcookieval (offset) 
   {
   var endstr = document.cookie.indexOf (";", offset);

   if (endstr == -1)      endstr = document.cookie.length;

   return unescape(document.cookie.substring(offset, endstr));
   }

function basicgetcookie (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 this.getCookieVal (j);

      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0)       break; 
      }

   return "";
   }

function basicsetcookie (name, value) 

   {
   t=new Date();   
   t.setTime(t.getTime() +  (24 * 60 * 60 * 1000 * 365)); 	

   var argv = basicsetcookie.arguments;
   var argc = basicsetcookie.arguments.length;
   var expires =  t; // (2 < argc) ? argv[2] : null;
   var path = (3 < argc) ? argv[3] : null;
   var domain = (4 < argc) ? argv[4] : null;
   var secure = (5 < argc) ? argv[5] : false;

	path="/";

   document.cookie = name + "=" + escape (value) +
   	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
     	((path == null) ? "" : ("; path=" + path)) +
     	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");

   }

	
	
	function loadvalues()
		{
		var sCookie=this.GetCookie(this.name_cookiejar);
		if(sCookie=="")
			return;
		if(this.cookie_values==null)
			this.cookie_values=new Array();
			
		var aKV=sCookie.split(this.separator_item);
		var i;
		var kv;
		for(i=0;i<aKV.length;i++)
			{
			kv=aKV[i].split(this.separator_keyvalue);
			this.cookie_values[kv[0]]=kv[1];
			}		
		}
		
	function savevalues()
		{
		if(this.cookie_values==null)
		 	return;
		var i;
		var sCookie="";
		for(i in this.cookie_values)
			{
			if(sCookie!="")
				sCookie+=this.separator_item;
			sCookie+=i;
			sCookie+=this.separator_keyvalue;
			sCookie+=this.cookie_values[i];
			}
		this.SetCookie(this.name_cookiejar,sCookie);
		}
		
	function getkeyvalue(sKey)
		{
		var sValue;
		if(this.cookie_values==null)
			return "";
		return (this.cookie_values[sKey]!=null) ? this.cookie_values[sKey]:"";
		}
		
	function setkeyvalue(sKey, sValue)
		{
		if(this.cookie_values==null)
			this.cookie_values=new Array();
		
		this.cookie_values[sKey]=sValue;
		return true;
		}
	}

