
var cookieManager = Class.create({
	
	userDataForIE : false,
	
	initialize : function(userdataforIE){
		this.cookieShelfLife = 7;
		this.isIE = Prototype.Browser.IE;
		this.isOpera = Prototype.Browser.Opera;
		this.userDataForIE = userdataforIE;
		
		if(this.isIE && this.userDataForIE){
			this.IE_CACHE_NAME ="storage";
			
			if($(this.IE_CACHE_NAME) == null) $('cookietemp').insert(B.DIV({id : this.IE_CACHE_NAME}));
			
			this.store = $(this.IE_CACHE_NAME);
			this.store.style.behavior ="url('#default#userData')";
		}
	},
	
	getCookie : function(cookname){
		var res = null;
		if(this.isIE && this.userDataForIE){
			this.store.load(this.IE_CACHE_NAME);
			res = this.store.getAttribure(cookname);
		}else{
			var crumb = document.cookie.split(';');
			for(var i = 0; i < crumb.length; i++){
				var crumbpart = crumb[i].split('=');
				if( crumbpart[0].strip() == cookname && crumbpart[1] != null){
					res = crumbpart[1];
					break;
				}
			}
		}
		
		if(this.isOpera && res != null){
			res = res.replace(/%22/g,'"');
		}
		
		return res;
	},
	
	setCookie : function(cookname,cookvalue){
		if(this.IE && this.userDataForIE){
			this.store.setAttribute(cookname,cookvalue);
			this.store.save(this.IE_CACHE_NAME);
		}else{
			if(this.isOpera){
				cookvalue = cookvalue.replace(/"/g,"%22");
			}
			var date = new Date();
			date.setTime(date.getTime() + (this.cookieShelfLife * 24 * 60 * 60 * 1000));
			var expirse = ';expires=' + date.toGMTString();
			document.cookie = cookname + '=' + cookvalue + expirse + '; path=/';
		}
	},
	
	clearCookie : function(cookname){
		if(this.IE && this.userDataForIE){
			this.store.load(this.IE_CACHE_NAME);
			this.store.removeAttribute(cookname);
			this.store.save(this.IE_CACHE_NAME);
		}else{
			document.cookie = cookname + '=;expires=Thu,  01-Jan-1970 00:00:01 GMT; path=/';
		}
		
	},
	
	dummy:function(){}
});

