	
	var editing		= 0;
	var title		= '';
	var oldtext		= '';
	var deleting	= 0;
	
	function LockSuccess(data)
	{
		// Change text on the button
		$('#lockthread').html(data);
	}
	
	function LockThread(threadid)
	{
		// Simply send an AJAX request
		jQuery.get('index.php', {category: 'forum', page: 'ajax', action: '1', threadid: threadid}, LockSuccess, 'text');
	}
	
	function StickSuccess(data)
	{
		// Change text on the button
		$('#stickthread').html(data);
	}
	
	function StickThread(threadid)
	{
		// Simply send an AJAX request
		jQuery.get('index.php', {category: 'forum', page: 'ajax', action: '2', threadid: threadid}, StickSuccess, 'text');
	}
	
	function ThreadName(threadid)
	{
		if(editing > 0)
		{
			CancelThreadName();
		}
		
		// Start editing
		title 		= jQuery.trim($('#link_' + threadid).html());
		editing		= threadid;
		
		$('#editname_' + threadid).html('<input type="text" id="editfield_' + threadid + '" class="text" /> <input type="submit" value="OK" onclick="SubmitThreadName(); return false;" /> <input type="submit" value="' + str_cancel + '" onclick="CancelThreadName(); return false;" />');
		$('#editfield_' + threadid).val(title);
		$('#editfield_' + threadid).focus();
	}
	
	function SubmitThreadName()
	{
		// Simply send an AJAX request
		jQuery.get('index.php', {category: 'forum', page: 'ajax', action: '3', threadid: editing, newtitle: escape($('#editfield_' + editing).val())}, RenameSuccess, 'text');
	}
	
	function CancelThreadName()
	{
		$('#editname_' + editing).html('<a href="index.php?category=forum&amp;page=thread&amp;threadid=' + editing + '" id="link_' + editing + '">' + title + '</a>');
		editing		= 0;
	}
	
	function RenameSuccess(data)
	{
		title		= data;
		CancelThreadName();
	}
	
	function Quote(postid)
	{
		var quote	= '[quote]' + $('#rawtext_' + postid).val() + '[/quote]\r\n\r\n';
	
		$('#postbox').html($('#postbox').html() + quote);
	}
	
	function Edit(postid)
	{
		if(editing > 0)
		{
			CancelEdit(editing);
		}
		
		// Store old formatted text
		oldtext			= jQuery.trim($('#editpost_' + postid).html());
		editing			= postid;
		
		// Put in the editbox and dizzle
		$('#editpost_' + postid).html('<textarea style="width: 90%; height: 200px;" id="editpostbox_' + postid + '">' + $('#rawtext_' + postid).val() + '</textarea> <input type="submit" class="formbutton" value="OK" onclick="SaveEdit(); return false;" /> <input type="submit" class="formbutton" value="' + str_cancel + '" onclick="CancelEdit(); return false;" />');
		$('#editpostbox_' + postid).focus();
	}
	
	function EditSuccess(data)
	{
		if(data.length > 0)
		{
			$('#rawtext_' + editing).val($('#editpostbox_' + editing).val());
			$('#editpost_' + editing).html(data);
			editing		= 0;
		}
		else
		{
			// Error
			CancelEdit();
		}
	}
	
	function SaveEdit()
	{
		$.ajax({
			type: 'GET',
			url: 'index.php?category=forum&page=ajax&action=4',
			data: ({postid: editing, newtext: escape($('#editpostbox_' + editing).val())}),
			success: EditSuccess,
			dataType: 'text',
		});
	}
	
	function CancelEdit()
	{
		$('#editpost_' + editing).html(oldtext);
		editing			= 0;
	}
	
	function DeletePost(postid)
	{
		if(deleting == 0 && confirm(str_deletepost))
		{
			jQuery.get('index.php', {category: 'forum', page: 'ajax', action: '5', postid: postid}, DeleteSuccess, 'text');
			deleting	= postid;
		}
	}
	
	function DeleteSuccess(data)
	{
		if(data == 'deleted ')
		{
			$('#postrow_' + deleting).addClass('dredrow');
		}
		else
		{
			$('#postrow_' + deleting).removeClass('dredrow');
		}
		
		deleting		= 0;
	}