<?php
/*=======================================================================
 *
 * customer_special.php
 *
 * Autor: Marc Vollmann
 *
 =======================================================================*/

include_once ("../include/mcglobal.inc.php");
include_once ("../include/auth.inc.php");
$doNotIncludeGeocode = "1";
include_once ("../include/inc_file.inc.php");


$httpVars = array("f_act", "companyId", "orderClause", "statusMessage", "printVersion");

$httpVisualVars = array("f_cmp_authenticated", "f_cmp_type", "f_cmp_comp", "f_cmp_comp2", "f_cmp_comp3", "f_cmp_comp4", "f_cs_eid", "f_usr_id", "f_usr_name", "f_usr_firstname", 
                        "f_usr_phone", "f_usr_phone2", "f_usr_fax", "f_usr_email", "f_usr_inv_email", "f_usr_reminder_email", "f_cmp_sustainability_email", "f_cmp_sustainability_interval", 
                        "f_cmp_iln", "f_cmp_tax_idno", "f_cmp_stax_idno", "f_cs_invmode", "f_cs_discount", "f_cmp_postage", "f_cmp_inv2hq", 
                        "f_cmp_bank", "f_cmp_bankno", "f_cmp_bankacc", "f_cmp_bankmode", "f_cmp_iban", "f_cmp_swift", "f_cmp_hqlino", "f_cmp_gln", "f_cs_eid_old", 
                        "f_usr_account", "f_usr_password", "cpfs", "f_usr_password2", "f_cs_jbedit", "f_cs_ar", "f_cs_jb_creator_discount", "f_cs_price_warn_uncomplete", "f_cs_joblist_disabled",
                        "f_cs_jbstatusmail2csc", "f_cs_jbstatusmail", "f_cs_jbstatusmail2", "f_cs_jbstatusmail3", "f_cs_jb_jam_waittime", "f_cs_jb_jam_waittime_minutes", "f_cs_jb_incomplete",
                        "f_cs_jbstatusmail_price", "f_cs_jbstatusmail_emp", "f_cs_jbstatusmail_pdf", "f_cs_par_email_lng", "f_cs_par_email_arrivaltime", "f_cs_par_email_no_footer",
                        "f_cs_jbstatusmail_field1", "f_cs_jbstatusmail_field2", "f_cs_jbstatusmail_field3", "f_cs_jbstatusmail_field4", "f_cs_jbstatusmail_field5", "f_cs_jbstatusmail_field6",
                        "f_cs_jbstatusmail_field7", "f_cs_jbstatusmail_field8", "f_cs_jbstatusmail_field9", "f_cs_jbstatusmail_fieldA",
                        "f_cs_commission_no", "f_cs_cr_fav_only", "f_cs_jobbatch", "f_cmp_cashmode", "f_cmp_visible", "f_cs_fixprice_discount",
                        "f_ad_changemode", "f_adt_change", "f_cmp_changemode", "f_adt_change2", "f_cs_invtext_mode", "f_cmp_no_longhaul", "f_cs_prov",
                        "f_ad_street", "f_cmp_hsno", "f_ad_zipcode", "f_ad_city", "f_ad_country", "f_cmp_match", "f_cmp_match2", "f_cs_markup", "f_cs_markup_prov",
                        "f_cmp_remark", "f_cmp_remark2", "f_cmp_newsletter", "f_cmp_dsgvo", "f_cs_tracking", "f_cs_charging_time", "f_cs_blur_markup_time", "f_cmp_proof_delivery", "f_cmp_pda_usage", 
                        "f_cs_par_tr_sort", "f_cs_par_order_color", "f_cs_par_dont_make", "f_cs_par_calc_usage", "f_cs_par_cst_all_ad", "f_cs_par_xxxxxxxx",
                        "f_cs_photo_disabled", "f_cs_photo_hq", "f_cs_photo_cs", "f_cs_photo_range_from", "f_cs_photo_range_to", "f_cs_payment_term",
                        "f_cs_jb_storno", "f_cs_jb_dispo", "f_noaddressvalidation", "g_cs_id", "g_csc_id", "g_tx_id", "g_br_id", "g2_cs_id", 
                        "g_sales_emp_id", "g_sales_usr_name", "g_sales_usr_firstname", "f_cmp_sales_ranking_man", "copyCs", "pt2cs", "generatePDF", "deactivateMenu");

$httpVarsArray = array_merge ($httpVars, $httpVisualVars);

getSecHttpVars("1", $httpVarsArray);                         

getLanguage(__FILE__);

// Check for authentication access and granted rights
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
authCheckEmployeeRights($emp_id, "0", "1");


// Check handling of the type of the customer
$f_cmp_current_type = getFieldValueFromId("company", "cmp_id", $companyId, "cmp_type");
if ($f_cmp_type == "") : $f_cmp_type = $f_cmp_current_type; endif;

// If there is at least one job then it has to be a customer !!!
// It is IMPORTANT to iterate ALSO if cmp_type == "0", because if there is NO job associated then the user has to be the possibitity to change the type (back) e.g. to prospect !!!
$showCmpTypeSelection = true;
$csCurrIsCashPayer = "0";
if ($companyId != "") :
   $tmpCsId = getFieldValueFromId("customer", "cmp_id", $companyId, "cs_id");   
   $cscVectorOfTheCustomerArrayLen = 0;
   if ($tmpCsId != "") :
      // Get internal cashpayers by parameter
      $tmpCsHqId = getFieldValueFromId("customer", "cs_id", $tmpCsId, "hq_id");
      $tmpCsCscId = getFieldValueFromId("customer", "cs_id", $tmpCsId, "csc_id");
      $csIdPayerCash = getFieldValueFromClause("parameter","par_value","par_key = 'CSC_ID_PAYER_CASH' AND hq_id = '" . $tmpCsHqId . "'");
      if ($tmpCsCscId == $csIdPayerCash) :
         $csCurrIsCashPayer = "1";
      endif;
      // Get costcenters         
      $cscVectorOfTheCustomerArray = getColVectorFromDB2Array("costcenter","cs_id",$tmpCsId,"csc_id");
      $cscVectorOfTheCustomerArrayLen = count($cscVectorOfTheCustomerArray);
   endif;
   if ($cscVectorOfTheCustomerArrayLen > 0) :
      for ($i = 0; $i < $cscVectorOfTheCustomerArrayLen; $i++) :
          if (existsEntry("job",array("csc_id_payer",$cscVectorOfTheCustomerArray[$i])) || existsEntry("job",array("csc_id_payer_cash",$cscVectorOfTheCustomerArray[$i]))) :
             if ($f_cmp_type != "0") :
                updateStmt("company","cmp_id",$companyId,array("cmp_type","0"));
                $f_cmp_type = "0";
                $f_cmp_current_type = "0";
             endif;
             $showCmpTypeSelection = false;
             break;
          endif;
      endfor;
   endif;
endif;

// Get title
$typeTextArray = getColVectorFromDB2ArrayByClause("metatype", "mt_value", "mt_type = 'customer_type'", "", "mt_sort", "");
$pageTitel = getLngt("KUNDE");
if ($f_cmp_type == "1") :
   $pageTitel = getLngt("INTERESSENT");
elseif ($f_cmp_type == "2") :
   $pageTitel = getLngt("POTENTIALKUNDE");
elseif ($f_cmp_type == "3") :
   $pageTitel = getLngt("WUNSCHKUNDE");   
endif;
if ($f_cmp_type != "" && $typeTextArray[$f_cmp_type] != "") : 
   $pageTitel = strtoupper($typeTextArray[$f_cmp_type]);
endif;

$deactivateMenuStatic = "1";

if ($generatePDF != "1") :
   include_once ("../geo/geocode.inc.php");
endif;
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
include_once ("../groupware/calendar.php");
$debug = false;
include_once ("../include/inc_customer.inc.php");
getCurrentScript(__FILE__);

// No operation if print version requested
if ($printVersion == "1") : $f_act = ""; endif;


$addressValidationErr = "";
$dbOperationCompleted = "0";

// Check for validation of the address assigned to the customer
$noValidationOfAddress = FALSE;
if ($f_noaddressvalidation != "") :
   if ($f_noaddressvalidation[0] == '1') : $noValidationOfAddress = TRUE; endif;
endif;

// Init parameters:
// Tracking
if (mcChkValOrArrCountIsEmpty($f_cs_tracking)) :
   $f_cs_tracking = "0";
else :
   if (is_array($f_cs_tracking)) :
      mcArrIsSet($f_cs_tracking, 0, 0);
      mcArrIsSet($f_cs_tracking, 1, 0);
      $f_cs_tracking = $f_cs_tracking[0] + $f_cs_tracking[1];
   else :
      $f_cs_tracking = "0";
   endif;
endif;
// Average charging time
if ($f_cs_charging_time == "") :
   $f_cs_charging_time = "0";
endif;
// Average charging time
if ($f_cs_blur_markup_time == "") :
   $f_cs_blur_markup_time = "0";
endif;
// Invoice mode
if ($f_cmp_inv2hq == "" || count($f_cmp_inv2hq) == 0) :
   $f_cmp_inv2hq = "0";
else :
   mcArrIsSet($f_cmp_inv2hq, 0, 0);
   mcArrIsSet($f_cmp_inv2hq, 1, 0);
   $f_cmp_inv2hq = $f_cmp_inv2hq[0] + $f_cmp_inv2hq[1];
endif;
// Only favoured couriers
if ($f_cs_cr_fav_only == "" || count($f_cs_cr_fav_only) == 0) :
   $f_cs_cr_fav_only = "0";
else: 
   $f_cs_cr_fav_only = "1";
endif;
// Flag for "list customer" (jobbatch)
if ($f_cs_jobbatch == "" || count($f_cs_jobbatch) == 0) :
   $f_cs_jobbatch = "0";
else: 
   $f_cs_jobbatch = "1";
endif;
// Flag for fixprice discount
if ($f_cs_fixprice_discount == "" || count($f_cs_fixprice_discount) == 0) :
   $f_cs_fixprice_discount = "0";
else: 
   $f_cs_fixprice_discount = "1";
endif;
// Flag for invoice text mode
if ($f_cs_invtext_mode == "" || count($f_cs_invtext_mode) == 0) :
   $f_cs_invtext_mode = "0";
else: 
   $f_cs_invtext_mode = "1";
endif;
// Flag for no longhaul
if ($f_cmp_no_longhaul == "" || count($f_cmp_no_longhaul) == 0) :
   $f_cmp_no_longhaul = "0";
else: 
   $f_cmp_no_longhaul = "1";
endif;
// Flag for (fuel) markup
if ($f_cs_markup == "" || count($f_cs_markup) == 0) :
   $f_cs_markup = "0";
else: 
   $f_cs_markup = "1";
endif;
// Flag for customer to create jobs
if ($f_cs_jbedit == "" || count($f_cs_jbedit) == 0) :
   $f_cs_jbedit = "0";
else: 
   $f_cs_jbedit = "1";
endif;
// Flag for customer to create jobs
if ($f_cs_ar == "" || count($f_cs_ar) == 0) :
   $f_cs_ar = "0";
else: 
   $f_cs_ar = "1";
endif;
// Flag for customer to check price has to blink in job list if it is uncomplete
if ($f_cs_price_warn_uncomplete == "" || count($f_cs_price_warn_uncomplete) == 0) :
   $f_cs_price_warn_uncomplete = "0";
else: 
   $f_cs_price_warn_uncomplete = "1";
endif;
// Flag for customer to disable displaying in job lists
if ($f_cs_joblist_disabled == "" || count($f_cs_joblist_disabled) == 0) :
   $f_cs_joblist_disabled = "0";
else: 
   $f_cs_joblist_disabled = "1";
endif;
// Flag for status mail extra fields
if ($f_cs_jbstatusmail_field1 == "" || count($f_cs_jbstatusmail_field1) == 0) :
   $f_cs_jbstatusmail_field1 = "0";
else: 
   $f_cs_jbstatusmail_field1 = "1";
endif;
if ($f_cs_jbstatusmail_field2 == "" || count($f_cs_jbstatusmail_field2) == 0) :
   $f_cs_jbstatusmail_field2 = "0";
else: 
   $f_cs_jbstatusmail_field2 = "1";
endif;
if ($f_cs_jbstatusmail_field3 == "" || count($f_cs_jbstatusmail_field3) == 0) :
   $f_cs_jbstatusmail_field3 = getParameterValue("0", "CS_JBSTATUSMAIL_FIELD3_DEFAULT", $hq_id);
else: 
   $f_cs_jbstatusmail_field3 = "1";
endif;
if ($f_cs_jbstatusmail_field4 == "" || count($f_cs_jbstatusmail_field4) == 0) :
   $f_cs_jbstatusmail_field4 = "0";
else: 
   $f_cs_jbstatusmail_field4 = "1";
endif;
if ($f_cs_jbstatusmail_field5 == "" || count($f_cs_jbstatusmail_field5) == 0) :
   $f_cs_jbstatusmail_field5 = "0";
else: 
   $f_cs_jbstatusmail_field5 = "1";
endif;
if ($f_cs_jbstatusmail_field6 == "" || count($f_cs_jbstatusmail_field6) == 0) :
   $f_cs_jbstatusmail_field6 = "0";
else: 
   $f_cs_jbstatusmail_field6 = "1";
endif;
if ($f_cs_jbstatusmail_field7 == "" || count($f_cs_jbstatusmail_field7) == 0) :
   $f_cs_jbstatusmail_field7 = "0";
else: 
   $f_cs_jbstatusmail_field7 = "1";
endif;
if ($f_cs_jbstatusmail_field8 == "" || count($f_cs_jbstatusmail_field8) == 0) :
   $f_cs_jbstatusmail_field8 = "0";
else: 
   $f_cs_jbstatusmail_field8 = "1";
endif;
if ($f_cs_jbstatusmail_field9 == "" || count($f_cs_jbstatusmail_field9) == 0) :
   $f_cs_jbstatusmail_field9 = getParameterValue("0", "CS_JBSTATUSMAIL_FIELD9_DEFAULT", $hq_id);
else: 
   $f_cs_jbstatusmail_field9 = "1";
endif;
if ($f_cs_jbstatusmail_fieldA == "" || count($f_cs_jbstatusmail_fieldA) == 0) :
   $f_cs_jbstatusmail_fieldA = getParameterValue("0", "CS_JBSTATUSMAIL_FIELDA_DEFAULT", $hq_id);
else: 
   $f_cs_jbstatusmail_fieldA = "1";
endif;
$f_cs_jbstatusmail_fields = $f_cs_jbstatusmail_field1 . $f_cs_jbstatusmail_field2 . $f_cs_jbstatusmail_field3 . $f_cs_jbstatusmail_field4 . $f_cs_jbstatusmail_field5 . $f_cs_jbstatusmail_field6 . $f_cs_jbstatusmail_field7 . $f_cs_jbstatusmail_field8 . $f_cs_jbstatusmail_field9 . $f_cs_jbstatusmail_fieldA;

// Job jam waittime default value (in minutes)
$parCsJbJamWaittimeAdHocDefault = getParameterValue("0", "CS_JB_JAM_WAITTIME_AD_HOC_DEFAULT", $hq_id);
  if ($parCsJbJamWaittimeAdHocDefault == "") : $parCsJbJamWaittimeAdHocDefault = getParameterValue("0", "CS_JB_JAM_WAITTIME_AD_HOC_DEFAULT", "0"); endif;
$parCsJbJamWaittimeReservationDefault = getParameterValue("0", "CS_JB_JAM_WAITTIME_RESERVATION_DEFAULT", $hq_id);
  if ($parCsJbJamWaittimeReservationDefault == "") : $parCsJbJamWaittimeReservationDefault = getParameterValue("0", "CS_JB_JAM_WAITTIME_RESERVATION_DEFAULT", "0"); endif;
// Customer job jam waittime
if ($f_cs_jb_jam_waittime == "" || count($f_cs_jb_jam_waittime) == 0) :
   $f_cs_jb_jam_waittime = 0;
else :
   if ($companyId != "") :
      $f_cs_jb_jam_waittime = getFieldValueFromId("customer", "cmp_id", $companyId, "cs_jb_jam_waittime");
   endif;
   if (!is_numeric($f_cs_jb_jam_waittime) || $f_cs_jb_jam_waittime == "0") :
      $f_cs_jb_jam_waittime = $parCsJbJamWaittimeAdHocDefault;
   endif;      
endif;

// Init
if ($f_cmp_sales_ranking_man == "") : $f_cmp_sales_ranking_man = "0"; endif;
if ($f_cmp_proof_delivery == "") : $f_cmp_proof_delivery = "0"; endif;
if ($f_cs_payment_term == "") : $f_cs_payment_term = "0"; endif;
mcIsSet($cs_id_new); mcIsSet($cmpId); mcIsSet($eid); mcIsSet($usrName); mcIsSet($usrFirstname); mcIsSet($adStreet); mcIsSet($cmpHsno);
mcIsSet($adZipcode); mcIsSet($adCity); mcIsSet($oldDpfChecksum); mcIsSet($phpCurrentNavigationInputHidden); mcIsSet($adCity);

// Photos
if ($f_cs_photo_disabled == "") :
   $f_cs_photo_disabled = "0";
else: 
   $f_cs_photo_disabled = "1";
endif;
if ($f_cs_photo_hq == "") :
   $f_cs_photo_hq = "0";
else: 
   $f_cs_photo_hq = "1";
endif;
if ($f_cs_photo_cs == "") :
   $f_cs_photo_cs = "0";
else: 
   $f_cs_photo_cs = "1";
endif;
if ($f_cs_photo_range_from == "") :
   $f_cs_photo_range_from = "0";
endif;
if ($f_cs_photo_range_to == "") :
   $f_cs_photo_range_to = "0";
endif;


// Init parameter for executing the personal embargo request
$execEmbargoCheck = "0";

// Change costcenter addresses according to the main address
$changeBeneficiaryAddress = FALSE;
$changeInvoiceAddress = FALSE;
$changePickUpAddress = FALSE;
if ($f_adt_change != "") :
   if (!(array_search("1",$f_adt_change) === FALSE)) : $changeBeneficiaryAddress = TRUE; endif;
   if (!(array_search("2",$f_adt_change) === FALSE)) : $changeInvoiceAddress = TRUE; endif;
   if (!(array_search("4",$f_adt_change) === FALSE)) : $changePickUpAddress = TRUE; endif;
endif;
// Change costcenter company names according to the main name
$changeBeneficiaryCompany = FALSE;
$changeInvoiceCompany = FALSE;
$changePickUpCompany = FALSE;
if ($f_adt_change2 != "") :
   if (!(array_search("1",$f_adt_change2) === FALSE)) : $changeBeneficiaryCompany = TRUE; endif;
   if (!(array_search("2",$f_adt_change2) === FALSE)) : $changeInvoiceCompany = TRUE; endif;
   if (!(array_search("4",$f_adt_change2) === FALSE)) : $changePickUpCompany = TRUE; endif;
endif;

// Check for minimum length of phone numbers
$parCsPhoneMinLength = getParameterValue("0", "CS_PHONE_MINIMUM_LENGTH", $hq_id);
if ($parCsPhoneMinLength == "") : $parCsPhoneMinLength = getParameterValue("0", "CS_PHONE_MINIMUM_LENGTH", "0"); endif;

// Get mask parameter regarding change behaviour of the tax field
$parMaskCsTaxIdsChangeMsg = getParameterValue("0", "MASK_CS_SPECIAL_TAX_IDS_CHANGE_MSG", $hq_id);
if ($parMaskCsTaxIdsChangeMsg == "") : $parMaskCsTaxIdsChangeMsg = getParameterValue("0", "MASK_CS_SPECIAL_TAX_IDS_CHANGE_MSG", "0"); endif;
if ($parMaskCsTaxIdsChangeMsg != "") : $parMaskCsTaxIdsChangeMsg = "'" . implode("','", spliti(",", $parMaskCsTaxIdsChangeMsg)) . "'"; endif;

// Get mandatory fields to be checked
$parMaskMandatoryFields = getMandatoryFields("MASK_CS_MANDATORY_FIELDS");
$parMaskMandatoryFieldsLen = count($parMaskMandatoryFields);

// Check tracking functionality enabled
$parCsTracking = getParameterValue("0", "CS_TRACKING_ENABLED", $hq_id);
if ($parCsTracking == "") : $parCsTracking = getParameterValue("0", "CS_TRACKING_ENABLED", "0"); endif;

// Get EID prefix and reset EID only if equals prefix
$constCsEidPrefix = getParameterValue("0", "CS_EID_PREFIX", $hq_id);
if ($f_cs_eid == $constCsEidPrefix) : $f_cs_eid = ""; endif;    

// ONLY for transformation from "prospect'"' to "customer" !!!
// ***
if ($pt2cs != "") :
   // Get max-value of the EID of the current customer for inserting a new row 
   // The constant value "CS_EID_GENERATION" contains the prefix of the SID [SPECIAL TREATMENT]
   $f_eid_maxval = "";
   // $csEidGeneration = getParameterValue("0", "CS_EID_GENERATION");
   if (CS_EID_GENERATION != "") :
      $f_eid_maxval = getMaxOfField("customer", "cs_eid", "cs_eid < '" . CS_EID_GENERATION . "'");
      if (is_numeric($f_eid_maxval)) :
         ++$f_eid_maxval;   // Increment because of the next free EID (Attention: Not TA-safe!)
      else :
        // Remove alphanumeric chars (e.g "HTHB123456" => "123456")
        $prefixChars = ereg_replace("[^[:alpha:]+]","",$f_eid_maxval);
        $f_eid_maxval = ereg_replace("[^[:digit:]+]","",$f_eid_maxval);
        ++$f_eid_maxval;
        $f_eid_maxval = $prefixChars . $f_eid_maxval;
      endif;
        $f_cs_eid = $f_eid_maxval;  // !!!
   endif;
endif;

