function isDigit (c){
	return ((c >= "0") && (c <= "9"))
}

function isInteger (s){
	var i;
	var st=s;
	//alert("st= "+st);
    for (i = 0; i < st.length; i++)
    {
        // Check that current character is number.
        var c = st.charAt(i);
        if (!isDigit(c)) return false;
    }
    // All characters are numbers.
    return true;
}

//function to strip off punctuation marks
function stripBag (s){
	var i;
	//bag is all unacceptable punctuations
	var bag=",/()&^%$#@!:;|\{}[]=+_";
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}//end function

function getTotal(f)
{
	var status,sals_bonus,investInc,rent,ira,groceries,util,tel,eat,clothes,sLoan,auto,
	pTrans,hIns,rIns,storage,aIns,dIns,lIns,homeEx,laundry,medical,bank,cc,hobbies,night,
	movies,internet,computer,gifts,vacation,magazines,personalC,healthCl,memberships,pets,misc,
	home,furniture,car,savings,retirement,assets,creditC,studentL,oLoans,liabilities,otherL,
	otherA;
	
	if (f.status[1].checked==true){status="married";}
	else {status="single";}

	sals_bonus = parseFloat(stripBag(f.sals_bonus.value));
	investInc = parseFloat(stripBag(f.investInc.value));
	rent = parseFloat(stripBag(f.rent.value));
	ira = parseFloat(stripBag(f.ira.value));
	groceries = parseFloat(stripBag(f.groceries.value));
	util = parseFloat(stripBag(f.util.value));
	tel = parseFloat(stripBag(f.tel.value));
	eat= parseFloat(stripBag(f.eat.value));
	clothes= parseFloat(stripBag(f.clothes.value));
	sLoan= parseFloat(stripBag(f.sLoan.value));
	auto= parseFloat(stripBag(f.auto.value));
	pTrans= parseFloat(stripBag(f.pTrans.value));
	hIns= parseFloat(stripBag(f.hIns.value));
	rIns= parseFloat(stripBag(f.rIns.value));
	storage= parseFloat(stripBag(f.storage.value));
	aIns= parseFloat(stripBag(f.aIns.value));
	dIns= parseFloat(stripBag(f.dIns.value));
	lIns= parseFloat(stripBag(f.lIns.value));
	homeEx= parseFloat(stripBag(f.homeEx.value));
	laundry= parseFloat(stripBag(f.laundry.value));
	medical= parseFloat(stripBag(f.medical.value));
	bank= parseFloat(stripBag(f.bank.value));
	cc= parseFloat(stripBag(f.cc.value));
	hobbies= parseFloat(stripBag(f.hobbies.value));
	night= parseFloat(stripBag(f.night.value));
	movies= parseFloat(stripBag(f.movies.value));
	internet= parseFloat(stripBag(f.internet.value));
	computer= parseFloat(stripBag(f.computer.value));
	gifts= parseFloat(stripBag(f.gifts.value));
	vacation= parseFloat(stripBag(f.vacation.value));
	healthCl=parseFloat(stripBag(f.healthCl.value));
	magazines= parseFloat(stripBag(f.magazines.value));
	personalC= parseFloat(stripBag(f.personalC.value));
	memberships=parseFloat(stripBag(f.memberships.value));
	pets= parseFloat(stripBag(f.pets.value));
	misc= parseFloat(stripBag(f.misc.value));
	var totExp=0.00;
	totExp=rent + ira + groceries + util + tel + eat + clothes + sLoan + auto + pTrans + hIns + rIns +
	storage + aIns + dIns + lIns +  laundry + medical + bank + cc + hobbies + night + movies +internet
	+ computer + gifts + vacation + magazines + personalC + memberships + healthCl + pets + misc;

	if (isNaN(totExp)){
		f.totExp.value="";
		}
	else{
		f.totExp.value = formatDollar(totExp);
		}

	//now get percentages of each budget item
	var rentPer,iraPer,groceriesPer,utilPer,eatPer,clothesPer,sLoanPer,autoPer,pTransPer,hInsPer,
	rInsPer,storagePer,aInsPer,dInsPer,lInsPer,laundryPer,medicalPer,bankPer,ccPer,hobbiesPer,
	nightPer,moviesPer,internetPer,computerPer,giftsPer,vacationPer,magazinesPer,personalCPer,healthClPer,
	membershipsPer,petsPer,miscPer;

	if (isNaN(sals_bonus)){
		alert("Please enter a value for Salary")
		sals_bonus=0.00;
		}

	if (isNaN(investInc)){
		alert("Please enter a value for Investment Income")
		investInc=0.00;
		}


	if(isNaN(rent)){
		alert("Please enter a value for Rent")
			rent=0.00;
		}

	if(isNaN(ira)){
		alert("Please enter a value for IRA")
			ira=0.00;
		}

	if(isNaN(groceries)){
		alert("Please enter a value for Groceries")
			groceries=0.00;
			}

	if(isNaN(util)){
		alert("Please enter a value for Utilities")
			util=0.00;
			}

	if(isNaN(tel)){
			alert("Please enter a value for Utilities")
			tel=0.00;
			}

	if(isNaN(eat)){
		alert("Please enter a value for Eating Out")
			eat=0.00;
			}

	if(isNaN(clothes)){
		alert("Please enter a value for Clothes")
		clothes=0.00;
			}

	if(isNaN(sLoan)){
		alert("Please enter a value for Student Loan")
			sLoan=0.00;
			}

	if(isNaN(auto)){
		alert("Please enter a value for Car")
			auto=0.00;
			}

	if(isNaN(pTrans)){
		alert("Please enter a value for Public Transportation")
			pTrans=0.00;
			}

	if(isNaN(hIns)){
		alert("Please enter a value for Health Ins")
			hIns=0.00;
			}

	if(isNaN(rIns)){
		alert("Please enter a value for Renter's Insurance")
			rIns=0.00;
			}

	if(isNaN(storage)){
		alert("Please enter a value for Storage")
			storage=0.00;
			}

	if(isNaN(aIns)){
		alert("Please enter a value for Auto Insurance")
			aIns=0.00;
			}

	if(isNaN(dIns)){
		alert("Please enter a value for Disability Insurance")
		dIns=0.00;
			}

	if(isNaN(lIns)){
		alert("Please enter a value for Life Insurance")
		lIns=0.00;
			}

	if(isNaN(homeEx)){
		alert("Please enter a value for Home Expenses")
		homeEx=0.00;
			}

	if(isNaN(laundry)){
		alert("Please enter a value for Laundry")
		laundry=0.00;
			}

	if(isNaN(medical)){
		alert("Please enter a value for Medical Expenses")
		medical=0.00;
			}

	if(isNaN(bank)){
		alert("Please enter a value for Bank Fees")
		bank=0.00;
			}

	if(isNaN(cc)){
		alert("Please enter a value for Credit Card Interest Payments & Finance Charges")
		cc=0.00;
			}

	if(isNaN(hobbies)){
		alert("Please enter a value for Hobbies")
			hobbies=0.00;
			}

	if(isNaN(night)){
		alert("Please enter a value for Nightlife")
			night=0.00;
			}

	if(isNaN(movies)){
		alert("Please enter a value for Movies")
			movies=0.00;
			}

	if(isNaN(internet)){
		alert("Please enter a value for Internet")
			internet=0.00;
			}

	if(isNaN(computer)){
		alert("Please enter a value for Computers")
			computer=0.00;
			}

	if(isNaN(gifts)){
		alert("Please enter a value for Gifts")
			gifts=0.00;
			}

	if(isNaN(vacation)){
		alert("Please enter a value for Vacation")
		vacation=0.00;
			}

	if(isNaN(magazines)){
		alert("Please enter a value for Magazines")
		magazines=0.00;
			}

	if(isNaN(personalC)){
		alert("Please enter a value for Personal Care")
		personalC=0.00;
			}

	if(isNaN(healthCl)){
		alert("Please enter a value for Health Club Fees")
		lIns=0.00;
			}

	if(isNaN(memberships)){
		alert("Please enter a value for Memberships")
		memberships=0.00;
			}

	if(isNaN(pets)){
		alert("Please enter a value for Pets")
		pets=0.00;
			}

	rentPer=(rent/totExp)*100;

	if(isNaN(rentPer))
		f.rentPer.value=0.00;
	else
		f.rentPer.value=formatPer(rentPer);
	iraPer=(ira/totExp)*100;

	if (isNaN(iraPer))
		f.iraPer.value=0.00;
	else
		f.iraPer.value=formatPer(iraPer);
	groceriesPer=(groceries/totExp)*100;

	if(isNaN(rentPer))
			f.groceriesPer.value=0.00;
	else
		f.groceriesPer.value=formatPer(groceriesPer);

	utilPer=(util/totExp)*100;

	if(isNaN(utilPer))
			f.utilPer.value=0.00;
	else
		f.utilPer.value=formatPer(utilPer);

	telPer=(tel/totExp)*100;

	if(isNaN(telPer))
			f.telPer.value=0.00;
	else
		f.telPer.value=formatPer(telPer);

	eatPer=(eat/totExp)*100;

	if(isNaN(eatPer))
		f.eatPer.value=0.00;
	else
		f.eatPer.value=formatPer(eatPer);

	clothesPer=(clothes/totExp)*100;

	if(isNaN(clothesPer))
			f.clothesPer.value=0.00;
	else
		f.clothesPer.value=formatPer(clothesPer);

	sLoanPer=(sLoan/totExp)*100;

	if(isNaN(sLoanPer))
		f.sLoanPer.value=0.00;
	else
		f.sLoanPer.value=formatPer(sLoanPer);

	autoPer=(auto/totExp)*100;

	if(isNaN(autoPer))
			f.autoPer.value=0.00;
	else
		f.autoPer.value=formatPer(autoPer);

	pTransPer=(pTrans/totExp)*100;

	if(isNaN(pTransPer))
			f.pTransPer.value=0.00;
	else
		f.pTransPer.value=formatPer(pTransPer);

	hInsPer=(hIns/totExp)*100;

	if(isNaN(hInsPer))
			f.hInsPer.value=0.00;
	else
		f.hInsPer.value=formatPer(hInsPer);

	rInsPer=(rIns/totExp)*100;

	if(isNaN(rInsPer))
			f.rInsPer.value=0.00;
	else
		f.rInsPer.value=formatPer(rInsPer);

	storagePer=(storage/totExp)*100;

	if(isNaN(storagePer))
			f.storagePer.value=0.00;
	else
		f.storagePer.value=formatPer(storagePer);

	aInsPer=(aIns/totExp)*100;

	if(isNaN(aInsPer))
			f.aInsPer.value=0.00;
	else
		f.aInsPer.value=formatPer(aInsPer);

	dInsPer=(dIns/totExp)*100;

	if(isNaN(dInsPer))
			f.dInsPer.value=0.00;
	else
		f.dInsPer.value=formatPer(dInsPer);

	lInsPer=(lIns/totExp)*100;

	if(isNaN(lInsPer))
			f.lInsPer.value=0.00;
	else

	f.lInsPer.value=formatPer(lInsPer);

	homeExPer=(homeEx/totExp)*100;

	if(isNaN(homeExPer))
			f.homeExPer.value=0.00;
	else
		f.homeExPer.value=formatPer(homeExPer);

	laundryPer=(laundry/totExp)*100;

	if(isNaN(laundryPer))
			f.laundryPer.value=0.00;
	else
		f.laundryPer.value=formatPer(laundryPer);

	medicalPer=(medical/totExp)*100;

	if(isNaN(medicalPer))
			f.medicalPer.value=0.00;
	else
		f.medicalPer.value=formatPer(medicalPer);

	bankPer=(bank/totExp)*100;

	if(isNaN(bankPer))
			f.bankPer.value=0.00;
	else
		f.bankPer.value=formatPer(bankPer);

	ccPer=(cc/totExp)*100;

	if(isNaN(ccPer))
			f.ccPer.value=0.00;
	else
		f.ccPer.value=formatPer(ccPer);

	hobbiesPer=(hobbies/totExp)*100;

	if(isNaN(hobbiesPer))
			f.hobbiesPer.value=0.00;
	else

	f.hobbiesPer.value=formatPer(hobbiesPer);

	nightPer=(night/totExp)*100;

	if(isNaN(nightPer))
		f.nightPer.value=0.00;
	else
		f.nightPer.value=formatPer(nightPer);

	moviesPer=(movies/totExp)*100;

	if(isNaN(moviesPer))
			f.moviesPer.value=0.00;
	else
		f.moviesPer.value=formatPer(moviesPer);

	internetPer=(internet/totExp)*100;

	if(isNaN(internetPer))
			f.internetPer.value=0.00;
	else
		f.internetPer.value=formatPer(internetPer);

	computerPer=(computer/totExp)*100;

	if(isNaN(computerPer))
			f.computerPer.value=0.00;
	else
		f.computerPer.value=formatPer(computerPer);

	giftsPer=(gifts/totExp)*100;

	if(isNaN(giftsPer))
			f.giftsPer.value=0.00;
	else
		f.giftsPer.value=formatPer(giftsPer);

	vacationPer=(vacation/totExp)*100;

	if(isNaN(vacationPer))
			f.vacationPer.value=0.00;
	else
		f.vacationPer.value=formatPer(vacationPer);

	magazinesPer=(magazines/totExp)*100;

	if(isNaN(magazinesPer))
		f.magazinesPer.value=0.00;
	else
		f.magazinesPer.value=formatPer(magazinesPer);

	personalCPer=(personalC/totExp)*100;

	if(isNaN(personalCPer))
		f.personalCPer.value=0.00;
	else
		f.personalCPer.value=formatPer(personalCPer);

	healthClPer=(healthCl/totExp)*100;

	if(isNaN(healthClPer))
		f.healthClPer.value=0.00;
	else
		f.healthClPer.value=formatPer(healthClPer);

	membershipsPer=(memberships/totExp)*100;

	if(isNaN(membershipsPer))
		f.membershipsPer.value=0.00;
	else
		f.membershipsPer.value=formatPer(membershipsPer);

	petsPer=(pets/totExp)*100;

	if(isNaN(petsPer))
		f.petsPer.value=0.00;
	else
		f.petsPer.value=formatPer(petsPer);

	miscPer=(misc/totExp)*100;

	if(isNaN(miscPer))
		f.miscPer.value=0.00;
	else
		f.miscPer.value=formatPer(miscPer);

	//now total the income 	
	var totIncome=0.00;
	totIncome=sals_bonus + investInc;

	//calculate income tax
	var taxableIncome=0.00;
	var incomeTax=0.00;


	if(status=="single"){
		taxableIncome=totIncome - (9350/12);
		if (taxableIncome<=(8350/12)){
			incomeTax=taxableIncome*.10;
			}
		if (taxableIncome>(8350/12) && taxableIncome<=(33950/12)){
			incomeTax=(835/12) + (taxableIncome*.15);
			}
		if (taxableIncome>(33950/12) && taxableIncome<=(82250/12)){
			incomeTax=(4675/12) + (taxableIncome*.25);
			}
		if (taxableIncome>(82250/12) && taxableIncome<=(171550/12)){
			incomeTax=(16750/12) + (taxableIncome*.28);
			}
		if (taxableIncome>(171550/12) && taxableIncome<=(372950/12)){
			incomeTax=(41754/12) + (taxableIncome*.33);
			}
		if (taxableIncome>=(372950/12)){
			incomeTax=(108216/12) + (taxableIncome*.35);
			}
		}

	if(status=="married"){
		taxableIncome=totIncome - (18700/12);
		if (taxableIncome<=(16700/12)){
			incomeTax=taxableIncome*.10;
			}
		if (taxableIncome>(16700/12) && taxableIncome<=(67900/12)){
			incomeTax=(1670/12) + (taxableIncome*.15);
			}
		if (taxableIncome>(67900/12) && taxableIncome<=(137050/12)){
			incomeTax=(9350/12) + (taxableIncome*.25);
			}
		if (taxableIncome>(137050/12) && taxableIncome<=(208850/12)){
			incomeTax=(26637.50/12) + (taxableIncome*.28);
			}
		if (taxableIncome>(208850/12) && taxableIncome<=(372950/12)){
			incomeTax=(46741.50/12) + (taxableIncome*.33);
			}
		if (taxableIncome>=(372950/12)){
			incomeTax=(100894.50/12) + (taxableIncome*.35);
			}
		}
		
	//calculate payroll tax
	var payrollTax=0.00;
	if (totIncome<=(76200/12)){
		payrollTax=totIncome*.0765;
		}
	if (totIncome>(76200/12)){
		payrollTax=(totIncome*.0145)+((76200/12)*.062);
		}
		
	//calculate net income
	var netIncome=0.00;
	netIncome=totIncome-payrollTax-incomeTax;

	if(netIncome==0)
		f.netIncome.value=0.00;

	if(isNaN(netIncome))
		f.netIncome.value="";
	else
		f.netIncome.value=formatDollar(netIncome);

	var monthlyCash=0.00
	monthlyCash=netIncome-totExp;

	if(monthlyCash==0)
		f.monthlyCash.value=0.00;

	if(isNaN(totExp))
		f.monthlyCash.value="";
	else
		f.monthlyCash.value=formatDollar(monthlyCash);

		
	//now get assets
	home=parseFloat(stripBag(f.home.value));
	furniture=parseFloat(stripBag(f.furniture.value));
	car= parseFloat(stripBag(f.car.value));
	savings= parseFloat(stripBag(f.savings.value));
	retirement= parseFloat(stripBag(f.retirement.value));
	otherA=parseFloat(stripBag(f.otherA.value));

	if(isNaN(home)){
		alert("Please enter a value for Home");
		home=0.00;
		}

	if(isNaN(furniture)){
		alert("Please enter a value for Furniture");
		furniture=0.00;
		}

	if(isNaN(car)){
		alert("Please enter a value for Car");
			car=0.00;
		}

	if(isNaN(retirement)){
		alert("Please enter a value for Retirement Accounts");
			retirement=0.00;
		}

	if(isNaN(savings)){
		alert("Please enter a value for Savings");
			savings=0.00;
		}

	if(isNaN(otherA)){
			alert("Please enter a value for Other Assets");
				otherA=0.00;
		}

	assets=home + furniture + car + savings + retirement + otherA;

	//now get liabilities
	mortgage= parseFloat(stripBag(f.mortgage.value));
	creditC= parseFloat(stripBag(f.creditC.value));
	studentL= parseFloat(stripBag(f.studentL.value));
	oLoans= parseFloat(stripBag(f.oLoans.value));
	otherL=parseFloat(stripBag(f.otherL.value));

	if(isNaN(mortgage)){
		alert("Please enter a value for Mortgage")
		mortgage=0.00;
			}

	if(isNaN(creditC)){
		alert("Please enter a value for Credit Card")
		creditC=0.00;
			}

	if(isNaN(studentL)){
		alert("Please enter a value for Student Loans")
		studentL=0.00;
			}

	if(isNaN(oLoans)){
		alert("Please enter a value for Other Loans")
		oLoans=0.00;
		}

	if(isNaN(otherL)){
			alert("Please enter a value for Other Liabilities")
			otherL=0.00;
		}

	liabilities=mortgage + creditC + studentL + oLoans + otherL;


	//now get networth
	var netWorth;
	netWorth=assets - liabilities;

	if (isNaN(netWorth))
		f.netWorth.value="";
	else
		f.netWorth.value = formatDollar(netWorth);

	//f.totIncome.value=formatDollar(totIncome);
	f.netIncome.value=formatDollar(netIncome);
	f.assets.value = formatDollar(assets);
	f.liabilities.value = formatDollar(liabilities);

}//closes getTotal

//function for percentages
function formatPer(cost){
	cost *= 100;
	cost = Math.round(cost);
	var dollars = Math.round(cost / 100);
	var cents = cost % 100;
	var result = dollars + ".";
	if (cents < 10)
	{
		result += "0" + cents;
	}
	else
	{
		result += cents;
	}
	return result;
}

function formatDollar(cost){
	cost *= 100;
	cost = Math.round(cost);
	var dollars = Math.floor(cost / 100);
	var cents = cost % 100;
	var result = "$" + dollars + ".";
	//cents=stripMinus(cents);
	if(cents<0){
		cents=cents*-1;
		}
	if (cents < 10)
	{
		result += "0" + cents;
	}
	else
	{
		result += cents;
	}
	return result;
}