try {
  var _InfoBoxId = '';
  var _MouseX = 0;
  var _MouseY = 0;
  var _MouseFixX = 0;
  var _MouseFixY = 0;
  var _DragAction = '';
  var _DragParam = '';
  var _KeyCode = 0;
  var _LoadTimeStamp;
  var _LoadTimeInterval;

  document.onmousemove = function(e) {
    if (!e)
      e = window.event;
    if (typeof(e.pageX) == 'number') {
      _MouseX = e.pageX;
      _MouseY = e.pageY;
    } else {
      _MouseX = e.clientX + getWindowScrollLeft();
      _MouseY = e.clientY + getWindowScrollTop();
    }
  }
  
  document.onmousedown = function(e) {
    if (_DragAction != '')
      return false;
  }
  
  document.onmouseup = function(e) {
    if (_DragAction != '') {
      eval(_DragAction);
      _DragAction = '';
      _DragParam = '';
      getElemBody().style.cursor = 'auto';
    }
  }

  document.onkeydown = function(e) {
    if (!e)
      e = window.event;
    _KeyCode = typeof(e.which) == 'number' ? e.which : e.keyCode;
  }
  
  document.onselectstart = function(e) {
    if (_DragAction != '')
      return false;
  } 
} catch (Err) {}

function blurText(pObj) {
  chgBgClr(pObj, '#FAFAFA');
}

function chgFlipMen() {
  _FlipMen = !_FlipMen;
  doHttpRequest('plain.php?page=flipmen.dyn&flipmen=' + (_FlipMen ? '1' : '0'), '', '', '');
}

function chgLang(pMsg, pLang) {
  if (confirm(pMsg))
    go('index.php?umi=' + _UMI + '&lang=' + pLang);
  else
    hideLangSelect();
}

function chgModus() {
  hideInfoBox();
  _FullScreen = !_FullScreen;
  if (_FullScreen) {
    displayElemById('head', 'none');
    displayElemById('mainh', 'none');
    displayElemById('menapp', 'none');
    displayElemById('menmodul', 'none');
    with (document.getElementsByTagName('colgroup')[0])
      removeChild(firstChild);
    imageByName('modus').src = 'global/img/modus0.png';
    setHTML(_Modus[0], 'modus');
    doHttpRequest('plain.php?page=fullscreen.dyn&fullscreen=1', '', '', '');
  } else {
    var Elem = document.createElement('col');
    Elem.setAttribute('width', '153');
    with (document.getElementsByTagName('colgroup')[0])
      insertBefore(Elem, firstChild);
    displayElemById('main', 'none');
    displayElemById('main', 'table-cell');
    displayElemById('head', 'table');
    displayElemById('mainh', 'table-row');
    displayElemById('menapp', 'table-cell');
    displayElemById('menmodul', _FlipMen || getHTML('menmodul') == '' ? 'none' : 'table-cell');
    imageByName('modus').src = 'global/img/modus1.png';
    setHTML(_Modus[1], 'modus');
    doHttpRequest('plain.php?page=fullscreen.dyn', '', '', '');
  }
}

function closeMsgBox(pNum) {
  displayElemById('msgbox' + pNum, 'none');
}

function closeIntroGuide(pMsg) {
  if (confirm(pMsg))
    doHttpRequest('plain.php?page=introguide.dyn&introguide=1', '', '', '');
  displayElemById('introguide', 'none');
}

function colAll(pId, pType) {
  var Elem;
  var S = pId + '0';
  var I = 1;
  while (Elem = elementById(S)) {
    imageByName(S).src = 'global/img/expand' + (pType == '' ? '.gif' : '_' + pType + '.png');
    displayElem(Elem, 'none');
    S = pId + I++;
  }
}

function dragStartScrollResize(pId) {
  _MouseFixY = _MouseY;
  _DragAction = "dragEndScrollResize('" + pId + "');";
  getElemBody().style.cursor = 's-resize';
}

function dragEndScrollResize(pId) {
  var Elem = elementById(pId + '_sub');
  if (Elem) {
    var I = Elem.offsetHeight + _MouseY - _MouseFixY;
    Elem.style.height = (I < 50 ? 50 : I) + 'px';
  }
}

function expcolElem(pId, pDisplay, pType) {
  var Elem = elementById(pId);
  if (Elem) {
    if (Elem.style.display == 'none') {
      imageByName(pId).src = 'global/img/collapse' + (pType == '' ? '.gif' : '_' + pType + '.png');
      fadeElemById(pId, pDisplay);
    } else {
      imageByName(pId).src = 'global/img/expand' + (pType == '' ? '.gif' : '_' + pType + '.png');
      displayElem(Elem, 'none');
    }
    return Elem.style.display != 'none';
  }
  return false;
}

