(function($){
	$.fn.extend({
		ReplacePlaceholders: function() {
			this.find("span.placeholder").each(function() {
				var $this = $(this);
				try {
					var data=eval("("+$this.html()+")");
				} catch(e) {
					if (window.console && console.error) {
						console.error("Error in the JSON string!", this);
					}
					return;
				}
				if (!data || !data.containerSelector) {
					return;
				}
				var cont = $(data.containerSelector);
				if (cont.length == 0) {
					return;
				}
				
				$this.replaceWith(cont.show());
				if (data.updateEles) {
					for(var i=0, eleObj; eleObj = data.updateEles[i]; i++) {
						var ele = $(eleObj.selector);
						if (typeof(eleObj.html) !== "undefined") {
							ele.html(eleObj.html);
						}
						if (typeof(eleObj.options) !== "undefined") {
							var opts = [];
							for(var j=0, opt; opt=eleObj.options[j]; j++) {
								opts.push('<option value="' + opt.value + '">' + opt.html + '</option>');
							}
							ele.html(opts.join(""));
						}
						if (typeof(eleObj.value) !== "undefined") {
							ele.val(eleObj.value);
						}
						if (typeof(eleObj.checked) !== "undefined") {
							ele.attr("checked", eleObj.checked);
						}
					}
				}
			});
		}
	});
})(jQuery);
