<%
Class Html
	dim replace_code

	Function echo()
		response.Write replace_code
	End Function
	
	Function ReadFromUTF(Byval FilePath, CharSet) 'FilePath为要读取的模版文件路径；Charset是编码
		Set fso = Server.CreateObject("Scripting.FileSystemObject")
		if fso.FileExists(server.MapPath(FilePath)) then
			Dim str
			Set stm = server.CreateObject("adodb.stream")
			stm.Type = 2
			stm.Mode = 3
			stm.Charset = CharSet
			stm.Open
			stm.loadfromfile Server.MapPath(FilePath)
			str = stm.readtext
			stm.Close
			Set stm = Nothing
			replace_code = str
		Else
			replace_code = ""
		end if
	End Function
	
	Function WriteToUTF(FilePath)
		Set objStream = Server.CreateObject("ADODB.Stream")
		With objStream
			.Open
			.Charset = "utf-8"
			.Position = objStream.Size
			.WriteText = replace_code
			.SaveToFile server.mappath(FilePath), 2
			.Close
		End With
		Set objStream = Nothing
	End Function

	Function ReplaceCommon()
		if Ke01 = "PC" Then replace_code = replace(replace_code, "{keyicms:TemplatePath}", TemplatePath)
		if Ke01 = "Mobile" Then replace_code = replace(replace_code, "{keyicms:TemplatePath}", TemplatePath)

		replace_code = replace(replace_code, "{keyicms:SiteTitle}", SiteTitle)
		replace_code = replace(replace_code, "{keyicms:Keywords}", Keywords)
		replace_code = replace(replace_code, "{keyicms:Descriptions}", Descriptions)
		replace_code = replace(replace_code, "{keyicms:Stats}", Stats)
		replace_code = replace(replace_code, "{keyicms:SiteUrl}", SiteUrl)
		replace_code = replace(replace_code, "{keyicms:ComName}", ComName)
		replace_code = replace(replace_code, "{keyicms:Address}", Address)
		replace_code = replace(replace_code, "{keyicms:Telephone}", Telephone)
		replace_code = replace(replace_code, "{keyicms:Mobile}", Mobile)
		replace_code = replace(replace_code, "{keyicms:Contacts}", Contacts)
		replace_code = replace(replace_code, "{keyicms:Fax}", Fax)
		replace_code = replace(replace_code, "{keyicms:Email}", Email)
	    replace_code = replace(replace_code, "{keyicms:KyQq}", Kyqq)
		replace_code = replace(replace_code, "{keyicms:IcpNumber}", IcpNumber)
		replace_code = replace(replace_code, "{keyicms:Gicp}", Gicp)
		replace_code = replace(replace_code, "{keyicms:SiteLogo}", SiteLogo)
		replace_code = replace(replace_code, "{keyicms:SiteDetail}", SiteDetail)
		replace_code = replace(replace_code, "{keyicms:Ico}", Ico)
		replace_code = replace(replace_code, "{keyicms:KeyicmsV}", KeyicmsV)
	
		If mStatus Then
			replace_code = replace(replace_code, "{keyicms:MobileTitle}", MobileTitle)
			replace_code = replace(replace_code, "{keyicms:MobileLogo}", MobileLogo)
			replace_code = replace(replace_code, "{keyicms:MobileKeywords}", MobileKeywords)
			replace_code = replace(replace_code, "{keyicms:MobileDescriptions}", MobileDescriptions)
			replace_code = replace(replace_code, "{keyicms:MobileTelephone}", MobileTelephone)
		End If
		
		set newPlugin = new Plugin
		With newPlugin
			.Load(replace_code)
			.Map()
			.ReplaceLoop("Ads")
			.ReplaceLoop("Slide")
			.ReplaceLoop("Custom")
			.ReplaceLoop("FriendLink")
			replace_code = newPlugin.Content
		End With
		set newPlugin = nothing

		set newExtraClass = new ExtraClass
		With newExtraClass
			.Load(replace_code)
			.Navigation()
			.Category()
			replace_code = newExtraClass.Content
		End With
		set newExtraClass = nothing

		set newMainClass = new MainClass
		With newMainClass
			.Load(replace_code)
			.Apage()
			.JobList()
			.NewsList()
			.CaseList()
			.DownList()
			.VideoList()
			.TeamList()
			.ProductList()
			replace_code = newMainClass.Content
		End With
		set newMainClass = nothing
	End Function

	Public Function KE01_If()
		labelRule = "{If:([\s\S]+?)}([\s\S]*?){End\s+If" & x & "}"
		Set regExpObj = New Regexp
		regExpObj.IgnoreCase = True
		regExpObj.Global = True
		regExpObj.Pattern = labelRule
		set matches = regExpObj.Execute(replace_code)
		If matches.count > 0 Then
			For Each match in matches
				replace_code = replace(replace_code, match.value, ParseIf(replace_code, ""))
			Next
		End If
		set matches = nothing
		Set regExpObj = nothing
	End Function
	
	Public Function ParseIf(Content, x)
		If not IsExistStr(Content, "{If" & x & ":") then Exit Function
		Dim nextone
		If IsNum(x) then
			nextone = Int(x) + 1
		Else
			nextone = 1
		End If
		If IsExistStr(Content,"{If" & nextone & ":") then ParseIf(nextone)
		Dim matchIf, matchesIf, strIf, strThen, strThen1, strElse1, labelRule2, labelRule3
		Dim IfFlag, ElseIfArray, ElseIfSubArray, ElseIfArrayLen, resultStr, ElseIfLen, strElseIf, strElseIfThen, ElseIfFlag
		labelRule = "{If" & x & ":([\s\S]+?)}([\s\S]*?){End\s+If" & x & "}" : labelRule2 = "{ElseIf" & x & "" : labelRule3="{Else}" : ElseIfFlag = false
		Set regExpObj = New Regexp
		regExpObj.IgnoreCase = True
		regExpObj.Global = True
		regExpObj.Pattern = labelRule
	
		set matchesIf = regExpObj.Execute(Content)
		For Each matchIf in matchesIf 			
			strIf = matchIf.SubMatches(0) : strThen = matchIf.SubMatches(1)

			If instr(strThen, labelRule2) > 0 then
				ElseIfArray = split(strThen, labelRule2) : ElseIfArrayLen = ubound(ElseIfArray) : ElseIfSubArray = split(ElseIfArray(ElseIfArrayLen), labelRule3)
				If instr(ElseIfArray(ElseIfArrayLen), labelRule3) > 0 then
					resultStr = ElseIfSubArray(1)
				End If
				Execute("If " & strIf & " then resultStr=ElseIfArray(0)")
				for ElseIfLen = 1 to ElseIfArrayLen - 1
					strElseIf = GetSubStrByFromAndEnd(ElseIfArray(ElseIfLen), ":", "}", "")
					strElseIfThen = GetSubStrByFromAndEnd(ElseIfArray(ElseIfLen), "}", "", "start")
					Execute("If " & strElseIf & " then resultStr = strElseIfThen")
					Execute("If " & strElseIf & " then ElseIfFlag = true Else ElseIfFlag = false")
					If ElseIfFlag then exit for
				Next
				Execute("If " & GetSubStrByFromAndEnd(ElseIfSubArray(0), ":", "}", "") & " then resultStr = GetSubStrByFromAndEnd(ElseIfSubArray(0),""}"", """", ""start"") : ElseIfFlag = true")
				Content = replace(Content, matchIf.value, resultStr)
			Else 
				If instr(strThen, labelRule3) > 0 then 
					strThen1 = split(strThen, labelRule3)(0)
					strElse1 = split(strThen, labelRule3)(1)
	
					Execute("If " & strIf & " then IfFlag = true Else IfFlag = false")
					If IfFlag then Content = replace(Content, matchIf.value, strThen1) Else Content = replace(Content, matchIf.value, strElse1)
				Else
					Execute("If " & strIf & " then IfFlag = true Else IfFlag = false")
					If IfFlag then Content = replace(Content, matchIf.value, strThen) Else Content = replace(Content, matchIf.value, "")
				End If
			End If
			elseIfFlag = false
		Next
		set matchesIf = nothing
		ParseIf = Content
	End Function

	Function Position(SortID, DataForm)
		If not IsExistStr(replace_code, "{keyicms:Position}") or not IsExistStr(replace_code, "{/keyicms:Position}") then
			Exit Function
		End If

		Set regExpObj = New Regexp
		set strDictionary = server.CreateObject("scripting.dictionary")
		regExpObj.IgnoreCase = True
		regExpObj.Global = True
		regExpObj.Pattern = "{keyicms:Position}([\s\S]*?){/keyicms:Position}"
		set matches = regExpObj.Execute(replace_code)
	
		for each match in matches
			loopStr = match.SubMatches(0)
			loopstrTotal = ""
			replace_code = replace(replace_code, match.value, KE01_Position(loopStr, SortID, DataForm))
			loopstrTotal = loopstrTotal & nloopstr
			strDictionary.removeAll
		next
	End Function

	Function KE01_Position(loopStr, SortID, DataForm)
		Dim rs, sql
		Set rs = server.CreateObject("adodb.recordset")
		sql = "select * from keyicms_System where DataForm=" & DataForm
		rs.open sql, Conn, 1, 2
		If Ke01 = "PC" Then AutoLink = "/" & rs("SystemDir")
		If Ke01 = "Mobile" Then AutoLink = "/" & mFolder & "/" & rs("SystemDir")
		SortName = rs("SeoTitle")
		rs.close : set rs = nothing
		SortForm = Conn.execute("select * from keyicms_DataForm where ID=" & DataForm)("SortForm")
	
		'ApageSort没有ViewFlag，子级类别
		If CLng(DataForm) = 1 Then
			Set rs = server.CreateObject("adodb.recordset")
			sql = "Select * From " & SortForm & " where ID=" & SortID
			rs.Open sql, conn, 1, 1
			If Not rs.EOF Then
				SortName = rs("SortName")
				AutoLink = AutoLink & "/" & rs("FolderName")
			End If
			rs.close : set rs = nothing
		Else
			If SortID <> "" Then
				Set rs = server.CreateObject("adodb.recordset")
				sql = "Select * From " & SortForm & " where ViewFlag and ID=" & SortID & ""
				rs.Open sql, conn, 1, 1
				If Not rs.EOF Then
					SortName = rs("SortName")
					AutoLink = AutoLink & "/" & rs("FolderName")
					KE01_Position = KE01_Position(loopStr, rs("ParentID"), DataForm)
				End If
				rs.close : set rs = nothing
			End If
		End If
		
		nloopstr = loopStr
		set regExpTwo = New Regexp
		regExpTwo.IgnoreCase = True
		regExpTwo.Global = True
		regExpTwo.Pattern = "\[Position:([\s\S]*?)\]"
		set matchesfield = regExpTwo.Execute(loopStr)
		
		for each matchfield in matchesfield
			FieldNameArr = RegExpReplace(matchfield.SubMatches(0), "[\s]+", chr(32))
			FieldNameArr = trim(FieldNameArr)
			m = instr(FieldNameArr, chr(32))
			if  m > 0 then 
				FieldName = left(FieldNameArr, m - 1)
				FieldArr = right(FieldNameArr, len(FieldNameArr) - m)
			else
				FieldName = FieldNameArr
				FieldArr = ""
			end if
			Select Case FieldName
				Case "Link"
					nloopstr = replace(nloopstr, matchfield.value, AutoLink)
				Case "PosName"
					nloopstr = replace(nloopstr, matchfield.value, SortName)
			end select
		next
		set matchesfield = nothing
		KE01_Position = KE01_Position & nloopstr
	End Function

	Function Include()
		Set regExpObj = New Regexp
		set strDictionary = server.CreateObject("scripting.dictionary")
		regExpObj.IgnoreCase = True
		regExpObj.Global = True
		regExpObj.Pattern = "{keyicms:Include([\s\S]*?)}"
		set matches = regExpObj.Execute(replace_code)
		for each match in matches
			labelStr = match.SubMatches(0)
			set labelArr = ParseArr(labelStr)
			lFile = labelArr("File")

			set hInc = new html
			hInc.ReadFromUTF TemFilePath & "/" & lFile, "utf-8"
			replace_code = replace(replace_code, match.value, hInc.replace_code)
			set hInc = nothing
			strDictionary.removeAll
		next
		set matches = nothing
	End Function
	
	Function ReplacePic(OtherPic, OtherDes)
		If IsNull(OtherPic) Then OtherPic = ""
		OtherPicShop = split(OtherPic, "|")
		OtherDesShop = split(OtherDes, "|")

		Set regExpObj = New Regexp
		regExpObj.IgnoreCase = True
		regExpObj.Global = True
		regExpObj.Pattern = "{keyicms:OtherPic([\s\S]*?)}([\s\S]*?){/keyicms:OtherPic}"
		set matches = regExpObj.Execute(replace_code)
		for each match in matches
			labelStr = match.SubMatches(0)
			loopStr = match.SubMatches(1)

			set regExpTwo = New Regexp
			regExpTwo.IgnoreCase = True
			regExpTwo.Global = True
			regExpTwo.Pattern = "\[OtherPic:([\s\S]*?)\]"
			set matchesfield = regExpTwo.Execute(loopStr)
			loopstrTotal = ""
			For j = 0 to Ubound(OtherPicShop)
				nloopstr = loopStr
				for each matchfield in matchesfield
					fieldNameArr = regExpReplace(matchfield.SubMatches(0), "[\s]+", chr(32))
					fieldNameArr = trim(fieldNameArr)
					m = instr(fieldNameArr, chr(32))
					If m > 0 then 
						fieldArr = ""
						fieldName = left(fieldNameArr,m - 1)
						fieldArr = right(fieldNameArr,len(fieldNameArr) - m)
					Else
						fieldName = fieldNameArr
						fieldArr = ""
					End If
					Select Case fieldName
						Case "i"
							nloopstr = replace(nloopstr, matchfield.value, j + 1)
						Case "Src"
							nloopstr = replace(nloopstr, matchfield.value, OtherPicShop(j))
						Case "Des"
							If OtherDes <> "" Then nloopstr = replace(nloopstr, matchfield.value, OtherDesShop(j))
					End Select
				next
				loopstrTotal = loopstrTotal & nloopstr
			Next
			
			replace_code = replace(replace_code, match.value, loopstrTotal)
		next
		
		Set matches = nothing
		Set regExpObj = nothing
	End Function
End Class

Class ExtraClass
	dim Content
	Function Load(Str)
		Content = Str
	End Function

	Function Navigation()
		labelRule = "{keyicms:Navigation"&str&"([\s\S]*?)}([\s\S]*?){/keyicms:Navigation" & str & "}"
		Set strDictionary = Server.CreateObject("scripting.dictionary")
		Set regExpObj = New Regexp
		regExpObj.IgnoreCase = True
		regExpObj.Global = True
		regExpObj.Pattern = labelRule
		set matches = regExpObj.Execute(Content)
		If matches.count > 0 Then
			For Each match in matches
				labelAttrLinklist = match.SubMatches(0)
				NavType = ParseArr(labelAttrLinklist)("NavType")
				Content = replace(Content, match.value, KE01_Navigation("", match.value, NavType))
				strDictionary.removeAll
			Next
		End If
		set matches = nothing
		Set regExpObj = nothing
	End Function

	Function KE01_Navigation(i, NavigationStr, NavType)
		If not IsExistStr(NavigationStr, "{keyicms:Navigation" & i) Then Exit Function
		labelRule = "{keyicms:Navigation" & i & "([\s\S]*?)}([\s\S]*?){/keyicms:Navigation" & i & "}"
		labelRuleField = "\[Navigation" & i & ":([\s\S]+?)\]"
		Set regExpObj = New Regexp
		regExpObj.IgnoreCase = True
		regExpObj.Global = True
		regExpObj.Pattern = labelRule
		set matches = regExpObj.Execute(NavigationStr)
		
		For Each match in matches
			labelAttrLinklist = match.SubMatches(0)
			ParentID = ParseArr(labelAttrLinklist)("ParentID")
			If IsNul(ParentID) then ParentID = 0

			loopstrLinklist = match.SubMatches(1)
			Set rs = Server.CreateObject("adodb.recordset")
			If Ke01 = "PC" Then sql = "Select * from Keyicms_Navigation where ViewFlag and ParentID=" & ParentID & " and NavType=" & NavType & " Order by Sequence Asc, ID Desc"
			If Ke01 = "Mobile" Then sql = "Select * from Keyicms_Navigation where MobileFlag and ParentID=" & ParentID & " and NavType=" & NavType & " Order by Sequence Asc, ID Desc"

			rs.open sql, Conn, 1, 2
			If not IsArray(linkArray) then vnum = -1 Else vnum = ubound(linkArray,2)
			regExpObj.IgnoreCase = True
			regExpObj.Global = True
			regExpObj.Pattern = labelRuleField
			set matchesfield = regExpObj.Execute(loopstrLinklist)
			loopstrTotal = ""
			If not rs.eof Then
				do until rs.eof
					If Ke01 = "PC" Then idCount = Conn.execute("Select Count(*) from Keyicms_Navigation where ViewFlag and ParentID="&rs("ID")&" and NavType=" & NavType)(0)
					If Ke01 = "Mobile" Then idCount = Conn.execute("Select Count(*) from Keyicms_Navigation where MobileFlag and ParentID="&rs("ID")&" and NavType=" & NavType)(0)
					loopstrLinklistNew = loopstrLinklist
					For Each matchfield in matchesfield
						fieldNameAndAttr = RegExpReplace(matchfield.SubMatches(0), "[\s]+", chr(32))
						m = instr(fieldNameAndAttr, chr(32))
						If m > 0 then 
							fieldName = left(fieldNameAndAttr, m - 1)
							fieldAttr = right(fieldNameAndAttr, len(fieldNameAndAttr) - m)
						Else
							fieldName = fieldNameAndAttr
							fieldAttr = ""
						End If
						Select Case fieldName
							Case "SubCount"
								loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, idCount)
							Case "NavName"
								loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, rs("NavName"))
							Case "KyIcon"
								loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, ChangeNull(rs("KyIcon")))
							Case "IconColor"
								loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, ChangeNull(rs("IconColor")))
							Case "Link"
								If rs("OutFlag") Then
									loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, rs("OutUrl"))
								Else
									If Ke01 = "PC" Then loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, rs("HtmlNavUrl"))
									If Ke01 = "Mobile" Then loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, "/m"&rs("HtmlNavUrl"))
								End If						
							Case "ID"
								loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, rs("ID"))	
						End Select
					Next
					loopstrTotal = loopstrTotal & loopstrLinklistNew
					rs.movenext
				loop
			End If
			set matchesfield = nothing
			NavigationStr = replace(NavigationStr, match.value, loopstrTotal)
		Next
		set matches = nothing
		If i = "" Then i = 0
		If Instr(NavigationStr, "{keyicms:Navigation" & i + 1) > 0 then KE01_Navigation i + 1, NavigationStr, NavType
		KE01_Navigation = KE01_Navigation & NavigationStr
	End Function

	Function Category()
		labelRule = "{keyicms:Category([\s\S]*?)}([\s\S]*?){/keyicms:Category}"
		Set regExpObj = New Regexp
		regExpObj.IgnoreCase = True
		regExpObj.Global = True
		regExpObj.Pattern = labelRule
		set matches = regExpObj.Execute(Content)
		If matches.count > 0 Then
			For Each match in matches
				labelAttrLinklist = match.SubMatches(0)
				lType = ParseArr(labelAttrLinklist)("Type")
				Content = replace(Content, match.value, KE01_Category("", match.value, lType))
			Next
		End If
		SortLoop = Content
		set matches = nothing
		Set regExpObj = nothing
	End Function

	Function KE01_Category(i, CategoryStr, CategoryType)
		If not IsExistStr(CategoryStr, "{keyicms:Category" & i) then Exit Function
		Select Case CategoryType
			Case "Apage"
				DataFrom = "keyicms_Apage"
				Dir = ApageDir
			Case "News"
				DataFrom = "keyicms_NewsSort"
				Dir = NewsDir
			Case "Product"
				DataFrom = "keyicms_ProductSort"
				Dir = ProDir
			Case "Case"
				DataFrom = "keyicms_CaseSort"
				Dir = CaseDir
			Case "Video"
				DataFrom = "keyicms_VideoSort"
				Dir = VideoDir
			Case "Team"
				DataFrom = "keyicms_TeamSort"
				Dir = TeamDir
			Case "Download"
				DataFrom = "keyicms_DownSort"
				Dir = DownDir
			Case Else
				KE01_Category = Keyicms_Lang_ErrMsg(2)
				Exit Function
		End Select
		
		labelRule = "{keyicms:Category" & i & "([\s\S]*?)}([\s\S]*?){/keyicms:Category" & i & "}"
		labelRuleField = "\[Category" & i & ":([\s\S]+?)\]"
		Set regExpObj = New Regexp
		regExpObj.IgnoreCase = True
		regExpObj.Global = True
		regExpObj.Pattern = labelRule
		set matches = regExpObj.Execute(CategoryStr)
		
		If CategoryType = "Apage" Then
			For Each match in matches
				labelAttrLinklist = match.SubMatches(0)
				lNum = ParseArr(labelAttrLinklist)("Num")
				lSortID = ParseArr(labelAttrLinklist)("SortID") 	
	
				loopstrLinklist = match.SubMatches(1)
				Set rs = Server.CreateObject("adodb.recordset")
				If IsNul(lNum) Then SQLTop = "" Else SQLTop = " top " & lNum & ""
				If IsNul(lSortID) Then
					If SortID <> "" Then SQLSort = " and SortID=" & SortID Else SQLSort = ""
				Else
					SQLSort = " and SortID=" & lSortID
				End If
				If Ke01 = "PC" Then sql = "Select " & SQLTop & " * from " & DataFrom & " where ViewFlag " & SQLSort & " Order by Sequence Asc, ID Desc"
				If Ke01 = "Mobile" Then sql = "Select " & SQLTop & "  * from " & DataFrom & " where MobileFlag " & SQLSort & " Order by Sequence Asc, ID Desc"
	
				rs.open sql, Conn, 1, 2
				Set regExpTwo = New Regexp
				regExpTwo.IgnoreCase = True
				regExpTwo.Global = True
				regExpTwo.Pattern = labelRuleField
				set matchesfield = regExpTwo.Execute(loopstrLinklist)
				loopstrTotal = ""
				If not rs.eof Then
					do until rs.eof
						loopstrLinklistNew = loopstrLinklist
						For Each matchfield in matchesfield
							fieldNameAndAttr = RegExpReplace(matchfield.SubMatches(0), "[\s]+", chr(32))
							m = instr(fieldNameAndAttr, chr(32))
							If m > 0 then 
								fieldName = left(fieldNameAndAttr, m - 1)
								fieldAttr = right(fieldNameAndAttr, len(fieldNameAndAttr) - m)
							Else
								fieldName = fieldNameAndAttr
								fieldAttr =	""
							End If
							Select Case fieldName
								Case "SortName"
									loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, rs("ApageName"))
								Case "Link"
									Dir = Conn.execute("select * from keyicms_ApageSort where ID=(select SortID from keyicms_Apage where ID=" & rs("ID") & ")")("FolderName")
									If Ke01 = "PC" Then loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, "/"&Dir&"/"&rs("ClassSeo")&Separated&rs("ID")&"."&HTMLName)
									If Ke01 = "Mobile" Then loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, "/m/"&Dir&"/"&rs("ClassSeo")&Separated&rs("ID")&"."&HTMLName)
								Case "ID"
									loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, rs("ID"))
								Case "AddTime"
									Format = ParseArr(fieldArr)("Format")
									nloopstr = replace(nloopstr, matchfield.value, FormatDate(rs("AddTime"), Format))
								Case "UpdateTime"
									Format = ParseArr(fieldArr)("Format")
									nloopstr = replace(nloopstr, matchfield.value, FormatDate(rs("UpdateTime"), Format))
								Case "Content"
									ContLen = ParseArr(fieldArr)("Len")
									If cInt(ContLen) > 0 Then
										ContLen = cInt(ContLen)
										Cont = StrLeft(RemoveHTML(rs("Content")), ContLen)
									Else
										Cont = RemoveHTML(rs("Content"))
									End If
									nloopstr = replace(nloopstr, matchfield.value, Cont)
							End Select
						Next
						loopstrTotal = loopstrTotal & loopstrLinklistNew
						rs.movenext
					loop
				End If
				set matchesfield = nothing
				set regExpTwo = nothing
				Content = replace(Content, match.value, loopstrTotal)
			Next
			set matches = nothing
			ParseSort = ParseSort & Content
		Else
			For Each match in matches
				labelAttrLinklist = match.SubMatches(0)
				lNum = ParseArr(labelAttrLinklist)("Num")
				ParentID = ParseArr(labelAttrLinklist)("ParentID") 	
				lOrder = ParseArr(labelAttrLinklist)("Order") 	
				If IsNul(ParentID) then ParentID = 0
				loopstrLinklist = match.SubMatches(1)
				
				Set rs = Server.CreateObject("adodb.recordset")
				If IsNul(lNum) Then SQLTop = "" Else SQLTop = " top " & lNum & ""

				rs.open "Select " & SQLTop & " * from " & DataFrom & " where ViewFlag and ParentID=" & ParentID & " Order by Sequence Desc, ID Asc", Conn, 1, 2
				Set regExpTwo = New Regexp
				regExpTwo.IgnoreCase = True
				regExpTwo.Global = True
				regExpTwo.Pattern = labelRuleField
				set matchesfield = regExpTwo.Execute(loopstrLinklist)
				loopstrTotal = ""
				If not rs.eof Then
					do until rs.eof
						idCount = Conn.execute("Select Count(*) from " & DataFrom & " where ViewFlag and ParentID=" & rs("ID"))(0)
						loopstrLinklistNew = loopstrLinklist
						For Each matchfield in matchesfield
							fieldNameAndAttr = RegExpReplace(matchfield.SubMatches(0), "[\s]+", chr(32))
							m = instr(fieldNameAndAttr, chr(32))
							If m > 0 then 
								fieldName = left(fieldNameAndAttr, m - 1)
								fieldAttr = right(fieldNameAndAttr, len(fieldNameAndAttr) - m)
							Else
								fieldName = fieldNameAndAttr
								fieldAttr =	""
							End If
							Select Case fieldName
								Case "SubCount"
									loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, idCount)
								Case "Name"
									loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, rs("SortName"))
								Case "SmallPic"
									loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, rs("SmallPic"))
								Case "Content"
									loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, rs("Content"))
								Case "Link"
									If Ke01 = "PC" Then loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, "/" & Dir & "/" & rs("FolderName"))
									If Ke01 = "Mobile" Then loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, "/" & mFolder & "/" & Dir & "/" & rs("FolderName"))
								Case "ID"
									loopstrLinklistNew = replace(loopstrLinklistNew, matchfield.value, rs("ID"))						
							End Select
						Next
						loopstrTotal = loopstrTotal & loopstrLinklistNew
						rs.movenext
					loop
				End If
				set matchesfield = nothing
				set regExpTwo = nothing
				CategoryStr = replace(CategoryStr, match.value, loopstrTotal)
			Next
			If i = "" Then i = 0
			If Instr(CategoryStr, "{keyicms:Category"& i + 1) > 0 Then KE01_Category i + 1, CategoryStr, CategoryType
		End If
		set matches = nothing
		KE01_Category = KE01_Category & CategoryStr
	End Function
End Class

Class Plugin
	dim Content
	dim MapX, MapY, MapLevel, MapLogo, MapAK
	dim labelStr, loopStr

	Function Load(Str)
		Content = Str
	End Function

	Function Map()
		Set rs = Server.CreateObject("adodb.recordset")
		rs.open "select top 1 * from keyicms_Map", Conn, 1, 2
		If not rs.eof Then
			MapX = rs("MapX")
			MapY = rs("MapY")
			MapLevel = rs("MapLevel")
			MapLogo = rs("MapLogo")
			MapAK = rs("AK")

			Content = replace(Content, "{keyicms:MapX}", MapX)
			Content = replace(Content, "{keyicms:MapY}", MapY)
			Content = replace(Content, "{keyicms:MapLevel}", MapLevel)
			Content = replace(Content, "{keyicms:MapLogo}", MapLogo)
			Content = replace(Content, "{keyicms:MapAK}", MapAK)
		End If
		rs.close : set rs = nothing
	End Function

	Function ReplaceLoop(Label)
		Set regExpObj = New Regexp
		set strDictionary = server.CreateObject("scripting.dictionary")
		regExpObj.IgnoreCase = True
		regExpObj.Global = True
		regExpObj.Pattern = "{keyicms:" & Label & "([\s\S]*?)}([\s\S]*?){/keyicms:" & Label & "}"
		set matches = regExpObj.Execute(Content)
		for each match in matches
			labelStr = match.SubMatches(0)
			loopStr = match.SubMatches(1)

			If Label = "Ads" Then ReplaceStr = Ads()
			If Label = "Slide" Then ReplaceStr = Flash()
			If Label = "Custom" Then ReplaceStr = Custom()
			If Label = "FriendLink" Then ReplaceStr = FriendLink()
			strDictionary.removeAll
			Content = replace(Content, match.value, ReplaceStr)
		next
		set matches = nothing
	End Function

	Function Ads()
		set labelArr = ParseArr(labelStr)
		lID = labelArr("ID")
		lSortID = labelArr("SortID")
		If lSortID = "" Then
			lSortPath = "0,"
		ElseIf lSortID <> "" Then
			sql = "select * from keyicms_AdsSort where ID=" & lSortID
			If Conn.execute(sql).Eof Then
				Ads = "SortID" & Keyicms_Lang_ErrMsg(0)
				Exit Function
			Else
				lSortPath = Conn.execute(sql)("SortPath")
			End If
		End If

		Set regExpTwo = New Regexp
		regExpTwo.IgnoreCase = True
		regExpTwo.Global = True
		regExpTwo.Pattern = "\[Ads:([\s\S]*?)\]"
		set matchesfield = regExpTwo.Execute(loopStr)
		
		Set rs = server.CreateObject("adodb.recordset")
		If lID <> "" Then
			sql = "select * from keyicms_Ads where ID=" & lID
		Else
			sql = "select * from keyicms_Ads where Instr(SortPath, '" & lSortPath & "')>0 Order by Sequence Asc, ID Desc"
		End If
	
		rs.open sql, Conn, 1, 2
		loopstrTotal = ""
		If rs.eof Then
			loopstrTotal = Keyicms_Lang_ErrMsg(1)
		Else
			do until rs.eof
				nloopstr = loopStr
				for each matchfield in matchesfield
					FieldNameArr = regExpReplace(matchfield.SubMatches(0), "[\s]+", chr(32))
					FieldNameArr = trim(FieldNameArr)
					m = instr(FieldNameArr, chr(32))
					if  m > 0 then 
						FieldName = left(FieldNameArr, m - 1)
						FieldArr = right(FieldNameArr, len(FieldNameArr) - m)
					else
						FieldName = FieldNameArr
						FieldArr = ""
					end if
					Select Case FieldName
						Case "ID"
							nloopstr = replace(nloopstr, matchfield.value, rs("ID"))
						Case "AdsUrl"
							nloopstr = replace(nloopstr, matchfield.value, rs("AdsUrl"))
						Case "AdsName"
							nloopstr = replace(nloopstr, matchfield.value, rs("AdsName"))
						Case "AdsPic"
							nloopstr = replace(nloopstr, matchfield.value, rs("AdsPic"))
						Case "Content"
							ContLen = ParseArr(FieldArr)("Len") 
							If cInt(ContLen) > 0 Then
								ContLen = cInt(ContLen)
								Cont = StrLeft(RemoveHTML(rs("Content")), ContLen)
							Else
								Cont = RemoveHTML(rs("Content"))
							End If
							nloopstr = replace(nloopstr, matchfield.value, Cont)
					end select
				next
				loopstrTotal = loopstrTotal & nloopstr
				rs.movenext
			loop
			rs.close : set rs = nothing
			set matchesfield = nothing
		End If
		Ads = loopstrTotal
	End Function
	
	Function Flash()
		Set regExpTwo = New Regexp
		regExpTwo.IgnoreCase = True
		regExpTwo.Global = True
		regExpTwo.Pattern = "\[Slide:([\s\S]*?)\]"
		set matchesfield = regExpTwo.Execute(loopStr)
	
		Set rs = server.CreateObject("adodb.recordset")
		sql = "select * from keyicms_Slide Order by State Asc, ID Desc"
		rs.open sql, Conn, 1, 2
		loopstrTotal = ""
		do until rs.eof
			nloopstr = loopStr
			for each matchfield in matchesfield
				FieldNameArr = regExpReplace(matchfield.SubMatches(0), "[\s]+", chr(32))
				FieldNameArr = trim(FieldNameArr)
				m = instr(FieldNameArr, chr(32))
				if  m > 0 then 
					FieldName = left(FieldNameArr, m - 1)
					FieldArr = right(FieldNameArr, len(FieldNameArr) - m)
				else
					FieldName = FieldNameArr
					FieldArr = ""
				end if
				Select Case FieldName
					Case "ID"
						nloopstr = replace(nloopstr, matchfield.value, rs("ID"))
					Case "Url"
						nloopstr = replace(nloopstr, matchfield.value, rs("Url"))
					Case "Pic"
						nloopstr = replace(nloopstr, matchfield.value, rs("Pic"))
					Case "SlideName"
						nloopstr = replace(nloopstr, matchfield.value, rs("SlideName"))
				end select
			next
			loopstrTotal = loopstrTotal & nloopstr
			rs.movenext
		loop
		rs.close : set rs = nothing
		set matchesfield = nothing
		Flash = loopstrTotal
	End Function
	
	Function Custom()
		set labelArr = ParseArr(labelStr)
		lStatus = labelArr("Status")
		If not isNum(lStatus) Then Contact = "" : exit Function
	
		Set regExpTwo = New Regexp
		regExpTwo.IgnoreCase = True
		regExpTwo.Global = True
		regExpTwo.Pattern = "\[Custom:([\s\S]*?)\]"
		set matchesfield = regExpTwo.Execute(loopStr)
	
		Set rs = server.CreateObject("adodb.recordset")
		If lStatus = 1 Then
			sql = "select * from keyicms_Custom where SortID=1 Order by Sequence Asc, ID Desc"
		rs.open sql, Conn, 1, 2
		loopstrTotal = ""
		do until rs.eof
			nloopstr = loopStr
			for each matchfield in matchesfield
				FieldNameArr = regExpReplace(matchfield.SubMatches(0), "[\s]+", chr(32))
				FieldNameArr = trim(FieldNameArr)
				m = instr(FieldNameArr, chr(32))
				if m > 0 then 
					FieldName = left(FieldNameArr, m - 1)
					FieldArr = right(FieldNameArr, len(FieldNameArr) - m)
				else
					FieldArr = ""
					FieldName = FieldNameArr
				end if
				Select Case FieldName
					Case "ID"
						nloopstr = replace(nloopstr, matchfield.value, rs("ID"))
					Case "Code"
						nloopstr = replace(nloopstr, matchfield.value, rs("Code"))
					Case "CustomQq"
						nloopstr = replace(nloopstr, matchfield.value, changeNull(rs("CustomQq")))
					Case "CustomName"
						nloopstr = replace(nloopstr, matchfield.value, rs("CustomName"))
					Case "CustomPhone"
						nloopstr = replace(nloopstr, matchfield.value, changeNull(rs("CustomPhone")))
					Case "CustomWeChat"
						nloopstr = replace(nloopstr, matchfield.value, changeNull(rs("CustomWeChat")))
					Case "Code"
						nloopstr = replace(nloopstr, matchfield.value, changeNull(rs("Code")))
				end select
			next
			loopstrTotal = loopstrTotal & nloopstr
			rs.movenext
		loop
		rs.close : set rs = nothing
		ElseIf lStatus = 2 Then
			sql = "select * from keyicms_Custom where SortID=2"
		End If
		set matchesfield = nothing
		Custom = loopstrTotal
	End Function

	Function FriendLink()
		set labelArr = ParseArr(labelStr)
		lLinkType = labelArr("LinkType")
		
		Set regExpTwo = New Regexp
		regExpTwo.IgnoreCase = True
		regExpTwo.Global = True
		regExpTwo.Pattern = "\[FriendLink:([\s\S]*?)\]"
		set matchesfield = regExpTwo.Execute(loopStr)
			
		Set rs = server.CreateObject("adodb.recordset")
		sql = "select * from keyicms_FriendLink Where LinkType = " & lLinkType & " Order by ID Desc"
		rs.open sql, Conn, 1, 2
		loopstrTotal = ""
		If rs.eof Then
			loopstrTotal = Keyicms_Lang_ErrMsg(1)
		Else
			do until rs.eof
				nloopstr = loopStr
				for each matchfield in matchesfield
					FieldNameArr = regExpReplace(matchfield.SubMatches(0), "[\s]+", chr(32))
					FieldNameArr = trim(FieldNameArr)
					m = instr(FieldNameArr, chr(32))
					if  m > 0 then 
						FieldName = left(FieldNameArr, m - 1)
						FieldArr = right(FieldNameArr, len(FieldNameArr) - m)
					else
						FieldName = FieldNameArr
						FieldArr = ""
					end if
					Select Case FieldName
						Case "ID"
							nloopstr = replace(nloopstr, matchfield.value, rs("ID"))
						Case "LinkUrl"
							nloopstr = replace(nloopstr, matchfield.value, rs("LinkUrl"))
						Case "LinkFace"
							nloopstr = replace(nloopstr, matchfield.value, rs("LinkFace"))
						Case "LinkName"
							nloopstr = replace(nloopstr, matchfield.value, rs("LinkName"))
						Case "Remark"
							nloopstr = replace(nloopstr, matchfield.value, rs("Remark"))
						Case "AddTime"
							Format = ParseArr(FieldArr)("Format")
							nloopstr = replace(nloopstr, matchfield.value, FormatDate(rs("AddTime"), Format))
					end select
				next
				loopstrTotal = loopstrTotal & nloopstr
				rs.movenext
			loop
			rs.close : set rs = nothing
			set matchesfield = nothing
		End If
		FriendLink = loopstrTotal
	End Function
End Class

Function ShowPage(replace_code)
	Dim Pagenc, Pagenmax, Pagenmin
	Pagenc = 2

	Dim Myself, PATH_INFO, QUERY_STRING
	PATH_INFO = request.servervariables("PATH_INFO")
	QUERY_STRING = request.ServerVariables("QUERY_STRING")'
	Myself = "Index"

	Pagenmin = Page - Pagenc
	Pagenmax = Page + Pagenc
	If Pagenmin < 1 Then Pagenmin = 1
	If Pagenmax > Pagec Then Pagenmax = Pagec

	Set strDictionary = Server.CreateObject("scripting.dictionary")
	Set regExpObj = New Regexp
	regExpObj.IgnoreCase = True
	regExpObj.Global = True
	regExpObj.Pattern = "{keyicms:Page([\s\S]*?)}([\s\S]*?){/keyicms:Page}"

	set matches = regExpObj.Execute(replace_code)

	For Each match in matches
		If idcount > 0 Then
			labelStr = match.SubMatches(0)
			loopStr = match.SubMatches(1)
			
			Set regExpObjTow = New Regexp
			regExpObjTow.IgnoreCase = True
			regExpObjTow.Global = True
			regExpObjTow.Pattern = "{Page:PageList([\s\S]*?)}([\s\S]*?){/Page:PageList}"
			set matchesTow = regExpObjTow.Execute(loopStr)
			For Each matchTow in matchesTow
				labelStrTow = matchTow.SubMatches(0)
				set labelArrTow = ParseArr(labelStrTow)

				loopStrTow = matchTow.SubMatches(1)
	
				Set regExpObjNew = New Regexp
				regExpObjNew.IgnoreCase = True
				regExpObjNew.Global = True
				regExpObjNew.Pattern = "\[PageList:([\s\S]*?)\]"
				set matchesfield = regExpObjNew.Execute(loopStrTow)

				loopstrTotal = ""
				For j = Pagenmin to Pagenmax
					nloopstr = loopStrTow
					For Each matchfield in matchesfield
						fieldNameArr = RegExpReplace(matchfield.SubMatches(0),"[\s]+",chr(32))
						fieldNameArr = trim(fieldNameArr)
						m = instr(fieldNameArr,chr(32))
						If  m > 0 then 
							fieldArr=""
							fieldName = left(fieldNameArr,m - 1)
							fieldArr = right(fieldNameArr,len(fieldNameArr) - m)
						Else
							fieldName = fieldNameArr
							fieldArr = ""
						End If
		
						Select Case fieldName
							Case "Link"
								nloopstr = replace(nloopstr, matchfield.value, Myself & Separated & j &"."&HTMLName)
							Case "PageInfo"
								nloopstr = replace(nloopstr, matchfield.value, j)
						End Select
					Next
					loopstrTotal = loopstrTotal & nloopstr
				Next
				loopStr = replace(loopStr, matchTow.value, loopstrTotal)
			Next
	
			Set regExpObjPage = New Regexp
			regExpObjPage.IgnoreCase = True
			regExpObjPage.Global = True
			regExpObjPage.Pattern = "\[Page:([\s\S]*?)\]"
			set matchesPage = regExpObjPage.Execute(loopStr)
			nloopstr = loopStr

			For Each matchPage in matchesPage
				FieldNameArr = regExpReplace(matchPage.SubMatches(0), "[\s]+", chr(32))
				FieldNameArr = trim(FieldNameArr)
				m = instr(FieldNameArr, chr(32))
				if  m > 0 then 
					FieldName = left(FieldNameArr, m - 1)
					FieldArr = right(FieldNameArr, len(FieldNameArr) - m)
				else
					FieldName = FieldNameArr
					FieldArr = ""
				end if
				Select Case FieldName
					Case "Page"
						nloopstr = replace(nloopstr, matchPage.value, Page)
					Case "Total"
						nloopstr = replace(nloopstr, matchPage.value, idCount)
					Case "Pages"
						nloopstr = replace(nloopstr, matchPage.value, newTotalPage)
					Case "FirstLink"
						nloopstr = replace(nloopstr, matchPage.value, Myself & Separated & "1."&HTMLName)
					Case "PrevLink"
						If Page > 1 Then
							nloopstr = replace(nloopstr, matchPage.value, Myself & Separated & (Page-1) & "."&HTMLName)
						Else
							nloopstr = replace(nloopstr, matchPage.value, "#")
						End If
					Case "NextLink"
						If Page < Pagec Then
							nloopstr = replace(nloopstr, matchPage.value, Myself & Separated & (Page+1) & "."&HTMLName)
						Else
							nloopstr = replace(nloopstr, matchPage.value, "#")
						End If
					Case "LastLink"
						nloopstr = replace(nloopstr, matchPage.value, Myself & Separated & Pagec & "."&HTMLName)
				End Select
			Next
			replace_code = replace(replace_code, match.value, nloopstr)
		Else
			replace_code = replace(replace_code, match.value, "")
		End If
	Next
	ShowPage = ShowPage & replace_code
End Function

'==========End=============
'搜索 __ 翻页
Function ShowPageAsp(replace_code)
	Dim Pagenc, Pagenmax, Pagenmin
	Pagenc = 2

	Dim Myself, PATH_INFO, QUERY_STRING
	PATH_INFO = request.servervariables("PATH_INFO")
	QUERY_STRING = request.ServerVariables("QUERY_STRING")'
	Myself = "Index"

	Pagenmin = Page - Pagenc
	Pagenmax = Page + Pagenc
	If Pagenmin < 1 Then Pagenmin = 1
	If Pagenmax > Pagec Then Pagenmax = Pagec

	Set strDictionary = Server.CreateObject("scripting.dictionary")
	Set regExpObj = New Regexp
	regExpObj.IgnoreCase = True
	regExpObj.Global = True
	regExpObj.Pattern = "{keyicms:Page([\s\S]*?)}([\s\S]*?){/keyicms:Page}"

	set matches = regExpObj.Execute(replace_code)

	For Each match in matches
		If idcount > 0 Then
			labelStr = match.SubMatches(0)
			loopStr = match.SubMatches(1)
			
			Set regExpObjTow = New Regexp
			regExpObjTow.IgnoreCase = True
			regExpObjTow.Global = True
			regExpObjTow.Pattern = "{Page:PageList([\s\S]*?)}([\s\S]*?){/Page:PageList}"
			set matchesTow = regExpObjTow.Execute(loopStr)
			For Each matchTow in matchesTow
				labelStrTow = matchTow.SubMatches(0)
				set labelArrTow = ParseArr(labelStrTow)

				loopStrTow = matchTow.SubMatches(1)
	
				Set regExpObjNew = New Regexp
				regExpObjNew.IgnoreCase = True
				regExpObjNew.Global = True
				regExpObjNew.Pattern = "\[PageList:([\s\S]*?)\]"
				set matchesfield = regExpObjNew.Execute(loopStrTow)

				loopstrTotal = ""
				For j = Pagenmin to Pagenmax
					nloopstr = loopStrTow
					For Each matchfield in matchesfield
						fieldNameArr = RegExpReplace(matchfield.SubMatches(0),"[\s]+",chr(32))
						fieldNameArr = trim(fieldNameArr)
						m = instr(fieldNameArr,chr(32))
						If  m > 0 then 
							fieldArr=""
							fieldName = left(fieldNameArr,m - 1)
							fieldArr = right(fieldNameArr,len(fieldNameArr) - m)
						Else
							fieldName = fieldNameArr
							fieldArr = ""
						End If
		
						Select Case fieldName
							Case "Link"
								nloopstr = replace(nloopstr, matchfield.value, Myself & Separated & j &"."&HTMLName)
							Case "PageInfo"
								nloopstr = replace(nloopstr, matchfield.value, j)
						End Select
					Next
					loopstrTotal = loopstrTotal & nloopstr
				Next
				loopStr = replace(loopStr, matchTow.value, loopstrTotal)
			Next
	
			Set regExpObjPage = New Regexp
			regExpObjPage.IgnoreCase = True
			regExpObjPage.Global = True
			regExpObjPage.Pattern = "\[Page:([\s\S]*?)\]"
			set matchesPage = regExpObjPage.Execute(loopStr)
			nloopstr = loopStr

			For Each matchPage in matchesPage
				FieldNameArr = regExpReplace(matchPage.SubMatches(0), "[\s]+", chr(32))
				FieldNameArr = trim(FieldNameArr)
				m = instr(FieldNameArr, chr(32))
				if  m > 0 then 
					FieldName = left(FieldNameArr, m - 1)
					FieldArr = right(FieldNameArr, len(FieldNameArr) - m)
				else
					FieldName = FieldNameArr
					FieldArr = ""
				end if
				Select Case FieldName
					Case "Page"
						nloopstr = replace(nloopstr, matchPage.value, Page)
					Case "Total"
						nloopstr = replace(nloopstr, matchPage.value, idCount)
					Case "Pages"
						nloopstr = replace(nloopstr, matchPage.value, newTotalPage)
					Case "FirstLink"
						nloopstr = replace(nloopstr, matchPage.value, Myself & Separated & "1."&HTMLName)
					Case "PrevLink"
						If Page > 1 Then
							nloopstr = replace(nloopstr, matchPage.value, Myself & Separated & (Page-1) & "."&HTMLName)
						Else
							nloopstr = replace(nloopstr, matchPage.value, "#")
						End If
					Case "NextLink"
						If Page < Pagec Then
							nloopstr = replace(nloopstr, matchPage.value, Myself & Separated & (Page+1) & "."&HTMLName)
						Else
							nloopstr = replace(nloopstr, matchPage.value, "#")
						End If
					Case "LastLink"
						nloopstr = replace(nloopstr, matchPage.value, Myself & Separated & Pagec & "."&HTMLName)
				End Select
			Next
			replace_code = replace(replace_code, match.value, nloopstr)
		Else
			replace_code = replace(replace_code, match.value, "")
		End If
	Next
	ShowPageAsp = ShowPageAsp & replace_code
End Function

'Function ShowPageAsp(replace_code, idcount, Page, Pagec, Pages)
'	Dim Pagenc, Pagenmax, Pagenmin
'	Pagenc = 2
'
'	Dim Myself, PATH_INFO, QUERY_STRING
'	PATH_INFO = request.servervariables("PATH_INFO")
'	QUERY_STRING = request.ServerVariables("QUERY_STRING")'
'	
'	If QUERY_STRING = "" Or InStr(PATH_INFO & "?" & QUERY_STRING, "Page=") = 0 Then
'		Myself = PATH_INFO & "?" & QUERY_STRING
'	Else
'		Myself = Left(PATH_INFO & "?" & QUERY_STRING, InStr(PATH_INFO & "?" & QUERY_STRING, "Page=")-2)
'	End If
'
'	Pagenmin = Page - Pagenc
'	Pagenmax = Page + Pagenc
'	If(Pagenmin < 1) Then Pagenmin = 1
'	If(Pagenmax > Pagec) Then Pagenmax = Pagec
'
'	Set strDictionary = Server.CreateObject("scripting.dictionary")
'	Set regExpObj = New Regexp
'	regExpObj.IgnoreCase = True
'	regExpObj.Global = True
'	regExpObj.Pattern = "{keyicms:Page([\s\S]*?)}([\s\S]*?){/keyicms:Page}"
'	set matches = regExpObj.Execute(replace_code)
'
'	For Each match in matches
'		If idcount > 0 Then
'			labelStr = match.SubMatches(0)
'			loopStr = match.SubMatches(1)
'
'			Set regExpObjTow = New Regexp
'			regExpObjTow.IgnoreCase = True
'			regExpObjTow.Global = True
'			regExpObjTow.Pattern = "{Page:PageList([\s\S]*?)}([\s\S]*?){/Page:PageList}"
'			set matchesTow = regExpObjTow.Execute(loopStr)
'			For Each matchTow in matchesTow
'				labelStrTow = matchTow.SubMatches(0)
'				set labelArrTow = ParseArr(labelStrTow)
'				lCurrent = labelArrTow("PageCur")
'				loopStrTow = matchTow.SubMatches(1)
'
'				Set regExpObjNew = New Regexp
'				regExpObjNew.IgnoreCase = True
'				regExpObjNew.Global = True
'				regExpObjNew.Pattern = "{Page:([\s\S]*?)}"
'				set matchesfield = regExpObjNew.Execute(loopStrTow)
'	
'				loopstrTotal = ""
'				For j = Pagenmin to Pagenmax
'					nloopstr = loopStrTow
'					For Each matchfield in matchesfield
'						fieldNameArr = RegExpReplace(matchfield.SubMatches(0),"[\s]+",chr(32))
'						fieldNameArr = trim(fieldNameArr)
'						m = instr(fieldNameArr,chr(32))
'						If  m > 0 then 
'							fieldArr=""
'							fieldName = left(fieldNameArr,m - 1)
'							fieldArr = right(fieldNameArr,len(fieldNameArr) - m)
'						Else
'							fieldName = fieldNameArr
'							fieldArr = ""
'						End If
'		
'						Select Case fieldName
'							Case "Link"
'								nloopstr = replace(nloopstr, matchfield.value, Myself & Separated & j &"."&HTMLName)
'							Case "PageInfo"
'								nloopstr = replace(nloopstr, matchfield.value, j)
'						End Select
'					Next
'					loopstrTotal = loopstrTotal & nloopstr
'				Next
'				loopStr = replace(loopStr, matchTow.value, loopstrTotal)
'			Next
'	
'			Set regExpObjPage = New Regexp
'			regExpObjPage.IgnoreCase = True
'			regExpObjPage.Global = True
'			regExpObjPage.Pattern = "\[Page:([\s\S]*?)\]"
'			set matchesPage = regExpObjPage.Execute(loopStr)
'			nloopstr = loopStr
'
'			For Each matchPage in matchesPage
'				labelStr = matchPage.SubMatches(0)
'				loopStr = matchPage.SubMatches(1)
'				Select Case labelStr
'					Case "First"
'						nloopstr = replace(nloopstr, matchPage.value, "<a href='"&Myself & "&Page=1'>"&loopStr&"</a>")
'					Case "Prev"
'						If Page > 1 Then
'							nloopstr = replace(nloopstr, matchPage.value, "<a href='"&Myself & "&Page=" & (Page-1) &"'>"&loopStr&"</a>")
'						Else
'							nloopstr = replace(nloopstr, matchPage.value, "")
'						End If
'					Case "Next"
'						If Page < Pagec Then
'							nloopstr = replace(nloopstr, matchPage.value, "<a href='"&Myself & "&Page=" & (Page+1) & "'>"&loopStr&"</a>")
'						Else
'							nloopstr = replace(nloopstr, matchPage.value, "")
'						End If
'					Case "Last"
'						nloopstr = replace(nloopstr, matchPage.value, "<a href='"&Myself & "&Page=" & Pagec & "'>"&loopStr&"</a>")
'				End Select
'			Next
'
'			replace_code = replace(replace_code, match.value, nloopstr)
'		Else
'			replace_code = replace(replace_code, match.value, "")
'		End If
'	Next
'
'	ShowPageAsp = ShowPageAsp & replace_code
'End Function
%>