	$(document).ready(function() {
		// Adding the euro symbols in front of all input fields exept 'shortfallyears' 
		// and the submit button
		$("form#lifepensioncalc input[id!='shortfallyears'][id!='lifepensioncalc_submit']")
			.before('<font size="2">&euro;&nbsp;</font>');

		// The previous figures in input fields are selected on 'click' event exept the submit button
		$("form#lifepensioncalc input[id!='lifepensioncalc_submit']")
			.click(function(e){$(e.target).select();});

		// Making all input fields part of the class 'smallText'			
		$("form#lifepensioncalc input[id!=lifepensioncalc_submit]")
			.addClass('smallInput');

		// Adding the string 'years' after the 'shortfallyears' input field			
		$("form#lifepensioncalc input[id='shortfallyears']")
			.after('<span style="font-size:0.8em">&nbsp;years</span>');
							
		// Correcting the auto-format: with the width unset, it distributes the fields properly
		$("td[width='40%']").removeAttr('width');

		//	Updates the 'residual income' result field
		//		, which is defined by a SPAN with the ID='residualincome' (see docs.jquery.com), 
		//	with the sum of the according input fields
		updateResidualIncome = function(){
			var myNumber = new NumberObj(); // using numberObj.js

			// Select several input fields and add each up
			$("input#spousesalary,input#spouseservicepension,input#socialwelfarepay,input#otherincome")
				.each(function(){
					myNumber.addPos($(this).val());
				});			
			
			// Output
			$("span#residualincome").text(myNumber.getWithComma());
		}

		// Updates the 'monthly short fall' result field 
		// with the difference of 'cost_of_living' minus 'residual_income' 
		// (similar to 'updateResidualIncome') 
		updateMonthlyshortfall = function(){
			var myNumber = new NumberObj(); // using numberObj.js
			
			myNumber.addPos ($("input#costofliving").val());
			myNumber.substPos ($("span#residualincome").text().replace(/,/g, "")); // removing the comma's from 'residualincome' only for calculation
			myNumber.makePos();	// Math.max(value,0);
			
			// Output
			$("span#monthlyshortfall").text(myNumber.getWithComma());
		}

		// Attaches the jQuery event 'change' to the according input fields
		$("input#spousesalary,input#spouseservicepension,input#socialwelfarepay,input#otherincome,input#costofliving")
			.change(function(){
				updateResidualIncome();
				updateMonthlyshortfall();
			});
	});

