var errorIcon=new Image();errorIcon.src='http://i.neoseeker.com/d/my/exclamation.png';var ratedUp_mono=new Image();ratedUp_mono.src=imgurl+'images/thumb_up_grey.png';var ratedDown_mono=new Image();ratedDown_mono.src=imgurl+'images/thumb_down_grey.png';$(document).ready(function(){$.ajaxSetup({url:url+'ajaxhandler.php',type:"POST",timeout:15000});$("#submit_comment").click(function(){if($("#comment_form textarea").val()){var formArray=$("#comment_form").serialize();$.ajax({beforeSend:function(){$("#error_box_container").html('').hide();$("#message_box_container").html('').hide();$("#comment_form input, #comment_form textarea").attr('disabled','disabled');$("#loading_str").show();},data:"action=post_comment&"+formArray,success:function(html){$("#comment_form input, #comment_form textarea").attr('disabled','');$("#loading_str").hide();if(html.indexOf('Error:')==-1){$("#message_box_container").html('Thank you, your comment is posted.').show();$("#comments_list").append(html);$("#comment_form textarea").val('');$("#comments_list li#no_comment").remove();setTimeout('$("#message_box_container").hide()',3000);}else{$("#error_box_container").html('<img src="'+errorIcon.src+'" alt="Error!" /> '+html).show();$("#comment_form textarea").focus();}
$("#captcha_img").attr('src',url+'news/captcha_img.php?t='+Math.random());$("#captcha").val('');}});}else{alert("Please enter your comment before posting.");$("#comment_form textarea").focus();}});$("#comments_list .sc_btn").live('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:"action=post_comment&"+formArray,success:function(html){if(html.indexOf('Error:')==-1){if(actionTag=='submit_comment'){if($("#comment_form_"+cid).siblings('ul').length>0){$("#comment_form_"+cid).siblings('ul').append(html);}else{$("#comment_form_"+cid).after('<ul>'+html+'</ul>');}
$("#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();}
function show_reply_form(cid){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="author_id" value="'+document.comment_form.author_id.value+'" /><input type="hidden" name="parent" value="'+cid+'" /><input type="hidden" name="action" value="post_comment" />';formHTML+='<textarea name="comment" id="ec_'+cid+'" class="expandable" rows="5" style="width: 95%"><\/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);}}
$(".reply_comment").live('click',function(event){var cid=$(this).parents('li').attr('id').substr(1);show_reply_form(cid);});$(".edit_comment").live('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="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="action" value="post_comment" />';formHTML+='<textarea name="comment" id="ec_'+cid+'" class="expandable" rows="5" style="width: 95%"><\/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:"action=get_comment_raw_content&cid="+cid,success:function(html){$("#comment_form_"+cid+" textarea").val(html);}});}else{discard_form('comment_form_'+cid);}});$(".quote_reply").live('click',function(){var cid=$(this).parents('li').attr('id').substr(1);var authorname=$('#c'+cid).find('.heading .username').html();show_reply_form(cid);$.ajax({data:"action=get_comment_raw_content&cid="+cid,success:function(html){$("#ec_"+cid).val('[quote='+authorname+']'+html+'[/quote]\n\n');}});});$(".discard_btn").live('click',function(){discard_form($(this).parents('form').attr('id'));});$(".rm_comment").live('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:"action=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").live('click',function(){var cid=$(this).parents('li').attr('id').substr(1);$.ajax({data:"action=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_ip').live('click',function(){var cid=$(this).parents('.comment').attr('id').substr(1);$.ajax({data:"action=remove_comment&cid="+cid+"&confirm=all",success:function(html){if(html=='false'){window.location.reload();}else{$("#c"+cid).html(html);setTimeout('$("#c'+cid+'").hide();',3000);}}});});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:"action=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").live('click',rate_comment);$("#comments_list .thumbdown").live('click',rate_comment);});