function output_toc()
{
var html='';

html=html+'<div class="toc_list">';
html=html+'<span class="title">'+calcConfig['definitions_headline_toc']+'</span><ul>';
html=html+'<li>'+calcConfig['definitions_loan_payment_toc']+'</li>';
html=html+'<li>'+calcConfig['definitions_loan_amount_toc']+'</li>';
html=html+'<li>'+calcConfig['definitions_loan_term_toc']+'</li>';
html=html+'</ul>';
html=html+'</div>';

return html;
}

/* BEGIN GENERAL LOAN PAYMENT */
function loan_payment(formTitle,isDownPayment)
{
var html='';

html=html+'<form action="#"><strong class="title">'+formTitle+'</strong><input type="hidden" name="loan_payment" id="loan_payment" value="1" />';
html=html+calcConfig['definitions_loan_amount_formfield'];
if(isDownPayment)
{
html=html+calcConfig['definitions_loan_down_formfield'];
}
else
{
html=html+'<input type="hidden" name="loan_down" id="loan_down" value="0" />';
}
html=html+calcConfig['definitions_loan_term_formfield'];
html=html+calcConfig['definitions_loan_rate_formfield'];
html=html+calcConfig['definitions_loan_payment_calculate']+'</form>';

html=html+'<div id="calc_answer"></div>';

var object=document.getElementById("calc_content");
object.innerHTML=html;
}

function loan_payment_calculate()
{
loan_validate();

if(loanRate==0)
{
loanPayment=loanAmount/loanTerm;
}
else
{
loanPayment=(loanRate+(loanRate/(Math.pow((1+loanRate),(loanTerm))-1)))*loanAmount;
}
loanPayment = loanPayment*100;loanPayment=Math.round(loanPayment);loanPayment=loanPayment/100;


if(isNaN(loanPayment) || loanPayment==Infinity){
document.getElementById("calc_answer").innerHTML='<div class="error">'+calcConfig['definitions_loan_payment_error']+'</div>'
}
else
{
document.getElementById("calc_answer").innerHTML='<span>Payment: </span><strong>$'+loanPayment+'</strong><em> per month</em>';
}
}
/* END GENERAL LOAN PAYMENT */

/* BEGIN GENERAL LOAN AMOUNT */
function loan_amount(formTitle,isDownPayment)
{
var html='';

html=html+'<form action="#"><strong class="title">'+formTitle+'</strong><input type="hidden" name="loan_down" id="loan_down" value="0" /><input type="hidden" name="loan_amount" id="loan_amount" value="1" />';
if(isDownPayment)
{
html=html+calcConfig['definitions_loan_down_formfield'];
}
else
{
html=html+'<input type="hidden" name="loan_down" id="loan_down" value="0" />';
}
html=html+calcConfig['definitions_loan_payment_formfield'];
html=html+calcConfig['definitions_loan_term_formfield'];
html=html+calcConfig['definitions_loan_rate_formfield'];
html=html+calcConfig['definitions_loan_amount_calculate']+'</form>';
html=html+'<div id="calc_answer"></div>';

var object=document.getElementById("calc_content");
object.innerHTML=html;
}

function loan_amount_calculate()
{
loan_validate();

if(loanRate==0)
{
loanAmount=loanTerm*loanPayment;
}
else
{
loanAmount = loanPayment/(loanRate+(loanRate/(Math.pow((1+loanRate),(loanTerm))-1)));
}
loanAmount = loanAmount*100;loanAmount=Math.round(loanAmount);loanAmount=loanAmount/100;


if(isNaN(loanAmount) || loanAmount==Infinity){
document.getElementById("calc_answer").innerHTML='<div class="error">'+calcConfig['definitions_loan_amount_error']+'</div>'
}
else
{
document.getElementById("calc_answer").innerHTML='<span>Amount: </span><strong>$'+loanAmount+'</strong>';
}
}
/* END GENERAL LOAN AMOUNT */

/* BEGIN GENERAL LOAN TERM */
function loan_term(formTitle,isDownPayment)
{
var html='';

html=html+'<form action="#"><strong class="title">'+formTitle+'</strong><input type="hidden" name="loan_term" id="loan_term" value="1" />';
html=html+calcConfig['definitions_loan_amount_formfield'];

if(isDownPayment)
{
html=html+calcConfig['definitions_loan_down_formfield'];
}
else
{
html=html+'<input type="hidden" name="loan_down" id="loan_down" value="0" />';
}
html=html+calcConfig['definitions_loan_payment_formfield'];
html=html+calcConfig['definitions_loan_rate_formfield'];
html=html+calcConfig['definitions_loan_term_calculate']+'</form>';

html=html+'<div id="calc_answer"></div>';

var object=document.getElementById("calc_content");
object.innerHTML=html;
}

function loan_term_calculate()
{
loan_validate();


if(loanRate==0)
{
loanTerm=loanAmount/loanPayment;
}
else
{
loanTerm=(Math.log(1+(loanRate/(loanPayment/(loanAmount)-loanRate)))/Math.log(1+loanRate));
}
//loanTerm=loanTerm*1000;
loanTerm=Math.round(loanTerm);
//loanTerm=loanTerm/1000;

if(isNaN(loanTerm) || loanTerm==Infinity){
document.getElementById("calc_answer").innerHTML='<div class="error">'+calcConfig['definitions_loan_term_error']+'</div>'
}
else
{
document.getElementById("calc_answer").innerHTML='<span>Term: </span><strong>'+loanTerm+' months</strong>';
}
}
/* END GENERAL LOAN TERM */

function loan_validate(){
loanAmount = document.getElementById('loan_amount').value;
loanDown = document.getElementById('loan_down').value;
loanTerm = document.getElementById('loan_term').value;
loanRate = document.getElementById('loan_rate').value;
loanPayment = document.getElementById('loan_payment').value;
if(isNaN(Number(loanAmount)) || isNaN(Number(loanDown)) || isNaN(Number(loanTerm)) || isNaN(Number(loanRate)) || isNaN(Number(loanPayment))){ document.getElementById("calc_answer").innerHTML='<div class="error"><strong>Invalid Entry - Please check your numbers.</strong></div>'; return 0; }

if(loanRate!=0){loanRate=loanRate/1200;}


loanAmount=loanAmount-loanDown;
if(loanAmount<=0 || loanDown<0 || loanTerm<=0 || loanPayment<=0 || loanRate<0 || loanRate>=1){ document.getElementById("calc_answer").innerHTML='<div class="error">'+calcConfig['definitions_loan_generic_error']+'</div>'; return 0; }
return 0;
}

