UserPref = {
	aInitList : null,
	aList : null,

	define : function(prefs) {
		this.aInitList = prefs;
		this.reset();
	},

	reset : function() {
		this.aList = {};
		$H(this.aInitList).each(function(pair) {
					this.aList[pair.key] = {
						type : typeof(pair.value),
						value : pair.value,
						tmp : (pair.value == null)
					};
				}, this);

	},

	get : function(sOptionName) {
		var a = this.aList[sOptionName];
		return a ? a.value : null;
	},

	set : function(sOptionName, vValue, tmp) {
		vValue = this.convert(sOptionName, vValue);
		var a = this.aList[sOptionName];
		if (!a) {
			a = this.aList[sOptionName] = {};
		}
		a.value = vValue;
		a.tmp = tmp || false;
	},

	setFlat : function(prefs) {
		if (prefs) {
			$A(prefs.split("|")).each(function(up) {
						var a = up.split('=');
						this.set(a[0], a[1]);
					}, this);
		}
	},

	getFlat : function(withTmp) {
		var liCookieValue = [];
		$H(this.aList).each(function(pair) {
					if ((withTmp || !pair.value.tmp) && !Object.isUndefined(pair.value.value)) {
						liCookieValue.push(pair.key + '=' + pair.value.value.toString());
					}
				});
		return liCookieValue.join('|');
	},

	convert : function(sOptionName, vValue) {
		var a = this.aList[sOptionName];
		if (a && a.type && vValue != null) {
			switch (a.type) {
				case 'number' :
					vValue = Number(vValue);
					break;
				case 'boolean' :
					vValue = (vValue !== "false" && vValue !== false);
					break;
			}
		}
		return vValue;
	}
}
