//variables for frame setup
var calcframe;
var calcform;
var bsingle=0;
var bconsolidation=0;
var single;
var consolidation;
var oldversionok=0;
var refsite="";
var grad_bg = "#eeeeff";

//variables for Control myltiple windows
var infoWin;
var iflag; //if click include link, iflag=1;
var openWin=0;

//variables for option selection
var blevel=0;
var bshorten=0;
var blarger=0;
var bincome=0;
var bgraduated=0;
var bcomparison=0;
var radiochk=0;

//flag to indicate cpb on change
var cpbflag=0;

//variable for consolidation input
var addnew=1;

//variables for calculation
var maxloans=10, numloans=0;
var mcpb = new Array(); //multiple current pricipal balance
var mrateyr = new Array();
var myes = new Array();
var mno = new Array();
var mtype = new Array();
var mindex; //the current number of loan input
var chkindex; //the checkbox number being checked
var mcontroltype = new Array();
//if (parent.refsite == "nslp")
//	var defaultrateyr = "8.25";
//else
var defaultrateyr = "6.8";

var cpb="", rate, rateyr="", wageyr="", wagemo;
var lrpmt, lrlpmt, lrterm, lrtotpay, lrtotint;
var ispmt, isterm, isoth, islimit, istotpmt, istotint;
var grpmt, grlpmt, grterm, grtotpay, grpmt0;
var USAFgrpmt1, USAFgrpmt2, USAFgrpmt3, USAFgrpmt4, USAFgrtotpmt, USAFgrtotint, USAFgrtotamt;

var lrpmtu, defaultterm=120.0, defaultamt="";
var astrick;
var calling = parent.history.length-1;  //contains the original history length so that the back button will work for IE.

//Parse CallingSite's URL and save the value of site to var refsite
function saveRefSite()
{
	var sitebegin = document.location.href.toLowerCase().indexOf("site=");
	var siteend=-1;
	if (sitebegin > -1) 
	{
		refsite = document.location.href.substring(sitebegin+5);
		siteend = refsite.indexOf("?");
		if (siteend > -1)
		{
			refsite = refsite.substring(0,siteend);
		}
	}
	else
	{
		refsite = "???";
	}
	//alert(document.location+"\n"+sitebegin+"\n"+siteend+"\n"+refsite);
}
//Print Copy right at the bottom of pages
function printCopyRight()
{
	calcframe.write(
		'<table border=0 cellspacing=0 cellpadding="5" width="625">'+
		'<tr ALIGN=CENTER>'+
		'<td>');
	

	if (parent.refsite == "nslp")
		calcframe.write(
			'<font size=1>used with permission from EducationQuest Foundation &copy; 2005 ' );
	else
		calcframe.write(
			'<font size=1>&copy; 2002 EducationQuest Foundation ' );
	
		
		calcframe.write(
			'<A HREF="#" onClick="setTimeout(\'parent.openLegalStuffWin()\',1); return false;"> Legal Stuff</A>'+
			'</font></td></tr></table>'
		);
}

// Open legal stuff window
function openLegalStuffWin()
{
	var legalWin;
	
	//window.status = parent.site;
	if(parent.refsite == "epc")
	{
	    //alert(document.location+"\n"+refsite);
		window.open('http://www.educationquest.org/legal.asp','EPC','width=550,height=550,scrollbars=yes,resizable=yes');
	}
	else if(parent.refsite == "nslp")
	{
	    //alert(document.location+"\n"+refsite);
		window.open('http://www.nslp.org/nslpterms.htm','NSLP','width=550,height=550,scrollbars=yes,resizable=yes'); 
	}
	else 
		calcframe.write(' ');
}	

function brversion()  // ie3, ie4, ns3, ns4, op3
{
	var browsername = navigator.appName;
	var browserversion = parseInt(navigator.appVersion);
	var ua = navigator.userAgent;
	
	if (browsername == "Netscape") 
		browser = "ns" + browserversion;
	else 
	{
		if (browsername == "Microsoft Internet Explorer") 
		{
			if (browserversion >= 2) 
				browser = "ie" + browserversion;
			else
				browser = "ie3";
		}
	}

// Check for opera separately since it returns "Netscape" as it's appName
	if (ua.indexOf("Opera") != -1)
		browser="op"+browserversion;

	return browser;
}

function brinfo()
{
	return "Information about your browser:<BR><strong>userAgent:</strong> '"+navigator.userAgent + "',<BR> <strong>appName:</strong> '"+navigator.appName+"', <strong>appVersion:</strong> '"+navigator.appVersion+"' "; 
}

function resetcalcform(single, consolidation)
{
	numloans=0;
	mindex=1; //show at least one row for input
	cpb="";
	rateyr="";
	wageyr="";
	//defaultrateyr = "8.25";
	//if (parent.refsite == "nslp")
	//	var defaultrateyr = "8.25";
	//else
	var defaultrateyr = "6.8";

	USAFgrtotpmt="";
	grpmt0="";
	grpmt="";
	ispmt="";
	addnew=1;

	bsingle = single;
	bconsolidation = consolidation;
	
	for (i = 0; i < maxloans; i++)
	{
		mcpb[i]="";
		mrateyr[i]=defaultrateyr;
		myes[i]=0;
		mno[i]=0;
		mtype[i]= 0;
	}
	lrterm = defaultterm;
	lrpmtu = defaultamt;
	browser=brversion();

	if (browser.substring(2,3) >= 4 || oldversionok)
	{
		parent.rows="*.0";
		refreshcalcform(bsingle, bconsolidation);
		return"";
	}
	else
		return '<HTML><HEAD><TITLE>Sorry</TITLE></HEAD><BODY>'+
		'Your browser version "<strong>'+browser+'</strong>" appears to be too old '+
		'and therefore may not compatible with this javascript calculator, which requires at least '+
		'<A HREF="http://home.netscape.com/download/">Netscape Navigator/Communicator 4</A> or '+
		'<A HREF="http://www.microsoft.com/ie/">Microsoft Internet Explorer 4.0</A>.'+
		'<form>You may use the links above to download either of these for free or '+
		'<input type=button value="continue" onClick="oldversionok=1;parent.refreshcalcform('+bsingle+', '+bconsolidation+');"> on at your own risk or '+
		'<input type=button value="go back" onClick="top.history.back();"> to the previous page.'+
		'</form>'+
	brinfo()+
	'</BODY></HTML>';
}

function refreshcalcform(single, consolidation)
{
	var i;
	bsingle = single;
	bconsolidation = consolidation;
	if (bsingle==1)
	{
		calcframe = parent.frames['framesingle'].document;
		calcform = calcframe.sform; 
		showsingleframe();
	}
	else if(bconsolidation==1)
	{
		calcframe = parent.frames['frameconsolidation'].document;
		calcform = calcframe.cform;
		showconsolidationframe();
	}
	else
		alert(" Both of bsingle and bconsolidation are 0.");	
	
	return "";
}


