<%
Function FreeHost_moneyNewlog(connmoney,isuser,isagn,issup,ishand,isadd,isAgnHostSer,moneyX,username,opusername,norusername,norStmoney,norEndmoney,agnusername,agnStmoney,agnEndmoney,supusername,forwhat,corewhat,whichProduct,pdid,pingzheng,type1,bank,haveget,havecheck)
	Set dsmoneynew = Server.CreateObject("ADODB.Recordset")	
	Sqlmoney="Select * from FreeHost.FreeHost_moneylog"
	dsmoneynew.Open Sqlmoney,connmoney,3,2
	dsmoneynew.addnew
dsmoneynew("username")=username
dsmoneynew("opusername")=opusername
dsmoneynew("isuser")=isuser
dsmoneynew("isagn")=isagn
dsmoneynew("issup")=issup
dsmoneynew("ishand")=ishand
dsmoneynew("isadd")=isadd
dsmoneynew("isfortest")=isfortest
dsmoneynew("isAgnHostSer")=isAgnHostSer
dsmoneynew("AgnRunasUser")=session("AgnRunasUser")
dsmoneynew("usermoney")=moneyX
dsmoneynew("norusername")=norusername
dsmoneynew("norStmoney")=norStmoney
dsmoneynew("norEndmoney")=norEndmoney
dsmoneynew("agnusername")=agnusername
dsmoneynew("agnStmoney")=agnStmoney
dsmoneynew("agnEndmoney")=agnEndmoney
dsmoneynew("supusername")=supusername
If session("admusername")<>""   Then dsmoneynew("supusername")=session("admusername")
dsmoneynew("forwhat")=left(forwhat,199)
dsmoneynew("corewhat")=Left(corewhat,199)
dsmoneynew("whichProduct")=whichProduct
dsmoneynew("pdid")=pdid
dsmoneynew("attime")=NOW
dsmoneynew("pingzheng")=pingzheng
dsmoneynew("type1")=type1
dsmoneynew("bank")=bank
dsmoneynew("haveget")=haveget
dsmoneynew("havecheck")=havecheck
dsmoneynew("atspace")=session("atspace")
dsmoneynew("pdtype")=pdtype
dsmoneynew("pdsttime")=starttime
dsmoneynew("pdendtime")=temptime
dsmoneynew("isnew")="y"
dsmoneynew("ip")=Request.ServerVariables("REMOTE_ADDR")
If Request.ServerVariables("HTTP_FreeHostAPIIP")<>"" Then dsmoneynew("ip")=Request.ServerVariables("HTTP_FreeHostAPIIP")
If session("agentname")<>"n"   Then dsmoneynew("agent1")=session("agentname")
If session("agentusername")<>"" and session("admusername")="" Then'2007-2-26
dsmoneynew("agent1")=session("agentusername")
if agnEndmoney<>"" then session("agentusermoney")=agnEndmoney
end if
If session("username")<>"" and norEndmoney<>"" Then session("usermoney")=norEndmoney
dsmoneynew("kefu")=kefu
dsmoneynew.update
dsmoneynew.close
set dsmoneynew=nothing
End Function

Function FreeHost_moneylog(connmoney,username,opusername,moneyX,forwhat,whichProduct,pdid,corewhat,isagent)
dim ret
ret=true
	Set dsmoney = Server.CreateObject("ADODB.Recordset")	
	Sqlmondy="Select * from FreeHost.FreeHost_moneylog"
	dsmoney.Open Sqlmondy,connmoney,3,2
	dsmoney.addnew
dsmoney("username")=username
dsmoney("opusername")=opusername
dsmoney("attime")=NOW
dsmoney("usermoney")=moneyX
dsmoney("forwhat")=forwhat
dsmoney("corewhat")=corewhat
dsmoney("whichProduct")=whichProduct
dsmoney("pdid")=pdid
dsmoney("ip")=Request.ServerVariables("REMOTE_ADDR")
If Request.ServerVariables("HTTP_FreeHostAPIIP")<>"" Then dsmoney("ip")=Request.ServerVariables("HTTP_FreeHostAPIIP")
dsmoney("isagent")=isagent
If session("agentname")<>"n" Then dsmoney("agent1")=session("agentname")
'response.write session("agentname")&".........."
If session("agentusername")<>"" Then dsmoney("agent1")=session("agentusername")
'response.write session("agentname")&"XXXX"
dsmoney.update
dsmoney.close
set dsmoney=nothing
FreeHost_moneylog=ret
End Function



Function FreeHost_moneylog2(connmoney,username,opusername,moneyX,forwhat,whichProduct,pdid,corewhat,isagent,pingzheng,type1,bank,haveget,havecheck)
dim ret
ret=true
	Set dsmoney = Server.CreateObject("ADODB.Recordset")	
	Sqlmondy="Select * from FreeHost.FreeHost_moneylog"
	dsmoney.Open Sqlmondy,connmoney,3,2
	dsmoney.addnew
dsmoney("username")=username
dsmoney("opusername")=opusername
dsmoney("attime")=NOW
dsmoney("usermoney")=moneyX
'response.write moneyX&".........."
dsmoney("forwhat")=forwhat
dsmoney("corewhat")=corewhat
dsmoney("whichProduct")=whichProduct
dsmoney("pdid")=pdid
dsmoney("ip")=Request.ServerVariables("REMOTE_ADDR")
If Request.ServerVariables("HTTP_FreeHostAPIIP")<>"" Then dsmoney("ip")=Request.ServerVariables("HTTP_FreeHostAPIIP")
dsmoney("isagent")=isagent
If session("agentname")<>"n" Then dsmoney("agent1")=session("agentname")
'response.write session("agentname")&".........."
If session("agentusername")<>"" Then dsmoney("agent1")=session("agentusername")
'response.write session("agentname")&"XXXX"
dsmoney("pingzheng")=pingzheng
dsmoney("type1")=type1
dsmoney("bank")=bank
dsmoney("haveget")=haveget
dsmoney("havecheck")=havecheck
dsmoney.update
dsmoney.close
set dsmoney=nothing
FreeHost_moneylog2=ret
End Function

Function FreeHost_clientlog(connmoney,username,opusername,forwhat,whichProduct,pdid,fun,URL,ftpname,returnstr)
Set connX=Server.CreateObject("ADODB.Connection")
	connX.Open Application("FreeHostDBlink")
	Set clientlog = Server.CreateObject("ADODB.Recordset")	
	Sqlclientlog="Select * from FreeHost.FreeHost_Functionlog"
	clientlog.Open Sqlclientlog,connX,3,3
	clientlog.addnew
clientlog("username")=username
clientlog("opusername")=opusername
clientlog("attime")=NOW
'clientlog("usermoney")=usermoney
clientlog("forwhat")=forwhat
clientlog("whichProduct")=whichProduct
clientlog("pdid")=pdid
clientlog("fun")=fun
clientlog("URL")=URL
clientlog("ftpname")=ftpname
clientlog("returnstr")=ret
clientlog("ip")=Request.ServerVariables("REMOTE_ADDR")
If Request.ServerVariables("HTTP_FreeHostAPIIP")<>"" Then clientlog("ip")=Request.ServerVariables("HTTP_FreeHostAPIIP")
If session("agentname")<>"n" Then clientlog("agent1")=session("agentname")
'response.write session("agentname")&".........."
If session("agentusername")<>"" Then clientlog("agent1")=session("agentusername")
'response.write session("agentname")&"XXXX"
clientlog.update
clientlog.close
connX.close
set connX=nothing
set clientlog=nothing
End Function

Function RegExpTest(patrn, strng)
  Dim regEx
  Set regEx = New RegExp
  regEx.Pattern = patrn
  regEx.IgnoreCase = False
  RegExpTest = regEx.Test(strng)
End Function 



Function IDCheck(e)
IDCheck = true
arrVerifyCode = Split("1,0,x,9,8,7,6,5,4,3,2", ",")
Wi = Split("7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2", ",")
Checker = Split("1,9,8,7,6,5,4,3,2,1,1", ",")
If Len(e) < 15 Or Len(e) = 16 Or Len(e) = 17 Or Len(e) > 18 Then
'IDCheck= "身份证号共有 15 码或18位"
IDCheck = False
Exit Function
End If
Dim Ai
If Len(e) = 18 Then
Ai = Mid(e, 1, 17)
ElseIf Len(e) = 15 Then
Ai = e
Ai = Left(Ai, 6) & "19" & Mid(Ai, 7, 9)
End If
If Not IsNumeric(Ai) Then
'IDCheck= "身份证除最后一位外，必须为数字！"
IDCheck = False
Exit Function
End If
Dim strYear, strMonth, strDay
strYear = Clng(Mid(Ai, 7, 4))
strMonth = Clng(Mid(Ai, 11, 2))
strDay = Clng(Mid(Ai, 13, 2))
BirthDay = Trim(strYear) + "-" + Trim(strMonth) + "-" + Trim(strDay)
If IsDate(BirthDay) Then
If DateDiff("yyyy",Now,BirthDay)<-140 or cdate(BirthDay)>date() Then
'IDCheck= "身份证输入错误！"
IDCheck = False
Exit Function
End If
If strMonth > 12 Or strDay > 31 Then
IDCheck = False
'IDCheck= "身份证输入错误！"
Exit Function
End If
Else
'IDCheck= "身份证输入错误！"
IDCheck = False
Exit Function
End If
Dim i, TotalmulAiWi
For i = 0 To 16
TotalmulAiWi = TotalmulAiWi + Clng(Mid(Ai, i + 1, 1)) * Wi(i)
Next
Dim modValue
modValue = TotalmulAiWi Mod 11
Dim strVerifyCode
strVerifyCode = arrVerifyCode(modValue)
Ai = Ai & strVerifyCode
IDCheck = Ai
If Len(e) = 18 And e <> Ai Then
'IDCheck= "身份证号码输入错误！"
IDCheck = False
Exit Function
End If
End Function



Function FreeHost_Loginlog(username,type1)
Set connX=Server.CreateObject("ADODB.Connection")
	connX.Open Application("FreeHostDBlink")
	Set clientlog = Server.CreateObject("ADODB.Recordset")	
	Sqlclientlog="Select * from FreeHost.FreeHost_Loginlog"
	clientlog.Open Sqlclientlog,connX,3,2
	clientlog.addnew
clientlog("username")=username
clientlog("type1")=type1
clientlog("logintime")=NOW
clientlog("ip")=Request.ServerVariables("REMOTE_ADDR")
If Request.ServerVariables("HTTP_FreeHostAPIIP")<>"" Then clientlog("ip")=Request.ServerVariables("HTTP_FreeHostAPIIP")
clientlog.update
clientlog.close
connX.close
set connX=nothing
set clientlog=nothing
End Function

