jQuery.cookie = {
	/* Internal functions */
	__read: function(name) {
		var cookies = document.cookie.split(';');
		var re = new RegExp("(?:^|\\s+)" + name + "=(.*)");
		for (var i=0, l=cookies.length; i<l; i++) {
			var match = cookies[i].match(re);
			if (match) return match[1];
		}
		return null;
	},

	__write: function(name, value, options) {
		options[name] = value;

		var keys = [name, 'expires', 'path', 'domain'], parts = [];
		for (var i=0, l=keys.length; i<l; i++) {
			if (typeof options[keys[i]] == 'undefined') continue;
			parts.push([keys[i], options[keys[i]]].join('='));
		}

		document.cookie = parts.join('; ');
	},

	__remove: function(name, options) {
		this.write(name, '', jQuery.extend(options, { expire_days: -1 }));
	},

	/*
	Finds cookie with the given name and returns it's value.
	Returns null if no cookie with that name is found.
	*/
	read: function(name) {
		var value = this.__read(name);
		if (value === null) {
			var t, i = 0;
			while(t = this.__read([name, i].join('.'))) {
				value = (value || '') + t;
				i++;
			}
		}
		return value;
	},

	/*
	Creates or updates cookie with given name. Value will be set to the given value.
	Options is a hash of other options that can be passed:
	  path: Path property of the cookie, defaults to '/'
	  domain: Domain property of the cookie, defaults to '.comcast.net'
	  expire_days: Days until this cookie expires
	  expire_date: JS Date object for when this cookie expires
	  expires: String date/time when this cookie expires (using expire_days or
	           expire_date is safer)
	*/
	write: function(name, value, options) {
		var cookie_data = jQuery.extend({
			path: '/',
			domain: '.comcast.net'
		}, options);

		if (typeof cookie_data.expire_days != 'undefined') {
			var d = new Date();
			d.setTime(d.getTime() + cookie_data.expire_days * 86400000);
			cookie_data.expires = d.toGMTString();
		}
		if (typeof cookie_data.expire_date != 'undefined') {
			cookie_data.expires = cookie_data.expire_date.toGMTString();
		}

		var max_length = 4000;
		if (value.length < max_length) {
			this.__write(name, value, cookie_data);
		} else {
			this.remove(name, options);

			var i = 0;
			while(value.length > 0) {
				this.__write([name, i].join('.'), value.substr(0, max_length), cookie_data);
				value = value.substr(max_length);
				i++;
			}
		}
	},

	/*
	Deletes a cookie with the given name. Options is the same as in jQuery.cookie.write.
	In order to successfully remove a cookie, it must be removed with the same path
	and domain attributes.
	*/
	remove: function(name, options) {
		if (this.__read(name) !== null) {
			this.__remove(name, options);
		} else {
			var i = 0;
			while(this.__read([name, i].join('.'))) {
				this.__remove([name, i].join('.'), options);
				i++;
			}
		}
	},

	/*
	Encode a hash to store in a cookie. The returned value will be an & seperated set
	of keyword-value pairs. Each pair will be of the form "key-word=value" with value
	passed through the JS escape() function
	*/
	encode: function(data) {
		var results = [];
		jQuery.each(data, function(i, v) {
			results.push([i, v.replace('%', '%25').replace(';', '%3B')].join('='));
		});
		return results.join('&');
	},

	/*
	Decodes a string that is the result of calling jQuery.cookie.encode.
	*/
	decode: function(data) {
		if (!data) return {};

		var results = {}, pairs = data.split('&');
		for (var i=0, l=pairs.length; i<l; i++) {
			var nv = pairs[i].split('=');
			results[nv[0]] = unescape(nv[1]);
		}
		return results;
	}
};

/**
  Deletes the EDATA cookies if the user is logged out
*/
if (!getPortalData()) {
	try {
		Prefs.remove('edata.last_success_version');
	} catch (e) {}
	jQuery.cookie.remove('token');
	jQuery.cookie.remove('edata');
	jQuery.cookie.remove('xedata');
	jQuery.cookie.remove('entitlementPageViewCount');
}