<!--
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//
//	Code From Book
//	JavaScript: The Definitive Guide, Fourth Edition
//	Copyright (c) 2001 by David Flanagan
//
//	26.01.2007 16:09	Slightly modified function load ():
//						Cookies can contain now Entries with similary Names,
//						for Example, "d100" and "100" as this.$name;
//						function load () kills now all empty Entries.
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//
// The constructor function: creates a cookie object for the specified
// document, with a specified name and optional attributes.
// Arguments:
//   document: The Document object that the cookie is stored for. Required.
//   name:     A string that specifies a name for the cookie. Required.
//   hours:    An optional number that specifies the number of hours from now
//             that the cookie should expire.
//   path:     An optional string that specifies the cookie path attribute.
//   domain:   An optional string that specifies the cookie domain attribute.
//   secure:   An optional Boolean value that, if true, requests a secure cookie.
//
function Cookie(document, name, hours, path, domain, secure)
{
    // All the predefined properties of this object begin with '$'
    // to distinguish them from other properties which are the values to
    // be stored in the cookie.
    this.$document = document;
    this.$name = name;
    if (hours)
        this.$expiration = new Date((new Date()).getTime() + hours*3600000);
    else this.$expiration = null;
    if (path) this.$path = path; else this.$path = null;
    if (domain) this.$domain = domain; else this.$domain = null;
    if (secure) this.$secure = true; else this.$secure = false;
}

// This function is the store() method of the Cookie object.
Cookie.prototype.store = function () {
    var cookieval = "";
    for(var prop in this) {
        // Ignore properties with names that begin with '$' and also methods.
        if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function'))
            continue;

        if (cookieval != "") cookieval += '&';
        cookieval += prop + '=' + escape(this[prop]);
    }

    var cookie = this.$name + '=' + ((cookieval == "") ? ('; expires=Fri, 02-Jan-1970 00:00:00 GMT') : (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';

    this.$document.cookie = cookie;
}

// This function is the load() method of the Cookie object.
Cookie.prototype.load = function() {
    var cookie;
	var start;
	var arTmp;
	var oRE = new RegExp (";\\s*" + this.$name + "=");
//	oRE.global = true;
    var allcookies = this.$document.cookie;
    if (allcookies == "") return false;
    // Now extract just the named cookie from that list.
    if ((arTmp = allcookies.match (oRE)) == null)
    {
	    if ((start = allcookies.indexOf (this.$name + "=")) != 0)
	    	return false;

	    else
		    start += this.$name.length + 1;  // Skip name and equals sign.
	}

	else
		start = arTmp.index + arTmp [0].length;

    var end = allcookies.indexOf(';', start);
    if (end == -1) end = allcookies.length;
    var cookieval = allcookies.substring(start, end);

	if (cookieval.length == 0)
	{
		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;
		return false;
	}

    var a = cookieval.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('=');

    for(var i = 0; i < a.length; i++)
        this[a[i][0]] = unescape(a[i][1]);

    return true;
}

// This function is the remove() method of the Cookie object.
Cookie.prototype.remove = function() {
    var cookie;
    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;
}

//=============================================================================
//  The previous code is the definition of the Cookie class.
//=============================================================================

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-->