context: using System;
  using System.Collections;
  using Server;
  using Server.Mobiles;
  using Server.Items;
  using Server.Gumps;
  using MC = Server.MegaSpawnerSystem.MasterControl;
  
  namespace Server.MegaSpawnerSystem
  {
  	public class SearchEntryGump : Gump
  	{
  		private ArrayList ArgsList = new ArrayList();
  
  		private ArrayList PageInfoList = new ArrayList();
  		private ArrayList ESGArgsList = new ArrayList();
  		private ArrayList AVSArgsList = new ArrayList();
  		private ArrayList PersonalConfigList = new ArrayList();
  		private FromGump FromWhere;
  		private ArrayList SEGArgsList = new ArrayList();
  
  		private int cpg, pg;
  		private StyleType StyleTypeConfig;
  		private BackgroundType BackgroundTypeConfig;
  		private TextColor DefaultTextColor, TitleTextColor, MessagesTextColor, CommandButtonsTextColor;
  
  		private bool Help, DisplayMessages;
  		private string MessagesTitle, Messages, OldMessagesTitle, OldMessages;
  		private string defaultTextColor, titleTextColor, messagesTextColor, commandButtonsTextColor;
  		private int PageNumberTextColor;
  
  		private int offsetMin, offsetMax;
  
  		private ArrayList SearchResultsList = new ArrayList();
  		private string entryType, addItem;
  		private ArrayList InsideItemList = new ArrayList();
  		private int insideIndex;
  
  		private SearchType searchType;
  		private string SearchFor;
  
  		private const int numOffset = 1000;
  		private const int amtPerPg = 14;
  		private const int listSpace = 308;
  		private int totalPages;
  		private Mobile gumpMobile;
  
  		public SearchEntryGump( Mobile mobile, ArrayList argsList ) : base( 0,0 )
  		{
  			gumpMobile = mobile;
  
  			ArgsList = argsList;
  			GetArgsList();
  
  			GetTextColors();
  
  			AddPage(0); // Page 0
  
  			MC.DisplayStyle( this, StyleTypeConfig, 80, 80, 600, 452 );
  
  			MC.DisplayBackground( this, BackgroundTypeConfig, 100, 450, 249, 19 );
  			MC.DisplayBackground( this, BackgroundTypeConfig, 350, 450, 279, 19 );
  			MC.DisplayBackground( this, BackgroundTypeConfig, 630, 450, 30, 19 );
  			MC.DisplayBackground( this, BackgroundTypeConfig, 100, 470, 249, 19 );
  			MC.DisplayBackground( this, BackgroundTypeConfig, 350, 470, 279, 19 );
  			MC.DisplayBackground( this, BackgroundTypeConfig, 630, 470, 30, 19 );
  			MC.DisplayBackground( this, BackgroundTypeConfig, 100, 490, 249, 20 );
  			MC.DisplayBackground( this, BackgroundTypeConfig, 350, 490, 279, 20 );
  			MC.DisplayBackground( this, BackgroundTypeConfig, 630, 490, 30, 20 );
  
  			MC.DisplayImage( this, StyleTypeConfig );
  
  			AddButton( 630, 490, 4017, 4019, 0, GumpButtonType.Reply, 0 );
  
  			string searchtype = "";
  
  			switch ( searchType )
  			{
  				case SearchType.MobileType:{ searchtype = " Mobile"; break; }
  				case SearchType.ItemType:{ searchtype = " Item"; break; }
  			}
  
  			if ( SearchFor == "" )
  				AddHtml( 121, 81, 560, 20, MC.ColorText( titleTextColor, String.Format( "Entire Listing Of Valid{0} Types", searchtype ) ), false, false );
  			else
  				AddHtml( 121, 81, 560, 20, MC.ColorText( titleTextColor, String.Format( "Search Results For \"{0}\"", SearchFor ) ), false, false );
  
  			if ( !Help )
  				AddButton( 597, 429, 2033, 2032, -5, GumpButtonType.Reply, 0 );
  			else
  				AddButton( 597, 429, 2032, 2033, -5, GumpButtonType.Reply, 0 );
  
  			if ( DisplayMessages )
  			{
  				MC.DisplayStyle( this, StyleTypeConfig, 80, 540, 600, 122 );
  				MC.DisplayBackground( this, BackgroundTypeConfig, 100, 560, 560, 80 );
  
  				AddHtml( 121, 541, 540, 20, MC.ColorText( titleTextColor, MessagesTitle ), false, false );
  				AddHtml( 100, 560, 560, 80, MC.ColorText( messagesTextColor, Messages ), false, true );
  				AddHtml( 531, 641, 100, 20, MC.ColorText( defaultTextColor, "Clear Messages" ), false, false );
  
  				AddButton( 630, 640, 4017, 4019, -6, GumpButtonType.Reply, 0 );
  				AddButton( 371, 645, 2436, 2435, -8, GumpButtonType.Reply, 0 );
  			}
  			else
  			{
  				MC.DisplayStyle( this, StyleTypeConfig, 80, 530, 600, 20 );
  
  				AddButton( 371, 535, 2438, 2437, -8, GumpButtonType.Reply, 0 );
  			}
  
  			OldMessagesTitle = MessagesTitle;
  			OldMessages = Messages;
  
  			AddHtml( 151, 431, 60, 20, MC.ColorText( defaultTextColor, "Refresh" ), false, false );
  			AddButton( 120, 433, 2118, 2117, -7, GumpButtonType.Reply, 0 );
  
  			SearchResultsList = GetSearchResults();
  
  			AddPages();
  		}
  
  		public override void OnResponse( Server.Network.NetState sender, RelayInfo info )
  		{
  			int index = (int) info.ButtonID - numOffset;
  
  			string entry = null;
  
  			if ( index >= 0 )
  				entry = (string) SearchResultsList[index];
  
  			switch ( info.ButtonID )
  			{
  				case -100: // Page Number
  				{
  					MessagesTitle = "Help: Page Number";
  					Messages = "This is where the current page number out of total pages is shown. You may delete the page number and type in a page you would like to go to, then click refresh to jump to that page.\n\nFor Example:\nThe page number is 1/20, delete the 1/20 and type in 6, then click refresh. You will jump to page 6.";
  
  					OpenGump();
  
  					break;
  				}
  				case -8: // Display Messages
  				{
  					if ( Help )
  					{
  						if ( DisplayMessages )
  						{
  							MessagesTitle = "Help: Minimize Messages Button";
  							Messages = "That button will minimize the messages window.";
  						}
  						else
  						{
  							MessagesTitle = "Help: Restore Messages Button";
  							Messages = "That button will restore the messages window.";
  						}
  
  						OpenGump();
  
  						break;
  					}
  
  					DisplayMessages = !DisplayMessages;
  
  					OpenGump();
  
  					break;
  				}
  				case -7: // Refresh
  				{
  					if ( Help )
  					{
  						MessagesTitle = "Help: Refresh Button";
  						Messages = "That button will refresh the current window and also change the page number if specified in the upper right hand corner. To change the page number, delete the current page number and type in the page you want to go to.";
  
  						OpenGump();
  
  						break;
  					}
  
  					int intPage = 0;
  					int totalPages = (int) ( ( SearchResultsList.Count - 1 ) / amtPerPg ) + 1;
  					string checkPage = Convert.ToString( info.GetTextEntry( 0 ).Text ).ToLower();
  
  					if ( checkPage == String.Format( "{0}/{1}", pg, totalPages ) )
  					{
  						OpenGump();
  
  						break;
  					}
  
  					try{ intPage = Convert.ToInt32( checkPage ); }
  					catch
  					{
  						MessagesTitle = "Refresh";
  						Messages = "The page number must be an integer.";
  
  						OpenGump();
  
  						break;
  					}
  
  					if ( intPage > 0 && intPage <= totalPages )
  					{
  						pg = intPage;
  					}
  					else
  					{
  						MessagesTitle = "Refresh";
  						Messages = "That page number does not exist.";
  					}
  
  					OpenGump();
  
  					break;
  				}
  				case -6: // Clear Messages
  				{
  					if ( Help )
  					{
  						MessagesTitle = "Help: Clear Messages Button";
  						Messages = "That button will clear all the messages in the messages window.";
  
  						OpenGump();
  
  						break;
  					}
  
  					MessagesTitle = "Messages";
  					Messages = null;
  
  					OpenGump();
  
  					break;
  				}
  
gt: 				case -5: // Help