
function atbRate($name, $period, $code,$rate ,$interest,$amount)
{

this.name = $name;

this.period = $period;

this.code = $code;
this.amount = $amount;
this.rate = $rate;
this.interest = $interest;
this.factor = this.calcFactor();
}

function calculateRepayment()
{
	return(this.round(this.amount*this.factor,2));
}

function calcFactor()
{
	var $factor = 0;
    if(this.interest)
    {
	    ifactor = 1 + this.rate/100;
	    $in = Math.pow(ifactor,(1/12));
	    $factor = Math.pow($in,this.period)*($in - 1)/(Math.pow($in,this.period)-1);
    }else{
    	$factor = 1/this.period;
    }
    return($factor);
}
atbRate.prototype.calculateRepayment = calculateRepayment;
atbRate.prototype.calcFactor = calcFactor;
atbRate.prototype.round = xfRound;
function getItemByCode(r,$code)
{
	for(i=0; i< r.length;i++)
	{
	    if(r[i].code == $code)
	    {
	        return(r[i]);
	    }
	}
    return(false)
}
function xfRound($test,$digits)
{
	$test = $test * Math.pow(10,$digits);
	$test = Math.floor($test);
	$test = $test/Math.pow(10,$digits);
	return($test);
}
function xRound($test,$digits)
{
	$test = $test * Math.pow(10,$digits);
	$test = Math.round($test);
	$test = $test/Math.pow(10,$digits);
	return($test);
}