Sub sub_FreeHost_oplog(username,type1,forwhat)
	Set clientlog = Server.CreateObject("ADODB.Recordset")	
	Sqlclientlog="Select * from FreeHost.FreeHost_oplog"
	clientlog.Open Sqlclientlog,conn,1,3
	clientlog.addnew
clientlog("username")=username
clientlog("type1")=type1
clientlog("forwhat")=forwhat
clientlog("logintime")=NOW
clientlog("ip")=Request.ServerVariables("REMOTE_ADDR")
If Request.ServerVariables("HTTP_FreeHostAPIIP")<>"" Then clientlog("ip")=Request.ServerVariables("HTTP_FreeHostAPIIP")
clientlog.update
clientlog.close
End Sub


Function FreeHost_oplog(username,type1,forwhat)
Set connX=Server.CreateObject("ADODB.Connection")
	connX.Open Application("FreeHostDBlink")
	Set clientlog = Server.CreateObject("ADODB.Recordset")	
	Sqlclientlog="Select * from FreeHost.FreeHost_oplog"
	clientlog.Open Sqlclientlog,connX,3,2
	clientlog.addnew
clientlog("username")=username
clientlog("type1")=type1
clientlog("forwhat")=forwhat
clientlog("logintime")=NOW
clientlog("ip")=Request.ServerVariables("REMOTE_ADDR")
If Request.ServerVariables("HTTP_FreeHostAPIIP")<>"" Then clientlog("ip")=Request.ServerVariables("HTTP_FreeHostAPIIP")
clientlog.update
clientlog.close
connX.close
set connX=nothing
set clientlog=nothing
End Function


