<!--#include file="copyright.asp" -->
<!--#include file="country.asp" --> 
<!--#include file="nameRelations.asp" --> 

<%
	'-----------------------------------------------------------------------------------------------------------------------
	' PTaxonDetail.asp - August 2003 - Javier de la Torre
	'
	' This file shows information about one or more potential taxons. It can recieve different parameters and with them
	' it constructs the SQL statements that is needed to select all the PTaxon that match this criteria.
	' When the PTaxon are selected then each one is represented inside a gray table. For each PTaxon there are many other
	' connections to the database that had to be made to get all the needed information.
	'
	' Parameters:
	' NameCache: String --> Cache field of the name table
	' NameId: Integer --> Id of the Name of the potential taxons
	' PTRefFk: integer --> Id of the reference of the potential taxons
	'
	'-----------------------------------------------------------------------------------------------------------------------
%>

<%
'Show back buttons
backToSearch = 1  'Shows the backToSearch-Button
backToResult = 1  'Shows the backToResult-Button
%>

<%
	Dim hierarchy()
	Dim facts()
	
	' Construct the SQL statement depending on the paramenter passed.
	' That selects all the potential taxon.
%>

<TABLE cellSpacing="0" cellPadding="5" width="100%" border="0">
	<TBODY>
		<TR>
			<TD vAlign="middle" width="5">
				<IMG height="19" width="17" alt="" src="images/logo_mini.jpg" border="0"> 
			</TD>
			<TD noWrap><B>Details for Taxon: <i><%=NameTotal%></i></B></TD>
			<TD width="100%"> <HR SIZE=1> </TD>
		</TR>
	</TBODY>
</TABLE>



<%
	Dim NameA(7)
 		'I first obtain the information that belongs to this potential taxon:
		
		nameID = Request("NameId")
		PTRefFk = Request("PTRefFk")
		'error handling
		if nameID = "" then nameID = "0"
		if PTRefFk = "" then PTRefFk = "0"
		
		SQL= _
				" SELECT PTaxon.PTNameFk, PTaxon.DoubtfulFlag, PTaxon.PTRefFk, PTaxon.IdInSource , Status.Status, PTaxon.StatusFk, Reference.NomTitleAbbrev, Reference.RefCache, PTaxon.Notes, Rank.Rank, Rank.RankId " & _
				" FROM Rank RIGHT JOIN ((Reference RIGHT JOIN (Name RIGHT JOIN (PTaxon LEFT JOIN Status ON PTaxon.StatusFk = Status.StatusId) ON Name.NameId = PTaxon.PTNameFk) ON Reference.RefId = PTaxon.PTRefFk) ) ON Rank.RankId = Name.RankFk " & _
				" WHERE ( ((PTaxon.PTNameFK)= " & nameID & ") AND ((PTaxon.PTRefFk)=" & PTRefFk & ") )"
			Set Rptaxon = Server.CreateObject("ADODB.Recordset")
			openRecordset RPtaxon, SQL

  If (Not RPtaxon.EOF) then
				'... then select all the information posible from this name
				SQL = " SELECT RefDetail.Notes as RefNote, RefDetail.Details, Name.NameCache, Name.FullNameCache, Name.NameId, Name.Genus, Name.SpeciesEpi, Name.InfraSpeciesEpi, Name.GenusSubdivisionEpi, Reference.NomTitleAbbrev, Reference.Volume, RefDetail.Details, Reference.InRefFk, Reference.RefYear, RefDetail.FullNomRefCache, Name.AuthorTeamFk, Name.ExAuthorTeamFk, Name.BasAuthorTeamFk, Name.ExBasAuthorTeamFk, Rank.RankAbbrev, NomStatus.NomStatus, Name.Notes, Name.UnnamedNamePhrase, Name.RankFk " & _ 
						" FROM NomStatus RIGHT JOIN ((((Name LEFT JOIN Reference ON Name.NomRefFk = Reference.RefId) LEFT JOIN RefDetail ON Name.NomRefDetailFk = RefDetail.RefDetailId) INNER JOIN Rank ON Name.RankFk = Rank.RankId) LEFT JOIN NomStatusRel ON Name.NameId = NomStatusRel.NameFk) ON NomStatus.NomStatusId = NomStatusRel.NomStatusFk " & _ 
						" WHERE (((Name.NameId) = " & Rptaxon("PTNameFk") &" ))"
	
				Set Rname = Server.CreateObject("ADODB.Recordset")
				openRecordset Rname, SQL


 '------------------------- printer friendly ------------------------
