

<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//change default year from 10 to 20yr. period.
j_term = 20;

//change jrate to change the interest rate.
jrate = 7.11;

function sval(num)
{
	j_term = num;
}

// variables
	totalProject = 0;
	bankTerm = 0;
	bankRate = 0;
	jterm = 0;
	bankLoan = 0;
	jloan = 0;
	equilty = 0;
	bankPayments = 0;
	jpayments = 0;
	totalPayments = 0;

	sfee = 0;
	cfee = 0;
	ffee = 0;
	lfee = 0;
	ufee = 0;
	tfee = 0;

//YO
function custRound(x,places) {
	return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places)
}


function FillForm(form)
{	// error checking //


	totalProject = strip_commas(form.totalproject.value);
	if (!checkNumber(totalProject,"Total Project"))
		return false;

	bankTerm = strip_commas(form.bankloanterm.value);

	if(bankTerm < 10)
	{
		alert("Loan Term must be at least 10 years!")
		return false;
	}


	if (!checkNumber(bankTerm,"Loan Term"))
		return false;

	bankRate = strip_commas(form.bankloanrate.value);
	if (!checkNumber(bankRate,"Bank Rate"))
		return false;

	jterm = j_term;

	bankLoan = (0.5 * totalProject);
	jloan = (0.4 * totalProject);
	if(jloan > 971000)
	{
		bankLoan += (jloan-971000);
		jloan = 971000;
	}
	equilty = (0.1 * totalProject);
	sfee = (bankLoan+jloan)*(0.005);
	cfee = (jloan)*(0.015);
	ffee = (jloan)*(0.0025);
	lfee = 1500.00;
	ufee = custRound(((sfee+cfee+ffee+lfee+jloan)/0.995),-3)*(0.005)
	tfee = sfee+cfee+ffee+lfee+ufee;



	i = bankRate / 100;
	if( i > 0){
	     i = i / 12;
	     n = bankTerm * 12;
		 tmp = (1/i) * (1 - Math.pow(1/(1+i), n));
		 tmp = bankLoan / tmp;
		 tmp = Math.round(tmp*100) / 100;
	     bankPayments = tmp;
	}

	i = jrate / 100;
		if( i > 0){
		     i = i / 12;
		     n = jterm * 12;
			 tmp = (1/i) * (1 - Math.pow(1/(1+i), n));
			 tmp = custRound((jloan+(tfee-(0.005*bankLoan))),-3)/tmp;
			 tmp = Math.round(tmp*100) / 100;
		     jpayments = tmp;

		     if(jloan < 971000)
		     {
		     	jpayments += 8.62
		     }else if(jloan == 971000)
		     {
		     	jpayments += 8.61
		     }

	}
	totalPayments = jpayments+bankPayments;

	form.totaljccdcloan.value = put_commas(jloan);
	form.totalbankloan.value = put_commas(bankLoan);
	form.equilty.value = put_commas(equilty);

	form.guaranteefee.value = put_commas(sfee);
	form.packagefee.value = put_commas(cfee);
	form.fundingfee.value = put_commas(ffee);
	form.legalcost.value = put_commas(lfee);
	form.underwriting.value = put_commas(ufee);
	form.onetimefeestotal.value = put_commas(tfee);
	form.paybank.value = put_commas(bankPayments);
	form.payjccdc.value = put_commas(jpayments);
	form.paytotal.value = put_commas(totalPayments);

}

function checkNumber(input,field)
{
	// blank field reset to default value.
	if (input == '') {
		alert("You must enter data for the field " + field)
		return false;
	}

	// remove any user added commas
	input = strip_commas(input);

	// place a warning on the status line if the field contains invalid data
	msg ="This field requires numeric data: " + input;
	var str = new String(input);
	for (var i = 0; i < str.length; i++) {
		var ch = str.substring(i, i + 1)
	   	if ((ch < "0" || "9" < ch) && ch != '.') {

			alert(msg);
			return false;
			status=msg;
		}
	}
	return true;
}

function add_input(input,form1,form2) {
	var total1;
	total1=(form1.price.value*1)
}

// Make a number a nice comma delimited number.
function put_commas(input) {
	var result, len;
	input += "";

	// Locate the decimal point if any.
	len = input.indexOf(".");
	if (len == -1) {
		len = input.length;
		result = ".00";
	} else if(len == 3) {
		result = input.substring(len, len+3) + "0";
	}else {
		result = input.substring(len, len+3);
	}

	// 3 characters at a time through the integer portion.
	while (len > 3) {
		result = input.substring(len-3, len) + result;
		result = "," + result;
		len -= 3;
	}

	// Add any remaining characters.
	result = "$" + input.substring(0, len) + result;
	return result;
}

