comment_asset=
{
    commentLoading: false,
    commentPosting: false,
    commentPage: 1,
    firstTime: true,
    currentTab: 0,
  insertSymbol: function(symbol)
  {
    var obj=$('comment_content');
    if (document.selection)
    {
      obj.focus();
      sel = document.selection.createRange();
      sel.text = symbol;
    }
    else if (obj.selectionStart || obj.selectionStart == 0)
    {
      var startPos = obj.selectionStart;
      var endPos = obj.selectionEnd;
      obj.value = obj.value.substring(0, startPos)
            + symbol
            + obj.value.substring(endPos, obj.value.length);
    } 
    else
    {
      obj.value += symbol;
    }
  },
  loadComment:  function(sid, p){
     if (comment_asset.commentLoading)
         return false;
     url = "/main/comment/sid/" + sid + "?page=" + p;
     new Ajax.Request(url,{ asynchronous:true, 
                            evalScripts:true, 
                            method: 'get',
                            onCreate: function(){
                              $('comment_loading').show();
                              comment_asset.commentLoading = true;
                            }, 
                            onComplete: function(res, js)
                            {
                              $('comment_loading').hide();
                              $('comment_area').innerHTML = res.responseText;
                              comment_asset.commentPage=p;
                              comment_asset.commentLoading = false;
                            }
                          }); 
    return false;
   },
   deleteComment: function(cid,sid)
   {
     if (!confirm("Bạn chắc chắn xóa bình luận này"))
       return false;
     if (comment_asset.commentLoading==true)
      return false;
     url = '/main/delcomment';
     new Ajax.Request(url,{ asynchronous:true, 
                            evalScripts:true, 
                            method: 'post',
                            onCreate: function(){
                              $('comment_loading').show();
                              comment_asset.commentLoading = true;
                            }, 
                            parameters: 'cid='+cid+'&sid='+sid+'&page='+comment_asset.commentPage,
                            onComplete: function(res, js)
                            {
                              $('comment_area').innerHTML = res.responseText;
                              $('comment_loading').hide();
                              comment_asset.commentLoading = false;
                            }
                          }); 
    return false;
   },
    saveComment: function(sid, cid){
      if (cid == '') {
          textAreaID = "comment_content";
      } else {            
          textAreaID = "comment_content_" + cid;
      }
      if ($F(textAreaID)=="")
          return;
      if (comment_asset.commentLoading)
          return;                  

      url = '/main/savecomment/sid/'+sid+'/cid/'+cid+'?page='+comment_asset.commentPage;
      new Ajax.Request(url, { asynchronous:true, 
                              evalScripts:true, 
                              method: 'post',
                              onCreate: function(){
                                $('comment_loading').show();
                                comment_asset.commentLoading = true;
                              }, 
                              parameters: $(textAreaID).serialize(),
                              onComplete: function(res, js)
                              {
                                $('comment_area').innerHTML = res.responseText;
                                $('comment_loading').hide();
                                comment_asset.commentLoading = false;
                              }
                            }); 
      return false;
   },
    showReplyBox: function(cid)
    {
        $("reply_box_" + cid).show();
        if ($("reply_hint_" + cid)!=null)
          $("reply_hint_" + cid).hide();
        $("comment_content_" + cid).focus();
        return false;
    },
    showReply: function(cid)
    {
        $$('div.reply_comment_' + cid).each(function(item){item.show()});
        $('display_reply_' + cid).hide();
        return false;
    }
}