<%
Function DisplayVoteForm(AnnounceID,VoteFlag)

	If isVote < 1000 Then Exit Function
	Dim Rs,SQL
	
	SQL = "Select top " & DEF_VOTE_MaxNum & " ID,AnnounceID,VoteName,VoteNum,VoteType,ExpiresTime from VoteItem where AnnounceID=" & AnnounceID
	Set Rs = conn.ExeCute(SQL)
	If Rs.Eof Then
		Rs.Close
		Set Rs = Nothing
		Exit Function
	End If

	Dim GetData
	GetData = Rs.GetRows(DEF_VOTE_MaxNum)
	Rs.Close
	Set Rs = Nothing
	If suo = 0 Then
		If cCur(GetData(5,0)) = 0 or cCur(GetData(5,0)) > GetTimeValue(now()) Then
			SQL = "select top 1 ID from VoteUser where AnnounceID=" & AnnounceID & " and UserName='" & replace(Request.Cookies(my_url)("huiyuan"),"'","''") & "'"
			Set Rs = conn.ExeCute(SQL)
			
			If Not Rs.Eof Then
				Rs.Close
				Set Rs = Nothing
				DisplayPollResult 0.8,AnnounceID,"你已经投过票，投票结果如下",GetData
			Else
				Rs.Close
				Set Rs = Nothing
				If VoteFlag = 1 Then
					If GetData(4,0) = 1 or GetData(4,0) = True Then
						If PollOneTicketCheckbox(GetData) = 1 Then DisplayPollResult 0.8,AnnounceID,"你已经投过票，投票结果如下",GetData
					Else
						If PollOneTicketRadio(GetData) = 1 Then DisplayPollResult 0.8,AnnounceID,"你已经投过票，投票结果如下",GetData
					End If
				Else
					DisplayPollForm 0.8,GetData
				End If
			End If
		Else
			DisplayPollResult 0.8,AnnounceID,"投票已经过期，投票结果如下",GetData
		End If
	Else
		DisplayPollResult 0.8,AnnounceID,"帖子已经锁定，投票结果如下",GetData
	End If

End Function

