<%
'**************************************************
'函数名：gotTopic
'作  用：截字符串，汉字一个算两个字符，英文算一个字符
'参  数：str   ----原字符串
'       strlen ----截取长度
'返回值：截取后的字符串
'**************************************************
function gotTopic(str,strlen)
	if str="" then
		gotTopic=""
		exit function
	end if
	dim l,t,c, i
	str=replace(replace(replace(replace(str,"&nbsp;"," "),"&quot;",chr(34)),"&gt;",">"),"&lt;","<")
	l=len(str)
	t=0
	for i=1 to l
		c=Abs(Asc(Mid(str,i,1)))
		if c>255 then
			t=t+2
		else
			t=t+1
		end if
		if t>=strlen then
			gotTopic=left(str,i) & "…"
			exit for
		else
			gotTopic=str
		end if
	next
	gotTopic=replace(replace(replace(replace(gotTopic," ","&nbsp;"),chr(34),"&quot;"),">","&gt;"),"<","&lt;")
end function
'===========================================================================
'函数：RemoveHTML(strHTML)
'功能：去除HTML标记
'参数：strHTML		--要去除HTML标记的字符串
'==========================================================================
Function RemoveHTML(strHTML) 
Dim objRegExp, Match, Matches 
Set objRegExp = New Regexp 

objRegExp.IgnoreCase = True 
objRegExp.Global = True 
'取闭合的<> 
objRegExp.Pattern = "<.+?>" 
'进行匹配 
Set Matches = objRegExp.Execute(strHTML) 

' 遍历匹配集合，并替换掉匹配的项目 
For Each Match in Matches 
strHtml=Replace(strHTML,Match.Value,"") 
Next 
RemoveHTML=strHTML 
Set objRegExp = Nothing 
End Function 
'======================================================================================
'                              登录成功，写入cookies                                    
'======================================================================================
function SaveCookie(CookieDate)
	Response.Cookies("tot")("userid")=userid
	Response.Cookies("tot")("password") = password	
	Response.Cookies("tot")("CookieDate") = CookieDate
	select case CookieDate
		case 0
			'not save
		case 1
		   	Response.Cookies("tot").Expires=Date+1 '保存一天
		case 2
			Response.Cookies("tot").Expires=Date+31 '保存一个月
		case 3
			Response.Cookies("tot").Expires=Date+365 '保存一年
	end select
end function

'**************************************************
'函数名：CheckUserLogined
'作  用：检查用户是否登录
'参  数：无
'返回值：True ----已经登录
'        False ---没有登录
'**************************************************
function CheckUserLogined()
	dim Logined,Password,UserName
	Logined=True
	UserName=Request.Cookies("tot")("userid")
	Password=Request.Cookies("tot")("Password")	
	if UserName="" then
		Logined=False
	end if
	if Password="" then
		Logined=False
	end if	
	CheckUserLogined=Logined
end function

'**************************************************
'函数名：strLength
'作  用：求字符串长度。汉字算两个字符，英文算一个字符。
'参  数：str  ----要求长度的字符串
'返回值：字符串长度
'**************************************************
function strLength(str)
	ON ERROR RESUME NEXT
	dim WINNT_CHINESE
	WINNT_CHINESE    = (len("中国")=2)
	if WINNT_CHINESE then
        dim l,t,c
        dim i
        l=len(str)
        t=l
        for i=1 to l
        	c=asc(mid(str,i,1))
            if c<0 then c=c+65536
            if c>255 then
                t=t+1
            end if
        next
        strLength=t
    else 
        strLength=len(str)
    end if
    if err.number<>0 then err.clear
end function

'------------------检查某一目录是否存在-------------------
Function CheckDir(FolderPath)
	dim fso
	folderpath=Server.MapPath(".")&"\"&folderpath
	Set fso1 = Server.CreateObject("Scripting.FileSystemObject")
	If fso.FolderExists(FolderPath) then
	'存在
		CheckDir = True
	Else
	'不存在
		CheckDir = False
	End if
	Set fso = nothing
End Function

