/*
 * myCookie v0.2
 * Copyright (C) 2003 by Frank Nägler [gnu-myCookie@naegler.net]
 * This program is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 2 of the License, or 
 * (at your option) any later version. 
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
 * General Public License for more details. 
 * 
 * You should have received a copy of the GNU General Public License along 
 * with this program; if not, write to the Free Software Foundation, 
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 
 *
*/
/*
 * this function is the main function for the cookie object
 * call this function to instance a new object.
 * var c = new myCookie("name", 100, "/", "domain.com");
 * the argumet name is binding, the other are optional
 * @arguments
 * - name  -> the name of the cookie
 * - life  -> the lifetime in days of the cookie
 * - path  -> the path of the cookie
 * - doma  -> the domain of the cookie
 * - valu  -> the value of the cookie
 *
 * @methods:
 * - value -> get or set the value of the cookie
 * - lifetime -> get or set the lifetime of the cookie
 * - destroy -> destroy the cookie
 * - update -> subfunction: update the cookie (don't call directly)
*/
var COOKIEJS = true;
function myCookie(name, life, path, doma)
{
 this.name = arguments[0];
 this.life = arguments[1];
 this.path = arguments[2];
 this.doma = (document.layers)?("."+arguments[3]):(arguments[3]);
 this.valu = "";
 this.value = value;
 this.lifetime = lifetime;
 this.destroy = destroy;
 this.update = update;
 this.valu = value();
}
/*
 * this function get or set the value of the cookie
*/
function value(what)
{
 if (arguments[0])
 {
  this.valu = arguments[0];
  this.update();
 }
 else
 {
  var start = document.cookie.indexOf(this.name+"=");
  var len = start+this.name.length+1;
  if ((!start) && (this.name != document.cookie.substring(0,this.name.length))) return null;
  if (start == -1) return null;
  var end = document.cookie.indexOf(";",len);
  if (end == -1) end = document.cookie.length;
  this.valu = unescape(document.cookie.substring(len,end));
  return (this.valu == "undefined")?("[NO COOKIE]"):(this.valu);
 }
}
/*
 * this function get or set the lifetime of the cookie
*/
function lifetime(which)
{
 if (arguments[0])
 {
  this.life = arguments[0];
  this.update();
 }
 else
 {
  return (this.life == "")?("[NO LIFETIME SET]"):(this.life);
 }
}
/*
 * this function destroy the cookie
*/
function destroy()
{
 this.life = 0;
 this.update();
}
/*
 * this function is a subfuction witch is called
 * from other methods of this object and update the cookie
 * !!! don't call this function directly !!!
*/
function update()
{
 var date = new Date();
 date.setTime(date.getTime()+(this.life*24*60*60*1000));
 document.cookie = this.name + "=" +escape(this.valu) +
 ( (this.life) ? (";expires=" + date.toGMTString()) : ("") ) +
 ( (this.path) ? (";path=" + this.path) : ("") ) +
 ( (this.doma) ? (";domain=" + this.doma) : ("") );
}