<%
	'********************************************************************************
	'*																				*
	'*																				*
	'********************************************************************************
	Function SetupPagination( sSQLText, bResetTtlNumItems, bResetDBLoc )
	
		Dim rsCount
		
		Set rsCount = Server.CreateObject("ADODB.recordset")
	
		iTtlNumItems = CDbl(Request("iTtlNumItems"))
		If IsNull(Request("iDBLoc")) Or Trim(Request("iDBLoc"))="" Then
			iDBLoc = 0
		Else
			iDBLoc = CDbl(Request("iDBLoc"))
			If (iDBLoc<0) Then
				iDBLoc = 0
			End If
		End If
		
		' if, for example a user deletes 5 products, we need to 
		'	get an updated iTtlNumItems
		If ( bResetTtlNumItems ) Then
			iTtlNumItems = 0
		End If
		
		' if, for example a user deletes 5 products, we need to get an 
		'	updated iDBLoc in case they delete the last 5, we'd be EOF 
		'	if we didn't get a new iDBLoc
		If ( bResetDBLoc ) Then
			iDBLoc = 0
		End If
		
		' Get ttl num of items from the database if it's not already in the QueryString
		if (iTtlNumItems = 0) then
			'rsCount.Open sSQLText, dbStoreConnection, adOpenKeyset, adLockReadOnly, adCmdText
			Call DB_getFromDatabase(sSQLText, rsCount, "")
			If Not(rsCount.EOF) Then
				iTtlNumItems = rsCount(0)
			End If
			rsCount.Close
		End If

		iTtlNumItems	= CDbl(iTtlNumItems)
		iDBLoc			= CDbl(iDBLoc)
		SetupPagination = (CDbl(iDBLoc) + CDbl(iOWNumPerPage))	' this is what we will set the SET ROWCOUNT to in the primary query on the page
		
		Set rsCount = Nothing
		
	End Function
	'********************************************************************************
	
	
	'********************************************************************************
	'*																				*
	'*																				*
	'********************************************************************************
	Sub PaginationQuery( sSQLText, rs, iBeginPagination )

		'sSQLText = "SET ROWCOUNT " & iBeginPagination & " " & sSQLText & " SET ROWCOUNT 0"
		'rs.Open sSQLText, dbStoreConnection, adOpenKeyset, adLockReadOnly, adCmdText
		Call DB_getFromDatabase(sSQLText, rs, "") 
		For x = 1 To CDbl(iDBLoc)
			rs.MoveNext
		Next
		
	End Sub
	'************************************************************************************
	
	
	'********************************************************************************
	'*																				*
	'*	This pagination is specifically for the manager files. Use the one in the	*
	'*		Template for the storefront.											*
	'*																				*
	'********************************************************************************
	Sub PrintRecordsetNav( sURL, iOWNumPerPage, iTtlNumItems, iDBLoc, sQuerystring )

		Dim sSqlTemp, iTtlTemp, iNumLinksPerPage
		Dim iDBLocTemp, sURLBeg, iA, iB, x, iTemp, rsObj

		iTtlNumItems	= CDbl(iTtlNumItems)
		iDBLoc			= CDbl(iDBLoc)
		iOWNumPerPage		= CDbl(iOWNumPerPage)
		iTtlTemp		= iTtlNumItems \ iOWNumPerPage	' this is the number of numbers overall (use the "\" to return int)
		iDBLocTemp		= iDBLoc \ iOWNumPerPage		' this is which number we are currently on (use the "\" to return int)
		iNumLinksPerPage= 10	' this is the number of links to display

		If (sQuerystring <> "") Then
			sURLBeg = "<a class='BoxedLinks' href = ""JavaScript:PaginationLink('" & sQuerystring & "&iTtlNumItems=" & iTtlNumItems & "&iDBLoc="
		Else
			sURLBeg = "<a class='BoxedLinks' href = ""JavaScript:PaginationLink('&iTtlNumItems=" & iTtlNumItems & "&iDBLoc="
		End If

		'***** BEGIN DISPLAY *****
		Response.Write "<table cellpadding=0 cellspacing=5 border=0><tr>"
		%>
		<table border="0" cellpadding="0" cellspacing="0" style="font-size: 11px">
			<tr>
				<td height="25" style="BORDER-RIGHT: #aaaaaa 0px solid; BORDER-LEFT: #ffffff 0px solid; " bgcolor="#C3DAF9">
					<%
					' Print the <<
					if (iDBLocTemp >= iOWNumPerPage) then
						iTemp = ( iDBLocTemp * iOWNumPerPage ) - ( iOWNumPerPage * iNumLinksPerPage)
						Response.Write "&nbsp;" & sURLBeg & iTemp & "')"">&lt;&lt;</a>&nbsp;"
					end if
					' Print the "Previous"
					if (iDBLoc <> 0) then
						iTemp = iDBLoc - iOWNumPerPage
						Response.Write "&nbsp;" & sURLBeg & iTemp & "')""> &#8592; </a>&nbsp;"
					end if
			
					' Print the numbers in between. Print them out in sets of 10.
					iA = iDBLocTemp-5
					If ( iA < 0 ) Then
						iA = 0
					End If
					iB = iA + iNumLinksPerPage
					for x = iA to iB
						iTemp = (x * iOWNumPerPage)
						if (iTemp < iTtlNumItems) then	' takes care of extra numbers after the overall final number
							If ( iDBLoc >= iTemp ) And ( iDBLoc < (iTemp + iOWNumPerPage) ) Then
								Response.Write "&nbsp;" & x+1 & "&nbsp;"
							else
								Response.Write "&nbsp;" & sURLBeg & (x * iOWNumPerPage) & "')"">" & x+1 & "</a>&nbsp;"
							end if
						else
							exit for
						end if
					next
					' Print the "Next"
					if ((iDBLoc + iOWNumPerPage) < iTtlNumItems) then
						iTemp = (iDBLoc + iOWNumPerPage)
						Response.Write "&nbsp;" & sURLBeg & iTemp & "')""> &#8594; </a>&nbsp;"
					end if
					' Print the >>
					if ((iDBLocTemp + iNumLinksPerPage) <= iTtlTemp) then
						iTemp = ( iDBLocTemp * iOWNumPerPage ) + ( iOWNumPerPage * iNumLinksPerPage)
						Response.Write "&nbsp;" & sURLBeg & iTemp & "')"">&gt;&gt;</a>&nbsp;"
					end if
					%>
				</td>
			</tr>
		</table>
		<%

	End Sub
	'********************************************************************************
%>