
//----------------------------------------------------------------------------------------------------------------------

function GameOptionsScreen() {
	var self = this;

	var resetButton = document.getElementById( "reset_game_options_button" );
	resetButton.onclick = function() {
		 self.onResetClicked();
	};

	var saveButton = document.getElementById( "save_game_options_button" );
	saveButton.onclick = function() {
		 self.onSaveClicked();
	};

	// Get all the UI elements that we can interact with.
	this.game_option1 = document.getElementById( "game_option1" );
	this.game_option2 = document.getElementById( "game_option2" );
	this.game_option3 = document.getElementById( "game_option3" );
	this.game_option4 = document.getElementById( "game_option4" );
	this.game_option5 = document.getElementById( "game_option5" );
}

//----------------------------------------------------------------------------------------------------------------------

GameOptionsScreen.prototype.onActivated = function() {
	
}

//----------------------------------------------------------------------------------------------------------------------

GameOptionsScreen.prototype.onResetClicked = function() {
	var self = this;

	if(confirm( StringTable.Code.resetGameOptionsWarning ))
	{
		self.game_option1.value = "";
		self.game_option2.value = "";
		self.game_option3.value = "";
		self.game_option4.value = "";
		self.game_option5.value = "";
	}
}

//----------------------------------------------------------------------------------------------------------------------

GameOptionsScreen.prototype.onSaveClicked = function() {
	var self = this;

	if(Helper.gameOptionsCount (
		Helper.trim(self.game_option1.value),
		Helper.trim(self.game_option2.value), 
		Helper.trim(self.game_option3.value), 
		Helper.trim(self.game_option4.value), 
		Helper.trim(self.game_option5.value)
		) >= 2
	)
	{
		// Add event listeners.
		fbService.onSuccess = function( response ) { self.onFatBookieGameOptionsResponse( response ) }
		fbService.onError = function( status ) { self.onFBServiceError( status ) }

		// Start the request.
		fbService.setGameOptions(	newgameScreen.draft_id, 
									self.game_option1.value,
									self.game_option2.value,
									self.game_option3.value,
									self.game_option4.value,
									self.game_option5.value 
									);
	}
	else
		alert( StringTable.Code.gameOptionsIncompleteValuesWarning );
}

//----------------------------------------------------------------------------------------------------------------------

GameOptionsScreen.prototype.onFatBookieGameOptionsResponse = function( response ) {
	var self = this;

	if(response.retcode != undefined) {
		if(parseInt(response.retcode) == 1)
			self.onFBServiceError(response.body);
		else
		{
			//jump to next wizard step
			widgetMenu.activate( Menu.PUBLISH_GAME_SCREEN );
		}
	}
	else
		alert( StringTable.Code.fatalAPIError );
}

//----------------------------------------------------------------------------------------------------------------------

GameOptionsScreen.prototype.onFBServiceError = function( status ) {
	// Alert the user that something has gone wrong.
	if(status == "Invalid session")
	{
		alert( StringTable.Code.gameOptionsScreenInvalidSessionError );

		// Load the login screen to allow user to get a new session
		widgetMenu.activate( Menu.LOGIN_SCREEN );
	}
	else
		alert( StringTable.Code.gameOptionsScreenDataError + " (" + status + ")" );
}

//----------------------------------------------------------------------------------------------------------------------