// *******


   // ********************************
   // * Operations for the customers *   
   // ********************************

   // Generate log string
   if ($f_act != "") :
      $f_cmp_comp = str_replace("'", "", $f_cmp_comp);
      $f_cmp_comp2 = str_replace("'", "", $f_cmp_comp2);
      $f_cmp_comp3 = str_replace("'", "", $f_cmp_comp3);
      $f_cmp_comp4 = str_replace("'", "", $f_cmp_comp4);
      $f_cmp_match = str_replace("'", "", $f_cmp_match);
      $f_cmp_match2 = str_replace("'", "", $f_cmp_match2);
      $f_cmp_remark = str_replace("'", "´", $f_cmp_remark);
      $f_cmp_remark2 = str_replace("'", "´", $f_cmp_remark2);

      $logString = makeLogString(array($f_cmp_authenticated,$f_cmp_comp,$f_cmp_comp2,$f_cs_eid,$f_usr_name,
                                       $f_usr_firstname,$f_usr_phone,$f_usr_phone2,$f_usr_fax,$f_usr_email,$f_cmp_iln,
                                       $f_cmp_tax_idno,$f_cs_invmode,$f_cmp_bank,$f_cmp_bankno,$f_cmp_bankacc,
                                       $f_cmp_bankmode,$f_cs_discount,$f_cmp_postage,$f_cmp_inv2hq,$f_usr_account,
                                       $f_cs_jbstatusmail,$f_cs_commission_no,$f_cs_cr_fav_only,$f_cs_jobbatch,
                                       $f_cmp_cashmode,$f_cmp_visible,$f_ad_changemode,$f_adt_change,$f_cmp_changemode,
                                       $f_adt_change2,$f_ad_street,$f_cmp_hsno,$f_ad_zipcode,$f_ad_city,$f_ad_country,
                                       $f_cmp_match,$f_cmp_match2,$g_cs_id,$g_csc_id,$g_tx_id,$g_br_id,$g2_cs_id,
                                       $f_cs_fixprice_discount,$f_cs_jbstatusmail2,$f_cs_jbstatusmail3, 
                                       $f_cs_invtext_mode, $f_cs_prov, $f_cmp_remark,$f_cmp_remark2,$f_cs_markup,
                                       $f_cs_markup_prov, $f_cs_jbstatusmail2csc, $f_cs_jbedit, $f_cs_jbstatusmail_price,
                                       $f_cs_jbstatusmail_emp, $f_cs_jbstatusmail_pdf, $f_cs_jbstatusmail_fields, 
                                       $f_cmp_stax_idno, $f_cmp_iban, $f_cmp_swift, $f_cmp_hqlino, $f_cmp_type, $f_cmp_newsletter, 
                                       $f_cs_price_warn_uncomplete, $g_sales_emp_id, $f_cmp_sales_ranking_man,$f_cmp_comp3,$f_cmp_comp4,
                                       $f_cmp_proof_delivery, $f_cmp_pda_usage, $f_cs_tracking, $f_cmp_dsgvo, $f_cs_joblist_disabled, 
                                       $f_cs_eid_old, $f_cs_jb_jam_waittime, $f_usr_inv_email, $f_cs_ar, $f_cs_charging_time, 
                                       $f_cs_blur_markup_time, $f_cmp_sustainability_email, $f_cmp_sustainability_interval,
                                       $f_cs_photo_disabled, $f_cs_photo_hq, $f_cs_photo_cs, $f_cs_photo_range_from, $f_cs_photo_range_to,
                                       $f_cmp_no_longhaul, $f_cs_payment_term, $f_cs_par_email_arrivaltime, $f_cs_par_email_lng, 
                                       $f_cs_jb_creator_discount, $f_cs_jb_incomplete, $f_cs_jb_jam_waittime_minutes, $f_usr_reminder_email,
                                       $f_cmp_gln), ";", "0");
   endif;

   // Insert new customer
   if ($f_act == "newCustomer") :

      if ($f_cmp_comp != "" && $f_cs_eid != "" && $f_usr_phone != "" && $f_ad_street != "" && $f_ad_zipcode != "" && $f_ad_city != "" && $f_cmp_hsno != "" && ($csCurrIsCashPayer == "1" || ($f_usr_inv_email != "" && $f_usr_reminder_email != ""))) :
          // $f_usr_name != "" && $f_usr_firstname != "" && 

         // Check unique account for all customers (all data) except the current one to be updated
         if ($f_usr_account != "" && $db->getOne("SELECT usr.usr_id FROM user AS usr WHERE usr.usr_account = '" . $f_usr_account . "' ")) :
            $statusMessage = getLngt("Der Benutzername existiert schon! Bitte wählen Sie einen anderen!");
            
         elseif (FALSE && $db->getOne("SELECT cmp_comp FROM company WHERE cmp_comp = '" . $f_cmp_comp . "'")) :
                $statusMessage = getLngt("Der Firmenname ist bereits vorhanden! Bitte wählen Sie einen anderen!");
         
         elseif ($db->getOne("SELECT cs_eid FROM customer WHERE cs_eid = '" . $f_cs_eid . "'")) :
                $statusMessage = getLngt("Die eindeutige Kundennummer (ExtID) ist bereits vergeben! Bitte wählen Sie eine andere");
         
         // The account and password can be empty (only for customer)
         elseif ($f_usr_password == "" || checkPasswordValidation($f_usr_password,$f_usr_password2)) : 

            // Check address for validation
            $addressValid = getGeoCoordinates($f_ad_street, $f_ad_zipcode, $f_ad_city, $f_cmp_hsno, $f_ad_country, "");
            if ($addressValid != "") :
                
                // Check zipcode and city
                $addressValidityArray = checkCityZipcode($f_ad_zipcode, $f_ad_city, $f_ad_street);
                
                if ($noValidationOfAddress || $addressValidityArray[0] >= 1) :

                   $currentTime = getDateTime("0");
                
                   // Execute INSERT operations
                   $insertOk = insertCustomer();

                   if ($insertOk) :

                      // Write into "servicepricehistory"
                      insertStmt("servicepricehistory", array("srvprch_obj_type","cs", "srvprch_obj_id", $cs_id_new, "srvprch_fieldname", "cs_discount", "srvprch_price", $f_cs_discount, "srvprch_validfrom", $currentTime));
                      insertStmt("servicepricehistory", array("srvprch_obj_type","cs", "srvprch_obj_id", $cs_id_new, "srvprch_fieldname", "cs_prov", "srvprch_price", $f_cs_prov, "srvprch_validfrom", $currentTime));
                      insertStmt("servicepricehistory", array("srvprch_obj_type","cs", "srvprch_obj_id", $cs_id_new, "srvprch_fieldname", "cs_markup_prov", "srvprch_price", $f_cs_markup_prov, "srvprch_validfrom", $currentTime));


                      // ********** DPF **********
                      
                      // Reset fields of form-parameters
                      // clearParameters($httpVisualVars);   // <= Moved to the end of the php-part of this script...
                      $dbOperationCompleted = "1";
                      
                      // Check according to personal embargo
                      // (NOT included in transaction)
                      $constDPFCustomerEnabled = getParameterValue("0", "DPF_CS_ENABLED", "0");  // "Meta-Global" <=> hq_id = 0
                      if ($constDPFCustomerEnabled == '1') :
                         $execEmbargoCheck = "1";
                         $cmpId = $cmp_id_new;
                         $eid = $f_cs_eid;
                         $usrName = $f_usr_name;
                         $usrFirstname = $f_usr_firstname;
                         $adStreet = $f_ad_street;
                         $cmpHsno = $f_cmp_hsno;
                         $adZipcode = $f_ad_zipcode;
                         $adCity = $f_ad_city;
                         // = $f_ad_country;
                         
                         // Check for DPF checksum
                         $oldDpfChecksum = "";
                         $newDpfChecksum = md5($usrFirstname . $usrName . $adStreet . $cmpHsno . $adZipcode . $adCity);
                         updateStmt("company", "cmp_id", $cmp_id_new, array("cmp_dpf_checksum", $newDpfChecksum));
                      endif;
                      
                      
                      // ********** HASH **********
                      
                      // Check for execute functionality
                      if ($GLOBAL_USAGE_HASH) :
                         // Get current global number of THIS database instance
                         $constGlobalDbInstNo = getParameterValue("0", "GLOBAL_UNIQUE_DB_INSTANCE_NO", "0", "0");
                         if ($constGlobalDbInstNo != "" && is_numeric($constGlobalDbInstNo)) :
                            // Generate unique hash value e.g. for newsletter
                            $tmpHash = makeMD5Hash($hq_id, $cs_id_new, $currentTime);
                            // Get database instance connection data of metaobject
                            $constExtDbInst = getExternalMetaDbInst();
                            $db_conn = getDbConnectionSpecial($constExtDbInst, $dbname, $dblogin, $dbpassword);
                            $tmpSqlQuery = "INSERT meta_object.metaobject (mo_id_ref_db,mo_mnemonic,mo_name,mo_obj_type,mo_obj_id,mo_hash) VALUES ('" . $constGlobalDbInstNo . "','','','cs','" . $cs_id_new . "','" . $tmpHash . "') ";
                            $result = $db_conn->dbQuery($tmpSqlQuery);
                            $err = "";
                            if (DB::isError($result)) {$err = "ERR";};
                            if ($err == "ERR") :
                               // Send info mail
                               sendInternalMail("customer_hash_generation_failed_in_metaobjects: CS_ID=" . $cs_id_new . "|CS_EID=" . $f_cs_eid);
                            endif;
                         endif;
                      endif;


                      // ********** GDC **********

                      // Old EID
                      $f_cs_eid_old = trim($f_cs_eid_old);
                      if ($f_cs_eid_old != "") :
                         insertStmt("genericdatacontainer", array("gdc_obj_type", "cs", "gdc_obj_id", $cs_id_new, "gdc_gen_fieldname", "eid_old", "gdc_content", $f_cs_eid_old, "gdc_context", $currentTime));
                      endif;
                      

                      // ********** PARAMETER **********

                      // Flag for configuration regarding "display station number"
                      if (mcChkValOrArrCountIsEmpty($f_cs_par_tr_sort)) :
                         $f_cs_par_tr_sort = "0";
                      else: 
                         $f_cs_par_tr_sort = "1";
                      endif;
                      setParameterValue("JOBDETAILS_STATIONS_STATION_NUMBER_" . $cs_id_new, $f_cs_par_tr_sort);

                      // Flag for color of the jobs in job lists
                      if (mcChkValOrArrCountIsEmpty($f_cs_par_order_color)) :
                         $f_cs_par_order_color = "FFFFFF";
                      endif;
                      if ($f_cs_par_order_color != "FFFFFF") :
                         setParameterValue("JOBLIST_CS_JB_COLOR_" . $cs_id_new, $f_cs_par_order_color);
                      endif;

                      // Flag for NOT displaying jobs in job lists
                      if (mcChkValOrArrCountIsEmpty($f_cs_par_xxxxxxxx)) :
                         $f_cs_par_xxxxxxxx = "0";
                      else: 
                         $f_cs_par_xxxxxxxx = "1";
                      endif;
                      setParameterValue("CUSTOMER_MASK_JOBLIST_XXXXXXXXXX_" . $cs_id_new, $f_cs_par_xxxxxxxx);

                      // Flag for job cancellation by customer
                      if (mcChkValOrArrCountIsEmpty($f_cs_jb_storno)) :
                         $f_cs_jb_storno = "0";
                      else: 
                         $f_cs_jb_storno = "1";
                      endif;
                      setParameterValue("CUSTOMER_MASK_JOBLIST_CANCELLATION_ENABLED_" . $cs_id_new, $f_cs_jb_storno);

                      // Flag for job disposition to favoured couriers by customer
                      if (mcChkValOrArrCountIsEmpty($f_cs_jb_dispo)) :
                         $f_cs_jb_dispo = "0";
                      else: 
                         $f_cs_jb_dispo = "1";
                      endif;
                      setParameterValue("CUSTOMER_MASK_JOBLIST_DISPO_FAV_ENABLED_" . $cs_id_new, $f_cs_jb_dispo);

                      // Flag for making standard price in customer login
                      // if ($f_cs_par_dont_make == "" || count($f_cs_par_dont_make) == 0) :
                      if (mcChkValOrArrCountIsEmpty($f_cs_par_dont_make)) :
                         $f_cs_par_dont_make = "0";
                      else: 
                         $f_cs_par_dont_make = "1";
                      endif;
                      setParameterValue("MASK_CS_DONT_MAKE_STANDARD_PRICE_" . $cs_id_new, $f_cs_par_dont_make);

                      // Flag for calculator has to be a must for jobs of the customer
                      // if ($f_cs_par_calc_usage == "" || count($f_cs_par_calc_usage) == 0) :
                      if (mcChkValOrArrCountIsEmpty($f_cs_par_calc_usage)) :
                         $f_cs_par_calc_usage = "0";
                      else: 
                         $f_cs_par_calc_usage = "1";
                      endif;
                      setParameterValue("CUSTOMER_MASK_CALCULATOR_USAGE_ONLY_" . $cs_id_new, $f_cs_par_calc_usage);

                      // Flag for not checking address in KAE
                      if ($f_cs_par_cst_all_ad == "" || count($f_cs_par_cst_all_ad) == 0) :
                         $f_cs_par_cst_all_ad = "0";
                      else: 
                         $f_cs_par_cst_all_ad = "1";
                      endif;
                      setParameterValue("MASK_CUST_ALL_ADDR_ENABLED_" . $cs_id_new, $f_cs_par_cst_all_ad);

                      // Flag for emails to avoid sending the footer
                      if (mcChkValOrArrCountIsEmpty($f_cs_par_email_no_footer)) :
                         $f_cs_par_email_no_footer = "0";
                      else: 
                         $f_cs_par_email_no_footer = "1";
                      endif;
                      setParameterValue("JOBDETAILS_EMAIL_NO_FOOTER_" . $cs_id_new, $f_cs_par_email_no_footer);

                      // Flag for customer to get a discount by self-creating jobs
                      if (mcChkValOrArrCountIsEmpty($f_cs_jb_creator_discount)) :
                         $f_cs_jb_creator_discount = "0";
                      else: 
                         $f_cs_jb_creator_discount = "1";
                      endif;
                      setParameterValue("CUSTOMER_MASK_JB_CREATOR_DISCOUNT_" . $cs_id_new, $f_cs_jb_creator_discount);

                      // Email arrival time
                      if ($f_cs_par_email_arrivaltime != "" && is_numeric($f_cs_par_email_arrivaltime)) :
                         // Check existence of parameter entry to avoid a parameter for each (new) customer if no arrivaltime will be displayed (!!!!)
                         $tmpEmailArrTime = getParameterValue("0", "JOB_MAIL_STATION_ARRIVAL_TIME_" . $cs_id_new, "0");
                         if ($f_cs_par_email_arrivaltime != "0" || $tmpEmailArrTime != "") :
                            setParameterValue("JOB_MAIL_STATION_ARRIVAL_TIME_" . $cs_id_new, $f_cs_par_email_arrivaltime);
                         endif;
                      endif;

                      // Email language
                      if ($f_cs_par_email_lng != "" && is_numeric($f_cs_par_email_lng)) :
                         // Check existence of parameter entry to avoid a parameter for each (new) customer if language is default language (!!!!)
                         $tmpEmailLng = getParameterValue("0", "JOBDETAILS_EMAIL_LANGUAGE_" . $cs_id_new, "0");
                         if ($f_cs_par_email_lng != "0" || $tmpEmailLng != "") :
                            setParameterValue("JOBDETAILS_EMAIL_LANGUAGE_" . $cs_id_new, $f_cs_par_email_lng);
                         endif;
                      endif;

                      // Flag for customer to set job being incomplete by creating or modifying a job
                      if (mcChkValOrArrCountIsEmpty($f_cs_jb_incomplete)) :
                         $f_cs_jb_incomplete = "0";
                      else: 
                         $f_cs_jb_incomplete = "1";
                      endif;
                      setParameterValue("CUSTOMER_MASK_JB_INCOMPLETE_" . $cs_id_new, $f_cs_jb_incomplete);

                      // Photos
                      setCsPhotoConf($cs_id_new, $f_cs_photo_disabled, $f_cs_photo_hq, $f_cs_photo_cs, $f_cs_photo_range_from, $f_cs_photo_range_to);

                   else :
                      $statusMessage = getLngt("Der Kundendatensatz wurde nicht angelegt!");
                   endif;
                else :
                  $statusMessage = getLngt("Die Postleitzahl bzw. Strasse passt nicht zu dem angegebenen Ort!");
                  $addressValidationErr = "1";
                endif;
 
            else :
              $statusMessage = getLngt("Der Adress-Server kennt die eingebene Adresse nicht oder besitzt keine Geocodierung!");
            endif;
 
         endif;
      else :
         $statusMessage = getLngt("Bitte geben Sie alle mit * gekennzeichneten Felder ein!");
      endif;
   endif;            

   // Modify customer
   if ($f_act == "modifyCustomer" && $companyId != "") :

      // Check customer to be modified is authenticated because of mandatory field
      $v_cmp_authenticated = getFieldValueFromId("company", "cmp_id", $companyId, "cmp_authenticated");

      if ($f_cmp_comp != "" && $f_cs_eid != "" && $f_usr_phone != "" && $f_ad_street != "" && $f_ad_zipcode != "" && $f_ad_city != "" && $f_cmp_hsno != "" && ($v_cmp_authenticated != "1" || $csCurrIsCashPayer == "1" || ($f_usr_inv_email != "" && $f_usr_reminder_email != ""))) :
          // $f_usr_name != "" && $f_usr_firstname != "" && 

         if ($f_usr_account != "" && 
            $db->getOne("SELECT usr.usr_id FROM user AS usr " . 
                         " WHERE usr.usr_account = '" . $f_usr_account . "' AND " .
                         "       usr.usr_id != $f_usr_id")) :
            $statusMessage = getLngt("Der Benutzername existiert schon! Bitte wählen Sie einen anderen!");
                                            
         else : 

           if (trim($f_usr_account) == "" || $cpfs == "0" || ($cpfs == "1" && trim($f_usr_account) != "" && checkPasswordValidation($f_usr_password,$f_usr_password2))) :

            $sqlquery = "SELECT cs.cs_id, emp.emp_id, usr.usr_id, cs.csc_id"
                      . " FROM user AS usr, employee AS emp, customer AS cs, company AS cmp"
                      . " WHERE cmp.cmp_id = " . $companyId
                      . "   AND cs.cmp_id = cmp.cmp_id"
                      . "   AND emp.emp_id = cs.cs_admin"
                      . "   AND usr.usr_id = emp.usr_id";
            $result = $db->dbQ($sqlquery);
            while ($row = $result->fetch_assoc()):
                  $v_cs_id = $row["cs_id"];
                  $v_emp_id = $row["emp_id"];
                  $v_usr_id = $row["usr_id"];
                  $v_csc_id = $row["csc_id"];
            endwhile;
            $result->free();

            if ($v_cs_id != "" && $v_emp_id != "" && $v_usr_id != "" && $v_csc_id != "") :

               if ($db->getOne("SELECT cs_eid FROM customer WHERE cs_eid = '" . $f_cs_eid . "' AND " 
                                                             . " NOT (cs_id = '" . $v_cs_id . "')")) :
                  $statusMessage = getLngt("Die eindeutige Kundennummer (ExtID) ist bereits vergeben! Bitte wählen Sie eine andere");
                                                                     
               else :         

                  $addressValid = getGeoCoordinates($f_ad_street, $f_ad_zipcode, $f_ad_city, $f_cmp_hsno, $f_ad_country, "");            
                  if ($addressValid != "") :

                     // Check zipcode and city
                     $addressValidityArray = checkCityZipcode($f_ad_zipcode, $f_ad_city, $f_ad_street);
                     if ($noValidationOfAddress || $addressValidityArray[0] >= 1) :

                        TA("B");
                        
                        $currentTime = getDateTime("0");

                        // Get current price values from "servicepricehistory"
                        $csPriceFieldsCurrent = getFieldsValueFromId("customer", "cs_id", $v_cs_id, array("cs_discount","cs_prov","cs_markup_prov"));

                        // Get current state in cmp_modify_status because it is equal to "1" then do NOT change                        
                        $modifyStatus = getFieldValueFromId("company", "cmp_id", $companyId, "cmp_modify_status");
                        if ($modifyStatus != "1") : $modifyStatus = "2"; endif;
                        
                        // Update company
                        $f_cmp_postage = str_replace (",", ".", $f_cmp_postage);

                        $defaultFields = array("cmp_type",$f_cmp_type,"cmp_comp",$f_cmp_comp,"cmp_comp2",$f_cmp_comp2,"cmp_comp3",$f_cmp_comp3,"cmp_comp4",$f_cmp_comp4,"cmp_hsno",$f_cmp_hsno,"cmp_iln",$f_cmp_iln,
                                               "cmp_tax_idno",$f_cmp_tax_idno,"cmp_stax_idno",$f_cmp_stax_idno,"tx_id",$g_tx_id,"br_id",$g_br_id,
                                               "emp_id_sales",$g_sales_emp_id,"cmp_sales_ranking_man",$f_cmp_sales_ranking_man, 
                                               "cmp_bank",$f_cmp_bank,"cmp_bankno",$f_cmp_bankno,"cmp_bankacc",$f_cmp_bankacc,"cmp_bankmode",$f_cmp_bankmode,
                                               "cmp_iban",$f_cmp_iban,"cmp_swift",$f_cmp_swift,"cmp_hqlino",$f_cmp_hqlino,"cmp_gln",$f_cmp_gln,"cmp_postage",$f_cmp_postage,"cmp_inv2hq",$f_cmp_inv2hq,"cmp_no_longhaul",$f_cmp_no_longhaul,
                                               "cmp_match",$f_cmp_match,"cmp_match2",$f_cmp_match2,"cmp_sustainability_email",$f_cmp_sustainability_email, "cmp_sustainability_interval", $f_cmp_sustainability_interval,
                                               "cmp_remark",$f_cmp_remark,"cmp_remark2",$f_cmp_remark2, "cmp_dsgvo", $f_cmp_dsgvo,
                                               "cmp_newsletter",$f_cmp_newsletter,"cmp_proof_delivery",$f_cmp_proof_delivery,"cmp_pda_usage", $f_cmp_pda_usage,"cmp_modify_status", $modifyStatus);

                        updateStmt("company","cmp_id",$companyId,$defaultFields);

                        // Update customer
                        $f_cs_discount = str_replace (",", ".", $f_cs_discount);
                        $f_cs_prov = str_replace (",", ".", $f_cs_prov);
                        $f_cs_markup_prov = str_replace (",", ".", $f_cs_markup_prov);
                        $defaultFields = array("cs_eid",$f_cs_eid,"csc_id_payer",$g_csc_id,"cs_id_parent",$g2_cs_id,"cs_discount",$f_cs_discount,"cs_invmode",$f_cs_invmode,"cs_jbstatusmail2csc",$f_cs_jbstatusmail2csc,"cs_jbstatusmail_price", $f_cs_jbstatusmail_price,"cs_jbstatusmail_emp",$f_cs_jbstatusmail_emp,"cs_jbstatusmail_pdf",$f_cs_jbstatusmail_pdf,"cs_jbstatusmail_fields",$f_cs_jbstatusmail_fields,"cs_jbstatusmail",$f_cs_jbstatusmail,"cs_jbstatusmail2",$f_cs_jbstatusmail2,"cs_jbstatusmail3",$f_cs_jbstatusmail3,"cs_jb_jam_waittime",$f_cs_jb_jam_waittime,"cs_jb_jam_waittime_minutes",$f_cs_jb_jam_waittime_minutes,"cs_commission_no",$f_cs_commission_no,"cs_cr_fav_only",$f_cs_cr_fav_only,"cs_jobbatch",$f_cs_jobbatch,"cs_jbedit",$f_cs_jbedit,"cs_ar",$f_cs_ar,"cs_invtext_mode",$f_cs_invtext_mode,"cs_fixprice_discount",$f_cs_fixprice_discount,"cs_prov",$f_cs_prov,"cs_markup",$f_cs_markup, "cs_markup_prov", $f_cs_markup_prov, "cs_price_warn_uncomplete", $f_cs_price_warn_uncomplete, "cs_joblist_disabled", $f_cs_joblist_disabled, "cs_charging_time", $f_cs_charging_time, "cs_blur_markup_time", $f_cs_blur_markup_time, "cs_payment_term", $f_cs_payment_term);
                        updateStmt("customer","cs_id",$v_cs_id,$defaultFields);
            
                        // Update user
                        $defaultFields = array("usr_name",$f_usr_name,"usr_firstname",$f_usr_firstname,"usr_email",$f_usr_email,"usr_inv_email",$f_usr_inv_email,"usr_reminder_email",$f_usr_reminder_email,"usr_phone",$f_usr_phone,"usr_phone2",$f_usr_phone2,"usr_fax",$f_usr_fax,"usr_account",$f_usr_account);
                        updateStmt("user","usr_id",$v_usr_id,$defaultFields);

                        // Update user, only password-field
                        if ($cpfs == "1") :
                           $sqlStmtPwd = "UPDATE user SET usr_password = PASSWORD('" . $f_usr_password . "'), usr_password_modify = '" . $currentTime . "' WHERE usr_id = '" . $v_usr_id . "'";
                           $res = $db->query($sqlStmtPwd);
                           if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif;                        
                        endif;
                        if (trim($f_usr_account) == "") :
                           $sqlStmtPwd = "UPDATE user SET usr_password = '' WHERE usr_id = '" . $v_usr_id . "'";
                           $res = $db->query($sqlStmtPwd);
                           if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif;                           
                        endif;
               
                        // Insert address
                        $tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
                        $ad_id_new = $tmpArray[0];
                
                        // Update (the new) company-entry with address-id
                        updateStmt("company", "cmp_id", $companyId, array("ad_id", $ad_id_new));
                                              
                        // * Perhaps also change the name of the root-costcenter! But think of changing all
                        // * path-entries, too!!! PRESENTLY IT IS NOT NECESSARY TO IMPLEMENT!
                        // Update costcenter
                        // $defaultFields = array("csc_name",$f_cmp_comp);
                        // updateStmt("costcenter","csc_id",$v_csc_id,$defaultFields);


                        // Update costcenter addresses if requested
                        // Only root costcenter addresses
                        if ($f_ad_changemode == "1") :
                           if ($changeBeneficiaryAddress) :
                              updateStmt("costcenteraddress","csc_id",$v_csc_id,array("ad_id", $ad_id_new, "cscad_hsno", $f_cmp_hsno),"adt_id = 1");
                           endif;
                           if ($changeInvoiceAddress) :
                              updateStmt("costcenteraddress","csc_id",$v_csc_id,array("ad_id", $ad_id_new, "cscad_hsno", $f_cmp_hsno),"adt_id = 2");
                           endif;
                           if ($changePickUpAddress) :
                              updateStmt("costcenteraddress","csc_id",$v_csc_id,array("ad_id", $ad_id_new, "cscad_hsno", $f_cmp_hsno),"adt_id = 4");
                           endif;
                        endif;
                        // ALL costcenter addresses
                        if ($f_ad_changemode == "2") :
                           // First get all costcenters of the current customer
                           $sqlquery = "SELECT csc.csc_id FROM costcenter AS csc WHERE csc.cs_id = " . $v_cs_id;
                           $result = $db->query($sqlquery);
                           if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
                           $cscIdArray = array();
                           while ($row = $result->fetch_assoc()):
                                 $cscIdArray[] = $row["csc_id"];
                           endwhile;
                           $result->free();
                           if (count($cscIdArray) > 0) :
                              if ($changeBeneficiaryAddress) :
                                 $sqlStmtAdress = "UPDATE costcenteraddress SET ad_id = '" . $ad_id_new . "', cscad_hsno = '" . $f_cmp_hsno . "'"
                                                 . " WHERE adt_id = '1' AND csc_id IN (" . implode($cscIdArray, ",") . ")";
                                 $res = $db->query($sqlStmtAdress);
                                 if (DB::isError($res)) die ("$PHP_SELF: <br>$sqlStmt<br>" . $res->getMessage());
                              endif;
                              if ($changeInvoiceAddress) :
                                 $sqlStmtAdress = "UPDATE costcenteraddress SET ad_id = '" . $ad_id_new . "', cscad_hsno = '" . $f_cmp_hsno . "'"
                                                 . " WHERE adt_id = '2' AND csc_id IN (" . implode($cscIdArray, ",") . ")";
                                 $res = $db->query($sqlStmtAdress);
                                 if (DB::isError($res)) die ("$PHP_SELF: <br>$sqlStmt<br>" . $res->getMessage());
                              endif;
                              if ($changePickUpAddress) :
                                 $sqlStmtAdress = "UPDATE costcenteraddress SET ad_id = '" . $ad_id_new . "', cscad_hsno = '" . $f_cmp_hsno . "'"
                                                 . " WHERE adt_id = '4' AND csc_id IN (" . implode($cscIdArray, ",") . ")";
                                 $res = $db->query($sqlStmtAdress);
                                 if (DB::isError($res)) die ("$PHP_SELF: <br>$sqlStmt<br>" . $res->getMessage());
                              endif;
                           endif;
                        endif;

                        // Update costcenter company names if requested
                        // Only root costcenter company name
                        if ($f_cmp_changemode == "1") :
                           if ($changeBeneficiaryCompany) :
                              updateStmt("costcenteraddress","csc_id",$v_csc_id,array("cscad_comp", $f_cmp_comp, "cscad_comp2", $f_cmp_comp2, "cscad_comp3", $f_cmp_comp3, "cscad_comp4", $f_cmp_comp4),"adt_id = 1");
                           endif;
                           if ($changeInvoiceCompany) :
                              updateStmt("costcenteraddress","csc_id",$v_csc_id,array("cscad_comp", $f_cmp_comp, "cscad_comp2", $f_cmp_comp2, "cscad_comp3", $f_cmp_comp3, "cscad_comp4", $f_cmp_comp4),"adt_id = 2");
                           endif;
                           if ($changePickUpCompany) :
                              updateStmt("costcenteraddress","csc_id",$v_csc_id,array("cscad_comp", $f_cmp_comp, "cscad_comp2", $f_cmp_comp2, "cscad_comp3", $f_cmp_comp3, "cscad_comp4", $f_cmp_comp4),"adt_id = 4");
                           endif;
                        endif;
                        // ALL costcenter addresses
                        if ($f_cmp_changemode == "2") :
                           // First get all costcenters of the current customer
                           $sqlquery = "SELECT csc.csc_id FROM costcenter AS csc WHERE csc.cs_id = " . $v_cs_id;
                           $result = $db->query($sqlquery);
                           if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
                           $cscIdArray = array();
                           while ($row = $result->fetch_assoc()):
                                 $cscIdArray[] = $row["csc_id"];
                           endwhile;
                           $result->free();
                           if (count($cscIdArray) > 0) :
                              if ($changeBeneficiaryCompany) :
                                 $sqlStmtAdress = "UPDATE costcenteraddress SET cscad_comp = '" . $f_cmp_comp . "', cscad_comp2 = '" . $f_cmp_comp2 . "', cscad_comp3 = '" . $f_cmp_comp3 . "', cscad_comp4 = '" . $f_cmp_comp4 . "'"
                                                 . " WHERE adt_id = '1' AND csc_id IN (" . implode($cscIdArray, ",") . ")";
                                 $res = $db->query($sqlStmtAdress);
                                 if (DB::isError($res)) die ("$PHP_SELF: <br>$sqlStmt<br>" . $res->getMessage());
                              endif;
                              if ($changeInvoiceCompany) :
                                 $sqlStmtAdress = "UPDATE costcenteraddress SET cscad_comp = '" . $f_cmp_comp . "', cscad_comp2 = '" . $f_cmp_comp2 . "', cscad_comp3 = '" . $f_cmp_comp3 . "', cscad_comp4 = '" . $f_cmp_comp4 . "'"
                                                 . " WHERE adt_id = '2' AND csc_id IN (" . implode($cscIdArray, ",") . ")";
                                 $res = $db->query($sqlStmtAdress);
                                 if (DB::isError($res)) die ("$PHP_SELF: <br>$sqlStmt<br>" . $res->getMessage());
                              endif;
                              if ($changePickUpCompany) :
                                 $sqlStmtAdress = "UPDATE costcenteraddress SET cscad_comp = '" . $f_cmp_comp . "', cscad_comp2 = '" . $f_cmp_comp2 . "', cscad_comp3 = '" . $f_cmp_comp3 . "', cscad_comp4 = '" . $f_cmp_comp4 . "'"
                                                 . " WHERE adt_id = '4' AND csc_id IN (" . implode($cscIdArray, ",") . ")";
                                 $res = $db->query($sqlStmtAdress);
                                 if (DB::isError($res)) die ("$PHP_SELF: <br>$sqlStmt<br>" . $res->getMessage());
                              endif;
                           endif;
                        endif;                        

                        // Write logdata into log database
                        writeToLogDB("36",$hq_id,"",$usr_id,"","",$v_cs_id,"STATUS_MODIFIED=" . $logString);

                        // Tracking
                        if ($f_cmp_type != "0") :
                           $f_cs_tracking = "0";  // Overwrite if state is changed
                        endif;
                        updateStmt("customer","cs_id",$v_cs_id,array("cs_tracking", $f_cs_tracking));

                        // Write to "servicepricehistory"
                        if ($csPriceFieldsCurrent[0] != $f_cs_discount) :
                            insertStmt("servicepricehistory", array("srvprch_obj_type","cs", "srvprch_obj_id", $v_cs_id, "srvprch_fieldname", "cs_discount", "srvprch_price", $f_cs_discount, "srvprch_validfrom", $currentTime));
                        endif;
                        if ($csPriceFieldsCurrent[1] != $f_cs_prov) :
                            insertStmt("servicepricehistory", array("srvprch_obj_type","cs", "srvprch_obj_id", $v_cs_id, "srvprch_fieldname", "cs_prov", "srvprch_price", $f_cs_prov, "srvprch_validfrom", $currentTime));
                        endif;
                        if ($csPriceFieldsCurrent[2] != $f_cs_markup_prov) :
                            insertStmt("servicepricehistory", array("srvprch_obj_type","cs", "srvprch_obj_id", $v_cs_id, "srvprch_fieldname", "cs_markup_prov", "srvprch_price", $f_cs_markup_prov, "srvprch_validfrom", $currentTime));
                        endif;

                        // Generate report entry
                        if ($f_cmp_current_type != $f_cmp_type) :

                           // First get user id of the sales employee created this customer dataset
                           $usr_id_type = $db->getOne("SELECT usr_id FROM phoenix_log.log WHERE logo_id = 95 AND cs_id = " . $v_cs_id . " AND logo_description LIKE '%|OLD=|%'");

                           $tmpReportText = getLngt("Änderung in") . " " . $pageTitel;
                           $tmpRpReportType = getParameterValue("0", "CS_CMPTYPE2RPTYPE_MODIFY", "0");
                           if ($tmpRpReportType == "") : $tmpRpReportType = "1"; endif;
                           if ($f_cmp_type == "0") :
                              $tmpRpReportType = getParameterValue("0", "CS_CMPTYPE2RPTYPE_MODIFY_2", "0");
                              if ($tmpRpReportType == "") : $tmpRpReportType = "2"; endif;
                           endif;
                           insertStmt("phoenix_group.report_process", array("usr_id", $usr_id, "hq_id", $hq_id, "rp_reporttype", $tmpRpReportType, "rp_text", $tmpReportText,
                                                                            "rp_createtime", $currentTime, "rp_objId", $v_cs_id, "rp_objtype", "cs"));

                           // Set special date if data row is set to "customer state"
                           if ($f_cmp_type == "0") :
                              $currentDate = getDateTime("3");
                              updateStmt("customer","cs_id",$v_cs_id,array("cs_become_cs_date", $currentDate));
                           endif;

                           // Write SALES logdata into log database
                           writeToLogDB("95",$hq_id,"",$usr_id_type,"","",$v_cs_id,"SRC=cs|OLD=" . $f_cmp_current_type . "|NEW=" . $f_cmp_type);
                        endif;
                        $f_cmp_current_type = $f_cmp_type;

                        TA("C");
                        TA("E");

                        $dbOperationCompleted = "1";

                        // Check according to personal embargo
                        // (NOT included in transaction)
                        $constDPFCustomerEnabled = getParameterValue("0", "DPF_CS_ENABLED", "0");  // "Meta-Global" <=> hq_id = 0
                        if ($constDPFCustomerEnabled == '1') :
                           $execEmbargoCheck = "1";
                           $cmpId = $companyId;
                           $eid = $f_cs_eid;
                           $usrName = $f_usr_name;
                           $usrFirstname = $f_usr_firstname;
                           $adStreet = $f_ad_street;
                           $cmpHsno = $f_cmp_hsno;
                           $adZipcode = $f_ad_zipcode;
                           $adCity = $f_ad_city;
                           // = $f_ad_country;

                           // Check for DPF checksum
                           $oldDpfChecksum = getFieldValueFromId("company", "cmp_id", $companyId, "cmp_dpf_checksum");
                           $newDpfChecksum = md5($usrFirstname . $usrName . $adStreet . $cmpHsno . $adZipcode . $adCity);
                           if ($oldDpfChecksum == $newDpfChecksum) :
                              $execEmbargoCheck = "0";
                           else :
                              updateStmt("company", "cmp_id", $companyId, array("cmp_dpf_checksum", $newDpfChecksum));
                           endif;
                        endif;


                        // ********** GDC **********
                        
                        // Old EID
                        $tmpCsEidOld = getFieldValueFromClause("genericdatacontainer","gdc_content","gdc_obj_type = 'cs' AND gdc_gen_fieldname = 'eid_old' AND gdc_obj_id = '" . $v_cs_id . "'");
                        if ($tmpCsEidOld != "" || $f_cs_eid_old != "") :                        
                           if (existsEntry("genericdatacontainer", array("gdc_obj_type", "cs", "gdc_gen_fieldname", "eid_old", "gdc_obj_id", $v_cs_id))) :
                              updateStmt("genericdatacontainer","gdc_obj_type","cs",array("gdc_content", $f_cs_eid_old, "gdc_context", $currentTime),"gdc_obj_id = '" . $v_cs_id . "' AND gdc_gen_fieldname = 'eid_old'");
                           else :
                              insertStmt("genericdatacontainer", array("gdc_obj_type", "cs", "gdc_obj_id", $v_cs_id, "gdc_gen_fieldname", "eid_old", "gdc_content", $f_cs_eid_old, "gdc_context", $currentTime));
                           endif;
                        endif;

                        // ********** PARAMETER **********

                        // Flag for configuration regarding "display station number"
                        if (mcChkValOrArrCountIsEmpty($f_cs_par_tr_sort)) :
                           $f_cs_par_tr_sort = "0";
                        else: 
                           $f_cs_par_tr_sort = "1";
                        endif;
                        setParameterValue("JOBDETAILS_STATIONS_STATION_NUMBER_" . $v_cs_id, $f_cs_par_tr_sort);

                        // Flag for color of the jobs in job lists
                        if (mcChkValOrArrCountIsEmpty($f_cs_par_order_color)) :
                           $f_cs_par_order_color = "FFFFFF";
                        endif;
                        if ($f_cs_par_order_color != "FFFFFF" || ($f_cs_par_order_color == "FFFFFF" && existsEntry("parameter",array("par_key","JOBLIST_CS_JB_COLOR_" . $v_cs_id)))) :
                           setParameterValue("JOBLIST_CS_JB_COLOR_" . $v_cs_id, $f_cs_par_order_color);
                        endif;

                        // Flag for NOT displaying jobs in job lists
                        if (mcChkValOrArrCountIsEmpty($f_cs_par_xxxxxxxx)) :
                           $f_cs_par_xxxxxxxx = "0";
                        else: 
                           $f_cs_par_xxxxxxxx = "1";
                        endif;
                        setParameterValue("CUSTOMER_MASK_JOBLIST_XXXXXXXXXX_" . $v_cs_id, $f_cs_par_xxxxxxxx);

                        // Flag for job cancellation by customer
                        if (mcChkValOrArrCountIsEmpty($f_cs_jb_storno)) :
                           $f_cs_jb_storno = "0";
                        else: 
                           $f_cs_jb_storno = "1";
                        endif;
                        setParameterValue("CUSTOMER_MASK_JOBLIST_CANCELLATION_ENABLED_" . $v_cs_id, $f_cs_jb_storno);

                        // Flag for job disposition to favoured couriers by customer
                        if (mcChkValOrArrCountIsEmpty($f_cs_jb_dispo)) :
                           $f_cs_jb_dispo = "0";
                        else: 
                           $f_cs_jb_dispo = "1";
                        endif;
                        setParameterValue("CUSTOMER_MASK_JOBLIST_DISPO_FAV_ENABLED_" . $v_cs_id, $f_cs_jb_dispo);

                        // Flag for making standard price in customer login
                        if (mcChkValOrArrCountIsEmpty($f_cs_par_dont_make)) :
                           $f_cs_par_dont_make = "0";
                        else: 
                           $f_cs_par_dont_make = "1";
                        endif;
                        setParameterValue("MASK_CS_DONT_MAKE_STANDARD_PRICE_" . $v_cs_id, $f_cs_par_dont_make);

                        // Flag for calculator has to be a must for jobs of the customer
                        if (mcChkValOrArrCountIsEmpty($f_cs_par_calc_usage)) :
                           $f_cs_par_calc_usage = "0";
                        else: 
                           $f_cs_par_calc_usage = "1";
                        endif;
                        setParameterValue("CUSTOMER_MASK_CALCULATOR_USAGE_ONLY_" . $v_cs_id, $f_cs_par_calc_usage);

                        // Flag for not checking address in KAE
                        if ($f_cs_par_cst_all_ad == "" || count($f_cs_par_cst_all_ad) == 0) :
                           $f_cs_par_cst_all_ad = "0";
                        else: 
                           $f_cs_par_cst_all_ad = "1";
                        endif;
                        setParameterValue("MASK_CUST_ALL_ADDR_ENABLED_" . $v_cs_id, $f_cs_par_cst_all_ad);

                        // Flag for emails to avoid sending the footer
                        if (mcChkValOrArrCountIsEmpty($f_cs_par_email_no_footer)) :
                           $f_cs_par_email_no_footer = "0";
                        else: 
                           $f_cs_par_email_no_footer = "1";
                        endif;
                        setParameterValue("JOBDETAILS_EMAIL_NO_FOOTER_" . $v_cs_id, $f_cs_par_email_no_footer);

                        // Flag for customer to get a discount by self-creating jobs
                        if (mcChkValOrArrCountIsEmpty($f_cs_jb_creator_discount)) :
                           $f_cs_jb_creator_discount = "0";
                        else: 
                           $f_cs_jb_creator_discount = "1";
                        endif;
                        setParameterValue("CUSTOMER_MASK_JB_CREATOR_DISCOUNT_" . $v_cs_id, $f_cs_jb_creator_discount);
                      
                        // Email arrival time
                        if ($f_cs_par_email_arrivaltime != "" && is_numeric($f_cs_par_email_arrivaltime)) :
                           // Check existence of parameter entry to avoid a parameter for each (new) customer if no arrivaltime will be displayed (!!!!)
                           $tmpEmailArrTime = getParameterValue("0", "JOB_MAIL_STATION_ARRIVAL_TIME_" . $v_cs_id, "0");
                           if ($f_cs_par_email_arrivaltime != "0" || $tmpEmailArrTime != "") :
                              setParameterValue("JOB_MAIL_STATION_ARRIVAL_TIME_" . $v_cs_id, $f_cs_par_email_arrivaltime);
                           endif;
                        endif;

                        // Email language
                        if ($f_cs_par_email_lng != "" && is_numeric($f_cs_par_email_lng)) :
                           // Check existence of parameter entry to avoid a parameter for each (new) if language is default language (!!!!)
                           $tmpEmailLng = getParameterValue("0", "JOBDETAILS_EMAIL_LANGUAGE_" . $v_cs_id, "0");
                           if ($f_cs_par_email_lng != "0" || $tmpEmailLng != "") :
                              setParameterValue("JOBDETAILS_EMAIL_LANGUAGE_" . $v_cs_id, $f_cs_par_email_lng);
                           endif;
                        endif;

                        // Flag for customer to set job being incomplete by creating or modifying a job
                        if (mcChkValOrArrCountIsEmpty($f_cs_jb_incomplete)) :
                           $f_cs_jb_incomplete = "0";
                        else: 
                           $f_cs_jb_incomplete = "1";
                        endif;
                        setParameterValue("CUSTOMER_MASK_JB_INCOMPLETE_" . $v_cs_id, $f_cs_jb_incomplete);

                        // Photos
                        setCsPhotoConf($v_cs_id, $f_cs_photo_disabled, $f_cs_photo_hq, $f_cs_photo_cs, $f_cs_photo_range_from, $f_cs_photo_range_to);

                     else :
                       $statusMessage = getLngt("Die Postleitzahl passt nicht zu dem angegebenen Ort!");
                       $addressValidationErr = "1";
                     endif;
                  
                  else :
                    $statusMessage = getLngt("Der Adress-Server kennt die eingebene Adresse nicht oder besitzt keine Geocodierung!");
                  endif;               
                  
               endif;
               
            else : 
               $statusMessage = getLngt("Datenfehler! Merken Sie sich bitte den Datensatz und kontaktieren uns!!!");
            endif;
          endif;  // account empty or not empty and checked by passwordcheck
         endif;        
      else :
         $statusMessage = getLngt("Bitte geben Sie alle mit * gekennzeichneten Felder ein!");
      endif;                                                            
   endif;
   
   // Delete customer
   if ($f_act == "removeCustomer" && $companyId != "") :
      if (!existsEntry("company",array("cmp_id",$companyId))) :
         // if (getDbFieldValues("employee",array("usr_id"),array("emp_id",$emp_id_act))) :
         //   TA("B");
         //   deleteStmt("employee","emp_id = ".$emp_id_act);
         //   deleteStmt("user","usr_id = ".$usr_id_new);
         
         //   // Write logdata into log database
         //   $v_cs_id = getFieldValueFromId("customer", "cmp_id", $companyId, "cs_id");
         //   writeToLogDB("42",$hq_id,"",$usr_id,"","",$v_cs_id,"STATUS_DELETED");
         
         //   TA("C");
         //   TA("E");
         // else : 
         //   $statusMessage = "Datenfehler! Merken Sie sich bitte den Datensatz und kontaktieren uns!!!";
         // endif;
      else :
         $statusMessage = getLngt("Der Kunde existiert nicht!");
      endif;
   endif;  
      
   // Set status of authentication of the customer
   if ($f_act == "setAuthentication") :

      // Check for company
      if ($companyId != "") :

         if (existsEntry("company",array("cmp_id",$companyId))) :

            // Check for existing jobs in the future
            $futureJobListStr = "";
            if ($f_cmp_authenticated != "1") :
               $futureJobList = getColVectorFromDB2ArrayByClause("company AS cmp, customer AS cs, costcenter AS csc, job AS jb", "jb.jb_id", "cmp.cmp_id = '" . $companyId . "' AND cmp.cmp_id = cs.cmp_id AND cs.cs_id = csc.cs_id AND csc.csc_id = jb.csc_id_payer AND jb.jb_status != '2' AND jb.jb_finishtime > DATE_SUB(NOW(), INTERVAL 1 MONTH)");
               if (count($futureJobList) > 0) :
                  $futureJobListStr = implode(",", $futureJobList);
               endif;
            endif;

            if ($f_cmp_authenticated == "1" || $futureJobListStr == "") :
            
               // Check in case the courier shall be set free but he/she is noticeable according to embargo check
               $currentDPFState = getFieldValueFromId("company", "cmp_id", $companyId, "cmp_dpf_state");
               if ($f_cmp_authenticated == "1" && $currentDPFState >= "1" && $currentDPFState <= "9") :
                  // Update DPF state 
                  // Attention: Description of the states look for "dpf.php"
                  $newDPFState = $currentDPFState + 10;
                  updateStmt("company","cmp_id",$companyId,array("cmp_dpf_state",$newDPFState));
               endif;
               
               // Update authentication-status
               updateStmt("company","cmp_id",$companyId,array("cmp_authenticated",$f_cmp_authenticated));
               
               // Write logdata into log database
               $v_cs_id = getFieldValueFromId("customer", "cmp_id", $companyId, "cs_id");
               writeToLogDB("38",$hq_id,"",$usr_id,"","",$v_cs_id,"STATUS_AUTHENTICATION=".$f_cmp_authenticated);
            else :
               $statusMessage = getLngt("Der spezifizierte Kunde kann noch nicht gesperrt werden. Es existieren noch die folgenden zukünftigen Aufträge: " . $futureJobListStr);
            endif;
         else :               
            $statusMessage = getLngt("Der spezifizierte Kunde ist nicht im Datenbestand erhalten!");
         endif;      
      else :
         $statusMessage = getLngt("Sie haben keinen Kunden spezifiziert!");
      endif;
   endif;
   
   // Set status of visibility of the customer
   if ($f_act == "setVisibility") :

      // Check for company
      if ($companyId != "") :

         if (existsEntry("company",array("cmp_id",$companyId))) :

            // Update authentication-status
            updateStmt("company","cmp_id",$companyId,array("cmp_visible",$f_cmp_visible));

            // Write logdata into log database
            $v_cs_id = getFieldValueFromId("customer", "cmp_id", $companyId, "cs_id");
            writeToLogDB("40",$hq_id,"",$usr_id,"","",$v_cs_id,"STATUS_VISIBILITY=".$f_cmp_visible);
         else :               
            $statusMessage = getLngt("Der spezifizierte Kunde ist nicht im Datenbestand erhalten!");
         endif;      
      else :
         $statusMessage = getLngt("Sie haben keinen Kunden spezifiziert!");
      endif;
   endif;   
   
   // Set status of cash mode of the customer
   if ($f_act == "setCashmode") :

      // Check for company
      if ($companyId != "") :

         if (existsEntry("company",array("cmp_id",$companyId))) :

            // Update authentication-status
            updateStmt("company","cmp_id",$companyId,array("cmp_cashmode",$f_cmp_cashmode));
            
            // Write logdata into log database
            $v_cs_id = getFieldValueFromId("customer", "cmp_id", $companyId, "cs_id");
            writeToLogDB("44",$hq_id,"",$usr_id,"","",$v_cs_id,"STATUS_CASHMODE=".$f_cmp_cashmode);
         else :               
            $statusMessage = getLngt("Der spezifizierte Kunde ist nicht im Datenbestand erhalten!");
         endif;      
      else :
         $statusMessage = getLngt("Sie haben keinen Kunden spezifiziert!");
      endif;
   endif;
   
   // Set state of completition of all current jobs of the customer
   if ($f_act == "setJobCompleteMulti") :

      // Check for company
      if ($companyId != "") :

         if (existsEntry("company",array("cmp_id",$companyId))) :
            $v_cs_id = getFieldValueFromId("customer", "cmp_id", $companyId, "cs_id");

            // Select all incomplete jobs of the customer to be set to state "complete"
            $jbSqlquery = "SELECT jb.jb_id"
                        . " FROM customer AS cs, costcenter AS csc, job AS jb"
                        . " WHERE cs.cs_id = '" . $v_cs_id . "' AND cs.cs_id = csc.cs_id AND csc.csc_id = jb.csc_id_payer AND"
                        . "       jb.jb_status = '2' AND jb.cr_sid != '' AND jb.cr_id != '' AND jb.jb_totalprice != 0 AND"
                        . "       vht_id != '0' AND jb.jb_incomplete = '1' AND "
                        . "       (ISNULL(jb.jb_storno) OR jb.jb_storno = '0') AND "
                        . "       jb.jb_finishtime > '" . getDateTime("date_plus_offset", array(-1,0,0), "Y-m-d") . " 00:00:00' AND"
                        . "       (ISNULL(jb.jb_export_time) OR jb.jb_export_time = '0000-00-00 00:00:00')";

            $result = $db->query($jbSqlquery);
            if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
            $tmpJbArray = array();
            while ($row = $result->fetch_assoc()):
                  $tmpJbArray[] = $row["jb_id"];
            endwhile;

            // Update completition state
            $tmpJbString = "";
            $tmpJbArrayLen = count($tmpJbArray);
            if ($tmpJbArrayLen > 0) :
               $tmpJbString = implode(",",$tmpJbArray);

               updateStmt("job","","",array("jb_incomplete","0"),"jb_id IN (" . $tmpJbString . ")");

               $statusMessage = getLngt("Anzahl der Aufträge: " . $tmpJbArrayLen);
            else :
               $statusMessage = getLngt("Es wurde kein Auftrag gegriffen und auf fertig gesetzt!");
            endif;

            // Write logdata into log database            
            writeToLogDB("94",$hq_id,"",$usr_id,"","",$v_cs_id,"JOBS=".$tmpJbString);
         else :               
            $statusMessage = getLngt("Der spezifizierte Kunde ist nicht im Datenbestand erhalten!");
         endif;      
      else :
         $statusMessage = getLngt("Sie haben keinen Kunden spezifiziert!");
      endif;
   endif;

   // Send sustainability report to the customer
   if ($f_act == "sendSustainabilityReport") :

      // Check for company
      if ($companyId != "") :
      
         if (existsEntry("company",array("cmp_id",$companyId))) :
   
            $v_cs_id = getFieldValueFromId("customer", "cmp_id", $companyId, "cs_id");
   
            $csIsMeta = false;
            $tmpCsIdsSub = getColVectorFromDB2ArrayByClause("customer", "cs_id", "cs_id_parent = '" . $v_cs_id . "'");
            if (count($tmpCsIdsSub) > 0) :
               $csIsMeta = true;
            endif;

            // Call script for (meta-)customer
            $path = getAbsoluteSystemPath();
            $passwd = "acapella7890";            
            $cmd = "php " . $path . "/tools/auto_trigger_jobs_sustainability_customer_report.php " . $passwd . " " . ($csIsMeta ? "cs_meta" : "cs") . " " . $v_cs_id . " " . $f_cmp_sustainability_interval . " &";
            $cmdOutput = null;
            exec($cmd, $cmdOutput);
