<!--#include file="conn.asp"-->
<!--#include file="inc/const.asp" -->
<!--#include file="inc/plus_check.asp"-->
<!--#include file="Dv_Plus/Avatar/Plus_Avatar_Const.asp"-->
<%
Dim UserName, UserSex, Action, Rs, ToolByUser, UserAvaSetting, CurPage
Dim ItemID, ItemName, ItemPeriod, ItemLayer, ItemSex, ItemPrice, ToolDays, RetPeriod
Dim RetFlag, nPos, UserAvatarSplit, i, Fee1, Fee2, Fee3
Dim AvatarFlag

Dv_Plus.Name = "Plus_Avatar"
Dv_Plus.CheckLogin
Dvbbs.LoadTemplates "Avatar"
Dvbbs.Stats = Template.Strings(41)
Dvbbs.ActiveOnline
v_FoundErr = False
If Dvbbs.Forum_Setting(82) <> "0" Then
	v_ErrCodes = "<li>该论坛尚未开启虚拟形象功能，不能使用整人道具！"
	v_FoundErr = True
	RetFlag = False
ElseIf Trim(Request("UserName")) <> "" Then
	UserName = Dvbbs.CheckStr(Trim(Request("UserName")))
	If LCase(Trim(UserName)) = LCase(Trim(Dvbbs.MemberName)) Then
		If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
		v_ErrCodes = v_ErrCodes & "<li>不能对自己使用整人道具！"
		v_FoundErr = True
		RetFlag = False
	Else
		Set Rs = Dvbbs.Execute("Select Top 1 UserAvaSetting, UserSex From Dv_User Where UserName='" & UserName & "'")
		If Rs.Eof Then
			If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
			v_ErrCodes = v_ErrCodes & "<li>该用户不存在，无法对其使用整人道具！"
			v_FoundErr = True
			RetFlag = False
		Else
			If Rs(0) <> "" And Not IsNull(Rs(0)) Then
				If InStr(Rs(0), ",") > 0 Then
					ToolByUser = Split(Rs(0), ",")(1)
					If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
					v_ErrCodes = v_ErrCodes & "<li>用户<font color=blue>" & UserName & "</font>正在被<b>" & ToolByUser & "</b>使用整人道具，无法追加使用！"
					v_FoundErr = True
					RetFlag = False
				End If
			End If
			If Not v_FoundErr Then
				UserAvaSetting = Rs(0)
				UserSex = Rs(1)
				AvatarFlag = True
				If IsNull(UserAvaSetting) Or UserAvaSetting = "" Then
					AvatarFlag = False
				ElseIf UBound(Split(UserAvaSetting, "|")) <> 24 Then
					AvatarFlag = False
				Else
					UserAvaSetting = Replace(UserAvaSetting, Chr(13), "")
				End If
				If Not AvatarFlag Then
					If UserSex = "1" Then
						UserAvaSetting = DefaultAvatarBoy
					Else
						UserAvaSetting = DefaultAvatarGirl
					End If
				End If
			End If
		End If
		Rs.Close
	End If
	If Request("Action") <> "" And Not v_FoundErr Then
		ItemID = Trim(Request("ItemID"))
		If ItemID = "" Then
			If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
			v_ErrCodes = v_ErrCodes & "<li>尚未选择要使用的整人道具！"
			v_FoundErr = True
			RetFlag = True
		ElseIf Not IsInteger(ItemID) Then
			If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
			v_ErrCodes = v_ErrCodes & "<li>提交的数据有错误！"
			v_FoundErr = True
			RetFlag = False
		Else
			ItemID = CLng(ItemID)
			Set Rs = Dvbbs.Plus_Execute("Select Top 1 Name,Class,Sex,Content From Dv_Plus_Avatar_Items Where ID=" & ItemID)
			IF Rs.Eof Then
				If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
				v_ErrCodes = v_ErrCodes & "<li>该道具不存在！"
				v_FoundErr = True
				RetFlag = False
			Else
				ItemName = Rs(0)
				ItemLayer = Rs(3)
				If Rs(1) <> 6 Then
					If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
					v_ErrCodes = v_ErrCodes & "<li>商品《" & ItemName & "》不是整人道具，无法使用！"
					v_FoundErr = True
					RetFlag = False
				ElseIf Rs(2) <> 2 And Rs(2) <> UserSex Then
					If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
					v_ErrCodes = v_ErrCodes & "<li>道具《" & ItemName & "》与用户<b>" & UserName & "</b>的性别不符，无法使用！"
					v_FoundErr = True
					RetFlag = False
				End If
			End If
			Rs.Close
			If Not v_FoundErr Then
				If InStr("|" & v_MyAvatar, "|" & ItemID & ".") > 0 Then
					If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
					v_ErrCodes = v_ErrCodes & "<li>不能使用正在自己身上发生作用的道具《" & ItemName & "》！"
					v_FoundErr = True
					RetFlag = False
				Else
					Set Rs = Dvbbs.Plus_Execute("Select Top 1 Period,FixDate,Type From Dv_Plus_Avatar_MyItems Where ItemID=" & ItemID & " And UserName='" & Dvbbs.MemberName & "'")
					If Rs.Eof Then
						If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
						v_ErrCodes = v_ErrCodes & "<li>您尚未拥有道具《" & ItemName & "》，无法使用！"
						v_FoundErr = True
						RetFlag = False
					ElseIf (Rs(0) > 0 And DateDiff("d", Rs(1), Now()) >= Rs(0)) Or Rs(2) = 0 Then
						If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
						v_ErrCodes = v_ErrCodes & "<li>道具《" & ItemName & "》已经过期，翻新后才能使用！"
						v_FoundErr = True
						RetFlag = False
					ElseIf Rs(2) = 5 Then
						If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
						v_ErrCodes = v_ErrCodes & "<li>道具《" & ItemName & "》正在二手市场出售，停售后才能使用！"
						v_FoundErr = True
						RetFlag = True
					End If
					If Not v_FoundErr Then
						If Rs(0) = 0 Then
							ItemPeriod = 0
						Else
							ItemPeriod = Rs(0) -  DateDiff("d", Rs(1), Now())
						End If
					End If
					Rs.Close
					Set Rs = Dvbbs.Plus_Execute("Select Top 1 ItemID From Dv_Plus_Avatar_MyItems Where UserName='" & UserName & "' And ItemID=" & ItemID)
					If Not Rs.Eof Then
						If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
						v_ErrCodes = v_ErrCodes & "<li>用户 " & UserName & " 已经对整人道具《" & ItemName & "》具有免疫能力，无法对其使用这个道具！"
						v_FoundErr = True
						RetFlag = True
					End If
				End If
			End If
		End If
		Action = "0"
	ElseIf Not v_FoundErr Then
		CurPage = Request("page")
		If CurPage = "" Or Not isInteger(CurPage) Then
			CurPage = 1
		Else
			CurPage = CLng(CurPage)
		End If
	End If
