/* File: js/controllers/comment.js, Ratio: 27.9% */

$(document).ready(function(){$('#addCommentForm').ajaxForm({dataType:'json',beforeSubmit:validateComment,success:addComment});$("#comment_list div.comment_row:odd").addClass("comment_row_alt");});function initComment(itemid,type){$.getJSON("/comments/get_comments/item_id:"+itemid+"/type:"+type,function(r){var data=r.comemnts;if(!data.length){$('#ajaxCommentLoader').hide();return;}
for(var x=0;x<data.length;x++){var html=getCommentHtml(data[x]);$(html).appendTo("#comment_list");}
var pager=r.pager;$(pager).appendTo("#comment_list");$('#ajaxCommentLoader').hide();initCommentPager();});}
function validateComment(formData){if(!my_id){userLoginBox();return false}
else{for(var i=0;i<formData.length;i++){if(!formData[i].value){alert('请输入评论内容');return false;}}
showSubmitLoading('comment_post');}}
function addComment(data){$('#comment_post').unblock();var s=data.success;var t="发表评论";var m=data.message;var r=data.redirect;if(s){var html=getCommentHtml(data);$(html).prependTo("#comment_list");}
else{Boxy.confirm(m,function(){if(r!=''){document.location.href=r;}},{title:t});}
$("#dataCommentBody").val("");}
function getCommentHtml(data){var c=$('#comment_list div:first-child').attr("class")=='comment_row'?'comment_row_alt':'comment_row';var html='';html+='<div class="'+c+'">';html+='<a href="/space/'+data.ps+'"><img src="'+imart_domain+'/static/avatars/crop_50/'+data.pp+'.jpg"></a>';html+='<div class="comment_details">';html+='<h4><a href="/space/'+data.ps+'">'+data.name+'</a></h4>';html+='<p>';html+=nl2br(data.comment);html+='</p>';if(data.dt==''){html+='<p class="post_date">just now</p></div></div>';}
else{html+='<p class="post_date">'+data.dt+'</p></div></div>';}
return html;}
function initCommentPager(){$(document).ready(function(){var divPaginationLinks="ul.pages li a";$(divPaginationLinks).click(function(){var url=$(this).attr("href");getComemnts(url);return false;});});}
function getComemnts(url){showSubmitLoading('comment_list');$.getJSON(url,function(r){$('#comment_list').html('');var data=r.comemnts;for(var x=0;x<data.length;x++){var html=getCommentHtml(data[x]);$(html).appendTo("#comment_list");}
var pager=r.pager;$(pager).appendTo("#comment_list");$('#ajaxCommentLoader').hide();initCommentPager();$('#comment_list').unblock();$.scrollTo('#comment_list');});}