Private Const BITS_TO_A_BYTE = 8
Private Const BYTES_TO_A_WORD = 4
Private Const BITS_TO_A_WORD = 32
Private m_lOnBits(30)
Private m_l2Power(30)
    m_lOnBits(0) = CLng(1)
    m_lOnBits(1) = CLng(3)
    m_lOnBits(2) = CLng(7)
    m_lOnBits(3) = CLng(15)
    m_lOnBits(4) = CLng(31)
    m_lOnBits(5) = CLng(63)
    m_lOnBits(6) = CLng(127)
    m_lOnBits(7) = CLng(255)
    m_lOnBits(8) = CLng(511)
    m_lOnBits(9) = CLng(1023)
    m_lOnBits(10) = CLng(2047)
    m_lOnBits(11) = CLng(4095)
    m_lOnBits(12) = CLng(8191)
    m_lOnBits(13) = CLng(16383)
    m_lOnBits(14) = CLng(32767)
    m_lOnBits(15) = CLng(65535)
    m_lOnBits(16) = CLng(131071)
    m_lOnBits(17) = CLng(262143)
    m_lOnBits(18) = CLng(524287)
    m_lOnBits(19) = CLng(1048575)
    m_lOnBits(20) = CLng(2097151)
    m_lOnBits(21) = CLng(4194303)
    m_lOnBits(22) = CLng(8388607)
    m_lOnBits(23) = CLng(16777215)
    m_lOnBits(24) = CLng(33554431)
    m_lOnBits(25) = CLng(67108863)
    m_lOnBits(26) = CLng(134217727)
    m_lOnBits(27) = CLng(268435455)
    m_lOnBits(28) = CLng(536870911)
    m_lOnBits(29) = CLng(1073741823)
    m_lOnBits(30) = CLng(2147483647)
    
    m_l2Power(0) = CLng(1)
    m_l2Power(1) = CLng(2)
    m_l2Power(2) = CLng(4)
    m_l2Power(3) = CLng(8)
    m_l2Power(4) = CLng(16)
    m_l2Power(5) = CLng(32)
    m_l2Power(6) = CLng(64)
    m_l2Power(7) = CLng(128)
    m_l2Power(8) = CLng(256)
    m_l2Power(9) = CLng(512)
    m_l2Power(10) = CLng(1024)
    m_l2Power(11) = CLng(2048)
    m_l2Power(12) = CLng(4096)
    m_l2Power(13) = CLng(8192)
    m_l2Power(14) = CLng(16384)
    m_l2Power(15) = CLng(32768)
    m_l2Power(16) = CLng(65536)
    m_l2Power(17) = CLng(131072)
    m_l2Power(18) = CLng(262144)
    m_l2Power(19) = CLng(524288)
    m_l2Power(20) = CLng(1048576)
    m_l2Power(21) = CLng(2097152)
    m_l2Power(22) = CLng(4194304)
    m_l2Power(23) = CLng(8388608)
    m_l2Power(24) = CLng(16777216)
    m_l2Power(25) = CLng(33554432)
    m_l2Power(26) = CLng(67108864)
    m_l2Power(27) = CLng(134217728)
    m_l2Power(28) = CLng(268435456)
    m_l2Power(29) = CLng(536870912)
    m_l2Power(30) = CLng(1073741824)

	'CHS MD5算法开始  --------------------------------------
	Private Function LShift(lValue, iShiftBits)
		If iShiftBits = 0 Then
			LShift = lValue
			Exit Function
		ElseIf iShiftBits = 31 Then
			If lValue And 1 Then
				LShift = &H80000000
			Else
				LShift = 0
			End If
			Exit Function
		ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
			Err.Raise 6
		End If
	
		If (lValue And m_l2Power(31 - iShiftBits)) Then
			LShift = ((lValue And m_lOnBits(31 - (iShiftBits + 1))) * m_l2Power(iShiftBits)) Or &H80000000
		Else
			LShift = ((lValue And m_lOnBits(31 - iShiftBits)) * m_l2Power(iShiftBits))
		End If
	End Function

	Private Function str2bin(varstr) 
		str2bin="" 
		 For i=1 To Len(varstr) 
			 varchar=mid(varstr,i,1) 
			 varasc = Asc(varchar) 
			 If varasc<0 Then 
				varasc = varasc + 65535 
			 End If 
			 If varasc>255 Then 
				varlow = Left(Hex(Asc(varchar)),2) 
				varhigh = right(Hex(Asc(varchar)),2) 
				str2bin = str2bin & chrB("&H" & varlow) & chrB("&H" & varhigh) 
			 Else 
				str2bin = str2bin & chrB(AscB(varchar)) 
			 End If 
		 Next 
	End Function 

	Private Function RShift(lValue, iShiftBits)
		If iShiftBits = 0 Then
			RShift = lValue
			Exit Function
		ElseIf iShiftBits = 31 Then
			If lValue And &H80000000 Then
				RShift = 1
			Else
				RShift = 0
			End If
			Exit Function
		ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
			Err.Raise 6
		End If
	
		RShift = (lValue And &H7FFFFFFE) \ m_l2Power(iShiftBits)
	
		If (lValue And &H80000000) Then
			RShift = (RShift Or (&H40000000 \ m_l2Power(iShiftBits - 1)))
		End If
	End Function
	
	Private Function RotateLeft(lValue, iShiftBits)
		RotateLeft = LShift(lValue, iShiftBits) Or RShift(lValue, (32 - iShiftBits))
	End Function
	
	Private Function AddUnsigned(lX, lY)
		Dim lX4
		Dim lY4
		Dim lX8
		Dim lY8
		Dim lResult
	
		lX8 = lX And &H80000000
		lY8 = lY And &H80000000
		lX4 = lX And &H40000000
		lY4 = lY And &H40000000
		
		lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF)
	
		If lX4 And lY4 Then
			lResult = lResult Xor &H80000000 Xor lX8 Xor lY8
		ElseIf lX4 Or lY4 Then
			If lResult And &H40000000 Then
				lResult = lResult Xor &HC0000000 Xor lX8 Xor lY8
			Else
				lResult = lResult Xor &H40000000 Xor lX8 Xor lY8
			End If
		Else
			lResult = lResult Xor lX8 Xor lY8
		End If
	
		AddUnsigned = lResult
	End Function
	
	Private Function md5_F(x, y, z)
		md5_F = (x And y) Or ((Not x) And z)
	End Function
	
	Private Function md5_G(x, y, z)
		md5_G = (x And z) Or (y And (Not z))
	End Function
	
	Private Function md5_H(x, y, z)
		md5_H = (x Xor y Xor z)
	End Function
	
	Private Function md5_I(x, y, z)
		md5_I = (y Xor (x Or (Not z)))
	End Function
	
	Private Sub md5_FF(a, b, c, d, x, s, ac)
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_F(b, c, d), x), ac))
		a = RotateLeft(a, s)
		a = AddUnsigned(a, b)
	End Sub
	
	Private Sub md5_GG(a, b, c, d, x, s, ac)
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_G(b, c, d), x), ac))
		a = RotateLeft(a, s)
		a = AddUnsigned(a, b)
	End Sub
	
	Private Sub md5_HH(a, b, c, d, x, s, ac)
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_H(b, c, d), x), ac))
		a = RotateLeft(a, s)
		a = AddUnsigned(a, b)
	End Sub
	
	Private Sub md5_II(a, b, c, d, x, s, ac)
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_I(b, c, d), x), ac))
		a = RotateLeft(a, s)
		a = AddUnsigned(a, b)
	End Sub
	
	Private Function ConvertToWordArray(sMessage)
		Dim lMessageLength
		Dim lNumberOfWords
		Dim lWordArray()
		Dim lBytePosition
		Dim lByteCount
		Dim lWordCount
		
		Const MODULUS_BITS = 512
		Const CONGRUENT_BITS = 448
		
		lMessageLength = LenB(sMessage)
		
		lNumberOfWords = (((lMessageLength + ((MODULUS_BITS - CONGRUENT_BITS) \ BITS_TO_A_BYTE)) \ (MODULUS_BITS \ BITS_TO_A_BYTE)) + 1) * (MODULUS_BITS \ BITS_TO_A_WORD)
		ReDim lWordArray(lNumberOfWords - 1)
		
		lBytePosition = 0
		lByteCount = 0
		Do Until lByteCount >= lMessageLength
			lWordCount = lByteCount \ BYTES_TO_A_WORD
			lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
			lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(AscB(MidB(sMessage, lByteCount + 1, 1)), lBytePosition)
			lByteCount = lByteCount + 1
		Loop
	
		lWordCount = lByteCount \ BYTES_TO_A_WORD
		lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
		
		lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(&H80, lBytePosition)
		
		lWordArray(lNumberOfWords - 2) = LShift(lMessageLength, 3)
		lWordArray(lNumberOfWords - 1) = RShift(lMessageLength, 29)
	
		ConvertToWordArray = lWordArray
	End Function
	
	Private Function WordToHex(lValue)
		Dim lByte
		Dim lCount
		
		For lCount = 0 To 3
			lByte = RShift(lValue, lCount * BITS_TO_A_BYTE) And m_lOnBits(BITS_TO_A_BYTE - 1)
			WordToHex = WordToHex & Right("0" & Hex(lByte), 2)
		Next
	End Function
	
	Public Function MD5(sMessage)
		m_lOnBits(0) = CLng(1)
		m_lOnBits(1) = CLng(3)
		m_lOnBits(2) = CLng(7)
		m_lOnBits(3) = CLng(15)
		m_lOnBits(4) = CLng(31)
		m_lOnBits(5) = CLng(63)
		m_lOnBits(6) = CLng(127)
		m_lOnBits(7) = CLng(255)
		m_lOnBits(8) = CLng(511)
		m_lOnBits(9) = CLng(1023)
		m_lOnBits(10) = CLng(2047)
		m_lOnBits(11) = CLng(4095)
		m_lOnBits(12) = CLng(8191)
		m_lOnBits(13) = CLng(16383)
		m_lOnBits(14) = CLng(32767)
		m_lOnBits(15) = CLng(65535)
		m_lOnBits(16) = CLng(131071)
		m_lOnBits(17) = CLng(262143)
		m_lOnBits(18) = CLng(524287)
		m_lOnBits(19) = CLng(1048575)
		m_lOnBits(20) = CLng(2097151)
		m_lOnBits(21) = CLng(4194303)
		m_lOnBits(22) = CLng(8388607)
		m_lOnBits(23) = CLng(16777215)
		m_lOnBits(24) = CLng(33554431)
		m_lOnBits(25) = CLng(67108863)
		m_lOnBits(26) = CLng(134217727)
		m_lOnBits(27) = CLng(268435455)
		m_lOnBits(28) = CLng(536870911)
		m_lOnBits(29) = CLng(1073741823)
		m_lOnBits(30) = CLng(2147483647)
		
		m_l2Power(0) = CLng(1)
		m_l2Power(1) = CLng(2)
		m_l2Power(2) = CLng(4)
		m_l2Power(3) = CLng(8)
		m_l2Power(4) = CLng(16)
		m_l2Power(5) = CLng(32)
		m_l2Power(6) = CLng(64)
		m_l2Power(7) = CLng(128)
		m_l2Power(8) = CLng(256)
		m_l2Power(9) = CLng(512)
		m_l2Power(10) = CLng(1024)
		m_l2Power(11) = CLng(2048)
		m_l2Power(12) = CLng(4096)
		m_l2Power(13) = CLng(8192)
		m_l2Power(14) = CLng(16384)
		m_l2Power(15) = CLng(32768)
		m_l2Power(16) = CLng(65536)
		m_l2Power(17) = CLng(131072)
		m_l2Power(18) = CLng(262144)
		m_l2Power(19) = CLng(524288)
		m_l2Power(20) = CLng(1048576)
		m_l2Power(21) = CLng(2097152)
		m_l2Power(22) = CLng(4194304)
		m_l2Power(23) = CLng(8388608)
		m_l2Power(24) = CLng(16777216)
		m_l2Power(25) = CLng(33554432)
		m_l2Power(26) = CLng(67108864)
		m_l2Power(27) = CLng(134217728)
		m_l2Power(28) = CLng(268435456)
		m_l2Power(29) = CLng(536870912)
		m_l2Power(30) = CLng(1073741824)
		
		
		Dim x
		Dim k
		Dim AA
		Dim BB
		Dim CC
		Dim DD
		Dim a
		Dim b
		Dim c
		Dim d
		
		Const S11 = 7
		Const S12 = 12
		Const S13 = 17
		Const S14 = 22
		Const S21 = 5
		Const S22 = 9
		Const S23 = 14
		Const S24 = 20
		Const S31 = 4
		Const S32 = 11
		Const S33 = 16
		Const S34 = 23
		Const S41 = 6
		Const S42 = 10
		Const S43 = 15
		Const S44 = 21
		
		x = ConvertToWordArray(str2bin(sMessage))
		
		a = &H67452301
		b = &HEFCDAB89
		c = &H98BADCFE
		d = &H10325476
		
		For k = 0 To UBound(x) Step 16
			AA = a
			BB = b
			CC = c
			DD = d
			
			md5_FF a, b, c, d, x(k + 0), S11, &HD76AA478
			md5_FF d, a, b, c, x(k + 1), S12, &HE8C7B756
			md5_FF c, d, a, b, x(k + 2), S13, &H242070DB
			md5_FF b, c, d, a, x(k + 3), S14, &HC1BDCEEE
			md5_FF a, b, c, d, x(k + 4), S11, &HF57C0FAF
			md5_FF d, a, b, c, x(k + 5), S12, &H4787C62A
			md5_FF c, d, a, b, x(k + 6), S13, &HA8304613
			md5_FF b, c, d, a, x(k + 7), S14, &HFD469501
			md5_FF a, b, c, d, x(k + 8), S11, &H698098D8
			md5_FF d, a, b, c, x(k + 9), S12, &H8B44F7AF
			md5_FF c, d, a, b, x(k + 10), S13, &HFFFF5BB1
			md5_FF b, c, d, a, x(k + 11), S14, &H895CD7BE
			md5_FF a, b, c, d, x(k + 12), S11, &H6B901122
			md5_FF d, a, b, c, x(k + 13), S12, &HFD987193
			md5_FF c, d, a, b, x(k + 14), S13, &HA679438E
			md5_FF b, c, d, a, x(k + 15), S14, &H49B40821
			
			md5_GG a, b, c, d, x(k + 1), S21, &HF61E2562
			md5_GG d, a, b, c, x(k + 6), S22, &HC040B340
			md5_GG c, d, a, b, x(k + 11), S23, &H265E5A51
			md5_GG b, c, d, a, x(k + 0), S24, &HE9B6C7AA
			md5_GG a, b, c, d, x(k + 5), S21, &HD62F105D
			md5_GG d, a, b, c, x(k + 10), S22, &H2441453
			md5_GG c, d, a, b, x(k + 15), S23, &HD8A1E681
			md5_GG b, c, d, a, x(k + 4), S24, &HE7D3FBC8
			md5_GG a, b, c, d, x(k + 9), S21, &H21E1CDE6
			md5_GG d, a, b, c, x(k + 14), S22, &HC33707D6
			md5_GG c, d, a, b, x(k + 3), S23, &HF4D50D87
			md5_GG b, c, d, a, x(k + 8), S24, &H455A14ED
			md5_GG a, b, c, d, x(k + 13), S21, &HA9E3E905
			md5_GG d, a, b, c, x(k + 2), S22, &HFCEFA3F8
			md5_GG c, d, a, b, x(k + 7), S23, &H676F02D9
			md5_GG b, c, d, a, x(k + 12), S24, &H8D2A4C8A
			
			md5_HH a, b, c, d, x(k + 5), S31, &HFFFA3942
			md5_HH d, a, b, c, x(k + 8), S32, &H8771F681
			md5_HH c, d, a, b, x(k + 11), S33, &H6D9D6122
			md5_HH b, c, d, a, x(k + 14), S34, &HFDE5380C
			md5_HH a, b, c, d, x(k + 1), S31, &HA4BEEA44
			md5_HH d, a, b, c, x(k + 4), S32, &H4BDECFA9
			md5_HH c, d, a, b, x(k + 7), S33, &HF6BB4B60
			md5_HH b, c, d, a, x(k + 10), S34, &HBEBFBC70
			md5_HH a, b, c, d, x(k + 13), S31, &H289B7EC6
			md5_HH d, a, b, c, x(k + 0), S32, &HEAA127FA
			md5_HH c, d, a, b, x(k + 3), S33, &HD4EF3085
			md5_HH b, c, d, a, x(k + 6), S34, &H4881D05
			md5_HH a, b, c, d, x(k + 9), S31, &HD9D4D039
			md5_HH d, a, b, c, x(k + 12), S32, &HE6DB99E5
			md5_HH c, d, a, b, x(k + 15), S33, &H1FA27CF8
			md5_HH b, c, d, a, x(k + 2), S34, &HC4AC5665
			
			md5_II a, b, c, d, x(k + 0), S41, &HF4292244
			md5_II d, a, b, c, x(k + 7), S42, &H432AFF97
			md5_II c, d, a, b, x(k + 14), S43, &HAB9423A7
			md5_II b, c, d, a, x(k + 5), S44, &HFC93A039
			md5_II a, b, c, d, x(k + 12), S41, &H655B59C3
			md5_II d, a, b, c, x(k + 3), S42, &H8F0CCC92
			md5_II c, d, a, b, x(k + 10), S43, &HFFEFF47D
			md5_II b, c, d, a, x(k + 1), S44, &H85845DD1
			md5_II a, b, c, d, x(k + 8), S41, &H6FA87E4F
			md5_II d, a, b, c, x(k + 15), S42, &HFE2CE6E0
			md5_II c, d, a, b, x(k + 6), S43, &HA3014314
			md5_II b, c, d, a, x(k + 13), S44, &H4E0811A1
			md5_II a, b, c, d, x(k + 4), S41, &HF7537E82
			md5_II d, a, b, c, x(k + 11), S42, &HBD3AF235
			md5_II c, d, a, b, x(k + 2), S43, &H2AD7D2BB
			md5_II b, c, d, a, x(k + 9), S44, &HEB86D391
			
			a = AddUnsigned(a, AA)
			b = AddUnsigned(b, BB)
			c = AddUnsigned(c, CC)
			d = AddUnsigned(d, DD)
		Next
		
		MD5 = LCase(WordToHex(a) & WordToHex(b) & WordToHex(c) & WordToHex(d))
	End Function

Function SendJmail(username,mailfrom,mailfromname,mailto,mailSubject,mailBody,mailserver,MailServerPassword,emailport,EnableSsl)

'更换自动通知时发送人，在太多通知时这样启用以下代码：
'If InStr(mailSubject,"到期通知") Then
'mailfrom="test1@test.com"
'tempsec=Right("0"&second(now),1)
'If tempsec="3" Or tempsec="4" Or tempsec="5" Then
'mailfrom="test2@test.com"
'End If
'If tempsec="6" Or tempsec="7" Or tempsec="8" Or tempsec="9" Then
'mailfrom="test3@test.com"
'End If
'End if

