var rb = {
	registerNamespace: function (n) {
		var l = window;
		var h = n.split(".");
		for (var j = 0, k = h.length; j < k; j++) {
			var o = h[j];
			var m = l[o];
			if (!m) {
				m = l[o] = {}
			}
			l = m
		}
	},
	createDelegate: function (d, c) {
		return function () {
			return c.apply(d, arguments)
		}
	},
	_tmplCache: {},
	parseTemplate: function (o, u, r, t) {
		var v = "";
		try {
			u.html("");
			var w = $(o).html();
			var e = rb._tmplCache[w];
			if (!e) {
				var n = "var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('" + w.replace(/[\r\t\n]/g, " ").replace(/'(?=[^#]*#>)/g, "\t").split("'").join("\\'").split("\t").join("'").replace(/<#=(.+?)#>/g, "',$1,'").split("<#").join("');").split("#>").join("p.push('") + "');}return p.join('');";
				e = new Function("obj", n);
				rb._tmplCache[w] = e
			}
			for (var s = 0; s < r.length; s++) {
				r[s].__index = s;
				var q = $(e(r[s]));
				u.append(q);
				if (t) {
					t(q, r[s])
				}
			}
			return u
		} catch(p) {
			alert(p)
		}
	},
	serialize: function (b) {
		return JSON.stringify(b)
	},
	deserialize: function (data) {
		var exp = data.replace(new RegExp('(^|[^\\\\])\\"\\\\/Date\\((-?[0-9]+)\\)\\\\/\\"', "g"), "$1new Date($2)");
		return eval("(" + exp + ")")
	},
	lastLog: new Date(),
	log: function (c, d) {
		c += " " + (new Date() - rb.lastLog);
		rb.lastLog = new Date();
		if (window.console) {
			console.log(c)
		} else {
			if (d) {
				alert(c)
			}
		}
	},
	getPropDiff: function (h, f, e) {
		var g = {};
		$.each(e, function (b, a) {
			if (h[a] != f[a]) {
				g[a] = f[a]
			}
		});
		return g
	},
	getPropCount: function (f) {
		var d = 0;
		for (var e in f) {
			if (f.hasOwnProperty(e)) {
				d++
			}
		}
		return d
	},
	isArray: function (b) {
		return Object.prototype.toString.call(b) === "[object Array]"
	},
	isNullOrEmpty: function (b) {
		return b == "" || b == null
	}
};
rb.UI = {
	createButton: function (c, d) {
		return $(String.format('<a class="jqbutton {0}"><span>{1}</span></a>', d, c)).button()
	},
	showThemeRoller: function () {
		if (!/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
			alert("Sorry, due to security restrictions, this tool only works in Firefox");
			return false
		}
		if (window.jquitr) {
			jquitr.addThemeRoller()
		} else {
			jquitr = {};
			jquitr.s = document.createElement("script");
			jquitr.s.src = "http://jqueryui.com/themeroller/developertool/developertool.js.php";
			document.getElementsByTagName("head")[0].appendChild(jquitr.s)
		}
		return false
	},
	replaceFont: function (b) {
		if (window.Cufon != null) {
			Cufon.replace(b)
		}
	},
	replaceFonts: function (c) {
		if (window.Cufon != null) {
			for (var d = 0; d < c.length; d++) {
				Cufon.replace(c[d])
			}
		}
	},
	refreshFont: function () {
		if (window.Cufon != null) {
			Cufon.refresh()
		}
	},
	lazyLoad: function (e, d, f) {
		if (!this.lazyLoadEnabled()) {
			if (f) {
				f(e)
			}
			return
		}
		if (d == null) {
			d = 100
		}
		e.bind("inview", function (a, b, c) {
			if (b) {
				var h = $(this);
				if (h.attr("original")) {
					setTimeout(function () {
						h.attr("src", h.attr("original"));
						h.attr("original", null);
						if (f) {
							f(h)
						}
					},
					d)
				}
				h.unbind("inview")
			}
		});
		if (this.lazyLoadEnabled()) {
			check_inview()
		}
	},
	lazyLoadEnabled: function () {
		return typeof(check_inview) != "undefined"
	}
};
rb.UI.eventHandlerList = function () {
	this._list = {}
};
rb.UI.eventHandlerList.prototype = {
	addHandler: function (e, d) {
		var f = this._getEvent(e, true);
		f.push(d)
	},
	removeHandler: function (f, e) {
		var h = this._getEvent(f);
		if (!h) {
			return
		}
		for (var g = 0; g < h.length; g++) {
			if (h[g] === e) {
				h.splice(g, 1);
				return true
			}
		}
		return false
	},
	getHandler: function (c) {
		var d = this._getEvent(c);
		if (!d || !d.length) {
			return null
		}
		var d = d.length === 1 ? [d[0]] : Array.apply(null, d);
		return function (b, h) {
			for (var g = 0, a = d.length; g < a; g++) {
				d[g](b, h)
			}
		}
	},
	_getEvent: function (d, e) {
		var f = this._list[d];
		if (!f) {
			if (!e) {
				return null
			}
			this._list[d] = f = []
		}
		return f
	}
};
rb.component = {
	controls: [],
	register: function (f, g, e) {
		var h = new g();
		e.id = f;
		rb.component._setProperties(h, e);
		rb.component.controls[f] = h;
		return h
	},
	find: function (b) {
		return rb.component.controls[b]
	},
	findFirstByType: function (d) {
		var c = this.findByType(d);
		if (c.length > 0) {
			return c[0]
		}
		return null
	},
	findByType: function (f) {
		var g = [];
		for (var h in rb.component.controls) {
			var c = rb.component.controls[h];
			if (c.get_type != null && c.get_type() == f) {
				g.push(c)
			}
		}
		return g
	},
	_setProperties: function (f, j) {
		for (var k in j) {
			var h = j[k];
			var g = f["set_" + k];
			if (typeof(g) === "function") {
				g.apply(f, [h])
			}
		}
	}
};
(function () {
	var c = false,
	d = /xyz/.test(function () {
		xyz
	}) ? /\b_super\b/: /.*/;
	rb.Class = function () {};
	rb.Class.extend = function (h) {
		var b = this.prototype;
		c = true;
		var j = new this();
		c = false;
		for (var a in h) {
			j[a] = typeof h[a] == "function" && typeof b[a] == "function" && d.test(h[a]) ? (function (f, e) {
				return function () {
					var l = this._super;
					this._super = b[f];
					var g = e.apply(this, arguments);
					this._super = l;
					return g
				}
			})(a, h[a]) : h[a]
		}
		function k() {
			if (!c && this.init) {
				this.init.apply(this, arguments)
			}
		}
		k.prototype = j;
		k.constructor = k;
		k.extend = arguments.callee;
		return k
	}
})();
rb.registerNamespace("rb.widget");
rb.widget.base = rb.Class.extend({
	get_id: function () {
		return this._id
	},
	set_id: function (b) {
		this._id = b
	},
	get_type: function () {
		return this._type
	},
	set_type: function (b) {
		this._type = b
	},
	get_urlPath: function () {
		return this._urlPath
	},
	set_urlPath: function (b) {
		this._urlPath = b
	},
	get_clientText: function () {
		return this._clientText
	},
	set_clientText: function (b) {
		this._clientText = b
	},
	get_events: function () {
		return this._eventHandlerList
	},
	getText: function (c, d) {
		if (this._clientText[c] != null) {
			return this._clientText[c]
		}
		if (d == null) {
			d = "[" + c + "]"
		}
		return d
	},
	getID: function (b) {
		return this._id + "_" + b
	},
	findChildWidget: function (b) {
		return rb.component.find(this.getID(b))
	},
	getControl: function (c) {
		var d = this.getID(c);
		if (this._controls[d] == null) {
			this._controls[d] = $("#" + d)
		}
		return this._controls[d]
	},
	getWidget: function (c) {
		var d = this.getID(c);
		return rb.component.find(d)
	},
	init: function () {
		this._id = null;
		this._urlPath = "";
		this._clientText = {};
		this._errorCtl = [];
		this._locked = false;
		this._controls = [];
		this._eventHandlerList = new rb.UI.eventHandlerList();
		this._baseDelegates = {
			onLoadDelegate: rb.createDelegate(this, this._onLoad),
			onAjaxFailDelegate: rb.createDelegate(this, this._onAjaxFail),
			onKeyPressDelegate: rb.createDelegate(this, this._onKeyPress)
		};
		$(document).ready(rb.createDelegate(this, function () {
			window.setTimeout(this._baseDelegates.onLoadDelegate, 0)
		}))
	},
	lock: function () {
		this._locked = true;
		this.getControl("ProgressBar").show()
	},
	unlock: function () {
		this._locked = false;
		this.getControl("ProgressBar").hide()
	},
	showNotification: function (b) {
		if (b) {
			this.getControl("Notification").html(b).show()
		} else {
			alert(b)
		}
	},
	hideNotification: function () {
		this.getControl("Notification").hide()
	},
	showError: function (c) {
		if (c) {
			if (this._errorCtl.length > 0) {
				var d = this._errorCtl.find("ul:first");
				if (d.size() == 1) {
					d.append('<li><label class="ui-state-error-text" generated="false" style="display: block;">' + c + "</label></li>");
					this._errorCtl.show().children().show()
				} else {
					this._errorCtl.html(c).show()
				}
			} else {
				alert(c)
			}
		} else {
			alert(c)
		}
	},
	hideError: function () {
		var b = this._errorCtl.find("li").has('label[generated="false"]');
		if (b.size() > 0) {
			b.remove()
		}
		this._errorCtl.hide()
	},
	addHandler: function (d, c) {
		this.get_events().addHandler(d, c)
	},
	removeHandler: function (d, c) {
		this.get_events().removeHandler(d, c)
	},
	raiseEvent: function (f, e) {
		var d = this.get_events().getHandler(f);
		if (d) {
			if (e == null) {
				e = {}
			}
			d(this, e);
			return e.cancel != true
		}
		return true
	},
	checkQueryStringExists: function (d, c) {
		if ($.deparam.querystring()[d] != null) {
			setTimeout(function () {
				c()
			},
			500)
		}
	},
	getQueryStringParam: function (b) {
		return this.htmlEncode($.deparam.querystring()[b])
	},
	htmlEncode: function (b) {
		return $("<div/>").text(b).html()
	},
	htmlDecode: function (b) {
		return $("<div/>").html(b).text()
	},
	_onLoad: function (c, d) {
		this._errorCtl = this.getControl("Error");
		this.getControl("Widget").keypress(this._baseDelegates.onKeyPressDelegate)
	},
	_onKeyEnter: function (b) {},
	_onKeyPress: function (b) {
		if (b.which == 13) {
			return this._onKeyEnter(b)
		}
	},
	_onAjaxFail: function (e, h, g) {
		var f = e.msg;
		if (this.Res && this.Res.AjaxRequestFailed) {
			f = String.format(this.Res.AjaxRequestFailed, e.get_statusCode())
		}
		if (f == null) {
			f = "Unknown API Error"
		}
		this.showError(f);
		this.unlock()
	},
	navigate: function (b) {
		if (b) {
			window.location.href = b
		}
	},
	scroll: function (d, c) {
		if (d) {
			if (c == null) {
				c = false
			}
			if ((c == true && d.is(":not(:inView)")) || c == false) {
				$("html,body").animate({
					scrollTop: d.offset().top
				},
				1500)
			}
		}
	}
});

