function RateSpec(domElement, ratingChange)
{
	var specId = 0;
	var rateIdName = domElement.attr('id');
	if (ratingChange < 0)
		specId = rateIdName.substr(12);
	else
		specId = rateIdName.substr(10);
	$('span#specresult' + specId).html('Sending...');
	$.post('/talents_process.php',
	{
		action: 'ratespec',
		rating: ratingChange,
		specid: specId
	},
	function(xmlResult)
	{
		var specResult = $('tresult', xmlResult);
		var rateStatus = specResult.attr('status');
		var rateError = specResult.attr('error');
		
		if (rateStatus)
		{
			var newRating = specResult.attr('rating');
			$('span#specrating' + specId).html(newRating);
			$('span#specresult' + specId).html(rateStatus);
		}
		
		if (rateError)
			$('span#specresult' + specId).html(rateError);
	});
}

$(document).ready(function()
{
	$('input.rateupspec').click(function() { RateSpec($(this), 1) });
	$('input.ratedownspec').click(function() { RateSpec($(this), -1) });
	
	$('input#submitcomment').click(function()
	{
		$('span#commentresult').html('Sending...');
		$('textarea#commentreply').attr('disabled', 'disabled');
		$.post('/talents_process.php',
		{
			action: 'postcomment',
			comment: $('textarea#commentreply').val(),
			specid: $('input#specid').val()
		},
		function(xmlResult)
		{
			var commentResult = $('tresult', xmlResult);
			var commentStatus = commentResult.attr('status');
			var commentError = commentResult.attr('error');
			
			if (commentStatus)
			{
				var newComment = commentResult.attr('comment');
				$('thead#replyheader').before(newComment);
				$('span#commentresult').html(commentStatus);
				$('textarea#commentreply').val('');
			}
			
			if (commentError)
				$('span#commentresult').html(commentError);
			$('textarea#commentreply').attr('disabled', '');
		});
	
	});
});