// Fields stored in the database
//
// LoanName				Description to be shown in the drop down list 
// LoanType				Acceptable Values: ALLsaver, Fixed, SelfHelp10, SelfHelp25
// APR_Federal			The Federal Rate, e.g. 3.42
// APR_Fixed			Fix rate APR, e.g. 7.5
// RateDiscount			APR Discount to be applied to ALLsaver loan, e.g. 2.25
// SelfHelpDiscount1	Discount applied to the first 48 payments
// SelfHelpDiscount2	Discount applied to payments 49 - 120
// SelfHelpDiscount3	Discount applied after payment 120
// MinAmount			Minimum dollar amount for loan
// MaxAmount			Maximum dollar amount for loan - Set to 0 for no maximum
// CashBackRate			The percentage of the cash back
//

// Gloabl variables go up here outside the functions
var AmountBorrowed = 0;
var APR_Federal = 0;
var APR_Discounted = 0;
var APR_Fixed = 0;
var NumberOfPayments = 0;
var RateDiscount = 0;
var SelfHelpDiscount1 = 0;
var SelfHelpDiscount2 = 0;
var MinAmount = 0;
var MaxAmount = 0;
var LoanType = 'Regular';
var OK2Calculate;
var OriginationFeeRate = 0;
var OriginationFee = 0;
var PrincipleReduction = 0;
var CashBackRate = 0 ;

// These are global variables used to return 
// multiple values from the amortization function
var amRemainingBalance = 0;
var amInterestPaid = 0;
var amTotalPaid = 0;


// This function strips all characters that would make a string not a numeric value
// It's primary function is to strip chars from the Loam Amount field
// when the text box loses focus
function StripCurrencyChars(ThisString) {

	var vString = new String(ThisString.value);
	vString = vString.replace(/[^0123456789\.]/g, '');

	if (vString == '') {vString = '0';}

	ThisString.value = vString;
	//return vString;

}


// ------------------------------------------------------------------------------------------
// Returns the balance of a loan after a specified number of identical payments has been made
// ------------------------------------------------------------------------------------------
// vBorrowed: The initial principal amount of the loan
// vRate: The interest rate for the period of the payments - e.g. Monthly Rate = APR / 1200
// vNumberOfPayments: The number of identical payents that has been made
// vPaymentAmount: The amount of the identical payments made
function GetCurrentBalance(vBorrowed, vRate, vNumberOfPayments, vPaymentAmount) {

	var vBalance;

	if ((isNaN(vBorrowed)) || (isNaN(vRate)) || (isNaN(vNumberOfPayments)) || (isNaN(vPaymentAmount))) {
		vBalance = NaN;
	} else {
		vBalance = (vBorrowed * Math.pow(1 + vRate, vNumberOfPayments)) - ((vPaymentAmount / vRate) * (Math.pow(1 + vRate, vNumberOfPayments) - 1));
		vBalance = vBalance;
	}

	return vBalance;

}


// ------------------------------------------------------------------------------------------
// Returns the number of payments it will take to pay off a loan for a given monthly payment
// ------------------------------------------------------------------------------------------
// vBorrowed: The initial principal amount of the loan
// vRate: The interest rate for the period of the payments - e.g. Monthly Rate = APR / 1200
// vPaymentAmount: The amount of the identical payments made
function GetNumberOfPayments(vBorrowed, vRate, vPaymentAmount) {

	var vPayments;

	if ((isNaN(vBorrowed)) || (isNaN(vRate)) || (isNaN(vPaymentAmount))) {
		vPayments = NaN;
	} else {

		vPayments = -1 * Math.log(1 - vRate * vBorrowed / vPaymentAmount)/Math.log(1 + vRate);

//		vPayments = Math.round(vPayments * 10000) / 10000;
	}

		return vPayments;

}





// ------------------------------------------------------------------------------------------
// Returns the number of payments it will take to pay off a loan for a given monthly payment
// ------------------------------------------------------------------------------------------
// vBorrowed: The initial principal amount of the loan
// vRate: The interest rate for the period of the payments - e.g. Monthly Rate = APR / 1200
// vPaymentAmount: The amount of the identical payments made
function GetMonthlyPayment(vBorrowed, vRate, vNumberOfPayments) {

	var vMonthlyPayment;

	if ((isNaN(vBorrowed)) || (isNaN(vRate)) || (isNaN(vNumberOfPayments))) {
		vMonthlyPayment = NaN;
	} else {

		vMonthlyPayment = (vRate * vBorrowed) / (1 - Math.pow(1 + vRate,vNumberOfPayments * -1));
//		vMonthlyPayment = Math.round(vMonthlyPayment * 100) / 100;
	}


	if (vMonthlyPayment < 50) {
		vMonthlyPayment = 50;
	}

	return vMonthlyPayment;



}


//function AmortizeLoan(double data[][])
function AmortizeLoan(vAmountBorrowed, vRate, vNumberOfPayments, vMonthlyPayment) {

		var start_balance = 0;//Beginning Balance of loan
		var PrincRepay = 0;   //Brings all the values to zero for a fresh calculation
		var IntRepay = 0;
		var AM_PRINC_REPAY = 0;     //aggregate variables that maintain the totals for the applet
		var AM_TOTAL_INTEREST = 0;  //screen itself.
		var EndBalance = 0;
		var IntRate = 0;
		var PrincAmt = 0;
		
		//CashBackRate = 3;
	
		var CashBackMax = vAmountBorrowed * CashBackRate / 100 ; // get the value of the cash back 
		var SumOfCashBack = 0 ; 
		var CashBackFlag = true ; 
		var CashBackStartbalance = vAmountBorrowed;

		IntRate = vRate;
		MonthlyAmt = vMonthlyPayment;
		NumPay = vNumberOfPayments;
		PrincAmt = vAmountBorrowed;

		if(PrincAmt > 0) {
			start_balance = PrincAmt;
			SelfHelpSecondPayAmt = 0;
		}


		 //This for loop calculates each period interest payment, monthly amt, and principal balance payment
		 //The data is inserted into a multi-dimensional array, which is imported into the canvas and
		 //repainted.

		for(i = 0; i < NumPay; i++) {
			/*Calculates the Interest to be repaid within pay period i */
			IntRepay = (IntRate) * start_balance ;

			/*Check to see if the payment is greater than needs to be paid, but
			**not yet zero, then we need to calculate the actual payment.
			**This will happen only once, in the last active payment period's month */

			if(((start_balance + IntRepay) <= MonthlyAmt) && (start_balance != 0)) {
				EndBalance = start_balance + IntRepay;
				AM_TOTAL_INTEREST = AM_TOTAL_INTEREST + IntRepay;  //keeps track of the overall interest paid
				start_balance = 0;
			}

			/* If the start_balance has gone to 0, then simply assign all
			** index values to 0. If a loan is paid earlier than planned, then
			** there will be multiple spaces left as zeros. This is needed to
			** Calculate the actual Payment Periods variable*/

			else if(start_balance == 0) {

			}

			/*This is the normal calculation used for all monthes except the
			**last pay period and those after all balances are paid. */

			else
			{
				//Hani this is to handle the cash back for the grad plus 
				if (( CashBackRate > 0 ) && (CashBackFlag == true))
				{
					IntRepay = (IntRate) * CashBackStartbalance ;
					
					var OldIntRepay = IntRepay ;
					SumOfCashBack = SumOfCashBack +IntRepay ;
					if ( CashBackMax  <= SumOfCashBack) 
					{
						OldIntRepay = SumOfCashBack -CashBackMax  ;
						CashBackFlag = false;
						
						IntRepay = 0
						PrincRepay = MonthlyAmt - IntRepay;
						AM_TOTAL_INTEREST = AM_TOTAL_INTEREST + OldIntRepay;  //keeps track of the overall interest paid
						start_balance = start_balance - PrincRepay + OldIntRepay ;  //reduces the Balance by that month's payment
						CashBackStartbalance = CashBackStartbalance - (MonthlyAmt  - OldIntRepay );
					
					}
					else
					{
						IntRepay = 0
						PrincRepay = MonthlyAmt - IntRepay;
						AM_TOTAL_INTEREST = AM_TOTAL_INTEREST + IntRepay;  //keeps track of the overall interest paid
						start_balance = start_balance - PrincRepay ;  //reduces the Balance by that month's payment
						CashBackStartbalance = CashBackStartbalance - (MonthlyAmt  - OldIntRepay );
					}
					
					
				}
				else
				{
					PrincRepay = MonthlyAmt - IntRepay;
					AM_TOTAL_INTEREST = AM_TOTAL_INTEREST + IntRepay;  //keeps track of the overall interest paid
					start_balance = start_balance - PrincRepay;  //reduces the Balance by that month's payment
				}
			}
		}

			AM_PRINC_REPAY = FormatCurrency(PrincAmt) + FormatCurrency(AM_TOTAL_INTEREST);  //Total amount repaid is calculated

			amRemainingBalance = start_balance;
			amInterestPaid = AM_TOTAL_INTEREST;

			return AM_TOTAL_INTEREST;
}

//Hani 




function FormatCurrency(vNumber) {

	var vDollarPart;
	var vCentPart;

	vNumber = (Math.round((vNumber * 100)) + .01) / 100;

	return vNumber;

//	vDollarPart = Math.floor(vNumber);
//	vCentPart = vNumber - vDollarPart;
//	vCentPart = vCentPart * 100;
//	vCentPart = Math.round(vCentPart);
//	vCentPart = vCentPart / 100;

//	return vDollarPart + vCentPart;
}

