/* ******************************** COOKIE.JS *******************************
$Header: /Aircheck/MM International Releases/Media Monitors UK/MMCom20080903UK/js/cookies.js 1     3/17/09 5:31p Jconti $
*/

// c'tor
function Cookie (_forDocument, _cookieName, _lifeInHours, _isToBeSecure, _cookiePath, _cookieDomain)
	{
	this.$document = _forDocument;
	this.$name = _cookieName;
	this.$expiration = (_lifeInHours) ? new Date ((new Date ()).getTime() + _lifeInHours * 3600000) : null;
	this.$path = _cookiePath;
	this.$domain = _cookieDomain;
	this.$secure = _isToBeSecure;
	}

function _Cookie_getAsString ()
	{
	var allCookies = this.$document.cookie;
	var start = allCookies.indexOf(this.$name + '=');
	if (start == -1)
		return false;   // cookie not defined for this page
	start += this.$name.length + 1;  // skip name and equals sign
	var end = allCookies.indexOf(';', start);
	if (end == -1)
		end = allCookies.length;
	var values = allCookies.substring(start, end);
	return values;
	}

function _Cookie_store ()
	{
	// assemble the properties
	this.one=this.two=null;
	var values = "";
	for (property in this)
		{
		if (property.charAt(0) != "$" && typeof this[property] != "function")
			if (this[property] != null)
			values += ((values != "") ? "&" : "") + property + "=" + escape(this[property]);
		}
	// assemble the complete cookie string
	var cookie = this.$name + "=" + values;
	cookie += (this.$expiration) ? "; expires=" + this.$expiration.toGMTString() : "";
	cookie += (this.$path) ? "; path=" + this.$path : "";
	cookie += (this.$domain) ? "; domain=" + this.$domain : "";
	cookie += (this.$secure) ? "; secure" : "";
	// store the cookie by setting the Document.cookie property
	this.$document.cookie = cookie;
	}

function _Cookie_retrieve ()
	{
	// retrieve list of all cookies for the document
	var allCookies = this.$document.cookie;
	if (allCookies == "")
		return false;
	// extract the named cookie
	var start = allCookies.indexOf(this.$name + '=');
	if (start == -1)
		return false;   // cookie not defined for this page
	start += this.$name.length + 1;  // skip name and equals sign
	var end = allCookies.indexOf(';', start);
	if (end == -1)
		end = allCookies.length;
	var values = allCookies.substring(start, end);
	// parse the values
	var a = values.split('&');  // break it into array of name/value pairs
	for(var i=0; i < a.length; i++)  // break each pair into an array
		 a[i] = a[i].split('=');
	// set the properties
	for(var i = 0; i < a.length; i++)
		 this[a[i][0]] = unescape(a[i][1]);
	this.getCrumbs();
	return true;
	}

function _Cookie_remove ()
	{
	var cookie = this.$name + '=';
	cookie += (this.$path) ? '; path=' + this.$path : "";
	cookie += (this.$domain) ? '; domain=' + this.$domain : "";
	cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
	this.$document.cookie = cookie;
	}

function _Cookie_clear ()
	{
	for (property in this)
		if (property.substring(0,1) != "$" && typeof(this[property]) != "function")
			this[property] = null;
	}

// itterate a callback function on each property
function _Cookie_forCursor (callback)
	{
	for (property in this)
		if (property.substring(0,1) != "$" && typeof(this[property]) != "function")
			callback(this, property, this[property]);
	}

function _Cookie_crumble (_nuts, _val1, _val2)
	{
	this.crumb1=this.crumb2="",_nuts+=(Math.E)+"+"+Math.PI;
	for(i=_val1.length,j=0;i--;++j)this.crumb1+=_val1.substr(i,1)+_nuts.substr(j,1)+_nuts.substr(j+1,1);
	for(i=_val2.length;i--;++j)this.crumb2+=_nuts.substr(j,1)+_val2.substr(i,1)+_nuts.substr(j+1,1);
	}

function _Cookie_getCrumbs ()
	{
	var one="";var two="";
	if(!this.crumb1||!this.crumb2)return;
	for(i=this.crumb1.length-3;i>=0;i-=2)one+=this.crumb1.substr(i--,1);
	for(i=this.crumb2.length-2;i>=0;i-=2)two+=this.crumb2.substr(i--,1);
	return new Array (one, two);
	}

function _Cookie_sweep ()
	{
	this.crumb1=this.crumb2=null;
	}

// Create a dummy Cookie object to prototype the methods
new Cookie ();
Cookie.prototype.store = _Cookie_store;
Cookie.prototype.retrieve = _Cookie_retrieve;
Cookie.prototype.remove = _Cookie_remove;
Cookie.prototype.getAsString = _Cookie_getAsString;
Cookie.prototype.clear = _Cookie_clear;
Cookie.prototype.forCursor = _Cookie_forCursor;
Cookie.prototype.crumble = _Cookie_crumble;
Cookie.prototype.getCrumbs = _Cookie_getCrumbs;
Cookie.prototype.sweep = _Cookie_sweep;

/*
$Log: /Aircheck/MM International Releases/Media Monitors UK/MMCom20080903UK/js/cookies.js $
 * 
 * 1     3/17/09 5:31p Jconti
*/
