// ----------------------------------------------------------- //
//                       localStorage                          //
// ----------------------------------------------------------- //
function localStorage() { this.clear(); }
localStorage.prototype.clear = function()
{
	this.fileName = new String();
}
localStorage.prototype._getRaw = function()
{
	var rawBuff = document.cookie;
	var cookieRegExp = new RegExp("\\b" + this.fileName + "=([^;]*)");
	theValue = cookieRegExp.exec(rawBuff);
	if (theValue != null) { theValue = theValue[1]; }
	return theValue;
}
localStorage.prototype.asArray = function()
{
	var outArr = new Object();
	var rawBuff = this._getRaw(this.fileName);
	if (rawBuff == undefined) { return false; }
	var tempArr = rawBuff.match(/([^&]+)/g);
	for (var i=0; i<tempArr.length; i++)
	{
		var parts = tempArr[i].match(/([^=]+)=(.*$)/);
		var varName = parts[1];
		var varValue = parts[2];
		outArr[varName] = unescape(varValue);
	}
	return outArr;
}
localStorage.prototype.dropFile = function()
{
	if (this.fileName)
	{
		var expiredDate = new Date();
		expiredDate.SetMonth(-1);
		var writeBuff = this.fileName + "=";
		writeBuff += "expires=" + expiredDate.toGMTString();
		document.cookie = writeBuff;
	}
}
localStorage.prototype.dropItem = function(theName)
{
	var rawBuff = readUnEscapedCookie(this.fileName);
	if (rawBuff)
	{
		var stripAttributeRegExp = new RegExp("(^|/&)" + theName + "=[^&]*&?");
		rawBuff = rawBuff.replace(stripAttributeRegExp, "$1");
		if (rawBuff.length != 0)
		{
			var newBuff = this.fileName + "=" + rawBuff;
			document.cookie = newBuff
		} else { this.dropFile(); }
	}
}
localStorage.prototype.enabled = function()
{
	var cookiesEnabled = window.navigator.cookieEnabled;
	if (!cookiesEnabled)
	{
		document.cookie = "cookiesEnabled=True";
		cookiesEnabled = new Boolean(document.cookie).valueOf();
	}
	return cookiesEnabled;
}
localStorage.prototype.retrieveItem = function(theName)
{
	var rawBuff = this._getRaw(this.fileName);
	var extractMultiValueCookieRegExp = new RegExp("\\b" + theName + "=([^;&]*)");
	resValue = extractMultiValueCookieRegExp.exec(rawBuff);
	if (resValue != null) { resValue = unescape(resValue[1]); }
	return resValue;
}
localStorage.prototype.storeItem = function(theName, theValue)
{
	var rawBuff = this._getRaw(this.fileName);
	if (rawBuff)
	{
		var stripAttributeRegExp = new RegExp("(^|&)" + theName + "=[^&]*&?");
		rawBuff = rawBuff.replace(stripAttributeRegExp, "$1");
		if (rawBuff.length != 0) { rawBuff += "&"; }
	} else rawBuff = "";
	
	rawBuff += theName + "=" + escape(theValue);
	document.cookie = this.fileName + "=" + rawBuff;
}
 