Function htmlEncode_m(str)

	If str & "" <> "" Then
		htmlEncode_m=Replace(Replace(Replace(str,">","&gt;"),"<","&lt;"),"""","&quot;")
	Else
		htmlEncode_m=str
	End If

End Function

Rem 显示某投票主题当前投票结果
Function DisplayPollResult(IMGWidth,AnnounceID,TmpStr,GetData)

	Dim ItemNum
	ItemNum = Ubound(GetData,2)
	If ItemNum >= 0 Then
		Dim Temp1,Temp2,ZPollNum,MaxNum,Temp3
		Dim TempN
		ZPollNum = 0
		MaxNum = 0
		For TempN = 0 to ItemNum
			ZPollNum = ZPollNum + Clng(GetData(3,TempN))
			If MaxNum < Clng(GetData(3,TempN)) Then
				MaxNum = Clng(GetData(3,TempN))
			End If
		Next

		Response.Write"<table width=98% border=0 align=center cellpadding=2 cellspacing=1 bgcolor=#CCCCCC><tr valign=middle><td height=28 colspan=2 background=skins/bg_bj.gif bgcolor=#f7f7f7><font color=#FFFFFF><b>&nbsp;&nbsp;投票：" & bt & " </b></font></td></tr>"
		For TempN = 0 To ItemNum
			Response.Write "	<tr valign=middle>" & VbCrLf
			Response.Write "		<td height=25 bgcolor=#ffffff>&nbsp;" & TempN + 1 & ". " & htmlEncode_m(GetData(2,TempN)) & "</td>" & VbCrLf
			If ZPollNum = 0 Then
				Temp1 = 0
				Temp3 = 0
			Else
				Temp1 = CLng(GetData(3,TempN))/ZPollNum
				Temp3 = CLng(GetData(3,TempN))/MaxNum
			End If
			Temp2 = Temp1 * IMGWidth * 100
                        If Temp2 > 0 and Temp2 < 1 then
                        	Temp2 = 1
                        End If
                        Response.Write "		<td width=60% bgcolor=#ffffff>"
                        	Response.Write "&nbsp;<IMG height=8 src=image/bar" & TempN + 1 & ".gif width=" & Temp2 & "% align=absmiddle> <b>"
						Response.Write "" & GetData(3,TempN) & "</b>票"
                        Response.Write "</td>" & VbCrLf
                        Response.Write "	</tr>" & VbCrLf
		Next
		Response.Write"<tr valign=middle bgcolor=#f7f7f7><td height=28 colspan=2 bgcolor=#f1f1f1>&nbsp;" & TmpStr & "&nbsp;[本投票限制会员需要拥有K币<b> 0 </b>元以上，等级 <b>0 </b>级以上。过期时间：2106-2-19 16:46:44 | <a href=# onClick=""javascript:window.open('vote_huiyuan.asp?id="&AnnounceID&"','','toolbar=no,scrollbars=yes,resizable=yes,width=550,height=400')"">查看投票会员</a>]</td></tr></table><table width=98% border=0 align=center cellpadding=0 cellspacing=0><tr><td height=5></td></tr></table>"
	End If

End Function

Rem 显示某投票主题投票界面
Function DisplayPollForm(IMGWidth,GetData)

	'Response.Write "	" & htmlEncode_m(LMT_TopicName) & "<br>" & VbCrLf
	Dim TypeStr
	If GetData(4,0) = 1 or GetData(4,0) = True Then
		TypeStr = "checkbox"
	Else
		TypeStr = "radio"
	End If
	Dim ItemNum
	ItemNum = Ubound(GetData,2)
	If ItemNum >= 0 Then
		Dim Temp1,Temp2,ZPollNum,MaxNum,Temp3
		Dim TempN
		ZPollNum = 0
		MaxNum = 0
		For TempN = 0 to ItemNum
			ZPollNum = ZPollNum + Clng(GetData(3,TempN))
			If MaxNum < Clng(GetData(3,TempN)) Then
				MaxNum = Clng(GetData(3,TempN))
			End If
		Next
	%>
	<script language=javascript>
		var PollForm<%=GetData(1,0)%>Value = -1;
		function CheckPollFromZwle<%=GetData(1,0)%>(obj)
		{
			var selitemstr = "";
			for (var i=0;i<PollForm<%=GetData(1,0)%>.elements.length;i++)
			{
				var e = document.PollForm<%=GetData(1,0)%>.elements[i];
				if(e.checked)selitemstr = selitemstr + "," + e.value
			}
			if (selitemstr=="")
			{
				alert("投票请先选择!");
				return false;
			}
			var act= document.PollForm<%=GetData(1,0)%>.action;
			act = act.replace("GetSelectItem", selitemstr);
			document.PollForm<%=GetData(1,0)%>.action = act;
			return true;
		}
	</script>
	<%
		Response.Write"<table width=98% border=0 align=center cellpadding=2 cellspacing=1 bgcolor=#CCCCCC><form name=PollForm" & GetData(1,0) & " id=PollForm" & GetData(1,0) & " action=?lbid="&request("lbid")&"&id="&request("id")&"&page="&page&"&abc=vote&SelectItemID=GetSelectItem onsubmit='return CheckPollFromZwle" & GetData(1,0) & "(this)' method=post><tr valign=middle><td height=28 colspan=2 background=skins/bg_bj.gif bgcolor=#f7f7f7><font color=#FFFFFF><b>&nbsp;&nbsp;投票：" & bt & " </b></font>"
		Response.Write "	<input type=hidden name=PollTitleID value=" & GetData(1,0) & "></td></tr>" & VbCrLf
		For TempN = 0 To ItemNum
			Response.Write "	<tr valign=middle>" & VbCrLf
			Response.Write "		<td height=25 bgcolor=#ffffff>&nbsp;" & TempN + 1 & ".<input type=" & TypeStr & " name=radios value=" & GetData(0,TempN) & " onclick='PollForm" & GetData(1,0) & "Value = " & GetData(0,TempN) & ";' class=fmchkbox>" & htmlEncode_m(GetData(2,TempN)) & "</td>" & VbCrLf
			If ZPollNum = 0 Then
				Temp1 = 0
				Temp3 = 0
			Else
				Temp1 = CLng(GetData(3,TempN))/ZPollNum
				Temp3 = CLng(GetData(3,TempN))/MaxNum
			End If
			Temp2 = Temp1 * IMGWidth * 100
                        If Temp2 > 0 and Temp2 < 1 then
                        	Temp2 = 1
                        End If
                        Response.Write "		<td width=60% bgcolor=#ffffff>"
                        	Response.Write "&nbsp;<IMG height=8 src=image/bar" & TempN + 1 & ".gif width=" & Temp2 & "% align=absmiddle> <b>"
						Response.Write "" & GetData(3,TempN) & "</b>票"
                        Response.Write "</td>" & VbCrLf
                        Response.Write "	</tr>" & VbCrLf
		Next
		Response.Write"<tr valign=middle bgcolor=#f7f7f7><td height=28 colspan=2 bgcolor=#f1f1f1>&nbsp;<input type=submit name=submit value=投上一票 class=go-wenbenkuang>&nbsp;[本投票限制会员需要拥有K币<b> 0 </b>元以上，等级 <b>0 </b>级以上。过期时间：2106-2-19 16:46:44 | <a href=# onClick=""javascript:window.open('vote_huiyuan.asp?id="&GetData(1,0)&"','','toolbar=no,scrollbars=yes,resizable=yes,width=550,height=400')"">查看投票会员</a>]</td></tr></form></table><table width=98% border=0 align=center cellpadding=0 cellspacing=0><tr><td height=5></td></tr></table>"
	End If

End Function

Rem 投一票
Function PollOneTicketRadio(GetData)
	If replace(Request.Cookies(my_url)("huiyuan"),"'","''") = "" Then
		Response.Write "　先登录才能投票"
		Exit function
	End If

	PollTitleID = Left(Request("PollTitleID"),14)
	SelectItemID = Left(Request("SelectItemID"),14)
	SelectItemID = Replace(SelectItemID,",","")

	If PollTitleID = "" or inStr(PollTitleID,",")>0 or isNumeric(PollTitleID) = 0 Then
		PollOneTicketRadio = 0
		Exit Function
	End If

	If SelectItemID = "" or inStr(SelectItemID,",")>0 or isNumeric(SelectItemID) = 0 Then
		response.write "****#"&SelectItemID
		PollOneTicketRadio = 0
		Exit Function
	End If
	PollTitleID = cCur(PollTitleID)
	SelectItemID = cCur(SelectItemID)

	conn.Execute ("Update VoteItem Set VoteNum=VoteNum+1 where AnnounceID=" & PollTitleID & " and ID=" & SelectItemID)
	conn.Execute ("insert into VoteUser(UserName,VoteItem,AnnounceID) values('" & replace(Request.Cookies(my_url)("huiyuan"),"'","''") & "','" & Replace(SelectItemID,"'","''") & "'," & PollTitleID & ")")

	Dim N
	For n = 0 to Ubound(GetData,2)
		If cCur(GetData(0,n)) = SelectItemID Then
			GetData(3,n) = cCur(GetData(3,n)) + 1
			Exit For
		End If
	Next
	PollOneTicketRadio = 1

End Function

Rem 投多票
Function PollOneTicketCheckbox(GetData)

	If replace(Request.Cookies(my_url)("huiyuan"),"'","''") = "" Then
		Response.Write "　先登录才能投票"
		Exit Function
	End If
	
	PollTitleID = Left(Request("PollTitleID"),14)
	SelectItemID = Request("SelectItemID")
	If Left(SelectItemID,1) = "," Then SelectItemID = Mid(SelectItemID,2)
	
	If PollTitleID = "" or inStr(PollTitleID,",")>0 or isNumeric(PollTitleID) = 0 Then
		PollOneTicketCheckbox = 0
		Exit Function
	End If
	
	If SelectItemID = "" Then
		PollOneTicketCheckbox = 0
		Exit Function
	End If
	
	Dim TA,N
	TA = Split(SelectItemID,",")
	SelectItemID = ""
	For N = 0 to Ubound(TA,1)
		If isNumeric(TA(N)) = 0 Then
			PollOneTicketCheckbox = 0
			Exit Function
		Else
			If N = 0 Then
				SelectItemID = Left(TA(0),14)
			Else
				SelectItemID = SelectItemID & "," & Left(TA(N),14)
			End if
		End If
	Next

	PollTitleID = cCur(PollTitleID)

	conn.Execute ("Update VoteItem Set VoteNum=VoteNum+1 where AnnounceID=" & PollTitleID & " and ID in(" & SelectItemID & ")")
	conn.Execute ("insert into VoteUser(UserName,VoteItem,AnnounceID) values('" & replace(Request.Cookies(my_url)("huiyuan"),"'","''") & "','" & Replace(Left(SelectItemID,255),"'","''") & "'," & PollTitleID & ")")

	SelectItemID = "," & SelectItemID & ","
	For n = 0 to Ubound(GetData,2)
		If inStr(SelectItemID,cCur(GetData(0,n))) Then
			GetData(3,n) = cCur(GetData(3,n)) + 1
		End If
	Next
	PollOneTicketCheckbox = 1

End Function%>