<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%Option Explicit%>
<!--#include file="../Conn.asp"-->
<!--#include file="../KS_Cls/Kesion.CommonCls.asp"-->
<!--#include file="../KS_Cls/Kesion.AdministratorCls.asp"-->
<!--#include file="Include/Session.asp"-->
<%

Dim KSCls
Set KSCls = New Admin_Brand
KSCls.Kesion()
Set KSCls = Nothing

Class Admin_Brand
        Private KS,Action,ComeUrl,Page,ItemName,Table,ClassID
		Private I,totalPut,CurrentPage,KeySql,RS,MaxPerPage,KSCls
		Private Sub Class_Initialize()
		  MaxPerPage =18
		  Set KS=New PublicCls
		  Set KSCls=New ManageCls
		End Sub
        Private Sub Class_Terminate()
		 Call CloseConn()
		 Set KS=Nothing
		 Set KSCls=Nothing
		End Sub


		Public Sub Kesion()
		
		  With Response
			.Write "<html>"
			.Write "<head>"
			.Write "<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>"
			.Write "<title>收货人信息管理</title>"
			.Write "<link href='Include/Admin_Style.CSS' rel='stylesheet' type='text/css'>"
			.Write "<script language=""JavaScript"" src=""../KS_Inc/common.js""></script>" & vbCrLf
	        .Write "<script language=""JavaScript"" src=""../KS_Inc/Jquery.js""></script>" & vbCrLf
			.Write "<script src=""../ks_inc/lhgdialog.js""></script>"& vbCrLf
             Action=KS.G("Action")
			   If Not KS.ReturnPowerResult(5, "M520075") Then                  '权限检查
				Call KS.ReturnErr(1, "")   
				Response.End()
				End if
			
			CurrentPage = KS.ChkClng(KS.G("page"))
			If CurrentPage<1 Then CurrentPage = 1

			 ItemName=KS.C_S(5,3)
			 Page=KS.G("Page")
			 ClassID=KS.G("ClassID")
			 
			 Select Case Action
			  case "Add","Edit"
					call S_AddEdit()
			  case "Save"
					call S_save()
			  case "Del"
					call S_Del()	
			  Case Else
			   Call S_Main()
			 End Select
			.Write "</body>"
			.Write "</html>"
		  End With
		End Sub
			  
		Sub ShowBrandClass()
		  Dim RS:Set RS=Conn.Execute("select FolderName from ks_class c inner join ks_classbrandr r on c.id=r.classid where brandid= " & KS.ChkCLng(KS.G("ID")))
		  If Not RS.Eof Then
		   Response.Write "<div style='margin:5px'><br><strong>品牌<font color=red>" & KS.G("BrandName") & "</font>属于分类：</strong><br>"
		  Do While Not RS.Eof
		   Response.Write RS(0) & " "
		   RS.MoveNext
		  Loop
		  RS.Close:Set RS=Nothing
		  Response.Write "</div>"
		  End If
		End Sub
		
	

