<%
'*************************************
'检查是否支持该组件
'*************************************
Function BolCheckObj(ByVal BolString)
    On Error Resume Next
    IsObjInstalled=False
    Set xTestObj=Server.CreateObject(bolString)
    If -2147221005<>Err then
        IsObjInstalled=True
    End If
	If IsObjInstalled=False Then
	    BolCheckObj=False
	ElseIf IsObjInstalled=True Then
	    BolCheckObj=True
	End if
    Set xTestObj=Nothing
End Function

'*************************************
'创建随机字符[参数：字符长度]
'*************************************
Function randomStr(strType,intLength)
    Dim strSeed,seedLength,pos,Str,i
	Select Case strType
		Case 0
            strSeed = "abcdefghijklmnopqrstuvwxyz"
		Case 1
            strSeed = "0123456789"
		Case 2
            strSeed = "0abc1def2ghi3jkl4mno5pqr6stu7vwx8yz9"
		Case 3
            strSeed = "asqb#@cdefghij&^klm59854%^#21aa843j(^&%o15841abu09yz"
	End Select
    seedLength = Len(strSeed)
    Str = ""
    Randomize
    For i = 1 To intLength
        Str = Str + Mid(strSeed, Int(seedLength * Rnd) + 1, 1)
    Next
    randomStr = Str
End Function

'*************************************
'日期转换函数
'Modify:N.Hong 2010.3.20
'*************************************
Function DateToStr(DateTime, ShowType)
	If Len(DateTime) = 0 Or DateTime = "" Then DateToStr = "" : Exit Function
	Dim DateMonth, DateDay, DateHour, DateMinute, DateWeek, DateSecond
	DateMonth = Month(DateTime)
	DateDay = Day(DateTime)
	DateHour = Hour(DateTime)
	DateMinute = Minute(DateTime)
	DateSecond = Second(DateTime)
	If Len(DateMonth)<2 Then DateMonth = "0"&DateMonth
	If Len(DateDay)<2 Then DateDay = "0"&DateDay
	If Len(DateMinute)<2 Then DateMinute = "0"&DateMinute
	
	Select Case ShowType
		Case "Y-m-d"
			DateToStr = Year(DateTime)&"-"&DateMonth&"-"&DateDay
		Case "Y-m-d H:I A"
			Dim DateAMPM
			If DateHour>12 Then
				DateHour = DateHour -12
				DateAMPM = "PM"
			Else
				DateHour = DateHour
				DateAMPM = "AM"
			End If
			If Len(DateHour)<2 Then DateHour = "0"&DateHour
			DateToStr = Year(DateTime)&"-"&DateMonth&"-"&DateDay&" "&DateHour&":"&DateMinute&" "&DateAMPM
		Case "Y-m-d H:I:S"
			If Len(DateHour)<2 Then DateHour = "0"&DateHour
			If Len(DateSecond)<2 Then DateSecond = "0"&DateSecond
			DateToStr = Year(DateTime)&"-"&DateMonth&"-"&DateDay&" "&DateHour&":"&DateMinute&":"&DateSecond
		Case "Y-m-d H:I:S-CN"
			If Len(DateHour)<2 Then DateHour = "0"&DateHour
			If Len(DateSecond)<2 Then DateSecond = "0"&DateSecond
			DateToStr = Year(DateTime)&"年"&DateMonth&"月"&DateDay&"日 "&DateHour&"时"&DateMinute&"分"&DateSecond&"秒"
		Case "YmdHIS"
			DateSecond = Second(DateTime)
			If Len(DateHour)<2 Then DateHour = "0"&DateHour
			If Len(DateSecond)<2 Then DateSecond = "0"&DateSecond
			DateToStr = Year(DateTime)&DateMonth&DateDay&DateHour&DateMinute&DateSecond
		Case "Ymd"
			DateToStr = Year(DateTime)&DateMonth&DateDay
		Case Else
			If Len(DateHour)<2 Then DateHour = "0"&DateHour
			DateToStr = Year(DateTime)&"-"&DateMonth&"-"&DateDay&" "&DateHour&":"&DateMinute
	End Select
End Function

'JPEG处理图片
Function ResizeImg(OrgImgUrl,SaveToUrl,MaxW,MaxH)
	Set Pimg=Server.CreateObject("Persits.Jpeg")
	PimgPath=Server.MapPath(OrgImgUrl)
	Pimg.Open PimgPath
	OrgW=Pimg.OriginalWidth
	OrgH=Pimg.OriginalHeight
	ScaleW=OrgW/OrgH '求高宽比
	ScaleH=OrgH/OrgW '求宽高比
	Ari1=0
	Ari2=0
	If OrgW>MaxW Then
		Ari1=OrgW/MaxW
	Else
		SetW=OrgW
	End If
	If OrgH>MaxH Then
		Ari2=OrgH/MaxH
	Else
		SetH=OrgH
	End If
	If Ari1 <> 0 or Ari2 <> 0 Then
		If Ari1 > Ari2 Then
			SetW = MaxW
			SetH = MaxW * ScaleH
		Else
			SetW = MaxH * ScaleW
			SetH = MaxH
		End If
	End If
	Pimg.Width=SetW
	Pimg.Height=SetH
	Pimg.Quality=90 '质量
	'Pimg.Sharpen 1,101 '锐化
	Pimg.Interpolation=1 '压缩算法
	Pimg.Save Server.MapPath(SaveToUrl) '保存图片
	Pimg.Close
	Set Pimg=Nothing
End Function
%>