﻿
// Class : Definitions
function Definitions()
{
   this._strDefPath = AVInstaller.Initialize();
   this._strCurrentVersion = AVInstaller.InstalledDefVersion;
   this._strCurrentDate = AVInstaller.InstalledDefDate;
   this._strAvailableVersion = AVInstaller.AvailDefVersion;
   this._strAvailableDate = AVInstaller.AvailDefDate;
   this._strDefSize = Math.round(AVInstaller.AvailDefSize/1000000);
}


Definitions.prototype.IsUpdateAvailable = function()
{
   return ((this._strCurrentVersion != this._strAvailableVersion) && (this._strAvailableDate != "") && (this._strCurrentVersion != ""));
} 

Definitions.prototype.GetDefinitionsPath = function()
{
   return this._strDefPath;
}

Definitions.prototype.GetDefinitionSize = function()
{
   return this._strDefSize;
}

Definitions.prototype.GetUsersCurrentVersionDate = function()
{
   return this._strCurrentDate;
}

Definitions.prototype.GetAvailableUpgradeDate = function()
{
   return this._strAvailableDate;
}


Definitions.prototype.Debug = function()
{
  for(strProp in this)
  {
     alert(strProp + ":  "+this[strProp]);
  }
  alert(this.IsUpdateAvailable());
}

// END 

var _intRefresh = 0;
window.onload = InitEngine;
function InitEngine()
{
   // IS IE?
   if (navigator.appName.indexOf("Microsoft") == -1)
   {
      ShowErrorMessage(102);
      return false; 
   }

   // Has AV Running, Which will cause conflicts?
   try
   {
      if(AVInstaller.IsAVRunning())
      {
         ShowErrorMessage(101);
         return false;
      }
      // install but check cookie first. if cookie exists, just load program
      var objCookie = new IoloCookie("AvDefn","",new Array("",null,false,15));
      var blnNeedsInstalltion = objCookie.GetCookie() == null;
      if (blnNeedsInstalltion)
      {
          objDefn = new Definitions();
          //objDefn.Debug();
          document.getElementById("hPath").value = objDefn.GetDefinitionsPath();
          objCookie.SetDefinitionsPath(objDefn.GetDefinitionsPath());
          objCookie.SetCookie();
          var blnAvailableUpdate = objDefn.IsUpdateAvailable();
          if(blnAvailableUpdate)
          {  
              document.getElementById('pnlPreScan').style.display = 'block';
              document.getElementById('pnlUpgrade').style.display = 'block';
              document.getElementById('spnUserDefDate').innerHTML = "(last updated: " + objDefn.GetUsersCurrentVersionDate() + ")";
              document.getElementById('spnAvailDefDate').innerHTML = "(available since: " + objDefn.GetAvailableUpgradeDate() + ")<br/><span style=\"padding-left: 23px;font-style:normal; font-size: 9px;\" >This option provides the most secure results, but takes more time and requires a</span><br/><span style=\"padding-left: 23px;font-style:normal; font-size: 9px;\" > download of approximately " + objDefn.GetDefinitionSize() + " MB.</span>";
          }  
          else
          {
             PerformPartialInstall(false);
          }
      }
      else
      {
          document.getElementById('hpath').value = objCookie.GetCookie();
          LoadProgram();
      }
   }
   catch (e) 
   {
      // AvInstaller is not a registered object
      ShowErrorMessage(-1);
   }

 }

function ValidateUpgrade(obj)
{
  var blnUpgrade = true;
  var arrRb = obj.getElementsByTagName("input");
  if(arrRb != null && arrRb.length == 2)
  {
     if(arrRb[0].checked) blnUpgrade = false;
  }
  if(blnUpgrade)
  {
     document.getElementById('pnlUpgrade').style.display = 'none';
     PerformPartialInstall(true);
  }
  else
  {
     PerformPartialInstall(false); 
  }
}
  
function PerformPartialInstall(bln)
{ 
   var interrcode = -1;
   try
   {
      ShowLoadingMessage();
      AVInstaller.DoInstall(bln);
      interrcode = AVInstaller.LastErrorCode;
      if(interrcode == 0)
      {
         LoadProgram();
      }
      else
      {
         if(AVInstaller.IsCancelled)
         {
            interrcode = 1;
         }
         ShowErrorMessage(interrcode);
      }
   }
   catch (e)
   {
      // AvInstaller is not a registered object
      ShowErrorMessage(100);
   }
}