//
//	show content of the single calculation frame
//
function showsingleframe()
{
	calcframe = parent.frames['framesingle'].document;

	calcframe.open();
	calcframe.write('<HTML>');
	showoptions();
	//
	//	show input fields
	//
	showsingleinputs();
	if (bsingle==1 &&(blevel==1 || bcomparison==1))
	{
		//
		// show accelerate options
		//
		accelerate();
	}
	calcframe.write('<table border=0 cellspacing=0 width="625"><tr valign="top">');
		if (blevel==1 || bcomparison==1)
		{
			calcframe.write('<td width="32%">');
			showlevelcalc();
			calcframe.write('</td>');
		}
		if (bgraduated==1 || bcomparison==1)
		{
			calcframe.write('<td width="32%">');
			showgraduatedcalc();
			calcframe.write('</td>');
		}
		if (bincome==1 || bcomparison==1)
		{
			calcframe.write('<td width="32%">');
			showincomecalc();
			calcframe.write('</td>');
		}
	calcframe.write('</td></tr></table>');
//To get back to the calling page had to use a wierd little formula for IE, for every button that was pushed it would add 1 to history,
//so I needed to get the original history length subtract 1 then subtract the current length to send it back to the correct page.
	//calcframe.write('<span style="padding-left:300px"><input type=button NAME="cmdBackEPC" value="Back" onclick="parent.history.go('+calling+' - parent.history.length);" ></span>');
	printCopyRight();
	calcframe.write('</FORM>');
	calcframe.write('</BODY>');
	calcframe.write('</HTML>');
	calcframe.close();

	calcframe = parent.frames['framesingle'].document;
	calcform = calcframe.sform; 
}
//
//	show content of the consolidation calculation frame
//
function showconsolidationframe()
{
	calcframe.open();
	calcframe.write('<HTML>');
	showoptions();
	showconsolidationinputs();
	calcframe.write('<table border=0 cellspacing=0 width="625"><tr valign="top">');
	if (blevel==1 || bcomparison==1)
	{
		calcframe.write('<td width="32%">');
		showlevelcalc();
	calcframe.write('</td>');
	}
	if (bgraduated==1 || bcomparison==1)
	{
		calcframe.write('<td width="32%">');
		showgraduatedcalc();
		calcframe.write('</td>');
	}
	if (bincome==1 || bcomparison==1)
	{
		calcframe.write('<td width="32%">');
		showincomecalc();
		calcframe.write('</td>');
	}
	calcframe.write('</td></tr></table>');
//To get back to the calling page had to use a wierd little formula for IE, for every button that was pushed it would add 1 to history,
//so I needed to get the original history length subtract 1 then subtract the current length to send it back to the correct page.
	showchart();
	//calcframe.write('<span style="padding-left:300px"><input type=button NAME="cmdBackEPC" value="Back" onclick="parent.history.go('+calling+' - parent.history.length);" ></span>');
	calcframe.write('</FORM>');
	printCopyRight();
	calcframe.write('</BODY>');
	calcframe.write('</HTML>');
	calcframe.close();

	calcframe = parent.frames['frameconsolidation'].document;
	calcform = calcframe.cform; 
}
//
//	show options in both frames
//
function showoptions() {
	calcframe.write('<BODY bgColor="white" aLink=Red bgProperties=fixed text=Navy>\n');
//	calcframe.write('<h4>');
	if(bsingle==1)	{
		if(parent.refsite == "epc") {
		   addFavIcon();
			calcframe.write(
				'<MAP NAME="EdquestHome">'+
					'<AREA SHAPE="RECT" COORDS="7,14,166,106" HREF="http://www.educationquest.org" TITLE="">'+
				'</MAP>'+
				'<TABLE WIDTH="625" border=0>'+
					'<TR><TD><IMG SRC="repayCAL_top.jpg" border="0" USEMAP="#EdquestHome"></TD>'+
					'</TR></TABLE>'+
					'<FORM name=sform>');
		}
		else {
			//NSLP site
			calcframe.write(
				'<TABLE WIDTH="625" border=0>'+
					'<TR><TD><IMG SRC="loan_repay_nslp.gif" border="0"></TD>'+
					'</TR></TABLE>'+
					'<FORM name=sform>');
		}
	}
	else if(bconsolidation==1)	{
		if(parent.refsite == "epc") {
		   addFavIcon();
			calcframe.write(
				'<MAP NAME="EdquestHome">'+
					'<AREA SHAPE="RECT" COORDS="5,14,163,106" HREF="http://www.educationquest.org" TITLE="">'+
				'</MAP>'+
				'<TABLE WIDTH="625" border=0>'+
				'<TR><TD><IMG SRC="consolCAL_top.jpg" border="0" USEMAP="#EdquestHome" ></TD>'+
				
				'</TR></TABLE>'+
				'<FORM name=cform>'
				);
		}
		else {
			//NSLP site
			calcframe.write(
				'<TABLE WIDTH="625" border=0>'+
				'<TR><TD><IMG SRC="consolidation_nslp.gif" border="0"</TD>'+
				
				'</TR></TABLE>'+
				'<FORM name=cform>'
				);
		}
	}
	else {
		alert("Both bsingle and bconsolidation are 0.\n");
	}
	
	calcframe.write(
		'<TABLE width="625" border="0">'+
			'<TR><TD colspan="4" align=left style="padding-left:5px"><font face="verdana" size=2 >Select one of the following options, ');
			if(bconsolidation==1)
				calcframe.write('and enter information for each loan.');
			else
				calcframe.write('and enter your student loan information.');
			
			if(parent.refsite == "nslp")
				calcframe.write('</font></TD></TR>'+'<TR><TD colspan=4 align=left><font face="verdana" size=2 >*You may change this field.</font></TD></TR> ' +'<TR bgcolor=#7AC142>'+ '<TD width=24% align=left>'+	'<INPUT TYPE="radio" name="radio1" ');
			else
				calcframe.write('</font></TD></TR>'+'<TR><TD colspan=4 align=left><font face="verdana" size=2 >*You may change this field.</font></TD></TR> ' +'<TR bgcolor=#ddeedd>'+ '<TD width=24% align=left>'+ '<INPUT TYPE="radio" name="radio1" ');

	if (blevel==1)
		calcframe.write(' CHECKED ');
		calcframe.write(
				'onclick="setTimeout(\'parent.clicklevel();\',1);" '+
				'tabindex=0>'+
				'<A HREF="#" onClick="parent.iflag=0; setTimeout(\'parent.openInfoWin()\',1); return false;"> Level</A>'+
				'</TD>'+
				'<TD width="150" align=left>'+
				'<input type="radio" name="radio1" '
	   );
	if (bgraduated==1)
		calcframe.write(' CHECKED ');
		calcframe.write(
					'onclick="setTimeout(\'parent.clickgraduated();\',1);"> '+
					'<A HREF="#" onClick="parent.iflag=0; setTimeout(\'parent.openInfoWin()\',1); return false;">Graduated</A>'+
				'</TD>'+
				'<TD width="150" align=left>'+
					'<input type="radio" name="radio1" '
	   );
	if (bincome==1)
		calcframe.write(' CHECKED ');
		calcframe.write(
					' onclick="setTimeout(\'parent.clickincome();\',1);"> '+
					'<A HREF="#" onClick="parent.iflag=0; setTimeout(\'parent.openInfoWin()\',1); return false;", '+
					' >Income Sensitive</A>'+
				'</TD>'+
				'<TD width="150" align=left>'+
					'<input type="radio" name="radio1" '
	);
	if (bcomparison==1)
		calcframe.write(' CHECKED ');
		calcframe.write(
					'onclick="setTimeout(\'parent.clickcomparison();\',1);"> '+
					'<A HREF="#" onClick="parent.iflag=0; setTimeout(\'parent.openInfoWin()\',1); return false;">Comparison</A>'+
				'</TD>'+
			'</TR>'+
		'</TABLE>'
	   );
}

//
//	shorten term and larger pmt fields are displayed
//
function accelerate()
{
	calcframe.write(
		'<TABLE width="625" CELLPADDING="0" CELLSPACING="0" border=0 >'+
		'<TR style="padding-left:5px">'+
				'<TD COLSPAN="3" align=left><font face="verdana" size=2>'+
					'Paying your loan back early saves interest. '+
					'Select one of the following options to accelerate your loan repayment '+ 
					'and our calculator will do the math.  '+
					'<A HREF="#" onClick="parent.iflag=2; setTimeout(\'parent.openInfoWin()\',1); return false;">Click here for more information.</A>' +
					'<br><br>Some borrowers qualify for Extended repayment. ' +
					'<A HREF="#" onClick="parent.iflag=0; setTimeout(\'parent.openInfoWin()\',1); return false;">Click here.</A>' +
					'to see if you qualify.</font>'+
				'</TD>'+
		'</TR>'+
		'<TR>')

		if (parent.refsite == "nslp")
			{
			calcframe.write('<TD width="125" ALIGN="center" bgcolor=#7ac142><I><B>' +
				'<A HREF="#" onClick="parent.iflag=3; setTimeout(\'parent.openInfoWin()\',1); return false;"> **Optional Input**</A>' +

			'</B></I></TD>' +
			'<TD width="500" bgcolor=#7ac142 ALIGN=center> Term: ');
			}
		else
			{
			calcframe.write('<TD width="125" ALIGN="center" bgcolor=#ddeedd><I><B>**Optional Input**</B></I></TD>' +
			'<TD width="500" bgcolor=#DDEEDD ALIGN=center> Term: ');
			}
	
		calcframe.write(
				'<input type="text" name="textshorten" size=4 length=4 '+
				'value="'+lrterm+'" tabindex=2 '+
				'onchange="setTimeout(\'parent.dellrpmt()\',1);setTimeout(\'parent.docalc(\\\'w\\\',-1)\',1);">'+
				'months&nbsp;&nbsp;&nbsp;&nbsp;<I><B>Or</B></I>&nbsp;&nbsp;&nbsp;&nbsp;'+
				'Larger Payment:  '+
				'<input type="text" name="textlarger" size=10 length=10 '+
				'value="'+lrpmtu+'" tabindex=2 '+
				'onchange="setTimeout(\'parent.delshrterm()\',1);setTimeout(\'parent.docalc(\\\'w\\\',-1)\',1);">'+
			'</TD>');

		if (parent.refsite == "nslp")
			calcframe.write('<TD BGCOLOR=#7ac142>&nbsp;</TD>');
		else
			calcframe.write('<TD BGCOLOR=#ddeedd>&nbsp;</TD>');
		
		calcframe.write(
		'</TR>'+
		'</TABLE>'
	);
}

