
// Needs Functions ------------------------------------------------------------
function add_needs() {
		var form = document.needs_calc;
		
		with (form) {
			var y1=i_1_y.value.replace(/,/g,'')-0;
			var s1=i_1_s.value.replace(/,/g,'')-0;
			var y2=i_2_y.value.replace(/,/g,'')-0;
			var s2=i_2_s.value.replace(/,/g,'')-0;
			var y3=i_3_y.value.replace(/,/g,'')-0;
			var s3=i_3_s.value.replace(/,/g,'')-0;
			var y4=t_1_y.value.replace(/,/g,'')-0;
			var s4=t_1_s.value.replace(/,/g,'')-0;
			var y5=t_2_y.value.replace(/,/g,'')-0;
			var s5=t_2_s.value.replace(/,/g,'')-0;
			var y6=t_3_y.value.replace(/,/g,'')-0;
			var s6=t_3_s.value.replace(/,/g,'')-0;
			var y7=l_1_y.value.replace(/,/g,'')-0;
			var s7=l_1_s.value.replace(/,/g,'')-0;
			var y8=l_2_y.value.replace(/,/g,'')-0;
			var s8=l_2_s.value.replace(/,/g,'')-0;
			var y9=l_3_y.value.replace(/,/g,'')-0;
			var s9=l_3_s.value.replace(/,/g,'')-0;
			var y10=l_4_y.value.replace(/,/g,'')-0;
			var s10=l_4_s.value.replace(/,/g,'')-0;
			var y11=l_5_y.value.replace(/,/g,'')-0;
			var s11=l_5_s.value.replace(/,/g,'')-0;
			var y12=r_1_y.value.replace(/,/g,'')-0;
			var s12=r_1_s.value.replace(/,/g,'')-0;
			
			youTotal = y1+y2+y3+y4+y5+y6+y7+y8+y9+y10+y11+y12;
			spouseTotal = s1+s2+s3+s4+s5+s6+s7+s8+s9+s10+s11+s12;
			
			if(isNaN(youTotal)) {
				//error("You");
				// do nothing
			}else {
				total_y.value = formatAsCurrency(youTotal);
			}
			if(isNaN(spouseTotal)) {
				//error("Spouse");
				// do nothing
			}else {
				total_s.value = formatAsCurrency(spouseTotal);
			}
			
		}
}


function add_resources() {
	var form = document.needs_calc;
	
	with (form) {
		var x1=a_1_y.value.replace(/,/g,'')-0;
		var z1=a_1_s.value.replace(/,/g,'')-0;
		var x2=a_2_y.value.replace(/,/g,'')-0;
		var z2=a_2_s.value.replace(/,/g,'')-0;
		
		yTotal = x1+x2;
		sTotal = z1+z2;
		
		if(isNaN(yTotal)) {
			// do nothing
		}else {
			tra_y.value = formatAsCurrency(yTotal);
		}
		if(isNaN(sTotal)) {
			// do nothing
		}else {
			tra_s.value = formatAsCurrency(sTotal);
		}
	}
}


function find_dif() {
	var form = document.needs_calc;
	add_needs();
	add_resources();
	with (form) {	// error handling moved here
		if(isNaN(youTotal-yTotal)) {
			total_y.value = "";
			tra_y.value = "";
			total_vol_y.value = "";
			error("You");
		}else {
			if(youTotal-yTotal <= 0) {
				total_vol_y.value=0;
			}else {
				total_vol_y.value=formatAsCurrency(youTotal-yTotal);
			}
		}
		if(isNaN(spouseTotal-sTotal)) {
			total_s.value = "";
			tra_s.value = "";
			total_vol_s.value = "";
			error("Spouse");
		}else {
			if(spouseTotal-sTotal <= 0) {
				total_vol_s.value=0;
			}else {
				total_vol_s.value=formatAsCurrency(spouseTotal-sTotal);
			}
		}
	}
	
}


function error(column) {	//pass the name of column, "you" or "spouse"
	alert("The calculator has encountered a non-numerical value\nin the "+column+" column.\n\nPlease verify that all fields contain only numerical values.\n\nThank you.");
}


