var inbox;
var act;

function reportMessage (reportUrl, inboxUrl, action)
{
	inbox = inboxUrl;
	act = action;
	var result;
	var spammsg = "You are about to mark this message as SPAM. \n\nA message is considered to be SPAM if it is "
				+ "an unwelcome advertisement or solicitation from another member or group. "
				+ "Marking this message as SPAM will notify an administrator who will review the message and take necessary action. Are you sure you want to mark this message as SPAM?";
				
	var abusemsg = "You are about to mark this message as ABUSE.\n\n A message is considered to be ABUSE if it is harassment, "
				 + "intended to hurt or embarrass, or contains inappropriate content. "
				 + "Marking this message as ABUSE will notify an administrator who will review the message and take necessary action. Are you sure you want to mark this message as ABUSE? ";
	switch (action)
	{
		case 0:
			result = confirm (spammsg);
			break;
		case 1:
			result = confirm (abusemsg);
			break;
		case 2:
			result = confirm ('Are you sure you want to remove this message from the spam and abuse list?');
			break;
		default:
			result = false;
			break;
	}
	if (result)
	{
		new Ajax.Request (reportUrl, {
			method: 'post',
			on400:alert_report_failure,
			on200:alert_report_success
			}
		);
	}
			
}

function alert_report_success()
{
	switch (act)
	{
		case 0:
			alert ('The message has been successfully marked as spam.');
			break;
		case 1:
			alert ('The message has been successfully marked as abuse.');
			break;
		case 2:
			alert ('The message has been successfully removed from the spam and abuse list.');
			break;
		default:
			alert ('The operation was successful.');
			break;
	}
	window.location=inbox;
}

function alert_report_failure()
{
	alert ('Sorry. The requested operation could not be completed.');
	window.location=inbox;
}