
var v_MonthlyAffordHold = ''; // hold value for onchange event
	
	function calcMonthlyAfford() {
			var v_Income,
					v_OutstandingDebt,
					v_RecommendMonthly,
					v_formName = document.calc;

			if ( confirmAffordValues() ) {
			v_Income = roundFloat(makeNumValid(v_formName.Income.value));
			v_OutstandingDebt = roundFloat(makeNumValid(v_formName.OutstandingDebt.value)); 
			v_RecommendMonthly = Math.floor(((((v_Income/12)-v_OutstandingDebt)*0.28))*100)/100; 

			// if recommended monthly payment is negative, set to 0
			if ( v_RecommendMonthly <0 ) {
				v_RecommendMonthly = 0;
			}
			v_formName.RecommendMonthly.value = addCommas(roundFloat(v_RecommendMonthly));
			v_MonthlyAffordHold = v_formName.RecommendMonthly.value;
			}
	}

	function confirmAffordValues () {
			var v_form = document.calc,
					v_Income = v_form.Income.value,
					v_OutstandingDebt = v_form.OutstandingDebt.value,
					v_tIncome,
					v_tOutstandingDebt,
					v_errorflag = 0,
					v_errorstr,
					v_returnval;
	
			// get values from form
			v_tIncome = parseFloat(makeNumValid(v_Income));
			v_tOutstandingDebt = parseFloat(makeNumValid(v_OutstandingDebt));
	
			if ( v_tOutstandingDebt <0 ) { // N3.x bug; returns -1 when set 0
				v_tOutstandingDebt = 0;
			}
			if ( v_tIncome == '' || isNaN(v_tIncome) ) {
				v_form.Income.value = 0;
				v_tIncome = 0;
			}
			// income > 0 or <100,000,000
			if ( v_tIncome <0 || v_tIncome > 100000000 ) {
					v_errorstr = "Sorry.	$" + v_Income + " is an invalid income.\nPlease enter an income between $0.00 and $100,000,000.00";
		v_form.Income.value = '';
		v_errorflag = 1;
			// outstanding debt <0 or > balance	
			} else if ( v_tOutstandingDebt <0 || v_tOutstandingDebt > v_tIncome ){
					v_errorstr = "Sorry.	Your outstanding debt of $" + v_OutstandingDebt + " must be \nless than your income of $" + v_Income;
		v_form.OutstandingDebt.value = '';
		v_errorflag = 1;
			}

			// display error and clear result
			if ( v_errorflag ) {
				alert(v_errorstr);
	clearRecommendMonthly();
	
	v_returnval = 0;
			} else {
				v_returnval = 1;
			}
			return ( v_returnval );
	}

	function clearRecommendMonthly () {
		var v_form = document.calc;

		v_form.RecommendMonthly.value = '';
	}

