//-------------------------------------------------------------------------
// singleton class: CookieUtils

var cookieUtils = new function() {

    // method: getCookie
    this.getCookie = function(name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
            var j = i + alen;
            if (document.cookie.substring(i, j) == arg)
            return getCookieVal (j);
            i = document.cookie.indexOf(" ", i) + 1;
            if (i == 0) break;
        }
        return null;
    }

    // method: setCookie
    this.setCookie = function(name, value, path, days, domain) {
        var cookie = name + "=" + value;
        if (path)
        	cookie += ";Path=" + path;
        else
        	cookie += ";Path=/";
        if (days) {
	        var expDate = new Date();
	        expDate.setDate(expDate.getDate()+parseInt(days));
	        cookie += ";Expires=" + expDate.toGMTString();
        }
        if (domain)
			cookie += ";Domain=" + domain;
        document.cookie = cookie;
        return cookie;
    }

    // private method: getCookieVal
    getCookieVal = function(offset) {
        var endstr = document.cookie.indexOf (";", offset);
        if (endstr == -1)
            endstr = document.cookie.length;
        return unescape(document.cookie.substring(offset, endstr));
    }

}

