var XWiki=(function(b){var a=b.viewers=b.viewers||{};
a.Tags=Class.create({initialize:function(){$$(".doc-tags .tag-delete").each(this.ajaxTagDelete);
$$(".doc-tags .tag-add a").each(this.createTagAddForm.bind(this));
if($$(".doc-tags .tag-add-form").length>0){this.ajaxifyForm($$(".doc-tags .tag-add-form")[0])
}},ajaxTagDelete:function(c){c.observe("click",function(d){if(d){d.stop()
}if(!c.disabled){new Ajax.Request(c.readAttribute("href").replace(/&xredirect=.+$/,"&ajax=1"),{onCreate:function(){c.disabled=true;
c.notification=new b.widgets.Notification("Deleting tag...","inprogress")
},onSuccess:function(){c.up(".tag-wrapper").remove()
},onFailure:function(e){new b.widgets.Notification(e.responseText||"Server not responding","error")
},on0:function(e){e.request.options.onFailure(e)
},onComplete:function(){c.disabled=false;
c.notification.hide()
}})
}}.bindAsEventListener())
},createTagAddForm:function(c){c.observe("click",function(d){if(d){d.stop()
}if(!c._x_form){if(!c.disabled){new Ajax.Request(c.readAttribute("href").replace(/#.+$/,"&ajax=1&xpage=documentTags"),{onCreate:function(){c.disabled=true;
c.notification=new b.widgets.Notification("Fetching form...","inprogress")
},onSuccess:function(e){var f=c.up();
c.remove();
f.update(e.responseText);
c._x_form=f.firstDescendant();
c._x_form._x_activator=c;
c._x_form.down("input[type=text]").focus();
this.ajaxifyForm(c._x_form)
}.bind(this),onFailure:function(e){new b.widgets.Notification(e.responseText||"Server not responding","error")
},on0:function(e){e.request.options.onFailure(e)
},onComplete:function(){c.disabled=false;
c.notification.hide()
}})
}}else{Element.replace(c,c._x_form);
c._x_form.down("input[type=text]").focus()
}}.bindAsEventListener(this))
},ajaxifyForm:function(d){d.setAttribute("autocomplete","off");
d.down("input[type=text]").setAttribute("autocomplete","off");
d.down("input[type=text]").setAttribute("autocomplete","off");
d.observe("submit",function(e){e.stop();
d.down("input[type=text]").focus();
if(d.tag.value!=""){new Ajax.Request(d.action.replace(/&xredirect=.+$/,"&ajax=1&tag=")+encodeURIComponent(d.tag.value),{onCreate:function(){d.disable();
d.notification=new b.widgets.Notification("Adding tag...","inprogress")
},onSuccess:function(f){var g=new Element("span");
g.insert(f.responseText+" ");
g.select(".tag-delete").each(this.ajaxTagDelete);
while(g.childNodes.length>0){d.up(".tag-add").insert({before:g.firstChild});
d.up(".tag-add").insert({before:" "});
g.removeChild(g.firstChild)
}d.reset()
}.bind(this),onFailure:function(f){new b.widgets.Notification(f.responseText||"Server not responding","error")
},onComplete:function(){d.enable();
d.notification.hide()
},on0:function(f){f.request.options.onFailure(f)
}})
}}.bindAsEventListener(this));
d.observe("reset",function(e){Element.replace(d,d._x_activator)
}.bindAsEventListener(this));
var c=new Element("input",{type:"reset",value:d.down(".button-add-tag-cancel").innerHTML,"class":"button secondary"});
d.down(".button-add-tag-cancel").replace(c);
new b.widgets.Suggest(d.down("input[type=text]"),{script:"/xwiki/bin/view/Main/WebHome?xpage=suggest&classname=XWiki.TagClass&fieldname=tags&firCol=%2D&secCol=%2D&",varname:"input",seps:" ,|",shownoresults:false,icon:"/xwiki/resources/icons/silk/tag_yellow.gif"})
}});
return b
}(XWiki||{}));
document.observe("xwiki:dom:loaded",function(){new XWiki.viewers.Tags()
});