function ShowErrorMessage(errCode)
{
  var objCookie = new IoloCookie("AvDefn", "", new Array("",null,false,15));
  objCookie.DeleteCookie();
  var errMsg = "";
  switch(errCode)
  {
     case 1:
        errMsg = "The initialization process for the Online Virus Scanner was cancelled.  If you want to proceed with a scan, please try again.";
        break;
     case 2:
        errMsg = "An important file was unable to  be downloaded . If you want to proceed with a scan, please try again.";
        break;
     case 3:
        errMsg = "The scanning engine was unable to be downloaded. Verify that Internet Explorer's security policies allow you to install and run ActiveX controls, and try again.";
        break;
     case 4:
        errMsg = "The Online Virus Scanner encountered an error while downloading or installing critical components. Verify that you are currently connected to the Internet, that Internet Explorer's security policies allow you to install and run ActiveX controls, and try again.";
        break;
     case 5:
        errMsg = "The Online Virus Scanner encountered an error while installing virus definition components. If you want to proceed with a scan, please try again.";
        break;
     case 6:
        errMsg = "The  Online Virus Scanner encountered an error while downloading  required components . Verify that Internet Explorer's security policies allow you to install and run ActiveX controls, and try again. ";
     case 7:
        errMsg = "The Online Virus Scanner encountered a corrupted component during initialization. Verify that you are currently connected to the Internet, that Internet Explorer's security policies allow you to install and run ActiveX controls, and try again.";
        break;
     case 100:
        errMsg = "The Online Virus Scanner encountered an unexpected problem. Verify that you are currently connected to the Internet, that Internet Explorer's security policies allow you to install and run ActiveX controls, and try again.  If this does not allow you to proceed, you may need to restart your web browser and attempt the process again.";
        break;
     case 101:
        errMsg = "The Online Virus Scanner may not be used when iolo AntiVirus is running. If you would like to use the Online Virus Scanner with iolo "
                +"AntiVirus installed, you must first close and disable iolo AntiVirus, however this is strongly discouraged.";
        break;
     default:
        errMsg =  "<span style=\"font-size: 11px; color: Black; font-weight:bold;\"> "
                  +"Your current browser security settings are blocking  the iolo Online Virus Scanner installation or "
                  +"execution.</span><br/><br/> To fix this problem, you have two options.<br/><br/>"
                  +"<b>Option 1:</b> Temporarily give iolo Online Virus Scanner permission to install and/or "
                  +"execute: <br/><br/>If you see the standard Internet Explorer Information Bar underneath  "
                  +"the browser address, click the Information Bar and select <b>Install ActiveX Control</b>. "
                  +"Note that you may need to repeat this process if you iolo Online Virus Scanner "
                  +"in the future.<br/><br/> "
                  +"<center><img src=\"images/virusscan/ActiveX.gif\" alt=\"\" /></center> "
                  +"<br /><br />"
                  +"<b>Option 2:</b> Permanently give iolo to install and/or execute:<br/><br/> "
                  +"1. Open Internet Explorer. "
                  +"<br/><br/>"
                  +"2. From the <span style=\"font-weight:bold;\">Tools menu</span>, "
                  +"click <span style=\"font-weight:bold;\">Internet Options</span> and then select the <span style=\"font-weight:bold;\">Security</span> tab. "
                  +"<br/><br/>"
                  +"3. In the <span style=\"font-weight:bold;\">Select a Web content zone to specify its  "
                  +"security settings</span> pane, click <span style=\"font-weight:bold;\">Trusted sites</span>. "
                  +"<br/><br/>"
                  +"4. Click <span style=\"font-weight:bold;\">Sites</span>. "
                  +"<br/><br/>"
                  +"5. Clear the <span style=\"font-weight:bold;\">Require server verification (https:) for "
                  +"all sites in this zone</span> check box. "
                  +"<br/><br/>"
                  +"6. In the <span style=\"font-weight:bold;\">Add this Web site to the Zone</span> field, "
                  +"type in the following Web address: "
                  +"<br/><br/>"
                  +"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; http://www.iolo.com "
                  +"<br/><br/>"
                  +"7. Click <span style=\"font-weight:bold;\">Add</span>. The iolo Web address will display "
                  +"in the Web sites pane. "
                  +"<br/><br/>"
                  +"8. Click <span style=\"font-weight:bold;\">OK</span> to close the Trusted sites window "
                  +"and then click <span style=\"font-weight:bold;\">OK</span> to close the Internet Options window.";

  }
  errMsg += "<br/><br/><a href=\"virusscanstart.aspx\">Try again</a> &nbsp; <a href=\"/threatcenter/\">Back to Threat Center</a>";
  document.getElementById('pnlMessages').innerHTML = errMsg;
}

function ShowLoadingMessage()
{
   var strHTML = "Please wait while the Online Virus Scanner components are installed or updated. "
                +"The time required to complete this process varies dependent on your connection speed: "
                +"<ul><li>Dial-up (56K) ~ 20 min</li><li>DSL/Cable (256K) ~ 5 min</li>"
                +"<li>DSL/Cable (768K) ~ 3 min</li><li>T1 (1.5M) ~ 3 min</li></ul>";
  document.getElementById('pnlMessages').innerHTML = strHTML;
  document.getElementById('pnlMessages').style.display = 'block';
  document.getElementById('pnlPreScan').style.display = 'none';
}

function LoadProgram()
{
   document.getElementById('pnlMessages').innerHTML = "";
   document.getElementById('pnlMessages').style.display = 'none';
   document.getElementById('pnlPreScan').style.display = 'block';
   document.getElementById('pnlUpgrade').style.display = 'none';
   document.getElementById('pnlFileOrFolders').style.display = 'block';
   if (_intRefresh == 0 )
   {
     try { TaskScanner.Initialize(); TaskScanner.Uninitialize(); }
     catch (e) { window.location.reload(); }
     _intRefresh++;
   }
}

function ScrollToTop()
{
  document.getElementById('ScanningInfections').style.scrollY = 0;
}

window.onbeforeunload = function() 
{ 

   var iX = window.document.body.offsetWidth - window.event.clientX ;
   var iY = window.event.clientY ;
   
   if ((iX <=30 && iY) < 0 || (window.event.keyCode != 0) )
   {
     var objCookie = new IoloCookie("AvDefn", "", new Array("",null,false,15));
     objCookie.DeleteCookie();
     try { AVInstaller.CleanUp(); } catch (e) { }
   }
}