Else
	RetFlag = False
	UserSex = v_MySex
	Action = Request("Action")
	If v_ToolByUser = "" Then
		If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
		v_ErrCodes = v_ErrCodes & "<li>您没有被他人使用任何整人道具，无需"
		If Action = "1" Then
			v_ErrCodes = v_ErrCodes & "“破财消灾”！"
		ElseIf Action = "2" Then
			v_ErrCodes = v_ErrCodes & "“免留后患”！"
		Else
			v_ErrCodes = v_ErrCodes & "“以牙还牙”！"
		End If
		v_FoundErr = True
	Else
		If v_MyVip <> 1 Then
			Set Rs = Dvbbs.Plus_Execute("Select Top 1 i.ID,i.Name,i.Sex,i.Content,i.Price1,i.Period,m.Period,m.FixDate From Dv_Plus_Avatar_MyItems m Inner Join Dv_Plus_Avatar_Items i On m.ItemID=i.ID Where m.UserName='" & Dvbbs.MemberName & "' And m.FromUser='" & v_ToolByUser & "' And i.Class=6 And '|" & v_MyAvatar & "' Like " & SqlConcateString("'%|'", "m.ItemID", "'.%'"))
		Else
			Set Rs = Dvbbs.Plus_Execute("Select Top 1 i.ID,i.Name,i.Sex,i.Content,i.Price2,i.Period,m.Period,m.FixDate From Dv_Plus_Avatar_MyItems m Inner Join Dv_Plus_Avatar_Items i On m.ItemID=i.ID Where m.UserName='" & Dvbbs.MemberName & "' And m.FromUser='" & v_ToolByUser & "' And i.Class=6 And '|" & v_MyAvatar & "' Like " & SqlConcateString("'%|'", "m.ItemID", "'.%'"))
		End If
		If Rs.Eof Then
			If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
			v_ErrCodes = v_ErrCodes & "<li>提交的数据有错误！"
			v_FoundErr = True
		ElseIf Rs(6) > 0 And DateDiff("d", Rs(7), Now()) >= Rs(6) Then
			If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
			v_ErrCodes = v_ErrCodes & "<li>被使用的整人道具已经过期！"
			v_FoundErr = True
		Else
			ItemID = Rs(0)
			ItemName = Rs(1)
			ItemSex = Rs(2)
			ItemLayer = Rs(3)
			ItemPrice = Rs(4)
			ItemPeriod = Rs(5)
			If Rs(6) = 0 Then
				ToolDays = 0
			Else
				ToolDays = Rs(6) - DateDiff("d", Rs(7), Now())
			End If
			RetPeriod = Rs(6)
			If ToolDays = 0 Then
				If ItemPeriod = 0 Then
					Fee1 = ItemPrice
				Else
					Fee1 = Int(ItemPrice * CLng(AvatarXMLDOM.documentElement.selectSingleNode("AvatarInfo").Attributes.getNamedItem("FixForeverFeeTimes").Text) / ItemPeriod + 0.99)
				End If
				Fee2 = Fee1 + ItemPrice
				Fee3 = Fee2 + Fee1
			Else
				If ItemPeriod = 0 Then
					Fee1 = ItemPrice
					Fee2 = Fee1 + ItemPrice
					Fee3 = Fee2
				Else
					Fee1 = Int(ItemPrice * ToolDays / ItemPeriod + 0.99)
					Fee2 = Fee1 + ItemPrice
					Fee3 = Fee2 + Int(ItemPrice * (Rs(6) - ItemPeriod) / ItemPeriod + 0.99)
				End If
			End If
		End If
		Rs.Close
	End If