//
//	when click level, graduated, income-sensitive, or comparison link
//
function openInfoWin()
{
	if(openWin==1){
		infoWin.close();
		openWin=0;
		openInfoWin();
	}
	else{
		if(iflag==1)
			infoWin=window.open('Includeinfo.htm', 'infoWin', 
				'width=450,height=150,scrollbars=yes,resizable=yes');
		else if (iflag==0)
			infoWin = window.open('optionsinfo.htm', 'infoWin', 
				'width=450,height=450,scrollbars=yes,resizable=yes'); 
		else if (iflag==2)
			infoWin = window.open('moreinfo.htm', 'infoWin', 
				'width=450,height=150,scrollbars=yes,resizable=yes'); 
		else if (iflag==3)
			infoWin = window.open('Optinputinfo.htm', 'infoWin',
				'width=450, height=150,scrllbars=yes,resizable=yes');
			
		infoWin.focus();
		openWin=1;
	}
}	

//
//	show input text boxes in single frame
//
function showsingleinputs()
{
	if (bincome==1 || bcomparison==1)
	{
		//
		//	when Income or Comparison selected
		//	annual wages field is displayed with other input fiels
		//
		calcframe.write('<TABLE WIDTH="625" border=0>');

//			'<TR><TD colspan=3 align=left><font face="verdana" size=2 >Enter your student loan information.  '+
//			'Once you complete the required fields, press the Tab key or Enter key, and our calculator will '+
//			'automatically estimate the results.</font></TD></TR>'+
		if (parent.refsite == "nslp")
			calcframe.write('<TR bgcolor=#7ac142>');
		else
			calcframe.write('<TR bgcolor=#DDEEDD>');
		
		calcframe.write('<TD width=208 align=center>Loan Amount:'+
					'<input type="text" name=fcpb  size=10 length=10 value="'+mcpb[0]+'" '+
					'tabindex=0 onchange="setTimeout(\'parent.amtonchange()\',1);">'+
				'</TD>'+
				'<TD width=208 align=center>* Interest Rate:'+
					'<input type="text" name=frateyr  size=5 length=5 value="'+mrateyr[0]+'" '+
					'tabindex=1 onchange="parent.mrateyr['+0+']=this.value; setTimeout(\'parent.docalc(\\\'w\\\','+0+')\',1);">%'+
				'</td>'+
				'<TD width=209 align=center>Annual Wages:'+
					'<input type="text" name=textwages  size=10 length=10 value="'+wageyr+'" '+
					'tabindex=2 onchange="setTimeout(\'parent.wagesonchange()\',1);">'+
				'</TD>'+
				'<TD>'+
					'<input type=button NAME="cmdCalculate" value="Calculate" onclick="setTimeout(\'parent.refreshcalcform('+bsingle+','+bconsolidation+');\',1);" >'+
				'</TD>'+
			'</TR>'
		);
		calcframe.write('</TABLE>');
	}
	else
	{
		//
		// when Graduated or Level selected, or before any selection
		//
		calcframe.write('<TABLE WIDTH="625" border=0>');
//		calcframe.write(
//			'<TR><TD colspan=2 align=left >'+
//				'<font face="verdana" size=2>Enter your student loan information.  '+
//				'Once you complete the required fields, press the Tab key or Enter key, '+
//				'and our calculator will automatically estimate the results.</font></TD>'+
//			'</TR>'+
			
		if (parent.refsite == "nslp")
			calcframe.write('<TR bgcolor=#7ac142>');
		else
			calcframe.write('<TR bgcolor=#DDEEDD>');
		
		calcframe.write(	
				'<td width=300 align=center>Loan Amount:'+
					'<input type="text" name=fcpb  size=10 length=10 value="'+mcpb[0]+'" '+
					'tabindex=0 onchange="setTimeout(\'parent.amtonchange()\',1);">'+
				'</td>'+
				'<td width=300 align=center>* Interest Rate:'+
					'<input type="text" name=frateyr  size=5 length=5 value="'+mrateyr[0]+'" '+
					'tabindex=1 onchange="setTimeout(\'parent.docalc(\\\'w\\\','+0+')\',1);">%</td>'+
				'<TD width=25>'+
					'<input type=button NAME="cmdCalculate" value="Calculate" onclick="setTimeout(\'parent.refreshcalcform('+bsingle+','+bconsolidation+');\',1);" >'+
				'</TD>'+
			'</TR>'
		);
	}
	calcframe.write('</TABLE>');
	calcframe.write(
	'<input name=fcpb type=hidden value="[end]">'+
	'<input name=frateyr type=hidden value="[end]">'
	);
}
//
//	when single loan amount changed
//
function amtonchange()
{
	mcpb[0]=calcform.fcpb[0].value;
	if (blevel==0 && bincome==0 && bgraduated==0 && bcomparison==0){ 
		msg = "Before you enter loan information, you need to select one of the four repayment options.";
		alert(msg);
		return false;
	}
	else
	{

		docalc('w', 0);
		calcform.frateyr[0].focus();
		return true;
	}
}
//
//	show input text boxes and calc button in consolidation frame
//
function showconsolidationinputs()
{
	var i;
	calcframe.write('<BR>');
	tableheader();
	for(i=0; i < mindex && mindex <= maxloans; i++)
	{
		addinputrow(i);
	}
	calcframe.write('</TABLE><BR>');
	
	// extra hidden field so there's always at least 2 rows
	calcframe.write(
		'<INPUT NAME="fcpb" type="HIDDEN" value="[end]">\n'+
		'<INPUT NAME="frateyr" type="HIDDEN" value="[end]">\n'+
		'<INPUT NAME="ftype" type="HIDDEN" value="[end]">\n'
	);
}

function tableheader()
{
	calcframe.write(
		'<TABLE WIDTH="625" BORDER=0 CELLSPACING=0 CELLPADDING=0>');
//				'<TR><TD colspan=5>'+
//					'<font face="verdana" size=2>Enter information for each loan.  Once you '+
//					'complete the required fields our calculator will automatically estimate the results.</font></td>'+
//				'</TR>'
	if(bcomparison==1||bincome==1)
	{
		if (parent.refsite == "nslp")
			calcframe.write('<TR><TD colspan="5" align=left bgcolor=#7ac142>Annual Wages: ');
		else
			calcframe.write('<TR><TD colspan="5" align=left bgcolor=#DDEEDD style="padding-left:5px">Annual Wages: ');

		calcframe.write(		
				'<input type=text name=textwages value="'+wageyr+'" size=11 length=11 '+
				'onChange="setTimeout(\'parent.wagesonchange()\',1);" ></TD>\n'+
				'</TD>'+
			'</TR>\n');
		
		if (parent.refsite == "nslp")
			calcframe.write('<TR bgcolor=#7ac142>');
		else
			calcframe.write('<TR bgcolor=#DDEEDD>');
		
		calcframe.write(			
				'<TD width="185" style="padding-left:5px">Loan Type:</TD>'+
				'<TD width="125">Loan Amount:</TD>'+
				'<TD width="125">Interest Rate:</TD>'+
				'<TD colspan=2>'+
				'<A HREF="#" onClick="parent.iflag=1; setTimeout(\'parent.openInfoWin()\',1); return false;">Consolidate?</A>:'+
				'</TD>'+
			'</TR>'
		);
	}
	else 
		{
			if (parent.refsite == "nslp")
				calcframe.write(
					'<TR bgcolor=#7ac142>'+
					'<TD width="185" style="padding-left:5px">Loan Type:</TD>'+
					'<TD width="125">Loan Amount:</TD>'+
					'<TD width="125">Interest Rate:</TD>'+
					'<TD colspan="2">'+
					'<A HREF="#" onClick="parent.iflag=1; setTimeout(\'parent.openInfoWin()\',1); return false;">Consolidate?</A>:'+
					'</TD>'+
					'</TR>'
					);
			else
				calcframe.write(
					'<TR bgcolor=#DDEEDD>'+
					'<TD width="185" style="padding-left:5px">Loan Type:</TD>'+
					'<TD width="125">Loan Amount:</TD>'+
					'<TD width="125">* Interest Rate:</TD>'+
					'<TD colspan=2>'+
					'<A HREF="#" onClick="parent.iflag=1; setTimeout(\'parent.openInfoWin()\',1); return false;">Consolidate?</A>:'+
					'</TD>'+
					'</TR>'
					);
		}	
}

