function Cookiemanager() {
	this.name = 'cookieManager';
       var hostname = window.location.hostname;
	var i = hostname.indexOf('.');
	if (i < 0) {
		this.defaultDomain = '';
	} else {
		this.defaultDomain = hostname.substring(i+1);
	}
	this.defaultPath = '/';
	this.cookies = new Object();
	this.domain = new Object();
	this.path = new Object();
	window.onunload = new Function (this.name+'.setDocumentCookies();');
	this.getDocumentCookies();
}

Cookiemanager.prototype.getDocumentCookies = function() {
	var cookie,pair;
	var cookies = document.cookie.split(';');
	var len = cookies.length;
	for(var i=0;i < len;i++) {
		cookie = cookies[i];
		while (cookie.charAt(0)==' ') cookie = cookie.substring(1,cookie.length);
		pair = cookie.split('=');
		this.cookies[pair[0]] = pair[1];
	}
}

Cookiemanager.prototype.setDocumentCookies = function() {
	var cookies = '';
	var domain = '';
	var path = '';
		
	for(var name in this.cookies) {
		path = this.defaultPath;
		domain = this.defaultDomain;
        if(name=='fontSize' || name=='style') {
		    var cookies = name + '=' + this.cookies[name] + '; path=' + path;
             if (domain != '') {
		  cookies = cookies + '; domain=' + domain;
		}
              cookies = cookies + '; expires=';
            if(cookies != '') {
                document.cookie = cookies;
            }
        }
	}
	return true;
}

Cookiemanager.prototype.getCookie = function(cookieName) {  
	return (this.cookies[cookieName])?this.cookies[cookieName]:false;
}

Cookiemanager.prototype.setCookie = function(cookieName, cookieValue) {
   this.cookies[cookieName] = cookieValue;
   this.domain[cookieName] = window.location.host.replace(/^[\w-]+\./, '');
   this.path[cookieName] = this.defaultPath;
   return true;
}

var cookieManager = new Cookiemanager();