function doConfirmAction(pTab, pAction, pMsg, pIndex) {
  loadPageConfirm(pMsg, '&action=' + pAction + '&index=' + pIndex + '&tab=' + pTab);
}

function doConfirmActionDeleteRecord(pMsg, pIndex, pSubIndex) {
  loadPageConfirm(pMsg, '&page=details&action=deleterecord&index=' + pIndex + '&subindex=' + pSubIndex);
}

function doIndexConfirmAction(pTab, pAction, pMsg) {
  doConfirmAction(pTab, pAction, pMsg, getOptSelValue(formByName('index').elements['index']));
}

function doPopupActionPublish(pMsg, pIndex) {
  if (confirm(pMsg)) {
    goOpener('index.php?umi=org_tasks&action=publish&index=' + pIndex + '&owner=' + encodeURIComponent(getSelectSelValue(formByIndex(0).elements['selowner'])));
    window.close();
  }
}

function getDynParent(pKeyPress) {
  var Form = formByName('details').elements;
  var S = Form['dyn_parent'].value;
  if (pKeyPress) {
    Form['parent'].value = '';
    displayElemById('ok', S == '' ? 'inline' : 'none');
  }
  doHttpRequest('plain.php?umi=org_tasks&page=parent.dyn', 'showDynParent', '', 'index=' + Form['index'].value + '&name=' + encodeURIComponent(S));
}

function getDynPreview(pIndex) {
  if (elementById('index_preview').style.display != 'none')
    doHttpRequest('plain.php?umi=org_tasks&page=preview.dyn&index=' + pIndex, 'setHTML', 'index_preview', '');
}

function goAssignedUser() {
  var S = getSelectSelValue(formByName('details').elements['assigneduser']);
  if (S != '')
    go('index.php?umi=admin_users&page=details&id=' + S);
}

function goParentTask() {
  var S = formByName('details').elements['parent'].value;
  if (S != '')
    loadPage('&page=details&index=' + S);
}

function hideDynParent() {
  window.setTimeout("displayElemById('dyn_parent', 'none');", 300);
}

function popupHistory(pIndex) {
  popupWindow('plain.php?page=history.pop&entity=org_tasks_tasks&index=' + pIndex, 240, 500);
}

function popupPublish(pIndex) {
  popupWindow('plain.php?umi=org_tasks&page=publish.pop&index=' + pIndex, 100, 220);
}

function popupSend(pIndex) {
  popupWindow('plain.php?page=send.pop&destumi=org_tasks&index=' + pIndex, 300, 420);
}

function setDynParent(pIndex, pName) {
  var Form = formByName('details').elements;
  Form['parent'].value = pIndex;
  Form['dyn_parent'].value = pName;
  displayElemById('ok', 'inline');
}

function showDynParent(pValue, pParam) {
  setHTML(pValue, 'dyn_parent');
  fadeElemById('dyn_parent', pValue == '' ? 'none' : 'block');
}

function updatePriority(pObj) {
  with (imageByName('priorityico'))
    src = src.replace(/priority[0-9]*\.gif/, 'priority' + pObj.selectedIndex + '.gif');
}

function updateProgress(pObj) {
  if (pObj.value > 100)
    pObj.value = 100;
  with (formByName('details').elements['status'])
    if (pObj.value == '100')
      selectedIndex = 4;
    else if (selectedIndex == 4 && pObj.value < 100)
      selectedIndex = 0;
  with (imageByName('progbar'))
    src = src.replace(/progress=[0-9]*/, 'progress=' + pObj.value);
}

function updateStatus() {
  var Form = formByName('details').elements;
  if (Form['status'].selectedIndex == 4) {
    Form['progress'].value = '100';
    with (imageByName('progbar'))
      src = src.replace(/progress=[0-9]*/, 'progress=' + Form['progress'].value);
  } else if (Form['progress'].value == '100')
    Form['status'].selectedIndex = 4;
}

function viewInfoBoxUser(pId) {
  if (pId != '')
    viewInfoBox('user' + pId, 'plain.php?umi=admin_users&page=user.info&id=' + pId);
}

function viewInfoBoxUser2() {
  viewInfoBoxUser(getSelectSelValue(formByName('details').elements['assigneduser']));
}