End If
If Not v_FoundErr Then
	If Request("Action") = "" Then
		Dvbbs.Head
		Call Main1
	Else
		If Action = "0" Then
			UserAvaSetting = TakeOnTool(UserAvaSetting, UserSex, ItemID, ItemLayer, Dvbbs.MemberName)
			Dvbbs.Execute ("Update Dv_User Set UserIsAva=1,UserAvaSetting='" & UserAvaSetting & "' Where UserName='" & UserName & "'")
			Dvbbs.Plus_Execute ("Update Dv_Plus_Avatar_MyItems Set UserName='" & UserName & "',FromUser='" & Dvbbs.MemberName & "',Type=6,AddDate='" & Date() & "',FixDate='" & Date() & "',Period=" & ItemPeriod & " Where UserName='" & Dvbbs.MemberName & "' And ItemID=" & ItemID)
			Dvbbs.Plus_Execute ("Delete From Dv_Plus_Avatar_Favorite Where ItemID=" & ItemID & " And UserName='" & UserName & "'")
			If ItemPeriod = 0 Then
				ItemPeriod = "永远有效"
			Else
				ItemPeriod = ItemPeriod & " 天"
			End If
			Call Dv_SendMsg(UserName, Dvbbs.Forum_Info(0), Template.Strings(42), Replace(Replace(Replace(Replace(Replace(Template.Strings(43),"\n",vbCrLf), "{$FromUser}", Dvbbs.MemberName), "{$ToolDate}", Date()), "{$ItemName}", ItemName), "{$ToolPeriod}", ItemPeriod))
			SucMsg = "<li>已经成功地向 <font color=blue>" & UserName & "</font> 使用了整人道具《" & ItemName & "》！"
			Call ShowSuc(SucMsg, False)
			Response.write "<script>if(window.opener) window.opener.document.execCommand('Refresh');</script>"
		ElseIf Action = "1" Then
			If Fee1 > v_MyMoney Then
				If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
				v_ErrCodes = v_ErrCodes & "<li>“破财消灾”需要现金 " & Fee1 & " 元，您的现金(" & v_MyMoney & " 元)不足，无法进行！"
				v_FoundErr = True
			Else
				If Request("Done") <> "" Then
					v_MyAvatar = TakeOffTool(v_MyAvatar, UserSex, ItemLayer)
					Call UpdateUserWealth(Dvbbs.MemberName, -Fee1)
					Dvbbs.Execute ("Update Dv_User Set UserAvaSetting='" & v_MyAvatar & "' Where UserName='" & Dvbbs.MemberName & "'")
					Dvbbs.Plus_Execute ("Delete From Dv_Plus_Avatar_MyItems Where UserName='" & Dvbbs.MemberName & "' And ItemID=" & ItemID)
					SucMsg = "<li>已经成功地消除了整人道具《" & ItemName & "》！"
					Call ShowSuc(SucMsg, False)
					Response.write "<script>" & vbCrLf
					Response.write "if(window.opener) {" & vbCrLf
					Response.write "window.opener.TakeOffTool('" & Dvbbs.UserID & "','" & v_MySex & "','" & ItemID & "','" & ItemLayer & "');" & vbCrLf
					Response.write "window.opener.document.execCommand('Refresh');" & vbCrLf
					Response.write "}" & vbCrLf
					Response.write "</script>" & vbCrLf
				Else
					Dvbbs.Head
					Call Main2
				End If
			End If
		ElseIf Action = "2" Then
			If Fee2 > v_MyMoney Then
				If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
				v_ErrCodes = v_ErrCodes & "<li>“免留后患”需要现金 " & Fee2 & " 元，您的现金(" & v_MyMoney & " 元)不足，无法进行！"
				v_FoundErr = True
			Else
				If Request("Done") <> "" Then
					v_MyAvatar = TakeOffTool(v_MyAvatar, UserSex, ItemLayer)
					Call UpdateUserWealth(Dvbbs.MemberName, -Fee2)
					Dvbbs.Execute ("Update Dv_User Set UserAvaSetting='" & v_MyAvatar & "' Where UserName='" & Dvbbs.MemberName & "'")
					Dvbbs.Plus_Execute ("Update Dv_Plus_Avatar_MyItems Set FromUser='" & Dvbbs.MemberName & "',Period=" & RetPeriod & ",AddDate='" & Date() & "',FixDate='" & Date() & "',Price=" & ItemPrice & ",Type=6 Where UserName='" & Dvbbs.MemberName & "' And ItemID=" & ItemID)
					SucMsg = "<li>已经成功地消除了整人道具《" & ItemName & "》，并同时具备了免疫能力！"
					Call ShowSuc(SucMsg, False)
					Response.write "<script>" & vbCrLf
					Response.write "if(window.opener) {" & vbCrLf
					Response.write "window.opener.TakeOffTool('" & Dvbbs.UserID & "','" & v_MySex & "','" & ItemID & "','" & ItemLayer & "');" & vbCrLf
					Response.write "window.opener.document.execCommand('Refresh');" & vbCrLf
					Response.write "}" & vbCrLf
					Response.write "</script>" & vbCrLf
				Else
					Dvbbs.Head
					Call Main3
				End If
			End If
		Else
			Set Rs = Dvbbs.Execute("Select Top 1 UserAvaSetting,UserSex From Dv_User Where UserName='" & v_ToolByUser & "'")
			If Rs.Eof Then
				If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
				v_ErrCodes = v_ErrCodes & "<li>对方用户<font color=blue>" & v_ToolByUser & "</font>不存在或已经删除，您无法进行“以牙还牙”！"
				v_FoundErr = True
			ElseIf Fee3 > v_MyMoney Then
				If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
				v_ErrCodes = v_ErrCodes & "<li>“以牙还牙”需要现金 " & Fee3 & " 元，您的现金(" & v_MyMoney & " 元)不足，无法进行！"
				v_FoundErr = True
			Else
				If Rs(0) <> "" And Not IsNull(Rs(0)) Then
					If InStr(Rs(0), ",") > 0 Then
						ToolByUser = Split(Rs(0), ",")(1)
						If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
						v_ErrCodes = v_ErrCodes & "<li>用户<font color=blue>" & v_ToolByUser & "</font>正在被<b>" & ToolByUser & "</b>使用整人道具，无法进行“以牙还牙”！"
						v_FoundErr = True
						RetFlag = False
					End If
				End If
				If Not v_FoundErr Then
					UserAvaSetting = Rs(0)
					UserName = v_ToolByUser
					UserSex = Rs(1)
					Set Rs = Dvbbs.Plus_Execute("Select Top 1 ItemID From Dv_Plus_Avatar_MyItems Where UserName='" & UserName & "' And ItemID=" & ItemID)
					If Not Rs.Eof Then
						If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
						v_ErrCodes = v_ErrCodes & "<li>用户 " & UserName & " 已经对整人道具《" & ItemName & "》具有免疫能力，无法对其“以牙还牙”！"
						v_FoundErr = True
						RetFlag = True
					End If
				End If
				If Not v_FoundErr Then
					AvatarFlag = True
					If IsNull(UserAvaSetting) Or UserAvaSetting = "" Then
						AvatarFlag = False
					ElseIf UBound(Split(UserAvaSetting, "|")) <> 24 Then
						AvatarFlag = False
					Else
						UserAvaSetting = Replace(UserAvaSetting, Chr(13), "")
					End If
					If Not AvatarFlag Then
						If UserSex = "1" Then
							UserAvaSetting = DefaultAvatarBoy
						Else
							UserAvaSetting = DefaultAvatarGirl
						End If
					End If
					UserAvaSetting = TakeOnTool(UserAvaSetting, UserSex, ItemID, ItemLayer, Dvbbs.MemberName)
					If Request("Done") <> "" Then
						v_MyAvatar = TakeOffTool(v_MyAvatar, UserSex, ItemLayer)
						Call UpdateUserWealth(Dvbbs.MemberName, -Fee3)
						Dvbbs.Execute ("Update Dv_User Set UserAvaSetting='" & v_MyAvatar & "' Where UserName='" & Dvbbs.MemberName & "'")
						Dvbbs.Execute ("Update Dv_User Set UserAvaSetting='" & UserAvaSetting & "' Where UserName='" & UserName & "'")
						Dvbbs.Plus_Execute ("Update Dv_Plus_Avatar_MyItems Set UserName='" & UserName & "',FromUser='" & Dvbbs.MemberName & "',Period=" & RetPeriod & ",AddDate='" & Date() & "',FixDate='" & Date() & "',Price=" & ItemPrice & ",Type=6 Where UserName='" & Dvbbs.MemberName & "' And ItemID=" & ItemID)
						If RetPeriod = 0 Then
							RetPeriod = "永远有效"
						Else
							RetPeriod = RetPeriod & " 天"
						End If
						Call Dv_SendMsg(UserName, Dvbbs.Forum_Info(0), Template.Strings(42), Replace(Replace(Replace(Replace(Replace(Template.Strings(44),"\n",vbCrLf), "{$FromUser}", Dvbbs.MemberName), "{$ToolDate}", Date()), "{$ItemName}", ItemName), "{$ToolPeriod}", RetPeriod))
						SucMsg = "<li>已经成功地消除了整人道具《" & ItemName & "》，并以同样的道具报复了整人者<font color=blue>" & UserName & "</font>！"
						Call ShowSuc(SucMsg, False)
						Response.write "<script>" & vbCrLf
						Response.write "if(window.opener) {" & vbCrLf
						Response.write "window.opener.TakeOffTool('" & Dvbbs.UserID & "','" & v_MySex & "','" & ItemID & "','" & ItemLayer & "');" & vbCrLf
						Response.write "window.opener.document.execCommand('Refresh');" & vbCrLf
						Response.write "}" & vbCrLf
						Response.write "</script>" & vbCrLf
					Else
						Dvbbs.Head
						Call Main4
					End If
				End If
			End If
		End If
	End If
