if(typeof(XWiki)=="undefined"){XWiki=new Object()}XWiki.Blog={blogToolsValues:{show:{title:"This blog post is not visible to other users. Make it visible",imageSrc:"/resources/icons/silk/lock_open.png",imageAlt:"show",comment:"Made%20entry%20visible"},hide:{title:"Hide this blog post from other users",imageSrc:"/resources/icons/silk/lock.png",imageAlt:"hide",comment:"Hidden%20entry"},loading:{title:"Loading...",imageSrc:"/resources/icons/xwiki/spinner.gif",imageAlt:"loading"}},initialize:function(){XWiki.Blog.addBehaviorToBlogTools()},addBehaviorToBlogTools:function(){$$(".blog-tool-hide").each(function(b){b.blogCallback=XWiki.Blog.makeEntryInvisible.bindAsEventListener(b)});$$(".blog-tool-show").each(function(b){b.blogCallback=XWiki.Blog.makeEntryVisible.bindAsEventListener(b)});$$(".blog-tool-show, .blog-tool-hide").each(function(b){b.href=b.href.replace(/&xredirect=.*?(&|$)/,"&ajax=1$1");Event.observe(b,"click",XWiki.Blog.linkDisabler.bindAsEventListener(b));Event.observe(b,"click",b.blogCallback)});var a=$("blog_AddCategoryButton");if(a){Event.observe(a,"click",XWiki.Blog.createBlogCategory.bindAsEventListener(a.form))}},makeEntryInvisible:function(a){Event.stopObserving(this,"click",this.blogCallback);XWiki.Blog.setToolLoadingStatus(this,XWiki.Blog.blogToolsValues.loading);new Ajax.Request(this.href,{method:"get",onSuccess:XWiki.Blog.onEntryMadeInvisible.bind(this),on1223:function(b){b.request.options.onSuccess(b)},on403:function(){alert("You are not allowed to perform this action")},on401:function(){alert("You have been logged out, please login")},onFailure:function(){alert("Failed to change blog post visibility")}})},makeEntryVisible:function(a){Event.stopObserving(this,"click",this.blogCallback);XWiki.Blog.setToolLoadingStatus(this,XWiki.Blog.blogToolsValues.loading);new Ajax.Request(this.href,{method:"get",onSuccess:XWiki.Blog.onEntryMadeVisible.bind(this),on1223:function(b){b.request.options.onSuccess(b)},on403:function(){alert("You are not allowed to perform this action")},on401:function(){alert("You have been logged out, please login")},onFailure:function(){alert("Failed to change blog post visibility")}})},onEntryMadeVisible:function(){var a=XWiki.Blog.getEntry(this);if(a){XWiki.Blog.setEntryVisibility(a,true)}XWiki.Blog.updateShowHideButton(this,XWiki.Blog.blogToolsValues.hide);this.blogCallback=XWiki.Blog.makeEntryInvisible.bindAsEventListener(this);Event.observe(this,"click",this.blogCallback);$$(".entry-content").each(function(b){b.previous(".warningmessage").hide()})},onEntryMadeInvisible:function(){var a=XWiki.Blog.getEntry(this);if(a&&!a.hasClassName("single-article")){XWiki.Blog.setEntryVisibility(a,false)}XWiki.Blog.updateShowHideButton(this,XWiki.Blog.blogToolsValues.show);this.blogCallback=XWiki.Blog.makeEntryVisible.bindAsEventListener(this);Event.observe(this,"click",this.blogCallback);$$(".entry-content").each(function(c){if(c.previous(".warningmessage")){c.previous(".warningmessage").show()}else{var d=document.createElement("div").addClassName("warningmessage");var b=document.createElement("span").addClassName("messagetype");b.appendChild(document.createTextNode("Warning: "));d.appendChild(b);d.appendChild(document.createTextNode("This blog post is hidden."));c.up().insertBefore(d,c)}})},updateShowHideButton:function(a,b){a.title=b.title;a.down("img").src=b.imageSrc;a.down("img").alt=b.alt;a.href=a.href.replace(/&comment=(.*?)(&|$)/,"&comment="+b.comment+"$2");if(a.href.match(/_hidden=1/)){a.href=a.href.replace(/_hidden=1/,"_hidden=0")}else{a.href=a.href.replace(/_hidden=0/,"_hidden=1")}},getEntry:function(a){return a.up(".hentry")},setEntryVisibility:function(a,b){if(b){a.removeClassName("hidden-article")}else{a.addClassName("hidden-article")}},setToolLoadingStatus:function(a,b){a.title=b.title;a.down("img").src=b.imageSrc;a.down("img").alt=b.alt},linkDisabler:function(a){Event.stop(a)},createBlogCategory:function(){var a=this.newCategoryName.value;var f=encodeURI(a.replace(/'/g,"").replace(/"/g,""));var e=encodeURI(a);var b=this.newCategoryParent.value;var d=encodeURI(b.substring(0,b.indexOf(".")));var c=encodeURI(b);new Ajax.Request("/save/Blog/__name__?ajax=1&template=Blog.CategoryTemplate&form_token=NjQC47Lk0Wt4QX6L9ope1w".replace(/__name__/g,f)+"&parent="+c+"&title="+e+"&Blog.CategoryClass_0_name="+e,{method:"get",onSuccess:XWiki.Blog.updateCategoryTree.bindAsEventListener(this,a,b,d),on1223:function(g){g.request.options.onSuccess(g)},on409:function(){alert("This category already exists")},on403:function(){alert("You are not allowed to perform this action")},on401:function(){alert("You have been logged out, please login")},onFailure:function(){alert("Failed to add category")}})},updateCategoryTree:function(p,t,h,o){var d=$("blog_category_"+h);if(!d){d=$("blog_category_container")}else{d=d.up()}var n=d.down("ul");if(!n){n=document.createElement("ul");d.appendChild(n)}var c=n.childElements();var j=false;var r="blog_category_"+o+"."+t;var k=document.createElement("li");var g=document.createElement("label");g.id=r;k.appendChild(g);var m=document.createElement("input");m.type="checkbox";m.checked="checked";m.name="Blog.BlogPostClass_0_category";m.value=o+"."+t;g.appendChild(m);g.appendChild(document.createTextNode(" "+t));var l=document.createElement("option");l.id=r+"_option";l.value=o+"."+t;var s=0;var f=d;while(f&&f!=$("blog_category_container")){s++;f=f.up("li")}l.appendChild(document.createTextNode("&nbsp;".unescapeHTML().times(2*s)+t));var b=$("blog_category_selectBox");for(var q=0;q<c.size();++q){if(c[q].down("label").id>r){n.insertBefore(k,c[q]);var e=$(c[q].down("label").id+"_option");b.insertBefore(l,e);j=true;break}}if(!j){n.appendChild(k);var f=d;var a;while(!a&&f){a=f.next("li");f=f.up("li")}if(a){b.insertBefore(l,$(a.down("label").id+"_option"))}else{b.appendChild(l)}}}};function publishEntry(c,a,b){new Ajax.Request("/Blog/__name__".replace(/__name__/g,c)+"?entryName="+a,{method:"get",onSuccess:function(){alert("done");b.parentNode.removeChild(b)}});return false}document.observe("xwiki:dom:loaded",XWiki.Blog.initialize);