<!--Last Updated: $Revision: 1.9 $ on $Date: 2006/07/28 16:08:58 $ -->
// why is borrowLess spread evenly across worse 3 loans instead of all to each worst loan in order?

function onerror(msg,url,lineNo)
{
	alert(msg+"\n"+url+"\n"+"Line No "+lineNo);
	return true;
}
var loaded;
var pageLoad = 1;
var LoanCount=0;
var AltLoanCount=0;
var text = "<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=2 width=460><TR><TD VALIGN='top' colspan='2'><font class='medium'>Check if Existing</font></TD><TD VALIGN='top' align=middle><font class='medium'>Loan Type</font></TD><TD VALIGN='top'><font class='medium'>Loan Amount/<br>Balance</font></TD><TD VALIGN='top'><font class='medium'>Interest Rate</font></TD><TD VALIGN='top'><font class='medium'># of Remaining Payments (months)</font></TD><TD VALIGN='top'><font class='medium'>First Disbursement Date mm/yyyy</font></TD></TR><TR><TD></TD><TD></TD><TD></TD><TD>Payments In School</TD><TD>Interest In School</TD><TD>Loan Fee</TD><TD>Repay Fee</TD></TR>";
var prevPage="";
var Calc=null;
var winHelp=null;
var range="";
var styleObj="";
var isNav4=false,isNav5=false, isIE4=false;

if (navigator.appName=="Netscape")
{
	if (navigator.appVersion < "5")
	{
		isNav4 = true;
	}
	if (navigator.appVersion > "4")
	{
		isNav5 = true;
	}
}
else
{
	isIE4=true;
	range="all.";
	styleObj=".style";
}


dual13 = new Array();	//holds the number of 13th payments for money savings
dualExtra = new Array(); //holds the number of extra payment amounts for money savings

var CombinedLoans = false; //All loans at one institution?
var extraPay = new Array();//will hold second payment if additional amount chosen
var gradDate="";
var ColBooks;
var ColSupplies;
var ColComputer;
var ColMiscSupplies;
var places=2;
var win;
var GlobalNewNumb=0;
var GlobalNewInt=0;
var GlobalNewAmnt=0;
var GlobalOldAmnt=0;
var GlobalExtraPay=0;
var extraBox1;
var extraPay1;
var extraMonths1;
var extraBox2;
var extraPay2;
var extraMonths2;
var extraBox3;
var extraPay3;
var extraMonths3;
var goodPay;
var box13;
var pay13;
var GlobalPaid13=0;
var GlobalNewAccrual;
var GlobalNewIntSub;
var GlobalNewAccrue;
var GlobalNewPrinc;
var GlobalPayDown;
var GlobalPaid;
var addPay;
var addBox;
var addMonths;
var CarFood;
var CarCleaning;
var CarPersonal;
var CarFoodMisc;
var ColFood;
var ColCleaning;
var ColPersonal;
var ColFoodMisc;
var sumColBud;
var sumColWork;
var sumCarBud;
var sumCarWork;
var sumCarLoanSum;
var sumCarExpCut;
var sumCashMan;
var sumCarAll;
var doneSaveMoney;
var GlobalMonthlySalary=0;
var GlobalPayPercent=0;
var GlobalExtraMonths=0;
// User
var worst1text="";//worst loans
var worst2text="";
var worst3text="";
var worst1atext="";//worst loans
var worst2atext="";
var worst3atext="";
var worst1btext="";//worst loans
var worst2btext="";
var worst3btext="";
worst = new Array(2);
var aBox;//borrow less ck
var bLess;//borrow less amnt
var GlobalTotalPrincipal;
var GlobalTotalInterest;
var GlobalFirstYearPay;
var TotalAnnualIncome = 0;
var TotalAnnualExpense = 0;
var FirstName="";
// College Finances;
var ColTotalAnnualIncome = 0;
var ColTotalFinancialAid = 0;
var ColTotalAnnualExpenses = 0;
// College StudentLoansWorksheets;
var ColLoan1;
var ColLoan2;
var ColLoan3;
// Career StudentLoansWorksheets;
var CarLoan1;
var CarLoan2;
var CarLoan3;
// College Annual Income;
var ColJobEarnings;
var ColMoneyFromParents;//added
var ColMoneyFromSavings;//added
var ColSpouseEarnings;
var ColOtherIncome;//other aid
// College Other Income;
var ColTANF;//detail
var ColSSI;//detail
var ColOtherMisc;//detail
var ColMiscOtherIncome;//total of detail
// College Financial Aid;
var ColWorkStudyIncome;
var ColScholarships;
var ColGrants;
var ColLoans;
// College Annual Expenses;
var ColTuition;
var ColBooksSupplies;
var ColRentMortgage;
var ColUtilities;
var ColGroceries;
var ColRestaurantsEntertainment;
var ColTransportationCosts;
var ColClothingCosts;
var ColSavings;

var ColStudentLoanPayment;
var ColCredit;
var ColAdditionalExpenses;
// College Rent/Mortgage;
var ColRentMortgagePayment;
var ColTaxes;
var ColrmInsurance;
var ColMiscRentMortgage;
// College Utilities;
var ColGroceries;
var ColCellTelephone;
var ColInternet;
var ColGasElectricity;
var ColWater;
var ColTrashPickup;
var ColCableTVSatellite;
var ColTelephone;
var ColMiscUtilities;
// College Transportation Costs;
var ColVehicleCosts;
var ColOtherTransportationCosts;
// College Vehicle Costs;
var ColVehiclePayment;
var ColVehicleRegistration;
var ColGas;
var ColMaintenance;
var ColInsurance;
var ColParking;
var ColMiscVehicleCosts;
// College Other Transportation Costs;
var ColPublicTransportation;
var ColVacation;
var ColGifts;
var CarGifts;
//	var ColBikeService;
//	var ColBikeRegistration;
//	var ColAirFareHome;
var ColMiscOtherTransportationCosts;
// College Clothing Costs;
var ColClothing;
var ColShoes;
var ColLaundryDryCleaning;
var ColDryCleaning;
var ColTailoringRepairs;
var ColMiscClothingCosts;
// College Savings
var ColRetSavings;
var ColRetSavInvestments;
var ColRetSavMisc;


//Career Post-College Budget
var CarRetSavings;
var CarRetSavInvestments;
var CarRetSavIRA;
var CarRetSavMisc;