function ChooseLoan(OptionNumber, ThisForm) {

//alert (OptionNumber);
	switch (OptionNumber) {

				// ALLsaver Stafford Loan - 10 Years - Auto Debit
				case '1':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					APR_Federal = 3.37;
					APR_Fixed = 0;
					RateDiscount = 2.25;
//					RateDiscount = 0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 7500;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $7,500.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;


					switch (LoanType) {
						case 'ALLSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;
							break;
						case 'SELFHELP10':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'SELFHELP25':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'FIXED':
							ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;
							break;
					}

					break;



				
				// ALLsaver Stafford Loan - 25 Years - Auto Debit
				case '2':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 300;
					APR_Federal = 3.37;
					APR_Fixed = 0;
					RateDiscount = 2.25;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 30000;
					MaxAmount = 0;
					MinError = 'The minumum amount for a 25-year repayment is $30,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;


					switch (LoanType) {
						case 'ALLSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;
							break;
						case 'SELFHELP10':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'SELFHELP25':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'FIXED':
							ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;
							break;
					}

					break;


				
				// ALLsaver Stafford Loan - 10 Years
				case '3':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					APR_Federal = 3.37;
					APR_Fixed = 0;
					RateDiscount = 2.0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 7500;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $7,500.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;


					switch (LoanType) {
						case 'ALLSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;
							break;
						case 'SELFHELP10':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'SELFHELP25':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'FIXED':
							ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;
							break;
					}

					break;

				//ALLsaver Stafford Loan - 25 Years
				case '4':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 300;
					APR_Federal = 3.37;
					APR_Fixed = 0;
					RateDiscount = 1.25;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 30000;
					MaxAmount = 0;
					MinError = 'The minumum amount for a 25-year repayment is $30,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;


					switch (LoanType) {
						case 'ALLSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;
							break;
						case 'SELFHELP10':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'SELFHELP25':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'FIXED':
							ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;
							break;
					}

					break;

				// SelfHelp Stafford Loan - 10 Years - Auto Debit
				case '5':
					LoanType = 'SELFHELP10';
					NumberOfPayments = 120;
					APR_Federal = 3.37;
					APR_Fixed = 0;
					RateDiscount = 0;
					SelfHelpDiscount1 = 0.25;
					SelfHelpDiscount2 = 2.25;
					SelfHelpDiscount3 = 0;
					MinAmount = 1000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $1,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;


					switch (LoanType) {
						case 'ALLSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;
							break;
						case 'SELFHELP10':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'SELFHELP25':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'FIXED':
							ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;
							break;
					}

					break;

				// SelfHelp Stafford Loan - 10 Years
				case '6':
					LoanType = 'SELFHELP10';
					NumberOfPayments = 120;
					APR_Federal = 3.37;
					APR_Fixed = 0;
					RateDiscount = 0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 2;
					SelfHelpDiscount3 = 0;
					MinAmount = 1000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $1,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;


					switch (LoanType) {
						case 'ALLSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;
							break;
						case 'SELFHELP10':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'SELFHELP25':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'FIXED':
							ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;
							break;
					}

					break;

				// Cal Loan
				case '7':
					LoanType = 'FIXED';
					NumberOfPayments = 120;
					APR_Federal = 0;
					APR_Fixed = 7.5;
					RateDiscount = 0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 1500;
					MaxAmount = 75000;
					MinError = 'The minimum amount for this loan is $1,500.';
					MaxError = 'The maximum amount of this loan is $75,000.';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					switch (LoanType) {
						case 'ALLSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;
							break;
						case 'SELFHELP10':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'SELFHELP25':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'FIXED':
							ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;
							break;
					}

					break;


				// ALLsaver PLUS Loan - 10 Years - Auto Debit
				case '8':
				
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					APR_Federal = 8.5;//4.17;

					APR_Fixed = 0;
					RateDiscount = 1.5;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 5000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $5,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;


					switch (LoanType) {
						case 'ALLSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;
							break;
						case 'SELFHELP10':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'SELFHELP25':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'FIXED':
							ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;
							break;
					}

					break;



				

				// ALLsaver PLUS Loan - 25 Years - Auto Debit
				case '9':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 300;
					APR_Federal = 8.5;//4.17;
					APR_Fixed = 0;
					RateDiscount = 1.5;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 30000;
					MaxAmount = 0;
					MinError = 'The minumum amount for a 25-year repayment is $30,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;


					switch (LoanType) {
						case 'ALLSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;
							break;
						case 'SELFHELP10':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'SELFHELP25':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'FIXED':
							ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;
							break;
					}

					break;



				

				// ALLsaver PLUS Loan - 10 Years
				case '10':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					APR_Federal = 8.5;//4.17;
					APR_Fixed = 0;
					RateDiscount = 0.5;//1.0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 5000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $5,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;


					switch (LoanType) {
						case 'ALLSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;
							break;
						case 'SELFHELP10':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'SELFHELP25':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'FIXED':
							ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;
							break;
					}

					break;



				

				// ALLsaver PLUS Loan - 25 Years
				case '11':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 300;
					APR_Federal = 8.5;//4.17;
					APR_Fixed = 0;
					RateDiscount = 0.5;//1.0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 30000;
					MaxAmount = 0;
					MinError = 'The minumum amount for a 25-year repayment is $30,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;


					switch (LoanType) {
						case 'ALLSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;
							break;
						case 'SELFHELP10':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'SELFHELP25':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'FIXED':
							ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;
							break;
					}

					break;


				// PLUS Loan - 10 Years
				case '12':
					LoanType = 'FIXED';
					NumberOfPayments = 120;
					APR_Federal = 0;
					APR_Fixed = 4.17;
					RateDiscount = 0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 0;
					MaxAmount = 0;
					MinError = '';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;


					switch (LoanType) {
						case 'ALLSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;
							break;
						case 'SELFHELP10':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'SELFHELP25':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'FIXED':
							ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;
							break;
					}

					break;



				
				// PLUS Loan - 25 Years
				case '13':
					LoanType = 'FIXED';
					NumberOfPayments = 300;
					APR_Federal = 0;
					APR_Fixed = 4.17;
					RateDiscount = 0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 30000;
					MaxAmount = 0;
					MinError = 'The minumum amount for a 25-year repayment is $30,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;


					switch (LoanType) {
						case 'ALLSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;
							break;
						case 'SELFHELP10':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'SELFHELP25':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'FIXED':
							ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;
							break;
					}

					break;

				// ALLsaver Consolidation USA - Auto Debit
				case '14':
					LoanType = 'CONSOLUSA';
					NumberOfPayments = 0;
					APR_Federal = 0;
					APR_Fixed = 8.25;
					RateDiscount = 0.5;
					SelfHelpDiscount1 = 0.25;
					SelfHelpDiscount2 = 1.25;
					SelfHelpDiscount3 = 0;
					MinAmount = 10000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $10,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					switch (LoanType) {
						case 'ALLSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;
							break;
						case 'SELFHELP10':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'SELFHELP25':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'FIXED':
							ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;
							break;
					}

					break;
				
				// ALLsaver Consolidation USA
				case '15':
					LoanType = 'CONSOLUSA';
					NumberOfPayments = 0;
					APR_Federal = 0;
					APR_Fixed = 8.25;
					RateDiscount = 0.5;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 1;
					SelfHelpDiscount3 = 0;
					MinAmount = 10000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $10,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					switch (LoanType) {
						case 'ALLSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;
							break;
						case 'SELFHELP10':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'SELFHELP25':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'FIXED':
							ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;
							break;
					}

					break;

				// GRADsaver 10-year
				case '16':
					LoanType = 'GRADSAVER';
					NumberOfPayments = 120;
					APR_Federal = 3.37;
					APR_Fixed = 0;
					OrigniationFeeRate = 3.0;
					RateDiscount = 0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 18500;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $18,500.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					switch (LoanType) {
						case 'GRADSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal) * 1000) / 1000;
							break;
						case 'ALLSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;
							break;
						case 'SELFHELP10':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'SELFHELP25':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'FIXED':
							ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;
							break;
					}

					break;

				//  GRADsaver 25-year
				case '17':
					LoanType = 'GRADSAVER';
					NumberOfPayments = 360;
					APR_Federal = 3.37;
					APR_Fixed = 0;
					OrigniationFeeRate = 3.0;
					RateDiscount = 0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 30000;
					MaxAmount = 0;
					MinError = 'The minumum amount for a 25-year repayment is $30,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					switch (LoanType) {
						case 'GRADSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal) * 1000) / 1000;
							break;
						case 'ALLSAVER':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;
							break;
						case 'SELFHELP10':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'SELFHELP25':
							ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;
							break;
						case 'FIXED':
							ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;
							break;
					}

					break;

				//  ALLsaver Consolidation USA - Auto Debit
				case '20':
					LoanType = 'CONSOLUSA';
					NumberOfPayments = 0;
					APR_Federal = 0;
					APR_Fixed = 8.25;

					PrincipleReductionRate = 1.0;
					RateReduction1 = 0.25;
					RateReduction2 = 1.25;
					RateReduction3 = 1.25;

					MinAmount = 10000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $10,000.';
					MaxError = '';

					break;
				
				// ALLsaver Consolidation USA
				case '21':
					LoanType = 'CONSOLUSA';
					NumberOfPayments = 0;
					APR_Federal = 0;
					APR_Fixed = 8.25;

					PrincipleReductionRate = 1.0;
					RateReduction1 = 0.0;
					RateReduction2 = 1.0;
					RateReduction3 = 1.0;

					MinAmount = 10000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $10,000.';
					MaxError = '';

					break;


				//  ALLsaver Consolidation - Auto Debit
				case '22':
					LoanType = 'CONSOL';
					NumberOfPayments = 0;
					APR_Federal = 0;
					APR_Fixed = 8.25;

					PrincipleReductionRate = 1.0;
					RateReduction1 = 0.25;
					RateReduction2 = 0.25;
					RateReduction3 = 0.25;

					MinAmount = 10000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $10,000.';
					MaxError = '';

					break;
				
				// ALLsaver Consolidation
				case '23':
					LoanType = 'CONSOL';
					NumberOfPayments = 0;
					APR_Federal = 0;
					APR_Fixed = 8.25;

					PrincipleReductionRate = 1.0;
					RateReduction1 = 0.0;
					RateReduction2 = 1.25;
					RateReduction3 = 1.25;

					MinAmount = 10000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $10,000.';
					MaxError = '';

					break;



// -----------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------
//                    FISCAL YEAR 2005-06
// -----------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------


				// ALLsaver Stafford Loan - 10 Years - Auto Debit
				case '24':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					//APR_Federal = 5.30; //hani
					APR_Federal = 6.80;
					APR_Fixed = 0;
					//RateDiscount = 1.75;//Salah Auguts 26, 2007
					RateDiscount = 2.25;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 7500;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $7,500.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;



				
				// ALLsaver Stafford Loan - 25 Years - Auto Debit
				case '25':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 300;
					//APR_Federal = 5.30; //hani
					APR_Federal = 6.8;
					APR_Fixed = 0;
					//RateDiscount = 1.75;//Salah Auguts 26, 2007
					RateDiscount = 2.25;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 30000;
					MaxAmount = 0;
					MinError = 'The minumum amount for a 25-year repayment is $30,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;


				
				// ALLsaver Stafford Loan -2007/2008 10 Years
				case '26':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					//APR_Federal = 5.30; //Hani
					APR_Federal = 6.80; 
					APR_Fixed = 0;
					//RateDiscount = 1.5;//salah Auguts 26, 2007
					RateDiscount = 1.0
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 7500;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $7,500.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;

				//ALLsaver Stafford Loan 2007/2008- 25 Years
				case '27':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 300;
					//APR_Federal = 5.30;  //Hani
					APR_Federal = 6.80;
					APR_Fixed = 0;
					//RateDiscount = 1.5;//salah Auguts 26, 2007
					RateDiscount = 1.0
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 30000;
					MaxAmount = 0;
					MinError = 'The minumum amount for a 25-year repayment is $30,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;




				// ALLsaver PLUS Loan - 10 Years - Auto Debit
				case '28':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					//APR_Federal = 6.10; //Hani
					APR_Federal = 8.50;
					APR_Fixed = 0;
					//RateDiscount = 1.75;//Salah August 26, 2007
					RateDiscount = 2.25;

					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 5000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $5,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;
				

				// ALLsaver PLUS Loan - 25 Years - Auto Debit
				case '29':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 300;
					//APR_Federal = 6.10; //Hani
					APR_Federal = 8.50;
					APR_Fixed = 0;
					//RateDiscount = 1.75;//Salah August 26, 2007
					RateDiscount = 2.25;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 30000;
					MaxAmount = 0;
					MinError = 'The minumum amount for a 25-year repayment is $30,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;



				

				// ALLsaver PLUS Loan - 10 Years
				case '30':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					//APR_Federal = 6.10; //Hani
					APR_Federal = 8.50;
					APR_Fixed = 0;
					//RateDiscount = 0.75//Hani;
					RateDiscount = 1.0;//Salah Auguts 26, 2007

					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 5000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $5,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;



				

				// ALLsaver PLUS Loan - 25 Years
				case '31':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 300;
					//APR_Federal = 6.10; //Hani
					APR_Federal = 8.50;
					APR_Fixed = 0;
					//RateDiscount = 0.75; //Hani
					RateDiscount = 1.0;//Salah Auguts 26, 2007
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 30000;
					MaxAmount = 0;
					MinError = 'The minumum amount for a 25-year repayment is $30,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;


				// PLUS Loan - 10 Years
				case '32':
					LoanType = 'FIXED';
					NumberOfPayments = 120;
					
				
					APR_Federal = 0;
					//APR_Fixed = 6.10;  //Hani
					APR_Fixed = 8.50;
					RateDiscount = 0;
					
					
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 0;
					MaxAmount = 0;
					MinError = '';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;

					break;

				
				// PLUS Loan - 25 Years
				case '33':
					LoanType = 'FIXED';
					NumberOfPayments = 300;
					APR_Federal = 0;
					//APR_Fixed = 6.10; //Hani
					APR_Fixed = 8.50;
					RateDiscount = 0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 30000;
					MaxAmount = 0;
					MinError = 'The minumum amount for a 25-year repayment is $30,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Fixed) * 1000) / 1000;

					break;



				// SelfHelp Stafford Loan - 10 Years - Auto Debit
				case '34':
					LoanType = 'SELFHELP10';
					NumberOfPayments = 120;
					APR_Federal = 5.30;
					APR_Fixed = 0;
					RateDiscount = 0;
					SelfHelpDiscount1 = 0.25;
					SelfHelpDiscount2 = 2.25;
					SelfHelpDiscount3 = 0;
					MinAmount = 1000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $1,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;

					break;

				// SelfHelp Stafford Loan - 10 Years
				case '35':
					LoanType = 'SELFHELP10';
					NumberOfPayments = 120;
					APR_Federal = 5.30;
					APR_Fixed = 0;
					RateDiscount = 0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 2;
					SelfHelpDiscount3 = 0;
					MinAmount = 1000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $1,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - SelfHelpDiscount2) * 1000) / 1000;

					break;



				//  ALLsaver Consolidation USA - Auto Debit
				case '36':
					LoanType = 'CONSOLUSA';
					NumberOfPayments = 0;
					APR_Federal = 0;
					APR_Fixed = 8.25;

					PrincipleReductionRate = 1.0;
					RateReduction1 = 0.25;
					RateReduction2 = 1.25;
					RateReduction3 = 1.25;

					MinAmount = 10000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $10,000.';
					MaxError = '';

					break;
				
				// ALLsaver Consolidation USA
				case '37':
					LoanType = 'CONSOLUSA';
					NumberOfPayments = 0;
					APR_Federal = 0;
					APR_Fixed = 8.25;

					PrincipleReductionRate = 1.0;
					RateReduction1 = 0.0;
					RateReduction2 = 1.0;
					RateReduction3 = 1.0;

					MinAmount = 10000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $10,000.';
					MaxError = '';

					break;


				//  ALLsaver Consolidation - Auto Debit
				case '38':
					LoanType = 'CONSOL';
					NumberOfPayments = 0;
					APR_Federal = 0;
					APR_Fixed = 8.25;

					PrincipleReductionRate = 1.0;
					RateReduction1 = 0.25;
					RateReduction2 = 1.5;
					RateReduction3 = 1.5;

					MinAmount = 10000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $10,000.';
					MaxError = '';

					break;
				
				// ALLsaver Consolidation
				case '39':
					LoanType = 'CONSOL';
					NumberOfPayments = 0;
					APR_Federal = 0;
					APR_Fixed = 8.25;

					PrincipleReductionRate = 1.0;
					RateReduction1 = 0.0;
					RateReduction2 = 1.25;
					RateReduction3 = 1.25;

					MinAmount = 10000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $10,000.';
					MaxError = '';

					break;




				// ALLsaver Stafford USA - 10 Years - Auto Debit
				case '40':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					//APR_Federal = 5.30; //Hani
					APR_Federal = 6.80;
					RateDiscount = 1.50; //Hani
					//RateDiscount = 1.25;
					MinAmount = 8500;

					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $8,500.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;



				
				// ALLsaver Stafford USA - 25 Years - Auto Debit
				case '41':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 300;
					//APR_Federal = 5.30; //Hani
					APR_Federal = 6.80;
					RateDiscount = 1.50; //Hani
					//RateDiscount = 1.25;
					MinAmount = 30000;
					MaxAmount = 0;
					MinError = 'The minumum amount for a 25-year repayment is $30,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;


				
				// ALLsaver Stafford USA - 10 Years
				case '42':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					//APR_Federal = 5.30; //Hani
					APR_Federal = 6.80;
					RateDiscount = 1.00;  
					MinAmount = 8500;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $8,500.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;

				//ALLsaver Stafford USA - 25 Years
				case '43':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 300;
					//APR_Federal = 5.30; //Hani
					APR_Federal = 6.80;
					RateDiscount = 1.00;					
					MinAmount = 30000;
					MaxAmount = 0;
					MinError = 'The minumum amount for a 25-year repayment is $30,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;

				// No Interest PLUS Loan - 10 Years - Auto Debit - Added 11/29/2005 by Steven Galfano
				case '44':
					LoanType = 'NOINTEREST12MONTHS';
					NumberOfPayments = 120;
					//APR_Federal = 6.10; //Hani
					APR_Federal = 8.50;
					APR_Fixed = 0;
					RateDiscount = 0;
					//SelfHelpDiscount1 = 6.10; //Hani
					SelfHelpDiscount1 = 8.50;
					//SelfHelpDiscount2 = 0;
					//SelfHelpDiscount2 = 0.25;
					SelfHelpDiscount2 = 0.151;

					MinAmount = 5000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $5,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;

				// No Interest PLUS Loan - 10 Years - NO Auto Debit - Added 11/29/2005 by Steven Galfano
				case '45':
					LoanType = 'NOINTEREST12MONTHS';
					NumberOfPayments = 120;
					//APR_Federal = 6.10; //Hani	
					APR_Federal = 8.50;
					APR_Fixed = 0;
					RateDiscount = 0;
					//SelfHelpDiscount1 = 6.10;  //Hani
					SelfHelpDiscount1 = 8.50;
					SelfHelpDiscount2 = 0.0;
					MinAmount = 5000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $5,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;

				// No Interest PLUS Loan - 25 Years - Auto Debit - Added 11/29/2005 by Steven Galfano
				case '46':
					LoanType = 'NOINTEREST12MONTHS';
					NumberOfPayments = 300;
					//APR_Federal = 6.10; //Hani
					APR_Federal = 8.50;
					APR_Fixed = 0;
					RateDiscount = 0;
					//SelfHelpDiscount1 = 6.10; //Hani
					SelfHelpDiscount1 = 8.50; 
					SelfHelpDiscount2 = 0.25;
					MinAmount = 30000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $30,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;

				// No Interest PLUS Loan - 25 Years - NO Auto Debit - Added 11/29/2005 by Steven Galfano
				case '47':
					LoanType = 'NOINTEREST12MONTHS';
					NumberOfPayments = 300;
					//APR_Federal = 6.10; //Hani
					APR_Federal = 8.50;
					APR_Fixed = 0;
					RateDiscount = 0;
					//SelfHelpDiscount1 = 6.10; //Hani
					SelfHelpDiscount1 = 8.50;
					SelfHelpDiscount2 = 0.0;
					MinAmount = 30000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $30,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;

				//  ALLsaver Consolidation - Auto Debit
				case '48':
					LoanType = 'CONSOL_NOINTEREST12MONTHS';
					NumberOfPayments = 0;
					APR_Federal = 0;
					APR_Fixed = 8.25;

					PrincipleReductionRate = 0.0;
					RateReduction1 = 0.0;
					RateReduction2 = 0.25;

					MinAmount = 10000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $10,000.';
					MaxError = '';

					break;
				
				// ALLsaver Consolidation
				case '49':
					LoanType = 'CONSOL_NOINTEREST12MONTHS';
					NumberOfPayments = 0;
					APR_Federal = 0;
					APR_Fixed = 8.25;

					PrincipleReductionRate = 0.0;
					RateReduction1 = 0.0;
					RateReduction2 = 0.0;

					MinAmount = 10000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $10,000.';
					MaxError = '';

					break;
					
					
						// Grad PLUS Loan - 10 Years 2007/2008--Hani
				case '50':
					LoanType = 'ALLSAVER';
					CashBackRate = 3;
					NumberOfPayments = 120;
					APR_Federal = 8.50;
					APR_Fixed = 0;
					//RateDiscount = 0.6;//Salah Auguts 26, 2007
					RateDiscount = 1.0;

					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 5000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $5,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;
				

				
				// Grad PLUS Loan - 25 Years 2007/2008  --Hani
				case '51':
					LoanType = 'ALLSAVER';
					CashBackRate = 3;
					NumberOfPayments = 300;
					APR_Federal = 8.50;
					APR_Fixed = 0;
					//RateDiscount = 0.6;//Salah Auguts 26, 2007
					RateDiscount = 1.0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 5000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $5,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;
					
						// Grad PLUS Loan - 10 Years 2008/2009 --Waheed
				case '52':
					LoanType = 'ALLSAVER49PercatageChange';
					CashBackRate = 3;
					NumberOfPayments = 120;
					APR_Federal = 8.50;
					APR_Fixed = 0;
					//RateDiscount = 0.6;//Salah Auguts 26, 2007
					RateDiscount = 1.0;

					SelfHelpDiscount1 = 0.25;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 5000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $5,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal) * 1000) / 1000;

					break;
					
					// Grad PLUS Loan - 25 Years 2008/2009  --Hani
				case '53':
					LoanType = 'ALLSAVER49PercatageChange';
					CashBackRate = 3;
					NumberOfPayments = 300;
					APR_Federal = 8.50;
					APR_Fixed = 0;
					//RateDiscount = 0.6;//Salah Auguts 26, 2007
					RateDiscount = 1.0;
					SelfHelpDiscount1 = 0.25;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 5000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $5,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal) * 1000) / 1000;

					break;
					
					
					
				// ALLsaver PLUS Loan 0.25 ACH discount
				case '60':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					//APR_Federal = 6.10; //Hani
					APR_Federal = 8.50;
					APR_Fixed = 0;
					//RateDiscount = 0.75//Hani;
					RateDiscount = 0.25;//Salah Auguts 26, 2007

					SelfHelpDiscount1 = 0; //ACH discount rate
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 50;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $50';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					//ThisForm.APR_Discounted.value = Math.round((APR_Federal) * 1000) / 1000;
					ThisForm.APR_Discounted.value = Math.round((APR_Federal-RateDiscount) * 1000) / 1000;

					break;



				

				// ALLsaver Grad PLUS Loan 0.25 ACH discount
				case '61':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					//APR_Federal = 6.10; //Hani
					APR_Federal = 8.5;
					APR_Fixed = 0;
					//RateDiscount = 0.75; //Hani
					RateDiscount = 0.25;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 50;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $50';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					//ThisForm.APR_Discounted.value = Math.round((APR_Federal) * 1000) / 1000;
					ThisForm.APR_Discounted.value = Math.round((APR_Federal-RateDiscount) * 1000) / 1000;

					break;

				// ALLsaver Stafford Loan Subsidized Undergrad 0.25 ACH discount
				case '62':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					//APR_Federal = 5.30; //Hani
					APR_Federal = 5.6; 
					APR_Fixed = 0;
					//RateDiscount = 1.5;//salah Auguts 26, 2007
					RateDiscount = 0.25;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 50;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $50';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					//ThisForm.APR_Discounted.value = Math.round((APR_Federal) * 1000) / 1000;
					ThisForm.APR_Discounted.value = Math.round((APR_Federal-RateDiscount) * 1000) / 1000;

					break;

				//ALLsaver Stafford Loan Unsubsidized Undergrad 0.25 ACH discount
				case '63':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					//APR_Federal = 5.30;  //Hani
					APR_Federal = 6.80;
					APR_Fixed = 0;
					//RateDiscount = 1.5;//salah Auguts 26, 2007
					RateDiscount = 0.25;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 50;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $50';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal) * 1000) / 1000;

					break;
					
					
			//ALLsaver Stafford Loan Subsidized Grad 0.25 ACH discount
				case '64':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					//APR_Federal = 5.30;  //Hani
					APR_Federal = 6.80;
					APR_Fixed = 0;
					//RateDiscount = 1.5;//salah Auguts 26, 2007
					RateDiscount = 0.25;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 50;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $50';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal) * 1000) / 1000;

					break;
					
					
					//ALLsaver Stafford Loan Unsubsidized Grad 0.25 ACH discount
				case '65':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					//APR_Federal = 5.30;  //Hani
					APR_Federal = 6.80;
					APR_Fixed = 0;
					//RateDiscount = 1.5;//salah Auguts 26, 2007
					RateDiscount = 0.25;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 50;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $50';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal) * 1000) / 1000;

					break;
					
					// ALLsaver PLUS Loan 
				case '70':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					//APR_Federal = 6.10; //Hani
					APR_Federal = 8.50;
					APR_Fixed = 0;
					//RateDiscount = 0.75//Hani;
					RateDiscount = 0;//Salah Auguts 26, 2007

					SelfHelpDiscount1 = 0; //ACH discount rate
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 50;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $50';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal) * 1000) / 1000;

					break;

				// ALLsaver Grad PLUS Loan
				case '71':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					//APR_Federal = 6.10; //Hani
					APR_Federal = 8.50;
					APR_Fixed = 0;
					//RateDiscount = 0.75; //Hani
					RateDiscount = 0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 50;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $50';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal) * 1000) / 1000;

					break;

				// ALLsaver Stafford Loan Subsidized Undergrad
				case '72':
				
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					//APR_Federal = 5.30; //Hani
					APR_Federal = 5.60; 
					APR_Fixed = 0;
					//RateDiscount = 1.5;//salah Auguts 26, 2007
					RateDiscount = 0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 50;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $50';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal) * 1000) / 1000;

					break;

				//ALLsaver Stafford Loan Unsubsidized Undergrad
				case '73':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					//APR_Federal = 5.30;  //Hani
					APR_Federal = 6.80;
					APR_Fixed = 0;
					//RateDiscount = 1.5;//salah Auguts 26, 2007
					RateDiscount = 0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 50;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $50';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal) * 1000) / 1000;

					break;
					
					
			//ALLsaver Stafford Loan Subsidized Grad
				case '74':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					//APR_Federal = 5.30;  //Hani
					APR_Federal = 6.80;
					APR_Fixed = 0;
					//RateDiscount = 1.5;//salah Auguts 26, 2007
					RateDiscount = 0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 50;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $50';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal) * 1000) / 1000;

					break;
					
					
					//ALLsaver Stafford Loan Unsubsidized Grad
				case '75':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					//APR_Federal = 5.30;  //Hani
					APR_Federal = 6.80;
					APR_Fixed = 0;
					//RateDiscount = 1.5;//salah Auguts 26, 2007
					RateDiscount = 0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 50;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $50';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal) * 1000) / 1000;

					break;
					
			
					
					
					
					
				//ALLsaver PLUS USA - 10 Years - Auto Debit	
				case '101':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					APR_Federal = 8.50;
					APR_Fixed = 0;
					RateDiscount = 1.5;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 5000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $5,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;
					
				//ALLsaver PLUS USA - 25 Years - Auto Debit
				case '102':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 300;
					APR_Federal = 8.50;
					APR_Fixed = 0;
					RateDiscount = 1.5;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 5000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $5,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;
					
				
				//ALLsaver PLUS USA - 10 Years				
				case '103':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 120;
					APR_Federal = 8.50;
					APR_Fixed = 0;

					RateDiscount = 0.5;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 5000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $5,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;
					
				//ALLsaver PLUS USA - 25 Years
				case '104':
					LoanType = 'ALLSAVER';
					NumberOfPayments = 300;
					APR_Federal = 8.50;
					APR_Fixed = 0;
					RateDiscount = 0.5;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 5000;
					MaxAmount = 0;
					MinError = 'The minimum amount for this loan is $5,000.';
					MaxError = '';

					Rate_Federal = APR_Federal / 1200;
					APR_Discounted = APR_Federal - RateDiscount;
					Rate_Discounted = APR_Discounted / 1200;

					APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
					APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
					Rate_Discounted1 = APR_Discounted1 / 1200;
					Rate_Discounted2 = APR_Discounted2 / 1200;

					Rate_Fixed = APR_Fixed / 1200;

					ThisForm.APR_Discounted.value = Math.round((APR_Federal - RateDiscount) * 1000) / 1000;

					break;

				default:

					LoanType = 0;
					NumberOfPayments = 0;
					APR_Federal = 0;
					APR_Fixed = 0;
					RateDiscount = 0;
					SelfHelpDiscount1 = 0;
					SelfHelpDiscount2 = 0;
					SelfHelpDiscount3 = 0;
					MinAmount = 0;
					MaxAmount = 0;
					ThisForm.APR_Discounted.value = '';

	}

}

