/// <summary> Saves the data rendered by this element to the provided bibliographic object during postback </summary>
        /// <param name="Bib"> Object into which to save the user's data, entered into the html rendered by this element </param>
        public override void Save_To_Bib(SobekCM_Item Bib)
        {
            string[] getKeys = HttpContext.Current.Request.Form.AllKeys;
            foreach (string thisKey in getKeys)
            {
                if (thisKey.IndexOf(html_element_name.Replace("_", "")) == 0)
                {
                    Thesis_Dissertation_Info etdInfo = Bib.Get_Metadata_Module(GlobalVar.THESIS_METADATA_MODULE_KEY) as Thesis_Dissertation_Info;

                    string value = HttpContext.Current.Request.Form[thisKey];
                    if (value.Length > 0)
                    {
                        if (etdInfo == null)
                        {
                            etdInfo = new Thesis_Dissertation_Info();
                            Bib.Add_Metadata_Module(GlobalVar.THESIS_METADATA_MODULE_KEY, etdInfo);
                        }
                        etdInfo.Committee_Chair = value;
                    }
                    else
                    {
                        if (etdInfo != null)
                            etdInfo.Committee_Chair = String.Empty;
                    }
                    return;
                }
            }
        }
        /// <summary> Reads the dmdSec at the current position in the XmlTextReader and associates it with the 
        /// entire package  </summary>
        /// <param name="Input_XmlReader"> Open XmlReader from which to read the metadata </param>
        /// <param name="Return_Package"> Package into which to read the metadata</param>
        /// <param name="Options"> Dictionary of any options which this METS section reader may utilize</param>
        /// <returns> TRUE if successful, otherwise FALSE</returns>  
        public bool Read_dmdSec(XmlReader Input_XmlReader, SobekCM_Item Return_Package, Dictionary<string, object> Options)
        {
            // Ensure this metadata module extension exists
            Sample_FavColor_Metadata_Module taxonInfo = Return_Package.Get_Metadata_Module(Sample_FavColor_Metadata_Module.Module_Name_Static) as Sample_FavColor_Metadata_Module;
            if (taxonInfo == null)
            {
                taxonInfo = new Sample_FavColor_Metadata_Module();
                Return_Package.Add_Metadata_Module(Sample_FavColor_Metadata_Module.Module_Name_Static, taxonInfo);
            }

            // Loop through reading each XML node
            do
            {
                // If this is the end of this section, return
                if ((Input_XmlReader.NodeType == XmlNodeType.EndElement) && ((Input_XmlReader.Name == "METS:mdWrap") || (Input_XmlReader.Name == "mdWrap")))
                    return true;

                // get the right division information based on node type
                if (Input_XmlReader.NodeType == XmlNodeType.Element)
                {
                    string name = Input_XmlReader.Name.ToLower();

                    switch (name)
                    {
                        case "absoluteFavoriteColor":
                            Input_XmlReader.Read();
                            if ((Input_XmlReader.NodeType == XmlNodeType.Text) && (Input_XmlReader.Value.Trim().Length > 0))
                            {
                                taxonInfo.Absolute_Favorite_Color = Input_XmlReader.Value.Trim();
                            }
                            break;

                        case "additionalFavoriteColor":
                            Input_XmlReader.Read();
                            if ((Input_XmlReader.NodeType == XmlNodeType.Text) && (Input_XmlReader.Value.Trim().Length > 0))
                            {
                                taxonInfo.Other_Favorite_Color.Add(Input_XmlReader.Value.Trim());
                            }
                            break;
                    }
                }
            } while (Input_XmlReader.Read());

            return true;
        }
        /// <summary> Saves the data rendered by this element to the provided bibliographic object during postback </summary>
        /// <param name="Bib"> Object into which to save the user's data, entered into the html rendered by this element </param>
        public override void Save_To_Bib(SobekCM_Item Bib)
        {
            // Try to get any existing learning object metadata module
            LearningObjectMetadata lomInfo = Bib.Get_Metadata_Module(GlobalVar.IEEE_LOM_METADATA_MODULE_KEY) as LearningObjectMetadata;

            string[] getKeys = HttpContext.Current.Request.Form.AllKeys;
            foreach (string thisKey in getKeys.Where(thisKey => thisKey.IndexOf(html_element_name.Replace("_", "")) == 0))
            {
                // Get the value from the form element
                string value = HttpContext.Current.Request.Form[thisKey].Trim();
                if (value.Length > 0)
                {
                    // There is a value, so ensure learning object metadata does exist
                    if (lomInfo == null)
                    {
                        lomInfo = new LearningObjectMetadata();
                        Bib.Add_Metadata_Module(GlobalVar.IEEE_LOM_METADATA_MODULE_KEY, lomInfo);
                    }

                    // Add the value
                    lomInfo.Add_LearningResourceType(value);

                }
            }
        }
        /// <summary> Saves the data rendered by this element to the provided bibliographic object during postback </summary>
        /// <param name="Bib"> Object into which to save the user's data, entered into the html rendered by this element </param>
        public override void Save_To_Bib(SobekCM_Item Bib)
        {
            string[] getKeys = HttpContext.Current.Request.Form.AllKeys;
            foreach (string thisKey in getKeys)
            {
                if (thisKey.IndexOf(html_element_name.Replace("_","")) == 0)
                {
                    // Get the value from the combo box
                    string value = HttpContext.Current.Request.Form[thisKey].Trim();

                    // Try to get any existing learning object metadata module
                    LearningObjectMetadata lomInfo = Bib.Get_Metadata_Module(GlobalVar.IEEE_LOM_METADATA_MODULE_KEY) as LearningObjectMetadata;

                    if (value.Length == 0)
                    {
                        // I fhte learning object metadata does exist, set it to undefined
                        if ( lomInfo != null )
                            lomInfo.InteractivityType = InteractivityTypeEnum.UNDEFINED;
                    }
                    else
                    {
                        // There is a value, so ensure learning object metadata does exist
                        if (lomInfo == null)
                        {
                            lomInfo = new LearningObjectMetadata();
                            Bib.Add_Metadata_Module(GlobalVar.IEEE_LOM_METADATA_MODULE_KEY, lomInfo);
                        }

                        // Save the new value
                        switch ( value )
                        {
                            case level1_text:
                                lomInfo.InteractivityType = InteractivityTypeEnum.active;
                                break;

                            case level2_text:
                                lomInfo.InteractivityType = InteractivityTypeEnum.expositive;
                                break;

                            case level3_text:
                                lomInfo.InteractivityType = InteractivityTypeEnum.mixed;
                                break;
                        }
                    }
                    return;
                }
            }
        }
        /// <summary> Saves the data rendered by this element to the provided bibliographic object during postback </summary>
        /// <param name="Bib"> Object into which to save the user's data, entered into the html rendered by this element </param>
        public override void Save_To_Bib(SobekCM_Item Bib)
        {
            // Try to get any existing learning object metadata module
            LearningObjectMetadata lomInfo = Bib.Get_Metadata_Module(GlobalVar.IEEE_LOM_METADATA_MODULE_KEY) as LearningObjectMetadata;

            // Pull the standard values
            NameValueCollection form = HttpContext.Current.Request.Form;

            foreach (string thisKey in form.AllKeys)
            {
                if (thisKey.IndexOf("lomcontext_select") == 0)
                {
                    string diff = thisKey.Replace("lomcontext_select", "");
                    string select_value = form[thisKey];
                    string text_value = form["lomcontext_text" + diff];

                    if ((select_value.Length > 0) && (text_value.Length > 0))
                    {
                        // There is a value, so ensure learning object metadata does exist
                        if (lomInfo == null)
                        {
                            lomInfo = new LearningObjectMetadata();
                            Bib.Add_Metadata_Module(GlobalVar.IEEE_LOM_METADATA_MODULE_KEY, lomInfo);
                        }

                        // Add the value
                        lomInfo.Add_Context(text_value, select_value);
                    }
                }
            }
        }
        /// <summary> Saves the data rendered by this element to the provided bibliographic object during postback </summary>
        /// <param name="Bib"> Object into which to save the user's data, entered into the html rendered by this element </param>
        public override void Save_To_Bib(SobekCM_Item Bib)
        {
            // Try to get any existing metadata module
            VRACore_Info vraInfo = Bib.Get_Metadata_Module(GlobalVar.VRACORE_METADATA_MODULE_KEY) as VRACore_Info;

            string[] getKeys = HttpContext.Current.Request.Form.AllKeys;
            foreach (string thisKey in getKeys.Where(thisKey => thisKey.IndexOf(html_element_name.Replace("_", "")) == 0))
            {
                // Get the value from the form element
                string value = HttpContext.Current.Request.Form[thisKey].Trim();
                if (value.Length > 0)
                {
                    // There is a value, so ensure metadata does exist
                    if (vraInfo == null)
                    {
                        vraInfo = new VRACore_Info();
                        Bib.Add_Metadata_Module(GlobalVar.VRACORE_METADATA_MODULE_KEY, vraInfo);
                    }

                    // Add the value
                    vraInfo.Add_Technique(value);

                }
            }
        }
        /// <summary> Saves the data rendered by this element to the provided bibliographic object during postback </summary>
        /// <param name="Bib"> Object into which to save the user's data, entered into the html rendered by this element </param>
        public override void Save_To_Bib(SobekCM_Item Bib)
        {
            string[] getKeys = HttpContext.Current.Request.Form.AllKeys;
            foreach (string thisKey in getKeys)
            {
                if (thisKey.IndexOf(html_element_name.Replace("_", "")) == 0)
                {
                    Thesis_Dissertation_Info etdInfo = Bib.Get_Metadata_Module(GlobalVar.THESIS_METADATA_MODULE_KEY) as Thesis_Dissertation_Info;

                    string value = HttpContext.Current.Request.Form[thisKey].Trim().ToLower();
                    if (value.Length > 0)
                    {
                        if (etdInfo == null)
                        {
                            etdInfo = new Thesis_Dissertation_Info();
                            Bib.Add_Metadata_Module(GlobalVar.THESIS_METADATA_MODULE_KEY, etdInfo);
                        }
                        switch (value)
                        {
                            case "bachelors":
                                etdInfo.Degree_Level = Thesis_Dissertation_Info.Thesis_Degree_Level_Enum.Bachelors;
                                break;

                            case "doctorate":
                                etdInfo.Degree_Level = Thesis_Dissertation_Info.Thesis_Degree_Level_Enum.Doctorate;
                                break;

                            case "masters":
                                etdInfo.Degree_Level = Thesis_Dissertation_Info.Thesis_Degree_Level_Enum.Masters;
                                break;

                            case "post-doctoratee":
                                etdInfo.Degree_Level = Thesis_Dissertation_Info.Thesis_Degree_Level_Enum.PostDoctorate;
                                break;

                            default:
                                etdInfo.Degree_Level = Thesis_Dissertation_Info.Thesis_Degree_Level_Enum.Unknown;
                                break;
                        }
                    }
                    else
                    {
                        if (etdInfo != null)
                            etdInfo.Degree_Level = Thesis_Dissertation_Info.Thesis_Degree_Level_Enum.Unknown;
                    }
                    return;
                }
            }
        }
        private void Finish_Building_Item(SobekCM_Item Package_To_Finalize, DataSet DatabaseInfo, bool Multiple, List<string> Item_Viewer_Priority, Custom_Tracer Tracer )
        {
            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Load the data from the database into the resource object");

            if ((DatabaseInfo == null) || (DatabaseInfo.Tables[2] == null) || (DatabaseInfo.Tables[2].Rows.Count == 0))
            {
                Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Invalid data from the database, either not enough tables, or no rows in Tables[2]");
            }
            else
            {
                // Copy over some basic values
                DataRow mainItemRow = DatabaseInfo.Tables[2].Rows[0];
                Package_To_Finalize.Behaviors.Set_Primary_Identifier(mainItemRow["Primary_Identifier_Type"].ToString(), mainItemRow["Primary_Identifier"].ToString());
                Package_To_Finalize.Behaviors.GroupTitle = mainItemRow["GroupTitle"].ToString();
                Package_To_Finalize.Behaviors.GroupType = mainItemRow["GroupType"].ToString();
                Package_To_Finalize.Web.File_Root = mainItemRow["File_Location"].ToString();
                Package_To_Finalize.Web.AssocFilePath = mainItemRow["File_Location"] + "\\" + Package_To_Finalize.VID + "\\";
                Package_To_Finalize.Behaviors.IP_Restriction_Membership = Convert.ToInt16(mainItemRow["IP_Restriction_Mask"]);
                Package_To_Finalize.Behaviors.CheckOut_Required = Convert.ToBoolean(mainItemRow["CheckoutRequired"]);
                Package_To_Finalize.Behaviors.Text_Searchable = Convert.ToBoolean(mainItemRow["TextSearchable"]);
                Package_To_Finalize.Web.ItemID = Convert.ToInt32(mainItemRow["ItemID"]);
                Package_To_Finalize.Web.GroupID = Convert.ToInt32(mainItemRow["GroupID"]);
                Package_To_Finalize.Behaviors.Suppress_Endeca = Convert.ToBoolean(mainItemRow["SuppressEndeca"]);
                //Package_To_Finalize.Behaviors.Expose_Full_Text_For_Harvesting = Convert.ToBoolean(mainItemRow["SuppressEndeca"]);
                Package_To_Finalize.Tracking.Internal_Comments = mainItemRow["Comments"].ToString();
                Package_To_Finalize.Behaviors.Dark_Flag = Convert.ToBoolean(mainItemRow["Dark"]);
                Package_To_Finalize.Tracking.Born_Digital = Convert.ToBoolean(mainItemRow["Born_Digital"]);
                Package_To_Finalize.Behaviors.Main_Thumbnail = mainItemRow["MainThumbnail"].ToString();
                //Package_To_Finalize.Divisions.Page_Count = Convert.ToInt32(mainItemRow["Pages"]);
                if (mainItemRow["Disposition_Advice"] != DBNull.Value)
                    Package_To_Finalize.Tracking.Disposition_Advice = Convert.ToInt16(mainItemRow["Disposition_Advice"]);
                else
                    Package_To_Finalize.Tracking.Disposition_Advice = -1;
                if (mainItemRow["Material_Received_Date"] != DBNull.Value)
                    Package_To_Finalize.Tracking.Material_Received_Date = Convert.ToDateTime(mainItemRow["Material_Received_Date"]);
                else
                    Package_To_Finalize.Tracking.Material_Received_Date = null;
                if (mainItemRow["Material_Recd_Date_Estimated"] != DBNull.Value)
                    Package_To_Finalize.Tracking.Material_Rec_Date_Estimated = Convert.ToBoolean(mainItemRow["Material_Recd_Date_Estimated"]);
                if (DatabaseInfo.Tables[2].Columns.Contains("Tracking_Box"))
                {
                    if (mainItemRow["Tracking_Box"] != DBNull.Value)
                        Package_To_Finalize.Tracking.Tracking_Box = mainItemRow["Tracking_Box"].ToString();
                }

                // Set more of the sobekcm web portions in the item
                Package_To_Finalize.Web.Set_BibID_VID(Package_To_Finalize.BibID, Package_To_Finalize.VID);
                Package_To_Finalize.Web.Image_Root = Engine_ApplicationCache_Gateway.Settings.Servers.Image_URL;
                if (Multiple)
                    Package_To_Finalize.Web.Siblings = 2;

                // Set the serial hierarchy from the database (if multiple)
                if ((Multiple) && (mainItemRow["Level1_Text"].ToString().Length > 0))
                {
                    Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Assigning serial hierarchy from the database info");

                    bool found = false;

                    // Get the values from the database first
                    string level1_text = mainItemRow["Level1_Text"].ToString();
                    string level2_text = mainItemRow["Level2_Text"].ToString();
                    string level3_text = mainItemRow["Level3_Text"].ToString();
                    int level1_index = Convert.ToInt32(mainItemRow["Level1_Index"]);
                    int level2_index = Convert.ToInt32(mainItemRow["Level2_Index"]);
                    int level3_index = Convert.ToInt32(mainItemRow["Level3_Index"]);

                    // Does this match the enumeration
                    if (level1_text.ToUpper().Trim() == Package_To_Finalize.Bib_Info.Series_Part_Info.Enum1.ToUpper().Trim())
                    {
                        // Copy the database values to the enumeration portion
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Enum1 = level1_text;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Enum1_Index = level1_index;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Enum2 = level2_text;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Enum2_Index = level2_index;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Enum3 = level3_text;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Enum3_Index = level3_index;
                        found = true;
                    }

                    // Does this match the chronology
                    if ((!found) && (level1_text.ToUpper().Trim() == Package_To_Finalize.Bib_Info.Series_Part_Info.Year.ToUpper().Trim()))
                    {
                        // Copy the database values to the chronology portion
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Year = level1_text;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Year_Index = level1_index;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Month = level2_text;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Month_Index = level2_index;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Day = level3_text;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Day_Index = level3_index;
                        found = true;
                    }

                    if (!found)
                    {
                        // No match.  If it is numeric, move it to the chronology, otherwise, enumeration
                        bool charFound = level1_text.Trim().Any(ThisChar => !Char.IsNumber(ThisChar));

                        if (charFound)
                        {
                            // Copy the database values to the enumeration portion
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Enum1 = level1_text;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Enum1_Index = level1_index;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Enum2 = level2_text;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Enum2_Index = level2_index;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Enum3 = level3_text;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Enum3_Index = level3_index;
                        }
                        else
                        {
                            // Copy the database values to the chronology portion
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Year = level1_text;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Year_Index = level1_index;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Month = level2_text;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Month_Index = level2_index;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Day = level3_text;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Day_Index = level3_index;
                        }
                    }

                    // Copy the database values to the simple serial portion (used to actually determine serial heirarchy)
                    Package_To_Finalize.Behaviors.Serial_Info.Clear();
                    Package_To_Finalize.Behaviors.Serial_Info.Add_Hierarchy(1, level1_index, level1_text);
                    if (level2_text.Length > 0)
                    {
                        Package_To_Finalize.Behaviors.Serial_Info.Add_Hierarchy(2, level2_index, level2_text);
                        if (level3_text.Length > 0)
                        {
                            Package_To_Finalize.Behaviors.Serial_Info.Add_Hierarchy(3, level3_index, level3_text);
                        }
                    }
                }

                // See if this can be described
                bool can_describe = false;
                foreach (DataRow thisRow in DatabaseInfo.Tables[1].Rows)
                {
                    int thisAggregationValue = Convert.ToInt16(thisRow["Items_Can_Be_Described"]);
                    if (thisAggregationValue == 0)
                    {
                        can_describe = false;
                        break;
                    }
                    if (thisAggregationValue == 2)
                    {
                        can_describe = true;
                    }
                }
                Package_To_Finalize.Behaviors.Can_Be_Described = can_describe;

                // Look for rights information to add
                if (mainItemRow["EmbargoEnd"] != DBNull.Value)
                {
                    try
                    {
                        DateTime embargoEnd = DateTime.Parse(mainItemRow["EmbargoEnd"].ToString());
                        string origAccessCode = mainItemRow["Original_AccessCode"].ToString();

                        // Is there already a RightsMD module in the item?
                        // Ensure this metadata module extension exists
                        RightsMD_Info rightsInfo = Package_To_Finalize.Get_Metadata_Module(GlobalVar.PALMM_RIGHTSMD_METADATA_MODULE_KEY) as RightsMD_Info;
                        if (rightsInfo == null)
                        {
                            rightsInfo = new RightsMD_Info();
                            Package_To_Finalize.Add_Metadata_Module(GlobalVar.PALMM_RIGHTSMD_METADATA_MODULE_KEY, rightsInfo);
                        }

                        // Add the data
                        rightsInfo.Access_Code_String = origAccessCode;
                        rightsInfo.Embargo_End = embargoEnd;
                    }
                    catch (Exception)
                    {

                    }
                }
            }

            // Look for user descriptions
            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Look for user descriptions (or tags)");
            foreach (DataRow thisRow in DatabaseInfo.Tables[0].Rows)
            {
                string first_name = thisRow["FirstName"].ToString();
                string nick_name = thisRow["NickName"].ToString();
                string last_name = thisRow["LastName"].ToString();
                int userid = Convert.ToInt32(thisRow["UserID"]);
                string tag = thisRow["Description_Tag"].ToString();
                int tagid = Convert.ToInt32(thisRow["TagID"]);
                DateTime dateAdded = Convert.ToDateTime(thisRow["Date_Modified"]);

                if (nick_name.Length > 0)
                {
                    Package_To_Finalize.Behaviors.Add_User_Tag(userid, nick_name + " " + last_name, tag, dateAdded, tagid);
                }
                else
                {
                    Package_To_Finalize.Behaviors.Add_User_Tag(userid, first_name + " " + last_name, tag, dateAdded, tagid);
                }
            }

            // Look for ticklers
            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Load ticklers from the database info");
            foreach (DataRow thisRow in DatabaseInfo.Tables[3].Rows)
            {
                Package_To_Finalize.Behaviors.Add_Tickler(thisRow["MetadataValue"].ToString().Trim());
            }

            // Set the aggregationPermissions in the package to the aggregation links from the database
            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Load the aggregations from the database info");
            Package_To_Finalize.Behaviors.Clear_Aggregations();
            foreach (DataRow thisRow in DatabaseInfo.Tables[1].Rows)
            {
                if (!Convert.ToBoolean(thisRow["impliedLink"]))
                {
                    string code = thisRow["Code"].ToString();
                    if (String.Compare(code, "all", StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        Package_To_Finalize.Behaviors.Add_Aggregation(code, thisRow["Name"].ToString(), thisRow["Type"].ToString());
                    }
                }
            }

            // If no collections, add some regardless of whether it was IMPLIED
            if ( Package_To_Finalize.Behaviors.Aggregation_Count == 0)
            {
                foreach (DataRow thisRow in DatabaseInfo.Tables[1].Rows)
                {
                    string code = thisRow["Code"].ToString();
                    if (String.Compare(code, "all", StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        Package_To_Finalize.Behaviors.Add_Aggregation(code, thisRow["Name"].ToString(), thisRow["Type"].ToString());
                    }
                }
            }

            // Step through each page and set the static page count
            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Set the static page count");

            pageseq = 0;
            List<Page_TreeNode> pages_encountered = new List<Page_TreeNode>();
            if (!Package_To_Finalize.Behaviors.Dark_Flag)
            {
                foreach (abstract_TreeNode rootNode in Package_To_Finalize.Divisions.Physical_Tree.Roots)
                {
                    recurse_through_nodes(Package_To_Finalize, rootNode, pages_encountered);
                }
            }
            Package_To_Finalize.Web.Static_PageCount = pages_encountered.Count;
            Package_To_Finalize.Web.Static_Division_Count = divseq;

            // Make sure no icons were retained from the METS file itself
            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Load the wordmarks/icons from the database info");
            Package_To_Finalize.Behaviors.Clear_Wordmarks();

            // Add the icons from the database information
            foreach (DataRow iconRow in DatabaseInfo.Tables[5].Rows)
            {
                string image = iconRow[0].ToString();
                string link = iconRow[1].ToString().Replace("&", "&amp;").Replace("\"", "&quot;");
                string code = iconRow[2].ToString();
                string name = iconRow[3].ToString();
                if ( name.Length == 0 )
                    name = code.Replace("&", "&amp;").Replace("\"", "&quot;");

                string html;
                if (link.Length == 0)
                {
                    html = "<img class=\"SobekItemWordmark\" src=\"<%BASEURL%>design/wordmarks/" + image + "\" title=\"" + name + "\" alt=\"" + name + "\" />";
                }
                else
                {
                    if (link[0] == '?')
                    {
                        html = "<a href=\"" + link + "\"><img class=\"SobekItemWordmark\" src=\"<%BASEURL%>design/wordmarks/" + image + "\" alt=\"" + name + "\" /></a>";
                    }
                    else
                    {
                        html = "<a href=\"" + link + "\" target=\"_blank\"><img class=\"SobekItemWordmark\" src=\"<%BASEURL%>design/wordmarks/" + image + "\" alt=\"" + name + "\" /></a>";
                    }
                }

                Wordmark_Info newIcon = new Wordmark_Info {HTML = html, Link = link, Title = name, Code = code};
                Package_To_Finalize.Behaviors.Add_Wordmark(newIcon);
            }

            // Make sure no web skins were retained from the METS file itself
            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Load the web skins from the database info");
            Package_To_Finalize.Behaviors.Clear_Web_Skins();

            // Add the web skins from the database
            foreach (DataRow skinRow in DatabaseInfo.Tables[6].Rows)
            {
                Package_To_Finalize.Behaviors.Add_Web_Skin(skinRow[0].ToString().ToUpper());
            }

            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Set the views from a combination of the METS and the database info");

            // Make sure no views were retained from the METS file itself
            Package_To_Finalize.Behaviors.Clear_Views();
            Package_To_Finalize.Behaviors.Clear_Item_Level_Page_Views();

            // If this has more than 1 sibling (this count includes itself), add the multi-volumes viewer
            if (Multiple)
            {
                Package_To_Finalize.Behaviors.Add_View(View_Enum.ALL_VOLUMES, String.Empty, Package_To_Finalize.Bib_Info.SobekCM_Type_String);
            }

            // Add the full citation view and the (hidden) tracking view and some other ALWAYS views
            Package_To_Finalize.Behaviors.Add_View(View_Enum.CITATION);
            Package_To_Finalize.Behaviors.Add_View(View_Enum.TRACKING);
            Package_To_Finalize.Behaviors.Add_View(View_Enum.TRACKING_SHEET);
            Package_To_Finalize.Behaviors.Add_View(View_Enum.GOOGLE_COORDINATE_ENTRY);
            Package_To_Finalize.Behaviors.Add_View(View_Enum.TEST);
            Package_To_Finalize.Behaviors.Add_View(View_Enum.MANAGE);

            // Add the full text searchable
            if ( Package_To_Finalize.Behaviors.Text_Searchable )
                Package_To_Finalize.Behaviors.Add_View(View_Enum.SEARCH);

            // Is there an embedded video?
            if (Package_To_Finalize.Behaviors.Embedded_Video.Length > 0)
                Package_To_Finalize.Behaviors.Add_View(View_Enum.EMBEDDED_VIDEO);

            // If there is no PURL, add one based on how SobekCM operates
            if (Package_To_Finalize.Bib_Info.Location.PURL.Length == 0)
            {
                Package_To_Finalize.Bib_Info.Location.PURL = Engine_ApplicationCache_Gateway.Settings.Servers.System_Base_URL + Package_To_Finalize.BibID + "/" + Package_To_Finalize.VID;

            }

            // If this is a newspaper, and there is no datecreated, see if we
            // can make one from the  serial hierarchy
            if (Package_To_Finalize.Behaviors.GroupType.ToUpper() == "NEWSPAPER")
            {
                if ((Package_To_Finalize.Bib_Info.Origin_Info.Date_Created.Length == 0) && (Package_To_Finalize.Bib_Info.Origin_Info.Date_Issued.Length == 0))
                {
                    // Is the serial hierarchy three deep?
                    if (Package_To_Finalize.Behaviors.hasSerialInformation)
                    {
                        if (Package_To_Finalize.Behaviors.Serial_Info.Count == 3)
                        {
                            int year;

                            if (Int32.TryParse(Package_To_Finalize.Behaviors.Serial_Info[0].Display, out year))
                            {
                                int day;
                                if (Int32.TryParse(Package_To_Finalize.Behaviors.Serial_Info[2].Display, out day))
                                {
                                    if ((year > 0) && (year < DateTime.Now.Year + 2) && ( day > 0 ) && ( day <= 31 ))
                                    {
                                        // Is the month a number?
                                        int month;
                                        if (Int32.TryParse(Package_To_Finalize.Behaviors.Serial_Info[1].Display, out month))
                                        {
                                            try
                                            {
                                                // Do it this way since hopefully that will work for localization issues
                                                DateTime date = new DateTime(year, month, day);
                                                Package_To_Finalize.Bib_Info.Origin_Info.Date_Created = date.ToShortDateString();
                                            }
                                            catch
                                            {
                                                // If this is an invalid date, catch the error and do nothing
                                            }
                                        }
                                        else
                                        {
                                            Package_To_Finalize.Bib_Info.Origin_Info.Date_Created = Package_To_Finalize.Behaviors.Serial_Info[1].Display + " " + day + ", " + year;
                                        }
                                    }
                                }
                            }
                        }
                        else if ( Package_To_Finalize.Behaviors.Serial_Info.Count == 2 )
                        {
                            int year;
                            if (Int32.TryParse(Package_To_Finalize.Behaviors.Serial_Info[0].Display, out year))
                            {
                                if ((year > 0) && (year < DateTime.Now.Year + 2) && ( Package_To_Finalize.Behaviors.Serial_Info[1].Display.Length > 0 ))
                                {
                                    Package_To_Finalize.Bib_Info.Origin_Info.Date_Created = Package_To_Finalize.Behaviors.Serial_Info[1].Display + " " + year;
                                }
                            }
                        }
                    }
                }
            }

            // IF this is dark, add no other views
            if (Package_To_Finalize.Behaviors.Dark_Flag) return;

            // Check to see which views were present from the database, and build the list
            Dictionary<View_Enum, View_Object> viewsFromDb = new Dictionary<View_Enum, View_Object>();
            foreach (DataRow viewRow in DatabaseInfo.Tables[4].Rows)
            {
                string viewType = viewRow[0].ToString();
                string attribute = viewRow[1].ToString();
                string label = viewRow[2].ToString();

                View_Enum viewTypeEnum = View_Enum.None;
                switch (viewType)
                {
                    case "Dataset Codebook":
                        viewTypeEnum = View_Enum.DATASET_CODEBOOK;
                        break;

                    case "Dataset Reports":
                        viewTypeEnum = View_Enum.DATASET_REPORTS;
                        break;

                    case "Dataset View Data":
                        viewTypeEnum = View_Enum.DATASET_VIEWDATA;
                        break;

                    case "Google Map":
                        viewTypeEnum = View_Enum.GOOGLE_MAP;
                        break;

                    case "Google Map Beta":
                        viewTypeEnum = View_Enum.GOOGLE_MAP_BETA;
                        break;

                    case "HTML Viewer":
                        viewTypeEnum = View_Enum.HTML;
                        break;

                    case "JPEG":
                        viewTypeEnum = View_Enum.JPEG;
                        break;

                    case "JPEG/Text Two Up":
                        viewTypeEnum = View_Enum.JPEG_TEXT_TWO_UP;
                        break;

                    case "JPEG2000":
                        viewTypeEnum = View_Enum.JPEG2000;
                        break;

                    case "Page Turner":
                        viewTypeEnum = View_Enum.PAGE_TURNER;
                        break;

                    case "Related Images":
                        viewTypeEnum = View_Enum.RELATED_IMAGES;
                        break;

                    case "TEI":
                        viewTypeEnum = View_Enum.TEI;
                        break;

                    case "Text":
                        viewTypeEnum = View_Enum.TEXT;
                        break;

                    case "TOC":
                        viewTypeEnum = View_Enum.TOC;
                        break;
                }

                if (viewTypeEnum != View_Enum.None)
                {
                    viewsFromDb[viewTypeEnum] = new View_Object(viewTypeEnum, label, attribute);
                }
            }

            // Add the dataset views (later we should do some checking here, but for
            // now just add them if the user selected them.
            if (viewsFromDb.ContainsKey(View_Enum.DATASET_VIEWDATA))
            {
                Package_To_Finalize.Behaviors.Add_View(viewsFromDb[View_Enum.DATASET_VIEWDATA]);
                viewsFromDb.Remove(View_Enum.DATASET_VIEWDATA);
            }
            if (viewsFromDb.ContainsKey(View_Enum.DATASET_CODEBOOK))
            {
                Package_To_Finalize.Behaviors.Add_View(viewsFromDb[View_Enum.DATASET_CODEBOOK]);
                viewsFromDb.Remove(View_Enum.DATASET_CODEBOOK);
            }
            if (viewsFromDb.ContainsKey(View_Enum.DATASET_REPORTS))
            {
                Package_To_Finalize.Behaviors.Add_View(viewsFromDb[View_Enum.DATASET_REPORTS]);
                viewsFromDb.Remove(View_Enum.DATASET_REPORTS);
            }

            // Add the thumbnail view, if requested and has multiple pages
            if (Package_To_Finalize.Divisions.Page_Count > 1)
            {
                if (viewsFromDb.ContainsKey(View_Enum.RELATED_IMAGES))
                {
                    Package_To_Finalize.Behaviors.Add_View(viewsFromDb[View_Enum.RELATED_IMAGES]);
                    viewsFromDb.Remove(View_Enum.RELATED_IMAGES);
                }
            }
            else
            {
                if (viewsFromDb.ContainsKey(View_Enum.RELATED_IMAGES))
                {
                    viewsFromDb.Remove(View_Enum.RELATED_IMAGES);
                }
            }

            // Always add the QC viewer ( the QC viewer will redirect to upload files if there are NO pages)
            Package_To_Finalize.Behaviors.Add_View(View_Enum.QUALITY_CONTROL);

            // If this item has more than one division, look for the TOC viewer
            if ((Package_To_Finalize.Divisions.Has_Multiple_Divisions) && (!Package_To_Finalize.Bib_Info.ImageClass))
            {
                if (viewsFromDb.ContainsKey(View_Enum.TOC))
                {
                    Package_To_Finalize.Behaviors.Add_View(viewsFromDb[View_Enum.TOC]);
                    viewsFromDb.Remove(View_Enum.TOC);
                }
            }

            // In addition, if there is a latitude or longitude listed, look for the Google Maps
            bool hasCoords = false;
            GeoSpatial_Information geoInfo = (GeoSpatial_Information) Package_To_Finalize.Get_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY);
            if (( geoInfo != null ) && ( geoInfo.hasData ))
            {
                if ((geoInfo.Point_Count > 0) || (geoInfo.Polygon_Count > 0))
                {
                    hasCoords = true;
                }
            }
            if (!hasCoords)
            {
                List<abstract_TreeNode> pageList = Package_To_Finalize.Divisions.Physical_Tree.Pages_PreOrder;
                if (pageList.Select(ThisPage => (GeoSpatial_Information) ThisPage.Get_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY)).Where(GeoInfo2 => (GeoInfo2 != null) && (GeoInfo2.hasData)).Any(GeoInfo2 => (GeoInfo2.Point_Count > 0) || (GeoInfo2.Polygon_Count > 0)))
                {
                    hasCoords = true;
                }
            }

            if (hasCoords)
            {
                if (viewsFromDb.ContainsKey(View_Enum.GOOGLE_MAP))
                {
                    Package_To_Finalize.Behaviors.Add_View(viewsFromDb[View_Enum.GOOGLE_MAP]);
                    viewsFromDb.Remove(View_Enum.GOOGLE_MAP);
                }
                else
                {
                    Package_To_Finalize.Behaviors.Add_View(View_Enum.GOOGLE_MAP);
                }
            }

            // Step through each download and make sure it is fully built
            if (( !Package_To_Finalize.Behaviors.Dark_Flag ) && ( Package_To_Finalize.Divisions.Download_Tree.Has_Files))
            {
                string ead_file = String.Empty;
                int pdf_download = 0;
                int video_download = 0;
                string pdf_download_url = String.Empty;
                List<abstract_TreeNode> downloadPages = Package_To_Finalize.Divisions.Download_Tree.Pages_PreOrder;
                string xsl = String.Empty;

                // Keep track of all the unhandled downloads, which will casue a DOWNLOAD tab to appear
                List<abstract_TreeNode> unhandledDownload = new List<abstract_TreeNode>();

                // Step through each download page
                foreach (Page_TreeNode downloadPage in downloadPages)
                {
                    bool download_handled = false;

                    // If this page has only a single file, might be handled by a single viewer
                    if ((!download_handled) && (downloadPage.Files.Count == 1))
                    {
                        string extension = downloadPage.Files[0].File_Extension;

                        // Was this an EAD page?
                        switch (extension)
                        {
                            case "XML":
                                if (downloadPage.Label == "EAD")
                                {
                                    Package_To_Finalize.Bib_Info.SobekCM_Type = TypeOfResource_SobekCM_Enum.EAD;
                                    ead_file = downloadPage.Files[0].System_Name;
                                    download_handled = true;
                                }
                                break;

                            case "SWF":
                                // FLASH files are always handled
                                string flashlabel = downloadPage.Label;
                                Package_To_Finalize.Behaviors.Add_View(View_Enum.FLASH, flashlabel, String.Empty, downloadPage.Files[0].System_Name);
                                download_handled = true;
                                break;

                            case "PDF":
                                pdf_download++;
                                if (pdf_download == 1)
                                {
                                    pdf_download_url = downloadPage.Files[0].System_Name;
                                    download_handled = true;
                                }
                                break;

                            case "XSL":
                                xsl = downloadPage.Files[0].System_Name;
                                download_handled = true;
                                break;

                            case "HTML":
                            case "HTM":
                                if (viewsFromDb.ContainsKey(View_Enum.HTML))
                                {
                                    if (String.Compare(viewsFromDb[View_Enum.HTML].Attributes, downloadPage.Files[0].System_Name, StringComparison.InvariantCultureIgnoreCase) == 0)
                                    {
                                        download_handled = true;
                                    }
                                }
                                break;

                            case "WEBM":
                            case "OGG":
                            case "MP4":
                            //case "AVI":
                            //case "WMV":
                            //case "MPG":
                            //case "MOV":
                            //case "FLV":
                            //case "VOB":
                            //case "WAV":
                            //case "OGM":
                            //case "MKV":
                                video_download++;
                                download_handled = true;
                                break;
                        }
                    }

                    // Check for video files
                    if ((!download_handled) && ( downloadPage.Files != null ))
                    {
                        foreach (SobekCM_File_Info thisFileInfo in downloadPage.Files)
                        {
                            string extension = thisFileInfo.File_Extension;

                            // Was this an EAD page?
                            switch (extension)
                            {
                                case "WEBM":
                                case "OGG":
                                case "MP4":
                                    //case "AVI":
                                    //case "WMV":
                                    //case "MPG":
                                    //case "MOV":
                                    //case "FLV":
                                    //case "VOB":
                                    //case "WAV":
                                    //case "OGM":
                                    //case "MKV":
                                    video_download++;
                                    download_handled = true;
                                    break;
                            }

                            if (download_handled)
                                break;
                        }
                    }

                    // Step through each download file
                    if (!download_handled)
                    {
                        unhandledDownload.Add(downloadPage);

                        foreach (SobekCM_File_Info thisFile in downloadPage.Files)
                        {
                            if (thisFile.File_Extension == "SWF")
                            {
                                string flashlabel = downloadPage.Label;
                                Package_To_Finalize.Behaviors.Add_View(View_Enum.FLASH, flashlabel, String.Empty, thisFile.System_Name);
                            }

                            if (thisFile.File_Extension == "PDF")
                            {
                                pdf_download++;
                                if (pdf_download == 1)
                                {
                                    pdf_download_url = thisFile.System_Name;
                                }
                            }

                        }
                    }
                }

                // Some special code for EAD objects
                if ((Package_To_Finalize.Bib_Info.SobekCM_Type == TypeOfResource_SobekCM_Enum.EAD) && (ead_file.Length > 0))
                {
                    // Now, read this EAD file information
                    string ead_file_location = Engine_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + Package_To_Finalize.Web.AssocFilePath + ead_file;
                    EAD_File_ReaderWriter reader = new EAD_File_ReaderWriter();
                    string errorMessage;
                    Dictionary<string, object> options = new Dictionary<string, object>();
                    options["EAD_File_ReaderWriter:XSL_Location"] = Engine_ApplicationCache_Gateway.Settings.Servers.System_Base_URL + "default/sobekcm_default.xsl";

                    reader.Read_Metadata(ead_file_location, Package_To_Finalize, options, out errorMessage);

                    // Clear all existing views
                    Package_To_Finalize.Behaviors.Add_View(View_Enum.EAD_DESCRIPTION);

                    // Get the metadata module for EADs
                    EAD_Info eadInfo = Package_To_Finalize.Get_Metadata_Module(GlobalVar.EAD_METADATA_MODULE_KEY) as EAD_Info;
                    if ((eadInfo != null) && (eadInfo.Container_Hierarchy.Containers.Count > 0))
                        Package_To_Finalize.Behaviors.Add_View(View_Enum.EAD_CONTAINER_LIST);

                }

                //string view_type_of = Package_To_Finalize.Behaviors.Views[0].GetType().ToString();
                //string ufdc_type_of = Package_To_Finalize.Behaviors.Views[0].View_Type.ToString();

                if (unhandledDownload.Count > 0 )
                {
                    Package_To_Finalize.Behaviors.Add_View(View_Enum.DOWNLOADS);
                }

                if (pdf_download == 1)
                {
                    Package_To_Finalize.Behaviors.Add_View(View_Enum.PDF).FileName = pdf_download_url;
                }

                if (video_download > 0)
                {
                    Package_To_Finalize.Behaviors.Add_View(View_Enum.VIDEO);
                }
            }
            else
            {
                if (Package_To_Finalize.Bib_Info.SobekCM_Type == TypeOfResource_SobekCM_Enum.Aerial )
                {
                    Package_To_Finalize.Behaviors.Add_View(View_Enum.DOWNLOADS);
                }
            }

            // If there is a RELATED URL with youtube, add that viewer
            if ((Package_To_Finalize.Bib_Info.hasLocationInformation) && (Package_To_Finalize.Bib_Info.Location.Other_URL.ToLower().IndexOf("www.youtube.com") >= 0))
            {
                View_Object newViewObj = new View_Object(View_Enum.YOUTUBE_VIDEO);
                Package_To_Finalize.Behaviors.Add_View(newViewObj);
            }

            // Look for the HTML type views next, and possible set some defaults
            if ((!Package_To_Finalize.Behaviors.Dark_Flag) && viewsFromDb.ContainsKey(View_Enum.HTML))
            {
                Package_To_Finalize.Behaviors.Add_View(viewsFromDb[View_Enum.HTML]);
                viewsFromDb.Remove(View_Enum.HTML);
            }

            // Copy the TEI flag
            if ((!Package_To_Finalize.Behaviors.Dark_Flag) && viewsFromDb.ContainsKey(View_Enum.TEI))
            {
                Package_To_Finalize.Behaviors.Add_View(viewsFromDb[View_Enum.TEI]);
                viewsFromDb.Remove(View_Enum.TEI);
            }

            // Look to add any index information here ( such as on SANBORN maps)
            Map_Info mapInfo = (Map_Info) Package_To_Finalize.Get_Metadata_Module(GlobalVar.SOBEKCM_MAPS_METADATA_MODULE_KEY);
            if (mapInfo != null)
            {
                //// Were there streets?
                //if (Package_To_Finalize.Map.Streets.Count > 0)
                //{
                //    returnValue.Item_Views.Add(new ViewerFetcher.Streets_ViewerFetcher());
                //}

                //// Were there features?
                //if (Package_To_Finalize.Map.Features.Count > 0)
                //{
                //    returnValue.Item_Views.Add(new ViewerFetcher.Features_ViewerFetcher());
                //}
            }

            // Finally, add all the ITEM VIEWS
            if ((!Package_To_Finalize.Behaviors.Dark_Flag) && (Package_To_Finalize.Web.Pages_By_Sequence != null) && (Package_To_Finalize.Web.Pages_By_Sequence.Count > 0))
            {
                // Look for the RELATED IMAGES view next
                if (viewsFromDb.ContainsKey(View_Enum.RELATED_IMAGES))
                {
                    Package_To_Finalize.Behaviors.Add_View(viewsFromDb[View_Enum.RELATED_IMAGES]);
                    viewsFromDb.Remove(View_Enum.RELATED_IMAGES);
                }

                // Look for the PAGE TURNER view next
                if (viewsFromDb.ContainsKey(View_Enum.PAGE_TURNER))
                {
                    Package_To_Finalize.Behaviors.Add_View(viewsFromDb[View_Enum.PAGE_TURNER]);
                    viewsFromDb.Remove(View_Enum.PAGE_TURNER);
                }

                // Add the individual PAGE VIEWS
                foreach (View_Object thisObject in viewsFromDb.Values)
                {
                    switch (thisObject.View_Type)
                    {
                        case View_Enum.TEXT:
                        case View_Enum.JPEG:
                        case View_Enum.JPEG2000:
                            Package_To_Finalize.Behaviors.Add_Item_Level_Page_View(thisObject);
                            break;
                    }
                }
            }

            // Set the default views for this item
            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Set the default view, if not already assigned");
            Package_To_Finalize.Behaviors.Default_View = null;
            Dictionary<string, View_Object> views_by_view_name = new Dictionary<string, View_Object>();
            foreach (View_Object thisView in Package_To_Finalize.Behaviors.Views)
            {
                if (!views_by_view_name.ContainsKey(thisView.View_Type.ToString()))
                    views_by_view_name[thisView.View_Type.ToString()] = thisView;
            }
            foreach (View_Object thisView in Package_To_Finalize.Behaviors.Item_Level_Page_Views)
            {
                if (!views_by_view_name.ContainsKey(thisView.View_Type.ToString()))
                    views_by_view_name[thisView.View_Type.ToString()] = thisView;
            }

            //If no viewer priorities have been passed in, add the default one
            if (Item_Viewer_Priority == null)
            {
                //TODO: Add default view here if present
               // if (views_by_view_name != null)
               //     Package_To_Finalize.Behaviors.Default_View =
            }
            else
            {
                foreach (string thisViewerType in Item_Viewer_Priority)
                {
                    if (views_by_view_name.ContainsKey(thisViewerType))
                    {
                        Package_To_Finalize.Behaviors.Default_View = views_by_view_name[thisViewerType];
                        break;
                    }
                }
            }

            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Done merging the database information with the resource object");
        }
        /// <summary> Saves the data rendered by this element to the provided bibliographic object during postback </summary>
        /// <param name="Bib"> Object into which to save the user's data, entered into the html rendered by this element </param>
        public override void Save_To_Bib(SobekCM_Item Bib)
        {
            // Try to get any existing VRAcore metadata module
            VRACore_Info vraInfo = Bib.Get_Metadata_Module(GlobalVar.VRACORE_METADATA_MODULE_KEY) as VRACore_Info;

            Dictionary<string, string> terms = new Dictionary<string, string>();
            Dictionary<string, string> schemes = new Dictionary<string, string>();

            string[] getKeys = HttpContext.Current.Request.Form.AllKeys;
            foreach (string thisKey in getKeys)
            {
                if (thisKey.IndexOf(html_element_name.Replace("_", "") + "_first") == 0)
                {
                    string term = HttpContext.Current.Request.Form[thisKey];
                    string index = thisKey.Replace(html_element_name.Replace("_", "") + "_first", "");
                    terms[index] = term;
                }

                if (thisKey.IndexOf(html_element_name.Replace("_", "") + "_second") == 0)
                {
                    string scheme = HttpContext.Current.Request.Form[thisKey];
                    string index = thisKey.Replace(html_element_name.Replace("_", "") + "_second", "");
                    schemes[index] = scheme;
                }
            }

            // Were values found?
            if (terms.Count > 0)
            {
                // There is a value, so ensure VRAcore metadata does exist
                if (vraInfo == null)
                {
                    vraInfo = new VRACore_Info();
                    Bib.Add_Metadata_Module(GlobalVar.VRACORE_METADATA_MODULE_KEY, vraInfo);
                }

                // Add each value
                foreach (string index in terms.Keys)
                {
                    vraInfo.Add_Measurement( terms[index], schemes.ContainsKey(index) ? schemes[index] : String.Empty);
                }
            }
        }
        /// <summary> Saves the data rendered by this element to the provided bibliographic object during postback </summary>
        /// <param name="Bib"> Object into which to save the user's data, entered into the html rendered by this element </param>
        public override void Save_To_Bib(SobekCM_Item Bib)
        {
            List<Coordinate_Point> points = new List<Coordinate_Point>();

            string[] getKeys = HttpContext.Current.Request.Form.AllKeys;
            string latitude = String.Empty;
            foreach (string thisKey in getKeys)
            {
                if (thisKey.IndexOf(html_element_name.Replace("_", "") + "_first") == 0)
                {
                    latitude = HttpContext.Current.Request.Form[thisKey];
                }

                if (thisKey.IndexOf(html_element_name.Replace("_", "") + "_second") != 0) continue;

                string longitude = HttpContext.Current.Request.Form[thisKey];
                if ((latitude.Length > 0) && ( longitude.Length > 0 ))
                {
                    double latitude_double, longitude_double;
                    if ((Double.TryParse(latitude, out latitude_double)) && (Double.TryParse(longitude, out longitude_double)))
                        points.Add(new Coordinate_Point(latitude_double, longitude_double));
                    latitude = String.Empty;
                }
            }

            // GEt the geospatial metadata module
            if (points.Count > 0)
            {
                GeoSpatial_Information geoInfo = Bib.Get_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY) as GeoSpatial_Information;
                if (geoInfo == null)
                {
                    geoInfo = new GeoSpatial_Information();
                    Bib.Add_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY, geoInfo);
                }

                foreach (Coordinate_Point thisPoint in points)
                {
                    geoInfo.Add_Point( thisPoint );
                }
            }
        }
        /// <summary> Saves the data rendered by this element to the provided bibliographic object during postback </summary>
        /// <param name="Bib"> Object into which to save the user's data, entered into the html rendered by this element </param>
        public override void Save_To_Bib(SobekCM_Item Bib)
        {
            // Try to get any existing learning object metadata module
            LearningObjectMetadata lomInfo = Bib.Get_Metadata_Module(GlobalVar.IEEE_LOM_METADATA_MODULE_KEY) as LearningObjectMetadata;

            string[] getKeys = HttpContext.Current.Request.Form.AllKeys;
            foreach (string thisKey in getKeys)
            {
                if (thisKey.IndexOf(html_element_name.Replace("_", "")) == 0)
                {
                    // Get the value from the combo box
                    string value = HttpContext.Current.Request.Form[thisKey].Trim();
                    if (value.Length > 0)
                    {
                        // There is a value, so ensure learning object metadata does exist
                        if (lomInfo == null)
                        {
                            lomInfo = new LearningObjectMetadata();
                            Bib.Add_Metadata_Module(GlobalVar.IEEE_LOM_METADATA_MODULE_KEY, lomInfo);
                        }

                        // Save the new value
                        switch (value)
                        {
                            case level1_text:
                                lomInfo.Add_IntendedEndUserRole(IntendedEndUserRoleEnum.teacher);
                                break;

                            case level2_text:
                                lomInfo.Add_IntendedEndUserRole(IntendedEndUserRoleEnum.author);
                                break;

                            case level3_text:
                                lomInfo.Add_IntendedEndUserRole(IntendedEndUserRoleEnum.learner);
                                break;

                            case level4_text:
                                lomInfo.Add_IntendedEndUserRole(IntendedEndUserRoleEnum.manager);
                                break;
                        }
                    }
                }
            }
        }
        /// <summary> Adds a bit of data to a bibliographic package using the mapping </summary>
        /// <param name="Package">Bibliographic package to receive the data</param>
        /// <param name="Data">Text of the data</param>
        /// <param name="Field">Mapped field</param>
        public static void Add_Data(SobekCM_Item Package, string Data, Mapped_Fields Field)
        {
            Data = Data.Trim();
            if (Data.Length == 0)
                return;

            // Everything depends on the field which is mapped
            switch (Field)
            {
                case Mapped_Fields.None:
                    // Do nothing, since no mapping exists
                    break;

                case Mapped_Fields.Abstract:
                    Package.Bib_Info.Add_Abstract(Data, "en");
                    break;
                case Mapped_Fields.Accession_Number:
                    Package.Bib_Info.Add_Identifier(Data, "Accession Number");
                    break;
                case Mapped_Fields.Alternate_Title:
                    Package.Bib_Info.Add_Other_Title(Data, Title_Type_Enum.alternative);
                    break;
                case Mapped_Fields.Alternate_Title_Language:
                    List<Title_Info> otherTitles = Package.Bib_Info.Other_Titles.Where(ThisTitle => ThisTitle.Title_Type == Title_Type_Enum.alternative).ToList();
                    if (otherTitles.Count > 0)
                    {
                        otherTitles[otherTitles.Count - 1].Language = Data;
                    }
                    break;
                case Mapped_Fields.Attribution:
                    Package.Bib_Info.Add_Note(Data, Note_Type_Enum.funding);
                    break;
                case Mapped_Fields.Aggregation_Code:
                    Package.Behaviors.Add_Aggregation(Data.ToUpper());
                    break;
                case Mapped_Fields.Classification:
                    Package.Bib_Info.Add_Classification(Data);
                    break;
                case Mapped_Fields.Classification_Authority:
                    if (Package.Bib_Info.Classifications_Count > 0)
                    {
                        Package.Bib_Info.Classifications[Package.Bib_Info.Classifications_Count - 1].Authority = Data;
                    }
                    break;
                case Mapped_Fields.Contributor:
                    Package.Bib_Info.Add_Named_Entity(new Name_Info(Data, "contributor"));
                    break;
                case Mapped_Fields.Creator:
                    Package.Bib_Info.Add_Named_Entity(new Name_Info(Data, "creator"));
                    break;
                case Mapped_Fields.Creator_Affiliation:
                    if (Package.Bib_Info.Names_Count > 0)
                    {
                        Package.Bib_Info.Names[Package.Bib_Info.Names_Count - 1].Affiliation = Data;
                    }
                    break;
                case Mapped_Fields.Creator_Dates:
                    if (Package.Bib_Info.Names_Count > 0)
                    {
                        Package.Bib_Info.Names[Package.Bib_Info.Names_Count - 1].Dates = Data;
                    }
                    break;
                case Mapped_Fields.Creator_Family_Name:
                    if (Package.Bib_Info.Names_Count > 0)
                    {
                        Name_Info lastNamedEntity = Package.Bib_Info.Names[Package.Bib_Info.Names_Count - 1];
                        if (lastNamedEntity.Family_Name.Length == 0)
                            lastNamedEntity.Family_Name = Data;
                        else
                        {
                            Name_Info newNameEntity = new Name_Info {Family_Name = Data};
                            Package.Bib_Info.Add_Named_Entity(newNameEntity);
                        }
                    }
                    else
                    {
                        Name_Info newNameEntity = new Name_Info {Family_Name = Data};
                        Package.Bib_Info.Add_Named_Entity(newNameEntity);
                    }
                    break;
                case Mapped_Fields.Creator_Given_Name:
                    if (Package.Bib_Info.Names_Count > 0)
                    {
                        Name_Info lastNamedEntity = Package.Bib_Info.Names[Package.Bib_Info.Names_Count - 1];
                        if (lastNamedEntity.Given_Name.Length == 0)
                            lastNamedEntity.Given_Name = Data;
                        else
                        {
                            Name_Info newNameEntity = new Name_Info {Given_Name = Data};
                            Package.Bib_Info.Add_Named_Entity(newNameEntity);
                        }
                    }
                    else
                    {
                        Name_Info newNameEntity = new Name_Info {Given_Name = Data};
                        Package.Bib_Info.Add_Named_Entity(newNameEntity);
                    }
                    break;
                case Mapped_Fields.Creator_Role:
                    if (Package.Bib_Info.Names_Count > 0)
                    {
                        Name_Info thisCreator = Package.Bib_Info.Names[Package.Bib_Info.Names_Count - 1];
                        if ((thisCreator.Roles.Count == 1) && ((thisCreator.Roles[0].Role == "creator") || (thisCreator.Roles[1].Role == "contributor")))
                            thisCreator.Roles.Clear();
                        Package.Bib_Info.Names[Package.Bib_Info.Names_Count - 1].Add_Role(Data);
                    }
                    break;
                case Mapped_Fields.Cultural_Context:
                    VRACore_Info vraCoreInfo = Package.Get_Metadata_Module("VRACore") as VRACore_Info;
                    if (vraCoreInfo == null)
                    {
                        vraCoreInfo = new VRACore_Info();
                        Package.Add_Metadata_Module("VRACore", vraCoreInfo);
                    }
                    vraCoreInfo.Add_Cultural_Context(Data);
                    break;
                case Mapped_Fields.Donor:
                    Package.Bib_Info.Donor.Full_Name = Data;
                    break;
                case Mapped_Fields.Genre:
                    Package.Bib_Info.Add_Genre(Data);
                    break;
                case Mapped_Fields.Genre_Authority:
                    if (Package.Bib_Info.Genres_Count > 0)
                    {
                        Package.Bib_Info.Genres[Package.Bib_Info.Genres_Count - 1].Authority = Data;
                    }
                    break;
                case Mapped_Fields.Holding_Code:
                    Package.Bib_Info.Location.Holding_Code = Data;
                    break;
                case Mapped_Fields.Holding_Statement:
                    Package.Bib_Info.Location.Holding_Name = Data;
                    break;
                case Mapped_Fields.Identifier:
                    Package.Bib_Info.Add_Identifier(Data);
                    break;
                case Mapped_Fields.Identifier_Type:
                    if (Package.Bib_Info.Identifiers_Count > 0)
                    {
                        Package.Bib_Info.Identifiers[Package.Bib_Info.Identifiers_Count - 1].Type = Data;
                    }
                    break;
                case Mapped_Fields.Inscription:
                    VRACore_Info vraCoreInfo8 = Package.Get_Metadata_Module("VRACore") as VRACore_Info;
                    if (vraCoreInfo8 == null)
                    {
                        vraCoreInfo8 = new VRACore_Info();
                        Package.Add_Metadata_Module("VRACore", vraCoreInfo8);
                    }
                    vraCoreInfo8.Add_Inscription(Data);
                    break;
                case Mapped_Fields.Language:
                    Package.Bib_Info.Add_Language(Data);
                    break;
                case Mapped_Fields.Publisher:
                    Package.Bib_Info.Add_Publisher(Data);
                    break;
                case Mapped_Fields.Pub_Place:
                    Package.Bib_Info.Origin_Info.Add_Place(Data);
                    break;
                case Mapped_Fields.Related_URL_Label:
                    Package.Bib_Info.Location.Other_URL_Display_Label = Data;
                    break;
                case Mapped_Fields.Related_URL_Link:
                    Package.Bib_Info.Location.Other_URL = Data;
                    break;
                case Mapped_Fields.Related_URL_Note:
                    Package.Bib_Info.Location.Other_URL_Note = Data;
                    break;
                case Mapped_Fields.Source_Code:
                    Package.Bib_Info.Source.Code = Data;
                    break;
                case Mapped_Fields.Source_Statement:
                    Package.Bib_Info.Source.Statement = Data;
                    break;
                case Mapped_Fields.Subject_Keyword:
                    Package.Bib_Info.Add_Subject(Data, String.Empty);
                    break;
                case Mapped_Fields.Subject_Keyword_Authority:
                    if (Package.Bib_Info.Subjects_Count > 0)
                    {
                        Package.Bib_Info.Subjects[Package.Bib_Info.Subjects_Count - 1].Authority = Data;
                    }
                    break;
                case Mapped_Fields.BibID:
                    Package.Bib_Info.BibID = Data.ToUpper();
                    break;
                case Mapped_Fields.VID:
                    Package.Bib_Info.VID = Data.PadLeft(5, '0');
                    break;
                case Mapped_Fields.Date:
                    try
                    {
                        // first, try converting the string value to a date object
                        Package.Bib_Info.Origin_Info.Date_Issued = Convert.ToDateTime(Data).ToShortDateString();
                    }
                    catch
                    {
                        try
                        {
                            // second, try converting the string value to an integer
                            Package.Bib_Info.Origin_Info.Date_Issued = Convert.ToInt32(Data).ToString();
                        }
                        catch
                        {
                            Package.Bib_Info.Origin_Info.Date_Issued = Data;
                        }
                    }
                    break;
                case Mapped_Fields.Edition:
                    Package.Bib_Info.Origin_Info.Edition = Data;
                    break;
                case Mapped_Fields.Format:
                    Package.Bib_Info.Original_Description.Extent = Data;
                    break;
                case Mapped_Fields.Note:
                    Package.Bib_Info.Add_Note(Data);
                    break;
                case Mapped_Fields.Rights:
                    Package.Bib_Info.Access_Condition.Text = Data;
                    break;
                case Mapped_Fields.Series_Title:
                    Package.Bib_Info.SeriesTitle.Title = Data;
                    Package.Behaviors.GroupTitle = Data;
                    break;
                case Mapped_Fields.Type:
                    string upper_data = Data.ToUpper();
                    if (upper_data.IndexOf("NEWSPAPER") >= 0)
                    {
                        Package.Bib_Info.SobekCM_Type = TypeOfResource_SobekCM_Enum.Newspaper;
                        break;
                    }
                    if ((upper_data.IndexOf("MONOGRAPH") >= 0) || (upper_data.IndexOf("BOOK") >= 0))
                    {
                        Package.Bib_Info.SobekCM_Type = TypeOfResource_SobekCM_Enum.Book;
                        break;
                    }
                    if (upper_data.IndexOf("SERIAL") >= 0)
                    {
                        Package.Bib_Info.SobekCM_Type = TypeOfResource_SobekCM_Enum.Serial;
                        break;
                    }
                    if (upper_data.IndexOf("AERIAL") >= 0)
                    {
                        Package.Bib_Info.SobekCM_Type = TypeOfResource_SobekCM_Enum.Aerial;
                        if (Package.Bib_Info.Original_Description.Extent.Length == 0)
                            Package.Bib_Info.Original_Description.Extent = "Aerial Photograph";
                        break;
                    }
                    if (upper_data.IndexOf("PHOTO") >= 0)
                    {
                        Package.Bib_Info.SobekCM_Type = TypeOfResource_SobekCM_Enum.Photograph;
                        break;
                    }
                    if (upper_data.IndexOf("POSTCARD") >= 0)
                    {
                        Package.Bib_Info.SobekCM_Type = TypeOfResource_SobekCM_Enum.Photograph;
                        if (Package.Bib_Info.Original_Description.Extent.Length == 0)
                            Package.Bib_Info.Original_Description.Extent = "Postcard";
                        break;
                    }
                    if (upper_data.IndexOf("MAP") >= 0)
                    {
                        Package.Bib_Info.SobekCM_Type = TypeOfResource_SobekCM_Enum.Map;
                        break;
                    }
                    if (upper_data.IndexOf("TEXT") >= 0)
                    {
                        Package.Bib_Info.SobekCM_Type = TypeOfResource_SobekCM_Enum.Book;
                        break;
                    }
                    if (upper_data.IndexOf("AUDIO") >= 0)
                    {
                        Package.Bib_Info.SobekCM_Type = TypeOfResource_SobekCM_Enum.Audio;
                        break;
                    }
                    if (upper_data.IndexOf("VIDEO") >= 0)
                    {
                        Package.Bib_Info.SobekCM_Type = TypeOfResource_SobekCM_Enum.Video;
                        break;
                    }
                    if ((upper_data.IndexOf("ARCHIVE") >= 0) || (upper_data.IndexOf("ARCHIVAL") >= 0))
                    {
                        Package.Bib_Info.SobekCM_Type = TypeOfResource_SobekCM_Enum.Archival;
                        break;
                    }
                    if (upper_data.IndexOf("ARTIFACT") >= 0)
                    {
                        Package.Bib_Info.SobekCM_Type = TypeOfResource_SobekCM_Enum.Artifact;
                        break;
                    }
                    if (upper_data.IndexOf("IMAGE") >= 0)
                    {
                        Package.Bib_Info.SobekCM_Type = TypeOfResource_SobekCM_Enum.Photograph;
                        break;
                    }

                    // if there was no match, set type to "UNDETERMINED"
                    Package.Bib_Info.SobekCM_Type = TypeOfResource_SobekCM_Enum.UNKNOWN;

                    if (Package.Bib_Info.Original_Description.Extent.Length == 0)
                        Package.Bib_Info.Original_Description.Extent = "Undetermined";
                    break;
                case Mapped_Fields.Uniform_Title:
                    Package.Bib_Info.Add_Other_Title(Data, Title_Type_Enum.uniform);
                    Package.Behaviors.GroupTitle = Data;
                    break;
                case Mapped_Fields.Title:
                    Package.Bib_Info.Main_Title.Title = Data;
                    break;
                case Mapped_Fields.Title_Language:
                    Package.Bib_Info.Main_Title.Language = Data;
                    break;
                case Mapped_Fields.Aleph:
                    Package.Bib_Info.Add_Identifier(Data, "ALEPH");
                    break;
                case Mapped_Fields.OCLC:
                    Package.Bib_Info.Add_Identifier(Data, "OCLC");
                    break;
                case Mapped_Fields.LCCN:
                    Package.Bib_Info.Add_Identifier(Data, "LCCN");
                    break;
                case Mapped_Fields.ISBN:
                    Package.Bib_Info.Add_Identifier(Data, "ISBN");
                    break;
                case Mapped_Fields.ISSN:
                    Package.Bib_Info.Add_Identifier(Data, "ISSN");
                    break;
                case Mapped_Fields.Sub_Title:
                    Package.Bib_Info.Main_Title.Subtitle = Data;
                    break;
                case Mapped_Fields.Volume:
                    Package.Bib_Info.Series_Part_Info.Enum1 = Data;
                    Package.Behaviors.Serial_Info.Add_Hierarchy(Package.Behaviors.Serial_Info.Count + 1, 1, Data);
                    break;
                case Mapped_Fields.Issue:
                    if (Package.Bib_Info.Series_Part_Info.Enum1.Length == 0)
                    {
                        Package.Bib_Info.Series_Part_Info.Enum1 = Data;
                    }
                    else
                    {
                        Package.Bib_Info.Series_Part_Info.Enum2 = Data;
                    }
                    Package.Behaviors.Serial_Info.Add_Hierarchy(Package.Behaviors.Serial_Info.Count + 1, 1, Data);
                    break;
                case Mapped_Fields.Section:
                    if (Package.Bib_Info.Series_Part_Info.Enum2.Length == 0)
                    {
                        if (Package.Bib_Info.Series_Part_Info.Enum1.Length == 0)
                            Package.Bib_Info.Series_Part_Info.Enum1 = Data;
                        else
                            Package.Bib_Info.Series_Part_Info.Enum2 = Data;
                    }
                    else
                    {
                        Package.Bib_Info.Series_Part_Info.Enum3 = Data;
                    }
                    Package.Behaviors.Serial_Info.Add_Hierarchy(Package.Behaviors.Serial_Info.Count + 1, 1, Data);
                    // Do nothing for now
                    break;

                case Mapped_Fields.Year:
                    Package.Bib_Info.Series_Part_Info.Year = Data;

                    if (Data.Length == 1)
                        year = "0" + Data;
                    else
                        year = Data;
                    build_date_string(Package);

                    break;

                case Mapped_Fields.Month:
                    Package.Bib_Info.Series_Part_Info.Month = Data;
                    month = Data;
                    build_date_string(Package);

                    break;

                case Mapped_Fields.Day:
                    Package.Bib_Info.Series_Part_Info.Day = Data;
                    day = Data;
                    build_date_string(Package);

                    break;

                case Mapped_Fields.Coordinates:
                    GeoSpatial_Information geoInfo = Package.Get_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY) as GeoSpatial_Information;
                    if (geoInfo == null)
                    {
                        geoInfo = new GeoSpatial_Information();
                        Package.Add_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY, geoInfo);
                    }
                    string[] coordinates = Data.Split(", ;".ToCharArray());
                    try
                    {
                        if (coordinates.Length == 2)
                        {
                            geoInfo.Add_Point(Convert.ToDouble(coordinates[0]), Convert.ToDouble(coordinates[1]), String.Empty);
                        }
                        else
                        {
                            coordinates = Data.Split(",;".ToCharArray());
                            if (coordinates.Length == 2)
                            {
                                geoInfo.Add_Point(Convert.ToDouble(coordinates[0]), Convert.ToDouble(coordinates[1]), String.Empty);
                            }
                        }
                    }
                    catch
                    {
                    }
                    break;

                case Mapped_Fields.Latitude:
                    GeoSpatial_Information geoInfo2 = Package.Get_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY) as GeoSpatial_Information;
                    if (geoInfo2 == null)
                    {
                        geoInfo2 = new GeoSpatial_Information();
                        Package.Add_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY, geoInfo2);
                    }
                    try
                    {
                        if (geoInfo2.Point_Count == 0)
                            geoInfo2.Add_Point(Convert.ToDouble(Data), 0, String.Empty);
                        else
                            geoInfo2.Points[0].Latitude = Convert.ToDouble(Data);
                    }
                    catch
                    {
                    }
                    break;

                case Mapped_Fields.Longitude:
                    GeoSpatial_Information geoInfo3 = Package.Get_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY) as GeoSpatial_Information;
                    if (geoInfo3 == null)
                    {
                        geoInfo3 = new GeoSpatial_Information();
                        Package.Add_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY, geoInfo3);
                    }
                    try
                    {
                        if (geoInfo3.Point_Count == 0)
                            geoInfo3.Add_Point(0, Convert.ToDouble(Data.Replace("°", "")), String.Empty);
                        else
                            geoInfo3.Points[0].Longitude = Convert.ToDouble(Data.Replace("°", ""));
                    }
                    catch
                    {
                    }
                    break;

                case Mapped_Fields.Projection:
                    Guarantee_Cartographics(Package).Projection = Data;
                    break;
                case Mapped_Fields.Scale:
                    Guarantee_Cartographics(Package).Scale = Data;
                    break;
                    //case Mapped_Fields.Spatial_Coverage:
                    //    Package.Bib_Info.Hierarchical_Spatials[0].Area = Data;
                    //    break;
                case Mapped_Fields.Icon_Wordmarks:
                case Mapped_Fields.Wordmark:
                    //    Package.Processing_Parameters.Icons.Add(Data, String.Empty);
                    Package.Behaviors.Add_Wordmark(Data);
                    break;
                case Mapped_Fields.Webskin:
                    Package.Behaviors.Add_Web_Skin(Data);
                    break;
                case Mapped_Fields.Temporal_Coverage:
                    Package.Bib_Info.Add_Temporal_Subject(-1, -1, Data);
                    break;
                case Mapped_Fields.Affiliation_University:
                    Guarantee_Affiliation_Collection(Package);
                    Package.Bib_Info.Affiliations[0].University = Data;
                    break;
                case Mapped_Fields.Affiliation_Campus:
                    Guarantee_Affiliation_Collection(Package);
                    Package.Bib_Info.Affiliations[0].Campus = Data;
                    break;
                case Mapped_Fields.Affiliation_College:
                    Guarantee_Affiliation_Collection(Package);
                    Package.Bib_Info.Affiliations[0].College = Data;
                    break;
                case Mapped_Fields.Affiliation_Unit:
                    Guarantee_Affiliation_Collection(Package);
                    Package.Bib_Info.Affiliations[0].Unit = Data;
                    break;
                case Mapped_Fields.Affiliation_Department:
                    Guarantee_Affiliation_Collection(Package);
                    Package.Bib_Info.Affiliations[0].Department = Data;
                    break;
                case Mapped_Fields.Affiliation_Institute:
                    Guarantee_Affiliation_Collection(Package);
                    Package.Bib_Info.Affiliations[0].Institute = Data;
                    break;
                case Mapped_Fields.Affiliation_Center:
                    Guarantee_Affiliation_Collection(Package);
                    Package.Bib_Info.Affiliations[0].Center = Data;
                    break;
                case Mapped_Fields.Affiliation_Section:
                    Guarantee_Affiliation_Collection(Package);
                    Package.Bib_Info.Affiliations[0].Section = Data;
                    break;
                case Mapped_Fields.Affiliation_Subsection:
                    Guarantee_Affiliation_Collection(Package);
                    Package.Bib_Info.Affiliations[0].SubSection = Data;
                    break;
                case Mapped_Fields.Geography_Continent:
                    Guarantee_Hierarchical_Spatial(Package).Continent = Data;
                    break;
                case Mapped_Fields.Geography_Country:
                    Guarantee_Hierarchical_Spatial(Package).Country = Data;
                    break;
                case Mapped_Fields.Geography_Province:
                    Guarantee_Hierarchical_Spatial(Package).Province = Data;
                    break;
                case Mapped_Fields.Geography_Region:
                    Guarantee_Hierarchical_Spatial(Package).Region = Data;
                    break;
                case Mapped_Fields.Geography_State:
                    Guarantee_Hierarchical_Spatial(Package).State = Data;
                    break;
                case Mapped_Fields.Geography_Territory:
                    Guarantee_Hierarchical_Spatial(Package).Territory = Data;
                    break;
                case Mapped_Fields.Geography_County:
                    Guarantee_Hierarchical_Spatial(Package).County = Data;
                    break;
                case Mapped_Fields.Geography_City:
                    Guarantee_Hierarchical_Spatial(Package).City = Data;
                    break;
                case Mapped_Fields.Geography_Island:
                    Guarantee_Hierarchical_Spatial(Package).Island = Data;
                    break;
                case Mapped_Fields.Geography_Area:
                    Guarantee_Hierarchical_Spatial(Package).Area = Data;
                    break;
                case Mapped_Fields.Copyright_Date:
                    Package.Bib_Info.Origin_Info.Date_Copyrighted = Data;
                    break;
                case Mapped_Fields.EAD_Name:
                    Package.Bib_Info.Location.EAD_Name = Data;
                    break;
                case Mapped_Fields.EAD_URL:
                    Package.Bib_Info.Location.EAD_URL = Data;
                    break;
                case Mapped_Fields.Internal_Comments:
                    Package.Tracking.Internal_Comments = Data;
                    break;
                case Mapped_Fields.Container_Box:
                    Package.Bib_Info.Add_Container("Box", Data, 1);
                    break;
                case Mapped_Fields.Container_Divider:
                    Package.Bib_Info.Add_Container("Divider", Data, 2);
                    break;
                case Mapped_Fields.Container_Folder:
                    Package.Bib_Info.Add_Container("Folder", Data, 3);
                    break;
                case Mapped_Fields.Viewer:
                    switch (Data.ToUpper().Replace("_"," ").Replace(" ",""))
                    {
                        case "JPEG":
                        case "JPG":
                            Package.Behaviors.Add_View(View_Enum.JPEG);
                            break;

                        case "JPEG2000":
                        case "JP2":
                            Package.Behaviors.Add_View(View_Enum.JPEG2000);
                            break;

                        case "PAGETURNER":
                            Package.Behaviors.Add_View(View_Enum.PAGE_TURNER);
                            break;

                        case "RELATEDIMAGES":
                        case "THUMBNAILS":
                            Package.Behaviors.Add_View(View_Enum.RELATED_IMAGES);
                            break;
                    }
                    break;
                case Mapped_Fields.Visibility:
                    switch (Data.ToUpper())
                    {
                        case "DARK":
                            Package.Behaviors.Dark_Flag = true;
                            Package.Behaviors.IP_Restriction_Membership = -1;
                            break;

                        case "PRIVATE":
                            Package.Behaviors.Dark_Flag = false;
                            Package.Behaviors.IP_Restriction_Membership = -1;
                            break;

                        case "PUBLIC":
                            Package.Behaviors.Dark_Flag = false;
                            Package.Behaviors.IP_Restriction_Membership = 0;
                            break;

                        case "RESTRICTED":
                            Package.Behaviors.Dark_Flag = false;
                            Package.Behaviors.IP_Restriction_Membership = 1;
                            break;
                    }
                    break;

                case Mapped_Fields.Tickler:
                    Package.Behaviors.Add_Tickler(Data);
                    break;

                case Mapped_Fields.Tracking_Box:
                    Package.Tracking.Tracking_Box = Data;
                    break;

                case Mapped_Fields.Born_Digital_Flag:
                    if (Data.ToUpper().Trim() == "TRUE")
                        Package.Tracking.Born_Digital = true;
                    break;

                case Mapped_Fields.Material_Received_Date:
                    DateTime materialReceivedDate;
                    if (DateTime.TryParse(Data, out materialReceivedDate))
                        Package.Tracking.Material_Received_Date = materialReceivedDate;
                    break;

                case Mapped_Fields.Materials:
                    VRACore_Info vraCoreInfo2 = Package.Get_Metadata_Module("VRACore") as VRACore_Info;
                    if (vraCoreInfo2 == null)
                    {
                        vraCoreInfo2 = new VRACore_Info();
                        Package.Add_Metadata_Module("VRACore", vraCoreInfo2);
                    }
                    vraCoreInfo2.Add_Material(Data, "medium");
                    break;

                case Mapped_Fields.Measurements:
                    VRACore_Info vraCoreInfo3 = Package.Get_Metadata_Module("VRACore") as VRACore_Info;
                    if (vraCoreInfo3 == null)
                    {
                        vraCoreInfo3 = new VRACore_Info();
                        Package.Add_Metadata_Module("VRACore", vraCoreInfo3);
                    }
                    vraCoreInfo3.Add_Measurement(Data, String.Empty);
                    break;

                case Mapped_Fields.State_Edition:
                    VRACore_Info vraCoreInfo4 = Package.Get_Metadata_Module("VRACore") as VRACore_Info;
                    if (vraCoreInfo4 == null)
                    {
                        vraCoreInfo4 = new VRACore_Info();
                        Package.Add_Metadata_Module("VRACore", vraCoreInfo4);
                    }
                    vraCoreInfo4.Add_State_Edition(Data);
                    break;

                case Mapped_Fields.Style_Period:
                    VRACore_Info vraCoreInfo5 = Package.Get_Metadata_Module("VRACore") as VRACore_Info;
                    if (vraCoreInfo5 == null)
                    {
                        vraCoreInfo5 = new VRACore_Info();
                        Package.Add_Metadata_Module("VRACore", vraCoreInfo5);
                    }
                    vraCoreInfo5.Add_Style_Period(Data);
                    break;

                case Mapped_Fields.Technique:
                    VRACore_Info vraCoreInfo6 = Package.Get_Metadata_Module("VRACore") as VRACore_Info;
                    if (vraCoreInfo6 == null)
                    {
                        vraCoreInfo6 = new VRACore_Info();
                        Package.Add_Metadata_Module("VRACore", vraCoreInfo6);
                    }
                    vraCoreInfo6.Add_Technique(Data);
                    break;
            }
        }
        /// <summary> Saves the data rendered by this element to the provided bibliographic object during postback </summary>
        /// <param name="Bib"> Object into which to save the user's data, entered into the html rendered by this element </param>
        public override void Save_To_Bib(SobekCM_Item Bib)
        {
            Zoological_Taxonomy_Info zooInfo = Bib.Get_Metadata_Module(GlobalVar.ZOOLOGICAL_TAXONOMY_METADATA_MODULE_KEY) as Zoological_Taxonomy_Info;
            if (zooInfo == null)
                zooInfo = new Zoological_Taxonomy_Info();

            string[] getKeys = HttpContext.Current.Request.Form.AllKeys;
            foreach (string thisKey in getKeys)
            {
                if (thisKey.IndexOf("formzootaxonkingdom_") == 0)
                {
                    string diff = thisKey.Replace("formzootaxonkingdom_", "");

                    zooInfo.Kingdom = HttpContext.Current.Request.Form[thisKey];
                    zooInfo.Phylum = HttpContext.Current.Request.Form["formzootaxonphylum_" + diff].Trim();
                    zooInfo.Class = HttpContext.Current.Request.Form["formzootaxonclass_" + diff].Trim();
                    zooInfo.Order = HttpContext.Current.Request.Form["formzootaxonorder_" + diff].Trim();
                    zooInfo.Family = HttpContext.Current.Request.Form["formzootaxonfamily_" + diff].Trim();
                    zooInfo.Genus = HttpContext.Current.Request.Form["formzootaxongenus_" + diff].Trim();
                    zooInfo.Specific_Epithet = HttpContext.Current.Request.Form["formzootaxonspecies_" + diff].Trim();
                    zooInfo.Common_Name = HttpContext.Current.Request.Form["formzootaxoncommon_" + diff].Trim();

                    Bib.Add_Metadata_Module(GlobalVar.ZOOLOGICAL_TAXONOMY_METADATA_MODULE_KEY, zooInfo);
                }
            }
        }
        private void Finish_Building_Item(SobekCM_Item Package_To_Finalize, DataSet DatabaseInfo, bool Multiple, Custom_Tracer Tracer )
        {
            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Load the data from the database into the resource object");

            if ((DatabaseInfo == null) || (DatabaseInfo.Tables[2] == null) || (DatabaseInfo.Tables[2].Rows.Count == 0))
            {
                Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Invalid data from the database, either not enough tables, or no rows in Tables[2]");
            }
            else
            {
                // Copy over some basic values
                DataRow mainItemRow = DatabaseInfo.Tables[2].Rows[0];
                Package_To_Finalize.Behaviors.Set_Primary_Identifier(mainItemRow["Primary_Identifier_Type"].ToString(), mainItemRow["Primary_Identifier"].ToString());
                Package_To_Finalize.Behaviors.GroupTitle = mainItemRow["GroupTitle"].ToString();
                Package_To_Finalize.Behaviors.GroupType = mainItemRow["GroupType"].ToString();
                Package_To_Finalize.Web.File_Root = mainItemRow["File_Location"].ToString();
                Package_To_Finalize.Web.AssocFilePath = mainItemRow["File_Location"] + "\\" + Package_To_Finalize.VID + "\\";
                Package_To_Finalize.Behaviors.IP_Restriction_Membership = Convert.ToInt16(mainItemRow["IP_Restriction_Mask"]);
                Package_To_Finalize.Behaviors.CheckOut_Required = Convert.ToBoolean(mainItemRow["CheckoutRequired"]);
                Package_To_Finalize.Behaviors.Text_Searchable = Convert.ToBoolean(mainItemRow["TextSearchable"]);
                Package_To_Finalize.Web.ItemID = Convert.ToInt32(mainItemRow["ItemID"]);
                Package_To_Finalize.Web.GroupID = Convert.ToInt32(mainItemRow["GroupID"]);
                Package_To_Finalize.Behaviors.Suppress_Endeca = Convert.ToBoolean(mainItemRow["SuppressEndeca"]);
                //Package_To_Finalize.Behaviors.Expose_Full_Text_For_Harvesting = Convert.ToBoolean(mainItemRow["SuppressEndeca"]);
                Package_To_Finalize.Tracking.Internal_Comments = mainItemRow["Comments"].ToString();
                Package_To_Finalize.Behaviors.Dark_Flag = Convert.ToBoolean(mainItemRow["Dark"]);
                Package_To_Finalize.Tracking.Born_Digital = Convert.ToBoolean(mainItemRow["Born_Digital"]);
                Package_To_Finalize.Behaviors.Main_Thumbnail = mainItemRow["MainThumbnail"].ToString();
                //Package_To_Finalize.Divisions.Page_Count = Convert.ToInt32(mainItemRow["Pages"]);
                if (mainItemRow["Disposition_Advice"] != DBNull.Value)
                    Package_To_Finalize.Tracking.Disposition_Advice = Convert.ToInt16(mainItemRow["Disposition_Advice"]);
                else
                    Package_To_Finalize.Tracking.Disposition_Advice = -1;
                if (mainItemRow["Material_Received_Date"] != DBNull.Value)
                    Package_To_Finalize.Tracking.Material_Received_Date = Convert.ToDateTime(mainItemRow["Material_Received_Date"]);
                else
                    Package_To_Finalize.Tracking.Material_Received_Date = null;
                if (mainItemRow["Material_Recd_Date_Estimated"] != DBNull.Value)
                    Package_To_Finalize.Tracking.Material_Rec_Date_Estimated = Convert.ToBoolean(mainItemRow["Material_Recd_Date_Estimated"]);
                if (DatabaseInfo.Tables[2].Columns.Contains("Tracking_Box"))
                {
                    if (mainItemRow["Tracking_Box"] != DBNull.Value)
                        Package_To_Finalize.Tracking.Tracking_Box = mainItemRow["Tracking_Box"].ToString();
                }
                if (mainItemRow["CitationSet"] != DBNull.Value)
                    Package_To_Finalize.Behaviors.CitationSet = mainItemRow["CitationSet"].ToString();

                // Set more of the sobekcm web portions in the item
                Package_To_Finalize.Web.Set_BibID_VID(Package_To_Finalize.BibID, Package_To_Finalize.VID);
                Package_To_Finalize.Web.Image_Root = Engine_ApplicationCache_Gateway.Settings.Servers.Image_URL;
                if (Multiple)
                    Package_To_Finalize.Web.Siblings = 2;

                // Set the serial hierarchy from the database (if multiple)
                if ((Multiple) && (mainItemRow["Level1_Text"].ToString().Length > 0))
                {
                    Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Assigning serial hierarchy from the database info");

                    bool found = false;

                    // Get the values from the database first
                    string level1_text = mainItemRow["Level1_Text"].ToString();
                    string level2_text = mainItemRow["Level2_Text"].ToString();
                    string level3_text = mainItemRow["Level3_Text"].ToString();
                    int level1_index = Convert.ToInt32(mainItemRow["Level1_Index"]);
                    int level2_index = Convert.ToInt32(mainItemRow["Level2_Index"]);
                    int level3_index = Convert.ToInt32(mainItemRow["Level3_Index"]);

                    // Does this match the enumeration
                    if (level1_text.ToUpper().Trim() == Package_To_Finalize.Bib_Info.Series_Part_Info.Enum1.ToUpper().Trim())
                    {
                        // Copy the database values to the enumeration portion
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Enum1 = level1_text;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Enum1_Index = level1_index;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Enum2 = level2_text;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Enum2_Index = level2_index;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Enum3 = level3_text;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Enum3_Index = level3_index;
                        found = true;
                    }

                    // Does this match the chronology
                    if ((!found) && (level1_text.ToUpper().Trim() == Package_To_Finalize.Bib_Info.Series_Part_Info.Year.ToUpper().Trim()))
                    {
                        // Copy the database values to the chronology portion
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Year = level1_text;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Year_Index = level1_index;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Month = level2_text;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Month_Index = level2_index;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Day = level3_text;
                        Package_To_Finalize.Bib_Info.Series_Part_Info.Day_Index = level3_index;
                        found = true;
                    }

                    if (!found)
                    {
                        // No match.  If it is numeric, move it to the chronology, otherwise, enumeration
                        bool charFound = level1_text.Trim().Any(ThisChar => !Char.IsNumber(ThisChar));

                        if (charFound)
                        {
                            // Copy the database values to the enumeration portion
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Enum1 = level1_text;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Enum1_Index = level1_index;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Enum2 = level2_text;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Enum2_Index = level2_index;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Enum3 = level3_text;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Enum3_Index = level3_index;
                        }
                        else
                        {
                            // Copy the database values to the chronology portion
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Year = level1_text;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Year_Index = level1_index;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Month = level2_text;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Month_Index = level2_index;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Day = level3_text;
                            Package_To_Finalize.Bib_Info.Series_Part_Info.Day_Index = level3_index;
                        }
                    }

                    // Copy the database values to the simple serial portion (used to actually determine serial heirarchy)
                    Package_To_Finalize.Behaviors.Serial_Info.Clear();
                    Package_To_Finalize.Behaviors.Serial_Info.Add_Hierarchy(1, level1_index, level1_text);
                    if (level2_text.Length > 0)
                    {
                        Package_To_Finalize.Behaviors.Serial_Info.Add_Hierarchy(2, level2_index, level2_text);
                        if (level3_text.Length > 0)
                        {
                            Package_To_Finalize.Behaviors.Serial_Info.Add_Hierarchy(3, level3_index, level3_text);
                        }
                    }
                }

                // See if this can be described
                bool can_describe = false;
                foreach (DataRow thisRow in DatabaseInfo.Tables[1].Rows)
                {
                    int thisAggregationValue = Convert.ToInt16(thisRow["Items_Can_Be_Described"]);
                    if (thisAggregationValue == 0)
                    {
                        can_describe = false;
                        break;
                    }
                    if (thisAggregationValue == 2)
                    {
                        can_describe = true;
                    }
                }
                Package_To_Finalize.Behaviors.Can_Be_Described = can_describe;

                // Look for rights information to add
                if (mainItemRow["EmbargoEnd"] != DBNull.Value)
                {
                    try
                    {
                        DateTime embargoEnd = DateTime.Parse(mainItemRow["EmbargoEnd"].ToString());
                        string origAccessCode = mainItemRow["Original_AccessCode"].ToString();

                        // Is there already a RightsMD module in the item?
                        // Ensure this metadata module extension exists
                        RightsMD_Info rightsInfo = Package_To_Finalize.Get_Metadata_Module(GlobalVar.PALMM_RIGHTSMD_METADATA_MODULE_KEY) as RightsMD_Info;
                        if (rightsInfo == null)
                        {
                            rightsInfo = new RightsMD_Info();
                            Package_To_Finalize.Add_Metadata_Module(GlobalVar.PALMM_RIGHTSMD_METADATA_MODULE_KEY, rightsInfo);
                        }

                        // Add the data
                        rightsInfo.Access_Code_String = origAccessCode;
                        rightsInfo.Embargo_End = embargoEnd;
                    }
                    catch (Exception)
                    {

                    }
                }
            }

            // Look for user descriptions
            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Look for user descriptions (or tags)");
            foreach (DataRow thisRow in DatabaseInfo.Tables[0].Rows)
            {
                string first_name = thisRow["FirstName"].ToString();
                string nick_name = thisRow["NickName"].ToString();
                string last_name = thisRow["LastName"].ToString();
                int userid = Convert.ToInt32(thisRow["UserID"]);
                string tag = thisRow["Description_Tag"].ToString();
                int tagid = Convert.ToInt32(thisRow["TagID"]);
                DateTime dateAdded = Convert.ToDateTime(thisRow["Date_Modified"]);

                if (nick_name.Length > 0)
                {
                    Package_To_Finalize.Behaviors.Add_User_Tag(userid, nick_name + " " + last_name, tag, dateAdded, tagid);
                }
                else
                {
                    Package_To_Finalize.Behaviors.Add_User_Tag(userid, first_name + " " + last_name, tag, dateAdded, tagid);
                }
            }

            // Look for ticklers
            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Load ticklers from the database info");
            foreach (DataRow thisRow in DatabaseInfo.Tables[3].Rows)
            {
                Package_To_Finalize.Behaviors.Add_Tickler(thisRow["MetadataValue"].ToString().Trim());
            }

            // Set the aggregations in the package to the aggregation links from the database
            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Load the aggregations from the database info");
            Package_To_Finalize.Behaviors.Clear_Aggregations();
            foreach (DataRow thisRow in DatabaseInfo.Tables[1].Rows)
            {
                if (!Convert.ToBoolean(thisRow["impliedLink"]))
                {
                    string code = thisRow["Code"].ToString();
                    if (String.Compare(code, "all", StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        Package_To_Finalize.Behaviors.Add_Aggregation(code, thisRow["Name"].ToString(), thisRow["Type"].ToString());
                    }
                }
            }

            // If no collections, add some regardless of whether it was IMPLIED
            if ( Package_To_Finalize.Behaviors.Aggregation_Count == 0)
            {
                foreach (DataRow thisRow in DatabaseInfo.Tables[1].Rows)
                {
                    string code = thisRow["Code"].ToString();
                    if (String.Compare(code, "all", StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        Package_To_Finalize.Behaviors.Add_Aggregation(code, thisRow["Name"].ToString(), thisRow["Type"].ToString());
                    }
                }
            }

            // Make sure no icons were retained from the METS file itself
            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Load the wordmarks/icons from the database info");
            Package_To_Finalize.Behaviors.Clear_Wordmarks();

            // Add the icons from the database information
            foreach (DataRow iconRow in DatabaseInfo.Tables[5].Rows)
            {
                string image = iconRow[0].ToString();
                string link = iconRow[1].ToString().Replace("&", "&amp;").Replace("\"", "&quot;");
                string code = iconRow[2].ToString();
                string name = iconRow[3].ToString();
                if ( name.Length == 0 )
                    name = code.Replace("&", "&amp;").Replace("\"", "&quot;");

                string html;
                if (link.Length == 0)
                {
                    html = "<img class=\"SobekItemWordmark\" src=\"<%BASEURL%>design/wordmarks/" + image + "\" title=\"" + name + "\" alt=\"" + name + "\" />";
                }
                else
                {
                    if (link[0] == '?')
                    {
                        html = "<a href=\"" + link + "\"><img class=\"SobekItemWordmark\" src=\"<%BASEURL%>design/wordmarks/" + image + "\" alt=\"" + name + "\" /></a>";
                    }
                    else
                    {
                        html = "<a href=\"" + link + "\" target=\"_blank\"><img class=\"SobekItemWordmark\" src=\"<%BASEURL%>design/wordmarks/" + image + "\" alt=\"" + name + "\" /></a>";
                    }
                }

                Wordmark_Info newIcon = new Wordmark_Info {HTML = html, Link = link, Title = name, Code = code};
                Package_To_Finalize.Behaviors.Add_Wordmark(newIcon);
            }

            // Make sure no web skins were retained from the METS file itself
            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Load the web skins from the database info");
            Package_To_Finalize.Behaviors.Clear_Web_Skins();

            // Add the web skins from the database
            foreach (DataRow skinRow in DatabaseInfo.Tables[6].Rows)
            {
                Package_To_Finalize.Behaviors.Add_Web_Skin(skinRow[0].ToString().ToUpper());
            }

            // Add the key/value settings
            foreach (DataRow settingRow in DatabaseInfo.Tables[7].Rows)
            {
                Package_To_Finalize.Behaviors.Settings.Add(new Tuple<string, string>(settingRow["Setting_Key"].ToString(), settingRow["Setting_Value"].ToString()));
            }

            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Set the views from a combination of the METS and the database info");

            // Make sure no views were retained from the METS file itself
            Package_To_Finalize.Behaviors.Clear_Views();

            // If there is no PURL, add one based on how SobekCM operates
            if (Package_To_Finalize.Bib_Info.Location.PURL.Length == 0)
            {
                Package_To_Finalize.Bib_Info.Location.PURL = Engine_ApplicationCache_Gateway.Settings.Servers.System_Base_URL + Package_To_Finalize.BibID + "/" + Package_To_Finalize.VID;

            }

            // If this is a newspaper, and there is no datecreated, see if we
            // can make one from the  serial hierarchy
            if (Package_To_Finalize.Behaviors.GroupType.ToUpper() == "NEWSPAPER")
            {
                if ((Package_To_Finalize.Bib_Info.Origin_Info.Date_Created.Length == 0) && (Package_To_Finalize.Bib_Info.Origin_Info.Date_Issued.Length == 0))
                {
                    // Is the serial hierarchy three deep?
                    if (Package_To_Finalize.Behaviors.hasSerialInformation)
                    {
                        if (Package_To_Finalize.Behaviors.Serial_Info.Count == 3)
                        {
                            int year;

                            if (Int32.TryParse(Package_To_Finalize.Behaviors.Serial_Info[0].Display, out year))
                            {
                                int day;
                                if (Int32.TryParse(Package_To_Finalize.Behaviors.Serial_Info[2].Display, out day))
                                {
                                    if ((year > 0) && (year < DateTime.Now.Year + 2) && ( day > 0 ) && ( day <= 31 ))
                                    {
                                        // Is the month a number?
                                        int month;
                                        if (Int32.TryParse(Package_To_Finalize.Behaviors.Serial_Info[1].Display, out month))
                                        {
                                            try
                                            {
                                                // Do it this way since hopefully that will work for localization issues
                                                DateTime date = new DateTime(year, month, day);
                                                Package_To_Finalize.Bib_Info.Origin_Info.Date_Created = date.ToShortDateString();
                                            }
                                            catch
                                            {
                                                // If this is an invalid date, catch the error and do nothing
                                            }
                                        }
                                        else
                                        {
                                            Package_To_Finalize.Bib_Info.Origin_Info.Date_Created = Package_To_Finalize.Behaviors.Serial_Info[1].Display + " " + day + ", " + year;
                                        }
                                    }
                                }
                            }
                        }
                        else if ( Package_To_Finalize.Behaviors.Serial_Info.Count == 2 )
                        {
                            int year;
                            if (Int32.TryParse(Package_To_Finalize.Behaviors.Serial_Info[0].Display, out year))
                            {
                                if ((year > 0) && (year < DateTime.Now.Year + 2) && ( Package_To_Finalize.Behaviors.Serial_Info[1].Display.Length > 0 ))
                                {
                                    Package_To_Finalize.Bib_Info.Origin_Info.Date_Created = Package_To_Finalize.Behaviors.Serial_Info[1].Display + " " + year;
                                }
                            }
                        }
                    }
                }
            }

            // Check to see which views were present from the database, and build the list
            foreach (DataRow viewRow in DatabaseInfo.Tables[4].Rows)
            {
                string viewType = viewRow[0].ToString();
                string attribute = viewRow[1].ToString();
                string label = viewRow[2].ToString();
                float menuOrder = float.Parse(viewRow[3].ToString());
                bool exclude = bool.Parse(viewRow[4].ToString());

                Package_To_Finalize.Behaviors.Add_View(viewType, label, attribute, menuOrder, exclude);
            }

            // IF this is dark, add no other views
            if (Package_To_Finalize.Behaviors.Dark_Flag) return;

            // We will continue to set the static page count
            // Step through each page and set the static page count
            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Set the static page count");
            pageseq = 0;
            List<Page_TreeNode> pages_encountered = new List<Page_TreeNode>();
            foreach (abstract_TreeNode rootNode in Package_To_Finalize.Divisions.Physical_Tree.Roots)
            {
                recurse_through_nodes( rootNode, pages_encountered);
            }
            Package_To_Finalize.Web.Static_PageCount = pages_encountered.Count;

            Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Finish_Building_Item", "Done merging the database information with the resource object");
        }