[%- wrap = false -%]
  function buildTest() {
    var ua = navigator.userAgent;
    var buildID = navigator.buildID;
    // Uncomment one of those user agents and/or buildIDs to test this script
    // ua="Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.8b2) Gecko/20050324 SeaMonkey/1.0a"
    // ua="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.6) Gecko/20070802 SeaMonkey/1.1.4"
    // ua="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9a8pre) Gecko/2007082021 SeaMonkey/2.0a1pre"
    // ua="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0rc3) Gecko/20020523"
    // ua="Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9a5pre) Gecko/20070515 SeaMonkey/1.5a"
    // ua="Mozilla/5.0 (Windows NT 6.1; rv:2.0) Gecko/20110101 Firefox/4.0 SeaMonkey/2.1"
    // ua="Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0a1) Gecko/20120201 Firefox/13.0a1 SeaMonkey/2.10a1"
    // buildID=0
    // ua="Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/16.0 Firefox/16.0a1 SeaMonkey/2.13a1"
    // buildID=20120612003002

    var smver = ua.match(/SeaMonkey\/([^ ]+)/);
    if (smver) {
      // SM 1.1 was the first to include navigator.buildID
      // SM 2.11 was the last to include the Gecko build date in the UA
      buildID = buildID ? buildID : ua.match(/Gecko\/(\d{8,10})/)[1];
    } else {
      buildID = 0;
    }

    if (!buildID) {
      // not SeaMonkey, display a "get SeaMonkey" box
      init();
      displayElement("stable", false);
      displayElement("old_get", true);
      displayElement("getseamonkey", true);
      return;
    }

    // stable builds only have digits and dots in their version number!
    var smver_parts = smver[1].split(".");
    if (smver[1].match(/^[\d\.]+$/)) {
      // stable build, leave "friendy" intro box turned on

      // check for version number and display a warning and download box if we have a newer version
      var curver = "[% releaseversion %]";
      var curver_parts = curver.split(".");
      var oldversion = false;
      for (var i = 0; i < curver_parts.length; i++) {
        if (i == smver_parts.length || parseInt(curver_parts[i]) > parseInt(smver_parts[i])) {
          oldversion = true;
          break;
        }
        else if (parseInt(curver_parts[i]) < parseInt(smver_parts[i])) {
          break;
        }
      }
      if (oldversion) {
        if (isSupportedOS(ua)) {
          init();
          var vertext = document.createTextNode(" (" + smver[1] + ")");
          document.getElementById("oldvernumber").appendChild(vertext);
          displayElement("old_get", true);
          displayElement("oldstable", true);
        }
        else {
          displayElement("unsupported", true);
        }
        displayElement("stable", false);
      }
    }
    else {
      // unstable build or prerelease, test if nagging box should be displayed
      displayElement("stable", false);
      displayElement("unstable", true);
      displayElement("stablenote", false);
      displayElement("unstablenote", true);

      // prereleases have a version number with a/b in it, possibly digits afterwards
      // however, with the rapid release train, nightlies end with a1
      var prerel_parts = smver[1].match(/^[\d\.]+([ab]\d*)$/);
      if (prerel_parts && prerel_parts[1] && prerel_parts[1][0] != "a") {
        // check for version number and display a warning and download box if we have a newer version
        var curbeta = "[% betaversion %]";
        var curbeta_parts = curbeta.split(".");
        var oldbeta = false;
        for (var i = 0; i < curbeta_parts.length; i++) {
          // don't use parseInt() for beta - this means that parts with numbers
          // larger than 9 are incorrect but alphas and betas are correct
          if (curbeta_parts[i] > smver_parts[i]) {
            oldbeta = true;
            break;
          }
          else if (curbeta_parts[i] < smver_parts[i]) {
            break;
          }
        }
        if (oldbeta) {
          displayElement("nagBox-beta", true);
        }
      }
      else {
        // milliseconds per day
        var msecsPerDay = 86400000;
        var nagLimit = 28 * msecsPerDay;

        // construct build date from ID
        var buildDate = new Date(buildID.substr(0,4),
                                 buildID.substr(4,2)-1,
                                 buildID.substr(6,2));

        var today = new Date();
        if (today - buildDate > nagLimit) {
          // build is old. Show the nag box
          displayElement("nagBox", true);
        }
      }
    }
  }

  if (window.addEventListener) {
    window.addEventListener("load", buildTest, true);
  }
  else if (window.attachEvent) {
    window.attachEvent("onload", buildTest);
  }
