// Cookie Handling JavaScript Functions
// File:    cookie.js
// Source:  http://www.quirksmode.org/js/cookies.html
// WEBCAT:  1.1
// Version: 1.0
// History:
//     8 Mar 2000  V1.0: Initial creation...ETB
//    13 Jun 2000  WEBCAT 1.1 (no changes)...ETB
//    02 Nov 2006  Completely redone to operate as a Singleton class...SRK
//

var Cookie = new function()
{

	this.create = function(name,value,days)
	{
		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 = name+"="+value+expires+"; path=/";
	}

	this.read = function(name)
	{
		var nameEQ = name + "=";
		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.erase = function(name)
	{
		createCookie(name,"",-1);
	}

}





/*
//-------------------------------------------------------------------
// Constructor function
// Creates a cookie object for the document
// Parameters
//   doc:    Document object for cookie (Required)
//   name:   Name string for cookie (Required)
//   hours:  Lifetime for cookie, string (Optional)
//   path:   Path attribute string (Optional)
//   domain: Domain attribute string (Optional)
//   secure: Boolean to request secure cookie (Optional)
function Cookie(doc,name,hours,path,domain,secure) {
	// predefined properties start with "$"
	this.$document = doc;
	this.$name = name;
	this.$expiration = (hours) ? new Date((new Date()).getTime() + hours*3600000) : null;
	this.$path = (path) ? path : null;
	this.$domain = (domain) ? domain : null;
	this.$secure = (secure) ? true : false;
}

// Method: store cookie
function _Cookie_store() {
	// build cookie value
	var cookieval = "";
	for (var prop in this) {
		// ignore methods and properties with names beginning with "$"
		if ((prop.charAt(0) == "$") || ((typeof this[prop]) == 'function')) continue;
		if (cookieval != "") cookieval += '&';
		cookieval += prop + ':' + escape(this[prop]);
	}
	// build cookie string with all attributes
	var cookie = this.$name + '=' + cookieval;
	if (this.$expiration) cookie += '; expires=' + this.$expiration.toGMTString();
	if (this.$path) cookie += '; path=' + this.$path;
	if (this.$domain) cookie += '; domain=' + this.$domain;
	if (this.$secure) cookie += '; secure';
	// set document cookie property to store
	this.$document.cookie = cookie;
}

// Method: load cookie
function _Cookie_load() {
	// get cookie list for this document
	var allcookies = this.$document.cookie;
	if (allcookies == "") return false;
	// extract 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 equal sign
	var end = allcookies.indexOf(';', start);
	if (end == -1) end = allcookies.length;
	var cookieval = allcookies.substring(start,end);
	// parse cookie
	var a = cookieval.split('&'); // array of name/value pairs
	for (var i = 0; i < a.length; i++) {
		a[i] = a[i].split(':');
	}
	// set names/values in Cookie object
	for (var i = 0; i < a.length; i++) {
		this[a[i][0]] = unescape(a[i][1]);
	}
	return true;
	}

	// Method: remove cookie
	function _Cookie_remove() {
		var cookie = this.$name + '=';
		if (this.$path) cookie += '; path=' + this.$path;
		if (this.$domain) cookie += '; domain=' + this.$domain;
		cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
		this.$document.cookie = cookie;
	}
	
	// Create dummy Cookie object so we can use the prototype object
	// to make the functions into methods
	new Cookie();
	Cookie.prototype.store = _Cookie_store;
	Cookie.prototype.load = _Cookie_load;
	Cookie.prototype.remove = _Cookie_remove;
	Cookie.prototype.eval = eval;
*/

