/*
 * Cooler Cookies 1.0.1
 * (c) 2008 Geth Dunne <geth.dunne@talk21.com> - ChatterBloc.com
 * All rights reserved
 *
 * Cookie access class - for simple saving of cookie information
 * version history:
 *  1.0.0 - inital version with createCookie, readCookie and deleteCookie
 *  1.0.1 - added getRoomList to return an array of rooms on the cookie
 */

function CoolerCookie() { 

	// Public properties
	this.Expires = 1;	// The time in days till the cookie expires
	
	// Public methods

	this.createCookie = function(RoomGuid, Name, Days) 
	{
	
		// If this cookie already exists then kill it first
		if (!Days)
		{
			Days = this.Expires;
		}

		if (Days) 
		{
			var date = new Date();
			date.setTime(date.getTime()+(Days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else 
		{
			var expires = "";
		}
		
		document.cookie = RoomGuid + "=" + Name + expires + "; path=/";
	}

	this.readCookie = function(RoomGuid) 
	{
		var nameEQ = RoomGuid + "=";
		var ca = document.cookie.split(";");
	
		for(var i=0; i < ca.length; i++) 
		{
			var c = ca[i];
			while (c.charAt(0) == " ") 
			{
				c = c.substring(1, c.length);
			}

			if (c.indexOf(nameEQ) == 0) 
			{
				return c.substring(nameEQ.length, c.length);
			}
		}
	
		return null;
	}

	this.deleteCookie = function(RoomGuid) 
	{
		this.createCookie(RoomGuid, "", -1);
	}

	this.getRoomList = function()
	{
		var roomArray = new Array();

		var nameEQ = RoomGuid + "=";
		var ca = document.cookie.split(";");
	
		for(var i=0; i < ca.length; i++) 
		{
			var c = ca[i];
			while (c.charAt(0) == " ") 
			{
				c = c.substring(1, c.length);
			}

			roomArray.push(c.substring(1, c.indexOf("=")));
		}

		return roomArray;
	}

}