function DisplayCurrency (vNum) {
    var vCurrencyFormat = '$0.00';
	var vDecimals = '00';
	var vWholePart = 0;
	var NumberOfCommas = 0;
	var LeadingDigitsCount = 0;
	var vNewWholePart = '';
	var vTmpStr = '';
	var i = 0;
	var n = 0;

	//Put commas on the left side
	vWholePart = Math.floor(vNum);
	
	vTotalDigits = vWholePart.toString().length;

	// This loop evaluates the whole part of a number
	// in reverse and puts a comma in after every
	// three digits
	for (i = vTotalDigits; i >= 0; i--) {
		if (n == 4) {
			vNewWholePart = vNewWholePart + ',';
			n = 2;
		} else {
			n++;
		}
		vNewWholePart = vNewWholePart + vWholePart.toString().charAt(i);
	}
	// This loop reverses the string back to normal
	for (i = vNewWholePart.length; i >= 0; i--) {
		vTmpStr = vTmpStr + vNewWholePart.toString().charAt(i);
	}
	vWholePart = vTmpStr;

    // make sure the number has exactly two decimal places
    vDecimals = Math.floor( (vNum*100) - (Math.floor(vNum)*100) );
//    vCurrencyFormat = "$" + Math.floor(vNum) + "." + ((vDecimals < 10) ? "0" : "") + vDecimals;
	vCurrencyFormat = "$" + vWholePart + "." + ((vDecimals < 10) ? "0" : "") + vDecimals;

    return vCurrencyFormat;
}

