$(function() {
    $('#emortgagecalc-capital, #emortgagecalc-rate').autoNumeric({
        aNeg: '',
        aSep: ' ',
        aDec: ',',
		mNum: 9,
		mDec: 2
	});
    $("#emortgagecalc-submit").click(function(){
        var L,P,n,c;
        L = parseInt($("#emortgagecalc-capital").val().replace(/ /g, ''));
        n = parseInt($("#emortgagecalc-time").val()) * 12;
        c = parseFloat($("#emortgagecalc-rate").val().replace(',','.'))/12;
        P = (L*c)/(100*(1-Math.pow((1+c/100),(n*-1))));
        //P = (L*(c*Math.pow(1+c,n)))/(Math.pow(1+c,n)-1);
        if(!isNaN(P))
        {
            $("#emortgagecalc-result").html(P.toFixed(2).replace('.', ','));
        }
        else
        {
            $("#emortgagecalc-result").val('Error');
        }
        return false;
    });

});
