/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Jim Stiles | www.jdstiles.com */
function startCalc(){
  interval = setInterval("calc()",1);
}
function startCalcLiab(){
  intervalliab = setInterval("calcliab()",1);
}

function calc(){
  cash = document.form1.assetsCash.value;
  savings = document.form1.assetsSavings.value; 
  ira = document.form1.assetsIRA.value; 
  ar =  document.form1.assetsAR.value;
  life = document.form1.assetsLife.value;
  stocks = document.form1.assetsStocks.value;
  real = document.form1.assetsReal.value;
  auto = document.form1.assetsAuto.value;
  property = document.form1.assetsProperty.value;
  other = document.form1.assetsOther.value;
  document.form1.assetsTotal.value = (cash * 1) + (savings * 1)  + (ira * 1)  + (ar * 1)  + (life * 1) + (stocks * 1)  + (real * 1) 
   + (auto * 1)  + (property * 1)  + (other * 1);
  document.form1.NetWorth.value = document.form1.assetsTotal.value - document.form1.liabTotal.value;
}
function calcliab(){
  ap = document.form1.liabAP.value;
  notes = document.form1.liabNotes.value; 
  install = document.form1.liabInstall.value; 
  installother =  document.form1.liabInstallOther.value;
  loans = document.form1.liabLoans.value;
  liabreal = document.form1.liabReal.value;
  taxes = document.form1.liabTaxes.value;
  liabother = document.form1.liabOther.value;
  document.form1.liabTotal.value = (ap * 1) + (notes * 1)  + (install * 1)  + (installother * 1)  + (loans * 1)
   + (liabreal * 1)  + (taxes * 1)    + (liabother * 1);
    document.form1.NetWorth.value = document.form1.assetsTotal.value  - document.form1.liabTotal.value;

}

function stopCalc(){
  clearInterval(interval);
}
function stopCalcLiab(){
  clearInterval(intervalliab);
}
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function checkNumber(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */

  if (cCode < 48 || cCode > 57 ) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  return false;
}