Sub BrandProList()
		 dim BrandID:BrandID=KS.ChkClng(request("BrandID"))
		 If BrandID=0 Then KS.Die "error"
		 
		 if request("flag")="add"  then
		   dim proids:proids=KS.FilterIds(request("prolist"))
		   If Proids<>"" then
		     conn.execute("update ks_product set brandid=" & brandid & " where id in(" & Proids & ")")
		   end if
			response.write "<script>alert('恭喜,在该品牌下加入商品成功!');location.href='?action=BrandProList&brandid=" & brandid & "';</script>"
		 end if
          
  		 Dim RS:Set rs=server.CreateObject("adodb.recordset")
	  With Response
		 	.Write "<table width='100%' border='0' cellspacing='0' cellpadding='0'>"
			.Write ("<form name='myform' method='Post' action='?'>")
	        .Write ("<input type='hidden' name='action' id='action' value='remove'>")
			.Write "        <tr>"
			.Write "          <td class=""sort"" width='35' align='center'>选择</td>"
			.Write "          <td class='sort' align='center'>小图</td>"
			.Write "          <td class='sort' align='center'>商品名称</td>"
			.Write "          <td class='sort' align='center'>会员价</td>"
			.Write "          <td class='sort' align='center'>管理操作</td>"
			.Write "  </tr>"

		 
		 RS.Open "select id,title,photourl,price_member,tid,fname from KS_Product Where BrandID=" & BrandID,conn,1,1
		  If RS.EOF And RS.Bof Then
		       .Write "<tr><td class='splittd' colspan=6>找不到属于该品牌的商品!</td></tr>"
		  Else
			   totalPut = RS.RecordCount
			   if CurrentPage >1 and (CurrentPage - 1) * MaxPerPage < totalPut Then
					RS.Move (CurrentPage - 1) * MaxPerPage
			   End If
					Do While Not RS.EOF
					 dim photourl:PhotoUrl=rs("photourl")
					 If KS.IsNul(PhotoUrl) Then PhotoUrl="../images/nopic.gif"
			          .Write "<tr onmouseout=""this.className='list'"" onmouseover=""this.className='listmouseover'"" id='u" & RS("ID") & "' onclick=""chk_iddiv('" & RS("ID") & "')"">"
			          .Write "<td class='splittd' align=center><input name='id'  onclick=""chk_iddiv('" &RS("ID") & "')"" type='checkbox' id='c"& RS("ID") & "' value='" &RS("ID") & "'></td>"
					  .write "<td class='splittd' align='center'><img style='margin:2px;border:1px solid #f1f1f1;padding:1px' src='" & photourl & "' width='40'/></td>"
					  .Write "<td class='splittd'><a href='" & KS.GetItemUrl(5,rs("tid"),rs("id"),rs("fname")) & "' target='_blank'>" & RS("title") & "</a></td>"
					  .Write "  <td class='splittd' align='center'><font color=brown>" & rs("price_member") & "</font> 元</td>"
					  .Write "  <td class='splittd' align='center'> <a href='?action=remove&id=" & rs("id") & "'>移除</a> </td>"
					  .Write "</tr>"
					  I = I + 1
					  If I >= MaxPerPage Then Exit Do
						   RS.MoveNext
					Loop
					  RS.Close
						
		      End If
			
			.Write "<tr><Td colspan=2><div style='margin:5px'><b>选择：</b><a href='javascript:Select(0)'><font color=#999999>全选</font></a> - <a href='javascript:Select(1)'><font color=#999999>反选</font></a> - <a href='javascript:Select(2)'><font color=#999999>不选</font></a> </div></td><td><input type='submit' value='批量移除' class='button'/></td></tr></form><tr><td colspan=6 align='right'>" 
			Call KS.ShowPage(totalput, MaxPerPage, "", CurrentPage,true,true)
	        .Write ("</td></tr></table><br/><br/>")
			  
			End With			   
		End Sub
 
		Sub S_Main()			
			With Response
			.Write "<body topmargin='0' leftmargin='0'  onkeydown='GetKeyDown();' onselectstart='return false;'>"
			%>


			<div class='topdashed sort' style='text-align:left'>
				<form action="?" name="myform" method="post" >
			   <div style="border:1px dashed #cccccc;margin:3px;padding:4px">
				  &nbsp;<strong>按用户搜索=></strong>
				 &nbsp;用户名:<input type="text" class='textbox' name="keyword">
				  &nbsp;<input type="submit" value="开始搜索" class="button" name="s1">
				  </div>
			</form>
			</div>
			<%
			If Not KS.IsNul(Request("keyword")) Then
			 .write "<div style='text-align:left;height:25px;line-height:25px'>搜索关键词“<font color=red>" & KS.G("keyword") & "</font>”搜索结果:</div>"
			End If
			.Write "<table width='100%' border='0' cellspacing='0' cellpadding='0'>"
			.Write ("<form name='myform' method='Post' action='?'>")
	        .Write ("<input type='hidden' name='action' id='action' value='" & Action & "'>")
			.Write "        <tr>"
			.Write "          <td class='sort' align='center' width='120'>用户名</td>"
			.Write "          <td class='sort' align='center' width='120'>收货人姓名</td>"
			.Write "          <td class='sort' align='center' width='450'>收货人地址</td>"
			.Write "          <td class='sort' align='center' width='120'>收货人邮编</td>"
			.Write "          <td align='center' class='sort' width='120'>手机号码</td>"
			.Write "          <td align='center' class='sort' >操作</td>"
			.Write "  </tr>"
			  
			  Set RS = Server.CreateObject("ADODB.RecordSet")
			  Dim Param:Param=" Where 1=1"
			  If Request("keyword")<>"" Then
			    Param=Param & " and username='"& KS.G("keyword") &"' "
			  End If
			  KeySql="Select * From KS_ShopUserOrder " & Param 
			  RS.Open KeySql, conn, 1, 1
					 If Not RS.EOF Then
						totalPut = RS.RecordCount
						If CurrentPage >1 and (CurrentPage - 1) * MaxPerPage < totalPut Then
							RS.Move (CurrentPage - 1) * MaxPerPage
						End If
						Call showContent
			  End If
			.Write "</table>"
			.Write ("<table border='0' width='100%' cellspacing='0' cellpadding='0' align='center'>")
	        .Write ("<tr>")
	        .Write ("</form><td align='right'>")
			Call KS.ShowPage(totalput, MaxPerPage, "", CurrentPage,true,true)
	        .Write ("</td></tr></table><br/><br/>")
            End With
			End Sub
			
			Sub showContent()
			   With Response
					Do While Not RS.EOF
					  .Write "<td class='splittd' height='20' align='center'><img src='Images/ico/unverify.gif' align='absmiddle'>"
					  .Write "  <span style='cursor:default;'>" & RS("username") & "</span></td>"
					   .Write "  <td class='splittd' align='center'>" &RS("ContactMan") &"</td>"
					  .Write "  <td class='splittd' align='center'>" &rs("Address") &"</td>"
					  .Write "  <td class='splittd' align='center'> "& rs("ZipCode") &"</td>"
					  .Write "  <td class='splittd' align='center'> "& rs("Mobile") &"</td>"
					.Write "  <td class='splittd' align='center'> "
					 %>
					 	<a href="KS.ShopUserOrder.asp?Action=Edit&id=<%=rs("id")%>&page=<%=CurrentPage%>" >修改</a>
			<a href="javascript:;" onclick = "$.dialog.confirm('确定删除信息吗?',function(){location.href='KS.ShopUserOrder.asp?Action=Del&id=<%=rs("id")%>&page=<%=CurrentPage%>';},function(){})" >删除</a>
					 <%
					 .Write "  </td> "
					  .Write "</tr>"
					  I = I + 1
					  If I >= MaxPerPage Then Exit Do
						   RS.MoveNext
					Loop
					  RS.Close
				End With
			End Sub
			
			Sub S_AddEdit()
			dim RS,ContactMan,Address,ZipCode,Mobile,Phone,Email,QQ
			if KS.G("action")="Edit" then
				Set RS=Server.CreateObject("ADODB.RECORDSET")
				RS.Open "Select top 1 * From KS_ShopUserOrder where  id="& KS.ChkClng(KS.G("id")) ,conn,1,1
				If not RS.EOF And  not RS.BOF Then
					ContactMan=rs("ContactMan")
					Address=rs("Address")
					ZipCode=rs("ZipCode")
					Mobile=rs("Mobile")
					Email=rs("Email")
					QQ=rs("QQ")
					Phone=rs("Phone")
				end if
				Rs.close: Set RS = Nothing
			end if
			
			%>
			<script type="text/javascript">
			  function CheckForm() 
				{ 
				  if ($("#ContactMan").val()==""){
				   alert('请输入收货人姓名!');
				   $("#ContactMan").focus();
				   return false;}
				  if ($("#Address").val()==""){
				   alert('请输入收货人地址!');
				   $("#Address").focus();
				   return false; }
				  if ($("#ZipCode").val()==""){
				   alert('请输入收货人邮编!');
				   $("#ZipCode").focus();
				   return false; }
				  if ($("#Phone").val()==""&&$("#Mobile").val()==""){
				   alert('收货人手机或电话至少要填一个!');
				   $("#Mobile").focus();
				   return false;}
				  if ($("#Email").val()==""){
				   alert('请输入收货人邮箱!');
				   $("#Email").focus();
				   return false;}
				  if ($("#mustyf").val()==1){
					if ($("#tocity").val()==''){
				   alert('请选择送货地区!');
				   return false;}
				  }
				  $("#myform").submit();
				}
			</script>
			  <div class="topdashed sort">请填写收货信息</div>

			  <FORM name="myform" id="myform"  action="KS.ShopUserOrder.asp?action=Save" method="post">
			  <input type="hidden" name="AddEdit" value="<%=KS.G("action")%>" />
			  <input type="hidden" name="id" value="<%=KS.G("id")%>" />
			  <input type="hidden" name="page" value="<%=KS.S("page")%>" />
			  <table cellSpacing=1 cellPadding=3 width="98%" align=center border=0 style="margin:10px;">
       
                          <tr class=tdbg>
                              <td align=right width=100>收货人姓名：</td>
                              <td><INPUT class="textbox"  maxLength=50 value="<%=ContactMan%>" name="ContactMan" id="ContactMan">* </td>
                          </tr>
                          <tr class=tdbg>
                             <td align=right width=100>收货人地址：</td>
                             <td><INPUT class="textbox" maxLength=255 size=60 value="<%=Address%>" name="Address" id="Address">*</td>
                           </tr>
                           <tr class=tdbg>
                             <td align=right width=100>收货人邮编：</td>
                             <td height=20><INPUT class="textbox" maxLength=6 value="<%=ZipCode%>" name="ZipCode" id="ZipCode">* </td>
                           </tr>
                           <tr class=tdbg>
                             <td align=right width=100>手机号码：</td>
                             <td><INPUT class="textbox" maxLength=50 size=20 value="<%=Mobile%>" name="Mobile" id="Mobile">
                                                或固定电话<INPUT maxLength=50 class="textbox" size=20 value="<%=Phone%>" name="Phone" id="Phone">*<span class='tips'>两个至少填一个</span> </td>
                            </tr>
                            <tr class=tdbg>
                              <td align=right width=100>收货人邮箱：</td>
                              <td height=20><INPUT class="textbox" maxLength=100 size=30 value="<%=Email%>" name=Email id="Email">*</td>
                            </tr>
                            <tr class=tdbg>
                               <td align=right>收货人QQ：</td>
                               <td><INPUT class="textbox" maxLength=50 size=30 value="<%=QQ%>" name="QQ" id="QQ"></td>
                            </tr>
				 </table>
				 <div align="center"><button class="pn" type="button" onClick="return CheckForm();" name="Submit"><strong> OK,保存信息 </strong></button></div>
				 </FORM>
			<%
		 End Sub
		 Sub S_save ()
			dim RS
			Set RS=Server.CreateObject("ADODB.RECORDSET")
			RS.Open "Select top 1 * From KS_ShopUserOrder where id="& KS.ChkClng(KS.G("id")) ,conn,1,3
			rs("ContactMan")=KS.G("ContactMan")
			rs("Address")=KS.G("Address")
			rs("ZipCode")=KS.G("ZipCode")
			rs("Mobile")=KS.G("Mobile")
			rs("Email")=KS.G("Email")
			rs("QQ")=KS.G("QQ")
			rs("Phone")=KS.G("Phone")
			Rs.update
			Rs.close: Set RS = Nothing
			Response.Write "<script>$.dialog.tips('恭喜，信息修改成功！',1,'success.gif',function(){location.href='KS.ShopUserOrder.asp?page="& KS.S("page") &"';});</script>"
		 End Sub
		 Sub S_Del()
		 	if KS.ChkClng(KS.G("id"))<>0 then
				Conn.Execute("Delete  from KS_ShopUserOrder where id ="&KS.ChkClng(KS.G("id")) )
				Response.Write "<script>location.href='KS.ShopUserOrder.asp?page="& KS.S("page") &"'</script>"
			end if
		 End sub
			
			
			
			
			
			
			Sub BrandAddOrEdit(OpType)
			With Response
			 Dim RS,Action, BrandName,BrandEName ,ID, PageRS, KeySql,Page,ClassID,OrderID,ShowInTop,Recommend,PhotoUrl,Intro,firstAlphabet
			  ID = KS.G("ID")
			  Page = KS.G("Page")
			 If OpType = "Edit" Then
				 Set RS = Server.CreateObject("ADODB.RECORDSET")
				 KeySql = "Select * From [KS_ClassBrand] Where ID=" & ID
				 RS.Open KeySql, conn, 1, 1
				 If Not RS.EOF Then 
				  BrandName = RS("BrandName")
				  BrandEname=RS("BrandEname")
				  firstAlphabet=RS("firstAlphabet")
				  Intro=RS("Intro")
				  OrderID = RS("OrderID")
				  ShowInTop=RS("ShowInTop")
				  Recommend=RS("Recommend")
				  PhotoUrl=RS("PhotoUrl")
				 End If
				 RS.Close:Set RS=Nothing
			 Else
			   ShowInTop=1:Recommend=0:orderid=1:classid=ks.g("classid"):ID=0
			   orderid=KS.ChkClng(conn.execute("select max(orderid) from ks_classbrand ")(0))+1
			 End If
			.Write"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">"
			.Write "<html xmlns=""http://www.w3.org/1999/xhtml"">"
		    .Write "<script type=""text/javascript"" src=""../editor/ckeditor.js"" mce_src=""../editor/ckeditor.js""></script>"
			.Write "<ul id='menu_top'>"
			.Write "<li class='parent' onclick=""return(CheckForm())""><span class=child onmouseover=""this.parentNode.className='parent_border'"" onMouseOut=""this.parentNode.className='parent'""><img src='images/ico/save.gif' border='0' align='absmiddle'>确定保存</span></li>"
			.Write "<li class='parent' onclick=""location.href='?';""><span class=child onmouseover=""this.parentNode.className='parent_border'"" onMouseOut=""this.parentNode.className='parent'""><img src='images/ico/back.gif' border='0' align='absmiddle'>取消返回</span></li>"
		    .Write "</ul>"
			.Write "<script language='JavaScript' src='../KS_Inc/common.js'></script>"
			.Write "<br>" & vbCrLf
			.Write "<table width='99%' class='ctable' border='0' align='center' cellpadding='0' cellspacing='0'>" & vbCrLf
			.Write "  <form  action='?Action=DoSave' method='post' name='BrandForm' onsubmit='return(CheckForm())'>" & vbCrLf
			.Write "    <tr class='tdbg'>" & vbCrLf
			.Write "      <td width='23%' class='clefttitle' align='right' nowrap>品牌名称：</td>" & vbCrLf
			.Write "      <td width='74%' height='30' nowrap>&nbsp;<b>" & vbCrLf
			.Write "        <input name='BrandName' type='text' id='BrandName' value='" & BrandName & "' class='textbox'>" & vbCrLf
			.Write "        </b>* 如三星，飞利浦等</td>" & vbCrLf
			.Write "    </tr>" & vbCrLf
			.Write "    <tr class='tdbg'>" & vbCrLf
			.Write "      <td width='23%' class='clefttitle' align='right' nowrap>品牌英文名称：</td>" & vbCrLf
			.Write "      <td width='74%' height='30' nowrap>&nbsp;<b>" & vbCrLf
			.Write "        <input name='BrandEName' type='text' id='BrandEName' value='" & BrandEName & "' class='textbox'>" & vbCrLf
			.Write "        </b>* 如SamSung等</td>" & vbCrLf
			.Write "    </tr>" & vbCrLf
			.Write "    <tr class='tdbg'>" & vbCrLf
			.Write "      <td width='23%' class='clefttitle' align='right' nowrap>品牌首字母：</td>" & vbCrLf
			.Write "      <td width='74%' height='30' nowrap>&nbsp;<b>" & vbCrLf
			.Write "        <Select name='firstAlphabet' id='firstAlphabet'>"
			Dim I
			For I=65 To 90
				If firstAlphabet=chr(I) Then
				.Write "<option value='" & I& "' selected>" & chr(I) &"</option>"
				Else
				.Write "<option value='" & I& "'>" & chr(I) &"</option>"
				End If
			Next
			
			.Write "        </select>" & vbCrLf
			.Write "        </b>* 方便前台按字母查找品牌</td>" & vbCrLf
			.Write "    </tr>" & vbCrLf
			
			
			.Write "    <tr class='tdbg'>" & vbCrLf
			.Write "      <td align='right' class='clefttitle'>绑定分类：<br><br><font color=red>当一个品牌有多个分类时，可以按ctrl键进行多选</a></td>" & vbCrLf
			.Write "      <td height='30' nowrap>&nbsp;"
			.Write " <select size='20' style='width:280px' multiple name='classid'>"
			Dim C_L_Str:C_L_Str=KS.LoadClassOption(5,false)
			If ID<>0 Then
				Dim RSB:Set RSB=Conn.Execute("Select ClassID From KS_ClassBrandR Where BrandID=" & ID)
				iF Not RSB.Eof Then
				  Do While Not RSB.Eof
				  C_L_Str=Replace(C_L_Str,"value='" & RSB(0) & "'","value='" & RSB(0) &"' selected")
				  RSB.MoveNext
				  Loop
				End If
				RSB.Close:Set RSB=Nothing
			End If
			.Write C_L_Str & " </select>"
			.Write "</td>" & vbCrLf
			.Write "    </tr>" & vbCrLf
			.Write "    <tr class='tdbg'>" & vbCrLf
			.Write "      <td width='23%' class='clefttitle' align='right' nowrap>品牌介绍：</td>" & vbCrLf
			.Write "      <td width='74%' height='30' nowrap>&nbsp;<textarea ID='Intro' name='Intro' style='display:none'>" & KS.HTMLCode(Intro) & "</textarea>"
			.Write "<script type=""text/javascript"">"
            .Write "CKEDITOR.replace('Intro', {width:""98%"",height:""160px"",toolbar:""Basic"",filebrowserBrowseUrl :""Include/SelectPic.asp?from=ckeditor&Currpath="& KS.GetUpFilesDir() &""",filebrowserWindowWidth:650,filebrowserWindowHeight:290});"
			.Write "</script> </td>" & vbCrLf
			.Write "    </tr>" & vbCrLf			
			
			.Write "    <tr class='tdbg'>" & vbCrLf
			.Write "      <td width='23%' class='clefttitle' align='right' nowrap>品牌图片：</td>" & vbCrLf
			.Write "      <td width='74%' height='30' nowrap>&nbsp;<b>" & vbCrLf
			.Write "        <input name='PhotoUrl' type='text' value='" & PhotoUrl & "' class='textbox'>&nbsp;<input class=""button"" type='button' name='Submit' value='选择图片...' onClick=""OpenThenSetValue('Include/SelectPic.asp?ChannelID=5&CurrPath=" & KS.GetUpFilesDir() & "',550,290,window,document.BrandForm.PhotoUrl);""> " & vbCrLf
			.Write "        </b> </td>" & vbCrLf
			.Write "    </tr>" & vbCrLf			
			.Write "    <tr class='tdbg'>" & vbCrLf
			.Write "      <td width='23%' class='clefttitle' align='right' nowrap>排 序 号：</td>" & vbCrLf
			.Write "      <td width='74%' height='30' nowrap>&nbsp;<b>" & vbCrLf
			.Write "        <input name='OrderID' type='text' value='" & OrderID & "' class='textbox'>" & vbCrLf
			.Write "        </b>*数据越小，前台排在越前面 </td>" & vbCrLf
			.Write "    </tr>" & vbCrLf
			.Write "    <tr class='tdbg' style='display:none'>" & vbCrLf
			.Write "      <td width='23%' class='clefttitle' align='right' nowrap>是否顶级树型菜单显示：</td>" & vbCrLf
			.Write "      <td width='74%' height='30' nowrap>&nbsp;" & vbCrLf
			.Write "        <input name='ShowInTop' type='radio' value='1'"
			If ShowInTop="1" Then .Write " checked"
			.Write ">是" & vbCrLf
			.Write "        <input name='ShowInTop' type='radio' value='0'"
			If ShowInTop="0" Then .Write " checked"
			.Write ">否" & vbcrlf 
			.Write "        </td>" & vbCrLf
			.Write "    </tr>" & vbCrLf
			.Write "    <tr class='tdbg'>" & vbCrLf
			.Write "      <td width='23%' class='clefttitle' align='right' nowrap>是否推荐：</td>" & vbCrLf
			.Write "      <td width='74%' height='30' nowrap>&nbsp;" & vbCrLf
			.Write "        <input name='Recommend' type='radio' value='1'"
			If Recommend="1" Then .Write " checked"
			.Write ">是" & vbCrLf
			.Write "        <input name='Recommend' type='radio' value='0'"
			If Recommend="0" Then .Write " checked"
			.Write ">否" & vbcrlf 
			.Write "       </td>" & vbCrLf
			.Write "    </tr>" & vbCrLf
			
			
			.Write "    <input type='hidden' value='" & ID & "' name='ID'>" & vbCrLf
			.Write "    <input type='hidden' value='" & Page & "' name='Page'>" & vbCrLf
			.Write "  </form>" & vbCrLf
			.Write "</table>" & vbCrLf

			.Write "<Script Language='javascript'>" & vbCrLf
			.Write "<!--" & vbCrLf
			.Write "function CheckForm()" & vbCrLf
			.Write "{ var form=document.BrandForm;" & vbCrLf
			.Write "   if (form.BrandName.value=='')" & vbCrLf
			.Write "    {" & vbCrLf
			.Write "     alert('请输入品牌!');" & vbCrLf
			.Write "     form.BrandName.focus();" & vbCrLf
			.Write "     return false;" & vbCrLf
			.Write "    }" & vbCrLf
			.Write "    form.submit();" & vbCrLf
			.Write "    return true;" & vbCrLf
			.Write "}" & vbCrLf
			.Write "//-->" & vbCrLf
			.Write "</Script>" & vbCrLf
			.Write "</body>" & vbCrLf
			.Write "</html>" & vbCrLf
			End With
			End Sub

			
			Sub DoSave()
			    Dim RS,ClassID,ClassID_Arr,ID,K
				Dim  BrandName:BrandName = KS.G("BrandName")
				ID=KS.ChkClng(KS.G("ID"))
				 ClassID=Replace(KS.G("ClassID")," ","")
				 If BrandName = "" Then Call KS.AlertHistory("请输入品牌名称!", -1)
				 If ClassID="" Then Call KS.AlertHistory("请选择品牌归属分类！",-1)
				 ClassID_Arr=Split(ClassID,",")
				  If not Conn.Execute("Select ID From KS_ClassBrand Where ID<>" & ID & " and BrandName='" & BrandName & "'").eof Then Call KS.AlertHistory("您输入的品牌名称已存在！",-1)
				  
				 Set RS = Server.CreateObject("ADODB.RECORDSET")
				  KeySql = "Select * From [KS_ClassBrand] Where ID=" & ID
				 RS.Open KeySql, conn, 1, 3
				 If RS.EOF And RS.BOF Then
				  RS.AddNew
				 End If
				  RS("BrandName") = BrandName
				  RS("OrderID")=KS.ChkClng(KS.G("OrderID"))
				  RS("ShowInTop")=KS.ChkClng(KS.G("ShowIntop"))
				  RS("PhotoUrl")=KS.G("PhotoUrl")
				  RS("Recommend")=KS.ChkClng(KS.G("Recommend"))
				  RS("Intro")=Request.Form("Intro")
				  RS("firstAlphabet")=Chr(request("firstAlphabet"))
				  RS("BrandEName")=Request("BrandEname")
				  RS.Update
				  If ID=0 Then
				    RS.MoveLast
				    ID=RS("ID")
					RS.Close
					For K=0 To Ubound(ClassID_Arr)
					 Conn.Execute("Insert Into KS_ClassBrandR(ClassID,BrandID) values('" & ClassID_Arr(K) & "'," & ID & ")")
					Next
					Call KS.CreateBrandCache()
                    Call KS.FileAssociation(1003,ID,Request.Form("Intro")&KS.G("PhotoUrl"),0)
				  Response.Write ("<Script> if (confirm('品牌增加成功,继续添加吗?')) { location.href='?classid=" & KS.G("ClassID") &"&Action=Add';} else{location.href='?Page=" & Page &"';$(parent.document).find('#BottomFrame')[0].src='KS.Split.asp?OpStr="& server.URLEncode(ItemName & "管理中心 >> 品牌管理")+"&ButtonSymbol=Disabled';}</script>")
				  Else
				   
					Conn.Execute("Delete From KS_ClassBrandR Where BrandID=" & ID)
					For K=0 To Ubound(ClassID_Arr)
					 Conn.Execute("Insert Into KS_ClassBrandR(ClassID,BrandID) values('" & ClassID_Arr(K) & "'," & RS("ID") & ")")
					Next
					 Call KS.CreateBrandCache()
					 Call KS.FileAssociation(1003,ID,Request.Form("Intro")&KS.G("PhotoUrl"),1)
				     Response.Write ("<Script>alert('恭喜，品牌修改成功！'); location.href='?Page=" & Page &"';$(parent.document).find('#BottomFrame')[0].src='KS.Split.asp?OpStr="& server.URLEncode(ItemName & "管理中心 >> 品牌管理")+"&ButtonSymbol=Disabled';</script>")
				  End If
			End Sub
			
			Sub BrandDel()
			  Dim ID,Page
			  Page=KS.G("Page")
			  ID = KS.G("ID")
			  ID = Replace(ID, " ", "")
			  Conn.Execute("Delete From [KS_UploadFiles] Where ChannelID=1003 And InfoID in(" & ID & ")")
			  Conn.Execute("Delete from [KS_ClassBrand] Where ID in(" & ID & ")")
			  Conn.Execute("Delete From [KS_ClassBrandR] Where BrandID in(" & ID & ")")
			  Call KS.CreateBrandCache()
			  Response.Redirect "?Page=" & Page
			End Sub
			
			Sub CreateJS()
				Response.Write "<div class='topdashed' style='text-align:center'>"
				Response.Write "<b>生成品牌树型菜单</b>"		
				Response.Write "</div>"
				Response.Write "<form method='POST' action='?Action=SaveCreateJS' id='myform' name='myform'>"
				Response.Write "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1'>"
				Response.Write "  <tr  class='title'>"
				Response.Write "    <td height='22' colspan='6'><strong>品牌树型菜单参数设置</strong> </td>"
				Response.Write "  </tr>"
				Response.Write "  <tr class='tdbg'> "
				Response.Write "    <td width='130' height='25' class='clefttitle'><strong>选择频道：</strong></td>"
				Response.Write "    <td>"
				Response.Write ReturnAllChannel()
				Response.Write "    </td>"
				Response.Write " </tr>"
				Response.Write " <tr class='tdbg' style='display:none'>"
				Response.Write "    <td width='130' height='25' class='clefttitle'><strong>生成样式：</strong></td>"
				Response.Write "    <td>"
				Response.Write "      <select name='fsostyle' onchange=""if (this.value==2) document.all.cols.style.display='';else document.all.cols.style.display='none';"">"
				Response.Write "        <option value=1>样式一</option>"
				Response.Write "        <option value=2>样式二</option>"
				Response.Write "      </select>"
				Response.Write "    </td>"
				Response.Write "</tr>"
				Response.Write "<tbody id='cols' style='display:none'>"
				Response.Write " <tr class='tdbg'>"
				Response.Write "    <td width='130' height='25' class='clefttitle'><strong>生成列数：</strong></td>"
				Response.Write "    <td>"
				Response.Write "      <input type='text' name='col' value='1' size=""6"">列"
				Response.Write "    </td>"
				Response.Write "</tr>"
				Response.Write "</tbody>"
				Response.Write "<tr class='tdbg'>"
				Response.Write "    <td width='130' height='25' class='clefttitle'><strong>生成文件名：</strong></td>"
				Response.Write "    <td>"
				Response.Write "      <input name='JsFileName' type='text' id='JsFileName' value='Brand.js' size='10' maxlength='10'>"
				Response.Write "    </td>"
				Response.Write "  </tr>"
				Response.Write "</table>"
				Response.Write "<br><div style='text-align:center'><input type='submit' name='Submit' value=' 生成树型导航 ' class='button'></div>"
				Response.Write "</form>"
			End Sub
			
			'取得网站的所有频道及其子栏目
			Function ReturnAllChannel()
				  Dim SQL,K,ChannelStr
				   ChannelStr = "<select class='textbox' name=""ChannelID"" style=""width:200;border-style: solid; border-width: 1""><option value='0'>不指定栏目（默认）</option>"
						ChannelStr=ChannelStr & KS.LoadClassOption(5,false)
				   ReturnAllChannel = ChannelStr &"</select>"
			End Function
			
			Sub SaveCreateJS()
				Call KS.WriteTOFile(KS.Setting(3) & KS.Setting(93) & KS.G("JsFileName"), HtreeList)
				Response.Write "<br><table width='100%' border='0' cellspacing='1' cellpadding='2' class='ctable'>"
				Response.Write "  <tr class='sort'>"
				Response.Write "    <td height='22' align='center'><strong> 生 成 树 形 导 航 菜 单 </strong></td>"
				Response.Write "  </tr>"
				Response.Write "  <tr class='tdbg'>"
				Response.Write "    <td height='150'>"
				Response.Write "<br><p align='center'><font color=red><b>恭喜您！品牌树形导航菜单成功生成,请按以下提示完成最好操作。</b></font></p>"
				Response.Write "<p><b>将以下代码复制到在模板里要显示的地方。</b></p>"
				Response.Write "<input name='s2' value='&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot; src=&quot;" & KS.Setting(3) & KS.Setting(93) & KS.G("JsFileName") & "&quot;&gt;&lt;/script&gt;' size='80'>&nbsp;<input class=""button"" onClick=""jm_cc('s2')"" type=""button"" value=""复制到剪贴板"" name=""button1"">"
				Response.Write "    </td>"
				Response.Write "  </tr>"
				Response.Write "</table>"
			 %>
			 <script>
			function jm_cc(ob)
			{
				var obj=MM_findObj(ob); 
				if (obj) 
				{
					obj.select();js=obj.createTextRange();js.execCommand("Copy");}
					alert('复制成功，粘贴到你要调用的模板里即可!');
				}
				function MM_findObj(n, d) { //v4.0
			  var p,i,x;
			  if(!d) d=document;
			  if((p=n.indexOf("?"))>0&&parent.frames.length)
			   {
				d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
			   }
			  if(!(x=d[n])&&d.all) x=d.all[n];
			  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
			  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
			  if(!x && document.getElementById) x=document.getElementById(n); return x;
			}
			  </script>
			 <%
			End Sub
			
			Function EncodeJS(str)
			EncodeJS = Replace(Replace(Replace(Replace(Replace(str, Chr(10), ""), "\", "\\"), "'", "\'"), vbCrLf, "\n"), Chr(13), "")
			End Function
			
			Function HtreeList()
			   Dim RS,TreeStr,ID,i,Param,ChannelID
			   ChannelID=KS.S("ChannelID")
			   Param=" Where ChannelID=5"
				If KS.S("ChannelID")="0" Then  
				 Param=Param & " and tj=1"
				Else
				 Param=Param & " and TN='" & ChannelID & "'"
				End If
				Set  RS=Server.CreateObject("ADODB.Recordset")
				RS.Open ("select ID,FolderName,ClassID from KS_Class "  & Param & " Order BY FolderOrder ASC"), Conn, 1, 1
						TreeStr=TreeStr & "document.writeln('<table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""3"">');" & vbcrlf
						Do While Not RS.EOF
						  TreeStr=TreeStr & "document.writeln('<tr>');" & vbcrlf
						  For I=1 To KS.ChkClng(KS.G("Col"))
						   TreeStr = TreeStr & "document.writeln('<td valign=""top"" width=""" & 100 / KS.ChkCLng(KS.G("Col")) & "%"">');" & vbcrlf
						   TreeStr = TreeStr & "document.writeln('<div class=""classtitle"" style=""font-weight:bold""><img src=""" & KS.Setting(3) & "images/gw12.gif"" align=""absmiddle"">&nbsp;<a href=""" & KS.GetDomain & "shop/showbrand.asp?id=" & rs(2) & """>" & rs(1)& "</a></div>');" & vbnewline 
						   TreeStr = TreeStr & SubList(RS(0),RS(2))
						   TreeStr = TreeStr & "document.writeln('</td>');" & vbcrlf
						   RS.MoveNext
						   If RS.EOF Then Exit For
						  Next
						   TreeStr = TreeStr & "document.writeln('</tr>');" & vbcrlf
						  if rs.eof then exit do
						Loop
						TreeStr =TreeStr & "document.writeln('</table>');" & vbcrlf
						RS.Close:Set RS=Nothing
				HtreeList=TreeStr
			End Function	
			
			Function SubList(TID,ClassID)
			  Dim RS:Set RS=Conn.Execute("select top 20 b.id,brandname from ks_classbrand b inner join ks_classbrandr r on b.id=r.brandid where r.classid ='" & TID & "' order by b.orderid")
			  Dim SQL,I
			  If Not RS.Eof Then
				 SQL=RS.GetRows(-1)
				 SubList="document.writeln('<div class=""list"">"
				 For I=0 To Ubound(SQL,2)
				   SubList=SubList & "<a href=""" & KS.Setting(3) & "shop/Search_list.asp?id=" & ClassID & "&brandid=" & SQL(0,I) & """ target=""_blank"">" & SQL(1,I) & "</a>&nbsp;"
				   If I <> Ubound(SQL,2) Then SubList=SubList & "<img src=""" & KS.Setting(3) & "images/nl.gif"" align=""absmiddle"">&nbsp;"
				   
				 Next
				 SubList=SubList & "</div>');"& vbcrlf
			  End IF
			  RS.Close:Set RS=Nothing
			End Function 

End Class
%>
 
