var errorIcon=new Image();errorIcon.src=imgurl+'d/my/exclamation.png';var ratedUp_mono=new Image();ratedUp_mono.src=imgurl+'d/icons/thumb_s_up_grey.png';var ratedDown_mono=new Image();ratedDown_mono.src=imgurl+'d/icons/thumb_s_down_grey.png';$(document).ready(function(){$.ajaxSetup({type:"POST",timeout:15000,success:function(html){if(html=="false"){window.location.reload();}},error:function(){}});$('textarea#comment').livequery('focus',function(){if($(this).val()=='Write your comment...'){$(this).val('');}}).livequery('blur',function(){if($(this).val()==''){$(this).val('Write your comment...');}});$("#submit_comment").livequery('click',function(){if($("#comment_form textarea").val()){var formArray=$("#comment_form").serialize();$.ajax({beforeSend:function(){$("#cmt_errorbox").html('').hide();$("#cmt_msgbox").html('').hide();$("input, textarea",'#comment_form').attr('disabled','disabled');},data:"in_ajax_mode=1&cmt_act=post_comment&"+formArray,success:function(html){$("input, textarea",'#comment_form').attr('disabled','');if(html.indexOf('Error:')==-1){$("#cmt_msgbox").html('Thank you, your comment is posted.').show();$("#comments_list").append(html);$("#comment_form textarea").val('');$("#comments_list li#no_comment").remove();setTimeout('$("#cmt_msgbox").hide()',3000);}else{$("#cmt_errorbox").html('<img src="'+errorIcon.src+'" alt="Error!" /> '+html).show();$("#comment_form textarea").focus();}}});}else{alert("Please enter your comment before posting.");$("#comment_form textarea").focus();}});$("#comments_list .sc_btn").livequery('click',function(){var cid=$(this).attr('id').split('_')[$(this).attr('id').split('_').length-1];var actionTag=$(this).attr('name');if($("#ec_"+cid).val()){var formArray=$("#comment_form_"+cid).serialize();$.ajax({beforeSend:function(){$("#errorbox_"+cid).html('').hide();$("#msgbox_"+cid).html('').hide();},data:"in_ajax_mode=1&cmt_act=post_comment&"+formArray,success:function(html){if(html.indexOf('Error:')==-1){if(actionTag=='submit_comment'){var curLevel=parseInt($("#comment_form_"+cid).parents('ul').attr('level'));if(DISABLE_AFTER_LEVEL>1){if($("#comment_form_"+cid).siblings('ul').length>0){$("#comment_form_"+cid).siblings('ul').append(html);}else if(curLevel>=DISABLE_AFTER_LEVEL){$("#comment_form_"+cid).parents('ul:first').append(html);}else{$("#comment_form_"+cid).after('<ul class="cchild" level="'+(curLevel+1)+'">'+html+'</ul>');}}else{$("ul#comments_list").append(html);}
$("#msgbox_"+cid).html('Thank you, your comment is posted.').show();}else{$('li#c'+cid).replaceWith(html);$("#msgbox_"+cid).html('Thank you, the comment is updated.').show();}
$("#comment_form_"+cid+" textarea").val('');$("#comment_form_"+cid).hide();setTimeout('$("#msgbox_'+cid+'").hide()',3000);}else{$("#errorbox_"+cid).html('<img src="'+errorIcon.src+'" alt="Error!" /> '+html).show();$("#comment_form_"+cid+" textarea").focus();}}});}else{alert("Please enter your comment before posting.");$("#ec_"+cid).focus();}});function discard_form(formID){$('#'+formID).replaceWith('<div id="'+formID+'"></div>');var cid=formID.split('_')[formID.split('_').length-1];$("#errorbox_"+cid).html('').hide();$("#msgbox_"+cid).html('').hide();}
$(".reply_comment").livequery('click',function(){var cid=$(this).parents('li').attr('id').substr(1);var tagNm=document.getElementById('comment_form_'+cid).tagName.toLowerCase();if(tagNm=='div'){var formHTML='<form method="post" id="comment_form_'+cid+'" name="ec_form" action=""><input type="hidden" name="ctype_id" value="'+document.comment_form.ctype_id.value+'" /><input type="hidden" name="item_ownerid" value="'+document.comment_form.item_ownerid.value+'" /><input type="hidden" name="author_id" value="'+document.comment_form.author_id.value+'" /><input type="hidden" name="parent" value="'+cid+'" /><input type="hidden" name="cmt_act" value="post_comment" />';formHTML+='<textarea name="comment" class="expandable" id="ec_'+cid+'"><\/textarea><br /><input type="button" name="submit_comment" class="sc_btn" value="Post comment" id="sc_'+cid+'" /> <input type="reset" class="discard_btn" value="Discard" /><\/form>';$('#comment_form_'+cid).replaceWith(formHTML);}else{discard_form('comment_form_'+cid);}});$(".edit_comment").livequery('click',function(){var cid=$(this).parents('li').attr('id').substr(1);var tagNm=document.getElementById('comment_form_'+cid).tagName.toLowerCase();if(tagNm=='div'){var formHTML='<form method="post" id="comment_form_'+cid+'" name="ec_form" action=""><input type="hidden" name="ctype_id" value="'+document.comment_form.ctype_id.value+'" /><input type="hidden" name="item_ownerid" value="'+document.comment_form.item_ownerid.value+'" /><input type="hidden" name="author_id" value="'+document.comment_form.author_id.value+'" /><input type="hidden" name="comment_id" value="'+cid+'" /><input type="hidden" name="last_updated_by" value="'+document.comment_form.author_id.value+'" /><input type="hidden" name="cmt_act" value="post_comment" />';formHTML+='<textarea name="comment" class="expandable" id="ec_'+cid+'"><\/textarea><br /><input type="button" name="update_comment" class="sc_btn" value="Update" id="sc_'+cid+'" /> <input type="reset" class="discard_btn" value="Discard" /><\/form>';$('#comment_form_'+cid).replaceWith(formHTML);$.ajax({data:"in_ajax_mode=1&cmt_act=get_comment_raw_content&cid="+cid,success:function(html){$("#comment_form_"+cid+" textarea").val(html);var lineNum=html.split("\n").length;if(lineNum>3){$("#comment_form_"+cid+" textarea").attr('rows',lineNum+3);}}});}else{discard_form('comment_form_'+cid);}});$(".quote_comment").livequery('click',function(){var cid=$(this).parents('li').attr('id').substr(1);var authorname=$('.username','#c'+cid).html();$.ajax({data:"in_ajax_mode=1&cmt_act=get_comment_raw_content&cid="+cid,success:function(html){$("#comment").val('[quote='+authorname+']'+html+'[/quote]\n\n');document.getElementById('comment').scrollIntoView();$('form#comment_form input[name="parent"]').val(cid);}});});$(".discard_btn").livequery('click',function(){discard_form($(this).parents('form').attr('id'));});$(".rm_comment").livequery('click',function(){var cid=$(this).parents('li').attr('id').substr(1);var tagNm=document.getElementById('hb_'+cid).tagName.toLowerCase();if(tagNm=='div'){var offset=$(this).offset();var portWidth=window.innerWidth;$.ajax({data:"in_ajax_mode=1&cmt_act=check_can_remove&cid="+cid,success:function(html){var formHTML='<form method="post" class="hb" id="hb_'+cid+'" name="rm_form" action=""><input type="hidden" name="cid" value="'+cid+'" />';if(html=='is_parent'){formHTML+='This comment has replies and cannot be removed.<br /><label><input type="radio" name="confirm" value="all" checked="checked" /> Remove the comment and remove all its child comment(s)</label><br /><label><input type="radio" name="confirm" value="move" /> Or remove the comment and move all its child comment(s) one level up</label><br />';}else{formHTML+='Are you sure to remove this comment?<br />';}
formHTML+='<input type="button" name="cfm_rm_comment" class="cfm_rm_comment" value="Remove comment" /> <input type="reset" class="discard_btn" value="Cancel removal" /><\/form>';$("#hb_"+cid).replaceWith(formHTML);$("#hb_"+cid).show().css('top',(offset.top+20)+'px').css('right',(portWidth-offset.left-25)+'px');}});}else{discard_form('hb_'+cid);}});$(".cfm_rm_comment").livequery('click',function(){var cid=$(this).parents('li').attr('id').substr(1);$.ajax({data:"in_ajax_mode=1&cmt_act=remove_comment&"+$("#hb_"+cid).serialize(),success:function(html){if(html=='false'){window.location.reload();}else{$("#hb_"+cid).hide();$("#msgbox_"+cid).html(html).show();if(html.indexOf('moved its child up')==-1){setTimeout('$("li#c'+cid+'").remove();$("#msgbox_'+cid+'").hide();',3000);}else{var code='$("li#c'+cid+'").after($("li#c'+cid+' ul").html());$("li#c'+cid+'").remove();$("#msgbox_'+cid+'").hide();';setTimeout(code,3000);}}}});});$(".rm_comment_by_author").livequery('click',function(){var cid=$(this).parents('li').attr('id').substr(1);var tagNm=document.getElementById('hb_'+cid).tagName.toLowerCase();if(tagNm=='div'){var offset=$(this).offset();var portWidth=window.innerWidth;var formHTML='<form method="post" class="hb" id="hb_'+cid+'" name="rm_form" action=""><input type="hidden" name="cid" value="'+cid+'" />';formHTML+='Are you sure to remove this comment written by you?<br />';formHTML+='<input type="button" name="cfm_rm_comment_by_author" class="cfm_rm_comment_by_author" value="Remove comment" /> <input type="reset" class="discard_btn" value="Cancel removal" /><\/form>';$("#hb_"+cid).replaceWith(formHTML);$("#hb_"+cid).show().css('top',(offset.top+20)+'px').css('right',(portWidth-offset.left-25)+'px');}else{discard_form('hb_'+cid);}});$(".cfm_rm_comment_by_author").livequery('click',function(){var cid=$(this).parents('li').attr('id').substr(1);$.ajax({data:"in_ajax_mode=1&cmt_act=remove_comment_by_author&"+$("#hb_"+cid).serialize(),success:function(html){if(html=='false'){window.location.reload();}else{$("#hb_"+cid).hide();$("#msgbox_"+cid).html('Thank you. Your comment has been removed.').show();if(html.indexOf('with children')!=-1){var code='$("li#c'+cid+' .commenttext:first").wrapInner("<blockquote></blockquote>").addClass("hidden_comment").prepend("*** This comment was removed by you. ***");';code+='$("li#c'+cid+' .heading .reply_comment:first, li#c'+cid+' .heading .quote_comment:first, li#c'+cid+' .heading .options .edit_comment:first").remove();';}else{var code='$("li#c'+cid+'").remove();';}
code+='$("#msgbox_'+cid+'").hide();';setTimeout(code,3000);}}});});$('.restore_removed_comment').click(function(){var cid=$(this).parents('li').attr('id').substr(1);$.ajax({data:"in_ajax_mode=1&cmt_act=restore_removed_comment&cid="+cid,success:function(html){if(html.indexOf('Error:')!=-1){alert(html);}else{$('#hc_link_'+cid).fadeOut('slow');$("#msgbox_"+cid).html('The comment has been restored. Refresh the page to make it shown properly.').show();setTimeout('$("#msgbox_'+cid+'").hide();',3000);}}});});$('.show_comment_tools').livequery('click',function(){var cid=$(this).parents('li').attr('id').substr(1);var tagNm=document.getElementById('hb_'+cid).tagName.toLowerCase();if(tagNm=='div'){var offset=$(this).offset();var portWidth=window.innerWidth;var html='<form method="post" id="hb_'+cid+'" action="" class="hb" onsubmit="return false;" title="View all comments by these options">Comment Mod Tools:<ul>';var author_id=$(this).attr('author_id');if(author_id>0){html+='<li>View all by <a href="http://www.neoseeker.com/tools/comment_modcp.php?fn=view_all_by_user&memberid='+author_id+'" target="_blank">'+$('.username','#c'+cid+' .heading').html()+'<\/a><\/li>';}
if(!author_id){var author_email=$(this).attr('author_email');html+='<li>View all by <a href="http://www.neoseeker.com/tools/comment_modcp.php?fn=view_all_by_email&email='+author_email+'" target="_blank">'+author_email+'<\/a><\/li>';}
var author_ip=$(this).attr('author_ip');html+='<li>View all by <a href="http://www.neoseeker.com/tools/comment_modcp.php?fn=view_all_by_ip&IP='+author_ip+'" target="_blank">'+author_ip+'<\/a><\/li>';html+='<\/ul>';$("#hb_"+cid).replaceWith(html);$("#hb_"+cid).css('top',(offset.top+20)+'px').css('right',(portWidth-offset.left-25)+'px').show();}else{discard_form('hb_'+cid);}})
function rate_comment(){var cid=$(this).parents('li').attr('id').substr(1);var sign=($(this).attr('class')=='thumbup'?'+':'-');$.ajax({beforeSend:function(){$("#rating_"+cid).fadeOut('fast');},data:"in_ajax_mode=1&cmt_act=rate_comment&sign="+sign+"&cid="+cid,success:function(html){if(html.indexOf('Error:')!=-1){alert(html);}else{$("#comments_list #c"+cid+" .heading:first .thumbup").attr('src',ratedUp_mono.src);$("#comments_list #c"+cid+" .heading:first .thumbdown").attr('src',ratedDown_mono.src);$("#rating_"+cid).html(html).fadeIn('fast');}}});}
$("#comments_list .thumbup").livequery('click',rate_comment);$("#comments_list .thumbdown").livequery('click',rate_comment);$('.restore_comment_rating').click(function(){var cid=$(this).parents('li').attr('id').substr(1);$.ajax({data:"in_ajax_mode=1&cmt_act=restore_comment&cid="+cid,success:function(html){if(html.indexOf('Error:')!=-1){alert(html);}else{$('#hc_link_'+cid).fadeOut('slow');$('#hc_'+cid).removeClass('hidden_comment');$('#hc_'+cid+' .hlabel').remove();}}});});});