/**************************************************************************************
	Description: Class for storing user defaults via cookies etc...
		  Author: Roarke Lynch
		    Date: 2005-09-22
		   Notes: none
  Dependencies: none
**************************************************************************************/

/* Constructor */
UserDefaults = function(path)
{
	this.path = (typeof(path) == 'undefined' ? "" : path);
}

/* Properties */
UserDefaults.prototype.getPath   = function() { return this.path; }
UserDefaults.prototype.setPath   = function(value) { this.path = value; }

UserDefaults.prototype.get = function(defaultName) 
{
	var pattern = "[;]?\\s*(" + defaultName + ")[=]([^;]*)[;]?";
	var exp = new RegExp(pattern, "i");
	var match = exp.exec(document.cookie);
	
	if(match) {	
		var value = match[2];
		return unescape(value);
	}

	return null;
}

UserDefaults.prototype.set = function(defaultName, value, expirationDate, isSecure)
{
	var cv = (defaultName + "=" + escape(value)) +
			("; expires=" + (expirationDate ? expirationDate.toGMTString() : "")) +
			("; path=" + this.getPath()) +
			(isSecure ? "; secure" : "");
		
	document.cookie = cv;
}

UserDefaults.prototype.clear = function(defaultName)
{
	if(this.get(defaultName))
	{	
		this.set(defaultName, this.getPath(), new Date(0));
	}
}