
/*
Script by RoBorg
RoBorg@geniusbug.com
http://javascript.geniusbug.com
Please do not remove or edit this message
*/



c = new Cookie();


/*
//c.erase();

c.setExpires(new Date(new Date().getTime() + 99999));
c.setValue('moo', 'cow');
c.setValue('moo2', 'cow2');

//Get using parse
c.parse();
alert(moo);

//Get using getValue
alert(c.getValue('moo'));

//Get using getCookieAsArray
x = c.getCookieAsArray();
for(var i in x) alert(i + '\n' + x[i]);
*/



function Cookie()
{



	//Public properties
	this.isSet = (document.cookie.toString().length != 0);
	this.isEnabled = navigator.cookieEnabled;


	//Private properties
	this.expires = new Date();
	this.path = '';
	this.domain = '';
	this.isSecure = false;


	//Public methods
	this.getIsSet = function() { return (document.cookie != ""); }
	this.setExpires = function(date) { this.expires = date; }
	this.setPath = function(path) { this.path = path; }
	this.setDomain = function(domain) { this.domain = domain; }
	this.setSecure = function(secure) { this.isSecure = secure; }


	this.erase = function()
	{
		this.setExpires(new Date(new Date().getTime() - 1000000));
		var cArr = this.getCookieAsArray();
		for(var i in cArr) this.setValue(i, '');

		document.cookie = '';
	}


	this.parse = function()
	{
		var cValues = this.getCookieAsArray();
		for(var i in cValues) eval(i + ' = unescape("' + cValues[i] + '");');
	}


	this.getValue = function(name)
	{
		var cValues = this.getCookieAsArray();
		return cValues[name];
	}


	this.setValue = function(name, value) { document.cookie = name + '=' + escape(value) + '; ' + this.getCookieSettings(); }


	this.getCookieAsArray = function()
	{
		if(!document.cookie.toString().length) return new Array();

		cArr = document.cookie.toString().split('; ');
		var cookieArray = new Array();
		for(var x=0; x<cArr.length; x++)
		{
			if(!cArr[x].length) continue;
			cArr[x] = cArr[x].split("=");
			cookieArray[cArr[x][0].toString()] = unescape(cArr[x][1]);
		}

		return cookieArray;
	}


	//Private methods

	this.getCookieSettings = function()
	{
		var str = 'expires=' + this.expires.toGMTString() + '; ';
		if(this.domain.length) str += 'path=' + this.path + '; ';
		if(this.domain.length) str += 'domain=' + this.domain + '; ';
		if(this.isSecure) str += 'secure; ';
		return str;
	}
}

