function init_inline_post_edits(submit_url,post_class,edit_link_id_regex,content_id_replacement){if(!submit_url||(submit_url.length===0)){throw"Empty submit url";}
$('.'+post_class).each(function(){var edit_link_id=this.id;var post_id=edit_link_id.match(edit_link_id_regex)[1];var post_content_id=edit_link_id.replace(edit_link_id_regex,content_id_replacement);var post_content=$('#'+post_content_id);var edit_toggle_link=$(this);edit_toggle_link.click(function(){if(!edit_toggle_link.data('open')){open_edit_post_area(edit_toggle_link,post_content,post_id,submit_url);}else{close_edit_post_area(edit_toggle_link,post_content,post_id);}
return false;});});}
$.site_feature('forum__should_be_normal_feature',function(){var default_platforms=null;$('#new-thread-form, #new-reply-form').submit(maintenance_check);$.live('#new-reply-form','submit',function(){if(!user_logged_in){PF.login_required(function(){$('#new-reply-form').submit();});return false;}});$('.show_thread_link').click(function(){var thread_id=$(this).attr('id').split('-')[1];$('#thread_row-'+thread_id).show();$('#show_thread_row-'+thread_id).hide();return false;});$('.ignore_user_link').click(function(){var post_id=$(this).attr('id').split('-',3)[1];var username=$(this).attr('id').split('-',3)[2];$('#ignore_status-'+post_id).html('');$('#lb_ignore_user .username').text(username);var ignore_link=$(this);$('#lb_ignore_user').showPopup({on_confirm:function(){$('#ignore_status_loader-'+post_id).show();ignore_link.hide();function showError(txt){$('#ignore_status-'+post_id).html(txt);$('#ignore_status_loader-'+post_id).hide();$('#ignore_user_link-'+post_id+'-'+username).show();}
$.ajax({url:'/a/xhr/ignore_user',data:{'user':username},type:'post',dataType:'json',timeout:20000,error:function(XMLHttpRequest,textStatus,errorThrown){if(errorThrown==='timeout'){showError('Timeout when trying to ignore user.');}else{showError('Error ignoring user');}},success:function(data,textStatus){if(data.status=='success'){location.reload(true);}else{showError('Error ignoring user.');}}});}});return false;});$('.show_post_link').click(function(){var post_id=$(this).attr('id').split('-')[1];$('#post_ignored_message-'+post_id).hide();$('#post_ignored_body-'+post_id).show();$('#post_info-'+post_id).show();$('#post_content-'+post_id).removeClass('post_content_ignored');$('#post_content_upper-'+post_id).removeClass('forum_thread_post_content_upper_ignored');$('#post_content_lower-'+post_id).removeClass('forum_thread_post_content_lower_ignored');return false;});$('.js_quote_reply').click(function(){var post_id=$(this).attr('id').split('-')[1];var author_id=$('#post_metadata-'+post_id).attr('data-author_id');var username=$('#post_metadata-'+post_id+' .post_username').attr('id').split('-')[1];var quote_text=$('#quote_value-'+post_id).attr('value');var content="[quote="
+username
+";"
+post_id
+";"
+author_id
+"]"
+quote_text.replace(/^<p>([^<]*)<\/p>$/,'$1')
+"[/quote]<p></p>";var editor=tinyMCE.get('new_post_body');var existing_content=editor.getContent();editor.setContent(editor.getContent()+content);return true;});var bind_forum_actions=null;bind_forum_actions=function(context){var replace_post=function(post_id,html){var post_container=$("#forum_thread_post-"+post_id);post_container.html(html);bind_forum_actions(post_container);};var center_of_post=function(post_id){return $('#js_post_content-'+post_id).offset_center();};var delete_post_ajax=function(data,after){$.ajaxPost({url:'/a/xhr/delete_forum_post',data:data,loading_anim:{pos:'before',element:$('#js_delete_post-'+data.id)},success:function(data){if(data.status==='deleted'){after(data);}}});};$('.js_delete_forum_post',context).click(function(){var post_id=this.id.split('-')[1];$('#lb_delete_own_post').showPopup({on_confirm:function(){delete_post_ajax({'id':post_id},function(){$('#forum_thread_post-'+post_id).fadeOut();});}});return false;});$('.js_mod_delete_forum_post',context).click(function(){var post_id=this.id.split('-')[1];var del_reason=$('#deletion-reason');var mdd=$('#lb_moderator_delete');mdd.find('#id-to-delete').val(post_id);mdd.showPopup({on_confirm:function(){var reason=$.trim_ws(del_reason.val());if(reason){delete_post_ajax({'id':post_id,'reason':reason},function(data){replace_post(post_id,data.post_html);});}else{}}});return false;});$('.js_report_post',context).click(function(){var link=$(this);var post_id=this.id.split('-')[1];var justification=$('#report-justification');var mdd=$('#lb_report_post');mdd.find('#id-to-report').val(post_id);mdd.showPopup({on_confirm:function(){var reason=$.trim_ws(justification.val());$.ajaxPost({url:'/a/forums/report_post',data:{'post_id':post_id,'justification':reason},success:function(){link.text('Reported').css('color','#a30303');}});}});return false;});$('.js_mod_restore_forum_post',context).click(function(){if(!confirm("Are you sure you want to restore this post?")){return false;}
var post_id=this.id.split('-')[1];var restore_link=$(this);$.ajaxPost({url:'/a/xhr/restore_forum_post',data:{'id':post_id},loading_anim:{pos:'before',element:$('#js_restore_post-'+post_id)},success:function(data){if(data.status==='success'){replace_post(post_id,data.post_html);}}});return false;});var replace_thread_tr=function(id,html){var thread_row=$("#thread_row-"+id);thread_row.html(html);bind_forum_actions(thread_row);};$('.js_ignore_thread',context).click(function(){var thread_id=this.id.split('-')[1];if(!confirm('Are you sure you wish to stop following this thread?')){return false;}
$.ajaxPost({url:'/a/xhr/ignore_forum_thread',data:{'id':thread_id},success:function(data){location.reload(true);},error:function(data){alert('There was an error when trying to ignore this thread');}});return false;});$('.js_mod_delete_thread',context).click(function(){var thread_id=this.id.split('-')[1];var thread_row=$("#thread_row-"+thread_id);var del_reason=$('#deletion-reason');var mdd=$('#lb_moderator_delete');mdd.find('#id-to-delete').val(thread_id);mdd.showPopup({on_confirm:function(){var reason=$.trim_ws(del_reason.val());if(reason){$.ajaxPost({url:'/a/xhr/delete_forum_thread',data:{'id':thread_id,'reason':reason,'show_thread_forum':thread_row.hasClass('show_thread_forum')?'true':''},loading_anim:{pos:'before',element:$('#js_delete_thread-'+thread_id)},success:function(data){if(data.status==='success'){replace_thread_tr(thread_id,data.thread_tr_html);thread_row.addClass('deleted');}}});}}});return false;});$('.js_mod_restore_thread',context).click(function(){if(!confirm("Are you sure you want to restore this thread?")){return false;}
var thread_id=this.id.split('-')[1];var thread_row=$("#thread_row-"+thread_id);var restore_link=$(this);$.ajaxPost({url:'/a/xhr/restore_forum_thread',data:{'id':thread_id,'show_thread_forum':thread_row.hasClass('show_thread_forum')?'true':''},loading_anim:{pos:'before',element:restore_link},success:function(data){if(data.status==='success'){replace_thread_tr(thread_id,data.thread_html);thread_row.removeClass('deleted');}}});return false;});init_inline_post_edits('/a/xhr/edit_forum_post','js_edit_forum_post',/js_edit_post-(\d+)/,'js_post_content-$1');};bind_forum_actions();function update_post_overview_text(game_txt){if(game_txt===undefined){return;}
if((game_txt=="Start typing game name...")||(game_txt==='')){game_txt='General Discussion';}
var txt=game_txt;var section=window.platform_section_mapping[$('#platform').val()];if(section){txt+=' for '+section;}
$('#section_name').text(txt);}
function update_overview(){update_post_overview_text($('#js_autocomplete_for_id_related_game').val());}
function check_game(){if(!$(this).val()){$('#id_related_game').val('');update_overview();if(default_platforms){$('#platform').replaceWith(default_platforms);}}
return true;}
$('#js_autocomplete_for_id_related_game').keyup(check_game);function xhr_game_result(t,game_name,gps){if(!default_platforms){default_platforms=$("#platform").clone();}
var s=$("#platform");s.empty();s.addOption('','Select a platform');s.addOption('-','------------');for(var i=0;i<gps.length;i++){s.addOption(gps[i].pslug,gps[i].pname);}
s.val($('#default_platform').val());update_post_overview_text(game_name);}
$('input[id^=js_autocomplete_for_]').each(function(){var el=$(this);var id=el.attr('id');var m=/js_autocomplete_for_(\w+)/.exec(id);el.result(function(event,data,formatted){xhr_game_result(this,data.name,data.gtps);});});$('#platform').change(update_overview);update_overview();$('#id_related_game').val('');});$(document).ready(function(){$('a.mark_post_up').click(function(){$('div.menu_mark_post').hide();$(this).parent().parent().find('.menu_mark_post_up').toggle();return false;});$('a.mark_post_down').click(function(){$('div.menu_mark_post').hide();$(this).parent().parent().find('.menu_mark_post_down').toggle();return false;});$('a.mark_post').click(function(){var selected_mark_post_link=$(this);var mark_post_wrapper=$(this).parents('.mark_post_wrapper');var thread_parent=$(this).parents('.forum_thread_post');var select=!selected_mark_post_link.hasClass('selected');pf_ajax({url:'/a/xhr/mark_post',data:{'post':thread_parent.attr('id').split('-')[1],'mark_type':$(this).attr('rel'),'select':select},type:'POST',success:function(data,textStatus){if(data.selected==='false'){selected_mark_post_link.removeClass('selected');mark_post_wrapper.find('a.mark_post_up').removeClass('selected');mark_post_wrapper.find('a.mark_post_down').removeClass('selected');return;}
if(data.type=='positive'){mark_post_wrapper.find('a.mark_post_up').addClass('selected');mark_post_wrapper.find('a.mark_post_down').removeClass('selected');}
if(data.type=='negative'){mark_post_wrapper.find('a.mark_post_up').removeClass('selected');mark_post_wrapper.find('a.mark_post_down').addClass('selected');}
mark_post_wrapper.find('a.mark_post').removeClass('selected');selected_mark_post_link.addClass('selected');}});return false;});$('a.get_post_score').click(function(){var thread_parent=$(this).parents('.forum_thread_post');pf_ajax({url:"/a/xhr/get_post_score",data:{'post':thread_parent.attr('id').split('-')[1]},type:'GET',success:function(data,textStatus){alert(data.score_info);}});return false;});});$.feature('f_forum',function(){$('#forum_platform_list').change(function(){window.location=$(this).val();});function load_more_threads(url)
{var last_thread_id=$('#thread_table tr:last').attr('id').split('-')[1];$.post(url,{last_thread_id:last_thread_id},function(more_threads){$('#thread_table').append(more_threads);if($('#thread_table tr:last').attr('data-is-last')=='true'){$('.load_more_threads').hide();}});}
$.live('.load_more_threads','click',function(){load_more_threads($(this).find('a').attr('data-ajax-url'));return false;});});