   (set! ModulesSelected {})
   (set! ModulesSelectedOrder [])
   (select2/select2-box-set-val select2/$Select2-Box (array))
-  (aset (aget js/document "location") "hash" ""))
+  (set-document-location-hash! ""))

   (sort-PreToUrlHashLessonGroup-seq
     (get-PreToUrlHashLessonGroup-seq-for-selected-module moduleCode))})

(defn- set-document-location-hash-based-on-modules-order!
  "Sets document.location.hash based on the `ModulesSelectedOrder` global."
  []

        (map #(get-PreToUrlHashModule-for-selected-module %1)
             ModulesSelectedOrder)]
    (.log js/console (str "ModulesSelectedOrder = " (.stringify js/JSON (clj->js ModulesSelectedOrder))))
    (set-document-location-hash!
      (clojure.string/join "&"
                           (map #(preToUrlHashModule-to-url-hash-string %1)
                                preToUrlHashModuleSeq)))))

(defn- update-document-location-hash-with-new-module
  "Updates document.location.hash with the `PreToUrlHashModule` of a
   newly added module."
  [preToUrlHashModule]
  (let [orgUrlHash    (get-document-location-hash)

        moduleUrlHash
        (preToUrlHashModule-to-url-hash-string preToUrlHashModule)]
    (.log js/console (str "orgUrlHash = \"" orgUrlHash "\""))
    (.log js/console (str "preToUrlHashModule = " (.stringify js/JSON (clj->js preToUrlHashModule))))
    (set-document-location-hash!
      (str orgUrlHash (if (empty? orgUrlHash) "" "&") moduleUrlHash))))

(defn- remove-module-from-document-location-hash
  "Removes a module from `document.location.hash`"
  [moduleCode]
  (let [orgUrlHash (get-document-location-hash)

        urlHashWithoutModule
        (clojure.string/replace
          orgUrlHash
          (re-pattern (str moduleCode "_[A-Z]{1,3}=[^&]+&?")) "")]
    (set-document-location-hash!
      (clojure.string/replace urlHashWithoutModule #"&$" ""))))

(defn- update-document-location-hash-with-changed-lesson-group
  "Updates a module's lesson type in `document.location.hash` with a changed
   changed lesson group."
  [moduleCode lessonTypeLongForm newLessonGroup]
  (let [orgUrlHash (get-document-location-hash)
        lessonType (Lesson-Type-Long-To-Short-Form lessonTypeLongForm)
        newUrlHash (clojure.string/replace
                     orgUrlHash
                     (re-pattern (str moduleCode "_" lessonType "=[^&]+"))
                     (str moduleCode "_" lessonType "=" newLessonGroup))]
    (set-document-location-hash! newUrlHash)))

(def ^{:doc "Vector of <tBody> objects representing the days of the timetable
             in the Timetable Builder page"
