	var interest= 0;
	var principle= 0;
	var numPeriods= 0;
	var effIR= 0;

	var amortTime= new Array(0, 0, 0);
	var result= new Array(0, 0, 0);
	var numPayments= new Array(0, 0, 0);
	var numYears= new Array(0, 0, 0);
	var monthPay= new Array(0, 0, 0);
	var totalInt= new Array(0, 0, 0);

	var amortPeriod= new Array(13);
	for (s= 0; s<= 12; s++)
		amortPeriod[s]= new Array();

	amortPeriod[0]= [0.5, "6 Months"];
	amortPeriod[1]=	[1, "1 Year"];
	amortPeriod[2]=	[2, "2 Years"];
	amortPeriod[3]=	[3, "3 Years"];
	amortPeriod[4]=	[4, "4 Years"];
	amortPeriod[5]=	[5, "5 Years"];
	amortPeriod[6]=	[6, "6 Years"];
	amortPeriod[7]=	[7, "7 Years"];
	amortPeriod[8]=	[10, "10 Years"];
	amortPeriod[9]=	[15, "15 Years"];
	amortPeriod[10]= [20, "20 Years"];
	amortPeriod[11]= [25, "25 Years"];
	amortPeriod[12]= [30, "30 Years"];


	var paymentPeriod= new Array(4);
	for (s= 0; s<= 3; s++)
		paymentPeriod[s]= new Array();

	paymentPeriod[0]= [12, "Monthly (12 Payments a year)"];
	paymentPeriod[1]= [24, "Bi-Monthly (24 payments a year)"];
	paymentPeriod[2]= [26, "Bi-Weekly (26 payments a year)"];
	paymentPeriod[3]= [52, "Weekly (52 payments a year)"];

	function Loan(curForm)
		{
		//var month;

		// Grab the form vars
		var basePrice= parseFloat(curForm.price.value);
		var dpayment= parseFloat(curForm.dpayment.value);
		if(isNaN(dpayment))
			dpayment= 0;
		var yearlyIR= parseFloat(curForm.interest.value);
		//var numYears= parseFloat(curForm.time1.value);

		// Now some prep calcs
		var mortAmount= basePrice- dpayment;

		numPeriods= parseInt(curForm.periods1.value);
		effIR= yearlyIR/ numPeriods;

		// Prep output window
		win02= window.open("", "", "menubar=no,location=no,toolbar=no,resizeable=yes,scrollbars=yes,directories=no");
		win02.window.resizeTo(600,600);

		htmlHeader= '<head> \
						<title>Comparing Savings for Various Amortization Periods</title> \
						<style> \
							body { font: 90% tahoma; } \
							.tableList { color: black; font: 80% tahoma; } \
							.tableList th { background-color: #cfe6f3; } \
							.tableList td { background-color: #e3f3f3; text-align:center} \
						</style> \
					</head> \
					<body bgcolor="#e3eeff"> \
					<html>';
		win02.document.write(htmlHeader);

		// THIS IS STRICTLY FOR TEXT OUTPUT, SO WE CAN PLAY BACK THE USER'S INPUT PAYMENT PERIOD
		for(a=0; a<paymentPeriod.length; a++)
			{
				if(getPaymentPeriod(a,0)== numPeriods)
				{
				//alert("We found the match to numPeriods (" +numPeriods+ ") at position a=" +a);
				method= getPaymentPeriod(a,1);
				break;
				}
			}

		htmlOut= '<h2>Your input data was...</h2> \
				  Purchase price: $' +basePrice+
				 '<br />Downpayment: $' +dpayment+
				 '<br />Mortgaged Amount (the Principal): $' +mortAmount+
				 '<br />Payment Method: ' +method+
				 '<br />Interest rate applied: ' +yearlyIR*100+
				 '% <br /><br /> \
				 <table class="tableList" border="2"> \
				 <tr>	\
				 	<td colspan="5" style="background-color: #00ccff; font: 140% tahoma" height="34" valign="bottom"> \
				 	Results of Amortization Calculations</td> \
				 </tr> \
					<tr> \
						<th width="20%">&nbsp</th> \
						<th width="20%" style="background-color: #cfe6f3"><strong>Amortization period (years)</strong></th> \
					 	<th width="20%">Total number of Payments you will make</th> \
					 	<th width="20%">Each payment will be</th> \
					 	<th width="20%">Total interest you will pay</th> \
					</tr>';

		win02.document.write(htmlOut);


		// Loop through each of the period choices
		var t= 0;
		for(j=0; j< curForm.elements.length; ++j)
			{
			// Only consider those input fields that were of type text. (i.e. ignore input buttons)
			if (curForm.elements[j].type== "select-one")
				{
				timePattern= /time+/;

				if (timePattern.test(curForm.elements[j].name)== true)
					{
					//checkNumeric(document.forms[curForm].elements[j], MAX);
					//alert(curForm.elements[j].value);

					//numPeriods[t]= parseInt(curForm.elements[j].value);
					//numPayments[t]= numYears* numPeriods[t];
					//effIR[t]= yearlyIR/ numPeriods[t];


					numYears[t]= parseFloat(curForm.elements[j].value);
					numPayments[t]= numYears[t]* numPeriods;

					var negmonth= -1* numPayments[t];
					var deno= 1- (Math.pow(effIR+ 1,negmonth));
					var numo= effIR;

					result[t]= numo/ deno;
					monthPay[t]= mortAmount* result[t];

					// Now, while still in here, loop through each of the numPayments loops
					var remainAmount= mortAmount;
					for(y= 1; y<= numPayments[t]; y++)
						{
						interest= remainAmount* effIR;
						principal= monthPay[t]- interest;

						remainAmount= remainAmount- principal;
						interest= Currency(interest);
						principal= Currency(principal);

						totalInt[t]+= parseInt(interest);

						} // end payment loop

					// Assign new values back to HTML form
					htmlOut= '<tr> \
								<th width="140">Method ' +t+ '</th><td>' +numYears[t]+
					         	'<td width="125">' +numPayments[t]+
								'<td width="125">$' +formatCurrency(monthPay[t])+
								'<td width="125">$' +formatCurrency(totalInt[t])+
							'</tr>';

					win02.document.write(htmlOut);
					t++;
					}
				}
			}

		htmlOut= '<tr> \
					 <td colspan="4" height="36">Choosing Method 0 v. Method 1 saves you</td> \
					 <td>$' +Math.abs(totalInt[1]-totalInt[0])+
				 '</tr> \
				  <tr> \
					 <td colspan="4" height="36">Choosing Method 1 v. Method 2 saves you</td> \
					 <td>$' +Math.abs(totalInt[2]-totalInt[1])+
					 '</td> \
				  </tr> \
				</table> \
				<br /> \
				<fieldset> \
					Please note that these calculations are only meant to be an estimate and a guide \
					in helping you to determine your \
					personal terms and requirements when selecting a mortgage from your lender. \
					Your lender may quote you different rates and values, and may consider costs \
					not included in these calculations. \
					Also note that these calculations assume a constant interest rate over the whole \
					of the amortization period.  Your rates may change with each newly negotiated term. \
					Please see our section on the various time periods used in mortgages <a href="http://www.thehomeslink.com/buyers/mortgageTypes.php">here</a>. \
				</fieldset><br /> \
				<div align="center"><img src="/imgs/thehomeslinklogo.gif" alt="theHomeslink.com"></div> \
				</body> \
				</html>';

		win02.document.write(htmlOut);

		} // end loan()



