/**
* @copyright 2006 Karsten Nymann Pedersen
* @version 2.00
* @author Karsten Nymann Pedersen
* @mail software@rapax.dk
* @license Freeware
* @package tool
* @subpackage cookie
* @tutorial 
myCookie = new tool_cookie();
myCookie.setCookie("cookieName","cookieValue"[,daysUntilExpire][,"DomainePath"][,"DomaineName"][,"SecureValue"]);
myCookieValue = myCookie.getCookie("cookieName");
myCookie.deleteCookie("cookieName"[,"DomainePath"][,"DomaineName"]);  
*/

var tool_cookie = function()
{
}

tool_cookie.prototype.setCookie = function(vName, vValue, vDays, vPath, vDomain, vSecure)
{
	 if (vDays)
	 {
		  this.date = new Date();
		  this.date.setTime(this.date.getTime()+(vDays*24*60*60*1000));
	 }
	 else this.date = "";
   document.cookie= vName + "=" + escape(vValue) + ((this.date) ? "; expires=" + this.date.toGMTString() : "") + ((vPath) ? "; path=" + vPath : "") + ((vDomain) ? "; domain=" + vDomain : "") + ((vSecure) ? "; secure" + vSecure : "");
}

tool_cookie.prototype.getCookie = function(vName)
{
    this.dc = document.cookie;
    this.prefix = vName + "=";
    this.begin = this.dc.indexOf("; " + this.prefix);
    if (this.begin == -1)
    {
        this.begin = this.dc.indexOf(this.prefix);
        if (this.begin != 0) return null;
    }
    else this.begin += 2;

    this.end = document.cookie.indexOf(";", this.begin);
    if (this.end == -1) this.end = this.dc.length;
    return unescape(this.dc.substring(this.begin + this.prefix.length, this.end));
}

tool_cookie.prototype.deleteCookie = function(vName, vPath, vDomain)
{
	if (this.getCookie(vName)) document.cookie = vName + "=" + ((vPath) ? "; path=" + vPath : "") + ((vDomain) ? "; domain=" + vDomain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

