function calculatePaymentInfo(formElements) {

    // Get the user's input from the form. Assume it is all valid.
    // Convert interest from a percentage to a decimal, and convert from
    // an annual rate to a monthly rate. Convert payment period in years
    // to the number of monthly payments.
    var principal = formElements["principal"].value;
    var interest = formElements["interest"].value / 100 / 12;
    var payments = formElements["years"].value * 12;

    // Now compute the monthly payment figure, using esoteric math.
    var x = Math.pow(1 + interest, payments);
    var monthly = (principal * x *interest)/(x-1);

    // Check that the result is a finite number. If so, display the results
    if (!isNaN(monthly) && 
        (monthly != Number.POSITIVE_INFINITY) &&
        (monthly != Number.NEGATIVE_INFINITY)) {

        formElements["payment"].value = formatNumber(monthly,2,',','.','','','-','');
		formElements["total"].value = formatNumber(monthly * payments,2,',','.','','','-','');
        formElements["total_interest"].value = 
            formatNumber((monthly * payments) - principal,2,',','.','','','-','');
    }
    // Otherwise, the user's input was probably invalid, so don't
    // display anything.
    else {
        formElements["payment"].value = "";
        formElements["total"].value = "";
        formElements["total_interest"].value = "";
    }
}

//http://www.gufamily.net/next/loanCalc.html
