/* $Workfile:: cookies.js   $ $Revision:: 1   $ $Modtime:: 13/05/04 16:23 $ */
function Cookie( pnombre)
{
	this.fecha = new Date();
	this.expira = new Date(this.fecha.getTime() + 24 * 3600000 * 365);
	this.path = null;
	this.dominio = null;
	this.segura = false;
	this.nombre = pnombre;
} 


Cookie.getCookieVal = function(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) { endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));
	}

Cookie.getCookie = function() {
	var arg = this.nombre + "=";
	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.getValor (j);
			}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
		}
	return null;
	}

Cookie.deleteCookie = function() {
	if (this.getCookie(this.nombre)) {
		document.cookie = this.nombre + "=" +
		((this.path) ? "; path=" + this.path : "") +
		((this.dominio) ? "; domain=" + this.dominio : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
		}
	}

Cookie.setCookie = function(value) {
  document.cookie = this.nombre + "=" + escape (value) +
    ((this.expira) ? "; expires=" + this.expira.toGMTString() : "") +
    ((this.path) ? "; path=" + this.path : "") +
    ((this.dominio) ? "; dominio=" + this.dominio : "") +
    ((this.segura) ? "; secure" : "");
	}




Cookie.getNames = function()
{
	var separator = "; ";
	var equals = "=";
	var clen = document.cookie.length;
	var names = new Array();
	var i = 0;
	while (i < clen) {
		var j = document.cookie.indexOf(equals,i);
		names[names.length] = document.cookie.substring(i, j);
		
		i = document.cookie.indexOf(separator, i);
		if(i==-1)
		{
			break
		}
		else
		{
			if(i<j)
			{
				names[names.length-1] = names[names.length-1].substring(0, names[names.length-1].indexOf(separator));
			}
			i+=separator.length;
		};
	}
	return names
}

Cookie.getCookies = function()
{
	var names = Cookie.getNames();
	for(var i = names.length; i >0;)
	{
		i--;
		names[i] = new Cookie(names[i]);
	}
	return names;
}

Cookie.prototype.getValor = Cookie.getCookieVal;
Cookie.prototype.getCookie = Cookie.getCookie;
Cookie.prototype.deleteCookie = Cookie.deleteCookie;
Cookie.prototype.setCookie = Cookie.setCookie;
Cookie.prototype.getNames = Cookie.getNames;
Cookie.prototype.getCookies = Cookie.getCookies;