function expAll(pId, pDisplay, pType) {
  var Elem;
  var S = pId + '0';
  var I = 1;
  while (Elem = elementById(S)) {
    imageByName(S).src = 'global/img/collapse' + (pType == '' ? '.gif' : '_' + pType + '.png');
    fadeElemById(S, pDisplay);
    S = pId + I++;
  }
}

function expcolMenApp(pId) {
  var Elem = elementById('menapp' + pId);
  if (Elem)
    fadeElemById('menapp' + pId, Elem.style.display == 'none' ? 'block' : 'none');
}

function expcolMenModul(pObj, pId) {
  var Elem = elementById('menmodul' + pId);
  if (Elem) {
    var B = Elem.style.display == 'none';
    fadeElemById('menmodul' + pId, B ? 'block' : 'none');
    pObj.style.color = B ? '' : 'gray';
  }
}

function expcolIndexPreview(pName, pFunc) {
  var Rows = getDOMTable('index');
  var J = 0;
  for (var I = 0; I < Rows.length; I++) {
    var Cols = Rows[I];
    if (J == 0)
      J = Cols.length - 2;
    if ((I == 1 || Cols.length == 2) && I < Rows.length - 1) {
      var H = Cols[1].getAttribute('colspan');
      var Attr = document.createAttribute('colspan');
      Attr.nodeValue = H == 1 ? J : 1;
      Cols[1].setAttributeNode(Attr);
    }
    for (var H = 0; H < Cols.length; H++)
      if (H > 1)
        displayElem(Cols[H], Cols[H].style.display == 'none' ? 'table-cell' : 'none');
  }
  with (imageByName('preview'))
    if (src.match(/preview_g\.png/))
      src = src.replace(/preview_g\.png/, 'preview.png');
    else
      src = src.replace(/preview\.png/, 'preview_g.png');
  var S = getOptSelValue(formByName('index').elements[pName]);
  if (S == '')
    selIndexPreviewCheck(pName, 0, pFunc);
  else
    eval(pFunc + '(S);');
}

function expMenAppAll() {
  for (var I = 0; I < _Packages.length; I++)
    fadeElemById('menapp' + _Packages[I], 'block');
}

function focusText(pObj) {
  chgBgClr(pObj, '#E4E7F8');
}

function hideIndicator() {
  elementById('indicator').style.visibility = 'hidden';
  getElemBody().style.cursor = 'auto';
  window.clearInterval(_LoadTimeInterval);
}

function hideInfoBox() {
  displayElemById('infobox', 'none');
}

function hideLangSelect() {
  displayElemById('lang_select', 'none');
  displayElemById('lang', 'block');
}

function hideMenModul() {
  if (_FlipMen && getHTML('menmodul') != '') {
    displayElemById('menmodul', 'none');
    displayElemById('menmodulh', 'none');
    displayElemById('menmodulflip', 'table-cell');
  }
}

function hideShortcut() {
  displayElemById('shortcut', 'none');
}

function loadHelp() {
  doHttpRequest('plain.php?page=introguide.dyn', '', '', '');
}

function loadPage(pAttr) {
  showIndicator();
  doHttpRequest('page.dyn.php?umi=' + _UMI + pAttr, 'eval', '', '');
}

function loadPageConfirm(pMsg, pAttr) {
  if (window.confirm(pMsg))
    loadPage(pAttr);
}

function loadShortcut(pName) {
  doHttpRequest('plain.php?page=shortcuts' + encodeURIComponent('/' + pName), 'showShortcut', '', '');
}

function pingSession() {
  doHttpRequest('plain.php?page=ping.dyn', '', '', '');
}

function popupBug() {
  popupWindow('plain.php?page=bug.pop&destumi=' + _UMI, 160, 300);
}

function selIndex(pName, pOpt) {
  var Elem = formByName('index').elements[pName];
  if (!Elem.checked)
    Elem[pOpt].checked = true;
}

function selIndexPreview(pName, pOpt, pFunc) {
  selIndex(pName, pOpt);
  eval(pFunc + "(getOptSelValue(formByName('index').elements[pName]));");
}

function selIndexPreviewCheck(pName, pOpt, pFunc) {
  var Elem = formByName('index').elements[pName];
  if (typeof(Elem.length) == 'number')
    Elem = Elem[pOpt];
  eval(pFunc + '(Elem.value);');
}

function selAllIndex(pName) {
  var Elem = formByName('index').elements[pName];
  if (typeof(Elem.length) == 'number') {
    var B = false;
    for (var I = 0; I < Elem.length; I++)
      if (!Elem[I].checked) {
        B = true;
        break;
      }
    for (var I = 0; I < Elem.length; I++)
      Elem[I].checked = B;
  } else
    Elem.checked = !Elem.checked;
}