End If
If v_FoundErr Then Call ShowErr(RetFlag)
Dvbbs.Footer
Set Dv_Plus = Nothing

Sub Main1()
	Dim i, TempStr, CurPic, Rs, CurPeriod, SQL, TotalRec, PageCount, ItemStr
	
	TempStr = Template.HTML(19)
	With AvatarXMLDOM.documentElement.selectSingleNode("AvatarInfo").Attributes
		TempStr = Replace(TempStr, "{$LocalPic}", .getNamedItem("LocalPic").Text)
		TempStr = Replace(TempStr, "{$PicPath}", .getNamedItem("PicPath").Text)
		TempStr = Replace(TempStr, "{$AvatarWidth}", .getNamedItem("AvatarWidth").Text)
		TempStr = Replace(TempStr, "{$AvatarHeight}", .getNamedItem("AvatarHeight").Text)
		TempStr = Replace(TempStr, "{$UserAvaSetting}", UserAvaSetting)
		TempStr = Replace(TempStr, "{$UserName}", UserName)
		TempStr = Replace(TempStr, "{$UserSex}", UserSex)
		TempStr = Replace(TempStr, "{$CurPage}", CurPage)
		SQL = "Select m.ItemID,i.Name,i.Sex,i.Content,m.Period,m.FixDate From Dv_Plus_Avatar_MyItems m Inner Join Dv_Plus_Avatar_Items i On i.ID=m.ItemID Where i.Class=6 And m.UserName='" & Dvbbs.MemberName & "' And '|" & v_MyAvatar & "' Not Like " & SqlConcateString("'%|'", "m.ItemID", "'.%'") & " Order By m.ID Desc"
		Set Rs = Server.CreateObject("ADODB.Recordset")
		If Cint(Dvbbs.Forum_Setting(92))=1 Then
			If Not IsObject(Plus_Conn) Then Plus_ConnectionDatabase
			Rs.Open SQL,Plus_Conn,1,1
		Else
			If Not IsObject(Conn) Then ConnectionDatabase
			Rs.Open SQL,Conn,1,1
		End If
		If Not Rs.EOF Then
			TotalRec = Rs.RecordCount
			TempStr = Replace(TempStr, "{$TotalRec}", TotalRec)
			If TotalRec Mod 6 = 0 Then
				PageCount = TotalRec \ 6
			Else
				PageCount = TotalRec \ 6 + 1
			End If
			If CurPage > PageCount Then CurPage = PageCount
			If CurPage < 1 Then CurPage = 1
			Rs.MoveFirst
			If CurPage > 1 Then
				Rs.Move (CurPage - 1) * 6
			End If
			SQL = Rs.GetRows(6)
			For i = 0 To UBound(SQL, 2)
				ItemStr = Template.html(20)
				ItemStr = Replace(ItemStr, "{$ItemID}", SQL(0, i))
				ItemStr = Replace(ItemStr, "{$ItemGender}", SQL(2, i))
				ItemStr = Replace(ItemStr, "{$ItemLayer}", SQL(3, i))
				CurPic = .getNamedItem("PicPath").text & GetPicURL(.getNamedItem("LocalPic").text, "0", SQL(0, i))
				ItemStr = Replace(ItemStr, "{$ItemPic}", CurPic)
				ItemStr = Replace(ItemStr, "{$SampleWidth}", .getNamedItem("SampleWidth").Text)
				ItemStr = Replace(ItemStr, "{$SampleHeight}", .getNamedItem("SampleHeight").Text)
				ItemStr = Replace(ItemStr, "{$ItemName}", SQL(1, i))
				If SQL(4, i) = 0 Then
					CurPeriod = "<font color=" & Dvbbs.MainSetting(1) & ">永远有效</font>"
					ItemStr = Replace(ItemStr, "{$ItemPeriod}", 0)
				Else
					If DateDiff("d", SQL(5, i), Now()) >= SQL(4, i) Then
						CurPeriod = "<font color=" & Dvbbs.MainSetting(1) & ">已经过期</font>"
						ItemStr = Replace(ItemStr, "{$ItemPeriod}", -1)
					Else
						CurPeriod = (SQL(4, i) - DateDiff("d", SQL(5, i), Now())) & " 天"
						ItemStr = Replace(ItemStr, "{$ItemPeriod}", 1)
					End If
				End If
				ItemStr = Replace(ItemStr, "{$ItemPeriodMsg}", CurPeriod)
				TempStr = Replace(TempStr, "{$Item" & (i + 1) & "}", ItemStr)
			Next
		Else
			TempStr = Replace(TempStr, "{$TotalRec}", 0)
		End If
		Do While i < 6
			ItemStr = Template.html(21)
			TempStr = Replace(TempStr, "{$Item" & (i + 1) & "}", ItemStr)
			i = i + 1
		Loop
		Rs.Close
		Set Rs = Nothing
	End With
	Response.Write TempStr
