function calculateBooking(changed) {
	var i		= 1;
	var qty		= 0;
	var price	= 0;
	var total	= 0;
	var subtotal=0;
	var delivery=0;
	var discount=0;
	var southAkl=false;
	var suburb	= '';
	var finalTotal = 0;
	var freeDelivery = false;
	
	// If the qty has been changed or not
	if(!changed) changed = false;
	
	// Check free delivery
	if(document.getElementById('free_delivery') && document.getElementById('free_delivery').value == "Yes") freeDelivery = true;
	
	// Total the lines
	while(document.getElementById('quantity_' + i)) {
		total = 0;
		qty = parseInt(document.getElementById('quantity_' + i).value);
		if(document.getElementById('price_day_' + i).checked) {
			price = parseFloat(document.getElementById('price_day_' + i).value);
		} else {
			price = parseFloat(document.getElementById('price_wk_' + i).value);
		}
		if(qty > 0) {
			total = price * qty;
			document.getElementById('total_' + i).className = 'bookingBoxPink';
		} else {
			if(changed) {
				if(confirm("Are you sure you want to delete this item?")) {
					document.getElementById('id_booking_form').submit();
					document.getElementById('total_' + i).className = 'bookingBox';
					break;
				} else {
					document.getElementById('quantity_' + i).value = 1;
					total = price * 1;
					document.getElementById('total_' + i).className = 'bookingBoxPink';
				}
			} else {
				document.getElementById('total_' + i).className = 'bookingBox';
			}
		}
		document.getElementById('total_' + i).innerHTML = formatPrice(total);
		subtotal = subtotal + total;
		i++;
	}
	// Check the delivery options
	var arrSub = document.getElementById('address_suburb').value.split(',');
	suburb = arrSub[0];
	if(document.getElementById('south_auckland').value.indexOf(',' + suburb + ',') >= 0) southAkl = true;
	if(freeDelivery == false || southAkl) { 
		if(arrSub[1]) {
			delivery = formatPrice(arrSub[1]);
			subtotal = subtotal + parseFloat(arrSub[1]);
		} else {
			delivery = 'TBC';
		}
		document.getElementById('price_delivery').innerHTML = delivery;
	} else {
		document.getElementById('price_delivery').innerHTML = 'FREE';
	}
	finalTotal = subtotal;
	//Update the booking totals
	document.getElementById('price_gst').innerHTML = formatPrice((subtotal * 0.125));
	document.getElementById('price_subtotal').innerHTML = formatPrice(subtotal);
	if(document.getElementById('payment_full').checked) {
		// Don't include discount if there is a loyalty code
		if(document.getElementById('loyalty_code').value == '') {
			discount = parseFloat(document.getElementById('booking_discount').value);
			document.getElementById('price_payment_full').innerHTML = formatPrice((subtotal - (subtotal * discount)));
			document.getElementById('price_payment_deposit').innerHTML = '&nbsp;';
			finalTotal = finalTotal - (finalTotal * discount);
		} else {
			document.getElementById('price_payment_full').innerHTML = formatPrice(0);
			document.getElementById('price_payment_deposit').innerHTML = '&nbsp;';
		}
		// Add the bond
		finalTotal = finalTotal + parseFloat(document.getElementById('price_payment_bond').value);
	} else {
		document.getElementById('price_payment_deposit').innerHTML = formatPrice(50);
		document.getElementById('price_payment_full').innerHTML = '&nbsp;';
		finalTotal = 50;
	}
	// Final total
	document.getElementById('booking_total').innerHTML = formatPrice(finalTotal);
}

function formatPrice(value) {
	returnNumber = value;
	// Add in decimals if there is at least one
	if(String(returnNumber).indexOf('.') > 0) {
		lowValue=Math.floor(value);
		var p=100*(value-lowValue)+0.6;
		
		if(p>99.99) {
			returnNumber = lowValue + 1;
			returnNumber +=".00";
		} else {
			returnNumber=lowValue+".";
			returnNumber+=Math.floor(p/10);
			returnNumber+=Math.floor(p%10);
		}
	}
	return '$' + returnNumber;
}