<%
Function DisplayVoteForm(AnnounceID,VoteFlag)

	If LMT_TopicTitleStyle >= 60 Then Exit Function
	Dim Rs,SQL
	
	SQL = "Select top " & DEF_VOTE_MaxNum & " ID,AnnounceID,VoteName,VoteNum,VoteType,ExpiresTime from LeadBBS_VoteItem where AnnounceID=" & AnnounceID
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	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 Article_NotReplay = 0 Then		
		If cCur(GetData(5,0)) = 0 or cCur(GetData(5,0)) > GetTimeValue(DEF_Now) Then
			SQL = "select top 1 ID from LeadBBS_VoteUser where AnnounceID=" & AnnounceID & " and UserName='" & Replace(GBL_CHK_User,"'","''") & "'"
			Set Rs = Con.ExeCute(SQL)
			GBL_DBNum = GBL_DBNum + 1
			If Not Rs.Eof Then
				Rs.Close
				Set Rs = Nothing
				DisplayPollResult 150,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 150,AnnounceID,"你已经投过票，投票结果如下",GetData
					Else
						If PollOneTicketRadio(GetData) = 1 Then DisplayPollResult 150,AnnounceID,"你已经投过票，投票结果如下",GetData
					End If
				Else
					DisplayPollForm 550,400,GetData
					If CheckSupervisorUserName = 1 and GBL_UserID > 0 Then DisplayPollResult 150,AnnounceID,"您是管理员，投票结果如下",GetData
				End If
			End If
		Else
			DisplayPollResult 150,AnnounceID,"投票已经过期，投票结果如下",GetData
		End If
	Else
		DisplayPollResult 150,AnnounceID,"帖子已经锁定，投票结果如下",GetData
	End If

End Function

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

	Dim ItemNum
	'Response.Write "	<center><font color=000088 class=BlueFont><b>" & HtmlEncode(LMT_TopicName) & "</b></font></center><br>" & VbCrLf
	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><tr><td colspan=3><b>" & TmpStr & "</b>[<a href=#dk onclick='window.open(" & chr(34) & "PollUser.asp?BoardID=" & GBL_board_ID & "&PollTitleID=" & GetData(1,0) & chr(34) & "," & chr(34) & chr(34) & "," & chr(34) & "width=450,height=400 scrollbars=yes" & chr(34) & ");'>投票人</a>]<hr size=1></td></tr>" & VbCrLf
		For TempN = 0 To ItemNum
			Response.Write "	<tr>" & VbCrLf
			Response.Write "		<td align=left>" & TempN + 1 & ". " & HtmlEncode(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 = Temp3 * IMGWidth
                        If Temp2 > 0 and Temp2 < 1 then
                        	Temp2 = 1
                        End If
                        Response.Write "		<td>"
                        'If temp2 > 0 then '当是0时是否显示图片
                        	Response.Write "&nbsp;<IMG height=9 src=" & DEF_BBS_HomeUrl & "images/vote.gif width=" & Temp2 & " align=absmiddle> "
                        'End If
                        'Response.Write "</td>" & VbCrLf
			'Response.Write "		<td>"
			If Temp1<0.01 Then
                        	If inStr(Temp1,"0.")<1 Then
                        		If temp2 <= 0 then
                        			Response.Write "&nbsp;0"
                        		Else
                        			Response.Write "0"
                        		End If
                        	End if
                        	Response.Write formatpercent(Temp1)
                        Else
                        	Response.Write formatpercent(Temp1)
                        End If
			Response.Write " (" & GetData(3,TempN) & "票)"
                        Response.Write "</td>" & VbCrLf
                        'Response.Write "		<td>&nbsp;" & GetData(3,TempN) & "票</td>" & VbCrLf
                        Response.Write "	</tr>" & VbCrLf
		Next
		Response.Write "	<tr><td colspan=3><hr size=1></td></tr></table>" & VbCrLf
	End If

End Function

Rem 显示某投票主题投票界面
Rem OpenWidth 投票结果窗口宽,OpenHeight 投票结果窗口高
Function DisplayPollForm(OpenWidth,OpenHeight,GetData)

	'Response.Write "	" & HtmlEncode(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 TempN
	%>
	<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;
			}
			window.open("PollResult.asp?BoardID=<%=GBL_board_ID%>&PollTitleID=<%=GetData(1,0)%>&SelectItemID=" + selitemstr,"","width=<%=OpenWidth%>,height=<%=OpenHeight%> scrollbars=yes");
			return true;
		}
	</script>
	<%
		Response.Write "	<table><tr><td colspan=3><b>先投票才能查看结果</b><hr size=1></td></tr><form name=PollForm" & GetData(1,0) & " id=PollForm" & GetData(1,0) & " onsubmit='return CheckPollFromZwle" & GetData(1,0) & "(this)' method=post><tr><td>" & VbCrLf
		Response.Write "	<input type=hidden name=PollTitleID value=" & GetData(1,0) & "><table width=100% border=0 height=0 cellpadding=0 cellspacing=0><tr><td>" & VbCrLf
		For TempN = 0 To ItemNum
			Response.Write "	<tr><td width=10><input type=" & TypeStr & " name=radios value=" & GetData(0,TempN) & " onclick='PollForm" & GetData(1,0) & "Value = " & GetData(0,TempN) & ";' class=fmchkbox>" & VbCrLf
			Response.Write "	<td>" & HtmlEncode(GetData(2,TempN)) & "<br></td></tr>" & VbCrLf
		Next
		Response.Write "	</table><table width=100% border=0 height=5 cellpadding=0 cellspacing=0><tr><td></td></tr></table>" & VbCrLf
		Response.Write "	<input type=button onclick='CheckPollFromZwle" & GetData(1,0) & "(this)' value='投 票' name=poll class=fmbtn>"
		'Response.Write "<img style='cursor:hand' border=0 src=" & DEF_BBS_HomeUrl & "images/pollResult.gif width=58 height=20 onclick='window.open(" & chr(34) & "PollResult.asp?BoardID=" & GBL_board_ID & "&PollTitleID=" & GetData(1,0) & "&SelectItemID=-1372795" & chr(34) & "," & chr(34) & chr(34) & "," & chr(34) & "width=" & OpenWidth & ",height=" & OpenHeight & " scrollbars=yes" & chr(34) & ");'>"
		Response.Write "	</td></tr></form><tr><td colspan=3><hr size=1></td></tr></table>" & VbCrLf
	End If

