if(single_bout==0) {
	Event.observe(window, 'load', is_autogenerator_in_progress);
	Event.observe(window, 'load', init_event_officials);
	Event.observe(window, 'load', init_event_vendors);	
} else {
	Event.observe(window, 'load', init_bouts);
}


function init_bouts ()
{
	response = new Ajax.Updater('bout_list', '/load.php', { evalJSON: true, sanitizeJSON: true, parameters: 
 { method: 'load_bout_list', id: id_to_edit, single_bout: single_bout },
																 onComplete:function()
																 {
																	 init_bouts_completed ();
																 }});


}  // end function init_bouts.


function init_bouts_completed ()
{
	$('loading_bout_list').style.display = 'none';
	
	if ( FB.XFBML.Host.parseDomTree )
		  setTimeout( FB.XFBML.Host.parseDomTree, 0 );
	alert('Finished');
}


// *************************************************************
//					AUTOGENERATOR PROGRESS
// *************************************************************
function is_autogenerator_in_progress ()
{
	var param_hash = new Hash ();
	param_hash.set ( 'method', 'get_autogenerator_progress_logged_out' );
	param_hash.set ( 'fight_card_id', id_to_edit );

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


function is_autogenerator_in_progress_callback ( oReq, json )
{
	//ajax_require_logged_in ( oReq.responseJSON.status );
	
	if (oReq.responseJSON.status == 'success') 
	{
		if (oReq.responseJSON.data['in_progress']) 
		{
			// The autogenerator is in progress.  Replace the bout div with a notification to the user.
			
			$('bout_list').innerHTML = oReq.responseJSON.data['fightcard_message'];
			autogenerator_progress_timeout ();
		}
		else 
		{
			init_bouts ( id_to_edit );
		}  // endif in_progress is true.
	}
	else 
	{
	
	}  // end if status == success. 
	
}  // end function is_autogenerator_in_progress_callback.



function autogenerator_progress_timeout ()
{
	// Wait 10 seconds, then check the autogenerator progress again.
	setTimeout ( "is_autogenerator_in_progress()", 10000 );
}




function init_event_officials ()
{
	response = new Ajax.Updater ('event_officials', '/load.php', 
									{ evalJSON: true, sanitizeJSON: true, 
									  parameters: { method: 'load_event_officials', 
									  fight_card_id: id_to_edit },
									  onComplete:function ()
									  	{init_event_official_elements ();} });
}  // end function init_event_venue.


function init_event_vendors ()
{
	response = new Ajax.Updater ('event_vendors', '/load.php', 
									{ evalJSON: true, sanitizeJSON: true, 
									  parameters: { method: 'load_event_vendors', 
									  fight_card_id: id_to_edit },
									  onComplete:function ()
									  	{init_event_official_elements ();} });
}  // end function init_event_venue.



function post_to_facebook_1(arg_bout_id, arg_fighter_position)
{
	
	show_loading ( $("facebook_wall_" + arg_fighter_position + "_" + arg_bout_id), 'Posting to facebook...');
	
	var param_hash = new Hash ();
	param_hash.set ( 'method', 'add_fighter_bout_to_facebook' );
	param_hash.set ( 'fighter_position', arg_fighter_position );
	param_hash.set ( 'bout_id', arg_bout_id );
	
	new Ajax.Request('/ajax.php', {
		method: "post",
		evalJSON: true,
		sanitizeJSON: true,
		parameters: $H(param_hash),
		onSuccess: post_to_facebook_callback,
		onFailure: errback_global
	});

}

function post_to_facebook_callback( oReq, json )
{
	
	if (oReq.responseJSON.status == 'success') 
	{
		$("facebook_wall_" + oReq.responseJSON.data['fighter_position'] + "_" + oReq.responseJSON.data['bout_id']).innerHTML = "<ul class=\"silk\"><li class=\"facebook\"><div class=\"facebook_wall_response\">Posted to facebook.</div></li></ul>";
	}
	else
	{
		$("facebook_wall_" + oReq.responseJSON.data['fighter_position'] + "_" + oReq.responseJSON.data['bout_id']).innerHTML = "<ul class=\"silk\"><li class=\"facebook\"><div class=\"facebook_wall_response\">Unable to post at this time.</div></li></ul>";
	}
}  // end function show_bout_category_fup_callback


function facebook_share_popup(arg_bout_id, arg_fighter_position)
{
	var url = "http://www.facebook.com/sharer.php?u=http%3A%2F%2Fthefightersunion.com%2Fbout%2F" + arg_bout_id + "%2Ffighter_position%2F" + arg_fighter_position + "&amp;src=sp";
	var strWindowFeatures = "menubar=no,location=no,resizable=yes,scrollbars=no,status=no";
	
	window.open(url, "Share TheFightersUnion on Facebook", strWindowFeatures);	
}
