<%
	Dim DBC, rs, MyEGold, Password, EGoldPass, AltPass, ContactEMail, SiteName, LuckyNumber, Bet, Win, MaxLinks, LinkCost, SponsorEarn, Command


	LoadCommon()

	Command = Request.Querystring("Command")


	If Command = "LogIn" Then
		Dim rsUser
		Set rsUser = DBC.Execute("SELECT ID FROM Admin WHERE ID = 1 AND " & _
			"MyEGold = " & Str2Num(Request.Form("EGold")) & " AND " & _
			"Password = " & EscapeSQLData(Request.Form("Password")))

		Session("IsAdminLogin") = (Not rsUser.EOF)
	End If


	If Command = "LogOut" Then
		Session("IsAdminLogin") = False
		Response.Redirect "default.asp"
	End If



	Sub OpenConnection()
		Set DBC = Server.CreateObject("ADODB.Connection")
		DBC.Open "DBQ=" & DataBaseFileName & ";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;MaxBufferSize=8192;Threads=20;"
	End Sub


	Sub PageHeader()

	Response.Expires = -1
%>
	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
	<html>
	<head>
	<title><%= SiteName & " - Your Lucky Number" %></title>
	<meta name="author" content="http://free-sign-up.com/LowCostScripts">
	<style type="text/css">
	td
	{
		FONT-FAMILY: Tahoma, Arial;
		FONT-SIZE: 10pt;
	}
	</style>
	</head>
	<body bgcolor="white" topmargin="5">
<%
	End Sub


	Sub PageBegin()
%>
	<img src="images/logo.gif" WIDTH="207" HEIGHT="45">
	<br><br>

	<table border="0" width="100%" cellspacing="0" cellpadding="0">
	<tr valign="top">
		<td>
<%
	End Sub


	Sub PageEnd()
%>
			<br>
		</td>
		<td width="25">
			&nbsp;
		</td>
		<td align="right">
			<table border="0" width="210" cellspacing="0" cellpadding="0">
			<tr>
				<td>
					<img src="images/toplinks.gif" alt="Top links" WIDTH="191" HEIGHT="28"></td>
			</tr>
			<tr>
				<td bgcolor="C6F39C">
					<% Links %>
				</td>
			</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td colspan="3">
			Feel free to <a href="mailto:<%= ContactEMail %>?subject=<%= SiteName %> -">contact us</a> 
			should you have any questions.
		</td>
	</tr>
	</table>
	<br>
	<!-- http://free-sign-up.com/LowCostScripts - Low Cost Scripts -->
	</body>
	</html>
<%
	End Sub


	Function IIf(cond, value1, value2)
		If cond Then IIf = value1 Else IIf = value2 End If
	End Function


	Function EscapeSQLData(s)
		If IsNull(s) Then
			EscapeSQLData = "''"
		Else
			EscapeSQLData = "'" & Replace(s, "'", "''") & "'"
		End If
	End Function


	Function Str2Num(s)
		If IsNull(s) Then
			Str2Num = 0
		Else
			If IsNumeric(s) Then
				Str2Num = CLng(s)
			Else
				Str2Num = 0
			End If
		End If
	End Function


	Function Str2Float(s)
		If IsNull(s) Then
			Str2Float = 0
		Else
			If IsNumeric(s) Then
				Str2Float = CDbl(s)
			Else
				Str2Float = 0
			End If
		End If
	End Function


	Function CurrentPath()
		Dim s
		s = Request.ServerVariables("SCRIPT_NAME")

		s = Left(s, InStrRev(s, "/"))

		CurrentPath = "http://" & Request.ServerVariables("SERVER_NAME") & s
	End Function


	Function CurrentFile()
		CurrentFile = "http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("SCRIPT_NAME")
	End Function


	Sub Links()
		Dim rs, i, c, HTML

		' keshiran li e HTML ?
		If Len(Application("N8_Links")) > 10 And DateDiff("d", Application("N8_Links_Date"), Now) < 1 Then
			Response.Write Application("N8_Links")
			Exit Sub
		End If


		OpenConnection

		Set rs = DBC.Execute("SELECT Title, URL FROM Links WHERE DateDiff('d', '" & Date() & "', ValidTo) >= 0")

		HTML =	"<table align=center cellpadding=5 cellspacing=1 width=100% bgcolor=9CAAF7>" & _
				"<col align=center>"

		c = 1

		Do While Not rs.EOF
			HTML = HTML & "<tr bgcolor=C6F39C><td><a href='" & rs("URL") & "'>" & rs("Title") & "</a></td></tr>"

			c = c + 1
			rs.MoveNext
		Loop

		For i = c To MaxLinks - 1
			HTML = HTML & "<tr bgcolor=C6F39C><td><a href=" & CurrentPath & "add.asp>$ " & LinkCost & " / month</a></td></tr>"
		Next

		HTML = HTML & "</table>"

		Application("N8_Links") = HTML
		Application("N8_Links_Date") = Now

		Response.Write HTML
	End Sub


	Function IsValidPayment()
		Dim MD, MD5String

		Set MD = New MD5

		MD5String =	Request.Form("PAYMENT_ID")				& ":" & _
					Request.Form("PAYEE_ACCOUNT")			& ":" & _
					Request.Form("PAYMENT_AMOUNT")			& ":" & _
					Request.Form("PAYMENT_UNITS")			& ":" & _
					Request.Form("PAYMENT_METAL_ID")		& ":" & _
					Request.Form("PAYMENT_BATCH_NUM")		& ":" & _
					Request.Form("PAYER_ACCOUNT")			& ":" & _
					MD.DigestStrToHexStr(AltPass)			& ":" & _
					Request.Form("ACTUAL_PAYMENT_OUNCES")	& ":" & _
					Request.Form("USD_PER_OUNCE")			& ":" & _
					Request.Form("FEEWEIGHT")				& ":" & _
					Request.Form("TIMESTAMPGMT")

		IsValidPayment = (MD.DigestStrToHexStr(MD5String) = Request.Form("V2_HASH"))

	End Function


	Sub LoadCommon()
		Dim rs, i, B

		OpenConnection

		Set rs = DBC.Execute("SELECT * FROM Admin WHERE ID = 1")

		If rs.EOF Then
			Response.Write "Unable to load data. Missing record."
			Response.End
		Else
			SiteName		= rs("SiteName")
			MyEGold			= rs("MyEGold")
			ContactEMail	= rs("ContactEMail")
			SponsorEarn		= rs("SponsorEarn")
			EGoldPass		= rs("EGoldPass")
			AltPass			= rs("AltPass")
			LuckyNumber		= rs("LuckyNumber")
			Bet				= rs("Bet")
			Win				= rs("Win")
			MaxLinks		= rs("MaxLinks")
			LinkCost		= rs("LinkCost")
		End If
		' -------------------------------------------
	End Sub


	' Admin subs and functions ----------------------
	Sub UserLogin()