// College Additional Expenses;
var ColEntertainment;
var ColCreditCardPayment;
var ColMedicalDental;
var ColChildCare;
var ColSavings;
var ColVeterinarian;
var ColMiscAdditionalExpenses;
var ColLoanPay;
var CarVacation;
// Loans;
var Type = new Array();
var Balance = new Array();
var InterestRate = new Array();
var Payments = new Array();
var DisbursementDate = new Array();
// Career Finances;
var CarTotalAnnualIncome = 0;
var CarTotalFinancialAid = 0;
var CarTotalAnnualExpenses = 0;
// Career Annual Income;
var CarJobEarnings;
var CarSpouseEarnings;
var CarOtherIncome;
// Career Other Income;
var CarTANF;
var CarSSI;
var CarMiscOtherIncome;
// Career Annual Expenses;
var CarTuition;
var CarBooksSupplies;
var CarRentMortgage;
var CarUtilities;
var CarGroceries;
var CarRestaurantsEntertainment;
var CarTransportationCosts;
var CarClothingCosts;
var CarStudentLoanPayment;
var CarRetirement;
var CarRetSavings;
var CarAdditionalExpenses;
// Career Rent/Mortgage;
var CarRentMortgagePayment;
var CarTaxes;
var CarrmInsurance;
var CarMiscRentMortgage;
// Career Utilities;
var CarCellTelephone;
var CarInternet;
var CarGasElectricity;
var CarWater;
var CarTrashPickup;
var CarCableTVSatellite;
var CarTelephone;
var CarMiscUtilities;
// Career Transportation Costs;
var CarVehicleCosts;
var CarOtherTransportationCosts;
// Career Vehicle Costs;
var CarVehiclePayment;
var CarVehicleRegistration;
var CarGas;
var CarMaintenance;
var CarInsurance;
var CarParking;
var CarMiscVehicleCosts;
// Career Other Transportation Costs;
var CarPublicTransportation;
var CarBikeService;
var CarBikeRegistration;
var CarAirFareHome;
var CarMiscOtherTransportationCosts;
// Career Clothing Costs;
var CarClothing;
var CarShoes;
var CarLaundryDryCleaning;
var CarDryCleaning;
var CarTailoringRepairs;
var CarMiscClothingCosts;
// Career Additional Expenses;
var CarEntertainment;
var CarCreditCardPayment;
var CarCredit;
var CarMedicalDental;
var CarChildCare;
var CarSavings=0;
var CarVeterinarian=0;
var CarMiscAdditionalExpenses;
var dontUpdate=false;
var dont=false;//dont reference an obj on blur
var OutOfSchool;
var colIncomeBy;
var carIncomeBy;
var incomeByIndex;
var colExpenseBy;
var carExpenseBy;
var aidBy;
var expenseByIndex;
var aidByIndex;
var ColCreditCard1;
var ColCreditCard2;
var ColCreditCard3;
var ColPerLoan1;
var ColPerLoan2;
var ColPerLoan3;
var CarCreditCard1;
var CarCreditCard2;
var CarCreditCard3;
var CarPerLoan1;
var CarPerLoan2;
var CarPerLoan3;
var salary1=0;
var salary2=0;
var incFactor,expFactor,aidFactor;
var today = new Date();


//total loans for summary page
var totalInterest=0;
var totalPrincipal=0;
var TotalPrincipal=0;
var TotalInterest=0;
var firstYearPay=0;
var dis=0;
var maxMonths=10000;
var menuLocation = 1;
antLoans = new Array();//summary page
existLoans = new Array();//summary page
Ant1Loans = new Array();
Exist1Loans = new Array();
var studentLoanFlag;
//-------------

function storeSalary(s1,s2)
{
	salary1=CarJobEarnings=dollarToNumb(s1);
	salary2=CarSpouseEarnings=dollarToNumb(s2);
}//End function storeSalary(

//-------------------------------------
function getGradDate()
{
	today = new Date();
	var tYear=parseInt(today.getFullYear());
	if (today.getMonth()>7)//august
		var gradYear=tYear+1;
	else
		var	gradYear=tYear;
	return "06/"+gradYear.toString();

}//End function getGradDate()

//-------------------------------------
function antLoan(existing,lType,bal,iRate,nPay,iPaid,mPay,accruAmount,onInt,onPrinc,disburseDate,worstNo,payLess,newBal,newMpay,newNpay,newAccrue,accrueMonths,goodPayPercent,newInt,loanFee,repayFee,repayPrinc,schoolRate,schoolPay,accrueBal)
{
	this.accrueBal=accrueBal;
	this.existing=existing;
	this.lTypeIndex= lType;
	this.bal= bal;
	this.iRate= iRate;
	this.nPay=nPay;//number of payments
	this.payments=nPay;
	this.iPaid=iPaid;//total interest Paid
	this.mPay=mPay;//monthly payment
	this.accruAmount=accruAmount;
	this.onPrinc=onPrinc;//monthly payment on principal
	this.onInt=onInt;//monthly payment on Interest, modified to total interest not including Accrual
	this.disburseDate=disburseDate;
	this.worstNo=worstNo;
	this.payLess=payLess;//amount less to borrow
	this.newBal=newBal;
	this.newMpay=newMpay;
	this.newNpay=newNpay;
	this.newAccrue=newAccrue;
	this.accrueMonths=accrueMonths;
	this.goodPayPercent=goodPayPercent;//percent for goodpayer starts at standard rate, then changes
	this.newInt=newInt;//interest after loan savings
 	//The following fields are for alternative loans
	this.loanFee=loanFee;
	this.repayFee=repayFee;
	this.repayPrinc=repayPrinc;
	this.schoolRate=schoolRate;
	this.schoolPay=schoolPay;
	
}//End function antLoan()

/*loanType = new Array(7);
loanType[0]="Sub Stafford";
loanType[1]="Unsub Stafford";
loanType[2]="Perkins";
loanType[3]="PCL/HPSL";
loanType[4]="Alt loan";
loanType[5]="Campus";
loanType[6]="Other";
*/
loanType = new Array(8);
loanType[0]="Sub Stafford";
loanType[1]="Unsub Stafford";
loanType[2]="Perkins";
loanType[3]="Graduate PLUS";
loanType[4]="PCL/HPSL";
loanType[5]="Alt loan";
loanType[6]="Campus";
loanType[7]="Other";
//-------------------------------------
function studentSaveLoan()
{
//transfer data from summary page to entry page arrays
	for (var i=0;i<LoanCount;i++)
	{
		Ant1Loans[i].lTypeIndex=antLoans[i].lTypeIndex;
		Ant1Loans[i].bal=antLoans[i].bal;
		Ant1Loans[i].iRate=antLoans[i].iRate;
		Ant1Loans[i].nPay=antLoans[i].nPay;
		Ant1Loans[i].payments=antLoans[i].nPay;
		Ant1Loans[i].iPaid=antLoans[i].iPaid;
		Ant1Loans[i].mPay=antLoans[i].mPay;
		Ant1Loans[i].accruAmount=antLoans[i].accruAmount;
		Ant1Loans[i].onPrinc=antLoans[i].onPrinc;
		Ant1Loans[i].onInt=antLoans[i].onInt;
	}
	return;
	loadPage('studentLoan1.html',3);
}//End function studentSaveLoan()

function loanSummary()
{
	document.places=0;
	parent.mainPage.document.lSum.monthlyIncome.value=numbToDollar(dollarToNumb(document.TotalAnnualIncome)/12);
	parent.mainPage.document.lSum.monthlyExpense.value=numbToDollar(dollarToNumb(document.TotalAnnualExpense)/12);
	parent.mainPage.document.lSum.monthlyDifference.value=numbToDollar(dollarToNumb(document.TotalAnnualIncome)/12-dollarToNumb(document.TotalAnnualExpense)/12);
	loanSummaryCalc();
}//End function loanSummary()

//-------------------------------------
var More=null;

//-------------------------------------
function worstArray(rating,index)
{
	this.rating=rating;
	this.index=index;
}//End function worstArray()