' Show the google images link only if is not a printer-frendly request

if Request("Print")<>1 then %>
	<div align="right">
		<a href="http://mobot.mobot.org/cgi-bin/search_vast?name=<%=RName("NameCache")%>" target="_blank"><strong>Link to species in Tropicos</strong></a>
		 | 
		<a href="http://images.google.com/images?as_q=<%=RName("NameCache")%>&num=20&btnG=Google%2BSearch&as_epq=&hl=&as_oq=&as_eq=&imgsz=&as_filetype=&imgc=&as_sitesearch=&imgsafe=active" target="_blank"><strong>Google Images</strong></a> 
	</div>
	<br>
<%end if

'------------------------------------------------------------------

			'0--> Name Part (Juncus Roemeriani)
			'1--> Authors string (L.)
			'2--> Complete Reference starting with ", " (, Byull. Moskovsk. Obshch. Isp. Prir., Otd. Biol., 95: 117 (1990))
			'3--> status part (,nom. illeg.)
			'4--> non part (,non Buchenau(1545))
			'5--> total, all in the same 0+1+2+3+4
			'6--> 0+1
			'7--> Name notes


			if Rname("notes")="ll" then
				'if there's something in the notes field i will use this as the complete name. This solution is valid for the IOPI project
				NameA(0)=Rname("FullNameCache")
				NameA(1)="Not parsed, see the notes"
				NameA(2)="Not parsed, see the notes"
				NameA(3)="Not parsed, see the notes"
				NameA(4)="Not parsed, see the name"
				NameA(5)=Rname("FullNameCache")
				NameA(6)=Rname("FullNameCache")
				NameA(7)=Rname("Notes")
			else
				'I have to add the status of the name (nomenclature status). It's possible to have more than one status, but maximum here is 2
				If Rname("NomStatus")<>"" then
					' changed for MCL
					status_part= Replace(Rname("NomStatus"),"nom. rej. prop.","nom. rejic. prop.")
					if (status_part = "") then 
						status_part = ""
					end if
					if Rname.Recordcount > 1 then
						'There's more than one status
						Rname.movenext
						'changed for MCL
						status_part=status_part & ", " & Replace(Rname("NomStatus"),"nom. rej. prop.","nom. rejic. prop.")
					End if
				End if
	
				NameA(0)=Rname("NameCache")
				' by Andreas
				if (NOT  ISNULL(Rname("FullNameCache")) AND NOT ISNULL(Rname("NameCache"))) Then
					NameA(1)=Replace(Rname("FullNameCache"),Rname("NameCache"),"")
				else
					NameA(1)=Rname("FullNameCache")
				end if
				' by Andreas
				if  (NOT ISNUll(Rname("FullNomRefCache"))) Then
					NameA(2)=Replace(Rname("FullNomRefCache"),"vol. ", "") & " " & Rname("RefNote")
				else
					NameA(2)= Rname("FullNomRefCache") & " " & Rname("RefNote")
				end if
				'by Andreas
				if (Rname("Details") <> "") then 
					NameA(2)=Replace(NameA(2),", " & Rname("Details"), ": " & Rname("Details"))
				end if
				NameA(3)=status_part
				NameA(4)=non_part
				'by Andreas
				'NameA(5)=Rname("FullNameCache") &", " & Rname("FullNomRefCache")
				NameA(6)=Rname("FullNameCache")
				NameA(7)=Rname("Notes")
			end if

			Rname.close
			set Rname=Nothing
%>

<% '--------------------- tabel color---------------------------------- 
			 if Rptaxon("StatusFk")=1 then
					table_color=color_acc 
               else
			   		table_color=color_syn
              end if