//
//	the j th input row is added
//
function addinputrow(j)
{
	if (parent.refsite == "nslp")
		calcframe.write(
			'\n<TR bgcolor=#7ac142 style="padding-left:5px">'+
			'<TD width="125">'+
			'<SELECT name="ftype" size=1 onChange="setTimeout(\'parent.clicktype('+j+')\',1);" >\n'+
			'<OPTION '
			);
	else
		calcframe.write(
			'\n<TR bgcolor=#DDEEDD style="padding-left:5px">'+
			'<TD width="125">'+
			'<SELECT name="ftype" size=1 onChange="setTimeout(\'parent.clicktype('+j+')\',1);" >\n'+
			'<OPTION '
			);
	
	if (mtype[j]==0)
	{
		calcframe.write(' SELECTED=true');				
	}
	calcframe.write(
		'>Stafford Loan'+
		'\n<OPTION '
	);
	if (mtype[j]==1)
	{
		calcframe.write(' SELECTED=true');	
	}
	calcframe.write(
		'>Unsubsidized Stafford'+
		'\n<OPTION '
	);
	if (mtype[j]==2)
	{
		calcframe.write(' SELECTED=true');
	}
	calcframe.write(
		'>Perkins Loan'+
		'\n<OPTION'
	);
	if (mtype[j]==3)
	{
		calcframe.write(' SELECTED=true');
	}
	calcframe.write(
		'>HPSL'+
		'\n<OPTION'
	);
	if (mtype[j]==4)
	{
		calcframe.write(' SELECTED=true ');				
	}
	calcframe.write(
		'>SLS'+
		'\n<OPTION'
	);
	if (mtype[j]==5)
	{
		calcframe.write(' SELECTED=true');
	}
	calcframe.write(
		'>PLUS'+
		'\n<OPTION'
	);
	if (mtype[j]==6)
	{
		calcframe.write(' SELECTED=true ');				
	}
	var finame = "finclude" +j;

	calcframe.write(		
		'>Other Education Loans'+
		'</SELECT>\n'
	);
	calcframe.write(
		'</TD>\n'+
		'<TD width="125" align=left><INPUT TYPE="TEXT" NAME="fcpb"  size=10 length=10 value= "'+mcpb[j]+'" '+
			'onChange="setTimeout(\'parent.cpbarrayonchange('+j+')\',2);" ></TD>\n'+
		'<TD width="125" align=left><INPUT TYPE="TEXT" NAME="frateyr"  size=5 length=5 value="'+mrateyr[j]+'" '+
			'onChange="parent.mrateyr['+j+']=this.value; setTimeout(\'parent.docalc(\\\'r\\\',-1)\',1); return true;">%</TD>\n'
	);
	if(j!=mindex-1)
	{
		calcframe.write(
				'<TD colspan="2" align=left><INPUT TYPE="radio" NAME= "'+finame+'" '
		);
		if (myes[j]==1)
			calcframe.write(' CHECKED ');
		calcframe.write(
			'value="'+myes[j]+'" onClick="setTimeout(\'parent.clickincludeyes('+j+')\',2);">Yes &nbsp;&nbsp; '+
			'<INPUT TYPE="radio" NAME="'+finame+'" '
		);
		if (mno[j]==1) 
			calcframe.write(' CHECKED '); 
		calcframe.write('value="'+mno[j]+'" onClick="setTimeout(\'parent.clickincludeno('+j+');\',2);">No</TD>\n'+
			'</TR>\n'
		);
	}
	else if(j==mindex-1||mindex==maxloans)
	{
		calcframe.write(						
			'<TD width="125" align=left><INPUT TYPE="radio" NAME= "'+finame+'" '
		);
		if (myes[j]==1)
			calcframe.write(' CHECKED ');
		calcframe.write(
		'value="'+myes[j]+'" onClick="setTimeout(\'parent.clickincludeyes('+j+');\',2);">Yes &nbsp;&nbsp; '+
			'<INPUT TYPE="radio" NAME="'+finame+'" '
		);
		if (mno[j]==1) 
			calcframe.write(' CHECKED '); 
		calcframe.write('value="'+mno[j]+'" onClick="setTimeout(\'parent.clickincludeno('+j+');\',2);">No</TD>'+
			'<TD width=4% align=right>&nbsp;</TD>'+
			'</TR>');
		
		if (parent.refsite == "nslp")
			calcframe.write('<TR BGCOLOR=#7ac142>');
		else
			calcframe.write('<TR BGCOLOR=#ddeedd>');
		
		calcframe.write(
			'<TD COLSPAN="5" ALIGN=center>'+
			'<input type=button NAME="cmdCalculate" value="Calculate" onclick="setTimeout(\'parent.refreshcalcform('+bsingle+','+bconsolidation+');\',1);" >'+
			'&nbsp;&nbsp;<input type=button name=clear value="Clear All"'+
			'onclick="setTimeout(\'parent.resetcalcform(0,1);\',10);">'+ 
			'</TD>'+
			'</TR>\n'
		);
	}
	return "";
}

function showlevelcalc()
{
if (cpb > 0.0)
	{
	
	if (parent.refsite == "nslp")
		calcframe.write('<table bgcolor=#b8d6ff border=0 cellspacing=0 cellpadding=0 width="100%">');
	else
		calcframe.write('<table bgcolor=#FFFFCC border=0 cellspacing=0 cellpadding=0 width="100%">');
	
// 	'<table bgcolor=#FFFFCC border=0 cellspacing=0 cellpadding=0 width="100%">'+
	
	calcframe.write(
			'<TR>'+
				'<TD colspan=2 align="center"><HR><strong>LEVEL<BR>REPAYMENT<BR></strong></td>'+
			'</tr>'+
			'<TR>'+
				'<TD colspan=2 align="center"><HR><B>Totals</B><BR></TD>'+
			'</TR>'+
			'<TR>'+
				'<TD align=middle><table border=0 cellspacing=0 cellpadding=0 width="50%">'+
					'<TR>'+
						'<TD>Term</TD>'+
					'</TR>'+   
					'<TR>'+
						'<TD>Interest Rate</TD>'+
					'</TR>'+
					'<TR>'+
						'<TD nowrap>First Payment</TD>'+
					'</TR>'+
					'<TR>'+
						'<TD nowrap>Total Interest</TD>'+
					'</TR>'+
					'<TR>'+
						'<TD nowrap>Total Loan Amount</TD>'+
					'</TR>'+
					'<TR>'+
						'<TD nowrap>Total Payments</TD>'+
					'</TR>'+
					'</table>'+
				'</TD>'+
				'<TD align=middle width="50%"><table border=0 cellspacing=0 cellpadding=0>'+
					 '<TR>'+
						'<TD align=right>'+lrterm+'</TD>'+
					'</TR>'+
					 '<TR>'+
						'<TD align=right>'+rateyr+'</TD>'+
					'</TR>'+
					'<TR>'+
						'<TD align=right>'+formatMoney(lrpmt)+'</TD>'+
					'</TR>'+
					'<TR>'+
						'<TD align=right>'+formatMoney(lrtotint)+'</TD>'+
					'</TR>'+
					'<TR><TD align=right>'+formatMoney(cpb)+'</TD></TR>'+
					'<TR>'+
						'<TD align=right>'+formatMoney(lrtotpay)+'</TD>'+
					'</TR>'+
					'</table>'+
				'</TD>'+
			'</TR>'+
			'<TR>'+
				'<TD colspan="2" align="middle"><HR><B>Payment Summary</B><BR><BR></TD>'+
			'</TR>'+
			'<TR>'+
				'<TD align=middle><table border=0 cellspacing=0 cellpadding=0>'+
			'<TR>'+
				'<TD align=middle>Number of<BR>Months</TD>'+
			'</TR>');
	if (lrlpmt > 0.0)
	{
		if (lrlpmt == lrpmt)
			calcframe.write(
				'<TR><TD align=middle>'+(lrterm)+'</TD></TR>');
		else
			calcframe.write(
				'<TR><TD align=middle>'+(lrterm-1)+'</TD></TR>'+
				'<TR><TD align=middle>1</TD></TR>');
	}
	else
	{
		calcframe.write(
			'<TR><TD align=left>'+lrterm+'</TD></TR>');
	}
	calcframe.write(
	'</table></TD><TD align=middle><table border=0 cellspacing=0 cellpadding=0>'+
	'<TR><TD align=right>Monthly<BR>Payment</TD></TR>');
	if (lrlpmt > 0.0)
	{   
		if (lrlpmt == lrpmt)
			calcframe.write('<TR><TD align=right>'+formatMoney(lrpmt)+'</TD></TR>');
		else
			calcframe.write(
				'<TR><TD align=right>'+formatMoney(lrpmt)+'</TD></TR>'+
				'<TR><TD align=right>'+formatMoney(lrlpmt)+'</TD></TR>');
	}
	else
	{
		calcframe.write('<TR><TD align=right>'+formatMoney(lrpmt)+'</TD></TR>');
	}
	calcframe.write('</table></TD></TR>');
	calcframe.write('<TR><TD colspan=2><HR></TD></TR>');
	if (astrick=="*")
	{
		calcframe.write('<TR><TD align=center colspan=2><table><TR><TD><small>The minimum monthly payment is $50.00.</small></TD></TR></table></TD></TR>');
		calcframe.write('<TR><TD colspan=2><HR></TD></TR>');
	};
	calcframe.write('</table>');
		
//		calcframe.write('</td>');
//		</tr></table></center>');
}
		
}

