var payment=0;


function SortNames(){
//Get the name from the text field
P=document.theform.principle.value;
I=document.theform.interest.value;
L=document.theform.length.value;
numbers= new Array("0","1","2","3","4","5","6","7","8","9",".");
var Principle="";
var Interest="";
var Length="";
var P2=0;
var I2=0;
var L2=0;

for(i=0; i<P.length; ++i)
for(j=0; j<11; ++j)
if(P.charAt(i)==numbers[j])
Principle+=P.charAt(i);

for(i=0; i<I.length; ++i)
for(j=0; j<11; ++j)
if(I.charAt(i)==numbers[j])
Interest+=I.charAt(i);

for(i=0; i<L.length; ++i)
for(j=0; j<11; ++j)
if(L.charAt(i)==numbers[j])
Length+=L.charAt(i);

P2=parseFloat(Principle);
I2=parseFloat(Interest);
I2=I2/100;
L2=parseFloat(Length);

var block=Math.pow((1+I2/12),-L2)
payment=P2*(I2/12)/(1-block);
payment=Math.round(payment*100)/100;

document.theform.sorted.value="$"+payment+" per month";


}

function PlaySound(){
var sound=document.getElementById("note_c1");
try{
//Real Player
sound.DoPlay();
} catch(e){
try{
//windows Media/Quicktime
sound.Play();
} catch(e)
{
alert("No sound support.");
}
}
document.theform.sorted.value="Calculating....";


setTimeout ( "SortNames()", 15000 );

}