// Remove all commas from a passed string.
function strip_commas(input) {
        var newnum;
        var ch;
	var newinp = new String(input)
        newnum ="";
        for(var i=0; i<newinp.length; i++) {
                ch = newinp.charAt(i);
                if(ch != ",") {
                        newnum += ch;
                }
        }
        return parseFloat(newnum);
}

function checkNumPeriods(input) {
        input.value = strip_commas(input.value);
        input.value = parseFloat(input.value);
//        input.value = parseInt(input.value);
        if(input.value == null ||
         input.value.length == 0 ||
           input.value == "NaN") {
                input.value = "";
        }
        else {
                if(parseFloat(input.value) <= 0) {
                        input.value = "";
                }
        }
        calcMonthly(input.form);
        input.value = put_commas(input.value);
}

function checkTotal(input) {
        input.value = strip_commas(input.value);
        input.value = parseFloat(input.value);
        if(input.value == null ||
         input.value.length == 0 ||
           input.value == "NaN") {
                input.value = "";
        }
        else {
                if(parseFloat(input.value) < 0) {
                        input.value = "";
                }
        }
        calcMonthly(input.form);
        input.value = put_commas(input.value);
}

// Verify the interest rate is a reasonable number, or set it to one.
function checkInterest(input) {
	input.value = parseFloat(input.value);
	if (input.value == null ||
	    input.value.length == 0 ||
	    input.value == "NaN" ||
	    input.value < 0 ||
	    input.value > 100) {
		input.value = 9;
	}
	calcMonthly(input.form);
}

function calcMonthly(input) {
        if(input.interest.value == "" ||
           input.nper.value == "" ||
           input.loan.value == "") {
                input.monthly.value = "";
        }
        else {
				i = strip_commas(input.interest.value) / 100;
                if( i > 0){
        	        i = i / 12;
                	n = strip_commas(input.nper.value) * 12;
	                tmp = (1/i) * (1 - Math.pow(1/(1+i), n));
	                tmp = strip_commas(input.loan.value) / tmp;
	                tmp = Math.round(tmp*100) / 100;
	                input.monthly.value = put_commas(tmp);
	                if(input.monthly.value == null ||
	                 input.monthly.value.length == 0 ||
	                   input.monthly.value == "NaN") {
        	                input.total.value = "";
                	}
		} else {
			nummonths  = strip_commas(input.nper.value) * 12;
			loanamount = strip_commas(input.loan.value);

			monthlypayment = Math.round((loanamount / nummonths)*100) / 100;
			input.monthly.value = put_commas(monthlypayment);
		}

        }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  var vw = window.open(theURL,winName,features);
  var pinfo = String();

//Each pinfo has to be done on one line.
  pinfo = "<head>\n <title>Printable Rates</title>\n</head>\n <body bgcolor=#FFFFFF leftmargin=15 topmargin=0 marginwidth=0 marginheight=0>";

//This actually puts the information into the printable page or new window
  pinfo += "<b>Total Project: </b>" + put_commas(totalProject) + "<BR><BR>\n";
  pinfo += "Bank Loan Term: " + bankTerm + " years<BR>\n";
  pinfo += "Bank Loan Rate: " + bankRate + "%<BR>\n";
  pinfo += "Citywide Loan Term: " + jterm + "years <BR><BR>\n";
  pinfo += "<b>Project Structure</b><BR>\n";
  pinfo += "Bank Loan: " + put_commas(bankLoan) + "<BR>\n";
  pinfo += "Citywide Loan: " + put_commas(jloan) + "<BR>\n";
  pinfo += "Equity: " + put_commas(equilty) + "<BR><BR>\n";
  pinfo += "<b>Payments</b><BR>\n";
  pinfo += "Bank Payments " + put_commas(bankPayments) + "/month<BR>\n";
  pinfo += "Citywide Payments " + put_commas(jpayments) + "/month<BR>\n";
  pinfo += "Total Payments " + put_commas(totalPayments) + "/month<BR><BR>\n";
  pinfo += "<b>One Time Fees</b><BR>\n";
  pinfo += "SBA Guarantee Fee: " + put_commas(sfee) + "<BR>\n";
  pinfo += "Citywide Packaging Fee: " + put_commas(cfee) + "<BR>\n";
  pinfo += "Funding Fee : " + put_commas(ffee) + "<BR>\n";
  pinfo += "Legal Cost: " + put_commas(lfee) + "<BR>\n";
  pinfo += "Underwriting Fee: " + put_commas(ufee) + "<BR>\n";
  pinfo += "Total Fee: " + put_commas(tfee) + "<BR><BR>\n";
  pinfo +=  "Citywide Development Corp.<BR>Suite 3<BR> 7628 State Ave.<BR>Kansas City, KS 66112<BR>(913) 788-9884";
  vw.document.write(pinfo);
  vw.document.close();
}
//-->
