   message.from = _.find(instances, (obj) -> obj.id is message.from_id)
 
 drawObjects = (instances, messages) ->
-  canvas = document.getElementById("diagram")
+  canvas = $('#diagram')[0]
   return unless canvas
   if instances.length is 0
     canvas.wodth = 0

# ------------------------------

disableOpenImageButton = (flag) ->
  button = document.getElementById("open_button")
  button.disabled = flag

this.openImage = ->
  canvas = document.getElementById("diagram")
  return unless canvas
  window.open(canvas.toDataURL("image/png"))
  return

  this.timerID = setTimeout("this.postRawText()", 1000)

this.postRawText = () ->
  text = "source_text=" + $("#source_text").val()
  if this.lastRawText is text
    setInfoText("")
    return
  disableOpenImageButton(true)
  
  $.ajax({
    type: "POST",
    url: "home/parse_text",
    data: text,
    success: (data) -> 
      fetchRestObjects("instances.json", instancesDidFetched)
    })
  this.lastRawText = text

setInfoText = (text) ->
  $("label#info_label").text(text)
