void LogisticsVariantDialog::begin()
{
	edits[0].allowIME(false);
	edits[0].setFocus(true);
	edits[0].setEntry("");
	initVariantList();
	status			 = RUNNING;
	bPromptOverwrite = 0;
	bDeletePrompt	= 0;
	bTranscript		 = 0;
	// change all the texts
	textObjects[0].setText(IDS_DIALOG_VARIANT_SAVE);
	textObjects[1].setText(IDS_DIALOG_VARIANT_LIST);
	buttons[2].setText(IDS_DIALOG_SAVE);
	LogisticsDialog::begin();
}
void LogisticsAcceptVariantDialog::update()
{
	LogisticsDialog::update();
	
	buttons[1].disable( 0 );

	if ( bPromptOverwrite )
	{
		LogisticsOKDialog::instance()->update();
		if ( YES == LogisticsOKDialog::instance()->getStatus() )
		{
			status = YES;
			bPromptOverwrite = 0;
		}
		else if ( NO == LogisticsOKDialog::instance()->getStatus() )
		{
			bPromptOverwrite = 0;
		}
	}
	else if ( bDeletePrompt )
	{
		LogisticsOKDialog::instance()->update();
		if ( YES == LogisticsOKDialog::instance()->getStatus() )
		{
			LogisticsData::instance->removeVariant( selectedName );
			initVariantList();
			bDeletePrompt = 0;

			edits[0].getEntry( selectedName );
			edits[0].setEntry( "" );
		
		}
		else if ( NO == LogisticsOKDialog::instance()->getStatus() )
		{
			bDeletePrompt = 0;
		}
	
	}
	
	gameListBox.update();

	if ( userInput->isLeftClick()  )
	{
		if ( gameListBox.pointInside( userInput->getMouseX(), userInput->getMouseY() ) )
		{
			// get selected item
			int item = gameListBox.GetSelectedItem();
			if ( item != -1 )
			{
				for ( int i = 0; i < gameListBox.GetItemCount(); i++ )
				{
					gameListBox.GetItem( i )->setColor( edits[0].getColor() );
				}
				gameListBox.GetItem( item )->setColor( edits[0].getHighlightColor() );
				const char* text = ((aTextListItem*)gameListBox.GetItem( item ))->getText();
				edits[0].setEntry( text );
				selectedName = text;
			}
		}
		else if ( edits[0].pointInside( userInput->getMouseX(), userInput->getMouseY() ) )
		{
			gameListBox.SelectItem( -1 );
			for ( int i = 0; i < gameListBox.GetItemCount(); i++ )
			{
				gameListBox.GetItem( i )->setColor( edits[0].getColor() );
			}
		}
	}

	EString text;
	edits[0].getEntry( text );
	if ( !LogisticsData::instance->canReplaceVariant( text ) )
	{
		buttons[1].disable( 1 );	
	}
	else
	{
		buttons[1].disable( 0 );
	}

}
void LogisticsVariantDialog::update()
{

	if ( bPromptOverwrite )
	{
		LogisticsOKDialog::instance()->update();
		if ( LogisticsOKDialog::instance()->isDone() )
		{
			if ( YES == LogisticsOKDialog::instance()->getStatus() )
			{
				status = YES;
				end();
				bPromptOverwrite = 0;
			}
			else if ( NO == LogisticsOKDialog::instance()->getStatus() )
			{
				bPromptOverwrite = 0;
			}
		}

		return;
	}
	else if ( bDeletePrompt )
	{
		LogisticsOKDialog::instance()->update();
		if ( YES == LogisticsOKDialog::instance()->getStatus() )
		{
			if ( bTranscript )
			{
				FullPathFileName path;
				path.init( "data\\multiplayer\\transcripts\\", selectedName, ".txt" );

				DeleteFile( path );
				initTranscript();

			}
			else
			{
				LogisticsData::instance->removeVariant( selectedName );
				initVariantList();
				edits[0].getEntry( selectedName );
			}
			bDeletePrompt = 0;
			edits[0].setEntry( "" );	
		}
		else if ( NO == LogisticsOKDialog::instance()->getStatus() )
		{
			bDeletePrompt = 0;
		}

		return;
	
	}

	LogisticsDialog::update();

	
	gameListBox.update();

	if ( userInput->isLeftClick()  )
	{
		if ( gameListBox.pointInside( userInput->getMouseX(), userInput->getMouseY() ) )
		{
			// get selected item
			int item = gameListBox.GetSelectedItem();
			if ( item != -1 )
			{
				for ( int i = 0; i < gameListBox.GetItemCount(); i++ )
				{
					gameListBox.GetItem( i )->setColor( edits[0].getColor() );
				}
				gameListBox.GetItem( item )->setColor( edits[0].getHighlightColor() );
				const char* text = ((aTextListItem*)gameListBox.GetItem( item ))->getText();
				edits[0].setEntry( text );
				selectedName = text;
			}
		}
		else if ( edits[0].pointInside( userInput->getMouseX(), userInput->getMouseY() ) )
		{
			gameListBox.SelectItem( -1 );
			for ( int i = 0; i < gameListBox.GetItemCount(); i++ )
			{
				gameListBox.GetItem( i )->setColor( edits[0].getColor() );
			}
		}
	}

	EString text;
	edits[0].getEntry( text );
	if ( ( !bTranscript && !LogisticsData::instance->canReplaceVariant( text ) ) || !text.Length() )
	{
		buttons[2].disable( 1 );	
	}
	else
	{
		buttons[2].disable( 0 );
	}

	if ( bTranscript || LogisticsData::instance->canDeleteVariant( text ) )
	{
		if ( bTranscript )
		{
			if ( !text.Length() )
				buttons[0].disable( true );
			else
			{
				FullPathFileName path;
				path.init( "data\\multiplayer\\transcripts\\", text, ".txt" );
				if ( fileExists( path ) )
				{
					buttons[0].disable( 0 );
				}
				else
					buttons[0].disable( 1 );
			}
		}

		else
			buttons[0].disable( 0 );
		
	}
	else
		buttons[0].disable( 1 );

}