function setRating(rating) {
	for(i = 1; i <= 5; i++) {
		className = 'clickable';
		
		if (i <= Math.round(rating))
			className += ' active';

		$('star'+i).className = className;
	}
}

function rate(game_id, amount) {
	$('rating').innerHTML = 'lādējas...';
	
	params = {'data[Rating][game_id]': game_id, 'data[Rating][amount]': amount};

	new Ajax.Updater('rating', url+'/ratings/add', { method: 'post', parameters: params });
}

function showComments(game_id, page) {
	if (page == null)
		page = 1;
	
	$('CommentsLabel').innerHTML = 'Lādējas...';

	new Ajax.Updater('comments', url+'/comments/index/'+game_id+'/'+page);
}

function submitComment( ) {
	
	var error = false;
	
	if ($('CommentName') != null) {
		if ($('CommentName').value == '') {
			$('CommentNameError').innerHTML = 'Lūdzu, ievadiet savu vārdu!';
			error = true;
		}
		else {
			$('CommentNameError').innerHTML = '';
		}
	}
	
	if ($('CommentBody').value == '') {
		$('CommentBodyError').innerHTML = 'Lūdzu, ievadiet komentāru!';
		error = true;
	}
	else {
		$('CommentBodyError').innerHTML = '';
	}
	
	if (!error) {
		new Ajax.Updater( 'comments', url+'/comments/add/', { method: 'post', parameters: $('CommentAddForm').serialize() } );
		
		$('CommentAddForm').reset();
		
		if ($('CommentName') != null) {
			$('CommentName').disabled = true;
		}

		$('CommentBody').disabled = true;
	}
}

