﻿var Cookies=
{
	Get:function(Name)
	{
		var p,C,s;
		if(!(C=document.cookie))return null;
		switch(p=C.indexOf(Name+"="))
		{
			case -1:
				return null;
			case 0:
				break;
			case 1:
				if(C.indexOf(";"))
					return null;
				break;
			case 2:
				if(C.indexOf("; "))
					return null;
				break;
			default:
				if((C.substr(p-1,1)!=";")&&(C.substr(p-2,2)!="; "))
					return null;
				break;
		}
		s=C.substr(p+Name.length+1);
		switch(p=s.indexOf(";"))
		{
			case -1:
				return unescape(s);
			case 0:
				return "";
			default:
				return unescape(s.substr(0,p));
		}
	}
	,
	Set:function(Name,Value,DaysOfLife)
	{
		var xDate=null;
		if(DaysOfLife!=null)
		{
			xDate=new Date();
			xDate.setTime(xDate.getTime()+(1000*60*60*24*DaysOfLife));
		}
		document.cookie=Name+"="+escape((Value==null)?"":Value)+(xDate?("; expires"+xDate.toGMTString()):"");
	}
	,
	Delete:function(Name)
	{
		if(Cookies.Get(Name)!=null)
			Cookies.Set(Name,"",-100);
	}
	,
	All:function()
	{
		var C,L=new Array(),v,k,p,n;
		if(!(C=document.cookie))return L;
		v=C.split(";");
		for(k=0;k<v.length;k++)
		{
			s=v[k];
			if((!s.length)||(s==" "))continue;
			if(s.charAt(0)==' ')s=s.substr(1);
			if(!s.length)continue;
			if(!(p=s.indexOf("=")))continue;
			if(p<0)
				L[L.length]=new Cookie(s,null);
			else
				L[L.length]=new Cookie(s.substr(0,p),s.substr(p+1));
		}
		return L;
	}
};

function Cookie(Name,Value)
{
	this.Name=Name;
	this.Value=Value;
}
