function reloadLessonList(module, cat_id) {
  var url = '/' + g_blogname + module + '/list/cat_id/' + cat_id + '/same/lesson';
  new Ajax.Updater('main', url, {asynchronous:true, evalScripts:true});
}

function treeOpenContent(itemId) {
  var module=cat_tree.getUserData(itemId,"mod");
  cat_tree.openItem(itemId);
  itemId = itemId.replace(/^../g, '');
  if(module==null) return false;
  var url = '/'+g_blogname+module+'/list/cat_id/'+itemId;
  if ($('main') == undefined) window.location.href = url;
  g_catid = itemId;

  new Ajax.Updater('main', url,
    {asynchronous:true, evalScripts:true, onComplete:function(request, json){
      new Effect.Opacity('main', {duration:0.5, to:1});
    }, onLoading:function(request, json){
      new Effect.Opacity('main', {duration:0.5, to:.2});}});
  return false;
}

function checkError(name, condition, error) {
  var o = $(name);
  var v = $F(name);
  condition = eval(condition);
  var ename = 'error_for_' + name;
  if (condition==false) {
    $(ename).innerHTML = '&darr;' + error + '&darr;';
    $(ename).style.display = 'block';
    $(name).style.border = '1px solid red';
  } else {
    $(ename).style.display = 'none';
    $(name).style.border = '';
  }
  return condition;
}

function updateCategoryOnTree() {
  try {
    if (!(g_catid===undefined || cat_tree===undefined)) {
      cat_tree.selectItem('tr'+g_catid, false);
      cat_tree.openItem('tr'+g_catid);
      clearInterval(g_updateCatId);
    } else {
      g_updateCount++;
      if (g_updateCount>=100) {
        clearInterval(g_updateCatId);
      }
    }
  } catch (e) {}
}

function setCategory(catid) {
  g_catid = catid;
  g_updateCount = 0;
  g_updateCatId = setInterval('updateCategoryOnTree()', 200);
}

function sameUser(us_id, us_type) {  
  new Ajax.Updater('same-user',
    '/'+g_blogname+'user/sameUser/us_id/'+us_id+'/type/'+us_type,
    {asynchronous:true, evalScripts:true,
    onComplete:function(request, json){}});
  return false;
}

function vietDecode(s) {
  var s1 = "đáàảãạăắằẳẵặâấầẩẫậéèẻẽẹêếềểễệíìỉĩịóòỏõọôốồổỗộơớờởỡợúùủũụưứừửữựýỳỷỹỵ" +
           "ĐÁÀẢÃẠĂẮẰẲẴẶÂẤẦẨẪẬÉÈẺẼẸÊẾỀỂỄỆÍÌỈĨỊÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢÚÙỦŨỤƯỨỪỬỮỰÝỲỶỸỴ";
  var s2 = "daaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiooooooooooooooooouuuuuuuuuuuyyyyy" +
           "DAAAAAAAAAAAAAAAAAEEEEEEEEEEEIIIIIOOOOOOOOOOOOOOOOOUUUUUUUUUUUYYYYY";
  var r = "";
  for (var i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    var p = s1.indexOf(c);
    r += (p == -1)? c: s2.charAt(p);
  }
  return r;
}