%>
<!-- --------------------print taxon tabel ------------------------------->
 				<table width="100%" border="1" cellpadding="0" cellspacing="4" bordercolor="#666666"  style="border-collapse: collapse">
                  <tr>
                    <td> <a name="<%=cont_sources%>"></a>
					<TABLE width="100%" cellspacing="6" bgcolor="<%=table_color%>" >
                        <TBODY>
                         
	<!--  ------------------ SOURCE ----------------------------------------- -->
						  <TR>
                            <TD width="16%" valign="top">
								<br><strong>Source:</strong>
							</TD>
                            <TD width="84%">
								<strong><font color="#990000">
									<br>
									<%=Rptaxon("Refcache")%>
									<br>
								</font></strong>
							</td>
                          </TR>
                          
	<!-- ------------------ MCL number  --------------------------------------- -->
						  <% if (len (Rptaxon("IdInSource")) > 0) then		%>				 
							  <TR>
								<TD width="16%" valign="top">
									<strong>MCL No.:</strong>
								</TD>
								<TD width="84%">
									<strong><font color="#000000">
										<%=Rptaxon("IdInSource")%>
										<br><br>
									</font></strong>
								</TD>
                          	   </TR>
							<%end if%>
<!-- ------------------ NAME  --------------------------------------- -->
						  <TR>
                            <TD width="16%" valign="top">
								<STRONG>Name:</STRONG>
							</TD>
                            <TD width="84%">
								<B><%=NameA(6)%></B>
							</TD>
                          </TR>
<!-- ------------------ Nomencl. ref.  --------------------------------------- -->
                      <% if len(NameA(2)) > 0 then %>
						  <TR>
                            <TD width="16%" valign="top"><STRONG>Nomencl. ref.:</STRONG></TD>
                            <TD><I><B><%=NameA(2)%></B></I></TD>
                          </TR>
					  <%end if %>

<!-- ------------------ Nomencl. status  --------------------------------------- -->
					  	<% if len(NameA(3)) > 0 then %>
                          <TR>
                            <TD width="16%" valign="top"><STRONG>Nomencl. status(es):</STRONG></TD>
                            <TD><% = NameA(3)%></I></TD>
                          </TR>
						<%end if %>
<%



	'---------------- Rank -------------------------------------------------------------------
%>
                          <TR>
							<TD width="16%" valign="top"><STRONG>Rank:</STRONG></TD>
                            <TD><%=Rptaxon("Rank")%></TD>
                          </TR>

<%
' ---------------------------- NAME RELATIONS --------------------------------------------------------------------------			
%>
<%			
' ----------------------------  RELATED TO ------------------------------------------------------------
'Is this name related to another name ? (e.g. this is basionym of that)

			SQL=" SELECT NameFrom.NameId, NameTo.NameId AS NameIdTo, NameTo.FullNameCache, RelName.RelNameQualifierFk relQualFk, RelNameQualifier.RelNameQualifier " & _ 
				" FROM Name NameFrom INNER JOIN Name NameTo INNER JOIN RelName ON NameTo.NameId = RelName.NameFk2 ON NameFrom.NameId = RelName.NameFk1 " & _ 
					" INNER JOIN RelNameQualifier On RelNameQualifier.RelNameQualifierId = RelName.RelNameQualifierFk " & _
				" WHERE (NameFrom.NameId="& Request("NameId")& ")"
			
			'MCL specific
			'no basionyms and no syn. subst.
			SQL=SQL & " AND RelName.RelNameQualifierFk <> 1 AND RelName.RelNameQualifierFk <> 3 "
			
			Set RRelTo = Server.CreateObject("ADODB.Recordset")
			openRecordset RRelTo, SQL
			While (NOt RRelTo.EOF)
			%>
			              <TR>
                            <TD width="16%" valign="top"><STRONG><%=RRelTo("RelNameQualifier")& ":"%></STRONG></TD>
                            <TD><A href="NamesDetail.asp?NameId=<%=RRelTo("NameIdTo")%>">
								<%=RRelTo("FullNameCache")%></A></TD>
                          </TR>
                          <%
						  RRelTo.moveNext
			WEnd
			RRelTo.close
			set RRelTo=Nothing
			
			
