<% Option Explicit %>
<!--#include file="config.asp"-->
<!--#include file="common.asp"-->
<%
	Server.ScriptTimeout = 100		' seconds

	Dim CID, rs, PageCost

	If MemberID = 0 Then
		PageHeader
%>
		<p class=PageText><br>Your session has been expired. Please <a href=log.asp target=_top>log in</a> again.</p>
		</body>
		</html>
<%
		Response.End
	End If

	CID = Str2Num(Request.Querystring("CID"))


	If CID > 0 Then
		PageHeader

		If (DateDiff("s", Session(Prefix & "LastVisit"), Now) < MemberDelay) Then
%>
<p align=center class=PageText>
<br>
<p>Our system indicates that you are clicking links too quickly. Please 
give that site the time and respect the advertiser deserves.<br>
Please wait <%= MemberDelay %> seconds before clicking on the next 
link. You may now close this window.<br><br>
<!--#include file="banners.asp"-->
</p>
</body>
</html>
<%
			Response.End
		End If

		If InStr(Session(Prefix & "VisitedCampaigns"), " " & CID & " ") > 0 Then
			Response.Write "<center class=PageText><br>You have already paid for this website.</center>"
		Else
			OpenConnection

			Set rs = DBC.Execute("SELECT * FROM Campaigns " & _
				"WHERE CID = " & CID & " AND Approved = 1")

			If rs.EOF Then
%>
<table width=100%><tr class=PageText>
<td align=center><br>You have already paid for this website.</td>
<td align=center width=474><!--#include file="banners.asp"--></td>
</tr></table>
<%
			Else
				If Session(Prefix & "IsGold") Then
					PageCost = PageCost4GoldMembers
				Else
					PageCost = PageCost4FreeMembers
				End If

				' visits = visits + 1
				DBC.Execute("UPDATE Campaigns SET VisitsLeft = VisitsLeft - 1, Visits = Visits + 1 " & _
					"WHERE CID = " & rs("CID"))

				' pay to member
				DBC.Execute("UPDATE Members SET Cash = Cash + " & PageCost & _
					" WHERE MemberID = " & MemberID)

				' pay to referral
				DBC.Execute("UPDATE Members SET Cash = Cash + " & ReferralCommission & _
					" WHERE EGold = " & Str2Num(Session(Prefix & "SponsorEGold")))

				' write link history
				DBC.Execute("INSERT INTO History (MemberID, CID) " & _
					"VALUES (" & MemberID & ", " & CID & ")")

				Session(Prefix & "VisitedCampaigns") = Session(Prefix & "VisitedCampaigns") & rs("CID") & " "

				Session(Prefix & "Cash") = Str2Float(Session(Prefix & "Cash")) + PageCost
%>
<table width=100%><tr class=PageText>
<td align=center>Thank you for your support!<br>
<%= IIf(Not Session(Prefix & "IsGold"), "You could earn $" & PageCost4GoldMembers & ", if you were a GOLD Member.<br><a href='goldupgrade.asp' target=_top>Upgrade now and earn more.</a><br>", "") %>
You may now close this window.</td>
<td align=center width=474><!--#include file="banners.asp"--></td>
</tr></table>
<%
			End If
		End If

		Response.Write "</body>"
		Response.Write "</html>"
	End If
%>