%>
		<form name="F" action="admin_stat.asp?Command=LogIn" method="post" onsubmit="return EGoldPresent() &amp;&amp; PasswordPresent()">
		<table border="0" width="100%" cellpadding="1">
		<tr>
			<td align="center" class="PageText">
				<img src="images/logo.gif" border="0" WIDTH="207" HEIGHT="45"><br><br class="HalfBreak">
			</td>
		</tr>
		<tr>
			<td align="center" class="PageText">
				E-Gold&nbsp;
				<input name="EGold" size="15" maxlength="20" class="ClientText">
				&nbsp;&nbsp;
				Password&nbsp;
				<input type="Password" name="Password" size="15" maxlength="20" class="ClientText">
				&nbsp;&nbsp;
				<input type="submit" value="Log In">
			</td>
		</tr>
		</table>
		</form>

		<script language="JavaScript">
		<!--
		function EGoldPresent()
		{
			if (document.F.EGold.value.length == 0)
			{
				alert ('Please enter your E-Gold number.');
				document.F.EGold.focus();
				return false;
			}

			return true;
		}

		function PasswordPresent()
		{
			if (document.F.Password.value.length == 0)
			{
				alert ('Please enter your password.');
				document.F.Password.focus();
				return false;
			}

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

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


	Sub AdminMenu()
%>
	<style type="text/css">
	.Header
	{
		BACKGROUND-COLOR: 00CC00;
		COLOR: black;
		FONT-FAMILY: Arial, Helvetica, sans-serif;
		FONT-SIZE: 9pt;
		FONT-WEIGHT: bold
	}
	</style>

	<table border="0" width="100%" cellspacing="0" cellpadding="2">
	<tr valign="bottom">
		<td>
			<img src="images/logo.gif" border="0" WIDTH="207" HEIGHT="45">
		</td>
		<td align="right">
			<a href="http://free-sign-up.com/LowCostScripts" target=_blank>Low Cost Scripts</a>
		</td>
	</tr>
	<tr class="Header">
		<td align="center" colspan="2">
			<a href="admin_main.asp" class="Admin">Main</a>&nbsp;|&nbsp;
			<a href="admin_payments.asp" class="Admin">Manual Payments</a>&nbsp;|&nbsp;
			<a href="admin_links.asp" class="Admin">Links</a>&nbsp;|&nbsp;
			<a href="admin_stat.asp" class="Admin">Statistics</a>&nbsp;|&nbsp;
			<a href="default.asp?Command=LogOut" class="Admin">Log Out</a>
		</td>
	</tr>
	</table>
<%
	End Sub
%>