<% Option Explicit %>
<!--#include file="config.asp"-->
<!--#include file="common.asp"-->
<!--#include file="md5.asp"-->
<%
	Dim PaymentMethod, Title, URL, Msg, IsBold, IsHighlight, 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

	PaymentMethod	= Request.Form("PaymentMethod")
	Title		= Request.Form("Title")
	URL		= Request.Form("URL")
	Msg		= Request.Form("Msg")
	IsBold		= Str2Float(Request.Form("IsBold"))
	IsHighlight	= Str2Float(Request.Form("IsHighlight"))


	If PaymentMethod = "EGold" Then
		MsgForm
	ElseIf PaymentMethod = "MyEarnings" Then
		If MemberID > 0 Then
			If Str2Float(Session(Prefix & "Cash")) >= Str2Float(MsgCost + IsBold + IsHighlight) Then
				Session(Prefix & "Cash") = Str2Float(Session(Prefix & "Cash")) - Str2Float(MsgCost + IsBold + IsHighlight)

				OpenConnection
				Payment

				DBC.Execute("UPDATE Members SET Cash = Cash - " & Str2Float(MsgCost + IsBold + IsHighlight) & " WHERE MemberID = " & MemberID)

				Response.Redirect "memberaccount.asp"

'				PageBegin
'				Response.Write "Your message has been inserted in our message board.<br><br>"
'				Response.Write "<a href='msgboard.asp'>Message Board</a>&nbsp;&nbsp;&nbsp;<a href='memberaccount.asp'>Member's Area</a><br><br>"
'				PageEnd
			Else
				PageBegin
				Response.Write "You don't have enough earnings to pay. You have $" & FormatNumber(Session(Prefix & "Cash"), 2) & ", but you need $" & FormatNumber(MsgCost + IsBold + IsHighlight) & "<br><br>"
				PageEnd
			End If
		End If

		Response.End
	Else
		PageBegin

		If Request("Command") = "ThankYou" Then
			Response.Write "<br><br>Your message has been inserted in our message board.<br><br>"
			Response.Write "<a href='msgboard.asp'>Message Board</a>&nbsp;&nbsp;&nbsp;<a href='memberaccount.asp'>Member's Area</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
	End If


	Sub MsgForm()
%>
		<form name=F action="https://www.e-gold.com/sci_asp/payments.asp" method="post">
		<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="IsHighlight IsBold Title URL Msg">
		<input type=hidden name="SUGGESTED_MEMO" value="<%= SiteName %> message">
		<input type=hidden name="PAYMENT_AMOUNT" value="<%= Str2Float(MsgCost + IsBold + IsHighlight) %>">

		<input type=hidden name="Title" value="<%= Title %>">
		<input type=hidden name="URL" value="<%= URL %>">
		<input type=hidden name="Msg" value="<%= Msg %>">
		<input type=hidden name=IsBold value="<%= IsBold %>">
		<input type=hidden name=IsHighlight value="<%= IsHighlight %>">
		<input type=hidden name="PAYMENT_METHOD" value="Pay">
		</form>

		<script language=JavaScript for=window event=onload>
		<!--
		document.F.submit();
		//-->
		</script>
<%
	End Sub


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

		If PaymentMethod = "MyEarnings" Then
			Title	= Request.Form("Title")
			Msg	= Request.Form("Msg")
		Else
			Title	= Replace(RequestForm("Title"), "+", " ")
			Msg	= Replace(RequestForm("Msg"), "+", " ")
		End If

		URL		= Request.Form("URL")
		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
%>