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

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

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

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

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

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

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

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_contracts&page=customer.dyn', 'showDynCustomer', '', 'name=' + encodeURIComponent(S));
  }
}

function getDynPreview(pIndex) {
  if (elementById('index_preview').style.display != 'none')
    doHttpRequest('plain.php?umi=crm_contracts&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 insertCodeClass(pName) {
  with (formByName('details'))
    insertCode(elements['code_' + pName], elements[pName]);
}

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

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

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

function popupHistoryContract(pIndex) {
  popupWindow('plain.php?page=history.pop&entity=crm_contracts_contracts&index=' + pIndex, 240, 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 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']));
}