<!--#include file="../Start.asp"-->
<!--#include file="../Include/PowerEasy.Common.Content.asp"-->
<!--#include file="../Include/PowerEasy.Common.Front.asp"-->
<!--#include file="../Include/PowerEasy.Channel.asp"-->
<!--#include file="../Include/PowerEasy.Class.asp"-->
<%

Dim ProductID, ProductNum, VisitedList, strSite_Sn, arrProduct, i, TempList, strTemp
Dim rs, ProductThumb, sNumber

ProductID = PE_Clng(Trim(Request("ProductID")))                                         '商品ID
ProductNum = PE_Clng1(Trim(Request("ProductNum")))                                      '列表最多显示两
strSite_Sn = LCase(Replace(Replace(DomainRoot & InstallDir, "/", ""), ".", ""))         '网站密钥
VisitedList = ReplaceBadChar(Request.Cookies(strSite_Sn)("Visited_Product"))            '读取Cookies

Const strNum = 30               '商品标题文字最多显示数量
Const Ellipsis = True           '标题是否显示缩略号，True为显示，False为不显示

Select Case Action
    Case "GetJS"
        GetJS
    Case "PicList"
        Call GetList(True)
    Case "ClearCookies"
        Response.Cookies(strSite_Sn)("Visited_Product") = ""
    Case Else
        Call GetList(False)
End Select

Sub GetJS()
    If InStr(VisitedList, ",") > 0 Then
        If FoundInArr(VisitedList, ProductID, ",") = False Then
            If ChkProduct Then Response.Cookies(strSite_Sn)("Visited_Product") = ProductID & "," & VisitedList
        End If
    Else
        If VisitedList = "" Then
            TempList = PE_Clng(TempList)
        Else
            TempList = VisitedList
        End If
        If ProductID <> CSng(TempList) Then
            If VisitedList <> "" Then VisitedList = "," & VisitedList
            If ChkProduct Then Response.Cookies(strSite_Sn)("Visited_Product") = ProductID & VisitedList
        End If
    End If
    Response.Cookies(strSite_Sn).Expires = Date + 3650
End Sub

Sub GetList(ShowType)
    strHtml = strHtml & "<style>"
    strHtml = strHtml & ".visited_border *{padding:0;margin:0;list-style:none;border:0;font-size:12px}"
    strHtml = strHtml & ".visited_border{width:170px;border:#D1E6F7 solid 1px}"
    strHtml = strHtml & ".visited_title{height:25px;line-height:25px;background:#D1E6F7;border:#fff solid 1px;padding-left:10px;font-weight:bold;color:#075BA3}"
    strHtml = strHtml & ".visited_border ul{padding:5px;line-height:20px}"
    strHtml = strHtml & ".visited_border li{clear:both;height:60px;padding:5px 0;border-bottom:#ccc dashed 1px}"
    strHtml = strHtml & ".visited_border li a{color:#00c;line-height:30px}"
    strHtml = strHtml & ".visited_border .pic5{border:#ccc solid 1px}"
    strHtml = strHtml & "</style>"
    strHtml = strHtml & "<form name=""compare"" action=""compare.asp"">" & vbCrLf
    strHtml = strHtml & "<div class=""visited_border"">" & vbCrLf
    strHtml = strHtml & "   <div class=""visited_title"">您浏览过的商品</div>" & vbCrLf
    strHtml = strHtml & "   <ul class=""visited_list"" id=""ProductList"">" & vbCrLf
    If InStr(VisitedList, ",") > 0 Then
        TempList = Split(VisitedList, ",")
        If UBound(TempList) >= ProductNum Then sNumber = ProductNum - 1 Else sNumber = UBound(TempList)
            For i = 0 To sNumber
                strHtml = strHtml & GetProuct(TempList(i), ShowType)
            Next
    Else
        strHtml = strHtml & GetProuct(VisitedList, ShowType)
    End If
    strHtml = strHtml & "   </ul>" & vbCrLf
    strHtml = strHtml & "<table align=center height=25><tr><td><img src=images/search_btn_compare.gif align-left></td><td><input type=""submit"" style=""cursor=hand""  value=""对比""/></td><td>&nbsp;&nbsp;<a href=""Visited_Product.asp?Action=ClearCookies"" target=""_ifw"" onclick=""ClearProduct();"">清除</s></td></tr></table>" & vbCrLf
    strHtml = strHtml & "</div></form><iframe name=""_ifw"" style=""display:none""></iframe>" & vbCrLf
    Response.Write Html2JS(strHtml) & vbCrLf
    Response.Write "function ClearProduct(){" & vbCrLf
    Response.Write "    document.getElementById(""ProductList"").innerHTML='';" & vbCrLf
    Response.Write "}" & vbCrLf