function loanSummaryCalc()//loanPage true if called from student loan page
{
        //calculate all loans for summary page (now student loan page)
        var evalLoanTypes = new Array(8);

/*		evalLoanTypes[0]="SubStafford";
		evalLoanTypes[1]="UnsubStafford";
		evalLoanTypes[2]="Perkins";
		evalLoanTypes[3]="PCL_HPSL";
		evalLoanTypes[4]="AltLoan";
		evalLoanTypes[5]="Campus";
		evalLoanTypes[6]="Other";
*/
		loanType = new Array(8);
		loanType[0]="Sub Stafford";
		loanType[1]="Unsub Stafford";
		loanType[2]="Perkins";
		loanType[3]="Graduate PLUS";
		loanType[4]="PCL/HPSL";
		loanType[5]="Alt loan";
		loanType[6]="Campus";
		loanType[7]="Other";
		for(var i=0;i<evalLoanTypes.length;i++)
		{
			eval("var num"+evalLoanTypes[i]+"=0;")
			eval("var int"+evalLoanTypes[i]+"=0;")
			eval("var total"+evalLoanTypes[i]+"=0;")
			eval("var pmnt"+evalLoanTypes[i]+"=0;")
			eval("var extra_"+evalLoanTypes[i]+"=0;")
		}
        for (var i=0;i<LoanCount;i++)
        {
                antLoans[i].disburseDate= Ant1Loans[i].disburseDate;
                antLoans[i].existing= Ant1Loans[i].existing;
                antLoans[i].lTypeIndex= Ant1Loans[i].lTypeIndex;
                var evalTypeIndexer = antLoans[i].lTypeIndex;
                eval("num"+evalLoanTypes[evalTypeIndexer]+"++");
                eval("total"+evalLoanTypes[evalTypeIndexer]+"+=Ant1Loans[i].bal");
                eval("if(int"+evalLoanTypes[evalTypeIndexer]+"<Ant1Loans[i].iRate) int"+evalLoanTypes[evalTypeIndexer]+"=Ant1Loans[i].iRate;");
                antLoans[i].bal= antLoans[i].newBal=Ant1Loans[i].bal;
                antLoans[i].iRate= antLoans[i].goodPayerPercent=Ant1Loans[i].iRate;
                antLoans[i].nPay=antLoans[i].newNpay=Ant1Loans[i].nPay;
				antLoans[i].iPaid= Ant1Loans[i].iPaid;
                antLoans[i].mPay= antLoans[i].newMpay=Ant1Loans[i].mPay;
                antLoans[i].accruAmount=Ant1Loans[i].accruAmount;
				antLoans[i].loanFee=Ant1Loans[i].loanFee;
				antLoans[i].schoolPay=Ant1Loans[i].schoolPay;
				antLoans[i].schoolRate=Ant1Loans[i].schoolRate;
				antLoans[i].repayPrinc=Ant1Loans[i].repayPrinc;
        }
        // do anticipated loans
        var runLoans=false;
        for (var i=0;i<LoanCount;i++)
        {
            if (antLoans[i].bal!=0)
                runLoans=true;
        }
        if (!runLoans)
        {
            return;//don't run. no loans
        }
        if (CombinedLoans==true)
        {
			for(var i=0;i<evalLoanTypes.length;i++)
			{
				eval("pmnt" + evalLoanTypes[i]+"=getMonthlyPayment(total"+evalLoanTypes[i]+",int"+evalLoanTypes[i]+",120)");
				eval("if(50-pmnt"+evalLoanTypes[i]+">0) extra_"+evalLoanTypes[i]+"=50-pmnt"+evalLoanTypes[i]);
			}

        }
        var payment;
        var newP=0;

		totalInterest  = 0;
		totalPrincipal = 0;
		TotalInterest  = 0;
		TotalPrincipal = 0;
		firstYearPay   = 0;
        var loans=0;
        worst = new Array(2);

        for (var i=0;i<LoanCount;i++)
        {
                document.places=0;
                var tIndex=antLoans[i].lTypeIndex;
				var b;
				if(tIndex!=5)
					b=dollarToNumb(antLoans[i].bal);
				else
					b=dollarToNumb(antLoans[i].repayPrinc);
                var r=dollarToNumb(antLoans[i].iRate);
                switch (tIndex)
                {
                        case 0://subsidized
                        case 1://unsubsidized
                                {
                                        var n=dollarToNumb(antLoans[i].nPay);
                                        var portion=eval("b/total"+evalLoanTypes[tIndex]);
                                        //if(n > 120)
                                        //      n=antLoans[i].nPay=120;
                                        if (n < 1)
                                                n=antLoans[i].nPay=1;
                                        if (CombinedLoans==true && (tIndex==0 || tIndex==3))
                                        {
                                                r=dollarToNumb(eval("int"+evalLoanTypes[tIndex]));
                                                antLoans[i].iRate=eval("int"+evalLoanTypes[tIndex]);
                                        }
                                        payment=doLoan(tIndex,i,b,r,n);
                                        if (payment==0) break;
										if (CombinedLoans==false || eval("num"+evalLoanTypes[tIndex]+"<=1"))
                                        {
											while (payment <50 || payment >100000)
											{
												n--;
												payment=doLoan(tIndex,i,b,r,n);
												if (n <=1)break;
											}
                                        }
										else
										{
											payment+=portion*eval("extra_"+evalLoanTypes[tIndex]);
										}
										antLoans[i].mPay=payment;
										antLoans[i].nPay=Math.ceil((antLoans[i].bal+antLoans[i].accrueBal)/payment);
                                        break;
                                }
						case 3://grad plus
								{
									var n=dollarToNumb(antLoans[i].nPay);
									var portion=eval("b/total"+evalLoanTypes[tIndex]);
									//if(n > 120)
									//      n=antLoans[i].nPay=120;
									if (n < 1)
											n=antLoans[i].nPay=1;
									if (CombinedLoans==true && (tIndex==0 || tIndex==3))
									{
											r=dollarToNumb(eval("int"+evalLoanTypes[tIndex]));
											antLoans[i].iRate=eval("int"+evalLoanTypes[tIndex]);
									}
									payment=doLoan(tIndex,i,b,r,n);
									if (payment==0) break;
									if (CombinedLoans==false || eval("num"+evalLoanTypes[tIndex]+"<=1"))
									{
										while (payment <40 || payment >100000)
										{
											n--;
											payment=doLoan(tIndex,i,b,r,n);
											if (n <=1)break;
										}
									}
									else
									{
										payment+=portion*eval("extra_"+evalLoanTypes[tIndex]);
									}
									antLoans[i].mPay=payment;
									antLoans[i].nPay=Math.ceil((antLoans[i].bal+antLoans[i].accrueBal)/payment);
									break;
								}
                        case 2://perkins
						case 4:
								{
									var n=dollarToNumb(antLoans[i].nPay);
									var portion=eval("b/total"+evalLoanTypes[tIndex]);
									//if(n > 120)
									//      n=antLoans[i].nPay=120;
									if (n < 1)
											n=antLoans[i].nPay=1;
									if (CombinedLoans==true && (tIndex==0 || tIndex==3))
									{
											r=dollarToNumb(eval("int"+evalLoanTypes[tIndex]));
											antLoans[i].iRate=eval("int"+evalLoanTypes[tIndex]);
									}
									payment=doLoan(tIndex,i,b,r,n);
									if (payment==0) break;
									if (CombinedLoans==false || eval("num"+evalLoanTypes[tIndex]+"<=1"))
									{
										while (payment <40 || payment >100000)
										{
											n--;
											payment=doLoan(tIndex,i,b,r,n);
											if (n <=1)break;
										}
									}
									else
									{
										payment+=portion*eval("extra_"+evalLoanTypes[tIndex]);
									}
									antLoans[i].mPay=payment;
									antLoans[i].nPay=Math.ceil((antLoans[i].bal+antLoans[i].accrueBal)/payment);
									break;
								}
                        case 5:
                        case 6:
                                {
                                        var n=dollarToNumb(antLoans[i].nPay);
                                        //if(n > 120)
                                        //      n=antLoans[i].nPay=120;
                                        if (n < 1)
                                                n=antLoans[i].nPay=1;
                                        payment=doLoan(tIndex,i,b,r,n);
                                        break;
                                }
						case 7:
                                {
                                        var n=dollarToNumb(antLoans[i].nPay);
                                        //if(n > 120)
                                        //      n=antLoans[i].nPay=120;
                                        if (n < 1)
                                                n=antLoans[i].nPay=1;
                                        payment=doLoan(tIndex,i,b,r,n);
                                        break;
                                }		

                        default:
                                alert("No such loan type:  "+tIndex);
                }
                document.places=2;
                Ant1Loans[i].mPay=payment;//for saving old payment
				antLoans[i].worstNo=0;
				if(tIndex!=5)
				{	
					totalPrincipal+=dollarToNumb(antLoans[i].bal);
				}
				else
				{
					totalPrincipal+=dollarToNumb(antLoans[i].repayPrinc);
				}
				totalInterest+=dollarToNumb(antLoans[i].iPaid);
				totalPrincipal+=dollarToNumb(antLoans[i].accruAmount);
				TotalInterest+=dollarToNumb(antLoans[i].onInt);
				TotalPrincipal+=dollarToNumb(antLoans[i].onPrinc);
				firstYearPay+=dollarToNumb(antLoans[i].mPay);

				if (antLoans[i].existing && antLoans[i].nPay+nowMonths < gradMonths)
					firstYearPay-=antLoans[i].mPay;//will be paid before grad date

                if (antLoans[i].bal >0)
                {
                        loans++;
                        if (antLoans[i].lTypeIndex==1 || antLoans[i].lTypeIndex==5 || antLoans[i].lTypeIndex==6)
                        {
							worst[i]= new worstArray(antLoans[i].iRate*antLoans[i].iRate+antLoans[i].bal/10000,i);
                        }
                        else
						{
                            worst[i]= new worstArray(antLoans[i].iRate*antLoans[i].bal/100000,i);
						}
                }
                else
				{
					worst[i]= new worstArray(0,i);
				}

        }
		GlobalTotalInterest=totalInterest;
		GlobalTotalPrincipal=totalPrincipal;
		GlobalFirstYearPay=firstYearPay;

        for (var i=0;i<LoanCount;i++)//find first disb date
        {
			if (Ant1Loans[i].disburseDate.charAt(2)!="/")
				break;
			dis=getNumMonths(Ant1Loans[i].disburseDate);
			if (dis==0)
				break;
			if (dis < maxMonths && !antLoans[i].existing)
			{
					maxMonths=dis;
			}
        }

        var gradMonths=getNumMonths(gradDate);// uses mm/yyyy, since 01/01/1970
        var nowMonths=today.getTime()/(1000*60*60*24*(365/12));

        var highest=0;
        var j,k,tempr,temp1;
        
		//sort for highest
		for (i=0;i<LoanCount;i++)
		{
			highest=0;
			k=i;
			for (j=i;j<LoanCount;j++)
			{
				if (worst[j].rating > highest)
				{
					k=j;
					highest=worst[j].rating;
				}
			}
			tempr=worst[i].rating;
			tempi=worst[i].index;
			worst[i].rating=worst[k].rating;
			worst[i].index=worst[k].index;
			worst[k].rating=tempr;
			worst[k].index=tempi;
		}
        antLoans[worst[0].index].worstNo=1;
        worst1text=loanType[antLoans[worst[0].index].lTypeIndex];
        worst1atext=""+antLoans[worst[0].index].bal;
        worst1btext=""+(antLoans[worst[0].index].disburseDate);
        if (loans >1)
        {
                antLoans[worst[1].index].worstNo=2;
                worst2text=loanType[antLoans[worst[1].index].lTypeIndex];
                worst2atext=""+antLoans[worst[1].index].bal;
                worst2btext=""+(antLoans[worst[1].index].disburseDate);
        }
        else
        {
                worst2text="";
                worst2atext="";
                worst2btext="";
        }
        if (loans>2)
        {
                antLoans[worst[2].index].worstNo=3;
                worst3text=loanType[antLoans[worst[2].index].lTypeIndex];
                worst3atext=""+antLoans[worst[2].index].bal;
                worst3btext=""+(antLoans[worst[2].index].disburseDate);
        }
        else
        {
                worst3text="";
                worst3atext="";
                worst3btext="";
        }
}//End function loanSummaryCalc()

