<%
'**************************************
'* 最后更新 2013-04-28 by 56770.kingdge
'* Copyright www.56770.com
'**************************************
Dim product_name,brand,keytype,pricetype,keytype1,addtime,price1,price2,page
Showpath = "<a href='"& Eshop_url & LangPath &"'>"& Lebi_word(0) &"</a> → "& Lebi_word(38)
page = checknum(request("page"),1)
sort_id = checknum(request("sort_id"),0)
brand=safereplace(trim(request("brand")))
keytype=safereplace(trim(request("keytype")))
pricetype=safereplace(trim(request("pricetype")))
keytype1=safereplace(trim(request("keytype1")))
addtime=safereplace(trim(request("addtime")))
price1=safereplace(trim(request("price1")))
price2=safereplace(trim(request("price2")))
product_name=safereplace(trim(request("product_name")))
If product_name <> "" Then
		strwebtitle = product_name &"-"
End If
sql = "select s_name"& LangTxt &" from [Lebi_SearchWords] where"
if IsSqlDataBase ="1" then sql=sql+" CharIndex(s_name"& LangTxt &",'"&product_name&"')>0"
if IsSqlDataBase ="0" then sql=sql+" instr('"&product_name&"',s_name"& LangTxt &")>0"
sql=sql+" order by s_order desc"
set rswords = conn.execute(sql)
If Not (rswords.eof And rswords.bof) Then
		Data_SearchWords = rswords.getrows()
		Count_SearchWords = 1
Else
		Count_SearchWords = 0
