<%

'+------------------
'| Your List Include - the mini shopping cart (ylist.inc)
'+------------------

'+------------------
'| Set a useragent string for Mozilla/IE/Every other browser (due to display differences)
'+------------------

tmpUa = Request.ServerVariables("HTTP_USER_AGENT")
If (((InStr(tmpUa,"MSIE 4")<>0) OR (InStr(tmpUa,"MSIE 5")<>0) OR (InStr(tmpUa,"MSIE 6")<>0)) AND (InStr(tmpUa,"Opera")=0)) Then
	tmpUa = 1	'IE4+
ElseIf (InStr(Request.ServerVariables("HTTP_USER_AGENT"),"Mozilla/5")<>0) Then
	tmpUa = 3	'Gecko
Else
	tmpUa = 2	'everyone else
End if

If ((tmpUa = 1) OR (tmpUa = 3)) Then %><table border=0 width=175 cellpadding=0 cellspacing=0><tr><td><img border=0 width=175 height=15 src="lt.gif"></td></tr><tr><td><div <% If (tmpUa = 3) Then %>width="173" style="width:173px;<% Else %>width="175" style="width:175px;<% End if %>text-align:left;padding:0px;height:68px;overflow:auto;overflow-x:clip;border:1px solid #006699;font-family:arial;font-size:11px;background-color:#ffffff;scrollbar-base-color:#f2f1df;scrollbar-highlight-color:#c1c0b2"><%
Else
%><img border=0 width=175 height=15 src="lt.gif"><table border=0 width=175 cellpadding=0 cellspacing=0><tr valign='top'><td width=1 bgcolor="#006699" valign=bottom><img src="spacer.gif" height=79 width=1 border=0></td><td width=2><img src="spacer.gif" height=1 width=2 border=0></td><td width=169><font face="arial,helvetica" size=1><%
End if

dim szEmpty
cCount = 1
cCount2 = 1
szOverLimit = "false"
szPlural = 0
nSameNo = 0
szEmpty = "true"

If szProductName = "" Then
	szProductName = Request("szProd")
End if
If szAsin = "" Then
	szAsin = Request("asin")
End if

'+------------------
'| Set up the two cookies (asin1 & asin2) to be read and written for item management
'| Using two cookies because of size limitations - browsers will only handle up to 4k per cookie
'| So two cookies accomodates up to 150 unique ASINs in this scheme.
'| The "HasKeys" method is unique to IIS Cookie Dictionary objects, just think of
'| of these cookie dictionaries as "overallname=name1=val1&name2=val2...", so one cookie
'| can support multiple name/value pairs.
'+------------------

''How many in 'asin'
	If Request.Cookies("asin1")<>"" Then
		If Request.Cookies("asin1").HasKeys Then
		    For Each strSubKey In Request.Cookies("asin1")
			If Request.Cookies("asin1")(strSubKey) <> "" Then
				cCount = cCount + 1
			End if
		    Next
	    End if
	End if

''How many in 'asin2'
	If Request.Cookies("asin2")<>"" Then
		If Request.Cookies("asin2").HasKeys Then
		    For Each strSubKey In Request.Cookies("asin2")
			If Request.Cookies("asin2")(strSubKey) <> "" Then
			    cCount2 = cCount2 + 1
			End if
		    Next
	    End if
	End if
	If cCount2 > 1 Then
		cCount = 75
	End if

''add an asin

	If ((Request("addasin") = "1") AND (szOverLimit = "false")) Then
		szAmt = 1
		If Len(szProductName) > 19 Then
			szPN = Left(szProductName,17) & "..."
		Else
			szPN = szProductName
		End if
		If (InStr(Request.Cookies("asin1"),szAsin)<>0) Then
			szPlural = 1
			For ac = (cCount - 1) to 1 step -1
				rgAsin = Split(Request.Cookies("asin1")(CStr(ac)),"|")
				If szAsin = rgAsin(0) Then
					szAmt = rgAsin(2) + 1
					If (CInt(szAmt) > 999) Then szAmt = "999"
			    		nSameNo = ac
			    		Exit For
				End if
			Next
			For ac = nSameNo to cCount-1
				Response.Cookies("asin1")(CStr(ac)) = Request.Cookies("asin1")(CStr(ac+1))
			Next

