/*
	User Defined PB Comments Script

	This script is designed to be pulled from the extension directory and is freely modifiable for
	customization.

	The following functions are called by the pbcomments.js file

	tx_pbcomments_setReportSpan - Event that should update the Report span
	tx_pbcomments_setRateUpSpan - Event that should update the Rating Up span
	tx_pbcomments_setRateDownSpan - Event that should update the Rating Down span
	tx_pbcomments_setHidden - Event that should set the comment as hidden
	tx_pbcomments_showHide - Event when user show/hides a comment
	tx_pbcomments_notLoggedIn - Event when user tries to rate or report a comment and is not logged in
*/


function tx_pbcomments_setReportSpan(commentID, is_disabled, is_reported) {
	var report_image;
	var report_html;

	if (is_disabled)
		report_image = 'fileadmin/template/images/flag_gray.gif';
	else if (is_reported)
		report_image = 'fileadmin/template/images/flag.gif';
	else
		report_image = 'fileadmin/template/images/flag.gif';

	if (is_reported)
		report_html = 'Reported';
	else
		report_html = 'Report';

	report_html = '<img src="' + report_image + '" alt="Flag" width="12" height="12" vspace="2" border="0" align="top" /> ' + report_html;

	//Wrap in link if not disabled and not reported yet
	if (!is_disabled && !is_reported)
	{
		report_html = '<a onclick="tx_pbcomments_submitReport(' + commentID + '); return false;" href="#">' + report_html + '</a>'
	}

	var span_report = $('tx_pbcomments_report'+commentID);

	span_report.innerHTML = report_html;
}
function tx_pbcomments_setRateUpSpan(commentID, is_disabled, is_rated) {
	var image;
	var html;

	if (is_disabled)
		image = 'fileadmin/template/images/commentup_gray.gif';
	else if (is_rated)
		image = 'fileadmin/template/images/commentup_off.gif';
	else
		image = 'fileadmin/template/images/commentup.gif';

	html = '<img src="' + image + '" alt="Flag" width="12" height="12" vspace="2" border="0" align="top" /> ';

	//Wrap in link if not disabled and not reported yet
	if (!is_disabled && !is_rated)
	{
		html = '<a onclick="tx_pbcomments_submitRating(' + commentID + ', +1); return false;" href="#">' + html + '</a>'
	}

	var span = $('tx_pbcomments_thumbs_up'+commentID);
	span.innerHTML = html;
}

function tx_pbcomments_setRateDownSpan(commentID, is_disabled, is_rated) {
	var image;
	var html;

	if (is_disabled)
		image = 'fileadmin/template/images/commentdn_gray.gif';
	else if (is_rated)
		image = 'fileadmin/template/images/commentdn_off.gif';
	else
		image = 'fileadmin/template/images/commentdn.gif';

	html = '<img src="' + image + '" alt="Flag" width="12" height="12" vspace="2" border="0" align="top" /> ';

	//Wrap in link if not disabled and not reported yet
	if (!is_disabled && !is_rated)
	{
		html = '<a onclick="tx_pbcomments_submitRating(' + commentID + ', -1); return false;" href="#">' + html + '</a>'
	}

	var span = $('tx_pbcomments_thumbs_down'+commentID);
	span.innerHTML = html;
}

function tx_pbcomments_setHidden(commentID, is_disabled, force_show)
{
	if (is_disabled)
	{
		var innerHTML;
		if (force_show) {
			innerHTML = 'Hide';
			$('tx_pbcomments_content'+commentID).show();
		}
		else {
			innerHTML = 'Show';
			$('tx_pbcomments_content'+commentID).hide();
		}

		var msg = 'Comment Below Threshold. <a onclick="tx_pbcomments_showHide('+ commentID +');return false;" id="tx_pbcomments_showhide'+ commentID +'" href="#">'+innerHTML+'</a>';
		$('tx_pbcomments_below_threshold'+commentID).innerHTML = msg;
	}
	else
	{
		$('tx_pbcomments_below_threshold'+commentID).innerHTML = '';
		$('tx_pbcomments_content'+commentID).show();
	}
}

function tx_pbcomments_showHide(commentID)
{
	var link = $('tx_pbcomments_showhide'+commentID)
	if (link.innerHTML == 'Show')
		comment_info_arr[commentID].force_show = true;
	else
		comment_info_arr[commentID].force_show = false;

	tx_pbcomments_updateComment(commentID);
}

function tx_pbcomments_notLoggedIn()
{
	var res = confirm('You must be logged in to do this. To register or login click OK. Otherwise click Cancel.');
	if (res)
	{
		window.location = "/tools/registerlogin.html";
	}
}
