/*--------------------------------------------------------------------------------
									Konfigurator
--------------------------------------------------------------------------------*/

// Floating-point rounding errors Fix
function Round(_Number, _DecimalPlaces) {
   return Math.round(parseFloat(_Number) * Math.pow(10, _DecimalPlaces)) / Math.pow(10, _DecimalPlaces);
}
function RoundFixed(_Number, _DecimalPlaces) {
   return Round(_Number, _DecimalPlaces).toFixed(_DecimalPlaces);
}

// Init
$(document).ready(function() {
	if($("#grundPris").length) {
		$(".konfiguratorValg").click(function() {
			$(".vis ul.pris").html('<li>'+sum().replace(".",",")+'<span>Dkk</span></li>');
			$(".vis form.options").find("input[name='price']").val(sum());
		});
		$(".vis ul.pris").html('<li>'+sum().replace(".",",")+'<span>Dkk</span></li>');
		$(".vis form.options").children("input[name='pris']").val(sum());
	};
});

// Udregn den totale SUM
function sum() {
	var _sum = new Number($("#grundPris").val());
	$(".checkbox").each(function() {
		if($(this).is(":checked")) {
			_sum = _sum + Number($(this).attr("title"));
		};
	});
	$(".radio").each(function() {
		if($(this).is(":checked")) {
			_sum = _sum + Number($(this).attr("title"));
		};
	});
	$(".select option").each(function() {
		if($(this).is(":selected")) {
			_sum = _sum + Number($(this).attr("title"));
		};
	});
	_total = RoundFixed(_sum,2);
	return _total;
}