' ----------------------------  RELATED FROM ------------------------------------------------------------
'IS a name related to this name ?

			SQL=" SELECT NameTo.NameId, NameFrom.NameId AS NameIdFrom, NameFrom.FullNameCache, RelName.RelNameQualifierFk relQualFk " & _ 
				" FROM Name NameFrom INNER JOIN Name NameTo INNER JOIN RelName ON NameTo.NameId = RelName.NameFk2 ON NameFrom.NameId = RelName.NameFk1 " & _ 
				" WHERE (NameTo.NameId="& Request("NameId")& ")"
			'MCL specific
			'no basionyms and no syn. subst.
			SQL=SQL & " AND RelName.RelNameQualifierFk <> 1 AND RelName.RelNameQualifierFk <> 3 "
			
			
			Set RRelFrom = Server.CreateObject("ADODB.Recordset")
			openRecordset RRelFrom, SQL
			While (NOt RRelFrom.EOF)
			%>
			              <TR>
                            <TD width="16%" valign="top"><STRONG><%=getNameRelation(RRelFrom("relQualFk")) & ":"%></STRONG></TD>
                            <TD><A href="NamesDetail.asp?NameId=<%=RRelFrom("NameIdFrom")%>">
								<%=RRelFrom("FullNameCache")%></A></TD>
                          </TR>
                          <%
						  RRelFrom.moveNext
			WEnd
			RRelFrom.close
			set RRelFrom=Nothing


 ' ------------------ STATUS OF TAXON ----------------------------------------------------
 %>
                          <TR>
                            <TD width="16%" valign="top"><STRONG>Status:</STRONG></TD>
                            <TD>
							  <%if Rptaxon("StatusFk")=1 then%>
									<font color=green>
                              <%else%>
							  		<font color=red>
                              <%end if%>
                              <%
                              ' If the DoubtfulFlag is set to d then show a PRELIMARY text in fron of the status
                              if Rptaxon("DoubtfulFlag")="d" then%>PRELIMINARY<% end if %>
                              <b><%=ucase(Rptaxon("Status"))%></b></font></TD>
                          </TR>
<%



'--------------HIERARCHY----------------------------------------------------------------------------
' See where this taxon is included. 
'only check hierarchy if the PTaxon is accepted, if not it is not supposed to be linked to anything (integrity rule)
			if Rptaxon("StatusFk")=1 then
				'First we will store in an array all the hierarchy in inverse order, then they will be shown. This array will
				' be three dimensional, the first dimension will store the nameid, the second the refid and the tirth
				' the namecache field. The very first is an index.
				nameid=Rptaxon("PTNameFk")
				refid=Rptaxon("PTRefFk")
				ReDim hierarchy(3,0)
				control=1
				cont=0
				While control=1
					SQL="SELECT PTaxon_1.PTNameFk, PTaxon_1.PTRefFk, Name.NameCache, Name.FullNameCache, Reference.RefCache, Name.Notes AS NameNotes, Rank.Rank"&_
					" FROM (PTaxon AS PTaxon_1 INNER JOIN Name ON PTaxon_1.PTNameFk = Name.NameId) INNER JOIN (PTaxon INNER JOIN RelPTaxon ON (PTaxon.PTNameFk = RelPTaxon.PTNameFk1) AND (PTaxon.PTRefFk = RelPTaxon.PTRefFk1)) ON (PTaxon_1.PTNameFk = RelPTaxon.PTNameFk2) AND (PTaxon_1.PTRefFk = RelPTaxon.PTRefFk2) INNER JOIN Reference ON PTaxon_1.PTRefFk = Reference.RefId INNER JOIN Rank ON Name.RankFk = Rank.RankId"&_
					" WHERE (((PTaxon.PTNameFk)="&nameid&") AND ((PTaxon.PTRefFk)="&refid&") AND ((RelPTaxon.RelQualifierFk)=1)) ORDER BY Name.NameCache"
					Set Rherar = Server.CreateObject("ADODB.Recordset")
					openRecordset  Rherar, SQL
					if Rherar.Recordcount > 0 then
						nameid=Rherar("PTNameFk")
						refid=Rherar("PTRefFk")
						Redim Preserve hierarchy(3,cont)
						hierarchy(0,cont)=nameid
						hierarchy(1,cont)=refid
						'Show the reference as "sec." when the reference is different from the one using the potential taxon
						if Rherar("PTRefFk")<> refid then
							hierarchy(2,cont)="<strong>"&Rherar("FullNameCache") & "</strong> sec. " & Rherar("RefCache")
						else
							hierarchy(2,cont)="<strong>"&Rherar("FullNameCache") & "</strong>"
						end if
						hierarchy(3,cont)=Rherar("Rank")
						cont=cont+1
					else
						nameid=""
						refid=""
						control=0
					end if
					Rherar.close
					set Rherar=Nothing
				Wend
				If hierarchy(0,0)<>"" then
				%>
					  <TR>
						<TD width="16%" valign="top"><STRONG>Taxonomy (this taxon is included in):</STRONG></TD>
						<TD>
						<%
							col=0
							for i=ubound(hierarchy,2) to 0 step -1
						%>
						<%=hierarchy(3,i)%> - <A href="PTaxonDetail.asp?NameId=<%=hierarchy(0,i)%>&PTRefFk=<%=hierarchy(1,i)%>"><%=hierarchy(2,i)%></A><br><%for c=0 to col%>&nbsp;&nbsp;&nbsp;&nbsp;<%next%>
						<%
						col=col+1
						next %>
						</TD>
					  </TR>
				<%
				end if
			
				Redim hierarchy(0)
				hierarchy(0)=""
			end if
