// Conditional alert.
function cAlert (message) {
   if (!this.silent)
      alert(message);
}

// Conditional confirm.
function cConfirm (message) {
   if (this.silent)
      return true;
   else
      return confirm(message);
}

// Variable indicating whether or not installation should proceed.
bInstall = true;

// Make sure Java is enabled before doing anything else.
if ( !navigator.javaEnabled() ) {
   bInstall = false;
   cAlert ("Java must be enabled to install.");
}

// Make sure installation is attempted on correct machine architecture.
//else if ( navigator.platform.compareTo("Win32") != 0 ) {
else if ( navigator.platform != "Win32") {
   bInstall = false;
   cAlert ("This plug-in only runs on Win32 platforms.");
}

// If all conditions look good, proceed with the installation.
if (bInstall) {
   // Create a version object and a software update object
   // version is compiled from current Blender version and plug-in
   // specific updates
   vi = new netscape.softupdate.VersionInfo(2, 22, 0, 0);
   su = new netscape.softupdate.SoftwareUpdate(this, 
      "NaN Technologies Blender 3D Plug-in");

   // Start the install process
   err = su.StartInstall("plugins/NaNTechnologies/Blender3DPlugin/", vi, 
      netscape.softupdate.SoftwareUpdate.FULL_INSTALL);

   if (err != 0)
      cAlert ("Installation error 1. Aborting.");

   else {
      bAbort = false;

      // Find the plug-ins directory on the user's machine
      PIFolder = su.GetFolder("Plugins");

      // Install the files. Unpack them and list where they go
      err = su.AddSubcomponent("Blender 3D Plug-in DLL", vi, "npBlender3DPlugin.dll",
         PIFolder, "", this.force);
      bAbort = bAbort || (err !=0);

//      if (!bAbort) {
//         err = su.AddSubcomponent("RoyalPI Help", vi, "help.htm", 
//            PIFolder, "RoyalPI/help.htm", this.force);
//         bAbort = bAbort || (err !=0);
//      }

      if (!bAbort) {
         err = su.AddSubcomponent("Python DLL", vi, "python20.dll", 
            PIFolder, "", this.force);
         bAbort = bAbort || (err !=0);
      }

      if (bAbort)
         cAlert ("Installation error 2. Aborting.");
   }

   // Unless there was a problem, move files to final location 
   // and update the Client Version Registry
   if (bAbort) {
      cAlert ("Installation error 3. Aborting.");
      su.AbortInstall();
   }
   else {
      err = su.FinalizeInstall();

      // Refresh list of available plug-ins
      if (err == 0)
      {
         navigator.plugins.refresh(true);
         cAlert ("The Blender 3D Plug-in is now ready for use.\nVisit http://www.blender3d.com/plugin/ demo's section for some examples.");
      }
      else if (err == 999) {
         cAlert("You must reboot to finish this installation.");
         err = 0;
      }
   }

   if ( bAbort || err != 0 )
      cAlert("Install encountered errors.");
}

