function calc_budget() {
	$$('form#budget_calculator input').invoke('observe', 'blur', function(event) { 
		event.stop();
		var values = $$('form#budget_calculator input');
		for(var i = 0; i < values.length; i++){
				if(values[i].present()) {}
				else {
					values[i].setValue('0');
				}
				if(values[i].getValue() >= 0 || values[i].getValue() < 0) {}
				else {
					values[i].setValue('0');
				} 
		}
		var total = parseInt(values[0].getValue()) + parseInt(values[1].getValue()) + parseInt(values[2].getValue());
		total = total - parseInt(values[3].getValue()) - parseInt(values[4].getValue());
		update_total(total);
		// console.log(Event.element(event).getValue());
	});
}

function update_total(total) {
	if(total >= 0 || total < 0) {
		$('total').update(total); 
		$('payment').setAttribute('href', '../calc/index.php?amt=' + total);
		//$('payment').observe('click', function() {
		//	event.stop();
		//	window.location('../calc/index.php?amt=' + total);
		//});
		console.log('../calc/index.php?amt=' + total);
	}
}

calc_budget();