
if (Calculators == undefined) {
    var Calculators = {};
}
if (Calculators.planning == undefined) {
    Calculators.planning = {};
}

Calculators.planning.CollegeExpense = function CollegeExpense(currentAge, collegeAge, tuition, board) {
	this.currentAge = new Number(currentAge);
	this.collegeAge = new Number(collegeAge);
	this.tuition = new Calculators.type.Money(tuition);
	this.board = new Calculators.type.Money(board);

	this.getCurrentAge = function() {
		return this.currentAge;
	}
		
	this.getCollegeAge = function() {
		return this.collegeAge;
	}
	
	this.getTuition = function(){
		return this.tuition;
	}
	
	this.getBoard = function(){
		return this.board;
	}
	
	this.calculateCosts = function(inflation) {
		// Get the future value for the 4 years of college starting after collegeAge - currentAge years have passed
		var startYear = this.collegeAge - this.currentAge;
		var runningCosts = this.tuition.getAmount() + this.board.getAmount();
		for (var i=0; i<startYear; i++) {
			var increase = (runningCosts * inflation.getAmount());
			runningCosts = runningCosts + increase;
		}
		var year1Costs = runningCosts;
		var year2Costs = year1Costs * (1 + inflation.getAmount());
		var year3Costs = year2Costs * (1 + inflation.getAmount());
		var year4Costs = year3Costs * (1 + inflation.getAmount());
		
		return new Calculators.type.Money(year1Costs + year2Costs + year3Costs + year4Costs);
	}
	
	this.getExpenseAmount = function(inflation, year) {
		var startYear = this.collegeAge - this.currentAge;
		var yearOutOfCollege = (startYear + 4);
		if (this.isPreCollege(year) || this.isPostCollege(year)) {
			return new Calculators.type.Money(0.00);
		}
		
		var runningCosts = this.tuition.getAmount() + this.board.getAmount();
		for (var i=0; i<year-1; i++) {
			var increase = (runningCosts * inflation.getAmount());
			runningCosts = runningCosts + increase;
		}
		return new Calculators.type.Money(runningCosts);
	}
	
	this.calculateFreshmenYearCost = function(inflation) {
		// Get the future value for the 4 years of college starting after collegeAge - currentAge years have passed
		var startYear = this.collegeAge - this.currentAge;
		var runningCosts = this.tuition.getAmount() + this.board.getAmount();
		for (var i=0; i<startYear; i++) {
			var increase = (runningCosts * inflation.getAmount());
			runningCosts = runningCosts + increase;
		}
		var year1Costs = runningCosts;
		
		return new Calculators.type.Money(year1Costs);
	}
	
	this.calculateSeniorYearCost = function(inflation) {
		// Get the future value for the 4 years of college starting after collegeAge - currentAge years have passed
		var startYear = this.collegeAge - this.currentAge;
		var runningCosts = this.tuition.getAmount() + this.board.getAmount();
		for (var i=0; i<startYear; i++) {
			var increase = (runningCosts * inflation.getAmount());
			runningCosts = runningCosts + increase;
		}
		var year1Costs = runningCosts;
		var year2Costs = year1Costs * (1 + inflation.getAmount());
		var year3Costs = year2Costs * (1 + inflation.getAmount());
		var year4Costs = year3Costs * (1 + inflation.getAmount());
		
		return new Calculators.type.Money(year4Costs);
	}
	
	this.getYearsUntilCollege = function() {
		return (this.collegeAge - this.currentAge);
	}
	
	this.isPreCollege = function(year) {
		var startYear = this.getYearsUntilCollege();
		return (year-1 < startYear);
	}
	
	this.isPostCollege = function(year) {
		var startYear = this.getYearsUntilCollege();
		var yearOutOfCollege = (startYear + 4);
		return (year > yearOutOfCollege);
	}
}
