/* Copyright HoangKC */
CookieHelper=function(name,value,path,expires,domain,secure)
{
    var exp=new Date();
    exp.setMonth(exp.getMonth()+6);
    this.Name=name;
    this.Value=value||"";
    this.Path=path;
    this.Expires=expires||exp;
    this.Domain=domain;
    this.Secure=secure;
};
CookieHelper.MaxSize=4000;
CookieHelper.prototype=
{
    toString:function()
    {
        return this.Value;
    },
    getValue:function(start)
    {
        var end=document.cookie.indexOf(";",start);
        if(end== -1)end=document.cookie.length;
        var cookie=document.cookie.substring(start,end);
        if(cookie=="")return null;
        else return unescape(cookie);
    },
    Get:function()
    {
        var arg=this.Name+"=";
        var alen=arg.length;
        var clen=document.cookie.length;
        var value=null;
        var i=0;
        while(i<clen)
        {
            var j=i+alen;
            if(document.cookie.substring(i,j)==arg)
            {
                this.Value=this.getValue(j);
                value=this.Value;
                break;
            }
            i=document.cookie.indexOf(" ",i)+1;
            if(i==0)break;
        }
        return value;
    },
    Set:function(value)
    {
        this.Value=value;
    },
    Add:function(value,before)
    {
        if(before)this.Value=value+this.Value;
        else this.Value+=value;
    },
    Save:function()
    {
        var newCookie=this.Name+"="+escape(this.Value)+((this.Expires==null)?"":("; expires="+this.Expires.toGMTString()))+((this.Path==null)?"":("; path="+this.Path))+((this.Domain==null)?"":("; domain="+this.Domain))+((this.Secure==true)?"; secure":"");
        if(newCookie.length>CookieHelper.MaxSize)throw Error("CookieHelper length was "+newCookieHelper.length+"kb but CookieHelpers cannot exceed "+CookieHelper.MaxSize+"kb");
        document.cookie=newCookie;
    },
    Delete:function()
    {
        var exp=new Date();
        exp.setTime(exp.getTime()-1);
        //document.cookie=this.Name+"=;expires="+exp.toGMTString();
        document.cookie=this.Name+"=;expires="+exp.toGMTString()+((this.Path==null)?"":("; path="+this.Path))+((this.Domain==null)?"":("; domain="+this.Domain))+((this.Secure==true)?"; secure":"");
    }
};