var XWiki=function(d){d.MessageStream=Class.create({initialize:function(b){b=b||$(document.body);this.prepareForms(b);this.enhanceSelect(b)},prepareTargetInput:function(b,a){b=a.options[a.selectedIndex].value;a.className=b;a=a.up(".messagestream");var f=a.down(".message-target-"+b);f||=a.down(".message-target-default");a.select(".message-target").forEach(function(c){var h=c.select("input, select, textarea");c===f?(c.removeClassName("hidden"),h.forEach(function(e){e.enable();e.hasClassName("selectized")&&
e.selectize.enable()})):(c.addClassName("hidden"),h.forEach(function(e){e.disable();e.hasClassName("selectized")&&e.selectize.disable()}))})},enhanceSelect:function(b){b.select('.messagestream select[name\x3d"visibilityLevel"]').each(function(a){a.observe("change",this.prepareTargetInput.bindAsEventListener(this,a));this.prepareTargetInput(null,a)}.bind(this))},prepareForms:function(b){b.select(".messagestream form").each(function(a){a.action=a.action.replace(/xredirect=.*$/,"xpage\x3dplain");a.observe("submit",
function(f){f.stop();1!=a._disabled&&""!=a.down("textarea").value.strip()&&new Ajax.Request(a.action,{parameters:a.serialize(!0),onCreate:function(){a._disabled=!0;a._notification=new d.widgets.Notification("Sending...","inprogress")},onSuccess:function(){a&&(a.messagestream_message.value="");a&&a._notification&&a._notification.hide();a._notification=new d.widgets.Notification("Message sent","done");document.fire("xwiki:activity:newActivity",a)},onFailure:function(c){c=c.statusText||"Server not responding";
a&&(a._disabled=!1,a._notification&&a._notification.hide(),a._notification=new d.widgets.Notification("Failed to send message: "+c,"error"))},on0:function(c){c.request.options.onFailure(c)},onComplete:function(){a._disabled=!1}.bind(this)})}.bindAsEventListener(this))}.bind(this))}});var g=function(b){(b&&b.memo.elements||[$(document.body)]).forEach(function(a){new d.MessageStream(a)});return!0};d.domIsLoaded&&g()||document.observe("xwiki:dom:loaded",g);document.observe("xwiki:dom:updated",g);return d}(XWiki||
{});