%>


<%'-------------------- ACCEPTED NAME -----------------------------------------------------------------------

' If the taxon is a synonymum find the accepted name. 

if Rptaxon("StatusFk") = 2 then
				SQL= "SELECT PTaxon_1.PTNameFk, PTaxon_1.PTRefFk, Name.NameCache, Name.FullNameCache, Name.Notes AS NameNotes" & _
				" FROM (PTaxon AS PTaxon_1 INNER JOIN Name ON PTaxon_1.PTNameFk = Name.NameId) INNER JOIN (PTaxon INNER JOIN RelPTaxon ON (PTaxon.PTNameFk = RelPTaxon.PTNameFk1) AND (PTaxon.PTRefFk = RelPTaxon.PTRefFk1)) ON (PTaxon_1.PTNameFk = RelPTaxon.PTNameFk2) AND (PTaxon_1.PTRefFk = RelPTaxon.PTRefFk2)" & _
				" WHERE (((PTaxon.PTNameFk)="&Rptaxon("PTNameFk")&") AND ((PTaxon.PTRefFk)="&Rptaxon("PTRefFk")&") AND ((RelPTaxon.RelQualifierFk) in (2, 4, 5, 6, 7))) ORDER BY Name.NameCache"
			
				Set Racc = Server.CreateObject("ADODB.Recordset")
				openRecordset  Racc, SQL
				if Racc.Recordcount>0 then
					contador=0
					While NOT Racc.EOF
					contador=contador+1
			%>

						  <TR>
							<TD width="16%" valign="top"><%if contador=1 then%>
							  <STRONG>Synonym of:</STRONG>
							  <%end if%></TD>
							<TD><A href="PTaxonDetail.asp?NameId=<%=Racc("PTNameFk")%>&PTRefFk=<%=Racc("PTRefFk")%>"><%=Racc("FullNameCache")%></A></TD>
						  </TR>
			<%
					Racc.Movenext
					Wend
					Racc.Close
					set Racc=Nothing
				end if
			end if
%>


