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


	If Request("Command") = "ThankYou" Then
		Response.Write "<br><br>Thank you.<br><br><a href='msgboard.asp'>View all messages</a><br><br><br><br>"
	Else
		If Len(Request.Form.Item) < 10 Then
			MsgForm
		Else
			If IsValidPayment Then
				OpenConnection

				Payment

				Response.End
			End If
		End If
	End If
	PageEnd


	Sub MsgForm()
%>
		<form name="F" action="https://www.e-gold.com/sci_asp/payments.asp" method="post" onsubmit="return ValidateForm()">
		<input type="hidden" name="PAYEE_ACCOUNT" value="<%= MyEGold %>">
		<input type="hidden" name="PAYEE_NAME" value="<%= SiteName %>">
		<input type="hidden" name="PAYMENT_UNITS" value="1">
		<input type="hidden" name="PAYMENT_METAL_ID" value="1">
		<input type="hidden" name="STATUS_URL" value="<%= CurrentFile %>">
		<input type="hidden" name="PAYMENT_URL" value="<%= CurrentFile %>?Command=ThankYou">
		<input type="hidden" name="NOPAYMENT_URL" value="<%= CurrentFile %>">
		<input type="hidden" name="BAGGAGE_FIELDS" value="">
		<input type="hidden" name="SUGGESTED_MEMO" value="<%= SiteName %> message">
		<input type="hidden" name="PAYMENT_AMOUNT" value="<%= MsgCost %>">

		<span class="Title">Message</span><br><br>

		<table border="0" cellpadding="2" cellspacing="0">
		<tr class="Odd">
			<td colspan=2>
				Message Title<br>
				<input name="Title" size="60" maxlength="60" class="ClientText"><br><br>
			</td>
		</tr>
		<tr class="Odd">
			<td colspan=2>
				Message URL<br>
				<input name="URL" value="http://" size="60" maxlength="120" class="ClientText"><br><br>
			</td>
		</tr>
		<tr class="PageText">
			<td colspan=2>
				Message (255 max. chars)<br>
				<input name="Msg" size="60" maxlength=255 class="ClientText"><br>
			</td>
		</tr>
		<tr>
			<td colspan=2>
				<br>
			</td>
		</tr>
		<tr class="PageText">
			<td>
				Life-time fee
			</td>
			<td>
				<input type=checkbox class=ClientText checked disabled>
				($ <%= FormatNumber(MsgCost, 2) %>)
			</td>
		</tr>
		<tr class="PageText">
			<td>
				<b>Bold</b>
			</td>
			<td>
				<input type=checkbox name=IsBold value="<%= MsgBoldCost %>" class=ClientText>
				($ <%= FormatNumber(MsgBoldCost, 2) %>)
			</td>
		</tr>
		<tr class="PageText">
			<td bgcolor=AAFFAA>
				Highlighted
			</td>
			<td>
				<input type=checkbox name=IsHighlight value="<%= MsgHighlightCost %>" class=ClientText>
				($ <%= FormatNumber(MsgHighlightCost, 2) %>)
			</td>
		</tr>
		<tr>
			<td colspan=2>
				<br>
			</td>
		</tr>
		<tr class="PageText">
			<td valign="top" colspan="2" align="center">
				<input type="image" name="PAYMENT_METHOD" src="images/egold.gif" alt="Pay through e-gold" WIDTH="88" HEIGHT="31">
			</td>
		</tr>
		</form>
		</table>

		<script language="JavaScript">
		<!--
		function ValidateForm()
		{
			if (document.F.Title.value.length < 3)
			{
				alert ('Please enter a title.');
				document.F.Title.focus();
				return false;
			}

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

			sum = <%= MsgCost %>;

			document.F.BAGGAGE_FIELDS.value = "Title URL Msg";


			if (document.F.IsBold.checked)
			{
				sum = parseFloat(sum) + parseFloat(document.F.IsBold.value);
				document.F.BAGGAGE_FIELDS.value += " IsBold";
			}

			if (document.F.IsHighlight.checked)
			{
				sum = parseFloat(sum) + parseFloat(document.F.IsHighlight.value);
				document.F.BAGGAGE_FIELDS.value += " IsHighlight";
			}

			document.F.PAYMENT_AMOUNT.value = parseFloat(sum);

			document.F.PAYMENT_AMOUNT.value = document.F.PAYMENT_AMOUNT.value.substr(0, document.F.PAYMENT_AMOUNT.value.indexOf(".") + 3);

			return true;
		}
		//-->
		</script>
<% 
	End Sub


	Sub Payment()
		Dim BatchNumber, PAYER_ACCOUNT, IsBold, IsHighlight, Title, URL, Msg

		Title		= Replace(RequestForm("Title"), "+", " ")
		URL			= Request.Form("URL")
		Msg			= Request.Form("Msg")
		IsBold		= IIf(Str2Float(Request.Form("IsBold")) > 0, "True", "False")
		IsHighlight	= IIf(Str2Float(Request.Form("IsHighlight")) > 0, "True", "False")

		BatchNumber		= Str2Num(Request("PAYMENT_BATCH_NUM"))
		PAYER_ACCOUNT	= Str2Num(Request("PAYER_ACCOUNT"))

		' ----- add campaign -----
		DBC.Execute ("INSERT INTO MsgBoard " & _
				"(Title, URL, Msg, BatchNumber, IsBold, IsHighlight) " & _
				"VALUES (" &	EscapeSQLData(Title)	& ", " & _
								EscapeSQLData(URL)		& ", " & _
								EscapeSQLData(Msg)		& ", " & _
								BatchNumber				& ", " & _
								IsBold					& ", " & _
								IsHighlight				& ")")
	End Sub


	Function RequestForm(param)

		Dim x, qs
		Dim Separator	:	Separator = "&"

		qs = Request.Form.Item

		If Len(param) = 0 Then
			RequestForm = ""
			Exit Function
		End If

		If InStr(qs, "?" & param & "=") > 0 Then
			x = Right(qs, Len(qs) - InStr(qs, "?" & param & "=") - Len(param) - 1)

			If InStr(x, Separator) > 0 Then
				x = Left(x, InStr(x, Separator) - 1)
			End If
		End If

		If InStr(qs, Separator & param & "=") > 0 Then
			x = Right(qs, Len(qs) - InStr(qs, Separator & param & "=") - Len(param) - 1)

			If InStr(x, Separator) > 0 Then
				x = Left(x, InStr(x, Separator) - 1)
			End If
		End If

		RequestForm = x

	End Function
%>