/// <summary> Adds a new field to this record </summary>
        /// <param name="New_Field"> New field to add </param>
        public void Add_Field(MARC_Field New_Field)
        {
            if (New_Field == null)
            {
                return;
            }

            // Either add this to the existing list, or create a new one
            if (fields.ContainsKey(New_Field.Tag))
            {
                fields[New_Field.Tag].Add(New_Field);
            }
            else
            {
                List <MARC_Field> newTagCollection = new List <MARC_Field> {
                    New_Field
                };
                fields[New_Field.Tag] = newTagCollection;
            }
        }
        /// <summary> Add a new data field to this record </summary>
        /// <param name="Tag">Tag for new data field</param>
        /// <param name="Indicator1">First indicator for new data field</param>
        /// <param name="Indicator2">Second indicator for new data field</param>
        /// <returns>New data field object created and added</returns>
        public MARC_Field Add_Field(int Tag, char Indicator1, char Indicator2)
        {
            // Create the new datafield
            MARC_Field newField = new MARC_Field(Tag, Indicator1, Indicator2);

            // Either add this to the existing list, or create a new one
            if (fields.ContainsKey(Tag))
            {
                fields[Tag].Add(newField);
            }
            else
            {
                List <MARC_Field> newTagCollection = new List <MARC_Field> {
                    newField
                };
                fields[Tag] = newTagCollection;
            }

            // Return the newlly built data field
            return(newField);
        }
        /// <summary> Add a new control field to this record </summary>
        /// <param name="Tag">Tag for new control field</param>
        /// <param name="Control_Field_Value">Data for the new control field</param>
        /// <returns>New control field object created and added</returns>
        public MARC_Field Add_Field(int Tag, string Control_Field_Value)
        {
            // Create the new control field
            MARC_Field newField = new MARC_Field(Tag, Control_Field_Value);

            // Either add this to the existing list, or create a new one
            if (fields.ContainsKey(Tag))
            {
                fields[Tag].Add(newField);
            }
            else
            {
                List <MARC_Field> newTagCollection = new List <MARC_Field> {
                    newField
                };
                fields[Tag] = newTagCollection;
            }

            // Return the newlly built control field
            return(newField);
        }
        internal override MARC_Field to_MARC_HTML()
        {
            MARC_Field returnValue = new MARC_Field();

            // Set the tag
            if ((id.IndexOf("SUBJ") == 0) && (id.Length >= 7))
            {
                string possible_tag = id.Substring(4, 3);
                try
                {
                    int possible_tag_number = Convert.ToInt16(possible_tag);
                    returnValue.Tag = possible_tag_number;
                }
                catch
                {
                }
            }

            // Try to guess the tag, if there was no tag
            if ((returnValue.Tag <= 0) && (Topics_Count == 0))
            {
                if ((Temporals_Count > 0) && (Genres_Count == 0) && (Geographics_Count == 0))
                    returnValue.Tag = 648;

                if ((Temporals_Count == 0) && (Genres_Count > 0) && (Geographics_Count == 0))
                    returnValue.Tag = 655;

                if ((Temporals_Count == 0) && (Genres_Count == 0) && (Geographics_Count > 0))
                    returnValue.Tag = 651;
            }

            // 650 is the default
            if (returnValue.Tag <= 0)
            {
                returnValue.Tag = 650;
            }

            // No indicators
            returnValue.Indicators = "  ";
            bool first_field_assigned = false;
            string scale = String.Empty;
            StringBuilder fieldBuilder = new StringBuilder();
            StringBuilder fieldBuilder2 = new StringBuilder();

            // Whenever there is an occupation, it must map into the 656
            if ((occupations != null) && (occupations.Count > 0))
            {
                returnValue.Tag = 656;
                fieldBuilder.Append("|a ");
                foreach (string occupation in occupations)
                {
                    if (!first_field_assigned)
                    {
                        fieldBuilder.Append(occupation);
                        first_field_assigned = true;
                    }
                    else
                    {
                        fieldBuilder.Append(" -- " + occupation);
                    }
                }
                fieldBuilder.Append(" ");
            }

            switch (returnValue.Tag)
            {
                case 690:
                    first_field_assigned = assign_genres(first_field_assigned, returnValue.Tag, fieldBuilder, fieldBuilder2);
                    first_field_assigned = assign_topics(first_field_assigned, returnValue.Tag, fieldBuilder, fieldBuilder2, ref scale);
                    first_field_assigned = assign_geographics(first_field_assigned, returnValue.Tag, fieldBuilder, fieldBuilder2);
                    assign_temporals(first_field_assigned, returnValue.Tag, fieldBuilder, fieldBuilder2);
                    break;

                case 691:
                    first_field_assigned = assign_genres(first_field_assigned, returnValue.Tag, fieldBuilder, fieldBuilder2);
                    first_field_assigned = assign_geographics(first_field_assigned, returnValue.Tag, fieldBuilder, fieldBuilder2);
                    first_field_assigned = assign_topics(first_field_assigned, returnValue.Tag, fieldBuilder, fieldBuilder2, ref scale);
                    assign_temporals(first_field_assigned, returnValue.Tag, fieldBuilder, fieldBuilder2);
                    break;

                default:
                    first_field_assigned = assign_geographics(first_field_assigned, returnValue.Tag, fieldBuilder, fieldBuilder2);
                    first_field_assigned = assign_temporals(first_field_assigned, returnValue.Tag, fieldBuilder, fieldBuilder2);
                    first_field_assigned = assign_topics(first_field_assigned, returnValue.Tag, fieldBuilder, fieldBuilder2, ref scale);
                   assign_genres(first_field_assigned, returnValue.Tag, fieldBuilder, fieldBuilder2);
                    break;
            }

            if (!String.IsNullOrEmpty(scale))
            {
                fieldBuilder2.Append("|x " + scale + " ");
            }

            fieldBuilder.Append(fieldBuilder2);
            if (fieldBuilder.Length > 2)
            {
                fieldBuilder.Remove(fieldBuilder.Length - 1, 1);
                if ((returnValue.Tag != 653) && (fieldBuilder[fieldBuilder.Length - 1] != '.'))
                    fieldBuilder.Append(". ");
            }

            Add_Source_Indicator(returnValue, fieldBuilder);

            returnValue.Control_Field_Value = returnValue.Tag == 653 ? fieldBuilder.ToString().Trim().Replace("|x ", "|a ") : fieldBuilder.ToString().Trim();

            return returnValue;
        }
        /// <summary> Adds a new field to this record </summary>
        /// <param name="New_Field"> New field to add </param>
        public void Add_Field(MARC_Field New_Field)
        {
            if (New_Field == null)
                return;

            // Either add this to the existing list, or create a new one
            if (fields.ContainsKey(New_Field.Tag))
                fields[New_Field.Tag].Add(New_Field);
            else
            {
                List<MARC_Field> newTagCollection = new List<MARC_Field> {New_Field};
                fields[New_Field.Tag] = newTagCollection;
            }
        }
        /// <summary> Add a new data field to this record </summary>
        /// <param name="Tag">Tag for new data field</param>
        /// <param name="Indicators">Both indicators</param>
        /// <param name="Control_Field_Value">Value for this control field </param>
        /// <returns>New data field object created and added</returns>
        public MARC_Field Add_Field(int Tag, string Indicators, string Control_Field_Value)
        {
            // Create the new datafield
            MARC_Field newField = new MARC_Field(Tag, Control_Field_Value) {Indicators = Indicators};

            // Either add this to the existing list, or create a new one
            if (fields.ContainsKey(Tag))
                fields[Tag].Add(newField);
            else
            {
                List<MARC_Field> newTagCollection = new List<MARC_Field> {newField};
                fields[Tag] = newTagCollection;
            }

            // Return the newlly built data field
            return newField;
        }
        /// <summary> Gets the collection of MARC tags to be written for this digital resource </summary>
        /// <param name="CatalogingSourceCode"> Cataloging source code for the 040 field, ( for example FUG for University of Florida ) </param>
        /// <param name="LocationCode"> Location code for the 852 |a - if none is given the system abbreviation will be used. Otherwise, the system abbreviation will be put in the 852 |b field. </param>
        /// <param name="ReproductionAgency"> Agency responsible for reproduction, or primary agency associated with the SobekCM instance ( for the added 533 |c field ) </param>
        /// <param name="ReproductionPlace"> Place of reproduction, or primary location associated with the SobekCM instance ( for the added 533 |b field ) </param>
        /// <param name="SystemName"> Name used for this SobekCM (or otherwise) digital repository system </param>
        /// <param name="SystemAbbreviation"> Abbrevation used for this SobekCM (or otherwise) digital repository system </param>
        /// <param name="ThumbnailBase"> Base URL for the thumbnail to be included</param>
        /// <returns> Collection of MARC tags to be written for this digital resource </returns>
        public MARC_Record To_MARC_Record(string CatalogingSourceCode, string LocationCode, string ReproductionAgency, string ReproductionPlace, string SystemName, string SystemAbbreviation, string ThumbnailBase )
        {
            // Find the first aggregation name
            string first_aggr_name = String.Empty;
            if (Behaviors.Aggregation_Count > 0)
            {
                foreach (Aggregation_Info thisAggr in Behaviors.Aggregations)
                {
                    if (( String.Compare(thisAggr.Code, "ALL", true) != 0 ) && (( String.IsNullOrEmpty(thisAggr.Type)) || (thisAggr.Type.IndexOf("INSTITUT", StringComparison.InvariantCultureIgnoreCase) < 0)))
                    {
                        first_aggr_name = thisAggr.Name;
                        break;
                    }
                }
            }

            // Create the sorted list
            MARC_Record tags = new MARC_Record();

            // Compute the sobekcm type, which will be used for some of these mappings
            TypeOfResource_SobekCM_Enum sobekcm_type = BIBInfo.SobekCM_Type;

            // Build a hashtable of all the pertinent genres
            Dictionary<string, string> genreHash = new Dictionary<string, string>();
            if (Bib_Info.Genres_Count > 0)
            {
                foreach (Genre_Info thisGenre in Bib_Info.Genres)
                {
                    if ((thisGenre.Authority == "marcgt") || (thisGenre.Authority == "sobekcm"))
                    {
                        genreHash[thisGenre.Genre_Term] = thisGenre.Genre_Term;
                    }
                }
            }

            // ADD THE 006 FOR ONLINE MATERIAL
            StringBuilder bldr006 = new StringBuilder("m     o  ");
            switch (Bib_Info.SobekCM_Type)
            {
                case TypeOfResource_SobekCM_Enum.Book:
                case TypeOfResource_SobekCM_Enum.Newspaper:
                case TypeOfResource_SobekCM_Enum.Multivolume:
                case TypeOfResource_SobekCM_Enum.Serial:
                    bldr006.Append("d");
                    break;

                case TypeOfResource_SobekCM_Enum.Video:
                case TypeOfResource_SobekCM_Enum.Audio:
                    bldr006.Append("i");
                    break;

                case TypeOfResource_SobekCM_Enum.Photograph:
                case TypeOfResource_SobekCM_Enum.Map:
                case TypeOfResource_SobekCM_Enum.Aerial:
                    bldr006.Append("c");
                    break;

                case TypeOfResource_SobekCM_Enum.Archival:
                    bldr006.Append("m");
                    break;

                default:
                    bldr006.Append(" ");
                    break;
            }
            bldr006.Append(" ");

            // Government publication?
            int govt_publication = 0;
            add_value(genreHash.ContainsKey("multilocal government publication"), 'c', ref govt_publication, 1, bldr006);
            add_value(genreHash.ContainsKey("federal government publication"), 'f', ref govt_publication, 1, bldr006);
            add_value(genreHash.ContainsKey("international intergovernmental publication"), 'i', ref govt_publication, 1, bldr006);
            add_value(genreHash.ContainsKey("local government publication"), 'l', ref govt_publication, 1, bldr006);
            add_value(genreHash.ContainsKey("multistate government publication"), 'm', ref govt_publication, 1, bldr006);
            add_value(genreHash.ContainsKey("government publication"), 'o', ref govt_publication, 1, bldr006);
            add_value(genreHash.ContainsKey("government publication (state, provincial, terriorial, dependent)"), 's', ref govt_publication, 1, bldr006);
            add_value(genreHash.ContainsKey("government publication (autonomous or semiautonomous component)"), 'a', ref govt_publication, 1, bldr006);
            if (govt_publication == 0)
            {
                bldr006.Append(" ");
            }
            bldr006.Append("      ");
            tags.Add_Field(6, "  ", bldr006.ToString());

            // ADD THE 007 FOR ELECTRONIC RESOURCE
            StringBuilder bldr007 = new StringBuilder("cr  n");
            switch (Bib_Info.SobekCM_Type)
            {
                case TypeOfResource_SobekCM_Enum.Audio:
                case TypeOfResource_SobekCM_Enum.Video:
                    bldr007.Append("a");
                    break;

                default:
                    bldr007.Append(" ");
                    break;
            }
            bldr007.Append("---ma mp");
            tags.Add_Field(new MARC_Field(7, "  ", bldr007.ToString()));

            // ADD THE MAIN ENTITY NAME
            if (Bib_Info.hasMainEntityName)
            {
                MARC_Field main_entity_marc = Bib_Info.Main_Entity_Name.to_MARC_HTML(false);

                switch (Bib_Info.Main_Entity_Name.Name_Type)
                {
                    case Name_Info_Type_Enum.Personal:
                        main_entity_marc.Tag = 100;
                        break;

                    case Name_Info_Type_Enum.Corporate:
                        main_entity_marc.Tag = 110;
                        break;

                    case Name_Info_Type_Enum.Conference:
                        main_entity_marc.Tag = 111;
                        break;

                    case Name_Info_Type_Enum.UNKNOWN:
                        main_entity_marc.Tag = 720;
                        break;
                }
                tags.Add_Field(main_entity_marc);
            }

            // ADD THE OTHER NAMES
            if (Bib_Info.Names_Count > 0)
            {
                foreach (Name_Info name in Bib_Info.Names)
                {
                    if ((!String.IsNullOrEmpty(name.Full_Name)) || (!String.IsNullOrEmpty(name.Given_Name)) || (!String.IsNullOrEmpty(name.Family_Name)))
                    {
                        MARC_Field name_marc = name.to_MARC_HTML(false);

                        switch (name.Name_Type)
                        {
                            case Name_Info_Type_Enum.Personal:
                                name_marc.Tag = 700;
                                break;

                            case Name_Info_Type_Enum.Corporate:
                                name_marc.Tag = 710;
                                break;

                            case Name_Info_Type_Enum.Conference:
                                name_marc.Tag = 711;
                                break;

                            case Name_Info_Type_Enum.UNKNOWN:
                                name_marc.Tag = 720;
                                break;
                        }

                        tags.Add_Field(name_marc);
                    }
                }
            }

            // ADD THE DONOR
            if ((Bib_Info.hasDonor) && (Bib_Info.Donor.Full_Name.Length > 0))
            {
                MARC_Field donor_marc = Bib_Info.Donor.to_MARC_HTML(false);

                switch (Bib_Info.Donor.Name_Type)
                {
                    case Name_Info_Type_Enum.Personal:
                    case Name_Info_Type_Enum.UNKNOWN:
                        donor_marc.Indicators = donor_marc.Indicators[0] + "3";
                        donor_marc.Tag = 796;
                        tags.Add_Field(donor_marc);
                        break;

                    case Name_Info_Type_Enum.Corporate:
                    case Name_Info_Type_Enum.Conference:
                        donor_marc.Indicators = donor_marc.Indicators[0] + "3";
                        donor_marc.Tag = 797;
                        tags.Add_Field(donor_marc);
                        break;
                }
            }

            // ADD THE 260
            if ((Bib_Info.Origin_Info.Publishers_Count > 0) || (Bib_Info.Origin_Info.Date_Issued.Length > 0) || (Bib_Info.Origin_Info.MARC_DateIssued.Length > 0))
            {
                MARC_Field publisher_tag = new MARC_Field();
                StringBuilder builder260 = new StringBuilder();
                publisher_tag.Tag = 260;
                publisher_tag.Indicators = "  ";
                int pub_count = 0;
                if (Bib_Info.Publishers_Count > 0)
                {
                    foreach (Publisher_Info thisPublisher in Bib_Info.Publishers)
                    {
                        int place_count = 1;
                        bool place_added = false;
                        // ADD ALL THE |a 's for this publisher
                        if (thisPublisher.Places_Count > 0)
                        {
                            foreach (Origin_Info_Place thisPlace in thisPublisher.Places)
                            {
                                if (thisPlace.Place_Text.Length > 0)
                                {
                                    place_added = true;
                                    if (place_count > 1)
                                    {
                                        builder260.Append("; |a " + thisPlace.Place_Text + " ");
                                    }
                                    else
                                    {
                                        builder260.Append("|a " + thisPlace.Place_Text + " ");
                                    }
                                    place_count++;
                                }
                            }
                        }
                        if (!place_added)
                        {
                            builder260.Append("|a [S.l.] ");
                        }
                        builder260.Append(": ");

                        // Add the |b for this publisher
                        string pubName = thisPublisher.Name.Trim();
                        if ((pubName.Length > 2) && (pubName[pubName.Length - 1] == ','))
                        {
                            pubName = pubName.Substring(0, pubName.Length - 1);
                        }

                        builder260.Append("|b " + thisPublisher.Name);
                        pub_count++;

                        if (pub_count == Bib_Info.Publishers_Count)
                        {
                            if ((Bib_Info.Origin_Info.Date_Issued.Length > 0) || (Bib_Info.Manufacturers_Count > 0))
                            {
                                builder260.Append(", ");
                            }
                        }
                        else
                        {
                            builder260.Append(" ; ");
                        }
                    }
                }

                if (Bib_Info.Origin_Info.MARC_DateIssued.Length > 0)
                {
                    builder260.Append("|c " + Bib_Info.Origin_Info.MARC_DateIssued);
                }
                else if (Bib_Info.Origin_Info.Date_Issued.Length > 0)
                {
                    builder260.Append("|c " + Bib_Info.Origin_Info.Date_Issued);
                }

                if (Bib_Info.Manufacturers_Count > 0)
                {
                    foreach (Publisher_Info thisManufacturer in Bib_Info.Manufacturers)
                    {
                        int place_count = 1;
                        bool place_added = false;
                        // ADD ALL THE |e 's for this manufacturer
                        if (thisManufacturer.Places_Count > 0)
                        {
                            foreach (Origin_Info_Place thisPlace in thisManufacturer.Places)
                            {
                                if (thisPlace.Place_Text.Length > 0)
                                {
                                    place_added = true;
                                    if (place_count > 1)
                                    {
                                        builder260.Append("; |e " + thisPlace.Place_Text + " ");
                                    }
                                    else
                                    {
                                        builder260.Append(" |e (" + thisPlace.Place_Text + " ");
                                    }
                                    place_count++;
                                }
                            }
                        }
                        if (!place_added)
                        {
                            builder260.Append("|e ( [S.l.] ");
                        }
                        builder260.Append(": ");

                        // Add the |f for this manufacturer
                        builder260.Append("|f " + thisManufacturer.Name + ")");
                    }
                }
                else
                {
                    builder260.Append(".");
                }

                publisher_tag.Control_Field_Value = builder260.ToString();
                tags.Add_Field(publisher_tag);
            }

            // ADD ALL THE FREQUENCIES
            if (Bib_Info.Origin_Info.Frequencies_Count > 0)
            {
                foreach (Origin_Info_Frequency frequency in Bib_Info.Origin_Info.Frequencies)
                {
                    if (frequency.Authority != "marcfrequency")
                    {
                        MARC_Field frequency_tag = new MARC_Field {Tag = 310, Indicators = "  "};

                        if (frequency.Term.IndexOf("[") < 0)
                        {
                            frequency_tag.Control_Field_Value = "|a " + frequency.Term;
                        }
                        else
                        {
                            if (frequency.Term.IndexOf("[ FORMER") > 0)
                            {
                                frequency_tag.Tag = 321;
                                int square_bracket_index = frequency.Term.IndexOf("[");
                                frequency_tag.Control_Field_Value = "|a " + frequency.Term.Substring(0, square_bracket_index).Trim() + " |b " + frequency.Term.Substring(square_bracket_index + 9).Replace("]", "").Trim();
                            }
                            else
                            {
                                int square_bracket_index2 = frequency.Term.IndexOf("[");
                                frequency_tag.Control_Field_Value = "|a " + frequency.Term.Substring(0, square_bracket_index2).Trim() + " |b " + frequency.Term.Substring(square_bracket_index2 + 1).Replace("]", "").Trim();
                            }
                        }
                        tags.Add_Field(frequency_tag);
                    }
                }
            }

            // Determine if there is a link to another version of this material
            bool another_version_exists = false;
            if (Bib_Info.RelatedItems_Count > 0)
            {
                if (Bib_Info.RelatedItems.Where(relatedItem => relatedItem.URL.Length > 0).Any(relatedItem => relatedItem.Relationship == Related_Item_Type_Enum.OtherVersion))
                {
                    another_version_exists = true;
                }
            }

            // ADD ALL THE NOTES
            string statement_of_responsibility = "";
            string electronic_access_note = "";
            if (Bib_Info.Notes_Count > 0)
            {
                foreach (Note_Info thisNote in Bib_Info.Notes)
                {
                    switch (thisNote.Note_Type)
                    {
                        case Note_Type_Enum.StatementOfResponsibility:
                            statement_of_responsibility = thisNote.Note;
                            break;

                        case Note_Type_Enum.ElectronicAccess:
                            electronic_access_note = thisNote.Note;
                            break;

                        case Note_Type_Enum.PublicationStatus:
                        case Note_Type_Enum.InternalComments:
                            // DO nothing
                            break;

                        default:
                            tags.Add_Field(thisNote.to_MARC_HTML());
                            break;
                    }
                }
            }

            // Add an 856 pointing to this item first
            MARC_Field tag856 = new MARC_Field {Tag = 856, Indicators = "40"};
            string url = Bib_Info.Location.PURL;
            if (url.Length == 0)
            {
                url = web.Service_URL;
            }
            string linkText = "Electronic Resource";
            if ((Bib_Info.Type.MODS_Type == TypeOfResource_MODS_Enum.Text))
                linkText = "Click here for full text";
            if ((another_version_exists) && ( SystemAbbreviation.Length > 0 ))
            {
                if (electronic_access_note.Length > 0)
                    tag856.Control_Field_Value = "|3 " + SystemAbbreviation + " Version |u " + url + " |y " + linkText + " |z " + electronic_access_note;
                else
                    tag856.Control_Field_Value = "|3 " + SystemAbbreviation + " Version |u " + url + " |y " + linkText;
            }
            else
            {
                if (electronic_access_note.Length > 0)
                    tag856.Control_Field_Value = "|u " + url + " |y " + linkText + " |z " + electronic_access_note;
                else
                    tag856.Control_Field_Value = "|u " + url + " |y " + linkText;
            }
            tags.Add_Field(tag856);

            // ADD THE RELATED ITEMS
            if (Bib_Info.RelatedItems_Count > 0)
            {
                foreach (Related_Item_Info relatedItem in Bib_Info.RelatedItems)
                {
                    // Add the main tag
                    tags.Add_Field(relatedItem.to_MARC_HTML());

                    // If there is a URL listed, add another tag
                    if (relatedItem.URL.Length > 0)
                    {
                        MARC_Field linking_tag = new MARC_Field {Tag = 856, Indicators = "42"};
                        if (relatedItem.Relationship == Related_Item_Type_Enum.OtherVersion)
                            linking_tag.Indicators = "41";

                        StringBuilder linking856_builder = new StringBuilder();
                        if (relatedItem.URL_Display_Label.Length > 0)
                        {
                            linking856_builder.Append("|3 " + XML_Writing_Base_Type.Convert_String_To_XML_Safe_Static(relatedItem.URL_Display_Label) + " ");
                        }
                        else
                        {
                            switch (relatedItem.Relationship)
                            {
                                case Related_Item_Type_Enum.Host:
                                    linking856_builder.Append("|3 Host material ");
                                    break;

                                case Related_Item_Type_Enum.OtherFormat:
                                    linking856_builder.Append("|3 Other format ");
                                    break;

                                case Related_Item_Type_Enum.OtherVersion:
                                    linking856_builder.Append("|3 Other version ");
                                    break;

                                case Related_Item_Type_Enum.Preceding:
                                    linking856_builder.Append("|3 Preceded by ");
                                    break;

                                case Related_Item_Type_Enum.Succeeding:
                                    linking856_builder.Append("|3 Succeeded by ");
                                    break;

                                default:
                                    linking856_builder.Append("|3 Related item ");
                                    break;
                            }
                        }

                        // Add the URL
                        linking856_builder.Append("|u " + XML_Writing_Base_Type.Convert_String_To_XML_Safe_Static(relatedItem.URL) + " ");

                        // Add the title if there is one
                        if ((relatedItem.hasMainTitle) && (relatedItem.Main_Title.Title.Length > 0))
                        {
                            linking856_builder.Append("|y " + XML_Writing_Base_Type.Convert_String_To_XML_Safe_Static(relatedItem.Main_Title.Title));
                        }

                        linking_tag.Control_Field_Value = linking856_builder.ToString().Trim();
                        tags.Add_Field(linking_tag);
                    }
                }
            }

            // ADD THE TARGET AUDIENCE
            string skipped_marctarget = String.Empty;
            bool done_with_skipped = false;
            if (Bib_Info.Target_Audiences_Count > 0)
            {
                foreach (TargetAudience_Info targetAudience in Bib_Info.Target_Audiences)
                {
                    if (targetAudience.Authority.Length > 0)
                    {
                        // This part is kinda wierd.  basically, one marctarget audience can be included in the
                        // leader, so it does not need to be included in the 521 as well.  But, if there is
                        // more than one "marctarget" audience, I want ALL of them to show up here.
                        if (targetAudience.Authority == "marctarget")
                        {
                            if (skipped_marctarget.Length == 0)
                            {
                                skipped_marctarget = targetAudience.Audience;
                            }
                            else
                            {
                                if (!done_with_skipped)
                                {
                                    tags.Add_Field(521, "  ", "|a " + skipped_marctarget + " |b marctarget");
                                    done_with_skipped = true;
                                }

                                tags.Add_Field(521, "  ", "|a " + targetAudience.Audience + " |b " + targetAudience.Authority);
                            }
                        }
                        else
                        {
                            tags.Add_Field(521, "  ", "|a " + targetAudience.Audience + " |b " + targetAudience.Authority);
                        }
                    }
                    else
                    {
                        tags.Add_Field(521, "  ", "|a " + targetAudience.Audience);
                    }
                }
            }

            //// ADD THE ORIGINAL CATALOGING SOURCE INFORMATION
            //if (this.Bib_Info.Record.MARC_Record_Content_Sources.Count > 0)
            //{
            //    MARC_XML_Field origCatSource = new MARC_XML_Field();
            //    StringBuilder builder599 = new StringBuilder();
            //    origCatSource.Tag = "599";
            //    origCatSource.Indicators = "  ";
            //    builder599.Append("|a " + this.Bib_Info.Record.MARC_Record_Content_Sources[0]);
            //    if (this.Bib_Info.Record.MARC_Record_Content_Sources.Count > 1)
            //    {
            //        builder599.Append(" |c " + this.Bib_Info.Record.MARC_Record_Content_Sources[1]);
            //    }
            //    int orig_count = 2;
            //    while (orig_count < this.Bib_Info.Record.MARC_Record_Content_Sources.Count)
            //    {
            //        builder599.Append(" |d " + this.Bib_Info.Record.MARC_Record_Content_Sources[orig_count]);
            //        orig_count++;
            //    }
            //    origCatSource.Field = builder599.ToString();
            //    tags.Add_Field(origCatSource);
            //}

            // Add the NEW cataloging source information
            if ((!String.IsNullOrEmpty(CatalogingSourceCode)) || ( Bib_Info.Record.MARC_Record_Content_Sources_Count > 0 ))
            {

                MARC_Field catSource = new MARC_Field { Tag = 40, Indicators = "  " };

                StringBuilder catSourceBuilder = new StringBuilder();
                if (Bib_Info.Record.MARC_Record_Content_Sources_Count > 0)
                {
                    bool a_added = false;
                    foreach (string thisSource in Bib_Info.Record.MARC_Record_Content_Sources)
                    {
                        if (!a_added)
                        {
                            catSourceBuilder.Append("|a " + thisSource);
                            a_added = true;
                        }
                        else
                        {
                            catSourceBuilder.Append(" |d " + thisSource);
                        }
                    }
                }
                else
                {
                    catSourceBuilder.Append("|a " + CatalogingSourceCode.Trim() + " |c " + CatalogingSourceCode.Trim());
                }

                if (BIBInfo.Record.Description_Standard.Length > 0)
                    catSourceBuilder.Append(" |e " + BIBInfo.Record.Description_Standard.ToLower());
                catSource.Control_Field_Value = catSourceBuilder.ToString();
                tags.Add_Field(catSource);
            }

            // ADD THE ABSTRACTS
            if (Bib_Info.Abstracts_Count > 0)
            {
                foreach (Abstract_Info thisAbstract in Bib_Info.Abstracts)
                {
                    tags.Add_Field(thisAbstract.to_MARC_HTML());
                }
            }

            // ADD THE MAIN TITLE
            if (Bib_Info.Main_Title.Title.Length > 0)
            {
                MARC_Field mainTitleTag = Bib_Info.Main_Title.to_MARC_HTML(245, 2, statement_of_responsibility, "[electronic resource]");
                if ((Bib_Info.hasMainEntityName) && (Bib_Info.Main_Entity_Name.Full_Name.Length > 0))
                    mainTitleTag.Indicators = "1" + mainTitleTag.Indicators[1];
                else
                    mainTitleTag.Indicators = "0" + mainTitleTag.Indicators[1];

                tags.Add_Field(mainTitleTag);
            }

            // ADD THE SERIES TITLE
            if ((Bib_Info.hasSeriesTitle) && (Bib_Info.SeriesTitle.Title.Length > 0))
            {
                tags.Add_Field(Bib_Info.SeriesTitle.to_MARC_HTML(490, 0, String.Empty, String.Empty));
            }

            // ADD ALL OTHER TITLES
            if (Bib_Info.Other_Titles_Count > 0)
            {
                foreach (Title_Info thisTitle in Bib_Info.Other_Titles)
                {
                    tags.Add_Field(thisTitle.to_MARC_HTML(-1, -1, String.Empty, String.Empty));
                }
            }

            // ADD THE EXTENT
            if (Bib_Info.Original_Description.Extent.Length > 0)
            {
                int semi_index = Bib_Info.Original_Description.Extent.IndexOf(";");
                int colon_index = Bib_Info.Original_Description.Extent.IndexOf(":");
                if ((semi_index > 0) || (colon_index > 0))
                {
                    string a_300_subfield_string;
                    string b_300_subfield_string = String.Empty;
                    string c_300_subfield_string = String.Empty;

                    if (semi_index > 0)
                    {
                        if (colon_index > 0)
                        {
                            a_300_subfield_string = Bib_Info.Original_Description.Extent.Substring(0, colon_index);
                            b_300_subfield_string = Bib_Info.Original_Description.Extent.Substring(colon_index + 1, semi_index - colon_index - 1);
                            c_300_subfield_string = Bib_Info.Original_Description.Extent.Substring(semi_index + 1);

                            //tags.Add_Field("300", "  ", "|a " + this.Bib_Info.Original_Description.Extent.Substring(0, colon_index + 1) + " |b " + this.Bib_Info.Original_Description.Extent.Substring(colon_index + 1, semi_index - colon_index) + " |c " + this.Bib_Info.Original_Description.Extent.Substring(semi_index + 1));
                        }
                        else
                        {
                            a_300_subfield_string = Bib_Info.Original_Description.Extent.Substring(0, semi_index);
                            c_300_subfield_string = Bib_Info.Original_Description.Extent.Substring(semi_index + 1);

                            // No colon ( colon_index < 0 )
                            //tags.Add_Field("300", "  ", "|a " + this.Bib_Info.Original_Description.Extent.Substring(0, semi_index + 1) + " |c " + this.Bib_Info.Original_Description.Extent.Substring(semi_index + 1));
                        }
                    }
                    else
                    {
                        a_300_subfield_string = Bib_Info.Original_Description.Extent.Substring(0, colon_index);
                        b_300_subfield_string = Bib_Info.Original_Description.Extent.Substring(colon_index + 1);

                        // No semi colon ( semi_index < 0 )
                        //tags.Add_Field("300", "  ", "|a " + this.Bib_Info.Original_Description.Extent.Substring(0, colon_index + 1) + " |b " + this.Bib_Info.Original_Description.Extent.Substring(colon_index + 1));
                    }

                    StringBuilder builder_300 = new StringBuilder("|a " + a_300_subfield_string, a_300_subfield_string.Length + b_300_subfield_string.Length + c_300_subfield_string.Length + 10);
                    if (b_300_subfield_string.Trim().Length > 0)
                    {
                        builder_300.Append(": |b " + b_300_subfield_string);
                    }
                    if (c_300_subfield_string.Trim().Length > 0)
                    {
                        builder_300.Append("; |c " + c_300_subfield_string);
                    }
                    tags.Add_Field(300, "  ", builder_300.ToString());
                }
                else
                {
                    tags.Add_Field(300, "  ", "|a " + Bib_Info.Original_Description.Extent);
                }
            }

            // ADD THE EDITION
            if (Bib_Info.Origin_Info.Edition.Length > 0)
            {
                if (Bib_Info.Origin_Info.Edition.IndexOf(" -- ") > 0)
                {
                    int edition_index = Bib_Info.Origin_Info.Edition.IndexOf(" -- ");
                    tags.Add_Field(250, "  ", "|a " + Bib_Info.Origin_Info.Edition.Substring(0, edition_index) + " /|b " + Bib_Info.Origin_Info.Edition.Substring(edition_index + 4));
                }
                else
                {
                    tags.Add_Field(250, "  ", "|a " + Bib_Info.Origin_Info.Edition);
                }
            }

            // ADD THE CLASSIFICATIONS
            if (Bib_Info.Classifications_Count > 0)
            {
                foreach (Classification_Info thisClassification in Bib_Info.Classifications)
                {
                    tags.Add_Field(thisClassification.to_MARC_Tag());
                }
            }

            // ADD ALL THE IDENTIFIERS
            if (Bib_Info.Identifiers_Count > 0)
            {
                foreach (Identifier_Info thisIdentifier in Bib_Info.Identifiers)
                {
                    switch (thisIdentifier.Type.ToUpper())
                    {
                        case "LCCN":
                            tags.Add_Field(10, "  ", "|a  " + thisIdentifier.Identifier);
                            break;

                        case "ISBN":
                            tags.Add_Field(20, "  ", "|a " + thisIdentifier.Identifier);
                            break;

                        case "ISSN":
                            tags.Add_Field(22, "  ", "|a " + thisIdentifier.Identifier);
                            break;

                        case "OCLC":
                            tags.Add_Field(776, "1 ", "|c Original |w (OCoLC)" + thisIdentifier.Identifier);
                            break;

                        case "NOTIS":
                            tags.Add_Field(035, "9 ", "|a " + thisIdentifier.Identifier + " |b UF");
                            break;

                        case "ALEPH":
                            tags.Add_Field(035, "9 ", "|a " + thisIdentifier.Identifier.PadLeft(9, '0') + " |b UF");
                            break;

                        default:
                            if (thisIdentifier.Type.Length > 0)
                            {
                                tags.Add_Field(024, "7 ", "|a " + thisIdentifier.Identifier + " |2 " + thisIdentifier.Type);
                            }
                            else
                            {
                                tags.Add_Field(024, "8 ", "|a " + thisIdentifier.Identifier);
                            }
                            break;
                    }
                }
            }

            // ADD THE MAIN IDENTIFIER
            if ((METS_Header.ObjectID.Length > 0) || (Bib_Info.Record.Main_Record_Identifier.Identifier.Length > 0) || ((BibID.Length > 0) && ((VID.Length > 0) || (METS_Header.RecordStatus_Enum != METS_Record_Status.BIB_LEVEL))))
            {
                if (Bib_Info.Record.Main_Record_Identifier.Identifier.Length > 0)
                {
                    tags.Add_Field(1, "  ", Bib_Info.Record.Main_Record_Identifier.Identifier);
                }
                else
                {
                    if (METS_Header.ObjectID.Length > 0)
                    {
                        tags.Add_Field(1, "  ", METS_Header.ObjectID);
                    }
                    else
                    {
                        if (METS_Header.RecordStatus_Enum != METS_Record_Status.BIB_LEVEL)
                            tags.Add_Field(1, "  ", BibID + "_" + VID);
                        else
                            tags.Add_Field(1, "  ", BibID);
                    }
                }
            }

            // ADD THE LAST MODIFIED DATE
            tags.Add_Field(5, "  ", METS_Header.Modify_Date.Year +
                                    METS_Header.Modify_Date.Month.ToString().PadLeft(2, '0') +
                                    METS_Header.Modify_Date.Day.ToString().PadLeft(2, '0') +
                                    METS_Header.Modify_Date.Hour.ToString().PadLeft(2, '0') +
                                    METS_Header.Modify_Date.Minute.ToString().PadLeft(2, '0') +
                                    METS_Header.Modify_Date.Second.ToString().PadLeft(2, '0') + ".0");

            // ADD THE SUBJECT KEYWORDS
            if (Bib_Info.Subjects_Count > 0)
            {
                foreach (Subject_Info thisSubject in Bib_Info.Subjects)
                {
                    tags.Add_Field(thisSubject.to_MARC_HTML());
                }
            }

            // ADD ANY NON-MARCGT GENRE TERMS AS 655 CODES AS WELL
            if (Bib_Info.Genres_Count > 0)
            {
                foreach (Genre_Info thisGenre in Bib_Info.Genres)
                {
                    tags.Add_Field(thisGenre.to_MARC_HTML());
                }
            }

            // ADD THE TEMPORAL SUBJECT (if the term appears nowehere in the subjects)
            if (Bib_Info.TemporalSubjects_Count > 0)
            {
                foreach (Temporal_Info thisTemporal in Bib_Info.TemporalSubjects)
                {
                    string temporal_upper = thisTemporal.TimePeriod.ToUpper();
                    string years = String.Empty;
                    if ((thisTemporal.Start_Year > 0) && (thisTemporal.End_Year > 0))
                        years = thisTemporal.Start_Year.ToString() + "-" + thisTemporal.End_Year;
                    if ((thisTemporal.Start_Year > 0) && (thisTemporal.End_Year < 0))
                        years = thisTemporal.Start_Year.ToString() + "-";
                    if ((thisTemporal.Start_Year < 0) && (thisTemporal.End_Year > 0))
                        years = "-" + thisTemporal.End_Year;
                    bool found = false;
                    if (Bib_Info.Subjects_Count > 0)
                    {
                        foreach (Subject_Info thisSubject in Bib_Info.Subjects)
                        {
                            if (thisSubject.Class_Type == Subject_Info_Type.Standard)
                            {
                                Subject_Info_Standard standSubject = (Subject_Info_Standard) thisSubject;
                                if (standSubject.Temporals_Count > 0)
                                {
                                    if (standSubject.Temporals.Any(temporal => (temporal_upper == temporal.ToUpper()) || (temporal == years)))
                                    {
                                        found = true;
                                    }
                                }
                            }

                            if (found)
                                break;
                        }
                    }

                    if (!found)
                    {
                        Subject_Info_Standard tempSubject = new Subject_Info_Standard();
                        if (years.Length > 0)
                        {
                            tempSubject.Add_Temporal(years);
                        }
                        if (thisTemporal.TimePeriod.Length > 0)
                        {
                            tempSubject.Add_Temporal(thisTemporal.TimePeriod);
                        }
                        tags.Add_Field(tempSubject.to_MARC_HTML());
                    }
                }
            }

            // ADD THE TABLE OF CONTENTS
            if (Bib_Info.TableOfContents.Length > 0)
            {
                tags.Add_Field(505, "0 ", "|a " + Bib_Info.TableOfContents);
            }

            // ADD THE RIGHTS
            if (Bib_Info.Access_Condition.Text.Length > 0)
            {
                if (String.Compare(Bib_Info.Access_Condition.Type, "use and reproduction", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    if ( Bib_Info.Access_Condition.Text.IndexOf("http") == 0 )
                        tags.Add_Field(540, "  ", "|u " + Bib_Info.Access_Condition.Text);
                    else
                        tags.Add_Field(540, "  ", "|a " + Bib_Info.Access_Condition.Text);
                }
                else
                {
                    if (Bib_Info.Access_Condition.Text.IndexOf("http") == 0)
                        tags.Add_Field(506, "  ", "|u " + Bib_Info.Access_Condition.Text);
                    else
                        tags.Add_Field(506, "  ", "|a " + Bib_Info.Access_Condition.Text);
                }
            }

            // ADD THE HOLDING LOCATION
            if ((Bib_Info.hasLocationInformation) && (Bib_Info.Location.Holding_Name.Length > 0))
            {
                if (Bib_Info.Location.Holding_Name[Bib_Info.Location.Holding_Name.Length - 1] != '.')
                    tags.Add_Field(535, "1 ", "|a " + Bib_Info.Location.Holding_Name + ".");
                else
                    tags.Add_Field(535, "1 ", "|a " + Bib_Info.Location.Holding_Name);
            }

            // IF THERE IS MORE THAN ONE LANGUAGE, ADD THEM ALL IN THE 041
            if (Bib_Info.Languages_Count > 1)
            {
                StringBuilder marc_coded_languages = new StringBuilder();
                foreach (Language_Info thisLanguage in Bib_Info.Languages)
                {
                    if (thisLanguage.Language_ISO_Code.Length > 0)
                        marc_coded_languages.Append("|a " + thisLanguage.Language_ISO_Code + " ");
                }
                if (marc_coded_languages.Length > 0)
                    tags.Add_Field(041, "  ", marc_coded_languages.ToString().Trim());
            }

            // ADD THE 008 FIELD (FIXED LENGTH DATA ELEMENTS)
            MARC_Field fixedField008 = new MARC_Field {Indicators = "  ", Tag = 008};
            StringBuilder builder008 = new StringBuilder();
            builder008.Append(METS_Header.Create_Date.Year.ToString().Substring(2) + METS_Header.Create_Date.Month.ToString().PadLeft(2, '0') + METS_Header.Create_Date.Day.ToString().PadLeft(2, '0'));

            if ((Bib_Info.Origin_Info.MARC_DateIssued_Start.Length == 0) && (Bib_Info.Origin_Info.MARC_DateIssued_End.Length == 0))
            {
                builder008.Append("n        ");
            }
            else
            {
                if ((sobekcm_type != TypeOfResource_SobekCM_Enum.Newspaper) && (sobekcm_type != TypeOfResource_SobekCM_Enum.Serial) && (sobekcm_type != TypeOfResource_SobekCM_Enum.Multivolume))
                {
                    if ((Bib_Info.Origin_Info.MARC_DateIssued_End.Length == 0) || (Bib_Info.Origin_Info.MARC_DateIssued_End == "0000"))
                    {
                        builder008.Append("s" + Bib_Info.Origin_Info.MARC_DateIssued_Start.PadLeft(4, '0') + "    ");
                    }
                    else
                    {
                        switch (Bib_Info.Origin_Info.MARC_DateIssued_End.ToUpper())
                        {
                            case "UUUU":
                                builder008.Append("u" + Bib_Info.Origin_Info.MARC_DateIssued_Start.PadLeft(4, '0') + "uuuu");
                                break;

                            case "9999":
                                builder008.Append("m" + Bib_Info.Origin_Info.MARC_DateIssued_Start.PadLeft(4, '0') + "9999");
                                break;

                            default:
                                if (Bib_Info.Origin_Info.Date_Reprinted == Bib_Info.Origin_Info.MARC_DateIssued_Start)
                                {
                                    builder008.Append("r" + Bib_Info.Origin_Info.MARC_DateIssued_Start.PadLeft(4, '0') + Bib_Info.Origin_Info.MARC_DateIssued_End.PadLeft(4, '0'));
                                }
                                else
                                {
                                    if (Bib_Info.Origin_Info.Date_Copyrighted == Bib_Info.Origin_Info.MARC_DateIssued_End)
                                    {
                                        builder008.Append("t" + Bib_Info.Origin_Info.MARC_DateIssued_Start.PadLeft(4, '0') + Bib_Info.Origin_Info.MARC_DateIssued_End.PadLeft(4, '0'));
                                    }
                                    else
                                    {
                                        builder008.Append("d" + Bib_Info.Origin_Info.MARC_DateIssued_Start.PadLeft(4, '0') + Bib_Info.Origin_Info.MARC_DateIssued_End.PadLeft(4, '0'));
                                    }
                                }
                                break;
                        }
                    }
                }
                else
                {
                    if (Bib_Info.Origin_Info.MARC_DateIssued_End.Length == 0)
                    {
                        builder008.Append("s" + Bib_Info.Origin_Info.MARC_DateIssued_Start.PadLeft(4, '0') + "    ");
                    }
                    else
                    {
                        switch (Bib_Info.Origin_Info.MARC_DateIssued_End.ToUpper())
                        {
                            case "UUUU":
                                builder008.Append("u" + Bib_Info.Origin_Info.MARC_DateIssued_Start.PadLeft(4, '0') + "uuuu");
                                break;

                            case "9999":
                                builder008.Append("c" + Bib_Info.Origin_Info.MARC_DateIssued_Start.PadLeft(4, '0') + "9999");
                                break;

                            default:
                                builder008.Append("d" + Bib_Info.Origin_Info.MARC_DateIssued_Start.PadLeft(4, '0') + Bib_Info.Origin_Info.MARC_DateIssued_End.PadLeft(4, '0'));
                                break;
                        }
                    }
                }
            }

            // Is there a place listed in marc country?
            string marccountry_code = "xx ";
            if (Bib_Info.Origin_Info.Places_Count > 0)
            {
                foreach (Origin_Info_Place thisPlace in Bib_Info.Origin_Info.Places)
                {
                    if (thisPlace.Place_MarcCountry.Length > 0)
                    {
                        marccountry_code = thisPlace.Place_MarcCountry.PadRight(3, ' ');
                        break;
                    }
                }
            }
            builder008.Append(marccountry_code);

            // Set the default code for the any simple flag characters
            char default_code = '|';
            if (Bib_Info.EncodingLevel.Length > 0)
                default_code = '0';

            #region Map Specific 008 Values

            // Build the Map-Specific 008 Values
            if (sobekcm_type == TypeOfResource_SobekCM_Enum.Map)
            {
                // Add the map relief information
                string map_relief_note = String.Empty;
                if (Bib_Info.Notes_Count > 0)
                {
                    foreach (Note_Info thisNote in Bib_Info.Notes)
                    {
                        if (thisNote.Note_Type == Note_Type_Enum.NONE)
                        {
                            if ((thisNote.Note.IndexOf("Relief shown") >= 0) || (thisNote.Note.IndexOf("Depths shown") >= 0) || (thisNote.Note.IndexOf("Depth shown") >= 0))
                            {
                                map_relief_note = thisNote.Note;
                            }
                        }
                    }
                }
                if (map_relief_note.Length > 0)
                {
                    string[] map_relief_note_splitter = map_relief_note.Split(".".ToCharArray());
                    int map_relief_info = 0;
                    foreach (string map_split in map_relief_note_splitter)
                    {
                        add_value((map_split.IndexOf("contours") >= 0), 'a', ref map_relief_info, 4, builder008);
                        add_value((map_split.IndexOf("shading") >= 0), 'b', ref map_relief_info, 4, builder008);
                        add_value((map_split.IndexOf("Relief") >= 0) && ((map_split.IndexOf("gradient") >= 0) || (map_split.IndexOf("bathymetric") >= 0)), 'c', ref map_relief_info, 4, builder008);
                        add_value((map_split.IndexOf("hachure") >= 0), 'd', ref map_relief_info, 4, builder008);
                        add_value(((map_split.IndexOf("Depth") >= 0) && (map_split.IndexOf("soundings") > 0)) || (map_split.IndexOf("spot depth") >= 0), 'e', ref map_relief_info, 4, builder008);
                        add_value(map_split.IndexOf("form lines") >= 0, 'f', ref map_relief_info, 4, builder008);
                        add_value((map_split.IndexOf("spot height") >= 0), 'g', ref map_relief_info, 4, builder008);
                        add_value((map_split.IndexOf("pictorially") >= 0), 'i', ref map_relief_info, 4, builder008);
                        add_value((map_split.IndexOf("land forms") >= 0), 'j', ref map_relief_info, 4, builder008);
                        add_value((map_split.IndexOf("isolines") >= 0), 'k', ref map_relief_info, 4, builder008);
                    }
                    for (int i = map_relief_info; i < 4; i++)
                        builder008.Append(" ");
                }
                else
                {
                    builder008.Append("    ");
                }

                // Add the projection information
                bool map_projection_handled = false;
                if (Bib_Info.Subjects_Count > 0)
                {
                    foreach (Subject_Info possibleCarto in Bib_Info.Subjects)
                    {
                        if ((possibleCarto.Authority == "marcgt") && (possibleCarto.Class_Type == Subject_Info_Type.Cartographics))
                        {
                            if (((Subject_Info_Cartographics) possibleCarto).Projection.Length == 2)
                            {
                                builder008.Append(((Subject_Info_Cartographics) possibleCarto).Projection);
                                map_projection_handled = true;
                                break;
                            }
                        }
                    }
                }
                if (!map_projection_handled)
                {
                    builder008.Append("  ");
                }

                // Undefined character position
                builder008.Append(" ");

                // Add the type of cartographic material
                int map_type = 0;
                add_value(genreHash.ContainsKey("atlas"), 'e', ref map_type, 1, builder008);
                add_value(genreHash.ContainsKey("globe"), 'd', ref map_type, 1, builder008);
                add_value(genreHash.ContainsKey("single map"), 'a', ref map_type, 1, builder008);
                add_value(genreHash.ContainsKey("map series"), 'b', ref map_type, 1, builder008);
                add_value(genreHash.ContainsKey("map serial"), 'c', ref map_type, 1, builder008);
                if (map_type == 0)
                {
                    builder008.Append(" ");
                }

                // Two undefined positions
                builder008.Append("  ");

                // Government publication?
                int map_govt_publication = 0;
                add_value(genreHash.ContainsKey("multilocal government publication"), 'c', ref map_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("federal government publication"), 'f', ref map_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("international intergovernmental publication"), 'i', ref map_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("local government publication"), 'l', ref map_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("multistate government publication"), 'm', ref map_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("government publication"), 'o', ref map_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("government publication (state, provincial, terriorial, dependent)"), 's', ref map_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("government publication (autonomous or semiautonomous component)"), 'a', ref map_govt_publication, 1, builder008);
                if (map_govt_publication == 0)
                {
                    builder008.Append(" ");
                }

                // Add form of item
                builder008.Append("o");

                // Undefined position
                builder008.Append(" ");

                // Code if this includes an index
                if (genreHash.ContainsKey("indexed"))
                {
                    builder008.Append("1");
                }
                else
                {
                    builder008.Append(default_code);
                }

                // Undefined position
                builder008.Append(" ");

                // Special format characteristics
                builder008.Append("  ");
            }

            #endregion

            #region Continuing Resource Specific 008 Values

            // Build the Continuing Resource-Specific 008 Values
            if ((sobekcm_type == TypeOfResource_SobekCM_Enum.Newspaper) || (sobekcm_type == TypeOfResource_SobekCM_Enum.Serial))
            {
                // Add the frequency (008/18)
                int newspaper_frequency = 0;
                if (Bib_Info.Origin_Info.Frequencies_Count > 0)
                {
                    foreach (Origin_Info_Frequency thisFrequency in Bib_Info.Origin_Info.Frequencies)
                    {
                        if (thisFrequency.Authority == "marcfrequency")
                        {
                            add_value(thisFrequency.Term == "annual", 'a', ref newspaper_frequency, 1, builder008);
                            add_value(thisFrequency.Term == "bimonthly", 'b', ref newspaper_frequency, 1, builder008);
                            add_value(thisFrequency.Term == "semiweekly", 'c', ref newspaper_frequency, 1, builder008);
                            add_value(thisFrequency.Term == "daily", 'd', ref newspaper_frequency, 1, builder008);
                            add_value(thisFrequency.Term == "bieweekly", 'e', ref newspaper_frequency, 1, builder008);
                            add_value(thisFrequency.Term == "semiannual", 'f', ref newspaper_frequency, 1, builder008);
                            add_value(thisFrequency.Term == "biennial", 'g', ref newspaper_frequency, 1, builder008);
                            add_value(thisFrequency.Term == "triennial", 'h', ref newspaper_frequency, 1, builder008);
                            add_value(thisFrequency.Term == "three times a week", 'i', ref newspaper_frequency, 1, builder008);
                            add_value(thisFrequency.Term == "three times a month", 'j', ref newspaper_frequency, 1, builder008);
                            add_value(thisFrequency.Term == "continuously updated", 'k', ref newspaper_frequency, 1, builder008);
                            add_value(thisFrequency.Term == "monthly", 'm', ref newspaper_frequency, 1, builder008);
                            add_value(thisFrequency.Term == "quarterly", 'q', ref newspaper_frequency, 1, builder008);
                            add_value(thisFrequency.Term == "semimonthly", 's', ref newspaper_frequency, 1, builder008);
                            add_value(thisFrequency.Term == "three times a year", 't', ref newspaper_frequency, 1, builder008);
                            add_value(thisFrequency.Term == "weekly", 'w', ref newspaper_frequency, 1, builder008);
                            add_value(thisFrequency.Term == "other", 'z', ref newspaper_frequency, 1, builder008);
                        }
                    }
                }
                if (newspaper_frequency == 0)
                    builder008.Append(" ");

                // Add the regularity (08/19)
                int newspaper_regularity = 0;
                if (Bib_Info.Origin_Info.Frequencies_Count > 0)
                {
                    foreach (Origin_Info_Frequency thisFrequency in Bib_Info.Origin_Info.Frequencies)
                    {
                        if (thisFrequency.Authority == "marcfrequency")
                        {
                            add_value(thisFrequency.Term == "normalized irregular", 'n', ref newspaper_regularity, 1, builder008);
                            add_value(thisFrequency.Term == "regular", 'r', ref newspaper_regularity, 1, builder008);
                            add_value(thisFrequency.Term == "completely irregular", 'x', ref newspaper_regularity, 1, builder008);
                        }
                    }
                }
                if (newspaper_regularity == 0)
                    builder008.Append("u");

                // undefined (008/20)
                builder008.Append(" ");

                // Add the type of continuing resource (008/21)
                int newspaper_type = 0;
                add_value(genreHash.ContainsKey("database"), 'd', ref newspaper_type, 1, builder008);
                add_value(genreHash.ContainsKey("loose-leaf"), 'l', ref newspaper_type, 1, builder008);
                add_value(genreHash.ContainsKey("newspaper"), 'n', ref newspaper_type, 1, builder008);
                add_value(genreHash.ContainsKey("periodical"), 'p', ref newspaper_type, 1, builder008);
                add_value(genreHash.ContainsKey("series"), 's', ref newspaper_type, 1, builder008);
                add_value(genreHash.ContainsKey("web site"), 'w', ref newspaper_type, 1, builder008);
                if (newspaper_type == 0)
                    builder008.Append(" ");

                // Add original form of item and this item (electronic) (008/22-23)
                builder008.Append(sobekcm_type == TypeOfResource_SobekCM_Enum.Newspaper ? "eo" : " o");

                // Add nature of work (008/24-27)
                int newspaper_nature_of_contents = 0;
                add_value(genreHash.ContainsKey("abstract or summary"), 'a', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("bibliography"), 'b', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("catalog"), 'c', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("dictionary"), 'd', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("directory"), 'r', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("discography"), 'k', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("encyclopedia"), 'e', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("filmography"), 'q', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("handbook"), 'f', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("index"), 'i', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("law report or digest"), 'w', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("legal article"), 'g', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("legal case and case notes"), 'v', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("legislation"), 'l', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("patent"), 'j', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("programmed text"), 'p', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("review"), 'o', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("statistics"), 's', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("survey of literature"), 'n', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("technical reports"), 't', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("theses"), 'm', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("treaty"), 'z', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("offprint"), '2', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("yearbook"), 'y', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("calendar"), '5', ref newspaper_nature_of_contents, 3, builder008);
                add_value(genreHash.ContainsKey("comic/graphic novel"), '6', ref newspaper_nature_of_contents, 3, builder008);
                for (int i = newspaper_nature_of_contents; i < 4; i++)
                {
                    builder008.Append(" ");
                }

                // Code if this is a government document (008/28)
                int newspaper_govt_publication = 0;
                add_value(genreHash.ContainsKey("multilocal government publication"), 'c', ref newspaper_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("federal government publication"), 'f', ref newspaper_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("international intergovernmental publication"), 'i', ref newspaper_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("local government publication"), 'l', ref newspaper_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("multistate government publication"), 'm', ref newspaper_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("government publication"), 'o', ref newspaper_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("government publication (state, provincial, terriorial, dependent)"), 's', ref newspaper_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("government publication (autonomous or semiautonomous component)"), 'a', ref newspaper_govt_publication, 1, builder008);
                if (newspaper_govt_publication == 0)
                {
                    builder008.Append(" ");
                }

                // Code if this is a conference publication (008/29)
                if (genreHash.ContainsKey("conference publication"))
                {
                    builder008.Append("1");
                }
                else
                {
                    builder008.Append(default_code);
                }

                // Undefined (008/30-32)
                builder008.Append("   ");

                // Code original alphebet or script of title
                builder008.Append(" ");

                // Code the entry convention
                builder008.Append("0");
            }

            #endregion

            #region Book Specific 008 Values

            if (sobekcm_type == TypeOfResource_SobekCM_Enum.Book)
            {
                if (Bib_Info.Original_Description.Extent.Length > 0)
                {
                    int book_illustration_specs = 0;
                    string extent_upper = Bib_Info.Original_Description.Extent.ToUpper();
                    add_value((extent_upper.IndexOf("ILL.") >= 0), 'a', ref book_illustration_specs, 4, builder008);
                    add_value((extent_upper.IndexOf("MAP") >= 0), 'b', ref book_illustration_specs, 4, builder008);
                    add_value(((extent_upper.IndexOf("PORT.") >= 0) || (extent_upper.IndexOf("PORTS.") >= 0)), 'c', ref book_illustration_specs, 4, builder008);
                    add_value((extent_upper.IndexOf("CHART") >= 0), 'd', ref book_illustration_specs, 4, builder008);
                    add_value((extent_upper.IndexOf("PLAN") >= 0), 'e', ref book_illustration_specs, 4, builder008);
                    add_value((extent_upper.IndexOf("PLATE") >= 0), 'f', ref book_illustration_specs, 4, builder008);
                    add_value((extent_upper.IndexOf("MUSIC") >= 0), 'g', ref book_illustration_specs, 4, builder008);
                    add_value(((extent_upper.IndexOf("FACSIM.") >= 0) || (extent_upper.IndexOf("FACSIMS.") >= 0)), 'h', ref book_illustration_specs, 4, builder008);
                    add_value(((extent_upper.IndexOf("COAT OF ARMS") >= 0) || (extent_upper.IndexOf("COATS OF ARMS") >= 0)), 'i', ref book_illustration_specs, 4, builder008);
                    add_value((extent_upper.IndexOf("FORM") >= 0), 'k', ref book_illustration_specs, 4, builder008);
                    add_value((extent_upper.IndexOf("SAMPLE") >= 0), 'l', ref book_illustration_specs, 4, builder008);
                    add_value(((extent_upper.IndexOf("PHOTO.") >= 0) || (extent_upper.IndexOf("PHOTOS.") >= 0)), 'o', ref book_illustration_specs, 4, builder008);

                    // Finish this off
                    if (book_illustration_specs == 0)
                    {
                        builder008.Append("    ");
                    }
                    else
                    {
                        for (int i = book_illustration_specs; i < 4; i++)
                        {
                            builder008.Append(" ");
                        }
                    }
                }
                else
                {
                    builder008.Append("||||");
                }

                // Look for target audience
                int book_target_audiences = 0;
                if (Bib_Info.Target_Audiences_Count > 0)
                {
                    foreach (TargetAudience_Info thisTarget in Bib_Info.Target_Audiences)
                    {
                        if (thisTarget.Authority == "marctarget")
                        {
                            add_value(thisTarget.Audience == "adolescent", 'd', ref book_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "adult", 'e', ref book_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "general", 'g', ref book_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "primary", 'b', ref book_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "pre-adolescent", 'c', ref book_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "juvenile", 'j', ref book_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "preschool", 'a', ref book_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "specialized", 'f', ref book_target_audiences, 1, builder008);
                        }
                    }
                }
                if (book_target_audiences == 0)
                    builder008.Append(" ");

                // Always electronic --> online (1/11/2013)
                builder008.Append("o");

                // Code nature of contents
                int book_nature_of_contents = 0;
                add_value(genreHash.ContainsKey("abstract or summary"), 'a', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("bibliography"), 'b', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("catalog"), 'c', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("dictionary"), 'd', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("directory"), 'r', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("discography"), 'k', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("encyclopedia"), 'e', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("filmography"), 'q', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("handbook"), 'f', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("index"), 'i', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("law report or digest"), 'w', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("legal article"), 'g', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("legal case and case notes"), 'v', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("legislation"), 'l', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("patent"), 'j', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("programmed text"), 'p', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("review"), 'o', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("statistics"), 's', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("survey of literature"), 'n', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("technical reports"), 't', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("theses"), 'm', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("treaty"), 'z', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("offprint"), '2', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("yearbook"), 'y', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("calendar"), '5', ref book_nature_of_contents, 4, builder008);
                add_value(genreHash.ContainsKey("comic/graphic novel"), '6', ref book_nature_of_contents, 4, builder008);

                for (int i = book_nature_of_contents; i < 4; i++)
                {
                    builder008.Append(" ");
                }

                // Code if this is a government document
                int book_govt_publication = 0;
                add_value(genreHash.ContainsKey("multilocal government publication"), 'c', ref book_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("federal government publication"), 'f', ref book_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("international intergovernmental publication"), 'i', ref book_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("local government publication"), 'l', ref book_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("multistate government publication"), 'm', ref book_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("government publication"), 'o', ref book_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("government publication (state, provincial, terriorial, dependent)"), 's', ref book_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("government publication (autonomous or semiautonomous component)"), 'a', ref book_govt_publication, 1, builder008);
                if (book_govt_publication == 0)
                {
                    builder008.Append(" ");
                }

                // Code if this is a conference publication
                if (genreHash.ContainsKey("conference publication"))
                {
                    builder008.Append("1");
                }
                else
                {
                    builder008.Append(default_code);
                }

                // Code if this is a festschrift
                if (genreHash.ContainsKey("festschrift"))
                {
                    builder008.Append("1");
                }
                else
                {
                    builder008.Append(default_code);
                }

                // Code if this includes an index
                if (genreHash.ContainsKey("indexed"))
                {
                    builder008.Append("1");
                }
                else
                {
                    builder008.Append(default_code);
                }

                // Undefined character spot
                builder008.Append(" ");

                // Code the literary form
                int book_literary_form = 0;
                add_value(genreHash.ContainsKey("drama"), 'd', ref book_literary_form, 1, builder008);
                add_value(genreHash.ContainsKey("comic strip"), 'a', ref book_literary_form, 1, builder008);
                add_value(genreHash.ContainsKey("essay"), 'e', ref book_literary_form, 1, builder008);
                add_value(genreHash.ContainsKey("humor, satire"), 'h', ref book_literary_form, 1, builder008);
                add_value(genreHash.ContainsKey("letter"), 'i', ref book_literary_form, 1, builder008);
                add_value(genreHash.ContainsKey("poetry"), 'p', ref book_literary_form, 1, builder008);
                add_value(genreHash.ContainsKey("novel"), 'f', ref book_literary_form, 1, builder008);
                add_value(genreHash.ContainsKey("short story"), 'j', ref book_literary_form, 1, builder008);
                add_value(genreHash.ContainsKey("speech"), 's', ref book_literary_form, 1, builder008);
                add_value(genreHash.ContainsKey("non-fiction"), '0', ref book_literary_form, 1, builder008);
                add_value(genreHash.ContainsKey("fiction"), '1', ref book_literary_form, 1, builder008);
                if (book_literary_form == 0)
                    builder008.Append("u");

                // Code the biography value
                int book_biography_value = 0;
                add_value(genreHash.ContainsKey("autobiography"), 'a', ref book_biography_value, 1, builder008);
                add_value(genreHash.ContainsKey("individual biography"), 'b', ref book_biography_value, 1, builder008);
                add_value(genreHash.ContainsKey("collective biography"), 'c', ref book_biography_value, 1, builder008);
                if (book_biography_value == 0)
                    builder008.Append(" ");
            }

            #endregion

            #region Visual Material Specific 008 Values

            if ((sobekcm_type == TypeOfResource_SobekCM_Enum.Aerial) || (sobekcm_type == TypeOfResource_SobekCM_Enum.Photograph) || (sobekcm_type == TypeOfResource_SobekCM_Enum.Audio) || (sobekcm_type == TypeOfResource_SobekCM_Enum.Video) || (sobekcm_type == TypeOfResource_SobekCM_Enum.Artifact))
            {
                // Code running time for movies (008/18-20)
                builder008.Append("nnn");

                // Undefined (008/21)
                builder008.Append(" ");

                // Target Audience (008/22)
                int visual_target_audiences = 0;
                if (Bib_Info.Target_Audiences_Count > 0)
                {
                    foreach (TargetAudience_Info thisTarget in Bib_Info.Target_Audiences)
                    {
                        if (thisTarget.Authority == "marctarget")
                        {
                            add_value(thisTarget.Audience == "adolescent", 'd', ref visual_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "adult", 'e', ref visual_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "general", 'g', ref visual_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "primary", 'b', ref visual_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "pre-adolescent", 'c', ref visual_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "juvenile", 'j', ref visual_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "preschool", 'a', ref visual_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "specialized", 'f', ref visual_target_audiences, 1, builder008);
                        }
                    }
                }
                if (visual_target_audiences == 0)
                    builder008.Append(" ");

                // Undefined (008/23-27)
                builder008.Append("     ");

                // Is this a government publication? (008/28)
                int visual_govt_publication = 0;
                add_value(genreHash.ContainsKey("multilocal government publication"), 'c', ref visual_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("federal government publication"), 'f', ref visual_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("international intergovernmental publication"), 'i', ref visual_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("local government publication"), 'l', ref visual_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("multistate government publication"), 'm', ref visual_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("government publication"), 'o', ref visual_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("government publication (state, provincial, terriorial, dependent)"), 's', ref visual_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("government publication (autonomous or semiautonomous component)"), 'a', ref visual_govt_publication, 1, builder008);
                if (visual_govt_publication == 0)
                {
                    builder008.Append(" ");
                }

                // What is the form of this item (always electronic) (008/29)
                builder008.Append("o");

                // Undefined (008/30-32)
                builder008.Append("   ");

                // Type of visual material (008/33)
                int visual_nature_of_contents = 0;
                add_value(genreHash.ContainsKey("art original"), 'a', ref visual_nature_of_contents, 1, builder008);
                add_value(genreHash.ContainsKey("art reproduction"), 'c', ref visual_nature_of_contents, 1, builder008);
                add_value(genreHash.ContainsKey("chart"), 'n', ref visual_nature_of_contents, 1, builder008);
                add_value(genreHash.ContainsKey("diorama"), 'd', ref visual_nature_of_contents, 1, builder008);
                add_value(genreHash.ContainsKey("filmstrip"), 'f', ref visual_nature_of_contents, 1, builder008);
                add_value(genreHash.ContainsKey("flash card"), 'o', ref visual_nature_of_contents, 1, builder008);
                add_value(genreHash.ContainsKey("graphic"), 'k', ref visual_nature_of_contents, 1, builder008);
                add_value(genreHash.ContainsKey("kit"), 'b', ref visual_nature_of_contents, 1, builder008);
                add_value(genreHash.ContainsKey("microscope slide"), 'p', ref visual_nature_of_contents, 1, builder008);
                add_value(genreHash.ContainsKey("model"), 'q', ref visual_nature_of_contents, 1, builder008);
                add_value(genreHash.ContainsKey("motion picture"), 'm', ref visual_nature_of_contents, 1, builder008);
                add_value(genreHash.ContainsKey("picture"), 'i', ref visual_nature_of_contents, 1, builder008);
                add_value(genreHash.ContainsKey("realia"), 'r', ref visual_nature_of_contents, 1, builder008);
                add_value(genreHash.ContainsKey("slide"), 's', ref visual_nature_of_contents, 1, builder008);
                add_value(genreHash.ContainsKey("technical drawing"), 'l', ref visual_nature_of_contents, 1, builder008);
                add_value(genreHash.ContainsKey("toy"), 'w', ref visual_nature_of_contents, 1, builder008);
                add_value(genreHash.ContainsKey("transparency"), 't', ref visual_nature_of_contents, 1, builder008);
                add_value(genreHash.ContainsKey("video recording"), 'v', ref visual_nature_of_contents, 1, builder008);
                if (visual_nature_of_contents == 0)
                {
                    builder008.Append(" ");
                }

                // Technique (008/34)
                builder008.Append(sobekcm_type == TypeOfResource_SobekCM_Enum.Video ? "u" : "n");
            }

            #endregion

            #region Visual Material Specific 008 Values

            if (sobekcm_type == TypeOfResource_SobekCM_Enum.Dataset)
            {
                // Undefined (008/18-21)
                builder008.Append("    ");

                // Target Audience (008/22)
                int visual_target_audiences = 0;
                if (Bib_Info.Target_Audiences_Count > 0)
                {
                    foreach (TargetAudience_Info thisTarget in Bib_Info.Target_Audiences)
                    {
                        if (thisTarget.Authority == "marctarget")
                        {
                            add_value(thisTarget.Audience == "adolescent", 'd', ref visual_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "adult", 'e', ref visual_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "general", 'g', ref visual_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "primary", 'b', ref visual_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "pre-adolescent", 'c', ref visual_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "juvenile", 'j', ref visual_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "preschool", 'a', ref visual_target_audiences, 1, builder008);
                            add_value(thisTarget.Audience == "specialized", 'f', ref visual_target_audiences, 1, builder008);
                        }
                    }
                }
                if (visual_target_audiences == 0)
                    builder008.Append(" ");

                // Form of item (008/23) (unknown or not specified)
                builder008.Append(" ");

                // Undefined (008/24-25)
                builder008.Append("  ");

                // Type of computer file (008/26)
                builder008.Append(" ");
                int computer_file_type = 0;
                add_value(genreHash.ContainsKey("numeric data"), 'c', ref computer_file_type, 1, builder008);
                add_value(genreHash.ContainsKey("computer program"), 'f', ref computer_file_type, 1, builder008);
                add_value(genreHash.ContainsKey("representational"), 'i', ref computer_file_type, 1, builder008);
                add_value(genreHash.ContainsKey("document"), 'l', ref computer_file_type, 1, builder008);
                add_value(genreHash.ContainsKey("bibliographic data"), 'm', ref computer_file_type, 1, builder008);
                add_value(genreHash.ContainsKey("font"), 'o', ref computer_file_type, 1, builder008);
                add_value(genreHash.ContainsKey("game"), 's', ref computer_file_type, 1, builder008);
                add_value(genreHash.ContainsKey("sound"), 'a', ref computer_file_type, 1, builder008);
                add_value(genreHash.ContainsKey("interactive multimedia"), 'm', ref computer_file_type, 1, builder008);
                add_value(genreHash.ContainsKey("online system or service"), 'o', ref computer_file_type, 1, builder008);
                add_value(genreHash.ContainsKey("combination"), 's', ref computer_file_type, 1, builder008);
                add_value(genreHash.ContainsKey("other computer file"), 'a', ref computer_file_type, 1, builder008);
                if (computer_file_type == 0)
                {
                    builder008.Append(" ");
                }

                // Undefined (008/27)
                builder008.Append(" ");

                // Is this a government publication? (008/28)
                int visual_govt_publication = 0;
                add_value(genreHash.ContainsKey("multilocal government publication"), 'c', ref visual_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("federal government publication"), 'f', ref visual_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("international intergovernmental publication"), 'i', ref visual_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("local government publication"), 'l', ref visual_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("multistate government publication"), 'm', ref visual_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("government publication"), 'o', ref visual_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("government publication (state, provincial, terriorial, dependent)"), 's', ref visual_govt_publication, 1, builder008);
                add_value(genreHash.ContainsKey("government publication (autonomous or semiautonomous component)"), 'a', ref visual_govt_publication, 1, builder008);
                if (visual_govt_publication == 0)
                {
                    builder008.Append(" ");
                }

                // Undefined (008/29-34)
                builder008.Append("      ");
            }

            #endregion

            if (sobekcm_type == TypeOfResource_SobekCM_Enum.Archival)
            {
                // Treat as MIXED material
                builder008.Append("     s           ");
            }

            // For any other type, just use spaces
            if ((sobekcm_type != TypeOfResource_SobekCM_Enum.Book) && (sobekcm_type != TypeOfResource_SobekCM_Enum.Map) && (sobekcm_type != TypeOfResource_SobekCM_Enum.Newspaper) && (sobekcm_type != TypeOfResource_SobekCM_Enum.Serial) && (sobekcm_type != TypeOfResource_SobekCM_Enum.Aerial) && (sobekcm_type != TypeOfResource_SobekCM_Enum.Photograph) && (sobekcm_type != TypeOfResource_SobekCM_Enum.Audio) && (sobekcm_type != TypeOfResource_SobekCM_Enum.Video) && (sobekcm_type != TypeOfResource_SobekCM_Enum.Artifact) && (sobekcm_type != TypeOfResource_SobekCM_Enum.Archival) && ( sobekcm_type != TypeOfResource_SobekCM_Enum.Dataset ))
            {
                builder008.Append("     s           ");
            }

            // Add the language code
            string language_code = "eng";
            if (Bib_Info.Languages_Count > 0)
            {
                foreach (Language_Info thisLanguage in Bib_Info.Languages)
                {
                    if (thisLanguage.Language_ISO_Code.Length > 0)
                    {
                        language_code = thisLanguage.Language_ISO_Code;
                        break;
                    }
                }
            }
            builder008.Append(language_code);

            builder008.Append(" d");

            //if (this.Bib_Info.Record.MARC_Record_Content_Sources.Count > 0)
            //{
            //    builder008.Append("d");
            //}
            //else
            //{
            //    builder008.Append("|");
            //}

            fixedField008.Control_Field_Value = builder008.ToString();
            tags.Add_Field(fixedField008);

            // Add the system name also as a 830 (before the collections)
            if (!String.IsNullOrEmpty(SystemName))
            {
                tags.Add_Field(new MARC_Field(830, " 0", "|a " + SystemName + "."));
            }

            // Add the collection name as well ( Was getting duplicates here sometimes )
            if (Behaviors.Aggregations != null)
            {
                List<string> added_already = new List<string>();
                foreach (Aggregation_Info thisAggr in Behaviors.Aggregations)
                {
                    if (( String.Compare(thisAggr.Code,"ALL", true ) != 0 ) && (( String.IsNullOrEmpty(thisAggr.Type)) || (thisAggr.Type.IndexOf("INSTITUT", StringComparison.InvariantCultureIgnoreCase) < 0)))
                    {
                        string collection = thisAggr.Name;
                        if (String.IsNullOrEmpty(collection)) collection = thisAggr.Code;

                        if (!added_already.Contains(collection.ToUpper().Trim()))
                        {
                            if (collection.Trim().Length > 0)
                            {
                                added_already.Add(collection.ToUpper().Trim());
                                tags.Add_Field(new MARC_Field(830, " 0", "|a " + collection + "."));
                            }
                        }
                    }
                }
            }

            // Add the thumbnail link (992)
            if ((Behaviors.Main_Thumbnail.Length > 0) && (!Behaviors.Dark_Flag))
            {

                string thumbnail_link = Path.Combine(web.Source_URL, Behaviors.Main_Thumbnail);

                if (!String.IsNullOrEmpty(ThumbnailBase))
                {
                    thumbnail_link = Path.Combine(ThumbnailBase, thumbnail_link);
                }

                tags.Add_Field(new MARC_Field(992, "04", "|a " + thumbnail_link.Replace("\\", "/").Replace("//", "/").Replace("http:/", "http://")));
            }

            // Was this born digital?  in which case this is NOT an electronic reproduction, so
            // leave out the 533 field
            bool borndigital = Bib_Info.Genres.Any(ThisGenre => (ThisGenre.Authority == "sobekcm") && (ThisGenre.Genre_Term == "born-digital"));
            if (!borndigital)
            {
                MARC_Field tag533 = new MARC_Field { Tag = 533, Indicators = "  " };
                StringBuilder builder533 = new StringBuilder(100);
                builder533.Append("|a Electronic reproduction. ");

                if ( !String.IsNullOrEmpty(ReproductionPlace))
                    builder533.Append("|b " + ReproductionPlace + " : ");

                List<string> agencies = new List<string>();
                if (!String.IsNullOrEmpty(ReproductionAgency))
                {
                    builder533.Append("|c " + ReproductionAgency + ", ");
                    agencies.Add(ReproductionAgency);
                }

                // Add the source statement as another agency possibly
                if (!String.IsNullOrEmpty(Bib_Info.Source.Statement))
                {
                    string source_statement = Bib_Info.Source.Statement;

                    // determine if this is a subset of any existing agency, or vice versa
                    bool found = false;
                    foreach (string thisAgency in agencies)
                    {
                        if ((source_statement.IndexOf(thisAgency, StringComparison.InvariantCultureIgnoreCase) >= 0) || (thisAgency.IndexOf(source_statement, StringComparison.InvariantCultureIgnoreCase) >= 0))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        builder533.Append("|c " + source_statement + ", ");
                        agencies.Add(source_statement);
                    }
                }

                // Add the source statement as another agency possibly
                if ((Bib_Info.hasLocationInformation) && (Bib_Info.Location.Holding_Code != Bib_Info.Source.Code) && (!String.IsNullOrEmpty(Bib_Info.Location.Holding_Name)))
                {
                    string holding_statement = Bib_Info.Location.Holding_Name;

                    // determine if this is a subset of any existing agency, or vice versa
                    bool found = false;
                    foreach (string thisAgency in agencies)
                    {
                        if ((holding_statement.IndexOf(thisAgency, StringComparison.InvariantCultureIgnoreCase) >= 0) || (thisAgency.IndexOf(holding_statement, StringComparison.InvariantCultureIgnoreCase) >= 0))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        builder533.Append("|c " + holding_statement + ", ");
                        agencies.Add(holding_statement);
                    }
                }

                builder533.Append("|d " + METS_Header.Create_Date.Year + ". ");
                if (!String.IsNullOrEmpty(SystemName))
                {
                    builder533.Append("|f (" + SystemName + ") ");
                }
                //foreach (string collection in Collection_Names)
                //{
                //    if (collection.Trim().Length > 0)
                //    {
                //        builder533.Append(" |f (" + collection + ")");
                //    }
                //}
                builder533.Append("|n Mode of access: World Wide Web.  |n System requirements: Internet connectivity; Web browser software.");
                tag533.Control_Field_Value = builder533.ToString();
                tags.Add_Field(tag533);
            }

            // Add the endeca only tags
            if (( !String.IsNullOrEmpty(SystemAbbreviation)) || ( !String.IsNullOrEmpty(LocationCode)))
            {
                // Add the 852
                MARC_Field tag852 = new MARC_Field { Tag = 852, Indicators = "  " };
                StringBuilder builder852 = new StringBuilder(100);

                if (!String.IsNullOrEmpty(LocationCode))
                {
                    builder852.Append("|a " + LocationCode + " ");
                    if (!String.IsNullOrEmpty(SystemAbbreviation))
                        builder852.Append("|b " + SystemAbbreviation);
                }
                else
                {
                    builder852.Append("|a " + SystemAbbreviation);
                }

                if ( !String.IsNullOrEmpty(first_aggr_name))
                    builder852.Append(" |c " + first_aggr_name);
                tag852.Control_Field_Value = builder852.ToString();
                tags.Add_Field(tag852);
            }

            // Add the collection name in the Endeca spot (997)
            if (!String.IsNullOrEmpty(first_aggr_name))
            {
                tags.Add_Field(new MARC_Field(997, "  ", "|a " + first_aggr_name));
            }

            // Now, set the leader
            tags.Leader = MARC_Leader();

            return tags;
        }
        internal override MARC_Field to_MARC_HTML()
        {
            MARC_Field returnValue = new MARC_Field();

            if ((String.IsNullOrEmpty(country)) && (String.IsNullOrEmpty(city)) && (String.IsNullOrEmpty(county)) && (String.IsNullOrEmpty(province)) && (String.IsNullOrEmpty(territory)) && (String.IsNullOrEmpty(citysection)))
            {
                if (!String.IsNullOrEmpty(area))
                {
                    returnValue.Tag = 752;
                    returnValue.Control_Field_Value = "|g " + area + ".";
                }
                if (!String.IsNullOrEmpty(region))
                {
                    returnValue.Tag = 752;
                    returnValue.Control_Field_Value = "|g " + region + ".";
                }
                return null;
            }

            // No indicators
            returnValue.Indicators = "  ";

            //if ((id.IndexOf("662") < 0) && (id.IndexOf("752") < 0) && (area.Length > 0)  && (country.Length == 0) && (city.Length == 0) && (county.Length == 0) && (province.Length == 0) && (territory.Length == 0) && ( citysection.Length == 0 ))
            //{
            //    returnValue.Tag = "752";
            //    returnValue.Field = "|g " + area;
            //}
            //else
            //{
            // Set the tag
            returnValue.Tag = 752;
            if (id.IndexOf("SUBJ662") == 0)
            {
                returnValue.Tag = 662;
            }

            StringBuilder fieldBuilder = new StringBuilder();
            if (!String.IsNullOrEmpty(country))
            {
                fieldBuilder.Append("|a " + country + " ");
            }

            if (!String.IsNullOrEmpty(state))
            {
                fieldBuilder.Append("|b " + state + " ");
            }
            else
            {
                if (!String.IsNullOrEmpty(territory))
                {
                    fieldBuilder.Append("|b " + territory + " ");
                }
                else if (!String.IsNullOrEmpty(province))
                {
                    fieldBuilder.Append("|b " + province + " ");
                }
            }
            if (!String.IsNullOrEmpty(county))
            {
                fieldBuilder.Append("|c " + county + " ");
            }
            if (!String.IsNullOrEmpty(city))
            {
                fieldBuilder.Append("|d " + city + " ");
            }
            if (!String.IsNullOrEmpty(citysection))
            {
                fieldBuilder.Append("|f " + citysection + " ");
            }
            if (!String.IsNullOrEmpty(area))
            {
                fieldBuilder.Append("|g " + area + " ");
            }
            if (!String.IsNullOrEmpty(island))
            {
                fieldBuilder.Append("|g " + island + " ");
            }

            if (fieldBuilder.Length > 2)
            {
                fieldBuilder.Remove(fieldBuilder.Length - 1, 1);
                fieldBuilder.Append(". ");
            }

            if (!String.IsNullOrEmpty(authority))
                fieldBuilder.Append("|2 " + authority + " ");

            returnValue.Control_Field_Value = fieldBuilder.ToString().Trim();
            //}

            return returnValue;
        }
        internal MARC_Field to_MARC_HTML()
        {
            MARC_Field related_item_tag = new MARC_Field
            {
                Indicators = "00",
                Tag = 787
            };
            switch (Relationship)
            {
                case Related_Item_Type_Enum.Host:
                    related_item_tag.Tag = 773;
                    related_item_tag.Indicators = "0 ";
                    break;

                case Related_Item_Type_Enum.OtherFormat:
                    related_item_tag.Tag = 776;
                    related_item_tag.Indicators = "0 ";
                    break;

                case Related_Item_Type_Enum.OtherVersion:
                    related_item_tag.Tag = 775;
                    related_item_tag.Indicators = "0 ";
                    break;

                case Related_Item_Type_Enum.Preceding:
                    related_item_tag.Tag = 780;
                    break;

                case Related_Item_Type_Enum.Succeeding:
                    related_item_tag.Tag = 785;
                    break;
            }

            StringBuilder relatedBuilder = new StringBuilder();
            string issn = String.Empty;
            string isbn = String.Empty;
            if (!String.IsNullOrEmpty(sobekcm_id))
            {
                relatedBuilder.Append("|o (UFDC)" + sobekcm_id + " ");
            }
            if ((title != null) && (title.Title.Length > 0))
            {
                relatedBuilder.Append("|t " + title.Title + " ");
            }
            if (identifiers != null)
            {
                foreach (Identifier_Info thisIdentifier in identifiers)
                {
                    switch (thisIdentifier.Type.ToUpper())
                    {
                        case "ISSN":
                            issn = thisIdentifier.Identifier;
                            break;

                        case "ISBN":
                            isbn = thisIdentifier.Identifier;
                            break;

                        case "OCLC":
                            relatedBuilder.Append("|w (OCoLC)" + thisIdentifier.Identifier + " ");
                            break;

                        case "LCCN":
                            relatedBuilder.Append("|w (DLC)sn" + thisIdentifier.Identifier + " ");
                            break;

                        default:
                            relatedBuilder.Append("|w " + thisIdentifier.Identifier + " ");
                            break;
                    }
                }
            }
            if (issn.Length > 0)
            {
                relatedBuilder.Append("|x " + issn + " ");
            }
            if (isbn.Length > 0)
            {
                relatedBuilder.Append("|z " + isbn + " ");
            }

            related_item_tag.Control_Field_Value = relatedBuilder.ToString();
            return related_item_tag;
        }
        /// <summary> Gets the SobekCM-specific tags to be written for this digital resource </summary>
        /// <param name="Collection_Names"> Collection of all the item aggregation names this digital resource is associated with </param>
        /// <param name="include_endeca_tags"> Flag indicates whether Endeca-specific tags should also be written </param>
        /// <param name="system_name"> Name of the host system, which is added into the MARC record </param>
        /// <param name="system_abbrev"> Abbreviation for the host system, which is added into the MARC record </param>
        /// <returns> Collection of MARC tags to be written for this digital resource </returns>
        public List<MARC_Field> MARC_Sobek_Standard_Tags(List<string> Collection_Names, bool include_endeca_tags, string system_name, string system_abbrev)
        {
            // Start to build the list of additional tags
            List<MARC_Field> tag_list = new List<MARC_Field>();

            if (system_name.Length > 0)
            {
                tag_list.Add(new MARC_Field(830, " 0", "|a " + system_name + "."));
            }

            // Was this born digital?  in which case this is NOT an electronic reproduction, so
            // leave out the 533 field
            bool borndigital = Bib_Info.Genres.Any(thisGenre => (thisGenre.Authority == "sobekcm") && (thisGenre.Genre_Term == "born-digital"));
            if (!borndigital)
            {
                MARC_Field tag533 = new MARC_Field {Tag = 533, Indicators = "  "};
                StringBuilder builder533 = new StringBuilder(100);
                builder533.Append("|a Electronic reproduction. ");
                if (Bib_Info.BibID.IndexOf("UF") == 0)
                    builder533.Append("|b Gainesville, Fla. : |c University of Florida, George A. Smathers Libraries, ");

                if (Bib_Info.Source.Code.IndexOf("UF") < 0)
                {
                    builder533.Append("|c " + Bib_Info.Source.Statement + ", ");
                }

                if ((Bib_Info.hasLocationInformation) && (Bib_Info.Location.Holding_Code.IndexOf("UF") < 0) && (Bib_Info.Location.Holding_Code != Bib_Info.Source.Code))
                {
                    builder533.Append("|c " + Bib_Info.Location.Holding_Name + ", ");
                }

                builder533.Append("|d " + METS_Header.Create_Date.Year + ". ");
                if (system_name.Length > 0)
                {
                    builder533.Append("|f (" + system_name + ")");
                }
                foreach (string collection in Collection_Names)
                {
                    if (collection.Trim().Length > 0)
                    {
                        builder533.Append(" |f (" + collection + ")");
                    }
                }
                builder533.Append("|n Mode of access: World Wide Web.  |n System requirements: Internet connectivity; Web browser software.");
                tag533.Control_Field_Value = builder533.ToString();
                tag_list.Add(tag533);
            }

            // Add the collection name as well ( Was getting duplicates here sometimes )
            List<string> added_already = new List<string>();
            foreach (string collection in Collection_Names)
            {
                if (!added_already.Contains(collection.ToUpper().Trim()))
                {
                    if (collection.Trim().Length > 0)
                    {
                        added_already.Add(collection.ToUpper().Trim());
                        tag_list.Add(new MARC_Field(830, " 0", "|a " + collection + "."));
                    }
                }
            }

            // REMOVED PER JIMMIE ( January 2010 )
            //tag_list.Add_Tag("530", "  ", "|a Also available in print.");

            // Add the endeca only tags
            if (include_endeca_tags)
            {
                // Add the thumbnail link (992)
                if ((Behaviors.Main_Thumbnail.Length > 0) && (!Behaviors.Dark_Flag))
                {
                    string thumbnail_link = web.Source_URL + "/" + Behaviors.Main_Thumbnail;
                    tag_list.Add(new MARC_Field(992, "04", "|a " + thumbnail_link.Replace("\\", "/").Replace("//", "/").Replace("http:/", "http://")));
                }

                // Add the 852
                MARC_Field tag852 = new MARC_Field {Tag = 852, Indicators = "  "};
                StringBuilder builder852 = new StringBuilder(100);
                builder852.Append("|a SUS01:;:;: ");
                if (system_abbrev.Length > 0)
                    builder852.Append("|b " + system_abbrev);
                if (Behaviors.Aggregation_Count > 0)
                    builder852.Append(" |c " + Behaviors.Aggregations[0].Name);
                tag852.Control_Field_Value = builder852.ToString();
                tag_list.Add(tag852);

                // Add the collection name in the Endeca spot (997)
                if (Collection_Names.Count > 0)
                {
                    tag_list.Add(new MARC_Field(997, "  ", "|a " + Collection_Names[0]));
                }
            }

            return tag_list;
        }
        internal MARC_Field to_MARC_HTML(int tag, int fill_indicator, string statement_of_responsibility, string h_field)
        {
            if (String.IsNullOrEmpty(title))
                return null;

            MARC_Field returnValue = new MARC_Field();
            StringBuilder fieldBuilder = new StringBuilder();
            returnValue.Tag = tag;
            if (tag < 0)
                returnValue.Tag = 0;
            returnValue.Indicators = "  ";
            string fill_indicator_value = "0";
            if (!String.IsNullOrEmpty(nonSort))
            {
                if (nonSort[nonSort.Length - 1] == ' ')
                    fill_indicator_value = (nonSort.Length).ToString();
                else
                {
                    if (nonSort[nonSort.Length - 1] == '\'')
                    {
                        fill_indicator_value = (nonSort.Length).ToString();
                    }
                    else
                    {
                        fill_indicator_value = (nonSort.Length + 1).ToString();
                        nonSort = nonSort + " ";
                    }
                }
            }

            if ((!String.IsNullOrEmpty(displayLabel)) && (displayLabel != "Uncontrolled") && (displayLabel != "Main Entry"))
            {
                fieldBuilder.Append("|i " + displayLabel + ": ");
            }

            if (!String.IsNullOrEmpty(nonSort))
            {
                fieldBuilder.Append("|a " + nonSort + title.Replace("|", "&bar;") + " ");
            }
            else
            {
                fieldBuilder.Append("|a " + title.Replace("|", "&bar;") + " ");
            }

            if (h_field.Length > 0)
            {
                fieldBuilder.Append("|h " + h_field + " ");
            }

            if (!String.IsNullOrEmpty(subtitle))
            {
                fieldBuilder.Append("|b " + subtitle + " ");
            }

            if (statement_of_responsibility.Length > 0)
            {
                fieldBuilder.Append("/ |c " + statement_of_responsibility + " ");
            }

            if (partNumbers != null)
            {
                foreach (string thisPart in partNumbers)
                {
                    fieldBuilder.Append("|n " + thisPart + " ");
                }
            }

            if (partNames != null)
            {
                foreach (string thisPart in partNames)
                {
                    fieldBuilder.Append("|p " + thisPart + " ");
                }
            }

            if (!String.IsNullOrEmpty(language))
            {
                fieldBuilder.Append("|y " + language + " ");
            }

            string completeField = fieldBuilder.ToString().Trim();
            if (completeField.Length > 0)
            {
                if (completeField[completeField.Length - 1] != '.')
                    returnValue.Control_Field_Value = completeField + ".";
                else
                    returnValue.Control_Field_Value = completeField;
            }

            if (returnValue.Tag <= 0)
            {
                switch (titleType)
                {
                    case Title_Type_Enum.uniform:
                        switch (displayLabel)
                        {
                            case "Main Entry":
                                returnValue.Tag = 130;
                                fill_indicator = 1;
                                break;

                            case "Uncontrolled":
                                returnValue.Tag = 730;
                                fill_indicator = 1;
                                break;

                            default:
                                returnValue.Tag = 240;
                                fill_indicator = 2;
                                break;
                        }
                        break;

                    case Title_Type_Enum.translated:
                        returnValue.Tag = 242;
                        fill_indicator = 2;
                        break;

                    case Title_Type_Enum.abbreviated:
                        returnValue.Tag = 210;
                        fill_indicator = -1;
                        break;

                    case Title_Type_Enum.alternative:
                        if ((!String.IsNullOrEmpty(displayLabel) && (displayLabel == "Uncontrolled")))
                        {
                            returnValue.Tag = 740;
                            fill_indicator = 1;
                        }
                        else
                        {
                            returnValue.Tag = 246;
                            fill_indicator = -1;
                            returnValue.Indicators = "3 ";
                            if (!String.IsNullOrEmpty(displayLabel))
                            {
                                switch (displayLabel)
                                {
                                    case "Portion of title":
                                        returnValue.Indicators = "30";
                                        break;

                                    case "Parallel title":
                                        returnValue.Indicators = "31";
                                        break;

                                    case "Distinctive title":
                                        returnValue.Indicators = "32";
                                        break;

                                    case "Other title":
                                        returnValue.Indicators = "33";
                                        break;

                                    case "Cover title":
                                        returnValue.Indicators = "34";
                                        break;

                                    case "Added title page title":
                                        returnValue.Indicators = "35";
                                        break;

                                    case "Caption title":
                                        returnValue.Indicators = "36";
                                        break;

                                    case "Running title":
                                        returnValue.Indicators = "37";
                                        break;

                                    case "Spine title":
                                        returnValue.Indicators = "38";
                                        break;

                                    default:
                                        returnValue.Indicators = "3 ";
                                        break;
                                }
                            }
                        }
                        break;
                }
            }

            switch (fill_indicator)
            {
                case 1:
                    returnValue.Indicators = fill_indicator_value + " ";
                    break;

                case 2:
                    returnValue.Indicators = " " + fill_indicator_value;
                    break;
            }

            return returnValue;
        }
        /// <summary> Writes this abstract as a MARC tag for aggregation into a MARC record </summary>
        /// <param name="ExcludeRelatorCodes"> Flag indicates to exclude the relator codes </param>
        /// <returns> Built MARC tag </returns>
        internal MARC_Field to_MARC_HTML(bool ExcludeRelatorCodes)
        {
            MARC_Field returnValue = new MARC_Field();
            StringBuilder fieldBuilder = new StringBuilder();

            // Get list of role codes first
            List<string> role_codes = new List<string>();
            List<string> role_texts = new List<string>();

            // Collect the codes first
            if (Roles != null)
            {
                foreach (Name_Info_Role thisRole in Roles)
                {
                    if ((thisRole.Role_Type == Name_Info_Role_Type_Enum.Code) && (thisRole.Authority == "marcrelator"))
                    {
                        role_codes.Add(thisRole.Role.ToLower());
                    }
                }

                // Collect the text next
                foreach (Name_Info_Role thisRole in Roles)
                {
                    if (((thisRole.Role_Type == Name_Info_Role_Type_Enum.Text) || (thisRole.Role_Type == Name_Info_Role_Type_Enum.UNSPECIFIED)) && (thisRole.Role.ToUpper() != "MAIN ENTITY") && (thisRole.Role.ToUpper() != "CREATOR"))
                    {
                        string code_from_text = Name_Info_MarcRelator_Code.Code_From_Text(thisRole.Role);
                        if ((code_from_text.Length > 0) && (!ExcludeRelatorCodes))
                        {
                            if (!role_codes.Contains(code_from_text))
                            {
                                role_codes.Add(code_from_text);
                            }
                        }
                        else
                        {
                            role_texts.Add(thisRole.Role.ToLower());
                        }
                    }
                }
            }

            switch (name_type)
            {
                case Name_Info_Type_Enum.Corporate:

                    returnValue.Indicators = "2 ";

                    if (!String.IsNullOrEmpty(full_name))
                    {
                        if (full_name.IndexOf(" -- ") > 0)
                        {
                            int corp_dash_index = full_name.IndexOf(" -- ");
                            fieldBuilder.Append("|a " + full_name.Substring(0, corp_dash_index) + " |b " + full_name.Substring(corp_dash_index + 4).Replace("|", "|b") + " ");
                        }
                        else
                        {
                            fieldBuilder.Append("|a " + full_name + " ");
                        }
                    }

                    if (!String.IsNullOrEmpty(description))
                        fieldBuilder.Append("|c " + description.Replace("|", "|c") + " ");

                    if (!String.IsNullOrEmpty(dates))
                        fieldBuilder.Append(", |d " + dates.Replace("|", "|d") + " ");

                    foreach (string thisRole in role_texts)
                    {
                        fieldBuilder.Append(", |e " + thisRole + " ");
                    }

                    if (!String.IsNullOrEmpty(affiliation))
                        fieldBuilder.Append("|u " + affiliation.Replace("|", "|u") + " ");

                    fieldBuilder.Append(". ");

                    if (!ExcludeRelatorCodes)
                    {
                        foreach (string thisRoleCode in role_codes)
                        {
                            fieldBuilder.Append("|4 " + thisRoleCode + " ");
                        }
                    }

                    returnValue.Control_Field_Value = fieldBuilder.ToString().Replace("  ", " ").Replace(" ,", ",").Replace(",,", ",").Replace("..", ".").Replace(" .", ".").Trim();
                    return returnValue;

                case Name_Info_Type_Enum.Conference:

                    returnValue.Indicators = "2 ";

                    if (!String.IsNullOrEmpty(full_name))
                    {
                        fieldBuilder.Append("|a " + full_name + " ");
                    }

                    if (!String.IsNullOrEmpty(description))
                        fieldBuilder.Append("|c " + description.Replace("|", "|c") + " ");

                    if (!String.IsNullOrEmpty(dates))
                        fieldBuilder.Append(", |d " + dates.Replace("|", "|d") + " ");

                    foreach (string thisRole in role_texts)
                    {
                        fieldBuilder.Append(", |j " + thisRole + " ");
                    }

                    if (!String.IsNullOrEmpty(affiliation))
                        fieldBuilder.Append("|u " + affiliation.Replace("|", "|u") + " ");

                    fieldBuilder.Append(". ");

                    if (!ExcludeRelatorCodes)
                    {
                        foreach (string thisRoleCode in role_codes)
                        {
                            fieldBuilder.Append("|4 " + thisRoleCode + " ");
                        }
                    }

                    returnValue.Control_Field_Value = fieldBuilder.ToString().Replace("  ", " ").Replace(" ,", ",").Replace(",,", ",").Replace("..", ".").Replace(" .", ".").Trim();
                    return returnValue;

                default:

                    // First, set the indicator and early name stuff
                    if ((Given_Name.Length == 0) && (Family_Name.Length == 0))
                    {
                        returnValue.Indicators = "  ";
                        string fullNameTesting = Full_Name.Trim();

                        fieldBuilder.Append("|a " + fullNameTesting + " ");

                        // If the full name has a comma just before the first space,
                        // (and it is a personal name being here) than this must be
                        // in inverted order, so set the indicator accordingly.
                        int comma_index = fullNameTesting.IndexOf(",");
                        int space_index = fullNameTesting.IndexOf(" ");
                        if ((comma_index > 0) && (space_index > 0) && (space_index == comma_index + 1))
                        {
                            returnValue.Indicator1 = '1';
                        }
                    }

                    if ((Given_Name.Length > 0) && (Family_Name.Length > 0))
                    {
                        returnValue.Indicators = "1 ";
                        fieldBuilder.Append("|a " + Family_Name + ", " + Given_Name + " ");
                    }

                    if ((Given_Name.Length == 0) && (Family_Name.Length > 0))
                    {
                        returnValue.Indicators = "3 ";
                        fieldBuilder.Append("|a " + Family_Name + " ");
                    }

                    if ((Given_Name.Length > 0) && (Family_Name.Length == 0))
                    {
                        returnValue.Indicators = "0 ";
                        fieldBuilder.Append("|a " + Given_Name + " ");
                    }

                    if (!String.IsNullOrEmpty(terms_of_address))
                    {
                        if (terms_of_address.IndexOf(";") > 0)
                        {
                            string[] toa_splitter = terms_of_address.Split(";".ToCharArray());
                            fieldBuilder.Append("|b " + toa_splitter[0].Trim().Replace("|", "|b") + " ");
                            fieldBuilder.Append("|c " + toa_splitter[1].Trim().Replace("|", "|c") + " ");
                        }
                        else
                        {
                            fieldBuilder.Append("|c " + terms_of_address.Replace("|", "|c") + " ");
                        }
                    }

                    if (!String.IsNullOrEmpty(display_form))
                    {
                        fieldBuilder.Append("|q (" + display_form + ") ");
                    }

                    if (!String.IsNullOrEmpty(dates))
                    {
                        fieldBuilder.Append(", |d " + dates.Replace("|", "|d") + " ");
                    }

                    foreach (string thisRole in role_texts)
                    {
                        fieldBuilder.Append(", |e " + thisRole + " ");
                    }

                    if (!String.IsNullOrEmpty(description))
                    {
                        if (description.IndexOf(";") > 0)
                        {
                            string[] desc_splitter = description.Split(";".ToCharArray());
                            fieldBuilder.Append("|g " + desc_splitter[0].Trim().Replace("|", "|g") + " ");
                            fieldBuilder.Append("|j " + desc_splitter[1].Trim().Replace("|", "|j") + " ");
                        }
                        else
                        {
                            fieldBuilder.Append("|g " + description.Replace("|", "|g") + " ");
                        }
                    }

                    if (!String.IsNullOrEmpty(affiliation))
                    {
                        fieldBuilder.Append("|u " + affiliation.Replace("|", "|u") + " ");
                    }

                    fieldBuilder.Append(". ");

                    if (!ExcludeRelatorCodes)
                    {
                        foreach (string thisRoleCode in role_codes)
                        {
                            fieldBuilder.Append("|4 " + thisRoleCode + " ");
                        }
                    }

                    returnValue.Control_Field_Value = fieldBuilder.ToString().Replace("  ", " ").Replace(" ,", ",").Replace(",,", ",").Replace("..", ".").Replace(" .", ".").Trim();
                    return returnValue;
            }
        }
        internal override MARC_Field to_MARC_HTML()
        {
            MARC_Field returnValue = new MARC_Field();

            // Set the tag
            returnValue.Tag = 255;
            if ((id.IndexOf("SUBJ") == 0) && (id.Length >= 7))
            {
                string possible_tag = id.Substring(4, 3);
                try
                {
                    int possible_tag_number = Convert.ToInt16(possible_tag);
                    returnValue.Tag = possible_tag_number;
                }
                catch
                {
                }
            }

            StringBuilder builder = new StringBuilder(50);
            if (!String.IsNullOrEmpty(scale))
                builder.Append("|a " + scale + " ");
            if (!String.IsNullOrEmpty(projection))
                builder.Append("|b " + projection + " ");
            if (!String.IsNullOrEmpty(coordinates))
                builder.Append("|c " + coordinates + " ");
            returnValue.Control_Field_Value = builder.ToString().Trim();

            return returnValue;
        }
        /// <summary> Analyzes this subject to determine the indicator based on the authority/source 
        /// when converting this subject into the equivalent MARC </summary>
        /// <param name="ReturnValue"> MARC Tag to add the indicator to </param>
        /// <param name="FieldBuilder"> Field builder to which the |2 source may be added if the source is not represented in the indicator </param>
        protected void Add_Source_Indicator(MARC_Field ReturnValue, StringBuilder FieldBuilder)
        {
            string second_indicator = " ";
            if (!String.IsNullOrEmpty(authority))
            {
                switch (authority.ToLower())
                {
                    case "lcnaf":
                    case "lcsh":
                        second_indicator = "0";
                        break;

                    case "lcshac":
                        second_indicator = "1";
                        break;

                    case "mesh":
                        second_indicator = "2";
                        break;

                    case "nal":
                        second_indicator = "3";
                        break;

                    case "csh":
                        second_indicator = "5";
                        break;

                    case "rvm":
                        second_indicator = "6";
                        break;

                    case "local":
                        second_indicator = "9";
                        break;

                    case "":
                        second_indicator = "4";
                        break;

                    default:
                        FieldBuilder.Append("|2 " + authority + " ");
                        second_indicator = "7";
                        break;
                }
            }

            ReturnValue.Indicators = ReturnValue.Indicators.Substring(0, 1) + second_indicator;
        }