<!--
/********************************************************************************
Copyright (C) 2001 Raymond James Financial
This script is made by and copyrighted to Raymond James Financial at www.raymondjames.com
This may not be used without prior permission from Raymond James Financial
********************************************************************************/
//declare global variables
var cashsubtotal = 0;
var investmentsSubtotal = 0;
var useSubtotal = 0;
var assetTotal = 0;
var ltLiaSubtotal = 0;
var stLiaSubtotal = 0;
var liabilitiesTotal = 0;
var totNetworth = 0;
var valid;

//Check for non-numeric info and alert user
function CheckNumber(TheNumber, theField) {
	var valid = 1;
	var GoodChars = "0123456789,.";
	var i = 0;
	if (TheNumber=="") {
		// Return false if number is empty
		valid = 0;
	}
	for (i =0; i <= TheNumber.length -1; i++) {
		if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
alert(TheNumber.charAt(i) + " is not a valid number.  Please enter numbers only.");
			valid = 0;
			theField.focus()
			theField.select();
			break;
		} // End if statement
		else{calcAll()}
	} // End for loop
	return valid
}

//Remove Commas from numbers entered
function remove(number){
	var number = number.replace(",", "");
	var number = number.replace(",", "");
	var number = number.replace(",", "");
	return number;
}

//Calculate Cash Subtotal
function CalcCash(){
	var Cash = remove(document.formCash.inputCash.value);
	var MoneyMarket = remove(document.formCash.inputMoneyMarket.value);
	var LifeInsurance = remove(document.formCash.inputLifeInsurance.value);
	cashsubtotal = eval(Cash) + eval(MoneyMarket) + eval(LifeInsurance);
	cashsubtotalcur = currency(cashsubtotal);
	document.formCash.inputCashSubtotal.value = cashsubtotalcur;
	}


//Calculate Investment Subtotal
function calcInvestment(){
	var CD = remove(document.formInvestments.inputCD.value);
	var Stock = remove(document.formInvestments.inputStock.value);
	var BondsTF = remove(document.formInvestments.inputBondsTF.value);
	var BondsTA = remove(document.formInvestments.inputBondsTa.value);
	var MutFundF = remove(document.formInvestments.inputMutFundF.value);
	var MutFundE = remove(document.formInvestments.inputMutFundE.value);
	var ProMon = remove(document.formInvestments.inputProMon.value);
	var Pen = remove(document.formInvestments.inputPen.value);
	var IRA = remove(document.formInvestments.inputIRA.value);
	var Ann = remove(document.formInvestments.inputAnn.value);
	var Notes = remove(document.formInvestments.inputNotes.value);
	var Real = remove(document.formInvestments.inputReal.value);
	var OtherInv = remove(document.formInvestments.inputOtherInv.value);
	investmentsSubtotal = eval(CD) + eval(Stock) + eval(BondsTF) +
eval(BondsTA) + eval(MutFundF) + eval(MutFundE) + eval(ProMon) +
eval(Pen) + eval(IRA) + eval(Ann) + eval(Notes) + eval(Real) + eval(OtherInv);
investmentsSubtotalCur = currency(investmentsSubtotal);
	document.formInvestments.inputInvestmentsSubtotal.value = investmentsSubtotalCur;
}

//Calculate Use Subtotal
function calcUse(){
	var Home = remove(document.formUse.inputHome.value);
	var Pers = remove(document.formUse.inputPers.value);
	var Auto = remove(document.formUse.inputAuto.value);
	var Coll = remove(document.formUse.inputColl.value);
	var OtherUse1 = remove(document.formUse.inputOtherUse1.value);
	var OtherUse2 = remove(document.formUse.inputOtherUse2.value);
	var OtherUse3 = remove(document.formUse.inputOtherUse3.value);
	var OtherUse4 = remove(document.formUse.inputOtherUse4.value);
	useSubtotal = eval(Home) + eval(Pers) + eval(Auto) + eval(Coll) + eval(OtherUse1) + eval(OtherUse2) + eval(OtherUse3) + eval(OtherUse4);
	useSubtotalCur = currency(useSubtotal);
	document.formUse.inputUseSubtotal.value = useSubtotalCur;
}
//Calculate Assets Total
function calcAssetTotals(){
	assetTotal = eval(cashsubtotal) + eval(investmentsSubtotal) + eval(useSubtotal);
	assetTotalCur = currency(assetTotal);
	document.formUse.inputTotalAssets.value = assetTotalCur;
}

//Calculate Long Term Liabilities Subtotal
function calcLTLiabilitiesSubtotal(){
	var Home = remove(document.formLT.inputHome.value);
	var Car = remove(document.formLT.inputCar.value);
	var REMort = remove(document.formLT.inputREMort.value);
	var LoansIns = remove(document.formLT.inputLoansIns.value);
	var LoansInv = remove(document.formLT.inputLoansInv.value);
	ltLiaSubtotal = eval(Home) + eval(Car) + eval(REMort) + eval(LoansIns) + eval(LoansInv);
	ltLiaSubtotalCur = currency(ltLiaSubtotal);
	document.formLT.inputLongTermSubtotal.value = ltLiaSubtotalCur;
}