<%'----------------- SYNONYMS -------------------------------------------------------------------------------------------
'Look for synonyms only if the potential taxon is accepted. SYNONYMS

			if Rptaxon("StatusFk")=1 then
				SQL= _ 
					" SELECT PTaxon_1.PTNameFk, PTaxon_1.PTRefFk AS PTRefFk_s, Name.NameCache, Name.FullNameCache, Name.Notes AS NameNotes, Name.UnnamedNamePhrase, PTaxon.PTRefFk AS PTRefFk, RelPTQualifier.RelPTQualifier "&_
					" FROM (PTaxon AS PTaxon_1 INNER JOIN (PTaxon INNER JOIN RelPTaxon ON (PTaxon.PTNameFk = RelPTaxon.PTNameFk2) AND (PTaxon.PTRefFk = RelPTaxon.PTRefFk2)) ON (PTaxon_1.PTNameFk = RelPTaxon.PTNameFk1) AND (PTaxon_1.PTRefFk = RelPTaxon.PTRefFk1)) INNER JOIN Name ON PTaxon_1.PTNameFk = Name.NameId INNER JOIN RelPTQualifier ON RelPTaxon.RelQualifierFk = RelPTQualifier.RelPTQualifierId " & _
					"  WHERE (((PTaxon.PTNameFk)="&Rptaxon("PTNameFk")&") AND ((PTaxon.PTRefFk)="&Rptaxon("PTRefFk")&") AND ((RelPTaxon.RelQualifierFk) in (2,4,5,6,7))) ORDER BY RelPTQualifier.RelPTQualifier DESC,Name.RankFk, Name.NameCache"
			
				Set Rsyn = Server.CreateObject("ADODB.Recordset")
				openRecordset  Rsyn, SQL
				if Rsyn.Recordcount>0 then
					contador=0
					syn_rel=""
					While NOT Rsyn.EOF
					contador=contador+1
			%>
									  <TR>
										<TD width="16%" valign="top">
										  <%if contador=1 or syn_rel<>Rsyn("RelPTQualifier") then%>
												<STRONG><%=ucase(left(Trim(Replace(Replace(Rsyn("RelPTQualifier"),"is",""),"of","")),1))&right(Trim(Replace(Replace(Rsyn("RelPTQualifier"),"is",""),"of","")),len(Trim(Replace(Replace(Rsyn("RelPTQualifier"),"is",""),"of","")))-1)&"(s):"%></STRONG>
										  <%end if%>
										</TD>
										<TD><A href="PTaxonDetail.asp?NameId=<%=Rsyn("PTNameFk")%>&PTRefFk=<%=Rsyn("PTRefFk_s")%>"><strong><%=Rsyn("FullNameCache")%></strong></A></TD>
									  </TR>
									  <%
						syn_rel=Rsyn("RelPTQualifier")
					Rsyn.Movenext
			
					Wend
					Rsyn.Close
					set Rsyn=Nothing
				end if
			end if
%>

<%'------------------------MISAPPLIED NAMES--------------------------------------------------------------------------------
'Look for misapplied names only if the potential taxon is accepted 

			if Rptaxon("StatusFk")=1 then
				SQL= _
					" SELECT PTaxon_1.PTNameFk, PTaxon_1.PTRefFk AS PTRefFk_s, Name.NameCache, Name.FullNameCache, Name.Notes AS NameNotes, PTaxon.PTRefFk AS PTRefFk, RelPTQualifier.RelPTQualifier as RelQualifier, RelPTaxon.Notes as RelNotes, Reference.RefCache"&_
					"  FROM (PTaxon AS PTaxon_1 INNER JOIN (PTaxon INNER JOIN RelPTaxon ON (PTaxon.PTNameFk = RelPTaxon.PTNameFk2) AND (PTaxon.PTRefFk = RelPTaxon.PTRefFk2)) ON (PTaxon_1.PTNameFk = RelPTaxon.PTNameFk1) AND (PTaxon_1.PTRefFk = RelPTaxon.PTRefFk1)) INNER JOIN Name ON PTaxon_1.PTNameFk = Name.NameId INNER JOIN RelPTQualifier ON RelPTaxon.RelQualifierFk = RelPTQualifier.RelPTQualifierId INNER JOIN Reference ON PTaxon_1.PTRefFk = Reference.RefId"&_
					"  WHERE (((PTaxon.PTNameFk)="&Rptaxon("PTNameFk")&") AND ((PTaxon.PTRefFk)="&Rptaxon("PTRefFk")&") AND ((RelPTaxon.RelQualifierFk)=3)) ORDER BY Name.NameCache"
			
				Set Rmiss = Server.CreateObject("ADODB.Recordset")
				openRecordset  Rmiss, SQL
				if Rmiss.Recordcount > 0 then
					contador=0
					While NOT Rmiss.EOF
					contador=contador + 1
			%>
									  <TR>
										<TD width="16%" valign="top">
										<%if contador=1 then%>
											<STRONG>Misapplied Name(s):</STRONG>
										<%end if%>
										</TD>
										<TD><A href="PTaxonDetailMiss.asp?NameId=<%=Rmiss("PTNameFk")%>&PTRefFk=<%=Rmiss("PTRefFk_s")%>">
										<strong><%=Rmiss("FullNameCache")%></strong> sec. <%=Left(Rmiss("RefCache") & Rmiss("RelNotes"), 50) & "..." %></A></TD>
									  </TR>
			<%
			
					Rmiss.Movenext
					Wend
					Rmiss.Close
					set Rmiss=Nothing
				end if
			end if
%>