function showgraduatedcalc()
{
if (USAFgrtotpmt > 0.0)
{
	if (parent.refsite == "nslp")
		calcframe.write('<table bgcolor="#baff87" border=0 cellspacing=0 cellpadding=0 width="100%">');
	else 
		calcframe.write('<table bgcolor="#eeeeff" border=0 cellspacing=0 cellpadding=0 width="100%">');

	calcframe.write(
		'<TR><TD colspan=2 align=middle><HR><strong>GRADUATED<BR>REPAYMENT<BR></strong></td></tr>'+
		'<TR><TD colspan=2 align=middle><HR><B>Totals</B><BR></TD></TR>'+
		'<TR><TD align=middle width=50%><table border=0 cellspacing=0 cellpadding=0>'+
		'<TR><TD>Term</TD></TR>'+   
		'<TR><TD nowrap>Interest Rate</TD></TR>'+
		'<TR><TD nowrap>First Payment</TD></TR>'+
		'<TR><TD nowrap>Total Interest</TD></TR>'+
		'<TR><TD nowrap>Total Loan Amount</TD></TR>'+
		'<TR><TD nowrap>Total Payments</TD></TR>'+
		'</table></TD><TD align=middle><table border=0 cellspacing=0 cellpadding=0>'+
		'<TR><TD align=right>'+grterm+'</TD></TR>'+
		'<TR><TD align=right>'+rateyr+'</TD></TR>'+
		'<TR><TD align=right>'+formatMoney(USAFgrpmt1)+'</TD></TR>'+
		'<TR><TD align=right>'+formatMoney(USAFgrtotint)+'</TD></TR>'+
		'<TR><TD align=right>'+formatMoney(cpb)+'</TD></TR>'+
		'<TR><TD align=right>'+formatMoney(USAFgrtotpmt)+'</TD></TR>'+
		'</table></TD></TR>'+
		'<TR><TD colspan=2 align=middle><HR><B>Payment Summary</B><BR><BR></TD></TR>'+
		'<TR><TD align=middle width=50%><table border=0 cellspacing=0 cellpadding=0>'+
		'<TR><TD align=middle>Number of<BR>Months</TD></TR>'+
		'<TR><TD align=middle>24</TD></TR>'+
		'<TR><TD align=middle>18</TD></TR>'+
		'<TR><TD align=middle>18</TD></TR>'+
		'<TR><TD align=middle>'+(grterm-60)+'</TD></TR>'+
		'</table></TD><TD align=middle width=50%><table border=0 cellspacing=0 cellpadding=0>'+
		'<TR><TD align=right>Monthly<BR>Payment</TD></TR>'+
		'<TR><TD align=right>'+formatMoney(USAFgrpmt1)+'</TD></TR>'+
		'<TR><TD align=right>'+formatMoney(USAFgrpmt2)+'</TD></TR>'+
		'<TR><TD align=right>'+formatMoney(USAFgrpmt3)+'</TD></TR>'+
		'<TR><TD align=right>'+formatMoney(USAFgrpmt4)+'</TD></TR>'+
		'</table></TD></TR>'+  
		'<TR><TD colspan=2><HR></TD></TR>'+   
		'<TR><TD align=center colspan=2><table width="66%"><TR><TD><small>This schedule is an estimate of your graduated payments.  Your lender will determine your exact payments if you choose this repayment option.</small></TD></TR></table></TD></TR>'+
		'<TR><TD colspan=2><HR></TD></TR>'+

		'');
	calcframe.write('</table>');
	}
}

function showincomecalc()
{
if (ispmt > 0.0)
{
	if (parent.refsite == "nslp")
		calcframe.write('<table bgcolor=#ffd267 border=0 cellspacing=0 cellpadding=0 width="100%">');
	else
		calcframe.write('<table bgcolor=#ffeeff border=0 cellspacing=0 cellpadding=0 width="100%">');

// 		'<table bgcolor=#ffeeff border=0 cellspacing=0 cellpadding=0 width="100%">'+

	calcframe.write(
		'<TR><TD colspan=2 align=middle><HR><strong>INCOME SENSITIVE<BR>REPAYMENT<BR></strong></td></tr>'+
		'<TR><TD colspan=2 align=middle><HR><B>Totals</B><BR></TD></TR>'+
		'<TR><TD align=middle width=50%><table border=0 cellspacing=0 cellpadding=0>'+
		'<TR><TD>Term</TD></TR>'+   
		'<TR><TD nowrap>Interest Rate</TD></TR>'+
		'<TR><TD nowrap>First Payment</TD></TR>'+
		'<TR><TD nowrap>Total Interest</TD></TR>'+
		'<TR><TD nowrap>Total Loan Amount</TD></TR>'+
		'<TR><TD nowrap>Total Payments</TD></TR>'+
		'</table></TD><TD align=middle><table border=0 cellspacing=0 cellpadding=0>'+
		'<TR><TD align=right>'+(isterm+12)+'</TD></TR>'+
		'<TR><TD align=right>'+rateyr+'</TD></TR>'+
		'<TR><TD align=right>'+formatMoney(ispmt)+'</TD></TR>'+   
		'<TR><TD align=right>'+formatMoney(istotint)+'</TD></TR>'+
		'<TR><TD align=right>'+formatMoney(cpb)+'</TD></TR>'+
		'<TR><TD align=right>'+formatMoney(istotpmt)+'</TD></TR>'+

		'</table></TD></TR>'+
		'<TR><TD colspan=2 align=middle><HR><B>Payment Summary</B><BR><BR></TD></TR>'+
		'<TR><TD align=middle width=50%><table border=0 cellspacing=0 cellpadding=0>'+
		'<TR><TD align=middle>Number of<BR>Months</TD></TR>'+
		'<TR><TD align=middle>'+12+'</TD></TR>'+
		'<TR><TD align=middle>'+(isterm)+'</TD></TR>'+
		'</table>'+
		'</TD><TD align=middle><table border=0 cellspacing=0 cellpadding=0>'+
		'<TR><TD align=right>Monthly<BR>Payment</TD></TR>'+
		'<TR><TD align=right>'+formatMoney(ispmt)+'</TD></TR>'+
		'<TR><TD align=right>'+formatMoney(isothpmt)+'</TD></TR>'+
		'</table></TD></TR>'+  
		'<TR><TD colspan=2><HR></TD></TR>'+
		'<TR><TD align=center colspan=2><table width="66%"><TR><TD><small>This schedule is an estimate of the first 12 months of your income sensitive payments.  Your lender will determine the exact payments if you choose this repayment option.  Your payments will be adjusted annually.</small></TD></TR></table></TD></TR>'+
		'<TR><TD colspan=2><HR></TD></TR>'+
		'</table>');
}
}

function clicklevel()
{
	blevel=1;
	bincome=0;
	bgraduated=0;
	bcomparison=0;
	refreshcalcform(bsingle, bconsolidation);
	if(radiochk==0)
	{
		if(bsingle==1)
			setTimeout(parent.docalc('w',-1),1);
		else
		{
			if (calcform.fcpb[0].value!="")
				mindex++;
			setTimeout(parent.docalc('r',-1),1);
		}
		radiochk=1;
	}
	if (calcform.fcpb[0].value=="")
		calcform.fcpb[0].focus();
	return "";
}

function clickincome()
{
	blevel=0;
	bincome=1;
	bgraduated=0;
	bcomparison=0;
	refreshcalcform(bsingle, bconsolidation);
	if(radiochk==0)
	{
		if(bsingle==1)
			setTimeout(parent.docalc('w',-1),1);
		else
		{
			if (calcform.fcpb[0].value!="")
				mindex++;
			setTimeout(parent.docalc('r',-1),1);
		}
		radiochk=1;
	}
	if(bsingle==1){
		if (calcform.textwages.value==""&&calcform.fcpb[0].value!="")
			calcform.textwages.focus();
		else if(calcform.fcpb[0].value=="")
			calcform.fcpb[0].focus();
	}
	else if(bconsolidation==1)
	{
		calcform = calcframe.cform;
		if (calcform.textwages.value!=""&&calcform.fcpb[0].value=="")
			calcform.fcpb[0].focus();
		else if(calcform.textwages.value=="")
			calcform.textwages.focus();
	}
	return "";
}

function clickgraduated()
{
	blevel=0;
	bincome=0;
	bgraduated=1;
	bcomparison=0;
	refreshcalcform(bsingle, bconsolidation);
	if(radiochk==0)
	{
		if(bsingle==1)
			setTimeout(parent.docalc('w',-1),1);
		else
		{
			if (calcform.fcpb[0].value!="")
				mindex++;
			setTimeout(parent.docalc('r',-1),1);
		}
		radiochk=1;
	}
	if (calcform.fcpb[0].value=="")
		calcform.fcpb[0].focus();
	return "";
}

