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

function doConfirmActionCancelInvoice(pMsg, pIndex, pSubIndex) {
  loadPageConfirm(pMsg, '&page=details&action=cancelinvoice&index=' + pIndex + '&subindex=' + pSubIndex + '&tab=2');
}

function doConfirmActionClearPriceList(pMsg, pIndex) {
  loadPageConfirm(pMsg, '&page=details&action=clear&index=' + pIndex + '&tab=4');
}

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

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

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

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

function doPopupActionAddPerson(pIndex, pSubIndex) {
  goOpener('index.php?umi=erp_suppliers&page=details&action=addperson&index=' + pIndex + '&subindex=' + pSubIndex);
  window.close();
}

function doPromptActionPayInvoice(pMsg, pIndex, pSubIndex) {
  var S = prompt(pMsg, '');
  if (S != null)
    loadPage('&page=details&action=payinvoice&index=' + pIndex + '&payment=' + encodeURIComponent(S) + '&subindex=' + pSubIndex + '&tab=2');
}

function editContact() {
  displayElemById('contact', 'none');
  fadeElemById('edit', 'block');
}

function getDynContact() {
  var Form = formByName('details').elements;
  Form['contact'].value = '';
  var S = Form['dyn_contact'].value;
  if (S == '')
    displayElemById('ok', 'inline');
  else {
    displayElemById('ok', 'none');
    doHttpRequest('plain.php?umi=erp_suppliers&page=contact.dyn', 'showDynContact', '', 'name=' + encodeURIComponent(S));
  }
}

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

function hideDynContact() {
  window.setTimeout("displayElemById('dyn_contact', 'none');", 300);
}

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

function popupAddPerson(pIndex) {
  popupWindow('plain.php?umi=erp_suppliers&page=addperson.pop&index=' + pIndex, 300, 420);
}

function popupContact() {
  popupWindow('plain.php?umi=erp_suppliers&page=contact.pop', 300, 420);
}

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

function replyEntry(pLabel, pContact, pSubject) {
  var Form = formByName('details').elements;
  with (Form['contact'])
    for (var I = 0; I < options.length; I++)
      if (options[I].value == pContact) {
        selectedIndex = I;
        break;
      }
  Form['label'].selectedIndex = pLabel;
  Form['subject'].value = pSubject;
  Form['text'].focus();
}

function setDynContact(pIndex, pName) {
  var Form = formByName('details').elements;
  Form['contact'].value = pIndex;
  Form['dyn_contact'].value = pName;
  displayElemById('ok', 'inline');
}

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

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