function commentAjax(C,A,B){$("#a_comments ul").html("<li class=\"comments_info\">Loading comments...</li>");$.ajax({url:"/ajax/comments.php",type:"get",dataType:"json",data:{fileid:C,num:A,p:B},error:function(D,F,E){alert(F+" error "+E)},success:function(D){$("#a_comments ul").hide().html(D.comments).fadeIn();$(".comments_paging").html(D.pager);$(".comments_paging").show();$("span .paginer_page a").click(function(){href=$(this).attr("href");if(href.substr(0,4)=="#cp="){commentAjax(C,10,href.substr(4))}});$("span .paginer_next a").click(function(){href=$(this).attr("href");if(href.substr(0,4)=="#cp="){commentAjax(C,10,href.substr(4))}});$("span .paginer_prev a").click(function(){href=$(this).attr("href");if(href.substr(0,4)=="#cp="){commentAjax(C,10,href.substr(4))}});if(D.pager){$(".comments_more").html("Show fewer comments");$(".comments_more").unbind();$(".comments_more").click(function(){commentAjax(C,5,1)})}else{if(D.totalItems>5){$(".comments_more").html("See all "+D.totalItems+" comments");$(".comments_more").unbind();$(".comments_more").click(function(){commentAjax(C,10,1)})}else{$(".comments_more").hide()}}$(".comment_report").unbind();$(".comment_report").click(function(){str=$(this).attr("href");commentid=str.substr(1);$.post("/ajax/comments.php?a=report_comment",{cid:commentid},function(E,F){if(E.status==1){alert(E.message)}},"json");return false})}})}function emoticon(A){if(typeof document.selection!=="undefined"){$("#cf_comment").focus();document.selection.createRange().text=A}else{$("#cf_comment").val($("#cf_comment").val()+A).focus()}}$(function(){commentAjax(gameid,5,1);$("#add_a_comment_button").click(function(){$("#add_a_comment_button").hide();if($.cookie("userid")){$("#cf_username_span").html($.cookie("username"));$(".commentsform").show()}else{$("#comments_please_login_container").show()}});comment_length=parseInt($("#cf_chars_left").html());$("#cf_comment").keyup(function(){len=comment_length-$("#cf_comment").val().length;if(len<0){len=0;v=$(this).val().substr(0,comment_length);$(this).val(v)}$("#cf_chars_left").html(len)});$("span.comments_smile img").click(function(){str=$(this).attr("src");emoticon("[em:"+str.slice(11,-4)+":]");len=comment_length-$("#cf_comment").val().length;if(len<0){len=0;v=$("#cf_comment").val().substr(0,comment_length);$("#cf_comment").val(v)}$("#cf_chars_left").html(len)});$("#cf_submit").click(function(){if($("#cf_comment").val().length==0){$("span.error").show();return false}fileid=$(this).attr("href").substr(1);$.ajax({url:"/ajax/comments.php?a=submit_comment&fileid="+fileid,type:"post",dataType:"json",data:{message:$("#cf_comment").val()},error:function(A,C,B){alert(C+" error "+B)},success:function(A){if(A.status==1){commentAjax(fileid,5,1);$("#cf_comment").val("");$("#cf_chars_left").html(comment_length);$("span.error").hide()}else{alert(A.message)}}})})})