<%'-----------------INCLUDED TAXA------------------------------------------------------------------------------------
'Look for included taxa only if the potential taxon is accepted. INCLUDED TAXA, hierarchy DOWN

			if Rptaxon("StatusFk")=1 then
				SQL="SELECT PTaxon_1.PTNameFk, PTaxon_1.PTRefFk, Name.FullNameCache, Reference.RefCache, Reference.RefId AS RefId "&_
				" FROM Reference INNER JOIN ((PTaxon AS PTaxon_1 INNER JOIN (PTaxon INNER JOIN RelPTaxon ON (PTaxon.PTNameFk = RelPTaxon.PTNameFk2) AND (PTaxon.PTRefFk = RelPTaxon.PTRefFk2)) ON (PTaxon_1.PTNameFk = RelPTaxon.PTNameFk1) AND (PTaxon_1.PTRefFk = RelPTaxon.PTRefFk1)) INNER JOIN Name ON PTaxon_1.PTNameFk = Name.NameId) ON Reference.RefId = PTaxon_1.PTRefFk "&_
				" WHERE (((PTaxon.PTNameFk)="&Rptaxon("PTNameFk")&") AND ((PTaxon.PTRefFk)="&Rptaxon("PTRefFk")&") AND ((RelPTaxon.RelQualifierFk)=1)) "&_
				" ORDER BY Name.FullNameCache"
			
				Set Rinclu = Server.CreateObject("ADODB.Recordset")
				openRecordset  Rinclu, SQL
				
				if Rinclu.Recordcount>0 then
					
					contador=0
					%><tr></tr><tr></tr><tr></tr><%
					While NOT Rinclu.EOF
					contador=contador+1
			%>
						<TR>
						<TD width="16%" valign="top"><%if contador=1 then%> <STRONG>Included taxa:</STRONG>
						<%end if%></TD>
						<TD>
							<A href="PTaxonDetail.asp?NameId=<%=Rinclu("PTNameFk")%>&PTRefFk=<%=Rinclu("PTRefFk")%>"><strong><%=Rinclu("FullNameCache")%></strong>
							<%if Rinclu("PTRefFk")<>Rptaxon("PTRefFk") then%> sec. <%=Rinclu("RefCache")%><%end if%></A>
						</TD>
						</TR>
			<%
					Rinclu.Movenext
					Wend
					Rinclu.Close
					set Rinclu=Nothing
				end if
			end if

%>


<%'---------------------------NOTES----------------------------------------------------------------------------------------
'There are two type of notes here, the one from the potential taxon and the one from the name. Show them if there´s something inside

			 if NameA(7)<>"" then %>
			
									  <TR>
										<TD width="16%" valign="top"><STRONG>Name Notes:</STRONG></TD>
										<TD><%=NameA(7)%></TD>
									  </TR>
			<%end if%>
			
			<% if Rptaxon("Notes")<>"" then %>
									  <TR>
										<TD width="16%" valign="top"><STRONG>Taxon Notes:</STRONG></TD>
										<TD><%=Rptaxon("Notes")%></TD>
									  </TR>
			<%end if%>
									  <TR>
										<TD width="16%" valign="top"></TD>
										<TD>&nbsp;</TD>
									  </TR>
			
<% '-------------- OCCURENCE ------------------------------------------------------------------------------------------

'TODO Anfragen Rfacts20 + Rfacts21 können noch zusammengefasst werden, wenn alles so bleibt