End Sub

Sub Main2()
	Dim TempStr
	
	TempStr = Template.HTML(22)
	TempStr = Replace(TempStr, "{$Fee1}", Fee1)
	TempStr = Replace(TempStr, "{$MyMoney}", v_MyMoney)
	TempStr = Replace(TempStr, "{$ItemName}", ItemName)
	If ToolDays > 0 Then
		TempStr = Replace(TempStr, "{$ToolDays}", "剩余有效期 <b>" & ToolDays & "</b> 天")
	Else
		TempStr = Replace(TempStr, "{$ToolDays}", "<font color=" & Dvbbs.MainSetting(1) & ">永远有效</font>")
	End If
	Response.Write TempStr
End Sub

Sub Main3()
	Dim TempStr
	
	TempStr = Template.HTML(23)
	TempStr = Replace(TempStr, "{$Fee2}", Fee2)
	TempStr = Replace(TempStr, "{$MyMoney}", v_MyMoney)
	TempStr = Replace(TempStr, "{$ItemName}", ItemName)
	If ToolDays > 0 Then
		TempStr = Replace(TempStr, "{$ToolDays}", "剩余有效期 <b>" & ToolDays & "</b> 天")
	Else
		TempStr = Replace(TempStr, "{$ToolDays}", "<font color=" & Dvbbs.MainSetting(1) & ">永远有效</font>")
	End If
	Response.Write TempStr