End If
rswords.close : Set rswords = Nothing
Function SearchList()
        Dim sql,DataCount,DataList,i,rs_gjc,showpic_width,showpic_height,div_width,div_height,Filename, briefed,icostr,loop_keyword,j,RLoadStyle(5),LoadListStr,strFile,tmpstr,loopstr,stock,pNameArr, PList_url,pic_url,Showname
		Dim scount
		scount = conn.execute("select count(id) from [Lebi_Product] where product_name"& LangTxt &" = '"& product_name &"'")(0)
		If IsNull(scount) Or IsEmpty(scount) Then scount = 0
		Dim ors
	    Set ors=new Cls_vbsPage
	    Set ors.Conn=conn
	    With ors
		    .PageSize=top24
		    .PageName="Page"
		    .DbType="AC"
		    .RecType=0
		    .Pkey="p.id"
    	    .Field="p.id,p.product_name"& LangTxt &",p.pic,p.sprice,p.cprice,p.cx,p.stj,p.ytj,p.p_jifen,p.briefed"& LangTxt &",p.sj,p.views,p.kucun,p.p_cx_sj,p.p_stj_sj,p.p_ytj_sj,p.pic_size,p.cpic,g.price,p.IsNew,p.p_filename,bianhao"
		    .Table="[Lebi_product] as p,[Lebi_product_price] as g"
			sql = "p.zhuangtai=1 and g.product_id=p.id and g.grade_id="&Lebi_UserGrade
			rem 空格分词搜索 2008-4-11 by 56770.WangLei
			If product_name <> "" Then
					If scount = 0 Then
							sql=sql + " and ("
							If Count_SearchWords > 0 Then 
								For ii = 0 To UBound(Data_SearchWords,2)
									If keytype="1" Then sql=sql + " (p.product_name"& LangTxt &" like '%"& Data_SearchWords(0,ii) &"%' or p.bianhao like '%"& Data_SearchWords(0,ii) &"%')"
									If keytype="2" Then sql=sql + " (p.product_name"& LangTxt &" like '%"& Data_SearchWords(0,ii) &"%' or p.briefed"& LangTxt &" like '%"& Data_SearchWords(0,ii) &"%' or p.bianhao like '%"& Data_SearchWords(0,ii) &"%')"
									If ii < UBound(Data_SearchWords,2) Then 
										If Split(sys_searchwords,"|")(0) = 0 Then sql = sql + " or "
										If Split(sys_searchwords,"|")(0) = 1 Then sql = sql + " and "
									End If 
								Next 
							Else 
								pNameArr = Split(product_name," ")
								For i = 0 To Ubound(pNameArr)
									If keytype="1" Then sql=sql + " (p.product_name"& LangTxt &" like '%"& pNameArr(i) &"%' or p.bianhao like '%"& pNameArr(i) &"%')"
									if keytype="2" then sql=sql + " (product_name"& LangTxt &" like '%"& pNameArr(i) &"%' or p.briefed"& LangTxt &" like '%"& pNameArr(i) &"%' or p.bianhao like '%"& pNameArr(i) &"%')"
									if keytype="3" then sql=sql + " p.bianhao like '%"& pNameArr(i) &"%'"
									if keytype="4" then sql=sql + " p.p_tags like '%"& product_name &"%'"
									If i < UBound(pNameArr) Then sql = sql + " and "
								Next
							End If 
							sql=sql + ")"
					Else
							If keytype="1" Then sql=sql + " and (p.product_name"& LangTxt &" like '%"& product_name &"%' or p.bianhao like '%"& product_name &"%')"
							if keytype="2" then sql=sql + " and (product_name"& LangTxt &" like '%"& product_name &"%' or p.briefed"& LangTxt &" like '%"& product_name &"%' or p.bianhao like '%"& product_name &"%')"
							if keytype="3" then sql=sql + " and p.bianhao like '%"& product_name &"%'"
							if keytype="4" then sql=sql + " and p.p_tags like '%"& product_name &"%'"
					End If
			End If
            if keytype1="2" then sql=sql+ " and p.cx=1"
            if keytype1="3" then sql=sql+ " and (p.stj=1 or p.ytj=1)"
            if addtime<>"" and product_name<>"" then sql=sql+ " and "& sqlnowstring &"-p.sj<"& addtime &""
            if brand<>"" And IsSqlDataBase ="1" then sql=sql+" and CharIndex('"&brand&"',brand"& LangTxt &")>0"
	        if brand<>"" And IsSqlDataBase ="0" then sql=sql+" and instr(brand"& LangTxt &",'"&brand&"')>0"
            if sort_id<>0 and keytype<>"3" And IsSqlDataBase ="1" then sql=sql+" and CharIndex(',"& sort_id &",',p.categoryid)>0"
            if sort_id<>0 and keytype<>"3" And IsSqlDataBase ="0" then sql=sql+" and instr(p.categoryid,',"& sort_id &",')>0"
			rem	<-{  价格差联合搜索  2008-2-29 by 56770.WangLei
            if price1<>"" and price2<>"" Then
				sql=sql + " and g.price >"&price1&" and g.price <"&price2&" "
			End If
			rem	}->
			.Condition = sql
            .OrderBy="p.p_order desc,p.id desc"
	    End With
	    DataCount=ors.RecCount()
	    DataList=ors.ResultSet()
		strFile = Eshop_url& Style_Folder &"Lebi.SearchList."
		RLoadStyle(0) = splits(LoadStyle(strFile&"9.style"))	'购买按钮
		RLoadStyle(2) = splits(LoadStyle(strFile&"10.style"))	'预订按钮
		RLoadStyle(3) = splits(LoadStyle(strFile&"11.style"))	'零库存
		RLoadStyle(1) = splits(LoadStyle(strFile&"12.style"))	'收藏按钮
		LoadListStr = loop_keyword & "<form action="""" method=""post"" name=""LEBI_FORMBUY_0001"" id=""LEBI_FORMBUY_0001"">" & LoadStyle(strFile&"0.style")
		tmpstr = LoadStyle(strFile&"1.style")
		ReplaceStyle "headpage",ors.ShowPageHead("default.asp"),tmpstr
		LoadListStr = LoadListStr & tmpstr
        If DataCount > 0 Then
				LoadListStr = LoadListStr & splits(LoadStyle(strFile&"3.style")) & LoadStyle(strFile&"4.style")
				RLoadStyle(4) = splits(LoadStyle(strFile&"5.style"))
                For i = 0 To Ubound(DataList,2)
						loopstr = RLoadStyle(4)
						stock=DataList(12,i)
						tmpstr = "" : icostr = "" : PList_url = ""
		                briefed = DataList(9,i)
 						Select Case show_html
							   Case "0"
									Select Case ISAPI_Rewrite
										   Case "0" PList_url=PagePath(10) &"?id="& DataList(0,i)
										   Case "1" PList_url=LangPath &"product-"& DataList(0,i) &".html"
									End Select
							   Case "1" : PList_url=LangPath & Folder(0) & DataList(20,i) &".1."& Sys_Ext
						End Select
						icostr=""
						If Config_Lebi_Eshop(7)=1 And DataList(19,i)=1 Then
								icostr=icostr&" <img src='"& Eshop_url &"images/icons/pro_3.gif' align='absmiddle'> "
						End if
						If Config_Lebi_Eshop(5)=1 And Int(DataList(11,i))>Int(Config_Lebi_Eshop(6)) Then
								icostr=icostr&" <img src='"& Eshop_url &"images/icons/pro_2.gif' align='absmiddle'> "
						End if
						If Config_Lebi_Eshop(3)=1 And DataList(8,i)=1 Then
								icostr=icostr&" <img src='"& Eshop_url &"images/icons/pro_1.gif' align='absmiddle'> "
						End If
						If Config_Lebi_Eshop(4)=1 And (DataList(6,i)=1 Or DataList(7,i)=1) Then
								icostr=icostr&" <img src='"& Eshop_url &"images/icons/pro_4.gif' align='absmiddle'> "
						End If
						ReplaceStyle "ico",icostr,loopstr
						If Trim(DataList(2,i))<>"" Then
								tmpstr = ""
								ReplaceStyle "pic_url",PicturePath & DataList(2,i),loopstr
								ReplaceStyle "lazyload_pic_url",Eshop_url & PicturePath & DataList(2,i),loopstr
								If show_mouse = "0" Then
										If InStr(DataList(17,i),"@@") > 0 Then
												pic_url = Split(DataList(17,i),"@@")(0)
												If pic_url = "" Then pic_url = Split(DataList(17,i),"@@")(1)
										Else
												pic_url = DataList(17,i)
										End If
										tmpstr = " onMouseover=""javascript:ddrivetip('<img src="& Eshop_url & PicturePath & pic_url &" width="& pic_dw &">', '#ffffff', '"& pic_dw + 10 &"')"" onMouseout=""hideddrivetip()"""
								Else
										tmpstr = ""
								End If
								ReplaceStyle "onmouse",tmpstr,loopstr
						End If
						ReplaceStyle "url",PList_url,loopstr
						ReplaceStyle "target",Config_Lebi_Eshop(9),loopstr
						ReplaceStyle "id",DataList(0,i),loopstr
						rem <-{将搜索词着色显示 2008-8-13 by 56770.kingdge
						ReplaceStyle "searchname",StyleKeyword(DataList(1,i),product_name),loopstr
						ReplaceStyle "name",DataList(1,i),loopstr
						rem }->
						rem	  会员组价格显示 2008-2-28 by 56770.WangLei
						If checkPricePurview(Lebi_UserGrade) Then
								Select Case DataList(5,i)
									   Case "0" : ReplaceStyle "buy_price",Formatnumber2(DataList(18,i)/moneyhl),loopstr
								       Case Else
											ReplaceStyle "buy_price",Formatnumber2(DataList(4,i)/moneyhl),loopstr
								End Select
						Else
								ReplaceStyle "buy_price",Lebi_word(66),loopstr
						End If
						ReplaceStyle "market_price",Formatnumber2(DataList(3,i)/moneyhl),loopstr
						ReplaceStyle "sale_price",Formatnumber2(DataList(4,i)/moneyhl),loopstr
						ReplaceStyle "point",DataList(8,i),loopstr
						ReplaceStyle "stock",DataList(12,i),loopstr
						ReplaceStyle "content",StyleKeyword(cutchar(briefed,100),product_name),loopstr
						ReplaceStyle "bianhao",DataList(21,i),loopstr
						rem	 购买、预订、零库存 样式 by 56770.WangLei
						If InStr(loopstr,"{@btn_buy}") > 0 Then
								tmpstr = ""
								if stock <= 0 then
										Select Case CInt(getGradePurview(17))
											   Case "1" : tmpstr=tmpstr & RLoadStyle(2)	'预定
											   Case "0" : tmpstr=tmpstr & RLoadStyle(3)	'零库存
										End Select
								else
										tmpstr=tmpstr & RLoadStyle(0)	'购买
								end If
								ReplaceStyle "listcode","0001",tmpstr
								ReplaceStyle "type","",tmpstr
								ReplaceStyle "isValid",getGradePurview(0),tmpstr
								ReplaceStyle "id",DataList(0,i),tmpstr
								ReplaceStyle "btn_buy",tmpstr,loopstr
						End If
						rem	}->
						rem	 收藏按钮 by 56770.WangLei
						If InStr(loopstr,"{@btn_fav}") > 0 Then
								tmpstr = ""
								tmpstr = RLoadStyle(1)	'收藏按钮
								ReplaceStyle "id",DataList(0,i),tmpstr
								ReplaceStyle "name",DataList(1,i),tmpstr
								ReplaceStyle "backurl",Urlencode(geturl()),tmpstr
								ReplaceStyle "type","",tmpstr
								ReplaceStyle "btn_fav",tmpstr,loopstr
						End If
						rem	}->
						ReplaceStyle "loop_num",i + 1,loopstr
						LoadListStr = LoadListStr & loopstr
                Next
		Else
