Number of fights on Raid Boss

This calculator gives you the optimal number of fights you need to do in order to get the maximum reward.

HTML

<p><b>THIS CALCULATOR IS NOT CHECKED FOR COMPATIBILITY WITH CLICKER HEROES VERSION 1.0</b></p>
<p>
This calculator is mainly meant to avoid overspending of rubies on a boss. The Hero Souls reward you can get is limited by the Total Hero Souls From Ascensions you gained during your gameplay. </p>
<p>
  The calculator is able to give you the optimal amount of fights you need to do in order to get the maximum reward. Also displays the optimal boss for a solo-clan.
</p>
<p><a href="https://www.reddit.com/r/ClickerHeroes/comments/3gj93c/clans_faq/ctywuan" target="_blank">Formulas used</a> | <a href="https://www.reddit.com/r/ClickerHeroes/comments/4933u8/update_to_raid_boss_calculator/" target="_blank">Reddit post</a> | v 0.61</p>
<form id='inputmethodform'>
  <input type='radio' name='inputmethod' id='savegameinput' checked /> Input via save game (recommended)
  <input type='radio' name='inputmethod' id='manualinput' /> Manual input
</form>
<div id='inputmethodsavegame'>
  <textarea id='savegame' placeholder='Paste your save game here' autofocus onclick='this.focus();this.select()'></textarea>
</div>
<div id='inputmethodmanual' style='display:none'>
  Immortal Damage:
  <input type='number' id='idInput' onkeyup="if (event.keyCode == 13)
document.getElementById('calculate').click()" placeholder="e.g. 1.234e9" />
  <br>Total Hero Souls From Ascensions (≈ID):
  <input type="number" id="totalHSInput" onkeyup="if (event.keyCode == 13)
document.getElementById('calculate').click()" placeholder="e.g. 1.234e9" />
</div>
<br> Raid boss level:
<input type="number" id="currentlevel" onkeyup="if (event.keyCode == 13)
document.getElementById('calculate').click()" placeholder="" />
<br> Select an option:
<br>
<select id="clickerchoice" size="3">
  <option selected="selected">Number of clicks in 1 fight (30sec):</option>
  <option>Total damage in 1 fight (30sec):</option>
  <option>Clicks/sec you perform:</option>
</select>
<input type="number" id="clicks" onkeyup="if (event.keyCode...

CSS

body {
  font-family: arial;
  font-size: 14px;
}

table.t1 {
  border-collapse: collapse;
  font-family: Arial, Helvetica, sans-serif;
}

.t1 th,
.t1 td {
  padding: 4px 8px;
}

.t1 thead th {
  background: #4f81bd;
  text-transform: lowercase;
  text-align: left;
  font-size: 15px;
  color: #fff;
}

.t1 tr {
  border-right: 1px solid #95b3d7;
}

.t1 tbody tr {
  border-bottom: 1px solid #95b3d7;
  text-align: left;
}

.t1 tbody tr:nth-child(odd) {
  background: #dbe5f0;
}

.t1 tbody th,
.t1 tbody tr:nth-child(even) td {
  border-right: 1px solid #95b3d7;
}

.t1 tfoot th {
  background: #4f81bd;
  text-align: left;
  font-weight: normal;
  font-size: 10px;
  color: #fff;
}

.t1 tr *:nth-child(2) {
  text-align: right;
}

.info,
.success,
.warning,
.error,
.validation {
  border: 1px solid;
  margin: 10px 0px;
  padding: 15px 10px 15px 50px;
  background-repeat: no-repeat;
  background-position: 10px center;
}

.info {
  color: #00529B;
  background-color: #BDE5F8;
}

.success {
  color: #4F8A10;
  background-color: #DFF2BF;
}

.warning {
  color: #9F6000;
  background-color: #FEEFB3;
}

.error {
  color: #D8000C;
  background-color: #FFBABA;
  background-image: url('https://i.imgur.com/wwnm5k1.png');
}

JavaScript

getCookies();

$('#inputmethodform').change(function() {
  if ($('#savegameinput').prop('checked')) {
    $('#inputmethodsavegame').show();
  } else {
    $('#inputmethodsavegame').hide();
  }
  if ($('#manualinput').prop('checked')) {
    $('#inputmethodmanual').show();
  } else {
    $('#inputmethodmanual').hide();
  }
});

function calculate() {
  var OptLevel;
  var OptRuns;
  var output1 = '';
  var output2 = '';
  var messages = ["output1", "output2"];
  for (i = 0; i < 2; i++) {
    document.getElementById(messages[i]).innerHTML = '';
  }

  if ($('#savegameinput').is(':checked')) {
    var txt = document.getElementById("savegame").value;
    if (txt.indexOf("Fe12NAfA3R6z4k0z") > -1) {
      setCookies();
      document.getElementById("output1").innerHTML = "Decoding...";
      var result = txt.split("Fe12NAfA3R6z4k0z");
      txt = "";
      for (var i = 0; i < result[0].length; i += 2)
        txt += result[0][i];
      var data = JSON.parse(atob(txt));
    } else
      document.getElementById("output1").innerHTML = '<div class="error">Not a valid save, try again.</div>';

    totalHS = +data.totalHeroSoulsFromAscensions;
    id = +data.titanDamage;
  } else {
      setCookies();
    totalHS = +document.getElementById("totalHSInput").value;
    id = +document.getElementById("idInput").value;
  }

  rewardLimit = Math.round(totalHS / 10);

  var currentlevel = +document.getElementById("currentlevel").value;
  clicks = +document.getElementById("clicks").value;
  switch (document.getElementById("clickerchoice").selectedIndex) {
    case 0: // this is default
      break;
    case 1:
      clicks = Math.round(clicks / id);
      break;
    case 2:
      clicks = clicks * 30;
      break;
  }


  if (currentlevel == 0 || clicks == 0 || id == 0 || totalHS == 0) {
    document.getElementById("output1").innerHTML = '<div class="error">Please enter all values.</div>';
    return;
  }

    runs = (rewardLimit * (100 + 10 * currentlevel) / (5 * Math.pow(2,...