<%
Class FCKeditor
	private sBasePath
	private sInstanceName
	private sWidth
	private sHeight
	private sToolbarSet
	private sValue

	private oConfig

	Private Sub Class_Initialize()
		sBasePath		= "/fckeditor/"
		sWidth			= "100%"
		sHeight			= "200"
		sToolbarSet		= "Default"
		sValue			= ""
		Set oConfig 	=CreateObject("Scripting.Dictionary")
		'Dictionary 	保存数据键和项目对的对象。
	End Sub

	Public Property Let BasePath( basePathValue )'设置sBasePath的值为(a)
		sBasePath = basePathValue
	End Property

	Public Property Let Width( widthValue )'设置sWidth的值
		sWidth = widthValue
	End Property

	Public Property Let Height( heightValue )'设置sHeight的值
		sHeight = heightValue
	End Property

	Public Property Let ToolbarSet( toolbarSetValue )'设置sToolbarSet的值
		sToolbarSet = toolbarSetValue
	End Property

	Public Property Let Value( newValue )'设置sValue的值
		If ( IsNull( newValue ) OR IsEmpty( newValue ) ) Then
		'IsEmpty 函数		返回 Boolean 值指明变量是否已初始化。
			sValue = ""
		Else
			sValue = newValue
		End If
	End Property
	
	Public Sub Create( instanceName )'显示修改的内容
		'instanceName="content"
		Fun.echo CreateHtml( instanceName )'显示修改的内容
	end Sub

	Public Property Let InstanceName( instanceNameValue )
		sInstanceName = instanceNameValue
	End Property
	
	Public Property Let Config( configKey, configValue )
		oConfig.Add configKey, configValue
	End Property

	Public Function CreateHtml( instanceName )'显示修改的内容
		'instanceName="content"
		dim html
		If IsCompatible() Then'true
			'IsCompatible()'是否可在客户端应用
			Dim sFile, sLink
			If Request.QueryString( "fcksource" ) = "true" Then'false	选择文件
			'QueryString 	HTTP 中查询字符串中变量的值。  
				sFile = "fckeditor.original.html"
			Else
				sFile = "fckeditor.html"
			End If
			sLink = sBasePath & "editor/" & sFile & "?InstanceName=" + instanceName
			'sLink="fckeditor/editor/fckeditor.html?InstanceName=content"
			If (sToolbarSet & "") <> "" Then'true	在Toolbar中添加值
				sLink = sLink + "&amp;Toolbar=" & sToolbarSet
				'sLink="fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=rendie"
			End If
			html = ""
			html = html & "<input type=""hidden"" id=""" & instanceName & """ name=""" & instanceName & """ value=""" & Server.HTMLEncode( sValue ) & """ style=""display:none"" />"
			'instanceName="content"
				'Server.HTMLEncode( sValue ) 内容
			html = html & "<input type=""hidden"" id=""" & instanceName & "___Config"" value=""" & GetConfigFieldString() & """ style=""display:none"" />"
			'"**___Config"		用來放物件的架構性參數。 
				'GetConfigFieldString()=""	'输出数据键和项目
			html = html & "<iframe id=""" & instanceName & "___Frame"" src=""" & sLink & """ width=""" & sWidth & """ height=""" & sHeight & """ frameborder=""0"" scrolling=""no""></iframe>"
			'"**___Frame"		用來放置編輯器介面
			'html="<input type="hidden" id="m_content" name="m_content" value="" style="display:none" /><input type="hidden" id="m_content___Config" value="" style="display:none" /><iframe id="m_content___Frame" src="fckeditor/editor/fckeditor.html?InstanceName=m_content&amp;Toolbar=rendie" width="650" height="300" frameborder="0" scrolling="no"></iframe>"
		Else
			Dim sWidthCSS, sHeightCSS
			If InStr( sWidth, "%" ) > 0  Then
				sWidthCSS = sWidth
			Else
				sWidthCSS = sWidth & "px"
			End If
			If InStr( sHeight, "%" ) > 0  Then
				sHeightCSS = sHeight
			Else
				sHeightCSS = sHeight & "px"
			End If
			html = "<textarea name=""" & instanceName & """ rows=""4"" cols=""40"" style=""width: " & sWidthCSS & "; height: " & sHeightCSS & """>" & Server.HTMLEncode( sValue ) & "</textarea>"
		End If
		CreateHtml = html
	End Function

	Private Function IsCompatible()'是否可在客户端应用
		IsCompatible = FCKeditor_IsCompatibleBrowser()'true		是否可在客户端应用
	End Function

	Private Function GetConfigFieldString()'输出数据键和项目
		Dim sParams
		Dim bFirst
		bFirst = True
		Dim sKey
		For Each sKey in oConfig'无效
			If bFirst = False Then
				sParams = sParams & "&amp;"
				'"&amp;"="&"
			Else
				bFirst = False
			End If
			sParams = sParams & EncodeConfig( sKey ) & "=" & EncodeConfig( oConfig(sKey) )
		Next
		GetConfigFieldString = sParams'=""
	End Function
	
	Private Function EncodeConfig( valueToEncode )
		' The locale of the asp server makes the conversion of a boolean to string different to "true" or "false"
		' so we must do it manually
    If vartype(valueToEncode) = vbBoolean then
			If valueToEncode=True Then
				EncodeConfig="True"
			Else
				EncodeConfig="False"
			End If
		Else
			EncodeConfig = Replace( valueToEncode, "&", "%26" )
			EncodeConfig = Replace( EncodeConfig , "=", "%3D" )
			EncodeConfig = Replace( EncodeConfig , """", "%22" )
		End if
	End Function
End Class

Function FCKeditor_IsCompatibleBrowser()'是否可在客户端应用
	Dim sAgent
	sAgent = Request.ServerVariables("HTTP_USER_AGENT")'="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)"
		'用request.ServerVariables("HTTP_USER_AGENT")取到的应该是客户端的相关信息。
	Dim iVersion
	Dim re, Matches
	If InStr(sAgent, "MSIE") > 0 AND InStr(sAgent, "mac") <= 0  AND InStr(sAgent, "Opera") <= 0 Then'true	是否可在客户端应用
		iVersion = clng( FCKeditor_ToNumericFormat( Mid(sAgent, InStr(sAgent, "MSIE") + 5, 3) ) )'=6	求sAgent中"MSIE "后3位的值
			'CLng 函数	返回表达式，此表达式已被转换为 Long 子类型的 Variant。
				'FCKeditor_ToNumericFormat(a)'是否自动将字符串数转为数字
					'Mid 函数	从字符串中返回指定数目的字符。
						'Mid(string, start[, length])
		FCKeditor_IsCompatibleBrowser = ( iVersion >= 5.5 )'true
	ElseIf InStr(sAgent, "Gecko/") > 0 Then
		iVersion = CLng( Mid( sAgent, InStr( sAgent, "Gecko/" ) + 6, 8 ) )
		FCKeditor_IsCompatibleBrowser = ( iVersion >= 20030210 )
	ElseIf InStr(sAgent, "Opera/") > 0 Then
		iVersion = CSng( FCKeditor_ToNumericFormat( Mid( sAgent, InStr( sAgent, "Opera/" ) + 6, 4 ) ) )
		FCKeditor_IsCompatibleBrowser = ( iVersion >= 9.5 )
	ElseIf InStr(sAgent, "AppleWebKit/") > 0 Then
		Set re = new RegExp
		re.IgnoreCase = true
		re.global = false
		re.Pattern = "AppleWebKit/(\d+)"
		Set Matches = re.Execute(sAgent)
		FCKeditor_IsCompatibleBrowser = ( re.Replace(Matches.Item(0).Value, "$1") >= 522 )
	Else
		FCKeditor_IsCompatibleBrowser = False
	End If
End Function
Private Function FCKeditor_ToNumericFormat( numberStr )'是否自动将字符串数转为数字
  'numberStr="6.0"
  If isNumeric( "5.5" ) Then'true
  'isNumeric 函数		返回 Boolean 值指明表达式的值是否为数字。
	FCKeditor_ToNumericFormat = Replace( numberStr, ",", ".")
  Else
	FCKeditor_ToNumericFormat = Replace( numberStr, ".", ",")
  End If
End Function
%>
