home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CyberMycha 2003 October
/
cmycha200310.iso
/
NHL2004
/
NHL2004Demo.exe
/
fe
/
COMMON
/
js
/
JAX_Cookie.js
< prev
next >
Wrap
Text File
|
2003-08-20
|
2KB
|
74 lines
function JAX_Cookie(document, name, hours)
{
var protect = this.createProtection(JAX_Object);
protect.document = document;
protect.name = name;
if (hours) {
protect.expiration = new Date((new Date()).getTime() + hours*3600000);
} else {
protect.expiration = null;
};
};
JAX_Cookie.prototype = new JAX_Object();
JAX_Cookie.prototype.save = function ()
{
var protect = this.getProtection(JAX_Cookie);
var cookieval = "";
var prop = null;
for(prop in this)
{
if ((typeof this[prop] == 'object') || ((typeof this[prop]) == 'function')) continue;
if (cookieval != "") cookieval += '&';
cookieval += prop + ':' + escape(this[prop]);
};
var cookie = protect.name + '=' + cookieval;
if (protect.expiration) { cookie += '; expires=' + protect.expiration.toGMTString(); };
protect.document.cookie = cookie;
};
JAX_Cookie.prototype.load = function()
{
var protect = this.getProtection(JAX_Cookie);
var allcookies = protect.document.cookie;
if (allcookies == "") return false;
var start = allcookies.indexOf(protect.name + '=');
if (start == -1) return false;
start += protect.name.length + 1;
var end = allcookies.indexOf(';', start);
if (end == -1) end = allcookies.length;
var cookieval = allcookies.substring(start, end);
var a = cookieval.split('&');
for(var i=0; i < a.length; i++) { a[i] = a[i].split(':'); };
for(var i = 0; i < a.length; i++) { this[a[i][0]] = unescape(a[i][1]); };
return true;
}
JAX_Cookie.prototype.destroy = function()
{
var protect = this.getProtection(JAX_Cookie);
var cookie;
cookie = protect.name + '=';
cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
protect.document.cookie = cookie;
};
JAX_Cookie.prototype.getCookieString = function()
{
var protect = this.getProtection(JAX_Cookie);
return unescape(protect.document.cookie);
};
JAX_Cookie.prototype.addItem = function(propName, propValue, saveNow)
{
if ( (typeof propValue != 'function') && (typeof propValue != 'object') ) {
this[propName] = propValue;
if (saveNow) {
this.save();
};
};
};
JAX_Cookie.prototype.deleteItem = function(propName, saveNow)
{
if (this[propName]) {
delete this[propName];
if (saveNow) {
this.save();
};
};
};