<%
'--JinCms Callings
'--Last Update:2015-03-13
'--My WebSite:www.oywork.com

'数组去重复（判断一级分类下有哪些分类类型）
Function MoveR(Rstr) 
	Dim i,SpStr 
	SpStr = Split(Rstr,",") 
	For i = 0 To Ubound(Spstr) 
	If I = 0 then 
	MoveR = MoveR & SpStr(i) & "," 
	Else 
	If instr(MoveR,SpStr(i))=0 and i=Ubound(Spstr) Then 
	MoveR = MoveR & SpStr(i) 
	Elseif instr(MoveR,SpStr(i))=0 Then 
	MoveR = MoveR & SpStr(i) & "," 
	End If 
	End If 
	Next 
End Function 

'/////////////////////////////////////////////////		分类相关调用		///////////////////////////////////////////////
'多级联动分类
Sub getClassByselect(moduleid,classtype,curid,num)
	If curid<>"" Then
	parentstr=getTbValue("parentstr",2,"ID",curid,0)
	parent=split(parentstr,",")
	If ubound(parent)=0 and parent(0)=0 then parent1=curid:parent2="":parent3="":parent4=""
	If ubound(parent)=0 and parent(0)<>0 then parent1=parent(0):parent2=curid:parent3="":parent4=""
	If ubound(parent)=1 then parent1=parent(0):parent2=parent(1):parent3=curid:parent4=""
	If ubound(parent)=2 then parent1=parent(0):parent2=parent(1):parent3=parent(2):parent4=curid
	If ubound(parent)=3 then parent1=parent(0):parent2=parent(1):parent3=parent(2):parent4=parent(3):parent5=curid
	End IF
	'If ubound(parent)=0 then parent1=curid:parent2="":parent3="":parent4=""

