//v1.4.4
function do_subscription(tid, type, loading_text, token) {
	if(type == '2' || type == '1' || type == '3') {
		var subtype = document.getElementById("substype").value;
		document.getElementById("subloadingarea").innerHTML = loading_text;
		doAjax('./pages/viewpost/ajax/subscribe.php', 'tid='+tid+'&type='+subtype+'&token='+token, 'show_reply', 'post', '', 'subloadingarea');
	} else alert("You must be logged in to subscribe to topics");
}
function delete_attach(t, id, loading_text) {
	document.getElementById("attachment_"+id).innerHTML = loading_text;
	doAjax('./pages/viewpost/ajax/del_attach.php', 'id='+id+'&t='+t, 'show_reply', 'post', '', 'attachment_'+id);
}

//v1.4.2
function do_topic_quote() {
	showreply_box();
	var quote = document.getElementById('topic_divbox').innerHTML;
	if(editor_type==1) WriteHTML("[QUOTE]"+quote+"[/QUOTE]",'editor');
	else WriteTEXT("[QUOTE]"+quote+"[/QUOTE]",'editor');
}
function do_quote(id, editor) {
	showreply_box();
	var quote = document.getElementById('post_'+id).innerHTML;
	if(editor_type==1) WriteHTML("[QUOTE]"+quote+"[/QUOTE]",'editor');
	else WriteTEXT("[QUOTE]"+quote+"[/QUOTE]",'editor');
}
function showreplyboxwithreturn() {
	document.getElementById('reply_box').style.display = 'block';
	location.hash = 'reply_box_anc_';
	return true;
}

function showreply_box() {
	document.getElementById('reply_box').style.display = 'block';
	location.hash = 'reply_box_anc_';
}

function hidereply_box() {
	document.getElementById('reply_box').style.display = 'none';
}

function notice_redirect(redirect, no_login) {
	if(confirm(no_login))
	location.href="index.php?p=login&c="+encodeURIComponent(redirect);
}

function add_reply(tid, user, loading_text, no_content, fid, uncheckhtml, token) {
	if (HTML_ON == "no"){
		alert (uncheckhtml);
		return false;
	}
	setCodeOutput();
	var bbcode_output= document.getElementById("hoteditor_bbcode_ouput_editor").value;
	document.getElementById("reply").value = bbcode_output;
	var comment = document.getElementById('reply').value;
	comment = trim(comment);
	if(comment == "") alert(no_content);
	else {
		text = encodeURIComponent(comment);
		document.getElementById("reply_box").innerHTML = loading_text;
		doAjax('./pages/viewpost/ajax/reply.php', 'tid='+tid+'&content='+text+'&uid='+user+'&fid='+fid+'&token='+token, 'show_reply', 'post', '', 'reply_box');
	}
}

function edit_post(id, userid, loading_text) {
	document.getElementById('post_'+id).style.display = 'none';
	document.getElementById('edit_box_'+id).style.display = 'block';
	document.getElementById('edit_box_'+id).innerHTHML = loading_text;
	doAjax('./pages/viewpost/ajax/build_post_edit.php', 'userid='+userid+'&postid='+id, 'show_reply', 'post', '', 'edit_box_'+id);
}

function hide_edit_box(id) {
	document.getElementById('edit_box_'+id).style.display = 'none';
	document.getElementById('post_'+id).style.display = 'block';
}

function do_edit(id, user, loading_text, confir, no_content, no_same, token) {
	var comment = document.getElementById('edit_textarea_'+id).value;
	var orig_comment = document.getElementById("post_"+id).innerHTML;
	comment = trim(comment);
	orig_comment = trim(orig_comment);
	if(comment == "") alert(no_content);
	else if(orig_comment == comment) alert(no_same);
	else {
		text = encodeURIComponent(comment);
		var reason_ue = document.getElementById("edit_reason_"+id).value;
		reason = encodeURIComponent(reason_ue);
		document.getElementById("global_post_"+id).innerHTML = loading_text;
		doAjax('./pages/viewpost/ajax/edit.php', 'id='+id+'&content='+text+'&uid='+user+'&confir='+confir+'&token='+token+'&reason='+reason, 'show_reply', 'post', '', 'global_post_'+id);
	}
}

function delete_post(id, user, msg, token) {
	document.getElementById('post_table_'+id).innerHTML = "";
	tb_remove();
	doAjax('./pages/viewpost/ajax/delete.php', 'id='+id+'&uid='+user+'&msg='+msg+'&token='+token, 'show_reply', 'post', '', 'post_table_'+id);
}

function edit_topic(userid, topicid, loading_text) {
	document.getElementById('topic_divbox').style.display = 'none';
	document.getElementById('topic_edit_box').style.display = 'block';
	document.getElementById('topic_edit_box').innerHTHML = loading_text;
	doAjax('./pages/viewpost/ajax/build_edit.php', 'userid='+userid+'&topicid='+topicid, 'show_reply', 'post', '', 'topic_edit_box');
}

function hide_topic_box() {
	document.getElementById('topic_edit_box').style.display = 'none';
	document.getElementById('topic_divbox').style.display = 'block';
}

function do_topic_edit(id, user, loading_text, confir, no_content, no_same, no_title_content, token) {
	var comment = document.getElementById("topic_edit_textarea").value;
	var orig_comment = document.getElementById("topic_divbox").innerHTML;
	var title = document.getElementById("topic_title_edit").value;
	var orig_title = document.getElementById("topic_title").innerHTML;
	comment = trim(comment);
	orig_comment = trim(orig_comment);
	title = trim(title);
	orig_title = trim(orig_title);
	if(comment == "") alert(no_content);
	else if(title == "") alert(no_title_content);
	else if(orig_comment == comment && orig_title == title) alert(no_same);
	else {
		text = encodeURIComponent(comment);
		new_title = encodeURIComponent(title);
		var reason_ue = document.getElementById("topic_edit_reason").value;
		reason = encodeURIComponent(reason_ue);
		document.getElementById("global_topic").innerHTML = loading_text;
		doAjax('./pages/viewpost/ajax/edit_topic.php', 'id='+id+'&content='+text+'&title='+new_title+'&uid='+user+'&confir='+confir+'&token='+token+'&reason='+reason, 'show_reply', 'post', '', 'global_topic');
		document.getElementById("topic_title").innerHTML = title;
	}
}

function poll_vote(pollid, token) {
	for (i=0; i<document.poll_form.vote.length; i++) {
	   if (document.poll_form.vote[i].checked) var vote = document.poll_form.vote[i].value;
	}
	doAjax('./pages/viewpost/ajax/polls/vote.php', 'pollid='+pollid+'&vote='+vote+'&token='+token, 'show_reply', 'post', '', 'poll_area');
}

function poll_show(pollid) {
	tb_show('Poll Results', './pages/viewpost/ajax/polls/show.php?pollid='+pollid+'&width=500&height=280');
}

function report(uid, id, confir) {
	tb_show('Topic Reported', './pages/viewpost/ajax/report.php?id='+id+'&uid='+uid+'&confir='+encodeURIComponent(confir));
	setTimeout("tb_remove()", 2000);
}