<% Option Explicit %>
<!--#include file="config.asp"-->
<!--#include file="common.asp"-->
<%
	Dim MsgCost

	If Str2Num(Session(Prefix & "MemberID")) = 0 Then
		' ne e lognat = non members
		MsgCost = FormatNumber(MsgCostNonMembers, 2)
	Else
		If Session(Prefix & "IsGold") Then
			MsgCost = FormatNumber(MsgCostGoldMembers, 2)
		Else
			MsgCost = FormatNumber(MsgCostFreeMembers, 2)
		End If
	End If


	PageBegin
	Info
	MessageList
	PageEnd



	Sub Info()
		Dim rs, m
%>
		<p align=center class=Title>
			Message Board<br><br class=HalfBreak>
		</p>

		<table align=center cellspacing=0 cellpadding=1>
		<tr class=PageText>
			<td>
				Life-time fee: $<%= MsgCost %>&nbsp;&nbsp;&nbsp;
			</td>
			<td>
				<b>Bold</b>: $<%= FormatNumber(MsgBoldCost, 2) %>&nbsp;&nbsp;&nbsp;
			</td>
			<td bgcolor=<%= MsgBoardHighlightedColor %>>
				Highlighted
			</td>
			<td>
				: $<%= FormatNumber(MsgHighlightCost, 2) %>
			</td>
		</tr>
		<tr>
			<td colspan=4 align=center class=PageText>
<%
				If Str2Num(Session(Prefix & "MemberID")) = 0 Then
					Response.Write "<br>If you a Member of " & SiteName & " please <a href='log.asp'>log-in</a>. The cost will be lower.<br><br>"
				End If
%>
				<a href='msgaddselect.asp'>Add your message</a><br><br>
			</td>
		</tr>
		</table>
<%
	End Sub


	Sub MessageList()
		Dim rs, rsCount, i, Index

		Dim PageSize	:	PageSize		= MsgBoardPageSize
		Dim PageCount	:	PageCount	= 0
		Dim Pos		:	Pos		= 0


		OpenConnection

		Set rsCount = DBC.Execute("SELECT COUNT(*) FROM MsgBoard")

		If rsCount(0) > PageSize Then
			PageCount = rsCount(0) \ PageSize
			If rsCount(0) - (PageCount * PageSize) > 0 Then
				PageCount = PageCount + 1
			End If
		Else
			PageCount = 1
			Pos = 0
		End If


		Set rs = DBC.Execute("SELECT * FROM MsgBoard ORDER BY MID DESC")

		Session(Prefix & "MsgList_Page") = Str2Num(Request.Form("page"))

		If Session(Prefix & "MsgList_Page") < 1 Then
			Session(Prefix & "MsgList_Page") = 1
		End If
		If Session(Prefix & "MsgList_Page") > PageCount Then
			Session(Prefix & "MsgList_Page") = PageCount
		End If

		If Pos = 0 Then
			Pos = (Session(Prefix & "MsgList_Page") - 1) * PageSize
		End If

		If Pos < 0 Then
			Pos = 0
		End If

		If Not rs.EOF Then
			rs.Move Pos
		End If
%>
		<table border=0 align=center bgcolor=black width=680 cellspacing=1 cellpadding=3>

		<form name=F action="msgboard.asp" method=POST>
		<input type=hidden name=Page value="<%= Session(Prefix & "MsgList_Page") %>">
<%
		i = 0

		Index = rsCount(0) - ((Session(Prefix & "MsgList_Page") - 1) * PageSize) - 1

		Do While (Not rs.EOF) And (i < PageSize)
%>
			<tr class=Odd valign=top>
				<td <%= IIf(rs("IsHighlight"), "bgcolor=" & MsgBoardHighlightedColor, "") %>>
					<a href='<%= rs("URL") %>'>
<%
					If rs("IsBold") Then
						Response.Write "<b>" & HTMLEncode(rs("Title")) & "</b>"
					Else
						Response.Write HTMLEncode(rs("Title"))
					End If
%>
					</a><br>
					<%= HTMLEncode(rs("Msg")) %>
				</td>
			</tr>
<%
			i = i + 1
			rs.MoveNext
		Loop
%>
		</table>

		<p align=center class=PageText>
<%
		If rsCount(0) >= PageSize Then
			If Session(Prefix & "MsgList_Page") > 1 Then
				Response.Write "<a href='javascript: Page(1)'>First</a>&nbsp;&nbsp;&nbsp;"
				Response.Write "<a href='javascript: Page(" & Session(Prefix & "MsgList_Page")-1 & ")'>Previous</a>&nbsp;&nbsp;&nbsp;"
			Else
				Response.Write "First&nbsp;&nbsp;&nbsp;Previous&nbsp;&nbsp;&nbsp;"
			End If

			If Session(Prefix & "MsgList_Page") < PageCount Then
				Response.Write "<a href='javascript: Page(" & Session(Prefix & "MsgList_Page")+1 & ")'>Next</a>&nbsp;&nbsp;&nbsp;"
				Response.Write "<a href='javascript: Page(" & PageCount & ")'>Last</a>"
			Else
				Response.Write "Next&nbsp;&nbsp;&nbsp;Last"
			End If
		End If
%>
		</p>
	</form>

	<script language=JavaScript>
	<!--
	function Page(PageN)
	{
		document.F.Page.value = PageN;
		document.F.submit();
	}
	//-->
	</script>
<%
	End Sub


	Function HTMLEncode (s)
		If IsNull(s) Then
			HTMLEncode = ""
		Else
			HTMLEncode = Server.HTMLEncode(s)
		End If
	End Function
%>