/**
 * @TODO merge with main when done
 */

var Utils = Utils || {};
/**
 * PMT
 * Returns the constant payment (annuity) for a cash flow with a constant interest rate.
 * @param	float	ir	Interest rate per period
 * @param	int		np	Number of periods
 * @param	float	pv		Present Value
 * @param	float	fv		Future Value
 * @return	float
 */
Utils.pmt = function(ir, np, pv, fv) {
	fv = fv || 0;
	return ( ir * ( pv * Math.pow ( (ir+1), np ) + fv ) ) / ( ( ir + 1 ) * ( Math.pow ( (ir+1), np) -1 ) );
}

Utils.ceil = function(x, precision) {
	var p = parseInt(precision) || 0;
	if(p > 0) {
		var y = Math.pow(10, p);
		return Math.ceil(x*y)/y;
	} else {
		return Math.ceil(x);
	}
}






$('#calculatorEditForm_').each(function() {
	/*
	$('form#app-calculator .buttonset input:radio, form#app-calculator select#calculator_pid').change(function(){
		$('form#app-calculator').submit();
	});
	*/
	
	//$('.has-datepicker input:text').datepicker({changeMonth:true,changeYear:true,dateFormat:'yy-mm-dd'});
	
	
	
	
	var currency = $('#app-calc-currency').text();
	var amount = {
		min: $('#app-calc-min-amount_'+currency).text(),
		max: $('#app-calc-max-amount_'+currency).text(),
		step: $('#app-calc-step-amount_'+currency).text()
	};
	var length = {
		min: $('#app-calc-min-length_'+currency).text(),
		max: $('#app-calc-max-length_'+currency).text(),
		step: $('#app-calc-step-length_'+currency).text()
	};
	var $montly_pay = $('#app-calc-monthly-pay');
	var $min_revenue = $('#app-calc-min-revenue');
	

});
