function DrawComment(Page,RowNum){
  var successCallback = function(response){
    $("#results").html(response);  
  };
  $.ajax({
  type:"POST",
  data:{"BookmarkId":$('#BookmarkId').val(),
        "Page":Page,
        "RowNum":RowNum,
        "sessionid":$("#sessionid").val()},
  url: "draw_comment.php",
  cache: false,
  success: successCallback
  });
}

function PostComment(){

  $("#SpinnerComment").show();
  var successCallback = function(response){
      DrawComment(1,7);
    $("#Comment").val("");
    $("#SpinnerComment").hide();
  };
    var errorCallback = function (xml, status, e)
    {
      alert("Some error happened while connection");
    };
  if($("#Comment").val()==""){
    $("#SpinnerComment").hide();
    return;
  }else{
  $.ajax({
  type:"POST",
  data:{"BookmarkId":$('#BookmarkId').val(),
	"CommunityId":$('#CommunityId').val(),
	"Comment":$('#Comment').val(),
        "sessionid":$("#sessionid").val()},
  url: "post_comment.php",
  cache: false,
  success: successCallback,
  error:errorCallback
  });
  }

}

function DeleteComment(CommentId){
  if(!confirm("Are you sure to delete this comment?")) return;
  var successCallback = function(response){
      DrawComment(1,7);
  };
  $.ajax({
  type:"POST",
      data:{"BookmarkId":$('#BookmarkId').val(),
            "sessionid":$("#sessionid").val(),
            "CommentId":CommentId},
  url: "delete_comment.php",
  cache: false,
  success: successCallback
  });

}
function Vote(CommunityId,BookmarkId,CommentId,Flag){
  $("#imgVoteCount"+CommentId).attr("src","../image/loading2.gif");
  setTimeout("_Vote(" + CommunityId + "," + BookmarkId + "," + CommentId + "," + Flag + ")",1500);
}
function _Vote(CommunityId,BookmarkId,CommentId,Flag){
  var successCallback = function(response){
    if(Flag==1){
      $("#imgVoteCount"+CommentId).attr("src","../image/thumb_up_gray_s.png");
      $("#btnVote"+CommentId).attr("onclick","Vote(" + CommunityId + "," + BookmarkId + "," + CommentId +",0)");
    }else{
      $("#imgVoteCount"+CommentId).attr("src","../image/thumb_up_s.png");
      $("#btnVote"+CommentId).attr("onclick","Vote(" + CommunityId + "," + BookmarkId + "," + CommentId +",1)");
    }
    if(response>0){
      $("#VoteCount"+CommentId).html("+" + response + "<span style='font-size:85%'>UPs</span>");
    }else{
      $("#VoteCount"+CommentId).html("0<span style='font-size:85%'>UPs</span>");
    }
    DrawPoint();
  };
  $.ajax({
  type:"POST",
  data:{"CommunityId":CommunityId,
        "BookmarkId":BookmarkId,
        "Flag":Flag,
        "sessionid":$("#sessionid").val(),
        "CommentId":CommentId},
  url: "vote.php",
  cache: false,
  success: successCallback
  });

}
function VoteL(CommunityId,BookmarkId,CommentId,Flag){
  $("#btnVote"+CommentId).css('background-image','url(../image/loading2.gif)');
  setTimeout("_VoteL(" + CommunityId + "," + BookmarkId + "," + CommentId + "," + Flag + ")",1500);
}
function _VoteL(CommunityId,BookmarkId,CommentId,Flag){
  var successCallback = function(response){
    if(Flag==1){
      $("#btnVote"+CommentId).css("background-image","url(../image/thumb_up_gray_l.png)");
      $("#btnVote"+CommentId).attr("onclick","VoteL(" + CommunityId + "," + BookmarkId + "," + CommentId +",0)");
    }else{
      $("#btnVote"+CommentId).css("background-image","url(../image/thumb_up_l.png)");
      $("#btnVote"+CommentId).attr("onclick","VoteL(" + CommunityId + "," + BookmarkId + "," + CommentId +",1)");

    }
    if(response>0){
      $("#VoteCount"+CommentId).html("+" + response + "<span style='font-size:85%'>UPs</span>");
    }else{
      $("#VoteCount"+CommentId).html("0<span style='font-size:85%'>UPs</span>");
    }
    DrawPoint();
  };
  $.ajax({
  type:"POST",
  data:{"CommunityId":CommunityId,
        "BookmarkId":BookmarkId,
        "Flag":Flag,
        "sessionid":$("#sessionid").val(),
        "CommentId":CommentId},
  url: "vote.php",
  cache: false,
  success: successCallback
  });

}
function DrawPoint(){
  if($('#BookmarkId').val()==0) return;
  var successCallback = function(response){

    json = eval("("+response+")");
    if(json.IsError==1) alert("[Favorite]error");
    $("#Point").text(json.Point);
  }
  $.ajax({
  type:"POST",
  data:{"BookmarkId":$('#BookmarkId').val()
        },
  url: "get_point.php",
  cache: false,
  success: successCallback
  });
}