End Sub

Sub Main4()
	Dim TempStr
	
	TempStr = Template.HTML(24)
	TempStr = Replace(TempStr, "{$Fee3}", Fee3)
	TempStr = Replace(TempStr, "{$MyMoney}", v_MyMoney)
	TempStr = Replace(TempStr, "{$ItemName}", ItemName)
	If ToolDays > 0 Then
		TempStr = Replace(TempStr, "{$ToolDays}", "剩余有效期 <b>" & ToolDays & "</b> 天")
	Else
		TempStr = Replace(TempStr, "{$ToolDays}", "<font color=" & Dvbbs.MainSetting(1) & ">永远有效</font>")
	End If
	TempStr = Replace(TempStr, "{$UserName}", UserName)
	TempStr = Replace(TempStr, "{$UserAvaSetting}", UserAvaSetting)
	With AvatarXMLDOM.documentElement.selectSingleNode("AvatarInfo").Attributes
		TempStr = Replace(TempStr, "{$AvatarWidth}", .getNamedItem("AvatarWidth").Text)
		TempStr = Replace(TempStr, "{$AvatarHeight}", .getNamedItem("AvatarHeight").Text)
		TempStr = Replace(TempStr, "{$LocalPic}", .getNamedItem("LocalPic").Text)
		TempStr = Replace(TempStr, "{$PicPath}", .getNamedItem("PicPath").Text)
	End With
	If RetPeriod = 0 Then
		TempStr = Replace(TempStr, "{$RetPeriod}", "<font color=" & Dvbbs.MainSetting(1) & ">永远</font>")
	Else
		TempStr = Replace(TempStr, "{$RetPeriod}", "在以后的 <b>" & RetPeriod & "</b> 天内")
	End If
	Response.Write TempStr