function zeroMoneyChanges()
{
	for (var i=0;i<LoanCount;i++)
	{
		antLoans[i].payLess=0;
		antLoans[i].newBal=newBal=antLoans[i].bal;
		antLoans[i].newMpay=newMpay=0;
		antLoans[i].newNpay=newNpay=0;
		antLoans[i].newAccrue=antLoans[i].accruAmount;
		antLoans[i].accrueMonths=0;
		antLoans[i].goodPayPercent=antLoans[i].iRate;
		antLoans[i].newInt=0;
	}
	//default values for money savings
	extraBox1=false;
	extraPay1=10;
	extraMonths1=48;
	extraBox2=false;
	extraPay2=10;
	extraMonths2=48;
	extraBox3=false;
	extraPay3=10;
	extraMonths3=48;
	GlobalExtraPay=0;
	goodPay=false;
	box13=false;
	pay13=10;
	addPay=10;
	addBox=false;
	addMonths=120;
	aBox=false;
	bLess=0;
}//End function zeroMoneyChanges()

function saveMoneyFunc(wl)//wl is count of worst loans
{
	//alert(antLoans[worst[0].index].newBal+" "+antLoans[worst[0].index].goodPayerPercent+" "+antLoans[worst[0].index].accruAmount);
	var t=0;
	var bl=bLess;
	GlobalPayDown=0;
	for (var i=0;i<LoanCount;i++)
	{
		antLoans[i].bal= antLoans[i].newBal=Ant1Loans[i].bal;
		antLoans[i].iRate= antLoans[i].goodPayerPercent=Ant1Loans[i].iRate;
		antLoans[i].nPay= antLoans[i].newNpay=Ant1Loans[i].nPay;
		antLoans[i].iPaid= Ant1Loans[i].iPaid;
		antLoans[i].mPay= antLoans[i].newMpay=Ant1Loans[i].mPay;
		antLoans[i].accruAmount=Ant1Loans[i].accruAmount;
		if(i<3)
		{
			antLoans[worst[i].index].newAccrue=0;
		}
	}
	if (aBox) borrowLess(bl,wl);
	
	var accPeriod=0;
	//Figure Accrual months
	for (var i=0;i<wl;i++)
	{
		switch (antLoans[worst[i].index].lTypeIndex)
		{
			case 0:	//sub staff
				accPeriod=getAccrualMonths(worst[i].index)+6;
				break;
			case 1:	//unsub staff
				accPeriod=getAccrualMonths(worst[i].index)+6;
				break;
			case 2:	//perk
				accPeriod=getAccrualMonths(worst[i].index)+9;
				break;
			case 3:	// grad plus
				accPeriod=getAccrualMonths(worst[i].index)+6;
				break;
			case 4:	//plc
				accPeriod=getAccrualMonths(worst[i].index)+12;
				break;
			case 5:	//alt
				accPeriod=getAccrualMonths(worst[i].index);
				break;
			case 6:	//camp
				accPeriod=getAccrualMonths(worst[i].index)+6;
				break;
			case 7: //Other
				accPeriod=getAccrualMonths(worst[i].index)+6;
				break;
				default:
				break;
		}
		if (accPeriod <0)
		{
			accPeriod=0;
			switch (i+1)
			{
				case 1:
					extraMonths1=0;
					break;
				case 2:
					extraMonths2=0;
					break;
				case 3:
					extraMonths3=0;
					break;
				default:
					break;
			}
		}
		antLoans[worst[i].index].accrueMonths=accPeriod; 
	}

	//figure pay as you go
	//alert(accPeriod);
	doPayDown();

	// figure all loans
	var bal;
	var inter;
	var grad_disb_diff;
	var k;
	var m;
	var yrs;
	var mPay;
	var paid;
	var GoodPayer=true;
	var yrsStart=-1;
	var pay13temp=0;
	var oldMonths=-1;

	//alert("1 - "+oldMonths);

	GlobalPaid=0;
	var order = new Array(LoanCount);
	for (k=0;k<LoanCount;k++)
	{
		order[k]=k;
	}
	extraPay[0]=0;//used if two diff monthly payments
	extraPay[1]=0;
	extraPay[2]=0;
	var j=0;
	for (k=0;k<LoanCount;k++)//put worst loans in array first
		if (order[k]==worst[0].index)
		{
			m=order[0];
			order[0]=worst[0].index;
			order[k]=m;
		}

	if (wl >1)
	{
		for (k=0;k<LoanCount;k++)
			if (order[k]==worst[1].index)
			{
				m=order[1];
				order[1]=worst[1].index;
				order[k]=m;
			}
	}
	if (wl >2)
	{
		for (k=0;k<LoanCount;k++)
			if (order[k]==worst[2].index)
			{
				m=order[2];
				order[2]=worst[2].index;
				order[k]=m;
			}
	}
	for (var i=0;i<LoanCount;i++)
	{
        j=order[i];
		if (antLoans[j].bal<=0)	continue;
		if (antLoans[j].lTypeIndex==0 || antLoans[j].lTypeIndex==1 || antLoans[j].lTypeIndex==4 || antLoans[j].lTypeIndex==3)
			GoodPayer=true;
		else
			GoodPayer=false;
		bal=antLoans[j].newBal+antLoans[j].newAccrue;
		if (bal <=0)//loan was paid off during paydown or borrow less
		{
			antLoans[j].newBal=0;
			antLoans[j].newNpay=0;
			antLoans[j].newInt=0;
			continue;
		}
		mPay=antLoans[j].mPay;
		iRate=antLoans[j].iRate/100/12;
		inter=0;
        if(antLoans[i].lTypeIndex==1 || antLoans[i].lTypeIndex==7)
		{																																						 
			grad_disb_diff = ((parseInt(gradDate.substring(0,2),10)-parseInt(antLoans[i].disburseDate.substring(0,2),10))+(parseInt(gradDate.substring(3,7))-parseInt(antLoans[i].disburseDate.substring(3,7)))*12);
			if(antLoans[i].lTypeIndex!=5)
				inter = getInterest(antLoans[i].newBal,antLoans[i].iRate,(grad_disb_diff+6),0,0) - antLoans[i].accruAmount;
		}
		k=0;
		m=0;
		yrs=0;
		dual13[j]=0;
		dualExtra[j]=0;
		paid=0;
		while (1)
		{
			m++;
			if (worst[0].index == j || (worst[1].index == j && wl >1) || (worst[2].index == j && wl > 2))
			{
				if (box13 && k==0 && yrs <= pay13 && yrs > yrsStart)
				{
					bal-=mPay;
					paid+=mPay;
					extraPay[i]=mPay*2;//2 different payments
					yrsStart=yrs;
					dual13[j]=yrs;
					if (bal <= 0)
					{
						paid+=bal;
						inter+=bal*iRate;
						bal=0;
						break;
					}
				}
				if (addBox && m> oldMonths && m<addMonths)
				{
					bal-=addPay;
					extraPay[i]=addPay+mPay;//2 different payments
					paid+=addPay;
					dualExtra[j]=m;
					oldMonths=m+1;
					if (bal <= 0)
					{
						paid+=bal;
						inter+=bal*iRate;
						bal=0;
						break;
					}
				}
			}
			inter+=iRate*bal;
			bal+=iRate*bal;
			bal-=mPay;
			paid+=mPay;
			k++;
			if (k==12)
			{
				k=0;
				yrs++;
			}
			if (GoodPayer && goodPay)//stafford & pcl only
			{
				if (m>6)
				{
					iRate=(antLoans[j].iRate-0.25)/100/12;
				}
				if (m>54)
				{
					iRate=(antLoans[j].iRate-2.25)/100/12;
				}
			}
			if (bal <= 0)
			{
				inter+=bal*iRate;
				paid+=bal;
				bal=0;
				break;
			}

		}
		antLoans[j].newInt=inter;
		antLoans[j].newNpay=m;
		if (box13)
			dual13[j]=Math.round(dual13[j]+(m%12)/12);
		GlobalPaid+=paid;
	}
	if (pay13 > yrsStart && yrsStart != -1)
		pay13=yrsStart+1;
	if (addMonths > oldMonths && oldMonths != -1)
		addMonths=oldMonths;
	if (addMonths == 0)
		addMonths=1;

	GlobalNewIntSub=0;
	GlobalNewAccrue=0;
	GlobalNewPrinc=0;

	for (var i=0;i<LoanCount;i++)
	{
		GlobalNewIntSub+=antLoans[i].newInt;
		GlobalNewPrinc+=antLoans[i].newBal;
		GlobalNewAccrue+=antLoans[i].newAccrue;
		if (antLoans[i].newNpay > antLoans[i].nPay)
			antLoans[i].newNpay=antLoans[i].nPay;
	}
	GlobalExtraPay=0;
	GlobalExtraMonths=0;
	if (extraBox1)
	{
		GlobalExtraPay+=extraPay1;
		GlobalExtraMonths=extraMonths1;
	}
	if (extraBox2)
	{
		GlobalExtraPay+=extraPay2;
		if (extraMonths2>GlobalExtraMonths)
			GlobalExtraMonths=extraMonths2;
	}
	if (extraBox3)
	{
		GlobalExtraPay+=extraPay3;
		if (extraMonths2>GlobalExtraMonths)
			GlobalExtraMonths=extraMonths2;
	}

} // End saveMoneyFunc()




