//<nowiki>
// AfD decatting, substituting closeboxes
addOnloadHook(function() {
if(location.href.indexOf('afddecat=Y')!=-1)
{
  var subst;
  if(document.editform.wpTextbox1.value.indexOf(
     'The following discussion is an archived debate of the proposed deletion of '+
     'the article below.')==-1
     &&document.editform.wpTextbox1.value.indexOf("{{a"+"t}}")==-1
     &&document.editform.wpTextbox1.value.indexOf("{{afd "+"t}}")==-1
     &&document.editform.wpTextbox1.value.indexOf("{{afd "+"top}}")==-1) {window.close(); return;} //still open, do nothing
  subst=1;
  if(document.editform.wpTextbox1.value.indexOf("{{a"+"t}}")==-1
     &&document.editform.wpTextbox1.value.indexOf("{{afd "+"t}}")==-1
     &&document.editform.wpTextbox1.value.indexOf("{{afd "+"top}}")==-1) subst=0;
  document.editform.wpTextbox1.value=document.editform.wpTextbox1.value.
    split("{{REMOVE THIS TEMPLATE WHEN CLOSING THIS AfD|").join("{{ns:0|");
  document.editform.wpTextbox1.value=document.editform.wpTextbox1.value.
    split("{{a"+"t}}").join("{{subs"+"t:at}}").split("{{afd "+"t}}").join("{{subs"+"t:at}}").
    split("{{afd "+"top}}").join("{{subs"+"t:at}}");
  document.editform.wpTextbox1.value=document.editform.wpTextbox1.value.
    split("{{a"+"b}}").join("{{subs"+"t:ab}}").split("{{afd "+"b}}").join("{{subs"+"t:ab}}").
    split("{{afd "+"bottom}}").join("{{subs"+"t:ab}}");
  document.editform.wpMinoredit.checked='checked';
  document.editform.wpSummary.value="BOT: Removing ] from closed" 
    + " ] debate"+(subst?" and ] closebox":"");
  document.editform.wpSave.click();
}
else if(location.href.indexOf("Wikipedia:Articles_for_deletion/")!=-1) window.close();
});
//</nowiki>