enablejmail=True
If enablejmail=True then
UseStarOutMailCom=False
on error resume Next
err.clear
     Set jmail = Server.CreateObject("JMAIL.Message")   '建立发送邮件的对象
     jmail.silent = true    '屏蔽例外错误，返回FALSE跟TRUE两值j
     jmail.logging = true   '启用邮件日志
     jmail.Charset = "GB2312"     '邮件的文字编码为国标
     jmail.AddHeader "Priority","3"
     jmail.AddHeader "MSMail-Priority","Normal"
     jmail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR")
     jmail.AddHeader "Mailer","Microsoft Outlook Express 6.00.2800.1437"
     jmail.AddHeader "MimeOLE","Produced By Microsoft MimeOLE V6.00.2800.1441"
     jmail.ContentType = "text/html"    '邮件的格式为HTML格式
     jmail.AddRecipient  mailto   '邮件收件人的地址
	'jmail.AddRecipientBCC Email '密件收件人的地址 
     jmail.From =  mailfrom  '发件人的E-MAIL地址
	 jmail.FromName = mailfromname
     jmail.MailServerUserName = mailfrom     '登录邮件服务器所需的用户名
     jmail.MailServerPassword = MailServerPassword     '登录邮件服务器所需的密码
     jmail.Subject = mailSubject    '邮件的标题 
     jmail.Body = mailBody     '邮件的内容
	if not jmail.Send( mailserver ) then
		'FreeHost_oplog username,"信息","发送邮件出错:发件人:"&mailfromname&":"&mailfrom&"/"&MailServerPassword&" 收件人："&mailto&"信息："&jmail.log
		FreeHost_oplog username,"信息","发送邮件出错:发件人:"&mailfromname&":"&mailfrom&" 收件人："&mailto&"信息："&jmail.Log
		SendJmail="发送失败!"&jmail.Log
	Else
	SendJmail="发送成功"
	end if
	    jmail.Close()   '关闭对象
if err.number <> 0 then response.write "发送邮箱通知出错,参考<a href=http://sys.7i24.com/system/support/show.asp?id=101302129033 target=_blank>http://sys.7i24.com/system/support/show.asp?id=101302129033</a>来解决您的问题."
end If
End Function


Function Send2Mail(conn,username,mailSubject,mailBody)
	Set dsSend2Mail = Server.CreateObject("ADODB.Recordset")	
		Sql="Select agent1,email from FreeHost.FreeHost_USER where username='"&username&"'"
		dsSend2Mail.Open Sql,conn,1,1
if Not dsSend2Mail.eof Then
If dsSend2Mail("agent1")<>"n" then
  Set dsSend2Mailagn = Server.CreateObject("ADODB.Recordset")	
		Sql="Select Mailfrom,MailfromName,MailfromPass,MailfromServer,emailendmessage,emailport,EnableSsl from FreeHost.FreeHost_AGENT where username='"&dsSend2Mail("agent1")&"'"
		dsSend2Mailagn.Open Sql,conn,1,1
If not dsSend2Mailagn.Eof Then

if not isnull(dsSend2Mailagn("MailfromServer")) then
if len(dsSend2Mailagn("MailfromServer"))>3 then
Mail_from=dsSend2Mailagn("Mailfrom")
Mail_fromName=dsSend2Mailagn("MailfromName")
Mail_fromPass=dsSend2Mailagn("MailfromPass")
Mail_fromServer=dsSend2Mailagn("MailfromServer")
Mail_emailport=dsSend2Mailagn("emailport")
Mail_EnableSsl=dsSend2Mailagn("EnableSsl")
emailendmessage=dsSend2Mailagn("emailendmessage")
end if
End If
End if
Else
'当不是代理名下用户时
Mail_from=Application("Mail_from")
Mail_fromName=Application("Mail_fromName")
Mail_fromPass=Application("Mail_fromPass")
Mail_fromServer=Application("Mail_fromServer")
Mail_emailport=Application("Mail_emailport")
Mail_EnableSsl=Application("Mail_EnableSsl")
emailendmessage=Application("emailendmessage")
End If
If Mail_fromServer="" And Application("sendtonodefineagn")=true Then
'当允许发给代理时
Mail_from=Application("Mail_from")
Mail_fromName=Application("Mail_fromName")
Mail_fromPass=Application("Mail_fromPass")
Mail_fromServer=Application("Mail_fromServer")
Mail_emailport=Application("Mail_emailport")
Mail_EnableSsl=Application("Mail_EnableSsl")
emailendmessage=Application("emailendmessage")
End if
If Mail_fromServer<>"" Then
mailBody =replace(mailBody,"#发件人#",Mail_fromName)
mailBody =replace(mailBody,"#结束#",emailendmessage)

Send2Mail=SendJmail(username,Mail_from,Mail_fromName,dsSend2Mail("email"),mailSubject,mailBody,Mail_fromServer,Mail_fromPass,Mail_emailport,Mail_EnableSsl)
Else
FreeHost_oplog username,"信息","代理没有定义自己的邮箱信息,因此此邮件没有发出:发件人:"&Mail_fromName&":"&Mail_from&" 收件人："&mailto&"主题："&mailSubject
End If
End If
dsSend2Mail.close
End Function

Function UpAgentretMoney()

if agent_UP="n" or ef then Exit Function'不是子代理
'response.write agent_UP&"<br>"
'response.write agent_thisgree_cost&"<br>"

Set dsagent = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_AGENT where username='"&agent_UP&"'"
		dsagent.Open Sql,conn,1,3
If dsagent.Eof Then
		ef=True
		ec="代理会员名不存在！"'用户的直接代理
end if

if not ef then
	Set dsmoney_next = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_price where prtype='"&forpaytype&"' and username='"&agent_UP&"' and id="&forpayid&""
		dsmoney_next.Open Sql,conn,1,1'上级代理的成本价
if dsmoney_next.eof then

'单独定价中不存在
if dsagent("agentdegree")=0 then'直接代理
'response.write "<br>直接代理"
	Set dsagnettype = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_Agent_pers where agenttype='"& dsagent("agenttype")&"'"
		dsagnettype.Open Sql,conn,1,1
myrealcost_UP=Userpaymoney*dsagnettype("pers")*forpayyear'直接代理共同折扣时的成本价
If cloudAddmoney>0 Then myrealcost_UP=(Userpaymoney+cloudAddmoney)*dsagnettype("pers")*forpayyear '2014-1-18增加的弹性购买附加
myrealcost_UP=Clng(FormatNumber(myrealcost_UP,0,-1,0,0))'四舍五入
'response.write "<br>cost"&myrealcost_UP
end if'直接代理

else''单独定价中存在 上级代理的成本价
myrealcost_UP=dsmoney_next("usermoney")*forpayyear

If cloudAddmoney>0 Then myrealcost_UP=(dsmoney_next("usermoney")+(cloudAddmoney*(dsmoney_next("usermoney")/Userpaymoney)))*forpayyear '2014-1-18增加的弹性购买附加代理直价

myrealcost_UP=Clng(FormatNumber(myrealcost_UP,0,-1,0,0))'四舍五入
end if'单独定价判断

thisagentgetmoney=agent_thisgree_cost-myrealcost_UP

if thisagentgetmoney>0 or thisagentgetmoney=0 then'是否是正常的返回折扣
agn_next_old_money=dsagent("usermoney")
dsagent("usermoney")=dsagent("usermoney")+thisagentgetmoney'to上级代理
agn_next_new_money=dsagent("usermoney")
'FreeHost_moneylog conn,dsagent("username"),agent_this_name,thisagentgetmoney,"子代理返回的收入",forpaytype,session("moneylog_pdid"),"","n"
FreeHost_moneyNewlog conn,"n","y","n","n","y",isAgnHostSer,thisagentgetmoney,dsagent("username"),agent_this_name,"",norStmoney,norEndmoney,dsagent("username"),agn_next_old_money,agn_next_new_money,supusername,logfor&"子代理返回的收入",logfor&"子代理返回的收入",forpaytype,session("moneylog_pdid"),pingzheng,type1,bank,haveget,havecheck
Else  
response.write "<br>操作失败，当前用户费用已扣，返回给上级金额中存在负数而被中止："&thisagentgetmoney
FreeHost_oplog session("username"),"信息","开通域名编号："&session("moneylog_pdid")&"时操作失败，当前用户费用已扣，返回给上级代理:"&dsagent("username")&"中存在负数而被中止"&thisagentgetmoney
response.end
'FreeHost_moneylog conn,dsagent("username"),agent_this_name,0,"由于子代理的定价比上级代理的成本价更低而不会有返回收入",forpaytype,session("moneylog_pdid"),"","n"
end if


dsagent.update

agent_UP=dsagent("agent1")'上级代理名
agent_this_name=dsagent("username")
agent_thisgree_cost=myrealcost_UP'本级代理成本

dsmoney_next.close

UpAgentretMoney

end if
End Function










Function DoPayMoney()
	Set dsendmoney = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_user_price where prtype='"&forpaytype&"' and username='"&Useragentname&"' and id="&forpayid&""
		dsendmoney.Open Sql,conn,1,1
if not dsendmoney.eof then
UserpaymoneyEnd=dsendmoney("usermoney")
else
UserpaymoneyEnd=Userpaymoney
end if
dsendmoney.close

If cloudAddmoney>0 Then UserpaymoneyEnd=UserpaymoneyEnd+cloudAddmoney '2014-1-18增加的弹性购买附加 原成本价加上基准增量

if isRepaymoney then UserpaymoneyEnd=Repaymoney'管理员设置单独续费价

UserpaymoneyEnd=UserpaymoneyEnd*forpayyear

UserpaymoneyEnd=Clng(FormatNumber(UserpaymoneyEnd,0,-1,0,0))'四舍五入

if forpayyear=999 then UserpaymoneyEnd=0'试用

If Request.Form ("chmoney")<>"" and session("agentusername")<>"" and Request.Form ("usermoney")<>"" Then UserpaymoneyEnd=Clng(Request.Form ("usermoney"))'代理手工设定扣费金额

If Request.Form ("chmoney")="" and session("agentusername")<>"" Then UserpaymoneyEnd=0'代理手工设定扣费金额(不扣用户费用时)

if Request.Form ("usermoney")<0 then
	ef=True
	ec="很抱歉,不能设为负。"
end if

if AgnRunasUser=true then UserpaymoneyEnd=0
'2005-5-10
'以代理的身份进入用户区

if UserpaymoneyEnd>RsUserds("usermoney") then
	ef=True
	ec="很抱歉,此用户的可用余额为("&RsUserds("usermoney")&"元)，需要支付的金额为："&UserpaymoneyEnd&" 元。余额不足。"