function clickcomparison()
{
	blevel=0;
	bincome=0;
	bgraduated=0;
	bcomparison=1;
	refreshcalcform(bsingle, bconsolidation);
	if(radiochk==0)
	{
		if(bsingle==1)
			setTimeout(parent.docalc('w',-1),1);
		else
		{
			if (calcform.fcpb[0].value!="")
				mindex++;
			setTimeout(parent.docalc('r',-1),1);
		}
		radiochk=1;
	}
	if(bsingle==1){
		if (calcform.textwages.value==""&&calcform.fcpb[0].value!="")
			calcform.textwages.focus();
		else if(calcform.fcpb[0].value=="")
			calcform.fcpb[0].focus();
	}
	else if(bconsolidation==1)
	{
		if (calcform.textwages.value!=""&&calcform.fcpb[0].value=="")
			calcform.fcpb[0].focus();
		else if(calcform.textwages.value=="")
			calcform.textwages.focus();
	}
	return "";
}

function wagesonchange()
{
	parent.wageyr=calcform.textwages.value; 
	if (bsingle==1)
		setTimeout(parent.docalc('w',0),1);
	if(bconsolidation==1)
		setTimeout(parent.docalc('r',-1),1);
	calcform.fcpb[mindex-1].focus();
	return true;
}
function cpbarrayonchange(k)
{
	parent.mcpb[k]=calcform.fcpb[k].value;
	if(parent.checktextboxes(k,1)==true){
		if(calcform.fcpb[mindex-1].value=="")
			calcform.fcpb[k+1].focus();
	}
	else
		calcform.frateyr[k].focus();
	return true;	
}
function clickincludeyes(k)
{
	parent.chkindex=k+1;
	parent.myes[k]=1;
	parent.mno[k]=0;
	if(parent.checktextboxes(k,0)==true)
		if(calcform.fcpb[mindex-1].value=="")
			calcform.fcpb[k+1].focus();
	return "";
}

function clickincludeno(k)
{
	parent.myes[k]=0;
	parent.mno[k]=1;
	if(parent.checktextboxes(k,0)==true)
		if(calcform.fcpb[mindex-1].value=="")
			calcform.fcpb[k+1].focus();
	return "";
}

function checktextboxes(n, cpbflag)
{
	var rate;
	var cpb;
 	var iyes, ino;
	var msg;
	calcform = calcframe.cform;
	chkindex=n+1;
	for(i=0;i<chkindex;i++){
		var k = i+1;
		rate = calcform.frateyr[i].value;
		cpb = calcform.fcpb[i].value;
		if (blevel==0 && bincome==0 && bgraduated==0 && bcomparison==0){ 
			msg = "Before you enter loan information, you need to select one of the four repayment options.";
			break;
		}
		else if (bincome==1 && calcform.textwages.value=="")
		{
			msg = "The field of annual wages is empty.";
			break;
		}
		else if (cpb =="")
		{
			msg = "In the input row "+k+", the field of Loan Amount is empty.";
			break;
		}
		else if (rate == "")
		{
			msg = "In the input row "+k+", the field of Interest Rate is empty.";
		}
		else if (myes[i]==0 && mno[i]==0)
		{
			msg = "In the input row "+k+", you need to make a choice from 'Include' field.";
		}
		else 
		{
			msg = "true"; 			
		}
	}
	if (msg=="true")
	{
		if(chkindex == mindex)
		{
			addnew=1;
			if(mindex<maxloans)
			mindex++;
		}
		docalc('r',-1)
		if (calcform.fcpb[mindex-1].value=="")
		{
			calcform.fcpb[mindex-1].focus();
		}
		return true;
	}
	else
	{
		if (cpbflag==0){
			alert(msg+"You have to fill all required fields.");
		}
		return false;
	}
}

function clicktype(k)
{
	mtype[k]=calcframe.cform.ftype[k].selectedIndex;
	if(mtype[k]==0 || mtype[k]==1)
		parent.mrateyr[k]="8.25";
	else if(mtype[k]==2 || mtype[k]==3)
		parent.mrateyr[k]="5.00";
	else if(mtype[k]==5)
		parent.mrateyr[k]="9.00";
	else if(mtype[k]==4)
		parent.mrateyr[k]="11.00";
	else
		parent.mrateyr[k]="0.00";
	calcform.frateyr[k].value= parent.mrateyr[k];
	setTimeout(parent.docalc('r',-1),1);
	calcform.fcpb[k].focus();
	return "";
}	

function dellrpmt()
{
	calcform.textlarger.value="";
}

function delshrterm()
{
	calcform.textshorten.value="";
}		

//calculation of the amount for the rest of the payments, (n) is the number that shows how many are left.
function PMT_PvFvRN(PV,FV,R,N)
{
var denominator;
if (R <= 0) denominator=1; else denominator=(Math.pow((1.0 + R),-N) - 1.0) / R;

return (FV*Math.pow((1.0 + R),-N)-PV)/denominator;
}

//calculation of the amount of the loan left to repay after the a certain number (n) payments have been made
function FV_PmtPvRN(PMT,PV,R,N)
{
var numeratorpart;

if (R <= 0) numeratorpart = 0.0; else numeratorpart = (1.0 - Math.pow((1.0 + R), -N)) / R;

return (PV - PMT*numeratorpart)/Math.pow((1.0 + R), -N);
}

function N_PmtPvR(PMT,PV,R)
{
	if (PMT > 0)
	{
		if (R > 0)  // need to check for negative 1+PV*R/PMT
		{
		return -(Math.log(1.0-PV*R/PMT) / Math.log(1.0+R));
		}
		else  
			return PV / PMT;
	}
	else
		return 0;
}

function parseMoney(Amount)
{
	var fixAmt="";
	var i;
	var dollar = "$"
	for (i=0; i<Amount.length; i++)
	{
		if (Amount.charAt(i)==',' || Amount.charAt(i)==dollar)
			fixAmt+="";
		else
			fixAmt+=Amount.charAt(i);
	}	
	return fixAmt;
}

//Fixes the amounts so that they contain 2 decimal places.
function formatDecimal(fixAmt,dec)
{
	var decPart, intPart;
	if (isNaN(parseInt(fixAmt)))
		intPart = 0;
	else
		intPart = parseInt(fixAmt);
	if (dec==2)		
		decPart = Math.round(100*(fixAmt - intPart));
	else if (dec==3)
		decPart = Math.round(1000*(fixAmt - intPart));
	
	if (decPart == 0)
		decPart = "00";
	if (decPart > 0 && decPart < 10) 
		decPart = "0" + decPart;
	return decPart;
}

//Fixes the amounts so that they contain $ and , in the appropriate places.
function formatMoney(fixAmt)
{
	var Amount="";
	var i, lenA="", newAmt="";
	var dif=0;

	if (fixAmt > 0 )	
	{
		fixAmt = Math.round(100.0 * fixAmt)/100.0;
		lenA = "'"+parseInt(fixAmt)+"'";
		if (isNaN(parseInt(fixAmt)))
			lenA="0";
		decPart = formatDecimal(fixAmt,2);
		
		for (i=lenA.length; i<11; i++)
		{
			fixAmt="0"+fixAmt;
			newAmt="'"+fixAmt+"'";
		}
		subA = newAmt.substr(1, 3);
		subB = newAmt.substr(4, 3);
		subC = newAmt.substr(7, 3);		
		Amount = subA+","+subB+","+subC+"."+decPart;
		for (i=0; i<11; i++)
		{
			if (Amount.charAt(i)!='0' && Amount.charAt(i)!=',')
				break;
		}
		return "$" + Amount.substr(i,11);
	}
	else
	 	return "";
}

