﻿// Cookies object
// This is how you do a regular object, where you need to instantiate it using the new keyword.
function Cookies()
{
    if (document.cookie.length > 0)
    {
        var items = document.cookie.split(/;\s*/);
        
        for (var i=0; i<items.length; i++)
        {
            var param = items[i].split('=');
            
            var name = unescape(param[0]);
            var value = unescape(param[1]);
            
            this[name] = value;
        }
    }
}

// Parameters:
// name - The name of the cookie
// value - The value for the cookie
// days :
//      < 0 - The cookie will get trashed immediately.
//      0   - The cookie will last as long as the session is alive.
//      > 0 - The cookie will last as long as the days specified.
Cookies.prototype.create = function (name, value, days)
{
    var expires = "";
    
    if (days)
    {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	    
	document.cookie = name+"="+value+expires+"; path=/";
	this[name] = unescape(value);
}

Cookies.prototype.erase = function (name)
{
    this.create(name, "", -1);
    this[name] = undefined;
}



//xmlHttpObject
function getHTTPObject()
{
	return window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
}
