var flag = {	

	assign: function(e) {
		var id = $('LessonFlagFlagId').value;
		
		if(id) // Needs to be defined
		{
			new Ajax.Updater(
				'flag-feedback', // Location to update
				'/flags/assign', // Request action
				{
					parameters: $('flag-form').serialize(),
					insertion: 'bottom',
					onCreate: function() {
						$('flag-feedback').update('');
						$('flag-form').disable(); // Disable the form while submitting
					},
					onSuccess: function() { 
						$('flag-form').enable().hide(); // Enable the form
					}
				}				
			);
		}
	
		Event.stop(e); // Used like "return false;" with submitted form
	},
	
	unassign: function(id) {
		new Ajax.Updater(
			'flag-feedback', // Location to update
			'/flags/unassign/', // Request action
			{
				parameters: {'id':id},
				insertion: 'bottom',
				onCreate: function() {
					$('flag-feedback').update('');
				},
				onSuccess: function() { 
					$('flag-form').show().reset(); // Show the form
				}
			}				
		);
	}
	
}; // END class

Event.observe(window, 'load', function() {
	if($('flag-form')) { Event.observe('flag-form', 'submit', flag.assign); } // Available if logged in
});