<!--#include file="owFunctions/I_GeneralFunctions.asp"-->
<!--#include file="./owTemplates/Template.asp"-->
<%
	'************************************************************************************
	'*																					*
	'*	MODIFICATION TO THIS SCRIPT OR ANY FILES INCLUDED WITH 							*
	'*		ONEWORLDSTORE IS DONE AT YOUR OWN RISK!										*
	'*	Product  : OneWorldStore														*
	'*	Version  : 9.0000																*
	'*	Modified : June 2004															*
	'*	Copyright:	Copyright (C) 2004 OneWorldStore.Com								*
	'*				Registration Number: 1024507										*
	'*				http://strategis.ic.gc.ca/											*
	'*																					*
	'************************************************************************************
	
	Dim iBeginPagination, bResetTtlNumItems, iTtlNumItems, iDBLoc, sSort, sSortQuerystring
	
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Sub ActionSubroutine()

		Dim sSQLCount

		sIdCategory			= CONVERSION_SQLEncode2(Request("idCategory"),4)
		bSub				= Trim(Request("bSub"))
		sSupplierAccountUnq	= Trim(Request("sAccountUnq"))
		bSpecials			= Trim(Request("bSpecials"))
		sSort				= Trim(Request("sSort"))
		sSortQuerystring	= "bSpecials=" & bSpecials & "&sAccountUnq=" & sSupplierAccountUnq & "&bSub=" & bSub & "&idCategory=" & sIdCategory	' this has to be different because the sSort value will change depending on what the customer chooses
		sQuerystring		= "sSort=" & sSort & "&bSpecials=" & bSpecials & "&sAccountUnq=" & sSupplierAccountUnq & "&bSub=" & bSub & "&idCategory=" & sIdCategory
		
		If ( bSpecials = "T" ) Then
			' they want to see the specials
			sSQLText		= "SELECT * FROM Products P WHERE P.hotDeal = -1 AND P.listhidden=0 AND P.active=-1"
			sSQLCount		= "SELECT Count(*) FROM Products P WHERE P.hotDeal = -1 AND P.active = -1 AND P.listhidden = 0"
		Else
			If ( sSupplierAccountUnq <> "" ) Then
				' they want to see a suppliers products (a brand)
				sSupplierBrand	= ACCNT_ReturnADV("OW_CUSTCOMPANY", "V", sSupplierAccountUnq, C_OVERRIDE_ADV)
				sSQLText		= "SELECT * FROM Products WHERE idsupplier = " & sSupplierAccountUnq & " AND listhidden=0 AND active = -1"
				sSQLCount		= "SELECT Count(*) FROM Products WHERE idsupplier = " & sSupplierAccountUnq & " AND active = -1 AND listhidden = 0"
			Else
				If ( bSub = "T" ) Then
					' this is a sub category, so list just it's products
					sSQLText	= "SELECT * FROM CatProdMap CPM, Categories C, Products P WHERE P.idProduct = CPM.idProduct AND CPM.idCategory = C.idCategory AND C.idCategory=" & sIdCategory & " AND P.active = -1 AND P.listhidden = 0"
					sSQLCount	= "SELECT Count(*) FROM CatProdMap CPM, Categories C, Products P WHERE P.idProduct = CPM.idProduct AND CPM.idCategory = C.idCategory AND C.idCategory=" & sIdCategory & " AND P.active = -1 AND P.listhidden = 0"
				Else
					' this is a parent category, so list all it's sub categories products (unfortunately this has a side-effect of not ever listing any products within the parent category)
					sSQLText	= "SELECT * FROM CatProdMap CPM, Categories C, Products P WHERE P.idProduct = CPM.idProduct AND CPM.idCategory = C.idCategory AND C.idParentCategory=" & sIdCategory & " AND P.active = -1 AND P.listhidden = 0"
					sSQLCount	= "SELECT Count(*) FROM CatProdMap CPM, Categories C, Products P WHERE P.idProduct = CPM.idProduct AND CPM.idCategory = C.idCategory AND C.idParentCategory=" & sIdCategory & " AND P.active = -1 AND P.listhidden = 0"
				End If
			End If
		End If
		
		If ( bOWEnableCategorySort ) Then
			Select Case sSort
				Case "POP"		' Popularity
					sSQLText = sSQLText & " ORDER BY P.Visits DESC"
				Case "TOP"		' Top Sales
					sSQLText = sSQLText & " ORDER BY P.Sales DESC"
				Case "PLH"		' Price (Low to High)
					sSQLText = sSQLText & " ORDER BY P.Price ASC"
				Case "PHL"		' Price (High to Low)
					sSQLText = sSQLText & " ORDER BY P.Price DESC"
				Case "PAZ"		' Product Name (A to Z)
					sSQLText = sSQLText & " ORDER BY P.Description ASC"
				Case "PZA"		' Product Name (Z to A)
					sSQLText = sSQLText & " ORDER BY P.Description ASC"
				Case Else
					If ( sSupplierAccountUnq = "" ) And ( bSpecials <> "T" ) Then
						' neither the supplier nor the hot deals queries have the categories table in them, so this'd break it
						sSQLText = sSQLText & " ORDER BY C.categoryDesc"
					Else
						sSQLText = sSQLText & " ORDER BY P.Visits DESC"
					End If
			End Select
		End If

		iBeginPagination = SetupPagination( sSQLCount, bResetTtlNumItems, bResetDBLoc )
		Call PaginationQuery( sSQLText, rsStoreData, iBeginPagination )

		%>
		<script language='JavaScript1.2' type='text/javascript'>
		
			function PaginationLink(sQueryString){
				location = "owListProduct.asp?" + sQueryString;
			}
			
		</script>
		<table width=<%=sOWStoreTableWidth%> border=0 style='border: 1px solid #000000;' cellspacing=0 cellpadding=5>
			<tr bgcolor="#eeeeee">
				<td style='border-bottom: 1px solid #000000;'>
					<b>
					<%
					If ( sSupplierAccountUnq <> "" ) Then
						Response.Write "<B>" & sSupplierBrand & "</b>"
					ElseIf ( bSpecials = "T" ) Then
						Response.Write "<B>" & LANG_DT( "LISTPROD_HOTDEALS", "Hot Deals!" ) & "</b>"
					Else
						Call STRUCTURE_Breadcrumbs(sBreadCrumb, sIdCategory)
						Response.Write sBreadCrumb
					End If
					%>
					</b>
				</td>
			</tr>
			<tr>
				<td>
					<%
					Call DisplayCategoryHead(sIdCategory)
					Call DisplaySortDropDown(sSort)
					Call TEMPLATE_PrintRecordsetNav( sURL, iOWNumPerPage, iTtlNumItems, iDBLoc, sQuerystring )
					If ( rsStoreData.EOF ) Then
						If ( sSupplierAccountUnq <> "" ) Then
							Response.Write "<B>" & Replace(LANG_DT( "LISTPROD_NOPRODSFORSUPPLIER", "No products for 1: were found." ), "1:", sSupplierBrand) & "</b><BR><BR>"
						ElseIf ( bSpecials = "T" ) Then
							Response.Write "<B>" & LANG_DT( "LISTPROD_NOHOTDEALS", "No Hot Deals! products were found." ) & "</b><BR><BR>"
						Else
							Response.Write "<B>" & LANG_DT( "LISTPROD_NOPRODSINCAT", "No products were found within this category." ) & "</b><BR><BR>"
						End If
					else
						sSQLCount = 0
						While ( ( NOT rsStoreData.EOF ) And ( sSQLCount < iOWNumPerPage ) )
							sIdProduct		= rsStoreData("idProduct")
							sDescription	= rsStoreData("description")   
							sPrice			= rsStoreData("price")   
							sBtoBPrice		= rsStoreData("bToBPrice")   
							slistprice		= rsStoreData("listprice")
							sSmallImageUrl	= rsStoreData("smallImageUrl")   
							sVisits			= rsStoreData("visits")
							Call TEMPLATE_ProductListingDisplay( sSmallImageUrl, sDescription, slistprice, sPrice, sBtoBPrice, 0, sVisits, sIdProduct, idCategory )
							sSQLCount = sSQLCount + 1
							rsStoreData.moveNext
						Wend
					End If
					Call DB_closeRecordset(rsStoreData)
					%>
				</td>
			</tr>
		</table>
		<%
		Call TEMPLATE_PrintRecordsetNav( sURL, iOWNumPerPage, iTtlNumItems, iDBLoc, sQuerystring )
		
	End Sub
	'********************************************************************************

	
	'********************************************************************************
	'*																				*
	'*																				*
	'********************************************************************************
	Sub DisplaySortDropDown(sSort)

		%>
		<center>
		Sort By:
		<select name='sSort' onChange='location="owListProduct.asp?sSort=" + this.value + "&<%=sSortQuerystring%>"'>
			<option value='POP' <%If ( sSort = "POP" ) Then Response.Write "selected" End If%>>Popularity</option>
			<option value='TOP' <%If ( sSort = "TOP" ) Then Response.Write "selected" End If%>>Top Seller</option>
			<option value='PLH' <%If ( sSort = "PLH" ) Then Response.Write "selected" End If%>>Price (Low to High)</option>
			<option value='PHL' <%If ( sSort = "PHL" ) Then Response.Write "selected" End If%>>Price (High to Low)</option>
			<option value='PAZ' <%If ( sSort = "PAZ" ) Then Response.Write "selected" End If%>>Product Name (A to Z)</option>
			<option value='PZA' <%If ( sSort = "PZA" ) Then Response.Write "selected" End If%>>Product Name (Z to A)</option>
			<option value='BAZ' <%If ( sSort = "BAZ" ) Then Response.Write "selected" End If%>>Brand (A to Z)</option>
			<option value='BZA' <%If ( sSort = "BZA" ) Then Response.Write "selected" End If%>>Brand (Z to A)</option>
		</select>
		</center>
		<%
		
	End Sub
	'********************************************************************************
	
	
	'********************************************************************************
	'*																				*
	'*																				*
	'********************************************************************************
	Sub DisplayCategoryHead(sIdCategory)
	
		If ( sIdCategory <> "" ) Then
			sSQLText = "SELECT idCategory, categoryDesc, idParentCategory, imageCategory, shortHTML, longHTML FROM categories WHERE IdCategory=" &sIdCategory& " AND idCategory<>1 AND active=-1"
			Call DB_getFromDatabase(sSQLText, rsStoreData2,"")   
			If ( NOT rsStoreData2.EOF ) Then
				%>
				<%if trim(rsStoreData2("shortHTML"))<>"" then%>
				<br><%=rsStoreData2("shortHTML")%><br>
				<%End If%>
				<%if trim(rsStoreData2("imageCategory"))<>"" then%>
				<img src="<%=sOWCategoryImage%>/<%=Server.HTMLEncode(rsStoreData2("imageCategory"))%>"><br>
				<%End If%>
				<%if trim(rsStoreData2("longHTML"))<>"" then%>
				<%=rsStoreData2("longHTML")%><br>
				<%End If%>
				<br><br>
				<%
			End If
			Call DB_closeRecordset(rsStoreData2)
		End If
		
	End Sub
	'********************************************************************************
%>