/* JavaScript Library file for estimator functions. *//* Begin common functions. */// initialize this UA variable.var blnUseTextarea = true;		// default to Truefunction validate_required(field){if (field==null||field=="")  {return false}else {return true}}// Removes Commas and any other characters which are not numbers function RemoveCommas(value){	var temp2 = "";    	var Done = false;    	var Max = value.length-1;    	for (var i=0; i<=Max; i++)      	{          	if ((" 0".indexOf(value.charAt(i))==-1)||Done)             	{                		if("0123456789.-".indexOf(value.charAt(i))!=-1)				{					temp2 = temp2 + value.charAt(i);				}             		Done=true;            	}        	}    	value = temp2;    	return value;}// Check for numeric values only, allow one decimal point (.) and multiple commas (,).function CharAlert(value){	var i = value.indexOf(".");	if (i!=-1) if (value.indexOf(".",i+1)!=-1) return false;	for (i=0; i<=value.length-1; i++)  if("0123456789.,".indexOf(value.charAt(i))==-1) return false;	// It's Good	return true;}// Check for numeric values only, allow one decimal point (.).  Do not allow commas (,).function CommaAlert(value){	var i = value.indexOf(".");	if (i!=-1) if (value.indexOf(".",i+1)!=-1) return false;	for (i=0; i<=value.length-1; i++)  if("0123456789.".indexOf(value.charAt(i))==-1) return false;	// It's Good	return true;}// Verify value is a Real number.  Allow one decimal point (.).  Allow one negative sign (-) only at beginning.  Do not allow commas (,).function RealNumber(value){	var d = value.indexOf(".");	if (d!=-1) if (value.indexOf(".",d+1)!=-1) return false;	// don't allow multiple decimal points	var m = value.indexOf("-");	if (m!=-1) if (value.indexOf("-",1)!=-1) return false;	// don't allow any negative signs that are not at the beginning	for (i=0; i<=value.length-1; i++)  if("0123456789.-".indexOf(value.charAt(i))==-1) return false;		// contains a non-numeric character	// It's Good	return true;}// Converts numbers in to currency number (adds decimal point)function FormatCurrency(amount){      var temp = "" + Math.round(100*amount);      while (temp.length <= 2) temp = "0" + temp;      var DecPlace = temp.length-2;       return temp.substring(0,DecPlace) + "." + temp.substring(DecPlace, temp.length);}// Formats numbers with commas every 3 digits to left of decimal pointfunction AddCommas(amount){      var DecPlace = amount.indexOf(".");      if (DecPlace >= 0) {  // has a decimal      	var LeftOfDecimal = amount.substring(0, (DecPlace));      }      else {      	var LeftOfDecimal = amount;      }      var temp = LeftOfDecimal;      var i = 0;      var array = new Array;      while (temp.length > 3) {      	array[i] = temp.substring(temp.length-3);  // rightmost 3 digits      	temp = temp.substring(0,(temp.length-3));	// all digits to left of last 3 digits      	i++;      }      if (temp.length <= 3) { // leftmost 3 digits      	array[i] = temp;      }      var CommaFormatted = array[i];      while (i > 0) {      	i--;      	CommaFormatted = CommaFormatted + "," + array[i];      }      if (DecPlace >= 0) {  // has a decimal      	CommaFormatted = CommaFormatted + amount.substring(DecPlace,amount.length);	// append decimals      }      return CommaFormatted;}// Display appropriate error message and place cursor in offending field.function HasError(field, form, txtErrorMessage) {	if (blnUseTextarea) {		// attributes for <textarea> method		var iHeight = Math.round(((txtErrorMessage.length)/60) + .5)*16;		document.getElementById('display_error_message').style.height = iHeight + 'px';	}	form.display_error_message.size = txtErrorMessage.length ;		// attribute for <input> method	document.getElementById('display_error_message').style.visibility = 'visible';	form.display_error_message.value = txtErrorMessage;	field.focus();	field.select();}// Clear the error message and hide the message display element.function ResetErrorMessageDisplay(form) {	form.display_error_message.value = "";	document.getElementById('display_error_message').style.visibility = 'hidden';	document.getElementById('display_error_message').style.height = '0px';	// attribute for <textarea> method}/* End common functions. *//* Begin Repay Loan Estimator functions. */// initialize error message variablesvar txtErrorNullLoanAmount = "";var txtErrorInvalidLoanAmount = "";var txtErrorNullInterestRate = "";var txtErrorInvalidInterestRate = "";var txtErrorNullTerm = "";var txtErrorInvalidTerm = "";var txtErrorZeroTerm = "";function ValidateLRE(passForm){	var txtLoan_Amount = "";	var txtInterest_Rate = "";	var txtNumber_of_Months_Years = "";  	txtLoan_Amount = passForm.loan_amount.value;	txtInterest_Rate = passForm.interest_rate.value	txtNumber_of_Months_Years = passForm.number_of_months_years.value  if (!validate_required(txtLoan_Amount)) {		HasError(passForm.loan_amount, document.repay_calc, txtErrorNullLoanAmount);		return false;	}  else if (!CharAlert(txtLoan_Amount)) {		HasError(passForm.loan_amount, document.repay_calc, txtErrorInvalidLoanAmount);		return false;	}  else if (!validate_required(txtInterest_Rate)) {		HasError(passForm.interest_rate, document.repay_calc, txtErrorNullInterestRate);  		return false;    }  else if (!CommaAlert(txtInterest_Rate)) {		HasError(passForm.interest_rate, document.repay_calc, txtErrorInvalidInterestRate);		return false;	}  else if (passForm.number_of_months_years.value=="0") {		HasError(passForm.number_of_months_years, document.repay_calc, txtErrorZeroTerm);  		return false;    }  else if (!validate_required(txtNumber_of_Months_Years)) {		HasError(passForm.number_of_months_years, document.repay_calc, txtErrorNullTerm);  		return false;  	}  else if (!CommaAlert(txtNumber_of_Months_Years)) {		HasError(passForm.number_of_months_years, document.repay_calc, txtErrorInvalidTerm);		return false;  	}  else {	ResetErrorMessageDisplay(document.repay_calc);	for (i=0;i<passForm.month_year_param.length;i++) {		if (passForm.month_year_param[i].checked==true) {			switch (i) {				case 0:					txtNumber_of_Months_Years = passForm.number_of_months_years.value;					break;				case 1:					txtNumber_of_Months_Years = Number(passForm.number_of_months_years.value) * 12;		     		break;				}			break;			}		}  	if (fnLoanRepayment(passForm,txtNumber_of_Months_Years,txtInterest_Rate,txtLoan_Amount)) {  			return true;  		}  	}}function fnLoanRepayment(passForm,txtNumber_of_Months_Years,txtInterest_Rate,txtLoan_Amount){	var Loan_Amount = RemoveCommas(txtLoan_Amount);	var MonthlyPayment = Loan_Amount * fnPayment(txtInterest_Rate,txtNumber_of_Months_Years);	var InterestCost = fnTotalInterest(MonthlyPayment, txtNumber_of_Months_Years, Loan_Amount);	var MinimumSalary = fnMinSal(MonthlyPayment, .10);  // assume 10% of minimum salary	var CumPayment = Number(Loan_Amount) + Number(InterestCost);  	document.repay_calc.monthly_payment.value = "$" + AddCommas(FormatCurrency(MonthlyPayment));	document.repay_calc.interest_cost.value = "$" + AddCommas(FormatCurrency(InterestCost));	document.repay_calc.minimum_salary.value = "$" + AddCommas(FormatCurrency(MinimumSalary));	document.repay_calc.cum_payment.value = "$" + AddCommas(FormatCurrency(CumPayment));return true;}		// Calculates Payments with Interest and divides it in to monthsfunction fnPayment(Rate, Months) {	if (Rate != 0)		{			var a           // Monthly repayment rate  		= Rate / 100. / 12.;			var b = 1. + a;    	b = Math.pow(b, Months) - 1.;			var c = a / b + a;        // Monthly repayment factor		}	else		{			c= 1/Months; // If rate = 0 no interest charged  	}	return c;}// Calculates the total amount of Interestfunction fnTotalInterest(Monthly , NofMonths , OriginalAmount){	var a = Monthly * NofMonths;	var b = a - OriginalAmount;	return b;}// Calculates the minimum salary needed to handle the paymentsfunction fnMinSal(Monthly , Percentage){	var a = Monthly / Percentage;	var b = a * 12;	return b;}/* End Repay Loan Estimator functions. *//* Begin Tuition College Cost Projector functions. */// initialize error message variablesvar txtErrorNullCurrentCost = "";var txtErrorNullInflateRate = "";var txtErrorNullYears_to_Enrollment = "";var txtErrorInvalidCurrentCost = "";var txtErrorInvalidInflateRate = "";var txtErrorInvalidYears_to_Enrollment = "";	function ValidateTCP(passForm, txtCurrent_Cost, txtCost_Inflate_Rate, txtYears_to_Enrollment) {  // Clear error message display before starting.  ResetErrorMessageDisplay(document.cost_projector);  if (!validate_required(txtCurrent_Cost)) {		HasError(passForm.current_cost, document.cost_projector, txtErrorNullCurrentCost);		return false;	}  else if (!CharAlert(txtCurrent_Cost)) {		HasError(passForm.current_cost, document.cost_projector, txtErrorInvalidCurrentCost);		return false;	}  else if (!validate_required(txtCost_Inflate_Rate)) {		HasError(passForm.cost_inflate_rate, document.cost_projector, txtErrorNullInflateRate);  		return false;    }  else if (!CommaAlert(txtCost_Inflate_Rate)) {		HasError(passForm.cost_inflate_rate, document.cost_projector, txtErrorInvalidInflateRate);		return false;	}  else if (!validate_required(txtYears_to_Enrollment)) {		HasError(passForm.years_to_enrollment, document.cost_projector, txtErrorNullYears_to_Enrollment);  		return false;  	}  else if (!RealNumber(txtYears_to_Enrollment)) {		HasError(passForm.years_to_enrollment, document.cost_projector, txtErrorInvalidYears_to_Enrollment);  		return false;  	}  else return true;}function ProjectTuitionCost(passForm) {	var txtCollege_Type = "";	var iYears_in_College = 0;	for (i=0;i<passForm.college_type.length;i++){	    if (passForm.college_type[i].checked==true){		switch (i) {		    case 0:		        txtCollege_Type="4 Year";		        iYears_in_College = 4;		        break;		    case 1:		        txtCollege_Type="2 Year";		        iYears_in_College = 2;		        break;		}		break //exist for loop, as target acquired.	    }	}	var txtCurrent_Cost = passForm.current_cost.value;	var txtCost_Inflate_Rate = passForm.cost_inflate_rate.value;	var txtYears_to_Enrollment = passForm.years_to_enrollment.value;	var blnContinue_Adjustments = new Boolean(true);	for (i=0;i<passForm.continue_adjustments.length;i++){	    if (passForm.continue_adjustments[i].checked==true){		switch (i) {		    case 0:		        blnContinue_Adjustments = true;		        break;		    case 1:		        blnContinue_Adjustments = false;		        break;		}		break //exist for loop, as target acquired.	    }	}		if (!ValidateTCP(passForm, txtCurrent_Cost, txtCost_Inflate_Rate, txtYears_to_Enrollment)) {		return false;	}	//	document.cost_projection.college_type.value = txtCollege_Type;//	document.cost_projection.current_cost.value = "$" + FormatCurrency(RemoveCommas(txtCurrent_Cost));//	document.cost_projection.cost_inflate_rate.value = txtCost_Inflate_Rate + "%";//	document.cost_projection.years_to_enrollment.value = txtYears_to_Enrollment + strTemp;//	document.cost_projection.continue_adjustments.value = blnContinue_Adjustments;		var fltCost_Inflate_Rate = Number(txtCost_Inflate_Rate) * 0.01;	var fltCompoundFactor = fltCost_Inflate_Rate + 1;		var fltProjectedCost = Number(RemoveCommas(txtCurrent_Cost));  // set initial value.	var iYears_to_Enrollment = Number(txtYears_to_Enrollment);	var iYear2 = iYears_to_Enrollment + 1.0;	var iYear3 = iYears_to_Enrollment + 2.0;	var iYear4 = iYears_to_Enrollment + 3.0;	var iYears_to_Graduation = iYears_to_Enrollment + (iYears_in_College - 1);	var i = 1;	// Calculate projected cost for each year.	var fltProjectedCostYear1 = 0;	var fltProjectedCostYear2 = 0;	var fltProjectedCostYear3 = 0;	var fltProjectedCostYear4 = 0;	fltProjectedCostYear1 = fltProjectedCost*Math.pow(fltCompoundFactor,iYears_to_Enrollment);     if (blnContinue_Adjustments) fltProjectedCostYear2 = fltProjectedCost*Math.pow(fltCompoundFactor,iYear2);     else fltProjectedCostYear2 = fltProjectedCostYear1;     if (blnContinue_Adjustments) fltProjectedCostYear3 = fltProjectedCost*Math.pow(fltCompoundFactor,iYear3);     else fltProjectedCostYear3 = fltProjectedCostYear1;     if (blnContinue_Adjustments) fltProjectedCostYear4 = fltProjectedCost*Math.pow(fltCompoundFactor,iYear4);     else fltProjectedCostYear4 = fltProjectedCostYear1;		var fltTotal_Projected_Cost = 0;	if (txtCollege_Type=="2 Year") {		fltTotal_Projected_Cost = fltProjectedCostYear1 + fltProjectedCostYear2;		document.getElementById('thirdyear').style.visibility = 'hidden';		document.getElementById('thirdyear').style.height = '0px';		document.getElementById('fourthyear').style.visibility = 'hidden';		document.getElementById('fourthyear').style.height = '0px';	}	else {		fltTotal_Projected_Cost = fltProjectedCostYear1 + fltProjectedCostYear2 + fltProjectedCostYear3 + fltProjectedCostYear4;		document.getElementById('thirdyear').style.visibility = 'visible';		document.getElementById('thirdyear').style.height = 'auto';		document.getElementById('fourthyear').style.visibility = 'visible';		document.getElementById('fourthyear').style.height = 'auto';	}	document.cost_projection.Projected_Cost_Year_1.value = "$" + AddCommas(FormatCurrency(fltProjectedCostYear1));	document.cost_projection.Projected_Cost_Year_2.value = "$" + AddCommas(FormatCurrency(fltProjectedCostYear2));	document.cost_projection.Projected_Cost_Year_3.value = "$" + AddCommas(FormatCurrency(fltProjectedCostYear3));	document.cost_projection.Projected_Cost_Year_4.value = "$" + AddCommas(FormatCurrency(fltProjectedCostYear4));	document.cost_projection.Total_Projected_Cost.value = "$" + AddCommas(FormatCurrency(fltTotal_Projected_Cost));		return true;}/* End Tuition College Cost Projector functions. */