function expand(e) {
  $(e).children(".collapsed").removeClass("collapsed").addClass("expanded").end().children(".boxbody").slideDown("slow");
}

function collapse(e) {
  $(e).children(".boxbody").slideUp("slow", function() { $(e).children(".expanded").removeClass("expanded").addClass("collapsed"); });
}

function er_(){
  $("form.qf td span.error").each(function(){
    $(this).parent().append($("<img/>").attr({src:"/images/error-s.gif",width:15,height:15,style:"vertical-align:middle"})).attr({title:$(this).text()}).tooltip({delay:0,showURL:false,fixPNG:true,top:2,left:2,track:true});
  }).remove();
}

function editor(elem) {
  if (elem.length != 1) return;
  var fckeditor = new FCKeditor(elem.attr("name"));
  fckeditor.BasePath = "/scripts/fckeditor/";
  fckeditor.Config["AutoDetectLanguage"] = false;
  fckeditor.Config["DefaultLanguage"] = "fa";
  fckeditor.Config["AutoDetectPasteFromWord"] = true;
  fckeditor.Config["CleanWordKeepsStructure"] = true;
  fckeditor.Config["ContentLangDirection"] = "rtl";
  fckeditor.Width = "100%";
  fckeditor.Height = "600px";
  fckeditor.ReplaceTextarea();
}

function toggle(This, aCls) {
  var parent = This.parentNode;
  var cls = parent.attributes["class"].nodeValue;
  if (cls.indexOf("open") >= 0)
    parent.attributes["class"].nodeValue = cls.replace("open", "");
  else
    parent.attributes["class"].nodeValue = cls + " open";
  var ul = parent.parentNode;
  var lis = ul.childNodes;
  aCls = aCls.substring(1, aCls.length);
  for (var i = 0; i < lis.length; ++i) {
    if (lis[i].tagName.toLowerCase() == "li") {
      var li = lis[i];
      if (li.attributes["class"].nodeValue && li.attributes["class"].nodeValue.indexOf(aCls) >= 0) {
        if (li.style.display == "none")
          li.style.display = "";
        else
          li.style.display = "none";
      }
    }
  }
  return false;
}

$(function() {
  $(".sidebox>.innerbox").each(function() {
    var o = $(this);
    if ($(".sep", o).hasClass("expanded")) {
      $(".title", o).addClass("hand").toggle(function() { collapse(o); }, function() { expand(o); });
    } else {
      $(".title", o).addClass("hand").toggle(function() { expand(o); }, function() { collapse(o); });
    }
  });
  er_();
});