end if

if not ef then
olduser_money=RsUserds("usermoney")
RsUserds("usermoney")=RsUserds("usermoney") - UserpaymoneyEnd
moneych=UserpaymoneyEnd
RsUserds.update'扣费
newuser_money=RsUserds("usermoney")
session("moneylog_pdid")=RsUserds ("username")&now
'Log
'FreeHost_moneylog conn,RsUserds ("username"),RsUserds ("username"),moneych,logfor&forpaytype,forpaytype,session("moneylog_pdid"),"","n"
if AgnRunasUser=false then FreeHost_moneyNewlog conn,"y","n","n","n","n",isAgnHostSer,moneych,RsUserds ("username"),RsUserds ("username"),RsUserds ("username"),olduser_money,newuser_money,agnusername,agnStmoney,agnEndmoney,supusername,logfor&forpaytype,logfor&forpaytype,forpaytype,session("moneylog_pdid"),pingzheng,type1,bank,haveget,havecheck


end if

if RsUserds("agent1")="n" or ef then Exit Function'不是代理名下用户
Set dsagent = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_AGENT where username='"&RsUserds("agent1")&"'"
		dsagent.Open Sql,conn,1,3
If dsagent.Eof Then
		ef=True
		ec="代理会员名不存在！"'用户的直接代理
end if

if not ef then
	Set dsagnettype = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_Agent_pers where agenttype='"& dsagent("agenttype")&"'"
		dsagnettype.Open Sql,conn,1,1
if dsagnettype.Eof then
	ef=True
	ec="代理类型折扣为空，请先设置它！"
end if
end if

if not ef then
	Set dsagnpri = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_price where prtype='"&forpaytype&"' and username='"&RsUserds ("agent1")&"' and id="&forpayid&""
		dsagnpri.Open Sql,conn,1,1
if dsagnpri.eof then
myrealcost=Userpaymoney*dsagnettype("pers")'用户的代理的成本
If cloudAddmoney>0 Then myrealcost=(Userpaymoney+cloudAddmoney)*dsagnettype("pers") '2014-1-18增加的弹性购买附加代理成本折扣 标准价加上增量X折扣
else
myrealcost=dsagnpri("usermoney")
If cloudAddmoney>0 Then myrealcost=(Userpaymoney+cloudAddmoney)*(myrealcost/Userpaymoney) '2014-1-18增加的弹性购买附加代理直价 标准价加上增量X比例
end if
dsagnpri.close
if isRepaymoney then myrealcost=Repaymoney'管理员设置单独续费价
end if

if not ef then
myrealcost=myrealcost*forpayyear'时间
myrealcost=Clng(FormatNumber(myrealcost,0,-1,0,0))'四舍五入
if forpayyear=999 then myrealcost=0'试用
if pubisagnSer=true then
myrealcost=0
logfor=logfor&"独立模式"
'2005-5-10
'代理独立模式开通
end If

if (dsagent("usermoney")+UserpaymoneyEnd-myrealcost)<0 then
	ef=True
	ec="上级的余额不足！"
end If

end if

if not ef then
oldagn_money=dsagent("usermoney")
dsagent("usermoney")=dsagent("usermoney")+UserpaymoneyEnd-myrealcost
mymoneych=UserpaymoneyEnd-myrealcost
dsagent.update
newagn_money=dsagent("usermoney")
'Log
'FreeHost_moneylog conn,dsagent("username"),RsUserds ("username"),mymoneych,logfor&"代理收入",forpaytype,session("moneylog_pdid"),"","n"
if AgnRunasUser=false then
if mymoneych>=0 then
FreeHost_moneyNewlog conn,"n","y","n","n","y",isAgnHostSer,mymoneych,dsagent("username"),RsUserds ("username"),RsUserds ("username"),norStmoney,norEndmoney,dsagent("username"),oldagn_money,newagn_money,supusername,logfor&"代理收入",logfor&"代理收入",forpaytype,session("moneylog_pdid"),pingzheng,type1,bank,haveget,havecheck
else
FreeHost_moneyNewlog conn,"n","y","n","n","n",isAgnHostSer,-mymoneych,dsagent("username"),RsUserds ("username"),RsUserds ("username"),norStmoney,norEndmoney,dsagent("username"),oldagn_money,newagn_money,supusername,logfor&"扣除代理资金",logfor&"扣除代理资金",forpaytype,session("moneylog_pdid"),pingzheng,type1,bank,haveget,havecheck
end if
else
FreeHost_moneyNewlog conn,"n","n","n","n","n",isAgnHostSer,-mymoneych,dsagent("username"),RsUserds ("username"),norusername,norStmoney,norEndmoney,dsagent("username"),oldagn_money,newagn_money,supusername,logfor&"扣代理成本",logfor&"扣代理成本",forpaytype,session("moneylog_pdid"),pingzheng,type1,bank,haveget,havecheck
olduser_money=oldagn_money
moneych=-mymoneych
newuser_money=newagn_money
end if
end if

if dsagent("agent1")="n" or ef or forpayyear=999 or pubisagnSer or isRepaymoney then Exit Function'不是子代理或出错或是试用或是[独立模式]不返还'或者是管理员单独设置的续费价
agent_UP=dsagent("agent1")'上级代理名
agent_this_name=dsagent("username")
agent_thisgree_cost=myrealcost'本级代理成本

UpAgentretMoney
End Function


















Function DoPayMoneyDomain()
	Set dsendmoney = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_user_price where prtype='"&forpaytype&"' and username='"&Useragentname&"' and id="&forpayid&""
		dsendmoney.Open Sql,conn,1,1
if not dsendmoney.eof then
UserpaymoneyEnd=dsendmoney("usermoney")
if isreplay Then'续费分api
UserpaymoneyEnd=dsendmoney("usermoneyrepay")'续费
If domainRepayAPI<>1 Then UserpaymoneyEnd=dsendmoney("usermoneyrepay"&domainRepayAPI)'续费选取API价格
End If

else
UserpaymoneyEnd=Userpaymoney
end if
dsendmoney.close

UserpaymoneyEnd=UserpaymoneyEnd*forpayyear
if forpayyear=999 then UserpaymoneyEnd=0'试用

If UserpaymoneyEnd=0 Or IsNull(UserpaymoneyEnd) Then 
		ef=True
		ec="产品的定价不能为0或为空,请联系您的服务商先为这个产品定价.也可能是系统参数中,没有设置显示这个接口,并设置AGN出售价造成."
Exit Function
End if

If cnrepay=True Then
UserpaymoneyEnd=5'cnnic特殊续费
logfor=logfor&"执行CNNIC特殊续费优惠"
End if

If Request("chmoney")<>"" and session("agentusername")<>"" and Request("usermoney")<>"" Then UserpaymoneyEnd=Clng(Request("usermoney"))'代理手工设定扣费金额

If Request("chmoney")="" and session("agentusername")<>"" Then UserpaymoneyEnd=0'代理手工设定扣费金额(不扣用户费用时)

if Request("usermoney")<0 then
	ef=True
	ec="很抱歉,不能设为负。"
end if



if AgnRunasUser=true then UserpaymoneyEnd=0
'2005-5-10
'以代理的身份进入用户区

if UserpaymoneyEnd>RsUserds("usermoney") then
	ef=True
	ec="很抱歉,此用户的可用余额为("&RsUserds("usermoney")&"元)，需要支付的金额为："&UserpaymoneyEnd&" 元。余额不足。"
end if

if not ef Then

olduser_money=RsUserds("usermoney")
RsUserds("usermoney")=RsUserds("usermoney") - UserpaymoneyEnd
moneych=UserpaymoneyEnd
RsUserds.update'扣费
newuser_money=RsUserds("usermoney")
'session("moneylog_pdid")=RsUserds ("username")&now'域名可以直接用pid
'Log
'FreeHost_moneylog conn,RsUserds ("username"),RsUserds ("username"),moneych,logfor&forpaytype,forpaytype,session("moneylog_pdid"),"","n"
if AgnRunasUser=false then FreeHost_moneyNewlog conn,"y","n","n","n","n",isAgnHostSer,moneych,RsUserds ("username"),RsUserds ("username"),RsUserds ("username"),olduser_money,newuser_money,agnusername,agnStmoney,agnEndmoney,supusername,logfor&forpaytype,logfor&forpaytype,forpaytype,session("moneylog_pdid"),pingzheng,type1,bank,haveget,havecheck


end if

if RsUserds("agent1")="n" or ef then Exit Function'不是代理名下用户
Set dsagent = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_AGENT where username='"&RsUserds("agent1")&"'"
		dsagent.Open Sql,conn,1,3
If dsagent.Eof Then
		ef=True
		ec="代理会员名不存在！"'用户的直接代理
end if

if not ef then
	Set dsagnettype = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_Agent_pers where agenttype='"& dsagent("agenttype")&"'"
		dsagnettype.Open Sql,conn,1,1
if dsagnettype.Eof then
	ef=True
	ec="代理类型折扣为空，请先设置它！"
end if
end if

if not ef then
	Set dsagnpri = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_price where prtype='"&forpaytype&"' and username='"&RsUserds ("agent1")&"' and id="&forpayid&""
		dsagnpri.Open Sql,conn,1,1
if dsagnpri.eof Or (IsNull(dsagnpri("usermoneyrepay")) And domainRepayAPI=1) Or (IsNull(dsagnpri("usermoneyrepay2")) And domainRepayAPI=2) Or (IsNull(dsagnpri("usermoneyrepay3")) And domainRepayAPI=3) Or (IsNull(dsagnpri("usermoneyrepay4")) And domainRepayAPI=4) Or (IsNull(dsagnpri("usermoneyrepay5")) And domainRepayAPI=5) Or (IsNull(dsagnpri("usermoneyrepay6")) And domainRepayAPI=6) then
usermoney=dsDlist("usermoneyagnrepay")
'myrealcost=Userpaymoney*dsagnettype("pers")'用户的代理的成本
myrealcost=RsDlist("usermoneyagn")'不用折扣算
if isreplay Then
myrealcost=RsDlist("usermoneyagnrepay")'续费
If domainRepayAPI<>1 Then myrealcost=RsDlist("usermoneyagnrepay"&domainRepayAPI)'续费API
End if
else
myrealcost=dsagnpri("usermoney")
if isreplay Then
myrealcost=dsagnpri("usermoneyrepay")'续费
If domainRepayAPI<>1 Then myrealcost=dsagnpri("usermoneyrepay"&domainRepayAPI)'续费API
End If

end if
dsagnpri.close
end if