var tempNumberOfActualPayments, tempDiscountAmount;

//returns the number od payment for ALLSAVER49PercatageChange loans - waheed
function GetLastMonthPayment(MonthlyPayment)
{
      var paidAmount = 0; //the value of amount paid without interest
      var remainingAmount; //the value of amount remaining without interest
      var discountAmount; //amount of balance dicounted after 48 months
      var remainingMonths = 1; //number of months the borrower has to pay after the 48 months
      
      //initilize remaining amount to amount borrowed
      remainingAmount = AmountBorrowed;
      
      //calculate paid and remaining amounts for first 48 months
      for (i = 0; i < 48; i++)
      {
         //paid amount equals monthly paiment minus interest paid
         paidAmount += MonthlyPayment - (remainingAmount * Rate_Discounted1);
         
         //remaining amount is the value of amount borrowed minus amount paid
         remainingAmount = AmountBorrowed - paidAmount  ;
      }
        
       
        //discount is 1% of amount remaining after 48 months
        discountAmount = remainingAmount * (RateDiscount / 100);
        
        //calculate the payment for month 49, and add the dicount amount to it
        paidAmount += MonthlyPayment - (remainingAmount * Rate_Discounted1) + discountAmount;
            
        remainingAmount = AmountBorrowed - paidAmount;
        //assign discount amount value to be used in another method
        tempDiscountAmount = discountAmount;
        
        //keep calculating the number of month untill the remaining amount is less than zero
        while (remainingAmount > 0)
        {
            paidAmount += MonthlyPayment - (remainingAmount * Rate_Discounted1);
            
            remainingAmount = AmountBorrowed - paidAmount;
            
            remainingMonths++;
        }
    
        //assign number of actual payment to be used in other methods
        tempNumberOfActualPayments = remainingMonths + 48;
               
        //return the amount of the last payment which is the monthly payment and the amount left in the remaining amount variable
        return MonthlyPayment + remainingAmount;
        

}

function Calculate(ThisForm) {

	var MonthlyPayment = 0;
	var NumberOfActualPayments = 0;
	var TotalAmountPaid = 0;
	var TotalInterestPaid = 0;
	var TotalPrincipalPaid = 0;
	var Month49Balance = 0;
	
	OK2Calculate = true;

	if (LoanType != 'CONSOL_NOINTEREST12MONTHS') {

		ThisForm.TotalPrincipalPaid.value = '';
		ThisForm.MonthlyPayment.value = '';
		ThisForm.TotalAmountPaid.value = '';
		ThisForm.TotalInterestPaid.value = '';
		ThisForm.NumberOfActualPayments.value = '';


		// Read variables from the form
		AmountBorrowed = FormatCurrency(ThisForm.AmountBorrowed.value);

		// Make sure they chose a loan
		if (ThisForm.LoanType.value == '0') {
			window.alert ('Please choose a loan');
			OK2Calculate = false;
		}

		// Check to make sure they entered a number as the amount borrowed
		if (isNaN(ThisForm.AmountBorrowed.value)) {
			OK2Calculate = false;
		}

		// Make sure the laon falls within the acceptable range
		// First make sure it's over the minimum amount
		if (AmountBorrowed < MinAmount) {
			window.alert(MinError);
			OK2Calculate = false;
		} else if ((AmountBorrowed > MaxAmount) && MaxAmount != 0) {
			window.alert(MaxError);
			OK2Calculate = false;
		}
	}

	if (OK2Calculate) {

		// Do calculations
		if (LoanType == 'ALLSAVER') {

			// The process of calculating an ALLsaver loan...
			// 1) Calculate monthly payment using federal interest rate
			// 2) Amortize loan to determine total interest paid
			// 3) Add the principal and interest paid to get total repayment amount
			// 4) Divide total repayment amount by monthly payment to get actual payments

			// 1) Calculate monthly payment using federal interest rate
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

			// 2) Amortize loan to determine total interest paid
			AmortizeLoan(AmountBorrowed, Rate_Discounted, NumberOfPayments, MonthlyPayment);
			TotalInterestPaid = amInterestPaid;

			// 3) Add the principal and interest paid to get total repayment amount
			TotalAmountPaid = TotalInterestPaid + AmountBorrowed;

			// 4) Divide total repayment amount by monthly payment to get actual payments
			NumberOfActualPayments = Math.ceil(TotalAmountPaid / MonthlyPayment);


		}
		else if (LoanType == 'ALLSAVER49PercatageChange')
		{
			// The process of calculating an ALLsaver loan...
			// 1) Calculate monthly payment using federal interest rate
			// 2) get last payment amount since it's the only different payment
			// 3) calculate total amount paid
			// 4) calculate total interest

            

			// 1) Calculate monthly payment using federal interest rate
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

			// 2) get last payment amount since it's the only different payment
			var LastMonthPayment  = GetLastMonthPayment(MonthlyPayment);
			
			//assign number of actual paymnets
			NumberOfActualPayments = tempNumberOfActualPayments;
			
			// 3) calculate total amount paid
			TotalAmountPaid = MonthlyPayment * (NumberOfActualPayments - 1) + LastMonthPayment + tempDiscountAmount;
			 
			// 4) calculate total interest
            TotalInterestPaid = TotalAmountPaid - AmountBorrowed;

		    
		}
		else if (LoanType == 'SELFHELP10') 
		{

			// The process of calculating an SELFHELP10 loan...
			// 1) Calculate monthly payment using federal interest rate
			// 2) Amortize loan for 48 months at the initial discounted rate to determine interest paid during that period
			// 3) Amortize loan for 72 months at the second discounted rate to determine interest paid during that period
			// 4) Add the principal and total interest paid to get total repayment amount
			// 5) Divide total repayment amount by monthly payment to get actual payments

			// 1) Calculate monthly payment using federal interest rate
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

			// 2) Amortize loan for 48 months at the initial discounted rate to determine interest paid during that period
			AmortizeLoan(AmountBorrowed, Rate_Discounted1, 48, MonthlyPayment);
			Interest1 = amInterestPaid;

			// 3) Amortize loan for 72 months at the second discounted rate to determine interest paid during that period
			AmortizeLoan(amRemainingBalance, Rate_Discounted2, 72, MonthlyPayment);
			Interest2 = amInterestPaid;
			TotalInterestPaid = Interest1 + Interest2;

			// 4) Add the principal and total interest paid to get total repayment amount
			TotalAmountPaid = AmountBorrowed + TotalInterestPaid;

			// 5) Divide total repayment amount by monthly payment to get actual payments
			NumberOfActualPayments = Math.ceil(TotalAmountPaid / MonthlyPayment);


		} 
		else if (LoanType == 'SELFHELP25') 
		{

			// The process of calculating an SELFHELP25 loan...
			// 1) Calculate monthly payment using federal interest rate
			// 2) Amortize loan for 48 months at the initial discounted rate to determine interest paid during that period
			// 3) Amortize loan for 72 months at the second discounted rate to determine interest paid during that period
			// 4) Add the principal and total interest paid to get total repayment amount
			// 5) Divide total repayment amount by monthly payment to get actual payments

			// 1) Calculate monthly payment using federal interest rate
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

			// 2) Amortize loan for 48 months at the initial discounted rate to determine interest paid during that period
			AmortizeLoan(AmountBorrowed, Rate_Discounted1, 48, MonthlyPayment);
			Interest1 = amInterestPaid;

			// 3) Amortize loan for 72 months at the second discounted rate to determine interest paid during that period
			AmortizeLoan(amRemainingBalance, Rate_Discounted2, 72, MonthlyPayment);
			Interest2 = amInterestPaid;

			// 4) Amortize loan for 72 months at the second discounted rate to determine interest paid during that period
			AmortizeLoan(amRemainingBalance, Rate_Federal, 180, MonthlyPayment);
			Interest3 = amInterestPaid;
			TotalInterestPaid = Interest1 + Interest2 + Interest3;

			// 5) Add the principal and total interest paid to get total repayment amount
			TotalAmountPaid = AmountBorrowed + TotalInterestPaid;

			// 6) Divide total repayment amount by monthly payment to get actual payments
			NumberOfActualPayments = Math.ceil(TotalAmountPaid / MonthlyPayment);

		} 
		else if (LoanType == 'FIXED') 
		{

			// The process of calculating an ALLsaver loan...
			// 1) Calculate monthly payment using federal interest rate
			// 2) Amortize loan to determine total interest paid
			// 3) Add the principal and interest paid to get total repayment amount
			// 4) Divide total repayment amount by monthly payment to get actual payments

			// 1) Calculate monthly payment using federal interest rate
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Fixed, NumberOfPayments);

			// 2) Amortize loan to determine total interest paid
			AmortizeLoan(AmountBorrowed, Rate_Fixed, NumberOfPayments, MonthlyPayment);
			TotalInterestPaid = amInterestPaid;

			// 3) Add the principal and interest paid to get total repayment amount
			TotalAmountPaid = TotalInterestPaid + AmountBorrowed;

			// 4) Divide total repayment amount by monthly payment to get actual payments
			NumberOfActualPayments = Math.ceil(TotalAmountPaid / MonthlyPayment);

		} 
		else if (LoanType == 'NOINTEREST12MONTHS') 
		{

			// The process of calculating an SELFHELP10 loan...
			// 1) Calculate monthly payment using federal interest rate
			// 2) Amortize loan for 12 months at no interest to determine interest paid during that period
			// 3) Amortize loan for 120 more months at the discounted rate to determine interest paid during that period
			// 4) Add the principal and total interest paid to get total repayment amount
			// 5) Divide total repayment amount by monthly payment to get actual payments

			// 1) Calculate monthly payment using federal interest rate
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

			// 2) Amortize loan for 12 months at the initial discounted rate to determine interest paid during that period
			AmortizeLoan(AmountBorrowed, Rate_Discounted1, 12, MonthlyPayment);
			Interest1 = amInterestPaid;

			// 3) Amortize loan for the remaining months at the second discounted rate to determine interest paid during that period
			AmortizeLoan(amRemainingBalance, Rate_Discounted2, NumberOfPayments , MonthlyPayment);
			Interest2 = amInterestPaid;
			TotalInterestPaid = Interest1 + Interest2;

			// 4) Add the principal and total interest paid to get total repayment amount
			TotalAmountPaid = AmountBorrowed + TotalInterestPaid;

			// 5) Divide total repayment amount by monthly payment to get actual payments
			NumberOfActualPayments = Math.ceil(TotalAmountPaid / MonthlyPayment);

		} 
		else if (LoanType == 'CONSOL_NOINTEREST12MONTHS') 
		{

			var InterestPaid_Standard = 0;
			var InterestPaid_Discounted = 0;
			var TotalPaid_Standard = 0;
			var TotalPaid_Discounted = 0;
			var CalculateSavings = true;

			OK2Calculate = true;

			ThisForm.APR_Standard.value = '';
			ThisForm.APR_Discounted.value = '';
			ThisForm.MonthlyPayment_Standard.value = '';
			ThisForm.MonthlyPayment_Discounted.value = '';
			ThisForm.NumberOfPayments_Standard.value = '';
			ThisForm.NumberOfPayments_Discounted.value = '';
			ThisForm.TotalInterest_Standard.value = '';
			ThisForm.TotalInterest_Discounted.value = '';
			ThisForm.TotalPaid_Standard.value = '';
			ThisForm.TotalPaid_Discounted.value = '';

			ThisForm.APR_Savings.value = '';
			ThisForm.TotalPaid_Savings.value = '';

			AmountBorrowed = GetConsolidationPrincpal(ThisForm);
			APR_Federal = GetWeightedAPR(ThisForm);

			// Make sure they chose a loan
			if ((OK2Calculate) && (ThisForm.LoanType.value == '0')) {
				window.alert ('Please choose a loan');
				OK2Calculate = false;
			}

			// Make sure the laon falls within the acceptable range
			// First make sure it's over the minimum amount
			if ((OK2Calculate) && (AmountBorrowed < MinAmount)) {
				window.alert(MinError);
				OK2Calculate = false;
			} else if ((OK2Calculate) && ((AmountBorrowed > MaxAmount) && MaxAmount != 0)) {
				window.alert(MaxError);
				OK2Calculate = false;
			}

			if (OK2Calculate) {


				// Determine the number of payments
				// These numbers are federally mandated
				if ((AmountBorrowed > 0) && (AmountBorrowed < 7500)) {
					NumberOfPayments = 120;
				} else if ((AmountBorrowed >= 7500) && (AmountBorrowed < 10000)) {
					NumberOfPayments = 144;
				} else if ((AmountBorrowed >= 10000) && (AmountBorrowed < 20000)) {
					NumberOfPayments = 180;
				} else if ((AmountBorrowed >= 20000) && (AmountBorrowed < 40000)) {
					NumberOfPayments = 240;
				} else if ((AmountBorrowed >= 40000) && (AmountBorrowed < 60000)) {
					NumberOfPayments = 300;
				} else if (AmountBorrowed >= 60000) {
					NumberOfPayments = 360;
				} else {
					NumberOfPayments = 0;
				}

				// This is the maximum loan rate, also federally mandated
				if (APR_Federal > APR_Fixed) {
					APR_Federal = APR_Fixed;
				}

				Rate_Federal = APR_Federal / 1200;

				// The process of calculating an SELFHELP10 loan...
				// 1) Calculate monthly payment using federal interest rate
				// 2) Amortize loan for 48 months at the initial discounted rate to determine interest paid during that period
				// 3) Amortize loan for 72 months at the second discounted rate to determine interest paid during that period
				// 4) Add the principal and total interest paid to get total repayment amount
				// 5) Divide total repayment amount by monthly payment to get actual payments

				APR_Discounted1 = 0.0;
				APR_Discounted2 = APR_Federal - RateReduction2;
				Rate_Discounted1 = APR_Discounted1 / 1200;
				Rate_Discounted2 = APR_Discounted2 / 1200;

				// This is only for display purposes
				// This variable is not used in the calculations
				APR_Discounted = APR_Discounted2; // ...

				// 1) Calculate monthly payment using federal interest rate
				MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

				// 2) Amortize loan at the federal rate to determine standard total interest paid
				AmortizeLoan(AmountBorrowed, Rate_Federal, NumberOfPayments, MonthlyPayment);
				InterestPaid_Standard = amInterestPaid;
				TotalPaid_Standard = AmountBorrowed + InterestPaid_Standard;

				// 2) Amortize loan for 12 months at interest
				AmortizeLoan(AmountBorrowed, Rate_Discounted1, 12, MonthlyPayment);
				InterestPaid_Discounted = amInterestPaid;

				// 3) Amortize loan for the remaining months to determine interest paid during that period
				AmortizeLoan(amRemainingBalance, Rate_Discounted2, NumberOfPayments, MonthlyPayment);
				InterestPaid_Discounted += amInterestPaid;
				TotalPaid_Discounted = AmountBorrowed + InterestPaid_Discounted;

				// 5) Divide total repayment amount by monthly payment to get actual payments
				NumberOfActualPayments = Math.ceil(TotalPaid_Discounted / MonthlyPayment);

			}

			//Set values on the form

			APR_Savings = APR_Federal - APR_Discounted;
			TotalPaid_Savings = TotalPaid_Standard - TotalPaid_Discounted;
			ThisForm.APR_Savings.value = APR_Savings;
			ThisForm.TotalPaid_Savings.value = DisplayCurrency(FormatCurrency(TotalPaid_Savings));

			ThisForm.APR_Standard.value = APR_Federal;
			ThisForm.MonthlyPayment_Standard.value = DisplayCurrency(FormatCurrency(MonthlyPayment));
			ThisForm.NumberOfPayments_Standard.value = NumberOfPayments;
			ThisForm.TotalInterest_Standard.value = DisplayCurrency(FormatCurrency(InterestPaid_Standard));
			ThisForm.TotalPaid_Standard.value = DisplayCurrency(FormatCurrency(TotalPaid_Standard));

			ThisForm.APR_Discounted.value = APR_Discounted;
			ThisForm.MonthlyPayment_Discounted.value = DisplayCurrency(FormatCurrency(MonthlyPayment));
			ThisForm.NumberOfPayments_Discounted.value = NumberOfActualPayments;
			ThisForm.TotalInterest_Discounted.value = DisplayCurrency(FormatCurrency(InterestPaid_Discounted));
			ThisForm.TotalPaid_Discounted.value = DisplayCurrency(FormatCurrency(TotalPaid_Discounted));


		}

		if (LoanType != 'CONSOL_NOINTEREST12MONTHS') {

			//Set values on the form
			ThisForm.TotalPrincipalPaid.value = DisplayCurrency(AmountBorrowed);
			ThisForm.MonthlyPayment.value = DisplayCurrency(FormatCurrency(MonthlyPayment));
			ThisForm.TotalAmountPaid.value = DisplayCurrency(FormatCurrency(TotalAmountPaid));
			ThisForm.TotalInterestPaid.value = DisplayCurrency(FormatCurrency(TotalInterestPaid));
			ThisForm.NumberOfActualPayments.value = Math.ceil(NumberOfActualPayments);

		}

	}

}