''Format for each cookie value is "ASIN|ProductName|Amount"
			Response.Cookies("asin1")(CStr(cCount-1)) = szAsin & "|" & szPN & "|" & szAmt
    		Response.Cookies("asin1").Expires = Now() + 90
		End if
		If (InStr(Request.Cookies("asin2"),szAsin)<>0) Then
			szPlural = 1
			For ac = (cCount2 - 1) to 1 step -1
				rgAsin = Split(Request.Cookies("asin2")(CStr(ac)),"|")
				If szAsin = rgAsin(0) Then
					szAmt = rgAsin(2) + 1
					If (CInt(szAmt) > 999) Then szAmt = "999"
			    		nSameNo = ac
			    		Exit For
				End if
			Next
			For ac = nSameNo to cCount2-1
				Response.Cookies("asin2")(CStr(ac)) = Request.Cookies("asin2")(CStr(ac+1))
			Next
			Response.Cookies("asin2")(CStr(cCount2-1)) = szAsin & "|" & szPN & "|" & szAmt
    		Response.Cookies("asin1").Expires = Now() + 90
    		Response.Cookies("asin2").Expires = Now() + 90
		End if

		If szPlural = 0 Then
			If cCount < 75 Then
				If cCount <> 1 Then
				    Response.Cookies("asin1")(CStr(cCount)) = szAsin & "|" & szPN & "|" & szAmt
				Else
					Response.Cookies("asin1")("1") = szAsin & "|" & szPN & "|" & szAmt
				End if
			    Response.Cookies("asin1").Expires = Now() + 90
			Else
				If cCount2 <= 75 Then
					If cCount2 <> 1 Then
					    Response.Cookies("asin2")(CStr(cCount2)) = szAsin & "|" & szPN & "|" & szAmt
					Else
						Response.Cookies("asin2")("1") = szAsin & "|" & szPN & "|" & szAmt
					End if
				    Response.Cookies("asin2").Expires = Now() + 90
				    Response.Cookies("asin1").Expires = Now() + 90
				Else
					szOverLimit = "true"
				End if
			End if
		End if
	End if


	If (Request("addasin") = "1") Then
		set objHTTP = Server.CreateObject("Microsoft.XMLHTTP")
		szGetString = "http://xml.amazon.com/onca/xml?v=1.0&t=kokogiak-20&dev-t=[Insert Developer's Token Here]&AsinSearch=" & szAsin & "&type=heavy&f=xml"
		objHTTP.open "GET", szGetString, false
		objHTTP.Send
		If szOverLimit = "true" Then
			szQs = Replace(Request.ServerVariables("QUERY_STRING"),"addasin=1","addasin=2") & "&ol=true"
		Else
			szQs = Replace(Request.ServerVariables("QUERY_STRING"),"addasin=1","addasin=2")
		End if
		szPath = Request.ServerVariables("URL") & "?" & szQs & szQQ
		Response.redirect(szPath)
	End if

	If Request("ol") = "true" Then
		Response.Write ("<center>OVERLIMIT<br>(150 Items or less)</center>")
	End if

	If ((Request.Cookies("asin2")<>"") AND ((tmpUa = 1) OR (tmpUa = 3))) Then
		If ((Request("addasin") = "1") AND (cCount2 <=75)) Then
		 	nStep = 0
		Else
		 	nStep = 1
		End if
		For ac = ((cCount2) - nStep) to 1 step -1
			szEmpty = "false"
			rgAsin = Split(Request.Cookies("asin2")(CStr(ac)),"|")
			Response.Write ("<nobr><a href='detpage.asp?asin=" & rgAsin(0) & "&field-keywords=" & szTerm & "&schMod=" & szSchMode & "&type=" & szSchType & "&sb=" & szSB & "'><img src='http://images.amazon.com/images/P/" & rgAsin(0) & ".01.THUMBZZZ.jpg' border=0 height=18 width=18 align=absbottom hspace='2'></a> " & rgAsin(2) & " <a href='detpage.asp?asin=" & rgAsin(0) & "&field-keywords=" & szTerm & "&schMod=" & szSchMode & "&type=" & szSchType & "&sb=" & szSB & "'>" & rgAsin(1) & "</a></nobr><br clear='all'>")
		Next
	End if
	If Request.Cookies("asin1")<>"" Then
		If ((Request("addasin") = "1") AND (cCount <75) AND (szPlural = 0)) Then
		 	nStep = 0
		Else
		 	nStep = 1
		End if
		nnCount = 0
		For ac = (cCount - nStep) to 1 step -1
			On error Resume Next
			nnCount = nnCount + 1
			If ((tmpUa = 2) AND (nnCount>3)) Then
			    Response.Write ("<center><font size=2> </font><font size=1> - <a href='yourlist.asp?asin=" & Request("asin") & "&field-keywords=" & szTerm & "&schMod=" & szSchMode & "&type=" & szSchType & "&sb=" & szSB & "'>More Items...</a> - </font><font size=2> </font></center>")
			    Exit For
			End if
			szEmpty = "false"
			rgAsin = Split(Request.Cookies("asin1")(CStr(ac)),"|")
			Response.Write ("<nobr><a href='detpage.asp?asin=" & rgAsin(0) & "&field-keywords=" & szTerm & "&schMod=" & szSchMode & "&type=" & szSchType & "&sb=" & szSB & "'><img src='http://images.amazon.com/images/P/" & rgAsin(0) & ".01.THUMBZZZ.jpg' border=0 height=18 width=18 align=absbottom hspace='2'></a> " & rgAsin(2) & " <a href='detpage.asp?asin=" & rgAsin(0) & "&field-keywords=" & szTerm & "&schMod=" & szSchMode & "&type=" & szSchType & "&sb=" & szSB & "'>" & rgAsin(1) & "</a></nobr><br clear='all'>")
		Next
	End if

	If szEmpty = "true" Then
		Response.write("<center>Your List is currently Empty.<br>Search for something, and Add It<br>to Your List, or click <a href='about_yl.asp'>here</a> to<br>learn more.</center>")
	End if

If ((tmpUa = 1) OR (tmpUa = 3)) Then %></div></td></tr><tr><td><a href='yourlist.asp?asin=<% Response.write(Request("asin") & "&field-keywords=" & szTerm & "&schMod=" & szSchMode & "&type=" & szSchType & "&sb=" & szSB) %>'><img border=0 width=175 height=15 src="lb.gif"></a></td></tr></table><%
Else
%></font></td><td width=2><img src="spacer.gif" height=1 width=2 border=0></td><td width=1 bgcolor="#006699" valign=bottom><img src="spacer.gif" height=79 width=1 border=0></td></tr></table><a href='yourlist.asp?asin=<% Response.write(Request("asin") & "&field-keywords=" & szTerm & "&schMod=" & szSchMode & "&type=" & szSchType & "&sb=" & szSB) %>'><img border=0 width=175 height=15 src="lb.gif"></a><br><%
End if
%>