# require jquery
# require jquery_ujs

toggleCities = (toggler) ->
  toggable.style.display = 'none'
  toggable.style.display = 'block' if toggler.dataset.region == 'sv'

togglers = document.querySelectorAll('[data-region]')
toggable = document.querySelector('[data-city]')
selected = document.querySelector('[data-region]:checked')

toggable.style.display = 'none'
if selected?
  toggleCities(selected)

for toggler in togglers
  toggler.onclick = ->
    toggleCities(this)

numerics = document.querySelectorAll('[data-numeric]')
for numeric in numerics
  numeric.onkeydown = (e) ->
    if ([46, 8, 9, 27, 13, 110].indexOf(e.keyCode) != -1 ||
    (e.keyCode == 65 && (e.ctrlKey == true || e.metaKey == true)) ||
    (e.keyCode >= 35 && e.keyCode <= 40))
      return
    if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 ||
    e.keyCode > 105))
      e.preventDefault()
