'dim txtReport
dim intVirusCount
dim blnTSIsRunning
dim blnFoundInfection
dim blnUserCanceled


Sub GetDefVersion
    'dim temp
    'temp = "defId: " + CStr(Version.defId) + vbCr + "defNum: " + CStr(Version.defNum) + vbCr
    'txtReport.value = temp
End Sub

Sub TaskScanner_OnBeginProcessFile(FilePath, bScanFile)
	dim temp
	temp = AVInstaller.CompactPath(FilePath + vbCr, "541", "Verdana", "11")
	if Len(temp) > 64 then
	  temp = Left(temp,64)
	end if 
	'txtReport.value = txtReport.value + temp
	
	' Display file being scanned
	document.getElementById("lblScanProgressLocation").innerHTML = temp
End Sub

Sub TaskScanner_OnEndProcessFile(FilePath)
   ' dim temp
	'temp = "TaskScanner::OnEndProcessFile: " + FilePath + vbCr
	'txtReport.value = txtReport.value + temp
End Sub

Sub TaskScanner_OnReport(Message, CCode, Infection)
    'dim temp
	'temp = "TaskScanner::OnReport: " + Message + vbCr
	'txtReport.value = txtReport.value + temp
End Sub

Sub TaskScanner_OnInfection(FilePath, AltFilePath, Message, CCode, Infection, bArchive)
	'dim temp
	'temp = "TaskScanner::OnInfection: " + Message + vbCr
	'txtReport.value = txtReport.value + temp
	blnFoundInfection = true
	
	document.getElementById("pnlScanningNoVirusesFound").style.display = "none"
	document.getElementById("pnlScanningVirusFound").style.display = "block"
	
	if Infection = "" then
	   Infection = "Unknown Infection"
	end if
	
	intVirusCount = intVirusCount + 1
	
	if intVirusCount = 1 then
	   document.getElementById("txtScanningNumOfViruses").innerHTML = "<b>1</b> virus has"
	else
	   document.getElementById("txtScanningNumOfViruses").innerHTML = "<b>" & intVirusCount & "</b> viruses have"
	end if
	
	dim tblrndr
	tblrndr = "<table cellpadding=""5"" cellspacing=""0"" border=""0"" width=""100%"" style=""border-bottom: 1px #c0c0c0 solid;""><tr><td align=""left"" width=""230px"">"& FilePath &"</td><td align=""left"" width=""100px"">"& AVInstaller.GroomedInfectionDescription (FilePath, Cstr(Infection), bArchive) &"</td><td align=""left"" width=""80px""><a href=""/threatcenter/virussearch.aspx?search="& Infection &""" target=""blank""><u>Infection Info</u></a></td></tr></table>"
    document.getElementById("ScanningInfections").innerHTML = document.getElementById("ScanningInfections").innerHTML & tblrndr
    call(ScrollToTop())
End Sub


Sub ScanFile(filePath)
   dim ccode, rcode, blnTSIsRunning
   blnTSIsRunning = true
   rcode = TaskScanner.Initialize2(objdefnpath.value)
	if rcode = 0 then
        dim  bScanCompressedFiles
        bScanCompressedFiles = true
		'txtReport.value = ""

        ' Establish settings for scan
		TaskScannerSettings.ListScannedFilesInReport = false
		TaskScannerSettings.ScanPackedFiles = bScanCompressedFiles
		TaskScannerSettings.ScanArchiveFiles = bScanCompressedFiles
		TaskScannerSettings.ScanSelfExtractingFiles = bScanCompressedFiles
		TaskScannerSettings.ScanAllFileExtensions = true
		TaskScannerSettings.TreatMacroVariantsAsInfections = true
		TaskScannerSettings.UseArtificialIntelligence = false
		'TaskScannerSettings.ArchivesRecursionLevel = 5

		TaskScanner.TaskScannerSettings = TaskScannerSettings

		' Perform scan
		rcode = TaskScanner.ScanFile(filePath)

		' Show results
        dim TaskScannerStatistics
		set TaskScannerStatistics = TaskScanner.TaskScannerStatistics

        
		' Was scan stopped prematurely?
        dim bCancel
		bCancel = TaskScanner.Cancel
		if bCancel = true then
			'temp = temp + vbCr + "Scan was cancelled" + vbCr
        end if

		'txtReport.value = txtReport.value + temp

		TaskScanner.Uninitialize()
	    
		blnTSIsRunning = false
    End If
End Sub

Function AdditionalScannedFileExtensions()
 Dim A(2)
 A(0) = "class"
 AdditionalScannedFileExtensions = A
End Function

Function ExcludedDirectories()
  Dim A(2)
  A(0) = "c:\temp\"
  A(1) = "d:\testviruses"
  A(2) = "c:\bin\virus\readonly\"
  ExcludedDirectories = A
End Function

Function ExcludedFiles()
  Dim A
  A = Array( "command.com", "eicar.boo" )
  ExcludedFiles = A
End Function
    
Sub ScanDir(dirPath, blnSubFldr)
	dim ccode, rcode
	intVirusCount = 0
    blnTSIsRunning = true
    
	rcode = TaskScanner.Initialize2(objdefnpath.value)
	if rcode = 0 then
        dim  bScanCompressedFiles
        bScanCompressedFiles = true
		'txtReport.value = ""

        ' Establish settings for scan
		TaskScannerSettings.ListScannedFilesInReport = false
		TaskScannerSettings.ScanPackedFiles = bScanCompressedFiles
		TaskScannerSettings.ScanArchiveFiles = bScanCompressedFiles
		TaskScannerSettings.ScanSelfExtractingFiles = bScanCompressedFiles
		TaskScannerSettings.ScanAllFileExtensions = false
		TaskScannerSettings.TreatMacroVariantsAsInfections = true
		TaskScannerSettings.UseArtificialIntelligence = false

		TaskScannerSettings.AdditionalScannedFileExtensions = AdditionalScannedFileExtensions()
		TaskScannerSettings.ExcludedDirectories = ExcludedDirectories()
		TaskScannerSettings.ExcludedFiles = ExcludedFiles()
		
		TaskScanner.TaskScannerSettings = TaskScannerSettings

		' Perform scan
		rcode = TaskScanner.ScanDirectory(dirPath, blnSubFldr)

		' Show results
        dim TaskScannerStatistics
		set TaskScannerStatistics = TaskScanner.TaskScannerStatistics

        'dim temp
		'temp = "Processed Files: " + CStr(TaskScannerStatistics.ProcessedFilesCount) + vbCr
		'temp = temp + "Scanned Files: " + CStr(TaskScannerStatistics.ScannedFilesCount) + vbCr
		'temp = temp + "Infected Files: " + CStr(TaskScannerStatistics.InfectedFilesCount) + vbCr
		'temp = temp + "Suspicious Files: " + CStr(TaskScannerStatistics.SuspiciousFilesCount) + vbCr
		'temp = temp + "Viruses: " + CStr(TaskScannerStatistics.VirusesFoundCount) + vbCr
        
		' Was scan stopped prematurely?
        dim bCancel
		bCancel = TaskScanner.Cancel
		if bCancel = true then
			'temp = temp + vbCr + "Scan was cancelled" + vbCr
        end if

		'txtReport.value = txtReport.value + temp

		TaskScanner.Uninitialize()
	    
		blnTSIsRunning = false
    End If
End Sub

Sub StopScan
    if blnTSIsRunning  then
    ' Tell scanner to stop
      blnUserCanceled = true
      TaskScanner.Cancel = true
    end if
End Sub
        

 Function isfolder(fldr)
    if AVInstaller.DirectoryExists(fldr) then
    ToggleSubfolderPanel(true)
    isfolder = true
    else
    ToggleSubfolderPanel(false)
    isfolder = false
    end if
 end Function

 
 Sub selectfolder
   dim fldr 
   fldr = AVInstaller.BrowseForFolder("Select folder","")
   if fldr <> "" then
    ToggleSubfolderPanel(true)
    document.getElementById("FolderPath").value = fldr
   end if
 end Sub
 
 Sub selectfile
   dim fle 
   fle = AVInstaller.BrowseForFile("Select a file", "", "All Files (*.*)|*.*|Executable Files (*.exe, *.com, *.msi)|*.exe;*.com;*.msi")
   if fle <> "" then
   ToggleSubfolderPanel(false)
    document.getElementById("FolderPath").value = fle
   end if
 end Sub
 
 Sub PreScan 
   if document.getElementById("FolderPath").value <> "" or document.getElementById("rbFullScan").checked then
   ToggleStartScanButton(true)
   end if
   call window.setTimeout(("Scan()"), 20)
 End Sub
 
 
 Sub Scan
   dim fpath 
   dim blnFullScan
   blnFullScan = document.getElementById("rbFullScan").checked
   fpath = document.getElementById("FolderPath").value
   if Trim(fpath) = "" and not blnFullScan then  
       ToggleStartScanButton(false)
        call alert("You must specify a file or folder before proceeding with a scan.  ")
       exit sub
   end if
   if blnFullScan then
      ToggleStage(1)
      dim strDelDrives, arrDrives
      strDelDrives = AVInstaller.GetAllActiveDrives()
      arrDrives = Split(strDelDrives, ";", -1, 1)
      for each d in arrDrives
        if not blnUserCanceled then
          call ScanDir((d), true)
        end if
      next
      document.getElementById("txtResultsNumOfViruses").innerHTML = document.getElementById("txtScanningNumOfViruses").innerHTML
      document.getElementById("ResultsInfections").innerHTML = document.getElementById("ScanningInfections").innerHTML
      ToggleStage(2)
   else
        if AVInstaller.FileExists(Trim(fpath)) then
            ToggleStage(1)
            ScanFile(fpath)
            document.getElementById("txtResultsNumOfViruses").innerHTML = document.getElementById("txtScanningNumOfViruses").innerHTML
            document.getElementById("ResultsInfections").innerHTML = document.getElementById("ScanningInfections").innerHTML
            call window.setTimeout(("ToggleStage(2)"), 3000)
        elseif AVInstaller.DirectoryExists(Trim(fpath)) then
            if document.getElementById("cbScanSubFolders").checked then
               ToggleStage(1)
               call ScanDir((fpath), true)
               document.getElementById("txtResultsNumOfViruses").innerHTML = document.getElementById("txtScanningNumOfViruses").innerHTML
               document.getElementById("ResultsInfections").innerHTML = document.getElementById("ScanningInfections").innerHTML
               call window.setTimeout(("ToggleStage(2)"), 2000)
            else
               ToggleStage(1)
               call ScanDir((fpath), false)
               document.getElementById("txtResultsNumOfViruses").innerHTML = document.getElementById("txtScanningNumOfViruses").innerHTML
               document.getElementById("ResultsInfections").innerHTML = document.getElementById("ScanningInfections").innerHTML
               call window.setTimeout(("ToggleStage(2)"), 3000)
            end if
        else
          ToggleStartScanButton(false)
          dim strAlert
          call alert("You must enter a valid file or directory  before proceeding with a scan.   ")
        end if
   end if 
   ToggleStartScanButton(false)
 end Sub
 
 Sub ToggleStartScanButton(blnOff)
    if blnOff then
       document.getElementById("imStartScan").src = "images/virusscan/button-startscanning-disabl.gif"
    else 
       document.getElementById("imStartScan").src = "images/virusscan/button-startscanning.gif"
    end if
 end Sub
 
 Sub ToggleSubfolderPanel(blnshow)
   if blnshow then
     document.getElementById("pnlScanSubfolders").style.visibility = "visible"
     ' corrects IE bug, with innerHTML visibility
     document.getElementById("cbScanSubFolders").style.visibility = "visible"
   else 
     document.getElementById("pnlScanSubfolders").style.visibility = "hidden"
     document.getElementById("cbScanSubFolders").style.visibility = "hidden"
   end if
 end Sub
 
 Sub FullScanSelected
   ToggleSubfolderPanel(false)
   document.getElementById("SelectOptions").style.visibility = "hidden"
   document.getElementById("rbFileScan").checked = false
   document.getElementById("rbFullScan").checked = true
 end Sub
 
 Sub FileScanSelected
    ToggleSubfolderPanel(true)
    document.getElementById("SelectOptions").style.visibility = "visible"
    document.getElementById("rbFullScan").checked = false
    document.getElementById("rbFileScan").checked = true
 end Sub
 
 Sub ToggleStage(intStage)
    ' 0 = select, 1 = scanning, 2 = results
    if intStage = 0 then
      document.getElementById("pnlPreScan").style.display = "block"
      document.getElementById("pnlFileOrFolders").style.display = "block"
      document.getElementById("pnlScanning").style.display = "none"
      document.getElementById("pnlResults").style.display = "none"
    elseif intStage = 1 then
      document.getElementById("pnlPreScan").style.display = "none"
      document.getElementById("pnlFileOrFolders").style.display = "none"
      document.getElementById("pnlScanning").style.display = "block"
      document.getElementById("pnlResults").style.display = "none"
    else
      document.getElementById("pnlPreScan").style.display = "none"
      document.getElementById("pnlFileOrFolders").style.display = "none"
      document.getElementById("pnlScanning").style.display = "none"
      document.getElementById("pnlResults").style.display = "block"
      if blnFoundInfection and blnUserCanceled then
         document.getElementById("vsComplete").innerHTML = "Virus Scan Cancelled"
         document.getElementById("pnlResultsVirusFound").style.display = "block"
      elseif blnFoundInfection then
         document.getElementById("pnlResultsVirusFound").style.display = "block"
      elseif blnUserCanceled then
         document.getElementById("pnlCancelResults").style.display = "block"
      else
         document.getElementById("pnlResultsNoVirusesFound").style.display = "block"
      end if
    end if
 end Sub
 
 Sub ResetVirusScanner
   intVirusCount = 0
   blnFoundInfection = false
   blnUserCanceled = false
   ToggleStage(0)
   document.getElementById("pnlScanningVirusFound").style.display = "none"
   document.getElementById("pnlCancelResults").style.display = "none"
   document.getElementById("pnlResultsNoVirusesFound").style.display = "none"
   document.getElementById("pnlResultsVirusFound").style.display = "none"
   document.getElementById("txtScanningNumOfViruses").innerHTML = "<b>0</b> viruses have"
   document.getElementById("ScanningInfections").innerHTML = ""
   document.getElementById("ResultsInfections").innerHTML = ""
   document.getElementById("txtResultsNumOfViruses").innerHTML = ""
   document.getElementById("FolderPath").value = ""
   FullScanSelected()
 end Sub