function selMultiIndex() {
  var Form = formByName('index').elements;
  var Elem = Form['index'];
  if (Elem.selectedIndex > 0) {
    Form['action'].value = 'update';
    Form['update'].value = Form['label1'].value;
    Form['name'].value = Elem.options[Elem.selectedIndex].text;
  } else {
    Form['action'].value = 'add';
    Form['update'].value = Form['label2'].value;
    Form['name'].value = '';
  }
}

function setCal(pTag, pDay, pMonth, pYear) {
  with (formByName('details')) {
    elements['d' + pTag].value = pDay;
    elements['m' + pTag].value = pMonth;
    elements['y' + pTag].value = pYear;
  }
  displayElemById('cal' + pTag, 'none');
}

function setHeadTitle(pValue) {
  setHTML(pValue, 'headtitle_content');
}

function setInfoBox(pValue, pParam) {
  if (pValue == '')
    _InfoBoxId = '';
  else {
    setHTML(pValue, 'infobox_content');
    showInfoBox();
  }
}

function setLoadTime(pValue) {
  setHTML(pValue, 'loadtime');
}

function setMainPage(pValue) {
  setHTML(pValue, 'main');
}

function setMenModul(pValue) {
  var S = _FlipMen || pValue == '' ? 'none' : 'table-cell';
  displayElemById('menmodul', S);
  displayElemById('menmodulh', S);
  displayElemById('menmodulflip', !_FlipMen || pValue == '' ? 'none' : 'table-cell');
  setHTML(pValue, 'menmodul');
}

function showCal(pValue, pTag) {
  setHTML(pValue, 'cal' + pTag);
  fadeElemById('cal' + pTag, pValue == '' ? 'none' : 'block');
}

function showIndicator() {
  getElemBody().style.cursor = 'wait';
  elementById('indicator').style.visibility = 'visible';
  _LoadTimeStamp = new Date();
  window.clearInterval(_LoadTimeInterval);
  _LoadTimeInterval = window.setInterval('setLoadTime((new Date() - _LoadTimeStamp) / 1000);', 10);
}

function showInfoBox() {
  if (_MouseFixX > 0 && _MouseFixY > 0) {
    var Elem = elementById('infobox');
    if (Elem) {
      displayElem(Elem, 'block');
      with (Elem) {
        var I = _MouseFixX - 200;
        style.left = (I < 0 ? 0 : I) + 'px';
        style.top = _MouseFixY - offsetHeight - 2 + 'px';
      }
    }
  }
}

function showLangSelect(pValue) {
  if (getHTML('lang_select') == '')
    doHttpRequest('plain.php?page=lang.dyn', 'setHTML', 'lang_select', '');
  displayElemById('lang', 'none');
  displayElemById('lang_select', 'block');
}

function showMenModul() {
  displayElemById('menmodulflip', 'none');
  fadeElemById('menmodulh', 'table-cell');
  fadeElemById('menmodul', 'table-cell');
  window.scrollBy(153, 0);
}

function showShortcut(pValue) {
  setHTML(pValue, 'shortcut_content');
  var Elem = elementById('shortcut');
  if (Elem) {
    Elem.style.left = Math.round(getWindowWidth() / 2 - 184 + getWindowScrollLeft()) + 'px';
    fadeElemById('shortcut', 'block');
  }
}

function submitFormIndicator(pName) {
  showIndicator();
  submitForm(pName);
}

function submitAndAction(pName, pAction) {
  formByName(pName).elements['action'].value = pAction;
  submitFormIndicator(pName);
}

function submitConfirmAndAction(pName, pAction, pMsg) {
  if (confirm(pMsg))
    submitAndAction(pName, pAction);
}

function updateCal(pTag) {
  with (formByName('details'))
    doHttpRequest('plain.php?page=cal.dyn&tag=' + pTag + '&m=' + getSelectSelValue(elements['cal_m' + pTag]) + '&y=' + elements['cal_y' + pTag].value, 'showCal', pTag, '');
}

function updateTitle(pObj) {
  setHTML(htmlcode(pObj.value) + '&nbsp;', 'title');
}

function viewCal(pTag) {
  with (formByName('details'))
    doHttpRequest('plain.php?page=cal.dyn&tag=' + pTag + '&m=' + elements['m' + pTag].value + '&y=' + elements['y' + pTag].value, 'showCal', pTag, '');
}

function viewInfoBox(pInfoBoxId, pUrl) {
  _MouseFixX = _MouseX;
  _MouseFixY = _MouseY;
  if (_InfoBoxId == pInfoBoxId)
    showInfoBox();
  else {
    hideInfoBox();
    _InfoBoxId = pInfoBoxId;
    doHttpRequest(pUrl, 'setInfoBox', '', '');
  }
}

function viewInfoBoxFilter(pValue) {
  _MouseFixX = _MouseX;
  _MouseFixY = _MouseY;
  _InfoBoxId = '';
  setInfoBox(pValue);
  showInfoBox();
}