var deleteUrl = '/members/poker_room_tournament_alerts/delete/';
var addUrl = '/members/poker_room_tournament_alerts/add/poker_room_tournament_id:';

function deleteAlert(id, elem)
{
	jQuery.getJSON(deleteUrl + id, function(json) {
		jQuery(elem).parent().html('<a href="#" onclick="return setAlert('+json.tournament_id+', this);"><img src="/img/tournaments/add.png" /></a>');
		return false;
	});
}

function setAlert(id, elem)
{
	jQuery.getJSON(addUrl + id, function(json) {
		jQuery(elem).parent().html('<a href="#" onclick="return deleteAlert('+json.id+', this);"><img src="/img/tournaments/delete.png" /></a>');
		return false;
	});
}


jQuery(document).ready(function() {

	jQuery('#search-form').ajaxForm({
		type: 'POST',
		target: '#tournaments',
		beforeSubmit: function() {
			jQuery('#tournaments').prepend('<p><img src="/img/ajax-loader.gif" /></p>');
			return true;
		},
		success: function()
		{
			jQuery('#alert-form').ajaxForm({
				type: 'POST',
				dataType: 'json',
				success: function(data) {
					alert(data.msg);
				}
			});
		}
	});

	jQuery('#search-form').submit();
});