End Function

Rem 投一票
Function PollOneTicketRadio(GetData)

	If GBL_CHK_User = "" Then
		Response.Write "先登录才能投票"
		Exit function
	End If
	If CheckUserAnnounceLimit = 0 Then
		Response.Write GBL_CHK_TempStr
		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
		PollOneTicketRadio = 0
		Exit Function
	End If

	PollTitleID = cCur(PollTitleID)
	SelectItemID = cCur(SelectItemID)

	Con.Execute ("Update LeadBBS_VoteItem Set VoteNum=VoteNum+1 where AnnounceID=" & PollTitleID & " and ID=" & SelectItemID)
	Con.Execute ("insert into LeadBBS_VoteUser(UserName,VoteItem,AnnounceID) values('" & Replace(GBL_CHK_User,"'","''") & "','" & Replace(SelectItemID,"'","''") & "'," & PollTitleID & ")")
	Con.Execute ("Update LeadBBS_Announce Set PollNum=PollNum+1 where ID=" & PollTitleID)
	Con.Execute ("Update LeadBBS_Topic Set PollNum=PollNum+1 where ID=" & PollTitleID)
	If inStr(application(DEF_MasterCookies & "TopAncList"),"," & PollTitleID & ",") Then
		UpdateAnnounceApplicationInfo PollTitleID,15,1,1,0
	Else
		If inStr(application(DEF_MasterCookies & "TopAncList" & GBL_Board_BoardAssort),"," & PollTitleID & ",") Then UpdateAnnounceApplicationInfo PollTitleID,15,1,1,GBL_Board_BoardAssort
	End If
	
	GBL_DBNum = GBL_DBNum + 3
	If DEF_EnableMakeTopAnc = 1 Then MakeAnnounceTop(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 GBL_CHK_User = "" Then
		Response.Write "先登录才能投票"
		Exit Function
	End If
	
	If CheckUserAnnounceLimit = 0 Then
		Response.Write GBL_CHK_TempStr
		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)

	Con.Execute ("Update LeadBBS_VoteItem Set VoteNum=VoteNum+1 where AnnounceID=" & PollTitleID & " and ID in(" & SelectItemID & ")")
	Con.Execute ("insert into LeadBBS_VoteUser(UserName,VoteItem,AnnounceID) values('" & Replace(GBL_CHK_User,"'","''") & "','" & Replace(Left(SelectItemID,255),"'","''") & "'," & PollTitleID & ")")
	Con.Execute ("Update LeadBBS_Announce Set PollNum=PollNum+1 where ID=" & PollTitleID)
	Con.Execute ("Update LeadBBS_Topic Set PollNum=PollNum+1 where ID=" & PollTitleID)
	If inStr(application(DEF_MasterCookies & "TopAncList"),"," & PollTitleID & ",") Then
		UpdateAnnounceApplicationInfo PollTitleID,15,1,1,0
	Else
		If inStr(application(DEF_MasterCookies & "TopAncList" & GBL_Board_BoardAssort),"," & PollTitleID & ",") Then UpdateAnnounceApplicationInfo PollTitleID,15,1,1,GBL_Board_BoardAssort
	End If
	GBL_DBNum = GBL_DBNum + 3
	If DEF_EnableMakeTopAnc = 1 Then MakeAnnounceTop(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%>