/*=======================================================================
 *
 * job_edit.js
 *
 * Autor: Carsten Annacker
 *
 =======================================================================*/

var von_fields = new Array();
var nach_fields = new Array();
var alertIsOpen = false;

/*
 * initFldList
 *   params: -
 *   return: -
 *   global:
 *
 */

function initFldList()
{
  von_csc_id_NumIdx = getNumIndex("job_tour", "tourForm", "von_csc_id");
  von_cs_comp_NumIdx = getNumIndex("job_tour", "tourForm", "von_cs_comp");
  von_tr_person_NumIdx = getNumIndex("job_tour", "tourForm", "von_tr_person");
  von_ad_street_NumIdx = getNumIndex("job_tour", "tourForm", "von_ad_street");
  von_tr_hsno_NumIdx = getNumIndex("job_tour", "tourForm", "von_tr_hsno");
  von_ad_city_NumIdx = getNumIndex("job_tour", "tourForm", "von_ad_city");
  von_ad_zipcode_NumIdx = getNumIndex("job_tour", "tourForm", "von_ad_zipcode");
  von_ad_country_NumIdx = getNumIndex("job_tour", "tourForm", "von_ad_country");
  von_tr_commission_no = getNumIndex("job_tour", "tourForm", "von_tr_commission_no");
  von_tr_tracking_NumIdx = getNumIndex("job_tour", "tourForm", "von_tr_tracking");
  von_tr_mediationarea_id = getNumIndex("job_tour", "tourForm", "von_tr_mediationarea_id");
  hide_von_tr_remark_NumIdx = getNumIndex("job_tour", "tourForm", "hide_von_tr_remark");
  von_tr_remark_NumIdx = getNumIndex("job_tour", "tourForm", "von_tr_remark");
  tr_photo_von_NumIdx = getNumIndex("job_tour", "tourForm", "tr_photo_von");
  tr_ware_from_von_NumIdx = getNumIndex("job_tour", "tourForm", "tr_ware_from_von");
  tr_ware_to_von_NumIdx = getNumIndex("job_tour", "tourForm", "tr_ware_to_von");
  payer_from_NumIdx = getNumIndex("job_tour", "tourForm", "payer_from");

  nach_csc_id_NumIdx = getNumIndex("job_tour", "tourForm", "nach_csc_id");
  nach_cs_comp_NumIdx = getNumIndex("job_tour", "tourForm", "nach_cs_comp");
  nach_tr_person_NumIdx = getNumIndex("job_tour", "tourForm", "nach_tr_person");
  nach_ad_street_NumIdx = getNumIndex("job_tour", "tourForm", "nach_ad_street");
  nach_tr_hsno_NumIdx = getNumIndex("job_tour", "tourForm", "nach_tr_hsno");
  nach_ad_country_NumIdx = getNumIndex("job_tour", "tourForm", "nach_ad_country");
  nach_ad_zipcode_NumIdx = getNumIndex("job_tour", "tourForm", "nach_ad_zipcode");
  nach_ad_city_NumIdx = getNumIndex("job_tour", "tourForm", "nach_ad_city");
  nach_tr_remark_NumIdx = getNumIndex("job_tour", "tourForm", "nach_tr_remark");
  tr_photo_nach_NumIdx = getNumIndex("job_tour", "tourForm", "tr_photo_nach");
  nach_tr_commission_no = getNumIndex("job_tour", "tourForm", "nach_tr_commission_no");
  nach_tr_tracking_NumIdx = getNumIndex("job_tour", "tourForm", "nach_tr_tracking");
  nach_tr_mediationarea_id = getNumIndex("job_tour", "tourForm", "nach_tr_mediationarea_id");
  hide_nach_tr_remark_NumIdx = getNumIndex("job_tour", "tourForm", "hide_nach_tr_remark");
  tr_ware_from_nach_NumIdx = getNumIndex("job_tour", "tourForm", "tr_ware_from_nach");
  tr_ware_to_nach_NumIdx = getNumIndex("job_tour", "tourForm", "tr_ware_to_nach");
  payer_to_NumIdx = getNumIndex("job_tour", "tourForm", "payer_to");

  von_fields = new Array(
    von_csc_id_NumIdx[2], von_cs_comp_NumIdx[2], von_tr_person_NumIdx[2], von_ad_street_NumIdx[2],
    von_tr_hsno_NumIdx[2], von_ad_country_NumIdx[2], von_ad_zipcode_NumIdx[2], von_ad_city_NumIdx[2],
    von_tr_remark_NumIdx[2], tr_photo_von_NumIdx[2], von_tr_commission_no[2], von_tr_tracking_NumIdx[2], hide_von_tr_remark_NumIdx[2],
    tr_ware_from_von_NumIdx[2], tr_ware_to_von_NumIdx[2], payer_from_NumIdx[2], von_tr_mediationarea_id[2]);
  nach_fields = new Array(
    nach_csc_id_NumIdx[2], nach_cs_comp_NumIdx[2], nach_tr_person_NumIdx[2], nach_ad_street_NumIdx[2],
    nach_tr_hsno_NumIdx[2], nach_ad_country_NumIdx[2], nach_ad_zipcode_NumIdx[2], nach_ad_city_NumIdx[2],
    nach_tr_remark_NumIdx[2], tr_photo_nach_NumIdx[2], nach_tr_commission_no[2], nach_tr_tracking_NumIdx[2], hide_nach_tr_remark_NumIdx[2],
    tr_ware_from_nach_NumIdx[2], tr_ware_to_nach_NumIdx[2], payer_to_NumIdx[2], nach_tr_mediationarea_id[2]);
}

//var von_prev = 3;
//var von_waste = 4;
//var nach_next = 7;
//var tourNoForm = 0;    // Form
//var tourNoVal = 0;     // Element
//var nach_csc_id = 1;
//var csc_id_orderer = 17;
//var toursubmit = 21;
//var job_tour_list = 3; // Frame
//var csc_id_payer = 22;
//var comp_payer = 23;
//var jb_cash_hidden = 24;

var maxTour = MASK_MAXTOUR;
var maxTr_remark = MASK_MAX_TR_REMARK;
var jobList_ori = "";
var jb_fixprice_ori = "";
var jb_serviceprice_ori = "";
var jb_markup_ori = "";
var jb_ordertime_ori = "";
var curCsc_id_payer_ori = "";
/* var jobListIsDefined = 0; */
var tr_photo_disabled = false;
var tr_photo_disabled1 = false;
var tr_photo_checked = false;
var tr_photo_label0 = "";
var tr_photo_label = "";

/*
 * initJobList
 *   params: -
 *   return: -
 *   global: job_tour, tourForm, job_options, tourOptions, jobList, maxTour, jobListIsDefined
 *
 * Die Etappenliste wird im Hidden-Formelement namens "jobList" im dritten Frame gespeichert,
 * damit sie beim Absenden des Formulars zum Server übermittelt wird. initJobList setzt die
 * jobList auf leere Werte. Die Funktion wird automatisch das erste Mal aufgerufen, sobald
 * eine andere Funktion auf auf die jobList lesend/schreibend zugreift (deshalb die globale
 * Variable.
 */

function initJobList()
{
  var tmpJobList = new Array(maxTour + 1);
  var tmpJobListJoin = new Array(maxTour + 1);

  for (var i = 0; i < (maxTour + 1); i++)
  {
    tmpJobList[i] = new Array(von_fields.length);
    for (var j = 0; j < von_fields.length; j++)
      tmpJobList[i][j] = "";
    tmpJobListJoin[i] = tmpJobList[i].join("²");
  }
  parent.job_options.document.tourOptions.jobList.value =
    tmpJobListJoin.join("¹");
  jobListIsDefined = 1;
  for (j = 0; j < (maxTour + 1); j++) {
    setJobList(j, jl_hide_tr_remark, "true");
    setJobList(j, jl_tr_photo, "false");
    setJobList(j, jl_ad_country, "DE");
  }
}

/*
 * getJobList
 *   params: tourNo, fieldNo
 *   return: adressierter Wert aus dem Hidden-Formelement "jobList"
 *   global: jobList, maxTour, jobListIsDefined
 */

function getJobList(tourNo, fldNo)
{
/*  if (!jobListIsDefined) initJobList(); */
  var tmpJobList = new Array(maxTour + 1);
  var tmpJobListJoin =
    parent.job_options.document.tourOptions.jobList.value.split("¹");
  tmpJobList[tourNo] = tmpJobListJoin[tourNo].split("²");
// alert (String(tmpJobList[tourNo][fldNo]));
  return tmpJobList[tourNo][fldNo];
}

/*
 * setJobList
 *   params: tourNo, fieldNo, newVal
 *   return: -
 *   global: maxTour, jobListIsDefined
 *
 * Speichert den Wert newVal an der spezifizierten Stelle in das
 * Hidden-Formelement "jobList".
 */

function setJobList(tourNo, fldNo, newVal)
{
/*  if (!jobListIsDefined) initJobList(); */
  var tmpJobList = new Array(maxTour + 1);
  var tmpJobListJoin =
    parent.job_options.document.tourOptions.jobList.value.split("¹");
  tmpJobList[tourNo] = tmpJobListJoin[tourNo].split("²");
  tmpJobList[tourNo][fldNo] = newVal;
  tmpJobListJoin[tourNo] = tmpJobList[tourNo].join("²");
  parent.job_options.document.tourOptions.jobList.value =
    tmpJobListJoin.join("¹");
}

/*
 * delJobList
 *   params: tourNo
 *   return: -
 *   global: -
 *
 * Löscht eine Etappe aus dem Hidden-Formelement "jobList"; wenn doMove = true
 * dann rückt die nachfolgende Etappe um eine Stelle nach vorne.
 */

function delJobList(tourNo, doMove)
{
  var tmpJobListJoin =
    parent.job_options.document.tourOptions.jobList.value.split("¹");
  var tmpJobList = new Array(tmpJobListJoin.length);
  var delTourNo = tourNo + 1;

  if ((tourNo < tmpJobList.length - 1) && doMove)
     tmpJobListJoin[tourNo] = tmpJobListJoin[tourNo + 1];
  else
     delTourNo = tourNo;

  tmpJobList[delTourNo] = tmpJobListJoin[delTourNo].split("²");
  for (var j = 0; j < tmpJobList[delTourNo].length; j++)
    tmpJobList[delTourNo][j] = "";
  tmpJobListJoin[delTourNo] = tmpJobList[delTourNo].join("²");

  parent.job_options.document.tourOptions.jobList.value =
    tmpJobListJoin.join("¹");
}

/*
 * switchJobList
 *   params: -
 *   return: -
 *   global: -
 *
 * Vertauscht die aktuell angezeigten Etappen in dem Hidden-Formelement "jobList"
 */

function switchJobList()
{
  var tourNo = getCurTourNo();
  var tmpJobListJoin =
    parent.job_options.document.tourOptions.jobList.value.split("¹");
  var tmpJob = tmpJobListJoin[tourNo];

  tmpJobListJoin[tourNo] = tmpJobListJoin[tourNo + 1];
  tmpJobListJoin[tourNo + 1] = tmpJob;
  parent.job_options.document.tourOptions.jobList.value =
    tmpJobListJoin.join("¹");
  refreshFormFields();
}

/*
 * getCurTourNo
 *   params: tourNo
 *   return: ausgelesener Wert von tourNo
 *   global: job_tour, tourNoForm, tourNoVal
 *
 * Die aktuelle Etappennummer wird im Formelement namens "tourNo" im zweiten Frame gespeichert
 * und dort auch angezeigt. Zur Vereinfachung der Bearbeitung dieser Variable wird sie hier
 * ausgelesen und zurückgegeben.
 */

function getCurTourNo()
{
  return (parseInt(
    parent.job_tour.document.tourNoForm.tourNoVal.value,
    10) - 1);
}

/*
 * setCurTourNo
 *   params: tourNo
 *   return: -
 *   global: job_tour, tourNoForm, tourNoVal, job_tour, tourForm, von_prev, von_waste, nach_next
 *
 * Die aktuelle Etappennummer im Formelement namens "tourNo" wird aktualisiert.
 */

function setCurTourNo(curTourNo)
{
  // Hold parameter
  parent.job_tour.document.tourNoForm.tourNoVal.value =
    (curTourNo + 1).toString(10);

  // Only for frontend
  if (curTourNo == 0)
  {
    parent.job_tour.document.tourForm.prevButton.disabled = true;
    parent.job_tour.document.tourForm.prevButton.className = "button_disabled";
    parent.job_tour.document.prev_gif.src = "../images/prev_dis.gif";
    /*
      parent.job_tour.document.tourForm.waste1Button.disabled = true;
      toggleImage(1, von_waste, "../images/waste_dis.gif");
    */
    parent.job_tour.document.getElementById('tr_tracking_von').style.visibility = 'collapse';
  } else {
    parent.job_tour.document.tourForm.prevButton.disabled = false;
    parent.job_tour.document.tourForm.prevButton.className = "button_enabled";
    parent.job_tour.document.prev_gif.src = "../images/prev.gif";
    /*
      parent.job_tour.document.tourForm.elements.waste1Button.disabled = false;
      toggleImage(1, von_waste, "../images/waste.png")
    */
    if (get_cs_tracking(curCsc_id_payer) == 1)
        parent.job_tour.document.getElementById('tr_tracking_von').style.visibility = 'visible';
  }
  if (curTourNo == maxTour - 1)
  {
    parent.job_tour.document.tourForm.nextButton.disabled = true;
    parent.job_tour.document.tourForm.nextButton.className = "button_disabled";
    parent.job_tour.document.next_gif.src = "../images/next_dis.gif";
  } else {
    parent.job_tour.document.tourForm.nextButton.disabled = false;
    parent.job_tour.document.tourForm.nextButton.className = "button_enabled";
    parent.job_tour.document.next_gif.src = "../images/next.gif";
  }
  refreshFormFields();
}

function get_tr_status(tr_id)
{
  // leere tr_id hat keinen tr_status
  if (tr_id.replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cur_tr_statuses.length; i++)
    if (cur_tr_statuses[i][0] == tr_id)
      return cur_tr_statuses[i][1];
  return 0;
}

/*
 * saveFormFields
 *   params: -
 *   return: -
 *   global: job_tour, tourForm, von_fields, nach_fields
 *
 * Die aktuell angezeigten Formularfelder werden in dem Hiddenelement "jobList" gespeichert.
 * Die globalen Arrays von_fields und nach_fields enthalten die Element-Indices für die Felder
 * der linken und der rechten Seite.
 */

function saveFormFields()
{
  var curTourNo = getCurTourNo();
/* nicht für Zentrale Hansetrans
  setJobList(curTourNo, 0, getSelectedVal("job_tour", "tourForm", von_fields[jl_csc_id]));
  setJobList(curTourNo + 1, 0, getSelectedVal("job_tour", "tourForm", nach_fields[jl_csc_id]));
*/
  if (trim(parent.job_tour.document.tourForm.elements[von_fields[jl_tr_tracking]].value) != "") {
    if (!validateEmail(parent.job_tour.document.tourForm.elements[von_fields[jl_tr_tracking]].value)) {
      alert('"' + parent.job_tour.document.tourForm.elements[von_fields[jl_tr_tracking]].value + '" ist keine gültige Mail-Adresse!');
      parent.job_tour.document.tourForm.elements[von_fields[jl_tr_tracking]].value = "";
    }
  }

  if (trim(parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_tracking]].value) != "") {
    if (!validateEmail(parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_tracking]].value)) {
      alert('"' + parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_tracking]].value + '" ist keine gültige Mail-Adresse!');
      parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_tracking]].value = "";
    }
  }

  for (var i = 1; i < (von_fields.length - 4); i++)
  {
  	if (von_fields[i] != -1) {
      setJobList(curTourNo, i,
        parent.job_tour.document.tourForm.elements[von_fields[i]].value);
    }
  	if (nach_fields[i] != -1) {
      setJobList(curTourNo + 1, i,
        parent.job_tour.document.tourForm.elements[nach_fields[i]].value);
    }
  }
/*
  setJobList(curTourNo, jl_ad_zipcode, getSelectedVal("job_tour", "tourForm", von_fields[jl_ad_zipcode]));
  setJobList(curTourNo + 1, jl_ad_zipcode, getSelectedVal("job_tour", "tourForm", nach_fields[jl_ad_zipcode]));
*/
  setJobList(curTourNo, jl_hide_tr_remark,
    parent.job_tour.document.tourForm.elements[von_fields[jl_hide_tr_remark]].checked);
  if (parent.job_tour.document.tourForm.elements[von_fields[jl_hide_tr_remark]].checked)
    parent.job_tour.document.tourForm.elements[von_fields[jl_tr_remark]].disabled = false;
  else parent.job_tour.document.tourForm.elements[von_fields[jl_tr_remark]].disabled = true;

  setJobList(curTourNo + 1, jl_hide_tr_remark,
    parent.job_tour.document.tourForm.elements[nach_fields[jl_hide_tr_remark]].checked);
  if (parent.job_tour.document.tourForm.elements[nach_fields[jl_hide_tr_remark]].checked)
    parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_remark]].disabled = false;
  else parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_remark]].disabled = true;

  if (von_fields[jl_tr_photo] != -1) {
    setJobList(curTourNo, jl_tr_photo,
      parent.job_tour.document.tourForm.elements[von_fields[jl_tr_photo]].checked);
  }
  if (nach_fields[jl_tr_photo] != -1) {
    setJobList(curTourNo + 1, jl_tr_photo,
      parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_photo]].checked);
  }

  setJobList(curTourNo, jl_tr_ware_from,
    parent.job_tour.document.tourForm.elements[von_fields[jl_tr_ware_from]].checked);
  setJobList(curTourNo, jl_tr_ware_to,
    parent.job_tour.document.tourForm.elements[von_fields[jl_tr_ware_to]].checked);
  setJobList(curTourNo + 1, jl_tr_ware_from,
    parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_ware_from]].checked);
  setJobList(curTourNo + 1, jl_tr_ware_to,
    parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_ware_to]].checked);

  if (typeof(parent.job_tour.document.tourForm.jb_costsplit) != 'undefined') {
    if (parent.job_tour.document.tourForm.elements[von_fields[jl_csc_id_payer]].checked ||
      parent.job_tour.document.tourForm.elements[nach_fields[jl_csc_id_payer]].checked /* ||
      parent.job_options.document.tourOptions.csc_id_payer.value == ""*/)
    {
      // wenn nicht Kostenteilung oder Barzahlung, dann ...
      // ... oder Mißbrauch der Kostenteilung für Barzahler
      if ((!parent.job_tour.document.tourForm.jb_costsplit.checked && !parent.job_tour.document.tourForm.jb_cash.checked) || cash_payer_select == "1")
      {
        // Bezahler wurde gesetzt, alle anderen müssen auf 'false' gesetzt werden
        // (es kann nur einen geben...)
        for (var i = 0; i < (maxTour + 1); i++)
          setJobList(i, jl_csc_id_payer, "false");
        // ... den neuen Bezahler merken
        setJobList(curTourNo, jl_csc_id_payer,
          parent.job_tour.document.tourForm.elements[von_fields[jl_csc_id_payer]].checked);
        setJobList(curTourNo + 1, jl_csc_id_payer,
          parent.job_tour.document.tourForm.elements[nach_fields[jl_csc_id_payer]].checked);
        setCsc_id_payer("", "");
      }
    }
  }

  // Testen, ob die Rechnungspostleitzahl noch zur eingetragenen passt
  for (var side = 0; side <= 1; side++)
  {
    if (getJobList(curTourNo + side, jl_ad_zipcode) != "" && getJobList(curTourNo + side, jl_tr_mediationarea_id) != "") {
      jl_tr_mediationarea_is_ok = false;
      for (i = 0; i < fz.length; i++) {
        if (fz[i][0] == getJobList(curTourNo + side, jl_ad_zipcode)) {
          if (fz[i][2] == getJobList(curTourNo + side, jl_tr_mediationarea_id)) {
            jl_tr_mediationarea_is_ok = true;
            break;
          }
        }
      }
      if (!jl_tr_mediationarea_is_ok)
        setJobList(curTourNo + side, jl_tr_mediationarea_id, "");
    }
  }

  writeJob();
}

function saveEmailAddress() {
  if (validateEmail(parent.job_tour.document.tourForm.jb_cashpayer_mail.value)) {
    parent.job_options.document.tourOptions.jb_cashpayer_mail_hidden.value = parent.job_tour.document.tourForm.jb_cashpayer_mail.value;
  } else {
    alert('"' + parent.job_tour.document.tourForm.jb_cashpayer_mail.value + '" ist keine gültige Mail-Adresse!');
  }
}

function saveEmailAddressOffer() {
  if (trim(parent.job_tour.document.tourForm.jb_offer_mail.value) == "" || validateEmail(parent.job_tour.document.tourForm.jb_offer_mail.value)) {
    parent.job_options.document.tourOptions.jb_offer_mail_hidden.value = trim(parent.job_tour.document.tourForm.jb_offer_mail.value);
  } else {
    alert('"' + parent.job_tour.document.tourForm.jb_offer_mail.value + '" ist keine gültige Mail-Adresse!');
  }
}

function saveInvmail() {
  if (validateEmail(parent.job_tour.document.tourForm.invmailOfPayer.value)) {
    parent.job_options.document.tourOptions.cs_invmail_hidden.value = parent.job_tour.document.tourForm.invmailOfPayer.value;
    parent.job_tour.document.tourForm.invmailOfPayer.className = "input";
  } else {
    parent.job_tour.document.tourForm.invmailOfPayer.className = "inputRed";
    parent.job_options.document.tourOptions.cs_invmail_hidden.value = "";
    alert('"' + parent.job_tour.document.tourForm.invmailOfPayer.value + '" ist keine gültige Mail-Adresse!');
    parent.job_options.document.tourOptions.jb_fixprice.focus();
    parent.job_tour.document.tourForm.invmailOfPayer.focus();
  }
}

// https://html.form.guide/best-practices/validate-email-address-using-javascript.html
function validateEmail(email) 
{
  var re = /^(?:[a-z0-9!#$%&amp;'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&amp;'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/;

  return re.test(email);
}

/*
 * checkJb_sales_tax_rate_sign
 *   params: -
 *   return: -
 *   global: sales_tax_rate_sign_list
 *
 */

function checkJb_sales_tax_rate_sign(tx_id)
{
  var curSelectedVal = tx_id;
  
  if (tx_id > 0) {
    setSelectedOption("job_options", "tourOptions", "jb_sales_tax_rate_sign", tx_id);
  } else {
    curSelectedVal = getSelectedVal("job_options", "tourOptions", "jb_sales_tax_rate_sign");
  }

  for (i = 0; i < sales_tax_rate_sign_list.length; i++)
  {
    if (sales_tax_rate_sign_list[i][0] == curSelectedVal)
    {
      parent.job_options.document.tourOptions.jb_sales_tax_rate.value =
        (parseInt(sales_tax_rate_sign_list[i][1], 10) > 0 ? 'voll' : 'ohne')
      return;
    }
  }
}

/*
 * checkCs_filter
 *   params: -
 *   return: -
 *   global: cfl, jb_cr_filter, jb_cr_filter_opt
 *
 */

function checkCs_filter(cs_filter, cs_jb_incomplete) {

// ACHTUNG: DER FALL, WENN EIN VOREINGESTELLTER KUNDENFILTER ABGEWÄHLT WURDE, IST NOCH NICHT BERÜCKSICHTIGT!
// BEIM LADEN EINES SOLCHEN GESPEICHERTEN JOBS WIRD DIESER FILTER WIEDER AUTOMATISCH GESETZT!!! (ähnliches Problem wie beim Kundenrabatt)
// AUCH FILTER MIT NUR EINEM BUCHSTABEN SIND GEFÄHRLICH WG. ERKENNUNG (Bsp.: "E" ->"EP")

  // wenn cs_filter leer, dann gibts nix zu tun...
  if (cs_filter.replace(/\s/,"").length == 0)
    return;

//  // beim Kunden voreingestellte Filter haben immer ein Komma am Anfang, das eliminiert werden muss
//  if (cs_filter.substr(0, 1) == ",")
//    cs_filter = cs_filter.substr(1, cs_filter.length - 1);

  var jb_cr_filter = parent.job_options.document.tourOptions.jb_cr_filter.value;
  if (jb_cr_filter != "")
    jb_cr_filter = "," + jb_cr_filter;
  var jb_cr_filter_opt = parent.job_options.document.tourOptions.jb_cr_filter_opt.value;
  if (jb_cr_filter_opt != "")
    jb_cr_filter_opt = "," + jb_cr_filter_opt;

  for (var i = 0; i < cfl.length; i++)
  {
    if (cs_filter.indexOf("," + cfl[i][0] + ",") > -1) // wenn aktueller Filter in cs_filter vorhanden, dann setzen
    {
      cfl[i][3] = 1; // Filter als gesetzt markieren ...
      // ... und in entsprechender Variable abspeichern, wenn nicht schon vorhanden
      if (cfl[i][2] == 1) // 0 = Info, 1 = Sperre, 2 = Warnung
      {
        if (jb_cr_filter.indexOf(cfl[i][0]) == -1)
          jb_cr_filter = jb_cr_filter + "," + cfl[i][0];
      } else {
        if (jb_cr_filter_opt.indexOf(cfl[i][0]) == -1)
          jb_cr_filter_opt = jb_cr_filter_opt + "," + cfl[i][0];
      }
    }
  }
  
  parent.job_options.document.tourOptions.jb_cr_filter.value = jb_cr_filter.substr(1, jb_cr_filter.length - 1);
  parent.job_options.document.tourOptions.jb_cr_filter_opt.value = jb_cr_filter_opt.substr(1, jb_cr_filter_opt.length - 1);
  parent.job_options.document.tourOptions.jb_cr_filterButton.value = "Filter*";

// Check if jb_incomplete has to be set by default on new jobs
  if (jb_id == "" && cs_jb_incomplete == "1") {
    if (typeof(parent.job_options.document.tourOptions.jb_incomplete) != 'undefined') {
      parent.job_options.document.tourOptions.jb_incomplete.checked = true;    
    }
  }
}

/*
 * checkJb_permanent
 *   params: -
 *   return: -
 *   global:
 *
 * Je nach eingestelltem Rhythmus soll checkJb_permanent2 aktiv sein oder nicht
 * Außerdem wird bei einem gültigen Rhythmus eine Vorauswhl getroffen
 */

function checkJb_permanent(doPresetWeekdays)
{
  if (typeof(parent.job_options.document.tourOptions.jb_permanent) == 'undefined')
    return;
  if (getSelectedVal("job_options", "tourOptions", "jb_permanent") == ""
    || (getSelectedVal("job_options", "tourOptions", "jb_permanent") > 3 && getSelectedVal("job_options", "tourOptions", "jb_permanent") != 9)
    || parent.job_options.document.tourOptions.jb_permanent.disabled == true) {
    parent.job_options.document.tourOptions.jb_permanent2_0.checked = false;
    parent.job_options.document.tourOptions.jb_permanent2_1.checked = false;
    parent.job_options.document.tourOptions.jb_permanent2_2.checked = false;
    parent.job_options.document.tourOptions.jb_permanent2_3.checked = false;
    parent.job_options.document.tourOptions.jb_permanent2_4.checked = false;
    parent.job_options.document.tourOptions.jb_permanent2_5.checked = false;
    parent.job_options.document.tourOptions.jb_permanent2_6.checked = false;
    parent.job_options.document.tourOptions.jb_permanent2_0.disabled = true;
    parent.job_options.document.tourOptions.jb_permanent2_1.disabled = true;
    parent.job_options.document.tourOptions.jb_permanent2_2.disabled = true;
    parent.job_options.document.tourOptions.jb_permanent2_3.disabled = true;
    parent.job_options.document.tourOptions.jb_permanent2_4.disabled = true;
    parent.job_options.document.tourOptions.jb_permanent2_5.disabled = true;
    parent.job_options.document.tourOptions.jb_permanent2_6.disabled = true;
  } else {
    parent.job_options.document.tourOptions.jb_permanent2_0.disabled = false;
    parent.job_options.document.tourOptions.jb_permanent2_1.disabled = false;
    parent.job_options.document.tourOptions.jb_permanent2_2.disabled = false;
    parent.job_options.document.tourOptions.jb_permanent2_3.disabled = false;
    parent.job_options.document.tourOptions.jb_permanent2_4.disabled = false;
    parent.job_options.document.tourOptions.jb_permanent2_5.disabled = false;
    parent.job_options.document.tourOptions.jb_permanent2_6.disabled = false;
    if (doPresetWeekdays == 1)
    {
      // werktags
      if (getSelectedVal("job_options", "tourOptions", "jb_permanent") == 1) {
        parent.job_options.document.tourOptions.jb_permanent2_0.checked = true;
        parent.job_options.document.tourOptions.jb_permanent2_1.checked = true;
        parent.job_options.document.tourOptions.jb_permanent2_2.checked = true;
        parent.job_options.document.tourOptions.jb_permanent2_3.checked = true;
        parent.job_options.document.tourOptions.jb_permanent2_4.checked = true;
        parent.job_options.document.tourOptions.jb_permanent2_5.checked = false;
        parent.job_options.document.tourOptions.jb_permanent2_6.checked = false;
      }
      // werktags mit Sa.
      if (getSelectedVal("job_options", "tourOptions", "jb_permanent") == 2) {
        parent.job_options.document.tourOptions.jb_permanent2_0.checked = true;
        parent.job_options.document.tourOptions.jb_permanent2_1.checked = true;
        parent.job_options.document.tourOptions.jb_permanent2_2.checked = true;
        parent.job_options.document.tourOptions.jb_permanent2_3.checked = true;
        parent.job_options.document.tourOptions.jb_permanent2_4.checked = true;
        parent.job_options.document.tourOptions.jb_permanent2_5.checked = true;
        parent.job_options.document.tourOptions.jb_permanent2_6.checked = false;
      }
      // täglich
      if (getSelectedVal("job_options", "tourOptions", "jb_permanent") == 3) {
        parent.job_options.document.tourOptions.jb_permanent2_0.checked = true;
        parent.job_options.document.tourOptions.jb_permanent2_1.checked = true;
        parent.job_options.document.tourOptions.jb_permanent2_2.checked = true;
        parent.job_options.document.tourOptions.jb_permanent2_3.checked = true;
        parent.job_options.document.tourOptions.jb_permanent2_4.checked = true;
        parent.job_options.document.tourOptions.jb_permanent2_5.checked = true;
        parent.job_options.document.tourOptions.jb_permanent2_6.checked = true;
      }
      // feiertags
      if (getSelectedVal("job_options", "tourOptions", "jb_permanent") == 9) {
        parent.job_options.document.tourOptions.jb_permanent2_0.checked = false;
        parent.job_options.document.tourOptions.jb_permanent2_1.checked = false;
        parent.job_options.document.tourOptions.jb_permanent2_2.checked = false;
        parent.job_options.document.tourOptions.jb_permanent2_3.checked = false;
        parent.job_options.document.tourOptions.jb_permanent2_4.checked = false;
        parent.job_options.document.tourOptions.jb_permanent2_5.checked = false;
        parent.job_options.document.tourOptions.jb_permanent2_6.checked = false;
      }
    }
  }
  checkJb_permanent2();
  checkMulti();
}

/*
 * checkJb_permanent2
 *   params: -
 *   return: -
 *   global:
 *
 * Auswahl der Tage für Dauerauftrag
 */

function checkJb_permanent2()
{
  var jb_permanent2_0 = "0";
  var jb_permanent2_1 = "0";
  var jb_permanent2_2 = "0";
  var jb_permanent2_3 = "0";
  var jb_permanent2_4 = "0";
  var jb_permanent2_5 = "0";
  var jb_permanent2_6 = "0";

  if (typeof(parent.job_options.document.tourOptions.jb_permanent) == 'undefined')
    return;

  // Sicherstellen, dass die Felder auch enabled sind (wg. Aufruf aus get_saved_tour.php)
  if (getSelectedVal("job_options", "tourOptions", "jb_permanent") == ""
    || getSelectedVal("job_options", "tourOptions", "jb_permanent") > 3
    || parent.job_options.document.tourOptions.jb_permanent.disabled == true) {
  } else {
    parent.job_options.document.tourOptions.jb_permanent2_0.disabled = false;
    parent.job_options.document.tourOptions.jb_permanent2_1.disabled = false;
    parent.job_options.document.tourOptions.jb_permanent2_2.disabled = false;
    parent.job_options.document.tourOptions.jb_permanent2_3.disabled = false;
    parent.job_options.document.tourOptions.jb_permanent2_4.disabled = false;
    parent.job_options.document.tourOptions.jb_permanent2_5.disabled = false;
    parent.job_options.document.tourOptions.jb_permanent2_6.disabled = false;
  }

  if (parent.job_options.document.tourOptions.jb_permanent2_0.checked)
    jb_permanent2_0 = "1";
  if (parent.job_options.document.tourOptions.jb_permanent2_1.checked)
    jb_permanent2_1 = "1";
  if (parent.job_options.document.tourOptions.jb_permanent2_2.checked)
    jb_permanent2_2 = "1";
  if (parent.job_options.document.tourOptions.jb_permanent2_3.checked)
    jb_permanent2_3 = "1";
  if (parent.job_options.document.tourOptions.jb_permanent2_4.checked)
    jb_permanent2_4 = "1";
  if (parent.job_options.document.tourOptions.jb_permanent2_5.checked)
    jb_permanent2_5 = "1";
  if (parent.job_options.document.tourOptions.jb_permanent2_6.checked)
    jb_permanent2_6 = "1";

  parent.job_options.document.tourOptions.jb_permanent2_hidden.value =
    jb_permanent2_0 + jb_permanent2_1 + jb_permanent2_2 + jb_permanent2_3
      + jb_permanent2_4 + jb_permanent2_5 + jb_permanent2_6;
}

function checkStartDate(caller_field) {
  fillDateFields(0, 'job_options', 'tourOptions', caller_field, 'tag', 'monat', 'jahr', 'stunde', 'minute', 'jb_permanent');
  writeJob();
  checkMulti();
}

function checkEndDate(caller_field) {
  fillDateFields(0, 'job_options', 'tourOptions', caller_field, 'endetag', 'endemonat', 'endejahr', '', '', '');
  checkMulti();
}

function checkMulti() {
  if (parent.job_options.document.tourOptions.jb_permanent.disabled != true
    && parent.job_options.document.tourOptions.endetag.value != ""
    && parent.job_options.document.tourOptions.endemonat.value != ""
    && parent.job_options.document.tourOptions.endejahr.value != "") {
    parent.job_options.document.tourOptions.jb_multi.disabled = false;
//    parent.job_options.document.tourOptions.jb_multi_factor.disabled = false;
  } else {
    parent.job_options.document.tourOptions.jb_multi.checked = false;
    parent.job_options.document.tourOptions.jb_multi.disabled = true;
//    parent.job_options.document.tourOptions.jb_multi_factor.disabled = true;
  }
}

/*
 * checkTr_ware_from_to
 *   params: -
 *   return: -
 * Setzen der Hidden-Felder 'tr_ware_from_to_von' und 'tr_ware_from_to_nach' entsprechend
 * der aktuell gesetzten Checkboxes für An und Ab bei Start und Ziel
 *
 */

/*
function checkTr_ware_from_to()
{
  var curTourNo = getCurTourNo();

  // Start: Nur Abholung
  if (parent.job_tour.document.tourForm.tr_ware_from_von.checked && !parent.job_tour.document.tourForm.tr_ware_to_von.checked)
    setJobList(curTourNo, jl_tr_ware_from_to, 1);
  // Start: Nur Anlieferung
  if (!parent.job_tour.document.tourForm.tr_ware_from_von.checked && parent.job_tour.document.tourForm.tr_ware_to_von.checked)
    setJobList(curTourNo, jl_tr_ware_from_to, 2);
  // Start: Anlieferung und Abholung
  if (parent.job_tour.document.tourForm.tr_ware_from_von.checked && parent.job_tour.document.tourForm.tr_ware_to_von.checked)
    setJobList(curTourNo, jl_tr_ware_from_to, 3);
  // Start: Keine Angabe
  if (!parent.job_tour.document.tourForm.tr_ware_from_von.checked && !parent.job_tour.document.tourForm.tr_ware_to_von.checked)
    setJobList(curTourNo, jl_tr_ware_from_to, 0);

  // Ziel: Nur Abholung
  if (parent.job_tour.document.tourForm.tr_ware_from_nach.checked && !parent.job_tour.document.tourForm.tr_ware_to_nach.checked)
    setJobList(curTourNo + 1, jl_tr_ware_from_to, 1);
  // Ziel: Nur Anlieferung
  if (!parent.job_tour.document.tourForm.tr_ware_from_nach.checked && parent.job_tour.document.tourForm.tr_ware_to_nach.checked)
    setJobList(curTourNo + 1, jl_tr_ware_from_to, 2);
  // Ziel: Anlieferung und Abholung
  if (parent.job_tour.document.tourForm.tr_ware_from_nach.checked && parent.job_tour.document.tourForm.tr_ware_to_nach.checked)
    setJobList(curTourNo + 1, jl_tr_ware_from_to, 3);
  // Ziel: Keine Angabe
  if (!parent.job_tour.document.tourForm.tr_ware_from_nach.checked && !parent.job_tour.document.tourForm.tr_ware_to_nach.checked)
    setJobList(curTourNo + 1, jl_tr_ware_from_to, 0);
}
*/

/*
 * checkPayer
 *   params: -
 *   return: -
 *   global: -
 *
 */

function checkPayer(side)
{
  if (typeof(parent.job_tour.document.tourForm.jb_costsplit) == 'undefined')
    return;
  if (side != 0)
    if (cash_payer_select != "1" || side == 1) // nur wenn Kostensplit nicht für Barzahlung mißbraucht wird
      parent.job_tour.document.tourForm.elements[von_fields[jl_csc_id_payer]].checked = false;
  if (side != 1)
    if (cash_payer_select != "1" || side == 0) // nur wenn Kostensplit nicht für Barzahlung mißbraucht wird
      parent.job_tour.document.tourForm.elements[nach_fields[jl_csc_id_payer]].checked = false;
  if (side == 0 || side == 1)
  {
    if (cash_payer_select != "1") { // nur wenn Kostensplit nicht für Barzahlung mißbraucht wird
      parent.job_tour.document.tourForm.jb_cash.checked = false;
      parent.job_tour.document.tourForm.jb_costsplit.checked = false;
    }
    var curTourNo = getCurTourNo();
    var cur_tr_remark = getJobList(curTourNo + side, jl_tr_remark);
    var pos_remString = cur_tr_remark.indexOf("*** BEMERKUNG ZAHLER ***\n");
    if (pos_remString > -1) {
	  cur_tr_remark = cur_tr_remark.substring(0, pos_remString);
      if (side == 0)
        parent.job_tour.document.tourForm.elements[von_fields[jl_tr_remark]].value = cur_tr_remark;
      if (side == 1)
        parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_remark]].value = cur_tr_remark;
//      setJobList(curTourNo + side, jl_tr_remark, cur_tr_remark);
    }
    saveFormFields();
  }
  if (side != 2)
  {
    if (cash_payer_select != "1" || side == 3) { // nur wenn Kostensplit nicht für Barzahlung mißbraucht wird
      parent.job_tour.document.tourForm.jb_cash.checked = false;
      checkCash(false);
    }
  }
  if (side != 3)
  {
    if (cash_payer_select != "1" || side == 2) { // nur wenn Kostensplit nicht für Barzahlung mißbraucht wird
      parent.job_tour.document.tourForm.jb_costsplit.checked = false;
      checkCostsplit(false);
    }
  }
  refreshFormFields();
  // Zahler geändert -> Treibstoffzuschlag muss wieder änderbar sein
  if (side == 0 || side == 1)
  {
    jb_markup_overwrite = 1;
    jb_markup_cr_overwrite = 1;
    checkFixprice(0);
  }
//  if (side == 2 || side == 3)
//  {
//    saveFormFields();
//  }
}

/*
 * checkCash
 *   params: -
 *   return: -
 *   global: job_options, tourOptions, jb_fixprice
 *
 */

function checkCash(doRefresh)
{
  if (!parent.job_tour.document.tourForm.jb_cash.checked)
  {
    // Barzahlung von 'ja' auf 'nein'
//    for (var i = 0; i < (maxTour + 1); i++)
//      if (getJobList(0, jl_csc_id_payer) == "true")
//        setJobList(i, jl_csc_id_payer, "false");
//alert(parent.job_tour.document.tourForm.elements[von_fields[jl_csc_id_payer]].disabled);
//    parent.job_tour.document.tourForm.elements[von_fields[jl_csc_id_payer]].disabled =
//      false;
//    parent.job_tour.document.tourForm.elements[nach_fields[jl_csc_id_payer]].disabled =
//      false;
    parent.job_options.document.tourOptions.jb_cash_hidden.value = "false";
    if (typeof(parent.job_tour.document.tourForm.jb_cashpayer_mail) != 'undefined' && !parent.job_tour.document.tourForm.jb_cashpayer_mail.disabled) {
      parent.job_tour.document.tourForm.jb_cashpayer_mail.value = "";
      parent.job_options.document.tourOptions.jb_cashpayer_mail_hidden.value = "";
    }
    parent.job_tour.document.getElementById("div_jb_cashpayer_mail").style.display = 'none';
    // Kostensplit wieder erlaubt
//    parent.job_tour.document.tourForm.jb_costsplit.disabled = false;
  } else {
    checkPayer(2);
    if (cash_payer_select != "1") // nur wenn Kostensplit nicht für Barzahlung mißbraucht wird
    {
      // Barzahlung von 'nein' auf 'ja'
      for (var i = 0; i < (maxTour + 1); i++)
        setJobList(i, jl_csc_id_payer, "false");
      parent.job_tour.document.tourForm.elements[von_fields[jl_csc_id_payer]].checked =
        false;
//      parent.job_tour.document.tourForm.elements[von_fields[jl_csc_id_payer]].disabled =
//        true;
      parent.job_tour.document.tourForm.elements[nach_fields[jl_csc_id_payer]].checked =
        false;
//      parent.job_tour.document.tourForm.elements[nach_fields[jl_csc_id_payer]].disabled =
//        true;
    }
    if (setCsc_id_payer("", ""))
      parent.job_options.document.tourOptions.jb_cash_hidden.value = "true";
    // Kostensplit nicht mehr erlaubt
//    parent.job_tour.document.tourForm.jb_costsplit.checked = false;
//    checkCostsplit();
//    parent.job_tour.document.tourForm.jb_costsplit.disabled = true;
  }
  if (doRefresh)
    refreshFormFields();
//alert(parent.job_options.document.tourOptions.jb_cash_hidden.value);
}

/*
 * checkCostsplit
 *   params: -
 *   return: -
 *   global: job_options, tourOptions, jb_fixprice
 *
 * Festpreis muss ein glatter Betrag sein.
 */

function checkCostsplit(doRefresh)
{
//alert (parent.job_tour.document.tourForm.jb_costsplit.checked);
  if (!parent.job_tour.document.tourForm.jb_costsplit.checked)
  {
    // Kostenteilung von 'ja' auf 'nein'
    parent.job_options.document.tourOptions.jb_costsplit_hidden.value = "false";
//    for (var i = 0; i < (maxTour + 1); i++)
//      setJobList(i, jl_csc_id_payer, "false");
//    parent.job_tour.document.tourForm.elements[von_fields[jl_csc_id_payer]].disabled =
//      false;
//    parent.job_tour.document.tourForm.elements[nach_fields[jl_csc_id_payer]].disabled =
//      false;
//    refreshFormFields();
    // Barzahlung wieder erlaubt
//    parent.job_tour.document.tourForm.jb_cash.disabled = false;
  } else {
    checkPayer(3);
    if (cash_payer_select != "1") // nur wenn Kostensplit nicht für Barzahlung mißbraucht wird
    {
      // Kostenteilung von 'nein' auf 'ja'
      for (var i = 0; i < (maxTour + 1); i++)
        setJobList(i, jl_csc_id_payer, "false");
      parent.job_tour.document.tourForm.elements[von_fields[jl_csc_id_payer]].checked =
        false;
//      parent.job_tour.document.tourForm.elements[von_fields[jl_csc_id_payer]].disabled =
//        true;
      parent.job_tour.document.tourForm.elements[nach_fields[jl_csc_id_payer]].checked =
        false;
    }
    if (setCsc_id_payer("donotdeleteifcash_payer_select", ""))
      parent.job_options.document.tourOptions.jb_costsplit_hidden.value = "true";
//    parent.job_tour.document.tourForm.elements[nach_fields[jl_csc_id_payer]].disabled =
//      true;
    // Barzahlung nicht mehr erlaubt
//    parent.job_tour.document.tourForm.jb_cash.checked = false;
//    checkCash();
//    parent.job_tour.document.tourForm.jb_cash.disabled = true;
  }
  if (doRefresh)
    refreshFormFields();
}

function setCsc_id_payer(csc_id_payer_val, comp_payer_val)
{
  // aktuell selektierten Zahler erkenn, bevor Meckerei kommt...
  var curTourNo = getCurTourNo();
  var selected_csc_payer = 0;
  if (parent.job_tour.document.tourForm.elements[von_fields[jl_csc_id_payer]].checked)
    selected_csc_id_payer = getJobList(curTourNo, jl_csc_id);
  if (parent.job_tour.document.tourForm.elements[nach_fields[jl_csc_id_payer]].checked)
    selected_csc_id_payer = getJobList(curTourNo + 1, jl_csc_id);

  // hier geht's normal weiter
  if (parent.job_options.document.tourOptions.payer_is_default.value == "true"
    && csc_id_payer_val != selected_csc_payer
    && ((parent.job_options.document.tourOptions.csc_id_payer.value != csc_id_payer_val) || (csc_id_payer_val == "" && ask_defaultpayer_change == "1"))
    && csc_id_payer_val != "donotdeleteifcash_payer_select"
    && ((csc_id_payer_val != csc_id_payer_cash) || ask_defaultpayer_change == "1"))
    if (!confirm("Wollen Sie den voreingestellten Bezahler wirklich ändern?"))
    {
//      for (var i = 0; i < (maxTour + 1); i++)
//        setJobList(i, jl_csc_id_payer, "false");
//      parent.job_tour.document.tourForm.elements[von_fields[jl_csc_id_payer]].checked = false;
//      parent.job_tour.document.tourForm.elements[nach_fields[jl_csc_id_payer]].checked = false;
//      if (parent.job_options.document.tourOptions.csc_id_payer.value != "") {
//        parent.job_options.document.tourOptions.jb_cash_hidden.value = "false";
//        parent.job_tour.document.tourForm.jb_cash.checked = false;
//      } else {
//        parent.job_options.document.tourOptions.jb_cash_hidden.value = "true";
//        parent.job_tour.document.tourForm.jb_cash.checked = true;
//        refreshformfields();
//      }
//      parent.job_options.document.tourOptions.jb_costsplit_hidden.value = "false";
//      parent.job_tour.document.tourForm.jb_costsplit.checked = false;
      return false;
    }
  if (csc_id_payer_val != "donotdeleteifcash_payer_select" &&
    (parent.job_tour.document.tourForm.nameOfPayer.value == "*** Bezahler wählen ***" || csc_id_payer_val != csc_id_payer_cash))
  {
    parent.job_options.document.tourOptions.csc_id_payer.value = csc_id_payer_val;
    parent.job_options.document.tourOptions.comp_payer.value = comp_payer_val;
    parent.job_options.document.tourOptions.payer_is_default.value = "";  
    if (csc_id_payer_val != "")
    {
      for (var i = 0; i < (maxTour + 1); i++)
        setJobList(i, jl_csc_id_payer, "false");
      checkPayer(4);
    }
  }
  return true;
}

/*
 * refreshFormFields
 *   params: -
 *   return: -
 *   global: job_tour, tourForm, von_fields, nach_fields,
 *     jl_csc_id
 *
 * Die aktuell angezeigten Formularfelder werden aus dem Hiddenelement "jobList"
 * wiederhergestellt.
 */

function refreshFormFields()
{
  var curTourNo = getCurTourNo();

  writeJob();

/* nicht für Zentrale Hansetrans
  setSelectedOption(1, 1, von_fields[jl_csc_id], getJobList(curTourNo, jl_csc_id));
  setSelectedOption(1, 1, nach_fields[jl_csc_id], getJobList(curTourNo + 1, jl_csc_id));
*/

  for (var i = 1; i < (von_fields.length - 4); i++)
  {
//alert(parent.job_tour.document.tourForm.elements[von_fields[i]].name +"="+ parent.job_tour.document.tourForm.elements[von_fields[i]].value);
  	if (von_fields[i] != -1) {
      parent.job_tour.document.tourForm.elements[von_fields[i]].value =
        getJobList(curTourNo, i);
    }
  	if (nach_fields[i] != -1) {
      parent.job_tour.document.tourForm.elements[nach_fields[i]].value =
        getJobList(curTourNo + 1, i);
    }
  }
  parent.job_tour.document.tourForm.elements[von_fields[jl_tr_ware_from]].checked =
    (getJobList(curTourNo, jl_tr_ware_from) == "true" ? true : false);
  parent.job_tour.document.tourForm.elements[von_fields[jl_tr_ware_to]].checked =
    (getJobList(curTourNo, jl_tr_ware_to) == "true" ? true : false);
  parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_ware_from]].checked =
    (getJobList(curTourNo + 1, jl_tr_ware_from) == "true" ? true : false);
  parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_ware_to]].checked =
    (getJobList(curTourNo + 1, jl_tr_ware_to) == "true" ? true : false);

  parent.job_tour.document.tourForm.elements[von_fields[jl_hide_tr_remark]].checked =
    (getJobList(curTourNo, jl_hide_tr_remark) == "true" ? true : false);
  parent.job_tour.document.tourForm.elements[von_fields[jl_tr_remark]].disabled =
    (getJobList(curTourNo, jl_hide_tr_remark) == "false" ? true : false);
  parent.job_tour.document.tourForm.elements[nach_fields[jl_hide_tr_remark]].checked =
    (getJobList(curTourNo + 1, jl_hide_tr_remark) == "true" ? true : false);
  parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_remark]].disabled =
    (getJobList(curTourNo + 1, jl_hide_tr_remark) == "false" ? true : false);

  if (von_fields[jl_tr_photo] != -1) {
    parent.job_tour.document.tourForm.elements[von_fields[jl_tr_photo]].checked =
      (getJobList(curTourNo, jl_tr_photo) == "true" ? true : false);
  }
  parent.job_tour.document.tourForm.tr_photo_von.disabled = tr_photo_disabled;
  if (tr_photo_disabled && tr_photo_checked && curTourNo == 0 && !tr_photo_disabled1)
    parent.job_tour.document.tourForm.tr_photo_von.disabled = false;
  if (tr_photo_checked && (curTourNo > 0 || tr_photo_disabled1))
    parent.job_tour.document.tourForm.tr_photo_von.checked = true;
  parent.job_tour.document.tourForm.tr_photo_von.title = "";
  if (typeof(getJobList(curTourNo, jl_tr_id)) != 'undefined') {
    if (get_tr_status(getJobList(curTourNo, jl_tr_id)) == 1) {
      parent.job_tour.document.tourForm.tr_photo_von.disabled = true;
      parent.job_tour.document.tourForm.tr_photo_von.title = "Die Pflichtfoto-Option kann nicht mehr geändert werden, da die Ankunft bei der Station bereits erfolgt ist";
    }
  }
  if (nach_fields[jl_tr_photo] != -1) {
    parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_photo]].checked =
      (getJobList(curTourNo + 1, jl_tr_photo) == "true" ? true : false);
  }
  parent.job_tour.document.tourForm.tr_photo_nach.disabled = tr_photo_disabled;
  if (tr_photo_checked)
    parent.job_tour.document.tourForm.tr_photo_nach.checked = true;
  parent.job_tour.document.tourForm.tr_photo_nach.title = "";
  if (typeof(getJobList(curTourNo + 1, jl_tr_id)) != 'undefined') {
    if (get_tr_status(getJobList(curTourNo + 1, jl_tr_id)) == 1) {
      parent.job_tour.document.tourForm.tr_photo_nach.disabled = true;
      parent.job_tour.document.tourForm.tr_photo_nach.title = "Die Pflichtfoto-Option kann nicht mehr geändert werden, da die Ankunft bei der Station bereits erfolgt ist";
    }
  }

  // Die Bezahler-Felder dürfen nur enabled sein, wenn Kostenstelle Rechnungszahler ist,
  // oder wenn Barzahlung statt Rechnungszahlung ausgewählt ist;
  // Explizite Rechnungszahlung findet statt durch 'Mißbrauch' des Radio-Buttons für Kostensplit 

  if (typeof(parent.job_tour.document.tourForm.jb_costsplit) != 'undefined') {
    parent.job_tour.document.tourForm.elements[von_fields[jl_csc_id_payer]].disabled =
      (getJobList(curTourNo, jl_csc_id_payer) == "disabled" && (cash_payer_select != "1" || parent.job_tour.document.tourForm.jb_costsplit.checked) ? true : false);
    parent.job_tour.document.tourForm.elements[von_fields[jl_csc_id_payer]].checked =
      (getJobList(curTourNo, jl_csc_id_payer) == "true" ? true : false);
    parent.job_tour.document.tourForm.elements[nach_fields[jl_csc_id_payer]].disabled =
      (getJobList(curTourNo + 1, jl_csc_id_payer) == "disabled" && (cash_payer_select != "1" || parent.job_tour.document.tourForm.jb_costsplit.checked) ? true : false);
    parent.job_tour.document.tourForm.elements[nach_fields[jl_csc_id_payer]].checked =
      (getJobList(curTourNo + 1, jl_csc_id_payer) == "true" ? true : false);
  }
  
//  parent.job_tour.document.tourForm.von_tr_commission_noButton.value =
//    (getJobList(curTourNo, jl_tr_commission_no) == "" ? "Ko.-Nr." : "Ko.-Nr.*");
//  parent.job_tour.document.tourForm.nach_tr_commission_noButton.value =
//    (getJobList(curTourNo + 1, jl_tr_commission_no) == "" ? "Ko.-Nr." : "Ko.-Nr.*");

  // Bemerkungsfeld (das berühmte Ctrl-H Feld)
//  if (typeof(parent.job_tour.document.tourForm.von_cmp_remarkButton) != 'undefined') {
    parent.job_tour.document.getElementById("von_cmp_remark_div").innerHTML = get_cs_mail(getJobList(curTourNo, jl_csc_id));
    if (get_cmp_remark(getJobList(curTourNo, jl_csc_id)) != "")
    {
      parent.job_tour.document.getElementById("von_cmp_remark_div").innerHTML += 'Bemerkung links<br><textarea class="input ' + parent.job_tour.cmp_remark_style + '" disabled>' + get_cmp_remark(getJobList(curTourNo, jl_csc_id)) + '</textarea>';
//      parent.job_tour.document.tourForm.von_cmp_remarkButton.disabled = false;
//      parent.job_tour.document.tourForm.von_cmp_remarkButton.className = "commission_no_enabled";
    } else {
      parent.job_tour.document.getElementById("von_cmp_remark_div").innerHTML += '&nbsp;';
//      parent.job_tour.document.tourForm.von_cmp_remarkButton.disabled = true;
//      parent.job_tour.document.tourForm.von_cmp_remarkButton.className = "button_disabled";
    }
//  }
//  if (typeof(parent.job_tour.document.tourForm.nach_cmp_remarkButton) != 'undefined') {
    parent.job_tour.document.getElementById("nach_cmp_remark_div").innerHTML = get_cs_mail(getJobList(curTourNo + 1, jl_csc_id));
    if (get_cmp_remark(getJobList(curTourNo + 1, jl_csc_id)) != "")
    {
      parent.job_tour.document.getElementById("nach_cmp_remark_div").innerHTML += 'Bemerkung rechts<br><textarea class="input ' + parent.job_tour.cmp_remark_style + '" disabled>' + get_cmp_remark(getJobList(curTourNo + 1, jl_csc_id)) + '</textarea>';
//      parent.job_tour.document.tourForm.nach_cmp_remarkButton.disabled = false;
//      parent.job_tour.document.tourForm.nach_cmp_remarkButton.className = "commission_no_enabled";
    } else {
      parent.job_tour.document.getElementById("nach_cmp_remark_div").innerHTML += '&nbsp;';
//      parent.job_tour.document.tourForm.nach_cmp_remarkButton.disabled = true;
//      parent.job_tour.document.tourForm.nach_cmp_remarkButton.className = "button_disabled";
    }
//  }

  // Kundennummer und Kostenstellenname
  parent.job_tour.document.tourNoForm.von_csc_name.value = get_cs_eid(getJobList(curTourNo, jl_csc_id)) + "  " + get_comp(getJobList(curTourNo, jl_csc_id));
  parent.job_tour.document.tourNoForm.nach_csc_name.value = get_cs_eid(getJobList(curTourNo + 1, jl_csc_id)) + "  " + get_comp(getJobList(curTourNo + 1, jl_csc_id));

  // Wenn Sondervereinbarungen vorhanden, dann rot anmalen!
  if (typeof(parent.job_options.document.tourOptions.calcButton) != 'undefined') {
    if (get_cs_srv_list(get_cs_id(curCsc_id_payer), 0) != "")
      parent.job_options.document.tourOptions.calcButton.className = "commission_no_enabled";
    else
      parent.job_options.document.tourOptions.calcButton.className = "button_enabled";
  }
  // check_tr_mediationarea_id(); // wird in writejob() aufgerufen
  check_tr_person(getJobList(curTourNo, jl_csc_id), 0);
  check_tr_person(getJobList(curTourNo + 1, jl_csc_id), 1);
}

// Rg.-Postleitzahl an/aus in Abhängigkeit von aktuellen PLZs
// Sofort Popup für Rg.-Postleitzahl, wenn Eingabe erforderlich aber Wert 0 vorhanden!
function check_tr_mediationarea_id()
{
  if (hq_invmode == 0 || typeof(parent.job_tour.document.tourForm.von_tr_mediationarea_id_Button) == 'undefined')
    return;

  var curTourNo = getCurTourNo();
  // Rg.-Postleitzahl-Button kennzeichnen, wenn Inhalt vorhanden
  parent.job_tour.document.tourForm.von_tr_mediationarea_id_Button.value =
    ((getJobList(curTourNo, jl_tr_mediationarea_id) == "" || getJobList(curTourNo, jl_tr_mediationarea_id) == 0) ? "Rg.-Plz" : "Rg.-Plz*");
  parent.job_tour.document.tourForm.nach_tr_mediationarea_id_Button.value =
    ((getJobList(curTourNo + 1, jl_tr_mediationarea_id) == "" || getJobList(curTourNo + 1, jl_tr_mediationarea_id) == 0) ? "Rg.-Plz" : "Rg.-Plz*");

  // Rg.-Postleitzahl-Button enablen, wenn erforderlich
  parent.job_tour.document.tourForm.von_tr_mediationarea_id_Button.disabled = true;
  parent.job_tour.document.tourForm.von_tr_mediationarea_id_Button.className = "button_disabled";
  for (i = 0; i < fz.length; i++)
  {
    if (fz[i][0] == getJobList(curTourNo, jl_ad_zipcode))
    {
      // Button enablen ...
      parent.job_tour.document.tourForm.von_tr_mediationarea_id_Button.disabled = false;
      parent.job_tour.document.tourForm.von_tr_mediationarea_id_Button.className = "button_enabled";
      // ... und sofort Popup für Rg.-Postleitzahl, wenn Eingabe erforderlich aber Wert 0 vorhanden!
      if (getJobList(curTourNo, jl_tr_mediationarea_id) == 0)
      {
        if (csc_id_payer_cash == "200004") { // erstmal nur Hamburg
        // Default-Wert setzen ...
          setJobList(curTourNo, jl_tr_mediationarea_id, -1);
        } else {
          setJobList(curTourNo, jl_tr_mediationarea_id, fz[i][2]);
          // ... und die Leute nerven
          mk_tr_mediationarea_id(0);
        }
      }
      break;
    }
  }
  parent.job_tour.document.tourForm.nach_tr_mediationarea_id_Button.disabled = true;
  parent.job_tour.document.tourForm.nach_tr_mediationarea_id_Button.className = "button_disabled";
  for (i = 0; i < fz.length; i++)
  {
    if (fz[i][0] == getJobList(curTourNo + 1, jl_ad_zipcode))
    {
      parent.job_tour.document.tourForm.nach_tr_mediationarea_id_Button.disabled = false;
      parent.job_tour.document.tourForm.nach_tr_mediationarea_id_Button.className = "button_enabled";
      if (getJobList(curTourNo + 1, jl_tr_mediationarea_id) == 0)
      {
        if (csc_id_payer_cash == "200004") {
          setJobList(curTourNo + 1, jl_tr_mediationarea_id, -1);
        } else {
          setJobList(curTourNo + 1, jl_tr_mediationarea_id, fz[i][2]);
          mk_tr_mediationarea_id(1);
        }
      }
      break;
    }
  }
}

/*
 * checkTourDirty
 *   params: i
 *   return: true, false
 *   global:
 *
 * Prüfen, ob eine Etappenstelle "dirty" ist; dort werden dann
 * auch visuelle Marker gesetzt
 */

function checkTourDirty(i)
{
  // whitespaces entfernen, dann Länge prüfen für die entscheidenden Felder
  //
  var retVal = false;
  var tourIsNotEmpty = false;
  var tourNo = getCurTourNo();

  // wenn alle Felder leer sind, dann sollen "fehlende" Felder
  // nicht markiert werden!
  if (!(((getJobList(i, jl_tr_comp)).replace(/\s/,"").length == 0) &&
      ((getJobList(i, jl_ad_street)).replace(/\s/,"").length == 0) &&
      ((getJobList(i, jl_tr_hsno)).replace(/\s/,"").length == 0) &&
      ((getJobList(i, jl_ad_zipcode)).replace(/\s/,"").length == 0) &&
      ((getJobList(i, jl_ad_city)).replace(/\s/,"").length == 0)))
    tourIsNotEmpty = true;

  if ((getJobList(i, jl_tr_comp)).replace(/\s/,"").length == 0)
  {
    if (i == tourNo && tourIsNotEmpty)
      parent.job_tour.document.tourForm.elements[von_fields[jl_tr_comp]].className = "inputRed";
    if (i == tourNo + 1 && tourIsNotEmpty)
      parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_comp]].className = "inputRed";
    if (tourIsNotEmpty)
      retVal = true;
  } else {
    if (i == tourNo)
      parent.job_tour.document.tourForm.elements[von_fields[jl_tr_comp]].className = "input";
    if (i == tourNo + 1)
      parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_comp]].className = "input";
  }
  if ((getJobList(i, jl_ad_street)).replace(/\s/,"").length == 0 && tourIsNotEmpty)
  {
    if (i == tourNo && tourIsNotEmpty)
      parent.job_tour.document.tourForm.elements[von_fields[jl_ad_street]].className = "inputRed";
    if (i == tourNo + 1 && tourIsNotEmpty)
      parent.job_tour.document.tourForm.elements[nach_fields[jl_ad_street]].className = "inputRed";
    if (tourIsNotEmpty)
      retVal = true;
  } else {
    if (i == tourNo)
      parent.job_tour.document.tourForm.elements[von_fields[jl_ad_street]].className = "input";
    if (i == tourNo)
      parent.job_tour.document.tourForm.elements[nach_fields[jl_ad_street]].className = "input";
  }
  if ((getJobList(i, jl_tr_hsno)).replace(/\s/,"").length == 0 && tourIsNotEmpty)
  {
    if (i == tourNo && tourIsNotEmpty)
      parent.job_tour.document.tourForm.elements[von_fields[jl_tr_hsno]].className = "inputRed";
    if (i == tourNo + 1 && tourIsNotEmpty)
      parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_hsno]].className = "inputRed";
    if (tourIsNotEmpty)
      retVal = true;
  } else {
    if (i == tourNo)
      parent.job_tour.document.tourForm.elements[von_fields[jl_tr_hsno]].className = "input";
    if (i == tourNo + 1)
      parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_hsno]].className = "input";
  }
  if ((getJobList(i, jl_ad_zipcode)).replace(/\s/,"").length == 0 && tourIsNotEmpty)
  {
    if (i == tourNo && tourIsNotEmpty)
      parent.job_tour.document.tourForm.elements[von_fields[jl_ad_zipcode]].className = "inputRed";
    if (i == tourNo + 1 && tourIsNotEmpty)
      parent.job_tour.document.tourForm.elements[nach_fields[jl_ad_zipcode]].className = "inputRed";
    if (tourIsNotEmpty)
      retVal = true;
  } else {
    if (i == tourNo)
      parent.job_tour.document.tourForm.elements[von_fields[jl_ad_zipcode]].className = "input";
    if (i == tourNo + 1)
      parent.job_tour.document.tourForm.elements[nach_fields[jl_ad_zipcode]].className = "input";
  }
  if ((getJobList(i, jl_ad_city)).replace(/\s/,"").length == 0 && tourIsNotEmpty)
  {
    if (i == tourNo && tourIsNotEmpty)
      parent.job_tour.document.tourForm.elements[von_fields[jl_ad_city]].className = "inputRed";
    if (i == tourNo + 1 && tourIsNotEmpty)
      parent.job_tour.document.tourForm.elements[nach_fields[jl_ad_city]].className = "inputRed";
    if (tourIsNotEmpty)
      retVal = true;
  } else {
    if (i == tourNo)
      parent.job_tour.document.tourForm.elements[von_fields[jl_ad_city]].className = "input";
    if (i == tourNo + 1)
      parent.job_tour.document.tourForm.elements[nach_fields[jl_ad_city]].className = "input";
  }
  if (tourIsNotEmpty && MASK_COMMISSION_NO_MANDATORY == "1" && trim(parent.job_tour.document.tourForm.jb_commission_no.value) == "" && is_commission_no(curCsc_id_payer))
    retVal = true; 

//  Ab 01.12.2025 komplett weggefallen bis auf check von MASK_COMMISSION_NO_MANDATORY
//  // Durch den Wegfall des Ko.-Nr. Buttons muss die Farbgebung des neuen Ko.-Nr.-Feldes überprüft werden, damit das konsistent ist
//  // Es ist zwar ein wenig ineffizient, das hier jedes Mal zu machen, aber frisst ja kein Brot...
//  var tr_commission_no_needed = false;
//  if (is_commission_no(curCsc_id_payer))
//  {
//    tr_commission_no_needed = true;
//    for (var j = 0; j < (maxTour + 1); j++)
//    {
//       if ((getJobList(j, jl_tr_commission_no)).replace(/\s/,"").length != 0) {
//         tr_commission_no_needed = false;
//         break;
//      }
//    }
//  }
//  if ((getJobList(i, jl_tr_commission_no)).replace(/\s/,"").length == 0 && tr_commission_no_needed && tourIsNotEmpty)
//  {
//    if (i == tourNo && tourIsNotEmpty)
//      parent.job_tour.document.tourForm.elements[von_fields[jl_tr_commission_no]].className = "inputRed";
//    if (i == tourNo + 1 && tourIsNotEmpty)
//      parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_commission_no]].className = "inputRed";
//    // Trotz fehlender Ko.-Nr. soll die Tour sendbar bleiben (nur wenn Parameter MASK_COMMISSION_NO_MANDATORY nicht auf "1" gesetzt ist)
//    if (tourIsNotEmpty && MASK_COMMISSION_NO_MANDATORY == "1")
//      retVal = true; 
//  } else {
//    if (i == tourNo)
//      parent.job_tour.document.tourForm.elements[von_fields[jl_tr_commission_no]].className = "input";
//    if (i == tourNo + 1)
//      parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_commission_no]].className = "input";
//  }

  if (i == 0) {
    if ((getJobList(i, jl_tr_commission_no)).replace(/\s/,"").length == 0) {
      setJobList(0, jl_tr_commission_no, get_cs_comm_prefix(curCsc_id_payer));
    } else {
      if ((getJobList(i, jl_tr_commission_no)).replace(/\s/,"").substr(0, get_cs_comm_prefix(curCsc_id_payer).length) != get_cs_comm_prefix(curCsc_id_payer)) {
        setJobList(0, jl_tr_commission_no, get_cs_comm_prefix(curCsc_id_payer) + " " + ((getJobList(i, jl_tr_commission_no)).replace(/\s/,"")));
      }
    }
  }
  return retVal;
}

/*
 * prevTour
 *   params: -
 *   return: -
 *   global: -
 *
 * Um eine Etappe in der jobList zurück gehen. Die angezeigten Navigationselemente
 * werden ggfs. an-/ausgeschaltet.
 */

function prevTour()
{
  if (getCurTourNo() > 0) setCurTourNo(getCurTourNo() - 1);
}

/*
 * prevTour
 *   params: -
 *   return: -
 *   global: -
 *
 * Um eine Etappe in der jobList nach vorne gehen. Die angezeigten Navigationselemente
 * werden ggfs. an-/ausgeschaltet.
 */

function nextTour()
{
  if (getCurTourNo() < maxTour - 1) setCurTourNo(getCurTourNo() + 1);
}

/*
 * moveToTour
 *   params: toTourNo
 *   return: -
 *   global: isCurrentlySubmitting, jl_csc_id
 *
 * Auf eine bestimmte Etappe in der jobList gehen,
 * danach die zu dieser Etappe gehörenden Adressen vom Server holen.
 */

function moveToTour(toTourNo)
{
  var curTourNo = getCurTourNo();
  var tempWin;
//alert (isCurrentlySubmitting);
  if (parent.job_options.isCurrentlySubmitting)
    return;
//alert (curTourNo + "," + toTourNo);

  while (curTourNo > toTourNo)
  {
    prevTour();
    curTourNo = getCurTourNo();
  }
  while (curTourNo < toTourNo)
  {
    nextTour();
    curTourNo = getCurTourNo();
  }

  // wenn zwei neue Kostenstellen, dann nicht Adresse(n) vom Server holen
  if (((getJobList(curTourNo, jl_csc_id)).replace(/\s/,"").length == 0) &&
    ((getJobList(curTourNo + 1, jl_csc_id)).replace(/\s/,"").length == 0))
    return;
  tempWin = mkPopupWin(
    "function startReload()\n" +
    "{\n" +
    "  checkDone();\n" +
    "  self.location.href=\"../jobs/get_address.php"
       + "?csc_id1=" + getJobList(curTourNo, jl_csc_id)
       + "&csc_id2=" + getJobList(curTourNo + 1, jl_csc_id) + "\";\n" +
    "}\n" +
    "\n" +
    "//--" + ">\n" +
    "<\/script>\n" +
    "<\/head>\n" +
    "<body onLoad=\"startReload()\"\n>" +
    "  <table border=0 align=center height=100% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n" +
    "    <tr>\n" +
    "      <td align=center valign=center>\n" +
    "        <b>Hole Daten...</b>\n" +
    "      <\/td>\n" +
    "    <\/tr>\n" +
    "  <\/table>\n" +
    "<\/body>\n" +
    "<\/html>\n", 0, 0);
}

/*
 * delTour
 *   params: side
 *   return: -
 *
 * Löscht eine komplette Etappe, alle nachfolgenden
 * Etappen rücken um eine Stelle nach vorne. side = 0 bedeutet, dass die
 * aktuell links angezeigt Adresse gelöscht wird, side = 1 die aktuell rechte.
 */

function delTour(side)
{
  var curTourNo = getCurTourNo();
  var delTourNo = curTourNo + side;

  while (delTourNo < maxTour + 1)
    delJobList(delTourNo++, true);
  refreshFormFields();
//  writeJob();
}

/*
 * csc_idChange
 *   params: side
 *   return: -
 *   global: von_fields, nach_fields
 *
 * Wenn eine neue Kostenstelle selektiert wird, dann wird verhindert, dass auf beiden
 * Seiten dieselbe Kostenstelle erscheint (Start immer ungleich Ziel).
 * Der Inhalt der geänderten Etappenstelle wird gelöscht, damit nicht evtl. falsche
 * Adressdaten darin stehen; side = 0 bedeutet, dass die aktuell links angezeigte
 * Adresse gelöscht wird, side = 1 die aktuell rechte.
 */

function csc_idChange(side)
{
  var curTourNo = getCurTourNo();
  var delTourNo = curTourNo + side;

/*  if (getSelectedVal("job_tour", "tourForm", von_fields[0]) == getSelectedVal("job_tour", "tourForm", nach_fields[0]))
    if (side == 0)
else
*/
  delJobList(delTourNo, false);

  setJobList(curTourNo, jl_csc_id, getSelectedVal("job_tour", "tourForm", von_fields[jl_csc_id]));
  setJobList(curTourNo + 1, jl_csc_id, getSelectedVal("job_tour", "tourForm", nach_fields[jl_csc_id]));
//  disableSelectOption("job_tour", "tourForm", nach_fields[0], getSelectedVal("job_tour", "tourForm", von_fields[0]));
//  disableSelectOption("job_tour", "tourForm", von_fields[0], getSelectedVal("job_tour", "tourForm", nach_fields[0]));
  if (parent.job_tour.document.tourForm.jb_costsplit.checked || parent.job_tour.document.tourForm.jb_cash.checked ||
    parent.job_options.document.tourOptions.csc_id_payer.value != "")
  {
    setJobList(curTourNo, jl_csc_id_payer, "disabled");
    setJobList(curTourNo + 1, jl_csc_id_payer, "disabled");
  }

  refreshFormFields();
//  writeJob();
}

/*
 * is_Extern
 *   params: csc_id
 *   return: true / false
 *   global: cs_eid_list
 *
 * Prüfen, ob übergebene csc_id in globalem Array cs_eid_list vorhanden ist
 * (kann dann kein Bezahler sein)
 */

function is_Extern(csc_id)
{
  // Wenn ein Kunde für Rechnungszahlung gesperrt ist, dann muss er hier als "extern" gelten
  if (cash_payer_select == "1" && parent.job_tour.document.tourForm.jb_costsplit.checked)
    if(is_cashpayer_only(csc_id))
      return true;

  // leere csc_id ist extern
  if (csc_id.replace(/\s/,"").length == 0)
    return true;
//  for (var i = 0; i < cs_eid_list.length; i++)
//    if (cs_eid_list[i] == csc_id)
//      return true;
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id)
      if (cs_eid_list[i][1] != "" && cs_eid_list[i][1] != 0)
        if (cs_eid_list[i][11] != 1)
//  alert("is_Extern(" + csc_id + ") = false");      
          return false;
  return true;
}

/*
 * get_cs_eid
 *   params: csc_id
 *   return: comp
 *   global: cs_eid_list
 *
 * Kundennummer der übergebenen csc_id finden
 */

function get_cs_eid(csc_id)
{
  // leere csc_id hat keine cs_eid
  if (csc_id.replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id)
      return cs_eid_list[i][1];
  return "";
}

/*
 * is_commission_no
 *   params: csc_id
 *   return: true / false
 *   global: cs_eid_list
 *
 * Prüfen, ob bei übergebener csc_id eine Kommissionsnummer eingetragen werden muss
 */

function is_commission_no(csc_id)
{
  // leere csc_id hat keine commission_no
  if (csc_id.replace(/\s/,"").length == 0)
    return false;
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id)
      if (cs_eid_list[i][2] == 1)
        return true;
  return false;
}

/*
 * is_cash_payer_only
 *   params: csc_id
 *   return: true / false
 *   global: cs_eid_list
 *
 * Prüfen, ob übergebene csc_id nur Barzahler sein darf
 */

function is_cashpayer_only(csc_id)
{
  if (csc_id.replace(/\s/,"").length == 0)
    return false;
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id)
      if (cs_eid_list[i][4] == 0)
        return true;
  return false;
}

/*
 * get_comp
 *   params: csc_id
 *   return: comp
 *   global: cs_eid_list
 *
 * Namen der übergebenen csc_id finden
 */

function get_comp(csc_id)
{
  // leere csc_id hat keine comp
  if (csc_id.replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id)
      return cs_eid_list[i][3];
  return "";
}

/*
 * get_cmp_remark
 *   params: csc_id
 *   return: comp
 *   global: cs_eid_list
 *
 * Bemerkung (Ctrl-H Feld) der übergebenen csc_id finden
 */

function get_cmp_remark(csc_id)
{
  // leere csc_id hat kein cmp_remark
  if (csc_id.replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id)
      return cs_eid_list[i][5];
  return "";
}

/*
 * get_cs_jobbatch
 *   params: csc_id
 *   return: comp
 *   global: cs_eid_list
 *
 * Bemerkung (Ctrl-H Feld) der übergebenen csc_id finden
 */

function get_cs_jobbatch(csc_id)
{
  // leere csc_id hat kein cmp_remark
  if (csc_id.replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id)
      return cs_eid_list[i][6];
  return "";
}

/*
 * get_cs_discount
 *   params: csc_id
 *   return: comp
 *   global: cs_eid_list
 *
 * Globalen Rabattsatz der übergebenen csc_id finden
 */

function get_cs_discount(csc_id)
{
  // leere csc_id hat kein cmp_remark
  if (csc_id.replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id)
      return cs_eid_list[i][7];
  return "";
}

/*
 * get_cs_filter
 *   params: csc_id
 *   return: comp
 *   global: cs_eid_list
 *
 * Voreingestellte Kurierfilter der übergebenen csc_id finden
 */

function get_cs_filter(csc_id)
{
  // leere csc_id hat keine Filter
  if (csc_id.replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id)
      return cs_eid_list[i][8];
  return "";
}

/*
 * get_tx_id
 *   params: csc_id
 *   return: comp
 *   global: cs_eid_list
 *
 * Voreingestellten Steuersatz der übergebenen csc_id finden
 */

function get_tx_id(csc_id)
{
  // leere csc_id bekommt Default-Steuersatz
  if (csc_id.replace(/\s/,"").length == 0)
    return 4;
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id && cs_eid_list[i][9] != 0)
      return cs_eid_list[i][9];
  return 4; // Default-Steuersatz
}

/*
 * get_name
 *   params: csc_id
 *   return: name
 *   global: cs_eid_list
 *
 * Kostenstellennamen der übergebenen csc_id finden
 */

function get_name(csc_id)
{
  // leere csc_id hat keinen Namen
  if (csc_id.replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id)
      return cs_eid_list[i][10];
  return "";
}

/*
 * get_cs_id
 *   params: csc_id
 *   return: cs_id
 *   global: cs_eid_list
 *
 * cs_id der übergebenen csc_id finden
 */

function get_cs_id(csc_id)
{
  // leere csc_id hat keine cs_id
  if (csc_id.replace(/\s/,"").length == 0)
    return 0;
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id)
      return cs_eid_list[i][12];
  return 0;
}

/*
 * get_cs_fixprice_discount
 *   params: csc_id
 *   return: cs_fixprice_discount
 *   global: cs_eid_list
 *
 * Rabattsatz default ja/nein
 */

function get_cs_fixprice_discount(csc_id)
{
  // leere csc_id hat kein cs_fixprice_discount
  if (csc_id.replace(/\s/,"").length == 0)
    return 0;
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id)
      return cs_eid_list[i][13];
  return 0;
}

/*
 * get_cs_fixprice_prov
 *   params: csc_id
 *   return: cs_prov
 *   global: cs_eid_list, MASK_CS_PROV_DEFAULT
 *
 * Rabattsatz default ja/nein
 */

function get_cs_prov(csc_id)
{
  // leere csc_id hat kein cs_prov
  if (csc_id.replace(/\s/,"").length == 0)
    return MASK_CS_PROV_DEFAULT;
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id && parseFloat(cs_eid_list[i][14]) > 0) {
      return cs_eid_list[i][14];
}
  return MASK_CS_PROV_DEFAULT;
}

function get_cs_comm_prefix(csc_id)
{
  // leere csc_id hat kein cs_comm_prefix
  if (csc_id.replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id && cs_eid_list[i][17] != '') {
      return cs_eid_list[i][17];
  }
  return "";
}

function get_cs_mail(csc_id)
{
  // leere csc_id hat kein cs_mail
  if (csc_id.replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id && cs_eid_list[i][18] != '') {
      return'<span style="color:blue;font-size: 9pt;color: #0000CC">' + cs_eid_list[i][18] + '</span><br><br>';
  }
  return "";
}

function get_cs_ask_mailrecipients(csc_id)
{
  // leere csc_id hat kein cs_mail
  if (csc_id.replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id && cs_eid_list[i][23] != '') {
      return cs_eid_list[i][23];
  }
  return "";
}


function get_cs_jb_jam_waittime(csc_id)
{
  // leere csc_id hat kein cs_comm_prefix
  if (csc_id.replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id && cs_eid_list[i][19] != '') {
      return cs_eid_list[i][19];
  }
  return "";
}

function get_cs_tracking(csc_id)
{
  // leere csc_id hat kein tracking
  if (csc_id.replace(/\s/,"").length == 0)
    return 0;
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id && cs_eid_list[i][20] != '') {
      return cs_eid_list[i][20];
  }
  return 0;
}

/*
 * get_invmail
 *   params: csc_id
 *   return: comp
 *   global: cs_eid_list
 *
 * Namen der übergebenen csc_id finden
 */

function get_invmail(csc_id)
{
  // leere csc_id hat keine comp
  if (csc_id.replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id)
      return cs_eid_list[i][21];
  return "";
}

function get_cs_jb_incomplete(csc_id)
{
  // leere csc_id hat keine comp
  if (csc_id.replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id)
      return cs_eid_list[i][22];
  return "";
}

function get_cs_invmode(csc_id)
{
  // leere csc_id hat keine comp
  if (csc_id.replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id)
      return cs_eid_list[i][24];
  return "";
}

function get_cs_photo(csc_id)
{
  if (csc_id.replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_eid_list.length; i++)
    if (cs_eid_list[i][0] == csc_id)
      return cs_eid_list[i][25];
  return new Array(0,0,0,'','');
}

function add_cs_eid(csc_id, cs_eid, cs_commission_no, comp, cmp_authenticated, cmp_remark, cs_jobbatch, cs_discount, cs_filter, tx_id, name, is_extern, cs_id, cs_fixprice_discount, cs_prov, cmp_stax_idno, comm_prefix, cs_jb_jam_waittime, cs_tracking, cs_invmail, cs_jb_incomplete, cs_invmode)
{
  var i = cs_eid_list.length;
  cs_eid_list[i] = new Array();
  cs_eid_list[i][0] = csc_id;
  cs_eid_list[i][1] = cs_eid;
  cs_eid_list[i][2] = cs_commission_no;
  cs_eid_list[i][3] = comp;
  cs_eid_list[i][4] = cmp_authenticated;
  cs_eid_list[i][5] = cmp_remark;
  cs_eid_list[i][6] = cs_jobbatch;
  cs_eid_list[i][7] = cs_discount;
  cs_eid_list[i][8] = cs_filter;
  cs_eid_list[i][9] = tx_id;
  cs_eid_list[i][10] = name;
  cs_eid_list[i][11] = is_extern;
  cs_eid_list[i][12] = cs_id;
  cs_eid_list[i][13] = cs_fixprice_discount;
  cs_eid_list[i][14] = cs_prov;
  cs_eid_list[i][15] = cmp_stax_idno;
  cs_eid_list[i][16] = new Array();

  ajaxRequestGet('../include/ajaxReqJob.php', 'cs_id=' + cs_id);
  if (retValue.length != 0) {
    for (var j = 0; j < retValue.length; j++) {
      cs_eid_list[i][16][j] = retValue[j];
    }
  }
  cs_eid_list[i][17] = comm_prefix;
  
  ajaxRequestGet('../include/ajaxReqJob.php', 'csc_id=' + csc_id);
  cs_eid_list[i][18] = retValue;

  cs_eid_list[i][19] = cs_jb_jam_waittime;
  cs_eid_list[i][20] = cs_tracking;
  cs_eid_list[i][21] = cs_invmail;
  cs_eid_list[i][22] = cs_jb_incomplete;

  ajaxRequestGet('../include/ajaxReqJob.php', 'csc_id_ask_mail=' + csc_id + "&cs_id_ask_mail=" + cs_id + "&hq_id=" + hq_id + "&vht_id=" + parent.job_options.document.tourOptions.vht_id.value + "&csc_id_payer_cash=" + csc_id_payer_cash);
  cs_eid_list[i][23] = retValue;
  cs_eid_list[i][24] = cs_invmode;

  ajaxRequestGet('../include/ajaxReqJob.php', 'cs_id_photo=' + cs_id);
  cs_eid_list[i][25] = retValue;

  tr_photo_disabled = false;
  tr_photo_disabled1 = false;
  tr_photo_checked = false;
  tr_photo_label0 = "";
  tr_photo_label = "";
}

/*
 * mkFieldsReloadPrice
 *   params: -
 *   return: -
 *   global:
 *
 */

function mkFieldsReloadPrice()
{
  var mkFieldsReloadPriceVal = "";
  for (var i = 0; i < parent.job_options.document.tourOptions.elements.length; i++)
  {
//if (parent.job_options.document.tourOptions.elements[i].name == "jb_id")
//  alert(parent.job_options.document.tourOptions.elements[i].value);

    mkFieldsReloadPriceVal +=
      "<input type=\"hidden\" name=\"" +
        parent.job_options.document.tourOptions.elements[i].name + "\" value=\"";
    if (parent.job_options.document.tourOptions.elements[i].name == "jb_discount") {
      if (parent.job_options.document.tourOptions.jb_discount.checked == true)
        mkFieldsReloadPriceVal += "1";
    } else {
      mkFieldsReloadPriceVal +=
        parent.job_options.document.tourOptions.elements[i].value.replace(/"/g,"\\x22");
	}
    mkFieldsReloadPriceVal += "\">\n";
  }
  return mkFieldsReloadPriceVal;
}


function resetSignificantPriceValues()
{
  significantPriceValues = "";
}

/*
 * writeJob
 *   params: -
 *   return: -
 *   global: job_tour, job_options, tourOptions, toursubmit, job_tour_list, maxTour,
 *     jl_csc_id
 *
 * Die aktuelle jobList wird im untersten Frame angezeigt, das dazu komplett neu
 * geschrieben werden muss. Die Etappenstellen werden mit ihrem Kostenstellennamen
 * identifiziert.
 */

var significantOptimizationValues = "";
var has_just_been_optimized = false;
function writeJob()
{
  var tourlink;

  checkSendTour();

  // wenn Nachbearbeitung, dann soll Link zu den Details verfügbar sein
  var detailLink = "";
  if (jb_id != "") {
    detailLink = "<a href=\"javascript:popupWindow('../admin/jb_detail.php?job_id=" + jb_id + "','Auftrag','scrollbars=yes,width=800,height=500');\">Auftragsdetails</a>";
    // Im Kundenmodus anderer Link!!!
    if (parent.job_options.csc_id_orderer != "" && parent.job_options.csc_id_orderer != "0")
      detailLink = "<a href=\"javascript:popupWindow('../customer/jb_detail.php?job_id=" + jb_id + "','Auftrag','scrollbars=yes,width=800,height=500');\">Auftragsdetails</a>";
  }

  // wenn Dispositionsmodus, dann soll Link zur Listenerfassung verfügbar sein
  var listLink = "";
  if (empModeLaterJob == "1") {
    listLink = "<a href=\"../jobs/jb_edit_batch.php\" target=\"_parent\">Listenerfassung</a>";
    if (empModeLaterJobWithNormal == "1") {
      listLink += "<br>&nbsp;<br><a href=\"../jobs/job_edit.php?disp=true\" target=\"_blank\">Dispositions-Maske</a>";
    }
    // wenn die normale Maske auch noch zur Verfügung stehen soll, dann soll Link zur normalen Erfassung verfügbar sein!
  }

  // check whether we need to get a new price from the server
  var curSignificantPriceValues = parent.job_options.document.tourOptions.vht_id.value.toString() + "" + curCsc_id_payer + "" + parent.job_options.document.tourOptions.jb_markup.value.toString() + 
    parent.job_options.document.tourOptions.jb_cr_markup.value.toString() + parent.job_options.document.tourOptions.tag.value.toString() + parent.job_options.document.tourOptions.monat.value.toString() +
    parent.job_options.document.tourOptions.jahr.value.toString() + parent.job_options.document.tourOptions.jb_discount.checked.toString();
  if (MASK_CR_PRICE_MODE == "1")
    curSignificantPriceValues += parent.job_options.document.tourOptions.jb_fixprice.value + parent.job_options.document.tourOptions.jb_serviceprice.value +
      parent.job_options.document.tourOptions.jb_cr_price.value;
  var curSignificantOptimizationValues = "";
  var j = 0;
  while ((getJobList(j, jl_csc_id) != "" || checkTourComplete(j)))
  {
    curSignificantPriceValues += getJobList(j, jl_ad_street) + getJobList(j, jl_tr_hsno) + getJobList(j, jl_ad_zipcode) + getJobList(j, jl_ad_city);
    curSignificantOptimizationValues += getJobList(j, jl_ad_street) + getJobList(j, jl_tr_hsno) + getJobList(j, jl_ad_zipcode) + getJobList(j, jl_ad_city);
    if (++j >= maxTour)
      break;
  }
  if (!has_just_been_optimized && (significantOptimizationValues == "" || significantOptimizationValues != curSignificantOptimizationValues) &&
    (parent.job_options.cur_jb_status == "" || parent.job_options.cur_jb_status == "9") && j > 3 && j < 26) {
    parent.job_tour.document.getElementById("div_optimize").style.display = 'inline';
  } else {
	if (has_just_been_optimized) {
      significantOptimizationValues = curSignificantOptimizationValues;
      has_just_been_optimized = false;
    }
    parent.job_tour.document.getElementById("div_optimize").style.display = 'none';
  }
  var onLoadFunc = "";
//alert(parent.job_tour.document.tourForm.nameOfPayer.value);
//alert(significantPriceValues + "\n\n" +  curSignificantPriceValues);
  if (significantPriceValues != curSignificantPriceValues && parent.job_tour.document.tourForm.nameOfPayer.value != "")
  {
    significantPriceValues = curSignificantPriceValues;
    onLoadFunc = "reloadPrice();\n";
//    alert("Preis wird aktualisiert");
    if (parent.job_tour.$('#div_distanceprice').html() != "")
      openDistanceprice(0);
    if (parent.job_tour.$('#div_zoneprice').html() != "")
      openDistanceprice("zone");
  }
  var i_payer = -1;
  // wenn nicht Kostenteilung, dann ... oder halt Kostenteilungsmißbrauch für Rechnungszahlung
  if(typeof(parent.job_tour.document.tourForm.jb_costsplit)!='undefined') {
    if (((!parent.job_tour.document.tourForm.jb_costsplit.checked &&
        !parent.job_tour.document.tourForm.jb_cash.checked) || (cash_payer_select == "1")) &&
      parent.job_options.document.tourOptions.csc_id_payer.value == "")
    { 
      var payer_selected = false;
      for (i = 0; i <= j; i++)
      {
//alert(i + ": jl_csc_id_payer:" + getJobList(i, jl_csc_id_payer) + ", jl_csc_id:" + getJobList(i, jl_csc_id));
        // prüfen, ob Bezahler-Radiobutton disabled war; wenn ja, dann
        // wieder enablen (wenn nicht externe Kostenstelle)
        // bei dieser Gelegenheit prüfen, ob überhaupt ein Bezahler
        // vorhanden
        // wenn nicht, dann wird die erste Kostenstelle Bezahler
        // (wenn nicht extern und nicht leer)
        if (getJobList(i, jl_csc_id_payer) == "disabled")
        {
          if (!is_Extern(getJobList(i, jl_csc_id)))
            setJobList(i, jl_csc_id_payer, "false");
        } else {
          // wenn Payer gefunden, dann in jedem Fall merken, auch wenn extern
          // (in Berlin kann der Zahler auch extern sein, wenn er Barzahler ist!)
          if (getJobList(i, jl_csc_id_payer) == "true")
          {
            payer_selected = true;
            i_payer = i;
          }
          if (is_Extern(getJobList(i, jl_csc_id)))
          {       
            if (cash_payer_select != "1" || parent.job_tour.document.tourForm.jb_costsplit.checked)
              setJobList(i, jl_csc_id_payer, "disabled");
          }
        }
      }
    // prüfen, ob ein Bezahler gesetzt ist
//// <--- honk --->
//    if (!payer_selected)
//    {
//      i = 0;
//      // erste nicht externe Kostenstelle finden, die nicht Bezahler ist
//      while (is_Extern(getJobList(i, jl_csc_id)) && i <= j)
//        i++;
//      // wenn nur externe Kostenstelle, dann kein Bezahler...
//      if (i <= j) {
//        setJobList(i, jl_csc_id_payer, "true");
//        i_payer = i;
//      }
//    }
//// <--- honk --->
    }
  }
  var oldCurCsc_id_payer = curCsc_id_payer;
  // externer Bezahler?
  if (parent.job_options.document.tourOptions.csc_id_payer.value != ""
    && parent.job_options.document.tourOptions.csc_id_payer.value!=csc_id_payer_cash)
  {
    parent.job_tour.document.tourForm.nameOfPayer.value =
      /*"Rechnung an: " +*/ parent.job_options.document.tourOptions.comp_payer.value;
    curCsc_id_payer = parent.job_options.document.tourOptions.csc_id_payer.value;
  } else {
    if (i_payer > -1 && !parent.job_tour.document.tourForm.jb_cash.checked) {
      // Bezahler schreiben, wenn nicht bar        
      curCsc_id_payer = getJobList(i_payer, jl_csc_id);
      parent.job_tour.document.tourForm.nameOfPayer.value =
        /*"Rechnung an: " +*/ get_comp(curCsc_id_payer);
      if (parent.job_options.document.tourOptions.dont_change_tx.value != "true") {
        checkJb_sales_tax_rate_sign(get_tx_id(curCsc_id_payer));
      } else {
        checkJb_sales_tax_rate_sign(0);
      }
      checkCs_filter(get_cs_filter(curCsc_id_payer), get_cs_jb_incomplete(curCsc_id_payer));
    }
    else {
      if (typeof(parent.job_tour.document.tourForm.jb_cash) != 'undefined')
      {
        if (parent.job_tour.document.tourForm.jb_cash.checked
          || parent.job_options.document.tourOptions.csc_id_payer.value == csc_id_payer_cash) {
          parent.job_tour.document.tourForm.nameOfPayer.value =
            "*** Barzahlung ***";
          if (parent.job_options.document.tourOptions.csc_id_payer.value == csc_id_payer_cash)
          {
            parent.job_tour.document.tourForm.jb_cash.checked = true;
            parent.job_tour.document.tourForm.jb_costsplit.checked = false;
            if (setCsc_id_payer("", ""))
              parent.job_options.document.tourOptions.jb_cash_hidden.value = "true";
            parent.job_options.document.tourOptions.payer_is_default.value = "";
          }
          if (cash_payer_select != "1")
          {
            curCsc_id_payer = "-1";
            if (csc_id_payer_cash != "") {
              curCsc_id_payer = csc_id_payer_cash;
            }
          } else {
            if (i_payer > -1)
              curCsc_id_payer = getJobList(i_payer, jl_csc_id);
            else
              curCsc_id_payer = "";
          }
          parent.job_tour.document.getElementById("div_jb_cashpayer_mail").style.display = 'inline';
        } else {
          parent.job_tour.document.tourForm.nameOfPayer.value = "";
          if (parent.job_tour.document.tourForm.jb_costsplit.checked) {
            parent.job_tour.document.tourForm.nameOfPayer.value =
            (cash_payer_select != "1" ? "*** Kostenteilung ***" : "*** Bezahler wählen ***");
          curCsc_id_payer = "0";
          }
        }
      }
    }
  }
  if (trim(parent.job_options.document.tourOptions.cs_invmail_hidden.value) == "")
    parent.job_tour.document.tourForm.invmailOfPayer.value =
      get_invmail(curCsc_id_payer);
  if (curCsc_id_payer != "" && curCsc_id_payer != "0" && !parent.job_tour.document.tourForm.jb_cash.checked && get_invmail(curCsc_id_payer) == "") {
    if (trim(parent.job_options.document.tourOptions.cs_invmail_hidden.value) == "")
      parent.job_tour.document.tourForm.invmailOfPayer.className = "inputRed";
      parent.job_tour.document.tourForm.invmailOfPayer.readOnly = false;
  } else {
    parent.job_tour.document.tourForm.invmailOfPayer.className = "hideRed";
    parent.job_tour.document.tourForm.invmailOfPayer.readOnly = true;
  }

  // Achtung Berlin: Listenzahler!!
  if (get_cs_jobbatch(curCsc_id_payer) == 1)
    parent.job_tour.document.tourForm.nameOfPayer.value =
      "*** Listenkunde ***";

  // Wenn globaler Kundenrabatt, dann auch bei Fest- und Servicepreis berücksichtigen
  checkDiscount();

  var curTourNo = getCurTourNo();
  
  // Rg.-Postleitzahl an/aus in Abhängigkeit von aktuellen PLZs
  check_tr_mediationarea_id();

  if (is_commission_no(curCsc_id_payer))
  {
//    parent.job_tour.document.tourForm.von_tr_commission_noButton.disabled = false;
//    parent.job_tour.document.tourForm.von_tr_commission_noButton.className = "commission_no_enabled";
//    parent.job_tour.document.tourForm.nach_tr_commission_noButton.disabled = false;
//    parent.job_tour.document.tourForm.nach_tr_commission_noButton.className = "commission_no_enabled";
//      parent.job_tour.document.tourForm.von_tr_commission_no.className = "inputRed";
//      parent.job_tour.document.tourForm.von_tr_commission_no.disabled = false;
//      parent.job_tour.document.tourForm.nach_tr_commission_no.className = "inputRed";
//      parent.job_tour.document.tourForm.nach_tr_commission_no.disabled = false;
      parent.job_tour.document.tourForm.jb_commission_no.className = "inputRed";
      parent.job_tour.document.tourForm.jb_commission_no.disabled = false;
  } else {
//    parent.job_tour.document.tourForm.von_tr_commission_noButton.disabled = true;
//    parent.job_tour.document.tourForm.von_tr_commission_noButton.className = "commission_no_disabled";
//    parent.job_tour.document.tourForm.nach_tr_commission_noButton.disabled = true;
//    parent.job_tour.document.tourForm.nach_tr_commission_noButton.className = "commission_no_disabled";
//      parent.job_tour.document.tourForm.von_tr_commission_no.className = "input";
//      parent.job_tour.document.tourForm.von_tr_commission_no.disabled = true;
//      parent.job_tour.document.tourForm.nach_tr_commission_no.className = "input";
//      parent.job_tour.document.tourForm.nach_tr_commission_no.disabled = true;
      parent.job_tour.document.tourForm.jb_commission_no.className = "input";
      parent.job_tour.document.tourForm.jb_commission_no.disabled = true;
  }
  // Kommissionsnummernfeld an/aus in Abhängigkeit vom Bezahler
  if (trim(parent.job_tour.document.tourForm.jb_commission_no.value) != "" || !is_commission_no(curCsc_id_payer)) {
    parent.job_tour.document.tourForm.jb_commission_no.className = "input";
  } else {
    parent.job_tour.document.tourForm.jb_commission_no.className = "inputRed";
  }
  // Bemerkungsfeld des Zahlers an/aus
//  if (typeof(parent.job_tour.document.tourForm.dritt_cmp_remarkButton) != 'undefined') {

    if (get_cmp_remark(getJobList(curTourNo, jl_csc_id)) != get_cmp_remark(curCsc_id_payer) && get_cmp_remark(getJobList(curTourNo + 1, jl_csc_id)) != get_cmp_remark(curCsc_id_payer))
      parent.job_tour.document.getElementById("dritt_cmp_remark_div").innerHTML = get_cs_mail(curCsc_id_payer);
    else
      parent.job_tour.document.getElementById("dritt_cmp_remark_div").innerHTML = '';
    if (get_cmp_remark(curCsc_id_payer) != ""
      && get_cmp_remark(getJobList(curTourNo, jl_csc_id)) != get_cmp_remark(curCsc_id_payer) && get_cmp_remark(getJobList(curTourNo + 1, jl_csc_id)) != get_cmp_remark(curCsc_id_payer)
    ) {
      parent.job_tour.document.getElementById("dritt_cmp_remark_div").innerHTML += 'Bemerkung Zahler' + (i_payer == -1 ? '&nbsp;3' : '') + '<br><textarea class="input ' + parent.job_tour.cmp_remark_payer_style + '" disabled">' + get_cmp_remark(curCsc_id_payer) + '</textarea>';
//      parent.job_tour.document.tourForm.dritt_cmp_remarkButton.disabled = false;
//      parent.job_tour.document.tourForm.dritt_cmp_remarkButton.className = "commission_no_enabled";
    } else {
      parent.job_tour.document.getElementById("dritt_cmp_remark_div").innerHTML += '&nbsp;';
//      parent.job_tour.document.tourForm.dritt_cmp_remarkButton.disabled = true;
//      parent.job_tour.document.tourForm.dritt_cmp_remarkButton.className = "button_disabled";
    }
//  }

  // Wenn schon was drin steht (im PDA kann immer was eingegeben werden),
  // dann muss das hier natürlich auch entfernt werden können
  // Ausserdem: Wenn der aktuelle Mitarbeiter aus der Buchhaltung kommt,
  // dann muss die Kommissionsnummer auch immer an sein
  // ODER das Feld soll immer an sein (zentralenabhängig)
  if (getJobList(curTourNo, jl_tr_commission_no) != "" || empModeLaterJob == "1" || commission_no_on == "1")
  {
//    parent.job_tour.document.tourForm.von_tr_commission_noButton.disabled = false;
////    parent.job_tour.document.tourForm.von_tr_commission_noButton.className = "button_enabled";
    parent.job_tour.document.tourForm.von_tr_commission_no.disabled = false;
    parent.job_tour.document.tourForm.jb_commission_no.disabled = false;
  }
  if (getJobList(curTourNo + 1, jl_tr_commission_no) != "" || empModeLaterJob == "1" || commission_no_on == "1")
  {
//    parent.job_tour.document.tourForm.nach_tr_commission_noButton.disabled = false;
////    parent.job_tour.document.tourForm.nach_tr_commission_noButton.className = "button_enabled";
    parent.job_tour.document.tourForm.nach_tr_commission_no.disabled = false;
    parent.job_tour.document.tourForm.jb_commission_no.disabled = false;
  }
  // bei den nicht angezeigten Touren muss das Feld "jl_csc_id_payer"
  // auf disabled gesetzt werden (sie können nicht Bezahler sein)
  for (j = j + 1; j < (maxTour + 1); j++)
    setJobList(j, jl_csc_id_payer, "disabled");
  // Wenn ein neuer Bezahler gesetzt wurde, muss die Liste der gespeicherten Touren aktualisiert werden
  // und der Preis neu berechnet werden ...
  if (oldCurCsc_id_payer != curCsc_id_payer)
  {
//alert("oldCurCsc_id_payer: '" + oldCurCsc_id_payer + "', curCsc_id_payer:'" +  curCsc_id_payer + "'");
    checkJb_tourname();
//  alert((getJobList(0, jl_tr_commission_no)).replace(/\s/,"").substr(0, get_cs_comm_prefix(oldCurCsc_id_payer).length));
    if ((getJobList(0, jl_tr_commission_no)).replace(/\s/,"").substr(0, get_cs_comm_prefix(oldCurCsc_id_payer).length) == get_cs_comm_prefix(oldCurCsc_id_payer) && get_cs_comm_prefix(oldCurCsc_id_payer) != "")
      setJobList(0, jl_tr_commission_no, (getJobList(0, jl_tr_commission_no)).replace(/\s/,"").substr(get_cs_comm_prefix(oldCurCsc_id_payer).length));

//    significantPriceValues = curSignificantPriceValues;
//    onLoadFunc = "onLoad=\"reloadPrice()\"";
    if (MASK_JB_REPORT_BUTTON_ENABLED_PERMANENT == "1" && get_cs_id(curCsc_id_payer) != 0) {
      parent.job_tour.myshow('maskDisplayBerichteButton');
    } else {
      ajaxRequestGet('../include/ajaxReqLib.php', 'mode=2&db_table=phoenix_group.report_process&db_id_field=rp_objid&db_return_field=rp_objtype&search_value=' + get_cs_id(curCsc_id_payer));
      if (retValue == 'cs') {
        parent.job_tour.myshow('maskDisplayBerichteButton');
      } else {
        parent.job_tour.myhide('maskDisplayBerichteButton');
      }
    }
//if (jb_id == "18953664")
//alert(cs_eid_list);
//  alert('curCsc_id_payer=' + curCsc_id_payer + 'mode=1&hqId=' + hq_id + '&cscIdCurrent=' + curCsc_id_payer + '&mdId=' + md_id + '&cmpId=');
    if (curCsc_id_payer != 0) {
      ajaxRequestGet('../include/ajaxReqDocument.php', 'mode=1&hqId=' + hq_id + '&cscIdCurrent=' + curCsc_id_payer + '&mdId=' + md_id + '&cmpId=');
      if (retValue != '') {
        if (parseInt(retValue) > 0) {
          parent.job_tour.myshow('maskDisplayDokumenteButton');
        } else {
          parent.job_tour.myhide('maskDisplayDokumenteButton');
        }
      }
    } else {
      parent.job_tour.myhide('maskDisplayDokumenteButton');
    }
    if (get_cs_tracking(curCsc_id_payer) == 1) {
      parent.job_tour.document.getElementById('tr_tracking_row').style.visibility = 'visible';
	  if (curTourNo > 0) {
        parent.job_tour.document.getElementById('tr_tracking_von').style.visibility = 'visible';
      } else {
        parent.job_tour.document.getElementById('tr_tracking_von').style.visibility = 'collapse';
      }
      parent.job_tour.document.getElementById('tr_tracking_nach').style.visibility = 'visible';
    } else {
      parent.job_tour.document.getElementById('tr_tracking_row').style.visibility = 'collapse';
      parent.job_tour.document.getElementById('tr_tracking_nach').style.visibility = 'collapse';
      parent.job_tour.document.getElementById('tr_tracking_von').style.visibility = 'collapse';
    }

    let photo_opts = (get_cs_photo(curCsc_id_payer));
    tr_photo_disabled = false;
    tr_photo_disabled1 = false;
    tr_photo_checked = false;
    tr_photo_label0 = "";
    tr_photo_label = "";
    if (photo_opts[0] == "1") { // Fotofunktion deaktiviert
      tr_photo_disabled = true;
      tr_photo_label = "Fotofunktion ist deaktiviert"
    } else {
      if (photo_opts[1] == "1") { // Foto Zentrale
        tr_photo_disabled = true;
        tr_photo_checked = true;
        tr_photo_label0 = (parseInt(photo_opts[3]) > 0 ? "Pflicht" : "Kann") + "foto (" + photo_opts[3] + " min / " + photo_opts[4] + " max)";
        tr_photo_label = tr_photo_label0 + " automatisch";
      } else {
        // photo_opts[2] (Foto KAE) ist hier egal
        if (photo_opts[3] != "" && photo_opts[4] != "" ) { // Fotos min // Fotos max          
          tr_photo_label = (parseInt(photo_opts[3]) > 0 ? "KAE-Pflicht" : "KAE-Kann") + "foto (" + photo_opts[3] + " min / " + photo_opts[4] + " max)";
        } else {
          tr_photo_label = "Pflichtfoto";
        }
      }
      if (photo_opts[3] == 0 && photo_opts[4] == 1) { // Kannfoto (0/1) immer disablen weil defaultmäßig immer möglich
        tr_photo_checked = true;
        tr_photo_disabled = true;
        tr_photo_disabled1 = true;
      }
    }
//    parent.job_tour.document.tourForm.tr_photo_von.disabled = tr_photo_disabled;
    parent.job_tour.document.getElementById('span_photo_von').innerHTML = tr_photo_label;
    if (tr_photo_label0 != "" && curTourNo == 0)
      parent.job_tour.document.getElementById('span_photo_von').innerHTML = tr_photo_label0;
//    parent.job_tour.document.tourForm.tr_photo_nach.disabled = tr_photo_disabled;
    parent.job_tour.document.getElementById('span_photo_nach').innerHTML = tr_photo_label;

    if (tr_photo_disabled) {
//      parent.job_tour.document.tourForm.tr_photo_von.checked = false;
//      parent.job_tour.document.tourForm.tr_photo_nach.checked = false;
      j_start = 0;
      if (tr_photo_checked)
        j_start = 1;
      for (j = j_start; j < (maxTour + 1); j++) {
        setJobList(j, jl_tr_photo, "false");
      }
    }

//  ... außerdem ist die Sperre bei geladenen Jobs bzgl. der Anpassung des Mehrwertsteuersatzes
//  des aktuellen Zahles aufzuheben (nur wenn der Zahler auch wirklich manuell geändert wurde)
    if (oldCurCsc_id_payer != "")
      parent.job_options.document.tourOptions.dont_change_tx.value = "";  

    parent.job_options.document.tourOptions.jb_jam_waittime.value = get_cs_jb_jam_waittime(curCsc_id_payer);
    if (parent.job_options.document.tourOptions.jb_jam_waittime.value == "0")
      parent.job_options.document.tourOptions.jb_jam_waittime.value = "";
    if (parent.job_options.document.tourOptions.jb_dispoinfo.value == "" &&
      parent.job_options.document.tourOptions.jb_warnjahr.value == "" && parent.job_options.document.tourOptions.jb_warnmonat.value == "" && parent.job_options.document.tourOptions.jb_warntag.value == "" &&
      parent.job_options.document.tourOptions.jb_warnstunde.value == "" && parent.job_options.document.tourOptions.jb_warnminute.value == "" /* ***jb_job_jam_test*** && parent.job_options.document.tourOptions.jb_jam_waittime.value == "" */) {
      parent.job_tour.document.tourForm.jb_dispoInfoButton.value = "Dispo Info";
      if (hq_id == 8)
        parent.job_tour.document.tourForm.jb_dispoInfoButton.className = "button_enabled";
    } else {
      if (hq_id == 8)
        parent.job_tour.document.tourForm.jb_dispoInfoButton.className = "inputRed";
      else
        parent.job_tour.document.tourForm.jb_dispoInfoButton.value = "Dispo Info*";
    }
  } else {
  // Es wurde nur verschoben, daher könnte die erste Station jetzt eine andere sein
    if (tr_photo_label0 != "") {
      if (curTourNo == 0)
        parent.job_tour.document.getElementById('span_photo_von').innerHTML = tr_photo_label0;
      else
        parent.job_tour.document.getElementById('span_photo_von').innerHTML = tr_photo_label;
    }
  }
  checkTourDirty(getCurTourNo());
  checkTourDirty(getCurTourNo() + 1);

  // jobList in unteres Frame schreiben
  var locationdata =
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" +
    "<html lang=\"de\">\n" +
    "<head>\n" +
    "<title>votian: Auftragserfassung - Tourendaten<\/title>\n" +
    "<link rel=\"stylesheet\" type=\"text/css\" href=\"../css/phoenix.css.php\">\n" +
    "<script type=\"text/javascript\">\n" +
    "<!" + "--\n" +
    "\n" +
    "// Opens a new (popup-)window with specified parameters\n" +
    "function popupWindow(url,title,config) {\n" +
    "  popup = window.open(url,title,config);\n" +
    "}" +
    "\n" +
    "function reloadPrice()\n" +
    "{\n" +
//"  alert ('reloadPrice()');" +    
    "  self.setTimeout('document.reloadPrice.submit()',300);\n" +
//    "  document.reloadPrice.submit();\n" +
    "}\n" +
    "\n" +
    "//--" + ">\n" +
    "<\/script>\n" +
    "<\/head>\n" +
    "<body>\n" +
//    "significantPriceValues: '" + significantPriceValues + "'<br>\n" +
//    "curSignificantPriceValues: '" + curSignificantPriceValues + "'<br>\n" +
    "  <form name=\"reloadPrice\" action=\"../jobs/job_options.php\" method=\"post\">\n" +
    mkFieldsReloadPrice() +
    "    <input type=\"hidden\" name=\"hq_id_job\" value=\"" + hq_id + "\">\n" +
    "    <input type=\"hidden\" name=\"getPriceOnly\" value=\"1\">\n" +
    "    <input type=\"hidden\" name=\"dbhistory\" value=\"" + dbhistory + "\">\n" +
    "  <\/form>\n" +
    "  <table border=0 width=100% align=center cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n" +
    "    <tr>\n" +
    "      <td colspan=3>\n" +
    "        <hr noshade size=\"1\">\n" +
    "      <\/td>\n" +
    "    <\/tr>\n" +
    "    <tr>\n" +
    "      <td width=20%>\n" +
    listLink +
    "        &nbsp;\n" +
    "      <\/td>\n" +
    "      <td width=60% align=center valign=top>\n" +
    "        <div class=headline2>\n" +
    "          Tourendaten (Etappen)\n" +
    "        <\/div>\n" +
    "      <\/td>\n" +
    "      <td width=20%>\n" +
    detailLink +
    "        &nbsp;\n" +
    "      <\/td>\n" +
    "    <\/tr>\n" +
    "    <tr>\n" +
    "      <td>\n" +
    "        &nbsp;\n" +
    "      <\/td>\n" +
    "      <td align=center>\n";

  var tourname1 = "";
  var tourname2 = "";
  var j = 0;
  // make list of currently defined pairs of start->goal
  while ((getJobList(j, jl_csc_id) != "" || checkTourComplete(j)) &&
    (getJobList(j + 1, jl_csc_id) != "" || checkTourComplete(j + 1)))
  {
    tourname1 = getOptionTextByVal("job_tour", "tourForm", "von_csc_id", getJobList(j, jl_csc_id));
    if (tourname1 == "") tourname1 = getJobList(j, jl_tr_comp);
    tourname2 = getOptionTextByVal("job_tour", "tourForm", "nach_csc_id", getJobList(j + 1, jl_csc_id));
    if (tourname2 == "") tourname2 = getJobList(j + 1, jl_tr_comp);
    tourLink = "<a href=javascript:parent.job_options.moveToTour(" + j + ")><b>" +
      tourname1 +
      "<\/b>&nbsp;&nbsp;<img src=\"../images/next1.gif\" border=0>&nbsp;&nbsp;<b>" +
      tourname2 +
      "<\/b><\/a><br>";
    locationdata += tourLink;
    if (++j >= maxTour)
      break;
  }

  locationdata +=
    "      <\/td>\n" +
    "      <td>\n" +
    "        &nbsp;\n" +
    "      <\/td>\n" +
    "    <\/tr>\n" +
    "    <tr>\n" +
    "      <td colspan=3>\n" +
    "        <img src=\"../images/empty.gif\" border=0 height=2>\n" +
    "      <\/td>\n" +
    "    <\/tr>\n" +
    "  <\/table>\n" +
    "<\/body>\n" +
    "<\/html>\n" +
    "<script type=\"text/javascript\">\n" +
    "<!" + "--\n" +
    onLoadFunc +
    "//--" + ">\n" +
    "<\/script>\n";
//  if (navigator.userAgent.indexOf("Firefox") == -1) {
    parent.job_tour_list.document.open();
    parent.job_tour_list.document.write(locationdata);
    parent.job_tour_list.document.close();
//  } else {
//    var url = "javascript:(function(){var html = '" + btoa(encodeURIComponent( escape( locationdata )))
//                 +"';document.open();document.write(unescape(decodeURIComponent(window.atob( html ))));document.close();})();";
//    parent.job_tour_list.location.href=url;
//  }
  checkSendTour();
}

/*
 * checkTourComplete
 *   params: i
 *   return: true, false
 *   global: jl_tr_comp, jl_ad_street, jl_tr_hsno,
 *     jl_ad_zipcode, jl_ad_city
 *
 * Prüfen, ob Etappenstelle komplett:
 * mind. Firma, Strasse, Nr., PLZ, Ort müssen angegeben sein
 * für eine Etappenstelle ohne Kostenstellennumer
 */

function checkTourComplete(i)
{
  // whitespaces entfernen, dann Länge prüfen für die entscheidenden Felder
  //
  if ((getJobList(i, jl_tr_comp)).replace(/\s/,"").length == 0) return false;
  if ((getJobList(i, jl_ad_street)).replace(/\s/,"").length == 0) return false;
  if ((getJobList(i, jl_tr_hsno)).replace(/\s/,"").length == 0) return false;
  if ((getJobList(i, jl_ad_zipcode)).replace(/\s/,"").length == 0) return false;
  if ((getJobList(i, jl_ad_city)).replace(/\s/,"").length == 0) return false;
  // wenn komplett, aber keine csc_id, dann hier gleich externe Kostenstelle eintragen  
  if ((getJobList(i, jl_csc_id)).replace(/\s/,"").length == 0)
    setJobList(i, jl_csc_id, CSC_ID_PAYER_EXTERN);
  return true;
}

function check_eu(country_code)
{
  if (country_code.replace(/\s/,"").length == 0)
    return true;

  for (var i = 0; i < EU_COUNTRYCODES.length; i++) {
    if (EU_COUNTRYCODES[i] == country_code) {
      return true;
    }
  }
  return false;
}

/*
 * checkSendTour
 *   params: -
 *   return: -
 *   global: job_options, tourOptions, vht_id, toursubmit,
 *     jl_csc_id, max_Tour, jl_csc_id_payer
 *
 * Button "Tour senden" aktivieren/deaktivieren.
 * Entweder mind. einmal Start und Ziel oder Start und Vor-Ort-Service.
 * ODER für Start und/oder Ziel sind mind.
 * Firma, Strasse, Nr., PLZ, Ort angegeben!
 * Weiterhin muss ein Bezahler gewählt sein (d. h. minstestens eine
 * Kostenstelle vorhanden, die nicht extern ist)
 *
 * Ausserdem muss der Kurier gewählt sein, wenn "Nacherfassung" aktiviert
 */

var is_eu_only = true;

function checkSendTour()
{
//if (jb_id == "18953664")
//alert(cs_eid_list);
  // Prüfen, ob in den ersten beiden Etappenstellen eine oder ob beide
  // durch die Angabe von Firma, Strasse, Nr., PLZ, Ort als neue externe
  // Kostenstelle definiert sind
  var newCsc = Array(true, true);
  var payer_selected = false;
  var afterwards_ok = true;
  is_eu_only = true;

  if ((is_exported && jb_id != "") || (dbhistory == 1 && jb_id != ""))
  {
    parent.job_options.document.tourOptions.toursubmit.disabled = true;
    return;
  }
//alert("is_eu_only=" + is_eu_only + "\nis_non_eu_notified=" + is_non_eu_notified);
  for (var i = 0; i < (maxTour + 1); i++)
  {
    if (checkTourDirty(i))
    {
      parent.job_options.document.tourOptions.toursubmit.disabled = true;
//      alert ("Tour " + i + " ist dirty");
      return;
    } else {
      if (is_eu_only) {
        is_eu_only = check_eu(getJobList(i, jl_ad_country));
//if (getJobList(i, jl_ad_country) != "DE")
//  alert(getJobList(i, jl_ad_country) + " = " + is_eu_only);
        if (!is_eu_only && !is_non_eu_notified) {
          alert("Fordern Sie bei Transporten in Nicht-EU-Länder immer eine schriftlichte Bestätigung der Versender-Eigenschaft des Auftraggebers gemäß der Handlungsanweisung Drittland an.");
          is_non_eu_notified = true;
        }
      }
    }
  }
  if (is_eu_only && !(((getJobList(0, jl_tr_comp)).replace(/\s/,"").length == 0) &&
    ((getJobList(0, jl_ad_street)).replace(/\s/,"").length == 0) &&
    ((getJobList(0, jl_tr_hsno)).replace(/\s/,"").length == 0) &&
    ((getJobList(0, jl_ad_zipcode)).replace(/\s/,"").length == 0) &&
    ((getJobList(0, jl_ad_city)).replace(/\s/,"").length == 0)))
    is_non_eu_notified = false;

  for (var i = 0; i < 2; i++)
  {
    newCsc[i] = checkTourComplete(i);
  }
//alert ("'" + newCsc[0] + "' '" + newCsc[1] + "'");
//alert (getJobList(0, jl_csc_id) + "," + getJobList(1, jl_csc_id));
  // Prüfen ob erste beiden Etappenstellen angegeben bzw. vollständig für neue Kostenstelle
  // ODER nur erste bzw. vollständig mit Vor-Ort-Service (vht_id = 6) ODER mit Barzahlung angekreuzt (Taxi-Modus)
  // ODER Zahler ist gesetzt (Drittzahler oder normaler Zahler)
  if (typeof (parent.job_tour.document.tourForm.jb_cash) != 'undefined') {
    if (((/*getJobList(0, jl_csc_id) != "" ||*/ newCsc[0]) &&
         (/*getJobList(1, jl_csc_id) != "" || */ newCsc[1]))
       || ((/*getJobList(0, jl_csc_id) != "" || */ newCsc[0]) &&
       (parent.job_options.document.tourOptions.vht_id.value == 7 ||
        parent.job_tour.document.tourForm.jb_cash.checked ||
        parent.job_options.document.tourOptions.csc_id_payer.value != "" ||
        getJobList(0, jl_csc_id_payer) == "true"
        ))) {
      // mind. einmal Start und Ziel oder Start und Vor-Ort-Service (vht_id = 6) oder Barzahlung
      // oder normale Zahlung oder Drittzahlung
      parent.job_options.document.tourOptions.toursubmit.disabled = false;
    } else {
      parent.job_options.document.tourOptions.toursubmit.disabled = true;
    }
  } else {
    if (((/*getJobList(0, jl_csc_id) != "" ||*/ newCsc[0]) &&
         (/*getJobList(1, jl_csc_id) != "" || */ newCsc[1]))
       || ((/*getJobList(0, jl_csc_id) != "" || */ newCsc[0]) &&
       (parent.job_options.document.tourOptions.vht_id.value == 7 ||
        parent.job_options.document.tourOptions.csc_id_payer.value != "" ||
        getJobList(0, jl_csc_id_payer) == "true"
        ))) {
      parent.job_options.document.tourOptions.toursubmit.disabled = false;
    } else {
      parent.job_options.document.tourOptions.toursubmit.disabled = true;
    }
  }

  // Prüfen, ob ein Bezahler gesetzt ist
  for (i = 0; i < (maxTour + 1); i++)
    if (getJobList(i, jl_csc_id_payer) == "true")
      payer_selected = true;      
  // Prüfen, ob Nacherfassung mit angegebenem Kurier
  if (typeof (parent.job_options.document.tourOptions.afterwards) != 'undefined')
    if (parent.job_options.document.tourOptions.afterwards.checked)
      // Prüfen, ob Kurier angegeben
      if (parent.job_options.document.tourOptions.cr_id_order.value == "")
        afterwards_ok = false;
  if (typeof (parent.job_tour.document.tourForm.jb_costsplit) != 'undefined') {
    if (!payer_selected && !parent.job_tour.document.tourForm.jb_costsplit.checked &&
         (!parent.job_tour.document.tourForm.jb_cash.checked && parent.job_options.document.tourOptions.csc_id_payer.value == "")
         || !afterwards_ok
         // Wenn Kostenteilung als Barzahlung mißbraucht, dann muß auf jeden Fall ein Bezahler ausgewählt werden
         // (es sei denn ein Drittzahler ist gesetzt!!!)
         || (cash_payer_select == "1" && (!payer_selected && parent.job_options.document.tourOptions.csc_id_payer.value == ""))) {
      parent.job_options.document.tourOptions.toursubmit.disabled = true;
    }
  }
  
  // Prüfen, ob ein gesetzter Zahler USt-ID hat, falls notwendig
  var ust_id_ok = false;
  if (getJobList(0, jl_ad_country) == "DE" || !parent.job_tour.document.tourForm.jb_costsplit.checked) {
    ust_id_ok = true;
  } else { // Abholung im Ausland und Rechnunngszahlung => Zahler muss USt-ID haben
    for (var i = 0; i < cs_eid_list.length; i++)
      if (cs_eid_list[i][0] == curCsc_id_payer)
        if (trim(cs_eid_list[i][15]) != "")
          ust_id_ok = true;
  }
  if (!ust_id_ok) {
    parent.job_options.document.tourOptions.toursubmit.disabled = true;
    if (getJobList(0, jl_ad_country) != "")
      parent.job_options.document.tourOptions.submitMessage.value = "Zahler hat keine USt-IdNr.!";
  } else {
    parent.job_options.document.tourOptions.submitMessage.value = "";
  }

  // Check if use of calculator is mandatory
  if (get_cs_calc_mand_list(get_cs_id(curCsc_id_payer)) == "1") {
//alert(curCsc_id_payer + ", " + get_cs_id(curCsc_id_payer) + ", " + get_cs_calc_mand_list(get_cs_id(curCsc_id_payer)));
    if (parent.job_options.document.tourOptions.tmp_add_srvs.value == "") {
      parent.job_options.document.tourOptions.toursubmit.disabled = true;
    }
  }

  // Check insurance
  if (parent.job_options.document.tourOptions.jb_insurance.checked) {
    if (trim(parent.job_options.document.tourOptions.jb_value_of_goods.value) == "")
      parent.job_options.document.tourOptions.toursubmit.disabled = true;
    if (document.getElementsByName("jb_insurance_rate")[0].selectedIndex == 0)
      parent.job_options.document.tourOptions.toursubmit.disabled = true;
  }

// check jb_orderer
  if (!parent.job_options.document.tourOptions.toursubmit.disabled)
  {
    check_jb_orderer();
  }
//if (jb_id == "18953664")
//alert(cs_eid_list);
}

function checkForeignStations()
{
  for (i = 0; i < (maxTour + 1); i++)
    if (getJobList(i, jl_ad_country) != "DE" && getJobList(i, jl_ad_country) != "")
      return false;
  return true;  
}

/*
 * checkCr_id_order
 *   params: -
 *   return: -
 *   global: job_options, tourOptions, cr_id_order,
 *     jb_waitstorno
 *
 * Die eingegebene cr_id_order muss in der Liste cr_id_order_list enthalten sein,
 * sonst wird sie auf "" zurückgesetzt.
 */

function checkCr_id_order()
{
  var found = false;
//alert("checkCr_id_order" + cr_id_order_list.length);
  if (parent.job_options.document.tourOptions.cr_id_order.value != "" && cr_id_order_list.length != 0)
  {
    for (var i = 0; i < cr_id_order_list.length; i++)
    {
      if (getCr_id(cr_id_order_list, i).toUpperCase() ==
        parent.job_options.document.tourOptions.cr_id_order.value.toUpperCase())
      {
        if (jb_id == "")
          parent.job_options.document.tourOptions.jb_waitstorno.disabled = false;
//        parent.job_options.document.tourOptions.jb_waitstorno.focus();
        parent.job_options.document.tourOptions.cr_id_order.value = getCr_id(cr_id_order_list, i);
        parent.job_options.document.tourOptions.cr_id_order_hidden.value = getCr_id(cr_id_order_list, i);
        found = true;
        break;
      }
    }
    if (!found && EMAIL_CRVHSID_NO_MAIL.indexOf(String(parent.job_options.document.tourOptions.cr_id_order.value.toUpperCase())) == -1)
    {
      alertIsOpen = true;
      alert("Die Kuriernummer '" + parent.job_options.document.tourOptions.cr_id_order.value + "' ist ungültig!");
      alertIsOpen = false;
      parent.job_options.document.tourOptions.cr_id_order.value = "";
    } else {
    	if (parent.job_options.document.tourOptions.tmp_add_sids.value != "")
    	{
    	  if (String(parent.job_options.document.tourOptions.cr_id_order.value).indexOf(MASK_INVOICE_SIDS_SID0) == -1 &&
            String(parent.job_options.document.tourOptions.cr_id_order.value).indexOf(MASK_INVOICE_SIDS_SID1) == -1) {
          parent.job_options.document.tourOptions.cr_id_order.value = get_MASK_INVOICE_SIDS_SID();
          parent.job_options.document.tourOptions.cr_id_order_hidden.value = get_MASK_INVOICE_SIDS_SID();
          alert("Bei eingetragenen weiteren Unternehmern im Calculator sind nur die Fahrzeuge " + MASK_INVOICE_SIDS_SID0 + " und " + MASK_INVOICE_SIDS_SID1 + " zulässig!");
        }        
      }
    }
  }
  if (parent.job_options.document.tourOptions.cr_id_order.value == "")
  {
    parent.job_options.document.tourOptions.jb_waitstorno.checked = false;
    parent.job_options.document.tourOptions.jb_waitstorno.disabled = true;
//    parent.job_options.document.tourOptions.cr_id_order.focus(); // führt zum Hängen, wenn cr_id_order disabled ist...
  }
  checkSendTour();
}

/*
 * checkWeight
 *   params: -
 *   return: -
 *   global: job_options, tourOptions, cr_id_order
 *
 * Die eingegebenen Werte für jb_weight und vht_id können nicht beliebig kombiniert
 * werden.
 * Diese Funktion stellt ausserdem sicher, dass in jb_weight nur gültige Werte
 * stehen können.
 */

function checkWeight(source)
{
  if (parent.job_options.document.tourOptions.jb_weight.value == "")
  {
    alertIsOpen = true;
    alert("Das Maximalgewicht eines Transportgutes muss angegeben werden" +
      " (wenn unerheblich, dann \"0\" eingetragen lassen)!");
    alertIsOpen = false;
    parent.job_options.document.tourOptions.jb_weight.value = "0";
//    parent.job_options.document.tourOptions.jb_weight.focus();
  }
  if ((parent.job_options.document.tourOptions.jb_weight.value != "") &&
    isNaN(parent.job_options.document.tourOptions.jb_weight.value))
  {
    alertIsOpen = true;
    alert("In der Gewichtsangabe sind nur Zahlen zulässig.");
    alertIsOpen = false;
    parent.job_options.document.tourOptions.jb_weight.value = "0";
//    parent.job_options.document.tourOptions.jb_weight.focus();
  }
  if (parseFloat(
    parent.job_options.document.tourOptions.jb_weight.value) >= 8)
  {
    if (parent.job_options.document.tourOptions.vht_id.value == 1)
    {
      alertIsOpen = true;
      alert("Fahrradkuriere können nur bis zu 8 kg Gewicht befördern.");
      alertIsOpen = false;
      if (source == 0)
      {
        parent.job_options.document.tourOptions.jb_weight.value = "0";
//        parent.job_options.document.tourOptions.jb_weight.focus();
      }
      if (source == 1)
      {
        parent.job_options.document.tourOptions.vht_id.value = "";
//        parent.job_options.document.tourOptions.vht_id.focus();
      }
    }
  }

  if (source == 1 && MASK_BIKE_FILTER == "1")
  {
    var indexOfBI = 0;
    for (var i = 0; i < cfl.length; i++)
    {
      if (cfl[i][0] == "BI")
      {
      	indexOfBI = i;
        break;
      }
    }

    if (parent.job_options.document.tourOptions.vht_id.value == 1 && cfl[indexOfBI][3] == 0 && indexOfBI > 0)
    {
      // Wenn Fahrrad gewählt ist, dann den entsprechenden Filter setzen
      cfl[indexOfBI][3] = 1;
      if (parent.job_options.document.tourOptions.jb_cr_filter.value != "")
        parent.job_options.document.tourOptions.jb_cr_filter.value = parent.job_options.document.tourOptions.jb_cr_filter.value + ",";
      parent.job_options.document.tourOptions.jb_cr_filter.value = parent.job_options.document.tourOptions.jb_cr_filter.value + "BI";
// alert ("Filter set: " + parent.job_options.document.tourOptions.jb_cr_filter.value);
    }
    if (parent.job_options.document.tourOptions.vht_id.value != 1 && cfl[indexOfBI][3] == 1 && indexOfBI > 0)
    {
      // Wenn Fahrrad nicht gewählt ist, dann den entsprechenden Filter löschen
      cfl[indexOfBI][3] = 0;
      parent.job_options.document.tourOptions.jb_cr_filter.value = parent.job_options.document.tourOptions.jb_cr_filter.value.replace(",BI","").replace("BI,","").replace("BI","");
// alert ("Filter unset: " + parent.job_options.document.tourOptions.jb_cr_filter.value);
    }
    if (typeof(parent.job_options.document.tourOptions.jb_cr_filterButton) != 'undefined') {
      if (parent.job_options.document.tourOptions.jb_cr_filter.value == "" &&
          parent.job_options.document.tourOptions.jb_cr_filter_opt.value == "")
        parent.job_options.document.tourOptions.jb_cr_filterButton.value = "Filter";
      else
        parent.job_options.document.tourOptions.jb_cr_filterButton.value = "Filter*";
    }
  }
//  if (source == 1 && parent.job_tour.$('#div_distanceprice').html() != "")
//    openDistanceprice(0);
//  if (source == 1 && parent.job_tour.$('#div_zoneprice').html() != "")
//    openDistanceprice("zone");
  checkSendTour();
  writeJob();
}

/*
 * Quelle: http://www.evocomp.de/beispiele/javascript/trim.html
 */
// Führende und Abschließende Whitespaces (Leerzeichen, Tabulatoren, ...)
// aus der übergebenen Zeichenkette entfernen.
function trim (zeichenkette) {
  // Erst führende, dann Abschließende Whitespaces entfernen
  // und das Ergebnis dieser Operationen zurückliefern
  return zeichenkette.replace (/^\s+/, '').replace (/\s+$/, '');
}

/*
 * checkDimensions
 *   params: -
 *   return: -
 *   global: job_options, tourOptions, cr_id_order
 *
 * Diese Funktion stellt sicher, dass in jb_crvh_length, jb_crvh_width, jb_crvh_height
 * und jb_crvh_position nur gültige Werte stehen können.
 */

function checkDimensions(source)
{
  var val = "";

  if (source == 0)
    val = parent.job_options.document.tourOptions.jb_crvh_length.value;
  if (source == 1)
    val = parent.job_options.document.tourOptions.jb_crvh_width.value;
  if (source == 2)
    val = parent.job_options.document.tourOptions.jb_crvh_height.value;
  if (source == 3)
    val = parent.job_options.document.tourOptions.jb_crvh_position.value;
  if (trim(val) == "")
  {
    alertIsOpen = true;
    alert("Bitte eine ganze Zahl angeben" +
      " (wenn unerheblich, dann \"0\" eintragen)!");
    alertIsOpen = false;
    val = "0";
  }
  if (isNaN(val))
  {
    alertIsOpen = true;
    alert("An dieser Stelle sind nur ganze Zahlen zulässig.");
    alertIsOpen = false;
    val = "0";
  }
  if (parseFloat(val) != parseInt(val))
  {
    alertIsOpen = true;
    alert("An dieser Stelle sind nur ganze Zahlen zulässig.");
    alertIsOpen = false;
    val = "0";
  }
  
  if (source == 0) {
    parent.job_options.document.tourOptions.jb_crvh_length.value = val;
//    parent.job_options.document.tourOptions.jb_crvh_length.focus();
  }
  if (source == 1) {
    parent.job_options.document.tourOptions.jb_crvh_width.value = val;
//    parent.job_options.document.tourOptions.jb_crvh_width.focus();
  }
  if (source == 2) {
    parent.job_options.document.tourOptions.jb_crvh_height.value = val;
//    parent.job_options.document.tourOptions.jb_crvh_height.focus();
  }
  if (source == 3) {
    parent.job_options.document.tourOptions.jb_crvh_position.value = val;
//    parent.job_options.document.tourOptions.jb_crvh_position.focus();
  }
  checkSendTour();
  writeJob();
}

function checkKm()
{
  if ((parent.job_options.document.tourOptions.jb_km.value != "") &&
    isNaN(parent.job_options.document.tourOptions.jb_km.value.replace(/,/,".")))
  {
    alertIsOpen = true;
    alert("Kilometer bitte in der Form '99999,999' eingeben.");
    alertIsOpen = false;
    parent.job_options.document.tourOptions.jb_km.value = "";
    parent.job_options.document.tourOptions.jb_km.focus();
  }
  // Sicherstellen dass, nur höchstens drei Nachkommastellen eingegeben werden.
  var parts = trim(parent.job_options.document.tourOptions.jb_km.value.replace(/,/,".")).split(".");
  if (parts[1].length > 3)
  {
    alertIsOpen = true;
    alert("Kilometer bitte in der Form '99999,999' eingeben.");
    alertIsOpen = false;
    parent.job_options.document.tourOptions.jb_km.value = "";
    parent.job_options.document.tourOptions.jb_km.focus();
  }
}

function checkInsurance()
{
  if (parent.job_options.document.tourOptions.jb_insurance.checked) {
    $('#div_insurance').show();
  } else {
    parent.job_options.document.tourOptions.jb_value_of_goods.value = "";
    parent.job_options.document.tourOptions.jb_value_of_goods.className = "inputRed";
    document.getElementsByName("jb_insurance_rate")[0].selectedIndex = 0;
    document.getElementsByName("jb_insurance_rate")[0].className = "inputRed";
    parent.job_options.document.tourOptions.special_case.checked = false;
    $('#div_insurance').hide();
  }
  checkSendTour();
}

function checkValueOfGoods()
{
  if(document.getElementsByName("jb_insurance_rate")[0].selectedIndex > 0) {
    document.getElementsByName("jb_insurance_rate")[0].className = "input";
  } else {
    document.getElementsByName("jb_insurance_rate")[0].className = "inputRed";
  }
  if ((parent.job_options.document.tourOptions.jb_value_of_goods.value != "") &&
    isNaN(parent.job_options.document.tourOptions.jb_value_of_goods.value.replace(/,/,".")))
  {
    alertIsOpen = true;
    alert("Warenwert bitte in der Form '999999,99' eingeben.");
    alertIsOpen = false;
    parent.job_options.document.tourOptions.jb_value_of_goods.className = "inputRed";
    parent.job_options.document.tourOptions.jb_value_of_goods.value = "";
    parent.job_options.document.tourOptions.jb_value_of_goods.focus();
  } else {
	if (parseFloat(parent.job_options.document.tourOptions.jb_value_of_goods.value.replace(/,/,".")) > 500000) {
	  alert("Ein Warenwert von mehr als 500.000,00 \u20AC kann nicht automatisch gebucht werden, dies erfordert eine individuelle Deckungsanfrage.");
      parent.job_options.document.tourOptions.jb_value_of_goods.value = "";
      parent.job_options.document.tourOptions.jb_value_of_goods.focus();
    } else {
      if (parseFloat(parent.job_options.document.tourOptions.jb_value_of_goods.value.replace(/,/,".")) > 0) {
        parent.job_options.document.tourOptions.jb_value_of_goods.className = "input";
      } else {
        parent.job_options.document.tourOptions.jb_value_of_goods.className = "inputRed";
	  }
	}
  }
  // Sicherstellen dass keine Nachkommastellen eingegeben werden.
  var parts = trim(parent.job_options.document.tourOptions.jb_value_of_goods.value.replace(/,/,".")).split(".");
  if (typeof(parts[1]) != 'undefined') {
    if (parts[1].length > 2)
    {
      alertIsOpen = true;
      alert("Warenwert bitte in der Form '99999,99' eingeben.");
      alertIsOpen = false;
      parent.job_options.document.tourOptions.jb_value_of_goods.value = "";
      parent.job_options.document.tourOptions.jb_value_of_goods.focus();
    }
  }
  checkSendTour();
}

//function checkOrigin() {
////  console.log(parent.job_tour.document.tourForm);
////  alert(parent.job_tour.document.tourForm.jb_origin.value);
////  alert(parent.job_tour.document.getElementsByName("jb_origin")[0].value);
//  if (parent.job_tour.document.tourForm.jb_origin.value == 6) {
//    parent.job_tour.document.getElementById("div_jb_origin_other").style.display = 'inline';
//    if (trim(parent.job_tour.document.tourForm.jb_origin_other.value) != "")
//      parent.job_tour.document.tourForm.jb_origin_other.className = "input";
//    else
//      parent.job_tour.document.tourForm.jb_origin_other.className = "inputRed";
//  } else {
//    parent.job_tour.document.getElementById("div_jb_origin_other").style.display = 'none';
//    parent.job_tour.document.tourForm.jb_origin_other.value = "";
//  }
//  parent.job_options.document.tourOptions.jb_origin_hidden.value = parent.job_tour.document.tourForm.jb_origin.value;
//  parent.job_options.document.tourOptions.jb_origin_other_hidden.value = parent.job_tour.document.tourForm.jb_origin_other.value;
//
//}

function checkOrigin() {
//  console.log(parent.job_tour.document.tourForm);
//  alert(parent.job_tour.document.tourForm.jb_origin.value);
//  alert(parent.job_tour.document.getElementsByName("jb_origin")[0].value);
  if (parent.job_tour.document.tourForm.jb_origin.value == 6) {
    parent.job_tour.document.getElementById("div_jb_origin_other").style.display = 'inline';
    if (trim(parent.job_tour.document.tourForm.jb_origin_other.value) != "")
      parent.job_tour.document.tourForm.jb_origin_other.className = "input";
    else
      parent.job_tour.document.tourForm.jb_origin_other.className = "inputRed";
  } else {
    parent.job_tour.document.getElementById("div_jb_origin_other").style.display = 'none';
    parent.job_tour.document.tourForm.jb_origin_other.value = "";
  }
  parent.job_options.document.tourOptions.jb_origin_hidden.value = parent.job_tour.document.tourForm.jb_origin.value;
  parent.job_options.document.tourOptions.jb_origin_other_hidden.value = parent.job_tour.document.tourForm.jb_origin_other.value;
}

function check_jb_orderer() {
  if (trim(parent.job_tour.document.tourForm.jb_orderer.value) != "" || !jb_orderer_mandatory) {
    parent.job_options.document.tourOptions.jb_orderer_hidden.value = trim(parent.job_tour.document.tourForm.jb_orderer.value);
    parent.job_tour.document.tourForm.jb_orderer.className = "input";
//    parent.job_options.document.tourOptions.toursubmit.disabled = false;
  } else {
    parent.job_tour.document.tourForm.jb_orderer.className = "inputRed";
//    parent.job_options.document.tourOptions.toursubmit.disabled = true;
  }
}

function check_jb_commission_no() {
  parent.job_options.document.tourOptions.jb_commission_no_hidden.value = trim(parent.job_tour.document.tourForm.jb_commission_no.value);
  if (trim(parent.job_tour.document.tourForm.jb_commission_no.value) != "" || !is_commission_no(curCsc_id_payer)) {
    parent.job_tour.document.tourForm.jb_commission_no.className = "input";
  } else {
    parent.job_tour.document.tourForm.jb_commission_no.className = "inputRed";
  }
}

/*
 * formatPrice
 *   params: -
 *   return: -
 *   global: job_options, tourOptions, jb_fixprice
 *
 */

function formatPrice(aStr)
{
  var partsSum = aStr.split(",");
  if (partsSum.length > 1) {
    if (partsSum[1].length < 1) {
      aStr = aStr + "00";
    } else {
      if (partsSum[1].length < 2)
        aStr = aStr + "0";
    }
  } else {
    if (partsSum[0].length > 0)
      aStr = aStr + ",00";
  }
  return aStr;
}

/*
 * checkFixprice
 *   params: -
 *   return: -
 *   global: job_options, tourOptions, jb_fixprice
 *
 */

function checkFixprice(mode)
{
  isSavedTour = false;
  if (mode == 2) {
    // if called from get_saved_tour.php the call of writeJob() at the end of this function will result in an undefined var "callerID" in checkDiscount() called from writeJob()
    // thus, in this case calling writeJob() must be prevented
    isSavedTour = true;
    mode = 1;
  }

  checkAmount("jb_fixprice", "Festpreis");
  checkDiscount();

  // Betragsverringerungen wg. Calcuator abfangen
  
  var curFixprice = parseFloat(parent.job_options.document.tourOptions.jb_fixprice.value.replace(/,/,"."));
  if (isNaN(curFixprice)) curFixprice = 0;
  var self_service_discount_text = "";
  if (parent.job_options.document.tourOptions.self_service_discount.value > 0) {
    curFixprice = Math.round(curFixprice * (100 - parent.job_options.document.tourOptions.self_service_discount.value)) / 100;
    self_service_discount_text = " -(" + formatPrice(String(Math.round(100 * parent.job_options.document.tourOptions.self_service_discount.value)/100).replace(/\./,",")) + "% KAE)";
  }
  if (parent.job_options.document.tourOptions.jb_discount.checked == true) {
    curFixprice = Math.round(curFixprice * (100 - parent.job_options.document.tourOptions.jb_discount_rate.value)) / 100;
  }

  var cur_jb_markup = parent.job_options.document.tourOptions.currentTSZ.value.substr(0, parent.job_options.document.tourOptions.currentTSZ.value.length - 2);
  if (trim(parent.job_options.document.tourOptions.jb_markup.value) != "")
    cur_jb_markup = parent.job_options.document.tourOptions.jb_markup.value;
//alert(cur_jb_markup);
  if (parseFloat(cur_jb_markup.replace(/,/,".")) > 0 && curFixprice > 0) {
    parent.job_options.document.tourOptions.jb_markup_text.value = "Festpreis mit " + cur_jb_markup + "% TSZ: " +
      formatPrice(String(Math.round(curFixprice * (100 + parseFloat(cur_jb_markup.replace(/,/,".")))) / 100).replace(/\./,",")) + " " + String.fromCodePoint(0x404) + self_service_discount_text;
  } else {
    parent.job_options.document.tourOptions.jb_markup_text.value = "";
  }
  var curJb_cr_price = parseFloat(parent.job_options.document.tourOptions.jb_cr_price.value.replace(/,/,"."));
  if (isNaN(curJb_cr_price)) curJb_cr_price = 0;

  // zuerst prüfen, ob ein Kundenprovisionssatz vorliegt; wenn ja, dann wird der Fuhrlohn automatisch aus dem
  // Festpreis berechnet
  
  var cs_prov = parseFloat(get_cs_prov(curCsc_id_payer));
  if (mode == 0 && cs_prov > 0) {
    parent.job_options.document.tourOptions.jb_cr_price.value = formatPrice(String(Math.round(curFixprice * (100 - cs_prov)) / 100).replace(/\./,","));
    if (parent.job_options.document.tourOptions.jb_cr_price.value == "0,00")
      parent.job_options.document.tourOptions.jb_cr_price.value = "";
    checkCalculator();
  } else {
    // Kein Kundenprovisionssatz: Fuhrlohn überprüfen (darf nicht größer sein als Festpreis)
    if (curFixprice < curJb_cr_price && curFixprice >= 0) {
      alertIsOpen = true;
//      alert("Der Fuhrlohn im Calculator ist größer als der Festpreis!");
      alert("Die Frachtvergütung im Calculator ist größer als der Festpreis. Daher wurde die Frachtvergütung auf Null zurückgesetzt!");
      alertIsOpen = false;
//      parent.job_options.document.tourOptions.jb_fixprice.value = parent.job_options.document.tourOptions.jb_cr_price.value;
      parent.job_options.document.tourOptions.jb_cr_price.value = "";
      checkCalculator();
      parent.job_options.document.tourOptions.jb_fixprice.focus();
    }
  }
  var sum = 0;
  var tmp_add_prices = parent.job_options.document.tourOptions.tmp_add_prices.value;
  var tmp_add_pricesArr = tmp_add_prices.split("¹");
  for (var i = 0; i < tmp_add_pricesArr.length; i++) {
    sum += parseFloat(tmp_add_pricesArr[i].replace(/,/,"."));
  }
  sum = Math.round(sum * 100) / 100;
  if (curFixprice < sum && curFixprice >= 0) {
    alertIsOpen = true; 
    alert("Die Summe der Unternehmerbelastungen im Calculator ist größer als der Festpreis!");
    alertIsOpen = false;
    if (parent.job_options.document.tourOptions.jb_discount.checked == true) {    
      sum = Math.round((sum / (100 - parent.job_options.document.tourOptions.jb_discount_rate.value)) * 10000) / 100;
    }
    parent.job_options.document.tourOptions.jb_fixprice.value = formatPrice(String(sum).replace(/\./,","));
    parent.job_options.document.tourOptions.jb_fixprice.focus();
  }
  checkToll();

//// Ist wahrscheinlich doch obsolet -> eher doch nicht
//  if (parent.job_options.document.tourOptions.afterwards.checked) {
//    if (parent.job_options.document.getElementById("div_jb_bwv").style.display == "none") {
//      parent.job_options.document.getElementById("div_jb_bwv").style.display = "inline";
////      if (bwv_alert)
//      alert("Bitte setzen Sie unbedingt das Häkchen unten rechts bei \"BWV-Auftrag\", falls es sich bei dem Originalauftrag um einen solchen handelt. Nur so kann die Gutschrift ordnungsgemäß verbucht werden.");
//    }
//  } else {
//    parent.job_options.document.getElementById("div_jb_bwv").style.display = "none";
//    parent.job_options.document.tourOptions.jb_bwv.checked = false;
////    bwv_alert = true;
//  }

  if (MASK_CR_PRICE_MODE == "1" && !isSavedTour)
    writeJob();
}

/*
 * checkServiceprice
 *   params: -
 *   return: -
 *   global: job_options, tourOptions, jb_fixprice
 *
 */

function checkServiceprice()
{
  checkAmount("jb_serviceprice", "Servicepreis");
  parent.job_options.document.tourOptions.jb_cr_serviceprice.value = "";
  checkDiscount();
  if (MASK_CR_PRICE_MODE == "1")
    writeJob();
}

function checkCrPrice() {
  checkAmount("jb_cr_price", "Frachtvergütung");

  if (MASK_CR_PRICE_MODE == "1") {
    var cur_jb_markup = parseFloat(parent.job_options.document.tourOptions.currentTSZ.value.substr(0, parent.job_options.document.tourOptions.currentTSZ.value.length - 2).replace(/,/,"."));
    if (trim(parent.job_options.document.tourOptions.jb_markup.value) != "")
      cur_jb_markup = parseFloat(parent.job_options.document.tourOptions.jb_markup.value.replace(/,/,"."));
    var cur_jb_cr_markup = parseFloat(parent.job_options.document.tourOptions.currentCrTSZ.value.substr(0, parent.job_options.document.tourOptions.currentCrTSZ.value.length - 2).replace(/,/,"."));
    if (trim(parent.job_options.document.tourOptions.jb_cr_markup.value) != "")
      cur_jb_cr_markup = parseFloat(parent.job_options.document.tourOptions.jb_cr_markup.value.replace(/,/,"."));
//    var cur_jb_markup = parseFloat(parent.job_options.document.tourOptions.jb_markup.value.replace(/,/,"."));
//    var cur_jb_cr_markup = parseFloat(parent.job_options.document.tourOptions.jb_cr_markup.value.replace(/,/,"."));
    checkCrPriceBounds("jb_fixprice", cur_jb_markup, "jb_cr_price", cur_jb_cr_markup, "Frachtvergütung");
    writeJob();
  }
}

function checkCrServiceprice() {
  checkAmount("jb_cr_serviceprice", "Service-Frachtvergütung");

//  if (MASK_CR_PRICE_MODE == "1") {
//    checkCrPriceBounds("jb_serviceprice", 0, "jb_cr_serviceprice", 0, "Service-Frachtvergütung");
//  }
}

function checkAmount(fieldName, fieldDisplayName) {
  var theField = document.getElementsByName(fieldName)[0];
//alert(theField.value);
  if ((theField.value != "") &&
    isNaN(theField.value.replace(/,/,".")))
  {
    alertIsOpen = true;
    alert(fieldDisplayName + "bitte in der Form '999999,99' eingeben.");
    alertIsOpen = false;
    theField.value = "";
    theField.focus();
  }
  // Sicherstellen, dass, nur höchstens zwei Nachkommastellen eingegeben werden.
  var parts = trim(theField.value.replace(/,/,".")).split(".");
  if (parts.length > 1)
  {
    if (parts[1].length > 2)
    {
      alertIsOpen = true;
      alert(fieldDisplayName + " bitte in der Form '999999,99' eingeben.");
      alertIsOpen = false;
      theField.value = "";
      theField.focus();
    } else {
      if (parts[1].length < 1)
      {
        theField.value = theField.value + "00";
      } else {
        if (parts[1].length < 2)
        {
          theField.value = theField.value + "0";
        }
      }
    }
  } else {
    if (parts[0].length > 0)
    {
      theField.value = theField.value + ",00";
    }
  }
}

function checkCrPriceBounds(fieldName, markup, fieldCrName, markupCr, fieldDisplayName) {

  var markupStr = "";
  var markupCrStr = "";
  if (isNaN(markup)) markup = 0;
  if (markup > 0)
    markupStr = " (inkl. " + markup + "% TSZ)";
  if (isNaN(markupCr)) markupCr = 0;
  if (markupCr > 0)
    markupCrStr = " (inkl. " + markupCr + "% TSZ)";
  var tmp_jb_discount_rate = 0;
  if (parent.job_options.document.tourOptions.jb_discount.checked == true) {
    tmp_jb_discount_rate = parent.job_options.document.tourOptions.jb_discount_rate.value;
//     Math.round(curFixprice * (100 - parent.job_options.document.tourOptions.jb_discount_rate.value)) / 100;
  }



  if (cr_price_block > 0) {
    var curfieldNameprice = parseFloat(document.getElementsByName(fieldName)[0].value.replace(/,/,"."));
    if (isNaN(curfieldNameprice)) curfieldNameprice = 0;
    curfieldNameprice = Math.round(curfieldNameprice * (100 + markup)) / 100;
    var curfieldNameCrPrice = parseFloat(document.getElementsByName(fieldCrName)[0].value.replace(/,/,"."));
    if (isNaN(curfieldNameCrPrice)) curfieldNameCrPrice = 0;
    curfieldNameCrPrice = Math.round(curfieldNameCrPrice * (100 + markupCr)) / 100;
    var maxcurfieldNameCrPrice = Math.round(curfieldNameprice * cr_price_block) / 100;
    if (curfieldNameCrPrice > maxcurfieldNameCrPrice) {
      if (cr_price_block_override != "1") {
        alert("ACHTUNG: Der " + fieldDisplayName + " kann nicht größer sein als " +
          formatPrice(String(maxcurfieldNameCrPrice).replace(/\./,",")) + " " + String.fromCodePoint(0x404)) + "!";
        document.getElementsByName(fieldCrName)[0].value = "";
//        document.getElementsByName(fieldCrName)[0].focus();
      } else {
        if (confirm("ACHTUNG: Bitte bestätigen Sie, dass der " + fieldDisplayName + " mit " +
          formatPrice(String(curfieldNameCrPrice).replace(/\./,",")) + " " + String.fromCodePoint(0x404) +
          markupCrStr + " über der Sperre von " +
          formatPrice(String(maxcurfieldNameCrPrice).replace(/\./,",")) + " " + String.fromCodePoint(0x404) +
          markupStr + " liegt!")) {
          parent.job_options.document.tourOptions.cr_price_block_override.value =
            "BLOCK=" + formatPrice(String(maxcurfieldNameCrPrice).replace(/\./,",")) + "|OVERRIDE=" + formatPrice(String(curfieldNameCrPrice).replace(/\./,","));
        } else {
          document.getElementsByName(fieldCrName)[0].value = "";
          parent.job_options.document.tourOptions.cr_price_block_override.value = "";
//          document.getElementsByName(fieldCrName)[0].focus();
        }
      }
      return;
    }
  }
  if (cr_price_threshold > 0) {
    var curfieldNameprice = parseFloat(document.getElementsByName(fieldName)[0].value.replace(/,/,"."));
    if (isNaN(curfieldNameprice)) curfieldNameprice = 0;
    curfieldNameprice = Math.round(curfieldNameprice * (100 + markup)) / 100;
    var curfieldNameCrPrice = parseFloat(document.getElementsByName(fieldCrName)[0].value.replace(/,/,"."));
    if (isNaN(curfieldNameCrPrice)) curfieldNameCrPrice = 0;
    curfieldNameCrPrice = Math.round(curfieldNameCrPrice * (100 + markupCr)) / 100;
    var maxcurfieldNameCrPrice = Math.round(curfieldNameprice * cr_price_threshold) / 100;
    if (curfieldNameCrPrice > maxcurfieldNameCrPrice) {
      if (confirm("ACHTUNG: Bitte bestätigen Sie, dass der " + fieldDisplayName + " mit " +
        formatPrice(String(curfieldNameCrPrice).replace(/\./,",")) + " " + String.fromCodePoint(0x404) +
        markupCrStr + " über der Schwelle von " +
        formatPrice(String(maxcurfieldNameCrPrice).replace(/\./,",")) + " " + String.fromCodePoint(0x404) +
        markupStr + " liegt!")) {
        parent.job_options.document.tourOptions.cr_price_threshold_override.value =
          "THRESHOLD=" + formatPrice(String(maxcurfieldNameCrPrice).replace(/\./,",")) + "|OVERRIDE=" + formatPrice(String(curfieldNameCrPrice).replace(/\./,","));
      } else {
        document.getElementsByName(fieldCrName)[0].value = "";
        parent.job_options.document.tourOptions.cr_price_threshold_override.value = "";
//        document.getElementsByName(fieldCrName)[0].focus();
      }
    }
  }
}

function checkDiscount()
{
  var jb_serviceprice_value = "";

  if (typeof(parent.job_options.document.tourOptions.jb_discount) == 'undefined')
    return;
  if (typeof(parent.job_options.document.tourOptions.jb_serviceprice) != 'undefined')
    jb_serviceprice_value = parent.job_options.document.tourOptions.jb_serviceprice.value;

  // Wenn globaler Kundenrabatt, dann auch bei Festpreis berücksichtigen
  if (get_cs_discount(curCsc_id_payer) != 0 && ((parent.job_options.document.tourOptions.jb_fixprice.value != ""
    && parent.job_options.document.tourOptions.jb_fixprice.value != "0,00" && parent.job_options.document.tourOptions.jb_fixprice.value != "0,0"
    && parent.job_options.document.tourOptions.jb_fixprice.value != "0," && parent.job_options.document.tourOptions.jb_fixprice.value != "0")
    ||(jb_serviceprice_value != ""
    && jb_serviceprice_value != "0,00" && jb_serviceprice_value != "0,0"
    && jb_serviceprice_value != "0," && jb_serviceprice_value != "0"))) {
    if (parent.job_options.document.tourOptions.jb_discount.disabled || discount_default) {
      parent.job_options.document.tourOptions.jb_discount.disabled = false;
      if (discount_default) { // Funktion writeJob darf enablen, aber kein Häkchen setzen (wg. get_saved_tour.php)
        parent.job_options.document.tourOptions.jb_discount.checked = true;
//        discount_default = false;
      }
      // default-discount nur dann, wenn neuer job
      if (get_cs_fixprice_discount(curCsc_id_payer) == 1 && (jb_id == "" || fixprice_was_0)) {
        parent.job_options.document.tourOptions.jb_discount.checked = true;
      }
    }
    parent.job_options.document.tourOptions.jb_discount_rate_text.value = "(" + get_cs_discount(curCsc_id_payer) + "%)";
    parent.job_options.document.tourOptions.jb_discount_rate.value = get_cs_discount(curCsc_id_payer);
  } else {
    if (!parent.job_options.document.tourOptions.jb_discount.disabled) {
      parent.job_options.document.tourOptions.jb_discount.disabled = true;
        if (typeof(callerID) == 'undefined' || callerID != "writeJob") // Funktion writeJob darf disablen, aber kein Häkchen wegnehmen (wg. get_saved_tour.php)
          parent.job_options.document.tourOptions.jb_discount.checked = false;
    }
    parent.job_options.document.tourOptions.jb_discount_rate_text.value = "";
    parent.job_options.document.tourOptions.jb_discount_rate.value = "0";
  }
}

function checkMarkup()
{
  if ((parent.job_options.document.tourOptions.jb_markup.value != "") &&
    isNaN(parent.job_options.document.tourOptions.jb_markup.value.replace(/,/,".")))
  {
    alertIsOpen = true;
    alert("Prozentsatz bitte in der Form '99,99' eingeben.");
    alertIsOpen = false;
    parent.job_options.document.tourOptions.jb_markup.value = "";
    parent.job_options.document.tourOptions.jb_markup.focus();
  }
  // Sicherheitsabfrage ab dem 13.03.2025
  if (parent.job_options.document.tourOptions.jb_markup.value == 0)
    if (!confirm("Wollen Sie den TSZ wirklich auf 0% setzen?")) {
      parent.job_options.document.tourOptions.jb_markup.value = "";
      parent.job_options.document.tourOptions.jb_markup.focus();
      return;
    }

  // Sicherstellen, dass, nur höchstens zwei Nachkommastellen eingegeben werden.
  var parts = trim(parent.job_options.document.tourOptions.jb_markup.value.replace(/,/,".")).split(".");
  if (parts.length > 1)
  {
    if (parts[1].length > 2)
    {
      alertIsOpen = true;
      alert("Prozentsatz bitte in der Form '99,99' eingeben.");
      alertIsOpen = false;
      parent.job_options.document.tourOptions.jb_markup.value = "";
      parent.job_options.document.tourOptions.jb_markup.focus();
    } else {
      if (parts[1].length < 1)
      {
        parent.job_options.document.tourOptions.jb_markup.value = parent.job_options.document.tourOptions.jb_markup.value + "00";
      } else {
        if (parts[1].length < 2)
        {
          parent.job_options.document.tourOptions.jb_markup.value = parent.job_options.document.tourOptions.jb_markup.value + "0";
        }
      }
    }
  } else {
    if (parts[0].length > 0)
    {
      parent.job_options.document.tourOptions.jb_markup.value = parent.job_options.document.tourOptions.jb_markup.value + ",00";
    }
  }
  // Zuschlag darf natürlich nicht mehr automatisch überschrieben werden!
  jb_markup_overwrite = 0;
  checkFixprice(1);
  if (MASK_CR_PRICE_MODE != "1")
    writeJob();
//  if (parent.job_tour.$('#div_distanceprice').html() != "")
//    openDistanceprice(0);
//  if (parent.job_tour.$('#div_zoneprice').html() != "")
//    openDistanceprice("zone");
}

function checkMarkupCr()
{
  if ((parent.job_options.document.tourOptions.jb_cr_markup.value != "") &&
    isNaN(parent.job_options.document.tourOptions.jb_cr_markup.value.replace(/,/,".")))
  {
    alertIsOpen = true;
    alert("Prozentsatz bitte in der Form '99,99' eingeben.");
    alertIsOpen = false;
    parent.job_options.document.tourOptions.jb_cr_markup.value = "";
    parent.job_options.document.tourOptions.jb_cr_markup.focus();
  }
  // Sicherstellen, dass, nur höchstens zwei Nachkommastellen eingegeben werden.
  var parts = trim(parent.job_options.document.tourOptions.jb_cr_markup.value.replace(/,/,".")).split(".");
  if (parts.length > 1)
  {
    if (parts[1].length > 2)
    {
      alertIsOpen = true;
      alert("Prozentsatz bitte in der Form '99,99' eingeben.");
      alertIsOpen = false;
      parent.job_options.document.tourOptions.jb_cr_markup.value = "";
      parent.job_options.document.tourOptions.jb_cr_markup.focus();
    } else {
      if (parts[1].length < 1)
      {
        parent.job_options.document.tourOptions.jb_cr_markup.value = parent.job_options.document.tourOptions.jb_cr_markup.value + "00";
      } else {
        if (parts[1].length < 2)
        {
          parent.job_options.document.tourOptions.jb_cr_markup.value = parent.job_options.document.tourOptions.jb_cr_markup.value + "0";
        }
      }
    }
  } else {
    if (parts[0].length > 0)
    {
      parent.job_options.document.tourOptions.jb_cr_markup.value = parent.job_options.document.tourOptions.jb_cr_markup.value + ",00";
    }
  }
  // Zuschlag darf natürlich nicht mehr automatisch überschrieben werden!
  jb_cr_markup_overwrite = 0;
  checkFixprice(1);
  if (MASK_CR_PRICE_MODE != "1")
    writeJob();
//  if (parent.job_tour.$('#div_distanceprice').html() != "")
//    openDistanceprice(0);
//  if (parent.job_tour.$('#div_zoneprice').html() != "")
//    openDistanceprice("zone");
}

function checkToll()
{
  if ((parent.job_options.document.tourOptions.jb_toll.value != "") &&
    isNaN(parent.job_options.document.tourOptions.jb_toll.value.replace(/,/,".")))
  {
    alertIsOpen = true;
    alert("Mautbetrag bitte in der Form '999,99' eingeben.");
    alertIsOpen = false;
    parent.job_options.document.tourOptions.jb_toll.value = "";
    parent.job_options.document.tourOptions.jb_toll.focus();
  }
  // Sicherstellen, dass negativer Fixpreis auch zu einem negativen jb_toll führt (und umgekehrt)
  if (!isNaN(parseFloat(parent.job_options.document.tourOptions.jb_fixprice.value.replace(/,/,".")))) {
    if (parseFloat(parent.job_options.document.tourOptions.jb_fixprice.value.replace(/,/,".")) < 0) {
      if (parseFloat(parent.job_options.document.tourOptions.jb_toll.value.replace(/,/,".")) >= 0) {
        parent.job_options.document.tourOptions.jb_toll.value = "-" + parent.job_options.document.tourOptions.jb_toll.value;
      }
    } else {
      if (parseFloat(parent.job_options.document.tourOptions.jb_toll.value.replace(/,/,".")) < 0) {
        parent.job_options.document.tourOptions.jb_toll.value = parent.job_options.document.tourOptions.jb_toll.value.replace(/-/,"");
      } 
    }
  }
  // Sicherstellen, dass nur höchstens zwei Nachkommastellen eingegeben werden.
  var parts = trim(parent.job_options.document.tourOptions.jb_toll.value.replace(/,/,".")).split(".");
  if (parts.length > 1)
  {
    if (parts[1].length > 2)
    {
      alertIsOpen = true;
      alert("Mautbetrag bitte in der Form '999,99' eingeben.");
      alertIsOpen = false;
      parent.job_options.document.tourOptions.jb_toll.value = "";
      parent.job_options.document.tourOptions.jb_toll.focus();
    } else {
      if (parts[1].length < 1)
      {
        parent.job_options.document.tourOptions.jb_toll.value = parent.job_options.document.tourOptions.jb_toll.value + "00";
      } else {
        if (parts[1].length < 2)
        {
          parent.job_options.document.tourOptions.jb_toll.value = parent.job_options.document.tourOptions.jb_toll.value + "0";
        }
      }
    }
  } else {
    if (parts[0].length > 0)
    {
      parent.job_options.document.tourOptions.jb_toll.value = parent.job_options.document.tourOptions.jb_toll.value + ",00";
    }
  }
  // Maut-Zuschlag darf natürlich nicht mehr automatisch überschrieben werden!
//  jb_toll_overwrite = 0;
}

function mkCscList(side)
{
  var customerId = parent.job_options.cs_id_ec;
  var cscIdRoot = csc_id_orderer_root_ec;
  var cscIdActual = csc_id_orderer_ec;  
  var f_comp;
  var f_person;
  var f_street;
  var f_hsno;
  var f_zipcode;
  var f_city;
  var f_country;
  var f_remark;

  if (side == 0)
  {
    f_comp = parent.job_tour.document.tourForm.elements[von_fields[jl_tr_comp]].value;
    f_person = parent.job_tour.document.tourForm.elements[von_fields[jl_tr_person]].value;
    f_street = parent.job_tour.document.tourForm.elements[von_fields[jl_ad_street]].value;
    f_hsno = parent.job_tour.document.tourForm.elements[von_fields[jl_tr_hsno]].value;
    f_zipcode = parent.job_tour.document.tourForm.elements[von_fields[jl_ad_zipcode]].value;
    f_city = parent.job_tour.document.tourForm.elements[von_fields[jl_ad_city]].value;
    f_country = "D";
    f_remark  = parent.job_tour.document.tourForm.elements[von_fields[jl_tr_remark]].value;
  }

  if (side == 1)
  {
    f_comp = parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_comp]].value;
    f_person = parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_person]].value;
    f_street = parent.job_tour.document.tourForm.elements[nach_fields[jl_ad_street]].value;
    f_hsno = parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_hsno]].value;
    f_zipcode = parent.job_tour.document.tourForm.elements[nach_fields[jl_ad_zipcode]].value;
    f_city = parent.job_tour.document.tourForm.elements[nach_fields[jl_ad_city]].value;
    f_country = "D";
    f_remark  = parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_remark]].value;
  }

  tempWin = mkPopupWin(
    "function startReload()\n" +
    "{\n" +
    "  checkDone();\n" +
    "  self.location.href=\"csc_list.php" +
       "?customerId=" + customerId +
       "&cscIdRoot=" + cscIdRoot +
       "&cscIdActual=" + cscIdActual +
       "&f_comp=" + f_comp +
       "&f_person=" + f_person +
       "&f_street=" + f_street +
       "&f_hsno=" + f_hsno +
       "&f_zipcode=" + f_zipcode +
       "&f_city=" + f_city +
       "&f_country=" + f_country +
       "&f_remark=" + f_remark +
       "&tourNo=" + (getCurTourNo() + side) +
       "&f_act=search" + "\";\n" +
    "}\n" +
    "\n" +
    "//--" + ">\n" +
    "<\/script>\n" +
    "<\/head>\n" +
    "<body onLoad=\"startReload()\"\n>" +
    "  <table border=0 align=center height=100% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n" +
    "    <tr>\n" +
    "      <td align=center valign=center>\n" +
    "        <b>Hole Daten...</b>\n" +
    "      <\/td>\n" +
    "    <\/tr>\n" +
    "  <\/table>\n" +
    "<\/body>\n" +
    "<\/html>\n", 1000, 480);
}

function searchCsCsc(side) {
  var f_comp;
  var f_act = 'search';
  var tourno = (getCurTourNo() + side);

  if (side == 0)
  {
    f_comp = parent.job_tour.document.tourForm.elements[von_fields[jl_tr_comp]].value;
  }

  if (side == 1)
  {
    f_comp = parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_comp]].value;
  }

  if (side == 2) // Bezahler aus Bestandskundenliste finden
  {
    f_comp = parent.job_options.document.tourOptions.comp_payer.value;
    tourno = -1;
  }

  var widthPopupWin = 950;
  var heightPopupWin = 600;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  // Im Kundenmodus wird eine andere Liste aufgerufen
  if (parent.job_options.csc_id_orderer != "" && parent.job_options.csc_id_orderer != "0") {
    var customerId = parent.job_options.cs_id_ec;
    var cscIdRoot = csc_id_orderer_root_ec;
    var cscIdActual = csc_id_orderer_ec;  
    popupWin = window.open("../customer/csc_list.php?" +
      "customerId=" + customerId + "&cscIdRoot=" + cscIdRoot + "&cscIdActual=" + cscIdActual +
      "&f_act=" + f_act +
      "&f_cmp_comp=" + myEncodeURI(f_comp) + "&f_cmp_authenticated=" + 1 + 
      "&tourno=" + tourno,
      "","dependent=yes,width=" + widthPopupWin + ",height=" +
      heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
      ",scrollbars=yes,resizable=yes,staus=no");
  } else {
    popupWin = window.open("../admin/cs_csc_list.php?f_act=" + f_act +
      "&f_cmp_comp=" + myEncodeURI(f_comp) + "&f_cmp_authenticated=" + 1 + 
      "&tourno=" + tourno + "&csc_id=" + curCsc_id_payer + "&job_hq_id=" + hq_id,
      "","dependent=yes,width=" + widthPopupWin + ",height=" +
      heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
      ",scrollbars=yes,resizable=yes,staus=no");
  }
};

function getReports()
{
// "<a href=\"../groupware/report.php?currentNavigationItem=vertrieb&rpObjType=cs&g_csc_id=" + curCsc_id_payer + "\" target=\"_blank\">[B]&nbsp;</a>" +      
  var widthPopupWin = 950;
  var heightPopupWin = 600;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../groupware/report.php?currentNavigationItem=vertrieb&rpObjType=cs&g_csc_id=" + curCsc_id_payer,
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
    ",scrollbars=yes,resizable=yes,status=no");
};

function getDocuments()
{
//https://test.assecutor.de/test/import/data_transfer.php?objType=cs&objId=__13316777__
  var widthPopupWin = 950;
  var heightPopupWin = 600;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../import/data_transfer.php?deactivateMenu=1&objType=cs&objId=" + get_cs_id(curCsc_id_payer),
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
    ",scrollbars=yes,resizable=yes,status=no");
};

function searchJbList() {
  var leftFields = parent.job_tour.document.tourForm;
  var f_act = 'search';
  var tourno = (getCurTourNo());
  var customerId = parent.job_options.cs_id_ec;
  var cscIdRoot = csc_id_orderer_root_ec;
  var cscIdActual = csc_id_orderer_ec;  

  var f_cmp_comp = leftFields.elements[von_fields[jl_tr_comp]].value;
  var f_person   = leftFields.elements[von_fields[jl_tr_person]].value;
  var f_street   = leftFields.elements[von_fields[jl_ad_street]].value;
  var f_hsno     = leftFields.elements[von_fields[jl_tr_hsno]].value;
  var f_zipcode  = leftFields.elements[von_fields[jl_ad_zipcode]].value;
  var f_city     = leftFields.elements[von_fields[jl_ad_city]].value;
  var f_remark   = leftFields.elements[von_fields[jl_tr_remark]].value;

  var widthPopupWin = 950;
  var heightPopupWin = 600;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../jobs/jb_search_list.php" +
    "?customerId=" + customerId +
    "&cscIdRoot=" + cscIdRoot +
    "&cscIdActual=" + cscIdActual +
    "&f_act=" + f_act +
    "&f_cmp_comp=" + myEncodeURI(f_cmp_comp) +
    "&f_person=" + myEncodeURI(f_person) + "&f_street=" + myEncodeURI(f_street) + "&f_hsno=" + myEncodeURI(f_hsno) +
    "&f_zipcode=" + myEncodeURI(f_zipcode) + "&f_city=" + myEncodeURI(f_city) + "&f_remark=" + myEncodeURI(f_remark) +
    "&tourno=" + tourno,
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
    ",scrollbars=yes,resizable=yes,status=no");
};

function duplicateJob(killMe) {
  if (confirm("Wollen Sie wirklich einen neuen Auftrag erzeugen?"))
  {
    parent.job_options.document.tourOptions.jb_id_org.value = jb_id;
    jb_id = "";
    parent.job_options.document.tourOptions.jb_id.value = "";
    parent.job_tour.document.tourForm.duplicateJobButton.disabled = true;
    parent.job_tour.document.tourForm.duplicateJobButton.className = "button_disabled";
    parent.job_options.document.tourOptions.jb_id_permanent_pre.value = "";
    parent.job_tour.document.tourForm.jb_origin[0].checked=true;
    parent.job_tour.document.tourForm.jb_origin_other.value = "";
    parent.job_tour.document.tourForm.jb_origin[0].disabled = false;
    parent.job_tour.document.tourForm.jb_origin[2].disabled = false;
    parent.job_tour.document.tourForm.jb_origin[7].disabled = false;
    checkOrigin();
    parent.job_options.document.tourOptions.jb_origin_hidden.value = 1;
    parent.job_options.document.tourOptions.jb_origin_other_hidden.value = "";
    jb_orderer_mandatory = true;
    parent.job_tour.document.tourForm.jb_orderer.value = "";
    parent.job_tour.document.tourForm.jb_commission_no.value = "";
    if (empModeCopyJob != "1") {
      if (typeof(parent.job_options.document.tourOptions.cr_id_order) != 'undefined')
        parent.job_options.document.tourOptions.cr_id_order.value = "";
      if (typeof(parent.job_options.document.tourOptions.jb_permanent) != 'undefined') {
        setDateTimeFields("job_options", "tourOptions", "", "", "", "", "", "tag", "monat", "jahr", "stunde", "minute", "jb_permanent");
        checkJb_permanent(0);
      } else {
        setDateTimeFields("job_options", "tourOptions", "", "", "", "", "", "tag", "monat", "jahr", "stunde", "minute", "");
      }
      if (typeof(parent.job_options.document.tourOptions.endetag) != 'undefined')
        setDateTimeFields("job_options", "tourOptions", "", "", "", "", "", "endetag", "endemonat", "endejahr", "", "", "");
      if (typeof(parent.job_options.document.tourOptions.afterwards) != 'undefined')
        parent.job_options.document.tourOptions.afterwards.disabled = false;
      if (manual_disposition == "1" && typeof(parent.job_options.document.tourOptions.jb_status_manual) != 'undefined') {
        parent.job_options.document.tourOptions.jb_status_manual.disabled=false;
        parent.job_options.document.tourOptions.jb_status_manual.checked=true;
      }
      if (typeof(parent.job_options.document.tourOptions.jb_offer) != 'undefined') {
        parent.job_options.document.tourOptions.jb_offer.disabled = false;
        checkOffer();
      }
    } else {
      if (typeof(parent.job_options.document.tourOptions.afterwards) != 'undefined') {
        parent.job_options.document.tourOptions.afterwards.disabled = false;
        parent.job_options.document.tourOptions.afterwards.checked = true;    
      }
      if (typeof(parent.job_options.document.tourOptions.jb_offer) != 'undefined') {
        parent.job_options.document.tourOptions.jb_offer.checked = false;    
        parent.job_options.document.tourOptions.jb_offer.disabled = true;
      }
      if (typeof(parent.job_options.document.tourOptions.jb_globaljob) != 'undefined') {
        parent.job_options.document.tourOptions.jb_globaljob.disabled = true;
        parent.job_options.document.tourOptions.jb_globaljob.checked = false;
      }
      checkAfterwards();
    }
    if (typeof(parent.job_options.document.tourOptions.jb_waitstorno) != 'undefined')
      parent.job_options.document.tourOptions.jb_waitstorno.disabled = false;
    if (typeof(parent.job_options.document.tourOptions.crSidList) != 'undefined') {
      parent.job_options.document.tourOptions.crSidList.disabled = false;
      parent.job_options.document.tourOptions.crSidList.className = "button_enabled";
    }
    if (typeof(parent.job_options.document.tourOptions.cr_id_order) != 'undefined')
      parent.job_options.document.tourOptions.cr_id_order.disabled = false;
    if (typeof(parent.job_options.document.tourOptions.jb_tourname) != 'undefined')
      parent.job_options.document.tourOptions.jb_tourname.value = "";
    if (hq_id == 1 || hq_id == 7 || hq_id == 8 || hq_id == 3 || hq_id == 2 || hq_id == 5)
      jb_markup_overwrite = 1;
    // 23.01.2024: Manuelle TSZs bei Auftragskopien immer löschen
    parent.job_options.document.tourOptions.jb_markup.value = "";
    parent.job_options.document.tourOptions.jb_cr_markup.value = "";
    parent.job_options.document.tourOptions.self_service_discount.value = "";
    parent.job_options.document.tourOptions.jb_id_insurance.value = "";
    parent.job_options.document.tourOptions.special_case.checked = false;
    parent.job_options.document.tourOptions.jb_insurance.checked = false;
    parent.job_options.document.tourOptions.jb_insurance.disabled = false;
    checkInsurance();
    is_non_eu_notified = false;
    significantPriceValues = "";
    writeJob();
    parent.frames[0].location.href="job_header.php?csc_id_orderer=" + csc_id_orderer_ec + "&what_is_this=Auftragserfassung" + "&hq_id_job=" + hq_id;
    if (empModeCopyJob == "1") // abhängig von akt. Mitarbeiter
    {
//Datum, Fahrzeugtyp und Fahrer bleiben erhalten
    }
    parent.job_options.cur_jb_status = 0;
    // Unteraufträge im Calculator löschen
    parent.job_options.document.tourOptions.tmp_add_jb_ids.value = "";
    parent.job_options.document.tourOptions.tmp_add_sids.value = "";
    parent.job_options.document.tourOptions.tmp_add_prices.value = "";
    // Fuhrlohn löschen, wenn Fuhrlohn nicht verfügbar
    if (MASK_CALC_CR_PRICE != "1" && MASK_CR_PRICE_MODE != "1")
      parent.job_options.document.tourOptions.jb_cr_price.value = "";
    checkCalculator();
    if (fixprice_was_zone) {
      parent.job_options.document.tourOptions.jb_fixprice.value = "";
      parent.job_options.document.tourOptions.jb_cr_price.value = "";
    }
    checkJb_sales_tax_rate_sign(0);
    // Natürlich keine Abfrage mehr nach Mailversand, ist ja keine Änderung mehr
    parent.job_options.document.tourOptions.ask_mailrecipients.value = '';
    // tr_ids rausnehmen, da jetzt neue Tour
    for (j = 0; j < (maxTour + 1); j++) {
      setJobList(j, jl_tr_id, "");
      setJobList(j, jl_tr_commission_no, "");
    }
    parent.job_tour.document.tourForm.elements[von_fields[jl_tr_commission_no]].value = "";
    parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_commission_no]].value = "";
    $('#multi_job_factor').show();
    $('#multi_job_all').show();
  } else {
    if ((typeof (killMe) != 'undefined') && killMe)
    parent.close();
  }
};

function getLastJob() {
  if (prev_jb_id != "") // should not be possible...
//    if (confirm("Wollen Sie wirklich einen neuen aus dem vorher erfassten Auftrag erzeugen?"))
    parent.frames[0].location.href="job_header.php?csc_id_orderer=" + csc_id_orderer_ec + "&what_is_this=Auftrags&auml;nderung (Nr. " + prev_jb_id + ")";
    parent.job_options.document.tourOptions.jb_id.value = prev_jb_id;
    self.setTimeout('getSavedTour(' + prev_jb_id + ',' + 'true' + ',' + '0' + ',' + 'false' + ')', 100);
  return;
}

function mk_tr_remark_Text(side) {
  var widthPopupWin = 520;
  var heightPopupWin = 200;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  var tr_remark = "";

  if (side == 0)
    tr_remark = parent.job_tour.document.tourForm.von_tr_remark.value;
  if (side == 1)
    tr_remark = parent.job_tour.document.tourForm.nach_tr_remark.value;

//isCurrentlySubmitting = false;
  var popupdata =
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" +
    "<html lang=\"de\">\n" +
    "<head>\n" +
    "<title>votian: Freitexteingabe<\/title>\n" +
    "<link rel=\"stylesheet\" type=\"text/css\" href=\"../css/phoenix.css.php\">\n" +
    "<script type=\"text/javascript\">\n" +
    "<!" + "--\n" +
    "\n" +
    "var side = " + side + ";\n" +
    "\n" +
    "function doFocus(){\n" +
    "  document.forms[0].tr_remark.focus();" +
    "}\n" +
    "\n" +
    "function doDelete(){\n" +
    "  document.forms[0].tr_remark.value = '';" +
    "  document.forms[0].tr_remark.focus();" +
    "}\n" +
    "\n" +
    "function doSave(){\n" +
    "  if (side == 0)" +
    "    opener.parent.job_tour.document.tourForm.von_tr_remark.value = document.forms[0].tr_remark.value;" +
    "  if (side == 1)" +
    "    opener.parent.job_tour.document.tourForm.nach_tr_remark.value = document.forms[0].tr_remark.value;" +
    "  opener.saveFormFields();\n" +
    "  self.close();\n" +
    "}\n" +
    "\n" +
    "// Quelle: http://www.nak-webmaster.de/modules.php?name=News&file=article&sid=71\n" +
    "function countDigits(){\n" +
    "  var maxDigits = " + maxTr_remark + ";\n" +
    "  var areaString = document.forms[0].tr_remark.value;\n" +
    "  var currLength = areaString.length + 1;\n" +
    "  var restLength = maxDigits - currLength +1;\n" +
    "  if ( restLength <  0 ) {\n" +
    "    restLength = 0;\n" +
    "  }\n" +
    "\n" +
    "//  document.forms[0].counter.value = restLength;\n" +
    "  if (areaString.length  > maxDigits-1) {\n" +
    "    //die folgende Zeile entfernt alle Zeichen die  > maxDigits sind\n" +
    "    document.forms[0].tr_remark.value = document.forms[0].tr_remark.value.substring(0, maxDigits);\n" +
    "  }\n" +
    "}\n" +
    "\n" +
    "//--" + ">\n" +
    "<\/script>\n" +
    "<\/head>\n" +
    "<body onload=\"doFocus()\"\n>" +
    "  <table border=0 align=center height=100% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n" +
    "    <tr>\n" +
    "      <td align=center valign=top>\n" +
    "<form>" +
    "<textarea name=\"tr_remark\" cols=\"60\" rows=\"8\" onKeyUp=\"countDigits()\" onClick=\"countDigits()\">"
    + tr_remark + "</textarea>" +
    "</form>" +
    "<input type=\"button\" class=\"button_enabled\" value=\"Abbrechen\" onClick=\"self.close()\" accesskey=\"a\">&nbsp;" +
    "<input type=\"button\" class=\"button_enabled\" value=\"Löschen\" onClick=\"doDelete()\" accesskey=\"l\">&nbsp;" +
    "<input type=\"button\" class=\"button_enabled\" value=\"Speichern\" onClick=\"doSave()\" accesskey=\"s\">&nbsp;" +
    "      <\/td>\n" +
    "    <\/tr>\n" +
    "  <\/table>\n" +
    "<\/body>\n" +
    "<\/html>\n";
  popupWin1(widthPopupWin, heightPopupWin, leftPopupWin, topPopupWin, popupdata);
};

function mkRechnungsText(textType) {
  var widthPopupWin = 520;
  var heightPopupWin = 200;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;

//isCurrentlySubmitting = false;
  var popupdata =
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" +
    "<html lang=\"de\">\n" +
    "<head>\n" +
    "<title>votian: Freitexteingabe<\/title>\n" +
    "<link rel=\"stylesheet\" type=\"text/css\" href=\"../css/phoenix.css.php\">\n" +
    "<script type=\"text/javascript\">\n" +
    "<!" + "--\n" +
    "\n" +
    "function doFocus(){\n" +
    "  document.forms[0].jb_freetext_1.focus();" +
    "}\n" +
    "\n" +
    "function doDelete(){\n" +
    "  document.forms[0].jb_freetext_1.value = '';" +
    "  document.forms[0].jb_freetext_1.focus();" +
    "}\n" +
    "\n" +
    "function doSave(){\n" +
    (textType != 'hidden' ? 

    "  opener.parent.job_options.document.tourOptions.jb_freetext_1.value = document.forms[0].jb_freetext_1.value;\n" +
    "  if (document.forms[0].jb_freetext_1.value == \"\")\n" +
    "    opener.parent.job_tour.document.tourForm.jb_freetextButton.value = \"Text\";\n" +
    "  else\n" +
    "    opener.parent.job_tour.document.tourForm.jb_freetextButton.value = \"Text*\";\n" :

    "  opener.parent.job_options.document.tourOptions.jb_hiddenFreetext_1.value = document.forms[0].jb_freetext_1.value;\n" +
    "  if (document.forms[0].jb_freetext_1.value == \"\")\n" +
    "    opener.parent.job_tour.document.tourForm.jb_hiddenFreetextButton.value = \"Text nur Rg\";\n" +
    "  else\n" +
    "    opener.parent.job_tour.document.tourForm.jb_hiddenFreetextButton.value = \"Text nur Rg*\";\n") +

    "  self.close();\n" +
    "}\n" +
    "\n" +
    "// Quelle: http://www.nak-webmaster.de/modules.php?name=News&file=article&sid=71\n" +
    "function countDigits(){\n" +
    "  var maxDigits = 800;   //maximale Zeichenanzahl\n" +
    "  var areaString = document.forms[0].jb_freetext_1.value;\n" +
    "  var currLength = areaString.length + 1;\n" +
    "  var restLength = maxDigits - currLength +1;\n" +
    "  if ( restLength <  0 ) {\n" +
    "    restLength = 0;\n" +
    "  }\n" +
    "\n" +
    "//  document.forms[0].counter.value = restLength;\n" +
    "  if (areaString.length  > maxDigits-1) {\n" +
    "    //die folgende Zeile entfernt alle Zeichen die  > maxDigits sind\n" +
    "    document.forms[0].jb_freetext_1.value = document.forms[0].jb_freetext_1.value.substring(0, maxDigits);\n" +
    "  }\n" +
    "}\n" +
    "\n" +
    "//--" + ">\n" +
    "<\/script>\n" +
    "<\/head>\n" +
    "<body onload=\"doFocus()\"\n>" +
    "  <table border=0 align=center height=100% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n" +
    "    <tr>\n" +
    "      <td align=center valign=top>\n" +
    "<form>" +
    "<textarea name=\"jb_freetext_1\" cols=\"60\" rows=\"8\" onKeyUp=\"countDigits()\" onClick=\"countDigits()\">" +
    (textType != 'hidden' ? parent.job_options.document.tourOptions.jb_freetext_1.value : parent.job_options.document.tourOptions.jb_hiddenFreetext_1.value)
    + "</textarea>" +
    "</form>" +
    "<input type=\"button\" class=\"button_enabled\" value=\"Abbrechen\" onClick=\"self.close()\" accesskey=\"a\">&nbsp;" +
    "<input type=\"button\" class=\"button_enabled\" value=\"Löschen\" onClick=\"doDelete()\" accesskey=\"l\">&nbsp;" +
    "<input type=\"button\" class=\"button_enabled\" value=\"Speichern\" onClick=\"doSave()\" accesskey=\"s\">&nbsp;" +
    "      <\/td>\n" +
    "    <\/tr>\n" +
    "  <\/table>\n" +
    "<\/body>\n" +
    "<\/html>\n";
  popupWin1(widthPopupWin, heightPopupWin, leftPopupWin, topPopupWin, popupdata);
};

function mkDispoInfo() {
  var widthPopupWin = 400;
  var heightPopupWin = 140;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;

  var jb_dispoinfo = parent.job_options.document.tourOptions.jb_dispoinfo.value;
  var jb_warnjahr =  parent.job_options.document.tourOptions.jb_warnjahr.value;
  var jb_warnmonat =  parent.job_options.document.tourOptions.jb_warnmonat.value;  
  var jb_warntag =  parent.job_options.document.tourOptions.jb_warntag.value;
  var jb_warnstunde =  parent.job_options.document.tourOptions.jb_warnstunde.value;
  var jb_warnminute =  parent.job_options.document.tourOptions.jb_warnminute.value; 
  var jb_jam_waittime =  parent.job_options.document.tourOptions.jb_jam_waittime.value; 

//isCurrentlySubmitting = false;
  var popupdata =
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" +
    "<html lang=\"de\">\n" +
    "<head>\n" +
    "<title>votian: Eingabe der Dispo-Info<\/title>\n" +
    "<link rel=\"stylesheet\" type=\"text/css\" href=\"../css/phoenix.css.php\">\n" +
    "<script src=\"../include/lib_global.js\" type=\"text/javascript\"></script>\n" +
    "<script type=\"text/javascript\">\n" +
    "<!" + "--\n" +
    "\n" +
    "function doFocus(){\n" +
    "  document.forms[0].jb_dispoinfo.focus();" +
    "}\n" +
    "\n" +
    "function doDelete(){\n" +
    "  document.forms[0].jb_dispoinfo.value = '';" +
    "  document.forms[0].jb_warnjahr.value = '';" +
    "  document.forms[0].jb_warnmonat.value = '';" +
    "  document.forms[0].jb_warntag.value = '';" +
    "  document.forms[0].jb_warnstunde.value = '';" +
    "  document.forms[0].jb_warnminute.value = '';" +
    "  document.forms[0].jb_jam_waittime.value = '';" +
    "  document.forms[0].jb_dispoinfo.focus();" +
    "}\n" +
    "\n" +
    "function doSave(){\n" +
    "  opener.parent.job_options.document.tourOptions.jb_dispoinfo.value = document.forms[0].jb_dispoinfo.value;\n" +
    "  opener.parent.job_options.document.tourOptions.jb_warnjahr.value = document.forms[0].jb_warnjahr.value;\n" +
    "  opener.parent.job_options.document.tourOptions.jb_warnmonat.value = document.forms[0].jb_warnmonat.value;\n" +
    "  opener.parent.job_options.document.tourOptions.jb_warntag.value = document.forms[0].jb_warntag.value;\n" +
    "  opener.parent.job_options.document.tourOptions.jb_warnstunde.value = document.forms[0].jb_warnstunde.value;\n" +
    "  opener.parent.job_options.document.tourOptions.jb_warnminute.value = document.forms[0].jb_warnminute.value;\n" +
// ***jb_job_jam_test***   "  if (typeof (document.forms[0].jb_jam_waittime_check) != 'undefined') {\n" +
// ***jb_job_jam_test***   "    if (document.forms[0].jb_jam_waittime_check.checked == false)\n" +
// ***jb_job_jam_test***   "      opener.parent.job_options.document.tourOptions.jb_jam_waittime.value = '';\n" +
// ***jb_job_jam_test***   "    else\n" +
// ***jb_job_jam_test***  "      opener.parent.job_options.document.tourOptions.jb_jam_waittime.value = '30';\n" +
// ***jb_job_jam_test***   "  } else {\n" +
// ***jb_job_jam_test***   "    opener.parent.job_options.document.tourOptions.jb_jam_waittime.value = document.forms[0].jb_jam_waittime.value;\n" +
// ***jb_job_jam_test***   "    if (opener.parent.job_options.document.tourOptions.jb_jam_waittime.value == '0')\n" +
// ***jb_job_jam_test***   "      opener.parent.job_options.document.tourOptions.jb_jam_waittime.value = '';\n" +
// ***jb_job_jam_test***   "  }\n" +
    "  if (document.forms[0].jb_dispoinfo.value == \"\" &&\n" +
    "    document.forms[0].jb_warnjahr.value == \"\" && document.forms[0].jb_warnmonat.value == \"\" && document.forms[0].jb_warntag.value == \"\" &&" +
    "    document.forms[0].jb_warnstunde.value == \"\" && document.forms[0].jb_warnminute.value == \"\" /* && ***jb_job_jam_test*** opener.parent.job_options.document.tourOptions.jb_jam_waittime.value == \"\" */) {" +
    "    opener.parent.job_tour.document.tourForm.jb_dispoInfoButton.value = \"Dispo Info\";\n" +
    "    if (opener.hq_id == 8)\n" +
    "      opener.parent.job_tour.document.tourForm.jb_dispoInfoButton.className = \"button_enabled\";\n" +
    "  } else {\n" +
    "    if (opener.hq_id == 8)\n" +
    "      opener.parent.job_tour.document.tourForm.jb_dispoInfoButton.className = \"inputRed\";\n" +
    "    else" +
    "      opener.parent.job_tour.document.tourForm.jb_dispoInfoButton.value = \"Dispo Info*\";\n" +
    "  }\n" +
    "  opener.saveFormFields();\n" +
    "  opener.refreshFormFields();\n" +
    "  self.close();\n" +
    "}\n" +
    "\n" +
    "//--" + ">\n" +
    "<\/script>\n" +
    "<\/head>\n" +
    "<body onload=\"doFocus()\"\n>" +
    "  <table border=0 align=center height=100% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n" +
    "<form name=\"jb_dispoinfo_form\">\n" +
    "    <tr>\n" +
    "      <td align=left valign=top>\n" +
    "<b>Dispo Info:</b><br>\n" +
    "<input name=\"jb_dispoinfo\" type=\"text\" value=\"" + jb_dispoinfo + "\" size=\"40\" maxlength=\"40\" class=\"input\">\n" +
    "      <\/td>\n" +
    "    <\/tr>\n" +
    "    <tr>\n" +
    "      <td align=left valign=top>\n" +
    "<b>Enddatum/-uhrzeit:</b><br>\n" +
    "<input name=\"jb_warntag\" type=\"text\" size=\"2\" maxlength=\"2\" class=\"input\" value=\"" + jb_warntag + "\"\n" +
    "onchange=\"fillDateFields(0, '', 'jb_dispoinfo_form', 'jb_warntag', 'jb_warntag', 'jb_warnmonat', 'jb_warnjahr', 'jb_warnstunde', 'jb_warnminute', '')\">\n" +
    "<input name=\"jb_warnmonat\" type=\"text\" size=\"2\" maxlength=\"2\" class=\"input\" value=\"" + jb_warnmonat + "\"\n" +
    "onchange=\"fillDateFields(0, '', 'jb_dispoinfo_form', 'jb_warnmonat', 'jb_warntag', 'jb_warnmonat', 'jb_warnjahr', 'jb_warnstunde', 'jb_warnminute', '')\">\n" +
    "<input name=\"jb_warnjahr\" type=\"text\" size=\"4\" maxlength=\"4\" class=\"input\" value=\"" + jb_warnjahr + "\"\n" +
    "onchange=\"fillDateFields(0, '', 'jb_dispoinfo_form', 'jb_warnjahr', 'jb_warntag', 'jb_warnmonat', 'jb_warnjahr', 'jb_warnstunde', 'jb_warnminute', '')\">\n&nbsp;&nbsp;" +
    "<input name=\"jb_warnstunde\" type=\"text\" size=\"2\" maxlength=\"2\" class=\"input\" value=\"" + jb_warnstunde + "\"\n" +
    "onchange=\"fillDateFields(0, '', 'jb_dispoinfo_form', 'jb_warnstunde', 'jb_warntag', 'jb_warnmonat', 'jb_warnjahr', 'jb_warnstunde', 'jb_warnminute', '')\">\n" +
    "<input name=\"jb_warnminute\" type=\"text\" size=\"2\" maxlength=\"2\" class=\"input\" value=\"" + jb_warnminute + "\"\n" +
    "onchange=\"fillDateFields(0, '', 'jb_dispoinfo_form', 'jb_warnminute', 'jb_warntag', 'jb_warnmonat', 'jb_warnjahr', 'jb_warnstunde', 'jb_warnminute', '')\">\n" +
// ***jb_job_jam_test***   "      <\/td>\n" +
// ***jb_job_jam_test***   "    <\/tr>\n" +
// ***jb_job_jam_test***   "    <tr>\n" +
// ***jb_job_jam_test***   "      <td align=left valign=top>\n" +
// ***jb_job_jam_test***   (parent.job_options.document.tourOptions.tag.value != "" && parent.job_options.document.tourOptions.monat.value != "" && parent.job_options.document.tourOptions.jahr.value != ""
// ***jb_job_jam_test***   ? "<b>Warn-Mail bei fehlgeschlagener Vermittlung</b>:\n" + "<input type=\"checkbox\" name=\"jb_jam_waittime_check\" value=\"" + 1 + "\"" + (jb_jam_waittime != "" ? "checked" : "") + ">\n"
// ***jb_job_jam_test***   : "<b>Wartezeit für Warn-Mail bei fehlgeschlagener Vermittlung (Minuten)</b>:\n" + "<input name=\"jb_jam_waittime\" type=\"text\" value=\"" + jb_jam_waittime + "\" size=\"3\" maxlength=\"3\" class=\"input\">\n" ) +
    "</form>" +
    "      <\/td>\n" +
    "    <\/tr>\n" +
    "    <tr>\n" +
    "      <td align=center valign=top>\n" +
    "<input type=\"button\" class=\"button_enabled\" value=\"Abbrechen\" onClick=\"self.close()\" accesskey=\"a\">&nbsp;" +
    "<input type=\"button\" class=\"button_enabled\" value=\"Löschen\" onClick=\"doDelete()\" accesskey=\"l\">&nbsp;" +
    "<input type=\"button\" class=\"button_enabled\" value=\"Speichern\" onClick=\"doSave()\" accesskey=\"s\">&nbsp;" +
    "      <\/td>\n" +
    "    <\/tr>\n" +
    "  <\/table>\n" +
    "<\/body>\n" +
    "<\/html>\n";
  popupWin1(widthPopupWin, heightPopupWin, leftPopupWin, topPopupWin, popupdata);
};

/*
function mk_tr_commission_no(side) {
  var widthPopupWin = 400;
  var heightPopupWin = 100;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;

  var tr_commission_no = "";
  if (side == 0)
    tr_commission_no = parent.job_tour.document.tourForm.von_tr_commission_no.value;
  if (side == 1)
    tr_commission_no = parent.job_tour.document.tourForm.nach_tr_commission_no.value;
//isCurrentlySubmitting = false;
  var popupdata =
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" +
    "<html lang=\"de\">\n" +
    "<head>\n" +
    "<title>votian: Eingabe der Kommissionsnummer<\/title>\n" +
    "<link rel=\"stylesheet\" type=\"text/css\" href=\"../css/phoenix.css.php\">\n" +
    "<script type=\"text/javascript\">\n" +
    "<!" + "--\n" +
    "\n" +
    "var side = " + side + ";\n" +
    "\n" +
    "function doFocus(){\n" +
    "  document.forms[0].tr_commission_no.focus();" +
    "}\n" +
    "\n" +
    "function doDelete(){\n" +
    "  document.forms[0].tr_commission_no.value = '';" +
    "  document.forms[0].tr_commission_no.focus();" +
    "}\n" +
    "\n" +
    "function doSave(){\n" +
    "  if (side == 0)" +
    "    opener.parent.job_tour.document.tourForm.von_tr_commission_no.value = document.forms[0].tr_commission_no.value;" +
    "  if (side == 1)" +
    "    opener.parent.job_tour.document.tourForm.nach_tr_commission_no.value = document.forms[0].tr_commission_no.value;" +
    "  opener.saveFormFields();\n" +
    "  opener.refreshFormFields();\n" +
    "  self.close();\n" +
    "}\n" +
    "\n" +
    "//--" + ">\n" +
    "<\/script>\n" +
    "<\/head>\n" +
    "<body onload=\"doFocus()\"\n>" +
    "  <table border=0 align=center height=100% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n" +
    "    <tr>\n" +
    "      <td align=center valign=top>\n" +
    "<form>" +
    "<input name=\"tr_commission_no\" type=\"text\" value=\"" + tr_commission_no + "\" size=\"30\" maxlength=\"30\" class=\"input\">" +
    "</form>" +
    "<input type=\"button\" class=\"button_enabled\" value=\"Abbrechen\" onClick=\"self.close()\" accesskey=\"a\">&nbsp;" +
    "<input type=\"button\" class=\"button_enabled\" value=\"Löschen\" onClick=\"doDelete()\" accesskey=\"l\">&nbsp;" +
    "<input type=\"button\" class=\"button_enabled\" value=\"Speichern\" onClick=\"doSave()\" accesskey=\"s\">&nbsp;" +
    "      <\/td>\n" +
    "    <\/tr>\n" +
    "  <\/table>\n" +
    "<\/body>\n" +
    "<\/html>\n";
  popupWin1(widthPopupWin, heightPopupWin, leftPopupWin, topPopupWin, popupdata);
};

function mk_cmp_remark(side) {
  var widthPopupWin = 520;
  var heightPopupWin = 200;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;

  var cmp_remark = get_cmp_remark(curCsc_id_payer);
  var comp = get_comp(curCsc_id_payer);

  if (side != 2) {
    var curTourNo = (getCurTourNo());
    cmp_remark = get_cmp_remark(getJobList(curTourNo + side, jl_csc_id));
    comp = get_comp(getJobList(curTourNo + side, jl_csc_id));
  }

//isCurrentlySubmitting = false;
  var popupdata =
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" +
    "<html lang=\"de\">\n" +
    "<head>\n" +
    "<title>votian: Bemerkung zu Kunde " + comp + "<\/title>\n" +
    "<link rel=\"stylesheet\" type=\"text/css\" href=\"../css/phoenix.css.php\">\n" +
    "<script type=\"text/javascript\">\n" +
    "<!" + "--\n" +
    "\n" +
    "function doFocus(){\n" +
    "  document.forms[0].ok_button.focus();" +
    "}\n" +
    "\n" +
    "//--" + ">\n" +
    "<\/script>\n" +
    "<\/head>\n" +
    "<body onload=\"doFocus()\"\n>" +
    "<\/head>\n" +
    "<body>\n" +
    "  <table border=0 align=center height=100% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n" +
    "    <tr>\n" +
    "      <td align=center valign=top>\n" +
    "<form>" +
    "<textarea name=\"cmp_remark\" cols=\"60\" rows=\"8\" readonly>"
    + cmp_remark + "</textarea>" +
    "<br><input type=\"button\" class=\"button_enabled\" name=\"ok_button\" value=\"OK\" onClick=\"self.close()\" accesskey=\"o\">&nbsp;" +
    "</form>" +
    "      <\/td>\n" +
    "    <\/tr>\n" +
    "  <\/table>\n" +
    "<\/body>\n" +
    "<\/html>\n";
  popupWin1(widthPopupWin, heightPopupWin, leftPopupWin, topPopupWin, popupdata);
};
*/

/*
 * is_in_customer_fiters
 *   params: csc_id
 *   return: cs_prov
 *   global: cs_eid_list, MASK_CS_PROV_DEFAULT
 *
 * Rabattsatz default ja/nein
 */

function is_in_customer_filters(crf_short)
{
  // leerer crf_short kann nicht vorkommen
  if (crf_short.replace(/\s/,"").length == 0)
    return false;
  for (var i = 0; i < cs_filter_list_customer.length; i++) {
    if (cs_filter_list_customer[i] == crf_short) {
      return true;
    }
  }
  return false;
}

function mkJb_cr_filter() {
  var widthPopupWin = 900;
  var heightPopupWin = 110 + Math.ceil(cfl.length / 4) * 20;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;

  var content = "<tr>\n";
  var jb_cr_filter_checked;
  var savefunction = "";

  // Kurierfilter zusammenstellen
  var j = 0;
  for (var i = 0; i < cfl.length; i++)
  {
    /* Kundenmodus? -> Kunden-Kurierfilter berücksichtigen */
    if (cs_jbedit_cs_filter == "" || is_in_customer_filters(cfl[i][0])) {
      if (j++ % 4 == 0)
        content = content + "</tr>\n<tr>";
      jb_cr_filter_checked = "";
      jb_cr_filter_musthave = "";
      jb_cr_filter_savefield = "jb_cr_filter_opt";
      if (cfl[i][2] == 1) // 0 = Info, 1 = Sperre, 2 = Warnung
      {
        jb_cr_filter_savefield = "jb_cr_filter";
        jb_cr_filter_musthave = "*";
      }
      if (cfl[i][3] == 1) // Selektiert = 1
        jb_cr_filter_checked = "checked";
      if (cfl[i][0] == "&nbsp;") // Dummy zum Füllen der Tabelle
      {
        content = content + "<td align=left>"
          + cfl[i][0] + jb_cr_filter_musthave + "</td><td align=left valign=center>&nbsp;&nbsp;&nbsp;" + cfl[i][1] + "</td>\n";
      } else {
        content = content + "<td align=left>" +
          "<input type=\"checkbox\" name=\"jb_cr_filter_list" + i + "\" value=\"1\"" + jb_cr_filter_checked + ">"
          + cfl[i][0] + jb_cr_filter_musthave + "</td><td align=left valign=center>&nbsp;&nbsp;&nbsp;" + cfl[i][1] + "</td>\n";
        savefunction = savefunction +
          "  if (document.jb_cr_filter_list.jb_cr_filter_list" + i + ".checked)\n" +
          "  { opener.cfl[" + i + "][3] = 1;\n" +
          "    " + jb_cr_filter_savefield + " = " + jb_cr_filter_savefield + " + \",\" + \"" + cfl[i][0] + "\";}\n" +
          "  else { opener.cfl[" + i + "][3] = 0 };\n";
      }
    }
  }
  content = content + "</tr>\n";
//isCurrentlySubmitting = false;
  var popupdata =
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" +
    "<html lang=\"de\">\n" +
    "<head>\n" +
    "<title>votian: Eingabe der Kurierfilter<\/title>\n" +
    "<link rel=\"stylesheet\" type=\"text/css\" href=\"../css/phoenix.css.php\">\n" +
    "<script type=\"text/javascript\">\n" +
    "<!" + "--\n" +
    "\n" +
    "var jb_cr_filter = \"\";\n" +
    "var jb_cr_filter_opt = \"\";\n" +
    "\n" +
    "function doSave(){\n" +
    savefunction +
    "  opener.parent.job_options.document.tourOptions.jb_cr_filter.value = jb_cr_filter.substr(1, jb_cr_filter.length - 1);\n" +
    "  opener.parent.job_options.document.tourOptions.jb_cr_filter_opt.value = jb_cr_filter_opt.substr(1, jb_cr_filter_opt.length - 1);\n" +
    "  if (opener.parent.job_options.document.tourOptions.jb_cr_filter.value == \"\" &&\n" +
    "      opener.parent.job_options.document.tourOptions.jb_cr_filter_opt.value == \"\")\n" +
    "    opener.parent.job_options.document.tourOptions.jb_cr_filterButton.value = \"Filter\";\n" +
    "  else\n" +
    "    opener.parent.job_options.document.tourOptions.jb_cr_filterButton.value = \"Filter*\";\n" +
    "  self.close();\n" +
    "}\n" +
    "\n" +
    "//--" + ">\n" +
    "<\/script>\n" +
    "<\/head>\n" +
    "<body>" +
    "<table border=0 align=center width=100% height=90% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n" +
    "<tr><td>" +
    "  <table border=1 align=center width=100% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n" +
    "<form name=\"jb_cr_filter_list\">" +
    content +
    "</form>"+
    "  <\/table>\n"+
    "</td><t/r>" +
    "  <\/table>\n<br><center>"+
    "<input type=\"button\" class=\"button_enabled\" value=\"Abbrechen\" onClick=\"self.close()\" accesskey=\"a\">&nbsp;"+
    "<input type=\"button\" class=\"button_enabled\" value=\"Speichern\" onClick=\"doSave()\" accesskey=\"s\">&nbsp;"+
    "<\/center><\/body>\n"+
    "<\/html>\n";
  popupWin1(widthPopupWin, heightPopupWin, leftPopupWin, topPopupWin, popupdata);
};

// Funktionen für Sondervereinbarungen

function get_cs_price_list(cs_id, srv, srvt)
{
  // leere cs_id hat keine Sondervereinbarungen
  if (String(cs_id).replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_price_list.length; i++) {
    if (cs_price_list[i][0] == cs_id && cs_price_list[i][1] == srv && cs_price_list[i][2] == srvt) {
      return cs_price_list[i][3];
    }
  }
  return 0;
}

function get_cs_price_list_cr(cs_id, srv, srvt)
{
  // leere cs_id hat keine Sondervereinbarungen
  if (String(cs_id).replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_price_list.length; i++) {
    if (cs_price_list[i][0] == cs_id && cs_price_list[i][1] == srv && cs_price_list[i][2] == srvt) {
      return cs_price_list[i][4];
    }
  }
  return 0;
}

function get_cs_srv_list(cs_id, cnt)
{
  var c = 0;
  // leere cs_id hat keine Sondervereinbarungen
  if (String(cs_id).replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_srv_list.length; i++) {
    if (cs_srv_list[i][0] == cs_id) {
      if (c++ == cnt)
        return cs_srv_list[i][1];
    }
  }
  return "";
}

function get_cs_srvt_list(cs_id, cnt)
{
  var c = 0;
  // leere cs_id hat keine Sondervereinbarungen
  if (String(cs_id).replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_srvt_list.length; i++) {
    if (cs_srvt_list[i][0] == cs_id) {
      if (c++ == cnt)
        return cs_srvt_list[i][1];
    }
  }
  return "";
}

function get_cs_calc_mand_list(cs_id)
{
  // leere cs_id hat keine Sondervereinbarungen
  if (String(cs_id).replace(/\s/,"").length == 0)
    return "";
  for (var i = 0; i < cs_calc_mand_list.length; i++) {
    if (cs_calc_mand_list[i][0] == cs_id) {
      return cs_calc_mand_list[i][1];
    }
  }
  return "";
}

function checkCalculator() {
//alert (parent.job_options.document.tourOptions.jb_type.value + " " + parent.job_options.document.tourOptions.jb_cr_price.value + " " + parent.job_options.document.tourOptions.tmp_add_sids.value);
  if (typeof (parent.job_options.document.tourOptions.calcButton) == 'undefined')
    return;
  if (((parent.job_options.document.tourOptions.jb_type.value != "2" && parent.job_options.document.tourOptions.jb_type.value != 0) && MASK_CALCULATOR_TYPE == "1" ) ||
//    parent.job_options.document.tourOptions.jb_cr_price.value != "" ||
    parent.job_options.document.tourOptions.tmp_add_sids.value != "" ||
    (parent.job_options.document.tourOptions.tmp_add_srvs.value != "" && MASK_CALCULATOR_SRV == "1"))
    parent.job_options.document.tourOptions.calcButton.value = "Calc*";
  else
    parent.job_options.document.tourOptions.calcButton.value = "Calc";
  checkSendTour();
  // Wenn das 751er-Fahrzeug als Default für die Unternehmerverteilung eingestellt ist, soll die Möglichkeit bestehen, das Fahrzeug manuell (in 750) zu ändern
  if (parent.job_options.document.tourOptions.tmp_add_sids.value != "" && String(MASK_INVOICE_SIDS_SID).indexOf(MASK_INVOICE_SIDS_SID1) != -1) {
    parent.job_options.document.tourOptions.cr_id_order.disabled = false;
    parent.job_options.document.tourOptions.crSidList.disabled = false;
    parent.job_options.document.tourOptions.crSidList.className = "button_enabled";
  } else {
    if (jb_id != "") {
      parent.job_options.document.tourOptions.cr_id_order.disabled = true;
      parent.job_options.document.tourOptions.crSidList.disabled = true;
      parent.job_options.document.tourOptions.crSidList.className = "button_disabled";
    }
  }
}

function get_MASK_INVOICE_SIDS_SID() {
  var real_MASK_INVOICE_SIDS_SID = MASK_INVOICE_SIDS_SID;
  if (MASK_INVOICE_SHOW_SIDS == "1") {
    if (parent.job_options.document.tourOptions.vht_id.value < 7 && MASK_INVOICE_SIDS_SID.indexOf(MASK_INVOICE_SIDS_SID0) == -1)
      real_MASK_INVOICE_SIDS_SID = MASK_INVOICE_SIDS_SID.replace(MASK_INVOICE_SIDS_SID1, MASK_INVOICE_SIDS_SID0);
  }
  return real_MASK_INVOICE_SIDS_SID;
}

function calculator() {
  var widthPopupWin = 500;
  var heightPopupWin = 450 - (MASK_CALCULATOR_TYPE == "1" ? 0 : 20) - (MASK_CALCULATOR_SRV == "1" ? 0 : 150);
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;

  var jb_type = parent.job_options.document.tourOptions.jb_type.value;
//  var jb_id_parent = parent.job_options.document.tourOptions.jb_id_parent.value;
  var jb_cr_price = parent.job_options.document.tourOptions.jb_cr_price.value;

  var tmp_add_jb_ids = parent.job_options.document.tourOptions.tmp_add_jb_ids.value;
  var tmp_add_sids = parent.job_options.document.tourOptions.tmp_add_sids.value;
  var tmp_add_prices = parent.job_options.document.tourOptions.tmp_add_prices.value;
  var tmp_add_srvs = parent.job_options.document.tourOptions.tmp_add_srvs.value;
  var tmp_add_srvts = parent.job_options.document.tourOptions.tmp_add_srvts.value;
  var tmp_add_mult = parent.job_options.document.tourOptions.tmp_add_mult.value;
  var tmp_add_mult_price = parent.job_options.document.tourOptions.tmp_add_mult_price.value;

  var tmp_add_sid_default = "";
  if (MASK_INVOICE_SHOW_SIDS == "1")
    if (parent.job_options.document.tourOptions.cr_id_order.value != MASK_INVOICE_SIDS_SID)
      tmp_add_sid_default = parent.job_options.document.tourOptions.cr_id_order.value;

//alert(tmp_add_jb_ids + "|" + tmp_add_sids + "|" + tmp_add_prices);
//alert("|" + tmp_add_srvs + "|");

  // Fuhrlohn: Warnung, wenn durch Provisionssatz ermittelter Wert überschritten wird!
  var curFixprice = parseFloat(parent.job_options.document.tourOptions.jb_fixprice.value.replace(/,/,"."));
  if (isNaN(curFixprice)) curFixprice = 0;
  var jb_cr_price_max = 0;
  var cs_prov = parseFloat(get_cs_prov(curCsc_id_payer));
  var cs_provStr = "";
  if (cs_prov > 0 && curFixprice > 0) {
    jb_cr_price_max = Math.round(curFixprice * (100 - cs_prov)) / 100;
    cs_provStr = "&nbsp;(Prov.: " + formatPrice(String(cs_prov).replace(/\./,",")) + "%)";
  }

  // Unternehmerverrechnungen
  var tmp_add_jb_idsArr = tmp_add_jb_ids.split("¹");
  var tmp_add_sidsArr = tmp_add_sids.split("¹");
  var tmp_add_pricesArr = tmp_add_prices.split("¹");
  var tmp_add_sids_prices_options = "";
  if (tmp_add_sidsArr.length == 1 && tmp_add_sidsArr[0] == "")
    tmp_add_sids_prices_options += "<option value=0>[kein Eintrag]</option>\n";
  else
    for (var i = 0; i < tmp_add_sidsArr.length; i++)
      tmp_add_sids_prices_options += "<option value=" + i + ">" + tmp_add_sidsArr[i] + " (" + tmp_add_pricesArr[i] + " €)</option>\n";

  // Kennzeichen für Export
  var vht_product_list_str = "jb_type";
  var is_selected_str = "";
  for (var i = 0; i < vht_product_list.length; i++) {
    is_selected_str = "";
    if (vht_product_list[i][0] == jb_type)
      is_selected_str = " selected";
    vht_product_list_str += "<option value=" + vht_product_list[i][0] + is_selected_str + ">" + vht_product_list[i][1] + "</option>\n";
  }

  // Sondervereinbarungen
  var tmp_add_srvsArr = tmp_add_srvs.split("¹");
  var tmp_add_srvtsArr = tmp_add_srvts.split("¹");
  var tmp_add_multArr = tmp_add_mult.split("¹");
  var tmp_add_mult_price_Arr = tmp_add_mult_price.split("¹");
  var tmp_srv_srvt_options = "";
  var cs_id = get_cs_id(curCsc_id_payer);
  var tmpCrPrice = 0;
  var tmpCrPriceStr = "";
  if (tmp_add_srvsArr.length == 1 && tmp_add_srvsArr[0] == "")
    tmp_srv_srvt_options += "<option value=0>[kein Eintrag]</option>\n";
  else
    for (var i = 0; i < tmp_add_srvsArr.length; i++) {
      tmpCrPrice = 0;
      tmpCrPriceStr = "";
      tmpCrPrice = Math.round(parseFloat(get_cs_price_list_cr(cs_id, trim(tmp_add_srvsArr[i].replace(/\n/g, "°")), trim(tmp_add_srvtsArr[i]))) * tmp_add_multArr[i] * 100) / 100;
      if (tmpCrPrice > 0)
        tmpCrPriceStr = " | " + tmpCrPrice.toFixed(2).replace(/\./,",") + " €";
      tmp_srv_srvt_options += "<option value=" + i + ">" + tmp_add_srvsArr[i].replace(/\n/g, "°") + " | " + tmp_add_srvtsArr[i] + " | " + tmp_add_multArr[i] + "x | (" + tmp_add_mult_price_Arr[i] + " €" + tmpCrPriceStr + ")</option>\n";
    }

  // Sondervereinbarungen für den aktuellen Zahler finden
  var srv_list = Array();
  var srvt_list = Array();
  var tmp_str = "";
  var srv_list_options = "";
  var srvt_list_options = "";

  var i = 0;
  do {
    tmp_str = get_cs_srv_list(cs_id, i++);
    if (tmp_str != "")
      srv_list_options += "<option value=" + i + ">" + tmp_str + "</option>\n";
  } while (tmp_str != "");
  if (i == 1)
    srv_list_options = "<option value=0>[kein Eintrag]</option>\n";
  i = 0;
  do {
    tmp_str = get_cs_srvt_list(cs_id, i++);
    if (tmp_str != "")
      srvt_list_options += "<option value=" + i + ">" + tmp_str + "</option>\n";
  } while (tmp_str != "");
  if (i == 1)
    srvt_list_options = "<option value=0>[kein Eintrag]</option>\n";

  var real_MASK_INVOICE_SIDS_SID = get_MASK_INVOICE_SIDS_SID();

//  cur_popupWin = popupWin;
//isCurrentlySubmitting = false;
  var popupdata =
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" +
    "<html lang=\"de\">\n" +
    "<head>\n" +
    "<title>votian: Calculator<\/title>\n" +
    "<link rel=\"stylesheet\" type=\"text/css\" href=\"../css/phoenix.css.php\">\n" +
    "<script type=\"text/javascript\">\n" +
    "<!" + "--\n" +
    "\n" +
    "var alertIsOpen = false;\n" +    
    "var cs_id = " + cs_id + ";\n" +
    "var jb_cr_price_max = " + jb_cr_price_max + ";\n" +
    "var deleted_sid = \"\";" +
    "\n" +
    "function doAddToTmp_srv(what){\n" +    
    "  var tmpPrice = 0;\n" +
    "  var tmpCrPrice = 0;\n" +
    "  var tmpCrPriceStr = \"\";\n" +
    "  var tmpMult = 0;\n" +
    "  var selSrv = \"\";\n" +
    "  var selSrvt = \"\";\n" +
    "  var found1 = 0;\n" +
    "  var found2 = 0;\n" +
    "  var i = 0;\n" +
    "  if (document.forms[0].tmp_srv_list.options.length >= 20) {\n" +
    "    alert(\"Maximale Anzahl von Einträgen ist erreicht, Hinzufügen nicht möglich.\");\n" +
    "    return;" +
    "  }\n" +
    "  if (what == 0) {\n" +
    "    while (i < document.forms[0].srv_list.length & !found1)\n" +
    "    {\n" +
    "      if (document.forms[0].srv_list.options[i].selected)\n" +
    "      {\n" +
    "        selSrv = document.forms[0].srv_list.options[i].text;\n" +
    "        found1 = 1;\n" +
    "      }\n" +
    "      i += 1;\n" +
    "    }\n" +
    "    i = 0;\n" +
    "    while (i < document.forms[0].srvt_list.length & !found2)\n" +
    "    {\n" +
    "      if (document.forms[0].srvt_list.options[i].selected)\n" +
    "      {\n" +
    "        selSrvt = document.forms[0].srvt_list.options[i].text;\n" +
    "        found2 = 1;\n" +
    "      }\n" +
    "      i += 1;\n" +
    "    }\n" +
    "    if (!found1 || !found2) {\n" +
    "      alert(\"Bitte beide Felder auswählen.\");\n" +
    "      return;" +
    "    }\n" +
    "  }\n" +
    "  if (what == 1) {\n" +
    "    if (document.forms[0].srv_list_man_text.value.replace(/\\s/g,\"\") == \"\") {\n" +
    "      alert(\"Bitte einen Text für den Rechnungsposten eingeben.\");\n" +
    "      document.forms[0].srv_list_man_text.focus();\n" +
    "      return;" +
    "    }\n" +
    "  }\n" +
    "  if (what == 0) {\n" +
    "    if (document.forms[0].srv_list_mult.value.replace(/\\s/g,\"\") == \"\" || isNaN(document.forms[0].srv_list_mult.value.replace(/\\s/g,\"\").replace(/,/,\".\"))) {\n" +
    "      alert(\"Ungültige Eingabe im Multiplikator.\");\n" +
    "      document.forms[0].srv_list_mult.value = \"\";\n" +
    "      document.forms[0].srv_list_mult.focus();\n" +
    "      return;" +
    "    }" +
    "  }\n" +
    "  if (what == 1) {\n" +
    "    if (document.forms[0].srv_list_man_mult.value.replace(/\\s/g,\"\") == \"\" || isNaN(document.forms[0].srv_list_man_mult.value.replace(/\\s/g,\"\").replace(/,/,\".\"))) {\n" +
    "      alert(\"Ungültige Eingabe im Multiplikator.\");\n" +
    "      document.forms[0].srv_list_man_mult.value = \"\";\n" +
    "      document.forms[0].srv_list_man_mult.focus();\n" +
    "      return;" +
    "    }" +
    "  }\n" +
    "  if (what == 0) {\n" +
    "    tmpMult = parseFloat(document.forms[0].srv_list_mult.value.replace(/\\s/g,\"\").replace(/,/,\".\"));\n" +
    "  }\n" +
    "  if (what == 1) {\n" +
    "    tmpMult = parseFloat(document.forms[0].srv_list_man_mult.value.replace(/\\s/g,\"\").replace(/,/,\".\"));\n" +
    "  }\n" +
    "  var parts = String(tmpMult).split(\".\");\n" +
//    "  if (parts.length == 2) {\n" +
//    "    if (!((parseInt(parts[1]) + 100) == 100 || (parseInt(parts[1]) + 75) == 100 || (parseInt(parts[1]) + 5) == 10 || (parseInt(parts[1]) + 25) == 100)) {" +
//    "      alert(\"Es sind nur folgende Bruchzahlen im Multiplikator zulässig: '0,25', '0,5' oder '0,75'.\");\n" +
//    "      if (what == 0) {\n" +
//    "        document.forms[0].srv_list_mult.focus();\n" +
//    "      }" +
//    "      if (what == 1) {\n" +
//    "        document.forms[0].srv_list_mult_man.focus();\n" +
//    "      }" +
//    "      return;" +
//    "    }" +    
//    "  }" +    
    "  if (parts.length == 2 && parts[1].length > 2) {\n" +
    "    alert(\"Im Multiplikator sind nur höchstens zwei Nachkommastellen zulässig.\");\n" +
    "    if (what == 0) {\n" +
    "      document.forms[0].srv_list_mult.focus();\n" +
    "    }" +
    "    if (what == 1) {\n" +
    "      document.forms[0].srv_list_mult_man.focus();\n" +
    "    }" +
    "    return;" +
    "  }" +    
    "  if (what == 0) {\n" +
    "    document.forms[0].srv_list_mult.value = String(tmpMult).replace(/\\./,\",\");\n" +
    "  }\n" +
    "  if (what == 1) {\n" +
    "    document.forms[0].srv_list_man_mult.value = String(tmpMult).replace(/\\./,\",\");\n" +
    "  }\n" +
    "  if (what == 0) {\n" +
    "    tmpPrice = Math.round(parseFloat(opener.get_cs_price_list(cs_id, selSrv, selSrvt)) * tmpMult * 100) / 100;\n" +
    "    tmpCrPrice = Math.round(parseFloat(opener.get_cs_price_list_cr(cs_id, selSrv, selSrvt)) * tmpMult * 100) / 100;\n" +
    "  }\n" +
    "  if (what == 1) {\n" +
    "    checkCr_price(2);\n" +
    "    if (document.forms[0].srv_list_man_price.value != \"\") {\n" +
    "      tmpPrice = Math.round(parseFloat(document.forms[0].srv_list_man_price.value.replace(/,/,\".\")) * tmpMult * 100) / 100;\n" +
    "    } else {\n" +
    "      document.forms[0].srv_list_man_price.focus();\n" +
    "      return;\n" +
    "    }\n" +
    "  }\n" +
    "  tmpPrice = String(tmpPrice).replace(/\\./,\",\");\n" +
    "  parts = tmpPrice.split(\",\");\n" +
    "  if (parts.length > 1) {\n" +
    "    if (parts[1].length < 2) {\n" +
    "      if (parts[1].length < 1) {\n" +
    "        tmpPrice += \"00\";\n" +
    "      } else {\n" +
    "        tmpPrice += \"0\";}}\n" +
    "  } else {\n" +
    "    if (parts[0].length > 0) {\n" +
    "      tmpPrice += \",00\";}\n" +
    "  }\n" +
    "  tmpCrPriceStr = \"\";" +
    "  if (tmpCrPrice > 0)" +
    "    tmpCrPriceStr = \" | \" + tmpCrPrice.toFixed(2).replace(/\\./,\",\") + \" €\";" +
    "  if (document.forms[0].tmp_srv_list.options[0].text == \"[kein Eintrag]\")\n" +
    "    document.forms[0].tmp_srv_list.options[0] = null;\n" + 
    "  document.forms[0].tmp_srv_list.options[document.forms[0].tmp_srv_list.options.length] = \n" +
    "    (what == 0 ? new Option(selSrv + \" | \" + selSrvt + \" | \" + document.forms[0].srv_list_mult.value + \"x | (\" + tmpPrice + \" €\" + tmpCrPriceStr + \")\", document.forms[0].tmp_srv_list.options.length, false, false)\n" +
    "     : (what == 1 ? new Option(document.forms[0].srv_list_man_text.value.replace(/\\n/g,\"°\")" /* + ".replace(/\\r/g,\"\").replace(/\l/g,\"\")" */ + " + \" | \" + \"\" + \" | \" + document.forms[0].srv_list_man_mult.value + \"x | (\" + tmpPrice + \" €)\" , document.forms[0].tmp_srv_list.options.length, false, false)\n" +
    "     : null));\n" +
    "}\n" +
    "function doDeleteTmp_srv_list(){\n" +
    "  if (confirm(\"Wollen Sie den Eintrag '\" + " +
    "    document.forms[0].tmp_srv_list.options[document.forms[0].tmp_srv_list.options.selectedIndex].text" +
    "    + \"' wirklich löschen?\")) {" +
    "    document.forms[0].tmp_srv_list.options[document.forms[0].tmp_srv_list.options.selectedIndex] = null;\n" +
    "    if (document.forms[0].tmp_srv_list.options.length == 0)\n" +
    "      document.forms[0].tmp_srv_list.options[0] = new Option(\"[kein Eintrag]\", 0, false, false);\n" +
    "  }\n" +
    "}\n" +
    "\n" +
    "function doDeleteAllTmp_srv_list(){\n" +
    "  while (document.forms[0].tmp_srv_list.options.length > 0)\n" +  
    "    document.forms[0].tmp_srv_list.options[document.forms[0].tmp_srv_list.options.length - 1] = null;\n" +
    "  document.forms[0].tmp_srv_list.options[0] = new Option(\"[kein Eintrag]\", 0, false, false);\n" +
    "}\n" +
    "function doAddToTmp_add_sids_prices(){\n" +
    "  if (!opener.checkForeignStations()) {\n" +
    "    alert(\"Diese Funktion ist für Aufträge mit Stationen im Ausland gesperrt.\");\n" +
    "    return;" +
    "  }\n" +
    "  if (!opener.parent.job_options.is_afterwards && opener.parent.job_options.cur_jb_status != 2) {\n" +
    "    alert(\"Diese Funktion ist nur bei erledigten Aufträgen möglich.\");\n" +
    "    return;" +
    "  }\n" +
    "  if (document.forms[0].tmp_add_sids_prices.options.length >= 20) {\n" +
    "    alert(\"Maximale Anzahl weiterer Unternehmer ist erreicht, Hinzufügen nicht möglich.\");\n" +
    "  } else {\n" +
    "    if (document.forms[0].tmp_add_sid.value.replace(/\\s/g,\"\") == \"\") {\n" +
    "      alert(\"Bitte Fahrzeug eingeben.\");\n" +
    "      document.forms[0].tmp_add_sid.focus();\n" +
    "    } else {\n" +
    "      if (document.forms[0].tmp_add_price.value.replace(/\\s/g,\"\") == \"\") {\n" +
    "        alert(\"Bitte Betrag eingeben.\");\n" +
    "        document.forms[0].tmp_add_price.focus();\n" +
    "      } else {\n" +
    "        checkCr_price(1);\n" +
    "        if (document.forms[0].tmp_add_price.value != \"\") {\n" +
    "          if (document.forms[0].tmp_add_sids_prices.options[0].text == \"[kein Eintrag]\") {\n" +
    "            document.forms[0].tmp_add_sids_prices.options[0] = null;\n" + 
    "            document.forms[0].jb_cr_price.value = '';\n" +
    "          }\n" +
    "          document.forms[0].tmp_add_sids_prices.options[document.forms[0].tmp_add_sids_prices.options.length] = \n" +
    "            new Option(document.forms[0].tmp_add_sid.value + \" (\" + document.forms[0].tmp_add_price.value + \" €)\", document.forms[0].tmp_add_sids_prices.options.length, false, false);\n" +
    "          document.forms[0].tmp_add_sid.value = \"\";\n" +
    "          document.forms[0].tmp_add_price.value = \"\";\n" +
    "        }\n" +
    "      }\n" +
    "    }\n" +
    "  }\n" +
    "}\n" +
    "\n" +
    "function doDeleteTmp_add_sids_prices(){\n" +
    "  if (confirm(\"Wollen Sie den Eintrag '\" + " +
    "    document.forms[0].tmp_add_sids_prices.options[document.forms[0].tmp_add_sids_prices.options.selectedIndex].text" +
    "    + \"' wirklich löschen?\")) {" +
    "    var tmp_entry = document.forms[0].tmp_add_sids_prices.options[0].text.split(\"(\");\n" +
    "    deleted_sid = tmp_entry[0].replace(/\\s/g,\"\");\n" +
    "    document.forms[0].tmp_add_sids_prices.options[document.forms[0].tmp_add_sids_prices.options.selectedIndex] = null;\n" +
    "    if (document.forms[0].tmp_add_sids_prices.options.length == 0){\n" +
    "      document.forms[0].tmp_add_sids_prices.options[0] = new Option(\"[kein Eintrag]\", 0, false, false);\n" +
    "    }\n" +
    "  }\n" +
    "}\n" +
    "\n" +
    "function doDeleteAllTmp_add_sids_prices(){\n" +
    "  while (document.forms[0].tmp_add_sids_prices.options.length > 0)\n" +  
    "    document.forms[0].tmp_add_sids_prices.options[document.forms[0].tmp_add_sids_prices.options.length - 1] = null;\n" +
    "  document.forms[0].tmp_add_sids_prices.options[0] = new Option(\"[kein Eintrag]\", 0, false, false);\n" +
    "}\n" +
    "\n" +
    "function doFocus(){\n" +
//    "  document.forms[0].jb_type.focus();\n" +
    "}\n" +
    "\n" +
    "function doDelete(){\n" +
    (MASK_CALCULATOR_TYPE == "1"
    ? "  document.forms[0].jb_type.selectedIndex = 2;\n"
    : "") +      
//    "  document.forms[0].jb_id_parent.value = '';\n" +
    "  document.forms[0].jb_cr_price.value = '';\n" +
    "  doDeleteAllTmp_add_sids_prices();\n" +
    (MASK_CALCULATOR_SRV == "1"
    ? "  doDeleteAllTmp_srv_list();\n"
    : "") +
//    "  document.forms[0].jb_type.focus();\n" +
    "}\n" +
    "\n" +
    "function doSave(){\n" +
    (MASK_CALCULATOR_TYPE == "1"
    ? "  opener.parent.job_options.document.tourOptions.jb_type.value = document.forms[0].jb_type.selectedIndex;\n" +
      "  opener.parent.job_options.document.tourOptions.jb_type.value = document.forms[0].jb_type.options[opener.parent.job_options.document.tourOptions.jb_type.value].value;\n"
    : "" ) +  
    "  if (alertIsOpen)\n" +
    "    return;" +
//    "  opener.parent.job_options.document.tourOptions.jb_id_parent.value = document.forms[0].jb_id_parent.value;\n" +
    (MASK_CALC_CR_PRICE == "1"
    ? "  opener.parent.job_options.document.tourOptions.jb_cr_price.value = document.forms[0].jb_cr_price.value;\n"
    : "" ) +  
    "  var tmp_entry = new Array();\n" +
    "  tmp_add_sids = \"\";\n" +
    "  tmp_add_prices = \"\";\n" +
    (MASK_CALC_SIDS == "1"
    ? "  if (document.forms[0].tmp_add_sids_prices.options[0].text != \"[kein Eintrag]\")\n {" +
      "    for (var i = 0; i < document.forms[0].tmp_add_sids_prices.options.length; i++) {\n" +
      "      tmp_entry = document.forms[0].tmp_add_sids_prices.options[i].text.split(\"(\");\n" +
      "      tmp_add_sids += \"¹\" + tmp_entry[0].replace(/\\s/g,\"\");\n" +
      "      tmp_add_prices += \"¹\" + tmp_entry[1].substr(0, tmp_entry[1].length - 3).replace(/\\s/g,\"\");\n" +
      "    }\n"
    : "" ) +
    (MASK_INVOICE_SHOW_SIDS == "1"
    ? "opener.parent.job_options.document.tourOptions.cr_id_order.value = \"" + real_MASK_INVOICE_SIDS_SID + "\";\n" +
      "opener.parent.job_options.document.tourOptions.cr_id_order_hidden.value = \"" + real_MASK_INVOICE_SIDS_SID + "\";\n" +
      "opener.checkCr_id_order();\n"
    : "" ) +
    (MASK_CALC_SIDS == "1"
    ? "  }\n"
    : "" ) +
    "  opener.parent.job_options.document.tourOptions.tmp_add_sids.value = tmp_add_sids.substr(1, tmp_add_sids.length - 1);\n" +
    "  opener.parent.job_options.document.tourOptions.tmp_add_prices.value = tmp_add_prices.substr(1, tmp_add_prices.length - 1);\n" +
    "  if (opener.parent.job_options.document.tourOptions.tmp_add_sids.value == \"\" && opener.parent.job_options.document.tourOptions.cr_id_order.value == \"" + real_MASK_INVOICE_SIDS_SID + "\") {" +
    "    opener.parent.job_options.document.tourOptions.cr_id_order.value = deleted_sid;" +
    "    opener.parent.job_options.document.tourOptions.cr_id_order_hidden.value = deleted_sid;" +
    "  }\n" +
    "  var tmp_add_srvs = \"\";\n" +
    "  var tmp_add_srvts = \"\";\n" +
    "  var tmp_add_mult = \"\";\n" +
    "  var tmp_add_mult_price = \"\";\n" +
    "  var theTmpPrice = \"\";\n" +
    "  var theTmpCrPrice = \"\";\n" +
    "  var priceSum = 0;\n" +
    "  var crPriceSum = 0;\n" +
    (MASK_CALCULATOR_SRV == "1"
    ? "  if (document.forms[0].tmp_srv_list.options[0].text != \"[kein Eintrag]\")\n {" +
      "    for (var i = 0; i < document.forms[0].tmp_srv_list.options.length; i++) {\n" +
      "      tmp_entry = document.forms[0].tmp_srv_list.options[i].text.split(\"|\");\n" +
      "      tmp_add_srvs += \"¹\" + tmp_entry[0].replace(/°/g,\"\\n\");\n" +
      "      tmp_add_srvts += \"¹\" + tmp_entry[1];\n" +
      "      tmp_add_mult += \"¹\" + tmp_entry[2].replace(/\\s/g,\"\").replace(/x/g,\"\");\n" +
      "      theTmpPrice = tmp_entry[3].replace(/\\s/g,\"\").substr(1, tmp_entry[3].length - 5);\n" +
      "      theTmpCrPrice = \"\";\n" +
      "      if (typeof(tmp_entry[4]) != 'undefined') {\n" +
      "        theTmpCrPrice = tmp_entry[4].replace(/\\s/g,\"\").substr(0, tmp_entry[4].length - 4);\n" +
      "      }\n" +
      "      tmp_add_mult_price += \"¹\" + theTmpPrice;\n" +
      "      priceSum += parseFloat(theTmpPrice.replace(/,/,\".\"));\n" +
      "      priceSum = Math.round(priceSum * 100) / 100;\n" +
      "      if (theTmpCrPrice != \"\") {\n" +
      "        crPriceSum += parseFloat(theTmpCrPrice.replace(/,/,\".\"));\n" +
      "        crPriceSum = Math.round(crPriceSum * 100) / 100;\n" +
      "      }\n" +
      "    }\n" +
      "  }\n"
    : "" ) +
    "  opener.parent.job_options.document.tourOptions.tmp_add_srvs.value = tmp_add_srvs.substr(1, tmp_add_srvs.length - 1);\n" +
    "  opener.parent.job_options.document.tourOptions.tmp_add_srvts.value = tmp_add_srvts.substr(1, tmp_add_srvts.length - 1);\n" +
    "  opener.parent.job_options.document.tourOptions.tmp_add_mult.value = tmp_add_mult.substr(1, tmp_add_mult.length - 1);\n" +
    "  opener.parent.job_options.document.tourOptions.tmp_add_mult_price.value = tmp_add_mult_price.substr(1, tmp_add_mult_price.length - 1);\n" +
    (MASK_CR_PRICE_MODE == "1"
    ? "  opener.parent.job_options.document.tourOptions.jb_cr_price.value = crPriceSum.toFixed(2).replace(/\\./,\",\");\n" // +
//      "  opener.checkCrPrice();\n"
    : "  if (crPriceSum > 0 && (opener.parent.job_options.is_afterwards || opener.parent.job_options.cur_jb_status == 2)) {\n" +
      "    if (opener.parent.job_options.document.tourOptions.cr_id_order.value != \"\" && String(opener.parent.job_options.document.tourOptions.cr_id_order.value).indexOf(opener.MASK_INVOICE_SIDS_SID0) == -1\n" +
      "      && String(opener.parent.job_options.document.tourOptions.cr_id_order.value).indexOf(opener.MASK_INVOICE_SIDS_SID1) == -1\n" +
      "      && opener.EMAIL_CRVHSID_NO_MAIL.indexOf(String(opener.parent.job_options.document.tourOptions.cr_id_order.value)) == -1) {\n" +
      "      opener.parent.job_options.document.tourOptions.tmp_add_sids.value = opener.parent.job_options.document.tourOptions.cr_id_order.value;\n" +
      "      opener.parent.job_options.document.tourOptions.cr_id_order.value = \"" + real_MASK_INVOICE_SIDS_SID + "\";\n" +
      "      opener.parent.job_options.document.tourOptions.cr_id_order_hidden.value = \"" + real_MASK_INVOICE_SIDS_SID + "\";\n" +
      "    }\n" +
      "    if (opener.parent.job_options.document.tourOptions.tmp_add_sids.value != \"\") {\n" +
      "//alert(crPriceSum + \"|\" + Math.trunc(crPriceSum)  + \"|\" + (Math.round((crPriceSum - Math.trunc(crPriceSum)) * 100)/100));\n" +
      "      opener.parent.job_options.document.tourOptions.tmp_add_prices.value = crPriceSum.toFixed(2).replace(/\\./,\",\");\n" +
      "    }\n" +
      "  }\n"
    ) +
    (MASK_CALCULATOR_SRV == "1"
    ? "  if (document.forms[0].tmp_srv_list.options[0].text != \"[kein Eintrag]\") {\n" +
      "    opener.parent.job_options.document.tourOptions.jb_fixprice.value = String(priceSum).replace(/\\./,\",\");\n" +
      "    opener.checkFixprice(0);\n" + // Festpreis aus Sondervereinbarungen soll Kundenprovision berücksichtigen
      "  } else {" +
      "    opener.checkFixprice(1);\n" +
      "  }\n"
    : "  opener.checkFixprice(1);\n" ) +
    "  opener.checkCalculator();\n" +
//    "  opener.saveFormFields();\n" +
//    "  opener.refreshFormFields();\n" +
    "  self.close();\n" +
    "}\n" +
    "\n" +
    "function checkCr_price(what)\n" +
    "{\n" +
    "  var the_price = \"\";\n" +
    "  if (what == 0) {\n" +
    "    document.forms[0].jb_cr_price.value = document.forms[0].jb_cr_price.value.replace(/\\s/g,\"\");\n" +
    "    the_price = document.forms[0].jb_cr_price.value;\n" +
    "  }\n" +
    "  if (what == 1) {\n" +
    "    document.forms[0].tmp_add_price.value = document.forms[0].tmp_add_price.value.replace(/\\s/g,\"\");\n" +
    "    the_price = document.forms[0].tmp_add_price.value;\n" +
    "  }\n" +
    "  if (what == 2) {\n" +
    "    document.forms[0].srv_list_man_price.value = document.forms[0].srv_list_man_price.value.replace(/\\s/g,\"\");\n" +
    "    the_price = document.forms[0].srv_list_man_price.value;\n" +
    "  }\n" +
    "  if (the_price == \"\")\n {" +
    "    alert(\"Bitte Betrag eingeben.\");\n" +
    "    if (what == 0) {\n" +
    "      document.forms[0].jb_cr_price.value = \"\";\n" +
    "      document.forms[0].jb_cr_price.focus();\n" +
    "    }\n" +
    "    if (what == 1) {\n" +
    "      document.forms[0].tmp_add_price.value = \"\";\n" +
    "      document.forms[0].tmp_add_price.focus();\n" +
    "    }\n" +
    "    if (what == 2) {\n" +
    "      document.forms[0].srv_list_man_price.value = \"\";\n" +
    "      document.forms[0].srv_list_man_price.focus();\n" +
    "    }\n" +
    "    return;\n" +
    "  }\n" +
    "  if (isNaN(the_price.replace(/,/,\".\")))\n" +
    "  {\n" +
    "    alert(\"Betrag bitte in der Form '999999,99' eingeben.\");\n" +
    "    if (what == 0) {\n" +
    "      document.forms[0].jb_cr_price.value = \"\";\n" +
    "      document.forms[0].jb_cr_price.focus();\n" +
    "    }\n" +
    "    if (what == 1) {\n" +
    "      document.forms[0].tmp_add_price.value = \"\";\n" +
    "      document.forms[0].tmp_add_price.focus();\n" +
    "    }\n" +
    "    if (what == 2) {\n" +
    "      document.forms[0].srv_list_man_price.value = \"\";\n" +
    "      document.forms[0].srv_list_man_price.focus();\n" +
    "    }\n" +
    "    return;\n" +
    "  }\n" +
    "  var parts = the_price.replace(/,/,\".\").split(\".\");\n" +
    "  if (parts.length > 1)\n" +
    "  {\n" +
    "    if (parts[1].length > 2)\n" +
    "    {\n" +
    "      alertIsOpen = true;\n" +
    "      alert(\"Betrag bitte in der Form '999999,99' eingeben.\");\n" +
    "      alertIsOpen = false;\n" +
    "      if (what == 0) {\n" +
    "        document.forms[0].jb_cr_price.value = \"\";\n" +
    "        document.forms[0].jb_cr_price.focus();\n" +
    "      }\n" +
    "      if (what == 1) {\n" +
    "        document.forms[0].tmp_add_price.value = \"\";\n" +
    "        document.forms[0].tmp_add_price.focus();\n" +
    "      }\n" +
    "      if (what == 2) {\n" +
    "        document.forms[0].srv_list_man_price.value = \"\";\n" +
    "        document.forms[0].srv_list_man_price.focus();\n" +
    "      }\n" +
    "      return;\n" +
    "    } else {\n" +
    "      if (parts[1].length < 1)\n" +
    "      {\n" +
    "        if (what == 0) {\n" +
    "          document.forms[0].jb_cr_price.value = document.forms[0].jb_cr_price.value + \"00\";\n" +
    "        }\n" +
    "        if (what == 1) {\n" +
    "          document.forms[0].tmp_add_price.value = document.forms[0].tmp_add_price.value + \"00\";\n" +
    "        }\n" +
    "        if (what == 2) {\n" +
    "          document.forms[0].srv_list_man_price.value = document.forms[0].srv_list_man_price.value + \"00\";\n" +
    "        }\n" +
    "      } else {\n" +
    "        if (parts[1].length < 2)\n" +
    "        {\n" +
    "          if (what == 0) {\n" +
    "            document.forms[0].jb_cr_price.value = document.forms[0].jb_cr_price.value + \"0\";\n" +
    "          }\n" +
    "          if (what == 1) {\n" +
    "            document.forms[0].tmp_add_price.value = document.forms[0].tmp_add_price.value + \"0\";\n" +
    "          }\n" +
    "          if (what == 2) {\n" +
    "            document.forms[0].srv_list_man_price.value = document.forms[0].srv_list_man_price.value + \"0\";\n" +
    "          }\n" +
    "        }\n" +
    "      }\n" +
    "    }\n" +
    "  } else {\n" +
    "    if (parts[0].length > 0) {\n" +
    "      if (what == 0) {\n" +
    "        document.forms[0].jb_cr_price.value = document.forms[0].jb_cr_price.value + \",00\";\n" +
    "      }\n" +
    "      if (what == 1) {\n" +
    "        document.forms[0].tmp_add_price.value = document.forms[0].tmp_add_price.value + \",00\";\n" +
    "      }\n" +
    "      if (what == 2) {\n" +
    "        document.forms[0].srv_list_man_price.value = document.forms[0].srv_list_man_price.value + \",00\";\n" +
    "      }\n" +
    "    }\n" +
    "  }\n" +
    "  var curFixprice = parseFloat(opener.parent.job_options.document.tourOptions.jb_fixprice.value.replace(/,/,\".\"));\n" +
    "  if (isNaN(curFixprice))" +
    "    curFixprice = 0;\n" +
    "  if (opener.parent.job_options.document.tourOptions.jb_discount.checked == true) {\n" +
    "    curFixprice = Math.round(curFixprice * (100 - opener.parent.job_options.document.tourOptions.jb_discount_rate.value)) / 100;\n" +
    "  }\n" +
    "  if (what == 0) {\n" +
    "    /* Fuhrlohn darf nicht größer sein als Fixpreis */\n" +
    "    if (curFixprice < parseFloat(document.forms[0].jb_cr_price.value.replace(/,/,\".\"))) {\n " +
    "      alertIsOpen = true;\n" +
    "      alert(\"Frachtvergütung ist größer als Festpreis.\");\n" +
    "      alertIsOpen = false;\n" +
    "      document.forms[0].jb_cr_price.value = \"\";\n" +
    "      document.forms[0].jb_cr_price.focus();\n" +
    "    } else {\n" +
    (MASK_CALC_SIDS == "1"
    ? "      doDeleteAllTmp_add_sids_prices();\n"
    : "") +
    "      /* Warnung, wenn Fuhrlohn größer Fixpreis abzgl. Kundenprovision (wenn vorhanden) */\n" +
    "      if ((jb_cr_price_max > 0) && (jb_cr_price_max < parseFloat(document.forms[0].jb_cr_price.value.replace(/,/,\".\")))) {\n " +
    "        alertIsOpen = true;\n" +
    "        alert(\"Frachtvergütung ist größer als Festpreis abzgl. Kundenprovision (" + formatPrice(String(jb_cr_price_max).replace(/\./,",")) + " EUR).\");\n" +
    "        alertIsOpen = false;\n" +
    "        document.forms[0].jb_cr_price.focus();\n" +
    "      }\n" +
    "    }\n" +
    "  }\n" +
    "  if (what == 1) {\n" +
    "    /* Summe der Unternehmerverrechnungen darf nicht größer sein als Fixpreis */\n" +
    "    var tmp_entry = new Array();\n" +
    "    var sum = 0;\n" +
    "    if (document.forms[0].tmp_add_sids_prices.options[0].text != \"[kein Eintrag]\")\n {" +
    "      for (var i = 0; i < document.forms[0].tmp_add_sids_prices.options.length; i++) {\n" +
    "        tmp_entry = document.forms[0].tmp_add_sids_prices.options[i].text.split(\"(\");\n" +
    "        sum += parseFloat(tmp_entry[1].substr(0, tmp_entry[1].length - 3).replace(/\\s/g,\"\"));\n" +
    "      }\n" +
    "    }\n" +
    "    // Gutschriften berücksichtigen\n" +
    "    tmpThe_price = parseFloat(the_price.replace(/,/,\".\"));\n" +
    "    if (curFixprice < 0) {\n" +
    "      sum *= -1;\n" +
    "      tmpThe_price *= -1;\n" +
    "    }\n" +
//    "alert(curFixprice + \"|\" + sum + \"|\" + tmpThe_price);" +
    "    if (Math.abs(curFixprice) < sum + tmpThe_price) {\n " +
    "      alert(\"Die Summe der Beträge ist größer als der Festpreis.\");\n" +
    "      document.forms[0].tmp_add_price.value = \"\";\n" +
    "      document.forms[0].tmp_add_price.focus();\n" +
    "    } else {\n" +
    "      if (curFixprice < 0 && tmpThe_price < 0) {\n" +
    "        alert(\"Positive Beträge sind bei negativem Festpreis nicht möglich.\");\n" +
    "        document.forms[0].tmp_add_price.value = \"\";\n" +
    "        document.forms[0].tmp_add_price.focus();\n" +
    "      } else {\n" +
    "        if (curFixprice >= 0 && tmpThe_price < 0) {\n" +
    "          alert(\"Negative Beträge sind bei positivem Festpreis nicht möglich.\");\n" +
    "          document.forms[0].tmp_add_price.value = \"\";\n" +
    "          document.forms[0].tmp_add_price.focus();\n" +
    "        }\n" +
    "      }\n" +
    "    }\n" +
    "  }\n" +
    "}\n" +
    "\n" +
    "function checkCr_id_order()\n" +
    "{\n" +
    "  var found = false;\n" +
    "  if (document.forms[0].tmp_add_sid.value != \"\" && opener.cr_id_order_list.length != 0)\n" +
    "  {\n" +
    "    for (var i = 0; i < opener.cr_id_order_list.length; i++)\n" +
    "    {\n" +
    "      if (opener.getCr_id(opener.cr_id_order_list, i).toUpperCase() ==\n" +
    "        document.forms[0].tmp_add_sid.value.toUpperCase())\n" +
    "      {\n" +
    "        document.forms[0].tmp_add_sid.value = opener.getCr_id(opener.cr_id_order_list, i);\n" +
    "        found = true;\n" +
    "        break;\n" +
    "      }\n" +
    "    }\n" +
    "    if (!found)\n" +
    "    {\n" +
    "      alert(\"Die Kuriernummer '\" + document.forms[0].tmp_add_sid.value + \"' ist ungültig.\");\n" +
    "      document.forms[0].tmp_add_sid.value = \"\";\n" +
    "      document.forms[0].tmp_add_sid.focus();\n" +
    "    }\n" +
    "  }\n" +
    "}\n" +
    "\n" +
    "//--" + ">\n" +
    "<\/script>\n" +
    "<\/head>\n" +
    "<body onload=\"doFocus()\"\n>" +
    "  <table border=0 align=center height=100% width=100% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n" +
    "<form>" +
    (MASK_CALCULATOR_TYPE == "1"
    ? "    <tr>\n" +
      "      <td align=left valign=top>\n" +
      "Abrechnungs-Typ:&nbsp;" +
      "  <select name=\"jb_type\" class=\"input\">\n" +
      vht_product_list_str +
      "  </select>\n" +
//    "Auftragsnummer:&nbsp;<input name=\"jb_id_parent\" type=\"text\" value=\"" + jb_id_parent + "\" size=\"8\" maxlength=\"8\" class=\"input\"><br>\n" +
      "      </td>\n" +
      "    </tr>\n"
    : "" ) +
    (MASK_CALC_CR_PRICE == "1"
    ? "    <tr>\n" +
      "      <td align=left valign=top>\n" +
      "Auszuzahlende Frachtvergütung:&nbsp;<input name=\"jb_cr_price\" type=\"text\" value=\"" + jb_cr_price + "\" size=\"8\" maxlength=\"9\" class=\"input\" onchange=\"checkCr_price(0)\">&nbsp;&euro;" +
      cs_provStr +
      "\n<br>" +
      "      </td>\n" +
      "    </tr>\n"
    : "<input type=\"hidden\" name=\"jb_cr_price\" value=\"0\">\n" ) +
    (MASK_CALC_SIDS == "1"
    ? "    <tr>\n" +
      "      <td align=left valign=top>\n" +
      "&nbsp;<br>Weitere Unternehmer" + (MASK_CALC_CR_PRICE == "1" ? "(alternativ zur auszuzahlenden Frachtvergütung)" : "") + ":&nbsp;<br>&nbsp;<br>" +
      "        <table border=0 align=center height=100% width=100% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n" +
      "          <tr>\n" +
    "            <td align=left valign=top width=50%>\n" +
//    "&nbsp;&nbsp;&nbsp;Fahrzeug:<br>\n" +
      "<input type=\"button\" class=\"button_enabled\" name=\"crSidList\" value=\"...\" title=\"Kurierliste (alt+k)\" accesskey=\"k\" onclick=\"opener.mk_cr_id_list('','calculator','')\">&nbsp;" +
      "<input name=\"tmp_add_sid\" type=\"text\" value=\"" + tmp_add_sid_default + "\" size=\"8\" maxlength=\"8\" class=\"input\" onchange=\"checkCr_id_order()\">\n" +
      "&nbsp;<input name=\"tmp_add_price\" type=\"text\" value=\"\" size=\"8\" maxlength=\"8\" class=\"input\">&nbsp;€\n" + 
      "<input type=\"button\" class=\"button_enabled\" value=\"+\" onClick=\"doAddToTmp_add_sids_prices()\" accesskey=\"h\">\n" +
      "            </td>\n" +
      "            <td align=left valign=top width=50%>\n" +
      "  &nbsp;&nbsp;<select name=\"tmp_add_sids_prices\" class=\"input\" size=\"6\" onclick=\doDeleteTmp_add_sids_prices()\>\n" +
      tmp_add_sids_prices_options +
      "  </select>&nbsp;&nbsp;<br>\n" +
      "            </td>\n" +
      "          </tr>\n" +
      "        <\/table>\n" +
      "      </td>\n" +
      "    </tr>\n"
    : "" ) +  
    (MASK_CALCULATOR_SRV == "1"
    ? "    <tr>\n" +
      "      <td align=left valign=top>\n" +
      "&nbsp;<br>Sondervereinbarungen (ändert beim Speichern automatisch den Festpreis):&nbsp;<br>&nbsp;<br>" +
      "        <table border=0 align=center height=100% width=100% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n" +
      "          <tr>\n" +
      "            <td align=left valign=top width=50%>\n" +
      "            </td>\n" +
      "              <select name=\"srv_list\" class=\"input\">\n" +
      srv_list_options +
      "              </select>\n" +
      "              <select name=\"srvt_list\" class=\"input\">\n" +
      srvt_list_options +
      "              </select>\n" +
      "&nbsp;<input name=\"srv_list_mult\" type=\"text\" value=\"\" size=\"3\" maxlength=\"6\" class=\"input\">&nbsp;x\n" + 
      "<input type=\"button\" class=\"button_enabled\" value=\"+\" onClick=\"doAddToTmp_srv(0)\" accesskey=\"s\">\n" +
      "            </td>\n" +
      "          </tr>\n" +
      "          <tr>\n" +
      "            <td align=left valign=top width=50%>\n" +
      "            </td>\n" +
      "<textarea name=\"srv_list_man_text\" cols=\"31\" rows=\"1\" class=\"input\"></textarea>\n" + 
      "&nbsp;<input name=\"srv_list_man_mult\" type=\"text\" value=\"\" size=\"3\" maxlength=\"6\" class=\"input\">&nbsp;x\n" + 
      "&nbsp;<input name=\"srv_list_man_price\" type=\"text\" value=\"\" size=\"6\" maxlength=\"8\" class=\"input\">&nbsp;€\n" +       
      "<input type=\"button\" class=\"button_enabled\" value=\"+\" onClick=\"doAddToTmp_srv(1)\" accesskey=\"m\">\n" +
      "            </td>\n" +
      "          </tr>\n" +
      "          <tr>\n" +
      "            <td align=left valign=top width=50%>\n" +
      "  <select name=\"tmp_srv_list\" class=\"input\" size=\"6\" onclick=\doDeleteTmp_srv_list()\>\n" +
      tmp_srv_srvt_options +
      "  </select>&nbsp;&nbsp;<br>\n" +
      "            </td>\n" +
      "          </tr>\n" +
      "        <\/table>\n" +
      "      </td>\n" +
      "    </tr>\n"
    : "" ) +  
    "</form>\n" +
    "    <tr>\n" +
    "      <td align=center valign=top>\n" +
    "&nbsp;<br>" +
    "<input type=\"button\" class=\"button_enabled\" value=\"Abbrechen\" onClick=\"self.close()\" accesskey=\"a\">&nbsp;\n" +
    "<input type=\"button\" class=\"button_enabled\" value=\"Löschen\" onClick=\"doDelete()\" accesskey=\"l\">&nbsp;\n" +
    "<input type=\"button\" class=\"button_enabled\" value=\"Speichern\" onClick=\"doSave()\" accesskey=\"s\">&nbsp;\n" +
    "      <\/td>\n" +
    "    <\/tr>\n" +
    "  <\/table>\n" +
    "<\/body>\n" +
    "<\/html>\n";
  popupWin1(widthPopupWin, heightPopupWin, leftPopupWin, topPopupWin, popupdata);
};

function searchAddress(side) {
  var customerId = parent.job_options.cs_id_ec;
  var cscIdRoot = csc_id_orderer_root_ec;
  var cscIdActual = csc_id_orderer_ec;
  var f_street;
  var f_hsno;
  var f_zipcode;
  var f_city;
  var f_act = 'search';

  // if (!(f_street == '' AND f_zipcode == '' AND f_city == '')) {f_act = 'search';};
  // if (f_street != '' OR f_zipcode != '' OR f_city != '') {f_act = 'search';};

  if (side == 0)
  {
    f_street = parent.job_tour.document.tourForm.elements[von_fields[jl_ad_street]].value;
    f_hsno = parent.job_tour.document.tourForm.elements[von_fields[jl_tr_hsno]].value;
    f_zipcode = parent.job_tour.document.tourForm.elements[von_fields[jl_ad_zipcode]].value;
    f_city = parent.job_tour.document.tourForm.elements[von_fields[jl_ad_city]].value;
  }

  if (side == 1)
  {
    f_street = parent.job_tour.document.tourForm.elements[nach_fields[jl_ad_street]].value;
    f_hsno = parent.job_tour.document.tourForm.elements[nach_fields[jl_tr_hsno]].value;
    f_zipcode = parent.job_tour.document.tourForm.elements[nach_fields[jl_ad_zipcode]].value;
    f_city = parent.job_tour.document.tourForm.elements[nach_fields[jl_ad_city]].value;
  }

  var widthPopupWin = 800;
  var heightPopupWin = 600;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;

  popupWin = window.open("../admin/ad_list.php?" + "customerId=" + customerId + "&cscIdRoot=" + cscIdRoot + "&cscIdActual=" + cscIdActual + "&f_act=" + f_act + "&f_street=" + myEncodeURI(f_street) + "&f_hsno=" + myEncodeURI(f_hsno) + "&f_zipcode=" + myEncodeURI(f_zipcode) + "&f_city=" + myEncodeURI(f_city) + "&tourno=" + (getCurTourNo() + side), "","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes,resizable=yes,status=no");
};

function myEncodeURI(aString) {
  var aStringNew = "";
  for (i = 0; i < aString.length; i++) {
    aStringNew = aStringNew + '%' + aString.charCodeAt(i).toString(16);
  }
  return aStringNew;
};

function mk_tr_mediationarea_id(side) {
  var widthPopupWin = 400;
  var heightPopupWin = 75;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  var curTourNo = getCurTourNo();

  var tr_mediationarea_id = getJobList(curTourNo + side, jl_tr_mediationarea_id);
  var tr_mediationarea_id_options = ""; /* "<option value=\"\">                         </option>\n"; */
  var cnt = 0;
  for (i = 0; i < fz.length; i++)
  {
    if (fz[i][0] == getJobList(curTourNo + side, jl_ad_zipcode))
    {
      tr_mediationarea_id_options += "<option ";
      if (tr_mediationarea_id == fz[i][2])
        tr_mediationarea_id_options += "selected ";
      tr_mediationarea_id_options += " value=\"" + fz[i][2] + "\">" + fz[i][1] + " (" + fz[i][3] + ")</option>\n";
      cnt++;
    }
  }
  while (cnt-- > 3)
    heightPopupWin += 30;
//isCurrentlySubmitting = false;
  var popupdata =
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" +
    "<html lang=\"de\">\n" +
    "<head>\n" +
    "<title>votian: Eingabe der Abrechnungs-PLZ<\/title>\n" +
    "<link rel=\"stylesheet\" type=\"text/css\" href=\"../css/phoenix.css.php\">\n" +
    "<script type=\"text/javascript\">\n" +
    "<!" + "--\n" +
    "\n" +
    "var side = " + side + ";\n" +
    "\n" +
    "function doFocus(){\n" +
    "  document.forms[0].tr_mediationarea_id.focus();" +
    "}\n" +
    "\n" +
    "function doDelete(){\n" +
    "  document.forms[0].tr_mediationarea_id.value = '';" +
    "  document.forms[0].tr_mediationarea_id.focus();" +
    "}\n" +
    "\n" +
    "function doSave(){\n" +
    "  opener.setJobList(" + curTourNo + " + " + side + ", opener.jl_tr_mediationarea_id, document.forms[0].tr_mediationarea_id.value);\n" +
    "  opener.saveFormFields();\n" +
    "  opener.resetSignificantPriceValues();\n" +
    "  opener.refreshFormFields();\n" +
    "  self.close();\n" +
    "}\n" +
    "\n" +
    "//--" + ">\n" +
    "<\/script>\n" +
    "<\/head>\n" +
    "<body onload=\"doFocus()\"\n>" +
    "  <table border=0 align=center height=100% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n" +
    "    <tr>\n" +
    "      <td align=center valign=top>\n" +
    "<form>" +
//    "<input name=\"tr_mediationarea_id\" type=\"text\" value=\"" + tr_mediationarea_id + "\" size=\"30\" maxlength=\"30\" class=\"input\">" +
    "<select name=\"tr_mediationarea_id\" class=\"input\">" +
    tr_mediationarea_id_options +
    "</select>" +
    "</form>" +
    "<input type=\"button\" class=\"button_enabled\" value=\"Abbrechen\" onClick=\"self.close()\" accesskey=\"a\">&nbsp;" +
    "<input type=\"button\" class=\"button_enabled\" value=\"Löschen\" onClick=\"doDelete()\" accesskey=\"l\">&nbsp;" +
    "<input type=\"button\" class=\"button_enabled\" value=\"Speichern\" onClick=\"doSave()\" accesskey=\"s\">&nbsp;" +
    "      <\/td>\n" +
    "    <\/tr>\n" +
    "  <\/table>\n" +
    "<\/body>\n" +
    "<\/html>\n";
  popupWin1(widthPopupWin, heightPopupWin, leftPopupWin, topPopupWin, popupdata);
};

function mkPriceQuery() {
  var widthPopupWin = 420;
  var heightPopupWin = 330;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  var curTourNo = (getCurTourNo());
  var tr_mediationarea_id;
  var zipcodes = [
    getJobList(0, jl_ad_zipcode),
    getJobList(1, jl_ad_zipcode),
    getJobList(2, jl_ad_zipcode),
    getJobList(3, jl_ad_zipcode),
    getJobList(4, jl_ad_zipcode),
    getJobList(5, jl_ad_zipcode)];

  // aktuelle PLZs sollen übergeben werden;
  // vorher checken, ob Rechnungs-PLZ(s) angegeben ist(sind)!
  for (j = 0; j < 6; j++)
  {
    tr_mediationarea_id = getJobList(j, jl_tr_mediationarea_id);
    if (tr_mediationarea_id != 0)
    {
      for (i = 0; i < fz.length; i++)
      {
        if (fz[i][0] == zipcodes[j])
        {
          if (tr_mediationarea_id == fz[i][2])
            zipcodes[j] = fz[i][1];
        }
      }
    }  
  }

  popupWin = window.open("../jobs/price_query.php?zipcode1=" + zipcodes[0] +
    "&zipcode2=" + zipcodes[1] + "&zipcode3=" + zipcodes[2] + "&zipcode4=" + zipcodes[3] + "&zipcode5=" + zipcodes[4] + 
    "&zipcode6=" + zipcodes[5] + "&vht_id=" + parent.job_options.document.tourOptions.vht_id.value +
    "&jb_markup=" + parent.job_options.document.tourOptions.jb_markup.value + "&job_hq_id=" + hq_id,
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin);
};

/*
 * checkJb_type
 *   params: -
 *   return: -
 *   global: job_options, tourOptions, jb_fixprice
 *
 * Wenn Frühauftrag gewählt, dann keine Vorbestellung/Dauerauftrag
 * Kurier muss angegeben werden (siehe checkSendTour)
 *
 */
/*
function checkJb_type()
{
  var tomorrow = new Date();
  var tomorrowTimestamp;

  if (parent.job_options.document.tourOptions.jb_type.checked)
  {
    parent.job_options.document.tourOptions.jb_globaljob.checked = true;
    // Frühauftrag: Datum auf den nächsten Arbeitstag 08:00 Uhr setzen
    // (Darf kein Samstag, kein Sonntag, kein Feiertag sein)
    do {
      tomorrowTimestamp = tomorrow.getTime() + (1*24*60*60*1000);
      tomorrow.setTime(tomorrowTimestamp);
    } while (tomorrow.getDay() == 6 || tomorrow.getDay() == 0 || isPublicHoliday(tomorrow.getFullYear(), (tomorrow.getMonth() + 1), tomorrow.getDate()));
    setDateTimeFields("job_options", "tourOptions", tomorrow.getDate(), (tomorrow.getMonth() + 1), tomorrow.getFullYear(), "08", "00", "tag", "monat", "jahr", "stunde", "minute", "jb_permanent");
  } else {
    parent.job_options.document.tourOptions.jb_globaljob.checked = false;
    setDateTimeFields("job_options", "tourOptions", "", "", "", "", "", "tag", "monat", "jahr", "stunde", "minute", "jb_permanent");
  }
  checkJb_globaljob();
  checkSendTour();
}
*/
/*
 * checkAccept_all_addresses
 *   params: -
 *   return: -
 *   global: job_options, tourOptions, jb_fixprice
 *
 * Wenn Frühauftrag gewählt, dann keine Vorbestellung/Dauerauftrag
 * Kurier muss angegeben werden (siehe checkSendTour)
 *
 */

function checkAccept_all_addresses()
{
  if (parent.job_tour.document.tourForm.accept_all_addresses.checked)
  {
    parent.job_options.document.tourOptions.accept_all_addresses.value = "1";
  } else {
    parent.job_options.document.tourOptions.accept_all_addresses.value = "";
  }
}


/*
 * checkJb_globaljob
 *   params: -
 *   return: -
 *   global: job_options, tourOptions, jb_fixprice
 *
 * Wenn Frühauftrag gewählt, dann keine Vorbestellung/Dauerauftrag
 * Kurier muss angegeben werden (siehe checkSendTour)
 *
 */

function checkJb_globaljob()
{
  if (parent.job_options.document.tourOptions.jb_globaljob.checked)
  {
    parent.job_options.document.tourOptions.crSidList.disabled = true;
    parent.job_options.document.tourOptions.crSidList.className = "button_disabled";
    parent.job_options.document.tourOptions.cr_id_order.disabled = true;
    parent.job_options.document.tourOptions.cr_id_order.value = "";
    parent.job_options.document.tourOptions.jb_waitstorno.disabled = true;
    parent.job_options.document.tourOptions.jb_waitstorno.checked = false;
    parent.job_options.document.tourOptions.afterwards.checked = false;
    parent.job_options.document.tourOptions.afterwards.disabled = true;
  } else {
    if (jb_id == "") {
      parent.job_options.document.tourOptions.jb_waitstorno.disabled = false;
      parent.job_options.document.tourOptions.crSidList.disabled = false;
      parent.job_options.document.tourOptions.crSidList.className = "button_enabled";
      parent.job_options.document.tourOptions.cr_id_order.disabled = false;
      parent.job_options.document.tourOptions.afterwards.disabled = false;
    }
  }
  checkSendTour();
}

/*
 * checkOffer
 *   params: -
 *   return: -
 *   global: job_options, tourOptions, jb_fixprice
 *
 * Wenn Angebot gewählt, dann kein Dauerauftrag
 *
 */
function checkOffer()
{
  if (typeof (parent.job_options.document.tourOptions.jb_offer) == 'undefined')
    return;

  if (parent.job_options.document.tourOptions.jb_offer.checked)
  {
//    is_offer = true;
    parent.job_options.document.tourOptions.jb_permanent.disabled = true;
//    parent.job_options.document.tourOptions.jb_type.checked = false;
//    parent.job_options.document.tourOptions.jb_type.disabled = true;
    parent.job_options.document.tourOptions.endetag.disabled = true;
    parent.job_options.document.tourOptions.endemonat.disabled = true;
    parent.job_options.document.tourOptions.endejahr.disabled = true;
    checkJb_permanent(0);
//    setSelectedOption("job_options", "tourOptions", "jb_waittime_hour", "");
//    setSelectedOption("job_options", "tourOptions", "jb_waittime_minute", "");
//    parent.job_options.document.tourOptions.jb_waittime_hour.disabled = true;
//    parent.job_options.document.tourOptions.jb_waittime_minute.disabled = true;
    parent.job_options.document.tourOptions.jb_globaljob.checked = false;
    parent.job_options.document.tourOptions.jb_globaljob.disabled = true;
    if (jb_id == "")
      parent.job_options.document.tourOptions.jb_waitstorno.disabled = true;
    if (typeof(parent.job_options.document.tourOptions.jb_status_manual) != 'undefined') {
      parent.job_options.document.tourOptions.jb_status_manual.checked = true;
      parent.job_options.document.tourOptions.jb_status_manual.disabled = true;
    }
    parent.job_options.document.tourOptions.afterwards.checked = false;
    parent.job_options.document.tourOptions.afterwards.disabled = true;
    parent.job_options.document.tourOptions.jb_incomplete.checked = true;
    parent.job_options.document.tourOptions.jb_incomplete.disabled = true;
    parent.job_options.document.tourOptions.jb_insurance.checked = false;
    parent.job_options.document.tourOptions.jb_insurance.disabled = true;
    checkInsurance();
//    parent.job_tour.document.getElementById("div_jb_offer_mail").style.display = 'inline'; *** since 25.02.2026 jb_offer_mail is deactivated until further notice *** 
  } else {
//    is_offer = false;
//    setDateTimeFields("job_options", "tourOptions", "", "", "", "", "", "tag", "monat", "jahr", "stunde", "minute", "jb_permanent");
    parent.job_options.document.tourOptions.jb_permanent.disabled = false;
//    parent.job_options.document.tourOptions.jb_type.disabled = false;
    parent.job_options.document.tourOptions.endetag.disabled = false;
    parent.job_options.document.tourOptions.endemonat.disabled = false;
    parent.job_options.document.tourOptions.endejahr.disabled = false;
    checkJb_permanent(0);
//    parent.job_options.document.tourOptions.jb_waittime_hour.disabled = false;
//    parent.job_options.document.tourOptions.jb_waittime_minute.disabled = false;
    parent.job_options.document.tourOptions.jb_waitstorno.disabled = false;
    if (jb_id == "") {
      parent.job_options.document.tourOptions.afterwards.disabled = false;
    }
    parent.job_options.document.tourOptions.jb_globaljob.disabled = false;
    parent.job_options.document.tourOptions.jb_status_manual.disabled = false;
    if (typeof(parent.job_options.document.tourOptions.jb_status_manual) != 'undefined') {
      if (manual_disposition == "1") {
        parent.job_options.document.tourOptions.jb_status_manual.checked=true;
      } else {
        parent.job_options.document.tourOptions.jb_status_manual.checked=false;
      }
    }
    parent.job_options.document.tourOptions.jb_incomplete.disabled = false;
    parent.job_options.document.tourOptions.jb_incomplete.checked = false;
    parent.job_options.document.tourOptions.jb_insurance.disabled = false;

    parent.job_tour.document.tourForm.jb_offer_mail.value = "";
    parent.job_options.document.tourOptions.jb_offer_mail_hidden.value = "";
    parent.job_tour.document.getElementById("div_jb_offer_mail").style.display = 'none';
  }
  checkSendTour();
}

/*
 * checkAfterwards
 *   params: -
 *   return: -
 *   global: job_options, tourOptions, jb_fixprice
 *
 * Wenn Nacherfassung gewählt, dann keine Vorbestellung/Dauerauftrag
 * Kurier muss angegeben werden (siehe checkSendTour)
 *
 */
function checkAfterwards()
{
  if (typeof (parent.job_options.document.tourOptions.afterwards) == 'undefined')
    return;

  // Eine Änderung darf niemals Nacherfasung sein!!!  
  if (parent.job_options.document.tourOptions.jb_id.value != "" && parent.job_options.document.tourOptions.jb_id.value != "____")
    parent.job_options.document.tourOptions.afterwards.checked = false;

  if (parent.job_options.document.tourOptions.afterwards.checked)
  {
    var now = new Date();
    setDateTimeFields("job_options", "tourOptions", now.getDate(), (now.getMonth() + 1), now.getFullYear(), now.getHours(), now.getMinutes(), "tag", "monat", "jahr", "stunde", "minute", "jb_permanent");
    is_afterwards = true;
    parent.job_options.document.tourOptions.jb_permanent.disabled = true;
//    parent.job_options.document.tourOptions.jb_type.checked = false;
//    parent.job_options.document.tourOptions.jb_type.disabled = true;
    setDateTimeFields("job_options", "tourOptions", "", "", "", "", "", "endetag", "endemonat", "endejahr", "", "", "");
    if (empModeLaterJob == "1")
      setDateTimeFields("job_options", "tourOptions", "", "", "", "", "", "tag", "monat", "jahr", "stunde", "minute", "jb_permanent");
    parent.job_options.document.tourOptions.endetag.disabled = true;
    parent.job_options.document.tourOptions.endemonat.disabled = true;
    parent.job_options.document.tourOptions.endejahr.disabled = true;
    checkJb_permanent(0);
//    setSelectedOption("job_options", "tourOptions", "jb_waittime_hour", "");
//    setSelectedOption("job_options", "tourOptions", "jb_waittime_minute", "");
//    parent.job_options.document.tourOptions.jb_waittime_hour.disabled = true;
//    parent.job_options.document.tourOptions.jb_waittime_minute.disabled = true;
    parent.job_options.document.tourOptions.jb_globaljob.disabled = true;
    if (jb_id == "")
      parent.job_options.document.tourOptions.jb_waitstorno.disabled = true;
    parent.job_options.document.tourOptions.jb_status_manual.disabled = true;
    parent.job_options.document.tourOptions.jb_status_manual.checked = false;
    parent.job_options.document.tourOptions.jb_offer.disabled = true;
    parent.job_options.document.getElementById("div_jb_km").style.display = "inline"; 
    parent.job_options.document.getElementById("div_jb_bwv").style.display = "inline";
    alert("Bitte setzen Sie unbedingt das Häkchen unten rechts bei \"BWV-Auftrag\", falls es sich bei dem Originalauftrag um einen solchen handelt. Nur so kann die Gutschrift ordnungsgemäß verbucht werden.");
  } else {
    is_afterwards = false;
//    setDateTimeFields("job_options", "tourOptions", "", "", "", "", "", "tag", "monat", "jahr", "stunde", "minute", "jb_permanent");
    parent.job_options.document.tourOptions.jb_permanent.disabled = false;
//    parent.job_options.document.tourOptions.jb_type.disabled = false;
    parent.job_options.document.tourOptions.endetag.disabled = false;
    parent.job_options.document.tourOptions.endemonat.disabled = false;
    parent.job_options.document.tourOptions.endejahr.disabled = false;
    checkJb_permanent(0);
//    parent.job_options.document.tourOptions.jb_waittime_hour.disabled = false;
//    parent.job_options.document.tourOptions.jb_waittime_minute.disabled = false;
    if (jb_id == "")
      parent.job_options.document.tourOptions.jb_waitstorno.disabled = false;
    // Auftragsänderung
    if (parent.job_options.document.tourOptions.jb_id.value != "" && parent.job_options.document.tourOptions.jb_id.value != "____")
    {
      parent.job_options.document.tourOptions.afterwards.disabled = true;
// ACHTUNG: Damit der Rest freigeschaltet werden kann, fehlt noch die Berücksichtigung des Status!!!
//      parent.job_options.document.tourOptions.jb_globaljob.disabled = true;
//      parent.job_options.document.tourOptions.jb_globaljob.checked = false;
//      parent.job_options.document.tourOptions.jb_status_manual.disabled = true;
//      parent.job_options.document.tourOptions.jb_status_manual.checked = false;
    }
    else
    {
      parent.job_options.document.tourOptions.afterwards.disabled = false;
      parent.job_options.document.tourOptions.jb_globaljob.disabled = false;
      parent.job_options.document.tourOptions.jb_status_manual.disabled = false;
      if (manual_disposition == "1" && typeof(parent.job_options.document.tourOptions.jb_status_manual) != 'undefined') {
        parent.job_options.document.tourOptions.jb_status_manual.checked=true;
      }      
      parent.job_options.document.tourOptions.jb_offer.disabled = false;
    }
    // Unternehmerverteilung im Calculator löschen!
    // (Nur wenn Status nicht erledigt; ansonsten werden beim Laden des Auftrages im Buchhaltungsmodus die korrekten Daten eliminiert)
    if (parent.job_options.cur_jb_status != 2) {
      parent.job_options.document.tourOptions.tmp_add_sids.value = "";
      parent.job_options.document.tourOptions.tmp_add_prices.value = "";
      checkCalculator();
    }
    if (cur_jb_status != 2)
      parent.job_options.document.getElementById("div_jb_km").style.display = "none"; 
    parent.job_options.document.getElementById("div_jb_bwv").style.display = "none";
    parent.job_options.document.tourOptions.jb_bwv.checked = false;
  }
  checkSendTour();
}

function checkIncomplete() {
  if (!parent.job_options.document.tourOptions.jb_incomplete.checked && jb_id != "" && !is_eu_only)
    alert("Liegt bei diesem Drittlandtransport die schriftliche Bestätigung des Versenders über seinen Status vor und wurde gemäß Handlungsanweisung Drittland die Umsatzsteuerpflicht des Transports geklärt?");
}

/*
 * checkJb_tourname
 *   params: -
 *   return: -
 *
 * Die Liste der Tournamen ("Tourkonserven") ist abhängig vom aktuellen csc_id_payer;
 * beim Abrufen dieser Liste muss also dafür gesorgt werden, dass aktuelle Daten vorhanden sind
 */

function checkJb_tourname()
{
  var tempWin;
  var csc_id_payer = "";

//  // csc_id_payer finden, wenn irgendwo in der Tourliste angekreuzt
//  for (var j = 0; j < (maxTour + 1); j++) {
////alert (j + ": " + getJobList(j, jl_csc_id_payer));
//    if (getJobList(j, jl_csc_id_payer) == "true")
//      csc_id_payer = getJobList(j, jl_csc_id);
//  }
//  // wenn nicht gefunden, dann nachschauen, ob csc_id_payer als Drittzahler vorhanden
//  if (csc_id_payer == "")
//    csc_id_payer = parent.job_options.document.tourOptions.csc_id_payer.value;
//alert ("csc_id_payer: " + csc_id_payer);
  // Wenn ein neuer Bezahler gesetzt wurde, muss die Liste der gespeicherten Touren aktualisiert werden

  // Bestehende Liste löschen; nur der erste, leere Eintrag bleibt bestehen
  while (parent.job_options.document.tourOptions.savedTour.length > 1)
  {
    parent.job_options.document.tourOptions.savedTour.options[
      parent.job_options.document.tourOptions.savedTour.length - 1] = null;
  };
  if (curCsc_id_payer != "")
  {
    tempWin = mkPopupWin(
      "function startReload()\n" +
      "{\n" +
      "  checkDone();\n" +
      "  self.location.href=\"../jobs/get_tournames.php?csc_id=" +
         curCsc_id_payer + "\";\n" +
      "}\n" +
      "\n" +
      "//--" + ">\n" +
      "<\/script>\n" +
      "<\/head>\n" +
      "<body onLoad=\"startReload()\">\n" +
      "  <table border=0 align=center height=100% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n" +
      "    <tr>\n" +
      "      <td align=center valign=center>\n" +
      "        <b>Hole Daten...</b>\n" +
      "      <\/td>\n" +
      "    <\/tr>\n" +
      "  <\/table>\n" +
      "<\/body>\n" +
      "<\/html>\n", 0, 0);
  }
}

// wg. einem f***ing IE Bug muss das Update der Liste der gespeicherten Touren über einen Umweg erfolgen
var savedTour_options;
function checkJb_tourname_workaround()
{
  var savedTour_options_arr = savedTour_options.split("\t");
  var numIdx = getNumIndex("job_options", "tourOptions", "savedTour");
  var j = 0;
  for (var i = 0; i < savedTour_options_arr.length; i+=2)
  {
    parent.frames[numIdx[0]].document.forms[numIdx[1]].elements[numIdx[2]].options[j++ + 1] =
      new Option(savedTour_options_arr[i], savedTour_options_arr[i + 1], false, false);
  }
  savedTour_options = "";
}
//    "opener.parent.job_options.document.tourOptions.savedTour.options[" .
//    "  opener.parent.job_options.document.tourOptions.savedTour.options.length] = newOption".$row['jb_id'].";\n";

// 22.10.2025: Fix zu #1242 (Konserven werden nicht angezeigt) wg. Firefox-Version 144.0 
function force_rerender() {
  var element = parent.job_options.document.querySelector("select[name='savedTour']"); 
  
  if (element) {
    let old_display = element.style.display;
    // Ein klassischer "Trick", um einen Reflow zu erzwingen:
    // Element kurz ausblenden und sofort wieder einblenden.
    element.style.display = 'none';
    // Diese Zeile liest eine Eigenschaft, was den Browser zur Berechnung zwingt
    void element.offsetWidth; 
    element.style.display = old_display; // Zurück zum Standard (z.B. 'block' oder 'inline-block')
  }
}

/*
 * checkJob
 *   params: -
 *   return: -
 *   global: job_tour, tour, von_csc_id, job_options, tourOptions, savedTour, jb_tourname,
 *     job_tour_list, isCurrentlySubmitting, alertIsOpen
 *
 * Job vor dem Senden prüfen, Aufruf durch Attribut 'onsubmit=' im submit-Formularfeld.
 * Wenn alles ok, dann wird 'true' zurückgeliefert, die Daten werden gesandt, sonst 'false'.
 * Die globale Variable 'isCurrentlySubmitting' wird auf true gesetzt, bis job_options durch
 * die Serverantwort verändert wurde (wird alle 100 Millisekunden überprüft). Ein mehr-
 * faches Absenden wird somit verhindert. Wenn nach einer Minute noch keine Serverantwort
 * erfolgt ist, wird das Popup-Fenster geschlossen und 'isCurrentlySubmitting' auf 'false'
 * gesetzt.
 */
var setDistancepriceSubmit = false;
function checkJob()
{
  var curTourNo = getCurTourNo();
  var tempWin;

//alert (parent.job_options.document.tourOptions.jb_waitstorno.checked);
//alert (parent.job_options.document.tourOptions.jb_waitstorno.value);
//alert (parent.job_options.document.tourOptions.afterwards.value);

  if (parent.job_options.isCurrentlySubmitting || alertIsOpen)
    return false;

  if (get_cs_invmode(curCsc_id_payer) == 0 && trim(parent.job_options.document.tourOptions.jb_fixprice.value) == "") {
    openDistanceprice("zone");
    const myDiv = parent.job_tour.document.getElementById('div_zoneprice');
    const link = myDiv.querySelector('a');
    setDistancepriceSubmit = true;
    link.click();
    return false;
  }

//  if (parent.job_options.document.tourOptions.jb_weight.value == "")
//  {
//    alert("Das Maximalgewicht eines Transportgutes muss angegeben werden " +
//      "(wenn unerheblich, dann '0' eintragen)!");
//    return false;
//  }
  if (optionTextExists("job_options", "tourOptions", "savedTour",
    parent.job_options.document.tourOptions.jb_tourname.value) &&
    parent.job_options.document.tourOptions.jb_tourname.value != "")
    if (!confirm("Wollen Sie den gespeicherten Auftrag wirklich überschreiben?\n" +
      "\n(Wenn nein, dann ändern Sie bitte vor dem nächsten \n" +
      "Senden den Wert \"" +
      parent.job_options.document.tourOptions.jb_tourname.value +
      "\" im Feld \"Tourname\"!)"))
      return false;

  if ((getJobList(i, jl_tr_commission_no)).replace(/\s/,"") == get_cs_comm_prefix(curCsc_id_payer))
    setJobList(i, jl_tr_commission_no, "");
  if (delete_suborder && parent.job_options.document.tourOptions.tmp_add_jb_ids.value != "") {
    var tmp_add_sidsArr = parent.job_options.document.tourOptions.tmp_add_sids.value.split("¹");
    // Fahrer auf den echten zurücksetzen 
    parent.job_options.document.tourOptions.cr_id_order.value = tmp_add_sidsArr[0];
    parent.job_options.document.tourOptions.cr_id_order_hidden.value = "";
//alert(parent.job_options.document.tourOptions.cr_id_order.value);
    // Unteraufträge im Calculator löschen
//    parent.job_options.document.tourOptions.tmp_add_jb_ids.value = "";
    parent.job_options.document.tourOptions.tmp_add_sids.value = "";
    parent.job_options.document.tourOptions.tmp_add_prices.value = "";
//alert(parent.job_options.document.tourOptions.tmp_add_sids.value);
    parent.job_options.document.tourOptions.do_delete_suborder.value = "1";
  }

  // Prüfen, ob Mail versandt werden soll
  if (parent.job_options.document.tourOptions.ask_mailrecipients.value == "1")
    parent.job_options.document.tourOptions.ask_mailrecipients.value = get_cs_ask_mailrecipients(curCsc_id_payer);
  if (parent.job_options.document.tourOptions.ask_mailrecipients.value != "" || parent.job_options.document.tourOptions.jb_offer_mail_hidden.value != "") {
//      alert("|" + jobList_ori + "|~~~|" + parent.job_options.document.tourOptions.jobList.value + "|\n\n"
//      + "|" + jb_fixprice_ori + "|~~~|" + parent.job_options.document.tourOptions.jb_fixprice.value + "|\n\n"
//      + "|" + jb_serviceprice_ori + "|~~~|" + parent.job_options.document.tourOptions.jb_serviceprice.value + "|\n\n"
//      + "|" + jb_ordertime_ori + "|~~~|" + parent.job_options.document.tourOptions.jahr.value.toString() + "-" + parent.job_options.document.tourOptions.monat.value.toString() + "-" + parent.job_options.document.tourOptions.tag.value.toString()
//        + " " + parent.job_options.document.tourOptions.stunde.value.toString() + ":" + parent.job_options.document.tourOptions.minute.value.toString() + "|\n\n"
//      + "|" + curCsc_id_payer_ori + "|~~~|" + curCsc_id_payer + "|\n");

    if (jobList_ori != parent.job_options.document.tourOptions.jobList.value
      || jb_fixprice_ori != parent.job_options.document.tourOptions.jb_fixprice.value
      || jb_serviceprice_ori != parent.job_options.document.tourOptions.jb_serviceprice.value
      || jb_markup_ori != parent.job_options.document.tourOptions.jb_markup.value
      || jb_ordertime_ori != parent.job_options.document.tourOptions.jahr.value.toString() + "-" + parent.job_options.document.tourOptions.monat.value.toString() + "-" + parent.job_options.document.tourOptions.tag.value.toString()
        + " " + parent.job_options.document.tourOptions.stunde.value.toString() + ":" + parent.job_options.document.tourOptions.minute.value.toString()
      || curCsc_id_payer_ori != curCsc_id_payer)
      if (typeof(parent.job_options.document.tourOptions.jb_offer) == 'undefined' || !parent.job_options.document.tourOptions.jb_offer.checked) {
        if (parent.job_options.document.tourOptions.ask_mailrecipients.value != "" && confirm("Soll eine Auftragsmail an \"" + parent.job_options.document.tourOptions.ask_mailrecipients.value + "\" versandt werden?"))
          parent.job_options.document.tourOptions.sendmail.value = "1";
//      } else { // *** since 25.02.2026 jb_offer_mail is deactivated until further notice *** 
//        if (parent.job_options.document.tourOptions.jb_offer_mail_hidden.value != "" && confirm("Soll eine Angebotsmail an \"" + parent.job_options.document.tourOptions.jb_offer_mail_hidden.value + "\" versandt werden?"))
//          parent.job_options.document.tourOptions.sendmail.value = "1";
      }
  }

  if (jb_id != "" && typeof(parent.job_options.document.tourOptions.jb_permanent) != 'undefined') {
    if (getSelectedVal("job_options", "tourOptions", "jb_permanent") != "" && parent.job_options.document.tourOptions.jb_id_permanent_pre.value != "") {
      if (confirm("Wollen Sie die Änderung des Dauerauftrags dauerhaft übernehmen?\n")) {
      	// Änderung ist dauerhaft
      	parent.job_options.document.tourOptions.jb_id_permanent_pre.value = "";
      }
    }
  }

  if (trim(parent.job_tour.document.tourForm.jb_orderer.value) == "" && jb_orderer_mandatory) {
    alert("Bitte den Besteller eintragen!")
    parent.job_tour.document.tourForm.jb_orderer.focus();
    return false;
  }

  tempWin=mkPopupWin(
    "//--" + ">\n" +
    "<\/script>\n" +
    "<\/head>\n" +
//    "<body onLoad=\"checkDone()\">\n" +
    "<body onLoad=\"self.setTimeout('checkDone()',100)\">\n" +
    "  <table border=0 align=center height=100% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n" +
    "    <tr>\n" +
    "      <td align=center valign=center>\n" +
    "        <b>Sende Auftrag...</b>\n" +
    "      <\/td>\n" +
    "    <\/tr>\n" +
    "  <\/table>\n" +
    "<\/body>\n" +
    "<\/html>\n", 0, 0);
  return true;
}

/*
 * getSavedTour
 *   params: -
 *   return: -
 *   global: isCurrentlySubmitting, job_options, tourOptions, savedTour,
 *     jl_csc_id
 *
 * Die ausgewählte Tour wird vom Server geholt
 */

function getSavedTour(jb_id, jb_copy, dbhistory, no_dates)
{
  var tempWin;
  var cr_sid_none = "";

  // Zuschlag darf bei einem zu ladenden Auftrag natürlich nicht mehr automatisch überschrieben werden!
  jb_markup_overwrite = 1;
  jb_cr_markup_overwrite = 0;
  if (is_b2b == "1" && vht_id_old == "0")
    jb_cr_markup_overwrite = 1;

  if (jb_copy == "")
    jb_copy = false;
  if (jb_id == 0)
  {
    if (parent.job_options.isCurrentlySubmitting)
      return;
    if (typeof (parent.job_header.job_header_isLoading) == 'undefined' || parent.job_header.job_header_isLoading == true ||
        typeof (parent.job_tour.job_tour_isLoading) == 'undefined' || parent.job_tour.job_tour_isLoading == true ||
       typeof (parent.job_options.job_options_isLoading) == 'undefined' || parent.job_options.job_options_isLoading == true)
    {
      self.setTimeout('getSavedTour(' + jb_id + ',' + jb_copy + ',' + dbhistory + "," + no_dates + ')', 100);
      return;
    }
    if (getSelectedVal("job_options", "tourOptions", "savedTour") == 0)
      return;
    if (getJobList(0, jl_csc_id) != "")
    {
      if (confirm(
        "Beim Laden einer gespeicherten Tour werden die bereits\n" +
        "erfassten Daten gelöscht. Wollen Sie das wirklich?") == false)
      {
        parent.job_options.document.tourOptions.savedTour.value = "";
        return;
      }
      // Normalerweise wird beim Laden eines Auftrages der im Auftrag gespeicherte Wert für den Treibstoffzuschlag genommen;
      // damit aber auch alte Tourkonserven mit den neuen Treibstoffzuschlägen ausgestattet werden, dafür sorgt der folgende
      // Parameter
      jb_markup_overwrite = 1;
      jb_cr_markup_overwrite = 1;
      // 23.01.2024: Manuelle TSZs immer löschen
      parent.job_options.document.tourOptions.jb_markup.value = "";
      parent.job_options.document.tourOptions.jb_cr_markup.value = "";
      parent.job_options.document.tourOptions.jb_id_org.value = getSelectedVal("job_options", "tourOptions", "savedTour");
    }
    jb_id = getSelectedVal("job_options", "tourOptions", "savedTour");
    cr_sid_none = "&cr_sid=none&consider_manual_disp=1";
    // Achtung: im Änderungsmodus sollen nur die Inhalte geändert werden, ...
    // ... nicht die Job-ID (also kein neuer Auftrag)
//    parent.frames[0].location.href="job_header.php?csc_id_orderer=" + csc_id_orderer_ec + "&what_is_this=Auftragserfassung";
//    parent.job_options.document.tourOptions.jb_id.value = "";
//    parent.job_options.document.tourOptions.afterwards.disabled = false;
//    if (empModeLaterJob == "1")
//      parent.job_options.document.tourOptions.afterwards.checked = true;    
  }
  is_non_eu_notified = true;
  tempWin = mkPopupWin(
    "function startReload()\n" +
    "{\n" +
    "  checkDone();\n" +
    "  self.location.href=\"get_saved_tour.php?jb_id=" +
       jb_id + cr_sid_none + "&jb_copy=" + jb_copy + "&dbhistory=" + dbhistory + "&no_dates=" + no_dates + "\";\n" +
    "}\n" +
    "\n" +
    "//--" + ">\n" +
    "<\/script>\n" +
    "<\/head>\n" +
    "<body onLoad=\"startReload()\">\n" +
    "  <table border=0 align=center height=100% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n" +
    "    <tr>\n" +
    "      <td align=center valign=center>\n" +
    "        <b>Hole Daten...</b>\n" +
    "      <\/td>\n" +
    "    <\/tr>\n" +
    "  <\/table>\n" +
    "<\/body>\n" +
    "<\/html>\n", 0, 0);
}

/*
 * getStartAddress
 *   params: -
 *   return: -
 *
 * Die ausgewählte Kostenstelle wird vom Server geholt
 */

function getStartAddress(csc_id_start)
{
  var tempWin;

  if (parent.job_options.isCurrentlySubmitting)
    return;
  if (typeof (parent.job_header.job_header_isLoading) == 'undefined' || parent.job_header.job_header_isLoading == true ||
      typeof (parent.job_tour.job_tour_isLoading) == 'undefined' || parent.job_tour.job_tour_isLoading == true ||
     typeof (parent.job_options.job_options_isLoading) == 'undefined' || parent.job_options.job_options_isLoading == true)
  {
    self.setTimeout('getStartAdress(' + csc_id_start + ')', 100);
    return;
  }
  tempWin = mkPopupWin(
    "function startReload()\n" +
    "{\n" +
    "  checkDone();\n" +
    "  self.location.href=\"../admin/cs_csc_list.php?csc_id_start=" + csc_id_start + "\";\n" +
    "}\n" +
    "\n" +
    "//--" + ">\n" +
    "<\/script>\n" +
    "<\/head>\n" +
    "<body onLoad=\"startReload()\">\n" +
    "  <table border=0 align=center height=100% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n" +
    "    <tr>\n" +
    "      <td align=center valign=center>\n" +
    "        <b>Hole Daten...</b>\n" +
    "      <\/td>\n" +
    "    <\/tr>\n" +
    "  <\/table>\n" +
    "<\/body>\n" +
    "<\/html>\n", 0, 0);
}

function popupWin1(widthPopupWin, heightPopupWin, leftPopupWin, topPopupWin, popupdata)
{
  popupWin=window.open("about:blank", "",
    "dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +
    ",left=" + leftPopupWin + ",top=" + topPopupWin);
//  if (navigator.userAgent.indexOf("Firefox") == -1) {
    popupWin.document.open();
    popupWin.document.write(popupdata);
    popupWin.document.close();
//  } else {
//// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding#Solution_.232_.E2.80.93_rewriting_atob%28%29_and_btoa%28%29_using_TypedArrays_and_UTF-8
//    var url = "javascript:(function(){var html = '" + btoa(encodeURIComponent( escape( popupdata )))
//                 +"';document.open();document.write(unescape(decodeURIComponent(window.atob( html ))));document.close();})();";
//    popupWin.location.href=url;
//  }
}

/*--------------------------------------------------------------------------------
 * calendarFunc: Wird vom Kalender (durch calendarMonthInit initialisert) aufgerufen,
 * siehe ../include/lib_calendar.js
 */

function calendarFunc(year, month, day) {
  parent.job_options.document.tourOptions.jahr.value = year;
  parent.job_options.document.tourOptions.monat.value = month;  
  parent.job_options.document.tourOptions.tag.value = day;
  calendarClose('appointment');
  $('#dateselect').show();
  fillDateFields(0, 'job_options', 'tourOptions', 'tag', 'tag', 'monat', 'jahr', 'stunde', 'minute', 'jb_permanent');
}

function openCalendar() {
  $('#dateselect').hide();

  ye = parent.job_options.document.tourOptions.jahr.value;
  if (trim(ye) == "")
    ye = "0";
  mo = parent.job_options.document.tourOptions.monat.value;
  if (trim(mo) == "")
    mo = "0";
  calendarMonthInit('appointment', parseInt(ye), parseInt(mo), true);
}

function calendarCloseFunc() {
  $('#dateselect').show();
  calendarClose('appointment');
}

function openDistanceprice(m) {
  if (typeof (m) != 'undefined' && m == "zone") {
    parent.job_tour.$('#div_zoneprice').hide();
    parent.job_tour.$('#div_zoneprice').html("&nbsp;Strecke wird ermittelt...");
    parent.job_tour.$('#div_zoneprice').show();
  } else {
    if (!(typeof (m) != 'undefined' && m == "optimize"))
      parent.job_tour.$('#div_distanceprice').html("&nbsp;Entfernung wird ermittelt...");
  }
  setTimeout(openDistancepriceDoit(m), 0);
}

// https://stackoverflow.com/questions/13484496/how-can-i-get-an-elements-innerhtml-to-update-immediately
function openDistancepriceDoit(m) {

  var mode = "km";
  var div_name = '#div_distanceprice';
  let modeAdd = "";

  if (typeof (m) != 'undefined' && m == "zone") {
    mode = "zone";
    div_name = '#div_zoneprice';
  }

  if (typeof (m) != 'undefined' && m == "optimize") {
    mode = "optimize";
    if (!parent.job_tour.document.tourForm.dont_optimize_last.checked)
      modeAdd = "All";
  }

  var ajaxParms = "";

  var cur_jb_markup = parseFloat(parent.job_options.document.tourOptions.jb_markup.value.replace(/,/,"."));
  if (MASK_CR_PRICE_MODE == "1") {
    cur_jb_markup = parseFloat(parent.job_options.document.tourOptions.currentTSZ.value.substr(0, parent.job_options.document.tourOptions.currentTSZ.value.length - 2).replace(/,/,"."));
    if (trim(parent.job_options.document.tourOptions.jb_markup.value) != "")
      cur_jb_markup = parseFloat(parent.job_options.document.tourOptions.jb_markup.value.replace(/,/,"."));
//    var cur_jb_cr_markup = parseFloat(parent.job_options.document.tourOptions.currentCrTSZ.value.substr(0, parent.job_options.document.tourOptions.currentCrTSZ.value.length - 2).replace(/,/,"."));
//    if (trim(parent.job_options.document.tourOptions.jb_cr_markup.value) != "")
//      cur_jb_cr_markup = parseFloat(parent.job_options.document.tourOptions.jb_cr_markup.value.replace(/,/,"."));
  }

  var i = 0;
  while (checkTourComplete(i))
  {
    if (ajaxParms != "")
      ajaxParms += "|";
    ajaxParms += getJobList(i, jl_ad_street) + ";" + getJobList(i, jl_tr_hsno) + ";" + getJobList(i, jl_ad_zipcode) + ";" + getJobList(i, jl_ad_city) + ";" + getJobList(i, jl_ad_country);    
    if (i++ >= maxTour)
      break;
  }
  let cntTour = i;
  
  var jb_ordertime = "";
  if (trim(parent.job_options.document.tourOptions.tag.value) != "")
//  if(!isNaN(new Date(parent.job_options.document.tourOptions.jahr.value, parent.job_options.document.tourOptions.monat.value - 1, parent.job_options.document.tourOptions.tag.value,
//    parent.job_options.document.tourOptions.stunde.value, parent.job_options.document.tourOptions.minute.value)))
    jb_ordertime = parent.job_options.document.tourOptions.jahr.value.toString() + "-" + parent.job_options.document.tourOptions.monat.value.toString() + "-" + parent.job_options.document.tourOptions.tag.value.toString()
      + "%20" + parent.job_options.document.tourOptions.stunde.value.toString() + ":" + parent.job_options.document.tourOptions.minute.value.toString() + ":00";
//alert(isNaN(new Date(parent.job_options.document.tourOptions.jahr.value, parent.job_options.document.tourOptions.monat.value - 1, parent.job_options.document.tourOptions.tag.value,
//    parent.job_options.document.tourOptions.stunde.value, parent.job_options.document.tourOptions.minute.value)) + "|" +
//jb_ordertime);
  ajaxParms = "hq_id=" + hq_id + '&cs_id=' + get_cs_id(curCsc_id_payer) + "&vht_id=" + parent.job_options.document.tourOptions.vht_id.value +
    "&jb_markup=" + cur_jb_markup + '&jb_ordertime=' + jb_ordertime + "&mode=" + mode + modeAdd + "&jb_id=" + jb_id + "&usr_id=" + usr_id + "&a=" + ajaxParms;
//alert(ajaxParms);
  ajaxRequestGet('../include/ajaxReqKmPrice.php', ajaxParms);

  if (retValue[0] != "ERROR" && mode != "optimize") {
    let duration = "";
    if (mode == "zone") {
      let parts = trim(retValue[9]).split(":");
//      duration = (parts[0] != 0 ? parts[0] + " Stunde" + (parts[0] > 1 ? "n" : "") + " " : "") + parts[1] + " Minute" + (parts[1] > 1 ? "n" : "");
      duration = "<br>Reine Fahrtzeit für den Transport (ohne Beachtung von Anfahrt und Verkehr) ca. " + (parts[0] != 0 ? parts[0] + "h " : "") + parts[1] + "m";
    }
    parent.job_tour.$(div_name).html("&nbsp;" + 
     "<a href=\"javascript:parent.job_options.setDistanceprice('" + retValue[5] + "', '" + retValue[6] + "', '" + retValue[2] + "|" + retValue[3] + "|" + retValue[4] + "|" + retValue[7] + "|" + retValue[8] + "|" + retValue[10] + "')\">" + retValue[0] + "<\/a>" +
     " (<a href=\"" + (mode != "zone" ? "https://www.google.de/maps/dir" + unescape(retValue[1]) : "../locating/map_pzm.php?p=" + encodeURI(retValue[1])) +
       "\" target=\"_blank\">" + retValue[2] + "</a> " + (mode != "zone" ? "* " : "") + retValue[3] + retValue[4] + ")" + duration);
    // retValue[2] = $total_km, retValue[3] = $price_per_km, retValue[4] = $basic_price
    if (MASK_HIDE_STANDARD_PRICE_IF_KM_PRICE == "1") {
      parent.job_tour.document.tourForm.currentPrice.style.visibility = "hidden";
      parent.job_tour.document.tourForm.currentCrPrice.style.visibility = "hidden";
    }
  } else {
    if (retValue[0] != "ERROR" && mode == "optimize") {
      let tourChanged = false;
      for (let i = 0; i < retValue[2].length; i++) {
        if (retValue[2][i] != i) {
          tourChanged = true;
        }
      }
      if (tourChanged) {
        if (confirm("Die Optimierung erbrachte eine Verbesserung von " + retValue[0].toString().replace(/\./,",") + " km auf " + retValue[1].toString().replace(/\./,",") + " km. Soll die verbesserte Tour übernommen werden?")) {
          let tmpJobList = new Array(cntTour);
          let tmpJobListJoin = parent.job_options.document.tourOptions.jobList.value.split("¹");
          for (let i = 1; i < cntTour; i++) {
            tmpJobList[i] = tmpJobListJoin[i];
          }
//console.log(tmpJobList);
          for (let i = 0; i < retValue[2].length; i++) {
            tmpJobListJoin[i + 1] = tmpJobList[retValue[2][i] + 1];
          }
          parent.job_options.document.tourOptions.jobList.value = tmpJobListJoin.join("¹");
//console.log(parent.job_options.document.tourOptions.jobList.value);
          has_just_been_optimized = true;
          significantOptimizationValues = "";
          refreshFormFields();
        }
      } else {
      	alert("Die Optimierung erbrachte keine Verbesserung, die Tour ist bereits optimal.");
        has_just_been_optimized = true;
        significantOptimizationValues = "";
        // refreshFormFields only to switch off Optimize-Button and save the optimzed adresses
        refreshFormFields();
      }
//console.log("openDistancepriceDoit: " + is_optimized);
    } else {
//console.log("retValue: " + retValue);
      if (retValue[0] == "ERROR" && mode == "optimize")
        alert("Es ist ein unbestimmter Fehler aufgetreten." + (mode == "optimize" ? " Optimierung nicht möglich." : ""));
      parent.job_tour.$(div_name).html("&nbsp;" + retValue[1]);
    }
  }
}

function setDistanceprice(priceStr, crPriceStr, km_price_params) {
  var addConfirmStr = "";
  if (setDistancepriceSubmit)
    addConfirmStr = " und Auftrag absenden";
  if (confirm(priceStr + " als Festpreis übernehmen" + addConfirmStr + "?\n" /*+ km_price_params*/)) {
    parent.job_options.document.tourOptions.jb_fixprice.value = priceStr;
    if (MASK_CR_PRICE_MODE == "1")
      parent.job_options.document.tourOptions.jb_cr_price.value = crPriceStr;
    parent.job_options.document.tourOptions.km_price_params.value = km_price_params;
    checkFixprice(1);
    if (setDistancepriceSubmit)
      parent.job_options.document.tourOptions.toursubmit.click();
  }
  setDistancepriceSubmit = false;
}

function check_tr_person(csc_id, side) {
  if (side == 0) {
  	var tmp_length = parent.job_tour.document.tourForm.select_von_tr_person.options.length;  	
    for (var j = tmp_length - 1; j >= 0; j--) {
      parent.job_tour.document.tourForm.select_von_tr_person.options[j] = null;
    }
    parent.job_tour.document.tourForm.select_von_tr_person.style.display = "none";
    parent.job_tour.document.tourForm.von_tr_person.size = "20";
  }
  if (side == 1) {
  	var tmp_length = parent.job_tour.document.tourForm.select_nach_tr_person.options.length;
    for (var j = tmp_length - 1; j >= 0; j--) {
      parent.job_tour.document.tourForm.select_nach_tr_person.options[j] = null;
    }
    parent.job_tour.document.tourForm.select_nach_tr_person.style.display = "none";
    parent.job_tour.document.tourForm.nach_tr_person.size = "20";
  }

  for (var i = 0; i < cs_eid_list.length; i++) {
    if (cs_eid_list[i][0] == csc_id) {	
      if (cs_eid_list[i][16].length != 0) {
        if (side == 0) parent.job_tour.document.tourForm.select_von_tr_person.options[0] = new Option("", "");
        if (side == 1) parent.job_tour.document.tourForm.select_nach_tr_person.options[0] = new Option("", "");
        for (var j = 0; j < cs_eid_list[i][16].length; j++) {
          if (side == 0) parent.job_tour.document.tourForm.select_von_tr_person.options[j+1] = new Option(unescape(cs_eid_list[i][16][j]), unescape(cs_eid_list[i][16][j]));
          if (side == 1) parent.job_tour.document.tourForm.select_nach_tr_person.options[j+1] = new Option(unescape(cs_eid_list[i][16][j]), unescape(cs_eid_list[i][16][j]));
        }        
        if (side == 0) parent.job_tour.document.tourForm.select_von_tr_person.style.display = "initial";
        if (side == 0) parent.job_tour.document.tourForm.von_tr_person.size = "16"
        if (side == 1) parent.job_tour.document.tourForm.select_nach_tr_person.style.display = "initial";
        if (side == 1) parent.job_tour.document.tourForm.nach_tr_person.size = "16"
      }
      return;
    }
  }
}

function set_tr_person(side) {
  if (side == 0) {
    parent.job_tour.document.tourForm.von_tr_person.value =
      parent.job_tour.document.tourForm.select_von_tr_person.options[parent.job_tour.document.tourForm.select_von_tr_person.selectedIndex].value;
  }
  if (side == 1) {
    parent.job_tour.document.tourForm.nach_tr_person.value =
      parent.job_tour.document.tourForm.select_nach_tr_person.options[parent.job_tour.document.tourForm.select_nach_tr_person.selectedIndex].value;
  }
  saveFormFields();
}

var cr_id_orders = ['','','','','','','','','',''];

function check_jb_multi_factor() {
  var cntCr_id_orders = document.getElementsByName("jb_multi_factor")[0].options[document.getElementsByName("jb_multi_factor")[0].selectedIndex].value;

  if (cntCr_id_orders > 1) {
    $('#courierselectsingle').hide();
    var content = 'Gew&uuml;nschte <b>Kuriere</b>:<br>\n';
    for (var i = 0; i < cntCr_id_orders; i++) {
      content += (i < 9 ? '&nbsp;&nbsp;' : '') + (i + 1) + '.' + ' <input name="cr_id_order' + i + '" type="text" size="8" maxlength="6" class="input"' +
        ' value="' + cr_id_orders[i] + '" onchange="saveCr_id_order(' + i + ')">' +
        '<input type="button" value="..." class="button_enabled" title="Kurierliste" onclick="mk_cr_id_list(\'\',\'cr_id_order' + i + '\')">' +
        '&nbsp;&nbsp;&nbsp;&nbsp;';
      if ((i + 1) % 2 == 0)
        content += '<br>\n';
    }
    parent.job_options.$('#courierselectmultiple').html(content);
    $('#courierselectmultiple').show();
    parent.job_options.document.tourOptions.cr_id_order.value = "";
    if (typeof(parent.job_options.document.tourOptions.afterwards) != 'undefined') {
      parent.job_options.document.tourOptions.afterwards.checked = false;    
      parent.job_options.document.tourOptions.afterwards.disabled = true;
    }
    checkAfterwards();
    if (typeof(parent.job_options.document.tourOptions.jb_offer) != 'undefined') {
      parent.job_options.document.tourOptions.jb_offer.checked = false;    
      parent.job_options.document.tourOptions.jb_offer.disabled = true;
    }
    if (typeof(parent.job_options.document.tourOptions.jb_globaljob) != 'undefined') {
      parent.job_options.document.tourOptions.jb_globaljob.checked = false;
      parent.job_options.document.tourOptions.jb_globaljob.disabled = true;
    }
  } else {
    $('#courierselectsingle').show();
    $('#courierselectmultiple').hide();
    if (typeof(parent.job_options.document.tourOptions.afterwards) != 'undefined') {
      parent.job_options.document.tourOptions.afterwards.disabled = false;
    }
    checkAfterwards();
  }
}

function saveCr_id_order(i) {
  cr_id_orders[i] = document.getElementsByName("cr_id_order" + i)[0].value;
  var content = "";
  for (var i = 0; i < cr_id_orders.length; i++)
    content += cr_id_orders[i] + ",";    
  parent.job_options.document.tourOptions.cr_id_orders.value = content.substr(0, content.length - 1);
}

/**  Converts from degrees to radian
 */
/*
function deg2rad(d)
{
  return (d / 180 * Math.PI);
}*/

/**  Converts from radian to degrees
 */
//function rad2deg(r)
//{
//  return (r / Math.PI * 180);
//}
/** Returns the distance between (lat1, long1) and (lat2, long2) as float. */
/*function getDistance(lat1, long1, lat2, long2)
{
  lat1 = deg2rad(lat1);  long1 = deg2rad(long1);  lat2 = deg2rad(lat2);  long2 = deg2rad(long2);  return Math.acos((Math.sin(lat1) * Math.sin(lat2)) +
                   (Math.cos(lat1) * Math.cos(lat2) *
                    Math.cos(long1 - long2))) * GEO_EARTH_RADIUS;}
*/
/** Returns the north-south distance between (lat1, long1) and (lat2, long2) as float.function getDistanceNS(lat1, long1, lat2, long2)
{  var direction;

  lat1 = deg2rad(lat1);  long1 = deg2rad(long1);  lat2 = deg2rad(lat2);  long2 = deg2rad(long2);  if (lat1 > lat2) { direction = -1; } else { direction = 1; }  return direction * Math.acos((Math.sin(lat1) * Math.sin(lat2)) +
                               (Math.cos(lat1) * Math.cos(lat2))) * GEO_EARTH_RADIUS;} ** Returns the west-east distance between (lat1, long1) and (lat2, long2) as float.function getDistanceWE(lat1, long1, lat2, long2)
{  var direction;

  lat1 = deg2rad(lat1);  long1 = deg2rad(long1);  lat2 = deg2rad(lat2);  long2 = deg2rad(long2);  if (lat1 > lat2) { direction = -1; } else { direction = 1; }  return direction * Math.acos(Math.pow(Math.sin(lat1), 2) +
                              (Math.pow(Math.cos(lat1), 2) *
                                        Math.cos(long1 - long2))) * GEO_EARTH_RADIUS;} ** Returns the orientation of the parametric GeoObject to this, like "GeoObject lies to the north of this" *  Orientation are declared within this function.function getOrientation(lat1, long1, lat2, long2) {
  var x = getDistanceWE(lat1, long1, lat2, long2);  var y = getDistanceNS(lat1, long1, lat2, long2);  var winkel = rad2deg(Math.atan2(y, x));
  if ((winkel > 67.5) && (winkel <= 112.5)) { return "N"; }
  if ((winkel > 22.5) && (winkel <= 67.5)) { return "NO"; }
  if ((winkel <= 22.5) && (winkel > -22.5)) { return "O"; }
  if ((winkel <= -22.5) && (winkel > -67.5)) { return "SO"; }
  if ((winkel <= -67.5) && (winkel > -112.5)) { return "S"; }
  if ((winkel <= -112.5) && (winkel > -157.5)) { return "SW"; }
  if ((winkel > 157.5) || (winkel <= -157.5)) { return "W"; }
  if ((winkel > 112.5) && (winkel <= 157.5)) { return "NW"; }
  return "";
}*/

/*
 * sortCr_id_order_list
 *   params: -
 *   return: -
 *   global: cr_id_order_list
 *
 * Sortiert die Liste cr_id_order_list GEOGRAPHISCH
 * in Abhängigkeit von der Distanz des Kuriers zur PLZ der ersten Tour
 * Anzuwenden vor der Ausgabe der Kurierauswahlliste
 */

/*
function sortCr_id_order_list()
{
  var distances = new Array(cr_id_order_list.length);
  var cr_id_order_list_resorted = new Array(cr_id_order_list.length);
  var cur_plz = getJobList(0, jl_ad_zipcode);
//alert (cur_plz);
  var cr_plz;
  var found;
  var dist_min;
  var dist_max;
  var i_min;
//  var buffer;

  // Keine PLZ in der ersten Tour angegeben --> keine Sortierung möglich
  if (cur_plz == "")
    return cr_id_order_list;
  found = false;
  for (var key in plz_geo_list)
    if (key == cur_plz)
      found = true;
  // PLZ nicht in Koordinatenliste vorhanden --> keine Sortierung möglich
  if (!found)
    return cr_id_order_list;

  found = false;
  for (var i = 0; i < cr_id_order_list.length; i++)
  {
    cr_plz = "";
//    cr_id_order_list_resorted[i] = cr_id_order_list[i];
    if (cr_id_order_list[i].indexOf("&nbsp;(") > -1 && cr_id_order_list[i].indexOf(",&nbsp;") > -1)
    {
      cr_plz = cr_id_order_list[i].substr(
        cr_id_order_list[i].indexOf("&nbsp;(") + 7,
        cr_id_order_list[i].indexOf(",&nbsp;") - (cr_id_order_list[i].indexOf("&nbsp;(") + 7));
    }
    distances[i] = (-1);
    if (cr_plz != "")
    {
      found = true;
      distances[i] = getDistance(plz_geo_list[cur_plz][0], plz_geo_list[cur_plz][1],
                                 plz_geo_list[cr_plz][0], plz_geo_list[cr_plz][1]);
//alert ("'" + cur_plz + "' -> '" + cr_plz + "' : " + distances[i] + "Km");
    }
  }
  // Kein Kurier mit PLZ-Angabe gefunden --> Keine Sortierung möglich
  if (!found)
    return cr_id_order_list;

  // cr_id_order_list nach Entfernungen umsortieren
  for (var j = 0; j < distances.length; j++)
  {
    dist_min = 99999;
    dist_max = 0;
    for (var i = 0; i < distances.length; i++)
    {
      if (distances[i] > -1 && distances[i] >= dist_max && distances[i] < dist_min)
      {
        dist_min = distances[i];
        i_min = i;
      }
    }
    if (distances[i] > dist_max)
      dist_max = distances[i];

//var temp = "";
//for (var z = 0; z < distances.length; z++)
//temp = temp + "'" + z + "' '" + cr_id_order_list_resorted[z] + "'\n";

    cr_id_order_list_resorted[j] = cr_id_order_list[i_min];
//alert ("'" + j + "' '" + cr_id_order_list_resorted[j] + "' -> '" + distances[i_min] + "' Km\n");
    distances[i_min] = 99999;
//    buffer = cr_id_order_list_resorted[j];
//    cr_id_order_list_resorted[j] = cr_id_order_list_resorted[i_min];
//    cr_id_order_list_resorted[i_min] = buffer;
//    buffer = distances[j];
//    distances[j] = distances[i_min];
//    distances[i_min] = buffer;
  }
  return cr_id_order_list_resorted;
}
*/
