
function Cookie(document,name,hours,path,domain,secure){
  this.$document=document;
  this.$n = name;
//   if (hours){this.$e=new Date(new Date().getTime() + hours*3600000);} else {this.$e = null;}
  if (path) {this.$p=path;} else {this.$p=null;}
  if (domain) {this.$d=domain;} else {this.$d=null;}
  if (secure) {this.$s=secure;} else {this.$s=false;}
  this.$skip =0;
}

var _Cookie_WARNED=0;

function _Cookie_store(){
  if (this.$skip) return;
  var cv =new String("");
  for (var p in this){
    if ((p.charAt(0) == '\$') 
 	|| (typeof(this[p]) == 'function')
 	|| p==0
	|| !p) continue;
    
    if (cv != "") {cv += '&';}
    cv += p + '&' + escape(this[p]);
  }
  
  cv = cv.replace(/%20/g,' ');
  
  var c = new String(this.$n + '=' + cv);
  if (this.$e) {c += '; expires=' + this.$e.toGMTString()}
  if (this.$p) {c += '; path=' + this.$p;}
  if (this.$d) {c += '; domain=' + this.$d;}
  if (this.$s) {c += '; secure'};

  if (c.length>4096 && !_Cookie_WARNED) {
    alert("Warning: The data is larger than the alloted memory ("+c.length+">4096). Data will be lost on transmission.\nPlease reduce the number of changes or lines.");
   _Cookie_WARNED =1;
}	

  this.$document.cookie = c;
}

function _Cookie_display(){
  var cv ="";
    for (var p in this){
      //      if ((p.charAt(0) == '\$') || 
      if ((typeof(this[p]) == 'function')
 	|| p==0
	|| !p) continue;
      cv += '['+ p + ':' + escape(this[p]) +']\n';
    }
  alert("Cookie: "+this.$n+"\n"+cv);
}

function _Cookie_load() {
  var ac = this.$document.cookie;
  
  if (ac == "") {return false;}
  var s = ac.indexOf(this.$n +'=');
 
  if (s == -1) {return false};

  s = s+this.$n.length+1;
  var e = ac.indexOf(';',s);
  if (e == -1) e = ac.length;
  var cv = ac.substring(s,e);  

  var a = cv.split('&');
  for (var i=0; i<a.length; i+= 2){
    var j = i-(-1)
    this[a[i]]=unescape(a[j]);
  }
  return a.length;
}

function _Cookie_remove(){
  var c;
  c = this.$n + '=';
  if (this.$p) {c += ';path='+this.$p;}
  if (this.$d) {c += ';domain=' + this.$d;}
  c += '; expires= fri, 02-jan-1970 00:00:00 GMT';
  this.$document.cookie=c;
}

new Cookie();
Cookie.prototype.store = _Cookie_store;
Cookie.prototype.display = _Cookie_display;
Cookie.prototype.load = _Cookie_load;
Cookie.prototype.remove = _Cookie_remove;

function Cookie_domain() {
  var z = new String(document.URL);
  var domain = '/';
  return domain;
}