function borrowLess(bl,wl)//called from saveMoneyFunc
{
	var t=0;
	var wl1=wl;
	var numworstloans = 3;
	if(numworstloans > LoanCount) numworstloans = LoanCount;
	for(var loopcount=0;loopcount<numworstloans;loopcount++)
	{
		if (antLoans[worst[loopcount].index].existing) wl1--;//find how many ways to divide
    }
	if (wl1 < 1) wl1=1;//wl1 will divide up borrow less amount
	for (var i=0;i<LoanCount;i++)
	{
		if (!antLoans[i].existing)
			t+=antLoans[i].bal;
	}
	if (t < bl)
	{
		bl=bLess=t;
		alert("Only $"+bl+" is possible.");
	}
	for(var loopVar=0;loopVar<numworstloans;loopVar++)
	{
		if(bl==0) break;
		if (bl < antLoans[worst[loopVar].index].bal && wl > loopVar && !antLoans[worst[loopVar].index].existing)
		{
			antLoans[worst[loopVar].index].newBal=antLoans[worst[loopVar].index].bal-bl;
			bl-=antLoans[worst[loopVar].index].bal;
			if(bl<0) bl=0;
		}
		else
		if (!antLoans[worst[loopVar].index].existing)
		{
			antLoans[worst[loopVar].index].newBal=antLoans[worst[loopVar].index].newMpay=antLoans[worst[loopVar].index].newNpay=0;
			bl-=antLoans[worst[loopVar].index].bal;
			if(bl<0) bl=0;
		}
	}

	if (bl >1)//figure rest of loans if any borrow less balance left

		for (var i=0;i<LoanCount;i++)
		{
			if (bl < antLoans[i].bal && !antLoans[i].existing && !(i==worst[0].index ||i==worst[1].index ||i==worst[2].index))
			{
				antLoans[i].newBal=antLoans[i].bal-bl;
				bl-=antLoans[i].bal;
				if(bl<0) bl=0;
			}
			else
				if (!antLoans[i].existing && !(i==worst[0].index ||i==worst[1].index ||i==worst[2].index))
			{
				antLoans[i].newBal=antLoans[i].newMpay=antLoans[i].newNpay=0;
				bl-=antLoans[i].bal;
				if(bl<0) bl=0;
			}
			if (bl <1)break;
		}
	for (var i=0;i<LoanCount;i++)
	{
		if (!antLoans[i].existing)
			antLoans[i].newBal=Math.round(antLoans[i].newBal);
	}
} //End function borrowLess()


