   $(".simulator-body").html ""
   $.post(getSimulateURL(), JSON.stringify({ hangup:true })).done (data) ->
 
+appendMessage = (newMessage, ussd=false) ->
+  ussd = if ussd then "ussd " else ""
+  imsgDiv = '<div class=\"imsg ' + ussd + 'to post-message\"></div>'
+  $(imsgDiv).text(newMessage).appendTo(".simulator-body")
+  $("#simulator textarea").val ""
+  $(".simulator-loading").css "display", "block"
+  # $(".simulator-body").css "height", $(".simulator-body").height() - 25
+  $(".simulator-body").scrollTop $(".simulator-body")[0].scrollHeight
 
 #-------------------------------------
 # Event bindings

    processForm newMessage

    # add the progress gif
    if newMessage and newMessage.length <= 160
      $("<div class=\"imsg to post-message\"></div>").text(newMessage).appendTo(".simulator-body")
      $("#simulator textarea").val ""
      $(".simulator-loading").css "display", "block"
      # $(".simulator-body").css "height", $(".simulator-body").height() - 25
      $(".simulator-body").scrollTop $(".simulator-body")[0].scrollHeight

$("#show-simulator").hover ->
  if not moving_sim

  processForm newMessage

  # add the progress gif
  if window.ussd and newMessage.length <= 182
    appendMessage newMessage, true
  else if newMessage.length <= 160
    appendMessage newMessage

# send new message on key press (enter)
$("#simulator textarea").keypress (event) ->