//Calculate Short Term Liabilities Subtotal
function calcSTLiabilitiesSubTotal(){
	var CC = remove(document.formST.inputCC.value);
	var OSTD1 = remove(document.formST.inputOSTD1.value);
	var OSTD2 = remove(document.formST.inputOSTD2.value);
	var OSTD3 = remove(document.formST.inputOSTD3.value);
	var OSTD4 = remove(document.formST.inputOSTD4.value);
		stLiaSubtotal = eval(CC) + eval(OSTD1) + eval(OSTD2) + eval(OSTD3) + eval(OSTD4);
	stLiaSubtotalCur = currency(stLiaSubtotal);
	document.formST.inputShortTermSubtotal.value = stLiaSubtotalCur;
}

//Calculate Total Liabilities
function calcTotLiabilities(){
	liabilitiesTotal = eval(ltLiaSubtotal) + eval(stLiaSubtotal);
	liabilitiesTotalCur = currency(liabilitiesTotal);
	document.formST.inputTotalLiabilities.value = liabilitiesTotalCur;
}

//Copy Insurance to Totals Insurance
function copyInsurancy(){
	document.formTotalNetWorth.inputTotalNetWorthIns.value = document.formIns.inputLI.value;
}

//Calculate Death Estate
function calcDeathEstate(){
	var LI = remove(document.formIns.inputLI.value)
	totDeathEstate = eval(totNetworth) + eval(LI);
	totDeathEstateCur = currency(totDeathEstate);
	document.formTotalNetWorth.inputdeathNetWorth.value = totDeathEstateCur;
}

//Calculate Total Net Worth (Living Benefit)
function calcTotNetWorth(){
	totNetworth = eval(assetTotal) - eval(liabilitiesTotal);
	totNetWorthCur = currency(totNetworth);
	document.formTotalNetWorth.inputTotalNetWorth.value = totNetWorthCur;
	calcDeathEstate();
}

//Convert Numbers to Currency format
function currency(anynum) {
   anynum=eval(anynum)
   workNum=Math.abs((Math.round(anynum*100)/100));workStr=""+workNum
   if (workStr.indexOf(".")==-1){workStr+=".00"}
   dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0
   pStr=workStr.substr(workStr.indexOf("."))
   while (pStr.length<3){pStr+="0"}

   //--- Adds comma in thousands place.
   if (dNum>=1000) {
      dLen=dStr.length
      dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen)
   }

   //-- Adds comma in millions place.
   if (dNum>=1000000) {
      dLen=dStr.length
      dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen)
   }
   retval = dStr + pStr 
   //-- Put negative sign infront of negative numbers.
   if (anynum<0) {retval="-"+retval}
   return "$"+retval
}


//Execute all functions
function calcAll(){
			CalcCash();
			calcInvestment();
			calcUse();
			calcAssetTotals();
			calcLTLiabilitiesSubtotal();
			calcSTLiabilitiesSubTotal();
			calcTotLiabilities();
			calcDeathEstate();
			calcTotNetWorth();
				
}


//Reset all values to zero
function resetAll(){
	document.formCash.inputCash.value = 0;
	document.formCash.inputMoneyMarket.value = 0;
	document.formCash.inputLifeInsurance.value = 0;
	document.formInvestments.inputCD.value = 0;
	document.formInvestments.inputStock.value = 0;
	document.formInvestments.inputBondsTF.value = 0;
	document.formInvestments.inputBondsTa.value = 0;
	document.formInvestments.inputMutFundF.value = 0;
	document.formInvestments.inputMutFundE.value = 0;
	document.formInvestments.inputProMon.value = 0;
	document.formInvestments.inputPen.value = 0;
	document.formInvestments.inputIRA.value = 0;
	document.formInvestments.inputAnn.value = 0;
	document.formInvestments.inputNotes.value = 0;
	document.formInvestments.inputReal.value = 0;
	document.formInvestments.inputOtherInv.value = 0;
	document.formUse.inputHome.value = 0;
	document.formUse.inputPers.value = 0;
	document.formUse.inputAuto.value = 0;
	document.formUse.inputColl.value = 0;
	document.formUse.inputOtherUse1.value = 0;
	document.formUse.inputOtherUse2.value = 0;
	document.formUse.inputOtherUse3.value = 0;
	document.formUse.inputOtherUse4.value = 0;
	document.formLT.inputHome.value = 0;
	document.formLT.inputCar.value = 0;
	document.formLT.inputREMort.value = 0;
	document.formLT.inputLoansIns.value = 0;
	document.formLT.inputLoansInv.value = 0;
	document.formST.inputCC.value = 0;
	document.formST.inputOSTD1.value = 0;
	document.formST.inputOSTD2.value = 0;
	document.formST.inputOSTD3.value = 0;
	document.formST.inputOSTD4.value = 0;
	document.formIns.inputLI.value = 0;
	document.formTotalNetWorth.inputTotalNetWorthIns.value = 0;
	calcAll();
}
//-->