// -------------------------------------------------------------------------------
// -------------------------------------------------------------------------------
// ALLSaver Consol Calculations - USA Product Only!!!  (Not the California Product)
// -------------------------------------------------------------------------------
// -------------------------------------------------------------------------------

function CalculateConsolidation_USA (ThisForm) {

	var InterestPaid_Standard = 0;
	var InterestPaid_Discounted = 0;
	var TotalPaid_Standard = 0;
	var TotalPaid_Discounted = 0;
	var CalculateSavings = true;

	Rate_Federal = APR_Federal / 1200;
	APR_Discounted = APR_Federal - RateDiscount;
	Rate_Discounted = APR_Discounted / 1200;

	APR_Discounted1 = APR_Federal - RateReduction1;
	APR_Discounted2 = APR_Federal - RateReduction2;

	Rate_Discounted1 = APR_Discounted1 / 1200;
	Rate_Discounted2 = APR_Discounted2 / 1200;

	Rate_Fixed = APR_Fixed / 1200;

	OK2Calculate = true;

	ThisForm.APR_Standard.value = '';
	ThisForm.APR_Discounted.value = '';
	ThisForm.MonthlyPayment_Standard.value = '';
	ThisForm.MonthlyPayment_Discounted.value = '';
	ThisForm.NumberOfPayments_Standard.value = '';
	ThisForm.NumberOfPayments_Discounted.value = '';
	ThisForm.TotalInterest_Standard.value = '';
	ThisForm.TotalInterest_Discounted.value = '';
	ThisForm.TotalPaid_Standard.value = '';
	ThisForm.TotalPaid_Discounted.value = '';

	ThisForm.APR_Savings.value = '';
	ThisForm.TotalPaid_Savings.value = '';

	AmountBorrowed = GetConsolidationPrincpal(ThisForm);
	APR_Federal = GetWeightedAPR(ThisForm);

	// Make sure they chose a loan
	if ((OK2Calculate) && (ThisForm.LoanType.value == '0')) {
		window.alert ('Please choose a loan');
		OK2Calculate = false;
	}

	// Make sure the laon falls within the acceptable range
	// First make sure it's over the minimum amount
	if ((OK2Calculate) && (AmountBorrowed < MinAmount)) {
		window.alert(MinError);
		OK2Calculate = false;
	} else if ((OK2Calculate) && ((AmountBorrowed > MaxAmount) && MaxAmount != 0)) {
		window.alert(MaxError);
		OK2Calculate = false;
	}

	if (OK2Calculate) {

		// Determine the number of payments
		// These numbers are federally mandated
		if ((AmountBorrowed > 0) && (AmountBorrowed < 7500)) {
			NumberOfPayments = 120;
		} else if ((AmountBorrowed >= 7500) && (AmountBorrowed < 10000)) {
			NumberOfPayments = 144;
		} else if ((AmountBorrowed >= 10000) && (AmountBorrowed < 20000)) {
			NumberOfPayments = 180;
		} else if ((AmountBorrowed >= 20000) && (AmountBorrowed < 40000)) {
			NumberOfPayments = 240;
		} else if ((AmountBorrowed >= 40000) && (AmountBorrowed < 60000)) {
			NumberOfPayments = 300;
		} else if (AmountBorrowed >= 60000) {
			NumberOfPayments = 360;
		} else {
			NumberOfPayments = 0;
		}

		// This is the maximum loan rate, also federally mandated
		if (APR_Federal > APR_Fixed) {
			APR_Federal = APR_Fixed;
		}

		Rate_Federal = APR_Federal / 1200;

		// Do calculations

		//
		if ((AmountBorrowed > 0) && (AmountBorrowed < 10000)) {
			// The process of calculating an ALLsaver loan...
			// 1) Calculate monthly payment using federal interest rate
			// 2) Amortize loan to determine total interest paid
			// 3) Add the principal and interest paid to get total repayment amount
			// 4) Divide total repayment amount by monthly payment to get actual payments

			APR_Discounted = APR_Federal - RateReduction1; // No discount
			Rate_Discounted = APR_Discounted / 1200; 

			// 1) Calculate monthly payment using federal interest rate
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

			// 2) Amortize loan at the federal rate to determine standard total interest paid
			AmortizeLoan(AmountBorrowed, Rate_Federal, NumberOfPayments, MonthlyPayment);
			InterestPaid_Standard = amInterestPaid;
			TotalPaid_Standard = AmountBorrowed + InterestPaid_Standard;

			// 3) Amortize loan to determine total interest paid
			AmortizeLoan(AmountBorrowed, Rate_Discounted, NumberOfPayments, MonthlyPayment);
			InterestPaid_Discounted = amInterestPaid;
			TotalPaid_Discounted = AmountBorrowed + InterestPaid_Discounted;

			// 4) Divide total repayment amount by monthly payment to get actual payments
			NumberOfActualPayments = NumberOfPayments;

			CalculateSavings = true;

		} else if (((AmountBorrowed >= 10000) && (AmountBorrowed <= 99999)) || (AmountBorrowed >= 100000)) {
			// The process of calculating an SELFHELP10 loan...
			// 1) Calculate monthly payment using federal interest rate
			// 2) Amortize loan for 48 months at the initial discounted rate to determine interest paid during that period
			// 3) Amortize loan for 72 months at the second discounted rate to determine interest paid during that period
			// 4) Add the principal and total interest paid to get total repayment amount
			// 5) Divide total repayment amount by monthly payment to get actual payments


			APR_Discounted1 = APR_Federal - RateReduction1;
			APR_Discounted2 = APR_Federal - RateReduction2;
			Rate_Discounted1 = APR_Discounted1 / 1200;
			Rate_Discounted2 = APR_Discounted2 / 1200;

			// This is only for display purposes
			// This variable is not used in the calculations
			APR_Discounted = APR_Discounted2; // ...

			// 1) Calculate monthly payment using federal interest rate
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

			// 2) Amortize loan at the federal rate to determine standard total interest paid
			AmortizeLoan(AmountBorrowed, Rate_Federal, NumberOfPayments, MonthlyPayment);
			InterestPaid_Standard = amInterestPaid;
			TotalPaid_Standard = AmountBorrowed + InterestPaid_Standard;

			// 3) Amortize loan for 36 months at the initial discounted rate to determine interest paid during that period
			AmortizeLoan(AmountBorrowed, Rate_Discounted1, 36, MonthlyPayment);
			InterestPaid_Discounted = amInterestPaid;

			// 4) Amortize loan for remainder at the second discounted rate to determine interest paid during that period
			AmortizeLoan(amRemainingBalance, Rate_Discounted2, NumberOfPayments, MonthlyPayment);
			InterestPaid_Discounted += amInterestPaid;
			TotalPaid_Discounted = AmountBorrowed + InterestPaid_Discounted;

			// 5) Divide total repayment amount by monthly payment to get actual payments
			NumberOfActualPayments = Math.ceil(TotalPaid_Discounted / MonthlyPayment);

		} else if (AmountBorrowed >= 100000) {

			APR_Discounted1 = APR_Federal - RateReduction1;
			APR_Discounted2 = APR_Federal - RateReduction2;
			APR_Discounted3 = APR_Federal - RateReduction3;
			Rate_Discounted1 = APR_Discounted1 / 1200;
			Rate_Discounted2 = APR_Discounted2 / 1200;
			Rate_Discounted3 = APR_Discounted3 / 1200;
			var vPrincipleReduction = 0;

			// This is only for display purposes
			// This variable is not used in the calculations
			// This is the discounted APR used for the ALLsaver product
			APR_Discounted = APR_Discounted3; // ...

			// Determine monthly payment using federal interest rate
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

			// ---------------------------------------------------------------------
			// STANDARD FEDERAL LOAN RATE
			// Amortize loan at the federal rate to determine standard total interest paid
			// ---------------------------------------------------------------------
			AmortizeLoan(AmountBorrowed, Rate_Federal, NumberOfPayments, MonthlyPayment);
			InterestPaid_Standard = amInterestPaid;
			TotalPaid_Standard = AmountBorrowed + InterestPaid_Standard;

			// ---------------------------------------------------------------------
			// ALLsaver REDUCED RATE CALCULATIONS
			// ---------------------------------------------------------------------

			// 1) Determine the principle reduction to be used after 12 months
			vPrincipleReduction = AmountBorrowed * PrincipleReductionRate / 100;

			// 2) Amortize loan for 13 months at the initial discounted rate to determine interest paid during that period
			AmortizeLoan(AmountBorrowed, Rate_Discounted1, 13, MonthlyPayment);
			InterestPaid_Discounted = amInterestPaid;

			// 3) Reduce the remaining balance using the principle reduction calculated above
			amRemainingBalance = amRemainingBalance - vPrincipleReduction;

			// 4) Amortize loan for 23 more months at the initial discounted rate to determine interest paid during that period
			AmortizeLoan(amRemainingBalance, Rate_Discounted1, 23, MonthlyPayment);
			InterestPaid_Discounted += amInterestPaid;
			TotalPaid_Discounted = AmountBorrowed + InterestPaid_Discounted;

			// 5) Amortize loan for remainder at the second discounted rate to determine interest paid during that period
			AmortizeLoan(amRemainingBalance, Rate_Discounted3, NumberOfPayments, MonthlyPayment);
			InterestPaid_Discounted += amInterestPaid;
			TotalPaid_Discounted = AmountBorrowed + InterestPaid_Discounted;

			// 6) Divide total repayment amount by monthly payment to get actual payments
			NumberOfActualPayments = Math.ceil(TotalPaid_Discounted / MonthlyPayment);

		}

		if (CalculateSavings) {

			APR_Savings = APR_Federal - APR_Discounted;
			TotalPaid_Savings = TotalPaid_Standard - TotalPaid_Discounted;
			ThisForm.APR_Savings.value = APR_Savings;
			ThisForm.TotalPaid_Savings.value = DisplayCurrency(FormatCurrency(TotalPaid_Savings));

			ThisForm.APR_Standard.value = APR_Federal;
			ThisForm.MonthlyPayment_Standard.value = DisplayCurrency(FormatCurrency(MonthlyPayment));
			ThisForm.NumberOfPayments_Standard.value = NumberOfPayments;
			ThisForm.TotalInterest_Standard.value = DisplayCurrency(FormatCurrency(InterestPaid_Standard));
			ThisForm.TotalPaid_Standard.value = DisplayCurrency(FormatCurrency(TotalPaid_Standard));

		}
		
		//Set values on the form
		ThisForm.APR_Discounted.value = APR_Discounted;
		ThisForm.MonthlyPayment_Discounted.value = DisplayCurrency(FormatCurrency(MonthlyPayment));
		ThisForm.NumberOfPayments_Discounted.value = NumberOfActualPayments;
		ThisForm.TotalInterest_Discounted.value = DisplayCurrency(FormatCurrency(InterestPaid_Discounted));
		ThisForm.TotalPaid_Discounted.value = DisplayCurrency(FormatCurrency(TotalPaid_Discounted));


	}

}