End Sub

Sub TakeOnSingle(AvatarSplit, ItemID, ItemLayer, UserSex)
	If InStr(AvatarSplit(CInt(ItemLayer) - 1), "_") > 0 Then
		Call TakeOffMulti(AvatarSplit, Split(AvatarSplit(CInt(ItemLayer) - 1), ".")(1), UserSex)
	End If
	Call TakeLayer(AvatarSplit, ItemLayer, ItemID)
End Sub

Sub TakeOffSingle(AvatarSplit, ItemLayer, UserSex)
	Call SetGenderIMG(AvatarSplit, ItemLayer, UserSex)
End Sub

Sub TakeOnMulti(AvatarSplit, ItemID, LayerStr, UserSex)
	Dim LayerArray, i
	
	LayerArray = Split(LayerStr, "_")
	For i = 0 To UBound(LayerArray)
		Call TakeOnSingle(AvatarSplit, GetGenderItemID(UserSex, LayerArray(i)), LayerArray(i), UserSex)
	Next
	For i = 0 To UBound(LayerArray)
		Call TakeOnSingle(AvatarSplit, ItemID, LayerArray(i), UserSex)
	Next
End Sub

Sub TakeOffMulti(AvatarSplit, LayerStr, UserSex)
	Dim LayerArray, i
	
	LayerArray = Split(LayerStr, "_")
	For i = 0 To UBound(LayerArray)
		Call TakeOffSingle(AvatarSplit, LayerArray(i), UserSex)
	Next
