// --- ASO COOKIE
// --- Amin Ladhani fevrier 2009
// --- v1.5

	aso.cook = {
		expire : null,
		path : null,
		domain : null,
		secure : null,
		writeCookie: function (nom, valeur){
			var argv = this.writeCookie.arguments;
			var argc = this.writeCookie.arguments.length;
			var expires = this.expire ? this.expire : null;
			var path = this.path ? this.path : null;
			var domain = this.domain ? this.domain : null;
			var secure = this.secure ? this.secure : false;
			document.cookie = nom+"="+escape(valeur)+
			((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
			((path==null) ? "" : ("; path="+path))+
			((domain==null) ? "" : ("; domain="+domain))+
			((secure==true) ? "; secure" : "");
		},
		getCookieVal: function (offset){
			var endstr=document.cookie.indexOf (";", offset);
			if (endstr==-1) endstr=document.cookie.length;
			return unescape(document.cookie.substring(offset, endstr));
		},
		readCookie: function(nom){
			var arg=nom+"=";
			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 this.getCookieVal(j);
				i = document.cookie.indexOf(" ",i)+1;
				if (i == 0) break;
			}
			return null;
		},
		delCookie: function(nom){
			date=new Date;
			date.setFullYear(date.getFullYear()-1);
			this.writeCookie(nom,null,date);
		}
	};
	aso.cook.cookiemanager = function(cookie){
		this.cookie = cookie;
		if(!cook.readCookie(this.cookie)){
			cook.writeCookie(this.cookie);
		}
	};
	aso.cook.cookiemanager.prototype.load = function(){
		var ck;
		this.ck = {};
		try{ 
			this.ck_loaded = cook.readCookie(this.cookie).split(';');
			for(ck in this.ck_loaded){
				_ck = this.ck_loaded[ck].split('=');
				this.ck[_ck[0]]=_ck[1];
			}
		}catch(e){}
	};
	aso.cook.cookiemanager.prototype.getname = function(){
		return this.cookie;
	}
	aso.cook.cookiemanager.prototype.get = function(ck_fragment){
		this.load();
		return this.ck[ck_fragment];
	};
	aso.cook.cookiemanager.prototype.set = function(ck_fragment,ck_value){
		this.load();
		this.ck[ck_fragment]=ck_value;
		this.save();
	};
	aso.cook.cookiemanager.prototype.remove = function(ck_fragment){
		this.load();
		this.ck[ck_fragment]='';
		this.save();
	};
	aso.cook.cookiemanager.prototype.count = function(){
		var j = 0;
		for(i in this.ck) j++;
		return j;
	};
	aso.cook.cookiemanager.prototype.show = function(){
		this.load();
		var i,str_ck='';
		for(i in this.ck) if(i) str_ck += i+" : "+this.ck[i]+"\n";
		alert(str_ck);
	};
	aso.cook.cookiemanager.prototype.save = function(){
		var str_ck = '',pr,i = 1, sep = '', num = this.count();
		for(pr in this.ck){
			if(!this.ck[pr]) continue;
			str_ck += pr+"="+this.ck[pr];
			str_ck += i == num ? '' : ';';
			i++;
		}
		cook.writeCookie(this.cookie,str_ck);
	};
	aso.cook.cookiemanager.prototype.deletecookie = function(){
		cook.writeCookie(this.cookie,'');
	};
	
	Cookie = aso.cook;
	CookieManager = aso.cook.cookiemanager;