if not ef then
myrealcost=myrealcost*forpayyear'时间
if forpayyear=999 then myrealcost=0'试用
if pubisagnSer=true then
myrealcost=0
logfor=logfor&"独立模式"
'2005-5-10
'代理独立模式开通

end if

If cnrepay=True Then myrealcost=5'cnnic特殊续费

if (dsagent("usermoney")+UserpaymoneyEnd-myrealcost)<0 then
	ef=True
	ec="上级的余额不足！"
end If

end if


if not ef Then

oldagn_money=dsagent("usermoney")
dsagent("usermoney")=dsagent("usermoney")+UserpaymoneyEnd-myrealcost
mymoneych=UserpaymoneyEnd-myrealcost
dsagent.update
newagn_money=dsagent("usermoney")
'Log
'FreeHost_moneylog conn,dsagent("username"),RsUserds ("username"),mymoneych,logfor&"代理收入",forpaytype,session("moneylog_pdid"),"","n"
if AgnRunasUser=false then
if mymoneych>=0 then
FreeHost_moneyNewlog conn,"n","y","n","n","y",isAgnHostSer,mymoneych,dsagent("username"),RsUserds ("username"),RsUserds ("username"),norStmoney,norEndmoney,dsagent("username"),oldagn_money,newagn_money,supusername,logfor&"代理收入",logfor&"代理收入",forpaytype,session("moneylog_pdid"),pingzheng,type1,bank,haveget,havecheck
else
FreeHost_moneyNewlog conn,"n","y","n","n","n",isAgnHostSer,-mymoneych,dsagent("username"),RsUserds ("username"),RsUserds ("username"),norStmoney,norEndmoney,dsagent("username"),oldagn_money,newagn_money,supusername,logfor&"扣除代理资金",logfor&"扣除代理资金",forpaytype,session("moneylog_pdid"),pingzheng,type1,bank,haveget,havecheck
end if
else
FreeHost_moneyNewlog conn,"n","n","n","n","n",isAgnHostSer,-mymoneych,dsagent("username"),RsUserds ("username"),norusername,norStmoney,norEndmoney,dsagent("username"),oldagn_money,newagn_money,supusername,logfor&"扣代理成本",logfor&"扣代理成本",forpaytype,session("moneylog_pdid"),pingzheng,type1,bank,haveget,havecheck
olduser_money=oldagn_money'2007-5-22
moneych=-mymoneych
newuser_money=newagn_money
end if
end if

if dsagent("agent1")="n" or ef or forpayyear=999 or pubisagnSer  Or cnrepay=True then Exit Function'不是子代理或出错或是试用或是[独立模式]不返还或是cnnic特殊
agent_UP=dsagent("agent1")'上级代理名
agent_this_name=dsagent("username")
agent_thisgree_cost=myrealcost'本级代理成本

UpAgentretMoneyDomin
End Function




Function UpAgentretMoneyDomin()

if agent_UP="n" or ef then Exit Function'不是子代理
'response.write agent_UP&"<br>"
'response.write agent_thisgree_cost&"<br>"

Set dsagent = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_AGENT where username='"&agent_UP&"'"
		dsagent.Open Sql,conn,1,3
If dsagent.Eof Then
		ef=True
		ec="代理会员名不存在！"'用户的直接代理
end if

if not ef then
	Set dsmoney_next = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_price where prtype='"&forpaytype&"' and username='"&agent_UP&"' and id="&forpayid&""
		dsmoney_next.Open Sql,conn,1,1'上级代理的成本价
'if dsmoney_next.eof then
if dsmoney_next.eof Or (IsNull(dsmoney_next("usermoneyrepay")) And domainRepayAPI=1) Or (IsNull(dsmoney_next("usermoneyrepay2")) And domainRepayAPI=2) Or (IsNull(dsmoney_next("usermoneyrepay3")) And domainRepayAPI=3) Or (IsNull(dsmoney_next("usermoneyrepay4")) And domainRepayAPI=4) Or (IsNull(dsmoney_next("usermoneyrepay5")) And domainRepayAPI=5) Or (IsNull(dsmoney_next("usermoneyrepay6")) And domainRepayAPI=6) then
usermoney=dsDlist("usermoneyagnrepay")'有可能存在空价格

'单独定价中不存在
if dsagent("agentdegree")=0 then'直接代理
'response.write "<br>直接代理"
	Set dsagnettype = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_Agent_pers where agenttype='"& dsagent("agenttype")&"'"
		dsagnettype.Open Sql,conn,1,1