// -------------------------------------------------------------------------------
// -------------------------------------------------------------------------------
// ALLSaver Consol Calculations - California Product Only!!!  (Not the USA Product)
// -------------------------------------------------------------------------------
// -------------------------------------------------------------------------------

function CalculateConsolidation_CA (ThisForm) {

	var InterestPaid_Standard = 0;
	var InterestPaid_Discounted = 0;
	var TotalPaid_Standard = 0;
	var TotalPaid_Discounted = 0;
	var CalculateSavings = true;

	Rate_Federal = APR_Federal / 1200;
	APR_Discounted = APR_Federal - RateDiscount;
	Rate_Discounted = APR_Discounted / 1200;

	APR_Discounted1 = APR_Federal - RateReduction1;
	APR_Discounted2 = APR_Federal - RateReduction2;

	Rate_Discounted1 = APR_Discounted1 / 1200;
	Rate_Discounted2 = APR_Discounted2 / 1200;

	Rate_Fixed = APR_Fixed / 1200;

	OK2Calculate = true;

	ThisForm.APR_Standard.value = '';
	ThisForm.APR_Discounted.value = '';
	ThisForm.MonthlyPayment_Standard.value = '';
	ThisForm.MonthlyPayment_Discounted.value = '';
	ThisForm.NumberOfPayments_Standard.value = '';
	ThisForm.NumberOfPayments_Discounted.value = '';
	ThisForm.TotalInterest_Standard.value = '';
	ThisForm.TotalInterest_Discounted.value = '';
	ThisForm.TotalPaid_Standard.value = '';
	ThisForm.TotalPaid_Discounted.value = '';

	ThisForm.APR_Savings.value = '';
	ThisForm.TotalPaid_Savings.value = '';

	AmountBorrowed = GetConsolidationPrincpal(ThisForm);
	APR_Federal = GetWeightedAPR(ThisForm);

	// Make sure they chose a loan
	if ((OK2Calculate) && (ThisForm.LoanType.value == '0')) {
		window.alert ('Please choose a loan');
		OK2Calculate = false;
	}

	// Make sure the laon falls within the acceptable range
	// First make sure it's over the minimum amount
	if ((OK2Calculate) && (AmountBorrowed < MinAmount)) {
		window.alert(MinError);
		OK2Calculate = false;
	} else if ((OK2Calculate) && ((AmountBorrowed > MaxAmount) && MaxAmount != 0)) {
		window.alert(MaxError);
		OK2Calculate = false;
	}

	if (OK2Calculate) {

		// Determine the number of payments
		// These numbers are federally mandated
		if ((AmountBorrowed > 0) && (AmountBorrowed < 7500)) {
			NumberOfPayments = 120;
		} else if ((AmountBorrowed >= 7500) && (AmountBorrowed < 10000)) {
			NumberOfPayments = 144;
		} else if ((AmountBorrowed >= 10000) && (AmountBorrowed < 20000)) {
			NumberOfPayments = 180;
		} else if ((AmountBorrowed >= 20000) && (AmountBorrowed < 40000)) {
			NumberOfPayments = 240;
		} else if ((AmountBorrowed >= 40000) && (AmountBorrowed < 60000)) {
			NumberOfPayments = 300;
		} else if (AmountBorrowed >= 60000) {
			NumberOfPayments = 360;
		} else {
			NumberOfPayments = 0;
		}

		// This is the maximum loan rate, also federally mandated
		if (APR_Federal > APR_Fixed) {
			APR_Federal = APR_Fixed;
		}

		Rate_Federal = APR_Federal / 1200;

		// Do calculations

		//
		if ((AmountBorrowed > 0) && (AmountBorrowed < 10000)) {
			// The process of calculating an ALLsaver loan...
			// 1) Calculate monthly payment using federal interest rate
			// 2) Amortize loan to determine total interest paid
			// 3) Add the principal and interest paid to get total repayment amount
			// 4) Divide total repayment amount by monthly payment to get actual payments

			APR_Discounted = APR_Federal - RateReduction1; // No discount
			Rate_Discounted = APR_Discounted / 1200; 

			// 1) Calculate monthly payment using federal interest rate
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

			// 2) Amortize loan at the federal rate to determine standard total interest paid
			AmortizeLoan(AmountBorrowed, Rate_Federal, NumberOfPayments, MonthlyPayment);
			InterestPaid_Standard = amInterestPaid;
			TotalPaid_Standard = AmountBorrowed + InterestPaid_Standard;

			// 3) Amortize loan to determine total interest paid
			AmortizeLoan(AmountBorrowed, Rate_Discounted, NumberOfPayments, MonthlyPayment);
			InterestPaid_Discounted = amInterestPaid;
			TotalPaid_Discounted = AmountBorrowed + InterestPaid_Discounted;

			// 4) Divide total repayment amount by monthly payment to get actual payments
			NumberOfActualPayments = NumberOfPayments;

			CalculateSavings = true;

		} else if ((AmountBorrowed >= 10000) && (AmountBorrowed <= 99999999)) {
			// The process of calculating an SELFHELP10 loan...
			// 1) Calculate monthly payment using federal interest rate
			// 2) Amortize loan for 48 months at the initial discounted rate to determine interest paid during that period
			// 3) Amortize loan for 72 months at the second discounted rate to determine interest paid during that period
			// 4) Add the principal and total interest paid to get total repayment amount
			// 5) Divide total repayment amount by monthly payment to get actual payments


			APR_Discounted1 = APR_Federal - RateReduction1;
			APR_Discounted2 = APR_Federal - RateReduction2;
			Rate_Discounted1 = APR_Discounted1 / 1200;
			Rate_Discounted2 = APR_Discounted2 / 1200;

			// This is only for display purposes
			// This variable is not used in the calculations
			APR_Discounted = APR_Discounted2; // ...

			// 1) Calculate monthly payment using federal interest rate
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

			// 2) Amortize loan at the federal rate to determine standard total interest paid
			AmortizeLoan(AmountBorrowed, Rate_Federal, NumberOfPayments, MonthlyPayment);
			InterestPaid_Standard = amInterestPaid;
			TotalPaid_Standard = AmountBorrowed + InterestPaid_Standard;

			// 3) Amortize loan for 24 months at the initial discounted rate to determine interest paid during that period
			AmortizeLoan(AmountBorrowed, Rate_Discounted1, 24, MonthlyPayment);
			InterestPaid_Discounted = amInterestPaid;

			// 4) Amortize loan for remainder at the second discounted rate to determine interest paid during that period
			AmortizeLoan(amRemainingBalance, Rate_Discounted2, NumberOfPayments, MonthlyPayment);
			InterestPaid_Discounted += amInterestPaid;
			TotalPaid_Discounted = AmountBorrowed + InterestPaid_Discounted;

			// 5) Divide total repayment amount by monthly payment to get actual payments
			NumberOfActualPayments = Math.ceil(TotalPaid_Discounted / MonthlyPayment);

		} else if (AmountBorrowed >= 100000000) {

			APR_Discounted1 = APR_Federal - RateReduction1;
			APR_Discounted2 = APR_Federal - RateReduction2;
			APR_Discounted3 = APR_Federal - RateReduction3;
			Rate_Discounted1 = APR_Discounted1 / 1200;
			Rate_Discounted2 = APR_Discounted2 / 1200;
			Rate_Discounted3 = APR_Discounted3 / 1200;
			var vPrincipleReduction = 0;

			// This is only for display purposes
			// This variable is not used in the calculations
			// This is the discounted APR used for the ALLsaver product
			APR_Discounted = APR_Discounted3; // ...

			// Determine monthly payment using federal interest rate
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

			// ---------------------------------------------------------------------
			// STANDARD FEDERAL LOAN RATE
			// Amortize loan at the federal rate to determine standard total interest paid
			// ---------------------------------------------------------------------
			AmortizeLoan(AmountBorrowed, Rate_Federal, NumberOfPayments, MonthlyPayment);
			InterestPaid_Standard = amInterestPaid;
			TotalPaid_Standard = AmountBorrowed + InterestPaid_Standard;

			// ---------------------------------------------------------------------
			// ALLsaver REDUCED RATE CALCULATIONS
			// ---------------------------------------------------------------------

			// 1) Determine the principle reduction to be used after 12 months
			vPrincipleReduction = AmountBorrowed * PrincipleReductionRate / 100;

			// 2) Amortize loan for 13 months at the initial discounted rate to determine interest paid during that period
			AmortizeLoan(AmountBorrowed, Rate_Discounted1, 13, MonthlyPayment);
			InterestPaid_Discounted = amInterestPaid;

			// 3) Reduce the remaining balance using the principle reduction calculated above
			amRemainingBalance = amRemainingBalance - vPrincipleReduction;

			// 4) Amortize loan for 11 more months at the initial discounted rate to determine interest paid during that period
			AmortizeLoan(amRemainingBalance, Rate_Discounted1, 11, MonthlyPayment);
			InterestPaid_Discounted += amInterestPaid;
			TotalPaid_Discounted = AmountBorrowed + InterestPaid_Discounted;

			// 5) Amortize loan for remainder at the second discounted rate to determine interest paid during that period
			AmortizeLoan(amRemainingBalance, Rate_Discounted3, NumberOfPayments, MonthlyPayment);
			InterestPaid_Discounted += amInterestPaid;
			TotalPaid_Discounted = AmountBorrowed + InterestPaid_Discounted;

			// 6) Divide total repayment amount by monthly payment to get actual payments
			NumberOfActualPayments = Math.ceil(TotalPaid_Discounted / MonthlyPayment);

		}

		if (CalculateSavings) {

			APR_Savings = APR_Federal - APR_Discounted;
			TotalPaid_Savings = TotalPaid_Standard - TotalPaid_Discounted;
			ThisForm.APR_Savings.value = APR_Savings;
			ThisForm.TotalPaid_Savings.value = DisplayCurrency(FormatCurrency(TotalPaid_Savings));

			ThisForm.APR_Standard.value = APR_Federal;
			ThisForm.MonthlyPayment_Standard.value = DisplayCurrency(FormatCurrency(MonthlyPayment));
			ThisForm.NumberOfPayments_Standard.value = NumberOfPayments;
			ThisForm.TotalInterest_Standard.value = DisplayCurrency(FormatCurrency(InterestPaid_Standard));
			ThisForm.TotalPaid_Standard.value = DisplayCurrency(FormatCurrency(TotalPaid_Standard));

		}
		
		//Set values on the form
		ThisForm.APR_Discounted.value = APR_Discounted;
		ThisForm.MonthlyPayment_Discounted.value = DisplayCurrency(FormatCurrency(MonthlyPayment));
		ThisForm.NumberOfPayments_Discounted.value = NumberOfActualPayments;
		ThisForm.TotalInterest_Discounted.value = DisplayCurrency(FormatCurrency(InterestPaid_Discounted));
		ThisForm.TotalPaid_Discounted.value = DisplayCurrency(FormatCurrency(TotalPaid_Discounted));


	}

}