End Sub

Sub SetGenderIMG(AvatarSplit, ItemLayer, UserSex)
	Call TakeLayer(AvatarSplit, ItemLayer, GetGenderItemID(UserSex, ItemLayer))
End Sub

Function GetGenderItemID(UserSex, ItemLayer)
	Dim ItemID
	
	If UserSex = "1" Then
		Select Case ItemLayer
		Case "7"
			ItemID = 14
		Case "8"
			ItemID = 13
		Case "9"
			ItemID = 12
		Case "11"
			ItemID = 11
		Case "13"
			ItemID = 10
		Case "14"
			ItemID = 9
		Case "18"
			ItemID = 8
		Case Else
			ItemID = -1
		End Select
	Else
		Select Case ItemLayer
		Case "7"
			ItemID = 7
		Case "8"
			ItemID = 6
		Case "9"
			ItemID = 5
		Case "11"
			ItemID = 4
		Case "13"
			ItemID = 3
		Case "14"
			ItemID = 2
		Case "18"
			ItemID = 1
		Case Else
			ItemID = -1
		End Select
	End If
	GetGenderItemID = ItemID
End Function

Sub TakeLayer(AvatarSplit, ItemLayer, ItemID)
	If ItemID = -1 Then
		AvatarSplit(CInt(ItemLayer) - 1) = ""
	Else
		AvatarSplit(CInt(ItemLayer) - 1) = ItemID & "." & ItemLayer
	End If
End Sub

Function TakeOnTool(AvatarStr, UserSex, ItemID, ItemLayer, ByUserName)
	Dim AvatarSplit, RetAvatar, i
	
	AvatarSplit = Split(AvatarStr, "|")
	If InStr(ItemLayer, "_") > 0 Then
		Call TakeOnMulti(AvatarSplit, ItemID, ItemLayer, UserSex)
	Else
		Call TakeOnSingle(AvatarSplit, ItemID, ItemLayer, UserSex)
	End If
	RetAvatar = ""
	For i = 0 To UBound(AvatarSplit)
		If i > 0 Then RetAvatar = RetAvatar & "|"
		RetAvatar = RetAvatar & AvatarSplit(i)
	Next
	RetAvatar = RetAvatar & "," & ByUserName
	TakeOnTool = RetAvatar
End Function

Function TakeOffTool(AvatarStr, UserSex, ItemLayers)
	Dim AvatarSplit, RetAvatar, i
	
	AvatarSplit = Split(AvatarStr, "|")
	If InStr(ItemLayer, "_") > 0 Then
		Call TakeOffMulti(AvatarSplit, ItemLayer, UserSex)
	Else
		Call TakeOffSingle(AvatarSplit, ItemLayer, UserSex)
	End If
	RetAvatar = ""
	For i = 0 To UBound(AvatarSplit)
		If i > 0 Then RetAvatar = RetAvatar & "|"
		RetAvatar = RetAvatar & AvatarSplit(i)
	Next
	TakeOffTool = RetAvatar
End Function
%>