function doPayDown()//new 12/19/99
{
	var payDown=0;
	var loopVar;
	var reps = LoanCount;
	if(reps > 3) reps=3;
	for(loopVar=1;loopVar<=reps;loopVar++)
	{
	   if (eval("extraBox"+loopVar+" && extraMonths"+loopVar+" > 0 && extraPay"+loopVar+" > 0 && antLoans[worst["+((loopVar-1))+"].index].accrueMonths > 0"))
	   {
		if (eval("extraMonths"+loopVar+" > antLoans[worst["+(loopVar-1)+"].index].accrueMonths"))
			eval("extraMonths"+loopVar+" = antLoans[worst["+loopVar+"-1].index].accrueMonths");
		if (eval("antLoans[worst["+(loopVar-1)+"].index].lTypeIndex==0 || antLoans[worst["+(loopVar-1)+"].index].lTypeIndex==2 ||  antLoans[worst["+(loopVar-1)+"].index].lTypeIndex==5||  antLoans[worst["+(loopVar-1)+"].index].lTypeIndex==6")) //subsidized
		{
			if (eval("extraPay"+loopVar+"*extraMonths"+loopVar+" <=antLoans[worst["+(loopVar-1)+"].index].newBal"))
			{
				eval("antLoans[worst["+(loopVar-1)+"].index].newBal-=extraPay"+loopVar+"*extraMonths"+loopVar);
			}
			else
			{
				eval("extraPay"+loopVar+"=antLoans[worst["+(loopVar-1)+"].index].newBal/extraMonths"+loopVar);
				eval("antLoans[worst["+(loopVar-1)+"].index].newBal=0");
			}
			eval("payDown=extraPay"+loopVar+"*extraMonths"+loopVar);
			continue;         
		}
		if (eval("antLoans[worst["+(loopVar-1)+"].index].lTypeIndex==1"))
			var iRate = 6.80;
		else
			eval("var iRate=antLoans[worst["+(loopVar-1)+"].index].iRate");
			
		var inter;
		for (var i=0;i<eval("antLoans[worst["+(loopVar-1)+"].index].accrueMonths");i++)
		{
			if (i >= eval("extraMonths"+loopVar))
			{
				var temp=eval("antLoans[worst["+(loopVar-1)+"].index].accrueMonths-extraMonths"+loopVar);
				eval("antLoans[worst["+(loopVar-1)+"].index].newAccrue+=iRate/100/12 * temp * antLoans[worst["+(loopVar-1)+"].index].newBal");
				break;
			}
			if (eval("antLoans[worst["+(loopVar-1)+"].index].newBal <=0"))
			{
				payDown+=eval("antLoans[worst["+(loopVar-1)+"].index].newBal");
				eval("extraMonths"+loopVar+"=i+1");
				break;
			}
			inter=eval("iRate/100/12 * antLoans[worst["+(loopVar-1)+"].index].newBal");
			if (eval("extraPay"+loopVar+" > inter"))
				eval("antLoans[worst["+(loopVar-1)+"].index].newBal-=(extraPay"+loopVar+"-inter)");
			else
				eval("antLoans[worst["+(loopVar-1)+"].index].newAccrue+=(inter-extraPay"+loopVar+")");
			payDown+=eval("extraPay"+loopVar);
		}
   	   }
	   else
	   {
		eval("antLoans[worst["+((loopVar-1))+"].index].newAccrue=antLoans[worst["+((loopVar-1))+"].index].accruAmount");//use orig amount
	   }
	}
	GlobalPayDown=payDown;
} // End function doPayDown1()


//-------------------------------------
function Aget1Rate(index)//student loan entry page
{
	var lt=parent.mainPage.studentLoan1.document.AntLoan.LoanType[index].selectedIndex;
	var r=getRt(lt);
	if (r=="")
		r=prompt("Interest Rate ?","7.000");
	return r;
} //function Aget1Rate()

//-------------------------------------
function getRt(i)
{
	switch (i)
	/*{
		case 0: return 5.300;
		case 1: return 5.300;
		case 2: return 5.000;
		case 3: return 5.000;
		case 4: return "";
		case 5: return 5.000;
		case 6: return "";
		default:
			alert("No such loan type");
	}
	*/
	{ 
		case 0: return 6.800;
		case 1: return 6.800;
		case 2: return 5.000;
		case 3: return 8.500;
		case 4: return 5.000;
		case 5: return "";
		case 6: return 5.000;
		case 7: return "";
		default:
			alert("No such loan type second");
	}
	return 0;
}//End function getRt()

//-------------------------------------
function getAccrualMonths(i)//i is index of loan
{
    return ((parseInt(gradDate.substring(0,2),10)-parseInt(antLoans[i].disburseDate.substring(0,2),10))+(parseInt(gradDate.substring(3,7))-parseInt(antLoans[i].disburseDate.substring(3,7)))*12);
}// End function getAccrualMonths()

//-------------------------------------


function doLoan(type,loanNumber,balance,rate,numPayments)
{
	switch(type)
	{
		case 0: // subStafford
		{
			antLoans[loanNumber].accruAmount=0;
			break;
		}
		case 2: // Perkins
		{
			antLoans[loanNumber].accruAmount=0;
			break;
		}
		case 3: // Grad PLUS
		{
			var periods=getAccrualMonths(loanNumber)+6;
			if (periods <0)
				periods=0;
			antLoans[loanNumber].accruAmount=getInterest(balance,rate,periods,0,0);
			break;
		}
		case 6: // Campus
		{
			antLoans[loanNumber].accruAmount=0;
			break;
		}
		case 1: // unSubStafford
		{
			var periods=getAccrualMonths(loanNumber)+6;
			if (periods <0)
				periods=0;
			antLoans[loanNumber].accruAmount=getInterest(balance,rate,periods,0,0);
			break;
		}
		case 4: // PCL/HSL
		{
			antLoans[loanNumber].accruAmount=0;
			break;
		}
		case 5: // Alternative
		{
			var periods=getAccrualMonths(loanNumber);
			if (periods<0)
				periods=0;
			antLoans[loanNumber].accruAmount=getInterest(balance,rate,periods,antLoans[loanNumber].schoolPay,periods);
			break;
		}
		case 7: // Other
		{
			var periods=getAccrualMonths(loanNumber)+6;
			if (periods <0)
				periods=0;
			antLoans[loanNumber].accruAmount=getInterest(balance,rate,periods,0,0);
			break;
		}
	}
	var pay = antLoans[loanNumber].mPay=getMonthlyPayment((balance+antLoans[loanNumber].accruAmount),rate,numPayments);
	antLoans[loanNumber].nPay = numPayments;
	var total = antLoans[loanNumber].mPay*numPayments;
	antLoans[loanNumber].iPaid=total-(balance+antLoans[loanNumber].accruAmount);
	antLoans[loanNumber].accrueBal=antLoans[loanNumber].mPay*numPayments-antLoans[loanNumber].bal;
	document.places=0;
	antLoans[loanNumber].onInt=total-(balance+antLoans[loanNumber].accruAmount);
	antLoans[loanNumber].onPrinc=pay-(total-(balance+antLoans[loanNumber].accruAmount))/numPayments;
	return pay;
}


//-------------------------------------
function getNumMonths(str)
{
	//accepts mm/dd/yyyy
	var xx=str.split("/");
	var month=parseInt(xx[0],10);
	var year;
	year=xx[1];
	if(year.length<4)
		year=xx[2];
	year=parseInt(year,10);
	grad = new Date(month+"/01/"+year);
	grad = grad.getTime();
	return grad/(1000*60*60*24*(365/12));
}//End function getNumMonths()

