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

function doConfirmActionDeleteJournal(pMsg, pIndex, pSubIndex) {
  loadPageConfirm(pMsg, '&page=details&action=deletejournal&index=' + pIndex + '&subindex=' + pSubIndex + '&tab=3');
}

function doConfirmActionRemoveFile(pMsg, pIndex, pSubIndex) {
  loadPageConfirm(pMsg, '&page=details&action=removefile&index=' + pIndex + '&subindex=' + pSubIndex + '&tab=4');
}

function doConfirmActionRemoveTask(pMsg, pIndex, pSubIndex) {
  loadPageConfirm(pMsg, '&page=details&action=removetask&index=' + pIndex + '&subindex=' + pSubIndex + '&tab=1');
}

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

function doConfirmActionDeleteCategory(pMsg) {
  if (formByName('index').elements['index'].selectedIndex > 0 && confirm(pMsg))
    submitAndAction('index', 'delete');
}

function doConfirmActionRemoveItem(pMsg, pIndex) {
  if (confirm(pMsg)) {
    formByName('details').elements['subindex'].value = pIndex;
    submitAndAction('details', 'remove');
  }
}

function doPopupActionAddFile(pIndex, pSubIndex) {
  goOpener('index.php?umi=crm_cases&page=details&action=addfile&index=' + pIndex + '&subindex=' + pSubIndex + '&tab=4');
  window.close();
}

function doPopupActionAddTask(pIndex, pSubIndex) {
  goOpener('index.php?umi=crm_cases&page=details&action=addtask&index=' + pIndex + '&subindex=' + pSubIndex + '&tab=1');
  window.close();
}

function doPopupActionItem() {
  if (!opener.closed)
    submitFormOpener('details');
  window.close();
}

function doPopupActionSelItems() {
  doPopupActionItem();
}

function dragEndMoveItem(pIndex) {
  if (_DragParam != '' && _DragParam - pIndex != 0) {
    with (formByName('details')) {
      elements['subindex'].value = pIndex;
      elements['offset'].value = _DragParam - pIndex;
    }
    submitAndAction('details', 'move');
  }
}

function dragOutMoveItem(pObj) {
  pObj.style.cursor = 'move';
}

function dragOverMoveItem(pObj) {
  if (_DragAction != '')
    pObj.style.cursor = 'url(bin/crm/cases/img/dragmove.ico),move';
}

function dragStartMoveItem(pIndex) {
  _DragAction = "dragEndMoveItem('" + pIndex + "');";
  getElemBody().style.cursor = 'url(bin/crm/cases/img/dragmove.ico),move';
}

function dragStopMoveItem(pIndex) {
  _DragParam = pIndex;
}

function getDynCustomer() {
  var Form = formByName('details').elements;
  Form['customer'].value = '';
  var S = Form['dyn_customer'].value;
  if (S == '')
    displayElemById('ok', 'inline');
  else {
    displayElemById('ok', 'none');
    doHttpRequest('plain.php?umi=crm_cases&page=customer.dyn', 'showDynCustomer', '', 'name=' + encodeURIComponent(S));
  }
}

function getDynPreview(pIndex) {
  if (elementById('index_preview').style.display != 'none')
    doHttpRequest('plain.php?umi=crm_cases&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 goCustomer() {
  var S = formByName('details').elements['customer'].value;
  if (S != '')
    go('index.php?umi=crm_customers&page=details&index=' + S);
}

function hideDynCustomer() {
  window.setTimeout("displayElemById('dyn_customer', 'none');", 300);
}

function popupAddFile(pIndex) {
  popupWindow('plain.php?umi=crm_cases&page=addfile.pop&index=' + pIndex, 300, 420);
}

function popupAddTask(pIndex) {
  popupWindow('plain.php?umi=crm_cases&page=addtask.pop&index=' + pIndex, 300, 260);
}

function popupCustomer() {
  popupWindow('plain.php?umi=crm_cases&page=customer.pop', 300, 420);
}

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

function popupItem(pItemsFile, pIndex) {
  popupWindow('plain.php?umi=crm_cases&page=item.pop&index=' + pIndex + '&itemsfile=' + pItemsFile, 160, 500);
}

function popupSelItems(pItemsFile) {
  popupWindow('plain.php?umi=crm_cases&page=selitems.pop&itemsfile=' + pItemsFile, 300, 500);
}

function setDynCustomer(pIndex, pName) {
  var Form = formByName('details').elements;
  Form['customer'].value = pIndex;
  Form['dyn_customer'].value = pName;
  displayElemById('ok', 'inline');
}

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

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

function viewInfoBoxCustomer(pIndex) {
  if (pIndex != '-1')
    viewInfoBox('customer' + pIndex, 'plain.php?umi=crm_customers&page=customer.info&index=' + pIndex);
}

function viewInfoBoxCustomer2() {
  viewInfoBoxCustomer(formByName('details').elements['customer'].value);
}

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']));
}