function CalculateGRADsaver (ThisForm) {

	var MonthlyPayment = 0;
	var NumberOfActualPayments = 0;
	var TotalAmountPaid = 0;
	var TotalInterestPaid = 0;
	var TotalPrincipalPaid = 0;
	var Month49Balance = 0;
	
	OK2Calculate = true;

	ThisForm.TotalPrincipalPaid.value = '';
	ThisForm.MonthlyPayment.value = '';
	ThisForm.TotalAmountPaid.value = '';
	ThisForm.TotalInterestPaid.value = '';
	ThisForm.NumberOfActualPayments.value = '';


	// Read variables from the form
	AmountBorrowed = FormatCurrency(ThisForm.AmountBorrowed.value);

	// Make sure they chose a loan
	if (ThisForm.LoanType.value == '0') {
		window.alert ('Please choose a loan');
		OK2Calculate = false;
	}

	// Check to make sure they entered a number as the amount borrowed
	if (isNaN(ThisForm.AmountBorrowed.value)) {
		OK2Calculate = false;
	}

	// Make sure the laon falls within the acceptable range
	// First make sure it's over the minimum amount
	if (AmountBorrowed < MinAmount) {
		window.alert(MinError);
		OK2Calculate = false;
	} else if ((AmountBorrowed > MaxAmount) && MaxAmount != 0) {
		window.alert(MaxError);
		OK2Calculate = false;
	}

	if (OK2Calculate) {

		// Do calculations
		if (LoanType == 'GRADSAVER') {

			// The process of calculating an SELFHELP10 loan...
			// 1) Calculate monthly payment using federal interest rate
			// 2) Amortize loan for 48 months at the initial discounted rate to determine interest paid during that period
			// 3) Amortize loan for 72 months at the second discounted rate to determine interest paid during that period
			// 4) Add the principal and total interest paid to get total repayment amount
			// 5) Divide total repayment amount by monthly payment to get actual payments

			// 1) Calculate monthly payment using federal interest rate
			OrigniationFee = Math.round(AmountBorrowed * OrigniationFeeRate / 100);
			// alert(OrigniationFee);
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

			// 2) Amortize loan for 12 months at the initial discounted rate to determine interest paid during that period
			AmortizeLoan(AmountBorrowed, Rate_Federal, 13, MonthlyPayment);
			Interest1 = amInterestPaid;

			// 3) Amortize loan for 72 months at the second discounted rate to determine interest paid during that period
			var amReducedBalance = 0;
			amReducedBalance = ((amRemainingBalance * 1000) - (OrigniationFee * 1000)) / 1000;
			// alert(amRemainingBalance + ' --- ' + amReducedBalance);
			AmortizeLoan(amReducedBalance, Rate_Federal, NumberOfPayments, MonthlyPayment);
			Interest2 = amInterestPaid;
			TotalInterestPaid = Interest1 + Interest2;

			// 4) Add the principal and total interest paid to get total repayment amount
			TotalAmountPaid = AmountBorrowed + TotalInterestPaid - OrigniationFee;

			// 5) Divide total repayment amount by monthly payment to get actual payments
			NumberOfActualPayments = Math.ceil(TotalAmountPaid / MonthlyPayment);


		} 

		//Set values on the form
		ThisForm.TotalPrincipalPaid.value = DisplayCurrency(AmountBorrowed - OrigniationFee);
		ThisForm.MonthlyPayment.value = DisplayCurrency(FormatCurrency(MonthlyPayment));
		ThisForm.TotalAmountPaid.value = DisplayCurrency(FormatCurrency(TotalAmountPaid));
		ThisForm.TotalInterestPaid.value = DisplayCurrency(FormatCurrency(TotalInterestPaid));
		ThisForm.NumberOfActualPayments.value = Math.ceil(NumberOfActualPayments);

	}

}




function GetConsolidationPrincpal(ThisForm) {

	var TotalBalance = 0;

	for (var n = 1; n <= 10; n++) {

		if ((eval('ThisForm.Balance_' + n + '.value') > 0) && (eval('ThisForm.APR_' + n + '.value') > 0)) {

			TotalBalance += Number(eval('ThisForm.Balance_' + n + '.value'));

		}

		if ((eval('ThisForm.Balance_' + n + '.value') > 0) && !(eval('ThisForm.APR_' + n + '.value') > 0)) {
			OK2Calculate = false;
			window.alert('You entered an invalid interest rate for one or more loans.');
			break;

		}

	}

	return TotalBalance;

}

function GetWeightedAPR(ThisForm) {

	var TotalBalance = 0;
	var WeightedAPR = 0;

	for (var n = 1; n <= 10; n++) {

		if ((eval('ThisForm.Balance_' + n + '.value') > 0) && (eval('ThisForm.APR_' + n + '.value') > 0)) {

			TotalBalance += Number(eval('ThisForm.Balance_' + n + '.value'));
			WeightedAPR += (Number(eval('ThisForm.APR_' + n + '.value')) * Number(eval('ThisForm.Balance_' + n + '.value')))

		}
	}

	WeightedAPR = WeightedAPR / TotalBalance;

	WeightedAPR = RoundConsolidatedAPR(WeightedAPR);

	return (WeightedAPR);

}

function RoundConsolidatedAPR(ThisAPR) {

	var vWholePart = 0;
	var vDecimalPart = 0;

	vWholePart = Math.floor(ThisAPR);
	vDecimalPart = ThisAPR - vWholePart;

	vDecimalPart = Math.round(vDecimalPart * 1000);

	if ((vDecimalPart > 0) && (vDecimalPart <= 125)) {
		vDecimalPart = 0.125;
	} else if ((vDecimalPart > 125) && (vDecimalPart <= 250)) {
		vDecimalPart = 0.25;
	} else if ((vDecimalPart > 250) && (vDecimalPart <= 375)) {
		vDecimalPart = 0.375;
	} else if ((vDecimalPart > 375) && (vDecimalPart <= 500)) {
		vDecimalPart = 0.5;
	} else if ((vDecimalPart > 500) && (vDecimalPart <= 625)) {
		vDecimalPart = 0.625;
	} else if ((vDecimalPart > 625) && (vDecimalPart <= 750)) {
		vDecimalPart = 0.75;
	} else if ((vDecimalPart > 750) && (vDecimalPart <= 875)) {
		vDecimalPart = 0.875;
	} else if ((vDecimalPart > 875) && (vDecimalPart <= 1000)) {
		vDecimalPart = 1;
	} else {
		vDecimalPart = 0;
	}

	ThisAPR = Number(vWholePart) + Number(vDecimalPart);

	return ThisAPR;

}





// This function is no longer used. It was the old rules for the consolidation product
// It has been replaced with a new Consolidation function
function CalculateConsolidation_OLD (ThisForm) {

	var InterestPaid_Standard = 0;
	var InterestPaid_Discounted = 0;
	var TotalPaid_Standard = 0;
	var TotalPaid_Discounted = 0;
	var CalculateSavings = true;

	OK2Calculate = true;

	ThisForm.APR_Standard.value = '';
	ThisForm.APR_Discounted.value = '';
	ThisForm.MonthlyPayment_Standard.value = '';
	ThisForm.MonthlyPayment_Discounted.value = '';
	ThisForm.NumberOfPayments_Standard.value = '';
	ThisForm.NumberOfPayments_Discounted.value = '';
	ThisForm.TotalInterest_Standard.value = '';
	ThisForm.TotalInterest_Discounted.value = '';
	ThisForm.TotalPaid_Standard.value = '';
	ThisForm.TotalPaid_Discounted.value = '';

	ThisForm.APR_Savings.value = '';
	ThisForm.TotalPaid_Savings.value = '';

	AmountBorrowed = GetConsolidationPrincpal(ThisForm);
	APR_Federal = GetWeightedAPR(ThisForm);

	// Make sure they chose a loan
	if ((OK2Calculate) && (ThisForm.LoanType.value == '0')) {
		window.alert ('Please choose a loan');
		OK2Calculate = false;
	}

	// Make sure the laon falls within the acceptable range
	// First make sure it's over the minimum amount
	if ((OK2Calculate) && (AmountBorrowed < MinAmount)) {
		window.alert(MinError);
		OK2Calculate = false;
	} else if ((OK2Calculate) && ((AmountBorrowed > MaxAmount) && MaxAmount != 0)) {
		window.alert(MaxError);
		OK2Calculate = false;
	}

	if (OK2Calculate) {


		// Do calculations
		if (LoanType == 'CONSOLUSA') {

			// Determine the number of payments
			// These numbers are federally mandated
			if ((AmountBorrowed > 0) && (AmountBorrowed < 7500)) {
				NumberOfPayments = 120;
			} else if ((AmountBorrowed >= 7500) && (AmountBorrowed < 10000)) {
				NumberOfPayments = 144;
			} else if ((AmountBorrowed >= 10000) && (AmountBorrowed < 20000)) {
				NumberOfPayments = 180;
			} else if ((AmountBorrowed >= 20000) && (AmountBorrowed < 40000)) {
				NumberOfPayments = 240;
			} else if ((AmountBorrowed >= 40000) && (AmountBorrowed < 60000)) {
				NumberOfPayments = 300;
			} else if (AmountBorrowed >= 60000) {
				NumberOfPayments = 360;
			} else {
				NumberOfPayments = 0;
			}

			// This is the maximum loan rate, also federally mandated
			if (APR_Federal > APR_Fixed) {
				APR_Federal = APR_Fixed;
			}

			Rate_Federal = APR_Federal / 1200;

			//
			if ((AmountBorrowed > 0) && (AmountBorrowed < 25000)) {
				// The process of calculating an ALLsaver loan...
				// 1) Calculate monthly payment using federal interest rate
				// 2) Amortize loan to determine total interest paid
				// 3) Add the principal and interest paid to get total repayment amount
				// 4) Divide total repayment amount by monthly payment to get actual payments

				APR_Discounted = APR_Federal; // No discount
				Rate_Discounted =APR_Discounted / 1200; 

				// 1) Calculate monthly payment using federal interest rate
				MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

				// 2) Amortize loan at the federal rate to determine standard total interest paid
				AmortizeLoan(AmountBorrowed, Rate_Federal, NumberOfPayments, MonthlyPayment);
				InterestPaid_Standard = amInterestPaid;
				TotalPaid_Standard = AmountBorrowed + InterestPaid_Standard;

				// 2) Amortize loan to determine total interest paid
				AmortizeLoan(AmountBorrowed, Rate_Discounted, NumberOfPayments, MonthlyPayment);
				InterestPaid_Discounted = amInterestPaid;
				TotalPaid_Discounted = AmountBorrowed + InterestPaid_Discounted;

				// 4) Divide total repayment amount by monthly payment to get actual payments
				NumberOfActualPayments = NumberOfPayments;

				CalculateSavings = false;

			} else if ((AmountBorrowed >= 25000) && (AmountBorrowed < 50000)) {
				// The process of calculating an SELFHELP10 loan...
				// 1) Calculate monthly payment using federal interest rate
				// 2) Amortize loan for 48 months at the initial discounted rate to determine interest paid during that period
				// 3) Amortize loan for 72 months at the second discounted rate to determine interest paid during that period
				// 4) Add the principal and total interest paid to get total repayment amount
				// 5) Divide total repayment amount by monthly payment to get actual payments

				APR_Discounted1 = APR_Federal - SelfHelpDiscount1;
				APR_Discounted2 = APR_Federal - SelfHelpDiscount2;
				Rate_Discounted1 = APR_Discounted1 / 1200;
				Rate_Discounted2 = APR_Discounted2 / 1200;

				// This is only for display purposes
				// This variable is not used in the calculations
				APR_Discounted = APR_Discounted2; // ...

				// 1) Calculate monthly payment using federal interest rate
				MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

				// 2) Amortize loan at the federal rate to determine standard total interest paid
				AmortizeLoan(AmountBorrowed, Rate_Federal, NumberOfPayments, MonthlyPayment);
				InterestPaid_Standard = amInterestPaid;
				TotalPaid_Standard = AmountBorrowed + InterestPaid_Standard;

				// 2) Amortize loan for 48 months at the initial discounted rate to determine interest paid during that period
				AmortizeLoan(AmountBorrowed, Rate_Discounted1, 36, MonthlyPayment);
				InterestPaid_Discounted = amInterestPaid;

				// 3) Amortize loan for 72 months at the second discounted rate to determine interest paid during that period
				AmortizeLoan(amRemainingBalance, Rate_Discounted2, NumberOfPayments, MonthlyPayment);
				InterestPaid_Discounted += amInterestPaid;
				TotalPaid_Discounted = AmountBorrowed + InterestPaid_Discounted;

				// 5) Divide total repayment amount by monthly payment to get actual payments
				NumberOfActualPayments = Math.ceil(TotalPaid_Discounted / MonthlyPayment);

			} else if (AmountBorrowed >= 50000) {
				// The process of calculating an ALLsaver loan...
				// 1) Calculate monthly payment using federal interest rate
				// 2) Amortize loan to determine total interest paid
				// 3) Add the principal and interest paid to get total repayment amount
				// 4) Divide total repayment amount by monthly payment to get actual payments

				APR_Discounted = APR_Federal - RateDiscount; // No discount
				Rate_Discounted =APR_Discounted / 1200; 

				// 1) Calculate monthly payment using federal interest rate
				MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

				// 2) Amortize loan at the federal rate to determine standard total interest paid
				AmortizeLoan(AmountBorrowed, Rate_Federal, NumberOfPayments, MonthlyPayment);
				InterestPaid_Standard = amInterestPaid;
				TotalPaid_Standard = AmountBorrowed + InterestPaid_Standard;

				// 2) Amortize loan to determine total interest paid
				AmortizeLoan(AmountBorrowed, Rate_Discounted, NumberOfPayments, MonthlyPayment);
				InterestPaid_Discounted = amInterestPaid;
				TotalPaid_Discounted = AmountBorrowed + InterestPaid_Discounted;

				// 4) Divide total repayment amount by monthly payment to get actual payments
				NumberOfActualPayments = Math.ceil(TotalPaid_Discounted / MonthlyPayment);

			}

		} else if (LoanType == 'CONSOL') {

			// Determine the number of payments
			// These numbers are federally mandated
			if ((AmountBorrowed > 0) && (AmountBorrowed < 7500)) {
				NumberOfPayments = 120;
			} else if ((AmountBorrowed >= 7500) && (AmountBorrowed < 10000)) {
				NumberOfPayments = 144;
			} else if ((AmountBorrowed >= 10000) && (AmountBorrowed < 20000)) {
				NumberOfPayments = 180;
			} else if ((AmountBorrowed >= 20000) && (AmountBorrowed < 40000)) {
				NumberOfPayments = 240;
			} else if ((AmountBorrowed >= 40000) && (AmountBorrowed < 60000)) {
				NumberOfPayments = 300;
			} else if (AmountBorrowed >= 60000) {
				NumberOfPayments = 360;
			} else {
				NumberOfPayments = 0;
			}

			// This is the maximum loan rate, also federally mandated
			if (APR_Federal > APR_Fixed) {
				APR_Federal = APR_Fixed;
			}

			Rate_Federal = APR_Federal / 1200;


			// The process of calculating an ALLsaver loan...
			// 1) Calculate monthly payment using federal interest rate
			// 2) Amortize loan to determine total interest paid
			// 3) Add the principal and interest paid to get total repayment amount
			// 4) Divide total repayment amount by monthly payment to get actual payments

			APR_Discounted = APR_Federal - RateDiscount; // No discount
			Rate_Discounted =APR_Discounted / 1200; 

			// 1) Calculate monthly payment using federal interest rate
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

			// 2) Amortize loan at the federal rate to determine standard total interest paid
			AmortizeLoan(AmountBorrowed, Rate_Federal, NumberOfPayments, MonthlyPayment);
			InterestPaid_Standard = amInterestPaid;
			TotalPaid_Standard = AmountBorrowed + InterestPaid_Standard;

			// 2) Amortize loan to determine total interest paid
			AmortizeLoan(AmountBorrowed, Rate_Discounted, NumberOfPayments, MonthlyPayment);
			InterestPaid_Discounted = amInterestPaid;
			TotalPaid_Discounted = AmountBorrowed + InterestPaid_Discounted;

			// 4) Divide total repayment amount by monthly payment to get actual payments
			NumberOfActualPayments = Math.ceil(TotalPaid_Discounted / MonthlyPayment);


		} else {
			// Nothing has to go here, since is should never get here...
//			window.alert ('Amount borrowed is not a number');

			APR_Federal = 0;
			APR_Discounted = 0;
			Rate_Discounted = 0; 

			MonthlyPayment = 0;

			InterestPaid_Standard = 0;
			TotalPaid_Standard = 0;

			InterestPaid_Discounted = 0;
			TotalPaid_Discounted = 0;
			NumberOfActualPayments = 0;

		}

		if (CalculateSavings) {

			APR_Savings = APR_Federal - APR_Discounted;
			TotalPaid_Savings = TotalPaid_Standard - TotalPaid_Discounted;
			ThisForm.APR_Savings.value = APR_Savings;
			ThisForm.TotalPaid_Savings.value = DisplayCurrency(FormatCurrency(TotalPaid_Savings));

			ThisForm.APR_Standard.value = APR_Federal;
			ThisForm.MonthlyPayment_Standard.value = DisplayCurrency(FormatCurrency(MonthlyPayment));
			ThisForm.NumberOfPayments_Standard.value = NumberOfPayments;
			ThisForm.TotalInterest_Standard.value = DisplayCurrency(FormatCurrency(InterestPaid_Standard));
			ThisForm.TotalPaid_Standard.value = DisplayCurrency(FormatCurrency(TotalPaid_Standard));

		}
		
		//Set values on the form
		ThisForm.APR_Discounted.value = APR_Discounted;
		ThisForm.MonthlyPayment_Discounted.value = DisplayCurrency(FormatCurrency(MonthlyPayment));
		ThisForm.NumberOfPayments_Discounted.value = NumberOfActualPayments;
		ThisForm.TotalInterest_Discounted.value = DisplayCurrency(FormatCurrency(InterestPaid_Discounted));
		ThisForm.TotalPaid_Discounted.value = DisplayCurrency(FormatCurrency(TotalPaid_Discounted));


	}

}



