private string AddSubmitterRecord(GedcomRecord record)
		{
			string xref;
			
			if (_lineValueType == GedcomLineValueType.PointerType)
			{
				xref = _lineValue;
				_missingReferences.Add(xref);
			}
			else
			{
				GedcomSubmitterRecord submitter = new GedcomSubmitterRecord();
				submitter.Level = 0; // always level 0
				submitter.ParsingLevel = _level + 1;
				submitter.XRefID = Database.GenerateXref("S");
				_ParseState.Records.Push(submitter);

				xref = submitter.XRefID;
			}
			
			return xref;
		}
		private void ReadSubmissionRecord()
		{
			GedcomSubmissionRecord submissionRecord;
			
			submissionRecord = _ParseState.Records.Peek() as GedcomSubmissionRecord;
			
			if (_level == submissionRecord.ParsingLevel + 1)
			{
				switch (_tag)
				{
					case "SUBM":
						if (_lineValueType == GedcomLineValueType.PointerType)
						{
							submissionRecord.Submitter = _lineValue;
							_missingReferences.Add(_lineValue);
						}
						else
						{
							GedcomSubmitterRecord submitter = new GedcomSubmitterRecord();
							submitter.Level = 0; // new top level submitter, always 0;
							submitter.ParsingLevel = _level;
							submitter.XRefID = Database.GenerateXref("SUBM");
							
							_ParseState.Records.Push(submitter);
							
							submissionRecord.Submitter = submitter.XRefID;
						}
						
						break;
					case "FAMF":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							submissionRecord.FamilyFile = _lineValue;	
						}
						break;
					case "TEMP":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							submissionRecord.TempleCode = _lineValue;	
						}
						break;
					case "ANCE":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							int num = 0;
							if (int.TryParse(_lineValue, out num))
							{
								submissionRecord.GenerationsOfAncestors = num;
							}
						}
						break;
					case "DESC":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							int num = 0;
							if (int.TryParse(_lineValue, out num))
							{
								submissionRecord.GenerationsOfDecendants = num;
							}
						}
						break;
					case "ORDI":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							submissionRecord.OrdinanceProcessFlag = (string.Compare(_lineValue, "YES", true) == 0); 	
						}
						break;
					case "RIN":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							submissionRecord.AutomatedRecordID = _lineValue;	
						}
						break;
					case "CHAN":
						GedcomChangeDate date = new GedcomChangeDate(Database);
						date.Level = _level;
						_ParseState.Records.Push(date);
						break;
					case "NOTE":
					    AddNoteRecord(submissionRecord);
						break;
				}
			}
			else
			{
				// shouldn't be here
				Debug.WriteLine("Unknown state / tag parsing submission node: " + _tag + "\t at level: " + _level);
			}
		}
		private void ReadIndividualRecord()
		{
			GedcomIndividualRecord individualRecord;
			
			individualRecord = _ParseState.Records.Peek() as GedcomIndividualRecord;
			
			GedcomIndividualEvent individualEvent;

			// some custom tags we convert to generic facts/events
			// this means we have to set the line value to the type
			// they represent, so store the real line value and use
			// for the event classification.
			string customToGenericClassification = string.Empty;
			
			if (_tag.StartsWith("_"))
			{
				switch (_tag)
				{
					// we convert _MILT to EVEN Military Service
					case "_MILT":
						_tag = "EVEN";
						_lineValue = "Military Service";
						_lineValueType = GedcomLineValueType.DataType;
						break;
					// we convert _MDCL to FACT Medical
					case "_MDCL":
						_tag = "FACT";
						customToGenericClassification = _lineValue;
						_lineValue = "Medical";
						_lineValueType = GedcomLineValueType.DataType;
						break;
					// we convert _HEIG to FACT Height
					case "_HEIG":
						_tag = "FACT";
						customToGenericClassification = _lineValue;
						_lineValue = "Height";
						_lineValueType = GedcomLineValueType.DataType;
						break;
					// we convert _WEIG to FACT Weight
					case "_WEIG":
						_tag = "FACT";
						customToGenericClassification = _lineValue;
						_lineValue = "Weight";
						_lineValueType = GedcomLineValueType.DataType;
						break;
					default:
						GedcomCustomRecord custom = new GedcomCustomRecord();
						custom.Level = _level;
						custom.XRefID = _xrefID;
						custom.Tag = _tag;
									
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							custom.Classification = _lineValue;
						}
						
						// FIXME: may want to use customs at some point
						//individualRecord.Events.Add(custom);
		
						_ParseState.Records.Push(custom);
						break;
				}
			}
			if (_level == individualRecord.ParsingLevel + 1)
			{
				switch (_tag)
				{
					case "FAMC":
						if (_lineValueType == GedcomLineValueType.PointerType)
						{
							GedcomFamilyLink childIn = new GedcomFamilyLink();
							childIn.Level = _level;
							childIn.Family = _lineValue;
							childIn.Indi = individualRecord.XRefID;
							
							_missingReferences.Add(_lineValue);
							
							individualRecord.ChildIn.Add(childIn);
							_ParseState.Records.Push(childIn);
							
						}
						break;
					case "FAMS":
						if (_lineValueType == GedcomLineValueType.PointerType)
						{
							GedcomFamilyLink spouseIn = new GedcomFamilyLink();
							spouseIn.Level = _level;
							spouseIn.Family = _lineValue;
							spouseIn.Indi = individualRecord.XRefID;
							spouseIn.PreferedSpouse = (individualRecord.SpouseIn.Count == 0);
							
							_missingReferences.Add(_lineValue);
							
							individualRecord.SpouseIn.Add(spouseIn);
							_ParseState.Records.Push(spouseIn);
						}
						break;
					case "ASSO":
						if (_lineValueType == GedcomLineValueType.PointerType)
						{
							GedcomAssociation association = new GedcomAssociation();
							association.Level = _level;
							association.Individual = _lineValue;
							
							_missingReferences.Add(_lineValue);
							
							individualRecord.Associations.Add(association);
							_ParseState.Records.Push(association);
						}
						break;
					case "RESN":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							try
							{
								individualRecord.RestrictionNotice = EnumHelper.Parse<GedcomRestrictionNotice>(_lineValue,true);
							}
							catch
							{
								Debug.WriteLine("Invalid restriction type: " + _lineValue);
								
								// default to confidential to protect privacy
								individualRecord.RestrictionNotice = GedcomRestrictionNotice.Confidential;
							}
						}
						break;
					case "NAME":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							GedcomName name = new GedcomName();
							name.Database = _ParseState.Database;
							name.Level = _level;
							name.Name = _lineValue;
							name.PreferedName = (individualRecord.Names.Count == 0);

							individualRecord.Names.Add(name);
							_ParseState.Records.Push(name);
						}
						break;
					// Invalid, but seen from Family Origins, Family Tree Maker, Personal Ancestral File, and Legacy
					case "AKA":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							GedcomName name = new GedcomName();
							name.Database = _ParseState.Database;
							name.Level = _level;
							name.Name = _lineValue;
							name.Type = "aka";
							name.PreferedName = (individualRecord.Names.Count == 0);
							individualRecord.Names.Add(name);
						}
						break;
					case "SEX":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							switch (_lineValue)
							{
								case "M":
									individualRecord.Sex = GedcomSex.Male;
									break;
								case "F":
									individualRecord.Sex = GedcomSex.Female;
									break;
								// non standard
								case "B":
									individualRecord.Sex = GedcomSex.Both;
									break;
								// non standard
								case "N":
									individualRecord.Sex = GedcomSex.Neuter;
									break;
								// non standard
								case "U":
									individualRecord.Sex = GedcomSex.Undetermined;
									break;
							}
						}
						break;
					case "SUBM":
						if (_lineValueType == GedcomLineValueType.PointerType)
						{
							individualRecord.SubmitterRecords.Add(_lineValue);
							_missingReferences.Add(_lineValue);
						}
						else
						{
							GedcomSubmitterRecord submitter = new GedcomSubmitterRecord();
							submitter.Level = 0; // new top level submitter, always 0
							submitter.ParsingLevel = _level;
							submitter.XRefID = Database.GenerateXref("SUBM");
							
							_ParseState.Records.Push(submitter);
							
							individualRecord.SubmitterRecords.Add(submitter.XRefID);
						}
						break;
					case "ALIA":
						if (_lineValueType == GedcomLineValueType.PointerType)
						{
							individualRecord.Alia.Add(_lineValue);	
							_missingReferences.Add(_lineValue);
						}
						else if (_lineValueType == GedcomLineValueType.DataType)
						{
							// Family Tree Maker doing this?
							// ALIA is unsupported in gedcom 5.5 as a way of
							// adding multiple names, the spec
							// does say it should be a pointer to an individual
							// though, not another name.
							// spec allows multiple NAME though, so add one
							// with this name
							GedcomName name = new GedcomName();
							name.Database = _ParseState.Database;
							name.Level = _level;
							name.Name = _lineValue;
							name.Type = "aka";
							name.PreferedName = (individualRecord.Names.Count == 0);
							individualRecord.Names.Add(name);
						}
						break;
					case "ANCI":
						if (_lineValueType == GedcomLineValueType.PointerType)
						{
							individualRecord.Anci.Add(_lineValue);	
							_missingReferences.Add(_lineValue);
						}
						break;
					case "DESI":
						if (_lineValueType == GedcomLineValueType.PointerType)
						{
							individualRecord.Desi.Add(_lineValue);	
							_missingReferences.Add(_lineValue);
						}
						break;
					case "RFN":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualRecord.PermanentRecordFileNumber = _lineValue;	
						}
						break;
					case "AFN":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualRecord.AncestralFileNumber = _lineValue;	
						}
						break;
					case "REFN":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualRecord.UserReferenceNumber = _lineValue;
						}
						break;
					case "RIN":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualRecord.AutomatedRecordID = _lineValue;
						}
						break;
					case "CHAN":
						GedcomChangeDate date = new GedcomChangeDate(Database);
						date.Level = _level;
						_ParseState.Records.Push(date);
						break;
					case "NOTE":
					    AddNoteRecord(individualRecord);
						break;
					case "SOUR":
					    AddSourceCitation(individualRecord);
						break;
					case "OBJE":
						AddMultimediaRecord(individualRecord);
						break;
					case "BIRT":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.BIRT;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "CHR":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.CHR;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "DEAT":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.DEAT;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "BURI":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.BURI;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "CREM":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.CREM;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "ADOP":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.ADOP;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "BAPM":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.BAPM;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "BARM":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.BARM;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "BASM":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.BASM;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "BLES":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.BLES;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "CHRA":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.CHRA;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "CONF":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.CONF;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "FCOM":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.FCOM;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "ORDN":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.ORDN;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "NATU":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.NATU;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "EMIG":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.EMIG;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "IMMI":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.IMMI;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "CENS":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.CENS;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "PROB":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.PROB;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;	
					case "WILL":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.WILL;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;		
					case "GRAD":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.GRAD;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;		
					case "RETI":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.RETI;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;		
					case "EVEN":
						
						// event
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.GenericEvent;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualEvent.EventName = _lineValue;
						}
					
						individualRecord.Events.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "CAST":
						
						// fact
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.CASTFact;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualEvent.EventName = _lineValue;
						}
					
						individualRecord.Attributes.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "DSCR":
						
						// fact
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.DSCRFact;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualEvent.EventName = _lineValue;
						}
					
						individualRecord.Attributes.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;	
					case "EDUC":
						
						// fact
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.EDUCFact;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;					
					
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualEvent.EventName = _lineValue;
						}
					
						individualRecord.Attributes.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;		
					case "IDNO":
						
						// fact
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.IDNOFact;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualEvent.EventName = _lineValue;
						}
					
						individualRecord.Attributes.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;		
					case "NATI":
						
						// fact
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.NATIFact;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualEvent.EventName = _lineValue;
						}
					
						individualRecord.Attributes.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;		
					case "NCHI":
						
						// fact
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.NCHIFact;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualEvent.EventName = _lineValue;
						}
					
						individualRecord.Attributes.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;		
					case "NMR":
						
						// fact
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.NMRFact;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualEvent.EventName = _lineValue;
						}
					
						individualRecord.Attributes.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;		
					case "OCCU":
						
						// fact
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.OCCUFact;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualEvent.EventName = _lineValue;
						}
					
						individualRecord.Attributes.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;		
					case "PROP":
						
						// fact
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.PROPFact;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualEvent.EventName = _lineValue;
						}
					
						individualRecord.Attributes.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;		
					case "RELI":
						
						// fact
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.RELIFact;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualEvent.EventName = _lineValue;
						}
					
						individualRecord.Attributes.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "RESI":
						
						// fact
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.RESIFact;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualEvent.EventName = _lineValue;
						}
					
						individualRecord.Attributes.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;	
					case "SSN":
						
						// fact
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.SSNFact;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualEvent.EventName = _lineValue;
						}
					
						individualRecord.Attributes.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;		
					case "TITL":
						
						// fact
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.TITLFact;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualEvent.EventName = _lineValue;
						}
					
						individualRecord.Attributes.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
					case "FACT":
						
						// fact
						individualEvent = new GedcomIndividualEvent();
						individualEvent.EventType = GedcomEvent.GedcomEventType.GenericFact;
						individualEvent.Level = _level;
						individualEvent.IndiRecord = individualRecord;
					
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualEvent.EventName = _lineValue;						
						}
						if (!string.IsNullOrEmpty(customToGenericClassification))
						{
							individualEvent.Classification = customToGenericClassification;
						}
						individualRecord.Attributes.Add(individualEvent);
					
						_ParseState.Records.Push(individualEvent);
					
						break;
										
					// Not according to the spec, but Family Tree Maker sticks
					// an address under an individual so we will support reading it
					case "ADDR":
						if (individualRecord.Address == null)
						{
							individualRecord.Address = new GedcomAddress();
							individualRecord.Address.Database = Database;
						}
						
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							individualRecord.Address.AddressLine = _lineValue;
						}
						
						break;
					case "PHON":
						if (individualRecord.Address == null)
						{
							individualRecord.Address = new GedcomAddress();	
							individualRecord.Address.Database = Database;
						}
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							if (string.IsNullOrEmpty(individualRecord.Address.Phone1))
							{
								individualRecord.Address.Phone1 = _lineValue;
							}
							else if (string.IsNullOrEmpty(individualRecord.Address.Phone2))
							{
								individualRecord.Address.Phone2 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(individualRecord.Address.Phone3))
							{
								individualRecord.Address.Phone3 = _lineValue;
							}
							else
							{
								// should never occur only 3 phone numbers are allowed	
							}
						}
						break;
					case "EMAIL":
						if (individualRecord.Address == null)
						{
							individualRecord.Address = new GedcomAddress();	
							individualRecord.Address.Database = Database;
						}
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							if (string.IsNullOrEmpty(individualRecord.Address.Email1))
							{
								individualRecord.Address.Email1 = _lineValue;
							}
							else if (string.IsNullOrEmpty(individualRecord.Address.Email2))
							{
								individualRecord.Address.Email2 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(individualRecord.Address.Email3))
							{
								individualRecord.Address.Email3 = _lineValue;	
							}
							else
							{
								// should never occur only 3 emails are allowed	
							}
						}
						break;
					case "FAX":
						if (individualRecord.Address == null)
						{
							individualRecord.Address = new GedcomAddress();	
							individualRecord.Address.Database = Database;
						}
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							if (string.IsNullOrEmpty(individualRecord.Address.Fax1))
							{
								individualRecord.Address.Fax1 = _lineValue;
							}
							else if (string.IsNullOrEmpty(individualRecord.Address.Fax2))
							{
								individualRecord.Address.Fax2 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(individualRecord.Address.Fax3))
							{
								individualRecord.Address.Fax3 = _lineValue;	
							}
							else
							{
								// should never occur only 3 fax numbers are allowed	
							}
						}
						break;
					case "WWW":
						if (individualRecord.Address == null)
						{
							individualRecord.Address = new GedcomAddress();	
							individualRecord.Address.Database = Database;
						}
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							if (string.IsNullOrEmpty(individualRecord.Address.Www1))
							{
								individualRecord.Address.Www1 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(individualRecord.Address.Www2))
							{
								individualRecord.Address.Www2 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(individualRecord.Address.Www3))
							{
								individualRecord.Address.Www3 = _lineValue;	
							}
							else
							{
								// should never occur only 3 urls are allowed	
							}
						}
						break;
				}
			}
			else if ( (!string.IsNullOrEmpty(_ParseState.PreviousTag)) &&
			            _level == _ParseState.PreviousLevel + 1)
			{
				string pTag = _ParseState.PreviousTag;
				
				if (pTag == "REFN" && _tag == "TYPE")
				{
					if (_lineValueType == GedcomLineValueType.DataType)
					{
						individualRecord.UserReferenceType = _lineValue;	
					}
				}
				else
				{
					AddressParse(individualRecord.Address, _tag, _lineValue, _lineValueType);	
				}
			}
			else if ( (!string.IsNullOrEmpty(_ParseState.PreviousTag)) &&
			            _level == _ParseState.PreviousLevel)
			{
				AddressParse(individualRecord.Address, _tag, _lineValue, _lineValueType);
			}
			else
			{
				// shouldn't be here
				Debug.WriteLine("Unknown state / tag parsing individual (" + individualRecord.XRefID + ") node: " + _tag + "\t at level: " + _level);
				System.Console.WriteLine("Unknown state / tag parsing individual (" + individualRecord.XRefID + ") node: " + _tag + "\t at level: " + _level);
				System.Console.WriteLine("Previous tag: " + _ParseState.PreviousTag + "\tPrevious Level: " + _ParseState.PreviousLevel);
			}
		}
		private void Parser_TagFound(object sender, EventArgs e)
		{
			_level = _Parser.Level;
			_xrefID = _Parser.XrefID;
			_tag = TagMap(_Parser.Tag);
			_lineValue = _Parser.LineValue;
			_lineValueType = _Parser.LineValueType;
					
			GedcomRecord current = null;

			// pop previous levels from the stack
			
			current = PopStack(_level);
			
			if (current == null)
			{
				switch (_tag)
				{
					case "FAM":
						
						// must have an xref id to have a family record
						// otherwise it can't be referenced anywhere
						if (!string.IsNullOrEmpty(_xrefID))
						{
							current = new GedcomFamilyRecord();
						}
						break;
					case "INDI":
						
						// must have an xref id to have an individual record
						// otherwise it can't be referenced anywhere
						if (!string.IsNullOrEmpty(_xrefID))
						{
							current = new GedcomIndividualRecord();
						}
						break;
					case "OBJE":
						
						// must have an xref id to have a multimedia record
						// otherwise it can't be referenced anywhere
						if (!string.IsNullOrEmpty(_xrefID))
						{
							current = new GedcomMultimediaRecord();
						}
						break;
					case "NOTE":
						
						// must have an xref id to have a note record
						// otherwise it can't be referenced anywhere
						if (!string.IsNullOrEmpty(_xrefID))
						{
							GedcomNoteRecord note = new GedcomNoteRecord();
							current = note;
							
							// set initial note text if needed
							
							if (_lineValueType == GedcomLineValueType.DataType)
							{
								note.ParsedText.Append(_lineValue);
							}
							else if (_lineValue != string.Empty)
							{
								// pointer to a note, this should not occur
								// as we should be at level 0 here
								
								Debug.WriteLine("Spurious Note pointer: " + _xrefID + "\t at level: " + _level);
							}
						}
						break;
					case "REPO":
						
						// must have an xref id to have a repository record
						// otherwise it can't be referenced anywhere
						if (!string.IsNullOrEmpty(_xrefID))
						{
							current = new GedcomRepositoryRecord();
						}
						break;
					case "SOUR":
						
						// must have an xref id to have a source record
						// otherwise it can't be referenced anywhere
						if (!string.IsNullOrEmpty(_xrefID))
						{
							current = new GedcomSourceRecord();
						}
						break;
					case "SUBM":
						
						// must have an xref id to have a submitter record
						// otherwise it can't be referenced anywhere
						if (!string.IsNullOrEmpty(_xrefID))
						{
							current = new GedcomSubmitterRecord();
						}
						break;
					case "HEAD":
						
						// header record
						current = new GedcomHeader();
					
						break;

					case "SUBN":

						// Submission record
						if (!string.IsNullOrEmpty(_xrefID))
						{
							current = new GedcomSubmissionRecord();
						}
						break;
						
					case "TRLR":
						
						break;
					default:
						
						// Unknown tag
						
						Debug.WriteLine("Unknown: " + _tag + " at level: " + _level);
						break;
				}
				
				// if we created a new record push it onto the stack
				if (current != null)
				{
					if (!string.IsNullOrEmpty(_xrefID))
					{
						current.XRefID = _xrefID;
					}
					current.Database = _ParseState.Database;
					current.Level = _level;
					_ParseState.Records.Push(current);
				}
			}
			else
			{
				switch (current.RecordType)
				{
					case GedcomRecordType.Header:
						ReadHeaderRecord();
						break;
					case GedcomRecordType.Family:
						ReadFamilyRecord();
						break;
					case GedcomRecordType.Individual:
						ReadIndividualRecord();
						break;
					case GedcomRecordType.Multimedia:
						ReadMultimediaRecord();
						break;
					case GedcomRecordType.Note:
						ReadNoteRecord();
						break;
					case GedcomRecordType.Repository:
						ReadRepositoryRecord();
						break;
					case GedcomRecordType.Source:
						ReadSourceRecord();
						break;
					case GedcomRecordType.Submitter:
						ReadSubmitterRecord();
						break;
					case GedcomRecordType.Submission:
						ReadSubmissionRecord();						
						break;
					
					// Non top level records
					case GedcomRecordType.Event:
						ReadEventRecord();
						break;
					case GedcomRecordType.FamilyEvent:
						ReadEventRecord();
						break;
					case GedcomRecordType.IndividualEvent:
						ReadEventRecord();
						break;
					
					case GedcomRecordType.Place:
						ReadPlaceRecord();
						break;
					case GedcomRecordType.SourceCitation:
						ReadSourceCitationRecord();
						break;
					case GedcomRecordType.FamilyLink:
						ReadFamilyLinkRecord();
						break;
					case GedcomRecordType.Association:
						ReadAssociationRecord();
						break;
					case GedcomRecordType.Name:
						ReadNameRecord();
						break;
					case GedcomRecordType.Date:
						ReadDateRecord();
						break;
					case GedcomRecordType.RepositoryCitation:
						ReadRepositoryCitation();
						break;
					case GedcomRecordType.CustomRecord:
						ReadEventRecord();
						break;
				}
			}
			
			_ParseState.AddPreviousTag(_tag, _level);
		}
		private void ReadFamilyRecord()
		{
			GedcomFamilyRecord familyRecord;
			
			// allowed sub records
			GedcomFamilyEvent familyEvent;
						
			familyRecord = _ParseState.Records.Peek() as GedcomFamilyRecord;
			
			if (_tag.StartsWith("_"))
			{
				switch (_tag)
				{
					case "_MSTAT":
						try
						{
							familyRecord.StartStatus = EnumHelper.Parse<MarriageStartStatus>(_lineValue, true);
						}
						catch
						{
							System.Diagnostics.Debug.WriteLine("Unknown marriage start state: " + _lineValue);
						}
						break;
					case "_FREL":
					case "_MREL":
						if ( (!string.IsNullOrEmpty(_ParseState.PreviousTag)) &&
						    _ParseState.PreviousTag == "CHIL" &&
						    _level == _ParseState.PreviousLevel + 1)
						{
							string childID = familyRecord.Children[familyRecord.Children.Count - 1];
							Gedcom.PedegreeLinkageType currentType = familyRecord.GetLinkageType(childID);
							
							Gedcom.GedcomAdoptionType linkTo = Gedcom.GedcomAdoptionType.Husband;
							if (_tag == "_MREL")
							{
								linkTo = Gedcom.GedcomAdoptionType.Wife;
							}
							
							switch (_lineValue)
							{
								case "Natural":
									familyRecord.SetLinkageType(childID, Gedcom.PedegreeLinkageType.Birth, linkTo);
									break;
								case "Adopted":
									familyRecord.SetLinkageType(childID, Gedcom.PedegreeLinkageType.Adopted, linkTo);
									break;
								default:
									System.Diagnostics.Debug.WriteLine("Unsupported value for " + _tag + ": " + _lineValue);
									break;
							}
							break;
						}
						
						break;
					default:
						GedcomCustomRecord custom = new GedcomCustomRecord();
						custom.Level = _level;
						custom.XRefID = _xrefID;
						custom.Tag = _tag;
						
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							custom.Classification = _lineValue;
						}
						
						// FIXME: may want to use customs at some point
						//familyRecord.Events.Add(custom);
						
						_ParseState.Records.Push(custom);
						break;
				}
			}
			else if (_level == familyRecord.ParsingLevel + 1)
			{
				switch (_tag)
				{
					case "RESN":
						
						// restriction notice
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							try
							{
								familyRecord.RestrictionNotice = EnumHelper.Parse<GedcomRestrictionNotice>(_lineValue,true);
							}
							catch
							{
								Debug.WriteLine("Invalid restriction type: " + _lineValue);
								
								// default to confidential to protect privacy
								familyRecord.RestrictionNotice = GedcomRestrictionNotice.Confidential;
							}
						}
						break;
					case "ANUL":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.ANUL);
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "CENS":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.CENS_FAM);				
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "DIV":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.DIV);				
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "DIVF":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.DIVF);
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "ENGA":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.ENGA);				
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "MARB":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.MARB);
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "MARC":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.MARC);
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "MARR":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.MARR);
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "MARL":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.MARL);
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "MARS":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.MARS);
						_ParseState.Records.Push(familyEvent);
					
						break;	
					case "RESI":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.RESI);
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "EVEN":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.GenericEvent);
					
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							familyEvent.EventName = _lineValue;
						}
										
						_ParseState.Records.Push(familyEvent);
					
						break;
					
					case "HUSB":
						if (_lineValueType == GedcomLineValueType.PointerType)
						{
							familyRecord.Husband = _lineValue;
							_missingReferences.Add(_lineValue);
						}
						break;
					case "WIFE":
						if (_lineValueType == GedcomLineValueType.PointerType)
						{
							familyRecord.Wife = _lineValue;
							_missingReferences.Add(_lineValue);
						}
						break;
					case "CHIL":
						if (_lineValueType == GedcomLineValueType.PointerType)
						{
							familyRecord.Children.Add(_lineValue);
							_missingReferences.Add(_lineValue);
						}
						break;
					case "NCHI":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							try
							{
								familyRecord.NumberOfChildren = Convert.ToInt32(_lineValue);
							}
							catch
							{
								Debug.WriteLine("Invalid number for Number of children tag");
							}
						}
						break;
					case "SUBM":
						if (_lineValueType == GedcomLineValueType.PointerType)
						{
							familyRecord.SubmitterRecords.Add(_lineValue);
							_missingReferences.Add(_lineValue);
						}
						else
						{
							GedcomSubmitterRecord submitter = new GedcomSubmitterRecord();
							submitter.Level = 0; // new top level submitter, always 0;
							submitter.ParsingLevel = _level;
							submitter.XRefID = Database.GenerateXref("SUBM");
							
							_ParseState.Records.Push(submitter);
							
							familyRecord.SubmitterRecords.Add(submitter.XRefID);
						}
						
						break;
					case "FIXME?????":
						// lds spouse sealing
						break;
					case "REFN":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							familyRecord.UserReferenceNumber = _lineValue;
						}
						break;
					case "RIN":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							familyRecord.AutomatedRecordID = _lineValue;	
						}
						break;
					case "CHAN":
						GedcomChangeDate date = new GedcomChangeDate(Database);
						date.Level = _level;
						_ParseState.Records.Push(date);
						break;
					case "NOTE":
					    AddNoteRecord(familyRecord);
						break;
					case "SOUR":
					    AddSourceCitation(familyRecord);				
						break;
					case "OBJE":
						AddMultimediaRecord(familyRecord);
						break;
				}
			}
			else if ( (!string.IsNullOrEmpty(_ParseState.PreviousTag)) &&
			            _ParseState.PreviousTag == "REFN" &&
			            _level == _ParseState.PreviousLevel + 1)
			{
				if (_tag == "TYPE")
				{
					if (_lineValueType == GedcomLineValueType.DataType)
					{
						familyRecord.UserReferenceType = _lineValue;
					}
				}
			}
			// not valid GEDCOM, but Family Tree Maker adds ADOP/FOST tags
			// to CHIL in a FAM, this is apparently valid in GEDCOM < 5.5
			else if ( (!string.IsNullOrEmpty(_ParseState.PreviousTag)) &&
			         _ParseState.PreviousTag == "CHIL" &&
			         _level == _ParseState.PreviousLevel + 1)
			{
				string childID = familyRecord.Children[familyRecord.Children.Count - 1];
				switch (_tag)
				{
					case "ADOP":
						switch (_lineValue)
						{
							case "HUSB":
								familyRecord.SetLinkageType(childID, Gedcom.PedegreeLinkageType.Adopted, Gedcom.GedcomAdoptionType.Husband);
								break;
							case "WIFE":
								familyRecord.SetLinkageType(childID, Gedcom.PedegreeLinkageType.Adopted, Gedcom.GedcomAdoptionType.Wife);
								break;
							case "BOTH":
							default:
								familyRecord.SetLinkageType(childID, Gedcom.PedegreeLinkageType.Adopted);
								break;
						}
						break;
					case "FOST":
						switch (_lineValue)
						{
							case "HUSB":
								familyRecord.SetLinkageType(childID, Gedcom.PedegreeLinkageType.Foster, Gedcom.GedcomAdoptionType.Husband);
								break;
							case "WIFE":
								familyRecord.SetLinkageType(childID, Gedcom.PedegreeLinkageType.Foster, Gedcom.GedcomAdoptionType.Wife);
								break;
							case "BOTH":
							default:
								familyRecord.SetLinkageType(childID, Gedcom.PedegreeLinkageType.Foster);
								break;
						}
						break;
				}
			}
			else
			{
				// shouldn't be here
				Debug.WriteLine("Unknown state / tag parsing family node: " + _tag + "\t at level: " + _level);
			}
		}