 key2cache   = (k) -> "#{CACHE_PREFIX}#{k}"
 
 saveData = ->
-  if localStorage?
+  if sessionStorage?
     for k in ["jid", "sid", "rid"] when connection[k]?
-      localStorage[key2cache k] = connection[k]
+      sessionStorage[key2cache k] = connection[k]
 
     for k in ["host", "port", "path"] when connection_options[k]?
-      localStorage[key2cache k] = connection_options[k]
-
-clearData = -> localStorage?.clear()
+      sessionStorage[key2cache k] = connection_options[k]
+
+clearData = -> sessionStorage?.clear()
 
 onConnected = ->
 

attach_connection = (opt) ->

  connection = create_connection_obj()
  connection_options.jid = Strophe.getBareJidFromJid connection_options.jid
  connection.attach connection_options.jid
    , connection_options.sid
    , connection_options.rid


# Loads the connection data from local storage.
restoreData = ->
  if sessionStorage?
    for k in [ "jid", "sid", "rid", "host", "port", "path" ]
      j = key2cache k
      connection_options[k] = sessionStorage[j]  if sessionStorage[j]

hasConnectionData = ->
  opt = connection_options
