poller = () ->
  $.getJSON("<%= Rails.application.routes.url_helpers.join_dynamic_path %>",
    (data, textStatus) ->
      if data["ready"]
        adjust_page(data["step"], data["body"], data["explanation"])
      if data["keep_polling"]
        setTimeout(poller, 200)
  )

<%# Include a helper for the header styles below %>
<% environment.context_class.instance_eval { include JoinHelper } %>

adjust_page = (step, body, explanation) ->
  for i in [1,2,3]
    if i == step
      if body
        node = $("#body#{i} > .contents")
        node.empty()
        node.append(body)
      if explanation
        node = $("#explanation#{i} > .contents")
        node.empty()
        node.append(explanation)
      $("#header#{i}").removeClass("<%= inactive_header_style %>")
      $("#header#{i}").addClass("<%= active_header_style %>")
      $("#body#{i}").removeClass("hidden")
      $("#explanation#{i}").removeClass("hidden")
    else
      $("#header#{i}").removeClass("<%= active_header_style %>")
      $("#header#{i}").addClass("<%= inactive_header_style %>")
      $("#body#{i}").addClass("hidden")
      $("#explanation#{i}").addClass("hidden")

$(document).ready ->
  setTimeout(poller, 200)

poller = () ->
  $.getJSON("<%= Rails.application.routes.url_helpers.join_dynamic_path %>",
    (data, textStatus) ->
      if data["ready"]
        adjust_page(data["step"], data["body"], data["explanation"])
      if data["keep_polling"]
        setTimeout(poller, 200)
  )

<%# Include a helper for the header styles below %>
<% environment.context_class.instance_eval { include JoinHelper } %>

adjust_page = (step, body, explanation) ->
  for i in [1,2,3]
    if i == step
      if body
        node = $("#body#{i} > .contents")
        node.empty()
        node.append(body)
      if explanation
        node = $("#explanation#{i} > .contents")
        node.empty()
        node.append(explanation)
      $("#header#{i}").removeClass("<%= inactive_header_style %>")
      $("#header#{i}").addClass("<%= active_header_style %>")
      $("#body#{i}").removeClass("hidden")
      $("#explanation#{i}").removeClass("hidden")
    else
      $("#header#{i}").removeClass("<%= active_header_style %>")
      $("#header#{i}").addClass("<%= inactive_header_style %>")
      $("#body#{i}").addClass("hidden")
      $("#explanation#{i}").addClass("hidden")

$(document).ready ->
  setTimeout(poller, 200)
  history.replaceState(null, null, "<%= Rails.application.routes.url_helpers.join_path %>")

Remove ?code from the url on the /join url.
Remove ?code from the url on the /join url.
