<%
Class Cls_Ad

    Dim ClassId, MaxAdNum, HtmlFilePath

    Private Sub Class_Initialize()
        ClassId = 1
        HtmlFilePath = SiteWebFilePath & "Scripts/Code/html/"
        Easp.Use "fso"
    End Sub

    Private Sub Class_Terminate()
    End Sub

    Public Property Let SetClassId(ByVal NewValue)
        ClassId = CLng(NewValue)
    End Property

    Private Sub GetAdClsVal()
        Dim oRs
        Set oRs = Easp.db.GR(TablePrefix & "AdType:MaxNum:1", " Id = " & ClassId & " ", "")
        If Easp.IsN(oRs) Then
            MaxAdNum = 1
        Else
            MaxAdNum = oRs("MaxNum")
        End If
        Easp.db.C oRs
    End Sub

    Private Function ReadTemp(ByVal UrlLink, ByVal PicUrl, ByVal Width, ByVal Height)
        Dim ExtName, strTemp
        ExtName = Easp.Fso.ExtOf(PicUrl)
        strTemp = "<div style=""position:relative;width:"& Width &"px;height:"& Height &"px;"">"
        If LCase(ExtName) = ".swf" Then
            strTemp = strTemp & "<object classid=""clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"""
            strTemp = strTemp & "  codebase=""http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"" "
            strTemp = strTemp & " width="""& Width &""" height="""& Height &""" ""classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"">"
            strTemp = strTemp & "<param name=""movie"" value="""& PicUrl &""">"
            strTemp = strTemp & "<param name=""salign"" value=""TL"">"
            strTemp = strTemp & "<param name=""wmode"" value=""Transparent"">"
            strTemp = strTemp & "<param name=""wmode"" value=""opaque"">"
            strTemp = strTemp & "<param name=""quality"" value=""High"">"
            strTemp = strTemp & "<embed src="""& PicUrl &""" quality=""high"" allowscriptaccess=""always"" wmode=""transparent"" type=""application/x-shockwave-flash"" "
            strTemp = strTemp & " pluginspage=""http://www.macromedia.com/go/getflashplayer"" height="""& Height &""" width="""& Width &""">"
            strTemp = strTemp & "</object>"
            strTemp = strTemp & "<a href="""& UrlLink &""" target=""_blank"" style=""position:absolute;left:0px;top:0px;width:"& Width &"px;height:"& Height &"px;"">"
            strTemp = strTemp & "<img src="""& SiteWebFilePath &"Scripts/Code/images/blank.gif"" style=""display:block;overflow:hidden;width:"& Width &"px;height:"& Height &"px;"" border=""0"" />"
            strTemp = strTemp & "</a>"
        Else
            strTemp = strTemp & "<a href=""" & UrlLink & """ target=""_blank"">"
            strTemp = strTemp & "<img src="""& SiteWebFilePath &"Scripts/Code/images/blank.gif"" style=""position:absolute;left:0px;top:0px;width:" & Width & "px;height:" & Height & "px;border:none;"" />"
            strTemp = strTemp & "<img src=""" & Picurl & """ width=""" & Width & """ height=""" & Height & """ border=""0"" />"
            strTemp = strTemp & "</a>"
        End If
        strTemp = strTemp & "</div>"
        ReadTemp = strTemp
    End Function

    Public Sub Show()
        Dim Rs, strTemp
        Dim strFalshAndPic, strAdContent, strJsContent
        Dim strMargin, strCommon, strFixed2, strFixed3, strAdcode
        strMargin = ""
        GetAdClsVal()
        Set Rs = Easp.db.GR(TablePrefix & "Ad:" & MaxAdNum, " ClassId=" & ClassId & " ", " Id Desc ")
        If Not Easp.IsN(Rs) Then
            Do While Not Rs.EOF
                If Now() > Rs("StartTime") And Now() < Rs("EndTime") Then
                    Select Case CInt(Rs("TypeId"))
                        Case 2, 3
                            If Rs("TypeId") = 2 Then strMargin = "style=""left:" & Rs("S") & "px;position:absolute;top:" & Rs("T") & "px;"""
                            If Rs("TypeId") = 3 Then strMargin = "style=""right:" & Rs("S") & "px;position:absolute;top:" & Rs("T") & "px;"""
                            strFalshAndPic = ReadTemp(Rs("Url"), Rs("PicUrl"), Rs("W"), Rs("H"))
                            strFixed2 = strFixed2 & "$('#ZjjCmsJsFileFixed" & Rs("id") & "').css('top', parseInt($('#ZjjCmsJsFileFixed" & Rs("id") & "').css('top')) + percent + 'px');" & vbCrLf
                            strFixed3 = strFixed3 & "suspendcode" & Rs("id") & "='<div id=""ZjjCmsJsFileFixed" & Rs("id") & """ " & strMargin & ">" & strFalshAndPic & "</div>'" & vbCrLf
                            strFixed3 = strFixed3 & "document.write(suspendcode" & Rs("id") & "); " & vbCrLf
                        Case 4
                            strAdContent = strAdContent & Rs("Adcode")
                            strAdcode = "" & vbCrLf
                            strAdcode = strAdcode & "/*" & vbCrLf
                            strAdcode = strAdcode & " * 代码广告" & vbCrLf
                            strAdcode = strAdcode & " * 加入时间：" & Rs("AddTime") & "" & vbCrLf
                            strAdcode = strAdcode & " * 投放时间：" & Rs("StartTime") & "" & vbCrLf
                            strAdcode = strAdcode & " * 结束时间：" & Rs("EndTime") & "" & vbCrLf
                            strAdcode = strAdcode & "*/" & vbCrLf
                            strAdcode = strAdcode & "document.writeln('<iframe scrolling=""no"" frameborder=""0"" marginheight=""0"" marginwidth=""0"" width=""" & Rs("W") & """ height=""" & Rs("H") & """ allowTransparency src=""" & HtmlFilePath & SysLable & "_" & ClassId & ".html""></iframe>');" & vbCrLf & vbCrLf

                        Case 5
                            strJsContent = strJsContent & Rs("Adcode")
                        Case Else
                            strFalshAndPic = ReadTemp(Rs("Url"), Rs("PicUrl"), Rs("W"), Rs("H"))
                            strCommon = strCommon & "/*" & vbCrLf
                            strCommon = strCommon & " * 普通广告" & vbCrLf
                            strCommon = strCommon & " * 加入时间：" & Rs("AddTime") & "" & vbCrLf
                            strCommon = strCommon & " * 投放时间：" & Rs("StartTime") & "" & vbCrLf
                            strCommon = strCommon & " * 结束时间：" & Rs("EndTime") & "" & vbCrLf
                            strCommon = strCommon & "*/" & vbCrLf
                            strCommon = strCommon & "document.writeln('" & strFalshAndPic & "');" & vbCrLf & vbCrLf
                    End Select
                End If
                Rs.MoveNext
            Loop
            Easp.Fso.CreateFolder HtmlFilePath
        End If
        Easp.db.C Rs
        strTemp = strCommon
        If Not Easp.IsN(Trim(strFixed2)) Then
            Dim RndNum
            RndNum = Easp.RandStr(20)
            strTemp = strTemp & Easp.Fso.Read(SiteWebFilePath & "Scripts/Code/template/fixed.js")
            strTemp = Replace(strTemp, "{$RandNum}", RndNum)
            strTemp = Replace(strTemp, "{$Scroll}", strFixed2)
            strTemp = Replace(strTemp, "{$SuspendCode}", strFixed3)
        End If
        If Not Easp.IsN(Trim(strAdcode)) Then
            Dim strHtml, HtmlName, Result
            HtmlName = HtmlFilePath & SysLable & "_" & ClassId & ".html"
            strHtml = Easp.Fso.Read(SiteWebFilePath & "Scripts/Code/template/html.html")
            strHtml = Replace(strHtml, "{$HtmlContent}", strAdContent)
            Result = Easp.Fso.CreateFile(HtmlName, strHtml)
            strTemp = strTemp & strAdcode
        End If
        If Not Easp.IsN(strJsContent) Then
            strTemp = strTemp & strJsContent
        End If
        If Not Easp.IsN(Trim(strTemp)) Then
            Easp.W strTemp
        End If
    End Sub

End Class
%>