$(document).ready(function(){

	$('#myList').listnav();
	$(".max_hyp_amount").inputInteger();
	
	$("#bm1").keyup(function(){
		calc_max_hypotheek();
	});
	
	$("#bm2").keyup(function(){
		calc_max_hypotheek();
	});
});

function calc_max_hypotheek()
{
	var bm1 = $("#bm1").val();
	var bm2 = $("#bm2").val();
	var bm_tot = (bm1*1) + (bm2*1);
	var max_hyp = (bm_tot*1.08*12) * 4.5;
	
	$('#bm_max_hyp').val(max_hyp);
	
	$('#max_hyp').html('&euro; '+display_bedrag(max_hyp));
}

function display_bedrag(waarde)
{
	stringbedrag = waarde.toString();
  	stringbedrag = stringbedrag.replace(/\,/, ".");
	bedrag = round_decimals(stringbedrag, 2);
	stringbedrag = bedrag.toString();
	stringbedrag = stringbedrag.replace(/\./, ",");
	return stringbedrag;
}

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {
    var value_string = rounded_value.toString()
    var decimal_location = value_string.indexOf(".")
	if (decimal_location == -1) {
        decimal_part_length = 0
		value_string += decimal_places > 0 ? "." : ""
    }
    else {
		decimal_part_length = value_string.length - decimal_location - 1
    }
	var pad_total = decimal_places - decimal_part_length
	if (pad_total > 0) {
		for (var counter = 1; counter <= pad_total; counter++)
            value_string += "0"
    }
	return value_string;
}




