
window.onunload = function() {
	var app = document.getElementById('mbapp');
	var cs = app.preference();
	cookie.write("pref", cs, 365);
}

var cookie = {

	write : function (name, val, exp_by_day) {
		if ((name == null) || (val == null)) return false;

		if (exp_by_day == null) exp_by_day = 365;
		// exp_by_day = eval(exp_by_day);
		var tm = new Date();
		tm.setTime(tm.getTime()+(1000*60*60*24*exp_by_day));
		document.cookie = name+"="+escape(val)+";expires="+tm.toGMTString();
		return true;
	},

	read : function (name) {
		name += "=";
		cookieString = document.cookie+";";
		s = cookieString.indexOf(name);
		if (s != -1){
			e = cookieString.indexOf(";", s);
			return cookieString.substring(s+name.length, e);
		}
		return null;
	}

}

