function Cookie(doc, name, days, path, domain, secure) {
 if(!doc)doc=document;
 this.value=new Object();
 if (doc.cookie&&doc.cookie.length>0) {
  var docCookie = '; '+doc.cookie;
  var start = docCookie.indexOf('; ' + name + '=');
	if(start>-1){
   start += name.length+3;
   var end = docCookie.indexOf('; ',start)
   var str;
   if(end==-1)str=docCookie.substring(start);
   else str=docCookie.substring(start,end);
   if(str.indexOf('&')>-1){
    var a = str.split('&');
    for (var i=0;a.length>i;i++){
     var v = a[i].split('=');
     this.value[v[0]] = unescape(v[1]);
    }
   }else{
    var v = str.split('=');
    this.value[v[0]] = unescape(v[1]);
   }
  }
 this._document = doc;
 this._name = name;
 if (days) {this._expires = new Date((new Date()).getTime() + days*24*3600000);}
 else {this._expires=new Date(); this._expires = this._expires.setFullYear(this._expires.getFullYear()+1)}
 if (path) {this._path = path;} else {this._path = '/';}
 this.setDomain(domain);
 if (secure) {this._secure = secure;} else {this._secure = false;}
 }
}

Cookie.prototype.toString=function(){
 var ret='';
 for (var key in this.value) ret += key + '=' + escape(this.value[key]) +  "&";
 return ret.substring(0,ret.length-1);
}

Cookie.prototype.setDomain=function(domain){
 if(domain){this._domain=domain;}
 else{var host=location.host.toLowerCase();this._domain=host.substring(host.search(/[^.]+\.[^.]+$/));}
 return this._domain;
}

Cookie.prototype.put=function(name, value){
 this.value[name] = value;
}

Cookie.prototype.set=function(name, value){
 this.value[name] = value;
}

Cookie.prototype.get=function(name){
 return this.value[name];
}

Cookie.prototype.del=function(name){
 delete this.value[name];
}

//this needs length checking
Cookie.prototype.write=function(){
 this._document.cookie=this._name + "=" +
 this.toString() +
 ((this._expires) ? "; expires=" + (new Date(this._expires)).toGMTString() : "") +
 ((this._path) ? "; path=" + this._path : "") +
 ((this._domain) ? "; domain=" + this._domain : "") +
 ((this._secure) ? "; secure" : "");
}

Cookie.prototype.remove=function(){
 this._document.cookie = this._name + '=; expires=Fri, 02-Jan-1970 00:00:00 GMT' +
 ((this._path) ? "; path=" + this._path : "") + 
 ((this._domain) ? "; domain=" + this._domain : "");
}

function storeInCookie (cookieName) {
 cookie = new Cookie(document, cookieName);
 for (var i=1; arguments[i]; i++) {
  cookie.put(arguments[i],arguments[++i]);
 }
 cookie.write();
}