// print_r($cmdOutput); echo "\n\n";

            // Write logdata into log database            
            writeToLogDB("176",$hq_id,"",$usr_id,"","",$v_cs_id,"EMAIL SENT");
         else :               
            $statusMessage = getLngt("Der spezifizierte Kunde ist nicht im Datenbestand erhalten!");
         endif;      
      else :
         $statusMessage = getLngt("Sie haben keinen Kunden spezifiziert!");
      endif;
   endif;

   // Reset 2-FA
   if ($f_act == "reset2FACustomer") :

      // Check for company
      if ($companyId != "") :

         if (existsEntry("company",array("cmp_id",$companyId))) :

            $v_cs_id = getFieldValueFromId("customer", "cmp_id", $companyId, "cs_id");
            $retVal = user2FARemove($v_cs_id, "cs");
            
            $statusMessage = $retVal[1];
         else :               
            $statusMessage = getLngt("Der spezifizierte Kunde ist nicht im Datenbestand erhalten!");
         endif;      
      else :
         $statusMessage = getLngt("Sie haben keinen Kunden spezifiziert!");
      endif;
   endif;


   // **********************************
   // * Selection of the customer data *
   // **********************************   
   // Gets ALL data from a special customer
   getCustomer($companyId);


   // Get max-value of the EID of the current customer for inserting a new row 
   // The constant value "CS_EID_GENERATION" contains the prefix of the SID [SPECIAL TREATMENT]
   $f_eid_maxval = "";
   // $csEidGeneration = getParameterValue("0", "CS_EID_GENERATION");
   if (CS_EID_GENERATION != "") :
      $f_eid_maxval = getMaxOfField("customer", "cs_eid", "cs_eid < '" . CS_EID_GENERATION . "'");
      if (is_numeric($f_eid_maxval)) :
         ++$f_eid_maxval;   // Increment because of the next free EID (Attention: Not TA-safe!)
      else :
        // Remove alphanumeric chars (e.g "HTHB123456" => "123456")
        $prefixChars = ereg_replace("[^[:alpha:]+]","",$f_eid_maxval);
        $f_eid_maxval = ereg_replace("[^[:digit:]+]","",$f_eid_maxval);
        ++$f_eid_maxval;
        $f_eid_maxval = $prefixChars . $f_eid_maxval;
      endif;
   endif;

   // Get number of contacts of the current customer
   $numOfContacts = getCountOfTable("metafieldvalue AS mtfv, metafieldcategorykey AS mtfck, metafieldkey AS mtfk", 
                                    "mtfv.mtfv_value = '" . $f_cs_id . "' AND mtfck.mtfc_id = '1' AND mtfv.mtfck_id = mtfck.mtfck_id AND mtfk.mtfk_id = mtfck.mtfk_id AND mtfk.mtfk_type = 'co2cs'");

   // Check if a copy of the current customer is requested. 
   // If it is then reset some values
   if ($copyCs == "1") :
      $companyId = "";
      $f_cs_eid = "";
      $statusMessage = getLngt("ACHTUNG: Aus Sicherheitsgründen werden ausschließlich Daten des Stammblatts kopiert! Filter, Services, Kostenstellen, etc. sind entsprechend nachträglich zuzuweisen!");
      
      // Special case for third party payer
      $constCsCopyNoThirdParty = getParameterValue("0", "CS_COPY_NO_THIRD_PARTY", $hq_id);
      if ($constCsCopyNoThirdParty == "1") :
         $g_csc_id = "";
         $g_cs_id = "";
         $g_cscad_comp = "";
         $statusMessage .= " " . getLngt("Der Drittzahler wurde ebenfalls entfernt!");
      endif;
   endif;

   if ($companyId != "") :
