//How much can I borrow?


function CalculateBorrowing(){
	
//declare income variables
	var	App1Income		=	document.getElementById("Income_app1").value;
	var	App2Income		=	document.getElementById("BorrowingCalc").Income_app2.value;
	var	App1Bonus		=	document.getElementById("BorrowingCalc").Bonus_app1.value;
	var	App2Bonus		=	document.getElementById("BorrowingCalc").Bonus_app2.value;
	App1Income			=	parseFloat(App1Income.replace(/[^0-9.]/g, ''));
	App2Income			=	parseFloat(App2Income.replace(/[^0-9.]/g, ''));
	App1Bonus			=	parseFloat(App1Bonus.replace(/[^0-9.]/g, ''));
	App2Bonus			=	parseFloat(App2Bonus.replace(/[^0-9.]/g, ''));
	
	if (isNaN(App1Income)){		App1Income = 0	}	
	if (isNaN(App2Income)){		App2Income = 0	}	
	if (isNaN(App1Bonus)){		App1Bonus = 0	}	
	if (isNaN(App2Bonus)){		App2Bonus = 0	}
		
//earnings are all of basic and half bonuses
	var	App1Earnings		=	0.5 * App1Bonus + App1Income
	var	App2Earnings		=	0.5 * App2Bonus + App2Income
	
// single or joint application 
	var joint = false
	if (App2Earnings > 1) {
		joint = true
	}
	else {
		joint = false
	}
	
// decide on main income
	var MainIncome
	var SecondIncome
	if (App1Earnings > App2Earnings){ 
	MainIncome = App1Earnings
	SecondIncome = App2Earnings
	} 
	else {
	MainIncome = App2Earnings
	SecondIncome = App1Earnings
	}
	
//declare higher and lower amounts
	var HigherAmount
	var LowerAmount

//Lower Amount
	if (joint == false) {
	LowerAmount = MainIncome * 3.25
	}
	else {
	LowerAmount = (MainIncome + SecondIncome) * 2.5
	}

// Higher Amount
	if (joint == true){
	var JointJoint = (MainIncome + SecondIncome) * 2.8
	var JointSingle = (MainIncome * 4) + SecondIncome
	if (JointJoint > JointSingle) {
	var JointIncome = JointJoint
	}
	else {
	var JointIncome = JointSingle
	}
	}
	if (joint == false) {
	HigherAmount = MainIncome * 4
	}
	else {
	HigherAmount = JointIncome
	}
	
// show results	
	var BorrowingAmount = "\u00A3" + LowerAmount + " and \u00A3" + HigherAmount;

	document.getElementById('results').innerHTML = "Based on the basic information you have provided, an indication of what you can borrow is between: " + BorrowingAmount +"<br><br>"
}
