<%
Function DisplayAnnouncesSplitPages

	Dim Rs,SQL
	Dim ALL_FirstRootID,ALL_LastRootID,ALL_FirstTopicSortID,ALL_LastTopicSortID
	SQL = "Select Top 1 RootIDBak,TopicSortID from LeadBBS_Announce where boardid=" & GBL_board_ID & " Order by RootIDBak DESC,TopicSortID"
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	If Not Rs.Eof Then
		ALL_FirstRootID = cCur(Rs(0))
		ALL_FirstTopicSortID = cCur(Rs(1))
	Else
		ALL_FirstRootID = 0
		ALL_FirstTopicSortID = 0
	End If
	Rs.Close
	Set Rs = Nothing
	SQL = "Select Top 1 RootIDBak,ID from LeadBBS_Announce where boardid=" & GBL_board_ID & " Order by RootIDBak ASC,TopicSortID"
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	If Not Rs.Eof Then
		ALL_LastRootID = cCur(Rs(0))
		ALL_LastTopicSortID = cCur(Rs(1))
	Else
		ALL_LastRootID = 0
		ALL_LastTopicSortID = 0
	End If
	Rs.Close
	Set Rs = Nothing

	SQL = "Select max(TopicSortID) from LeadBBS_Announce where boardid=" & GBL_board_ID & " and RootIDBak=" & ALL_LastRootID
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	If Not Rs.Eof Then
		If isNull(Rs(0)) Then
			ALL_LastTopicSortID = 0
		Else
			ALL_LastTopicSortID = cCur(Rs(0))
		End If
	Else
		ALL_LastTopicSortID = 0
	End If
	Rs.Close
	Set Rs = Nothing

	Dim ALL_Count
	'SQL = "Select count(*) from LeadBBS_Announce where boardid=" & GBL_board_ID
	'Rs.Open SQL,con,1,1
	'GBL_DBNum = GBL_DBNum + 1
	'If Not Rs.Eof Then
	'	If isNull(Rs(0)) Then
	'		ALL_Count = 0
	'	Else
	'		ALL_Count = cCur(Rs(0))
	'	End If
	'Else
	'	ALL_Count = 0
	'End If
	'Rs.Close	
	All_Count = GBL_Board_AnnounceNum

	Dim RootID,TopicSortID,Temp1,Temp2
	Dim SQLEndString,Upflag,WhereFlag
	WhereFlag = 0

	RootID = Left(Request("RootID"),14)
	TopicSortID = Left(Request("TopicSortID"),14)
	If isNumeric(TopicSortID)=0 Then TopicSortID=0
	If isNumeric(RootID)=0 Then RootID=0
	RootID = cCur(RootID)
	TopicSortID = cCur(TopicSortID)
	
	Upflag = Request("Upflag")
	If Upflag<>"1" and Upflag<>"0" Then Upflag="0"

	Dim HaveTopicSortIDFlag,HaveRootIDFlag
	Dim FirstRootID,LastRootID,FirstTopicSortID,LastTopicSortID
	Dim GetData
	If TopicSortID<>0 and RootID<>0 Then
		If Upflag="0" Then
			SQLEndString = " where boardid=" & GBL_board_ID
			WhereFlag = 1
			If WhereFlag = 1 Then
				SQLEndString = SQLEndString & " and (RootIDBak=" & RootID & " and TopicSortID>" & TopicSortID & ")"
			Else
				SQLEndString = SQLEndString & " Where (RootIDBak=" & RootID & " and TopicSortID>" & TopicSortID & ")"
				WhereFlag = 1
			End If
		Else
			If WhereFlag = 1 Then
				SQLEndString = SQLEndString & " and (RootIDBak=" & RootID & " and TopicSortID<" & TopicSortID & ")"
			Else
				SQLEndString = SQLEndString & " where (RootIDBak=" & RootID & " and TopicSortID<" & TopicSortID & ")"
				WhereFlag = 1
			End If
		End If

		If Upflag="0" Then
			SQLEndString = SQLEndString & " order by TopicSortID ASC"
		Else
			SQLEndString = SQLEndString & " order by TopicSortID DESC"
		End If
		SQL = "select top " & DEF_MaxListNum & " id,ParentID,ChildNum,Layer,Title,FaceIcon,ndatetime,Hits,Length,UserName,UserID,RootIDBak,TopicSortID,TitleStyle from LeadBBS_Announce " & SQLEndString
		Set Rs = Con.ExeCute(SQL)
		GBL_DBNum = GBL_DBNum + 1
		If Not Rs.Eof Then
			HaveTopicSortIDFlag = 1
			GetData = Rs.GetRows(-1)
		Else
			HaveTopicSortIDFlag = 0
		End If
		Rs.Close
		Set Rs = Nothing
	Else
		HaveTopicSortIDFlag = 0
	End If

	If HaveTopicSortIDFlag = 1 Then
		Temp1 = Ubound(GetData,2)
		FirstRootID = cCur(GetData(11,0))
		LastRootID = cCur(GetData(11,Temp1))
		FirstTopicSortID = cCur(GetData(12,0))
		LastTopicSortID = cCur(GetData(12,Temp1))
	
		If FirstRootID<LastRootID Then
			SQL = FirstRootID
			FirstRootID = LastRootID
			LastRootID = SQL
		End If
	
		If FirstTopicSortID>LastTopicSortID Then
			SQL = LastTopicSortID
			LastTopicSortID = FirstTopicSortID
			FirstTopicSortID = SQL
		End If
	Else
		Temp1 = 0
	End If
	

	If Temp1+1<DEF_MaxListNum or HaveTopicSortIDFlag = 0 Then

		SQLEndString = " where boardid=" & GBL_board_ID
		WhereFlag = 1
		If Upflag="0" Then
			If RootID<>0 Then
				If WhereFlag = 1 Then
					SQLEndString = SQLEndString & " And RootIDBak<" & RootID
				Else
					SQLEndString = SQLEndString & " Where RootIDBak<" & RootID
					WhereFlag = 1
				End If
			End If
		Else
			If RootID>=ALL_FirstRootID Then
				RootID = ALL_FirstRootID-1
				TopicSortID = ALL_FirstRootID + 1
			
				If RootID<>0 Then
					If WhereFlag = 1 Then
						SQLEndString = SQLEndString & " And RootIDBak>" & RootID
					Else
						SQLEndString = SQLEndString & " Where RootIDBak>" & RootID
						WhereFlag = 1
					End If
				End If

				If WhereFlag = 1 Then
					SQLEndString = SQLEndString & " And TopicSortID<" & TopicSortID
				Else
					SQLEndString = SQLEndString & " Where TopicSortID<" & TopicSortID
					WhereFlag = 1
				End If
			Else
				If RootID<>0 Then
					If WhereFlag = 1 Then
						SQLEndString = SQLEndString & " And RootIDBak>" & RootID
					Else
						SQLEndString = SQLEndString & " Where RootIDBak>" & RootID
						WhereFlag = 1
					End If
				End If
			End If
		End If

		If Upflag="0" Then
			SQLEndString = SQLEndString & " order by RootIDBak DESC,TopicSortID"
		Else
			SQLEndString = SQLEndString & " order by RootIDBak ASC,TopicSortID DESC"
		End If

		Dim FirstRootID_2,LastRootID_2,FirstTopicSortID_2,LastTopicSortID_2
		Dim GetData_2

		If HaveTopicSortIDFlag = 1 Then
			SQL = 	DEF_MaxListNum-Temp1-1
		Else
			SQL = 	DEF_MaxListNum
		End If
		If SQL < 1 Then SQL = 1
		SQL = "select top " & SQL & " id,ParentID,ChildNum,Layer,Title,FaceIcon,ndatetime,Hits,Length,UserName,UserID,RootIDBak,TopicSortID,TitleStyle from LeadBBS_Announce " & SQLEndString
		Set Rs = Con.ExeCute(SQL)
		GBL_DBNum = GBL_DBNum + 1
		If Not Rs.Eof Then
			HaveRootIDFlag = 1
			GetData_2 = Rs.GetRows(-1)
		Else
			HaveRootIDFlag = 0
		End If
		Rs.Close
		Set Rs = Nothing
	
		If HaveRootIDFlag = 1 Then
			Temp2 = Ubound(GetData_2,2)
			FirstRootID_2 = cCur(GetData_2(11,0))
			LastRootID_2 = cCur(GetData_2(11,Temp2))
			FirstTopicSortID_2 = cCur(GetData_2(12,0))
			LastTopicSortID_2 = cCur(GetData_2(12,Temp2))
	
			If FirstRootID_2<LastRootID_2 Then
				SQL = FirstRootID_2
				FirstRootID_2 = LastRootID_2
				LastRootID_2 = SQL
			End If
	
			If FirstTopicSortID_2>LastTopicSortID_2 Then
				SQL = LastTopicSortID_2
				LastTopicSortID_2 = FirstTopicSortID_2
				FirstTopicSortID_2 = SQL
			End If
	
			If HaveTopicSortIDFlag = 1 Then
				If FirstRootID<FirstRootID_2 Then
					SQL = FirstRootID_2
					FirstRootID_2 = FirstRootID
					FirstRootID = SQL
				End If
		
		
				If LastRootID>LastRootID_2 Then
					SQL = LastRootID_2
					LastRootID_2 = LastRootID
					LastRootID = SQL
				End If
				If FirstRootID = LastRootID Then
					If FirstTopicSortID>FirstTopicSortID_2 Then
						SQL = FirstTopicSortID
						FirstTopicSortID = FirstTopicSortID_2
						FirstTopicSortID_2 = SQL
					End If
			
					If LastTopicSortID<LastTopicSortID_2 Then
						SQL = LastTopicSortID
						LastTopicSortID = LastTopicSortID_2
						LastTopicSortID_2 = SQL
					End If
				Else
					If Upflag="0" Then
						FirstTopicSortID = FirstTopicSortID
						LastTopicSortID = LastTopicSortID_2
					Else
						FirstTopicSortID = FirstTopicSortID_2
						LastTopicSortID = LastTopicSortID
					End If
				End If
			Else
				FirstTopicSortID = FirstTopicSortID_2
				LastTopicSortID = LastTopicSortID_2
				LastRootID = LastRootID_2
				FirstRootID = FirstRootID_2
			End If
		Else
			Temp2 = 0
		End If
	Else
		HaveRootIDFlag = 0
	End If

	SQL = "?BoardID=" & GBL_board_ID
	Dim PageSplitString,PageSplitString2
	PageSplitString = "<tr bgcolor=" & DEF_BBS_LightestColor & " height=25 class=TBBG9><td colspan=5><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td><img src=" & DEF_BBS_HomeUrl & "images/null.gif width=2 height=2><br>&nbsp;"
	If FirstRootID >= All_FirstRootID and FirstTopicSortID<=ALL_FirstTopicSortID Then
		PageSplitString = PageSplitString & "<font color=888888 class=GrayFont>首页</font>"
		PageSplitString = PageSplitString & " <font color=888888 class=GrayFont>上页</font>"
	Else
		PageSplitString = PageSplitString & "<a href=Board2.asp" & SQL & ">首页</a>"
		PageSplitString = PageSplitString & " <a href=Board2.asp" & SQL & "&RootID=" & FirstRootID & "&TopicSortID=" & FirstTopicSortID & "&Upflag=1>上页</a>"
	End If

	If LastRootID <= All_LastRootID and LastTopicSortID>=ALL_LastTopicSortID Then
		PageSplitString = PageSplitString & " <font color=888888 class=GrayFont>下页</font>"
		PageSplitString = PageSplitString & " <font color=888888 class=GrayFont>尾页</font>"
	Else
		PageSplitString = PageSplitString & " <a href=Board2.asp" & SQL & "&RootID=" & LastRootID & "&TopicSortID=" & LastTopicSortID & ">下页</a>"
		PageSplitString = PageSplitString & " <a href=Board2.asp" & SQL & "&Upflag=1>尾页</a>"
	End If
	Rs = Temp1
	If HaveTopicSortIDFlag = 1 Then Rs = Rs+1
	Rs = Temp2+Rs
	If HaveRootIDFlag = 1 Then Rs = Rs+1
	PageSplitString = PageSplitString & " 此版共有<b>" & ALL_Count &"</b>帖 此页<b>" & Rs & "</b>帖 每页<b>" & DEF_MaxListNum & "</b>帖<td align=right><img src=" & DEF_BBS_HomeUrl & "images/null.gif width=2 height=2><br>"
	
	PageSplitString2 = "</td></tr></table></td></tr>"

	Dim For1,For2,StepValue
	%>
	<%If GBL_TableHeadString <> "" Then%><table width=<%=DEF_BBS_ScreenWidth%> border=0 cellspacing=0 cellpadding=0 align=center><tr><td><%=GBL_TableHeadString%></td></tr></table><%End If%>
	<table width="<%=DEF_BBS_ScreenWidth%>" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="<%=DEF_BBS_DarkColor%>" class=TBone>
	<tr>
		<td>
	<table width="100%" border="0" cellspacing="1" cellpadding="3" align="center">
	<%'Response.Write PageSplitString
	'Response.Write PageSplitString2%>
	<tr height=20 bgcolor=<%=DEF_BBS_LightDarkColor%> align=center class=TBHead2>
		<td width=45 align=center class=TBHead2><img src=<%=DEF_BBS_HomeUrl%>images/null.gif width=2 height=2><br><b><font color=ffffff class=HeadFont>ID</font></b></td>
		<td align=left class=TBHead2><img src=<%=DEF_BBS_HomeUrl%>images/null.gif width=300 height=2><br>&nbsp;<b><font color=ffffff class=HeadFont>主题</font></b></td>
		<td width=84 class=TBHead2><img src=<%=DEF_BBS_HomeUrl%>images/null.gif width=2 height=2><br><b><font color=ffffff class=HeadFont>作者</font></b></td>
		<td width=27 class=TBHead2><img src=<%=DEF_BBS_HomeUrl%>images/null.gif width=2 height=2><br><b><font color=ffffff class=HeadFont>点击</font></b></td>
		<td width=115 class=TBHead2><img src=<%=DEF_BBS_HomeUrl%>images/null.gif width=2 height=2><br><b><font color=ffffff class=HeadFont>时间</font></b></td>
	</tr><%
	If Upflag="0" Then
		If HaveTopicSortIDFlag = 1 Then
			If Upflag="0" Then
				For1 = 0
				For2 = Temp1
				StepValue = 1
			Else
				For1 = Temp1
				For2 = 0
				StepValue = -1
			End If
			DisplayAnnounceData For1,For2,StepValue,GetData
		End If

		If HaveRootIDFlag = 1 Then
			If Upflag="0" Then
				For1 = 0
				For2 = Temp2
				StepValue = 1
			Else
				For1 = Temp2
				For2 = 0
				StepValue = -1
			End If
			DisplayAnnounceData For1,For2,StepValue,GetData_2
		End If
	Else

		If HaveRootIDFlag = 1 Then
			If Upflag="0" Then
				For1 = 0
				For2 = Temp2
				StepValue = 1
			Else
				For1 = Temp2
				For2 = 0
				StepValue = -1
			End If
			DisplayAnnounceData For1,For2,StepValue,GetData_2
		End If

		If HaveTopicSortIDFlag = 1 Then
			If Upflag="0" Then
				For1 = 0
				For2 = Temp1
				StepValue = 1
			Else
				For1 = Temp1
				For2 = 0
				StepValue = -1
			End If
			DisplayAnnounceData For1,For2,StepValue,GetData
		End If
	End If
	Response.Write PageSplitString
	%>
	<!-- #include file=../../inc/IncHtm/BoardJump2.asp -->
	<%
	Response.Write PageSplitString2
	Response.Write "</table>"%></td>
	</tr>
	</table>
	<%If GBL_TableBottomString <> "" Then%><table width=<%=DEF_BBS_ScreenWidth%> border=0 cellspacing=0 cellpadding=0 align=center><tr><td><%=GBL_TableBottomString%></td></tr></table><%End If%>
	<%

