var JSV="1.0";

if (navigator.appName.indexOf("Netscape")==0 && parseInt(navigator.appVersion)>2)
   JSV="1.1";
else
   JSV="1.0";

function Cookie(document, name, hours, path, domain, secure)
{
    this._document = document;
    this._name = name;
    if (hours)
        this._expiration = new Date((new Date()).getTime() + hours*3600000);
    else 
        this._expiration = null;
    if (path) this._path = path; else this._path = null;
    if (domain) this._domain = domain; else this._domain = null;
    if (secure) this._secure = true; else this._secure = false;
}
function _Cookie_store()
{
  var buf="";
  for(var prop in this)
  {
     if ((prop.charAt(0) == '_') || ((typeof this[prop]) == 'function')) 
         continue;     
     if (buf != '')
       buf += '&';
      buf += prop + ":" + escape(this[prop]);
  }
  var buf2 = this._name + '=' + buf ;
  if (this._expiration)
     buf2 += '; expires=' + this._expiration.toGMTString();
  this._document.cookie = buf2;
  //alert("STORE\n"+buf2);
}
function _Cookie_load()
{
  var all = this._document.cookie;
  //if (all =="") alert("A-1");
  if (all =="") return false;
  var start = all.indexOf(this._name+"=");
  //if (start==-1) alert("B-2");
  if (start==-1) return false;
  
  start += this._name.length +1;
  var end= all.indexOf(';',start);
  if (end==-1) end=all.length;
  var cval = all.substring(start,end);

  if (JSV=="1.1")
  {
     var a = cval.split('&');
     //alert("A LENGTH = "+a.length);
     for(var i=0;i<a.length;i++)
       a[i]=a[i].split(':');
  }
  else
    a = stringSplit(cval);

  for(var i=0;i<a.length;i++)
    this[a[i][0]]=unescape(a[i][1]);

  
  return true;
  
}
function _Cookie_remove()
{
    var cookie;
    cookie = this._name + '=';
    if (this._path) cookie += '; path=' + this._path;
    if (this._domain) cookie += '; domain=' + this._domain;
    cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
    //alert(cookie);
    this._document.cookie = cookie;
}


function _Cookie_show()
{
  var buf="";
  for(var prop in this)
     if ((prop.charAt(0) != '_') && ((typeof this[prop]) != 'function')) 
     //if ((typeof this[prop]) != 'function') 
         buf += "\n" + prop + "=" + unescape(this[prop]);
  alert(buf);
}
function _Cookie_show2()
{
  alert(
//"\ndocument = "+this._document.title +
"\nname = "+this._name +
"\nexpire = "+this._expiration +
"\npath = "+this._path +
"\ndomain = "+this._domain +
"\nsecure = "+this._secure +
"\n"
);
}

function stringSplit(buf)
{
  var a = new Array();
  var cnt = 0;

  start=0;
  end=buf.indexOf("&",start);

  while (end != -1)
  {
    sbuf=buf.substring(start,end);
    pos=sbuf.indexOf(":");
    s1=sbuf.substring(0,pos);
    s2=sbuf.substring(pos+1);
    a[cnt]=new Array(s1,s2);
    cnt++;
    start=end+1;
    end=buf.indexOf("&",start);
  }

  sbuf=buf.substring(start);
  pos=sbuf.indexOf(":");
  s1=sbuf.substring(0,pos);
  s2=sbuf.substring(pos+1);
  a[cnt]=new Array(s1,s2);
  cnt++;

  return a;
}

//-----------------


new Cookie();
Cookie.prototype.store = _Cookie_store;
Cookie.prototype.load = _Cookie_load;
Cookie.prototype.remove = _Cookie_remove;
Cookie.prototype.show = _Cookie_show;
Cookie.prototype.show2 = _Cookie_show2;
