<% Option Explicit %>
<!--#include file="../config.asp"-->
<!--#include file="../common.asp"-->
<!--#include file="main.asp"-->
<%
	Dim rs, MID, Title, URL, Msg, BatchNumber, IsBold, IsHighlight

	Command	= Request.Form("Command")
	MID		= Str2Num(Request("MID"))

	OpenConnection

	If Command = "Save" Then
		Set rs = DBC.Execute("SELECT * FROM MsgBoard WHERE MID = " & MID)

		If rs.EOF Then
			DBC.Execute("INSERT INTO MsgBoard (Title, URL, Msg, BatchNumber, IsBold, IsHighlight) " & _
				"VALUES (" &	EscapeSQLData(Request.Form("Title"))				& ", " & _
						EscapeSQLData(Request.Form("URL"))				& ", " & _
						EscapeSQLData(Request.Form("Msg"))				& ", " & _
						Str2Num(Request.Form("BatchNumber"))			& ", " & _
						IIf(Str2Num(Request.Form("IsBold")) = 1, "true", "false")		& ", " & _
						IIf(Str2Num(Request.Form("IsHighlight")) = 1, "true", "false")	& ")")
		Else
			DBC.Execute("UPDATE MsgBoard SET " & _
				"Title		= " & EscapeSQLData(Request.Form("Title"))			& ", " & _
				"URL		= " & EscapeSQLData(Request.Form("URL"))			& ", " & _
				"Msg		= " & EscapeSQLData(Request.Form("Msg"))			& ", " & _
				"BatchNumber	= " & Str2Num(Request.Form("BatchNumber"))			& ", " & _
				"IsBold		= " & IIf(Str2Num(Request.Form("IsBold")) = 1, "true", "false")	& ", " & _
				"IsHighlight	= " & IIf(Str2Num(Request.Form("IsHighlight")) = 1, "true", "false")	& "  " & _
				"WHERE MID = " & MID)
		End If

		Response.Redirect "msg_list.asp?page=" & Session(Prefix & "MsgList_Page")
	End If


	PageHeader

	If Not Session("IsAdminLogin") Then
		PageLogin
		Response.End
	End If

	AdminPageBegin "Add Message"
	MessageEdit
	AdminPageEnd



	Sub MessageEdit()
		Set rs = DBC.Execute("SELECT * FROM MsgBoard WHERE MID = " & MID)

		If rs.EOF Then
			Title		= ""
			URL		= ""
			Msg		= ""
			BatchNumber	= 0
			IsBold		= False
			IsHighlight	= False
		Else
			Title		= rs("Title")
			URL		= rs("URL")
			Msg		= rs("Msg")
			BatchNumber	= rs("BatchNumber")
			IsBold		= rs("IsBold")
			IsHighlight	= rs("IsHighlight")
		End If
%>
		<script language=JavaScript>
		<!--
		function Validate()
		{
			if (document.F.Title.value.length == 0)
			{
				alert ('Please enter a Title.');
				document.F.Title.focus();
				return false;
			}

			if (document.F.URL.value.length == 0)
			{
				alert ('Please enter a URL.');
				document.F.URL.focus();
				return false;
			}

			if (document.F.Msg.value.length == 0)
			{
				alert ('Please enter a Message.');
				document.F.Msg.focus();
				return false;
			}

			if (isNaN(document.F.BatchNumber.value))
				document.F.BatchNumber.value = 0;

			return true;
		}
		//-->
		</script>

		<form name=F action="msg_edit.asp" method=post onsubmit="return Validate()">
		<input type=hidden name=MID value="<%= MID %>">
		<table border=0 align=center bgcolor=black cellspacing=1 cellpadding=3>
		<tr>
			<td colspan=2 class=SelectedParent align=center>
				Message information
			</td>
		</tr>
		<tr class=Odd>
			<td>Title</td>
			<td>
				<input name=Title value="<%= Title %>" size=50 maxlength=60 class=ClientText>
			</td>
		</tr>
		<tr class=Odd>
			<td>URL</td>
			<td>
				<input name=URL value="<%= URL %>" size=50 maxlength=120 class=ClientText>
			</td>
		</tr>
		<tr class=Odd>
			<td>Message (255 chars. max)</td>
			<td>
				<input name=Msg value="<%= Msg %>" size=50 maxlength=255 class=ClientText>
			</td>
		</tr>
		<tr class=Odd>
			<td>Batch number</td>
			<td>
				<input name=BatchNumber value="<%= BatchNumber %>" size=50 maxlength=11 class=ClientText>
			</td>
		</tr>
		<tr class=Odd>
			<td><b>Bold</b></td>
			<td>
				<input type=checkbox name=IsBold value=1 <%= IIf(IsBold, " checked", "") %> class=ClientText>
			</td>
		</tr>
		<tr class=Odd>
			<td bgcolor=<%= MsgBoardHighlightedColor %>>Highlight</td>
			<td>
				<input type=checkbox name=IsHighlight value=1 <%= IIf(IsHighlight, " checked", "") %> class=ClientText>
			</td>
		</tr>
		<tr>
			<td colspan=2 bgcolor=white align=center>
				<input type=submit name=Command value=Save style="width:200">
			</td>
		</tr>
		</table>
		</form>
<%
	End Sub
%>