End Function

Function DisplayAnnounceData(For1,For2,StepValue,GetData)
	
	Dim N,Temp
	For N = For1 to For2 Step StepValue
		Response.Write "<tr align=center height=25"
		
		If cCur(GetData(1,N))=0 Then
			Response.Write " bgcolor=" & DEF_BBS_LightColor
		Else
			Response.Write " bgcolor=" & DEF_BBS_LightestColor
		End If
		Response.Write " class=TBBG9><td>"
		If cCur(GetData(2,N))>0 Then
			Response.Write "+" & GetData(2,N) & ""
		Else
			Response.Write GetData(0,N)
		End If
		Response.Write "</td><td align=left>"
		
		If GetData(3,N)>DEF_BBS_MaxLayer Then GetData(3,N)=10
		Response.Write Replace(string((GetData(3,N)-1),"-"),"-","&nbsp; &nbsp; ")
		If cCur(GetData(11,N))>=DEF_BBS_TOPMinID And cCur(GetData(1,N))=0 Then
			Response.Write "<img src=" & DEF_BBS_HomeUrl & "images/" & GBL_DefineImage & "intop.gif align=absbottom width=15>"
		Else
			Response.Write "<img src=" & DEF_BBS_HomeUrl & "images/" & GBL_DefineImage & "bf/face" & GetData(5,N) & ".gif align=absbottom width=20 height=20>"
		End If
		Response.Write " <a href=../Announce/announce2.asp?BoardID=" & GBL_Board_ID & "&ID=" & GetData(0,N) & ">"
		If GetData(13,n) <> 1 and strLength(GetData(4,N))>DEF_BBS_DisplayTopicLength Then GetData(4,N) = LeftTrue(GetData(4,N),DEF_BBS_DisplayTopicLength-3) & "..."
		If GetData(13,n) = 0 Then
			Response.Write htmlencode(GetData(4,n))
		Else
			Response.Write DisplayAnnounceTitle(GetData(4,n),GetData(13,n))
		End If
		Response.Write "</a>"
		'Response.Write " " & GetData(8,N) & "字节"
		GetData(10,N) = cCur(GetData(10,N))
		If GetData(10,N) > 0 Then
			Response.Write "</td><td><a href=" & DEF_BBS_HomeUrl & "User/LookUserInfo.asp?ID=" & GetData(10,N) & ">" & htmlencode(GetData(9,N)) & "</a></td><td>"
		Else
			Response.Write "</td><td>" & htmlencode(GetData(9,N)) & "</td><td>"
		End If
		Response.Write GetData(7,N) & "</td><td>"
		Temp = RestoreTime(GetData(6,N))
		If DateDiff("d",Temp,DEF_Now)<1 Then Response.Write "<font color=990000 class=RedFont>"
		Response.Write Temp & "</td></tr>"
	Next

End Function
%>