' Show the Type information
	SQL= _
			" SELECT Fact.Fact, FactCategory.FactCategory, FactCategory.FactCategoryId " & _
			" FROM (PTaxon INNER JOIN Fact ON (PTaxon.PTRefFk = Fact.PTRefFk) AND (PTaxon.PTNameFk = Fact.PTNameFk)) INNER JOIN FactCategory ON Fact.FactCategoryFk = FactCategory.FactCategoryId " & _
			" WHERE (((PTaxon.PTNameFk)=" & Rptaxon("PTNameFk")&") " & _ 
			" 		AND ((PTaxon.PTRefFk)=" & Rptaxon("PTRefFk")&")) " & _
			" 		AND (FactCategory.FactCategoryId = 20) "
	SET Rfacts20 = Server.CreateObject("ADODB.Recordset")
	openRecordset  Rfacts20, SQL
	
	SQL= _
			" SELECT Fact.Fact, FactCategory.FactCategory, FactCategory.FactCategoryId, Reference.IdInSource as ref " & _
			" FROM (PTaxon INNER JOIN Fact ON (PTaxon.PTRefFk = Fact.PTRefFk) AND (PTaxon.PTNameFk = Fact.PTNameFk)) " & _ 
				" INNER JOIN FactCategory ON Fact.FactCategoryFk = FactCategory.FactCategoryId " & _
				" LEFT OUTER JOIN Reference ON Fact.FactRefFK = Reference.RefId " & _
			" WHERE (((PTaxon.PTNameFk)=" & Rptaxon("PTNameFk")&") " & _ 
			" 		AND ((PTaxon.PTRefFk)=" & Rptaxon("PTRefFk")&")) " & _
			" 		AND (FactCategory.FactCategoryId = 21) " & _
			" ORDER BY Fact.Fact"
	SET Rfacts21 = Server.CreateObject("ADODB.Recordset")
	openRecordset  Rfacts21, SQL
	
	
	IF Rfacts20.RecordCount > 0 THEN
	'----- Category 20--------------------------
		 
		While ( NOT Rfacts20.EOF )
		%>
				<TR>
					<TD width="16%" valign="top">
						<STRONG>Occurrence status:</STRONG>
					</TD>
					<TD width="84%">
						<font color="#990000">
								<%
								IF (Rfacts20("Fact") = "E") THEN
									Response.Write("Endemic")
								ELSEIF (Rfacts20("Fact") = "X") THEN
									Response.Write("Xenophyte")
								ELSE 
									Response.Write("ERROR: unknown")
								END IF
								%>
								<br><br>
							</font>
					</TD>
				</TR>
<% 
			Rfacts20.MoveNext
		WEnd
	END IF
	Rfacts20.close
	SET Rfacts20=Nothing
	
	IF (Rfacts21.RecordCount > 0) THEN
		%>
			<TR>
				<TD width="16%" valign="top"><STRONG>Geographical occurrence:</STRONG></TD>
				<TD width="84%">
					<% 
					While ( NOT Rfacts21.EOF )
					%>
						<TABLE cellSpacing="0" cellPadding="0" width="100%" border="0">
							<TBODY>
								<TR>
									<TD width="20%" valign="top">
										<%
											Response.Write(getCountryName(Left(Rfacts21("Fact"), 2)))
										%>
									</TD>
									<TD width="80%">
										<font color="#010000">
											<%
												writeOccuranceType(Right (Rfacts21("Fact"),1))
											%>
												
											<%
												ref = Rfacts21("ref")
												if (ref = null or isNull(ref)) then
													' nothing
												elseif(left(ref, 5) = "Basic") then
													floraNr= right(ref, len(ref)-6)
													Response.Write("&nbsp;<A href=""appendix1.asp?floraNr=" & floraNr & "#activ"">"	)
													Response.Write ("(" & floraNr & ")")
													Response.Write ("</A>")
												else
													floraNr= right(ref, len(ref)-9)
													volumeNr= mid(ref, 6, 1)
													Response.Write("&nbsp;<A href=""appendix2.asp?floraNr=" & floraNr & "&volume=" & volumeNr  &"#activ"">")
													Response.Write ("(" & floraNr & ")")
													Response.Write ("</A>")
												end if
											%>
											
										</font>
									</TD>
								</TR>
							</TBODY>
						</TABLE>
			<% 
						Rfacts21.MoveNext
					WEnd
			%>
				</TD>
			</TR>
				<%
	ELSE   ' no MCL-facts
		%> <!-- 
			<TR>
				<TD width="16%" valign="top"> -</TD>
				<TD width="84%">
					no information found
					<br><br>
				</TD>
			</TR  -->
		<%
	END IF  
	Rfacts21.close
	SET Rfacts21=Nothing



'-----------END of TAXON --------------------------------------------------------------------------------------------------------
%>

				</TBODY>
			</table></td>
		  </tr>
		</table>
		

<%
	else ' no taxon found matching the requested data
		Response.Write("<BR><STRONG> No matching data found!</STRONG><BR>")
	End if
	
	Rptaxon.close
	set Rptaxon = Nothing

%>
<!--include file="backButton.asp" -->
<!--#include file="copyright_end.asp" -->