
function setValue(inputId, value) {
	var inputSelector = document.getElementById(inputId);
	if(inputSelector) {
		inputSelector.value = value;
	}
}

function updatePrice() {
	var basePrice = document.getElementById('basePrice');
	var price = document.getElementById('price');
	var priceQuantity = document.getElementById('priceQuantity');

	var nextPrice = 0;

	var currentPrice = document.getElementById('currentPrice');

	var heightSelector = document.getElementById('heightSelector');

	var quantitySelector = document.getElementById('quantity');

	if(heightSelector) {
		var highPrice	= parseInt(basePrice.value) + parseInt(document.getElementById('7').value);
		var adjustPrice	= parseInt(document.getElementById('6').value);
	}
	
	var adjustments = 0;

	nextPrice = parseInt(basePrice.value);

	// Høyde
	if(heightSelector) {
		if(isNaN(parseInt(heightSelector.value))) {
			heightSelector.value = 247;
		} else {
			heightSelector.value = parseInt(heightSelector.value);
		}
	
	
		if(parseInt(heightSelector.value) <= 247) {
			currentPrice.value = parseInt(basePrice.value)+',-';
	
			if(parseInt(heightSelector.value) < 5) {
				heightSelector.value = 247;
			}
		} else {
			nextPrice = parseInt(highPrice);
			currentPrice.value = parseInt(highPrice)+',-';
	
			if(parseInt(heightSelector.value) > 530) {
				alert('Lengder over 530 cm leveres kun etter avtale. Kontakt oss for tilbud');
				heightSelector.value = 530;
			}
	
			if(parseInt(heightSelector.value) > 260) {
				adjustments = Math.ceil((parseInt(heightSelector.value)-260) / 10);
			}
		}
	
		if(adjustments > 0) {	
			nextPrice += parseInt(adjustments * adjustPrice);
			currentPrice.value = parseInt(nextPrice)+',-';
		}
	} else {
		nextPrice = parseInt(basePrice.value);
	}

	for(var i = 0; i <= 100; i++) {
		var optionGroup = document.getElementById('og'+i);
		if(optionGroup) {
			nextPrice += parseInt(optionGroup.value);
		}
	}

	for(var i = 0; i <= 100; i++) {
		var option = document.getElementById(i);
		if(option && option.checked) {
			nextPrice += parseInt(option.value);
		}
	}

	price.value = nextPrice + ',-';
	priceQuantity.value = parseInt(nextPrice * parseInt(quantitySelector.value)) + ',-';
}
