-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
-
 DAY = 1000 * 60 * 60 * 24
 
 $ ->

  if (days_passed == 1)
    return days_passed + " day from now"
  return days_passed + " days from now"

# character count for statement on discussion:show page
pluralize_characters = (num) ->
  if(num == 1)
    return num + " character"
  else
    return num + " characters"

# display charcaters left
display_count = (num, object) ->
  if(num >= 0)
    $(".character-counter").text(pluralize_characters(num) + " left")
    object.parent().removeClass("error")
  else
    num = num * (-1)
    $(".character-counter").text(pluralize_characters(num) + " too long")
    object.parent().addClass("error")

# character count for 250 characters max
$ ->
  $(".limit-250").keyup(() ->
    $(".error-message").hide()
    chars = $(".limit-250").val().length
    left = 250 - chars
    display_count(left, $(".limit-250"))
  )

 #character count for 150 characters max
$ ->
  $(".limit-150").keyup(() ->
    $(".error-message").hide()
    chars = $(".limit-150").val().length
    left = 150 - chars
    display_count(left, $(".limit-150"))
  )

# adds bootstrap popovers to vote buttons
$ ->

  else 
    $(".date-description").text("")

remove_date_error = ->
  $(".validate-motion-close-date").parent().removeClass("error")
  $(".date-error-message").hide()
