/// <summary> Constructor for a new instance of the ManageMenu_ItemViewer class </summary>
        /// <param name="Current_Object"> Digital resource to display </param>
        /// <param name="Current_User"> Current user for this session </param>
        /// <param name="Current_Mode"> Navigation object which encapsulates the user's current request </param>
        public ManageMenu_ItemViewer(SobekCM_Item Current_Object, User_Object Current_User, Navigation_Object Current_Mode)
        {
            // Save the current user and current mode information (this is usually populated AFTER the constructor completes,
            // but in this case (QC viewer) we need the information for early processing
            CurrentMode = Current_Mode;
            CurrentUser = Current_User;
            CurrentItem = Current_Object;

            // Determine if this user can edit this item
            if (CurrentUser == null)
            {
                Current_Mode.ViewerCode = String.Empty;
                UrlWriterHelper.Redirect(Current_Mode);
                return;
            }
            else
            {
                bool userCanEditItem = CurrentUser.Can_Edit_This_Item( CurrentItem.BibID, CurrentItem.Bib_Info.SobekCM_Type_String, CurrentItem.Bib_Info.Source.Code, CurrentItem.Bib_Info.HoldingCode, CurrentItem.Behaviors.Aggregation_Code_List );
                if (!userCanEditItem)
                {
                    Current_Mode.ViewerCode = String.Empty;
                    UrlWriterHelper.Redirect(Current_Mode);
                    return;
                }
            }
        }
        /// <summary> Constructor for a new instance of the Static_Pages_Builder class </summary>
        /// <param name="Primary_Web_Server_URL"> URL for the primary web server </param>
        /// <param name="Static_Data_Location"> Network location for the data directory </param>
        /// <param name="Default_Skin"> Default skin code </param>
        public Static_Pages_Builder(string Primary_Web_Server_URL, string Static_Data_Location, string Default_Skin)
        {
            primaryWebServerUrl = Primary_Web_Server_URL;
            staticSobekcmDataLocation = Static_Data_Location;
            staticSobekcmLocation = UI_ApplicationCache_Gateway.Settings.Servers.Application_Server_Network;

            tracer = new Custom_Tracer();
            assistant = new SobekCM_Assistant();

            // Save all the objects needed by the SobekCM Library
            defaultSkin = Default_Skin;

            // Create the mode object
            currentMode = new Navigation_Object
                              {
                                  ViewerCode = "citation",
                                  Skin = String.Empty,
                                  Mode = Display_Mode_Enum.Item_Display,
                                  Language = Web_Language_Enum.English,
                                  Base_URL = primaryWebServerUrl
                              };

            // Set some constant settings
            // SobekCM.Library.UI_ApplicationCache_Gateway.Settings.Watermarks_URL = primary_web_server_url + "/design/wordmarks/";
            UI_ApplicationCache_Gateway.Settings.Base_SobekCM_Location_Relative = primaryWebServerUrl;

            // Ensure all the folders exist
            if (!Directory.Exists(staticSobekcmDataLocation))
                Directory.CreateDirectory(staticSobekcmDataLocation);
            if (!Directory.Exists(staticSobekcmDataLocation + "\\rss"))
                Directory.CreateDirectory(staticSobekcmDataLocation + "\\rss");
        }
        /// <summary> Constructor for a new instance of the TEI_ItemViewer class, used to display a
        /// TEI file for a given digital resource </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        public TEI_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest)
        {
            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;

            // Get the TEI files to use
            tei_file = BriefItem.Behaviors.Get_Setting("TEI.Source_File");
            xslt_file = BriefItem.Behaviors.Get_Setting("TEI.XSLT");
            css_file = BriefItem.Behaviors.Get_Setting("TEI.CSS");

            // Ensure the XSLT file really exists
            if (!File.Exists(xslt_file))
            {
                // This may just not have the path on it
                if ((xslt_file.IndexOf("/") < 0) && (xslt_file.IndexOf("\\") < 0))
                {
                    xslt_file = Path.Combine(UI_ApplicationCache_Gateway.Settings.Servers.Application_Server_Network, "plugins\\tei\\xslt", xslt_file);
                }
            }

            string tei_file_network = SobekFileSystem.Resource_Network_Uri(BriefItem, tei_file);

            XSLT_Transformer_ReturnArgs returnArgs = XSLT_Transformer.Transform(tei_file_network, xslt_file);
            tei_string_to_display = String.Empty;
            if (returnArgs.Successful)
            {
                tei_string_to_display = returnArgs.TransformedString;

                // FInd the head information
                int head_start = tei_string_to_display.IndexOf("<head", StringComparison.OrdinalIgnoreCase);
                int head_end = tei_string_to_display.IndexOf("</head>", StringComparison.OrdinalIgnoreCase);
                if ((head_start > 0) && (head_end > 0))
                {
                    head_info = tei_string_to_display.Substring(head_start, head_end - head_start);
                    int end_bracket = head_info.IndexOf(">");
                    head_info = head_info.Substring(end_bracket + 1);
                }

                // Trim down to the body
                int body_start = tei_string_to_display.IndexOf("<body", StringComparison.OrdinalIgnoreCase);
                int body_end = tei_string_to_display.IndexOf("</body>", StringComparison.OrdinalIgnoreCase);

                if ((body_start > 0) && (body_end > 0))
                {
                    tei_string_to_display = tei_string_to_display.Substring(body_start, body_end - body_start);
                    int end_bracket = tei_string_to_display.IndexOf(">");
                    tei_string_to_display = tei_string_to_display.Substring(end_bracket + 1);
                }

            }
            else
            {
                tei_string_to_display = "Error during XSLT transform of TEI<br /><br />" + returnArgs.ErrorMessage;
            }
        }
        /// <summary> Constructor for a new instance of the Text_Search_ItemViewer class, which allows the full text of an 
        /// individual resource to be searched and individual matching pages are displayed with page thumbnails </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        public Text_Search_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest, Custom_Tracer Tracer )
        {
            Tracer.Add_Trace("Text_Search_ItemViewer.Constructor");

            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;

            if (!String.IsNullOrWhiteSpace(CurrentRequest.Text_Search))
            {
                List<string> terms = new List<string>();
                List<string> web_fields = new List<string>();

                // Split the terms correctly
                SobekCM_Assistant.Split_Clean_Search_Terms_Fields(CurrentRequest.Text_Search, "ZZ", Search_Type_Enum.Basic, terms, web_fields, null, Search_Precision_Type_Enum.Contains, '|');

                Tracer.Add_Trace("Text_Search_ItemViewer.Constructor", "Performing Solr/Lucene search");

                int page = CurrentRequest.SubPage.HasValue ? Math.Max(CurrentRequest.SubPage.Value, ((ushort)1)) : 1;
                results = Solr_Page_Results.Search(BriefItem.BibID, BriefItem.VID, terms, 20, page, false);

                Tracer.Add_Trace("Text_Search_ItemViewer.Constructor", "Completed Solr/Lucene search in " + results.QueryTime + "ms");
            }
        }
 /// <summary> Constructor for a new instance of the RequestCache class </summary>
 /// <param name="Current_Mode"> Mode / navigation information for the current request</param>
 /// <param name="Hierarchy_Object"> Current item aggregation object to display </param>
 /// <param name="Results_Statistics"> Information about the entire set of results for a search or browse </param>
 /// <param name="Paged_Results"> Single page of results for a search or browse, within the entire set </param>
 /// <param name="Browse_Object"> Object contains all the basic information about any browse or info display </param>
 /// <param name="Current_Item"> Current item to display </param>
 /// <param name="Current_Page"> Current page within the item</param>
 /// <param name="HTML_Skin"> HTML Web skin which controls the overall appearance of this digital library </param>
 /// <param name="Current_User"> Currently logged on user </param>
 /// <param name="Public_Folder"> Object contains the information about the public folder to display </param>
 /// <param name="Site_Map"> Optional site map object used to render a navigational tree-view on left side of static web content pages </param>
 /// <param name="Items_In_Title"> List of items within the current title ( used for the Item Group display )</param>
 /// <param name="Static_Web_Content"> HTML content-based browse, info, or imple CMS-style web content objects.  These are objects which are read from a static HTML file and much of the head information must be maintained </param>
 /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
 public RequestCache(Navigation_Object Current_Mode,
     Item_Aggregation Hierarchy_Object,
     Search_Results_Statistics Results_Statistics,
     List<iSearch_Title_Result> Paged_Results,
     Item_Aggregation_Child_Page Browse_Object,
     SobekCM_Item Current_Item,
     Page_TreeNode Current_Page,
     Web_Skin_Object HTML_Skin,
     User_Object Current_User,
     Public_User_Folder Public_Folder,
     SobekCM_SiteMap Site_Map,
     SobekCM_Items_In_Title Items_In_Title,
     HTML_Based_Content Static_Web_Content,
     Custom_Tracer Tracer)
 {
     this.Current_Mode = Current_Mode;
     this.Hierarchy_Object = Hierarchy_Object;
     this.Results_Statistics = Results_Statistics;
     this.Paged_Results = Paged_Results;
     this.Browse_Object = Browse_Object;
     this.Current_Item = Current_Item;
     this.Current_Page = Current_Page;
     this.HTML_Skin = HTML_Skin;
     this.Current_User = Current_User;
     this.Public_Folder = Public_Folder;
     this.Site_Map = Site_Map;
     this.Items_In_Title = Items_In_Title;
     this.Static_Web_Content = Static_Web_Content;
     this.Tracer = Tracer;
 }
        /// <summary> Constructor for a new instance of the JPEG_ItemViewer class, used to display JPEGs linked to
        /// pages in a digital resource </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        /// <param name="JPEG_ViewerCode"> JPEG viewer code, as determined by configuration files </param>
        /// <param name="FileExtensions"> File extensions that this viewer allows, as determined by configuration files </param>
        public JPEG_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest, Custom_Tracer Tracer, string JPEG_ViewerCode, string[] FileExtensions)
        {
            // Add the trace
            if ( Tracer != null )
                Tracer.Add_Trace("JPEG_ItemViewer.Constructor");

            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties
            Behaviors = EmptyBehaviors;

            // Is the JPEG2000 viewer included in this item?
            bool zoomableViewerIncluded = BriefItem.UI.Includes_Viewer_Type("JPEG2000");
            string[] jpeg2000_extensions = null;
            if (zoomableViewerIncluded)
            {
                iItemViewerPrototyper jp2Prototyper = ItemViewer_Factory.Get_Viewer_By_ViewType("JPEG2000");
                if (jp2Prototyper == null)
                    zoomableViewerIncluded = false;
                else
                {
                    zoomableViewerCode = jp2Prototyper.ViewerCode;
                    jpeg2000_extensions = jp2Prototyper.FileExtensions;
                }
            }

            // Set some default values
            width = 500;
            height = -1;
            includeLinkToZoomable = false;

            // Determine the page
            page = 1;
            if (!String.IsNullOrEmpty(CurrentRequest.ViewerCode))
            {
                int tempPageParse;
                if (Int32.TryParse(CurrentRequest.ViewerCode.Replace(JPEG_ViewerCode.Replace("#",""), ""), out tempPageParse))
                    page = tempPageParse;
            }

            // Just a quick range check
            if (page > BriefItem.Images.Count)
                page = 1;

            // Try to set the file information here
            if ((!set_file_information(FileExtensions, zoomableViewerIncluded, jpeg2000_extensions)) && (page != 1))
            {
                // If there was an error, just set to the first page
                page = 1;
                set_file_information(FileExtensions, zoomableViewerIncluded, jpeg2000_extensions);
            }

            // Since this is a paging viewer, set the viewer code
            if (String.IsNullOrEmpty(CurrentRequest.ViewerCode))
                CurrentRequest.ViewerCode = JPEG_ViewerCode.Replace("#", page.ToString());
        }
        /// <summary> Constructor for the Tracking Sheet ItemViewer </summary>
        /// <param name="Current_Object"></param>
        /// <param name="Current_User"></param>
        /// <param name="Current_Mode"></param>
        public TrackingSheet_ItemViewer(SobekCM_Item Current_Object, User_Object Current_User, Navigation_Object Current_Mode)
        {
            CurrentMode = Current_Mode;
            CurrentUser = Current_User;

            //Assign the current resource object to track_item
            track_item = Current_Object;

            //Get the ItemID for this Item from the database
            itemID = track_item.Web.ItemID;

            //Get aggregation info
            aggregations = track_item.Behaviors.Aggregation_Codes;

            //If no aggregationPermissions present, display "none"
            aggregations = aggregations.Length>0 ? aggregations.ToUpper() : "(none)";
            aggregations = aggregations.Replace(";", "; ");

            //Determine the OCLC & Aleph number for display
            oclc = track_item.Bib_Info.OCLC_Record;
            aleph = track_item.Bib_Info.ALEPH_Record;

            if (String.IsNullOrEmpty(oclc) || oclc.Trim() == "0" || oclc.Trim() == "1")
                oclc = "(none)";
            if (String.IsNullOrEmpty(aleph) || aleph.Trim() == "0" || aleph.Trim() == "1")
                aleph = "(none)";

            //Determine the author(s) for display
            authors_list = new List<string>();
            int author_startCount = 0;

            //Add the main entity first
            if (track_item.Bib_Info.hasMainEntityName)
            {
                authors_list.Add(track_item.Bib_Info.Main_Entity_Name.Full_Name + track_item.Bib_Info.Main_Entity_Name.Role_String);
                author_startCount++;
            }

            //Now add all other associated creators
            for (int i = author_startCount; i < track_item.Bib_Info.Names_Count; i++)
            {
                //Skip any publishers in this list
                if(track_item.Bib_Info.Names[i].Role_String.ToUpper().Contains("PUBLISHER"))
                    continue;
                authors_list.Add(track_item.Bib_Info.Names[i].Full_Name  + track_item.Bib_Info.Names[i].Role_String);
            }

            //Determine the publisher(s) for display
            publishers_list=new string[track_item.Bib_Info.Publishers_Count];
            for (int i = 0; i < track_item.Bib_Info.Publishers_Count; i++)
                publishers_list[i] = track_item.Bib_Info.Publishers[i].Name;

            //Create the temporary location for saving the barcode images
               image_location = UI_ApplicationCache_Gateway.Settings.Servers.Base_Temporary_Directory + "tsBarcodes\\" + itemID.ToString();

            // Create the folder for the user in the temp directory
            if (!Directory.Exists(image_location))
                Directory.CreateDirectory(image_location);
        }
        /// <summary> Constructor for a new instance of the PDF_ItemViewer class </summary>
        /// <param name="FileName"> Name of the PDF file to display </param>
        /// <param name="Current_Mode"> Current navigation information for this request </param>
        public PDF_ItemViewer(string FileName, Navigation_Object Current_Mode)
        {
            // Determine if this should be written as an iFrame
            writeAsIframe = ((!String.IsNullOrEmpty(Current_Mode.Browser_Type)) && (Current_Mode.Browser_Type.IndexOf("CHROME") == 0));

            // Save the filename
            this.FileName = FileName;
        }
 /// <summary> Redirect the user to the current mode's URL </summary>
 /// <param name="Current_Mode"> Current navigation object which contains the information  </param>
 /// <param name="Flush_Response"> Flag indicates if the response should be flushed</param>
 /// <remarks> This does not stop execution immediately (which would raise a ThreadAbortedException
 /// and be costly in terms of performance) but it does set the 
 /// Request_Completed flag, which should be checked and will effectively stop any 
 /// further actions. </remarks>
 public static void Redirect(Navigation_Object Current_Mode, bool Flush_Response)
 {
     if (Flush_Response)
         HttpContext.Current.Response.Flush();
     Current_Mode.Request_Completed = true;
     HttpContext.Current.Response.Redirect(Redirect_URL(Current_Mode), false);
     HttpContext.Current.ApplicationInstance.CompleteRequest();
 }
        /// <summary> init viewer instance </summary>
        public Google_Coordinate_Entry_ItemViewer(User_Object Current_User, SobekCM_Item Current_Item, Navigation_Object Current_Mode)
        {
            try
            {

            currentUser = Current_User;
            currentItem = Current_Item;
            CurrentMode = Current_Mode;

            //string resource_directory = UI_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + CurrentItem.Web.AssocFilePath;
            //string current_mets = resource_directory + CurrentItem.METS_Header.ObjectID + ".mets.xml";

            // If there is no user, send to the login
            if (currentUser == null)
            {
                CurrentMode.Mode = Display_Mode_Enum.My_Sobek;
                CurrentMode.My_Sobek_Type = My_Sobek_Type_Enum.Logon;
                CurrentMode.Return_URL = Current_Item.BibID + "/" + Current_Item.VID + "/mapedit";
                UrlWriterHelper.Redirect(CurrentMode);
                return;
            }

            //holds actions from page
            string action = HttpContext.Current.Request.Form["action"] ?? String.Empty;
            string payload = HttpContext.Current.Request.Form["payload"] ?? String.Empty;

            // See if there were hidden requests
            if (!String.IsNullOrEmpty(action))
            {
               if ( action == "save")
                   SaveContent(payload);
            }

            ////create a backup of the mets
            //string backup_directory = UI_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + Current_Item.Web.AssocFilePath + UI_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name;
            //string backup_mets_name = backup_directory + "\\" + CurrentItem.METS_Header.ObjectID + "_" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + ".mets.bak";
            //File.Copy(current_mets, backup_mets_name);

            }
            catch (Exception ee)
            {
                //Custom_Tracer.Add_Trace("MapEdit Start Failure");
                throw new ApplicationException("MapEdit Start Failure\r\n" + ee.Message);
            }

            // Create the options dictionary used when saving information to the database, or writing MarcXML
            options = new Dictionary<string, object>();
            if (UI_ApplicationCache_Gateway.Settings.MarcGeneration != null)
            {
                options["MarcXML_File_ReaderWriter:MARC Cataloging Source Code"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Cataloging_Source_Code;
                options["MarcXML_File_ReaderWriter:MARC Location Code"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Location_Code;
                options["MarcXML_File_ReaderWriter:MARC Reproduction Agency"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Reproduction_Agency;
                options["MarcXML_File_ReaderWriter:MARC Reproduction Place"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.Reproduction_Place;
                options["MarcXML_File_ReaderWriter:MARC XSLT File"] = UI_ApplicationCache_Gateway.Settings.MarcGeneration.XSLT_File;
            }
            options["MarcXML_File_ReaderWriter:System Name"] = UI_ApplicationCache_Gateway.Settings.System.System_Name;
            options["MarcXML_File_ReaderWriter:System Abbreviation"] = UI_ApplicationCache_Gateway.Settings.System.System_Abbreviation;
        }
        /// <summary> Constructor for a new instance of the Google_Coordinate_Entry_ItemViewer class, used to edit the 
        /// coordinate information associated with this digital resource within an online google maps interface </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        public Google_Coordinate_Entry_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest, Custom_Tracer Tracer )
        {
            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            try
            {

                // Get the full SobekCM item
                Tracer.Add_Trace("Google_Coordinate_Entry_ItemViewer.Constructor", "Try to pull this sobek complete item");
                currentItem = SobekEngineClient.Items.Get_Sobek_Item(CurrentRequest.BibID, CurrentRequest.VID, Tracer);
                if (currentItem == null)
                {
                    Tracer.Add_Trace("Google_Coordinate_Entry_ItemViewer.Constructor", "Unable to build complete item");
                    CurrentRequest.Mode = Display_Mode_Enum.Error;
                    CurrentRequest.Error_Message = "Invalid Request : Unable to build complete item";
                    return;
                }

                //string resource_directory = UI_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + CurrentItem.Web.AssocFilePath;
                //string current_mets = resource_directory + CurrentItem.METS_Header.ObjectID + ".mets.xml";

                // If there is no user, send to the login
                if (CurrentUser == null)
                {
                    CurrentRequest.Mode = Display_Mode_Enum.My_Sobek;
                    CurrentRequest.My_Sobek_Type = My_Sobek_Type_Enum.Logon;
                    CurrentRequest.Return_URL = BriefItem.BibID + "/" + BriefItem.VID + "/mapedit";
                    UrlWriterHelper.Redirect(CurrentRequest);
                    return;
                }

                //holds actions from page
                string action = HttpContext.Current.Request.Form["action"] ?? String.Empty;
                string payload = HttpContext.Current.Request.Form["payload"] ?? String.Empty;

                // See if there were hidden requests
                if (!String.IsNullOrEmpty(action))
                {
                    if (action == "save")
                        SaveContent(payload);
                }

                ////create a backup of the mets
                //string backup_directory = UI_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + Current_Item.Web.AssocFilePath + UI_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name;
                //string backup_mets_name = backup_directory + "\\" + CurrentItem.METS_Header.ObjectID + "_" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + ".mets.bak";
                //File.Copy(current_mets, backup_mets_name);

            }
            catch (Exception ee)
            {
                //Custom_Tracer.Add_Trace("MapEdit Start Failure");
                throw new ApplicationException("MapEdit Start Failure\r\n" + ee.Message);
            }
        }
        /// <summary> Constructor for a new instance of the Flash_ItemViewer class, used to display a
        /// flash file, or flash video, for a given digital resource </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        public Flash_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest)
        {
            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;

            // Find the appropriate flash files and label
            flash_file = String.Empty;
            flash_label = String.Empty;
            string first_label = String.Empty;
            string first_file = String.Empty;

            int current_flash_index = 0;
            const int FLASH_INDEX = 0;
            foreach (BriefItem_FileGrouping thisPage in BriefItem.Downloads)
            {
                // Look for a flash file on each page
                foreach (BriefItem_File thisFile in thisPage.Files)
                {
                    if (String.Compare(thisFile.File_Extension, ".SWF", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        // If this is the first one, assign it
                        if (String.IsNullOrEmpty(first_file))
                        {
                            first_file = thisFile.Name;
                            first_label = thisPage.Label;
                        }

                        if (current_flash_index == FLASH_INDEX)
                        {
                            flash_file = thisFile.Name;
                            flash_label = thisPage.Label;
                            break;
                        }
                        current_flash_index++;
                    }
                }
            }

            // If none found, but a first was found, use that
            if ((String.IsNullOrEmpty(flash_file)) && (!String.IsNullOrEmpty(first_file)))
            {
                flash_file = first_file;
                flash_label = first_label;
            }

            // If this is not already a link format, make it one
            if (( !String.IsNullOrEmpty(flash_file)) && ( flash_file.IndexOf("http:") < 0))
            {
                flash_file = BriefItem.Web.Source_URL + "/" + flash_file;
            }
        }
        /// <summary> Constructor for a new instance of the Restricted_ItemViewer class, used display
        ///  the applicable restricted message for a digital resource which is currently restricted due to IP restrictions </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        public Restricted_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest)
        {
            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;
        }
        /// <summary> Constructor for a new instance of the Directory_ItemViewer class, used display
        /// the tracking milestones information for a digital resource </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        public Directory_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest, Custom_Tracer Tracer)
        {
            Tracer.Add_Trace("Directory_ItemViewer.Constructor");

            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;
        }
        /// <summary> Resolve the requested URL (sepecified via the base url and the query string ) into a SobekCM navigation object </summary>
        /// <param name="RequestQueryString"> Query string, from the request The request query string.</param>
        /// <param name="BaseUrl"> Base URL of the original request </param>
        /// <param name="RequestUserLanguages"> List of user languages requested (via browser settings) </param>
        /// <param name="Tracer">The tracer.</param>
        /// <returns> Fully built navigation controller object </returns>
        public Navigation_Object get_navigation_object(NameValueCollection RequestQueryString, string BaseUrl, string[] RequestUserLanguages, Custom_Tracer Tracer)
        {
            NameValueCollection keys = RequestQueryString.Copy();

            string redirect_url = RequestQueryString["urlrelative"];
            redirect_url = redirect_url.Replace("/url-resolver/json", "").Replace("/url-resolver/json-p", "").Replace("/url-resolver/protobuf", "").Replace("/url-resolver/xml", "");
            keys["urlrelative"] = redirect_url;

            Navigation_Object currentMode = new Navigation_Object();
            QueryString_Analyzer.Parse_Query(keys, currentMode, BaseUrl, RequestUserLanguages, Engine_ApplicationCache_Gateway.Codes, Engine_ApplicationCache_Gateway.Collection_Aliases, Engine_ApplicationCache_Gateway.Items, Engine_ApplicationCache_Gateway.URL_Portals, Engine_ApplicationCache_Gateway.WebContent_Hierarchy, Tracer);

            return currentMode;
        }
        /// <summary> Constructor for a new instance of the PDF_ItemViewer class, used to display a PDF file from a digital resource </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        /// <param name="FileExtensions"> List of file extensions this video viewer should show </param>
        public PDF_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest, Custom_Tracer Tracer, string[] FileExtensions)
        {
            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Determine if this should be written as an iFrame
            writeAsIframe = ((!String.IsNullOrEmpty(CurrentRequest.Browser_Type)) && (CurrentRequest.Browser_Type.IndexOf("CHROME") == 0));

            // Set the behavior properties
            Behaviors = new List<HtmlSubwriter_Behaviors_Enum> {HtmlSubwriter_Behaviors_Enum.Suppress_Footer};

            // Determine if a particular video was selected
            pdf = 1;
            if (!String.IsNullOrEmpty(HttpContext.Current.Request.QueryString["pdf"]))
            {
                int tryPdf;
                if (Int32.TryParse(HttpContext.Current.Request.QueryString["pdf"], out tryPdf))
                {
                    if (tryPdf < 1)
                        tryPdf = 1;
                    pdf = tryPdf;
                }
            }

            // Collect the list of pdf by stepping through each download page
            pdfFileNames = new List<string>();
            pdfLabels = new List<string>();
            foreach (BriefItem_FileGrouping downloadPage in BriefItem.Downloads)
            {
                foreach (BriefItem_File thisFileInfo in downloadPage.Files)
                {
                    string extension = thisFileInfo.File_Extension.Replace(".", "");
                    foreach (string thisPossibleFileExtension in FileExtensions)
                    {
                        if (String.Compare(extension, thisPossibleFileExtension, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            pdfFileNames.Add(thisFileInfo.Name);
                            pdfLabels.Add(downloadPage.Label);
                        }
                    }
                }
            }

            // Ensure the pdf count wasn't too large
            if (pdf > pdfFileNames.Count)
                pdf = 1;
        }
        /// <summary> Constructor for a new instance of the Citation_MARC_ItemViewer class, used to display the 
        /// descriptive citation in MARC21 format</summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        public Citation_MARC_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest)
        {
            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;

            // Check to see if the user can edit this
            userCanEdit = false;
            if ( CurrentUser != null )
                userCanEdit = CurrentUser.Can_Edit_This_Item(BriefItem.BibID, BriefItem.Type, BriefItem.Behaviors.Source_Institution_Aggregation, BriefItem.Behaviors.Holding_Location_Aggregation, BriefItem.Behaviors.Aggregation_Code_List);
        }
        /// <summary> Constructor for a new instance of the Citation_Standard_ItemViewer class, used to display the 
        /// descriptive citation in standard, human-readable format for the digital resource </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        public Citation_Standard_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest)
        {
            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;

            // Set the width
            if ((CurrentRequest.Language == Web_Language_Enum.French) || (CurrentRequest.Language == Web_Language_Enum.Spanish))
                width = 230;

            // Get  the robot flag (if this is rendering for robots, the other citation views are not available)
            isRobot = CurrentRequest.Is_Robot;
        }
        /// <summary> Constructor for a new instance of the Video_ItemViewer class, used to display a video loaded
        /// locally with the digital resource files </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        /// <param name="FileExtensions"> List of file extensions this video viewer should show </param>
        public Video_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest, Custom_Tracer Tracer, string[] FileExtensions )
        {
            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;

            // Determine if a particular video was selected
            video = 1;
            if (!String.IsNullOrEmpty(HttpContext.Current.Request.QueryString["video"]))
            {
                int tryVideo;
                if (Int32.TryParse(HttpContext.Current.Request.QueryString["video"], out tryVideo))
                {
                    if (tryVideo < 1)
                        tryVideo = 1;
                    video = tryVideo;
                }
            }

            // Collect the list of videos by stepping through each download page
            videoFileNames = new List<string>();
            videoLabels = new List<string>();
            foreach (BriefItem_FileGrouping downloadPage in BriefItem.Downloads)
            {
                foreach (BriefItem_File thisFileInfo in downloadPage.Files)
                {
                    string extension = thisFileInfo.File_Extension.Replace(".","");
                    foreach (string thisPossibleFileExtension in FileExtensions)
                    {
                        if (String.Compare(extension, thisPossibleFileExtension, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            videoFileNames.Add(thisFileInfo.Name);
                            videoLabels.Add(downloadPage.Label);
                        }
                    }
                }
            }

            // Ensure the video count wasn't too large
            if (video > videoFileNames.Count)
                video = 1;
        }
 /// <summary> Constructor for a new instance of the RequestCache class </summary>
 /// <param name="Current_Mode"> Mode / navigation information for the current request</param>
 /// <param name="Results_Statistics"> Information about the entire set of results for a search or browse </param>
 /// <param name="Paged_Results"> Single page of results for a search or browse, within the entire set </param>
 /// <param name="HTML_Skin"> HTML Web skin which controls the overall appearance of this digital library </param>
 /// <param name="Current_User"> Currently logged on user </param>
 /// <param name="Public_Folder"> Object contains the information about the public folder to display </param>
 /// <param name="Top_Collection"> Item aggregation for the top-level collection, which is used in a number of places, for example 
 /// showing the correct banner, even when it is not the "current" aggregation </param>
 /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
 public RequestCache(Navigation_Object Current_Mode,
     Search_Results_Statistics Results_Statistics,
     List<iSearch_Title_Result> Paged_Results,
     Web_Skin_Object HTML_Skin,
     User_Object Current_User,
     Public_User_Folder Public_Folder,
     Item_Aggregation Top_Collection,
     Custom_Tracer Tracer)
 {
     this.Current_Mode = Current_Mode;
     this.Results_Statistics = Results_Statistics;
     this.Paged_Results = Paged_Results;
     this.HTML_Skin = HTML_Skin;
     this.Current_User = Current_User;
     this.Public_Folder = Public_Folder;
     this.Top_Collection = Top_Collection;
     this.Tracer = Tracer;
 }
        /// <summary> Constructor for a new instance of the JPEG2000_ItemViewer class, used to display JPEG2000s linked to
        /// pages in a digital resource </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        public JPEG2000_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest, Custom_Tracer Tracer, string ViewerCode, string[] FileExtensions)
        {
            // Add the trace
            if (Tracer != null)
                Tracer.Add_Trace("JPEG2000_ItemViewer.Constructor");

            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Determine if the navigator ( in the left nav bar ) should be suppressed
            suppressNavigator = false;
            if (UI_ApplicationCache_Gateway.Settings.Contains_Additional_Setting("JPEG2000 ItemViewer.Suppress Navigator"))
            {
                if (UI_ApplicationCache_Gateway.Settings.Get_Additional_Setting("JPEG2000 ItemViewer.Suppress Navigator").ToLower().Trim() != "false")
                    suppressNavigator = true;
            }

            // Determine the page
            page = 1;
            if (!String.IsNullOrEmpty(CurrentRequest.ViewerCode))
            {
                int tempPageParse;
                if (Int32.TryParse(CurrentRequest.ViewerCode.Replace(ViewerCode.Replace("#", ""), ""), out tempPageParse))
                    page = tempPageParse;
            }

            // Just a quick range check
            if (page > BriefItem.Images.Count)
                page = 1;

            // Try to set the file information here
            if ((!set_file_information(FileExtensions)) && (page != 1))
            {
                // If there was an error, just set to the first page
                page = 1;
                set_file_information(FileExtensions);
            }

            // Since this is a paging viewer, set the viewer code
            if ( String.IsNullOrEmpty(CurrentRequest.ViewerCode))
                CurrentRequest.ViewerCode = ViewerCode.Replace("#", page.ToString());
        }
        /// <summary> Constructor for a new instance of the Tracking_ItemViewer class, used display
        /// the full workflow history information for a digital resource </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        public Tracking_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest, Custom_Tracer Tracer )
        {
            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;

            // Get the tracking information
            Tracer.Add_Trace("Tracking_ItemViewer.Constructor", "Try to pull the tracking details for this item");
            trackingDetails = SobekEngineClient.Items.Get_Item_Tracking_Work_History(BriefItem.BibID, BriefItem.VID, Tracer);
            if (trackingDetails == null)
            {
                Tracer.Add_Trace("Tracking_ItemViewer.Constructor", "Unable to pull tracking details");
                CurrentRequest.Mode = Display_Mode_Enum.Error;
                CurrentRequest.Error_Message = "Internal Error : Unable to pull tracking information for " + BriefItem.BibID + ":" + BriefItem.VID;
            }
        }
        /// <summary> Returns the HTML for one element within tab which appears over the search box in the collection view </summary>
        /// <param name="ThisView"> Collection view type for this tab </param>
        /// <param name="Current_Mode"> Mode / navigation information for the current request, to see if the tab is currently selected or not and determine current skin language </param>
        /// <param name="Translations"> Language support object for writing the name of the view in the appropriate interface language </param>
        /// <returns> HTML to display the tab, including the link if it is not currently selected </returns>
        public static string Menu_Get_Nav_Bar_HTML(Item_Aggregation_Views_Searches_Enum ThisView, Navigation_Object Current_Mode, Language_Support_Info Translations )
        {
            string skinCode = Current_Mode.Base_Skin_Or_Skin;

            switch (ThisView)
            {
                case Item_Aggregation_Views_Searches_Enum.Advanced_Search:
                case Item_Aggregation_Views_Searches_Enum.Advanced_Search_YearRange:
                case Item_Aggregation_Views_Searches_Enum.Advanced_Search_MimeType:
                    return Menu_HTML_Helper(skinCode, Search_Type_Enum.Advanced, Translations.Get_Translation("Advanced Search", Current_Mode.Language), Current_Mode);

                case Item_Aggregation_Views_Searches_Enum.Basic_Search:
                case Item_Aggregation_Views_Searches_Enum.Basic_Search_YearRange:
                case Item_Aggregation_Views_Searches_Enum.Basic_Search_MimeType:
                    return Menu_HTML_Helper(skinCode, Search_Type_Enum.Basic, Translations.Get_Translation("Basic Search", Current_Mode.Language), Current_Mode);

                case Item_Aggregation_Views_Searches_Enum.Map_Search:
                    return Menu_HTML_Helper(skinCode, Search_Type_Enum.Map, Translations.Get_Translation("Map Search", Current_Mode.Language), Current_Mode);

                case Item_Aggregation_Views_Searches_Enum.Map_Search_Beta:
                    return Menu_HTML_Helper(skinCode, Search_Type_Enum.Map_Beta, Translations.Get_Translation("Map Search", Current_Mode.Language), Current_Mode);

                case Item_Aggregation_Views_Searches_Enum.Newspaper_Search:
                    return Menu_HTML_Helper(skinCode, Search_Type_Enum.Newspaper, Translations.Get_Translation("Newspaper Search", Current_Mode.Language), Current_Mode);

                case Item_Aggregation_Views_Searches_Enum.Admin_View:
                    return String.Empty; // HTML_Helper(Skin_Code, SobekCM.Library.Navigation.Search_Type_Enum.Admin_View, Translations.Get_Translation("ADMIN", Current_Mode.Language), Current_Mode, Downward_Tabs);

                case Item_Aggregation_Views_Searches_Enum.DLOC_FullText_Search:
                    return Menu_HTML_Helper(skinCode, Search_Type_Enum.dLOC_Full_Text, Translations.Get_Translation("Text Search", Current_Mode.Language), Current_Mode);

                case Item_Aggregation_Views_Searches_Enum.FullText_Search:
                    return Menu_HTML_Helper(skinCode, Search_Type_Enum.Full_Text, Translations.Get_Translation("Text Search", Current_Mode.Language), Current_Mode);
            }

            return String.Empty;
        }
        /// <summary> Constructor for a new instance of the HTML_ItemViewer class, used to display a HTML file from a digital resource </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        public HTML_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest)
        {
            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;

            // Find the first HTML file loaded
            foreach (BriefItem_FileGrouping thisPage in BriefItem.Downloads)
            {
                // Look for a HTML file on each page
                foreach (BriefItem_File thisFile in thisPage.Files)
                {
                    if (thisFile.File_Extension.IndexOf(".HTM", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        htmlFile = thisFile.Name;
                        break;
                    }
                }
            }
        }
        /// <summary> Constructor for a new instance of the UF_Archives_ItemViewer class, used display
        /// the tracking milestones information for a digital resource </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        public UF_Archives_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest, Custom_Tracer Tracer)
        {
            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;

            // Get the archives information
            Tracer.Add_Trace("UF_Archives_ItemViewer.Constructor", "Try to pull the archives details for this item");
            DataSet data = Engine_Database.Tracking_Get_History_Archives(BriefItem.Web.ItemID, Tracer);
            if ((data == null) || ( data.Tables.Count < 3 ))
            {
                Tracer.Add_Trace("Constructor.Constructor", "Unable to pull tracking details");
                CurrentRequest.Mode = Display_Mode_Enum.Error;
                CurrentRequest.Error_Message = "Internal Error : Unable to pull tracking information for " + BriefItem.BibID + ":" + BriefItem.VID;
                return;
            }

            // Save this table
            archiveTable = data.Tables[2];
        }
 private static string HTML_Helper_PageView(string Viewer_Code, string Display_Text, Navigation_Object Current_Mode)
 {
     string previousViewerCode = Current_Mode.ViewerCode;
     Current_Mode.ViewerCode = Viewer_Code;
     string returnValue = "<a href=\"" + UrlWriterHelper.Redirect_URL(Current_Mode) + "\">" + Display_Text + "</a>";
     Current_Mode.ViewerCode = previousViewerCode;
     return returnValue;
 }
        /// <summary> Get the navigation bar html for a view, given information about the current request </summary>
        /// <param name="Item_View"> View for which to generate the html </param>
        /// <param name="Resource_Type"> Current resource type, which determines the text in several viewer's tabs</param>
        /// <param name="Skin_Code"> Code for the current web sking, which determines which tab images to use </param>
        /// <param name="Current_Mode"> Mode / navigation information for the current request</param>
        /// <param name="Page_Sequence"> Current page sequence </param>
        /// <param name="Translator"> Language support object provides support for translating common user interface elements, like the names of these tabs </param>
        /// <param name="Show_Zoomable"> Flag indicates if the zoomable server is online and should be displayable </param>
        /// <param name="Current_Item"> Current digital resource, with the viewers that should be displayed </param>
        /// <returns> Collection of the html for the navigation bar (one view could have multiple tabs)</returns>
        public static List<string> Get_Nav_Bar_HTML(View_Object Item_View, string Resource_Type, 
            string Skin_Code, Navigation_Object Current_Mode, int Page_Sequence,
            Language_Support_Info Translator, bool Show_Zoomable, SobekCM_Item Current_Item )
        {
            List<string> returnVal = new List<string>();

            switch (Item_View.View_Type)
            {
                case View_Enum.ALL_VOLUMES:
                    string allVolumeCode = "allvolumes";
                    string resource_type_upper = Resource_Type.ToUpper();
                    if (Current_Mode.ViewerCode.IndexOf("allvolumes") == 0)
                        allVolumeCode = Current_Mode.ViewerCode;
                    if (resource_type_upper.IndexOf("NEWSPAPER") >= 0)
                    {
                        returnVal.Add(HTML_Helper(allVolumeCode, Translator.Get_Translation("All Issues", Current_Mode.Language), Current_Mode));
                    }
                    else
                    {
                        if (resource_type_upper.IndexOf("MAP") >= 0)
                        {
                            returnVal.Add(HTML_Helper(allVolumeCode, Translator.Get_Translation("Related Maps", Current_Mode.Language), Current_Mode));
                        }
                        else
                        {
                            returnVal.Add(resource_type_upper.IndexOf("AERIAL") >= 0
                                              ? HTML_Helper(allVolumeCode, Translator.Get_Translation("Related Flights", Current_Mode.Language), Current_Mode)
                                              : HTML_Helper(allVolumeCode, Translator.Get_Translation("All Volumes", Current_Mode.Language), Current_Mode));
                        }
                    }
                    break;

                case View_Enum.CITATION:
                    if ((Current_Mode.ViewerCode == "citation") || ( Current_Mode.ViewerCode == "marc" ) || ( Current_Mode.ViewerCode == "metadata" ) || ( Current_Mode.ViewerCode == "usage" ))
                    {
                        returnVal.Add(HTML_Helper(Current_Mode.ViewerCode, Translator.Get_Translation("Citation", Current_Mode.Language), Current_Mode));
                    }
                    else
                    {
                        returnVal.Add(HTML_Helper("citation", Translator.Get_Translation("Citation", Current_Mode.Language), Current_Mode));
                    }
                    break;

                case View_Enum.DATASET_CODEBOOK:
                    returnVal.Add(HTML_Helper("dscodebook", Translator.Get_Translation("Data Structure", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.DATASET_REPORTS:
                    returnVal.Add(HTML_Helper("dsreports", Translator.Get_Translation("Reports", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.DATASET_VIEWDATA:
                    returnVal.Add(HTML_Helper("dsview", Translator.Get_Translation("Explore Data", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.DOWNLOADS:
                    returnVal.Add(HTML_Helper("downloads", Translator.Get_Translation("Downloads", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.FEATURES:
                    returnVal.Add(HTML_Helper("features", Translator.Get_Translation("Features", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.FLASH:
                    returnVal.Add( String.IsNullOrEmpty(Item_View.Label)
                                      ? HTML_Helper("flash", Translator.Get_Translation("Flash View", Current_Mode.Language), Current_Mode)
                                      : HTML_Helper("flash", Translator.Get_Translation(Item_View.Label.ToUpper(), Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.GOOGLE_MAP:
                    if ( !String.IsNullOrEmpty(Current_Mode.Coordinates))
                    {
                        if (Current_Mode.ViewerCode == "mapsearch")
                        {
                            returnVal.Add( HTML_Helper("mapsearch", Translator.Get_Translation("Map Search", Current_Mode.Language), Current_Mode));
                        }
                        else
                        {
                            if (( Current_Item.Web.Static_PageCount > 1 ) || ( Current_Item.Bib_Info.SobekCM_Type != TypeOfResource_SobekCM_Enum.Map ))
                            {
                                returnVal.Add(HTML_Helper("map", Translator.Get_Translation("Search Results", Current_Mode.Language), Current_Mode));
                            }
                            else
                            {
                                returnVal.Add(HTML_Helper("map", Translator.Get_Translation("Map Coverage", Current_Mode.Language), Current_Mode));
                            }

                        }
                    }
                    else
                    {
                        returnVal.Add(HTML_Helper("map", Translator.Get_Translation("Map It!", Current_Mode.Language), Current_Mode));
                    }
                    break;

                case View_Enum.GOOGLE_MAP_BETA:
                    if (!String.IsNullOrEmpty(Current_Mode.Coordinates))
                    {
                        if (Current_Mode.ViewerCode == "mapsearchbeta")
                        {
                            returnVal.Add(HTML_Helper("mapsearchbeta", Translator.Get_Translation("Map Search", Current_Mode.Language), Current_Mode));
                        }
                        else
                        {
                            if ((Current_Item.Web.Static_PageCount > 1) || (Current_Item.Bib_Info.SobekCM_Type != TypeOfResource_SobekCM_Enum.Map_Beta))
                            {
                                returnVal.Add(HTML_Helper("mapbeta", Translator.Get_Translation("Search Results", Current_Mode.Language), Current_Mode));
                            }
                            else
                            {
                                returnVal.Add(HTML_Helper("mapbeta", Translator.Get_Translation("Map Coverage", Current_Mode.Language), Current_Mode));
                            }

                        }
                    }
                    else
                    {
                        returnVal.Add(HTML_Helper("map", Translator.Get_Translation("Map It!", Current_Mode.Language), Current_Mode));
                    }
                    break;

                case View_Enum.HTML:
                    returnVal.Add(!String.IsNullOrEmpty(Item_View.Label)
                                      ? HTML_Helper("html", Item_View.Label.ToUpper(), Current_Mode)
                                      : HTML_Helper("html", "HTML LINK", Current_Mode));
                    break;

                case View_Enum.JPEG:
                    returnVal.Add(HTML_Helper_PageView(Page_Sequence.ToString() + "j", Translator.Get_Translation("Standard", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.JPEG_TEXT_TWO_UP:
                    returnVal.Add(HTML_Helper_PageView(Page_Sequence.ToString() + "u", Translator.Get_Translation("Page Image with Text", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.JPEG2000:
                    if (Show_Zoomable)
                    {
                        returnVal.Add(HTML_Helper_PageView(Page_Sequence.ToString() + "x", Translator.Get_Translation("Zoomable", Current_Mode.Language), Current_Mode));
                    }
                    break;

                case View_Enum.PDF:
                    returnVal.Add(HTML_Helper("pdf", Translator.Get_Translation("PDF Viewer", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.RELATED_IMAGES:
                    returnVal.Add(Current_Mode.ViewerCode.IndexOf("thumbs") >= 0
                                      ? HTML_Helper(Current_Mode.ViewerCode, Translator.Get_Translation("Thumbnails", Current_Mode.Language), Current_Mode)
                                      : HTML_Helper("thumbs", Translator.Get_Translation("Thumbnails", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.SEARCH:
                    returnVal.Add(HTML_Helper("search", Translator.Get_Translation("Search", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.SIMPLE_HTML_LINK:
                    returnVal.Add("<li> <a href=\"" + Item_View.Attributes + "\" target=\"_blank\" alt=\"Link to '" + Item_View.Label + "'\"> " + Translator.Get_Translation(Item_View.Label.ToUpper(), Current_Mode.Language) + " </a></li>");
                    break;

                case View_Enum.STREETS:
                    returnVal.Add(HTML_Helper("streets", Translator.Get_Translation("Streets", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.TEXT:
                    returnVal.Add(HTML_Helper_PageView(Page_Sequence.ToString() + "t", Translator.Get_Translation("Page Text", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.TOC:
                     // returnVal.Add(base.HTML_Helper(Skin_Code, "TC", "Table of Contents", Current_Mode));
                    break;

                case View_Enum.RESTRICTED:
                    returnVal.Add(HTML_Helper("restricted", Translator.Get_Translation("Restricted", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.EAD_CONTAINER_LIST:
                    returnVal.Add(HTML_Helper("container", Translator.Get_Translation("Container List", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.EAD_DESCRIPTION:
                    // Return nothing, this is currently written when writing the CITATION, for
                    // all EAD type items.
                    //returnVal.Add(HTML_Helper(Skin_Code, "description", Translator.Get_Translation("DESCRIPTION", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.PAGE_TURNER:
                    returnVal.Add(HTML_Helper("pageturner#page/1/mode/2up", Translator.Get_Translation("Page Turner", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.YOUTUBE_VIDEO:
                    returnVal.Add(HTML_Helper("youtube", Translator.Get_Translation("Video", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.EMBEDDED_VIDEO:
                    returnVal.Add(HTML_Helper("videoem", Translator.Get_Translation("Video", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.VIDEO:
                    returnVal.Add(HTML_Helper("video", Translator.Get_Translation("Video", Current_Mode.Language), Current_Mode));
                    break;

                case View_Enum.TRACKING:
                    // DO nothing in this case.. do not write any tab
                    break;

                case View_Enum.TRACKING_SHEET:
                    //DO nothing in this case.. do not write any tab
                    break;

                case View_Enum.QUALITY_CONTROL:
                    // DO nothing in this case.. do not write any tab
                    break;
            }

            return returnVal;
        }
        /// <summary> Parse the query and set the internal variables </summary>
        /// <param name="QueryString"> QueryString collection passed from the main page </param>
        /// <param name="Navigator"> Navigation object to hold the mode information </param>
        /// <param name="Base_URL">Requested base URL (without query string, etc..)</param>
        /// <param name="User_Languages"> Languages preferred by user, per their browser settings </param>
        /// <param name="Code_Manager"> List of valid collection codes, including mapping from the Sobek collections to Greenstone collections </param>
        /// <param name="Aggregation_Aliases"> List of all existing aliases for existing aggregationPermissions</param>
        /// <param name="All_Items_Lookup"> [REF] Lookup object used to pull basic information about any item loaded into this library</param>
        /// <param name="URL_Portals"> List of all web portals into this system </param>
        /// <param name="WebHierarchy"> Hierarchy of all non-aggregational web content pages and redirects </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param>
        public static void Parse_Query(NameValueCollection QueryString,
			Navigation_Object Navigator,
			string Base_URL,
			string[] User_Languages,
			Aggregation_Code_Manager Code_Manager,
			Dictionary<string, string> Aggregation_Aliases,
			Item_Lookup_Object All_Items_Lookup,
			Portal_List URL_Portals,
            WebContent_Hierarchy WebHierarchy,
			Custom_Tracer Tracer )
        {
            if (Tracer != null)
                Tracer.Add_Trace("QueryString_Analyzer.Parse_Query", "Parse the query into the provided Navigation_Object");

            // Set default mode to error
            Navigator.Mode = Display_Mode_Enum.Error;

            // If this has 'verb' then this is an OAI-PMH request
            if ( QueryString["verb"] != null )
            {
                Navigator.Writer_Type = Writer_Type_Enum.OAI;
                return;
            }

            // Is there a TOC state set?
            if (QueryString["toc"] != null)
            {
                if (QueryString["toc"] == "y")
                {
                    Navigator.TOC_Display = TOC_Display_Type_Enum.Show;
                }
                else if ( QueryString["toc"] == "n" )
                {
                    Navigator.TOC_Display = TOC_Display_Type_Enum.Hide;
                }
            }

            // Determine the default language, per the browser settings
            if (User_Languages != null)
            {
                foreach (string thisLanguage in User_Languages)
                {
                    if (thisLanguage.IndexOf("en") == 0)
                    {
                        Navigator.Default_Language = Web_Language_Enum.English;
                        break;
                    }

                    if (thisLanguage.IndexOf("fr") == 0)
                    {
                        Navigator.Default_Language = Web_Language_Enum.French;
                        break;
                    }

                    if (thisLanguage.IndexOf("es") == 0)
                    {
                        Navigator.Default_Language = Web_Language_Enum.Spanish;
                        break;
                    }
                }
            }

            // Is there a language defined?  If so, load right into the navigator
            Navigator.Language = Navigator.Default_Language;
            if ( !String.IsNullOrEmpty(QueryString["l"]))
            {
                Navigator.Language = Web_Language_Enum_Converter.Code_To_Enum(QueryString["l"]);
            }

            // If there is flag indicating to show the trace route, save it
            if (QueryString["trace"] != null)
            {
                Navigator.Trace_Flag = QueryString["trace"].ToUpper() == "NO" ? Trace_Flag_Type_Enum.No : Trace_Flag_Type_Enum.Explicit;
            }
            else
            {
                Navigator.Trace_Flag = Trace_Flag_Type_Enum.Unspecified;
            }

            // Did the user request to have it render like it would for a search robot?
            if (QueryString["robot"] != null)
            {
                Navigator.Is_Robot = true;
            }

            // Was a fragment specified in the query string?
            if (QueryString["fragment"] != null)
            {
                Navigator.Fragment = QueryString["fragment"];
            }

            // Get the valid URL Portal
            Navigator.Default_Aggregation = "all";
            Portal urlPortal = URL_Portals.Get_Valid_Portal(Base_URL);
            Navigator.Instance_Abbreviation = urlPortal.Abbreviation;
            Navigator.Instance_Name = urlPortal.Name;
            if ( !String.IsNullOrEmpty(urlPortal.Base_PURL ))
                Navigator.Portal_PURL = urlPortal.Base_PURL;
            if (String.IsNullOrEmpty(urlPortal.Default_Aggregation))
            {
                Navigator.Aggregation = "";
            }
            else
            {
                Navigator.Default_Aggregation = urlPortal.Default_Aggregation;
                Navigator.Aggregation = urlPortal.Default_Aggregation;
            }
            if (!String.IsNullOrEmpty(urlPortal.Default_Web_Skin))
            {
                Navigator.Default_Skin = urlPortal.Default_Web_Skin;
                Navigator.Skin = urlPortal.Default_Web_Skin;
                Navigator.Skin_In_URL = false;
            }

            // Collect the interface string
            if (QueryString["n"] != null)
            {
                string currSkin = QueryString["n"].ToLower().Replace("'", "");

                // Save the interface
                if (currSkin.Length > 0)
                {
                    if (currSkin.IndexOf(",") > 0)
                        currSkin = currSkin.Substring(0, currSkin.IndexOf(","));
                    Navigator.Skin = currSkin.ToLower();
                    Navigator.Skin_In_URL = true;
                }
            }

            // Parse URL request different now, depending on if this is a legacy URL type or the new URL type
            Navigator.Mode = Display_Mode_Enum.None;

            // CHECK FOR LEGACY VALUES
            // Check for legacy bibid / vid information, since this will be supported indefinitely
            if (( QueryString["b"] != null ) || ( QueryString["bib"] != null ))
            {
                Navigator.BibID = QueryString["b"] ?? QueryString["bib"];

                if ( Navigator.BibID.Length > 0 )
                {
                    Navigator.Mode = Display_Mode_Enum.Item_Display;

                    if ( QueryString["v"] != null )
                        Navigator.VID = QueryString["v"];
                    else if ( QueryString["vid"] != null )
                        Navigator.VID = QueryString["vid"];
                }

                // No other item information is collected here anymore.. just return
                return;
            }

            // Set the default mode
            Navigator.Mode = Display_Mode_Enum.Aggregation;
            Navigator.Aggregation_Type = Aggregation_Type_Enum.Home;
            Navigator.Home_Type = Home_Type_Enum.List;

            // Get any url rewrite which occurred
            if (QueryString["urlrelative"] != null)
            {
                string urlrewrite = QueryString["urlrelative"].ToLower();
                if (urlrewrite.Length > 0)
                {
                    // Split the url relative list
                    string[] url_relative_info = urlrewrite.Split("/".ToCharArray());
                    List<string> url_relative_list = (from thisPart in url_relative_info where thisPart.Length > 0 select thisPart.ToLower()).ToList();

                    // Determine the main writer (html, json, xml, oai-pmh, etc..)
                    Navigator.Writer_Type = Writer_Type_Enum.HTML;
                    if ( url_relative_list.Count > 0 )
                    {
                        switch (url_relative_list[0])
                        {
                            case "l":
                                Navigator.Writer_Type = Writer_Type_Enum.HTML_LoggedIn;
                                url_relative_list.RemoveAt(0);
                                break;

                            case "my":
                                Navigator.Writer_Type = Writer_Type_Enum.HTML_LoggedIn;
                                break;

                            case "json":
                                Navigator.Writer_Type = Writer_Type_Enum.JSON;
                                url_relative_list.RemoveAt(0);
                                break;

                            case "dataset":
                                Navigator.Writer_Type = Writer_Type_Enum.DataSet;
                                url_relative_list.RemoveAt(0);
                                break;

                            case "dataprovider":
                                Navigator.Writer_Type = Writer_Type_Enum.Data_Provider;
                                url_relative_list.RemoveAt(0);
                                break;

                            case "xml":
                                Navigator.Writer_Type = Writer_Type_Enum.XML;
                                url_relative_list.RemoveAt(0);
                                break;

                            case "textonly":
                                Navigator.Writer_Type = Writer_Type_Enum.Text;
                                url_relative_list.RemoveAt(0);
                                break;
                        }
                    }

                    // Is the first part of the list one of these constants?
                    if (( url_relative_list.Count > 0 ) && ( url_relative_list[0].Length > 0 ))
                    {
                        switch ( url_relative_list[0] )
                        {
                            case "shibboleth":
                                Navigator.Mode = Display_Mode_Enum.My_Sobek;
                                Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Shibboleth_Landing;
                                break;

                            case "internal":
                                Navigator.Mode = Display_Mode_Enum.Internal;
                                Navigator.Internal_Type = Internal_Type_Enum.Aggregations_List;
                                if ( url_relative_list.Count > 1 )
                                {
                                    switch( url_relative_list[1] )
                                    {
                                        case "aggregations":
                                            Navigator.Internal_Type = Internal_Type_Enum.Aggregations_List;
                                            if (url_relative_list.Count > 2)
                                            {
                                                if (url_relative_list[2] == "tree")
                                                {
                                                    Navigator.Internal_Type = Internal_Type_Enum.Aggregations_Tree;
                                                }
                                            }
                                            break;

                                        case "cache":
                                            Navigator.Internal_Type = Internal_Type_Enum.Cache;
                                            break;

                                        case "new":
                                            Navigator.Internal_Type = Internal_Type_Enum.New_Items;
                                            if (url_relative_list.Count > 2)
                                            {
                                                Navigator.Info_Browse_Mode = url_relative_list[2];
                                            }
                                            break;

                                        case "failures":
                                            Navigator.Internal_Type = Internal_Type_Enum.Build_Failures;
                                            if (url_relative_list.Count > 2)
                                                Navigator.Info_Browse_Mode = url_relative_list[2];
                                            break;

                                        case "wordmarks":
                                            Navigator.Internal_Type = Internal_Type_Enum.Wordmarks;
                                            break;
                                    }
                                }
                                break;

                            case "contact":
                                Navigator.Mode = Display_Mode_Enum.Contact;
                                if ( url_relative_list.Count > 1 )
                                {
                                    if (url_relative_list[1] == "sent")
                                    {
                                        Navigator.Mode = Display_Mode_Enum.Contact_Sent;
                                    }
                                    else
                                    {
                                        Navigator.Aggregation = url_relative_list[1];
                                    }
                                }
                                if (QueryString["em"] != null)
                                    Navigator.Error_Message = QueryString["em"];
                                break;

                            case "folder":
                                Navigator.Mode = Display_Mode_Enum.Public_Folder;
                                if (url_relative_list.Count >= 2)
                                {
                                    try
                                    {
                                        Navigator.FolderID = Convert.ToInt32(url_relative_list[1]);
                                    }
                                    catch
                                    {
                                        Navigator.FolderID = -1;
                                    }

                                    // Look for result display type
                                    if (url_relative_list.Count >=3 )
                                    {
                                        switch (url_relative_list[2])
                                        {
                                            case "brief":
                                                Navigator.Result_Display_Type = Result_Display_Type_Enum.Brief;
                                                break;
                                            case "export":
                                                Navigator.Result_Display_Type = Result_Display_Type_Enum.Export;
                                                break;
                                            case "citation":
                                                Navigator.Result_Display_Type = Result_Display_Type_Enum.Full_Citation;
                                                break;
                                            case "image":
                                                Navigator.Result_Display_Type = Result_Display_Type_Enum.Full_Image;
                                                break;
                                            case "map":
                                                Navigator.Result_Display_Type = Result_Display_Type_Enum.Map;
                                                break;
                                            case "mapbeta":
                                                Navigator.Result_Display_Type = Result_Display_Type_Enum.Map_Beta;
                                                break;
                                            case "table":
                                                Navigator.Result_Display_Type = Result_Display_Type_Enum.Table;
                                                break;
                                            case "thumbs":
                                                Navigator.Result_Display_Type = Result_Display_Type_Enum.Thumbnails;
                                                break;
                                            default:
                                                Navigator.Result_Display_Type = Result_Display_Type_Enum.Brief;
                                                break;
                                        }
                                    }

                                    // Look for a page number
                                    if (url_relative_list.Count >= 4 )
                                    {
                                        string possible_page = url_relative_list[3];
                                        if ((possible_page.Length > 0) && (is_String_Number(possible_page)))
                                        {
                                            ushort page_result;
                                            UInt16.TryParse(possible_page, out page_result);
                                            Navigator.Page = page_result;
                                        }
                                    }
                                }
                                break;

                            case "register":
                                Navigator.Mode = Display_Mode_Enum.My_Sobek;
                                Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Preferences;
                                break;

                            case "my":
                                Navigator.Mode = Display_Mode_Enum.My_Sobek;
                                Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                                if (QueryString["return"] != null)
                                    Navigator.Return_URL = QueryString["return"];
                                if ( url_relative_list.Count > 1 )
                                {
                                    switch( url_relative_list[1] )
                                    {
                                        case "logon":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Logon;
                                            if (QueryString["return"] != null)
                                                Navigator.Return_URL = QueryString["return"];
                                            break;

                                        case "home":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                                            if (QueryString["return"] != null)
                                                Navigator.Return_URL = QueryString["return"];
                                            break;

                                        case "delete":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Delete_Item;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.VID = url_relative_list[3];
                                            break;

                                        case "submit":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.New_Item;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "itempermissions":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Edit_Item_Permissions;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.VID = url_relative_list[3];
                                            if (url_relative_list.Count > 4)
                                                Navigator.My_Sobek_SubMode = url_relative_list[4];
                                            break;

                                        case "behaviors":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Edit_Item_Behaviors;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.VID = url_relative_list[3];
                                            if (url_relative_list.Count > 4)
                                                Navigator.My_Sobek_SubMode = url_relative_list[4];
                                            break;

                                        case "edit":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Edit_Item_Metadata;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.VID = url_relative_list[3];
                                            if (url_relative_list.Count > 4)
                                                Navigator.My_Sobek_SubMode = url_relative_list[4];
                                            break;

                                        case "files":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.File_Management;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.VID = url_relative_list[3];
                                            if (url_relative_list.Count > 4)
                                                Navigator.My_Sobek_SubMode = url_relative_list[4];
                                            break;

                                        case "images":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Page_Images_Management;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.VID = url_relative_list[3];
                                            if (url_relative_list.Count > 4)
                                                Navigator.My_Sobek_SubMode = url_relative_list[4];
                                            break;

                                        case "addvolume":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Group_Add_Volume;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.My_Sobek_SubMode = url_relative_list[3];
                                            break;

                                        case "autofill":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Group_AutoFill_Volumes;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.My_Sobek_SubMode = url_relative_list[3];
                                            break;

                                        case "massupdate":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Group_Mass_Update_Items;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.My_Sobek_SubMode = url_relative_list[3];
                                            break;

                                        case "groupbehaviors":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Edit_Group_Behaviors;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.My_Sobek_SubMode = url_relative_list[3];
                                            break;

                                        case "serialhierarchy":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Edit_Group_Serial_Hierarchy;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.My_Sobek_SubMode = url_relative_list[3];
                                            break;

                                        case "bookshelf":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Folder_Management;
                                            Navigator.Result_Display_Type = Result_Display_Type_Enum.Bookshelf;
                                            if (url_relative_list.Count > 2)
                                            {
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                                if (url_relative_list.Count > 3)
                                                {
                                                    switch (Navigator.My_Sobek_SubMode)
                                                    {
                                                        case "brief":
                                                            Navigator.Result_Display_Type = Result_Display_Type_Enum.Brief;
                                                            Navigator.My_Sobek_SubMode = url_relative_list[3];
                                                            break;

                                                        case "export":
                                                            Navigator.Result_Display_Type = Result_Display_Type_Enum.Export;
                                                            Navigator.My_Sobek_SubMode = url_relative_list[3];
                                                            break;

                                                        case "thumbs":
                                                            Navigator.Result_Display_Type = Result_Display_Type_Enum.Thumbnails;
                                                            Navigator.My_Sobek_SubMode = url_relative_list[3];
                                                            break;

                                                        case "table":
                                                            Navigator.Result_Display_Type = Result_Display_Type_Enum.Table;
                                                            Navigator.My_Sobek_SubMode = url_relative_list[3];
                                                            break;

                                                        case "citation":
                                                            Navigator.Result_Display_Type = Result_Display_Type_Enum.Full_Citation;
                                                            Navigator.My_Sobek_SubMode = url_relative_list[3];
                                                            break;

                                                        case "image":
                                                            Navigator.Result_Display_Type = Result_Display_Type_Enum.Full_Image;
                                                            Navigator.My_Sobek_SubMode = url_relative_list[3];
                                                            break;

                                                        default:
                                                            if (is_String_Number(url_relative_list[3]))
                                                            {
                                                                ushort page_result;
                                                                UInt16.TryParse(url_relative_list[3], out page_result);
                                                                Navigator.Page = page_result;
                                                            }
                                                            break;
                                                    }
                                                }
                                                if ((url_relative_list.Count > 4) && ( is_String_Number( url_relative_list[4] )))
                                                {
                                                    ushort page_result;
                                                    UInt16.TryParse(url_relative_list[4], out page_result);
                                                    Navigator.Page = page_result;
                                                }
                                            }
                                            break;

                                        case "preferences":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Preferences;
                                            break;

                                        case "logout":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Log_Out;
                                            if (QueryString["return"] != null)
                                                Navigator.Return_URL = QueryString["return"];
                                            break;

                                        case "shibboleth":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Shibboleth_Landing;
                                            if (QueryString["return"] != null)
                                                Navigator.Return_URL = QueryString["return"];
                                            break;

                                        case "itemtracking":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Item_Tracking;
                                            //if(url_relative_list.Count>3 && is_String_Number(url_relative_list[3]))
                                            //    Navigator.My_Sobek_SubMode = url_relative_list[3];
                                            break;

                                        case "searches":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Saved_Searches;
                                            break;

                                        case "tags":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.User_Tags;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "stats":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.User_Usage_Stats;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;
                                    }
                                }
                                break;

                            case "admin":
                                Navigator.Mode = Display_Mode_Enum.Administrative;
                                Navigator.Admin_Type = Admin_Type_Enum.Home;
                                if (QueryString["return"] != null)
                                    Navigator.Return_URL = QueryString["return"];
                                if (url_relative_list.Count > 1)
                                {
                                    switch (url_relative_list[1])
                                    {
                                        case "builder":
                                            Navigator.Admin_Type = Admin_Type_Enum.Builder_Status;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;
                                            break;

                                        case "addcoll":
                                            Navigator.Admin_Type = Admin_Type_Enum.Add_Collection_Wizard;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "aggregations":
                                            Navigator.Admin_Type = Admin_Type_Enum.Aggregations_Mgmt;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "editaggr":
                                            Navigator.Admin_Type = Admin_Type_Enum.Aggregation_Single;
                                            if (url_relative_list.Count > 2)
                                                Navigator.Aggregation = url_relative_list[2];
                                            if (url_relative_list.Count > 3)
                                                Navigator.My_Sobek_SubMode = url_relative_list[3];
                                            break;

                                        case "aliases":
                                            Navigator.Admin_Type = Admin_Type_Enum.Aliases;
                                            break;

                                        case "webskins":
                                            Navigator.Admin_Type = Admin_Type_Enum.Skins_Mgmt;
                                            break;

                                        case "editskin":
                                            Navigator.Admin_Type = Admin_Type_Enum.Skins_Single;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            if (url_relative_list.Count > 3)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2] + "/" + url_relative_list[3];
                                            break;

                                        case "defaults":
                                            Navigator.Admin_Type = Admin_Type_Enum.Default_Metadata;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "restrictions":
                                            Navigator.Admin_Type = Admin_Type_Enum.IP_Restrictions;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "portals":
                                            Navigator.Admin_Type = Admin_Type_Enum.URL_Portals;
                                            break;

                                        case "users":
                                            Navigator.Admin_Type = Admin_Type_Enum.Users;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "groups":
                                            Navigator.Admin_Type = Admin_Type_Enum.User_Groups;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "permissions":
                                            Navigator.Admin_Type = Admin_Type_Enum.User_Permissions_Reports;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "webadd":
                                            Navigator.Admin_Type = Admin_Type_Enum.WebContent_Add_New;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "webcontent":
                                            Navigator.Admin_Type = Admin_Type_Enum.WebContent_Mgmt;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "webhistory":
                                            Navigator.Admin_Type = Admin_Type_Enum.WebContent_History;
                                            break;

                                        case "websingle":
                                            Navigator.Admin_Type = Admin_Type_Enum.WebContent_Single;
                                            if (url_relative_list.Count > 2)
                                            {
                                                int possiblewebid;
                                                if (Int32.TryParse(url_relative_list[2], out possiblewebid))
                                                {
                                                    Navigator.WebContentID = possiblewebid;
                                                }
                                                if (url_relative_list.Count > 3)
                                                {
                                                    Navigator.My_Sobek_SubMode = url_relative_list[3];
                                                }
                                            }
                                            if ( Navigator.WebContentID < 1 )
                                                Navigator.Admin_Type = Admin_Type_Enum.WebContent_Mgmt;
                                            break;

                                        case "webusage":
                                            Navigator.Admin_Type = Admin_Type_Enum.WebContent_Usage;
                                            break;

                                        case "wordmarks":
                                            Navigator.Admin_Type = Admin_Type_Enum.Wordmarks;
                                            break;

                                        case "reset":
                                            Navigator.Admin_Type = Admin_Type_Enum.Reset;
                                            break;

                                        case "headings":
                                            Navigator.Admin_Type = Admin_Type_Enum.Thematic_Headings;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "settings":
                                            Navigator.Admin_Type = Admin_Type_Enum.Settings;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;
                                    }
                                }
                                break;

                            case "preferences":
                                Navigator.Mode = Display_Mode_Enum.Preferences;
                                break;

                            case "reports":
                                Navigator.Mode = Display_Mode_Enum.Reports;
                                if (url_relative_list.Count > 1)
                                {
                                    Navigator.Report_Name = url_relative_list[1];
                                }
                                break;

                            case "stats":
                            case "statistics":
                                Navigator.Mode = Display_Mode_Enum.Statistics;
                                Navigator.Statistics_Type = Statistics_Type_Enum.Item_Count_Standard_View;
                                if ( url_relative_list.Count > 1 )
                                {
                                    switch( url_relative_list[1] )
                                    {
                                        case "itemcount":
                                            Navigator.Statistics_Type = Statistics_Type_Enum.Item_Count_Standard_View;
                                            if ( url_relative_list.Count > 2 )
                                            {
                                                switch( url_relative_list[2])
                                                {
                                                    case "arbitrary":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Item_Count_Arbitrary_View;
                                                        if (url_relative_list.Count > 3)
                                                        {
                                                            Navigator.Info_Browse_Mode = url_relative_list[3];
                                                        }
                                                        break;

                                                    case "growth":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Item_Count_Growth_View;
                                                        break;

                                                    case "text":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Item_Count_Text;
                                                        break;

                                                    case "standard":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Item_Count_Standard_View;
                                                        break;
                                                }
                                            }
                                            break;

                                        case "searches":
                                            Navigator.Statistics_Type = Statistics_Type_Enum.Recent_Searches;
                                            break;

                                        case "usage":
                                            Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Overall;
                                            if ( url_relative_list.Count > 2 )
                                            {
                                                switch( url_relative_list[2])
                                                {
                                                    case "all":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Overall;
                                                        break;

                                                    case "history":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Collection_History;
                                                        if ( url_relative_list.Count > 3 )
                                                        {
                                                            switch( url_relative_list[3] )
                                                            {
                                                                case "text":
                                                                    Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Collection_History_Text;
                                                                    break;

                                                                default:
                                                                    Navigator.Info_Browse_Mode = url_relative_list[3];
                                                                    break;
                                                            }

                                                            if ((String.IsNullOrEmpty(Navigator.Info_Browse_Mode)) && (url_relative_list.Count > 4))
                                                                Navigator.Info_Browse_Mode = url_relative_list[4];
                                                        }
                                                        break;

                                                    case "collections":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Collections_By_Date;
                                                        if (url_relative_list.Count > 3)
                                                            Navigator.Info_Browse_Mode = url_relative_list[3];
                                                        break;

                                                    case "definitions":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Definitions;
                                                        break;

                                                    case "titles":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Titles_By_Collection;
                                                        if (( String.IsNullOrEmpty( Navigator.Info_Browse_Mode )) && ( url_relative_list.Count > 4 ))
                                                            Navigator.Info_Browse_Mode = url_relative_list[4];
                                                        break;

                                                    case "items":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Item_Views_By_Date;
                                                        if ( url_relative_list.Count > 3 )
                                                        {
                                                            switch( url_relative_list[3] )
                                                            {
                                                                case "date":
                                                                    Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Item_Views_By_Date;
                                                                    break;

                                                                case "top":
                                                                    Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Items_By_Collection;
                                                                    break;

                                                                case "text":
                                                                    Navigator.Statistics_Type = Statistics_Type_Enum.Usage_By_Date_Text;
                                                                    break;

                                                                default:
                                                                    Navigator.Info_Browse_Mode = url_relative_list[3];
                                                                    break;
                                                            }

                                                            if (( String.IsNullOrEmpty( Navigator.Info_Browse_Mode )) && ( url_relative_list.Count > 4 ))
                                                                Navigator.Info_Browse_Mode = url_relative_list[4];
                                                        }
                                                        break;

                                                }
                                            }
                                            break;
                                    }
                                }
                                break;

                            case "partners":
                                if (( String.IsNullOrEmpty(Navigator.Default_Aggregation)) || ( Navigator.Default_Aggregation == "all"))
                                {
                                    Navigator.Mode = Display_Mode_Enum.Aggregation;
                                    Navigator.Aggregation_Type = Aggregation_Type_Enum.Home;
                                    Navigator.Aggregation = String.Empty;
                                    Navigator.Home_Type = Home_Type_Enum.Partners_List;
                                    if ((url_relative_list.Count > 1) && (url_relative_list[1] == "thumbs"))
                                    {
                                        Navigator.Home_Type = Home_Type_Enum.Partners_Thumbnails;
                                    }
                                }
                                else
                                {
                                    aggregation_querystring_analyze(Navigator, QueryString, Navigator.Default_Aggregation, url_relative_list);
                                }
                                break;

                            case "tree":
                                Navigator.Mode = Display_Mode_Enum.Aggregation;
                                Navigator.Aggregation_Type = Aggregation_Type_Enum.Home;
                                Navigator.Aggregation = String.Empty;
                                Navigator.Home_Type = Home_Type_Enum.Tree;
                                break;

                            case "brief":
                                Navigator.Mode = Display_Mode_Enum.Aggregation;
                                Navigator.Aggregation_Type = Aggregation_Type_Enum.Home;
                                Navigator.Aggregation = String.Empty;
                                Navigator.Home_Type = Home_Type_Enum.Descriptions;
                                break;

                            case "personalized":
                                Navigator.Mode = Display_Mode_Enum.Aggregation;
                                Navigator.Aggregation_Type = Aggregation_Type_Enum.Home;
                                Navigator.Aggregation = String.Empty;
                                Navigator.Home_Type = Home_Type_Enum.Personalized;
                                break;

                            case "inprocess":
                                Navigator.Aggregation = String.Empty;
                                Navigator.Mode = Display_Mode_Enum.Aggregation;
                                Navigator.Aggregation_Type = Aggregation_Type_Enum.Home;
                                Navigator.Aggregation_Type = Aggregation_Type_Enum.Private_Items;
                                Navigator.Page = 1;
                                if (url_relative_list.Count > 1)
                                {
                                    if (is_String_Number(url_relative_list[1]))
                                        Navigator.Page = Convert.ToUInt16(url_relative_list[1]);
                                }
                                if ((QueryString["o"] != null) && (is_String_Number(QueryString["o"])))
                                {
                                    Navigator.Sort = Convert.ToInt16(QueryString["o"]);
                                }
                                else
                                {
                                    Navigator.Sort = 0;
                                }
                                break;

                            case "all":
                            case "new":
                            case "edit":
                            case "map":
                            case "mapbeta":
                            case "advanced":
                            case "text":
                            case "results":
                            case "contains":
                            case "exact":
                            case "resultslike":
                            case "browseby":
                            case "info":
                            case "aggrmanage":
                            case "aggrhistory":
                            case "aggrpermissions":
                            case "geography":
                                aggregation_querystring_analyze(Navigator, QueryString, Navigator.Default_Aggregation, url_relative_list);
                                break;

                            // This was none of the main constant mode settings,
                            default:
                                // Always check the top-level static web content pages and redirects hierarchy first
                                if ((WebHierarchy != null) && (WebHierarchy.Root_Count > 0))
                                {
                                    WebContent_Hierarchy_Node matchedNode = WebHierarchy.Find(url_relative_list);
                                    if (matchedNode != null)
                                    {
                                        // Maybe this is a web content / info page
                                        Navigator.Mode = Display_Mode_Enum.Simple_HTML_CMS;

                                        // Get the URL reassembled
                                        string possible_info_mode = String.Empty;
                                        if (url_relative_list.Count == 1)
                                            possible_info_mode = url_relative_list[0];
                                        else if (url_relative_list.Count == 2)
                                            possible_info_mode = url_relative_list[0] + "/" + url_relative_list[1];
                                        else if (url_relative_list.Count == 3)
                                            possible_info_mode = url_relative_list[0] + "/" + url_relative_list[1] + "/" + url_relative_list[2];
                                        else if (url_relative_list.Count == 4)
                                            possible_info_mode = url_relative_list[0] + "/" + url_relative_list[1] + "/" + url_relative_list[2] + "/" + url_relative_list[3];
                                        else if (url_relative_list.Count > 4)
                                        {
                                            StringBuilder possibleInfoModeBuilder = new StringBuilder();
                                            if (url_relative_list.Count > 0)
                                            {
                                                possibleInfoModeBuilder.Append(url_relative_list[0]);
                                            }
                                            for (int i = 1; i < url_relative_list.Count; i++)
                                            {
                                                possibleInfoModeBuilder.Append("/" + url_relative_list[i]);
                                            }
                                            possible_info_mode = possibleInfoModeBuilder.ToString().Replace("'", "").Replace("\"", "");
                                        }

                                        // Set the source location
                                        Navigator.Info_Browse_Mode = possible_info_mode;
                                        Navigator.Page_By_FileName = Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design\\webcontent\\" + possible_info_mode.Replace("/","\\") + "\\default.html";
                                        Navigator.WebContentID = matchedNode.WebContentID;
                                        Navigator.Redirect = matchedNode.Redirect;

                                        //// If it is missing, mark that
                                        //if ((!File.Exists(Navigator.Page_By_FileName)) && ( String.IsNullOrEmpty(Navigator.Redirect)))
                                        //{
                                        //    Navigator.Missing = true;
                                        //    Navigator.Info_Browse_Mode = possible_info_mode;
                                        //    Navigator.Page_By_FileName = Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design\\webcontent\\missing.html";
                                        //}

                                        // If something was found, then check for submodes
                                        Navigator.WebContent_Type = WebContent_Type_Enum.Display;
                                        if (!String.IsNullOrEmpty(QueryString["mode"]))
                                        {
                                            switch (QueryString["mode"].ToLower())
                                            {
                                                case "edit":
                                                    Navigator.WebContent_Type = WebContent_Type_Enum.Edit;
                                                    break;

                                                case "menu":
                                                    Navigator.WebContent_Type = WebContent_Type_Enum.Manage_Menu;
                                                    break;

                                                case "milestones":
                                                    Navigator.WebContent_Type = WebContent_Type_Enum.Milestones;
                                                    break;

                                                case "permissions":
                                                    Navigator.WebContent_Type = WebContent_Type_Enum.Permissions;
                                                    break;

                                                case "usage":
                                                    Navigator.WebContent_Type = WebContent_Type_Enum.Usage;
                                                    break;

                                                case "verify":
                                                    Navigator.WebContent_Type = WebContent_Type_Enum.Delete_Verify;
                                                    break;
                                            }
                                        }

                                        return;
                                    }
                                }

                                // Check to see if the first term was an item aggregation alias, which
                                // allows for the alias to overwrite an existing aggregation code (limited usability
                                // but can be used to hide an existing aggregation easily)
                                if (Aggregation_Aliases.ContainsKey(url_relative_list[0]))
                                {
                                    // Perform all aggregation_style checks next
                                    string aggregation_code = Aggregation_Aliases[url_relative_list[0]];
                                    Navigator.Aggregation_Alias = url_relative_list[0];
                                    aggregation_querystring_analyze( Navigator, QueryString, aggregation_code, url_relative_list.GetRange(1, url_relative_list.Count - 1));
                                }
                                else if ( Code_Manager.isValidCode( url_relative_list[0] ))
                                {
                                    // This is an item aggregation call
                                    // Perform all aggregation_style checks next
                                    aggregation_querystring_analyze( Navigator, QueryString, url_relative_list[0], url_relative_list.GetRange(1, url_relative_list.Count - 1 ));
                                }
                                else if ((Engine_Database.Verify_Item_Lookup_Object(false, true, All_Items_Lookup, Tracer)) && (All_Items_Lookup.Contains_BibID(url_relative_list[0].ToUpper())))
                                {
                                    // This is a BibID for an existing title with at least one public item
                                    Navigator.BibID = url_relative_list[0].ToUpper();
                                    Navigator.Mode = Display_Mode_Enum.Item_Display;

                                    // Is the next part a VID?
                                    int current_list_index = 1;
                                    if (url_relative_list.Count > 1)
                                    {
                                        string possible_vid = url_relative_list[1].Trim().PadLeft(5, '0');
                                        if ((All_Items_Lookup.Contains_BibID_VID(Navigator.BibID, possible_vid)) || ( possible_vid == "00000" ))
                                        {
                                            Navigator.VID = possible_vid;
                                            current_list_index++;
                                        }
                                    }

                                    // Look for the item print mode now
                                    if ((url_relative_list.Count > current_list_index) && (url_relative_list[current_list_index] == "print"))
                                    {
                                        // This is an item print request
                                        Navigator.Mode = Display_Mode_Enum.Item_Print;

                                        // Since we need special characters for ranges, etc.. the viewer code
                                        // is in the options query string variable in this case
                                        if (QueryString["options"] != null)
                                        {
                                            Navigator.ViewerCode = QueryString["options"];
                                        }
                                    }
                                    else
                                    {
                                        // Look for the viewercode next
                                        if (url_relative_list.Count > current_list_index)
                                        {
                                            string possible_viewercode = url_relative_list[current_list_index].Trim();

                                            // Get the view code
                                            if (possible_viewercode.Length > 0)
                                            {
                                                // Get the viewer code
                                                Navigator.ViewerCode = possible_viewercode;

                                                // Now, get the page
                                                if ((Navigator.ViewerCode.Length > 0) && (Char.IsNumber(Navigator.ViewerCode[0])))
                                                {
                                                    // Look for the first number
                                                    int numberEnd = Navigator.ViewerCode.Length;
                                                    int count = 0;
                                                    foreach (char thisChar in Navigator.ViewerCode)
                                                    {
                                                        if (!Char.IsNumber(thisChar))
                                                        {
                                                            numberEnd = count;
                                                            break;
                                                        }
                                                        count++;
                                                    }

                                                    // Get the page
                                                    ushort testPage;
                                                    if (UInt16.TryParse(Navigator.ViewerCode.Substring(0, numberEnd), out testPage))
                                                        Navigator.Page = testPage;
                                                }
                                            }
                                            else
                                            {
                                                // Sequence is set to 1
                                                Navigator.Page = 1;
                                            }

                                            // Used or discarded the possible viewer code (used unless length of zero )
                                            current_list_index++;

                                            // Look for a subpage now, if there since there was a (possible) viewer code
                                            if (url_relative_list.Count > current_list_index)
                                            {
                                                string possible_subpage = url_relative_list[current_list_index].Trim();
                                                if (is_String_Number(possible_subpage))
                                                {
                                                    ushort testSubPage;
                                                    if (UInt16.TryParse(possible_subpage, out testSubPage))
                                                        Navigator.SubPage = testSubPage;
                                                }
                                            }
                                        }
                                    }

                                    // Collect number of thumbnails per page
                                    if (QueryString["nt"] != null)
                                    {
                                        short nt_temp;
                                        if (short.TryParse(QueryString["nt"], out nt_temp))
                                            Navigator.Thumbnails_Per_Page = nt_temp;
                                    }

                                    // Collect size of thumbnails per page
                                    if (QueryString["ts"] != null)
                                    {
                                        short ts_temp;
                                        if (short.TryParse(QueryString["ts"], out ts_temp))
                                            Navigator.Size_Of_Thumbnails = ts_temp;
                                    }

                                    // Collect the text search string
                                    if (QueryString["search"] != null)
                                        Navigator.Text_Search = QueryString["search"].Replace("+"," ");

                                    // If coordinates were here, save them
                                    if (QueryString["coord"] != null)
                                        Navigator.Coordinates = QueryString["coord"];

                                    // If a page is requested by filename (rather than sequenc), collect that
                                    if (QueryString["file"] != null)
                                        Navigator.Page_By_FileName = QueryString["file"];
                                }
                                else if ((String.IsNullOrEmpty(Navigator.Page_By_FileName)) && ((String.IsNullOrEmpty(Navigator.Default_Aggregation)) || (Navigator.Default_Aggregation == "all")))
                                {
                                    // This may be a top-level aggregation call
                                    // aggregation_querystring_analyze(Navigator, QueryString, Navigator.Default_Aggregation, url_relative_list);

                                    // Pass this unmatched query to the simple html cms to show the missing (custom) screen
                                    Navigator.Mode = Display_Mode_Enum.Simple_HTML_CMS;

                                    string possible_info_mode = String.Empty;
                                    if (url_relative_list.Count == 1)
                                        possible_info_mode = url_relative_list[0];
                                    else if (url_relative_list.Count == 2)
                                        possible_info_mode = url_relative_list[0] + "/" + url_relative_list[1];
                                    else if (url_relative_list.Count == 3)
                                        possible_info_mode = url_relative_list[0] + "/" + url_relative_list[1] + "/" + url_relative_list[2];
                                    else if (url_relative_list.Count == 4)
                                        possible_info_mode = url_relative_list[0] + "/" + url_relative_list[1] + "/" + url_relative_list[2] + "/" + url_relative_list[3];
                                    else if ( url_relative_list.Count > 4)
                                    {
                                        StringBuilder possibleInfoModeBuilder = new StringBuilder();
                                        if (url_relative_list.Count > 0)
                                        {
                                            possibleInfoModeBuilder.Append(url_relative_list[0]);
                                        }
                                        for (int i = 1; i < url_relative_list.Count; i++)
                                        {
                                            possibleInfoModeBuilder.Append("/" + url_relative_list[i]);
                                        }
                                        possible_info_mode = possibleInfoModeBuilder.ToString().Replace("'", "").Replace("\"", "");
                                    }

                                    string base_source = Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design\\webcontent";

                                    // Set the source location
                                    Navigator.Missing = true;
                                    Navigator.Info_Browse_Mode = possible_info_mode;
                                    Navigator.WebContent_Type = WebContent_Type_Enum.Display;
                                    Navigator.Page_By_FileName = base_source + "\\missing.html";
                                    Navigator.WebContentID = -1;
                                }
                                break;
                        }
                    }
                }
            }
        }
        private static string HTML_Helper(string Viewer_Code, string Display_Text, Navigation_Object Current_Mode)
        {
            if (Current_Mode.ViewerCode == Viewer_Code)
            {
                return "<li class=\"selected-sf-menu-item\">" + Display_Text + "</li>";
            }

            // When rendering for robots, provide the text and image, but not the text
            if (Current_Mode.Is_Robot)
            {
                return "<li class=\"selected-sf-menu-item\">" + Display_Text + "</li>";
            }

            string previousViewerCode = Current_Mode.ViewerCode;
            Current_Mode.ViewerCode = Viewer_Code;
            string returnValue = "<li><a href=\"" + UrlWriterHelper.Redirect_URL(Current_Mode) + "\">" + Display_Text + "</a></li>";
            Current_Mode.ViewerCode = previousViewerCode;
            return returnValue;
        }
        private static void aggregation_querystring_analyze(Navigation_Object Navigator, NameValueCollection QueryString, string Aggregation, List<string> RemainingURLRedirectList)
        {
            // If the aggrgeation passed in was null or empty, use ALL
            if (String.IsNullOrEmpty(Aggregation))
                Aggregation = "all";

            Navigator.Aggregation = Aggregation;
            Navigator.Mode = Display_Mode_Enum.Aggregation;
            Navigator.Aggregation_Type = Aggregation_Type_Enum.Home;

            // Collect any search and search field values
            if (QueryString["t"] != null) Navigator.Search_String = QueryString["t"].Trim();
            if (QueryString["f"] != null) Navigator.Search_Fields = QueryString["f"].Trim();

            // Look for any more url information
            if (RemainingURLRedirectList.Count > 0)
            {
                switch (RemainingURLRedirectList[0])
                {

                    case "edit":
                        Navigator.Aggregation_Type = Aggregation_Type_Enum.Home_Edit;
                        break;

                    case "itemcount":
                        Navigator.Aggregation_Type = Aggregation_Type_Enum.Item_Count;
                        if (RemainingURLRedirectList.Count > 1)
                        {
                            Navigator.Info_Browse_Mode = RemainingURLRedirectList[1];
                        }
                        break;

                    case "inprocess":
                        Navigator.Aggregation_Type = Aggregation_Type_Enum.Private_Items;
                        Navigator.Page = 1;
                        if (RemainingURLRedirectList.Count > 1)
                        {
                            if (is_String_Number(RemainingURLRedirectList[1]))
                                Navigator.Page = Convert.ToUInt16(RemainingURLRedirectList[1]);
                        }
                        if ((QueryString["o"] != null) && (is_String_Number(QueryString["o"])))
                        {
                            Navigator.Sort = Convert.ToInt16(QueryString["o"]);
                        }
                        else
                        {
                            Navigator.Sort = 0;
                        }
                        break;

                    case "contact":
                        Navigator.Mode = Display_Mode_Enum.Contact;
                        if (RemainingURLRedirectList.Count > 1)
                        {
                            if (RemainingURLRedirectList[1] == "sent")
                            {
                                Navigator.Mode = Display_Mode_Enum.Contact_Sent;
                            }
                        }
                        if (QueryString["em"] != null)
                            Navigator.Error_Message = QueryString["em"];
                        break;

                    case "manage":
                    case "aggrmanage":
                        Navigator.Aggregation_Type = Aggregation_Type_Enum.Manage_Menu;
                        break;

                    case "permissions":
                    case "aggrpermissions":
                        Navigator.Aggregation_Type = Aggregation_Type_Enum.User_Permissions;
                        break;

                    case "history":
                    case "aggrhistory":
                        Navigator.Aggregation_Type = Aggregation_Type_Enum.Work_History;
                        break;

                    case "geography":
                        Navigator.Aggregation_Type = Aggregation_Type_Enum.Browse_Map;
                        break;

                    case "usage":
                        Navigator.Aggregation_Type = Aggregation_Type_Enum.Usage_Statistics;
                        if (RemainingURLRedirectList.Count > 1)
                        {
                            Navigator.Info_Browse_Mode = RemainingURLRedirectList[1];
                        }
                        break;

                    case "map":
                        Navigator.Mode = Display_Mode_Enum.Search;
                        Navigator.Search_Type = Search_Type_Enum.Map;
                        if (RemainingURLRedirectList.Count > 1)
                        {
                            Navigator.Info_Browse_Mode = RemainingURLRedirectList[1];
                        }
                        break;

                    case "mapbeta":
                        Navigator.Mode = Display_Mode_Enum.Search;
                        Navigator.Search_Type = Search_Type_Enum.Map_Beta;
                        if (RemainingURLRedirectList.Count > 1)
                        {
                            Navigator.Info_Browse_Mode = RemainingURLRedirectList[1];
                        }
                        break;

                    case "advanced":
                        Navigator.Mode = Display_Mode_Enum.Search;
                        Navigator.Search_Type = Search_Type_Enum.Advanced;
                        break;

                    case "text":
                        Navigator.Mode = Display_Mode_Enum.Search;
                        Navigator.Search_Type = Search_Type_Enum.Full_Text;
                        break;

                    case "info":
                        Navigator.Aggregation_Type = Aggregation_Type_Enum.Browse_Info;
                        if (RemainingURLRedirectList.Count > 1)
                            Navigator.Info_Browse_Mode = RemainingURLRedirectList[1];
                        if ((RemainingURLRedirectList.Count > 2) && (RemainingURLRedirectList[2] == "edit"))
                        {
                            Navigator.Aggregation_Type = Aggregation_Type_Enum.Child_Page_Edit;
                        }
                        break;

                    case "browseby":
                        Navigator.Aggregation_Type = Aggregation_Type_Enum.Browse_By;
                        if (RemainingURLRedirectList.Count > 1)
                            Navigator.Info_Browse_Mode = RemainingURLRedirectList[1];
                        if ( RemainingURLRedirectList.Count > 2 )
                        {
                            string possible_page = RemainingURLRedirectList[2];
                            bool isNumber = possible_page.All(Char.IsNumber);
                            if ( isNumber )
                            {
                                Navigator.Page = Convert.ToUInt16(possible_page);
                            }
                        }
                        break;

                    case "results":
                    case "resultslike":
                    case "contains":
                    case "exact":
                        switch (RemainingURLRedirectList[0])
                        {
                            case "results":
                                Navigator.Search_Precision = Search_Precision_Type_Enum.Inflectional_Form;
                                break;

                            case "resultslike":
                                Navigator.Search_Precision = Search_Precision_Type_Enum.Synonmic_Form;
                                break;

                            case "contains":
                                Navigator.Search_Precision = Search_Precision_Type_Enum.Contains;
                                break;

                            case "exact":
                                Navigator.Search_Precision = Search_Precision_Type_Enum.Exact_Match;
                                break;
                        }
                        Navigator.Mode = Display_Mode_Enum.Results;
                        Navigator.Search_Type = Search_Type_Enum.Basic;
                        Navigator.Result_Display_Type = Result_Display_Type_Enum.Default;
                        Navigator.Page = 1;
                        Navigator.Sort = 0;
                        if ((HttpContext.Current != null) && (HttpContext.Current.Session != null) && (HttpContext.Current.Session["User_Default_Sort"] != null))
                            Navigator.Sort = Convert.ToInt16(HttpContext.Current.Session["User_Default_Sort"]);

                        int search_handled_args = 1;

                        // Look for result display type
                        if (RemainingURLRedirectList.Count > search_handled_args)
                        {
                            switch (RemainingURLRedirectList[search_handled_args])
                            {
                                case "brief":
                                    Navigator.Result_Display_Type = Result_Display_Type_Enum.Brief;
                                    search_handled_args++;
                                    break;
                                case "export":
                                    Navigator.Result_Display_Type = Result_Display_Type_Enum.Export;
                                    search_handled_args++;
                                    break;
                                case "citation":
                                    Navigator.Result_Display_Type = Result_Display_Type_Enum.Full_Citation;
                                    search_handled_args++;
                                    break;
                                case "image":
                                    Navigator.Result_Display_Type = Result_Display_Type_Enum.Full_Image;
                                    search_handled_args++;
                                    break;
                                case "map":
                                    Navigator.Result_Display_Type = Result_Display_Type_Enum.Map;
                                    search_handled_args++;
                                    break;
                                case "mapbeta":
                                    Navigator.Result_Display_Type = Result_Display_Type_Enum.Map_Beta;
                                    search_handled_args++;
                                    break;
                                case "table":
                                    Navigator.Result_Display_Type = Result_Display_Type_Enum.Table;
                                    search_handled_args++;
                                    break;
                                case "thumbs":
                                    Navigator.Result_Display_Type = Result_Display_Type_Enum.Thumbnails;
                                    search_handled_args++;
                                    break;
                            }
                        }

                        // Look for a page number
                        if (RemainingURLRedirectList.Count > search_handled_args)
                        {
                            string possible_page = RemainingURLRedirectList[search_handled_args];
                            if ((possible_page.Length > 0) && (is_String_Number(possible_page)))
                            {
                                ushort page_result ;
                                UInt16.TryParse(possible_page, out page_result);
                                Navigator.Page = page_result;
                            }
                        }

                        // Collect the coordinate information from the URL query string
                        if (QueryString["coord"] != null)
                        {
                            Navigator.Coordinates = QueryString["coord"].Trim();
                            if (!String.IsNullOrEmpty(Navigator.Coordinates))
                            {
                                Navigator.Search_Type = Search_Type_Enum.Map;
                                Navigator.Search_Fields = String.Empty;
                                Navigator.Search_String = String.Empty;
                            }
                        }

                        // Collect any date range that may have existed
                        if (QueryString["yr1"] != null)
                        {
                            short year1;
                            if (Int16.TryParse(QueryString["yr1"], out year1))
                                Navigator.DateRange_Year1 = year1;
                        }
                        if (QueryString["yr2"] != null)
                        {
                            short year2;
                            if (Int16.TryParse(QueryString["yr2"], out year2))
                                Navigator.DateRange_Year2 = year2;
                        }
                        if ((Navigator.DateRange_Year1.HasValue ) && ( Navigator.DateRange_Year2.HasValue ) && (Navigator.DateRange_Year1.Value > Navigator.DateRange_Year2.Value ))
                        {
                            short temp = Navigator.DateRange_Year1.Value;
                            Navigator.DateRange_Year1 = Navigator.DateRange_Year2.Value;
                            Navigator.DateRange_Year2 = temp;
                        }
                        if (QueryString["da1"] != null)
                        {
                            long date1;
                            if (Int64.TryParse(QueryString["da1"], out date1))
                                Navigator.DateRange_Date1 = date1;
                        }
                        if (QueryString["da2"] != null)
                        {
                            long date2;
                            if (Int64.TryParse(QueryString["da2"], out date2))
                                Navigator.DateRange_Date2 = date2;
                        }

                        // Was a search string and fields included?
                        if ((Navigator.Search_String.Length > 0) && (Navigator.Search_Fields.Length > 0))
                        {
                            Navigator.Search_Type = Search_Type_Enum.Advanced;
                        }
                        else
                        {
                            Navigator.Search_Fields = "ZZ";
                        }

                        // If no search term, look foor the TEXT-specific term
                        if (Navigator.Search_String.Length == 0)
                        {
                            if (QueryString["text"] != null)
                            {
                                Navigator.Search_String = QueryString["text"].Trim();
                            }

                            if (Navigator.Search_String.Length > 0)
                            {
                                Navigator.Search_Type = Search_Type_Enum.Full_Text;
                            }
                        }

                        // Check for any sort value
                        if (QueryString["o"] != null)
                        {
                            string sort = QueryString["o"];
                            if (is_String_Number(sort))
                            {
                                short sort_result ;
                                Int16.TryParse(sort, out sort_result);
                                Navigator.Sort = sort_result;
                            }
                        }
                        break;

                    default:
                        Navigator.Mode = Display_Mode_Enum.Aggregation;
                        Navigator.Aggregation_Type = Aggregation_Type_Enum.Browse_Info;
                        Navigator.Info_Browse_Mode = RemainingURLRedirectList[0];
                        Navigator.Result_Display_Type = Result_Display_Type_Enum.Default;
                        Navigator.Page = 1;
                        Navigator.Sort = 0;
                        if ((HttpContext.Current != null) && (HttpContext.Current.Session != null) && (HttpContext.Current.Session["User_Default_Sort"] != null))
                            Navigator.Sort = Convert.ToInt16(HttpContext.Current.Session["User_Default_Sort"]);
                        int aggr_handled_args = 1;

                        // Look for result display type
                        if (RemainingURLRedirectList.Count > aggr_handled_args)
                        {
                            switch ( RemainingURLRedirectList[ aggr_handled_args ] )
                            {
                                case "brief":
                                    Navigator.Result_Display_Type = Result_Display_Type_Enum.Brief;
                                    aggr_handled_args++;
                                    break;
                                case "export":
                                    Navigator.Result_Display_Type = Result_Display_Type_Enum.Export;
                                    aggr_handled_args++;
                                    break;
                                case "citation":
                                    Navigator.Result_Display_Type = Result_Display_Type_Enum.Full_Citation;
                                    aggr_handled_args++;
                                    break;
                                case "image":
                                    Navigator.Result_Display_Type = Result_Display_Type_Enum.Full_Image;
                                    aggr_handled_args++;
                                    break;
                                case "map":
                                    Navigator.Result_Display_Type = Result_Display_Type_Enum.Map;
                                    aggr_handled_args++;
                                    break;
                                case "mapbeta":
                                    Navigator.Result_Display_Type = Result_Display_Type_Enum.Map_Beta;
                                    aggr_handled_args++;
                                    break;
                                case "table":
                                    Navigator.Result_Display_Type = Result_Display_Type_Enum.Table;
                                    aggr_handled_args++;
                                    break;
                                case "thumbs":
                                    Navigator.Result_Display_Type = Result_Display_Type_Enum.Thumbnails;
                                    aggr_handled_args++;
                                    break;
                                case "edit":
                                    Navigator.Aggregation_Type = Aggregation_Type_Enum.Child_Page_Edit;
                                    aggr_handled_args++;
                                    break;
                            }
                        }

                        // Look for a page number
                        if (RemainingURLRedirectList.Count > aggr_handled_args)
                        {
                            string possible_page = RemainingURLRedirectList[aggr_handled_args];
                            if (( possible_page.Length > 0 ) && ( is_String_Number(possible_page)))
                            {
                                ushort page_result;
                                UInt16.TryParse(possible_page, out page_result);
                                Navigator.Page = page_result;
                            }
                        }

                        // Check for any sort value
                        if (QueryString["o"] != null)
                        {
                            string sort = QueryString["o"];
                            if (is_String_Number(sort))
                            {
                                short sort_result;
                                Int16.TryParse(sort, out sort_result);
                                Navigator.Sort = sort_result;
                            }
                        }

                        break;
                }
            }
        }