function need_to_show_more(){if(comments_page<max_comments_page){upper=comments_count-((comments_page*comments_per_page))-10;lower=comments_count-((comments_page+1)*comments_per_page)-9;if(lower<1)lower=1;if(sort_order=='oldest'){upper=((comments_page+1)*comments_per_page)+10;lower=(comments_page*comments_per_page)+11;if(upper>comments_count)upper=comments_count;}
$('#show_more_comments').html('Show '+lower+'-'+upper+' of '+comments_count+' comments');$('#show_more_comments').show();}else{$('#show_more_comments').hide();}}
function show_hide_comments(upper,lower,order){var comments=$('#paged_comments');jQuery.get('/do/comment_page',{'node_id':comment_node_id,'lower':lower,'upper':upper,'section_id':comment_section_id,'order':order},function(data){comments.append(data);});need_to_show_more();}
function comments_next(button){var upper=comments_count-((comments_page*comments_per_page))-10;var lower=comments_count-((comments_page+1)*comments_per_page)-9;if(lower<1)lower=1;if(sort_order=='oldest'){upper=((comments_page+1)*comments_per_page)+10;lower=(comments_page*comments_per_page)+11;if(upper>comments_count)upper=comments_count;}
comments_page=comments_page+1;show_hide_comments(upper,lower,sort_order);}
function expand_all(button){var upper=comments_count;var lower=1;var comments=$('#paged_comments');jQuery.get('/do/comment_page',{'node_id':comment_node_id,'lower':lower,'upper':upper,'section_id':comment_section_id,'order':sort_order},function(data){comments.html(data);});comments_page=max_comments_page;need_to_show_more();$('#subscribe_order').html('<a href="#comments" onclick="collapse_all();return false;">Collapse All</a>');}
function collapse_all(button){var upper=comments_count;var lower=comments_count-9;comments_page=0;if(lower<1)lower=1;if(sort_order=='oldest'){upper=10;lower=1;}
var comments=$('#paged_comments');jQuery.get('/do/comment_page',{'node_id':comment_node_id,'lower':lower,'upper':upper,'section_id':comment_section_id,'order':sort_order},function(data){comments.html(data);});need_to_show_more();$('#subscribe_order').html('<a href="#comments" onclick="expand_all()">Expand All</a>');}
function sort_oldest(button){var lower=1;var upper=10;sort_order='oldest';comments_page=0;jQuery.get('/do/comment_page',{'node_id':comment_node_id,'lower':lower,'upper':upper,'section_id':comment_section_id,'order':'oldest'},function(data){$('#paged_comments').html(data);});need_to_show_more();$('#newest_option').show();$('#oldest_option').hide();$('#subscribe_order').html('<a href="#comments" onclick="expand_all();return false;">Expand All</a>');}
function sort_newest(button){sort_order='newest';var upper=comments_count;var lower=comments_count-9;comments_page=0;if(lower<1)lower=1;var comments=$('#paged_comments');jQuery.get('/do/comment_page',{'node_id':comment_node_id,'lower':lower,'upper':upper,'section_id':comment_section_id},function(data){comments.html(data);});need_to_show_more();$('#newest_option').hide();$('#oldest_option').show();$('#subscribe_order').html('<a href="#comments" onclick="expand_all();return false;">Expand All</a>');}