$(document).ready(function(){

	$(".offerte_aanvraag").click(function(){

		var arr_arrangement = $(this).attr("id").split('offerte_aanvraag_');
		var arrangement = arr_arrangement[1];

		$.ajax({
			type: "POST",
			url: "/"+taal+"/private/helpers/ajax_arrangementen.php",
			data: 'arrangement='+arrangement+'&action=get_arrangement',
			dataType: "html",
			success: function(result)
			{
                            switch(taal){
                                case 'nl':
                                    window.location = '/'+taal+'/arrangementen/stap1/set/'+arrangement;
                                    break;
                                case 'de':
                                    window.location = '/'+taal+'/arrangements/schritt1/set/'+arrangement;
                            }
				
			}
		});

	});

	$(".number_persons").blur(function(){

		var aantal_pers_new = parseFloat($(this).val());
		var total = 0;

		$(".act_ppa").each(function(){
			var arrId = $(this).attr('id').split('_');
			var actId = arrId[2];

			var price_pp = $(this).val();

			price_pp = price_pp.replace(',','.');
			price_pp = parseFloat(price_pp);

			var subtotal = parseFloat(price_pp * aantal_pers_new);
			total = total + subtotal;

			subtotal = Math.round(subtotal * 100) / 100;
			subtotal = subtotal.toFixed(2);

			subtotal = subtotal.replace('.',',');

			price_pp = price_pp.toFixed(2);
			price_pp = price_pp.replace('.',',');


			$("#act_sub_tot_"+actId).html('&euro; '+subtotal);
			$("#act_nr_pers_"+actId).html('Aantal pers: '+aantal_pers_new+' pers.');

			$("#act_pers_"+actId).val(aantal_pers_new);
		});

		var total_price_pp = 0;
		total_price_pp = total / aantal_pers_new;

		total = Math.round(total * 100) / 100;
		total = total.toFixed(2);
		total = total.replace('.',',');


		total_price_pp = Math.round(total_price_pp * 100) / 100;
		total_price_pp = total_price_pp.toFixed(2);
		total_price_pp = total_price_pp.replace('.',',');


		$(".act_totalp").val(total);

		$("#totaal_prijs").html("&euro; "+total);

		$("#totaal_prijs_pp").html("&euro; "+total_price_pp);
	});

});