	function up(amount) {	
		amount = 10*(Math.ceil(amount/10));
		document.calc.donation.value = amount;
		return amount;
	}
	
	function loanamounts(amount) {
		var dollarsperyear = "$" + amount*3;
		document.calc.loans1.value = dollarsperyear;
		document.calc.loans3.value = dollarsperyear;
		document.calc.loans5.value = dollarsperyear;
		document.calc.cum1.value = dollarsperyear;
	}
	
	function cumloans(amount) {
		document.calc.cum3.value = "$" + 3*(amount*3);
		document.calc.cum5.value = "$" + 5*(amount*3);
	}

	function aspercentwithpeople(amount) {
		amount = 3*(amount/50);
		var ppl = 5;
		aspercent1 = amount;
		document.calc.people1.value = Math.round(aspercent1*ppl);
		document.calc.aspercent1.value = aspercent1.toFixed(1);
		aspercent3 = 3*amount;
		document.calc.people3.value = Math.round(aspercent3*ppl);
		document.calc.aspercent3.value = aspercent3.toFixed(1);		
		aspercent5 = 5*amount;
		document.calc.people5.value = Math.round(aspercent5*ppl);
		document.calc.aspercent5.value = aspercent5.toFixed(1);
		
		//do people box
		upwithpeople(Math.floor(aspercent5));
	}
	
	function upwithpeople(amount) {
		document.calc.numberofpeople.value = amount + " clients";
		var rows;
		var widthofperson = 10;
		var widthofrow = 500;
		var pplperrow = widthofrow/widthofperson;
		var rowheight=22;
		if (amount >= pplperrow) {
			rows = Math.floor(amount/pplperrow);  //one person per 10 pixels, 500 pixels wide
			var upwithppl = document.getElementById("upwithpeople");
			upwithppl.style.width = widthofrow + "px";
			upwithppl.style.height = rows*rowheight + "px";
		} else {
			rows = 0;
		}
		var remainder = amount - (rows*pplperrow);
		if (remainder > 0) {
			var lastrowofppl = document.getElementById("lastrow");
			lastrowofppl.style.width = (remainder*10) + "px";
			lastrowofppl.style.height = rowheight + "px";
		} 
	}
			
	function calculate(amount) {
		if (amount > 5000) {
			alert('We welcome your most generous gifts but, for this calculation, \nthe amount entered must be $5,000 or less. \nPlease try again.');
			document.calc.donation.value = '';
		} else {
			amount = up(amount);
			loanamounts(amount);
			cumloans(amount);
			aspercentwithpeople(amount);
		}
	}
	
	function cleareverything() {
		document.calc.donation.value = '';
		var lastrowofppl = document.getElementById("lastrow");
		lastrowofppl.style.width = "0px";
		lastrowofppl.style.height = "0px";
		var upwithppl = document.getElementById("upwithpeople");
		upwithppl.style.width = "0px";
		upwithppl.style.height = "0px";
		document.calc.aspercent1.value = '';
		document.calc.aspercent3.value = '';
		document.calc.aspercent5.value = '';
		document.calc.loans1.value = '';
		document.calc.loans3.value = '';
		document.calc.loans5.value = '';
		document.calc.people1.value = '';
		document.calc.people3.value = '';
		document.calc.people5.value = '';
		document.calc.numberofpeople.value = '';
		document.calc.cum1.value = '';
		document.calc.cum3.value = '';
		document.calc.cum5.value = '';
	}
