<!--#include file="owFunctions/I_GeneralFunctions.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 bProdInfoReturned, sDescription, sPrice, sBtoBPrice, sDetails, sListPrice, simageUrl
	Dim sSmallImageURL, sSku, sFormQuantity
	Dim sFreeShipQty, sSearchKeywords
	Dim sIDProduct, sIDCategory
	
	bProdInfoReturned = False
	
	bProdInfoReturned = ReturnProductData()	' have to call this before the template so that we'll have the product's description for the page title
	
	%><!--#include file="./owTemplates/Template_NoNav.asp"--><%

	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Sub ActionSubroutine()

		Dim sError

		sAction		= Trim(Request("sAction"))
		bDetail		= CONVERSION_SQLEncode2(Request("bDetail"),2)
		
		If ( ( sIDProduct = "" ) Or ( NOT IsNumeric(sIDProduct) ) ) Then
			Call owMessage(LANG_DT( "PROD_DETAIL_NOTFOUND", "Unable to find the product. The product ID# is missing." ), C_ERROR)
		Else
			If ( sIDCategory = "" ) Then	' do the slow way of looking it up
				sSQLText = "SELECT C.idCategory FROM categories C, CatProdMap CP WHERE CP.idProduct = " & sIDProduct & " AND CP.idCategory = C.idCategory"
				Call DB_getFromDatabase (sSQLText, rsStoreData, "")
				If ( NOT rsStoreData.EOF ) Then
					sIDCategory = rsStoreData("idCategory") 
				End If
				Call DB_closeRecordset(rsStoreData)
			End If
	
			call DB_updateDatabase("UPDATE products SET visits = visits + 1 WHERE idProduct = " & sIDProduct)
	
			If ( bProdInfoReturned ) Then				
				
				If ( Trim(Request("bSelectOption")) = "T" ) Then
					' this var will be set on the querystring from the owAddItem.asp when a user tries to add a product from a product listing page where that product requires at least one option
					'	and this error should display at the top of the product detail page w/ all the other info under it
					sError = sError & LANG_DT( "PROD_DETAIL_OPTIONISREQUIRED", "Please choose an option for this product before adding it to your cart." )
				End If

				Call STRUCTURE_Breadcrumbs(sBreadCrumb, sIDCategory)
				Response.Write " > " & sBreadCrumb

				%>
				<br><br>
				
				<script language=JavaScript src="owScriptLibrary/overlib_products.js"><!-- overLIB (c) Erik Bosrup --></script>
				<div id=overDiv style="Z-INDEX: 1000; VISIBILITY: hidden; POSITION: absolute"></div>
				
				<script type="text/javascript" src="owManager/Script/fValConfig.js"></script>
				<script type="text/javascript" src="owManager/Script/fValidate.js"></script>
				<%
				If ( sError <> "" ) Then
					Call owMessage(sError, C_ERROR)
				End If
				%>
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td><b><font size=+1><%=sDescription%></td>
					</tr>
				</table>
				
				<br>
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<form method="post" action="owBasket/owAddItem.asp" name="additem" onSubmit="if ( validateForm( this, false, false, false, false, 17 ) ) { return true; } else { return false; }">
					<input type="hidden" name="idProduct" value="<%=sIDProduct%>">
					<tr>
						<td valign="top" align=center>
							<table border="0" cellspacing="0" cellpadding="0" width="100%">
								<tr>
									<td valign=top align=right>
										<table border="0" cellspacing="0" cellpadding="0" width="100%">
											<tr>
												<td width=50%>
												</td>
												<td width=50% align=right>
													<table><tr><td nowrap>
													<%If ( ( sFormQuantity > 1 ) ) Then%>
													<%=LANG_DT( "PROD_DETAIL_QTYDROPDOWN", "Qty" )%>
													<select name="quantity">
														<option value="1">1</option>
														<%for iX = 2 to sFormQuantity%>
															<option value="<%=iX%>"><%=iX%></option>              
														<%next%>
													</select>
													<%End If%>
													</td><td>
													<input alt=Add src="owTemplates/images/English/viewitem_addcart.gif" type=image name="add" border="0">
													</td></tr></table>
													<%=LANG_DT( "PROD_DETAIL_ITEMNUM", "Item #" )%>: <%=sSku%>
												</td>
											</tr>
										</table>
									</td>
								</tr>
								<tr>
									<td>
										<%if Trim(simageUrl)<>"" then%>
										<center><img src='<%=sOWImagesDir%>/<%=simageUrl%>' width=450 alt="<%=Server.HTMLEncode(sDescription)%>"></center>
										<%else%>
										<%If Trim(sSmallImageURL) = "" Then%>
										<center><img src='owTemplates/Images/English/imageNA.gif'></center>
										<%Else%>
										<img src="<%=sOWImagesDir%>/small/<%=sSmallImageURL%>" width=150 border=0>
										<%End If%>
										<%End If%>
									</td>
								</tr>
							</table>
						</td>
						<td valign="top" width="10"><img src="owTemplates/images/ClearDot.gif" width="10" height="1"></td>
						<td valign="top" width="1" bgcolor="#999999"><img src="owTemplates/images/ClearDot.gif" width="1" height="1"></td>
						<td valign="top" width="10"><img src="owTemplates/images/ClearDot.gif" width="10" height="1"></td>
						<td valign="top"> 
						
							<%Call getOptionsGroups(sIDProduct)%>
		
							<table border="0">
								<tr> 
									<td>
										<table class='StandardBox' cellpadding=5>
											<tr>
												<td>
													<font size=+1 color=660000>
													<%
													if sBtoBPrice>0 and (bOWShowBtoBPrice or ACCNT_InGroup(iLoginAccountUnq, C_GROUP_WHOLESALE)) then
														Response.Write LANG_DT( "PROD_DETAIL_WHOLESALE", "Wholesale Price " ) & CONVERSION_Currency(sBtoBPrice) & "&nbsp;<font size=-2>" & sTempCurrencyCode & "</font><br>"
													End If
													if ((sListPrice-sPrice)>0 and ACCNT_InGroup(iLoginAccountUnq, C_GROUP_RETAIL)) then
														Response.Write LANG_DT( "PROD_DETAIL_MSRP", "MSRP Price " ) & CONVERSION_Currency((sListPrice)) & "<br>"
													End If
													%>
													<font size=+1>Our Price: <%=CONVERSION_Currency(sPrice)%>&nbsp;<font size=-2><%=sTempCurrencyCode%></font></font><br>
													<%
													if (sPrice-sBtoBPrice)>0 and ( sBtoBPrice > 0 ) and ACCNT_InGroup(iLoginAccountUnq, C_GROUP_WHOLESALE) then
														Response.Write "<span class='owProductPriceV'>" & LANG_DT( "PROD_DETAIL_YOUSAVE", "You save " ) & CONVERSION_Currency((sPrice-sBtoBPrice)) & " (" & FormatPercent((1-(sBtoBPrice/sListPrice))) & ")!</span><br>"
													Elseif ((sListPrice-sPrice)>0 and ( sPrice > 0 ) and ACCNT_InGroup(iLoginAccountUnq, C_GROUP_RETAIL)) then
														Response.Write "<span class='owProductPriceV'>" & LANG_DT( "PROD_DETAIL_YOUSAVE", "You save " ) & CONVERSION_Currency((sListPrice-sPrice)) & " (" & FormatPercent((1-(sPrice/sListPrice))) & ")!</span><br>"
													End If
													%>
													</font>
												</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</td>
					</tr>
					</form>
					<tr><td colspan=5 height=1 bgcolor="#999999"><img src="owTemplates/images/ClearDot.gif" width="1" height="1"></td></tr>
					<tr><td colspan=5><img src="owTemplates/images/ClearDot.gif" height="10"></td></tr>
					<tr>
						<td colspan=5>
							<span style='font-size:13px; color: #000000; font-family: tahoma, Verdana, Arial, Sans-Serif; letter-spacing: 0.09em;'>
							<%=sDetails%>
							</span>
						</td>
					</tr>
				</table>
				<%
			Else
				Call owMessage(LANG_DT( "PROD_DETAIL_NOTFOUND2", "Unable to find the item specified." ), C_ERROR)
			End If
		End If

	End Sub
	'************************************************************************************


	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Function getOptionsGroups(idProduct)
	
		dim rsStoreData, rsStoreData2, iCount
		
		set rsStoreData		= CreateObject("ADODB.Recordset")
		set rsStoreData2	= CreateObject("ADODB.Recordset")
		iCount				= 0
		
		sSQLText = "SELECT OGP.idOptionGroup, OGP.Required FROM Products P, OptionsGroups_Products OGP WHERE P.idProduct = " & idProduct &" AND P.idProduct = OGP.idProduct"
		Call DB_getFromDatabase (sSQLText, rsStoreData, "")
		If ( NOT rsStoreData.EOF ) Then
			While ( NOT rsStoreData.EOF )
				sRequired = Trim(rsStoreData("Required"))
				sSQLText = "SELECT O.priceToAdd, O.optionDescrip, O.idOption, OG.idOptionGroup, OG.optionGroupDesc, OG.Type FROM OptionsGroups OG, Options_OptionsGroups OOG, Options O WHERE OG.idOptionGroup = " & rsStoreData("idOptionGroup") & " AND OG.idOptionGroup = OOG.idOptionGroup AND O.idOption = OOG.idOption ORDER BY O.optionDescrip"
				Call DB_getFromDatabase (sSQLText, rsStoreData2, "")
				If ( NOT rsStoreData2.EOF ) Then
					iCount = iCount + 1
					sType = Trim(rsStoreData2("Type"))
					Select Case sType
						Case "Dropdown"
							%>
							<table>
								<tr>
									<td>
										<b><%=rsStoreData2("optionGroupDesc")%>:
									</td>
									<td>
										<%If ( sRequired = "Y" ) Then%>
										<SELECT name='idOption_Dropdown_<%=rsStoreData2("idOptionGroup")%>' alt='select' emsg='<%=Replace(LANG_DT( "PROD_DETAIL_CHOOSELIST", "Please choose from the 1: list." ), "1:", rsStoreData2("optionGroupDesc"))%>'>
										<%Else%>
										<SELECT name='idOption_Dropdown_<%=rsStoreData2("idOptionGroup")%>' alt=''>
										<%End If%>
										<option value='<%=C_S_NULL%>'><%=LANG_DT( "PROD_DETAIL_NOCHOICE", "None" )%></option>
										<%
										While ( NOT rsStoreData2.EOF )
											response.write "<option value='" & rsStoreData2("idOption") & "'>" & rsStoreData2("optionDescrip")
											If ( CDbl(rsStoreData2("priceToAdd")) > 0 ) Then
												response.write " +" & CONVERSION_Currency(rsStoreData2("priceToAdd"))
											End If
											response.write "</option>" & VBcrlf
											rsStoreData2.MoveNext
										Wend
										%>
										</select>
									</td>
									<%If ( sRequired = "Y" ) Then%>
									<td>
										(*)
									</td>
									<%End If%>
								</tr>
							</table>
							<%
							
					End Select
					Call DB_closeRecordset(rsStoreData2)
				End If
				rsStoreData.MoveNext
			Wend
			Response.Write LANG_DT( "PROD_DETAIL_REQOPTION", "(*) Required Option" )
			Response.Write "<BR><BR>"
		End If
		Call DB_closeRecordset(rsStoreData) 
		
		set rsStoreData = Nothing
		set rsStoreData2 = Nothing
	
	End Function
	'************************************************************************************
	
	

	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Function ReturnProductData()
	
		sIDProduct	= CONVERSION_SQLEncode2(Request("idProduct"),10)
		sIDCategory	= CONVERSION_SQLEncode2(Request("idCategory"),4)
	
		sSQLText = "SELECT * FROM products WHERE idProduct = " & sIDProduct & " AND active = -1"
		Call DB_getFromDatabase (sSQLText, rsStoreData, "")
		If ( NOT rsStoreData.EOF ) Then
			sDescription		= Trim(rsStoreData("description"))
			sPrice				= Trim(rsStoreData("price"))
			sBtoBPrice			= Trim(rsStoreData("bToBPrice"))
			sDetails			= Trim(rsStoreData("details"))
			sListPrice			= Trim(rsStoreData("listPrice"))
			simageUrl			= Trim(rsStoreData("imageUrl"))
			sSmallImageURL		= Trim(rsStoreData("smallimageUrl"))
			sSku				= Trim(rsStoreData("sku"))
			sFormQuantity		= Trim(rsStoreData("formQuantity"))
			sSearchKeywords		= Trim(rsStoreData("SearchKeywords"))
			ReturnProductData	= True
		Else
			ReturnProductData	= False
		End If
		Call DB_closeRecordset(rsStoreData)
	
	End Function
	'************************************************************************************
%>