%>
	<script LANGUAGE="javascript">
	subcity = new Array();
	<%
	Dim counti
	set Rs4=server.createobject("adodb.recordset")
	sql="SELECT * FROM Jin_Class WHERE ModuleID="&moduleid&" and Depth<>0 and ShowNav ORDER BY RootID,OrdeRs"
	Rs4.open sql,conn,3,3
	counti=0
	Do While Not Rs4.Eof
	If Instr(Rs4("ClassType"),classtype)>0 Then	
	Response.Write "subcity[" & counti & "] = new Array(""" &Rs4("ParentID") & """,""" &Rs4("ClassName") & """,""" &Rs4("ID") & """);" & Chr(10)
	counti=counti+1
	End If
	Rs4.MoveNext
	Loop
	Rs4.close
	set Rs4=nothing
	%>
	function mychange(provalue) {					
	document.form1.fenlei1.length = 0;				
	document.form1.fenlei2.length = 0;				
	document.form1.fenlei3.length = 0;				
	document.form1.fenlei4.length = 0;				
	document.form1.fenlei1.options[0] = new Option('请选择二级分类','');
	var i; 
	for (i=0;i < subcity.length; i++)				
	{ 
	if (subcity[i][0] == provalue)			
	{  
	document.form1.fenlei1.options[document.form1.fenlei1.length] = new Option(subcity[i][1],subcity[i][2]); 
	}         
	} 
	}  
	//////////////////////////////////////////
	function mychange1(provalue) {					
	document.form1.fenlei2.length = 0;			
	document.form1.fenlei3.length = 0;				
	document.form1.fenlei4.length = 0;				
	document.form1.fenlei2.options[0] = new Option('请选择三级分类','');
	var i; 
	for (i=0;i < subcity.length; i++)				
	{ 
	if (subcity[i][0] == provalue)			
	{  
	document.form1.fenlei2.options[document.form1.fenlei2.length] = new Option(subcity[i][1],subcity[i][2]); 
	}         
	} 
	}  
	//////////////////////////////////////////
	function mychange2(provalue) {					
	document.form1.fenlei3.length = 0;			
	document.form1.fenlei4.length = 0;				
	document.form1.fenlei3.options[0] = new Option('请选择四级分类','');
	var i; 
	for (i=0;i < subcity.length; i++)				
	{ 
	if (subcity[i][0] == provalue)			
	{  
	document.form1.fenlei3.options[document.form1.fenlei3.length] = new Option(subcity[i][1],subcity[i][2]); 
	}         
	} 
	}    
	//////////////////////////////////////////
	function mychange3(provalue) {					
	document.form1.fenlei4.length = 0;				
	document.form1.fenlei4.options[0] = new Option('请选择五级分类','');
	var i; 
	for (i=0;i < subcity.length; i++)				
	{ 
	if (subcity[i][0] == provalue)			
	{  
	document.form1.fenlei4.options[document.form1.fenlei4.length] = new Option(subcity[i][1],subcity[i][2]); 
	}         
	} 
	}    
	</script>	
    
    <select class="jinselect left" name="fenlei" onChange="mychange(this.options[this.selectedIndex].value);" datatype="*" nullmsg="请选择详细分类！">
    <%if parent1<>"" then%><option value="<%=parent1%>"><%=getTbValue("ClassName",2,"ID",parent1,0)%></option><%end if%>
    <option value="">请选择一级分类</option>
    <%
    set Rs1=server.createobject("adodb.recordset")
    sql="SELECT * FROM Jin_Class WHERE ModuleID="&moduleid&" and Depth=0 and ShowNav ORDER BY RootID,OrdeRs"
    Rs1.open sql,conn,1,1
    do until Rs1.eof
		'获取一级分类下存在的所有分类类型
		set Rsa=server.createobject("adodb.recordset")
		sqla="SELECT ClassType FROM Jin_Class WHERE ModuleID="&moduleid&" and id in ("&Rs1("ChildStr")&") ORDER BY RootID,OrdeRs"
		Rsa.open sqla,conn,1,1
		ClassTypeAll="Default"
		do until Rsa.eof
		ClassTypeAll=ClassTypeAll&","&Rsa("ClassType")
		Rsa.movenext
		loop
		Rsa.close
		set Rsa=nothing
		ClassTypeAll=MoveR(ClassTypeAll)	'ClassTypeAll表示一级分类下存在的所有分类类型
	If Instr(ClassTypeAll,classtype)>0 Then			'如果一级分类下有子分类是我们调用的类型，则显示一级分类
    %>
    <option value="<%=Rs1("ID")%>"><%=Rs1("ClassName")%></option>
    <%
	End If
    Rs1.movenext
    loop
    Rs1.close
    set Rs1=nothing
    %>
    </select>
    <select class="jinselect left <%If clng(num)<2 then%>hidden<%end if%>" name="fenlei1" onChange="mychange1(this.options[this.selectedIndex].value);">
    <%if parent2<>"" then%><option value="<%=parent2%>"><%=getTbValue("ClassName",2,"ID",parent2,0)%></option><%end if%>
    <option value="">请选择二级分类</option>
    </select>	
    <select class="jinselect left <%If clng(num)<3 then%>hidden<%end if%>" name="fenlei2" onChange="mychange2(this.options[this.selectedIndex].value);">
    <%if parent3<>"" then%><option value="<%=parent3%>"><%=getTbValue("ClassName",2,"ID",parent3,0)%></option><%end if%>
    <option value="">请选择三级分类</option>
    </select>	
    <select class="jinselect left <%If clng(num)<4 then%>hidden<%end if%>" name="fenlei3" onChange="mychange3(this.options[this.selectedIndex].value);">
	<%if parent4<>"" then%><option value="<%=parent4%>"><%=getTbValue("ClassName",2,"ID",parent4,0)%></option><%end if%>
    <option value="">请选择四级分类</option>
    </select>	
    <select class="jinselect left <%If clng(num)<5 then%>hidden<%end if%>" name="fenlei4">
	<%if parent5<>"" then%><option value="<%=parent5%>"><%=getTbValue("ClassName",2,"ID",parent5,0)%></option><%end if%>
    <option value="">请选择五级分类</option>
    </select>	
<%End Sub%>


<%
'无限级栏目下拉框调用
'Design by Jin at 2014-10-13 12:45
Sub getclass(moduleid,selectname,curclassid,classtype,classname)
	SQLc = "SELECT * FROM Jin_Class WHERE ModuleID="&moduleid&" and ClassType = '"&classtype&"' ORDER BY RootID,OrdeRs"
	Set Rsc = Server.CreateObject("ADODB.Recordset")
	Rsc.Open SQLc, Conn, 1, 1
	SqlQueryNum = SqlQueryNum + 1
	If Rsc.BOF And Rsc.EOF Then
		Response.Write "" '您还没有添加任何分类
	End If
	response.Write("<select name="&selectname&" class="&classname&">")
	i = 0
	Do While Not Rsc.EOF
	'If Rsc("Depth")>0 And Rsc("ClassType")=classtype Then
		If (i mod 2) = 0 Then iCount=1:lCount=2 Else iCount=2:lCount=1
		If curclassid=Rsc("id") then selectstr="selected" Else selectstr=""
		Response.Write "<option value="&Rsc("id")&" "&selectstr&">"
		If Rsc("Depth") = 1 Then Response.Write "&nbsp;&nbsp;<font color=""#666666"">├</font>"
		If Rsc("Depth") > 1 Then
			For i = 2 To Rsc("Depth")
				Response.Write "&nbsp;&nbsp;<font color=""#666666"">│</font>"
			Next
			Response.Write "&nbsp;&nbsp;<font color=""#666666"">├</font> "
		End If
		Response.Write Rsc("ClassName")
		If Rsc("Child") > 0 Then Response.Write "(" & Rsc("Child") & ")"
		Response.Write " </option>" & vbNewLine
	'End If
		Rsc.movenext
		i = i + 1
	Loop
	response.Write("</select>")
	Rsc.Close
	Set Rsc = Nothing
End Sub

'后台管理列表分类
Sub getClassList(classtype,Pid)		
%>
	<select onChange="window.location.href=this.options[this.selectedIndex].value" class="jinselect">
    <option value="?" <%If Pid=0 then%>selected="selected"<%End If%>>全部分类</option>
    <%
	SQLc = "SELECT * FROM Jin_Class WHERE ModuleID="&Web_ModuleID&" and ClassType Like '%"&classtype&"%' ORDER BY RootID,OrdeRs"
	Set Rsc = Server.CreateObject("ADODB.Recordset")
	Rsc.Open SQLc, Conn, 1, 1
	Do While Not Rsc.EOF
	If Rsc("Depth")=1 Then 
	Str="-- "
	Elseif Rsc("Depth")=2 Then 
	Str="---- "
	Elseif Rsc("Depth")=3 Then 
	Str="------ "
	Else
	Str=" "
	End If
	%>
	<option value="?Pid=<%=Rsc("ID")%>" <%If Pid=Rsc("ID") then%>selected="selected"<%End If%>><%=Str%><%=Rsc("ClassName")%></option>
	<%
	Rsc.movenext
	i = i + 1
	Loop
	Rsc.Close
	Set Rsc = Nothing
	%>
    </select>
<%End Sub%>


<%
'获取相应分类类型下的分类ID
Function getClassBytype(str,pid,style)
	If pid<>"" Then Childstr=getClassValue(pid,"Childstr"):wherestr=" and ID in ("&Childstr&")" else wherestr=""
	If style=1 then
	SQLc = "SELECT * FROM Jin_Class WHERE ModuleID="&Web_ModuleID&" and ClassType='"&str&"' "&wherestr&" ORDER BY RootID,OrdeRs"
	Else
	SQLc = "SELECT * FROM Jin_Class WHERE ModuleID="&Web_ModuleID&" and ClassType like '%"&str&"%' "&wherestr&" ORDER BY RootID,OrdeRs"
	End If
	Set Rsc = Server.CreateObject("ADODB.Recordset")
	Rsc.Open SQLc, Conn, 1, 1
	aaaa=0
	Do While Not Rsc.EOF
	aaaa=aaaa&","&Rsc("ID")
	Rsc.movenext
	Loop
	Rsc.Close
	Set Rsc = Nothing
	getClassBytype=aaaa
End Function 

Function getClassSysID()
	Set Rsc = Server.CreateObject("ADODB.Recordset")
	SQLc = "SELECT top 1 ID FROM Jin_Class ORDER BY ID desc "
	Rsc.Open SQLc, Conn, 1, 1
	IF not Rsc.eof then
			getClassSysID=Rsc("ID")+1
		Else
			getClassSysID=1
		End if
	Rsc.close
	set Rsc=nothing
End Function
%>

<%
'////////////////////////////////////////////////////////////////////////////////////////////////
'编辑器调用
Sub Kindeditor(editorName,ContentID,Upfile,isJs)
%>
    <%If isJs=1 then%>
    <link href="../../kindeditor/themes/default/default.css" rel="stylesheet" type="text/css">
	<script charset="utf-8" src="../../kindeditor/kindeditor-all-min.js"></script>
    <script charset="utf-8" src="../../kindeditor/lang/zh_CN.js"></script>
    <%End If%>
	<script>
        KindEditor.ready(function(K) {
            var <%=editorName%> = K.create('textarea[name="<%=ContentID%>"]', {
                uploadJson : '../../kindeditor/asp/upload_json.asp?u=<%=Upfile%>',
                fileManagerJson : '../../kindeditor/asp/file_manager_json.asp?u=<%=Upfile%>',
				resizeType:0,
				filterMode: false,
                allowFileManager : true
            });
        });
    </script>
<%
End Sub
Sub Kindeditormini(editorName,ContentID,Upfile,isJs)
%>
    <%If isJs=1 then%>
    <link href="../../kindeditor/themes/default/default.css" rel="stylesheet" type="text/css">
	<script charset="utf-8" src="../../kindeditor/kindeditor-all-min.js"></script>
    <script charset="utf-8" src="../../kindeditor/lang/zh_CN.js"></script>
    <%End If%>
	<script>
        KindEditor.ready(function(K) {
            var <%=editorName%> = K.create('textarea[name="<%=ContentID%>"]', {
                uploadJson : '../../kindeditor/asp/upload_json.asp?u=<%=Upfile%>',
                fileManagerJson : '../../kindeditor/asp/file_manager_json.asp?u=<%=Upfile%>',
				items: ["source", "preview", "plainpaste", "wordpaste", "clearhtml" , "|", "justifyleft", "justifycenter", "justifyright", "justifyfull", "insertorderedlist", "insertunorderedlist",  "|", "formatblock", "fontname", "fontsize", "|", "forecolor", "hilitecolor", "bold", "italic", "underline", "lineheight",  "image", "|",  "about" , "fullscreen"],
				resizeType:0,
				filterMode: false,
                allowFileManager : true
            });
        });
    </script>
<%
End Sub
'编辑器图片上传调用
Sub KindeditorPic(editorName,Upfile,isJs,uploadID,PicID)
%>
	<%If isJs=1 then%>
    <link href="../../kindeditor/themes/default/default.css" rel="stylesheet" type="text/css">
    <script charset="utf-8" src="../../kindeditor/kindeditor.js"></script>
    <script charset="utf-8" src="../../kindeditor/lang/zh_CN.js"></script>
    <%End If%>
    <script>
        KindEditor.ready(function(K) {
            var <%=editorName%> = K.editor({
                uploadJson : '../../kindeditor/asp/upload_json.asp?u=<%=Upfile%>',
                fileManagerJson : '../../kindeditor/asp/file_manager_json.asp?u=<%=Upfile%>',
                allowFileManager : true
            });
            K('#<%=uploadID%>').click(function() {
                <%=editorName%>.loadPlugin('image', function() {
                    <%=editorName%>.plugin.imageDialog({
                        imageUrl : K('#<%=PicID%>').val(),
                        clickFn : function(url, title, width, height, border, align) {
                            K('#<%=PicID%>').val(url);
                            <%=editorName%>.hideDialog();
                        }
                    });
                });
            });
        });
    </script>
<%
End Sub

'Validform表单验证、表单美化
Sub getValidform(formname,meihua,yanzheng,isJs)
%>
	<%If isJs=1 then%>
    <link href="<%=Web_Root%>Admin/Css/jqtransform.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="<%=Web_Root%>Admin/Js/Validform.js"></script>
    <script type="text/javascript" src="<%=Web_Root%>Admin/Js/jquery.jqtransform-min.js"></script>
    <%End If%>
    <script type="text/javascript">
    $(function(){
    	<%If meihua=1 then%>
        $(".<%=formname%>").Validform({
            usePlugin:{
                jqtransform:{		//会在当前表单下查找这些元素;
                    selector:"select,:checkbox,:radio,.decorate"	
                }
            }
        });
		<%End If%>
		<%If yanzheng=1 then%>
        $(".<%=formname%>").Validform({
            tiptype:3,
            callback:function(form){
            	form[0].submit();
            }
        });
    	<%End If%>
    })
    </script>
<%
End Sub
%>