var httpRequest;var postid;var previoustrail=0;var cssclass='';var main_post_table=document.getElementById('main_posts_table');var deleted_hash;var table_rows=main_post_table.rows.length;function confirmDelete(msg_flag){if(msg_flag){return confirm("Deleting the first post will cause the entire thread to be deleted.\n\nAre you sure you would like to continue?");}else{return confirm("Are you sure you would like to delete this post?");}}
function delete_request(post_id,msg_flag){if(confirmDelete(msg_flag)){postid=post_id;document.getElementById('loading_'+postid).style.display='';var url_delete="/post/ajaxdeletePost?id="+id+"&trail="+trail+"&pid="+postid+"&forum="+forum+"&ajax_request=1"+query;httpRequest=CreateXmlHttpReq(_postdeleteHandler);if(httpRequest){XmlHttpGET(httpRequest,url_delete);}}}
function _postdeleteHandler(){if(httpRequest.readyState==4){document.getElementById('loading_'+postid).style.display='none';if(httpRequest.status==200){if(httpRequest.responseXML){var responsedata=httpRequest.responseXML;if(responsedata.getElementsByTagName("error")[0]){if(responsedata.getElementsByTagName("error")[0].firstChild.nodeValue){alert(responsedata.getElementsByTagName("error")[0].firstChild.nodeValue.replace(/<\S[^><]*>/g,''));}
if(responsedata.getElementsByTagName("redirect_url")[0]){window.location=responsedata.getElementsByTagName("redirect_url")[0].firstChild.nodeValue;}
return false;}
Effect.Fade('tr_'+postid);_remove_post();previoustrail=(trail-replies_perpage);var ajax_pagination_data=responsedata.getElementsByTagName("pagination")[0].firstChild.nodeValue;if(ajax_pagination_data){if(responsedata.getElementsByTagName("postid")[0]){var ajax_post_id=responsedata.getElementsByTagName("postid")[0].firstChild.nodeValue;var ajax_data_td_1=responsedata.getElementsByTagName("data_td_1")[0].firstChild.nodeValue;var ajax_data_td_2=responsedata.getElementsByTagName("data_td_2")[0].firstChild.nodeValue;var td1_id=responsedata.getElementsByTagName("td1_id")[0].firstChild.nodeValue;var td2_id=responsedata.getElementsByTagName("td2_id")[0].firstChild.nodeValue;var _tr=document.createElement("tr");_tr.id=ajax_post_id;_tr.style.display="none";var _td1=document.createElement("td");_td1.innerHTML=ajax_data_td_1;_td1.id=td1_id;_td1.setAttribute("valign","top");_td1.setAttribute("width","19%");var _td2=document.createElement("td");_td2.innerHTML=ajax_data_td_2;_td2.id=td2_id;_td2.setAttribute("valign","top");_td2.style.height='100%';_tr.appendChild(_td1);_tr.appendChild(_td2);main_post_table.appendChild(_tr);_css_walk();Effect.Appear(ajax_post_id,{duration:2.0,from:0.0,to:2.0});}
setTimeout("_css_walk()",2000);document.getElementById('div_pagination').innerHTML=ajax_pagination_data;if(table_rows<1){window.location="/post?id="+id+"&trail="+previoustrail+query;}}else{window.location="/?forum="+forum;}}}else{alert('There was a problem with the request.');return false;}}}
function _switchclass(){cssclass=(cssclass=='table_row')?'alternate_table_row':'table_row';return cssclass;}
function remove_row(){var row=document.getElementById('tr_'+postid);main_post_table.removeChild(row);}
function _remove_post(){var row=document.getElementById('tr_'+postid);deleted_hash=row.getElementsByTagName('td')[0].id.split('_');table_rows--;setTimeout("remove_row()",2000);cssclass="";var childs=0;childs=main_post_table.rows.length;var i=(trail-replies_perpage)+1;childs=parseInt(childs)+parseInt(i);document.getElementById('td1_'+deleted_hash[1]).id='';document.getElementById('td2_'+deleted_hash[1]).id='';document.getElementById('postcount_'+deleted_hash[1]).id='';for(i;i<=childs;i++){if(document.getElementById('td1_'+i)){var current_hash=new Array(2);current_hash[0]='postcount';current_hash[1]=parseInt(i);var current_row=document.getElementById('postcount_'+current_hash[1]);if(current_row){if(parseInt(deleted_hash[1])<parseInt(current_hash[1])){current_row.id=current_hash[0]+'_'+(parseInt(current_hash[1])-1);var td1_id=document.getElementById('td1_'+current_hash[1]);var td2_id=document.getElementById('td2_'+current_hash[1]);td1_id.id='td1_'+(parseInt(current_hash[1])-1);td2_id.id='td2_'+(parseInt(current_hash[1])-1);document.getElementById(current_hash[0]+'_'+(parseInt(current_hash[1])-1)).firstChild.data='#'+(parseInt(current_hash[1])-1);var post_href=document.getElementById(current_hash[0]+'_'+(parseInt(current_hash[1])-1)).getAttribute('href').split('postcount=');document.getElementById(current_hash[0]+'_'+(parseInt(current_hash[1])-1)).setAttribute("href",post_href[0]+"postcount="+(parseInt(current_hash[1])-1));}}}}}
function _css_walk(){var childs=0;cssclass="";childs=main_post_table.rows.length;for(i=0;i<childs;i++){if(main_post_table.rows[i]){main_post_table.rows[i].className=_switchclass();}}}
var httpReq;var httpImgReq;var clicked;function add_request(){if(is_last_page&&(clicked==document.PostTopic.submitbutton.value)){var post_data;document.getElementById('qr_posting_msg').style.display='';if(document.getElementById("edit")){finishEditor();}else if(document.getElementById("_message_editor")){editor_filterOutput('message');}
post_data=document.PostTopic.message.value;var id=document.PostTopic.id.value;var adv_toolbar=document.PostTopic.adv_toolbar.value;var trail=document.PostTopic.trail.value;var forum=document.PostTopic.forum.value;var done=document.PostTopic.done.value;var thread_userid=document.PostTopic.thread_userid.value;var threadid=document.PostTopic.threadid.value;if(navigator.appName=='Netscape'&&!document.getElementById("edit")){post_data=post_data.replace(/\n/g,'\r\n');}
post_data=encodeURIComponent(post_data);var url_post="id="+id+"&adv_toolbar="+adv_toolbar+"&trail="+trail+"&reply=1&forum="+forum+"&ajax_request=1&message="+post_data+"&done="+done+"&thread_userid="+thread_userid+"&threadid="+threadid;if(document.PostTopic.code){var code=document.PostTopic.code.value;var md5sum=document.PostTopic.md5sum.value;url_post=url_post+"&code="+code+"&md5sum="+md5sum;document.PostTopic.code.value='';}
httpReq=CreateXmlHttpReq(_postHandler);if(httpReq){XmlHttpPOST(httpReq,"/post/ajaxReply",url_post);}
if(document.PostTopic.code){change_image(0);}
return false;}else{return true;}}
function _postHandler(){if(httpReq.readyState==4){document.getElementById('qr_posting_msg').style.display='none';if(httpReq.status==200){var responsedata=httpReq.responseXML;if(responsedata){if(responsedata.getElementsByTagName("error")[0]){var error=responsedata.getElementsByTagName("error")[0].firstChild.nodeValue;if(error){if(error.match('Message Posted')){document.PostTopic.message.value='';if(document.getElementById("edit")){document.getElementById("edit").contentWindow.document.body.innerHTML='';}else if(document.getElementById("_message_editor")){document.getElementById("_message_editor").contentWindow.document.body.innerHTML='';}}
alert(error.replace(/<\S[^><]*>/g,''));}
return false;}
document.PostTopic.message.value='';if(document.getElementById("edit")){document.getElementById("edit").contentWindow.document.body.innerHTML='';}else if(document.getElementById("_message_editor")){document.getElementById("_message_editor").contentWindow.document.body.innerHTML='';}
if(responsedata.getElementsByTagName("postid")[0]){var ajax_post_id=responsedata.getElementsByTagName("postid")[0].firstChild.nodeValue;var ajax_data_td_1=responsedata.getElementsByTagName("data_td_1")[0].firstChild.nodeValue;var ajax_data_td_2=responsedata.getElementsByTagName("data_td_2")[0].firstChild.nodeValue;var td1_id=responsedata.getElementsByTagName("td1_id")[0].firstChild.nodeValue;var td2_id=responsedata.getElementsByTagName("td2_id")[0].firstChild.nodeValue;var _tr=document.createElement("tr");_tr.id=ajax_post_id;_tr.style.display="none";var _td1=document.createElement("td");_td1.innerHTML=ajax_data_td_1;_td1.id=td1_id;_td1.setAttribute("vAlign","top");_td1.setAttribute("width","19%");var _td2=document.createElement("td");_td2.innerHTML=ajax_data_td_2;_td2.id=td2_id;_td2.setAttribute("vAlign","top");_td2.style.height='100%';_tr.appendChild(_td1);_tr.appendChild(_td2);_tr.className="table_row";main_post_table.appendChild(_tr);_css_walk();Effect.Appear(ajax_post_id,{duration:1.0,from:0.0,to:2.0});}}}else{alert('There was a problem with the request.');return false;}}}
function change_image(flag){if(flag){document.getElementById('qr_loading_msg').style.display='';}
var url_post="/post/generate_captcha?ajax_request=1";httpImgReq=CreateXmlHttpReq(changeImageHandler);if(httpImgReq){XmlHttpGET(httpImgReq,url_post);}}
function changeImageHandler(){if(httpImgReq.readyState==4){if(httpImgReq.status==200){document.getElementById('qr_loading_msg').style.display='none';if(httpImgReq.responseText){document.getElementById('img_captcha').src='/images/captcha/'+httpImgReq.responseText+'.png';document.PostTopic.md5sum.value=httpImgReq.responseText;}}}}