function docalc(fieldname,fieldindex)
{
	var grpmtu;  
	var notinclude=0.0, totcpb=0.0; 

  	if (bsingle == 1)
   	    calcform = parent.frames['framesingle'].document.sform;
   	else
   		calcform = parent.frames['frameconsolidation'].document.cform;    	

    cpb=0;
	USAFgrtotpmt=0;
    tempnum=0;
	ispmt=0;
	
    for (var i = 0; i < Math.max(numloans+addnew,1); i++)
    {
    // NS3.x doesn't allow indexing of form fields so fcpb[i].value doesn't work.
  		mcpb[i] = parseMoney(calcform.fcpb[i].value);
        if (mcpb[i] > 0.0) 
        {
	        tempnum=i+1;
			if (myes[i] == 1 || bsingle == 1) 
				cpb=parseFloat(cpb)+parseFloat(mcpb[i]);
			else if (mno[i] == 1)
				notinclude = parseFloat(notinclude)+parseFloat(mcpb[i]);
			else
//		        calcform.myes[fieldindex].focus();
				return "";
        }
		else 
			mcpb[i] = "";
	}
    numloans=tempnum;
    rateyr=0;
    for (i = 0; i < numloans; i++)
    {
    	mrateyr[i] = parseInt(calcform.frateyr[i].value) + "." + formatDecimal(parseFloat("00"+calcform.frateyr[i].value),3);
        if (mrateyr[i] > 0.0 && (myes[i]==1 || bsingle==1))
        {
        	rateyr = rateyr + (mrateyr[i] * mcpb[i]);
    		mcpb[i] = formatMoney(mcpb[i]);
        }
		else
    		mcpb[i] = formatMoney(mcpb[i]);
    }
	lrterm = grterm = isterm = 120.0;
	if(bsingle == 1)
	{
		group2 = .94;
		group3 = .81;
	}

    if ((blevel == 1 || bcomparison == 1) && bsingle == 1)
    {
    	if ((calcform.textshorten.value > 120 && cpb < 30000.00) && (bconsolidation != 1))
			{ 
				msg = "A term of greater than 120 months is not allowed for loan amounts under $30,000.";
				alert(msg);
				calcform.textshorten.value = 120.0;
			}
		    	
    		
    	lrterm = calcform.textshorten.value;
    	lrpmtu = parseMoney(calcform.textlarger.value);
    }
	else
	{
		if (bsingle == 1)
		{
			lrterm = grterm = isterm = 120.0;
			group2 = .94;
			group3 = .81;
		}			
		else
		{
			totcpb = cpb + notinclude;
			if (totcpb < 7500)
			{ 
				lrterm = grterm = isterm = 120;
				group2 = .94;
				group3 = .81;
			}
			if (totcpb >= 7500 && totcpb < 10000) 
			{
				lrterm = grterm = isterm = 144;
				group2 = .96;
				group3 = .87;
			}
			if (totcpb >= 10000 && totcpb < 20000) 
			{
				lrterm = grterm = isterm = 180;
				group2 = .975;
				group3 = .918;
			}
			if (totcpb >= 20000 && totcpb < 40000) 
			{
				lrterm = grterm = isterm = 240;
				group2 = .986;
				group3 = .955;
			}
			if (totcpb >= 40000 && totcpb < 60000) 
			{
				lrterm = grterm = isterm = 300;
				group2 = .992;
				group3 = .974;
			}	
			if (totcpb >= 60000) 
			{
				lrterm = grterm = isterm = 360;
				group2 = .995;
				group3 = .9838;
			}
		}
	}

    if (numloans > 0 && cpb > 0.0) 
	{
		rateyr = rateyr / cpb;
		if (bconsolidation == 1)
		{
			rateyr = Math.ceil(rateyr/.125) * .125;
			if (rateyr > 8.25)
				rateyr = 8.25;
		}
	}	
    
	cpb = Math.round(100.0 * cpb) / 100.0;
    rateyr = Math.round(1000.0 * rateyr) / 1000.0;
    
    if (rateyr > 100.0) 
		rateyr = 100.0;
    if (rateyr < 0.000001) 
		rateyr = 0.0;
    
	rate = rateyr / 1200.0;
    iopmt = Math.round(100.0*(cpb * rate))/100.0;
    
    //  compute payment size using a term of 120 months
    
    //    lrterm = 120.0;
    //	lrpmtu = 61.33;
    if (lrterm > 0)
    	if (rate > 0.0)
        	lrpmtu = cpb * rate / (1.0 - Math.pow((1.0 + rate),(-lrterm)));
    	else
            lrpmtu = cpb / lrterm;
    else
    	if (rate > 0.0)
    		lrterm = -(Math.log(1-(cpb/lrpmtu)*(rate)))/Math.log(1+rate);
    	else
    		lrterm = -(Math.log(1-(cpb/lrpmtu)));
    			
    
    if ((lrterm > 120 && cpb < 30000.00) && (bconsolidation != 1))
	{ 
		msg = "A term of greater than 120 months is not allowed for loan amounts under $30,000.";
		alert(msg);
		calcform.textshorten.value = 120.0;
	    		
       	lrterm = 120.0;

       	if (rate > 0.0)
        	lrpmtu = cpb * rate / (1.0 - Math.pow((1.0 + rate),(-lrterm)));
    	else
            lrpmtu = cpb / lrterm;
    }
    
    	//  if payment is too small, first compute a new, shorter term with payment size of $50, 
    	//  then recompute payment with this smaller term
    if (lrpmtu < 50.0 && cpb > 0.0)
	{
     	if (rate > 0.0)
        {
         	lrterm = Math.max(1.0,Math.floor(-Math.log(1.0-cpb*rate/50.0)/Math.log(1.0+rate)));
            lrpmtu = cpb * rate / (1.0 - Math.pow((1.0 + rate),(-lrterm)));
       	}
        else
        {
            lrterm = Math.max(1.0,Math.floor(cpb / 50.0));
       	    lrpmtu = cpb / lrterm;
        }
		astrick = "*";

		if ((lrterm > 120 && cpb < 30000.00) && (bconsolidation != 1))
		{ 
			msg = "A term of greater than 120 months is not allowed for loan amounts under $30,000.";
			alert(msg);
			calcform.textshorten.value = 120.0;
	    		
	       	lrterm = 120.0;

		   	if (rate > 0.0)
				lrpmtu = cpb * rate / (1.0 - Math.pow((1.0 + rate),(-lrterm)));
	    	else
				lrpmtu = cpb / lrterm;
	    }
    }		
	else
		astrick = "";

	lrpmt = Math.round(100.0*lrpmtu)/100.0;
    lrtotpay = Math.round(100.0*lrpmtu*lrterm)/100.0;
    lrtotint = Math.round(100.0*(lrtotpay - cpb))/100.0;
    lrlpmt = Math.round(100.0*(lrtotpay - (parseInt(Math.round(lrterm)-1.0))*lrpmt))/100.0;
    lrterm = Math.round(lrterm);			
	lrpmtu = formatMoney(lrpmtu);
		    
    
	// Income Sensitive Calculations:
    if ((bincome == 1 || bcomparison == 1) && cpb > 0.0)
	{
    	wageyr = parseMoney(calcform.textwages.value);
        if (wageyr > 0)
        	calcform.textwages.value = formatMoney(wageyr);
        else
          	calcform.textwages.value = "";
    
        if (wageyr > 0.0)
       	{
           	wagemo = wageyr / 12.0;
            iopmt = Math.round(100.0*(cpb * rate))/100.0;
       	    wage4p = Math.round(100.0* 0.04 * wagemo) / 100.0;
           	isrpmt = Math.round(100.0 * (iopmt + ((2.0 * (wagemo - 1000.0)/100.0)/lrpmt) * (lrpmt - iopmt))) / 100.0;
            ispmt = isrpmt;
       	    islimit = "monthly income";

	       	if (ispmt < iopmt) {ispmt = iopmt; islimit = "interest only payment";}
    //        if (ispmt < wage4p) {ispmt = wage4p; islimit = "4% of wages";}
       	    isterm=isterm - 12;
    
	   	    isfpb = Math.round(100.0*FV_PmtPvRN(ispmt, cpb, rate, 12))/100.0;
           	isothpmt = Math.round(100.0*PMT_PvFvRN(isfpb, 0.0, rate, (isterm)))/100.0;
    
	        if (isothpmt < 50.0) 
       	    {
           	    isterm = Math.max(1.0,Math.floor(N_PmtPvR(50.0, isfpb, rate)));
               	isothpmt = Math.round(100.0*PMT_PvFvRN(isfpb, 0.0, rate, isterm))/100.0;
            }
       	    istotpmt = Math.round(100.0*(12*ispmt + isterm*isothpmt))/100.0;
           	istotint = Math.round(100.0*(istotpmt - cpb))/100.0;
        }
       	else
           	ispmt=0;
    }	

    // Graduated Repayment Calculations
	if(cpb > 0.0)
	{
		USAFgrpmt1 = Math.round(100.0*PMT_PvFvRN(1.00*cpb, 1.00*cpb, rate, 24))/100.0;
    	USAFgrpmt2 = Math.round(100.0*PMT_PvFvRN(1.00*cpb, group2*cpb, rate, 18))/100.0;
	    USAFgrpmt3 = Math.round(100.0*PMT_PvFvRN(group2*cpb, group3*cpb, rate, 18))/100.0;
    	USAFgrpmt4 = Math.round(100.0*PMT_PvFvRN(group3*cpb, 0.00*cpb, rate, grterm - 60))/100.0;
		USAFgrtotamt = cpb;  
	    USAFgrtotpmt = Math.round(100.0*(24.0*USAFgrpmt1 + 18.0*USAFgrpmt2 + 18.0*USAFgrpmt3 + (grterm - 60.0)*USAFgrpmt4))/100.0;
    	USAFgrtotint = Math.round(100.0*(USAFgrtotpmt - cpb))/100.0;
    
    
    	grpmt0 = iopmt;
//    grterm = grterm - 24.0;
    
		if (rate > 0.0)
    		grpmtu = cpb * rate / (1.0 - Math.pow((1.0 + rate),(-(grterm-24.0))));
	    else
    	    grpmtu = cpb / (grterm-24.0);
    
    //  if payment is too small, first compute a new, shorter term with payment size of $50, 
    //  then recompute payment with this smaller term
    
/*	if (grpmtu < 50.0)
   		if (rate > 0.0)
        {
        	grterm = Math.max(1.0, Math.floor(-Math.log(1.0 - cpb*rate/50.0)/Math.log(1.0 + rate)));
            grpmtu = cpb * rate / (1.0 - Math.pow((1.0 + rate),-grterm));
        }
        else
        {
        	grterm = Math.max(1.0, Math.floor(cpb / 50.0));
            grpmtu = cpb / grterm;
        }
*/    
    	grpmt = Math.round(100.0*grpmtu)/100.0;
	    grtotpay = Math.round(100.0*grpmtu*(grterm-24.0))/100.0;
    	grlpmt = Math.round(100.0*(grtotpay - ((grterm - 24.0 - 1)*grpmt)))/100.0;
	    grtotpay = Math.round(100.0*(24.0*grpmt0 + grtotpay))/100.0;            
    }
    if (cpb <= 0.0)
        cpb = ""; 
        
    if (rateyr <= 0.0)
    	rateyr = "";
    else
    	rateyr = rateyr + "%";
    
    wageyr = parseMoney(wageyr);
	if (wageyr <= 0.0)
    	wageyr = "";
    else
		wageyr = formatMoney(wageyr);
    	
    if (fieldname=='w' && numloans > 0)
    	addnew = 0;
    else
        addnew = 1;
    
	refreshcalcform(bsingle, bconsolidation);

    //    calcform = parent.frames['calculator'].document.formCalc;
    
    //    calcform.textwages.value=calcform.textwages.value+fieldname+fieldindex;
    
  	if (fieldname == 'w')
		if((bincome || bcomparison) && wageyr=="")
			calcform.textwages.focus();
		else
		    calcform.fcpb[0].focus();
    
	if ((fieldname == 'c' || fieldname == 'r') && (fieldindex >= 0 && fieldindex < numloans))
    if (fieldname == 'c')
    	calcform.frateyr[fieldindex].focus();
    else
        calcform.fcpb[fieldindex+1].focus();

    return "";
}