function getAmortPeriod(row, ind)
	{
	return amortPeriod[row][ind];
	}

function getPaymentPeriod(row, ind)
	{
	return paymentPeriod[row][ind];
	}

function check(curForm)
	{
	var dPayment = curForm.dpayment.value;
	var price = curForm.price.value;

	// First two checks on on the string values represented by the price and downpayment
	if(price.indexOf(",") >= 0)
		{
		alert("Please do not put commas in the Purchase Price.");
		return false;
		}

	if(dPayment.indexOf(",") >= 0)
		{
		alert("Please do not put commas in the Down Payment number");
		return false;
		}


	// Now pull the integer values- and check if they are set.
	price= parseInt(price);
	dPayment= parseInt(dPayment);

	// Price cannot be empty
	if( isNaN(price) )
		{
		alert("Please enter a purchase price for your home.");
		return false;
		}

	// Downpayment can be empty, but set it to zero if it is.
	if(isNaN(dPayment))
		dpayment= 0;

	// Downpayment cannot be greater than purchase price
	if(price< dPayment)
		{
		alert("Your downpayment is greater than the purchase price.\nYou can buy the home with cash!");
		return false;
		}

	// And must be >0
	if(price<0 || dPayment<0)
		{
		alert("Please use numbers greater than 0.");
		curForm.price.value= 0;
		curForm.dpayment.value= 0;
		return false;
		}

	return true;
	}



