function comment_preview()
{
	var d = new Date();

	output  = "<h2>Live Preview</h2>";

	output += "<table class='ForumThread' width='100%'>\n";
	output += "<tr class='ForumThreadDate'><td colspan='2'>:) " + d.formatDate("j M Y g:i a") + "</td></tr>\n";
	output += "<tr>";
	output += "<td class='ForumThreadPostUser' valign='top' width='130'><span class='comment_author'>" + $('comment_username').value + "</span></td>";
	output += "<td class='ForumThreadPostBody' valign='top'><div class='comment_body' id='comment_preview_body'>Loading...</div></td>";
	output += "</tr>\n";
	output += "</table>\n";

	$('preview_container').innerHTML = output;
	$('comment_preview_button').disabled = 1;
	ajax_preview();

	Event.observe('comment', 'keyup', ajax_preview_set, false);
	new PeriodicalExecuter(ajax_preview, 1.5);
}

var preview_update = 1;

function ajax_preview_set()
{
	preview_update = 1;
}

function ajax_preview()
{
	if(preview_update == 1)
	{
		url = '/global/ajax/string_parser.php';
		pars = 'string='+encodeURIComponent($('comment').value);
		target = 'comment_preview_body';
		//Element.scrollTo('preview_container');
		myAjax = new Ajax.Updater(target, url, {method: 'post', postBody: pars, onlyLatestOfClass: 'live_preview'});
		preview_update = 0;
	}
}

function comment_quote(obj)
{
	post = forum_id + '.' + thread_id + '.' + obj.substr(8);
	
	$('comment').value = $('comment').value + '[quote="' + $(obj + '_author').innerHTML + '" post="' + post + '"]' + $(obj + '_body').value + '[/quote]';
	$('comment_parent_id').value = $(obj + '_id').value;
}

function comment_reply(obj)
{
	$('comment_parent_id').value = $(obj + '_id').value;
}

function post_options()
{
	var e_list = document.getElementsByClassName('comment_options');
	for(var i = 0; i < e_list.length; i++)
	{
		comment_id = e_list[i].id.substr(16);

		var output = '';
		if(can_post == 1)
		{
			if((is_admin == 1)||(ims_user_id == $("comment_"+comment_id+"_user_id").value)) output += "<a href='/forums/edit/"+forum_id+"."+thread_id+"."+comment_id+"'>Edit</a> | ";
			output += "<a href='#comment_form' onClick=\"comment_quote('comment_"+comment_id+"');\">Quote</a> | <a href='#comment_form'>Reply</a>";
		}
		e_list[i].innerHTML = output;

	}
}

function report_comment(id)
{
	new Insertion.After('report_' + id,'<span id=\'reported_'+id+'\'>reporting...</span>');
	$('report_' + id).hide();
	
	pars  = 'post_id=' + id;
	pars += '&thread_id=' + thread_id;
	pars += '&forum_id=' + forum_id;

	new Ajax.Request('/forums/include/ajax/report_post.php', {method:'post', postBody:pars,onComplete:finish_report});

	return false;
}

function finish_report(response)
{
	id = response.responseText;
	$('reported_'+id).innerHTML = 'reported!';
}

function poll_preview()
{
    pollContainer = document.getElementById('poll_container');
    if (pollContainer) {
        if (pollContainer.style.display == "none") {
            pollContainer.style.display = "block";
        }
        else {
            pollContainer.style.display = "none";
        }
    }
}

function forum_jump()
{
	if($('ForumDropdown').value != 0)
	{
		window.location = '/forums/index/' + $('ForumDropdown').value;
	}
}
