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

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

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

function doPopupActionAddFile(pIndex, pSubIndex) {
  goOpener('index.php?umi=crm_opportunities&page=details&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_opportunities&page=customer.dyn', 'showDynCustomer', '', 'name=' + encodeURIComponent(S));
  }
}

function getDynPreview(pIndex) {
  if (elementById('index_preview').style.display != 'none')
    doHttpRequest('plain.php?umi=crm_opportunities&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_opportunities&page=addfile.pop&index=' + pIndex, 300, 420);
}

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

function popupHistory(pIndex) {
  popupWindow('plain.php?page=history.pop&entity=crm_opportunities_opportunities&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 updateForecast() {
  var Form = formByName('details').elements;
  with (imageByName('forecast')) {
    src = src.replace(/mostlikely=[0-9\.]*/, 'mostlikely=' + Form['mostlikely'].value);
    src = src.replace(/upside=[0-9\.]*/, 'upside=' + Form['upside'].value);
    src = src.replace(/worstcase=[0-9\.]*/, 'worstcase=' + Form['worstcase'].value);
  }
}

function updateProbability(pObj) {
  if (pObj.value > 100)
    pObj.value = 100;
  with (formByName('details').elements['status'])
    if (selectedIndex == 4 && pObj.value < 100)
      selectedIndex = 3;
}

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

function updateStatus() {
  with (formByName('details'))
    if (elements['status'].selectedIndex == 3)
      elements['probability'].value = '100';
    else if (elements['status'].selectedIndex == 0)
      elements['probability'].value = '0';
}

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