
function flagUser(id)
{
	// Show loading indicator
	if ($('loading'))
	{
		$('loading').appear({duration: .75});
	}

	new Ajax.Request('/ajax.utilities.php', {
		parameters: 'flaguser='+id,

		onSuccess: function(resp) 
		{
			if (resp.responseText.indexOf('success') == 0)
			{
				ajax_showSuccess('This profile has been flagged.');
			}else if(resp.responseText.indexOf('error') == 0)
			{
				ajax_showError('There was an error attempting to flag this user. #flge1');
			}else{
				ajax_showNotice('That\'s weird... something unexplanable has just happened. Please try again.', false);
			}

			// Hide the loading indicator
			if ($('loading'))
			{
				$('loading').fade({duration: .25, from: 1, to: 0});
			}
		},

		onFailure: function(resp) 
		{
			ajax_showError('There was a network error while attempting to flag this user. Please try again.');

			// Hide the loading indicator
			if ($('loading'))
			{
				$('loading').fade({duration: .25, from: 1, to: 0});
			}
		}

	});
}

function trackUser(id, a, b, c, d)
{
	// Show loading indicator
	if ($('loading'))
	{
		$('loading').appear({duration: .75});
	}

	new Ajax.Request('/ajax.utilities.php', {
		parameters: 'trackuser='+id+'&a='+a+'&b='+b+'&c='+c+'&d='+d,

		onSuccess: function(resp) 
		{
			if (resp.responseText.indexOf('success') == 0)
			{
				ajax_showSuccess(resp.responseText.indexOf(':') > 0 ? resp.responseText.replace('success:', '') : 'You are now tracking this user.');

				// Swap the track/untrack links
				if ($('trackuser'))
				{
					$('trackuser').hide();
				}
				if ($('untrackuser'))
				{
					$('untrackuser').show();
				}
			}else if(resp.responseText.indexOf('notice') == 0)
			{
				ajax_showNotice(resp.responseText.indexOf(':') > 0 ? resp.responseText.replace('notice:', '') : 'Cannot track this user.');
			}else if(resp.responseText.indexOf('error') == 0)
			{
				ajax_showError(resp.responseText.indexOf(':') > 0 ? resp.responseText.replace('error:', '') : 'There was an error attempting to track this user. #tkbe3');
			}else{
				ajax_showNotice('That\'s weird... something unexplanable has just happened. Please try again.', false);
			}

			// Hide the loading indicator
			if ($('loading'))
			{
				$('loading').fade({duration: .25, from: 1, to: 0});
			}
		},

		onFailure: function(resp) 
		{
			ajax_showError('There was a network error while attempting to track this user. Please try again.');

			// Hide the loading indicator
			if ($('loading'))
			{
				$('loading').fade({duration: .25, from: 1, to: 0});
			}
		}

	});
}

function untrackUser(id, a, b, c, d)
{
	// Show loading indicator
	if ($('loading'))
	{
		$('loading').appear({duration: .75});
	}

	new Ajax.Request('/ajax.utilities.php', {
		parameters: 'untrackuser='+id+'&a='+a+'&b='+b+'&c='+c+'&d='+d,

		onSuccess: function(resp) 
		{
			if (resp.responseText.indexOf('success') == 0)
			{
				ajax_showSuccess(resp.responseText.indexOf(':') > 0 ? resp.responseText.replace('success:', '') : 'You are no longer tracking this user.');

				// Swap the track/untrack links
				if ($('untrackuser'))
				{
					$('untrackuser').hide();
				}
				if ($('trackuser'))
				{
					$('trackuser').show();
				}
			}else if(resp.responseText.indexOf('error') == 0)
			{
				ajax_showError(resp.responseText.indexOf(':') > 0 ? resp.responseText.replace('error:', '') : 'There was an error attempting to stop tracking this user. #tkbe10');
			}else{
				ajax_showNotice('That\'s weird... something unexplanable has just happened. Please try again.', false);
			}

			// Hide the loading indicator
			if ($('loading'))
			{
				$('loading').fade({duration: .25, from: 1, to: 0});
			}
		},

		onFailure: function(resp) 
		{
			ajax_showError('There was a network error while attempting to stop tracking this user. Please try again.');

			// Hide the loading indicator
			if ($('loading'))
			{
				$('loading').fade({duration: .25, from: 1, to: 0});
			}
		}

	});
}