<%
function countPercentages(conn, poll_id)
	dim sum
	sum =  (Cint(getAnswerPercent(conn, poll_id, "phit_que1")) + _
			Cint(getAnswerPercent(conn, poll_id, "phit_que2")) + _
			Cint(getAnswerPercent(conn, poll_id, "phit_que3")) + _
			Cint(getAnswerPercent(conn, poll_id, "phit_que4")) )
			
	sum = 100 - sum
	countPercentages = sum
end function

function getPollTitle(conn, order)
	dim strsql
	strsql = "SELECT TOP 2 * FROM Polls ORDER BY poll_datecreated DESC"

	dim objRS
	set objRS = server.createobject("ADODB.Recordset")
	objRS.open strsql, conn

	If order="previous" then
		objRS.Movenext
	End If
	
	set getPollTitle = objRS
end function

function getPollDetails(conn, poll_id)
	dim strsql
	strsql = "SELECT * FROM PollQuestions WHERE poll_id=" & poll_id

	dim objRS
	set objRS = server.createobject("ADODB.Recordset")
	objRS.open strsql, conn

	set getPollDetails = objRS
end function

function getAnswerPercent(conn, poll_id, returnField)
	dim strsql
	strsql = "SELECT * FROM PollHits WHERE poll_id=" & poll_id

	dim objRS
	set objRS = server.createobject("ADODB.Recordset")
	objRS.open strsql, conn
	
	dim CurrentPercent
	
	If (getTotalHits(conn, poll_id)) = 0 Then
		CurrentPercent = 0
	Else
		CurrentPercent = Cint((CInt(objRS(returnField))/getTotalHits(conn, poll_id))*100)
	End If
	
	getAnswerPercent = CurrentPercent
end function

function getTotalHits(conn, poll_id)
	dim strsql
	strsql = "SELECT * FROM PollHits WHERE poll_id=" & poll_id

	dim objRS
	set objRS = server.createobject("ADODB.Recordset")
	objRS.open strsql, conn
	
	dim TotalHits
	TotalHits = Cint(objRS("phit_que1")) + Cint(objRS("phit_que2")) + Cint(objRS("phit_que3")) + Cint(objRS("phit_que4"))
	
	getTotalHits = TotalHits
end function

function imgColor(conn, poll_id, returnField)
	dim strsql
	strsql = "SELECT * FROM PollHits WHERE poll_id=" & poll_id

	dim objRS
	set objRS = server.createobject("ADODB.Recordset")
	objRS.open strsql, conn
	
	dim queHits
	queHits = CInt(objRS(returnField))
	
	dim Flag
	Flag=true
	
		select case returnField
			case "phit_que1"
				If 	(queHits < CInt(objRS("phit_que2"))) OR (queHits < CInt(objRS("phit_que3"))) OR (queHits < CInt(objRS("phit_que4"))) Then
					Flag = false
				End If
			case "phit_que2"
				If 	(queHits < CInt(objRS("phit_que1"))) OR (queHits < CInt(objRS("phit_que3"))) OR (queHits < CInt(objRS("phit_que4"))) Then
					Flag = false
				End If
			case "phit_que3"
				If 	(queHits < CInt(objRS("phit_que1"))) OR (queHits < CInt(objRS("phit_que2"))) OR (queHits < CInt(objRS("phit_que4"))) Then
					Flag = false
				End If
			case "phit_que4"
				If 	(queHits < CInt(objRS("phit_que1"))) OR (queHits < CInt(objRS("phit_que2"))) OR (queHits < CInt(objRS("phit_que3"))) Then
					Flag = false
				End If
		end select
		
	If Flag=true Then
		imgColor = "pa_GRAPHBAR_IMAGE_HIGH"
	End If
	
	If Flag=false Then
		imgColor = "pa_GRAPHBAR_IMAGE_LOW"
	End If
	
end function
%>