﻿function CookieClass()
{
    this.expires = 30 ; //day
    this.path = "";
    this.domain = ""; 
    this.secure = false;

    this.setCookie = function(name,value)
    {
        var str = name+"="+escape(value);
        
        if (this.expires>0)
        {
            var date=new Date();
            var ms=this.expires * 24 * 60 * 60 * 1000 ;
            date.setTime(date.getTime()+ms);
            str+="; expires="+date.toGMTString();
        }
      
        if(this.path!="")str+="; path="+this.path;
        if(this.domain!="")str+="; domain="+this.domain; 
        if(this.secure!="")str+="; true"; 
       
        document.cookie=str;
    }

    this.getCookie=function(name)
    {
        var cookieArray=document.cookie.split("; "); 
        var cookie=new Object();
       
        for(var i=0;i<cookieArray.length;i++)
        {
            var arr=cookieArray[i].split("=");
            if(arr[0]==name)return unescape(arr[1]); 
        }
        
        return "";
    }

    this.deleteCookie=function(name)
    {
        var date=new Date();
        var ms= 1 * 1000;
        date.setTime(date.getTime() - ms);
        var str = name+"=no; expires=" + date.toGMTString();
        document.cookie=str;
    }

    this.showCookie=function()
    {
        alert(unescape(document.cookie));
    }
}
