I'm looking for a loan calculator script to use on a site. I've come across a few, but I need this to work the opposite way round to a typical calculator. On the ones I've seen, you input the amount you want to borrow and the repayment period, and it calculates the total interest and the amount of the weekly or monthly instalments. What I need is one which allows you to input the amount of the weekly or monthly instalment, specify whether that's including or excluding interest, and the script calculates the period of the loan and the total interest payable. (Having two calculators - one for amount including interest and one for amount excluding interest would be fine, if that's easier. )

Any ideas?