$(document).ready(function() {
	// selector
	$('#select_all').live('click', function() {
		var state = $(this).is(':checked');
		
		$('#mailbox input[type="checkbox"]').attr('checked', state);
	});
	
	$('form#mailbox button').live('click', function() {
		var checked = $('form#mailbox input:checkbox:checked').not('#select_all').length;

		if(checked<1) {
			$("#dialog").dialog({
				bgiframe: true,
				modal: true,
				buttons: {
					Ok: function() {
						$(this).dialog('close').dialog('destroy');
					}
				}
			});
			return false;
		}
		else
		{
			var val = $(this).attr('name');
			val = val.replace('button_', '');

			$('form#mailbox').append('<input type="hidden" name="'+$(this).attr('name').toLowerCase()+'" value="'+val+'" />');
			if (val == 'delete')
			{
				confirm_dialog('form#mailbox', true);
				return false;
			}
		}
	});
});