function CalculateSavings(ThisForm) {

	var MonthlyPayment = 0;
	var NumberOfActualPayments = 0;
	var TotalAmountPaid = 0;
	var TotalInterestPaid = 0;
	var TotalPrincipalPaid = 0;
	var Month49Balance = 0;
	
	var OK2Calculate = true;


	// Read variables from the form
	AmountBorrowed = FormatCurrency(ThisForm.AmountBorrowed.value);

	// Make sure they chose a loan
	if (ThisForm.LoanType.value == '0') {
		window.alert ('Please choose a loan');
		OK2Calculate = false;
	}

	// Check to make sure they entered a number as the amount borrowed
	if (isNaN(ThisForm.AmountBorrowed.value)) {
		OK2Calculate = false;
	}

	// Make sure the laon falls within the acceptable range
	// First make sure it's over the minimum amount
	if (AmountBorrowed < MinAmount) {
		window.alert(MinError);
		OK2Calculate = false;
	} else if ((AmountBorrowed > MaxAmount) && MaxAmount != 0) {
		window.alert(MaxError);
		OK2Calculate = false;
	}

	if (OK2Calculate) {


		var AmountPaidWithDiscount = 0;
		var AmountPaidWithoutDiscount = 0;

		// Do calculations
		if (LoanType == 'ALLSAVER') {

			// The process of calculating an ALLsaver loan...
			// 1) Calculate monthly payment using federal interest rate
			// 2) Amortize loan to determine total interest paid
			// 3) Add the principal and interest paid to get total repayment amount
			// 4) Divide total repayment amount by monthly payment to get actual payments

			// 1) Calculate monthly payment using federal interest rate
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

			// 2) Amortize the entire ALLsaver loan
			AmortizeLoan(AmountBorrowed, Rate_Discounted, NumberOfPayments, MonthlyPayment);
			AmountPaidWithDiscount = amInterestPaid + AmountBorrowed;

			// 3) Amortize the entire FEDERAL loan
			AmortizeLoan(AmountBorrowed, Rate_Federal, NumberOfPayments, MonthlyPayment);
			AmountPaidWithoutDiscount = amInterestPaid + AmountBorrowed;


		} else if (LoanType == 'SELFHELP10') {

			// The process of calculating an SELFHELP10 loan...
			// 1) Calculate monthly payment using federal interest rate
			// 2) Amortize loan for 48 months at the initial discounted rate to determine interest paid during that period
			// 3) Amortize loan for 72 months at the second discounted rate to determine interest paid during that period
			// 4) Add the principal and total interest paid to get total repayment amount
			// 5) Divide total repayment amount by monthly payment to get actual payments



			// 1) Calculate monthly payment using federal interest rate
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

			// 2) Amortize the entire FEDERAL loan
			AmortizeLoan(AmountBorrowed, Rate_Discounted, NumberOfPayments, MonthlyPayment);
			AmountPaidWithoutDiscount = amInterestPaid + AmountBorrowed;

			// 3) Amortize the entire SelfHelp loan
			AmortizeLoan(AmountBorrowed, Rate_Discounted1, 48, MonthlyPayment);
			Interest1 = amInterestPaid;
			AmortizeLoan(amRemainingBalance, Rate_Discounted2, 72, MonthlyPayment);
			Interest2 = amInterestPaid;
			AmountPaidWithDiscount = AmountBorrowed + Interest1 + Interest2;


		} else if (LoanType == 'SELFHELP25') {

			// The process of calculating an SELFHELP25 loan...
			// 1) Calculate monthly payment using federal interest rate
			// 2) Amortize loan for 48 months at the initial discounted rate to determine interest paid during that period
			// 3) Amortize loan for 72 months at the second discounted rate to determine interest paid during that period
			// 4) Add the principal and total interest paid to get total repayment amount
			// 5) Divide total repayment amount by monthly payment to get actual payments

			// 1) Calculate monthly payment using federal interest rate
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

			// 2) Amortize loan for 48 months at the initial discounted rate to determine interest paid during that period
			AmortizeLoan(AmountBorrowed, Rate_Discounted1, 48, MonthlyPayment);
			Interest1 = amInterestPaid;

			// 3) Amortize loan for 72 months at the second discounted rate to determine interest paid during that period
			AmortizeLoan(amRemainingBalance, Rate_Discounted2, 72, MonthlyPayment);
			Interest2 = amInterestPaid;

			// 4) Amortize loan for 72 months at the second discounted rate to determine interest paid during that period
			AmortizeLoan(amRemainingBalance, Rate_Federal, 180, MonthlyPayment);
			Interest3 = amInterestPaid;
			TotalInterestPaid = Interest1 + Interest2 + Interest3;

			// 5) Add the principal and total interest paid to get total repayment amount
			TotalAmountPaid = AmountBorrowed + TotalInterestPaid;

			// 6) Divide total repayment amount by monthly payment to get actual payments
			NumberOfActualPayments = Math.ceil(TotalAmountPaid / MonthlyPayment);

		} else if (LoanType == 'FIXED') {

			// The process of calculating an ALLsaver loan...
			// 1) Calculate monthly payment using federal interest rate
			// 2) Amortize loan to determine total interest paid
			// 3) Add the principal and interest paid to get total repayment amount
			// 4) Divide total repayment amount by monthly payment to get actual payments

			// 1) Calculate monthly payment using federal interest rate
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Fixed, NumberOfPayments);

			// 2) Amortize loan to determine total interest paid
			AmortizeLoan(AmountBorrowed, Rate_Fixed, NumberOfPayments, MonthlyPayment);
			TotalInterestPaid = amInterestPaid;

			// 3) Add the principal and interest paid to get total repayment amount
			TotalAmountPaid = TotalInterestPaid + AmountBorrowed;

			// 4) Divide total repayment amount by monthly payment to get actual payments
			NumberOfActualPayments = Math.ceil(TotalAmountPaid / MonthlyPayment);

		} else if (LoanType == 'GRADSAVER') {

			// The process of calculating an SELFHELP10 loan...
			// 1) Calculate monthly payment using federal interest rate
			// 2) Amortize loan for 48 months at the initial discounted rate to determine interest paid during that period
			// 3) Amortize loan for 72 months at the second discounted rate to determine interest paid during that period
			// 4) Add the principal and total interest paid to get total repayment amount
			// 5) Divide total repayment amount by monthly payment to get actual payments

			// 1) Calculate monthly payment using federal interest rate
			OrigniationFee = Math.round(AmountBorrowed * OrigniationFeeRate / 100);
			// alert(OrigniationFee);
			MonthlyPayment = GetMonthlyPayment(AmountBorrowed, Rate_Federal, NumberOfPayments);

			// 2) Amortize loan for 12 months at the initial discounted rate to determine interest paid during that period
			AmortizeLoan(AmountBorrowed, Rate_Federal, 13, MonthlyPayment);
			Interest1 = amInterestPaid;

			// 3) Amortize loan for 72 months at the second discounted rate to determine interest paid during that period
			var amReducedBalance = 0;
			amReducedBalance = ((amRemainingBalance * 1000) - (OrigniationFee * 1000)) / 1000;
			// alert(amRemainingBalance + ' --- ' + amReducedBalance);
			AmortizeLoan(amReducedBalance, Rate_Federal, NumberOfPayments, MonthlyPayment);
			Interest2 = amInterestPaid;
			TotalInterestPaid = Interest1 + Interest2;

			// 4) Add the principal and total interest paid to get total repayment amount
			TotalAmountPaid = AmountBorrowed + TotalInterestPaid - OrigniationFee;

			// 5) Divide total repayment amount by monthly payment to get actual payments
			NumberOfActualPayments = Math.ceil(TotalAmountPaid / MonthlyPayment);


		} 

		//Set values on the form
		ThisForm.AmountPaidWithDiscount.value = DisplayCurrency(FormatCurrency(AmountPaidWithDiscount));
		ThisForm.AmountPaidWithoutDiscount.value = DisplayCurrency(FormatCurrency(AmountPaidWithoutDiscount));
		ThisForm.Savings.value = DisplayCurrency(FormatCurrency(AmountPaidWithoutDiscount) - FormatCurrency(AmountPaidWithDiscount));


	}

}
