<!--
//NERO East Tennessee Build Calculator
//Created by: Brian Ball, NERO ETN Webmaster
//Created on: October 7, 2003
//For personal use only
//Accurate as of the 8th edition NERO Rulebook
//You may copy this onto another website, as long as I get credit.
//Versions:
//          1.0  First release
//{current} 1.1  Calculates new build total after each blanket, instead of adding all blankets at once
//               this eliminated the need for the "transfer BP" button, and it was removed.
  function newchar(){
    document.bpcalc.tb.value=30
  }
  function validate(){
    if ((isNaN(document.bpcalc.tb.value)) || (isNaN(document.bpcalc.blankets.value)) || (parseInt(document.bpcalc.tb.value) < 0) || (parseInt(document.bpcalc.blankets.value) < 0) || (document.bpcalc.tb.value == "") || (document.bpcalc.blankets.value =="")){
      alert("'Current Build Points' and 'Number of blankets to add' both must be non-negative numbers!")
    }
    else{
      calcbuild()
    }
  }
  function calcbuild(){
    var tbp = parseInt(document.bpcalc.tb.value)//total built points
    var blanket = parseInt(document.bpcalc.blankets.value)//number of blankets
    var level = ((tbp - 5) / 10) //character level
    var baselvl = Math.floor(level)//base character level (whole number)
    var basexp = 0 //minimum xp needed for a level
    var xplvl = 30 //how many xp are needed to gain a level
    var step = 40
    var xptobp = 3 //how many xp it takes to make 1 bp
    var xptobpstep = 4
    var totalxp = 0
    var xpgained = tbp * blanket
    var count = 1
    for (count; count < baselvl; count++){
      basexp += xplvl
      xplvl += step
      step += 10
      xptobp += xptobpstep
      xptobpstep++
    }
    totalxp = basexp
    if (baselvl != level){
      var times = parseInt((level-baselvl)*10)
      for (times; times != 0; times--){
        totalxp += xptobp
        basexp = totalxp
      }
    }
    for (var i = 0; i < blanket; i++){
      totalxp += tbp
      var whiletest = 1
      while (whiletest != 0){
        var templvl = baselvl
        if (totalxp >= (basexp + xptobp)){
          basexp += xptobp
          tbp++
          level = ((tbp - 5) / 10)
          baselvl = Math.floor(level)
          if (templvl != baselvl){
            xptobp += xptobpstep
            xptobpstep++
          }
        }
        else{
          whiletest = 0
        }
      }// end while loop
    }//end for loop
 
    document.bpcalc.newxp.value = totalxp
    document.bpcalc.newbp.value = tbp

  }  //end calcbuild( )
//-->