End Sub


Function GetProuct(sProductID, ShowType)
    strTemp = ""
    If sProductID = "" Then Exit Function
    Set rs = Conn.Execute("Select P.ProductName,P.ProductThumb,P.Price,P.IsHot,P.IsElite,C.ChannelDir,C.UploadDir,P.ChannelID,P.ClassID,P.UpdateTime from PE_Product P inner join PE_Channel C on P.ChannelID=C.ChannelID where P.ProductID=" & PE_Clng(sProductID) & " and P.EnableSale=" & PE_True & " and P.Deleted=" & PE_False)
        If Not (rs.Bof And rs.EOF) Then
            ChannelID = rs("ChannelID")
            ClassID = rs("ClassID")
            Call GetChannel(ChannelID)
            Call GetClass
            strTemp = strTemp & "       <li>"
            If ShowType Then
                If rs("ProductThumb") = "" Then
                    ProductThumb = StrInstallDir & "images/nopic.gif"
                Else
                    ProductThumb = StrInstallDir & rs("ChannelDir") & "/" & rs("UploadDir") & "/" & rs("ProductThumb")
                End If
                'strTemp = strTemp & "<a href=""" & StrInstallDir & rs("ChannelDir") & "/ShowProduct.asp?ProductID=" & sProductID & """ target=""_blank"">" & vbCrLf
                strTemp = strTemp & "<a href=""" & GetProductUrl(ParentDir, ClassDir, rs("UpdateTime"), sProductID) & """ target=""_blank"">" & vbCrLf
                strTemp = strTemp & "<img src=""" & ProductThumb & """ align=""left"" alt=""" & rs("ProductName") & """ width=""60"" height=""60"" class=""pic5"" /></a>" & vbCrLf
            End If
            strTemp = strTemp & "<a href=""" & StrInstallDir & rs("ChannelDir") & "/ShowProduct.asp?ProductID=" & sProductID & """ target=""_blank"">" & vbCrLf
            strTemp = strTemp & GetSubStr(rs("ProductName"), strNum, Ellipsis) & vbCrLf
            strTemp = strTemp & "</a><br />" & vbCrLf
            If rs("IsHot") Then strTemp = strTemp & "<font color=""red"">热</font>&nbsp;&nbsp;"
            If rs("IsElite") Then strTemp = strTemp & "<font color=""green"">荐</font>&nbsp;&nbsp;"
            strTemp = strTemp & "￥" & FormatNumber(rs("Price"), 2, vbTrue, vbFalse, vbTrue)
            strTemp = strTemp & "       </li><input type=""hidden"" name=""ProductID"" value=""" & sProductID & """>"
        End If
    Set rs = Nothing
    GetProuct = strTemp
End Function


Function Html2JS(Str)
    Html2JS = Replace(Str, "'", Chr(34))
    Html2JS = Replace(Html2JS, "/", "\/")
    Html2JS = Replace(Html2JS, Chr(34), "\" & Chr(34))
    Html2JS = Replace(Html2JS, vbCrLf, Chr(34) & ");" & vbCrLf & "document.writeln (" & Chr(34))
    Html2JS = "document.writeln (" & Chr(34) & Html2JS & Chr(34) & ");"
End Function


Function ChkProduct()
    strTemp = False
    Set rs = Conn.Execute("Select ProductName from PE_Product where ProductID=" & ProductID & " and EnableSale=" & PE_True & " and Deleted=" & PE_False)
        If rs.Bof And rs.EOF Then
            strTemp = False
        Else
            strTemp = True
        End If
    Set rs = Nothing
    ChkProduct = strTemp
End Function
CloseConn
%>