// YYYYYYYYYYYYYYYYYYYYYYYYYY      
   endif;

   // Only for output
   $pageHeadline = getLngt("NEUER KUNDE");
   $title = "<div><span class=\"f8np1\">" . getLngt("Typ:") . "</span> &nbsp;<select class=\"f8np1\" name=\"f_cmp_type\">" . addOptionsFromTable("metatype","mt_sort","mt_value","mt_sort","mt_type = 'customer_type'",$f_cmp_current_type) . "</select></div>";
   $title2 = $pageHeadline;

   $leftColWidth = "140px";

   $buttonContacts = ""; 
   $buttonAppointments = ""; 
   $buttonDocuments = "";

   $buttonCourier = "";
   $buttonAuthentication = "";
   $buttonVisibility = "";
   $buttonCashmode = "";
   $buttonGroup = "";
   $buttonContact = "";
   $buttonPage2 = "";
   $buttonCopyCustomer = "";
   $buttonJobComplete = "";
   $displayTextAuthentication = "";
   $displayTextVisibility = "";
   $confirmTextAuthentication = "";
   $confirmTextVisibility = "";
   $confirmTextCashmode = "";   
   $serviceLink1 = "";
   $serviceLink2 = "";
   $serviceLink3 = "";
   $serviceLink4 = "";
   $buttonFilter = "";
   $buttonService = "";
   $buttonReport = "";
   $buttonCostcenter = "";
   $buttonCsHistory = "";
   $buttonReset2FA = "";
   
   if ($companyId != "") :
      $pageHeadline = ($f_cmp_type > "0" ? "<span class=\"f12bp1_red\">" . $pageTitel . "</span>" : "<span class=\"f12bp1_blue\">" . $pageTitel . "</span>") . " &nbsp;&nbsp;&nbsp;&nbsp;" . substr($f_cmp_comp . " " . $f_cmp_comp2, 0, 100);
      $title = "";
      $title2 = substr($f_cmp_comp . " " . $f_cmp_comp2, 0, 100);

      // Show mandator
      if (authCheckEmployeeRights($emp_id, "10")) :

         // Name of the headquarter
         $hq_name = getFieldValueFromId("headquarters", "hq_id", $f_cs_hq_id, "hq_name");
         $pageHeadline .= "&nbsp;&nbsp;&nbsp;&nbsp;" . "[" . $hq_name . "]";
      endif;      

      // Type of the customer (customer, prospect, ...)
      // No job may be associated to the customer !!!
      if ($showCmpTypeSelection) :
         $title .= "<div style=\"float:left\">";
         $title .= "<span class=\"f8np1\">" . getLngt("Typ:") . "</span> &nbsp;<select class=\"f8np1\" name=\"f_cmp_type\">" . addOptionsFromTable("metatype","mt_sort","mt_value","mt_sort","mt_type = 'customer_type'",$f_cmp_type) . "</select>";
         $title .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
         $title .= "</div>";

         $pageHeadline .= "&nbsp;&nbsp;&nbsp;&nbsp;" . "<span class=\"f8np1\">" . getLngt("Typ:") . "</span> &nbsp;<select class=\"f8np1\" name=\"f_cmp_type\">" . addOptionsFromTable("metatype","mt_sort","mt_value","mt_sort","mt_type = 'customer_type'",$f_cmp_type) . "</select>";
      endif;

      // Parent customer
      $title .= "<div class=\"f8np1\" style=\"float:left\">" . getLngt("Übergeordneter Kunde:") . "&nbsp;&nbsp;" .
                "<input class=\"f8np1\" style=\"max-width: 10ch;\" type=\"text\" name=\"g2_cs_eid\" value=\"" . $g2_cs_eid . "\" disabled >&nbsp;" .
                "<input class=\"f8np1\" style=\"max-width: 20ch;\" type=\"text\" name=\"g2_cmp_comp\" value=\"" . $g2_cmp_comp . "\" disabled >&nbsp;&nbsp;</div>" .
                defineButtonType08("...", "action_meta", "searchCsCsc('10000000000011','2','');", "30", "left", "2") .
                "<div style=\"float:left\"><a href=\"javascript:clearParent();\" tabindex=\"\"><img src=\"../images/waste.png\" border=\"0\" height=\"15\" width=\"12\"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>";

      $importPath = "";
      if (authCheckEmployeeRights($emp_id, "11")) :
         // Number of contacts
         if (is_numeric($numOfContacts)) :
            $buttonContacts = defineButtonType10(getLngt("Kontakte") . ":&nbsp;" . $numOfContacts, "action_co", "openContacts('" . ec($f_cs_id) . "');", "200", "left", "0");
         endif;

         // Number of appointments
         $f_selUsrId = $usr_id;   // Used variable for appointments
         $f_ap_visibility_search = array("1","2","3","4","5","6","7","8");   // Used variable for appointments
         $csAppointments = getAppointmentsFromDB(getDateTime("year"), getDateTime("month"), getDateTime("day"), getDateTime("year") + 1, "12", "31", $f_cs_id);
         $numOfAppointments = count($csAppointments);
         $buttonAppointments = defineLinkButtonType10(getLngt("Termine") . ":&nbsp;" . $numOfAppointments, "action_ap_cs", "../groupware/appointment.php?viewMode=" . ec(3) . "&csSpecial=" . ec($f_cs_id), "200", "left", "0");

         // Get path for customer data (type "CS")
         if ($importPath == "") : $importPath = getFieldValueFromId("mandator","md_id",$md_id,"md_doc_path"); endif;
         $importPath = getPathForObjectData($importPath, "CS");
      endif;

      // Get number of documents for the current customer
      $csNumOfFiles = getNumOfFilesByFilterInFolder($importPath, $f_cs_eid . "_", "1");
      $buttonDocuments = defineLinkButtonType10(getLngt("Dokumente") . ":&nbsp;" . ($csNumOfFiles != "-1" ? $csNumOfFiles : "0"), "action_dt_cs", "../import/data_transfer.php?objType=cs&objId=" . ec($f_cs_id), "200", "left", "0");

      $buttonCourier = defineButtonType10(getLngt("Transporteure"), "action_cr", "openCustomerCouriers();", "120", "left", "0");
      $buttonFilter = defineButtonType10(getLngt("Filter"), "action_crf", "openCustomerFilters();", "120", "left", "0");
      $buttonService = defineButtonType10(getLngt("Services"), "action_srv", "openCustomerServices();", "120", "left", "0");
      $buttonReport = defineButtonType10(getLngt("Berichte"), "action_rp", "openCustomerReports('" . $f_cs_eid . "');", "120", "left", "0");
      $buttonCopyCustomer = defineButtonType10(getLngt("Kopie"), "action_copy", "copyCustomer();", "120", "left", "0");
      $buttonGroup = defineButtonType10(getLngt("Gruppen"), "action_grp", "openGroups('" . ec($f_cs_id) . "');", "120", "left", "0");
      $buttonContact = defineButtonType10(getLngt("Kontakte"), "action_co", "openContacts('" . ec($f_cs_id) . "');", "120", "left", "0");
      if (authCheckEmployeeRights($emp_id, "21")) :
         $buttonJobComplete = defineButtonType10(getLngt("Ausbuchen"), "action_jb", "jobCompleteFinishPage();", "120", "left", "0");
      endif;
      $buttonPage2 = defineButtonType10(getLngt("2. Seite"), "action_2ndpage", "openMetaFieldSpecial('" . ec($f_cs_id) . "');", "120", "left", "0");
      $buttonAuthentication = defineButtonType10(getLngt("Sperren"), "action_lock", "authenticationFinishPage();", "120", "left", "0");
      $confirmTextAuthentication = getLngt("Soll der Kunde wirklich gesperrt werden?");
      if ($f_cmp_authenticated != "1") : 
         $buttonAuthentication = defineButtonType10(getLngt("Freischalten"), "action_lock", "authenticationFinishPage();", "120", "left", "0");
         $displayTextAuthentication = getLngt("(gesperrt)");
         $confirmTextAuthentication = getLngt("Soll der Kunde wirklich freigeschaltet werden?");
      endif;
      
      $buttonVisibility = defineButtonType10(getLngt("Ausblenden"), "action_visible", "visibilityFinishPage();", "120", "left", "0");
      $confirmTextVisibility = getLngt("Soll der Kunde wirklich ausgeblendet werden?");
      if ($f_cmp_visible != "1") : 
         $buttonVisibility = defineButtonType10(getLngt("Einblenden"), "action_visible", "visibilityFinishPage();", "120", "left", "0");
         $displayTextVisibility = getLngt("(ausgeblendet)");
         $confirmTextVisibility = getLngt("Soll der Kunde wirklich eingeblendet werden?");
      endif;

      $buttonCashmode = defineButtonType10(getLngt("Rechnung"), "action_cashmode", "cashModeFinishPage();", "120", "left", "0");
      $confirmTextCashmode = getLngt("Soll der Kunde zukünftig wieder Rechnungen erhalten?");      
      if ($f_cmp_cashmode != "1") : 
         $buttonCashmode = defineButtonType10(getLngt("Nur&nbsp;bar"), "action_cashmode", "cashModeFinishPage();", "120", "left", "0");
         $confirmTextCashmode = getLngt("Soll der Kunde zukünftig wirklich nur barzahlen?");
      endif;
      
      $buttonCsHistory = defineButtonType10(getLngt("Änderungshistorie"), "action_cs_history", "openCsHistory('" . ec($f_cs_id) . "');", "190", "left", "0");
      $buttonReset2FA = defineButtonType10(getLngt("2FA&nbsp;zurücksetzen"), "action_2fa", "reset2FACustomerFinishPage();", "190", "left", "0", "", "", "150px");
      
      // IMPORTANT: Check if customer-admin-user-account exists, because in this case only the customer has to administrate the costcenters !!!
      if (true || $f_usr_account == "") :         
         $buttonCostcenter = defineButtonType10(getLngt("Kostenstellen"), "action_csc", "openCostcenterAdmin();", "120", "left", "0");
      endif;
      
      if (MASK_CUSTOMERDETAILS_TARGET == "1") :
         if (authCheckEmployeeRights($emp_id, "2")) :
            $serviceLink1 = "Service (Grundpreise, Kilometer, Radien, Zuschläge, Preis-/Leistungstypen): <a href=\"../admin/services.php?opener=1&mode=price&csId=" . ec($f_cs_id) . "\" target=\"_blank\">" . getLngt("Preise") . "</a>/" .
                                     "<a href=\"../admin/services.php?opener=1&mode=discount&csId=" . ec($f_cs_id) . "\" target=\"_blank\">" . getLngt("Rabatte") . "</a>\n";
            $serviceLink2 = "PLZ: <a href=\"../admin/services_plz.php?opener=1&mode=price&csId=" . ec($f_cs_id) . "\" target=\"_blank\">" . getLngt("Preise") . "</a>/" . 
                                 "<a href=\"../admin/services_plz.php?opener=1&mode=discount&csId=" . ec($f_cs_id) . "\" target=\"_blank\">" . getLngt("Rabatte") . "</a>\n";
            $serviceLink3 = "Bereiche: <a href=\"../admin/services_plz_area.php?opener=1&mode=price&csId=" . ec($f_cs_id) . "\" target=\"_blank\">" . getLngt("Preise") . "</a>/" . 
                                          "<a href=\"../admin/services_plz_area.php?opener=1&mode=discount&csId=" . ec($f_cs_id) . "\" target=\"_blank\">" . getLngt("Rabatte") . "</a>\n";
            $serviceLink4 = "\n";
         else :
            $serviceLink1 = getLngt("Service: Preise/Rabatte") . "</td>\n";
            $serviceLink2 = getLngt("PLZ: Preise/Rabatte") . "</td>\n";
            $serviceLink3 = getLngt("PLZ-Bereiche: Preise/Rabatte") . "</td>\n";
            $serviceLink4 = "\n";      
         endif;
      else :
         if (authCheckEmployeeRights($emp_id, "2")) :
            $serviceLink1 = "<td>Service: <a href=\"../admin/services.php?opener=1&mode=price&csId=" . ec($f_cs_id) . "\" target=\"_blank\">" . getLngt("Preise") . "</a>/" .
                                                             "<a href=\"../admin/services.php?opener=1&mode=discount&csId=" . ec($f_cs_id) . "\" target=\"_blank\">" . getLngt("Rabatte") . "</a></td>\n";
            $serviceLink2 = "<td>PLZ: <a href=\"../admin/services_plz.php?opener=1&mode=price&csId=" . ec($f_cs_id) . "\" target=\"_blank\">" . getLngt("Preise") . "</a>/" . 
                                                         "<a href=\"../admin/services_plz.php?opener=1&mode=discount&csId=" . ec($f_cs_id) . "\" target=\"_blank\">" . getLngt("Rabatte") . "</a></td>\n";
            $serviceLink3 = "<td>PLZ-Bereiche: <a href=\"../admin/services_plz_area.php?opener=1&mode=price&csId=" . ec($f_cs_id) . "\" target=\"_blank\">" . getLngt("Preise") . "</a>/" . 
                                                              "<a href=\"../admin/services_plz_area.php?opener=1&mode=discount&csId=" . ec($f_cs_id) . "\" target=\"_blank\">" . getLngt("Rabatte") . "</a></td>\n";
            $serviceLink4 = "<td></td>\n";
         else :
            $serviceLink1 = "<td>" . getLngt("Service: Preise/Rabatte") . "</td>\n";
            $serviceLink2 = "<td>" . getLngt("PLZ: Preise/Rabatte") . "</td>\n";
            $serviceLink3 = "<td>" . getLngt("PLZ-Bereiche: Preise/Rabatte") . "</td>\n";
            $serviceLink4 = "<td></td>\n";      
         endif;      
      endif;

      // Get current photo settings
      list($f_cs_photo_disabled, $f_cs_photo_hq, $f_cs_photo_cs, $f_cs_photo_range_from, $f_cs_photo_range_to) = getCsPhotoConf($f_cs_id); 
      // echo "<b>Fotos:</b><br>Fotofunktion deaktiviert: $f_cs_photo_disabled<br>Foto Zentrale: $f_cs_photo_hq<br>Foto KAE: $f_cs_photo_cs<br>Fotos mindestens: $f_cs_photo_range_from<br>Fotos höchstens: $f_cs_photo_range_to<br>";
   endif;
    
   // Password-fields for entering a new customer (admin-user)
   $setPasswordForNewUserOutput = "";
   $setPassword2ForNewUserOutput = "";
   $cpfs = "0";   // checkPasswordForStoring
   if ($companyId == "" || $f_usr_account == "") :
      $setPasswordForNewUserOutput = "<input class=\"f8np1\" type=\"text\" name=\"f_usr_password\" value=\"\" size=\"15\" tabindex=\"250\">\n";
      $setPassword2ForNewUserOutput = "<input class=\"f8np1\" type=\"text\" name=\"f_usr_password2\" value=\"\" size=\"15\" tabindex=\"260\">\n";
      $cpfs = "1";      
   endif;    

   // Only for output:
   // Check for updating the list
   $javaScriptOut = "myhide('f_colorpicker');";
   if ($statusMessage == "" && $f_act != "" && $dbOperationCompleted == "1" && MASK_CUSTOMER_SHOW_LIST == "1") :
      // $javaScriptOut .= "parent.admin_cs_list.finishPage('".$f_cmp_comp."','".$f_cmp_comp2."','".$f_ad_street."','".$f_ad_zipcode."','".$f_cmp_match."','".$f_cs_eid."','".$f_usr_phone."','".$f_usr_email."','".$f_cmp_comp3."','".$f_cmp_comp4."');";
      $javaScriptOut .= "parent.admin_cs_list.finishPage('".strWrapJs($f_cmp_comp)."','".strWrapJs($f_cmp_comp2)."','".strWrapJs($f_ad_street)."','".$f_ad_zipcode."','".strWrapJs($f_cmp_match)."','".$f_cs_eid."','".$f_usr_phone."','".$f_usr_email."','".$f_cmp_comp3."','".$f_cmp_comp4."');";
   endif;
   // Call embargo check
   if ($execEmbargoCheck == "1") :
      $javaScriptOut .= "openEmbargoCheck();";
   endif;
   
   $maskCloseWindowAfterNewCs = getParameterValue("0", "MASK_CS_NEW_CLOSE_WINDOW", "0");
   if ($f_act == "newCustomer" && $dbOperationCompleted == "1") :
      // Parameter to switch between closing window OR clearing form parameters after storing a new customer
      if ($maskCloseWindowAfterNewCs != "1" && $maskCloseWindowAfterNewCs != "2") :
         // Reset fields of form parameters
         clearParameters($httpVisualVars);
      // else :
      //   Close window by javascript...
      endif;
   endif;
   
   // Initialize service-mode for invoicing with global default setting
   if ($f_cs_invmode == "") : 
      // Get the general invmode for the headquarter
      $hq_invmode = getFieldValueFromId("headquarters", "hq_id", "$hq_id", "hq_invmode");
      $f_cs_invmode = $hq_invmode;
   endif;
   
   // Main invoice address of the root costcenter
   // Display output only if it´s different to main address
   // Get the ID and housenumber of the current invoice address of the root costcenter
   $outAdditionalAddresses = "";
   $outAdditionalCompanyNames = "";
   if ($f_cs_id != "") :
      $adIdRootInvoice = getFieldValueFromClause("costcenteraddress","ad_id","adt_id = '2' AND csc_id = '" . $f_csc_id . "'");
      $adHsnoRootInvoice = getFieldValueFromClause("costcenteraddress","cscad_hsno","adt_id = '2' AND csc_id = '" . $f_csc_id . "'");
      if ($adIdRootInvoice != "" && ($adIdRootInvoice != $f_ad_id || $adHsnoRootInvoice != $f_cmp_hsno)) :
         $adInvoiceFields = getFieldsValueFromId("address", "ad_id", $adIdRootInvoice, array("ad_street","ad_zipcode","ad_city","ad_country"));
         $outAdditionalAddresses .= "<input class=\"f8np1\" type=\"text\" name=\"adInvStreet\" value=\"" . $adInvoiceFields[0] . "\" size=\"56\" readonly>";
         $outAdditionalAddresses .= "<input class=\"f8np1\" type=\"text\" name=\"adInvHsno\" value=\"" . $adHsnoRootInvoice . "\" size=\"5\" readonly>";
         $outAdditionalAddresses .= "<br>";
         $outAdditionalAddresses .= "<input class=\"f8np1\" type=\"text\" name=\"adInvZipcode\" value=\"" . $adInvoiceFields[1] . "\" size=\"5\" readonly>";
         $outAdditionalAddresses .= "<input class=\"f8np1\" type=\"text\" name=\"adInvCity\" value=\"" . $adInvoiceFields[2] . "\" size=\"50\" readonly>";
         $outAdditionalAddresses .= "<input class=\"f8np1\" type=\"text\" name=\"adInvcountry\" value=\"" . $adInvoiceFields[3] . "\" size=\"3\" readonly>";
      endif;
      
      $cmpCompRootInvoice = getFieldValueFromClause("costcenteraddress","cscad_comp","adt_id = '2' AND csc_id = '" . $f_csc_id . "'");
      $cmpComp2RootInvoice = getFieldValueFromClause("costcenteraddress","cscad_comp2","adt_id = '2' AND csc_id = '" . $f_csc_id . "'");
      $cmpComp3RootInvoice = getFieldValueFromClause("costcenteraddress","cscad_comp3","adt_id = '2' AND csc_id = '" . $f_csc_id . "'");
      $cmpComp4RootInvoice = getFieldValueFromClause("costcenteraddress","cscad_comp4","adt_id = '2' AND csc_id = '" . $f_csc_id . "'");
      if (($cmpCompRootInvoice != $f_cmp_comp || $cmpComp2RootInvoice != $f_cmp_comp2 || $cmpComp3RootInvoice != $f_cmp_comp3 || $cmpComp4RootInvoice != $f_cmp_comp4)) :
         $outAdditionalCompanyNames .= "<div><input class=\"f8np1\" type=\"text\" name=\"cmpCompRootInvoice\" value=\"" . $cmpCompRootInvoice . "\" size=\"50\" readonly></div>";
         $outAdditionalCompanyNames .= "<div><input class=\"f8np1\" type=\"text\" name=\"cmpComp2RootInvoice\" value=\"" . $cmpComp2RootInvoice . "\" size=\"50\" readonly></div>";
         $outAdditionalCompanyNames .= "<div><input class=\"f8np1\" type=\"text\" name=\"cmpComp2RootInvoice\" value=\"" . $cmpComp3RootInvoice . "\" size=\"50\" readonly></div>";
         $outAdditionalCompanyNames .= "<div><input class=\"f8np1\" type=\"text\" name=\"cmpComp2RootInvoice\" value=\"" . $cmpComp4RootInvoice . "\" size=\"50\" readonly></div>";
      endif;
   endif;

  
   // ******************************************************************************************************************   

   $f_cmp_comp = strWrapHtml($f_cmp_comp);
   $f_cmp_comp2 = strWrapHtml($f_cmp_comp2);
   $f_cmp_comp3 = strWrapHtml($f_cmp_comp3);
   $f_cmp_comp4 = strWrapHtml($f_cmp_comp4);
   $f_usr_firstname = strWrapHtml($f_usr_firstname);
   $f_usr_name = strWrapHtml($f_usr_name);
   $f_ad_street = strWrapHtml($f_ad_street);
   $f_ad_city = strWrapHtml($f_ad_city);
   $f_cmp_bank = strWrapHtml($f_cmp_bank);
   $f_cmp_remark = strWrapHtml($f_cmp_remark);
   $f_cmp_remark2 = strWrapHtml($f_cmp_remark2);
   $f_cmp_match = strWrapHtml($f_cmp_match);
   $f_cmp_match2 = strWrapHtml($f_cmp_match2);

   if ($companyId != "" || CS_EID_GENERATION == "") :
        $f_cs_eid_out = "<input class=\"f8np mc_input_type_10\" type=\"text\" id=\"f_cs_eid\" name=\"f_cs_eid\" value=\"" . $f_cs_eid . "\" maxlength=\"10\" tabindex=\"30\" " . (CS_EID_EDITABLE != "1" ? "readonly" : "") . ">";
   else :
        if ($f_cs_eid == "") :
           $f_cs_eid = $constCsEidPrefix;
        endif;
   
        $f_cs_eid_out = "<div style=\"float:left;\"><input class=\"f8np1 mc_input_type_10\" type=\"text\" id=\"f_cs_eid\" name=\"f_cs_eid\" value=\"" . $f_cs_eid . "\" onchange=\"checkCsEidOld();\" maxlength=\"10\" tabindex=\"30\" >&nbsp;</div>";        
        $f_cs_eid_out .= defineButtonType08("...", "action_eid", "searchMaxEID();", "20", "left", "2");
   endif;
   
   // Generate Output
   if ($companyId != "") : 
       $f_actText = "modifyCustomer";
   else :
       $f_actText = "newCustomer";
   endif;

   // Identification-parameters
   $f_cmp_id = $companyId;

   // Use costcenter mail address if activated
   $f_cs_jbstatusmail2csc_0 = "";
   $f_cs_jbstatusmail2csc_1 = "";
   if ($f_cs_jbstatusmail2csc == "0" || $f_cs_jbstatusmail2csc == "") : $f_cs_jbstatusmail2csc_0 = "checked"; endif;
   if ($f_cs_jbstatusmail2csc == "1") : $f_cs_jbstatusmail2csc_1 = "checked"; endif;

   // Show price information in mail
   $f_cs_jbstatusmail_price_0 = "";
   $f_cs_jbstatusmail_price_1 = "";
   if ($f_cs_jbstatusmail_price == "0") : $f_cs_jbstatusmail_price_0 = "checked"; endif;
   if ($f_cs_jbstatusmail_price == "1" || $f_cs_jbstatusmail_price == "") : $f_cs_jbstatusmail_price_1 = "checked"; endif;
   
   // Show employee information in mail with question of contentment
   $f_cs_jbstatusmail_emp_0 = "";
   $f_cs_jbstatusmail_emp_1 = "";
   if ($f_cs_jbstatusmail_emp == "0" || $f_cs_jbstatusmail_emp == "") : $f_cs_jbstatusmail_emp_0 = "checked"; endif;
   if ($f_cs_jbstatusmail_emp == "1") : $f_cs_jbstatusmail_emp_1 = "checked"; endif;
   
   // Send PDF document as attachment
   $f_cs_jbstatusmail_pdf_0 = "";
   $f_cs_jbstatusmail_pdf_1 = "";
   if ($f_cs_jbstatusmail_pdf == "0" || $f_cs_jbstatusmail_pdf == "") : $f_cs_jbstatusmail_pdf_0 = "checked"; endif;
   if ($f_cs_jbstatusmail_pdf == "1") : $f_cs_jbstatusmail_pdf_1 = "checked"; endif;

   // Send newsletter
   $f_cmp_newsletter_0 = "";
   $f_cmp_newsletter_1 = "";
   if ($f_cmp_newsletter == "0" || $f_cmp_newsletter == "") : $f_cmp_newsletter_0 = "checked"; endif;
   if ($f_cmp_newsletter == "1") : $f_cmp_newsletter_1 = "checked"; endif;

   // State DSGVO
   $f_cmp_dsgvo_0 = "disabled";
   $f_cmp_dsgvo_1 = "disabled";
   if (authCheckEmployeeRights($emp_id, "33")) :
      $f_cmp_dsgvo_0 = "";
      $f_cmp_dsgvo_1 = "";
   endif;
   if ($f_cmp_dsgvo == "0") : $f_cmp_dsgvo_0 = "checked"; endif;
   if ($f_cmp_dsgvo == "1" || $f_cmp_dsgvo == "") : $f_cmp_dsgvo_1 = "checked"; endif;

   // Proof of delivery (photo)   
   $f_cmp_proof_delivery_0 = "";
   $f_cmp_proof_delivery_1 = "";
   if ($f_cmp_proof_delivery == "0") : $f_cmp_proof_delivery_0 = "checked"; endif;
   if ($f_cmp_proof_delivery == "1" || $f_cmp_proof_delivery == "") : $f_cmp_proof_delivery_1 = "checked"; endif;

   // PDA usage (e.g. relevant for statistics)
   $f_cmp_pda_usage_0 = "disabled";
   $f_cmp_pda_usage_1 = "disabled";
   if (authCheckEmployeeRights($emp_id, "32")) :
      $f_cmp_pda_usage_0 = "";
      $f_cmp_pda_usage_1 = "";
   endif;
   if ($f_cmp_pda_usage == "0") : $f_cmp_pda_usage_0 = "checked"; endif;
   if ($f_cmp_pda_usage == "1" || $f_cmp_pda_usage == "") : $f_cmp_pda_usage_1 = "checked"; endif;


   // Show extra fields in mail 
   // 1. tr.tr_remark   
   $f_cs_jbstatusmail_field1 = "0";
   if (substr($f_cs_jbstatusmail_fields,0,1) == "1") : $f_cs_jbstatusmail_field1 = "1"; endif;
   // 2. cr_mobile_pda
   $f_cs_jbstatusmail_field2 = "0";
   if (substr($f_cs_jbstatusmail_fields,1,1) == "1") : $f_cs_jbstatusmail_field2 = "1"; endif;
   // 3. jb_invtext
   $f_cs_jbstatusmail_field3 = "0";
   if (substr($f_cs_jbstatusmail_fields,2,1) == "1") : $f_cs_jbstatusmail_field3 = "1"; endif;
   // 4. Enables the question in job_edit to send an extra mail after changing a finished job
   $f_cs_jbstatusmail_field4 = "0";
   if (substr($f_cs_jbstatusmail_fields,3,1) == "1") : $f_cs_jbstatusmail_field4 = "1"; endif;
   // 5. Enables the station based delivery mail
   $f_cs_jbstatusmail_field5 = "0";
   if (substr($f_cs_jbstatusmail_fields,4,1) == "1") : $f_cs_jbstatusmail_field5 = "1"; endif;
   // 6. Enables photos as attachement
   $f_cs_jbstatusmail_field6 = "0";
   if (substr($f_cs_jbstatusmail_fields,5,1) == "1") : $f_cs_jbstatusmail_field6 = "1"; endif;
   // 7. Enables vehicle sign
   $f_cs_jbstatusmail_field7 = "0";
   if (substr($f_cs_jbstatusmail_fields,6,1) == "1") : $f_cs_jbstatusmail_field7 = "1"; endif;
   // 8. Enables mail after cancellation
   $f_cs_jbstatusmail_field8 = "0";
   if (substr($f_cs_jbstatusmail_fields,7,1) == "1") : $f_cs_jbstatusmail_field8 = "1"; endif;
   // 9. Enables events
   $f_cs_jbstatusmail_field9 = "0";
   if (substr($f_cs_jbstatusmail_fields,8,1) == "1") : $f_cs_jbstatusmail_field9 = "1"; endif;
   // A. Enables "Bemerkung Innendienst"
   $f_cs_jbstatusmail_fieldA = "0";
   if (substr($f_cs_jbstatusmail_fields,9,1) == "1") : $f_cs_jbstatusmail_fieldA = "1"; endif;

   // Check for some email state fields having default values by creating a new customer
   if ($companyId == "" && $copyCs != "1") :
      $csJbStatusMailFieldsEnabled = getParameterValue("0", "CS_JBSTATUSMAIL_FIELDS_ENABLED", $hq_id);
      $csJbStatusMailFieldsEnabledArr = explode("|", $csJbStatusMailFieldsEnabled);
      $f_cs_jbstatusmail  = $csJbStatusMailFieldsEnabledArr[0];
      $f_cs_jbstatusmail2 = $csJbStatusMailFieldsEnabledArr[1];
      $f_cs_jbstatusmail3 = $csJbStatusMailFieldsEnabledArr[2];
   endif;

   // Email job finished
   $f_cs_jbstatusmail_0 = "";
   $f_cs_jbstatusmail_1 = "";
   if ($f_cs_jbstatusmail == "0" || $f_cs_jbstatusmail == "") : $f_cs_jbstatusmail_0 = "checked"; endif;
   if ($f_cs_jbstatusmail == "1") : $f_cs_jbstatusmail_1 = "checked"; endif;
   
   // Email job pickup 1. station
   $f_cs_jbstatusmail2_0 = "";
   $f_cs_jbstatusmail2_1 = "";
   if ($f_cs_jbstatusmail2 == "0" || $f_cs_jbstatusmail2 == "") : $f_cs_jbstatusmail2_0 = "checked"; endif;
   if ($f_cs_jbstatusmail2 == "1") : $f_cs_jbstatusmail2_1 = "checked"; endif;
   
   // Email job created
   $f_cs_jbstatusmail3_0 = "";
   $f_cs_jbstatusmail3_1 = "";
   if ($f_cs_jbstatusmail3 == "0" || $f_cs_jbstatusmail3 == "") : $f_cs_jbstatusmail3_0 = "checked"; endif;
   if ($f_cs_jbstatusmail3 == "1") : $f_cs_jbstatusmail3_1 = "checked"; endif;

   $f_cs_invmode_0 = "";
   $f_cs_invmode_1 = "";
   $f_cs_invmode_2 = "";
   $f_cs_invmode_3 = "";
   $f_cs_invmode_9 = "";
   if ($f_cs_invmode == "0" || $f_cs_invmode == "") : $f_cs_invmode_0 = "checked"; endif;
   if ($f_cs_invmode == "1") : $f_cs_invmode_1 = "checked"; endif;
   if ($f_cs_invmode == "2") : $f_cs_invmode_2 = "checked"; endif;
   if ($f_cs_invmode == "3") : $f_cs_invmode_3 = "checked"; endif;
   if ($f_cs_invmode == "9") : $f_cs_invmode_9 = "checked"; endif;

   $f_cmp_bankmode_0 = "";
   $f_cmp_bankmode_1 = "";
   if ($f_cmp_bankmode == "0" || $f_cmp_bankmode == "") : $f_cmp_bankmode_0 = "checked"; endif;
   if ($f_cmp_bankmode == "1") : $f_cmp_bankmode_1 = "checked"; endif;

   $f_cs_jobbatch_0 = "";
   if ($f_cs_jobbatch == "1") : $f_cs_jobbatch_0 = "checked"; endif;
   
   $f_cs_jbedit_0 = "";
   if ($f_cs_jbedit == "1") : $f_cs_jbedit_0 = "checked"; endif;

   if ($companyId == "") :
      $f_cs_ar = "1";
      $f_maskManDisp = getParameterValue("0", "MASK_MANUAL_DISPOSITION", $hq_id);
      if ($f_maskManDisp == "1") :
         $f_cs_ar = "0";
      else :
         $f_maskManDispCsMand = getParameterValue("0", "MASK_MANUAL_DISPOSITION_CUSTOMER_MANDATORY", $hq_id);
         if ($f_maskManDispCsMand == "1") :
            $f_cs_ar = "0";
         endif;
      endif;
   endif;
   $f_cs_ar_0 = "";
   if ($f_cs_ar == "1") : $f_cs_ar_0 = "checked"; endif;

   $f_cs_fixprice_discount_0 = "";
   if ($f_cs_fixprice_discount == "1") : $f_cs_fixprice_discount_0 = "checked"; endif;

   $f_cs_markup_0 = "";
   if ($f_cs_markup == "1") : $f_cs_markup_0 = "checked"; endif;

   $f_cs_price_warn_uncomplete_0 = "";
   if ($f_cs_price_warn_uncomplete == "1") : $f_cs_price_warn_uncomplete_0 = "checked"; endif;

   $f_cs_joblist_disabled_0 = "";
   if ($f_cs_joblist_disabled == "1") : $f_cs_joblist_disabled_0 = "checked"; endif;

   $f_cs_invtext_mode_0 = "";
   if ($f_cs_invtext_mode == "1") : $f_cs_invtext_mode_0 = "checked"; endif;

   $f_cmp_no_longhaul_0 = "";
   if ($f_cmp_no_longhaul == "1") : $f_cmp_no_longhaul_0 = "checked"; endif;

   $f_cs_tracking_0 = "";
   $f_cs_tracking_1 = "";
   if ($f_cs_tracking == "1" || $f_cs_tracking == "3") : $f_cs_tracking_0 = "checked"; endif;
   if ($f_cs_tracking == "2" || $f_cs_tracking == "3") : $f_cs_tracking_1 = "checked"; endif;

   $f_cmp_inv2hq_0 = "";
   $f_cmp_inv2hq_1 = "";
   if ($f_cmp_inv2hq == "1" || $f_cmp_inv2hq == "3") : $f_cmp_inv2hq_0 = "checked"; endif;
   if ($f_cmp_inv2hq == "2" || $f_cmp_inv2hq == "3") : $f_cmp_inv2hq_1 = "checked"; endif;

   $f_cs_commission_no_0 = "";
   $f_cs_commission_no_1 = "";
   if ($f_cs_commission_no == "0" || $f_cs_commission_no == "") : $f_cs_commission_no_0 = "checked"; endif;
   if ($f_cs_commission_no == "1") : $f_cs_commission_no_1 = "checked"; endif;

   $f_cs_cr_fav_only_0 = "";
   if ($f_cs_cr_fav_only == "1") : $f_cs_cr_fav_only_0 = "checked"; endif;


   // Parameter to initiate a similarity search
   $maskCsNewSimilaritySearch = getParameterValue("0", "MASK_CS_NEW_SIMILARITY_SEARCH", $hq_id);
   if ($maskCsNewSimilaritySearch == "") : $maskCsNewSimilaritySearch = getParameterValue("0", "MASK_CS_NEW_SIMILARITY_SEARCH", "0"); endif;
   
   // Parameter to check for being a potential INTERNAL customer as "booking account"
   $maskCsCheckInternalBookingAccounts = getParameterValue("0", "MASK_CS_CHECK_INTERNAL_BOOKING_ACCOUNT", $hq_id);
   if ($maskCsCheckInternalBookingAccounts == "") : $maskCsCheckInternalBookingAccounts = getParameterValue("0", "MASK_CS_CHECK_INTERNAL_BOOKING_ACCOUNT", "0"); endif;

   // Output to PDF
   if ($generatePDF == "1" && $companyId != "") :
      $includePDFGeneric = "1";
      $f_act = "generatePDFCustomer";
      $csId = getFieldValueFromId("customer", "cmp_id", $companyId, "cs_id");
      // include_once ("../admin/pdf_generic.php");
      include ("../admin/pdf_generic.php");
      die();
   endif;
   
   // Check for customized range of provision value
   // Lower Range
   $parCsProvRangeLower = getParameterValue("0", "MASK_CS_PROV_RANGE_LOWER", $hq_id);
   if ($parCsProvRangeLower == "") : $parCsProvRangeLower = getParameterValue("0", "MASK_CS_PROV_RANGE_LOWER", "0"); endif;
   // Upper Range
   $parCsProvRangeUpper = getParameterValue("0", "MASK_CS_PROV_RANGE_UPPER", $hq_id);
   if ($parCsProvRangeUpper == "") : $parCsProvRangeUpper = getParameterValue("0", "MASK_CS_PROV_RANGE_UPPER", "0"); endif;

   // Parameter to show last job
   $maskCsShowLastJob = "";
   if ($f_cmp_type == "0") :
      $maskCsShowLastJob = getParameterValue("0", "MASK_CS_SHOW_LAST_JOB", $hq_id);
      if ($maskCsShowLastJob == "") : $maskCsShowLastJob = getParameterValue("0", "MASK_CS_SHOW_LAST_JOB", "0"); endif;
      if ($maskCsShowLastJob == "1") :
         include ("../include/inc_job.inc.php");
      endif;
   endif;


   // Flag for configuration regarding "display station number"
   $f_cs_par_tr_sort_0 = "checked";
   $f_cs_par_tr_sort = getParameterValue("0", "JOBDETAILS_STATIONS_STATION_NUMBER_" . $f_cs_id, "0");
   if ($f_cs_par_tr_sort != "1") :
      $f_cs_par_tr_sort = "0";
      $f_cs_par_tr_sort_0 = "";
   endif;

    // Flag for color of the jobs in job lists
   $f_cs_par_order_color = getParameterValue("0", "JOBLIST_CS_JB_COLOR_" . $f_cs_id, "0");
   if ($f_cs_par_order_color == "") :
      $f_cs_par_order_color = "FFFFFF";
   endif;

   // Flag for ........
   $f_cs_par_xxxxxxxx_0 = "checked";
   $f_cs_par_xxxxxxxx = getParameterValue("0", "CUSTOMER_MASK_JOBLIST_XXXXXXXXXX_" . $f_cs_id, "0");
   if ($f_cs_par_xxxxxxxx != "1") :
      $f_cs_par_xxxxxxxx = "0";
      $f_cs_par_xxxxxxxx_0 = "";
   endif;

   // Flag for job cancellation by customer
   $f_cs_jb_storno_0 = "checked";
   $f_cs_jb_storno = getParameterValue("0", "CUSTOMER_MASK_JOBLIST_CANCELLATION_ENABLED_" . $f_cs_id, "0");
   if ($f_cs_jb_storno != "1") :
      $f_cs_jb_storno = "0";
      $f_cs_jb_storno_0 = "";
   endif;

   // Flag for job disposition to favoured couriers by customer
   $f_cs_jb_dispo_0 = "checked";
   $f_cs_jb_dispo = getParameterValue("0", "CUSTOMER_MASK_JOBLIST_DISPO_FAV_ENABLED_" . $f_cs_id, "0");
   if ($f_cs_jb_dispo != "1") :
      $f_cs_jb_dispo = "0";
      $f_cs_jb_dispo_0 = "";
   endif;
   $f_cs_jb_dispo_disabled = "disabled";
   if (authCheckEmployeeRights($emp_id, "41")) :
      $f_cs_jb_dispo_disabled = "";
   endif;

   // Flag for making standard price in customer login
   $f_cs_par_dont_make_0 = "checked";
   $f_cs_par_dont_make = getParameterValue("0", "MASK_CS_DONT_MAKE_STANDARD_PRICE_" . $f_cs_id, "0");
   if ($f_cs_par_dont_make != "1") :
      $f_cs_par_dont_make = "0";
      $f_cs_par_dont_make_0 = "";
   endif;

   // Flag for calculator has to be a must for jobs of the customer
   $f_cs_par_calc_usage_0 = "checked";
   $f_cs_par_calc_usage = getParameterValue("0", "CUSTOMER_MASK_CALCULATOR_USAGE_ONLY_" . $f_cs_id, "0");
   if ($f_cs_par_calc_usage != "1") :
      $f_cs_par_calc_usage = "0";
      $f_cs_par_calc_usage_0 = "";
   endif;

   // Flag for not checking address in KAE
   $f_cs_par_cst_all_ad_0 = "checked";
   $f_cs_par_cst_all_ad = getParameterValue("0", "MASK_CUST_ALL_ADDR_ENABLED_" . $f_cs_id, "0");
   if ($f_cs_par_cst_all_ad != "1") :
      $f_cs_par_cst_all_ad = "0";
      $f_cs_par_cst_all_ad_0 = "";
   endif;

   // Flag for emails to avoid sending the footer
   $f_cs_par_email_no_footer_0 = "checked";
   $f_cs_par_email_no_footer = getParameterValue("0", "JOBDETAILS_EMAIL_NO_FOOTER_" . $f_cs_id, "0");
   if ($f_cs_par_email_no_footer != "1") :
      $f_cs_par_email_no_footer = "0";
      $f_cs_par_email_no_footer_0 = "";
   endif;

   // Flag for customer to get a discount by self-creating jobs
   $f_cs_jb_creator_discount_0 = "checked";
   $f_cs_jb_creator_discount = getParameterValue("0", "CUSTOMER_MASK_JB_CREATOR_DISCOUNT_" . $f_cs_id, "0");
   if ($f_cs_jb_creator_discount != "1") :
      $f_cs_jb_creator_discount = "0";
      $f_cs_jb_creator_discount_0 = "";
   endif;

   // Language of the email
   $f_cs_par_email_arrivaltime = getParameterValue("0", "JOB_MAIL_STATION_ARRIVAL_TIME_" . $f_cs_id, "0");
   if ($f_cs_par_email_arrivaltime == "") :
      $f_cs_par_email_arrivaltime = "0";
   endif;

   // Language of the email
   $f_cs_par_email_lng = getParameterValue("0", "JOBDETAILS_EMAIL_LANGUAGE_" . $f_cs_id, "0");
   if ($f_cs_par_email_lng == "") :
      $f_cs_par_email_lng = "0";
   endif;

   // Flag for customer to set job being incomplete by creating or modifying a job
   $f_cs_jb_incomplete_0 = "checked";
   $f_cs_jb_incomplete = getParameterValue("0", "CUSTOMER_MASK_JB_INCOMPLETE_" . $f_cs_id, "0");
   if ($f_cs_jb_incomplete != "1") :
      $f_cs_jb_incomplete = "0";
      $f_cs_jb_incomplete_0 = "";
   endif;
