 			if $this.data 'persist'
 				store[$this.attr('id')] = $this.val() if $this.val().length > 0
 		localStorage.setItem 'bookITStorage', JSON.stringify store
+
+
+	# dis amount of UX... changes end_date to begin_date if end_date > begin_date
+	$('.booking-dates-container').on 'change', 'input', ->
+		$this = $(@)
+		$other = $('.booking-dates-container input').not($this)
+		begin_date = $('#booking_begin_date')
+		end_date = $('#booking_end_date')
+		if begin_date.val() > end_date.val()
+			if $this.is(begin_date)
+				end_date.val(begin_date.val())
+			else
+				begin_date.val(end_date.val())
+
+setFormValues = (activeRadio) ->
+	fest = $(activeRadio).data 'fest'
+	$('.party-container').toggle fest
+	options = $('option', '#booking_group')
+	options.first().attr('disabled', fest)
+
+	# prevents a person to book rooms only to be booked by groups
+	if options.length > 1
+		$('#booking_group').val(options[1].value)
+	else
+	$('#booking_group')[0].setCustomValidity('Lokalen kan ej bokas som privatperson')
+
+
+	# Disable booking_fest if not festrum
+	$('#booking_party').attr('checked', false) unless fest
+
+
+	$('#booking_party').trigger('change')
+	# $('.party-info-container').toggle fest


$ ->
	$('.party-info-container').show() if $('#booking_party').prop('checked')
	$('.location-container').on 'change', 'input[type="radio"]', ->
		fest = $(@).data 'fest'
		$('.party-container').toggle fest

		# Disable booking_fest if not festrum
		$('#booking_party').attr('checked', false) unless fest

		$('#booking_party').trigger('change')
		# $('.party-info-container').toggle fest
	$('#booking_party').on 'change', (e) ->
		$('.party-info-container').toggle @checked
	if window.location.href.match /new/

			$elem = $("\##{name}")
			if $elem.val().length == 0
				$elem.val(value)


	$('form').on 'submit', (e) ->
		return unless window.localStorage
		store = {}
