// JavaScript Document

function stripAlphaChars(pstrSource) 
{ 
var m_strOut = new String(pstrSource); 
    m_strOut = m_strOut.replace(/[^0-9]/g, ''); 

    return m_strOut; 
}


function computeForm(form) {

var i = stripAlphaChars(form.interest.value);

    if (i > 1.0) {

        i = i / 100.0;

        //form.interest.value = i;

    }

     i /= 12;

    var j = 3; //form.minpayperc.value

    if (j > 1.0) {

        j = j / 100.0;

        j = j * 1;

    }

   var prin = stripAlphaChars(form.principal.value);
   
   

   var pmt = 0;

   var prinPort = 0;

   var intPort = 0;

   var count = 0;
    
    accruedInt = 0;
    
    while(prin > 0) {
         if(eval(prin * j) < eval(form.minpaydol.value)) {pmt = eval(form.minpaydol.value); } else { pmt = eval(j * prin); }
                    intPort = eval(i * prin);
                    prinPort = eval(pmt - intPort);
                    prin = eval(prin - prinPort);
                    accruedInt = eval(accruedInt + intPort);
                    count = count + 1
                    if(count > 600) { break; } else { continue;}
                    }

      form.ccInt.value = Math.round(accruedInt);
      form.nPer.value = Math.round(count);
	  if (count >= 12) {
		var years = Math.round(count / 12).toString();
		var final = years.concat(" years");
      	form.years.value = final;
	  }
	  else {
		var months = count.toString();
		var final = months.concat(" months");
		form.years.value = final;
	  }
}



function clearForm(form)

{

    form.principal.value = "";

    form.interest.value = "";

    form.minpaydol.value = "";

    form.minpayperc.value = "";

    form.ccInt.value = "";

    form.nPer.value = "";

    form.years.value = "";

}

// -->