?>

<html>

<head>
<title><?php echo $title2 ?></title>

<style type="text/css">
  <?php include_once ("../css/phoenix.css.php"); ?>
  <?php include_once ("../css/navigation.css.php"); ?>
  <?php include_once ("../css/mc.css.php"); ?>
</style>

<?php include_once ("../include/js_framework.inc.php"); ?>

<script src="../include/swift.js" type="text/javascript"></script>
<script src="../include/iban.js" type="text/javascript"></script>
<script src="../include/checkFormTags.js" type="text/javascript"></script>
<script src="../include/searchLists.js" type="text/javascript"></script>

<script type="text/javascript">
<!--
var doCloseWindowAfterStoringNewCustomer = '<?php echo $maskCloseWindowAfterNewCs ?>';
if (doCloseWindowAfterStoringNewCustomer == '1') {
	alert('<?php echo getLngt("Der neue Kundendatensatz wurde gespeichert!") ?>');
	window.close();
}
if (doCloseWindowAfterStoringNewCustomer == '2') {
	if ('<?php echo $cs_id_new ?>' != '') {
	   if (confirm('<?php echo getLngt("Der neue Kundendatensatz wurde gespeichert! Möchten Sie einen neuen Kontakt für ihn anlegen?") ?>')) {
	      openContacts('<?php echo ec($cs_id_new) ?>');
     }
  }
  window.close();
}

// NAVIGATION
<?php echo $jsMenuOut; ?>

var f_cs_id = '<?php echo $f_cs_id ?>';
var f_cmp_id = '<?php echo $f_cmp_id ?>';
var f_csc_id = '<?php echo $f_csc_id ?>';
var toggleStateJobColor = 0;

function clearAllFields() {
  document.location.href = "customer_special.php";
};

function authenticationFinishPage() {
  if (confirm('<?php echo $confirmTextAuthentication ?>')) {
     document.forms[0].f_cmp_authenticated.value='<?php echo $f_cmp_authenticated2 ?>';
     document.forms[0].f_act.value='setAuthentication';
     document.forms[0].submit();
  }
};

function visibilityFinishPage() {
  if (confirm('<?php echo $confirmTextVisibility ?>')) {	
     document.forms[0].f_cmp_visible.value='<?php echo $f_cmp_visible2 ?>';
     document.forms[0].f_act.value='setVisibility';
     document.forms[0].submit();
  }
};

function cashModeFinishPage() {
  if (confirm('<?php echo $confirmTextCashmode ?>')) {
     document.forms[0].f_cmp_cashmode.value='<?php echo $f_cmp_cashmode2 ?>';
     document.forms[0].f_act.value='setCashmode';
     document.forms[0].submit();  
  }
};

function checkMinimumLength(elemName, elemValueMinLen) {
	var retBool = true;
  elem = eval('document.forms[0].' + elemName);
  var elemValue = elem.value;
  elemValue = trim(elemValue);
  elemValue = elemValue.replace(/\s/g, "");
  elemValueLen = elemValue.length;
  if ('<?php echo $parCsPhoneMinLength ?>' != '' && '<?php echo $parCsPhoneMinLength ?>' != '0') {
  	 if (elemValueLen < elemValueMinLen) { retBool = false; }
  }
	return retBool;
};

function finishPage() {
  var ok = true;

  var usrEmailValue = document.forms[0].f_usr_email.value;
  if (usrEmailValue.length != 0) {
     // If email has content then check syntax
     if (!checkMailAddress(document.forms[0].f_usr_email, '<?php echo getLngt("Bitte tragen Sie eine gültige Email-Adresse ein!") ?>')) {ok = false;};
  }
  var usrInvEmailValue = document.forms[0].f_usr_inv_email.value;
  if (usrInvEmailValue.length != 0) {
     // If invoice email has content then check syntax
     if ('<?php echo getParameterValue("0", "MASK_INV_EMAIL_SINGLE_ONLY", "0") ?>' == '1') {
        if (!checkMailAddress(document.forms[0].f_usr_inv_email, '<?php echo getLngt("Bitte tragen Sie eine gültige Rechnungs-Email-Adresse ein!") ?>', '1', '<?php echo getLngt("Es darf nur eine Rechnungs-Email-Adresse erfasst werden!") ?>')) {ok = false;};
     } else {
        if (!checkMailAddress(document.forms[0].f_usr_inv_email, '<?php echo getLngt("Bitte tragen Sie eine gültige Rechnungs-Email-Adresse ein!") ?>')) {ok = false;};
     };
  }
  var usrReminderEmailValue = document.forms[0].f_usr_reminder_email.value;
  if (usrReminderEmailValue.length != 0) {
     // If reminder email has content then check syntax
     if ('<?php echo getParameterValue("0", "MASK_REMINDER_EMAIL_SINGLE_ONLY", "0") ?>' == '1') {
        if (!checkMailAddress(document.forms[0].f_usr_reminder_email, '<?php echo getLngt("Bitte tragen Sie eine gültige Mahn-Email-Adresse ein!") ?>', '1', '<?php echo getLngt("Es darf nur eine Mahn-Email-Adresse erfasst werden!") ?>')) {ok = false;};
     } else {
        if (!checkMailAddress(document.forms[0].f_usr_reminder_email, '<?php echo getLngt("Bitte tragen Sie eine gültige Mahn-Email-Adresse ein!") ?>')) {ok = false;};
     };
  }
  var cmpSustainabilityEmailValue = document.forms[0].f_cmp_sustainability_email.value;
  if (cmpSustainabilityEmailValue.length != 0) {
     // If sustainability email has content then check syntax
     if (!checkMailAddress(document.forms[0].f_cmp_sustainability_email, '<?php echo getLngt("Bitte tragen Sie eine gültige Nachhaltigkeits-Email-Adresse ein!") ?>')) {ok = false;};
  }
  if (ok && ('<?php echo $csCurrIsCashPayer ?>' == '0' && document.forms[0].f_cs_jbstatusmail2csc[0].checked && document.forms[0].f_usr_email.value.length == 0 &&
             (document.forms[0].f_cs_jbstatusmail[1].checked || document.forms[0].f_cs_jbstatusmail2[1].checked || document.forms[0].f_cs_jbstatusmail3[1].checked))) {
     alert('<?php echo getLngt("Um Auftragsbestätigungs-Emails zu verschicken, tragen Sie bitte eine gültige Email-Adresse ein!") ?>');
     ok = false;
  }
  if (!checkIsNaNIgnoreSpace(document.forms[0].f_usr_phone.value, '<?php echo getLngt("Bitte tragen Sie eine Nummer bei Telefon ein!") ?>')) {ok = false;};
  if (!checkIsNaNIgnoreSpace(document.forms[0].f_usr_phone2.value, '<?php echo getLngt("Bitte tragen Sie eine Nummer bei Mobil ein!") ?>')) {ok = false;};

  if (ok && !checkMinimumLength('f_usr_phone', '<?php echo $parCsPhoneMinLength ?>')) {
     alert('<?php echo getLngt("Die erforderliche Mindestlänge der Telefonnummer ist noch nicht erfüllt!") ?>' + ' ' + '<?php echo getLngt("Mindestanzahl:") . " " . $parCsPhoneMinLength ?>');
     ok = false;
  }
  if (ok) {
  	 if (!checkAddress()) {
  	 	  ok = false;
  	 }
  }
  if (ok) {
  	 if (<?php echo $parMaskMandatoryFieldsLen ?> > 0) {
  	    var mandatorFieldsArray = <?php if ($parMaskMandatoryFieldsLen > 0) : echo json_encode($parMaskMandatoryFields); else : echo "new Array()"; endif; ?>;
  	    var elem;
	      var elemValue;
	      for (var key in mandatorFieldsArray) {
            elem = eval('document.forms[0].' + key);
            elemValue = elem.value;
	          if (elemValue == '') {
               alert('<?php echo getLngt("Bitte füllen Sie das Feld") ?> ' + mandatorFieldsArray[key]);
               ok = false;
	          }
        }
     }
  }
  if (ok) {
  	 // Finally check mandatory fields
  	 if (finishPageByCheckingMandatoryFields()) {
        document.forms[0].submit();
     }
  }
};

function openCostcenterAdmin() {	
  var widthPopupWin = 1024;
  var heightPopupWin = 768;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../customer/costcenter.php?deactivateMenu=1&customerId=" + f_cs_id + "&cscIdRoot=" + f_csc_id + "&cscIdActual=" + f_csc_id,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");  
};

function searchCsCsc(genVal,genNum,genJsParName) {
  var f_act = 'search';
  
  var widthPopupWin = 1024;
  var heightPopupWin = 768;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/cs_csc_list.php?f_act=" + f_act + "&generic=" + genVal + "&genNum=" + genNum + "&genJsParName=" + genJsParName,
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
    ",scrollbars=yes");
};

function clearPayer() {	
  document.forms[0].g_cs_id.value='';
  document.forms[0].g_csc_id.value='';
  document.forms[0].g_cscad_comp.value='';
};

function clearParent() {	
  document.forms[0].g2_cs_id.value='';
  document.forms[0].g2_cmp_comp.value='';
  document.forms[0].g2_cs_eid.value='';
};

function clearExtIdOld() {	
  document.forms[0].f_cs_eid_old.value='';
};


// *** TAX (Begin) ***
popupWinTx = [];