'myrealcost_UP=Userpaymoney*dsagnettype("pers")*forpayyear'直接代理共同折扣时的成本价
myrealcost_UP=RsDlist("usermoneyagn")*forpayyear'''''''''不用折扣的算法
if isreplay Then
myrealcost_UP=RsDlist("usermoneyagnrepay")*forpayyear
If domainRepayAPI<>1 Then myrealcost_UP=RsDlist("usermoneyagnrepay"&domainRepayAPI)*forpayyear' api
End if
'response.write "<br>cost"&myrealcost_UP
end if'直接代理

else''单独定价中存在 上级代理的成本价
myrealcost_UP=dsmoney_next("usermoney")*forpayyear
if isreplay Then
myrealcost_UP=dsmoney_next("usermoneyrepay")*forpayyear
If domainRepayAPI<>1 Then myrealcost_UP=dsmoney_next("usermoneyrepay"&domainRepayAPI)*forpayyear'api
End If

end if'单独定价判断

thisagentgetmoney=agent_thisgree_cost-myrealcost_UP

if thisagentgetmoney>0 or thisagentgetmoney=0 then'是否是正常的返回折扣
agn_next_old_money=dsagent("usermoney")
dsagent("usermoney")=dsagent("usermoney")+thisagentgetmoney'to上级代理
agn_next_new_money=dsagent("usermoney")
'FreeHost_moneylog conn,dsagent("username"),agent_this_name,thisagentgetmoney,"子代理返回的收入",forpaytype,session("moneylog_pdid"),"","n"
FreeHost_moneyNewlog conn,"n","y","n","n","y",isAgnHostSer,thisagentgetmoney,dsagent("username"),agent_this_name,"",norStmoney,norEndmoney,dsagent("username"),agn_next_old_money,agn_next_new_money,supusername,logfor&"子代理返回的收入",logfor&"子代理返回的收入",forpaytype,session("moneylog_pdid"),pingzheng,type1,bank,haveget,havecheck
Else
response.write "<br>操作失败，当前用户费用已扣，返回给上级金额中存在负数而被中止："&thisagentgetmoney
FreeHost_oplog session("username"),"信息","开通域名编号："&session("moneylog_pdid")&"时操作失败，当前用户费用已扣，返回给上级代理:"&dsagent("username")&"中存在负数而被中止"&thisagentgetmoney
response.end
'FreeHost_moneylog conn,dsagent("username"),agent_this_name,0,"由于子代理的定价比上级代理的成本价更低而不会有返回收入",forpaytype,session("moneylog_pdid"),"","n"
end if


dsagent.update

agent_UP=dsagent("agent1")'上级代理名
agent_this_name=dsagent("username")
agent_thisgree_cost=myrealcost_UP'本级代理成本

dsmoney_next.close

UpAgentretMoneyDomin

end if
End Function












'------------新的域名注册财务处理----不带有续费





Function DoPayMoneyDomainNew()
	Set dsendmoney = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_user_price where prtype='"&forpaytype&"' and username='"&Useragentname&"' and id="&forpayid&""
		dsendmoney.Open Sql,conn,1,1
if not dsendmoney.eof then
UserpaymoneyEnd=dsendmoney("usermoney")
if forpayyear=2 then UserpaymoneyEnd=dsendmoney("year2")
if forpayyear=3 then UserpaymoneyEnd=dsendmoney("year3")
if forpayyear=4 then UserpaymoneyEnd=dsendmoney("year4")
if forpayyear=5 then UserpaymoneyEnd=dsendmoney("year5")
if Application("domaincansetM")=true Then
If Not IsNull(dsendmoney("usermoney"&"API"&regapi)) Then UserpaymoneyEnd=dsendmoney("usermoney"&"API"&regapi)
if forpayyear=2 And Not IsNull(dsendmoney("year2"&"API"&regapi)) then UserpaymoneyEnd=dsendmoney("year2"&"API"&regapi)
if forpayyear=3 And Not IsNull(dsendmoney("year3"&"API"&regapi)) then UserpaymoneyEnd=dsendmoney("year3"&"API"&regapi)
if forpayyear=4 And Not IsNull(dsendmoney("year4"&"API"&regapi)) then UserpaymoneyEnd=dsendmoney("year4"&"API"&regapi)
if forpayyear=5 And Not IsNull(dsendmoney("year5"&"API"&regapi)) then UserpaymoneyEnd=dsendmoney("year5"&"API"&regapi)
End if
if isreplay then UserpaymoneyEnd=dsendmoney("usermoneyrepay")'续费
else'没有单独定价的用户
UserpaymoneyEnd=Userpaymoney
if forpayyear=2 then UserpaymoneyEnd=RsDlist("year2")
if forpayyear=3 then UserpaymoneyEnd=RsDlist("year3")
if forpayyear=4 then UserpaymoneyEnd=RsDlist("year4")
if forpayyear=5 then UserpaymoneyEnd=RsDlist("year5")
if Application("domaincansetM")=true Then
If Not IsNull(RsDlist("usermoney"&"API"&regapi)) Then UserpaymoneyEnd=RsDlist("usermoney"&"API"&regapi)
if forpayyear=2 And Not IsNull(RsDlist("year2"&"API"&regapi)) then UserpaymoneyEnd=RsDlist("year2"&"API"&regapi)
if forpayyear=3 And Not IsNull(RsDlist("year3"&"API"&regapi)) then UserpaymoneyEnd=RsDlist("year3"&"API"&regapi)
if forpayyear=4 And Not IsNull(RsDlist("year4"&"API"&regapi)) then UserpaymoneyEnd=RsDlist("year4"&"API"&regapi)
if forpayyear=5 And Not IsNull(RsDlist("year5"&"API"&regapi)) then UserpaymoneyEnd=RsDlist("year5"&"API"&regapi)
end if
end if
dsendmoney.close

'UserpaymoneyEnd=UserpaymoneyEnd*forpayyear 2007-3-15取消
if forpayyear>5 and forpayyear<>999 then
	ef=True
	ec="很抱歉,注册的年限不能超过5年。"
end if

if forpayyear=999 then UserpaymoneyEnd=0'试用

If Request("chmoney")<>"" and session("agentusername")<>"" and Request("usermoney")<>"" Then UserpaymoneyEnd=Clng(Request("usermoney"))'代理手工设定扣费金额

If Request("chmoney")="" and session("agentusername")<>"" Then UserpaymoneyEnd=0'代理手工设定扣费金额(不扣用户费用时)

if Request("usermoney")<0 then
	ef=True
	ec="很抱歉,不能设为负。"
end if

if AgnRunasUser=true then UserpaymoneyEnd=0
'2005-5-10
'以代理的身份进入用户区

if UserpaymoneyEnd>RsUserds("usermoney") then
	ef=True
	ec="很抱歉,此用户的可用余额为("&RsUserds("usermoney")&"元)，需要支付的金额为："&UserpaymoneyEnd&" 元。余额不足。"
end if

if not ef then
olduser_money=RsUserds("usermoney")
RsUserds("usermoney")=RsUserds("usermoney") - UserpaymoneyEnd
moneych=UserpaymoneyEnd
RsUserds.update'扣费
newuser_money=RsUserds("usermoney")
'session("moneylog_pdid")=RsUserds ("username")&now'域名可以直接用pid
'Log
'FreeHost_moneylog conn,RsUserds ("username"),RsUserds ("username"),moneych,logfor&forpaytype,forpaytype,session("moneylog_pdid"),"","n"
if AgnRunasUser=false then FreeHost_moneyNewlog conn,"y","n","n","n","n",isAgnHostSer,moneych,RsUserds ("username"),RsUserds ("username"),RsUserds ("username"),olduser_money,newuser_money,agnusername,agnStmoney,agnEndmoney,supusername,logfor&forpaytype,logfor&forpaytype,forpaytype,session("moneylog_pdid"),pingzheng,type1,bank,haveget,havecheck


end if

if RsUserds("agent1")="n" or ef then Exit Function'不是代理名下用户
Set dsagent = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_AGENT where username='"&RsUserds("agent1")&"'"
		dsagent.Open Sql,conn,1,3
If dsagent.Eof Then
		ef=True
		ec="代理会员名不存在！"'用户的直接代理
end if

if not ef then
	Set dsagnettype = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_Agent_pers where agenttype='"& dsagent("agenttype")&"'"
		dsagnettype.Open Sql,conn,1,1
if dsagnettype.Eof then
	ef=True
	ec="代理类型折扣为空，请先设置它！"
end if
end if

if not ef then
	Set dsagnpri = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_price where prtype='"&forpaytype&"' and username='"&RsUserds ("agent1")&"' and id="&forpayid&""
		dsagnpri.Open Sql,conn,1,1
if dsagnpri.eof then
'myrealcost=Userpaymoney*dsagnettype("pers")'用户的代理的成本
myrealcost=RsDlist("usermoneyagn")'不用折扣算
if forpayyear=2 then myrealcost=RsDlist("year2agn")
if forpayyear=3 then myrealcost=RsDlist("year3agn")
if forpayyear=4 then myrealcost=RsDlist("year4agn")
if forpayyear=5 then myrealcost=RsDlist("year5agn")

if Application("domaincansetM")=true Then
If Not isNull(RsDlist("usermoneyagn"&"API"&regapi)) Then myrealcost=RsDlist("usermoneyagn"&"API"&regapi)'不用折扣算
if forpayyear=2 And Not IsNull(RsDlist("year2agn"&"API"&regapi)) then myrealcost=RsDlist("year2agn"&"API"&regapi)
if forpayyear=3 And Not IsNull(RsDlist("year3agn"&"API"&regapi)) then myrealcost=RsDlist("year3agn"&"API"&regapi)
if forpayyear=4 And Not IsNull(RsDlist("year4agn"&"API"&regapi)) then myrealcost=RsDlist("year4agn"&"API"&regapi)
if forpayyear=5 And Not IsNull(RsDlist("year5agn"&"API"&regapi)) then myrealcost=RsDlist("year5agn"&"API"&regapi)
End if

if isreplay then myrealcost=RsDlist("usermoneyagnrepay")'续费
else
myrealcost=dsagnpri("usermoney")
if forpayyear=2 then myrealcost=dsagnpri("year2")
if forpayyear=3 then myrealcost=dsagnpri("year3")
if forpayyear=4 then myrealcost=dsagnpri("year4")
if forpayyear=5 then myrealcost=dsagnpri("year5")

if Application("domaincansetM")=true Then
If Not isNull(RsDlist("usermoneyagn"&"API"&regapi)) Then myrealcost=RsDlist("usermoneyagn"&"API"&regapi)
if forpayyear=2 And Not IsNull(RsDlist("year2agn"&"API"&regapi)) then myrealcost=RsDlist("year2agn"&"API"&regapi)
if forpayyear=3 And Not IsNull(RsDlist("year3agn"&"API"&regapi)) then myrealcost=RsDlist("year3agn"&"API"&regapi)
if forpayyear=4 And Not IsNull(RsDlist("year4agn"&"API"&regapi)) then myrealcost=RsDlist("year4agn"&"API"&regapi)
if forpayyear=5 And Not IsNull(RsDlist("year5agn"&"API"&regapi)) then myrealcost=RsDlist("year5agn"&"API"&regapi)

If Not isNull(dsagnpri("usermoney"&"API"&regapi)) Then myrealcost=dsagnpri("usermoney"&"API"&regapi)
if forpayyear=2 And Not IsNull(dsagnpri("year2"&"API"&regapi)) then myrealcost=dsagnpri("year2"&"API"&regapi)
if forpayyear=3 And Not IsNull(dsagnpri("year3"&"API"&regapi)) then myrealcost=dsagnpri("year3"&"API"&regapi)
if forpayyear=4 And Not IsNull(dsagnpri("year4"&"API"&regapi)) then myrealcost=dsagnpri("year4"&"API"&regapi)
if forpayyear=5 And Not IsNull(dsagnpri("year5"&"API"&regapi)) then myrealcost=dsagnpri("year5"&"API"&regapi)
End if

if isreplay then myrealcost=dsagnpri("usermoneyrepay")'续费
'If IsNull(dsagnpri("usermoney")) And forpayyear=1 Then myrealcost=RsDlist("usermoneyagn")
'If IsNull(dsagnpri("year2")) And forpayyear=2 Then myrealcost=RsDlist("year2agn")
'If IsNull(dsagnpri("year3")) And forpayyear=3 Then myrealcost=RsDlist("year3agn")
'If IsNull(dsagnpri("year4")) And forpayyear=4 Then myrealcost=RsDlist("year4agn")
'If IsNull(dsagnpri("year5")) And forpayyear=5 Then myrealcost=RsDlist("year5agn")
If IsNull(myrealcost) And forpayyear=1 Then myrealcost=RsDlist("usermoneyagn")
If IsNull(myrealcost) And forpayyear=2 Then myrealcost=RsDlist("year2agn")
If IsNull(myrealcost) And forpayyear=3 Then myrealcost=RsDlist("year3agn")
If IsNull(myrealcost) And forpayyear=4 Then myrealcost=RsDlist("year4agn")
If IsNull(myrealcost) And forpayyear=5 Then myrealcost=RsDlist("year5agn")

end if
dsagnpri.close
end if

if not ef then
'myrealcost=myrealcost*forpayyear'时间2007-3-15取消
if forpayyear=999 then myrealcost=0'试用
if pubisagnSer=true then
myrealcost=0
logfor=logfor&"独立模式"
'2005-5-10
'代理独立模式开通
end If


if (dsagent("usermoney")+UserpaymoneyEnd-myrealcost)<0 then
	ef=True
	ec="上级的余额不足！"
end If

end if

if not ef then
oldagn_money=dsagent("usermoney")
dsagent("usermoney")=dsagent("usermoney")+UserpaymoneyEnd-myrealcost
mymoneych=UserpaymoneyEnd-myrealcost
dsagent.update
newagn_money=dsagent("usermoney")
'Log
'FreeHost_moneylog conn,dsagent("username"),RsUserds ("username"),mymoneych,logfor&"代理收入",forpaytype,session("moneylog_pdid"),"","n"
if AgnRunasUser=false then
if mymoneych>=0 then
FreeHost_moneyNewlog conn,"n","y","n","n","y",isAgnHostSer,mymoneych,dsagent("username"),RsUserds ("username"),RsUserds ("username"),norStmoney,norEndmoney,dsagent("username"),oldagn_money,newagn_money,supusername,logfor&"代理收入",logfor&"代理收入",forpaytype,session("moneylog_pdid"),pingzheng,type1,bank,haveget,havecheck
else
FreeHost_moneyNewlog conn,"n","y","n","n","n",isAgnHostSer,-mymoneych,dsagent("username"),RsUserds ("username"),RsUserds ("username"),norStmoney,norEndmoney,dsagent("username"),oldagn_money,newagn_money,supusername,logfor&"扣除代理资金",logfor&"扣除代理资金",forpaytype,session("moneylog_pdid"),pingzheng,type1,bank,haveget,havecheck
end if
else
FreeHost_moneyNewlog conn,"n","n","n","n","n",isAgnHostSer,-mymoneych,dsagent("username"),RsUserds ("username"),norusername,norStmoney,norEndmoney,dsagent("username"),oldagn_money,newagn_money,supusername,logfor&"扣代理成本",logfor&"扣代理成本",forpaytype,session("moneylog_pdid"),pingzheng,type1,bank,haveget,havecheck
olduser_money=oldagn_money'2007-5-22
moneych=-mymoneych
newuser_money=newagn_money
end if
end if

if dsagent("agent1")="n" or ef or forpayyear=999 or pubisagnSer then Exit Function'不是子代理或出错或是试用或是[独立模式]不返还
agent_UP=dsagent("agent1")'上级代理名
agent_this_name=dsagent("username")
agent_thisgree_cost=myrealcost'本级代理成本

UpAgentretMoneyDominNew
End Function




Function UpAgentretMoneyDominNew()

if agent_UP="n" or ef then Exit Function'不是子代理
'response.write agent_UP&"<br>"
'response.write agent_thisgree_cost&"<br>"

Set dsagent = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_AGENT where username='"&agent_UP&"'"
		dsagent.Open Sql,conn,1,3
If dsagent.Eof Then
		ef=True
		ec="代理会员名不存在！"'用户的直接代理
end if

if not ef then
	Set dsmoney_next = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_price where prtype='"&forpaytype&"' and username='"&agent_UP&"' and id="&forpayid&""
		dsmoney_next.Open Sql,conn,1,1'上级代理的成本价
if dsmoney_next.eof then

'单独定价中不存在
if dsagent("agentdegree")=0 then'直接代理
'response.write "<br>直接代理"
	Set dsagnettype = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_Agent_pers where agenttype='"& dsagent("agenttype")&"'"
		dsagnettype.Open Sql,conn,1,1
'myrealcost_UP=RsDlist("usermoneyagn")*forpayyear'''''''''不用折扣的算法
myrealcost_UP=RsDlist("usermoneyagn")'''''''''不用折扣的算法  2007-3-15 改为
if forpayyear=2 then myrealcost_UP=RsDlist("year2agn")
if forpayyear=3 then myrealcost_UP=RsDlist("year3agn")
if forpayyear=4 then myrealcost_UP=RsDlist("year4agn")
if forpayyear=5 then myrealcost_UP=RsDlist("year5agn")

if Application("domaincansetM")=true Then
If Not IsNull(RsDlist("usermoneyagn"&"API"&regapi)) Then myrealcost_UP=RsDlist("usermoneyagn"&"API"&regapi)
if forpayyear=2 And Not IsNull(RsDlist("year2agn"&"API"&regapi)) then myrealcost_UP=RsDlist("year2agn"&"API"&regapi)
if forpayyear=3 And Not IsNull(RsDlist("year3agn"&"API"&regapi)) then myrealcost_UP=RsDlist("year3agn"&"API"&regapi)
if forpayyear=4 And Not IsNull(RsDlist("year4agn"&"API"&regapi)) then myrealcost_UP=RsDlist("year4agn"&"API"&regapi)
if forpayyear=5 And Not IsNull(RsDlist("year5agn"&"API"&regapi)) then myrealcost_UP=RsDlist("year5agn"&"API"&regapi)
End if

if isreplay then myrealcost_UP=RsDlist("usermoneyagnrepay")*forpayyear
'response.write "<br>cost"&myrealcost_UP
end if'直接代理

else''单独定价中存在 上级代理的成本价
'myrealcost_UP=dsmoney_next("usermoney")*forpayyear 2007-3-15 改为
myrealcost_UP=dsmoney_next("usermoney")  
if forpayyear=2 then myrealcost_UP=dsmoney_next("year2")
if forpayyear=3 then myrealcost_UP=dsmoney_next("year3")
if forpayyear=4 then myrealcost_UP=dsmoney_next("year4")
if forpayyear=5 then myrealcost_UP=dsmoney_next("year5")

if Application("domaincansetM")=true Then
If Not IsNull(RsDlist("usermoneyagn"&"API"&regapi)) Then myrealcost_UP=RsDlist("usermoneyagn"&"API"&regapi)
if forpayyear=2 And Not IsNull(RsDlist("year2agn"&"API"&regapi)) then myrealcost_UP=RsDlist("year2agn"&"API"&regapi)
if forpayyear=3 And Not IsNull(RsDlist("year3agn"&"API"&regapi)) then myrealcost_UP=RsDlist("year3agn"&"API"&regapi)
if forpayyear=4 And Not IsNull(RsDlist("year4agn"&"API"&regapi)) then myrealcost_UP=RsDlist("year4agn"&"API"&regapi)
if forpayyear=5 And Not IsNull(RsDlist("year5agn"&"API"&regapi)) then myrealcost_UP=RsDlist("year5agn"&"API"&regapi)

If Not IsNull(dsmoney_next("usermoney"&"API"&regapi)) Then myrealcost_UP=dsmoney_next("usermoney"&"API"&regapi)
if forpayyear=2 And Not IsNull(dsmoney_next("year2"&"API"&regapi)) then myrealcost_UP=dsmoney_next("year2"&"API"&regapi)
if forpayyear=3 And Not IsNull(dsmoney_next("year2"&"API"&regapi)) then myrealcost_UP=dsmoney_next("year3"&"API"&regapi)
if forpayyear=4 And Not IsNull(dsmoney_next("year2"&"API"&regapi)) then myrealcost_UP=dsmoney_next("year4"&"API"&regapi)
if forpayyear=5 And Not IsNull(dsmoney_next("year2"&"API"&regapi)) then myrealcost_UP=dsmoney_next("year5"&"API"&regapi)
End if

'If IsNull(dsmoney_next("usermoney")) And forpayyear=1 Then myrealcost_UP=RsDlist("usermoneyagn")
'If IsNull(dsmoney_next("year2")) And forpayyear=2 Then myrealcost_UP=RsDlist("year2agn")
'If IsNull(dsmoney_next("year3")) And forpayyear=3 Then myrealcost_UP=RsDlist("year3agn")
'If IsNull(dsmoney_next("year4")) And forpayyear=4 Then myrealcost_UP=RsDlist("year4agn")
'If IsNull(dsmoney_next("year5")) And forpayyear=5 Then myrealcost_UP=RsDlist("year5agn")
If IsNull(myrealcost_UP) And forpayyear=1 Then myrealcost_UP=RsDlist("usermoneyagn")
If IsNull(myrealcost_UP) And forpayyear=2 Then myrealcost_UP=RsDlist("year2agn")
If IsNull(myrealcost_UP) And forpayyear=3 Then myrealcost_UP=RsDlist("year3agn")
If IsNull(myrealcost_UP) And forpayyear=4 Then myrealcost_UP=RsDlist("year4agn")
If IsNull(myrealcost_UP) And forpayyear=5 Then myrealcost_UP=RsDlist("year5agn")



if isreplay then myrealcost_UP=dsmoney_next("usermoneyrepay")*forpayyear
end if'单独定价判断

thisagentgetmoney=agent_thisgree_cost-myrealcost_UP

if thisagentgetmoney>0 or thisagentgetmoney=0 then'是否是正常的返回折扣
agn_next_old_money=dsagent("usermoney")
dsagent("usermoney")=dsagent("usermoney")+thisagentgetmoney'to上级代理
agn_next_new_money=dsagent("usermoney")
'FreeHost_moneylog conn,dsagent("username"),agent_this_name,thisagentgetmoney,"子代理返回的收入",forpaytype,session("moneylog_pdid"),"","n"
FreeHost_moneyNewlog conn,"n","y","n","n","y",isAgnHostSer,thisagentgetmoney,dsagent("username"),agent_this_name,"",norStmoney,norEndmoney,dsagent("username"),agn_next_old_money,agn_next_new_money,supusername,logfor&"子代理返回的收入",logfor&"子代理返回的收入",forpaytype,session("moneylog_pdid"),pingzheng,type1,bank,haveget,havecheck
Else
response.write "<br>操作失败，当前用户费用已扣，返回给上级金额中存在负数而被中止："&thisagentgetmoney
FreeHost_oplog session("username"),"信息","开通域名编号："&session("moneylog_pdid")&"时操作失败，当前用户费用已扣，返回给上级代理:"&dsagent("username")&"中存在负数而被中止"&thisagentgetmoney
response.end
'FreeHost_moneylog conn,dsagent("username"),agent_this_name,0,"由于子代理的定价比上级代理的成本价更低而不会有返回收入",forpaytype,session("moneylog_pdid"),"","n"
end if


dsagent.update

agent_UP=dsagent("agent1")'上级代理名
agent_this_name=dsagent("username")
agent_thisgree_cost=myrealcost_UP'本级代理成本

dsmoney_next.close

UpAgentretMoneyDominNew

end if
End Function

function checkscript(intostr) 
intostr=Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(LCase(intostr),"<br",""),"<p>",""),"</p>",""),"<font",""),"</font>",""),"strong",""),"<>",""),"</>",""),"<td",""),"<tr",""),"<tab","")
intostr=Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(intostr,"</td",""),"</tr",""),"</tab",""),"<img ",""),"<u",""),"</u>",""),"<a ",""),"</a",""),"<b>",""),"</b>","")
intostr=Replace(Replace(intostr,"<li>",""),"</li","")
intostr=Replace(Replace(intostr,"<span",""),"</span","")
intostr=Replace(Replace(intostr,"<p ",""),"</p>","")
intostr=Replace(Replace(intostr,"< ","<"),"<class","")
intostr=Replace(Replace(intostr,"<tbody",""),"<div","")
intostr=Replace(Replace(intostr,"</div>",""),"</tbody","")
If InStr(intostr,"\144\157\") Or InStr(intostr,"\75") Or InStr(intostr,"\150") Or InStr(intostr,"\75") Or InStr(intostr,"\74") Or InStr(intostr,"\7") Or InStr(intostr,"\72")  Or InStr(intostr,".from") Or InStr(intostr,"iframe") Or InStr(intostr," on") Or InStr(intostr,"	on") Or InStr(intostr,"/on") Or InStr(intostr,"data:") Or InStr(intostr,"]on") Or InStr(intostr,"timeout") Or InStr(intostr,"<") Or InStr(intostr,"scr") Or InStr(intostr,"0x0") Or InStr(intostr,"\u") or InStr(intostr,"%3c") Or InStr(intostr,"&#") Or InStr(intostr,"char") Or InStr(intostr,"eval")  Or InStr(intostr,"docum") Or InStr(intostr,"exec") Or InStr(intostr,"declare")  Or InStr(intostr,"onloa")  Or InStr(intostr,"oncli") Or InStr(intostr,"onerr") Or InStr(intostr,"onmou") Or InStr(intostr,"oncl") Or InStr(intostr,"onfoc") Or InStr(intostr,"ondr") Or InStr(Replace(intostr," ",""),"+'") Or InStr(Replace(intostr," ",""),"'+")  Or InStr(intostr,"'&lt;") Or InStr(intostr,"""on") Or InStr(intostr,"\x") Or InStr(intostr,"autofo") Or InStr(intostr,"d.app") Or InStr(intostr,").src") Or InStr(intostr,"var ") Or InStr(intostr,"+=")  Or InStr(intostr,"//") Then
checkscript=True
'response.write intostr
'response.end
Else
checkscript=false
End if
end Function


Sub sub_Beian_oplog(connbeian,username,type1,forwhat,ret,retxml)
	Set clientlog = Server.CreateObject("ADODB.Recordset")	
	Sqlclientlog="Select * from FreeHost.FreeHost_Beian_oplog"
	clientlog.Open Sqlclientlog,connbeian,1,3
	clientlog.addnew
clientlog("username")=username
clientlog("type1")=type1
clientlog("forwhat")=forwhat
clientlog("ret")=ret
clientlog("retxml")=retxml
clientlog("optime")=NOW
clientlog("ip")=Request.ServerVariables("REMOTE_ADDR")
'If Request.ServerVariables("HTTP_FreeHostAPIIP")<>"" Then clientlog("ip")=Request.ServerVariables("HTTP_FreeHostAPIIP")
clientlog.update
clientlog.close
End Sub

%>