'-------------根据指定名称生成目录---------
Function MakeNewsDir(foldername)
	dim fso,f
	Set fso = Server.CreateObject("Scripting.FileSystemObject")
    Set f = fso.CreateFolder(foldername)
    MakeNewsDir = True
	Set fso = nothing
End Function


'**************************************************
'函数名：SendMail
'作  用：用Jmail组件发送邮件
'参  数：MailtoAddress  ----收信人地址
'        MailtoName    -----收信人姓名
'        Subject       -----主题
'        MailBody      -----信件内容
'        FromName      -----发信人姓名
'        MailFrom      -----发信人地址
'        Priority      -----信件优先级
'**************************************************
function SendMail(MailtoAddress,MailtoName,Subject,MailBody,FromName,MailFrom,Priority)
	on error resume next
	Dim JMail
	Set JMail=Server.CreateObject("JMail.Message")
	if err then
		SendMail= "<br><li>没有安装JMail组件</li>"
		err.clear
		exit function
	end if
	JMail.Charset="gb2312"          '邮件编码
	JMail.silent=true
	JMail.ContentType = "text/html"     '邮件正文格式
	'JMail.ServerAddress=MailServer     '用来发送邮件的SMTP服务器
   	'如果服务器需要SMTP身份验证则还需指定以下参数
	JMail.MailServerUserName = MailServerUserName    '登录用户名
   	JMail.MailServerPassWord = MailServerPassword        '登录密码
  	JMail.MailDomain = MailDomain       '域名（如果用“name@domain.com”这样的用户名登录时，请指明domain.com
	JMail.AddRecipient MailtoAddress,MailtoName     '收信人
	JMail.Subject=Subject         '主题
	JMail.HMTLBody=MailBody       '邮件正文（HTML格式）
	JMail.Body=MailBody          '邮件正文（纯文本格式）
	JMail.FromName=FromName         '发信人姓名
	JMail.From = MailFrom         '发信人Email
	JMail.Priority=Priority              '邮件等级，1为加急，3为普通，5为低级
	JMail.Send(MailServer)
	SendMail =JMail.ErrorMessage
	JMail.Close
	Set JMail=nothing
end function
'*************************************************************
'函数作用：判断非法字符
'*************************************************************
Public Function IsValidStr(Str)
	IsValidStr = True
	If IsNull(Str) Then Exit Function
	Dim ForbidStr, i
	ForbidStr = ":|=|%|&|$|#|@|+|-|*|/|\|<|>|;|,|"& Chr(32) &"|"& Chr(34) &"|"& Chr(39) &"|"& Chr(9)&"|"&Chr(10)&"|"&Chr(13)
	ForbidStr = Split(ForbidStr, "|")
	For i = 0 To UBound(ForbidStr)
		If InStr(Str, ForbidStr(i)) > 0 Then
			IsValidStr = False
			Exit Function
		End If
	Next
	IsValidStr = True
End Function
'*************************************************************
'函数作用：判断密码非法字符
'*************************************************************
Public Function IsValidPassword(Str)
	IsValidPassword = True
	If IsNull(Str) Then Exit Function
	Dim ForbidStr, i
	ForbidStr = "=|%|&|;|,|"& Chr(32) &"|"& Chr(34) &"|"& Chr(39) &"|"& Chr(9)&"|"&Chr(10)&"|"&Chr(13)
	ForbidStr = Split(ForbidStr, "|")
	For i = 0 To UBound(ForbidStr)
		If InStr(Str, ForbidStr(i)) > 0 Then
			IsValidPassword = False
			Exit Function
		End If
	Next
	IsValidPassword = True
End Function

'*************************************************************
'函数作用：判断有效字符
'*************************************************************

Function hasValidStr(strings)
    CONST str="abcdefghijklmnopqrstuvwxyz1234567890" '将允许出现的字符集
    strings=Lcase(strings)
    For i = 1 to len(strings)
      get1Char=mid(strings,i,1) '取1个字符
      If instr(str,get1Char)=0 then
        hasValidStr=False '包含非法字符，返回False
        Exit Function
      Else
        hasValidStr=True '未发现非法字符，返回True
      End if
    Next
End Function
%>