$(document).ready(function() {

	/***** prevent multiple submits - start */
	$('form').submit(function(e) {
		$(this).find(':submit').attr('disabled', true);
	});
    /***** prevent multiple submits - end */
    
	/***** hide flash message - start */
	$('#flashMessage, #authMessage').append(
		$('<a>')
			.attr('href', '#')
			.attr('class', 'close-flash')
			.text('close')
			.click(function(e) {
				e.preventDefault();
				$(this).parent('div').fadeOut('slow');
			})
	);
	/***** hide flash message - end */
	
    /***** with-selected :: index page, checkbox selection of multiple rows - start *****/
	$(':checkbox.with-selected').change(function(e) {
		var num = $(':checkbox.with-selected:checked').length;
		if (num > 0) {
			$('.with-selected-actions:hidden').fadeIn('fast');
			$('.with-selected-num span').text(num);
		} else {
			$('.with-selected-actions:visible').fadeOut('fast');
		}
	}).change();
	
	$('.with-selected-form tr:has(:checkbox.with-selected) td:not(:has(:checkbox.with-selected), .actions)').click(function(e) {
		var state = $(this).parents('tr').find(':checkbox.with-selected').attr('checked');
		
		$(this).parents('tr').find(':checkbox.with-selected')
			.attr('checked', !state)
			.change();
	});
	
	$('.with-selected-check-all').click(function(e) {
		$(':checkbox.with-selected').attr('checked', true).eq(0).change();
		e.preventDefault();
	});

	$('.with-selected-check-none').click(function(e) {
		$(':checkbox.with-selected').attr('checked', false).eq(0).change();
		e.preventDefault();
	});
	
	$('.paginate-limit select').change(function() {
		var num = $(this).val();
		window.location = $('a.paginate-limit-link-'+num).attr('href');
	});
    /***** with-selected :: index page, checkbox selection of multiple rows - end *****/
	
});