function searchTx() {
  var f_act = 'search';
  
  var widthPopupWin = 500;
  var heightPopupWin = 400;
  // var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var leftPopupWin = 50;
  // var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;  
  var topPopupWin = 50;
/*  
  popupWinTx[popupWinTx.length] = window.open("../admin/tx_list.php?f_act=" + f_act + "&generic=1011" + "&callOpenerFunction=checkTx()",
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
    ",scrollbars=yes");
*/
  popupWinTx[popupWinTx.length] = window.open("../admin/selection_list.php?f_act=" + f_act + "&generic=1011&listType=tax" + "&callOpenerFunction=checkTx()",
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
    ",scrollbars=yes");
};

function clearTx() {	
  document.forms[0].g_tx_id.value='';  
  document.forms[0].g_tx_sign.value='';
  document.forms[0].g_tx_value.value='';
  
  document.forms[0].g_tx_id_rem.value='';    // Remembers the last setting only
  document.forms[0].g_tx_sign_rem.value='';  // Dito
  document.forms[0].g_tx_value_rem.value=''; // Dito
};

function removeTxWindows() {
  for (var i = 0; i < popupWinTx.length; i++) {
    popupWinTx[i].close();
  }
  popupWinTx = [];
}

function checkTx() {
	var txCheckArray = new Array(<?php echo $parMaskCsTaxIdsChangeMsg ?>);
	var txCheckArrayLen = txCheckArray.length;
	var txChangeFromWarning = false;
	var txChangeToWarning = false;
  for (var i = 0; i < txCheckArrayLen; i++) {
  	  if (document.forms[0].g_tx_id.value != document.forms[0].g_tx_id_rem.value) {
  	     if (document.forms[0].g_tx_id_rem.value == txCheckArray[i]) { txChangeFromWarning = true; };
         if (document.forms[0].g_tx_id.value == txCheckArray[i]) { txChangeToWarning = true; };
      };
  }
  if (txChangeFromWarning || txChangeToWarning) {
  	 removeTxWindows();
  	 if (!confirm('<?php echo getLngt("Möchten Sie dem Kunden diesen Steuersatz wirklich zuordnen?") ?>')) {
        document.forms[0].g_tx_id.value = document.forms[0].g_tx_id_rem.value;  
        document.forms[0].g_tx_sign.value = document.forms[0].g_tx_sign_rem.value;
        document.forms[0].g_tx_value.value = document.forms[0].g_tx_value_rem.value;
  	 };
  };
  document.forms[0].g_tx_id_rem.value = document.forms[0].g_tx_id.value;  
  document.forms[0].g_tx_sign_rem.value = document.forms[0].g_tx_sign.value;
  document.forms[0].g_tx_value_rem.value = document.forms[0].g_tx_value.value;
};
// *** TAX (End) ***

function searchBr() {
  var f_act = 'search';
  
  var widthPopupWin = 300;
  var heightPopupWin = 550;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
/*  
  popupWin = window.open("../admin/br_list.php?f_act=" + f_act + "&generic=111",
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
    ",scrollbars=yes");
*/
  popupWin = window.open("../admin/selection_list.php?f_act=" + f_act + "&generic=1112&listType=branch",
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
    ",scrollbars=yes");
};

function clearBr() {	
  document.forms[0].g_br_id.value='';
  document.forms[0].g_br_key.value='';
  document.forms[0].g_br_name.value='';
};

function searchEmpSales() {
  var f_act = 'search';
  
  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/selection_list.php?f_act=" + f_act + "&generic=1111&listType=employee",
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
    ",scrollbars=yes");
};

function clearEmpSales() {
  document.forms[0].g_sales_emp_id.value='';
  document.forms[0].g_sales_usr_name.value='';
  document.forms[0].g_sales_usr_firstname.value='';
};

function searchMaxEID() {
  var maxvalue = document.forms[0].f_eid_maxval.value;
  if (confirm('<?php echo getLngt("Soll der Wert") ?>' + ' ' + maxvalue + ' ' + '<?php echo getLngt("übernommen werden") ?>')) {
     document.forms[0].f_cs_eid.value = maxvalue;
     <?php if ($companyId == "") : ?>
       checkCsEidOld();
     <?php endif; ?>
  };
};

