// Helpers for HTML document element:
class HElement
{
   static ById(id: string): HTMLElement {
      return HById.ElementOf<HTMLElement>(id)
   }
   static GetById(id: string): HTMLElement|null {
      return document.getElementById(id)
   }

   static ScriptCurrent(): HTMLElement {
      let scriptTags = document.getElementsByTagName('script')
      if (scriptTags.length == 0)
         throw 'ScriptCurrentElement function must be called from <script> tag.'
      let element = scriptTags[scriptTags.length - 1].parentElement
      if (!element)
         throw 'Unknown element of <script> tag (ScriptCurrentElement function)'
      return element
   }
   static ScriptCurrent_Get(): HTMLElement|null {
      let scriptTags = document.getElementsByTagName('script')
      return scriptTags.length > 0 ?
         scriptTags[scriptTags.length - 1].parentElement :
         null
   }

   static UseClass(element: HTMLElement, className: string, use: boolean) {
      if (use)
         HElement.IncludeClass(element, className)
      else
         HElement.ExcludeClass(element, className)
   }
   static IncludeClass(element: HTMLElement,className: string): boolean {
      var classList = element.classList
      if (!classList.contains(className)) {
         classList.add(className)
         return true
      }
      return false
   }
   static ExcludeClass(element: HTMLElement, className: string): boolean {
      var classList = element.classList
      if (classList.contains(className)) {
         classList.remove(className)
         return true
      }
      return false
   }

   static Focus(element: HTMLElement) {
      element.focus()
   }
   static Click(element: HTMLElement) {
      element.click()
   }
} // HElement
