// Obtain the decoded cookie value
Function getcookieval (offset)
{
VaR endstr = Document. Cookie. indexof (";", offset );
If (endstr =-1)
Endstr = Document. Cookie. length;
Return Unescape (document. Cookie. substring (offset, endstr ));
}
// Set the cookie value
Function setcookie (name, value)
{
VaR expdate = new date ();
VaR argv = setcookie. arguments;
VaR argc = setcookie. Arguments. length;
Alert (argc );
VaR expires = (argc> 2 )? Argv [2]: NULL;
VaR Path = (argc> 3 )? Argv [3]: NULL;
VaR domain = (argc> 4 )? Argv [4]: NULL;
VaR secure = (argc> 5 )? Argv [5]: false;
If (expires! = NULL) expdate. settime (expdate. gettime () + (expires * 1000 ));
Document. Cookie = Name + "=" + escape (value) + (expires = NULL )? "": ("; Expires =" + expdate. togmtstring ()))
+ (Path = NULL )? "": ("; Path =" + path) + (domain = NULL )? "": ("; Domain =" + domain ))
+ (Secure = true )? "; Secure ":"");
}
// Delete the cookie
Function delcookie (name)
{
VaR exp = new date ();
Exp. settime (exp. gettime ()-1 );
VaR cval = getcookie (name );
Document. Cookie = Name + "=" + cval + "; expires =" + exp. togmtstring ();
}
// Obtain the original cookie value
Function getcookie (name)
{
VaR Arg = Name + "= ";
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 getcookieval (j );
I = Document. Cookie. indexof ("", I) + 1;
If (I = 0)
Break;
}
Return NULL;
}