//-------------------------------------

function getAdate(d,m,y)
{
	if (m<10)
		str="0"+m.toString();
	else
		str=m.toString();
	str+="/";
	if (d<10)
		str+="0"+d.toString();
	else
		str+=d.toString();
	str+="/";
	str+=y;
	return str;
}// End function getAdate()

//-------------------------------------
var summaryWin=null;
function doSummary()
{
	if (summaryWin != null && summaryWin.open)
		summaryWin.close();
	summaryWin=open("SummaryReportFrame.html","summaryWindow","scrollbars,toolbar,menubar,noresize,height=440,width=640,top=25,left=100,screenX=100,screenY=25");
}// End function doSummary()

//-------------------------------------
function setFactors()
{
	switch (colIncomeBy)
	{
		case 1:
			incFactor=1;
			break;
		case 2:
			incFactor=12;
			break;
		case 3:
			incFactor=52;
			break;
		default:
	}
	switch (colExpenseBy)
	{
		case 1://quarter 3
			expFactor=3;
			break;
		case 2://quarter 4
			expFactor=4;
			break;
		case 3://trimester
			expFactor=3;
			break;
		case 4://semester
			expFactor=2;
			break;
		case 5://annual
			expFactor=1;
			break;
		default:
	}
	switch (aidBy)
	{
		case 1:
			aidFactor=3;
			break;
		case 2:
			aidFactor=4;
			break;
		case 3:
			aidFactor=3;
			break;
		case 4:
			aidFactor=2;
			break;
		case 5:
			aidFactor=1;
			break;
		default:
	}
}// End function setFactors()

//-------------------
function setFactorsCar()
{
	incFactor=1;
	expFactor=12;
}// End function setFactorsCar()

//--------------------
function dontChange(i)
{
	i=1;
	dontUpdate=true;
}// End function dontChange()

function ckNull(obj)
{
	if (dontUpdate)
	{
		dontUpdate=false;
		return;
	}
	var fld=obj.name;
	var frm=obj.form.name;
	var l=eval("parent.mainPage.document."+frm+"."+fld+".value");
	if (l.length==0)
		var val=eval("parent.mainPage.document."+frm+"."+fld+".value=0");
}// End function ckNull()

function saveMoney()
{
	for (var i=0;i<LoanCount;i++)
		if (antLoans[i].bal > 0)
		{
			loadPage("saveMoneyFrame.html",-1);
			return;
		}
	alert("No loans to process");        
}//End function saveMoney()
//----------
function totalsMsg(fld)
{
	return confirm(fld+"\nDo You Want To Clear The Data\n In The Worksheet?");
}// Endfunction totalsMsg()

function checkForDetails(obj)//called from change on any totals field which has details button
{
	if (win != null)
	{
		win.close();
		win=null;
	}
	var val=obj.value;
	var fld=obj.Name;
	var frm=obj.form.Name;
	switch(frm)
	{
		case "colFin":
			{
				switch(fld)
				{
					case "other":
					{
						if (ColTANF+ColSSI+ColOtherMisc==0)
							return;
						if (!totalsMsg("Other"))
							val=ColMiscOtherIncome;//restore
						else
							ColTANF=ColSSI=ColOtherMisc=0;//use new value, zero details
						break;
					}
					case  "credit":
					{
						if (ColCreditCard1+ColCreditCard2+ColCreditCard3+ColPerLoan1+ColPerLoan2+ColPerLoan3== 0)
							return;
						if (!totalsMsg("Credit Card Loans"))
							val=ColCredit;//restore
						else
							ColCreditCard1=ColCreditCard2=ColCreditCard3=ColPerLoan1=ColPerLoan2=ColPerLoan3=0;//use new value, zero details
						break;
					}
					case  "rent":
					{
						if (ColRentMortgagePayment+ColTaxes+ColrmInsurance+ColMiscRentMortgage== 0)
							return;
						if (!totalsMsg("Rent/Mortgage"))
							val=ColRentMortgage;//restore
						else
							ColRentMortgagePayment=ColTaxes=ColrmInsurance=ColMiscRentMortgage=0;//use new value, zero details
						break;
					}
					case "books":
					{
						if (ColBooks+ColSupplies+ColComputer+ColMiscSupplies== 0)
							return;
						if (!totalsMsg("Books"))
							val=ColBooksSupplies;//restore
						else
							ColBooks=ColSupplies=ColComputer=ColMiscSupplies=0;//use new value, zero details
						break;
					}
					case "groc":
					{
						if (ColFood+ColCleaning+ColPersonal+ColFoodMisc== 0)
							return;
						if (!totalsMsg("Food/Household"))
							val=ColGroceries;//restore
						else
							ColFood=ColCleaning=ColPersonal=ColFoodMisc=0;//use new value, zero details
						break;
					}
					case "LoanPay":
					{
						if (ColLoan1+ColLoan2+ColLoan3== 0)
							return;
						if (!totalsMsg("Student Loans"))
							val=ColLoanPay;//restore
						else
							ColLoan1=ColLoan2=ColLoan3=0;//use new value, zero details
						break;
					}
					case "utilities":
					{
						if (ColGasElectricity+ColWater+ColTrashPickup+ColCableTVSatellite+ColTelephone+ColCellTelephone+ColInternet+ColMiscUtilities== 0)
							return;
						if (!totalsMsg("Utilities"))
							val=ColUtilities;//restore
						else
							ColGasElectricity=ColWater=ColTrashPickup=ColCableTVSatellite=ColTelephone=ColCellTelephone=ColInternet=ColMiscUtilities=0;//use new value, zero details
						break;
					}
					case "vehicle":
					{
						if (ColVehiclePayment+ColVehicleRegistration+ColGas+ColMaintenance+ColInsurance+ColParking+ColMiscVehicleCosts+ColPublicTransportation+ColBikeService+ColBikeRegistration+ColAirFareHome== 0)
							return;
						if (!totalsMsg("Transportation Costs"))
							val=ColVehicleCosts;//restore
						else
							ColVehiclePayment=ColVehicleRegistration=ColGas=ColMaintenance=ColInsurance=ColParking=ColMiscVehicleCosts=ColPublicTransportation=ColBikeService=ColBikeRegistration=ColAirFareHome=0;//use new value, zero details
						break;
					}
					case "transOther":
					{
						if (ColPublicTransportation+ColBikeService+ColBikeRegistration+ColAirFareHome+ColMiscOtherTransportationCosts== 0)
							return;
						if (!totalsMsg("Other"))
							val=ColOtherTransportationCosts;//restore
						else
							ColPublicTransportation=ColBikeService=ColBikeRegistration=ColAirFareHome=ColMiscOtherTransportationCosts=0;//use new value, zero details
						break;
					}
					case "clothing":
					{
						if (ColClothing+ColShoes+ColLaundryDryCleaning+ColDryCleaning+ColTailoringRepairs+ColMiscClothingCosts== 0)
							return;
						if (!totalsMsg("Clothing"))
							val=ColClothingCosts;//restore
						else
							ColClothing=ColShoes=ColLaundryDryCleaning=ColDryCleaning=ColTailoringRepairs=ColMiscClothingCosts=0;//use new value, zero details
						break;
					}
					case "additional":
					{
						if (ColEntertainment+ColCreditCardPayment+ColMedicalDental+ColChildCare+ColSavings+ColVeterinarian+ColGifts+ColMiscAdditionalExpenses+ColVacation== 0)
							return;
						if (!totalsMsg("Additional Expenses"))
							val=ColAdditionalExpenses;//restore
						else
							ColEntertainment=ColCreditCardPayment=ColMedicalDental=ColChildCare=ColSavings=ColVeterinarian=ColGifts=ColMiscAdditionalExpenses=ColVacation=0;//use new value, zero details
						break;
					}
				}
				break;
			}
		case "carFin":
			{
				switch(fld)
				{
					case "otherIncome":
					{
						if (CarTANF+CarSSI+CarOtherMisc==0)
							return;
						if (!totalsMsg("Other"))
							val=CarOtherIncome;//restore
						else
							CarTANF=CarSSI=CarOtherMisc=0;//use new value, zero details
						break;
					}
					case "credit":
					{
						if (CarCreditCard1+CarCreditCard2+CarCreditCard3+CarPerLoan1+CarPerLoan2+CarPerLoan3== 0)
							return;
						if (!totalsMsg("Credit Card Loans"))
							val=CarCredit;//restore
						else
							CarCreditCard1=CarCreditCard2=CarCreditCard3=CarPerLoan1=CarPerLoan2=CarPerLoan3=0;//use new value, zero details
						break;
					}
					case "rent":
					{
						if (CarRentMortgagePayment+CarTaxes+CarrmInsurance+CarMiscRentMortgage== 0)
							return;
						if (!totalsMsg("Rent/Mortgage"))
							val=CarRentMortgage;//restore
						else
							CarRentMortgagePayment=CarTaxes=CarrmInsurance=CarMiscRentMortgage=0;//use new value, zero details
						break;
					}
					case "grocs":
					{
						if (CarFood+CarCleaning+CarPersonal+CarFoodMisc== 0)
							return;
						if (!totalsMsg("Food/Household"))
							val=CarGroceries;//restore
						else
							CarFood=CarCleaning=CarPersonal=CarFoodMisc=0;//use new value, zero details
						break;
					}
					case "loanpayment":
					{
						if (CarLoan1+CarLoan2+CarLoan3== 0)
							return;
						if (!totalsMsg("Student Loans"))
							val=CarLoanPayment;//restore
						else
							CarLoan1=CarLoan2=CarLoan3=0;//use new value, zero details
						break;
					}
					case "utilities":
					{
						if (CarGasElectricity+CarWater+CarTrashPickup+CarCableTVSatellite+CarTelephone+CarCellTelephone+CarInternet+CarMiscUtilities== 0)
							return;
						if (!totalsMsg("Utilities"))
							val=CarUtilities;//restore
						else
							CarGasElectricity=CarWater=CarTrashPickup=CarCableTVSatellite=CarTelephone=CarCellTelephone=CarInternet=CarMiscUtilities=0;//use new value, zero details
						break;
					}
					case "vehicle":
					{
						if (CarVehiclePayment+CarVehicleRegistration+CarGas+CarMaintenance+CarInsurance+CarParking+CarPublicTransportation+CarMiscVehicleCosts== 0)
							return;
						if (!totalsMsg("Transportation Costs"))
							val=CarVehicleCosts;//restore
						else
							CarVehiclePayment=CarVehicleRegistration=CarGas=CarMaintenance=CarInsurance=CarParking=CarPublicTransportation=CarMiscVehicleCosts=0;//use new value, zero details
						break;
					}
					case "vehicleOther":
					{
						if (CarPublicTransportation+CarMiscOtherTransportationCosts== 0)
							return;
						if (!totalsMsg("Other"))
							val=CarOtherTransportationCosts;//restore
						else
							CarPublicTransportation=CarMiscOtherTransportationCosts=0;//use new value, zero details
						break;
					}
					case "clothes":
					{
						if (CarClothing+CarShoes+CarLaundryDryCleaning+CarDryCleaning+CarTailoringRepairs+CarMiscClothingCosts== 0)
							return;
						if (!totalsMsg("Clothing"))
							val=CarClothingCosts;//restore
						else
							CarClothing=CarShoes=CarLaundryDryCleaning=CarDryCleaning=CarTailoringRepairs=CarMiscClothingCosts=0;//use new value, zero details
						break;
					}
					case "additional":
					{
						if (CarEntertainment+CarCreditCardPayment+CarMedicalDental+CarChildCare+CarSavings+CarVeterinarian+CarGifts+CarMiscAdditionalExpenses+CarVacation== 0)
							return;
						if (!totalsMsg("Additional Expenses"))
							val=CarAdditionalExpenses;//restore
						else
							CarEntertainment=CarCreditCardPayment=CarMedicalDental=CarChildCare=CarSavings=CarVeterinarian=CarGifts=CarMiscAdditionalExpenses=CarVacation=0;//use new value, zero details
						break;
					}
					case "retirement":
					{
						if (CarRetSavings+CarRetSavInvestments+CarRetSavIRA+CarRetSav40+CarRetSavMisc	== 0)
							return;
						if (!totalsMsg("Retirement/Savings"))
							val=CarRetirement;//restore
						else
							CarRetSavings=CarRetSavInvestments=CarRetSavIRA=CarRetSav40=CarRetSavMisc=0;//use new value and zero details
						break;
					}
				}
				break;
			}
	}
	
}// End function checkForDetails()