function openCustomerCouriers() {
  var widthPopupWin = 1024;
  var heightPopupWin = 768;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;  
  popupWin = window.open("../admin/customer_courier.php?customerId=" + f_cs_id,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openCustomerFilters() {
  var widthPopupWin = 1024;
  var heightPopupWin = 768;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/filter.php?customerId=" + f_cs_id + "&actionMode=1","","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openCustomerServices() {
  var widthPopupWin = 1500;
  var heightPopupWin = 1024;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/customer_service.php?customerId=" + f_cs_id,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openCustomerReports(f_cs_eid) {
  var widthPopupWin = 1200;
  var heightPopupWin = 1024;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../groupware/report.php?rpObjType=cs&g_cs_eid=" + f_cs_eid,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openPrintLayout() {
  var widthPopupWin = 800;
  var heightPopupWin = 700;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/customer_special.php?companyId=" + f_cmp_id + "&printVersion=1","","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openCs2pdf() {
  var widthPopupWin = 1200;
  var heightPopupWin = 1024;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/customer_special.php?companyId=" + f_cmp_id + "&generatePDF=1","","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openCsHistory(f_cs_id) {
  var widthPopupWin = 1200;
  var heightPopupWin = 1024;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/history.php?history_mode=<?php echo ec(0) ?>&cs_id=" + f_cs_id + "&op=<?php echo ec(1) ?>&logoselection=<?php echo ec(1) ?>&displayselection=<?php echo ec(1) ?>","","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function copyCustomer() {
  document.forms[0].copyCs.value = '1';
  document.forms[0].submit();
};

function checkCsProv() {
  var csProv = trim(document.forms[0].f_cs_prov.value);
  csProv = csProv.replace(/,/, ".");
  if (!checkIsNaN(csProv, '<?php echo getLngt("Die Eingabe im Provisionsfeld ist nicht numerisch!") ?>')) {
     document.forms[0].f_cs_prov.value = '0.00';
  } else {
    if (csProv < 0) {
       document.forms[0].f_cs_prov.value = '0.00';
       alert('<?php echo getLngt("Der Prozentsatz darf nicht negativ sein!") ?>');
    } else {
  
       var pos = csProv.indexOf(".");
       if (pos != -1) {
          var decimal = csProv.substr(pos + 1);
          if (decimal == '00' || decimal == '50' || decimal == '0' || decimal == '5') {
             if (pos == 0) {csProv = '0' + csProv;};     // If value like ".0", ".5", ... then set to "0.0", "0.5", ...
             document.forms[0].f_cs_prov.value = csProv;
          } else {
             document.forms[0].f_cs_prov.value = '0.00';
             alert('<?php echo getLngt("Die Systemeinstellungen erfordern eine Dezimalstelle der Form ,0 bzw ,5 oder auch ,00 bzw. ,50 !") ?>');
          }
       } else {
          if (csProv >= 0 && csProv <= 99) {
             document.forms[0].f_cs_prov.value = csProv + '.00';
          } else {
             document.forms[0].f_cs_prov.value = '0.00';
             alert('<?php echo getLngt("Der Prozentsatz muss größer gleich 0 und kleiner 100 sein!") ?>');
          }
       }
    }
  }
  <?php if ($parCsProvRangeLower != "" && is_numeric($parCsProvRangeLower)) : ?>
    if (csProv > 0 && csProv < <?php echo $parCsProvRangeLower ?>) {
       document.forms[0].f_cs_prov.value = '0.00';
       alert('<?php echo getLngt("Der Prozentsatz muss folgenden Mindestwert aufweisen:") ?>' + ' ' + '<?php echo $parCsProvRangeLower ?>');
    }
  <?php endif; ?>
  <?php if ($parCsProvRangeUpper != "" && is_numeric($parCsProvRangeUpper)) : ?>
    if (csProv > 0 && csProv > <?php echo $parCsProvRangeUpper ?>) {
       document.forms[0].f_cs_prov.value = '0.00';
       alert('<?php echo getLngt("Der Prozentsatz darf folgenden Maximalwert aufweisen:") ?>' + ' ' + '<?php echo $parCsProvRangeUpper ?>');
    }
  <?php endif; ?>
};

function openGroups(customerId) {
  var widthPopupWin = 1024;
  var heightPopupWin = 768;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/groupmembers.php?itemType=cs&itemId=" + customerId,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openContacts(customerId) {
  var widthPopupWin = 1200;
  var heightPopupWin = 800;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  var presetFields = '<?php echo urlencode(getParameterValue("0", "MASK_CS2CO_PRESET", "0")) ?>';
  popupWin = window.open("../admin/metafield_list.php?deactivateMenu=<?php echo ec(1) ?>&callMode=<?php echo ec(1) ?>&callObjId=" + customerId + "&presetFields=" + presetFields,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openMetaFieldSpecial(objId) {
  var widthPopupWin = 1024;
  var heightPopupWin = 768;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/metafield_special.php?deactivateMenu=1&category=<?php echo ec(2); ?>&objId=" + objId ,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openEmbargoCheck() {
  var widthPopupWin = 1024;
  var heightPopupWin = 768;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../include/dpf.php?cmpId=<?php echo ec($cmpId); ?>&hqId=<?php echo $hq_id; ?>&eid=<?php echo $eid; ?>&usrName=<?php echo $usrName; ?>&usrFirstname=<?php echo $usrFirstname; ?>&adStreet=<?php echo $adStreet; ?>&cmpHsno=<?php echo $cmpHsno; ?>&adZipcode=<?php echo $adZipcode; ?>&adCity=<?php echo $adCity; ?>&cmpDpfChecksum=<?php echo $oldDpfChecksum; ?>" ,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openJob(jobId, dbhistory) {
  var widthPopupWin = 1200;
  var heightPopupWin = 870;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/jb_detail.php?job_id=" + jobId + "&dbhistory=" + dbhistory,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openSimilaritySearch() {
  var widthPopupWin = 1024;
  var heightPopupWin = 768;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  var phrase = document.forms[0].f_cmp_comp.value;
  popupWin = window.open("../admin/nearBySearch.php?phrase=" + phrase + "&compareType=cs" ,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function checkCmpComp() {
	var cmpComp = document.forms[0].f_cmp_comp.value;
  var csNewSimilaritySearch = '<?php echo $maskCsNewSimilaritySearch ?>';
  var csCheckInternalBookingAccounts = '<?php echo $maskCsCheckInternalBookingAccounts ?>';
  // Similarity search
  if (csNewSimilaritySearch == '1') {
  	 openSimilaritySearch();
  }
  // Ckeck for INTERNAL customers as "booking accounts"
  if (csCheckInternalBookingAccounts != '') {
     cmpCompLowerCase = cmpComp.toLowerCase();
     var elemArray = csCheckInternalBookingAccounts.split(",");
     var elemArrayArrayLen = elemArray.length;
     var doAlert = false;
     for(i=0; i<elemArrayArrayLen ;++i) {
     	  if (cmpCompLowerCase.indexOf(elemArray[i]) != -1) {
     	  	 doAlert = true;
     	  }
     }
     if (doAlert) {
     	  alert('<?php echo getLngt("Sollte der aktuelle Kunde ein interner Verrechnungskunde sein, achten Sie bitte auf den Steuersatz!") ?>');
     }
  }
};

// Check address
function checkAddress() {
	var retBool = true;
	if (document.getElementsByName('f_noaddressvalidation[]')[0].checked == false) {
		 retBool = false;
     var street = document.forms[0].f_ad_street.value;
     var zipcode = document.forms[0].f_ad_zipcode.value;
     var city = document.forms[0].f_ad_city.value;
     var country = document.forms[0].f_ad_country.value;
     if (street != '' && zipcode != '' && city != '') {
     	 ajaxRequestGet('../include/ajaxReqLib.php', 'mode=6&db_table=address&id_01=ad_street&value_01=' + encodeURI(escape(street)) + '&id_02=ad_zipcode&value_02=' + encodeURI(escape(zipcode)) + '&id_03=ad_city&value_03=' + encodeURI(escape(city)) + '&id_04=ad_country&value_04=' + encodeURI(escape(country)) + '&db_return_field=ad_id');
     	 if (retValue == '') {
     	 	  document.getElementsByName('f_noaddressvalidation[]')[0].checked = true;
     	 	  alert('<?php echo getLngt("Die Adresse ist bisher unbekannt! Das Kennzeichen zur ungeprüften Übernahme wurde gesetzt! Bisher erfolgte keine Speicherung!") ?>');
     	 } else {
     	    ajaxRequestGet('../include/ajaxReqGeneric.php', 'fun=checkCityZipcode&par_01=' + encodeURI(escape(zipcode)) + '&par_02=' + encodeURI(escape(city)) + '&par_03=' + encodeURI(escape(street)) + '&par_04=0&retIdx=0&retParName=checkCityZipcode');
     	    if (checkCityZipcode == '0') {
     	    	  document.getElementsByName('f_noaddressvalidation[]')[0].checked = true;
     	    	  alert('<?php echo getLngt("Die Postleitzahl bzw. Strasse passt nicht zu dem angegebenen Ort! Das Kennzeichen zur ungeprüften Übernahme wurde gesetzt! Bisher erfolgte keine Speicherung!") ?>');
     	    } else {
     	       retBool = true;
     	    }
     	 }
     } else {
     	alert('<?php echo getLngt("Bitte geben Sie die Adresse vollständig ein!") ?>');
     }
  }
  return retBool;
};

function jobCompleteFinishPage () {
  if (confirm('<?php echo getLngt("Sollen alle aktuellen UNFERTIGEN Aufträge des Kunden auf FERTIG gesetzt werden?") ?>')) {
  	 if (confirm('<?php echo getLngt("Dieser Vorgang wird mit Benutzerkennung im Log festgehalten! Möchten Sie den Vorgang fortsetzen?") ?>')) {
        document.forms[0].f_act.value='setJobCompleteMulti';
        document.forms[0].submit();
     }
  }
}

function sustainabilityFinishPage () {
	if ($('#f_cmp_sustainability_email').val() != '') {
     if (confirm('<?php echo getLngt("Möchten sie jetzt den Nachhaltigkeitsreport gemäß der aktuellen Intervalleinstellung an den Kunden senden?") ?>')) {
  	    if (confirm('<?php echo getLngt("Dieser Vorgang wird mit Benutzerkennung im Log festgehalten! Möchten Sie den Vorgang fortsetzen?") ?>')) {
           document.forms[0].f_act.value='sendSustainabilityReport';
           document.forms[0].submit();
        }
     }
  } else {
  	 alert('<?php echo getLngt("Bitte erst eine Adresse für den Nachhaltigkeitsreport eintragen und im Nachgang abspeichern!") ?>');
  }
}

function reset2FACustomerFinishPage() {
  if (confirm('<?php echo getLngt("Möchten Sie 2-Faktor-Authentifikation des Kunden wirklich zurücksetzen?") ?>')) {
     document.forms[0].f_act.value='reset2FACustomer';
     document.forms[0].submit();
  }
};

function setJobColor (rgbCol) {
	$('#f_cs_par_order_color').val(rgbCol);
	$('#f_cs_button_job_col').css('background-color', rgbCol);
}

function toggleJobColor () {
  if (toggleStateJobColor == 0) {
  	 toggleStateJobColor = 1;
  	 myshow('f_colorpicker');
  } else {
  	toggleStateJobColor = 0;
  	myhide('f_colorpicker');
  }
}

function checkCsEidOld (header = '<?php echo getLngt("Bestätigung") ?>', message = '<?php echo getLngt("Unterliegt die Neuanlage einer Umfirmierung?") ?>') {
  $('<div></div>').append('body')
    .html('<div><h4>' + message + '</h4></div>')
    .dialog({
        modal: true, title: header, zIndex: 100, autoOpen: true,
        width: 'auto', resizable: false, position: { my: "center top+150", at: "center top+150"},
        buttons: {
            Ja: function () {
		            $('#f_cs_eid_old_mandatory').val('1');
		            $('#f_cs_eid_old').css('background-color', 'red');
		            $('#f_cs_eid_old').focus();
		            alert('<?php echo getLngt("Bitte tragen Sie die vorherige ExtID in das rot markierte Feld ein!") ?>');
                $(this).dialog("close");
            },
            Nein: function () {
                $(this).dialog("close");
            }
        },
        close: function (event, ui) {
            $(this).remove();
        }
  });
};

function csSetPhoto(mode) {
	// Init
	// $('#f_cs_photo_disabled');
	// $('#f_cs_photo_hq');
	// $('#f_cs_photo_cs');
	csPhRrangeFrom = getSelectedValue('f_cs_photo_range_from');
	csPhRrangeTo = getSelectedValue('f_cs_photo_range_to');
	isCheckedDisabled = $('#f_cs_photo_disabled').prop('checked');
	// Check and set		
	if (mode == 'cs_photo_init' || mode == 'cs_photo_disabled') {
		 if (isCheckedDisabled) {
		 	  // Reset values
		 	  $('#f_cs_photo_hq').prop('checked', false);
		 	  $('#f_cs_photo_cs').prop('checked', false);
		 	  setSelectedValue('f_cs_photo_range_from', '');
		 	  setSelectedValue('f_cs_photo_range_to', '');
		 	  // Disable elements
		 	  $('#f_cs_photo_hq').prop('disabled', true);
		 	  $('#f_cs_photo_cs').prop('disabled', true);
		 	  $('#f_cs_photo_range_from').prop('disabled', true);
		 	  $('#f_cs_photo_range_to').prop('disabled', true);
		 } else {
		 	  $('#f_cs_photo_hq').prop('disabled', false);
		 	  $('#f_cs_photo_cs').prop('disabled', false);
		 	  $('#f_cs_photo_range_from').prop('disabled', false);
		 	  $('#f_cs_photo_range_to').prop('disabled', false);
		 	  // Check "cs_photo_hq" and "cs_photo_cs" regarding selectboxes
		 	  mode = 'cs_photo_init';
		 }
  }
  // Check both checkboxes
	if (mode == 'cs_photo_init' || mode == 'cs_photo_hq' || mode == 'cs_photo_cs') {
		 isCheckedHq = $('#f_cs_photo_hq').prop('checked');
		 isCheckedCs = $('#f_cs_photo_cs').prop('checked');
		 // Check both checkboxes being deactivated the reset and disable selectboxes
		 if (!isCheckedHq && !isCheckedCs) {
		 	  setSelectedValue('f_cs_photo_range_from', '');
		 	  setSelectedValue('f_cs_photo_range_to', '');
		 	  $('#f_cs_photo_range_from').prop('disabled', true);
		 	  $('#f_cs_photo_range_to').prop('disabled', true);
		 }
		 // If at least one of the checkboxes is activated the the selectboxes have to be activated
		 if (isCheckedHq || isCheckedCs) {
		 	  $('#f_cs_photo_range_from').prop('disabled', false);
		 	  $('#f_cs_photo_range_to').prop('disabled', false);
		 }
		 // If both checkboxes were disabled and at one of them is activated, set the range values to 0|1
		 if ((mode == 'cs_photo_hq' && isCheckedHq && !isCheckedCs) || (mode == 'cs_photo_cs' && isCheckedCs && !isCheckedHq)) {
		 	  setSelectedValue('f_cs_photo_range_from', '0');
		 	  setSelectedValue('f_cs_photo_range_to', '1');
		 }
	}
	// Check both selectboxes
	if (mode == 'cs_photo_range_from' || mode == 'cs_photo_range_to') {
		 // Check at least one selectbox is set to '' (<=> '----')
		 if (mode == 'cs_photo_range_from') {
        if (csPhRrangeFrom == '') {
		 	     setSelectedValue('f_cs_photo_range_to', '');
		 	  } else {
		      if (csPhRrangeTo == '') {
             setSelectedValue('f_cs_photo_range_to', csPhRrangeFrom);
		    	} else if (!(csPhRrangeFrom <= csPhRrangeTo)) {
		    	  setSelectedValue('f_cs_photo_range_to', csPhRrangeFrom);
		    	  alert('<?php echo getLngt("ACHTUNG: Die Untergrenze darf nicht größer sein als die Obergrenze! Die Obergrenze wurde automatisch auf denselben Wert gesetzt") ?>');
		      }
		    }
		 } else if (mode == 'cs_photo_range_to') {
        if (csPhRrangeTo == '') {
           setSelectedValue('f_cs_photo_range_from', '');
		 	  } else {
		      if (csPhRrangeFrom == '') {
		      	 setSelectedValue('f_cs_photo_range_from', '0');
		      } else if (!(csPhRrangeFrom <= csPhRrangeTo)) {
		      	setSelectedValue('f_cs_photo_range_from', csPhRrangeTo);
		      	alert('<?php echo getLngt("ACHTUNG: Die Obergrenze darf nicht kleiner sein als die Untergrenze! Die Untergrenze wurde automatisch auf denselben Wert gesetzt") ?>');
		      }
		 	  }
	   }
	}
}

function checkMandatoryFieldsCs () {
	var bgcol = 'red';
  $('#f_cmp_comp').css('background-color', bgcol);
  // $('#f_usr_name').css('background-color', bgcol);
  // $('#f_usr_firstname').css('background-color', bgcol);
  $('#f_usr_phone').css('background-color', bgcol);
  $('#f_usr_inv_email').css('background-color', bgcol);
  $('#f_usr_reminder_email').css('background-color', bgcol);
  // $('#f_usr_account').css('background-color', bgcol);
  <?php if ($companyId == "") : ?>
      $('#f_usr_password').css('background-color', bgcol);
      $('#f_usr_password2').css('background-color', bgcol);
  <?php endif; ?>
  $('#f_ad_street').css('background-color', bgcol);
  $('#f_cmp_hsno').css('background-color', bgcol);
  $('#f_ad_zipcode').css('background-color', bgcol);
  $('#f_ad_city').css('background-color', bgcol);
  // $('#f_cmp_tax_idno').css('background-color', bgcol);
  $('#f_cs_eid').css('background-color', bgcol);
  $('#f_vht_id_inv').css('background-color', bgcol);
  <?php if ($companyId == "") : ?>
  // $('#f_cmp_contract_date_day').css('background-color', bgcol);
  // $('#f_cmp_contract_date_month').css('background-color', bgcol);
  // $('#f_cmp_contract_date_year').css('background-color', bgcol);
	<?php else : ?>

  <?php endif ?>
  if ($('#f_cmp_stax_idno_mandatory').val() == '1') {
     $('#f_cmp_stax_idno').css('background-color', bgcol);
  }
}

function finishPageByCheckingMandatoryFields () {
	var doFinishPage = true;
	if ($('#f_cmp_comp').val() == '') {doFinishPage = false;};
	// if ($('#f_usr_name').val() == '') {doFinishPage = false;};
	// if ($('#f_usr_firstname').val() == '') {doFinishPage = false;};
	if ($('#f_usr_phone').val() == '') {doFinishPage = false;};
	if ($('#f_usr_inv_email').val() == '') {doFinishPage = false;};
	if ($('#f_usr_reminder_email').val() == '') {doFinishPage = false;};
	// if ($('#f_usr_account').val() == '') {doFinishPage = false;};
  <?php if ($companyId == "") : ?>
      if ($('#f_usr_password').val() == '') {doFinishPage = false;};
      if ($('#f_usr_password2').val() == '') {doFinishPage = false;};
  <?php endif; ?>
	if ($('#f_ad_street').val() == '') {doFinishPage = false;};
	if ($('#f_cmp_hsno').val() == '') {doFinishPage = false;};
	if ($('#f_ad_zipcode').val() == '') {doFinishPage = false;};
	if ($('#f_ad_city').val() == '') {doFinishPage = false;};
	// if ($('#f_cmp_tax_idno').val() == '') {doFinishPage = false;};
	if ($('#f_cs_eid').val() == '') {doFinishPage = false;};
	$('#f_cmp_stax_idno_mandatory').val('');  // Init flag for "stax_idno" being mandatory
	<?php if ($companyId == "") : ?>
	  // if ($('#f_cmp_contract_date_day').val() == '') {doFinishPage = false;};
	  // if ($('#f_cmp_contract_date_month').val() == '') {doFinishPage = false;};
	  // if ($('#f_cmp_contract_date_year').val() == '') {doFinishPage = false;};
// alert('f_cmp_stax_idno = ' + $('#f_cmp_stax_idno').val());
// alert('f_ad_country = ' + $('#f_ad_country').val());
    if ($('#f_cmp_stax_idno').val() == '') {
	     if ($('#f_ad_country').val() != 'DE') {
	     	  $('#f_cmp_stax_idno_mandatory').val('1');
	     	  doFinishPage = false;
	     	  alert('<?php echo getLngt("Die Anschrift liegt nicht in Deutschland. Die USt-IdNr. muss eingetragen werden!"); ?>');
	     }
	  }
	<?php else : ?>
		if ($('#f_cmp_stax_idno').val() == '') {
		   var adIdSrv = '<?php echo $f_ad_id_srv ?>';
	     var adCountrySrv = '<?php echo $f_ad_country_srv ?>';
	     var adIdInv = '<?php echo $f_ad_id_inv ?>';
	     var adCountryInv = '<?php echo $f_ad_country_inv ?>';
// alert('adIdSrv = ' + adIdSrv + ' => adCountrySrv = ' + adCountrySrv);
// alert('adIdInv = ' + adIdInv + ' => adCountryInv = ' + adCountryInv);
       if (adIdSrv > 0 && adCountrySrv != 'DE') {
	     	 $('#f_cmp_stax_idno_mandatory').val('1');
	     	 doFinishPage = false;
	     	 alert('<?php echo getLngt("Die Leistungsanschrift (Hauptkostenstelle) liegt nicht in Deutschland. Die USt-IdNr. muss eingetragen werden!"); ?>');
	     } else {
	     	if (adIdSrv == 0 && adIdInv > 0 && adCountryInv != 'DE') {
	     	   $('#f_cmp_stax_idno_mandatory').val('1');
	     	   doFinishPage = false;
	     	   alert('<?php echo getLngt("Die Leistungsanschrift (Hauptkostenstelle) existiert nicht und die Rechnungsanschrift liegt nicht in Deutschland. Die USt-IdNr. muss eingetragen werden!"); ?>');
	     	} else {
	     		if (adIdSrv == 0 && adIdInv == 0 && $('#f_ad_country').val() != 'DE') {
	     	   $('#f_cmp_stax_idno_mandatory').val('1');
	     	   doFinishPage = false;
	     	   alert('<?php echo getLngt("Die Leistungsanschrift (Hauptkostenstelle) und ebenfalls die Rechnungsanschrift existieren nicht. Die Hauptadresse liegt nicht in Deutschland. Die USt-IdNr. muss eingetragen werden!"); ?>');
	     	 }
	     	}
	    }
	  }
	<?php endif; ?>
  if (!doFinishPage) {
     checkMandatoryFieldsCs();
     alert('<?php echo getLngt("Bitte geben Sie alle mit * gekennzeichneten Felder ein!"); ?>');
  };
  return doFinishPage;
}
-->
</script>

</head>

<body class="menu_bgcol" onLoad="<?php echo $phpCurrentNavigationOnLoad ?><?php echo $javaScriptOut ?>csSetPhoto('cs_photo_init');displayStatusMessage();">

<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>

<div class="mc_page-header">
  <?php echo $pageHeadline ?>
</div>

<?php // echo htmlDivLineSpacer("5px", "", "left"); ?>
<div>
  <?php echo $buttonFilter ?>
  <?php echo $buttonCourier ?>
  <?php echo $buttonCostcenter ?>
  <?php echo $buttonService ?>
  <?php echo $buttonReport ?>
  <?php // echo $buttonCashmode ?>
  <?php echo $buttonGroup ?>
  <?php // echo $buttonContact ?>
  <?php echo $buttonPage2 ?>
  <?php // echo htmlDivLineSpacer("5px", "", "left"); ?>
  <?php // echo defineButtonType10(getLngt("Druckversion"), "action_prt", "openPrintLayout();", "120", "left", "0"); ?>
  <?php echo defineButtonType10(getLngt("PDF"), "action_pdf", "openCs2pdf();", "120", "left", "0"); ?>
  <?php echo $buttonCopyCustomer ?>
  <?php echo $buttonJobComplete ?>
  <?php echo $buttonAuthentication ?>
  <?php echo $buttonVisibility ?>
  <?php echo $buttonCsHistory ?>
  <?php echo $buttonReset2FA ?>
  <?php echo htmlDivLineSpacer("1px", "", "left"); ?>
  <?php echo defineButtonType10(getLngt("Speichern"), "action_save", "document.forms[0].f_act.value='" . $f_actText . "';finishPage();", "120", "left", "20"); ?>
  <?php echo defineButtonType10(getLngt("Zurücksetzen"), "action_reset", "clearAllFields();", "120", "left", "0"); ?>
  <?php echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "120", "left", "20"); ?>
  <?php echo $buttonContacts ?>
  <?php echo $buttonAppointments ?>
  <?php echo $buttonDocuments ?>
</div> 
<?php echo htmlDivLineSpacer("20px", "", "left"); ?>

<div class="maincontent mc_elem" name="maincontent" id="maincontent">
	

<form action="../admin/customer_special.php" method="post">
  <input type="hidden" name="f_act" value="">
  <input type="hidden" name="companyId" value="<?php echo $companyId ?>">
  <input type="hidden" name="f_usr_id" value="<?php echo $f_usr_id ?>">
  <input type="hidden" name="f_cmp_authenticated" value="<?php echo $f_cmp_authenticated ?>">
  <input type="hidden" name="f_cmp_visible" value="<?php echo $f_cmp_visible ?>">
  <input type="hidden" name="f_cmp_cashmode" value="<?php echo $f_cmp_cashmode ?>">
  <input type="hidden" name="cpfs" value="<?php echo $cpfs ?>">
  <input type="hidden" name="g_cs_id" value="<?php echo $g_cs_id ?>">
  <input type="hidden" name="g_csc_id" value="<?php echo $g_csc_id ?>">
  <input type="hidden" name="g_tx_id" value="<?php echo $g_tx_id ?>">
  <input type="hidden" name="g_br_id" value="<?php echo $g_br_id ?>">
  <input type="hidden" name="g_sales_emp_id" value="<?php echo $g_sales_emp_id ?>">
  <input type="hidden" name="g2_cs_id" value="<?php echo $g2_cs_id ?>">
  <input type="hidden" name="g2_csc_id" value="<?php echo $g2_csc_id ?>">
  <input type="hidden" name="f_eid_maxval" value="<?php echo $f_eid_maxval ?>">
  <input type="hidden" name="f_cs_eid_old_mandatory" id="f_cs_eid_old_mandatory" value="">
  <input type="hidden" name="f_cmp_stax_idno_mandatory" id="f_cmp_stax_idno_mandatory" value="">
  
  <input type="hidden" name="copyCs" value="">
  <?php echo $phpCurrentNavigationInputHidden ?>
  <input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">

  <input type="hidden" name="g_tx_id_rem" value="<?php echo $g_tx_id ?>">
  <input type="hidden" name="g_tx_sign_rem" value="<?php echo $g_tx_sign ?>">
  <input type="hidden" name="g_tx_value_rem" value="<?php echo $g_tx_value ?>">

   
  <div class="f10bp1_blue">
    <?php echo $title ?>&nbsp;&nbsp;&nbsp;<span class="f10bp1_red"><?php echo $displayTextAuthentication ?></span>
  </div>
  <?php echo htmlDivLineSpacer("20px", "", "left"); ?>

  <?php if ($companyId != "") : ?>
    <div>
      <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Ereignisse") ?>:</div>
      <div>
        <div style="float:left">
          <?php
            echo getLngt("Datensatzerstellung") . ":&nbsp";
            if ($f_cmp_new_date != "" && substr($f_cmp_new_date,0,10) != "0000-00-00") :
               echo substr($f_cmp_new_date,8,2) . "." . substr($f_cmp_new_date,5,2) . "." . substr($f_cmp_new_date,0,4);
            else :
               echo getLngt("Nicht bekannt");
            endif;
            echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; 
          ?>
          <?php 
            echo getLngt("Kunde seit") . ":&nbsp";
            // if ($f_cmp_type == "0" && (($f_cs_become_cs_date != "" && $f_cs_become_cs_date != "0000-00-00") || ($f_cmp_new_date != "" && substr($f_cmp_new_date,0,10) != "0000-00-00"))) :
            if (($f_cs_become_cs_date != "" && $f_cs_become_cs_date != "0000-00-00") || ($f_cmp_new_date != "" && substr($f_cmp_new_date,0,10) != "0000-00-00")) :
               echo ($f_cs_become_cs_date != "" && $f_cs_become_cs_date != "0000-00-00" ? substr($f_cs_become_cs_date,8,2) . "." . substr($f_cs_become_cs_date,5,2) . "." . substr($f_cs_become_cs_date,0,4) : getLngt("Erstellung des Datensatzes"));
            else :
               echo getLngt("Nicht bekannt");
            endif;
            echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
          ?>
          <?php 
            $tmpModifyDate = $f_cs_modify;
            if ($f_cmp_modify > $f_cs_modify) : $tmpModifyDate = $f_cmp_modify; endif;
            echo getLngt("Letzte Modifikation") . ":&nbsp;" . substr($tmpModifyDate,8,2) . "." . substr($tmpModifyDate,5,2) . "." . substr($tmpModifyDate,0,4) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
          ?>
          <?php
            if ($companyId != "") :
               $f_cs_eid_old = getFieldValueFromClause("genericdatacontainer", "gdc_content", "gdc_obj_type = 'cs' AND gdc_gen_fieldname = 'eid_old' AND gdc_obj_id = '" . $f_cs_id . "'");
               $tmpStyleOut = "max-width: 10ch;";
               if ($f_cs_eid_old != "") :                  
                  $csIdOld = getFieldValueFromId("customer", "cs_eid", $f_cs_eid_old, "cs_id");
                  if ($csIdOld != "") :
                     $tmpStyleOut .= "background-color: #00FF00;";
                  else :
                     $tmpStyleOut .= "background-color: red;";
                  endif;
               endif;
               if ($tmpStyleOut != "") :
                  $tmpStyleOut = "style=\"" . $tmpStyleOut . "\"";
               endif;
               echo getLngt("Alte ExtID nach Umfirmierung") . ":&nbsp;" . "<input class=\"f8np1\" " . $tmpStyleOut . " type=\"text\" id=\"f_cs_eid_old\" name=\"f_cs_eid_old\" value=\"" . $f_cs_eid_old . "\" maxlength=\"10\" size=\"10\" tabindex=\"23\">";
               echo "</div>";
               echo defineButtonType08("...", "action_cscsc", "searchCsCsc('0000000000001','','f_cs_eid_old');", "30", "left", "2");
               echo "<div style=\"float:left\">";
               echo "<a href=\"javascript:clearExtIdOld();\"><img src=\"../images/waste.png\" border=\"0\" height=\"15\" width=\"12\"></a>";
               echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
            endif;
          ?>
          <?php
            if ($maskCsShowLastJob == "1") :
               $lastJbId = getLastJob($companyId, "cmp");
               if ($lastJbId != "") :
                  $dbhistory = checkHistoryLevel($dbhistory, "jb", $job_id);
                  $dbhistory = getDBNames($dbhistory);
                  // echo getLngt("Letzter Auftrag") . ":&nbsp;" . $lastJbId;
                  echo getLngt("Letzter Auftrag") . ":&nbsp;" . "<a href=\"javascript:openJob('" . ec($lastJbId) . "');\">" . $lastJbId . "</a>";
                  echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp";
               endif;
            endif;
          ?>          
        </div>
      </div>
    </div>
    <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
  <?php endif; ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Firma*") ?>, <?php echo getLngt("Zusatz") ?>:</div>
    <div>
      <div style="float:left">      	
        <input class="f8np1" type="text" id="f_cmp_comp" name="f_cmp_comp" value="<?php echo $f_cmp_comp ?>" maxlength="35" size="50" tabindex="10" onChange="checkCmpComp();">        
        <input class="f8np1" type="text" id="f_cmp_comp2" name="f_cmp_comp2" value="<?php echo $f_cmp_comp2 ?>" maxlength="35"  size="50" tabindex="20">
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        ExtID*:&nbsp;
      </div>
      <?php echo $f_cs_eid_out ?>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
      <div style="float:left">
      <input class="f8np1" type="text" id="f_cmp_comp3" name="f_cmp_comp3" value="<?php echo $f_cmp_comp3 ?>" maxlength="35" size="50" tabindex="21">
      <input class="f8np1" type="text" id="f_cmp_comp4" name="f_cmp_comp4" value="<?php echo $f_cmp_comp4 ?>" maxlength="35" size="50" tabindex="22">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  
  <?php if ($companyId == "") : ?>
    <div>
      <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
      <div>
        <div style="float:left">
        <?php echo getLngt("Alte ExtID nach Umfirmierung") . ":&nbsp;"; ?><input class="f8np1" type="text" id="f_cs_eid_old" name="f_cs_eid_old" value="<?php echo $f_cs_eid_old ?>" maxlength="10" size="10" tabindex="23">
        <?php
          echo "</div>";
          echo defineButtonType08("...", "action_cscsc", "searchCsCsc('0000000000001','','f_cs_eid_old');", "30", "left", "2");
          echo "<div style=\"float:left\">";
          echo "<a href=\"javascript:clearExtIdOld();\"><img src=\"../images/waste.png\" border=\"0\" height=\"15\" width=\"12\"></a>";
          echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        ?>
      </div>
    </div>
    <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <?php endif; ?>
  
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Übernahme") ?>:</div>
    <div>
      <input class="f8np1" type="radio" id="f_cmp_changemode" name="f_cmp_changemode" value="0" checked tabindex="32"> <?php echo getLngt("Keine") ?>
      <input class="f8np1" type="radio" id="f_cmp_changemode" name="f_cmp_changemode" value="1" tabindex="33"> <?php echo getLngt("Nur Hauptkostenstelle") ?>
      <input class="f8np1" type="radio" id="f_cmp_changemode" name="f_cmp_changemode" value="2" tabindex="34"> <?php echo getLngt("Alle Kostenstellen") ?>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Adresstypen") ?>:
      &nbsp;&nbsp;
      <?php echo getLngt("Rechnungsadr.") ?>&nbsp;<input class="f8np1" type="checkbox" name="f_adt_change2[]" value="2" tabindex="36">
      &nbsp;&nbsp;
      <?php echo getLngt("Abhol-/Lieferadr.") ?>&nbsp;<input class="f8np1" type="checkbox" name="f_adt_change2[]" value="4" tabindex="37">
      &nbsp;&nbsp;
      <?php echo getLngt("Leistungsadr.") ?>&nbsp;<input class="f8np1" type="checkbox" name="f_adt_change2[]" value="1" tabindex="38">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Tel.*") ?>, <?php echo getLngt("Mobil") ?>, <?php echo getLngt("Fax") ?>:</div>
    <div>
      <input class="f8np1" type="text" id="f_usr_phone" name="f_usr_phone" value="<?php echo $f_usr_phone ?>" tabindex="40">
      <input class="f8np1" type="text" id="f_usr_phone2" name="f_usr_phone2" value="<?php echo $f_usr_phone2 ?>" tabindex="50">
      <input class="f8np1" type="text" id="f_usr_fax" name="f_usr_fax" value="<?php echo $f_usr_fax ?>" tabindex="60">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px"); ?>
  
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("St.-Nr.") ?>, <?php echo getLngt("USt-IdNr.") ?>:</div>
    <div>
    	<input class="f8np1" type="text" id="f_cmp_tax_idno" name="f_cmp_tax_idno" value="<?php echo $f_cmp_tax_idno ?>" size="30" tabindex="70">
    	<input class="f8np1" type="text" id="f_cmp_stax_idno" name="f_cmp_stax_idno" value="<?php echo $f_cmp_stax_idno ?>" size="30" tabindex="71">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px"); ?>
  
  <div>  
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Email") ?>:</div>
    <div>
      <input class="f8np1" type="text" id="f_usr_email" name="f_usr_email" value="<?php echo $f_usr_email ?>" size="40" tabindex="80">
      &nbsp;&nbsp;
      <?php echo getLngt("Mail bei:") ?>&nbsp;
      <?php echo getLngt("Erledigung") ?>:&nbsp;
      <input class="f8np1" type="radio" id="f_cs_jbstatusmail" name="f_cs_jbstatusmail" value="0" <?php echo $f_cs_jbstatusmail_0 ?> tabindex="90"> <?php echo getLngt("N") ?>
      <input class="f8np1" type="radio" id="f_cs_jbstatusmail" name="f_cs_jbstatusmail" value="1" <?php echo $f_cs_jbstatusmail_1 ?> tabindex="94"> <?php echo getLngt("J") ?>
      &nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Erfassung") ?>:&nbsp;
      <input class="f8np1" type="radio" id="f_cs_jbstatusmail3" name="f_cs_jbstatusmail3" value="0" <?php echo $f_cs_jbstatusmail3_0 ?> tabindex="98"> <?php echo getLngt("N") ?>
      <input class="f8np1" type="radio" id="f_cs_jbstatusmail3"name="f_cs_jbstatusmail3" value="1" <?php echo $f_cs_jbstatusmail3_1 ?> tabindex="100"> <?php echo getLngt("J") ?>
      &nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Abholung") ?>:&nbsp;
      <input class="f8np1" type="radio" id="f_cs_jbstatusmail2" name="f_cs_jbstatusmail2" value="0" <?php echo $f_cs_jbstatusmail2_0 ?> tabindex="102"> <?php echo getLngt("N") ?>
      <input class="f8np1" type="radio" id="f_cs_jbstatusmail2" name="f_cs_jbstatusmail2" value="1" <?php echo $f_cs_jbstatusmail2_1 ?> tabindex="104"> <?php echo getLngt("J") ?>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
      <?php echo getLngt("Mails an") . ": " ?>
      &nbsp;&nbsp;
      <input class="f8np1" type="radio" name="f_cs_jbstatusmail2csc" value="0" <?php echo $f_cs_jbstatusmail2csc_0 ?> tabindex="106"> <?php echo getLngt("Email-Adresse(n) im Kundenstammblatt") ?>
      &nbsp;&nbsp;
      <input class="f8np1" type="radio" name="f_cs_jbstatusmail2csc" value="1" <?php echo $f_cs_jbstatusmail2csc_1 ?> tabindex="107"> <?php echo getLngt("Email-Adresse(n) in der Rechnungsadresse der jeweiligen Bezahler-Kostenstellen") ?>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
      <?php echo getLngt("Mailausgabe") . ": " ?>&nbsp;
      <?php echo getLngt("Preis anzeigen") . ": " ?>&nbsp;
      <input class="f8np1" type="radio" name="f_cs_jbstatusmail_price" value="0" <?php echo $f_cs_jbstatusmail_price_0 ?> tabindex="108"> <?php echo getLngt("N") ?>
      <input class="f8np1" type="radio" name="f_cs_jbstatusmail_price" value="1" <?php echo $f_cs_jbstatusmail_price_1 ?> tabindex="109"> <?php echo getLngt("J") ?>
      &nbsp;&nbsp;&nbsp;
      <?php 
         $mailSuccessRequest = getParameterValue("0", "MAIL_SUCCESS_REQUEST", $hq_id);
         if ($mailSuccessRequest != "") :
      ?>
            <?php echo getLngt("Mitarbeiterdaten anzeigen bei Erledigung") . ": " ?>&nbsp;
            <input class="f8np1" type="radio" name="f_cs_jbstatusmail_emp" value="0" <?php echo $f_cs_jbstatusmail_emp_0 ?> tabindex="110"> <?php echo getLngt("N") ?>
            <input class="f8np1" type="radio" name="f_cs_jbstatusmail_emp" value="1" <?php echo $f_cs_jbstatusmail_emp_1 ?> tabindex="111"> <?php echo getLngt("J") ?>
            &nbsp;&nbsp;&nbsp;
      <?php 
         endif;
      ?>
      <?php echo getLngt("PDF-Anhang mitsenden") . ": " ?>&nbsp;
      <input class="f8np1" type="radio" name="f_cs_jbstatusmail_pdf" value="0" <?php echo $f_cs_jbstatusmail_pdf_0 ?> tabindex="111"> <?php echo getLngt("N") ?>
      <input class="f8np1" type="radio" name="f_cs_jbstatusmail_pdf" value="1" <?php echo $f_cs_jbstatusmail_pdf_1 ?> tabindex="112"> <?php echo getLngt("J") ?>
    </div>
  </div>  
  <?php echo htmlDivLineSpacer("10px"); ?>
  
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
      <?php echo getLngt("Extrafelder") . ": " ?>&nbsp;
      <?php echo getLngt("Etappenbemerkung") . ": " ?><input class="f8np1" type="checkbox" name="f_cs_jbstatusmail_field1[]" value="1" <?php echo ($f_cs_jbstatusmail_field1 == "1" ? "checked" : "") ?> tabindex="113">
      &nbsp;&nbsp;&nbsp;
      <?php if (false) : ?>
      <?php echo getLngt("VPA-Mobil-Nr.") . ": " ?><input class="f8np1" type="checkbox" name="f_cs_jbstatusmail_field2[]" value="1" <?php echo ($f_cs_jbstatusmail_field2 == "1" ? "checked" : "") ?> tabindex="114">
      &nbsp;&nbsp;&nbsp;
      <?php endif; ?>
      <?php echo getLngt("Rechnungstext") . ": " ?><input class="f8np1" type="checkbox" name="f_cs_jbstatusmail_field3[]" value="1" <?php echo ($f_cs_jbstatusmail_field3 == "1" ? "checked" : "") ?> tabindex="115">
      &nbsp;&nbsp;&nbsp;
      <?php if (false) : ?>
      <?php echo getLngt("Fotos") . ": " ?><input class="f8np1" type="checkbox" name="f_cs_jbstatusmail_field6[]" value="1" <?php echo ($f_cs_jbstatusmail_field6 == "1" ? "checked" : "") ?> tabindex="115">
      &nbsp;&nbsp;&nbsp;
      <?php endif; ?>
      <?php echo getLngt("KFZ-Kennzeichen") . ": " ?><input class="f8np1" type="checkbox" name="f_cs_jbstatusmail_field7[]" value="1" <?php echo ($f_cs_jbstatusmail_field7 == "1" ? "checked" : "") ?> tabindex="115">
      &nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Bemerkung Kundenmail Kurier") . ": " ?><input class="f8np1" type="checkbox" name="f_cs_jbstatusmail_field9[]" value="1" <?php echo ($f_cs_jbstatusmail_field9 == "1" ? "checked" : "") ?> tabindex="115">
      &nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Bemerkung Kundenmail Innendienst") . ": " ?><input class="f8np1" type="checkbox" name="f_cs_jbstatusmail_fieldA[]" value="1" <?php echo ($f_cs_jbstatusmail_fieldA == "1" ? "checked" : "") ?> tabindex="115">
    </div>
  </div>  
  <?php echo htmlDivLineSpacer("10px"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
      <?php echo getLngt("KEINE Fußzeile beim Email-Versand") . ": " ?><input class="f8np1" type="checkbox" name="f_cs_par_email_no_footer[]" value="1" <?php echo $f_cs_par_email_no_footer_0 ?> tabindex="116">
      &nbsp;&nbsp;&nbsp;
    </div>
  </div>  
  <?php echo htmlDivLineSpacer("10px"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
      <?php echo getLngt("Abfrage nach Bearbeitung eines erledigten Auftrags für einen zusätzlichen Mailversand") . ": " ?><input class="f8np1" type="checkbox" name="f_cs_jbstatusmail_field4[]" value="1" <?php echo ($f_cs_jbstatusmail_field4 == "1" ? "checked" : "") ?> tabindex="116">
      &nbsp;&nbsp;&nbsp;
    </div>
  </div>  
  <?php echo htmlDivLineSpacer("10px"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
      <?php echo getLngt("Zusätzlicher Mailversand nach Erledigung einer Station") . ": " ?><input class="f8np1" type="checkbox" name="f_cs_jbstatusmail_field5[]" value="1" <?php echo ($f_cs_jbstatusmail_field5 == "1" ? "checked" : "") ?> tabindex="117">
      &nbsp;&nbsp;&nbsp;
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
      <?php echo getLngt("Mailversand nach Auftragsstorno") . ": " ?><input class="f8np1" type="checkbox" name="f_cs_jbstatusmail_field8[]" value="1" <?php echo ($f_cs_jbstatusmail_field8 == "1" ? "checked" : "") ?> tabindex="117">
      &nbsp;&nbsp;&nbsp;
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
      <?php echo getLngt("Mailversand bei Vermittlungsstau") . ": " ?><input class="f8np1" type="checkbox" name="f_cs_jb_jam_waittime[]" value="1" <?php echo ($f_cs_jb_jam_waittime > "0" ? "checked" : "") ?> tabindex="117">
      &nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Wartezeit [Minuten]") ?>:
      &nbsp;&nbsp;
      <select name="f_cs_jb_jam_waittime_minutes" class="f8np1">"<?php echo addOptionsFromRange("0","60",$f_cs_jb_jam_waittime_minutes,"","","","5") ?></select>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
      <?php echo getLngt("Ausgabe der Ankunftszeit:") ?>
      <input class="f8np1" type="radio" name="f_cs_par_email_arrivaltime" value="0" <?php if ($f_cs_par_email_arrivaltime == "0") : echo "checked"; endif; ?> tabindex="118"> <?php echo getLngt("Nein") ?>
      <input class="f8np1" type="radio" name="f_cs_par_email_arrivaltime" value="1" <?php if ($f_cs_par_email_arrivaltime == "1") : echo "checked"; endif; ?> tabindex="119"> <?php echo getLngt("Ja") ?>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
      <?php echo getLngt("Verwendete Sprache in den Emails:") ?> 
      <input class="f8np1" type="radio" name="f_cs_par_email_lng" value="0" <?php if ($f_cs_par_email_lng == "0") : echo "checked"; endif; ?> tabindex="118"> <?php echo getLngt("Deutsch") ?>
      <input class="f8np1" type="radio" name="f_cs_par_email_lng" value="1" <?php if ($f_cs_par_email_lng == "1") : echo "checked"; endif; ?> tabindex="119"> <?php echo getLngt("Englisch") ?>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Fotos:") ?></div>
    <div>
      <?php echo getLngt("Fotofunktion deaktiviert") . ": " ?><input class="f8np1" type="checkbox" id="f_cs_photo_disabled" name="f_cs_photo_disabled" value="1" <?php echo ($f_cs_photo_disabled > "0" ? "checked" : "") ?> onChange="csSetPhoto('cs_photo_disabled');" tabindex="120">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Foto Zentrale") . ": " ?><input class="f8np1" type="checkbox" id="f_cs_photo_hq" name="f_cs_photo_hq" value="1" <?php echo ($f_cs_photo_hq > "0" ? "checked" : "") ?> onChange="csSetPhoto('cs_photo_hq');" tabindex="120">
      &nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Foto KAE") . ": " ?><input class="f8np1" type="checkbox" id="f_cs_photo_cs" name="f_cs_photo_cs" value="1" <?php echo ($f_cs_photo_cs > "0" ? "checked" : "") ?> onChange="csSetPhoto('cs_photo_cs');" tabindex="120">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Fotos mindestens") . ": " ?>
      <select id="f_cs_photo_range_from" name="f_cs_photo_range_from" class="f8np1" onChange="csSetPhoto('cs_photo_range_from');">"
      	<option value="" selected>----</option>
        <?php echo addOptionsFromRange("0","5",$f_cs_photo_range_from,"") ?>
      </select>
      &nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Fotos höchstens") . ": " ?>
      <select id="f_cs_photo_range_to" name="f_cs_photo_range_to" class="f8np1" onChange="csSetPhoto('cs_photo_range_to');">"
      	<option value="" selected>----</option>
        <?php echo addOptionsFromRange("0","5",$f_cs_photo_range_to,"") ?>
      </select>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>
  <div>  
  	<?php
  	  $outUsrInvEmailMandatory = "*";
  	  if ($companyId != "" && getFieldValueFromId("company", "cmp_id", $companyId, "cmp_authenticated") != "1") :
  	     $outUsrInvEmailMandatory = "";
  	  endif;
  	?>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Rechnungs-Email") . $outUsrInvEmailMandatory ?>:</div>
    <div>
      <input class="f8np1" type="text" id="f_usr_inv_email" name="f_usr_inv_email" value="<?php echo $f_usr_inv_email ?>" size="40" tabindex="120">
      &nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Mahn-Email") . $outUsrInvEmailMandatory ?>:&nbsp;&nbsp;
      <input class="f8np1" type="text" id="f_usr_reminder_email" name="f_usr_reminder_email" value="<?php echo $f_usr_reminder_email ?>" size="40" tabindex="120">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>
  <div>  
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Nachhaltigkeits-Email") ?>:</div>
    <div style="float:left">
      <input class="f8np1" type="text" id="f_cmp_sustainability_email" name="f_cmp_sustainability_email" value="<?php echo $f_cmp_sustainability_email ?>" size="40" tabindex="120">
      &nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Automatisches Intervall des Reportversands") ?>:
      <select name="f_cmp_sustainability_interval" class="f8np1">"
        <?php echo addOptionsFromTable("metatype","mt_sort","mt_value","mt_sort","mt_type = 'interval'",$f_cmp_sustainability_interval) ?>
      </select>
      &nbsp;&nbsp;&nbsp;&nbsp;
    </div>
    <?php 
      $cmpSustainabilityEmail = getFieldValueFromId("company", "cmp_id", $companyId, "cmp_sustainability_email");
      if ($cmpSustainabilityEmail != "") :
         if (authCheckEmployeeRights($emp_id, "32")) :
            echo defineButtonType08("Report versenden", "action_sustainability_email", "sustainabilityFinishPage();");
         endif;
      endif;
    ?>
  </div>
  <?php echo htmlDivLineSpacer("20px", "", "left"); ?>
  <?php if ($parCsTracking == "1") : ?>
    <div>
      <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Sendungsverfolgung") ?>:</div>
      <div>      	
<?php if (false) : ?>
        <?php echo getLngt("Bezahler selbst") ?>&nbsp;<input class="f8np1" type="checkbox" name="f_cs_tracking[]" value="1" <?php echo $f_cs_tracking_0 ?> tabindex="350">
        &nbsp;&nbsp;
        <?php echo getLngt("Endkunde") ?>&nbsp;<input class="f8np1" type="checkbox" name="f_cs_tracking[]" value="2" <?php echo $f_cs_tracking_1 ?> tabindex="360">        
<?php else : ?>
        <?php echo getLngt("Endkunde") ?>&nbsp;<input class="f8np1" type="checkbox" name="f_cs_tracking[]" value="1" <?php echo $f_cs_tracking_0 ?> tabindex="350">
<?php endif ?>
        &nbsp;&nbsp;&nbsp;&nbsp;
      	<?php echo getLngt("Durchschnittliche Ladedauer [Minuten]") ?>:
      	&nbsp;&nbsp;
      	<select name="f_cs_charging_time" class="f8np1">"
      	  <?php echo addOptionsFromRange("0","15",$f_cs_charging_time,"") ?>
      	  <?php echo addOptionsFromRange("20","60",$f_cs_charging_time,"","","","5") ?>
      	</select>
        &nbsp;&nbsp;&nbsp;&nbsp;
      	<?php echo getLngt("Unschärfeaufschlag [Minuten]") ?>:
      	&nbsp;&nbsp;
      	<select name="f_cs_blur_markup_time" class="f8np1">"<?php echo addOptionsFromRange("0","60",$f_cs_blur_markup_time,"","","","5") ?></select>
      </div>
    </div>
    <?php echo htmlDivLineSpacer("10px"); ?>
  <?php endif; ?>

  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Newsletter") ?>:</div>
    <div>
      <?php echo getLngt("Abonnement:") ?>&nbsp;
      <input class="f8np1" type="radio" name="f_cmp_newsletter" value="0" <?php echo $f_cmp_newsletter_0 ?> tabindex="120"> <?php echo getLngt("Nein") ?>
      <input class="f8np1" type="radio" name="f_cmp_newsletter" value="1" <?php echo $f_cmp_newsletter_1 ?> tabindex="121"> <?php echo getLngt("Ja") ?>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("DSGVO") ?>:</div>
    <div>
      <?php echo getLngt("Zustimmung:") ?>&nbsp;
      <input class="f8np1" type="radio" name="f_cmp_dsgvo" value="0" <?php echo $f_cmp_dsgvo_0 ?> tabindex="120"> <?php echo getLngt("Nein") ?>
      <input class="f8np1" type="radio" name="f_cmp_dsgvo" value="1" <?php echo $f_cmp_dsgvo_1 ?> tabindex="121"> <?php echo getLngt("Ja") ?>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <?php if (false) : ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Abliefernachweis") ?>:</div>
    <div>
      <?php echo getLngt("Foto:") ?>&nbsp;
      <input class="f8np1" type="radio" name="f_cmp_proof_delivery" value="0" <?php echo $f_cmp_proof_delivery_0 ?> tabindex="120"> <?php echo getLngt("Nein") ?>
      <input class="f8np1" type="radio" name="f_cmp_proof_delivery" value="1" <?php echo $f_cmp_proof_delivery_1 ?> tabindex="121"> <?php echo getLngt("Ja") ?>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>
  <?php endif; ?>

  <?php if (false) : ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Endgeräte") ?>:</div>
    <div>
      <?php echo getLngt("Auswertung:") ?>&nbsp;
      <input class="f8np1" type="radio" name="f_cmp_pda_usage" value="0" <?php echo $f_cmp_pda_usage_0 ?> tabindex="120"> <?php echo getLngt("Nein") ?>
      <input class="f8np1" type="radio" name="f_cmp_pda_usage" value="1" <?php echo $f_cmp_pda_usage_1 ?> tabindex="121"> <?php echo getLngt("Ja") ?>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>
  <?php endif; ?>

  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Bank") ?>, <?php echo getLngt("BLZ") ?>, <?php echo getLngt("Kto.") ?>:</div>
    <div>
      <input class="f8np1" type="text" id="f_cmp_bank" name="f_cmp_bank" value="<?php echo $f_cmp_bank ?>" size="50" tabindex="125">
      <input class="f8np1" type="text" id="f_cmp_bankno" name="f_cmp_bankno" value="<?php echo $f_cmp_bankno ?>" tabindex="130">
      <input class="f8np1" type="text" id="f_cmp_bankacc" name="f_cmp_bankacc" value="<?php echo $f_cmp_bankacc ?>" tabindex="135">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input class="f8np1" type="radio" id="f_cmp_bankmode" name="f_cmp_bankmode" value="0" <?php echo $f_cmp_bankmode_0 ?> tabindex="140"> <?php echo getLngt("Rechnung") ?>
      <input class="f8np1" type="radio" id="f_cmp_bankmode" name="f_cmp_bankmode" value="1" <?php echo $f_cmp_bankmode_1 ?> tabindex="150"> <?php echo getLngt("Einzug") ?>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>
  
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("IBAN") ?>, <?php echo getLngt("BIC/Swift") ?>:</div>
    <div>
    	<div style="float:left">
        <input class="f8np1" type="text" id="f_cmp_iban" name="f_cmp_iban" value="<?php echo $f_cmp_iban ?>" maxlength="40" size="40" tabindex="152" onChange="javascript:checkIBAN();">
      </div>
      <?php echo defineButtonType08("...", "action_iban", "createIBAN();", "30", "left"); ?>      
      <div>
      	&nbsp;&nbsp;&nbsp;
        <input class="f8np1" type="text" id="f_cmp_swift" name="f_cmp_swift" value="<?php echo $f_cmp_swift ?>" maxlength="20" size="20"  tabindex="154" onChange="javascript:swiftValidate();">
      </div>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Str.*") ?>, <?php echo getLngt("Hausnr.*") ?>:</div>
    <div>
      <div style="float:left">
        <input class="f8np1" type="text" id="f_ad_street" name="f_ad_street" value="<?php echo $f_ad_street ?>" size="50" tabindex="160">
        <input class="f8np1" type="text" id="f_cmp_hsno" name="f_cmp_hsno" value="<?php echo $f_cmp_hsno ?>" size="5" tabindex="170">
        &nbsp;&nbsp;
      </div>
      <?php echo defineButtonType08("...", "action_ad", "searchAddress();", "30", "left"); ?>
      <div>
        &nbsp;&nbsp;
        <input type="checkbox" name="f_noaddressvalidation[]" value="1" tabindex="175">&nbsp;<?php echo getLngt("(Keine Prüfung)") ?>
      </div>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("PLZ*") ?>, <?php echo getLngt("Ort*") ?>:</div>
    <div>
      <input class="f8np1" type="text" id="f_ad_zipcode" name="f_ad_zipcode" value="<?php echo $f_ad_zipcode ?>" size="5" tabindex="180">
      <input class="f8np1" type="text" id="f_ad_city" name="f_ad_city" value="<?php echo $f_ad_city ?>" size="50" tabindex="190">
      <select class="f8np1" id="f_ad_country" name="f_ad_country" tabindex="195">
        <?php echo getCountryCodesAsOptions($f_ad_country); ?>
      </select>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Übernahme") ?>:</div>
    <div>
      <input class="f8np1" type="radio" name="f_ad_changemode" value="0" checked tabindex="212"> <?php echo getLngt("Keine") ?>
      <input class="f8np1" type="radio" name="f_ad_changemode" value="1" tabindex="213"> <?php echo getLngt("Nur Hauptkostenstelle") ?>
      <input class="f8np1" type="radio" name="f_ad_changemode" value="2" tabindex="214"> <?php echo getLngt("Alle Kostenstellen") ?>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Adresstypen") ?>:
      &nbsp;&nbsp;
      <?php echo getLngt("Rechnungsadr.") ?>&nbsp;<input class="f8np1" type="checkbox" name="f_adt_change[]" value="2" tabindex="216">
      &nbsp;&nbsp;
      <?php echo getLngt("Abhol-/Lieferadr.") ?>&nbsp;<input class="f8np1" type="checkbox" name="f_adt_change[]" value="4" tabindex="218">
      &nbsp;&nbsp;
      <?php echo getLngt("Leistungsadr.") ?>&nbsp;<input class="f8np1" type="checkbox" name="f_adt_change[]" value="1" tabindex="218">
    </div>
  </div>  
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Name") ?>, <?php echo getLngt("Vorname") ?>:</div>
    <div>
      <input class="f8np1" type="text" name="f_usr_name" value="<?php echo $f_usr_name ?>" size="50" tabindex="225">&nbsp;
      <input class="f8np1" type="text" name="f_usr_firstname" value="<?php echo $f_usr_firstname ?>" size="50" tabindex="230">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px"); ?>
  <div>  
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Login") ?>, <?php echo getLngt("Passwort") ?>:</div>
    <div>
      <input class="f8np1" type="text" name="f_usr_account" value="<?php echo $f_usr_account ?>" tabindex="240">
      <?php echo $setPasswordForNewUserOutput ?>
      <?php echo $setPassword2ForNewUserOutput ?> <?php echo getLngt("(Wiederholung)") ?>
    </div>
  </div>  
  <?php echo htmlDivLineSpacer("5px"); ?>
  <div>  
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("KAE") ?>:</div>
    <div>
      <?php echo getLngt("Kundenseitige&nbsp;Auftragserfassung:") ?> <input class="f8np1" type="checkbox" name="f_cs_jbedit[]" value="1" <?php echo $f_cs_jbedit_0 ?> tabindex="260">
      &nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Automatische Vermittlung KAE:") ?> <input class="f8np1" type="checkbox" name="f_cs_ar[]" value="1" <?php echo $f_cs_ar_0 ?> tabindex="261">
      &nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Selbsterfassungsrabatt:") ?> <input class="f8np1" type="checkbox" name="f_cs_jb_creator_discount[]" value="1" <?php echo $f_cs_jb_creator_discount_0 ?> tabindex="262">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
    	<?php echo getLngt("Farbe der Aufträge in den Auftragslisten:") ?> <input type="hidden" id="f_cs_par_order_color" name="f_cs_par_order_color" value="<?php echo $f_cs_par_order_color ?>">
    	<input type="button" id="f_cs_button_job_col" style="height:20px; width:20px; background-color: #<?php echo $f_cs_par_order_color ?>;" onclick="toggleJobColor();">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <?php echo getWebColors(); ?>

  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <?php if (false) : ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
    	<?php echo getLngt("Warnendes Blinken in den Auftragslisten bei Aufträgen, die der Kunde eingestellt hat, wenn noch kein Preis vorliegt:") ?> <input class="f8np1" type="checkbox" name="f_cs_price_warn_uncomplete[]" value="1" <?php echo $f_cs_price_warn_uncomplete_0 ?> tabindex="">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <?php endif; ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
    	<?php echo getLngt("In den Auftragslisten werden die Aufträge ausgeblendet:") ?> <input class="f8np1" type="checkbox" name="f_cs_joblist_disabled[]" value="1" <?php echo $f_cs_joblist_disabled_0 ?> tabindex="" disabled>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
    	<?php echo getLngt("Aktivierung kundenseitiges Auftrags-Storno:") ?> <input class="f8np1" type="checkbox" name="f_cs_jb_storno[]" value="1" <?php echo $f_cs_jb_storno_0 ?> tabindex="">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
    	<?php echo getLngt("Aktivierung kundenseitige Auftragsvermittlung an bevorzugte Transporteure:") ?> <input class="f8np1" type="checkbox" name="f_cs_jb_dispo[]" value="1" <?php echo $f_cs_jb_dispo_0 ?> <?php echo $f_cs_jb_dispo_disabled ?> tabindex="">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
    	<?php echo getLngt("Preisausgabe in der KAE:") ?> <input class="f8np1" type="checkbox" name="f_cs_par_dont_make[]" value="1" <?php echo $f_cs_par_dont_make_0 ?> tabindex="">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
    	<?php echo getLngt("Ausschließlich Calculator-Nutzung zur Preisberechnung:") ?> <input class="f8np1" type="checkbox" name="f_cs_par_calc_usage[]" value="1" <?php echo $f_cs_par_calc_usage_0 ?> tabindex="">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
    	<?php echo getLngt("Adresse ungeprüft übernehmen in KAE:") ?> <input class="f8np1" type="checkbox" name="f_cs_par_cst_all_ad[]" value="1" <?php echo $f_cs_par_cst_all_ad_0 ?> tabindex="">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Rabatt") ?>, <?php echo getLngt("Porto") ?>:</div>
    <div>
      <input class="f8np1" type="text" name="f_cs_discount" value="<?php echo $f_cs_discount ?>" size="5" maxlength="5" tabindex="270">%
      <input class="f8np1" type="text" name="f_cmp_postage" value="<?php echo $f_cmp_postage ?>" size="5" maxlength="5" tabindex="280">€
      &nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Rabatt-Eintrag auf Fixpreis:") ?>&nbsp;
      <input class="f8np1" type="checkbox" name="f_cs_fixprice_discount[]" value="1" <?php echo $f_cs_fixprice_discount_0 ?> tabindex="285">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <?php if (false) : ?>
      <?php echo getLngt("Provision:") ?>&nbsp;
      <input class="f8np1" type="text" name="f_cs_prov" value="<?php echo $f_cs_prov ?>" size="5" maxlength="5" onChange="javascript:checkCsProv();" tabindex="287">%
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("SAP-Sortierfeld:") ?>&nbsp;
      <input class="f8np1" type="text" name="f_cmp_match2" value="<?php echo $f_cmp_match2 ?>" size="10" maxlength="50" tabindex="290">
      <?php endif; ?>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Aufschlag") ?>:</div>
    <div>
      <?php echo getLngt("Treibstoffaufschlag erheben:") ?>&nbsp;
      <input class="f8np1" type="checkbox" name="f_cs_markup[]" value="1" <?php echo $f_cs_markup_0 ?> tabindex="292">
      &nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Treibstoffaufschlag:") ?>&nbsp;
      <input class="f8np1" type="text" name="f_cs_markup_prov" value="<?php echo $f_cs_markup_prov ?>" size="5" maxlength="5" tabindex="294">%
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("MwSt") ?>, <?php echo getLngt("Branche") ?>:</div>
    <div>
      <div style="float:left">
        <input class="f8np1" type="text" name="g_tx_value" value="<?php echo $g_tx_value ?>" size="4" disabled >
        <input class="f8np1" type="text" name="g_tx_sign" value="<?php echo $g_tx_sign ?>" size="15" disabled >
        &nbsp;&nbsp;
      </div>
      <?php echo defineButtonType08("...", "action_tx", "searchTx();", "30", "left", "2"); ?>
      <div style="float:left">
        <a href="javascript:clearTx();" tabindex="310"><img src="../images/waste.png" border="0" height="15" width="12"></a>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input class="f8np1" type="text" name="g_br_key" value="<?php echo $g_br_key ?>" size="4" disabled >
        <input class="f8np1" type="text" name="g_br_name" value="<?php echo $g_br_name ?>" size="15" disabled >
        &nbsp;&nbsp;
      </div>
      <?php echo defineButtonType08("...", "action_br", "searchBr();", "30", "left", "2"); ?>
      <div style="float:left">
        <a href="javascript:clearBr();" tabindex="330"><img src="../images/waste.png" border="0" height="15" width="12"></a>
      </div>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Vertrieb") ?>:</div>
    <div>
      <div style="float:left">
        <input class="f8np1" type="text" name="g_sales_usr_name" value="<?php echo $g_sales_usr_name ?>" size="50" disabled >
        <input class="f8np1" type="text" name="g_sales_usr_firstname" value="<?php echo $g_sales_usr_firstname ?>" size="50" disabled >
        &nbsp;&nbsp;
      </div>
      <?php if (authCheckEmployeeRights($emp_id, "24")) : ?>
         <?php echo defineButtonType08("...", "action_emp_sales", "searchEmpSales();", "30", "left", "2"); ?>
         <div style="float:left">
           <a href="javascript:clearEmpSales();" tabindex="335"><img src="../images/waste.png" border="0" height="15" width="12"></a>
         </div>
      <?php endif; ?>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Ranking") ?>:</div>
    <div>
      <div style="float:left">
      	<?php echo getLngt("Subjektive Einstufung") ?>:
      	&nbsp;&nbsp;
        <select class="f8np1" name="f_cmp_sales_ranking_man" tabindex="337">
          <option value="" <?php if ($f_cmp_sales_ranking_man == "" || $f_cmp_sales_ranking_man == "0") : echo "selected"; endif; ?>></option>
          <option value="1" <?php if ($f_cmp_sales_ranking_man == "1") : echo "selected"; endif; ?>>A</option>
          <option value="2" <?php if ($f_cmp_sales_ranking_man == "2") : echo "selected"; endif; ?>>B</option>
          <option value="3" <?php if ($f_cmp_sales_ranking_man == "3") : echo "selected"; endif; ?>>C</option>
        </select>
        &nbsp;&nbsp;&nbsp;&nbsp;
      </div>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>    

  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Rechnung") ?>:</div>
    <div>
      <div style="float:left">
        <input class="f8np1" type="text" name="g_cscad_comp" value="<?php echo $g_cscad_comp ?>" size="20" disabled >
        &nbsp;&nbsp;
      </div>
      <?php echo defineButtonType08("...", "action_cscsc", "searchCsCsc('110100000000','','');", "30", "left", "2"); ?>
      <div style="float:left">
        <a href="javascript:clearPayer();" tabindex="340"><img src="../images/waste.png" border="0" height="15" width="12"></a> <?php echo getLngt("(Drittzahler)") ?>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <?php if (false) : ?>
        <?php echo getLngt("Rechnung an Zentrale") ?>&nbsp;<input class="f8np1" type="checkbox" name="f_cmp_inv2hq[]" value="1" <?php echo $f_cmp_inv2hq_0 ?> tabindex="350">
        &nbsp;&nbsp;
        <?php endif; ?>
        <?php echo getLngt("Einzelrechnung") ?>&nbsp;<input class="f8np1" type="checkbox" name="f_cmp_inv2hq[]" value="2" <?php echo $f_cmp_inv2hq_1 ?> tabindex="360">
        &nbsp;&nbsp;&nbsp;&nbsp;
        <?php echo getLngt("Komm.-Nr.:") ?>&nbsp;
        <input class="f8np1" type="radio" name="f_cs_commission_no" value="0" <?php echo $f_cs_commission_no_0 ?> tabindex="370"> <?php echo getLngt("Nein") ?>
        <input class="f8np1" type="radio" name="f_cs_commission_no" value="1" <?php echo $f_cs_commission_no_1 ?> tabindex="380"> <?php echo getLngt("Ja") ?>
        &nbsp;&nbsp;&nbsp;&nbsp;
      </div>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
      <?php echo getLngt("Eigene Lieferantennummer beim Kunden") . ": " ?>&nbsp;&nbsp;        
      <input class="f8np1" type="text" name="f_cmp_hqlino" value="<?php echo $f_cmp_hqlino ?>" maxlength="12" size="12"  tabindex="385">
      &nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Zahlungsbedingung") . ": " ?>&nbsp;&nbsp;
      <select class="f8np1" name="f_cs_payment_term"><?php echo addOptionsFromTable("metatype","mt_sort","mt_mapped_value","mt_sort","mt_type = 'payment_term'",$f_cs_payment_term) ?>"</select>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
<?php if (false) : ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
      <?php echo getLngt("Eigene GLN-Nummer beim Kunden") . ": " ?>&nbsp;&nbsp;        
      <input class="f8np1" type="text" name="f_cmp_gln" value="<?php echo $f_cmp_gln ?>" maxlength="13" size="13"  tabindex="386">
      &nbsp;&nbsp;&nbsp;&nbsp;
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
<?php else : ?>
  <input type="hidden" name="f_cmp_gln" value="">
<?php endif; ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>        
        <?php echo getLngt("Bei Auftragserstellung automatisch auf unfertig setzen:") ?> <input class="f8np1" type="checkbox" name="f_cs_jb_incomplete[]" value="1" <?php echo $f_cs_jb_incomplete_0 ?> tabindex="387">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Vermittlung") ?>:</div>
    <div>
      <?php echo getLngt("Listenkunde:") ?> <input class="f8np1" type="checkbox" name="f_cs_jobbatch[]" value="1" <?php echo $f_cs_jobbatch_0 ?> tabindex="390">
      &nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Nur Anforderungen:") ?>&nbsp;
      <input class="f8np1" type="checkbox" name="f_cs_cr_fav_only[]" value="1" <?php echo $f_cs_cr_fav_only_0 ?> tabindex="400">
      &nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Rechnungskurztext:") ?> <input class="f8np1" type="checkbox" name="f_cs_invtext_mode[]" value="1" <?php echo $f_cs_invtext_mode_0 ?> tabindex="402">
      &nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Keine bundesweite Vermittlung:") ?> <input class="f8np1" type="checkbox" name="f_cmp_no_longhaul[]" value="1" <?php echo $f_cmp_no_longhaul_0 ?> tabindex="402">
      &nbsp;&nbsp;&nbsp;&nbsp;
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Bemerkung") ?>:</div>
    <div>
      <textarea class="f8np1" name="f_cmp_remark" cols="90" rows="1" tabindex="410"><?php echo $f_cmp_remark ?></textarea>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Freitext") ?>:</div>
    <div>
      <textarea class="f8np1" name="f_cmp_match" cols="90" rows="1" tabindex="420"><?php echo $f_cmp_match ?></textarea>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Intern") ?>:</div>
    <div>
      <textarea class="f8np1" name="f_cmp_remark2" cols="90" rows="1" tabindex="430"><?php echo $f_cmp_remark2 ?></textarea>
    </div>
  </div>
  
  <?php echo htmlDivLineSpacer("15px"); ?>
  
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Preise") ?>, <?php echo getLngt("Rabatte") ?>:</div>
    <div>
      <?php echo $serviceLink1 ?>&nbsp;&nbsp;
      <?php echo $serviceLink2 ?>&nbsp;&nbsp;
      <?php echo $serviceLink3 ?>&nbsp;&nbsp;
      <?php echo $serviceLink4 ?>&nbsp;&nbsp;
    </div>
  </div>
  
  <?php echo htmlDivLineSpacer("10px"); ?>
  
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Abrechnung") ?>:</div>
    <div>
      <input class="f8np1" type="radio" name="f_cs_invmode" value="0" <?php echo $f_cs_invmode_0 ?> tabindex=""> PZM
      <input class="f8np1" type="radio" name="f_cs_invmode" value="1" <?php echo $f_cs_invmode_1 ?> tabindex=""> PLZ
      <input class="f8np1" type="radio" name="f_cs_invmode" value="2" <?php echo $f_cs_invmode_2 ?> tabindex=""> Bereich (= zusammengefasste PLZn)
      <input class="f8np1" type="radio" name="f_cs_invmode" value="3" <?php echo $f_cs_invmode_3 ?> disabled tabindex=""> Radius
      <?php if (false) : ?> <input class="f8np1" type="radio" name="f_cs_invmode" value="9" <?php echo $f_cs_invmode_9 ?> tabindex=""> Keine Preisberechnung <?php endif; ?>
    </div>
  </div>

  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Einstellungen") ?>:</div>
    <div>
      <div><?php echo getLngt("Stationsnummernanzeige in der Auftragsdetailansicht:") ?> <input class="f8np1" type="checkbox" name="f_cs_par_tr_sort[]" value="1" <?php echo $f_cs_par_tr_sort_0 ?> tabindex=""></div>
    </div>
  </div>
<?php if (false) : ?>
  <div>
    <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>>&nbsp;</div>
    <div>
      <div><?php echo getLngt("XXXXXXXXXXXXX:") ?> <input class="f8np1" type="checkbox" name="f_cs_par_xxxxxxxx[]" value="1" <?php echo $f_cs_par_xxxxxxxx_0 ?> tabindex=""></div>
    </div>
  </div>
<?php endif; ?>

  <?php echo htmlDivLineSpacer("15px"); ?>

  <?php if ($outAdditionalCompanyNames != "") : ?>
    <div>
      <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Abweichender<br>Firmenname<br>Hauptkostenst.") ?><br>&nbsp;<br>&nbsp;</div>
      <div>
        <?php echo $outAdditionalCompanyNames ?>
      </div>
    </div>
    <?php echo htmlDivLineSpacer("15px"); ?>
  <?php endif; ?>
  
  
  <?php if ($outAdditionalAddresses != "") : ?>
    <div>
      <div <?php echo setStyleHtmlDiv($leftColWidth,"left"); ?>><?php echo getLngt("Abweichende<br>Rechnungsadr.<br>Hauptkostenst.") ?><br>&nbsp;<br>&nbsp;</div>
      <div>
        <?php echo $outAdditionalAddresses ?>
      </div>
    </div>
  <?php endif; ?>

</form>
</div>
</body>

</html>
