//Event.observe(window, 'load', init_fighter_fighting_styles);
//Event.observe(window, 'load', init_fighter_fighting_strengths);
Event.observe(window, 'load', init_fighter_gyms);
//Event.observe(window, 'load', init_fighter_promotions);
Event.observe(window, 'load', init_fighter_sanctioning_body_discipline_records);
Event.observe(window, 'load', init_fighter_sanctioning_body);


function init_fighter_sanctioning_body_discipline_records ()
{
	response = new Ajax.Updater('fighter_sanctioning_discipline_records', '/load.php', 
								{ 
									evalJSON: true, 
									sanitizeJSON: true, 
									parameters: 
 									{ 
										method: 'load_fighter_sanctioning_discipline', 
										id: id_to_edit
									}
								});
}  // end function init_fighter_fighting_styles.

function init_fighter_promotions ()
{
	response = new Ajax.Updater('fighter_promotions_list', '/load.php', 
								{ 
									evalJSON: true, 
									sanitizeJSON: true, 
									parameters: 
 									{ 
										method: 'load_fighter_promotions', 
										fighter_id: id_to_edit
									}
								});
								
				
}  // end function init_fighter_promotions.


function init_fighter_fighting_styles ()
{
	
	response = new Ajax.Updater('fighter_fighting_styles', '/load.php', 
								{ 
									evalJSON: true, 
									sanitizeJSON: true, 
									parameters: 
 									{ 
										method: 'load_fighter_fighting_styles', 
										id: id_to_edit
									}
								});
}  // end function init_fighter_fighting_styles.


function init_fighter_fighting_strengths ()
{
	
	response = new Ajax.Updater('fighting_strengths_list', '/load.php', 
								{ 
									evalJSON: true, 
									sanitizeJSON: true, 
									parameters: 
 									{ 
										method: 'load_fighter_fighting_strengths', 
										id: id_to_edit
									}
								});
}  // end function init_fighter_fighting_styles.

function init_fighter_gyms ()
{
	response = new Ajax.Updater('fighter_gyms_list', '/load.php', 
								{ 
									evalJSON: true, 
									sanitizeJSON: true, 
									parameters: 
 									{ 
										method: 'load_fighter_gyms', 
										id: id_to_edit
									}
								});
}  // end function init_fighter_fighting_styles.



function remove_fighter_sanctioning_body ( arg_tr_id )
{
	if ( confirm ( 'Are you sure you want to remove this sanctioning body from your list?' ) )
	{
		callback_hide_general_errors ( 'fighter_sanctioning_body_error_general' );
		show_loading ( 'fighter_sanctioning_bodies_' + arg_tr_id, 'Removing fighter sanctioning body...' );
		
		var param_hash = new Hash ();
		param_hash.set ( 'method', 'remove_fighter_sanctioning_body' );
		param_hash.set ( 'fighter_sanctioning_body_id', arg_tr_id );
		param_hash.set ( 'id', id_to_edit );
	
		new Ajax.Request('/ajax.php', 
		{
			method: "post",
			evalJSON: true, 
			sanitizeJSON: true, 
			parameters: $H(param_hash),
			onSuccess: remove_fighter_sanctioning_body_callback,
			onFailure: errback_global
		});  // end Ajax.Request.
	}	
}

function remove_fighter_sanctioning_body_callback ( oReq, json )
{
	ajax_require_logged_in ( oReq.responseJSON.status );
	if ( oReq.responseJSON.status == 'success' )
	{
		init_fighter_sanctioning_body ();
	}
	else
	{
		callback_show_general_errors ( 'fighter_sanctioning_body_error_general', oReq );
	}
}  // end function remove_fighter_sanctioning_body_callback.



function display_fighter_santioning_body_fup ( arg_tr_id )
{
	$('fighter_sanctioning_body_id').value = arg_tr_id;
			
	var param_hash = new Hash ();
	param_hash.set ( 'method', 'get_fighter_sanctioning_body' );
	param_hash.set ( 'fighter_sanctioning_body_id', arg_tr_id );

	new Ajax.Request('/ajax.php', 
	{
		method: "post",
		evalJSON: true, 
		sanitizeJSON: true, 
		parameters: $H(param_hash),
		onSuccess: display_fighter_santioning_body_fup_callback,
		onFailure: errback_global
	});  // end Ajax.Request.
	
}