//---------

function openWorksheet(worksheetName, wsWidth, wsHeight)
{
	if (win != null && win.Open)
		win.close();
	win = open(worksheetName, "Worksheet", "noresize,width="+wsWidth+",height="+wsHeight+"top=25,left=100,screenX=100,screenY=25");
}

var winHelp = null;

function getHelp(word,height,width)
{
	winHelp=open("edw_PopupHelp.html?word="+escape(word),"","menu=0,toolbar=0,scrollbars=0,height="+height+",width="+width+",top=25,left=100,screenX=100,screenY=25");
}//End function getHelp()

function getCookieVal (offset) 
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}//End function getCookieVal ()

function GetCookie (name) 
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)	break;
	}
	return null;
}//End function GetCookie ()  

function SetCookie (name, value) 
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
					  ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
					  ((path == null) ? "" : ("; path=" + path)) +
					  ((domain == null) ? "" : ("; domain=" + domain)) +
					  ((secure == true) ? "; secure" : "");
}//End function SetCookie()

// Function for opening calculators

function openCalc(calcPage,calcWidth,calcHeight)
{
	if(Calc!=null && Calc.open)
		Calc.close();
	Calc=open(calcPage,"Calculator","width="+calcWidth+",height="+calcHeight+",toolbar=0,resize=1,scrollbars=1,top=25,left=100,screenX=100,screenY=25");
}

// Beginning of menu selection functions

function setMenuImage(menuLoc)
{
	
	parent.topPage.document.menuItem1.src="/images/edw_button1a.gif";
	parent.topPage.document.menuItem2.src="/images/edw_button2a.gif";
	parent.topPage.document.menuItem3.src="/images/edw_button3a.gif";
	parent.topPage.document.menuItem4.src="/images/edw_button4a.gif";
	parent.topPage.document.menuItem5.src="/images/edw_button5a.gif";
	parent.topPage.document.menuItem6.src="/images/edw_button6a.gif";

	if(!menuLoc)
		menuLoc=menuLocation;
	eval("parent.topPage.document.menuItem"+menuLoc+".src='/images/edw_button"+menuLoc+"b.gif'");
}

function loadPage(mainPage,menuImage,menuPage) //arg1 = page name, arg2 = menu location(-1 for no change), arg3 = menu bar page
{
	prevPage=parent.mainPage.location.href.substring((parent.mainPage.location.href.lastIndexOf("/")+1),parent.mainPage.location.href.length);
	if(menuPage)
	    parent.topPage.location.href=menuPage;
	parent.frames[1].location.href=mainPage;
      if(menuImage>-1)
	{
		setMenuImage(menuImage);
		menuLocation=menuImage;
	}
}

function salaries()
{
	loadPage("dbaseframe.html",-1);
}
// End of menu selection functions



//End of Javascript File - pageManip.js