function truncateDecimals(obj, decimals){
	num = obj.value.toString();
	//if ((num.indexOf(".")) == -1)
	//	return num;
		
	if (decimals <= (num.length - num.indexOf(".")))
		obj.value=num.substr(0,num.indexOf(".") + decimals)
		//return (num.substr(0,num.indexOf(".") + decimals + 1));
	//else
	//	return num;
}    

function addFavIcon() {
   var headtg = document.getElementsByTagName('head')[0];
   if (!headtg) {
      return;
   }
   var linktg = document.createElement('link');
   linktg.rel = 'shortcut icon';
   linktg.href = 'http://www.educationquest.org/images/favicon_EQF.ico';
   linktg.type = 'image/x-icon'
   headtg.appendChild(linktg);
}

function showchart(){
	calcframe.write('<table border="0" width="620" cellspacing="5" id="ratetable"><tr style="font-family:arial,sans-serif; font-size:10pt;padding-left:5px" id="ratetblhdr"><td colspan="5"><span style="color:navy;font-weight:bold;font-size:16px;">The Federal Consolidation Loan (or Direct Consolidation Loan)</span><br>This loan simplifies repayment and may lower your monthly payment.  You can combine loans even if you borrowed from more than one lender, or have more than one loan type or guarantor.</td></tr>'+
				'<tr><td colspan="5">')
				if (parent.refsite == "nslp")
					calcframe.write('<tr><td valign="top" style="background-color:#7ac142">');
				else
					calcframe.write('<tr><td valign="top" style="background-color:#DDEEDD">');
				
				calcframe.write('<span style="font-family:arial, sans-serif; font-size:9pt; font-weight: bold">Qualifications:</span></td><td valign="top" style="font-family:arial,sans-serif; font-size:10pt">You must be in your grace period or repayment for any of the following loans:'+
				'<br><i>&nbsp;&nbsp;Federal Stafford Loan (subsidized or unsubsidized)</i>'+
				'<br><i>&nbsp;&nbsp;Health Professions Student Loans (HPSL)</i>'+
				'<br><i>&nbsp;&nbsp;Nursing Student Loan</i>'+
				'<br><i>&nbsp;&nbsp;Health Professions Student Loan (HEAL)</i>'+
				'<br><i>&nbsp;&nbsp;Perkins Loan</i>'+
				'<br><i>&nbsp;&nbsp;PLUS Loan (for parent and grad/professional student)</i>'+
				'<br><i>&nbsp;&nbsp;SLS Loan (formerly ALAS)</i>'+
				'<br><i>&nbsp;&nbsp;National Direct Student Loan (NDSL)</i>'+
				'<br><i>&nbsp;&nbsp;Federally Insured Student Loan (FISL)</i>'+
				'<br><i>&nbsp;&nbsp;Consolidation Loan</i>'+				
				'</td></tr>');
				
				if (parent.refsite == "nslp")
					calcframe.write('<tr><td valign="top" style="background-color:#7ac142">');
				else
					calcframe.write('<tr><td valign="top" style="background-color:#DDEEDD">');
					
				calcframe.write('<span style="font-family:arial, sans-serif; font-size:10pt; font-weight: bold">Interest:</span></td><td valign="top" class="normaltext">Your consolidation interest rate is the weighted average interest rate of all the loans you consolidate, rounded up to the nearest 1/8%, with a maximum rate of 8.25%.  You can choose to consolidate only the loans that will benefit you financially.</td></tr>');
				
				if (parent.refsite == "nslp")
					calcframe.write('<tr><td valign="top" style="background-color:#7ac142">');
				else
					calcframe.write('<tr><td valign="top" style="background-color:#DDEEDD">');
				
				calcframe.write('<span style="font-family:arial, sans-serif; font-size:10pt; font-weight: bold">Fees:</span></td><td valign="top" class="normaltext">None</td></tr>');
				
				if (parent.refsite == "nslp")
					calcframe.write('<tr><td valign="top" style="background-color:#7ac142">');
				else
					calcframe.write('<tr><td valign="top" style="background-color:#DDEEDD">');
				
				calcframe.write('<span style="font-family:arial, sans-serif; font-size:10pt; font-weight: bold">Repayment:</span></td><td valign="top" class="normaltext">Your lender will calculate your repayment schedule based on the balance of your loans.  Use the following table as a guideline.<br>'+
				'<center>'+
					'<table border=0 cellpadding="5">');
						if (parent.refsite == "nslp")
							calcframe.write('<tr><th style="background-color:#7ac142">');
						else
							calcframe.write('<tr><th style="background-color:#DDEEDD">');
						
						calcframe.write('Total Student Loan Debt</th><td>&nbsp;&nbsp;&nbsp;</td>');
						
						if (parent.refsite == "nslp")
							calcframe.write('<th style="background-color:#7ac142">');
						else
							calcframe.write('<th style="background-color:#DDEEDD">');
						
						calcframe.write('Repayment Period</th></tr>'+
						'<tr><td class="normaltext">Less than $7,500</td><td></td><td class="normaltext" align="center">10 years</td></tr>'+
						'<tr><td class="normaltext">$7,500 - 9,999</td><td></td><td class="normaltext" align="center">12 years</td></tr>'+
						'<tr><td class="normaltext">$10,000 - 19,999</td><td></td><td class="normaltext" align="center">15 years</td></tr>'+
						'<tr><td class="normaltext">$20,000 - 39,999</td><td></td><td class="normaltext" align="center">20 years</td></tr>'+
						'<tr><td class="normaltext">$40,000 - 59,999</td><td></td><td class="normaltext" align="center">25 years</td></tr>'+
						'<tr><td class="normaltext">$60,000 or more</td><td></td><td class="normaltext" align="center">30 years</td></tr>'+
					'</table>'+
				'</center></td></tr>');
				if (parent.refsite == "nslp")
					calcframe.write('<tr><td valign="top" style="background-color:#7ac142">');
				else
					calcframe.write('<tr><td valign="top" style="background-color:#DDEEDD">');
				calcframe.write('<span style="font-family:arial, sans-serif; font-size:10pt; font-weight: bold">Application:</span></td><td valign="top" class="normaltext">To apply for a consolidation loan contact any consolidating lender.  Allow six to eight weeks to process your loan.  If you are in repayment, continue making monthly payments while your consolidation loan is being processed.</td></tr>'+
				'</table>'
				);





}