function display_fighter_santioning_body_fup_callback ( oReq, json )
{
	ajax_require_logged_in ( oReq.responseJSON.status );
	if ( oReq.responseJSON.status == 'success' )
	{
		// Fill the edit form with data from the db.
		$('edit_sanctioning_body_id').value = oReq.responseJSON.data['sanctioning_body_id'];
		$('edit_fighter_sanctioning_body_state').value = oReq.responseJSON.data['state'];
		$('edit_fighter_sanctioning_body_number').value = oReq.responseJSON.data['registration_id'];
		$('edit_fighter_sanctioning_body_dues_paid').value = oReq.responseJSON.data['dues_paid_status_id'];		
		$('start_date_day').value = oReq.responseJSON.data['start_date_day'];
		$('start_date_month').value = oReq.responseJSON.data['start_date_month'];
		$('start_date_year').value = oReq.responseJSON.data['start_date_year'];
		$('edit_fighter_sanctioning_body_registration_fee').value = oReq.responseJSON.data['registration_fee'];
		show_fup ( 'fup_edit_fighter_sanctioning_body' );		
	}
	else
	{
		callback_show_general_errors ( 'fighter_sanctioning_body_error_general', oReq );
	}
}

function edit_fighter_sanctioning_body ( arg_tr_id )
{
	callback_hide_general_errors('edit_fighter_sanctioning_body_error_general');
	submit_button_processing_on('edit_fighter_sanctioning_body_submit_button', 'Saving...');
	
	var param_hash = new Hash();
	param_hash.set('method', 'edit_fighter_sanctioning_body');
	param_hash.set('fighter_sanctioning_body_id', $('fighter_sanctioning_body_id').value );
	param_hash.set('sanctioning_body_id', $('edit_sanctioning_body_id').value);
	param_hash.set('state', $('edit_fighter_sanctioning_body_state').value);
	param_hash.set('id', id_to_edit);
	param_hash.set('registration_id', $('edit_fighter_sanctioning_body_number').value);
	param_hash.set('dues_paid_status_id', $('edit_fighter_sanctioning_body_dues_paid').value);
	param_hash.set('start_date', $('start_date_year').value + '-' + $('start_date_month').value + '-' + $('start_date_day').value);
	param_hash.set('registration_fee', $('edit_fighter_sanctioning_body_registration_fee').value);

	new Ajax.Request('/ajax.php', {
		method: "post",
		evalJSON: true,
		sanitizeJSON: true,
		parameters: $H(param_hash),
		onSuccess: edit_fighter_sanctioning_body_callback,
		onFailure: errback_global
	}); // end Ajax.Request.
}

function edit_fighter_sanctioning_body_callback ( oReq, json )
{
	ajax_require_logged_in ( oReq.responseJSON.status );
	if ( oReq.responseJSON.status == 'success' )
	{
		hide_fup ( 'fup_edit_fighter_sanctioning_body', '' );
		init_fighter_sanctioning_body ();
	}
	else
	{
		callback_show_general_errors ( 'edit_fighter_sanctioning_body_error_general', oReq );
	}
	submit_button_processing_off ( 'edit_fighter_sanctioning_body_submit_button', 'Add' );
}



function submit_fighter_sanctioning_body ()
{
	callback_hide_general_errors ( 'add_fighter_sanctioning_body_error_general' );
	submit_button_processing_on ( 'add_fighter_sanctioning_body_submit_button', 'Adding...' );
	
	var param_hash = new Hash ();
	param_hash.set ( 'method', 'save_fighter_sanctioning_body' );
	param_hash.set ( 'sanctioning_body_id', $('add_sanctioning_body_id').value );
	param_hash.set ( 'state', $('add_fighter_sanctioning_body_state').value );
	param_hash.set ( 'id', id_to_edit );
	param_hash.set ( 'registration_id', $('add_fighter_sanctioning_body_number').value);

	new Ajax.Request('/ajax.php', 
	{
		method: "post",
		evalJSON: true, 
		sanitizeJSON: true, 
		parameters: $H(param_hash),
		onSuccess: submit_fighter_sanctioning_body_callback,
		onFailure: errback_global
	});  // end Ajax.Request.
}

function submit_fighter_sanctioning_body_callback ( oReq, json )
{
	ajax_require_logged_in ( oReq.responseJSON.status );
	if ( oReq.responseJSON.status == 'success' )
	{
		hide_fup ( 'fup_add_fighter_sanctioning_body', '' );
		init_fighter_sanctioning_body ();
	}
	else
	{
		callback_show_general_errors ( 'add_fighter_sanctioning_body_error_general', oReq );
	}
	submit_button_processing_off ( 'add_fighter_sanctioning_body_submit_button', 'Add' );
}

function init_fighter_sanctioning_body()
{
	response = new Ajax.Updater('fighter_sanctioning_body_list', '/load.php', 
								{ 
									evalJSON: true, 
									sanitizeJSON: true, 
									parameters: 
 									{ 
										method: 'load_fighter_sanctioning_body', 
										id: id_to_edit
									}
								});
}  // end function init_fighter_fighting_styles.