'				Set rs = conn.execute("select gjc"& LangTxt &" from search order by cs DESC")
'				do while not rs.eof
'						Select Case ISAPI_Rewrite
'							   Case "0" LoadListStr=LoadListStr&"<a href="""& Eshop_url & PagePath(9) &"?product_name="&Urlencode(rs(0))&"&keytype=1"" target=""_self"" title="""&rs(0)&""">"&rs(0)&"</a>&nbsp;&nbsp;|&nbsp;&nbsp;"
'							   Case "1" LoadListStr=LoadListStr&"<a href="""& Eshop_url & LangPath &"search-"&Urlencode(rs(0))&"-1.html"" target=""_self"" title="""&rs(0)&""">"&rs(0)&"</a>&nbsp;&nbsp;|&nbsp;&nbsp;"
'						End Select
'				rs.movenext
'				loop
'				rs.close:set rs=Nothing
				LoadListStr = LoadListStr & splits(LoadStyle(strFile&"2.style"))
        End If
		LoadListStr = LoadListStr & LoadStyle(strFile&"6.style")
		tmpstr = LoadStyle(strFile&"7.style")
		ReplaceStyle "footpage",ors.ShowPageFoot(Filename),tmpstr
		LoadListStr = LoadListStr & tmpstr
		LoadListStr = LoadListStr & LoadStyle(strFile&"8.style") &"</FORM>"
	    SearchList = LoadListStr
End Function

Function StyleKeyword(Name1,Name2)
		pNameArr = Split(Name2," ")
		Showname = Name1
		If Count_SearchWords > 0 Then 
			For i = 0 To UBound(Data_SearchWords,2)
				Showname = Replace(Showname,Data_SearchWords(0,i),"<$>"& Data_SearchWords(0,i) &"</$>")
			Next 
		Else 
			For i = 0 To Ubound(pNameArr)
					Showname = Replace(Showname,pNameArr(i),"<$>"& pNameArr(i) &"</$>")
			Next
		End If 
		StyleKeyword = Replace(Replace(Showname,"<$>","<span style='font-weight:bold;color:#FF0000;'>"),"</$>","</span>")
End Function
%>