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

include_once ("../include/mcglobal.inc.php");
include_once ("../include/auth.inc.php");


// Get the rights of the employee logged in and check the accessibility (same as for courier-administration)
authCheckEmployeeRights($emp_id, "1", "1");

// Check for right to access amount fields
$crvhRgtRule01 = false;
if (authCheckEmployeeRights($emp_id, "40")) : $crvhRgtRule01 = true; endif;
$crvhRgtRule02 = false;
if (authCheckEmployeeRights($emp_id, "41")) : $crvhRgtRule02 = true; endif;


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

$httpVisualVars = array("f_crvh_id", "f_vht_id", "f_crvh_sort", "f_crvh_sid", "f_crvh_vh_sign", "f_crvh_vh_name", 
                        "f_crvh_licence_date_month", "f_crvh_licence_date_year", "f_crvh_comm_no",
                        "f_crvh_owner_month", "f_crvh_owner_year", "f_crvh_prov", "f_crvh_payload", "f_crvh_totalweight", 
                        "f_crvh_length", "f_crvh_width", "f_crvh_height", "f_crvh_position", "f_crvh_id_inv",
                        "f_crvh_aperture_height_side", "f_crvh_aperture_height_rear", "f_crvh_corporate_identity", "f_crvh_corporate_identity_2",
                        "f_crvh_mobile", "f_crvh_insurance_name", "f_crvh_special", "f_crvh_env_badge_level",
                        "f_crvh_insurance_no", "f_crvh_filter", "f_crvh_remark", "f_crvh_freetext_1", "f_crvh_service", 
                        "f_crvh_funding_state", "f_crvh_funding_final_installment_month", "f_crvh_funding_final_installment_year",
                        "f_crvh_funding_residual_value", "f_crvh_vhd_disabled", "f_crvh_pda_usage", "f_crvh_system_fee", "f_crvh_drivetype",
                        "f_cr_id_same_contractor", "f_crvh_cr_eid_new", "f_crvh_sid_new", "f_crvh_comm_no_new", "deactivateMenu");

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

if ($crvhRgtRule02) :
   $httpVisualVarsRgtRule02 = array("f_crvh_partner_premium", "f_crvh_partner_text", "f_crvh_partner_commission");

   $httpVarsArray = array_merge($httpVarsArray, $httpVisualVarsRgtRule02);
endif;

if ($crvhRgtRule01) :
   $httpVisualVarsRgtRule01 = array("f_crvh_advertising_allowance", "f_crvh_transport_insurance_amount", 
                                    "f_crvh_transport_insurance_date_day", "f_crvh_transport_insurance_date_month", "f_crvh_transport_insurance_date_year",
                                    "f_crvh_business_liability_insurance_amount", "f_crvh_system_fee_amount", 
                                    "f_crvh_business_liability_insurance_date_day", "f_crvh_business_liability_insurance_date_month", "f_crvh_business_liability_insurance_date_year");

   $httpVarsArray = array_merge($httpVarsArray, $httpVisualVarsRgtRule01);
endif;


getSecHttpVars("1", $httpVarsArray);

getLanguage(__FILE__);

$deactivateMenuStatic = "1";
$pageTitel = getLngt("FAHRZEUGE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
include_once ("../include/inc_file.inc.php");
include_once ("../include/inc_filters.inc.php");   // Attention: Courier filters were also translated into another language. The next command "getCurrentScript(...)" is a must!
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_wording_wrapper.inc.php");
getCurrentScript(__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, "1", "1");


// IMPORTANT SYSTEM PARAMETERS 
// Rules the generation of a "fake vehicle-courier"
$globalVehicleCourierRelation = getParameterValue("0", "GLOBAL_VEHICLE_COURIER_RELATION", "0");

// Declares all vehicles being a stock by itself and are associated to a special (root) stock
$globalVehicleStockRelation = getParameterValue("0", "GLOBAL_VEHICLE_STOCK_RELATION", "0");
if ($globalVehicleStockRelation == "1") :
   // INCLUDE stock lib
   include ("../include/inc_stock.inc.php");

   // There could be defined a special stock being parent stock for all vehicle stocks.
   // Otherwise every vehicle will be associated to a special root stock (!!!!)
   $vehicleStockIdParent = getParameterValue("0", "VEHICLE_STOCK_PARENT_ID", $hq_id);
   if ($vehicleStockIdParent == "" || !is_numeric($vehicleStockIdParent)) :
      $vehicleStockIdParent = getParameterValue("0", "VEHICLE_STOCK_PARENT_ID", "0");
      if ($vehicleStockIdParent == "" || !is_numeric($vehicleStockIdParent)) :
         $vehicleStockIdParent = "0";
      endif;
   endif;
endif;


// Initializations
$outputFilter = "";
$outputService = "";
$title = $pageTitel;
$importPath = "";
if ($f_crvh_sort == "") : $f_crvh_sort = "0"; endif;
if ($f_vht_id == "0") : $f_vht_id = ""; endif;
if ($f_crvh_drivetype == "0") : $f_crvh_drivetype = ""; endif;
if ($f_crvh_id_inv == "") : $f_crvh_id_inv = "0"; endif;
if ($f_crvh_env_badge_level == "") : $f_crvh_env_badge_level = "0"; endif;
if ($f_crvh_prov == "") : $f_crvh_prov = "0"; endif;
if ($f_crvh_payload == "") : $f_crvh_payload = "0"; endif;
if ($f_crvh_totalweight == "") : $f_crvh_totalweight = "0"; endif;
if ($f_crvh_length == "") : $f_crvh_length = "0"; endif;
if ($f_crvh_width == "") : $f_crvh_width = "0"; endif;
if ($f_crvh_height == "") : $f_crvh_height = "0"; endif;
if ($f_crvh_position == "") : $f_crvh_position = "0"; endif;
if ($f_crvh_aperture_height_side == "") : $f_crvh_aperture_height_side = "0"; endif;
if ($f_crvh_aperture_height_rear == "") : $f_crvh_aperture_height_rear = "0"; endif;
if ($f_crvh_advertising_allowance == "") : $f_crvh_advertising_allowance = "0.00"; endif;
if ($f_crvh_transport_insurance_amount == "") : $f_crvh_transport_insurance_amount = "0.00"; endif;
if ($f_crvh_business_liability_insurance_amount == "") : $f_crvh_business_liability_insurance_amount = "0.00"; endif;
if ($f_crvh_system_fee_amount == "") : $f_crvh_system_fee_amount = "0.00"; endif;
if ($f_crvh_funding_residual_value == "") : $f_crvh_funding_residual_value = "0"; endif;
mcIsSet($f_crvh_partner_premium, "0.00");
mcIsSet($f_crvh_partner_text);
mcIsSet($f_crvh_partner_commission, "0.00");
mcIsSet($phpCurrentNavigationInputHidden);
mcIsSet($csId);
mcIsSet($f_hq_id);
mcTrim($f_crvh_sid);

$f_crvh_licence_date = "0000-00-00";
if ($f_crvh_licence_date_year != "" && $f_crvh_licence_date_month != "") :
   $f_crvh_licence_date = $f_crvh_licence_date_year . "-" . $f_crvh_licence_date_month . "-" . "01";   // The day is not important, default "01"
endif;

$f_crvh_funding_final_installment = "0000-00-00";
if ($f_crvh_funding_final_installment_year != "" && $f_crvh_funding_final_installment_month != "") :
   $f_crvh_funding_final_installment = $f_crvh_funding_final_installment_year . "-" . $f_crvh_funding_final_installment_month . "-" . "01";   // The day is not important, default "01"
endif;

$f_crvh_owner = "0000-00-00";
if ($f_crvh_owner_year != "" && $f_crvh_owner_month != "") :
   $f_crvh_owner = $f_crvh_owner_year . "-" . $f_crvh_owner_month . "-" . "01";   // The day is not important, default "01"
endif;

// Fields for vehicle copy
mcTrim($f_crvh_cr_eid_new);
mcTrim($f_crvh_sid_new);
mcTrim($f_crvh_comm_no_new);

// Only for output
$htmlClass01 = "class=\"smaller\"";                // input,select
$html_td_01  = "valign=\"top\" align=\"left\"";    // input
$html_td_02  = "valign=\"top\" align=\"right\"";   // input

// Init
$outputFilter = "";
$outputService = "";
$title = $pageTitel;


// Implode checked couriervehicle filter fields to store in DB
$f_crvh_filter2 = getImplodedFilterstring($f_crvh_filter);

// Implode checked couriervehicle services fields to store in DB
//$f_crvh_service2 = getImplodedFilterstring($f_crvh_service);
$f_crvh_service2 = mcConvertSel2Num($f_crvh_service);

// Get installation services to set "static" installation service
$parInstallationServices = getObjectBasedParameterValue("DISPOSITION_INSTALLATIONSERVICES", $csId, $f_hq_id);
$parInstallationServiceArray = spliti(",", $parInstallationServices);
// $parInstallationServiceArrayLen = count($parInstallationServiceArray);
$parInstallationServiceDec = mcConvertSel2Num($parInstallationServiceArray);
// Check selected service of the vehicle has installation state
if (((int)$parInstallationServiceDec & (int)$f_crvh_service2) == 0) :
   // Is NO installation vehicle
   (int)$f_crvh_service2 = ((int)$f_crvh_service2 & ~2);
else :
   // is installation vehicle
   (int)$f_crvh_service2 = ((int)$f_crvh_service2 | 2);
endif;

// Mandatory fields
$parMaskMandatoryFieldTotalweight = getParameterValue("0", "MASK_CRVH_TOTALWEIGHT_MANDATORY", $hq_id);
if ($parMaskMandatoryFieldTotalweight == "") :
   $parMaskMandatoryFieldTotalweight = getParameterValue("0", "MASK_CRVH_TOTALWEIGHT_MANDATORY", "0");
endif;
if ($parMaskMandatoryFieldTotalweight != "1") :
   $parMaskMandatoryFieldTotalweight = "0";
endif;


// Special flag
if (authCheckEmployeeRights($emp_id, "13")) :
   if ($f_crvh_special == "" || count($f_crvh_special) == 0) :
      $f_crvh_special = "0";
   else: 
      $f_crvh_special = "1";
   endif;
else :
   $f_crvh_special = "0";
   if ($f_crvh_id != "") :
      $f_crvh_special = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_special");
   endif;
endif;

// Corporate identity
if ($f_crvh_corporate_identity == "") : $f_crvh_corporate_identity = "0"; endif;
if ($f_crvh_corporate_identity_2 == "") : $f_crvh_corporate_identity_2 = "0"; endif;
// Right 4 bits for f_crvh_corporate_identity and left 4 bits for f_crvh_corporate_identity_2
$f_crvh_corporate_identity = ((int)$f_crvh_corporate_identity | ((int)$f_crvh_corporate_identity_2 * 16));

// NO graphical vehicle disposition
if ($f_crvh_vhd_disabled == "" || count($f_crvh_vhd_disabled) == 0) :
   $f_crvh_vhd_disabled = "0";
else: 
   $f_crvh_vhd_disabled = "1";
endif;

// Funding of the vehicle
if ($f_crvh_funding_state == "" || count($f_crvh_funding_state) == 0) :
   $f_crvh_funding_state = "0";
else: 
   $f_crvh_funding_state = "1";
endif;

// Check for right to administrate CUSTOMERS
if (authCheckEmployeeRights($emp_id, "10")) :
   // Device usage
   if ($f_crvh_pda_usage == "" || count($f_crvh_pda_usage) == 0) :
      $f_crvh_pda_usage = "0";
   else: 
      $f_crvh_pda_usage = "1";
   endif;
   // System fee
   if ($f_crvh_system_fee == "" || count($f_crvh_system_fee) == 0) :
      $f_crvh_system_fee = "0";
   else: 
      $f_crvh_system_fee = "1";
   endif;
else :
   // Device usage
   $f_crvh_pda_usage = "0";
   if ($f_crvh_id != "") :
      $f_crvh_pda_usage = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_pda_usage");
   endif;
   // System fee
   $f_crvh_system_fee = "0";
   if ($f_crvh_id != "") :
      $f_crvh_system_fee = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_system_fee");
   endif;
endif;

// Insurance dates
$f_crvh_transport_insurance_date = "0000-00-00";
$f_crvh_business_liability_insurance_date = "0000-00-00";
if ($crvhRgtRule01) :
   // Transport insurance date   
   if ($f_crvh_transport_insurance_date_year != "" && $f_crvh_transport_insurance_date_month != "" && $f_crvh_transport_insurance_date_day != "") :
     $f_crvh_transport_insurance_date = $f_crvh_transport_insurance_date_year . "-" . pad($f_crvh_transport_insurance_date_month, 2, "0") . "-" . pad($f_crvh_transport_insurance_date_day, 2, "0");
   endif;
   // Business liability insurance date
   if ($f_crvh_business_liability_insurance_date_year != "" && $f_crvh_business_liability_insurance_date_month != "" && $f_crvh_business_liability_insurance_date_day != "") :
     $f_crvh_business_liability_insurance_date = $f_crvh_business_liability_insurance_date_year . "-" . pad($f_crvh_business_liability_insurance_date_month, 2, "0") . "-" . pad($f_crvh_business_liability_insurance_date_day, 2, "0");
   endif;
endif;

// If $f_crvh_id is known then the $courierId has to be set if unknown
if ($f_crvh_id != "" && is_numeric($f_crvh_id)) :
   $courierId = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"cr_id");
endif;
// Headquarters of the current courier
$crHqId = "";
if ($courierId != "" && is_numeric($courierId)) :
   $crHqId = getFieldValueFromId("courier","cr_id",$courierId,"hq_id");
endif;


// It has to be possible to change the vehicle ralation to another courier.
// But two preconditions are a MUST: 
// - Both drivers (the "old" and the "new") are drivers only (existing relation "drives for" ["fährt für"])
// - Both drivers drive for the SAME contractor ["Unternehmer"]
// Get the list of related drivers
$couriersOfTheSameContractorArr = array();
$couriersOfTheSameContractorArrLen = 0;
$outputCouriersOfTheSameContractor = "<option value=\"\">----</option>\n";  // Init



// **********************************************************
// * FUNCTIONS FOR ASSOCIATED FAKE COURIERS TO THE VEHICLES *
// **********************************************************

function insertAssociatedVehicleCourier ($crId, $crSid) {
	global $db, $PHP_SELF, $hq_id;
  $retVal = "";
  if ($crId != "" && $crSid != "") :
     $xCmpId = getFieldValueFromId("courier", "cr_id", $crId, "cmp_id");
     $xAdId = getFieldValueFromId("company", "cmp_id", $xCmpId, "ad_id");
     $xCmpHsno = getFieldValueFromId("company", "cmp_id", $xCmpId, "cmp_hsno");
     $xCrEid = "INT_" . $crSid;
     $xCmpComp = "Fahrzeug " . $crSid;
     $xUsrAccount = "int_" . $crSid;
     $xUsrPassword = "jdzu2ebf5dh8";
     $xUsrName = "INT_" . $crSid;
     $xUsrFirstname = $crSid;
     $currentTime = getDateTime("0");
     // Insert user
     $sqlStmtPwd = "INSERT INTO user (hq_id,usr_type,usr_name,usr_firstname,usr_account,usr_password,usr_password_modify) VALUES ($hq_id,'3','$xUsrName','$xUsrFirstname','$xUsrAccount',PASSWORD('$xUsrPassword'),'$currentTime')";
     $res = $db->query($sqlStmtPwd);
     if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif;                                     
     $xUsrIdNew = getLastInsertID();
     // Insert company
     insertStmt("company", array("cmp_comp", $xCmpComp, "cmp_comp2", "", "ad_id", $xAdId, "cmp_hsno", $xCmpHsno, "cmp_tax_idno", "0", "cmp_stax_idno", "0", 
                "cmp_authenticated", "1", "cmp_visible", "0", "cmp_visible_internal", "1", "cmp_newsletter", "0", "cmp_new_date", $currentTime, "cmp_modify_status", "0"));
     $xCmpIdNew = getLastInsertId();
     // Insert courier
     $vhtIdInv = getVhtId("7", "truck_01");
     insertStmt("courier", array("cmp_id", $xCmpIdNew, "hq_id", $hq_id, "usr_id", $xUsrIdNew, "cr_sid", $crSid, "cr_eid", $xCrEid, "vht_id_inv", $vhtIdInv, 
                                 "cr_available", "1", "cr_id_parent", $crId, "cr_imei", "", "cr_mobile_pda", "0"));
     $xCrIdNew = getLastInsertId();
     $retVal = $xCrIdNew;
  endif;
  return $retVal;
}

function updateAssociatedVehicleCourier ($crSid, $crSidOld) {
	global $hq_id;
  $retVal = "";
  if ($crSid != "" && $crSidOld != "") :
     $xCrId = getFieldValueFromId("courier", "cr_sid", $crSidOld, "cr_id");  // Get associated fake courier
     $xCmpId = getFieldValueFromId("courier", "cr_id", $xCrId, "cmp_id");
     $xUsrId = getFieldValueFromId("courier", "cr_id", $xCrId, "usr_id");
     $xCrEid = "INT_" . $crSid;
     $xCmpComp = "Fahrzeug " . $crSid;
     $xUsrAccount = "int_" . $crSid;
     $xUsrName = "INT_" . $crSid;
     $xUsrFirstname = $crSid;
     // Update user, company, courier
     updateStmt("user","usr_id",$xUsrId,array("usr_name",$xUsrName,"usr_firstname",$xUsrFirstname,"usr_account",$xUsrAccount));
     updateStmt("company","cmp_id",$xCmpId,array("cmp_comp",$xCmpComp));
     updateStmt("courier","cr_id",$xCrId,array("cr_eid",$xCrEid,"cr_sid",$crSid));
     $retVal = $xCrId;
  endif;
  return $retVal;
}

function removeAssociatedVehicleCourier ($crSid) {
	global $hq_id;
  $retVal = "";
  if ($crSid != "") :
     $xCrId = getFieldValueFromId("courier", "cr_sid", $crSid, "cr_id");  // Get associated fake courier
     $xCmpId = getFieldValueFromId("courier", "cr_id", $xCrId, "cmp_id");
     $xUsrId = getFieldValueFromId("courier", "cr_id", $xCrId, "usr_id");
     // Check existence of reference(s) in job
     $numOfJobs = getCountOfTable("job", "cr_id = '" . $xCrId . "'");
     if ($numOfJobs <= 0) :
        deleteStmt("courierdatatransfer","cr_id = ".$xCrId);
        deleteStmt("customercourier","cr_id = ".$xCrId);
        deleteStmt("user","usr_id = ".$xUsrId . " AND hq_id = '" . $hq_id . "'");
        deleteStmt("company","cmp_id = ".$companyId);
        updateStmt("courier","cr_id_parent",$xCrId,array("cr_id_parent",""));
        deleteStmt("courier","cr_id = ".$xCrId . " AND hq_id = '" . $hq_id . "'");
     endif;
  endif;
  return $retVal;
}

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



   // **************************************
   // * Operations for the couriervehicles *   
   // **************************************

   // Generate log string
   if ($f_act != "") :
   
      // In case of modifying without special right(s) init some fields with existing value(s)
      if ($f_act == "modifyCourierVehicle" && $courierId != "" && $crHqId != "" && $f_crvh_id != "") :
         if (!$crvhRgtRule02) :
            $f_crvh_partner_premium = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_partner_premium");
            $f_crvh_partner_text = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_partner_text");
            $f_crvh_partner_commission = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_partner_commission");
         endif;
         if (!$crvhRgtRule01) :
            $f_crvh_advertising_allowance = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_advertising_allowance");
            $f_crvh_transport_insurance_amount = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_transport_insurance_amount");
            $f_crvh_business_liability_insurance_amount = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_business_liability_insurance_amount");
            $f_crvh_business_liability_insurance_date = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_business_liability_insurance_date");
            $f_crvh_system_fee_amount = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_system_fee_amount");
            $f_crvh_transport_insurance_date = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_transport_insurance_date");
         endif;
      endif;

      $logArr = array($f_vht_id,$f_crvh_comm_no,$f_crvh_vh_sign,$f_crvh_vh_name,$f_crvh_licence_date,$f_crvh_owner,
                      $f_crvh_env_badge_level,$f_crvh_prov,$f_crvh_payload,$f_crvh_totalweight,
                      $f_crvh_length,$f_crvh_width,$f_crvh_height,$f_crvh_position,$f_crvh_mobile,
                      $f_crvh_insurance_name,$f_crvh_insurance_no,$f_crvh_special,$f_crvh_remark,$f_crvh_freetext_1,
                      $f_crvh_corporate_identity,$f_crvh_funding_state,$f_crvh_funding_final_installment,
                      $f_crvh_funding_residual_value,$f_crvh_aperture_height_side,$f_crvh_aperture_height_rear,
                      $f_crvh_vhd_disabled,$f_crvh_id_inv,$f_crvh_pda_usage,$f_crvh_system_fee,$f_crvh_drivetype,
                      $f_crvh_cr_eid_new,$f_crvh_sid_new,$f_crvh_comm_no_new,
                      $f_crvh_partner_premium,$f_crvh_partner_commission,$f_crvh_advertising_allowance,$f_crvh_transport_insurance_amount, 
                      $f_crvh_business_liability_insurance_amount,$f_crvh_business_liability_insurance_date,$f_crvh_system_fee_amount,
                      $f_crvh_partner_text,$f_crvh_transport_insurance_date);

      $logString = makeLogString($logArr, ";", "0");
   endif;

   // Copy couriervehicle
   if ($f_act == "copyCourierVehicle") :
       if ($f_crvh_cr_eid_new != "" && $f_crvh_sid_new != "" && $f_crvh_comm_no_new != "") :
          // Get courier ID of the existing courier to be associated
          $courierId = getFieldValueFromId("courier","cr_eid",$f_crvh_cr_eid_new,"cr_id");
          if ($courierId != "" && is_numeric($courierId) && $courierId > "0") :
             $f_crvh_sid = $f_crvh_sid_new;
             $f_crvh_comm_no = $f_crvh_comm_no_new;
             $crHqId = getFieldValueFromId("courier","cr_id",$courierId,"hq_id");
             $f_act = "newCourierVehicle";
             // $statusMessage = getLngt("Nach erfolgreicher Fahrzeuganlage wird das neue Fahrzeugstanmmblatt angezeigt!");
          else :
             $statusMessage = getLngt("Der Transporteursdatensatz für die Zuweisung des kopierten Fahrzeugs existiert nicht!");
          endif;
       else :
          $statusMessage = getLngt("Die erfassten Daten für die Datensatzkopie des Fahrzeug sind nicht vollständig!");
       endif;
   endif;

   // Insert new couriervehicle
   if ($f_act == "newCourierVehicle" && $courierId != "" && $crHqId != "") :

      if ($f_crvh_sid != "" && $f_vht_id != "" && $f_crvh_vh_sign != "" && 
          $f_crvh_comm_no != "" && $f_crvh_licence_date_month != "" && $f_crvh_licence_date_year != "" &&
          ($parMaskMandatoryFieldTotalweight == "0" || ($f_crvh_totalweight != "" && is_numeric($f_crvh_totalweight) && $f_crvh_totalweight > 0))) :
                                                         
         // if ($db->getOne("SELECT crvh_sid FROM couriervehicle WHERE crvh_sid = '" . $f_crvh_sid . "'")) :
         //        $statusMessage = "Die systemweit eindeutige Kuriernummer ist bereits vergeben! Bitte wählen Sie eine andere";
         
         // Check for existence of the unique SID
         $sqlquery = "SELECT crvh.crvh_sid FROM couriervehicle AS crvh, courier AS cr"
                                       . " WHERE crvh.crvh_sid = '" . $f_crvh_sid . "' AND"
                                       . "       cr.cr_id = crvh.cr_id AND"
                                       . "       cr.hq_id = '" . $crHqId . "'";
         if ($db->getOne($sqlquery)) :

            $statusMessage = getLngt("Die eindeutige Fahrzeugnummer (SID) ist bereits vergeben! Bitte wählen Sie eine andere");
         else :
         
            // Check for existence of the unique commission number
            $sqlquery = "SELECT crvh.crvh_comm_no FROM couriervehicle AS crvh, courier AS cr"
                                          . " WHERE crvh.crvh_comm_no = '" . $f_crvh_comm_no . "' AND"
                                          . "       cr.cr_id = crvh.cr_id AND"
                                          . "       cr.hq_id = '" . $crHqId . "'";
            if ($db->getOne($sqlquery)) :

               $statusMessage = getLngt("Die eindeutige Kommissionsnummer ist bereits vergeben! Bitte wählen Sie eine andere");
            else :

               TA("B");
              
               $currentTime = getDateTime("0");
   
               // Insert couriervehicle
               $f_crvh_prov = str_replace (",", ".", $f_crvh_prov);
               $f_crvh_funding_residual_value = str_replace (",", ".", $f_crvh_funding_residual_value);
               insertStmt("couriervehicle", array("vht_id",$f_vht_id, "cr_id", $courierId, "crvh_id_inv", $f_crvh_id_inv, "crvh_sort", $f_crvh_sort,
                                                  "crvh_sid", $f_crvh_sid, "crvh_comm_no", $f_crvh_comm_no,
                                                  "crvh_vh_sign", $f_crvh_vh_sign, "crvh_vh_name", $f_crvh_vh_name,
                                                  "crvh_licence_date", $f_crvh_licence_date, "crvh_owner", $f_crvh_owner, 
                                                  "crvh_env_badge_level", $f_crvh_env_badge_level, "crvh_prov", $f_crvh_prov, "crvh_payload", $f_crvh_payload, 
                                                  "crvh_totalweight", $f_crvh_totalweight, "crvh_length", $f_crvh_length, 
                                                  "crvh_width", $f_crvh_width, "crvh_height", $f_crvh_height, 
                                                  "crvh_position", $f_crvh_position, "crvh_aperture_height_side", $f_crvh_aperture_height_side, 
                                                  "crvh_aperture_height_rear", $f_crvh_aperture_height_rear, "crvh_mobile", $f_crvh_mobile, 
                                                  "crvh_insurance_name", $f_crvh_insurance_name, "crvh_insurance_no", $f_crvh_insurance_no, 
                                                  "crvh_filter ", $f_crvh_filter2, "crvh_service", $f_crvh_service2, "crvh_group", "", "crvh_special", $f_crvh_special, 
                                                  "crvh_vhd_disabled", $f_crvh_vhd_disabled, "crvh_corporate_identity", $f_crvh_corporate_identity, 
                                                  "crvh_funding_state", $f_crvh_funding_state, "crvh_funding_final_installment", $f_crvh_funding_final_installment, 
                                                  "crvh_funding_residual_value", $f_crvh_funding_residual_value,
                                                  "crvh_pda_usage", $f_crvh_pda_usage, "crvh_system_fee", $f_crvh_system_fee, "crvh_drivetype", $f_crvh_drivetype,
                                                  "crvh_remark ", $f_crvh_remark, "crvh_freetext_1", $f_crvh_freetext_1, 
                                                  "crvh_partner_premium", "0", "crvh_partner_text", "",
                                                  "crvh_partner_commission", "0", "crvh_advertising_allowance", "0", "crvh_system_fee_amount", "0",
                                                  "crvh_transport_insurance_amount", "0", "crvh_transport_insurance_date", "0000-00-00", 
                                                  "crvh_business_liability_insurance_amount", "0", "crvh_business_liability_insurance_date", "0000-00-00", 
                                                  "crvh_modify_status", "1", "crvh_modify", $currentTime));

               $f_crvh_id = getLastInsertID();

               if ($crvhRgtRule01) :
                  $f_crvh_advertising_allowance = str_replace(",", ".", $f_crvh_advertising_allowance);
                  $f_crvh_transport_insurance_amount = str_replace(",", ".", $f_crvh_transport_insurance_amount);
                  $f_crvh_business_liability_insurance_amount = str_replace(",", ".", $f_crvh_business_liability_insurance_amount);
                  $f_crvh_system_fee_amount = str_replace(",", ".", $f_crvh_system_fee_amount);

                  // Insert new values per update
                  $crvhRgtRule01Fields = array("crvh_advertising_allowance", $f_crvh_advertising_allowance, "crvh_system_fee_amount", $f_crvh_system_fee_amount,
                                               "crvh_transport_insurance_amount", $f_crvh_transport_insurance_amount, "crvh_transport_insurance_date", $f_crvh_transport_insurance_date, 
                                               "crvh_business_liability_insurance_amount", $f_crvh_business_liability_insurance_amount, "crvh_business_liability_insurance_date", $f_crvh_business_liability_insurance_date);

                  updateStmt("couriervehicle","crvh_id",$f_crvh_id,$crvhRgtRule01Fields);
               endif;

               if ($crvhRgtRule02) :
                  $f_crvh_partner_premium = str_replace(",", ".", $f_crvh_partner_premium);
                  $f_crvh_partner_text = trim($f_crvh_partner_text);
                  $f_crvh_partner_commission = str_replace(",", ".", $f_crvh_partner_commission);

                  $crvhRgtRule02Fields = array("crvh_partner_premium", $f_crvh_partner_premium, "crvh_partner_text", $f_crvh_partner_text, "crvh_partner_commission", $f_crvh_partner_commission);

                  updateStmt("couriervehicle","crvh_id",$f_crvh_id,$crvhRgtRule02Fields);
               endif;

               // Write logdata into log database
               writeToLogDB("85",$hq_id,"",$usr_id,$courierId,$f_crvh_sid,"","OBJ_TYPE=CRVH|STATUS_NEW=" . $logString . "|FILTER=" . $f_crvh_filter2 . "|SERVICES=" . $f_crvh_service2);

               // Write into "servicepricehistory"
               insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_partner_commission", 
                          "srvprch_context", "", "srvprch_price", $f_crvh_partner_commission, "srvprch_validfrom", $currentTime));
               insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_advertising_allowance", 
                          "srvprch_context", "", "srvprch_price", $f_crvh_advertising_allowance, "srvprch_validfrom", $currentTime));
               insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_transport_insurance_amount", 
                          "srvprch_context", "", "srvprch_price", $f_crvh_transport_insurance_amount, "srvprch_validfrom", $currentTime));
               insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_business_liability_insurance_amount", 
                          "srvprch_context", "", "srvprch_price", $f_crvh_business_liability_insurance_amount, "srvprch_validfrom", $currentTime));
               insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_system_fee_amount", 
                          "srvprch_context", "", "srvprch_price", $f_crvh_system_fee_amount, "srvprch_validfrom", $currentTime));
               insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_partner_premium", 
                          "srvprch_context", "", "srvprch_price", $f_crvh_partner_premium, "srvprch_validfrom", $currentTime));

               // New entry in the "Fast Disposition Structure"
               generateVehicleFastDispositionStructure($f_crvh_id, "3");  // Remember: "vehicleavailabilitytimeunits" would not have any entry for this vehicle because there is no relation to any customer yet !!!!


               // * Insert "active" courier for the vehicle having "cr.cr_sid <=> crvh.crvh_sid" *
               if ($globalVehicleCourierRelation == "1") :
                  insertAssociatedVehicleCourier($courierId, $f_crvh_sid);
               endif;

               if ($globalVehicleStockRelation == "1") :
                  $opVal = objectInsertStock("crvh", $f_crvh_id, $vehicleStockIdParent, "SYSTEM-VEHICLES", getLngt("FZG") . $f_crvh_sid, $dbConnection);
                  if ($opVal == "-1") :
                     $statusMessage = getLngt("Es wurde kein spezielles Objekt bzw. dessen Typ spezifiziert!");
                  elseif ($opVal == "-2") :
                     $statusMessage = getLngt("ACHTUNG! Es existiert kein notwendiges fahrzeugbezogenes Hauptlager! Bitte den Administrator kontaktieren!");
                  elseif ($opVal == "-3") :
                     $statusMessage = getLngt("ACHTUNG! Die Anlage des Lagerortes konnte nicht durchgeführt werden! Bitte wiederholen bzw. den Administrator kontaktieren!");
                  endif;
               endif;

               TA("C");
               TA("E");
           
               // Reset fields of form-parameters
               // clearParameters($httpVisualVars);
            endif;
         endif;
      else :
         $statusMessage = getLngt("Bitte geben Sie alle mit * gekennzeichneten Felder ein!");
      endif;
   endif;            

   // Modify couriervehicle
   if ($f_act == "modifyCourierVehicle" && $courierId != "" && $crHqId != "") :

      if ($f_crvh_id != "" && $f_vht_id != "" && $f_crvh_sid != "" && $f_crvh_vh_sign != "" &&
          $f_crvh_comm_no != "" && $f_crvh_licence_date_month != "" && $f_crvh_licence_date_year != "" &&
          ($parMaskMandatoryFieldTotalweight == "0" || ($f_crvh_totalweight != "" && is_numeric($f_crvh_totalweight) && $f_crvh_totalweight > 0))) :

         // Check for existence of the unique SID (except the current row to be modified)
         $sqlquery = "SELECT crvh.crvh_sid FROM couriervehicle AS crvh, courier AS cr"
                                       . " WHERE crvh.crvh_sid = '" . $f_crvh_sid . "' AND"
                                       . "       NOT (crvh_id = '" . $f_crvh_id . "') AND "
                                       . "       cr.cr_id = crvh.cr_id AND"
                                       . "       cr.hq_id = '" . $crHqId . "'";
         if ($db->getOne($sqlquery)) :
            $statusMessage = getLngt("Die eindeutige Fahrzeugnummer (SID) ist bereits vergeben! Bitte wählen Sie eine andere");

         else :
            // Check for existence of the unique commission number
            $sqlquery = "SELECT crvh.crvh_comm_no FROM couriervehicle AS crvh, courier AS cr"
                                          . " WHERE crvh.crvh_comm_no = '" . $f_crvh_comm_no . "' AND"
                                          . "       NOT (crvh_id = '" . $f_crvh_id . "') AND "
                                          . "       cr.cr_id = crvh.cr_id AND"
                                          . "       cr.hq_id = '" . $crHqId . "'";
            if ($db->getOne($sqlquery)) :

               $statusMessage = getLngt("Die eindeutige Kommissionsnummer ist bereits vergeben! Bitte wählen Sie eine andere");
            else :         

               TA("B");

               $currentTime = getDateTime("0");

               // Get existing (old) "crvh_sid" to compare with new SID, in case of generating a fake courier only
               $crvhSidCurrent = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_sid");

               // Get current specific data (payload, positions, etc.) of the vehicle before update
               $crvhFieldsCurrent = getFieldsValueFromId("couriervehicle", "crvh_id", $f_crvh_id, array("crvh_payload","crvh_position"));

               // Get current price values
               $crvhPriceFieldsCurrent = getFieldsValueFromId("couriervehicle", "crvh_id", $f_crvh_id, array("crvh_partner_commission","crvh_advertising_allowance","crvh_transport_insurance_amount","crvh_business_liability_insurance_amount","crvh_system_fee_amount","crvh_partner_premium"));

               // Update couriervehicle
               $f_crvh_prov = str_replace (",", ".", $f_crvh_prov);
               $f_crvh_funding_residual_value = str_replace (",", ".", $f_crvh_funding_residual_value);
               $defaultFields = array("vht_id",$f_vht_id, "cr_id", $courierId, "crvh_id_inv", $f_crvh_id_inv, "crvh_sort", $f_crvh_sort, 
                                      "crvh_sid", $f_crvh_sid, "crvh_comm_no", $f_crvh_comm_no,
                                      "crvh_vh_sign", $f_crvh_vh_sign, "crvh_vh_name", $f_crvh_vh_name, 
                                      "crvh_licence_date", $f_crvh_licence_date, "crvh_owner", $f_crvh_owner, 
                                      "crvh_env_badge_level", $f_crvh_env_badge_level, 
                                      "crvh_prov", $f_crvh_prov, "crvh_payload", $f_crvh_payload, 
                                      "crvh_totalweight", $f_crvh_totalweight, "crvh_length", $f_crvh_length, 
                                      "crvh_width", $f_crvh_width, "crvh_height", $f_crvh_height, 
                                      "crvh_position", $f_crvh_position, "crvh_aperture_height_side", $f_crvh_aperture_height_side,
                                      "crvh_aperture_height_rear", $f_crvh_aperture_height_rear, "crvh_mobile", $f_crvh_mobile, 
                                      "crvh_insurance_name", $f_crvh_insurance_name, "crvh_insurance_no", $f_crvh_insurance_no, 
                                      "crvh_filter ", $f_crvh_filter2, "crvh_service", $f_crvh_service2, 
                                      "crvh_corporate_identity", $f_crvh_corporate_identity, "crvh_funding_state", $f_crvh_funding_state, 
                                      "crvh_funding_final_installment", $f_crvh_funding_final_installment, "crvh_funding_residual_value", $f_crvh_funding_residual_value,
                                      "crvh_special", $f_crvh_special, "crvh_vhd_disabled", $f_crvh_vhd_disabled, 
                                      "crvh_pda_usage", $f_crvh_pda_usage, "crvh_system_fee", $f_crvh_system_fee, "crvh_drivetype", $f_crvh_drivetype,
                                      "crvh_remark ", $f_crvh_remark, "crvh_freetext_1", $f_crvh_freetext_1,
                                      "crvh_modify_status", "2", "crvh_modify", $currentTime);

               if ($crvhRgtRule01) :
                  $f_crvh_advertising_allowance = str_replace (",", ".", $f_crvh_advertising_allowance);
                  $f_crvh_transport_insurance_amount = str_replace (",", ".", $f_crvh_transport_insurance_amount);
                  $f_crvh_business_liability_insurance_amount = str_replace (",", ".", $f_crvh_business_liability_insurance_amount);
                  $f_crvh_system_fee_amount = str_replace (",", ".", $f_crvh_system_fee_amount);

                  $crvhRgtRule01Fields = array("crvh_advertising_allowance", $f_crvh_advertising_allowance, "crvh_system_fee_amount", $f_crvh_system_fee_amount,
                                               "crvh_transport_insurance_amount", $f_crvh_transport_insurance_amount, "crvh_transport_insurance_date", $f_crvh_transport_insurance_date, 
                                               "crvh_business_liability_insurance_amount", $f_crvh_business_liability_insurance_amount, "crvh_business_liability_insurance_date", $f_crvh_business_liability_insurance_date);

                  $defaultFields = array_merge($defaultFields, $crvhRgtRule01Fields);
               endif;

               if ($crvhRgtRule02) :
                  $f_crvh_partner_premium = str_replace(",", ".", $f_crvh_partner_premium);
                  $f_crvh_partner_text = trim($f_crvh_partner_text);
                  $f_crvh_partner_commission = str_replace (",", ".", $f_crvh_partner_commission);

                  $crvhRgtRule02Fields = array("crvh_partner_premium", $f_crvh_partner_premium, "crvh_partner_text", $f_crvh_partner_text, "crvh_partner_commission", $f_crvh_partner_commission);

                  $defaultFields = array_merge($defaultFields, $crvhRgtRule02Fields);
               endif;

               updateStmt("couriervehicle","crvh_id",$f_crvh_id,$defaultFields);

               // Update vehicletype in "courier" if it has been changed in "couriervehicle"
               $tmpCrSid = getFieldValueFromId("courier","cr_id",$courierId,"cr_sid");
               $tmpCrVhtId = getFieldValueFromId("courier","cr_id",$courierId,"vht_id");
               if ($tmpCrSid != $f_crvh_sid || $tmpCrVhtId != $f_vht_id) :
                  updateStmt("courier","cr_id",$courierId,array("cr_sid",$f_crvh_sid,"vht_id",$f_vht_id));
               endif;

               // Write logdata into log database
               writeToLogDB("86",$hq_id,"",$usr_id,$courierId,$f_crvh_sid,"","OBJ_TYPE=CRVH|STATUS_MODIFIED=" . $logString . "|FILTER=" . $f_crvh_filter2 . "|SERVICES=" . $f_crvh_service2);

               // Write into "servicepricehistory"
               if ($crvhPriceFieldsCurrent[0] != $f_crvh_partner_commission) :
                   insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_partner_commission", 
                              "srvprch_context", "", "srvprch_price", $f_crvh_partner_commission, "srvprch_validfrom", $currentTime));
               endif;
               if ($crvhPriceFieldsCurrent[1] != $f_crvh_advertising_allowance) :
                   insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_advertising_allowance", 
                              "srvprch_context", "", "srvprch_price", $f_crvh_advertising_allowance, "srvprch_validfrom", $currentTime));
               endif;
               if ($crvhPriceFieldsCurrent[2] != $f_crvh_transport_insurance_amount) :
                   insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_transport_insurance_amount", 
                              "srvprch_context", "", "srvprch_price", $f_crvh_transport_insurance_amount, "srvprch_validfrom", $currentTime));
               endif;
               if ($crvhPriceFieldsCurrent[3] != $f_crvh_business_liability_insurance_amount) :
                   insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_business_liability_insurance_amount", 
                              "srvprch_context", "", "srvprch_price", $f_crvh_business_liability_insurance_amount, "srvprch_validfrom", $currentTime));
               endif;
               if ($crvhPriceFieldsCurrent[4] != $f_crvh_system_fee_amount) :
                   insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_system_fee_amount", 
                              "srvprch_context", "", "srvprch_price", $f_crvh_system_fee_amount, "srvprch_validfrom", $currentTime));
               endif;
               if ($crvhPriceFieldsCurrent[5] != $f_crvh_partner_premium) :
                   insertStmt("servicepricehistory", array("srvprch_obj_type","crvh", "srvprch_obj_id", $f_crvh_id, "srvprch_obj_eid", $f_crvh_sid, "srvprch_fieldname", "crvh_partner_premium", 
                              "srvprch_context", "", "srvprch_price", $f_crvh_partner_premium, "srvprch_validfrom", $currentTime));
               endif;

               // Update specific vehicle data (payload, positions, etc.) in the "Fast Disposition Structure"
               generateVehicleFastDispositionStructure($f_crvh_id, "4", "", $crvhFieldsCurrent);  // Call with OLD data of the modified vehicle for checking to be updated in the FDS


               // * Update "active" courier for the vehicle having "cr.cr_sid <=> crvh.crvh_sid" *
               if ($globalVehicleCourierRelation == "1") :
                  // In case of changing the vehicle SID only remove existing fake courier and generate a new one
                  if ($crvhSidCurrent != "" && $f_crvh_sid != "" && $crvhSidCurrent != $f_crvh_sid) :
                     updateAssociatedVehicleCourier($f_crvh_sid, $crvhSidCurrent);
                  endif;
               endif;

               if ($globalVehicleStockRelation == "1") :
                  $opVal = objectInsertStock("crvh", $f_crvh_id, $vehicleStockIdParent, "SYSTEM-VEHICLES", getLngt("FZG") . $f_crvh_sid, $dbConnection);
                  if ($opVal == "-1") :
                     $statusMessage = getLngt("Es wurde kein spezielles Objekt bzw. dessen Typ spezifiziert!");
                  elseif ($opVal == "-2") :
                     $statusMessage = getLngt("ACHTUNG! Es existiert kein notwendiges fahrzeugbezogenes Hauptlager! Bitte den Administrator kontaktieren!");
                  elseif ($opVal == "-3") :
                     $statusMessage = getLngt("ACHTUNG! Die Anlage des Lagerortes konnte nicht durchgeführt werden! Bitte wiederholen bzw. den Administrator kontaktieren!");
                  endif;
               endif;

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

      else :
         $statusMessage = getLngt("Bitte geben Sie alle mit * gekennzeichneten Felder ein!");
      endif;                                                            
   endif;

   // Remove couriervehicle
   if ($f_act == "removeCourierVehicle" && $courierId != "" && $f_crvh_id != "") :

      TA("B");       

      $doRemove = true;
      if ($globalVehicleCourierRelation == "1") :
         $doRemove = false;  // The vehicle will adapt the role of the courier having a vehicle statistic like a courier statistic. Therefore do NOT remove the vehicle if at least one job does exist !!!!
         $statusMessage = getLngt("Das Fahrzeug darf wg. der Statistik nicht gelöscht werden! Bitte vergeben Sie z.B. eine andere SID!");
         $xCrSid = getFieldValueFromId("couriervehicle", "crvh_id", $f_crvh_id, "crvh_sid");
         $xCrId = getFieldValueFromId("courier", "cr_sid", $xCrSid, "cr_id");  // Get associated fake courier
         // Check existence of reference(s) in job for the fake courier
         $numOfJobs = getCountOfTable("job", "cr_id = '" . $xCrId . "'");
         if ($numOfJobs <= 0) :
            $doRemove = true;
            $statusMessage = "";
            // * Remove "active" courier for the vehicle having "cr.cr_sid <=> crvh.crvh_sid" *
            removeAssociatedVehicleCourier($xCrSid);
         endif;
      endif;

      if ($doRemove && $globalVehicleStockRelation == "1") :
         if (existsEntry("stock",array("stk_obj_type","crvh","stk_obj_id",$f_crvh_id))) :
            // Get all (sub-)stock IDs of the vehicle to be removed
            $stkIdsToBeRemoved = getColVectorFromDB2ArrayByClause("stock", "stk_id", "stk_obj_type = 'crvh' AND stk_obj_id = '" . $f_crvh_id . "'");
            $stkIdsToBeRemovedLen = count($stkIdsToBeRemoved);
            for ($i = 0; $i < $stkIdsToBeRemovedLen; $i++) :
                $checkDelStk = checkStockExistingStockarticle($stkIdsToBeRemoved[$i]);
                if ($checkDelStk) :
                   $doRemove = false;
                   $statusMessage = getLngt("Die Löschung des Fahrzeugs kann nicht durchgeführt werden wegen Beziehungen zu mindestens einem Lagerort! Bitte die Lagerorte bereinigen!");
                   break;
                endif;
            endfor;
         endif;
      endif;

      if ($doRemove) :
         if ($globalVehicleStockRelation == "1") :
            // Remove all (sub-)stock IDs of the vehicle
            for ($i = 0; $i < $stkIdsToBeRemovedLen; $i++) :
                $opDelStk = deleteStock($stkIdsToBeRemoved[$i]);
                if ($opDelStk == "" || $opDelStk == "0"):
                   $statusMessage = getLngt("ACHTUNG! Fehler beim Löschvorgang! Bitte den Administrator kontaktieren!"); 
                   die();  // The following delete statements may not be executed!
                endif;
            endfor;
         endif;

         // delete couriervehicle
         // deleteStmt("couriervehicle", "crvh_id = '$f_crvh_id' AND cr_id = '$courierId'");

         // Remove associations to customers
         deleteStmt("customervehicle", "crvh_id = '$f_crvh_id'");
         
         // On this place only virtual removement
         // Physical removement follows after export
         updateStmt("couriervehicle","crvh_id",$f_crvh_id,array("crvh_modify_status","3"),"cr_id = '$courierId'");
         
         // Get crvh_sid from vehicle to be removed
         $crvhSid = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_sid");
         
         // Remove all cr_sid entries where courier matches the vehicle to be removed      
         updateStmt("courier","cr_sid",$crvhSid,array("cr_sid",""));
         
         // Remove vehicle from the "Fast Disposition Structure"
         generateVehicleFastDispositionStructure($f_crvh_id, "1");

         // Write logdata into log database
         writeToLogDB("125",$hq_id,"",$usr_id,$courierId,$crvhSid,"","");

         // Reset fields of form-parameters
         clearParameters($httpVisualVars);

      else :
         // In case of associated fake courier only
         if ($statusMessage == "") :
            $statusMessage = getLngt("Das Fahrzeug darf wg. der Statistik nicht gelöscht werden! Bitte vergeben Sie z.B. eine andere SID!");
         endif;
      endif;

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

   // Associate vehicle to the selected courier of the same contractor
   if ($f_act == "associateVehicleToNewCourierOfTheSameContractor" && $f_crvh_id != "" && $f_cr_id_same_contractor != "") :

      TA("B");

      // Remove all cr_sid entries where old courier matches the vehicle to be removed
      $tmpCrSid = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_sid");
      updateStmt("courier","cr_sid",$tmpCrSid,array("cr_sid",""));

      // Move relation   
      updateStmt("couriervehicle","crvh_id",$f_crvh_id,array("cr_id", $f_cr_id_same_contractor));

      // Write logdata into log database
      writeToLogDB("186",$hq_id,"",$usr_id,$f_cr_id_same_contractor,$tmpCrSid,"","");

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

   // ******************************************************************
   // * Selection of the courier data for the current headquarter only *
   // ******************************************************************
   if ($courierId != "" && $crHqId != "") :

      // Get the vehicles of a specified courier for selection
      // IMPORTANT: No virtual removed rows (=> clause crvh.crvh_modify_status != '3')
      $crvhList = getVehicleList("crvh.cr_id = '" . $courierId . "' AND cr.hq_id = '" . $crHqId . "' AND crvh.crvh_modify_status != '3'");

      // Get the data of one special vehicle of a specified courier
      if ($f_crvh_id != "") :
         // Get (global) vehicle data of the specified vehicle
         getVehicle($f_crvh_id, "crvh.cr_id = '" . $courierId . "' AND cr.hq_id = '" . $crHqId . "'");

         // Transport insurance date
         if ($f_crvh_transport_insurance_date != "" && $f_crvh_transport_insurance_date != "0000-00-00") :
           $f_crvh_transport_insurance_date_year = substr($f_crvh_transport_insurance_date,0,4);
           $f_crvh_transport_insurance_date_month = substr($f_crvh_transport_insurance_date,5,2);
           $f_crvh_transport_insurance_date_day = substr($f_crvh_transport_insurance_date,8,2);
         endif;

         // Business liability insurance date
         if ($f_crvh_business_liability_insurance_date != "" && $f_crvh_business_liability_insurance_date != "0000-00-00") :
           $f_crvh_business_liability_insurance_date_year = substr($f_crvh_business_liability_insurance_date,0,4);
           $f_crvh_business_liability_insurance_date_month = substr($f_crvh_business_liability_insurance_date,5,2);
           $f_crvh_business_liability_insurance_date_day = substr($f_crvh_business_liability_insurance_date,8,2);
         endif;

         // Services associated to the vehicle
         if ($f_crvh_service != "") :
            // if (substr($f_crvh_service, 0, 1) == ",") : $f_crvh_service = substr($f_crvh_service, 1); endif;        // Remove first comma
            // if (substr($f_crvh_service, -1) == ",") : $f_crvh_service = substr($f_crvh_service, 0, -1); endif;      // Remove last comma
            // $f_crvh_service = spliti(",", $f_crvh_service);    // Convert to an array
            $f_crvh_service = mcConvertNum2Sel($f_crvh_service);
         else :
            $f_crvh_service = array();
         endif;
         $outputService = addCheckboxesFromTable("f_crvh_service","metatype","mt_sort","mt_value","mt_sort","mt_type = 'service' AND mt_objtype = '' AND mt_objid = '0' AND mt_sort != '1'",$f_crvh_service, "<br>");

         // Get path for courier documents (type "CRVH")
         if ($importPath == "") : $importPath = getFieldValueFromId("mandator","md_id",$md_id,"md_doc_path"); endif;
         $importPath = getPathForObjectData($importPath, "CRVH");
         // Get number of documents for the current customer
         $crvhNumOfFiles = getNumOfFilesByFilterInFolder($importPath, $f_crvh_id . "_", "1");

         // Get the related drivers of the same contractor
         $crIdParent = getFieldValueFromId("courier", "cr_id", $courierId, "cr_id_parent");
         if ($crIdParent != "" && $crIdParent > 0) :
            $couriersOfTheSameContractorArr = getColVectorFromDB2ArrayByClause("courier", "cr_id", "cr_id_parent = '" . $crIdParent . "' AND cr_id != '" . $courierId . "'");
            $couriersOfTheSameContractorArrLen = count($couriersOfTheSameContractorArr);
            
            // Prepare display of all couriers of the same contractor
            if ($couriersOfTheSameContractorArrLen > 0) :
               for ($i = 0; $i < $couriersOfTheSameContractorArrLen; $i++) :
                   $tmpCrOut = getFieldValueFromId("courier", "cr_id", $couriersOfTheSameContractorArr[$i], "cr_eid");
                   $tmpUsrId = getFieldValueFromId("courier", "cr_id", $couriersOfTheSameContractorArr[$i], "usr_id");
                   $tmpUsrName = "";
                   if ($tmpUsrId != "" && $tmpUsrId > 0) :
                      $tmpUsrName = getFieldValueFromId("user", "usr_id", $tmpUsrId, "usr_name");
                      $tmpUsrFirstname = getFieldValueFromId("user", "usr_id", $tmpUsrId, "usr_firstname");
                      if ($tmpUsrName != "" && $tmpUsrFirstname != "") :
                         $tmpUsrName .= ", " . $tmpUsrFirstname;
                      endif;
                      if ($tmpUsrName != "") :
                         $tmpCrOut = $tmpCrOut . " - " . $tmpUsrName;
                      endif;
                   endif;
                   $outputCouriersOfTheSameContractor .= "<option value=\"" . $couriersOfTheSameContractorArr[$i] . "\">" . $tmpCrOut . "</option>\n";
               endfor;
            endif;
         endif;
      else :
         if ($f_crvh_sid == "") :
            $f_crvh_sid = getParameterValue("0", "CR_SID_PREFIX", $crHqId);
         endif;      
      endif;

      // Courier filters (mandatory fields ONLY)
      $outputFilter = getFilters($f_crvh_filter, "0", "1", $f_vht_id, "", "0", "0");
      getCurrentScript(__FILE__);

      // For output only
      $tmp_usr_id = getFieldValueFromId("courier", "cr_id", $courierId, "usr_id");
      $tmpFields = getFieldsValueFromId("user","usr_id",$tmp_usr_id,array("usr_name","usr_firstname"));
      $tmp_usr_name = $tmpFields[0];
      $tmp_usr_firstname = $tmpFields[1];   
      $title = $pageTitel . "&nbsp;" . $tmp_usr_firstname . " " . $tmp_usr_name;
      
      if ($f_crvh_sid != "") :
         $title .= " (" . $f_crvh_sid . ")";
      else :
         $title .= " " . getLngt("(Neues Fahrzeug)");
      endif;
   else :

      // Get all vehicles (of the current headquarters the employee is logged in!!!!)
      // IMPORTANT: No virtual removed rows (=> clause crvh.crvh_modify_status != '3')
      $crvhList = getVehicleList("cr.hq_id = '" . $hq_id . "' AND crvh.crvh_modify_status != '3'", "crvh.crvh_sid");
   endif;

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

   // Vehicle photo
   $crvhPhotoPath = "";
   $crvhPhotoFilename = "";
   if ($f_crvh_id != "") :
      $crvhPhotoFilename = $f_crvh_id . "_vehicle_photo.png";
      $rootDirDefault = "../import/upload/";
      $mdRootDirDefault = getFieldValueFromId("mandator","md_id",$md_id,"md_doc_path");
      if ($mdRootDirDefault != "") :
         $rootDirDefault = $mdRootDirDefault;
      endif;
      
      $dirSpecialForObjType = getParameterValue("0", "DATATRANSFER_DIRECTORY_CRVH", $hq_id);
      if ($dirSpecialForObjType == "") : $dirSpecialForObjType = getParameterValue("0", "DATATRANSFER_DIRECTORY_CRVH", "0"); endif;
      
      // Check for headquartes
      if ($crHqId != "" && $dirSpecialForObjType != "") :
         $hqMnemonic = getFieldValueFromId("headquarters","hq_id",$crHqId,"hq_mnemonic");
         if ($hqMnemonic == "") : $hqMnemonic = "MISC" ; endif;
         $crvhPhotoPath .= $rootDirDefault . $dirSpecialForObjType . "/" . $hqMnemonic . "/";
         $crvhPhotoPath = "EMC2" . substr($crvhPhotoPath, 2);
      endif;
   endif;

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

   // Prepare display of all vehicles (possibly filtered by the current selected courier)
   $crvhListLen = count($crvhList);
   $courierVehicles = "<option value=\"\">----</option>\n";
   for ($i = 0; $i < $crvhListLen; $i++) :
       $courierVehicles .= "<option value=\"" . $crvhList[$i][0] . "\"";
       if ($crvhList[$i][0] == $f_crvh_id) :
          $courierVehicles .= " selected";
       endif;                              
       $courierVehicles .= ">" . $crvhList[$i][4] . "</option>\n";
   endfor;

   // Special (filter) checks
   // [I] If there is no value in "cmp_stax_idno" then filter "EU" cannot be set
   $crStaxIdNo = "";
   if ($courierId != "") :       
       $crCmpId = getFieldValueFromId("courier","cr_id",$courierId,"cmp_id");
       $crStaxIdNo = getFieldValueFromId("company","cmp_id",$crCmpId,"cmp_stax_idno");
   endif;
   // [II] If total weight (<=> f_crvh_totalweight) >= 2.500 kg AND there is NO filter "TG" (<=> Tachograph) is set then filter "AL" cannot be set and an info shall appear
   $crvhTotalweight = "";
   if ($f_crvh_id != "" && is_numeric($f_crvh_id)) :
      $crvhTotalweight = getFieldValueFromId("couriervehicle","crvh_id",$f_crvh_id,"crvh_totalweight");
   endif;

   // Check for customized range of partner provision value
   // Lower Range
   $parCrvhPartnerProvRangeLower = getParameterValue("0", "MASK_CRVH_PARTNER_PROV_RANGE_LOWER", $hq_id);
   if ($parCrvhPartnerProvRangeLower == "") : $parCrvhPartnerProvRangeLower = getParameterValue("0", "MASK_CRVH_PARTNER_PROV_RANGE_LOWER", "0"); endif;
   // Upper Range
   $parCrvhPartnerProvRangeUpper = getParameterValue("0", "MASK_CRVH_PARTNER_PROV_RANGE_UPPER", $hq_id);
   if ($parCrvhPartnerProvRangeUpper == "") : $parCrvhPartnerProvRangeUpper = getParameterValue("0", "MASK_CRVH_PARTNER_PROV_RANGE_UPPER", "0"); endif;

   $pageHeadline = $title;
?>

<html>

<head>
<title><?php echo $pageTitel ?></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/checkFormTags.js" type="text/javascript"></script>
<script src="../include/searchLists.js" type="text/javascript"></script>

<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>

// Check for special filter checkbox being activated
function isFilterCheckboxActivated(filter) {
  const filterCheckboxes = document.querySelectorAll('input[name="f_crvh_filter[]"]');
  for (let i = 0; i < filterCheckboxes.length; i++) {
    if (filterCheckboxes[i].value === filter && filterCheckboxes[i].checked) {
      return true;
    }
  }
  return false;
}

function setFilterCheckbox(filter, beingChecked) {
  const filterCheckboxes = document.querySelectorAll('input[name="f_crvh_filter[]"]');
  for (let i = 0; i < filterCheckboxes.length; i++) {
    if (filterCheckboxes[i].value === filter) {
      filterCheckboxes[i].checked = beingChecked; // Setzt die Checkbox mit Wert "B" auf unchecked
    }
  }
}

function finishPage(mode) {
  var ok = true;

  if (mode == 'save' || mode == 'copy') {
     // if (!NaN(document.forms[0].f_crvh_prov.value, 'Bitte tragen Sie eine Zahl bei Provision ein!')) {ok = false;};
     if (!checkIsNaNIgnoreSpace(document.forms[0].f_crvh_payload.value, '<?php echo getLngt("Bitte tragen Sie eine Zahl bei Nutzlast ein!") ?>')) {ok = false;};
     if (!checkIsNaNIgnoreSpace(document.forms[0].f_crvh_totalweight.value, '<?php echo getLngt("Bitte tragen Sie eine Zahl bei Gesamtgewicht ein!") ?>')) {ok = false;};
     if (!checkIsNaNIgnoreSpace(document.forms[0].f_crvh_length.value, '<?php echo getLngt("Bitte tragen Sie eine Zahl bei Länge ein!") ?>')) {ok = false;};
     if (!checkIsNaNIgnoreSpace(document.forms[0].f_crvh_width.value, '<?php echo getLngt("Bitte tragen Sie eine Zahl bei Breite ein!") ?>')) {ok = false;};
     if (!checkIsNaNIgnoreSpace(document.forms[0].f_crvh_height.value, '<?php echo getLngt("Bitte tragen Sie eine Zahl bei Höhe ein!") ?>')) {ok = false;};
     if (!checkIsNaNIgnoreSpace(document.forms[0].f_crvh_position.value, '<?php echo getLngt("Bitte tragen Sie eine Zahl bei Stellplätze ein!") ?>')) {ok = false;};
     if (!checkIsNaNIgnoreSpace(document.forms[0].f_crvh_aperture_height_side.value, '<?php echo getLngt("Bitte tragen Sie eine Zahl bei der seitlichen Durchladehöhe ein!") ?>')) {ok = false;};
     if (!checkIsNaNIgnoreSpace(document.forms[0].f_crvh_aperture_height_rear.value, '<?php echo getLngt("Bitte tragen Sie eine Zahl bei der Heckdurchladehöhe ein!") ?>')) {ok = false;};

     <?php if ($crvhRgtRule01) : ?>
       document.forms[0].f_crvh_advertising_allowance.value = document.forms[0].f_crvh_advertising_allowance.value.replace(",",".");
       document.forms[0].f_crvh_transport_insurance_amount.value = document.forms[0].f_crvh_transport_insurance_amount.value.replace(",",".");
       document.forms[0].f_crvh_business_liability_insurance_amount.value = document.forms[0].f_crvh_business_liability_insurance_amount.value.replace(",",".");
       document.forms[0].f_crvh_system_fee_amount.value = document.forms[0].f_crvh_system_fee_amount.value.replace(",",".");

       if (!checkIsNaNIgnoreSpace(document.forms[0].f_crvh_advertising_allowance.value, '<?php echo getLngt("Bitte tragen Sie eine Zahl bei der Werbevergütung ein!") ?>')) {ok = false;};
       if (!checkIsNaNIgnoreSpace(document.forms[0].f_crvh_transport_insurance_amount.value, '<?php echo getLngt("Bitte tragen Sie eine Zahl bei der Transportversicherung ein!") ?>')) {ok = false;};
       /* if (!checkIsNaNIgnoreSpace(document.forms[0].f_crvh_transport_insurance_date.value, '<?php echo getLngt("Bitte tragen Sie ein Datum beim Transportversicherungsdatum ein!") ?>')) {ok = false;}; */
       if (!checkIsNaNIgnoreSpace(document.forms[0].f_crvh_business_liability_insurance_amount.value, '<?php echo getLngt("Bitte tragen Sie eine Zahl bei der Betriebshaftpflichtversicherung ein!") ?>')) {ok = false;};
       /* if (!checkIsNaNIgnoreSpace(document.forms[0].f_crvh_business_liability_insurance_date.value, '<?php echo getLngt("Bitte tragen Sie ein Datum beim Betriebshaftpflichtversicherungsdatum ein!") ?>')) {ok = false;}; */
       if (!checkIsNaNIgnoreSpace(document.forms[0].f_crvh_system_fee_amount.value, '<?php echo getLngt("Bitte tragen Sie eine Zahl bei der Systemgebühr ein!") ?>')) {ok = false;};
     <?php endif; ?>

     <?php if ($crvhRgtRule02) : ?>
       /* document.forms[0].f_crvh_partner_premium.value = document.forms[0].f_crvh_partner_premium.value.replace(",","."); */
       document.forms[0].f_crvh_partner_commission.value = document.forms[0].f_crvh_partner_commission.value.replace(",",".");
       
       /* if (!checkIsNaNIgnoreSpace(document.forms[0].f_crvh_partner_premium.value, '<?php echo getLngt("Bitte tragen Sie eine Zahl bei der Partnerprämie ein!") ?>')) {ok = false;}; */
       if (!checkIsNaNIgnoreSpace(document.forms[0].f_crvh_partner_commission.value, '<?php echo getLngt("Bitte tragen Sie eine Zahl bei der Partnerprovision ein!") ?>')) {ok = false;};
     <?php endif; ?>

     if (mode == 'save') {
     	  // Finally there are some special conditions
     	  // [I] Check for filter "EU"
     	  if ('<?php echo $courierId ?>' != '') {
     	  	 var filter_01 = 'EU';
     	     var crStaxIdNo = '<?php echo $crStaxIdNo ?>';
     	     if (crStaxIdNo == '' && isFilterCheckboxActivated(filter_01)) {
     	     	  setFilterCheckbox(filter_01, false);
     	     	  alert('<?php echo getLngt("Es existiert bei dem Transporteur keine Umsatzsteuer-ID. Der folgende Filter kann nicht aktiviert werden:") ?>' + ' [' + filter_01 + '] <?php echo getLngt("Das Fahrzeug wurde ohne diesen Filter gespeichert!") ?>');
     	     }
     	  }
        // [II] If total weight (<=> f_crvh_totalweight) >= 2.500 kg AND there is NO filter "TG" (<=> Tachograph) is set then filter "AL" cannot be set and an info shall appear
     	  if (ok && '<?php echo $f_crvh_id ?>' != '') {
     	  	 var filter_01 = 'AL';
     	  	 var filter_02 = 'TG';
     	  	 var crvhTotalweight = document.forms[0].f_crvh_totalweight.value;
     	     if (crvhTotalweight >= 2500 && isFilterCheckboxActivated(filter_01) && !isFilterCheckboxActivated(filter_02)) {
     	     	  setFilterCheckbox(filter_01, false);
     	     	  alert('<?php echo getLngt("Das zulässige Gesamtgewicht liegt bei mindestens 2.500 kg und der Filter TG ist nicht aktiviert. Deshalb darf der Filter AL nicht aktiviert sein!") ?>');
     	     }
     	  }

        if (ok) {
        	 if (mode == 'save') {
        	    document.forms[0].f_act.value = '<?php echo ($f_crvh_id != "" ? "modifyCourierVehicle" : "newCourierVehicle"); ?>';
        	 }
           document.forms[0].submit();
        };
     };
  } 
  
  if (mode == 'reset') {
     document.location.href = "courier_vehicle.php?courierId=<?php echo ec($courierId) ?>";  
  } 
  
  if (mode == 'resetAll') {
     document.location.href = "courier_vehicle.php";
  } 
  
  if (mode == 'remove') {
     if (confirm('<?php echo getLngt("Möchten Sie das aktuell angezeigte Fahrzeug wirklich herauslöschen?") ?>')) {
        document.forms[0].f_act.value='removeCourierVehicle';
        document.forms[0].submit();
     };  
  }
  
  if (mode == 'select') {
     if (document.forms[0].f_crvh_id.options[0].selected == true) {   
        finishPage('reset');
     } else {
     	document.forms[0].submit();
     };
  };

  if (mode == 'select_new_driver') {
  	 var f_cr_id_same_contractor = getSelectedValue('f_cr_id_same_contractor');
  	 if (f_cr_id_same_contractor != '') {
        if (confirm('<?php echo getLngt("Möchten Sie das aktuell angezeigte Fahrzeug dem Fahrerkollegen zuweisen?") ?>')) {
           document.forms[0].f_act.value='associateVehicleToNewCourierOfTheSameContractor';
           document.forms[0].submit();
        } else {
        	setSelectedValue('f_cr_id_same_contractor', '');
        };
     };
  }

  if (mode == 'selectFromAll') {
     document.forms[0].submit();
  };

  if (mode == 'copy' && ok) {
  	 var cr_eid_new = $('#f_crvh_cr_eid_new').val();
  	 var crvh_sid_new = $('#f_crvh_sid_new').val();
  	 var crvh_comm_no_new = $('#f_crvh_comm_no_new').val();
  	 if (cr_eid_new != '' && crvh_sid_new != '' && crvh_comm_no_new != '') {
  	 	  // Check "cr_eid_new" does exist
  	 	  ajaxRequestGet('../include/ajaxReqLib.php', 'mode=0&db_table=courier&db_id_field=cr_eid&search_value=' + cr_eid_new + '&db_return_field=cr_id');
  	    if (retValue > '0') {
  	    	 // Check "crvh_sid_new" does NOT exist
  	       ajaxRequestGet('../include/ajaxReqLib.php', 'mode=0&db_table=couriervehicle&db_id_field=crvh_sid&search_value=' + crvh_sid_new + '&db_return_field=crvh_id');	
  	    	 if (retValue > '0') {
  	 	       alert('<?php echo getLngt("Die neue Fahrzeug-SID existiert leider schon.") ?>');
  	 	     } else {
  	 	     	 // Check "crvh_comm_no_new" does NOT exist
  	 	       ajaxRequestGet('../include/ajaxReqLib.php', 'mode=0&db_table=couriervehicle&db_id_field=crvh_comm_no&search_value=' + crvh_comm_no_new + '&db_return_field=crvh_id');		 
  	    	   if (retValue > '0') {
  	 	          alert('<?php echo getLngt("Die neue Kommissionsnummer existiert leider schon.") ?>');
  	 	       } else {
  	 	       	  document.forms[0].f_act.value='copyCourierVehicle';
  	 	  	      document.forms[0].submit();
  	 	  	   }
  	       }
  	 	  } else {
  	 	  	 alert('<?php echo getLngt("Der angegebene Transporteur existiert leider nicht.") ?>');
  	    }
  	 } else {
  	 	 alert('<?php echo getLngt("Für den Kopiervorgang müssen alle neuen Felder einen gültigen Eintrag.") ?>');
  	 }
  };
};

function openMetaFieldSpecial (category, objId, specialPageTitle) {
  var widthPopupWin = 900;
  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/metafield_special.php?deactivateMenu=1&category=" + category + "&objId=" + objId + "&specialPageTitle=" + specialPageTitle ,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openVehicleCustomer (crvhId) {
  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/vehicle_customer.php?crvhId=" + crvhId,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openPremiumDetails(crvhId) {
  var widthPopupWin = 1200;
  var heightPopupWin = 900;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/premium_details.php?crvh_id=" + crvhId,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

var vehicleCopyIsDisplayed = true;
function callVehicleCopy() {
	if (vehicleCopyIsDisplayed) {
		 myhide('vehicleselectioncontainer');
		 vehicleCopyIsDisplayed = false;
  } else {
     myshow('vehicleselectioncontainer');
     vehicleCopyIsDisplayed = true;
  }
}

/*
function checkDate(checkObj,mode) {
  var resetValue = checkDateFields(checkObj,mode);
  if (resetValue) {
     checkObj.value = '';
     checkObj.focus();
  };
};
*/

function openCrvhPhoto () {
  var widthPopupWin = 1200;
  var heightPopupWin = 1024;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  var f_path = '<?php echo $crvhPhotoPath ?>';
  var f_fileName = '<?php echo $crvhPhotoFilename ?>';
  var f_width = 1000;
  var f_height = 0;
  popupWin = window.open("../include/image_viewer.php?f_fileName=" + f_fileName + "&f_width=" + f_width + "&f_height=" + f_height + "&f_path=" + f_path,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openCrvhHistory(f_cr_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(1) ?>&cr_id=" + f_cr_id + "&op=<?php echo ec(2) ?>&logoselection=<?php echo ec(2) ?>&displayselection=<?php echo ec(1) ?>","","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

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

function execBodyOnLoad () {
	callVehicleCopy();
	displayStatusMessage();	
};
-->
</script>

</head>

<body class="menu_bgcol" onLoad="<?php echo $phpCurrentNavigationOnLoad ?>execBodyOnLoad();">

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

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

<!-- Buttons -->
<?php // echo htmlDivLineSpacer("5px", "", "left"); ?>
<div>
  <?php echo defineButtonType10(getLngt("Gesamtauswahl"), "action_crvh_all", "finishPage('resetAll');", "155", "left", "0"); ?>
	<?php
	  if ($f_crvh_id != "" && $f_crvh_id != "0") :
	     echo defineButtonType10(getLngt("Fahrzeug&nbsp;entfernen"), "action_remove", "finishPage('remove');", "155", "left", "0");
       echo defineButtonType10(getLngt("2. Seite"), "action_2ndpage", "openMetaFieldSpecial('4','" . ec($f_crvh_id) . "');", "155", "left", "0");
       echo defineButtonType10(getLngt("Kunde"), "action_cs", "openVehicleCustomer('" . ec($f_crvh_id) . "');", "155", "left", "0");
       echo defineButtonType10(getLngt("Fahrzeug&nbsp;kopieren"), "action_copy_prep", "callVehicleCopy();", "155", "left", "0");
       echo defineLinkButtonType10(getLngt("Dokumente") . ($crvhNumOfFiles != "-1" ? ": " . $crvhNumOfFiles : ""), "action_dt_crvh", "../import/data_transfer.php?objType=crvh&objId=" . ec($f_crvh_id), "155", "left", "0", "", "", "", "", "0");
       echo htmlDivLineSpacer("1px", "", "left");
       if ($courierId != "") :
          echo defineButtonType10(getLngt("Änderungshistorie"), "action_crvh_history", "openCrvhHistory('" . ec($courierId) . "');", "190", "left", "0");
       endif;
       echo defineButtonType10(getLngt("Fahrzeugfoto"), "action_photo", "openCrvhPhoto();", "155", "left", "0");
    endif;
  ?>
  <?php echo htmlDivLineSpacer("1px", "", "left"); ?>
  <?php echo defineButtonType10(getLngt("Speichern"), "action_save", "finishPage('save');", "155", "left", "0"); ?>
  <?php echo defineButtonType10(getLngt("Zurücksetzen"), "action_reset", "finishPage('reset');", "155", "left", "0"); ?>  
  <?php echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "155", "left", "0"); ?>
	<?php
	  if ($f_crvh_id != "" && $f_crvh_id != "0") :
	     echo htmlDivLineSpacer("5px", "", "left");
       echo "<div id=\"vehicleselectioncontainer\">";
       echo htmlDivLineSpacer("5px");
       echo "  <div>" . getLngt("Transporteur [EID]") . ":</div>";
       echo "  <div>" . "<input type=\"text\"" . $htmlClass01 . " id=\"f_crvh_cr_eid_new\" name=\"f_crvh_cr_eid_new\" value=\"\">" . "</div>";
       echo htmlDivLineSpacer("5px");
       echo "  <div>" . getLngt("Neue SID") . ":</div>";
       echo "  <div>" . "<input type=\"text\"" . $htmlClass01 . " id=\"f_crvh_sid_new\" name=\"f_crvh_sid_new\" value=\"\">" . "</div>";
       echo htmlDivLineSpacer("5px");
       echo "  <div>" . getLngt("Neue Komm.-Nr.") . ":</div>";
       echo "  <div>" . "<input type=\"text\"" . $htmlClass01 . " id=\"f_crvh_comm_no_new\" name=\"f_crvh_comm_no_new\" value=\"\">" . "</div>";
       echo htmlDivLineSpacer("5px");
       echo defineButtonType10(getLngt("Kopie speichern"), "action_copy", "finishPage('copy');", "155");
       echo "</div>";
    endif;
  ?>
</div>

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

<form action="../admin/courier_vehicle.php" method="post">
  <input type="hidden" name="f_act" value="">
  <input type="hidden" name="courierId" value="<?php echo ec($courierId) ?>">
  <?php echo $phpCurrentNavigationInputHidden ?>
  <input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">

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

  <?php 
    $col1 = "220px";
    $row1 = "30px";
    $divCounter = 0;

    function getDivStyleCrvh () {
    	global $divCounter, $divStyle, $col1, $row1;
    	$divCounter++;
    	if ($divCounter % 2 == 0) :
         $divStyle = "background-color: " . getListColor(0, 0) . "; padding: 4px; vertical-align: middle;";
      else :
         $divStyle = "background-color: " . getListColor(1, 0) . "; padding: 4px; vertical-align: middle;";
      endif;
      return $divStyle;
    }

    function getDivStyleFullCrvh () {
    	global $divCounter, $divStyle, $col1, $row1;
    	// $divCounter++;
    	if ($divCounter % 2 == 0) :
         $divStyleFull = "style=\"" . $divStyle . "height:" . $row1 . "\"";
      else :
         $divStyleFull = "style=\"" . $divStyle . "height:" . $row1 . "\"";
      endif;
      return $divStyleFull;
    }
  ?>
  <div>
  	<?php if ($courierId != "") : ?>
      <div <?php echo setStyleHtmlDiv("500px","left","","margin-top: 5px;"); ?>>
        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left",$row1,getDivStyleCrvh()); ?>><b><?php echo getLngt("Fahrzeuge:") ?></b></div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <select <?php echo $htmlClass01 ?> name="f_crvh_id" onChange="finishPage('select');" tabindex="30">
              <?php echo $courierVehicles; ?>
            </select>
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("30px"); ?>

        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Fahrzeugtyp") ?>*:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <select <?php echo $htmlClass01 ?> name="f_vht_id" tabindex="30">
              <?php
                // Check excludes vehicle type IDs
                $mask_exclude_vht_ids = getParameterValue("0", "MASK_EXCLUDE_VHT_IDS", $hq_id);      
                if ($mask_exclude_vht_ids != "") $mask_exclude_vht_ids = " AND NOT mt_sort IN (" . $mask_exclude_vht_ids . ")";
                echo addOptionsFromTable("metatype","mt_sort","mt_value","mt_sort","mt_type = 'vehicletype'" . $mask_exclude_vht_ids, $f_vht_id);
              ?>
            </select>
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>

        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Antriebsart") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <select <?php echo $htmlClass01 ?> name="f_crvh_drivetype" tabindex="31">
              <?php echo addOptionsFromTable("metatype","mt_sort","mt_value","mt_sort","mt_type = 'drivetype'",$f_crvh_drivetype); ?>
            </select>
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>
        
        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("SID") ?>*:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_sid" value="<?php echo $f_crvh_sid ?>" tabindex="1">
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>
        
        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Komm.-Nr.") ?>*:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_comm_no" value="<?php echo $f_crvh_comm_no ?>" tabindex="1">
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>
        
        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Kennzeichen") ?>*:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_vh_sign" value="<?php echo $f_crvh_vh_sign ?>" tabindex="1">
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>
        
        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Marke") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_vh_name" value="<?php echo $f_crvh_vh_name ?>" tabindex="1">
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>
        
        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Erstzulassung") ?>* <?php echo getLngt("[Monat/Jahr]") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <select <?php echo $htmlClass01 ?> name="f_crvh_licence_date_month" tabindex="1">
              <?php echo addOptionsFromRange(1,12,$f_crvh_licence_date_month,"1") ?>
            </select>
            /
            <select <?php echo $htmlClass01 ?> name="f_crvh_licence_date_year" tabindex="1">
              <?php echo addOptionsFromRange(getDateTime("year")-20,getDateTime("year"),$f_crvh_licence_date_year,"1") ?>
            </select>
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>
  
        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Umweltstufe") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <select <?php echo $htmlClass01 ?> name="f_crvh_env_badge_level" tabindex="1">
              <?php echo addOptionsFromRange(1,6,$f_crvh_env_badge_level,"1") ?>
            </select>
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>

        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Fahrzeugübernahme") ?> <?php echo getLngt("[Monat/Jahr]") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <select <?php echo $htmlClass01 ?> name="f_crvh_owner_month" tabindex="1">
              <?php echo addOptionsFromRange(1,12,$f_crvh_owner_month,"1") ?>
            </select>
            /
            <select <?php echo $htmlClass01 ?> name="f_crvh_owner_year" tabindex="1">
              <?php echo addOptionsFromRange(getDateTime("year")-20,getDateTime("year"),$f_crvh_owner_year,"1") ?>
            </select>
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>
  
        <?php /*
        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("[FELD UNGENUTZT]") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_prov" value="<?php echo $f_crvh_prov ?>" size="5" maxlength="5" tabindex="1">
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>
        */ ?>
        
        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Nutzlast") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_payload" value="<?php echo $f_crvh_payload ?>" size="5" maxlength="5" tabindex="1">
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>
        
        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Zulässiges Gesamtgewicht"); if ($parMaskMandatoryFieldTotalweight == "1") : echo "*"; endif; ?>:<?php echo getLngt("[Zulassungsbescheinigung Teil I.F1]"); ?></div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_totalweight" value="<?php echo $f_crvh_totalweight ?>" size="5" maxlength="5" tabindex="1">
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>
        <?php // echo htmlDivLineSpacer("5px"); ?>
        
        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Länge") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_length" value="<?php echo $f_crvh_length ?>" size="5" maxlength="5" tabindex="1">
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>
        
        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Breite") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_width" value="<?php echo $f_crvh_width ?>" size="5" maxlength="5" tabindex="1">
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>
        
        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Höhe") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_height" value="<?php echo $f_crvh_height ?>" size="5" maxlength="5" tabindex="1">
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>
        
        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Stellplätze") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_position" value="<?php echo $f_crvh_position ?>" size="5" maxlength="5" tabindex="1">
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>

        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Seitendurchladehöhe") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_aperture_height_side" value="<?php echo $f_crvh_aperture_height_side ?>" size="5" maxlength="5" tabindex="1">
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>

        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Heckdurchladehöhe") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_aperture_height_rear" value="<?php echo $f_crvh_aperture_height_rear ?>" size="5" maxlength="5" tabindex="1">
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>

        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Versicherung") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_insurance_name" value="<?php echo $f_crvh_insurance_name ?>" tabindex="1">
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>

        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Versicherungsnr.") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_insurance_no" value="<?php echo $f_crvh_insurance_no ?>" tabindex="1">
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("10px"); ?>

        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt(wrapPhrase("Finanzierung", "crvh")) ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <input type="checkbox" name="f_crvh_funding_state[]" value="1" <?php echo ($f_crvh_funding_state == "1" ? "checked" : ""); ?> tabindex="1">
          </div>
        </div>
        <?php if (false) : ?>
          <?php // echo htmlDivLineSpacer("5px"); ?>
          <div>
            <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Letzte Rate") ?>:</div>
            <div <?php echo getDivStyleFullCrvh() ?>> 
              <select <?php echo $htmlClass01 ?> name="f_crvh_funding_final_installment_month" tabindex="1">
                <?php echo addOptionsFromRange(1,12,$f_crvh_funding_final_installment_month,"1") ?>
              </select>
              /
              <select <?php echo $htmlClass01 ?> name="f_crvh_funding_final_installment_year" tabindex="1">
                <?php echo addOptionsFromRange(getDateTime("year")-10,getDateTime("year")+1,$f_crvh_funding_final_installment_year,"1") ?>
              </select>          
              <?php echo getLngt("(Monat/Jahr)") ?>
            </div>
          </div>
          <?php // echo htmlDivLineSpacer("5px"); ?>        
          <div>
            <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Restwert") ?>:</div>
            <div <?php echo getDivStyleFullCrvh() ?>>
              <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_funding_residual_value" value="<?php echo $f_crvh_funding_residual_value ?>" size="10" maxlength="10" tabindex="1">
            </div>
          </div>
        <?php endif; ?>
        <?php // echo htmlDivLineSpacer("10px"); ?>


        <?php if (authCheckEmployeeRights($emp_id, "10")) :  ?>
          <div>
            <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Endgerätenutzung") ?>:</div>
            <div <?php echo getDivStyleFullCrvh() ?>>
              <input type="checkbox" name="f_crvh_pda_usage[]" value="1" <?php echo ($f_crvh_pda_usage == "1" ? "checked" : ""); ?> tabindex="1">
            </div>
          </div>
          <?php // echo htmlDivLineSpacer("10px"); ?>

          <?php /*
          <div>
            <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("[FELD UNGENUTZT]") ?>:</div>
            <div <?php echo getDivStyleFullCrvh() ?>>
              <input type="checkbox" name="f_crvh_system_fee[]" value="1" <?php echo ($f_crvh_system_fee == "1" ? "checked" : ""); ?> tabindex="1">
            </div>
          </div>          
          <?php echo htmlDivLineSpacer("10px"); ?>
          */ ?>
        <?php endif; ?>

        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Fahrzeug-CI") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
          	<select class="f8np1" name="f_crvh_corporate_identity">"
          		<option value="0">----</option>
          		<?php echo addOptionsFromTable("metatype","mt_sort","mt_value","mt_sort","mt_type = 'vehicle_ci' AND mt_objtype = '' AND mt_objid = '0'",((int)$f_crvh_corporate_identity & 15)) ?>
            </select>
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("10px"); ?>

        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Fahrer-Pflicht-CI") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
          	<select class="f8np1" name="f_crvh_corporate_identity_2">"
          		<option value="0">----</option>
          		<?php echo addOptionsFromTable("metatype","mt_sort","mt_value","mt_sort","mt_type = 'vehicle_ci' AND mt_objtype = '' AND mt_objid = '0'",(((int)$f_crvh_corporate_identity / 16) & 15)) ?>
            </select>
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("10px"); ?>

        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Bemerkung") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_remark" value="<?php echo $f_crvh_remark ?>" size="27" tabindex="1">
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>

        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Freitext") ?>:</div>
          <div <?php echo getDivStyleFullCrvh() ?>>
            <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_freetext_1" value="<?php echo $f_crvh_freetext_1 ?>" size="27" tabindex="1">
          </div>
        </div>
        <?php // echo htmlDivLineSpacer("5px"); ?>

        <?php if ($crvhRgtRule02) : ?>
          <?php if (false) : ?>
          <div>
            <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Partnerprämie [&euro;]") ?>:</div>
            <div <?php echo getDivStyleFullCrvh() ?>>
              <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_partner_premium" value="<?php echo $f_crvh_partner_premium ?>" size="8" maxlength="8" tabindex="1">&nbsp;&nbsp;
              <?php /* 
              <input type="button" name="action_crvh_premium_details" id="action_crvh_premium_details" title="" value="..." accesskey="" style="width:20px; height:20px; background:#1b12b9; color:#FFFFFF; font-size:8pt; font-weight:bold; font-style:normal; font-family:Helvetica,Arial; " onMouseover="vSetCss('action_crvh_premium_details', {color: '#97bcFF'})" onMouseout="vSetCss('action_crvh_premium_details', {color: '#FFFFFF'})" onClick="openPremiumDetails('<?php echo ec($f_crvh_id) ?>');"  > 
              */ ?>
            </div>
          </div>
          <?php echo htmlDivLineSpacer("5px"); ?>
          
          <div>
            <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Text&nbsp;zur&nbsp;Partnerprämie ") ?>:</div>
            <div <?php echo getDivStyleFullCrvh() ?>>
            	<?php /* 
              <textarea <?php echo $htmlClass01 ?> name="f_crvh_partner_text" cols="20" rows="1" tabindex="1"><?php echo $f_crvh_partner_text ?></textarea>
              */ ?>
              <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_partner_text" value="<?php echo $f_crvh_partner_text ?>" size="27" tabindex="1">&nbsp;&nbsp;
            </div>
          </div>
          <?php echo htmlDivLineSpacer("5px"); ?>
          <?php endif; ?>
          
          <div>
            <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Partnerprovision [%]") ?>:</div>
            <div <?php echo getDivStyleFullCrvh() ?>>
              <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_partner_commission" value="<?php echo $f_crvh_partner_commission ?>" onChange="javascript:checkCrvhPartnerProv();" size="5" maxlength="5" tabindex="1">
            </div>
          </div>
          <?php echo htmlDivLineSpacer("5px"); ?>
          
        <?php endif; ?>

        <?php if ($crvhRgtRule01) : ?>
          <div>
            <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Werbevergütung [&euro;]") ?>:</div>
            <div <?php echo getDivStyleFullCrvh() ?>>
              <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_advertising_allowance" value="<?php echo $f_crvh_advertising_allowance ?>" size="5" maxlength="5" tabindex="1">
            </div>
          </div>
          <?php // echo htmlDivLineSpacer("5px"); ?>
          
          <div>
            <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Transportversicherung [&euro;]") ?>:</div>
            <div <?php echo getDivStyleFullCrvh() ?>>
              <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_transport_insurance_amount" value="<?php echo $f_crvh_transport_insurance_amount ?>" size="8" maxlength="8" tabindex="1">
            </div>
          </div>
          <?php // echo htmlDivLineSpacer("5px"); ?>

          <div>
            <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Transportversicherungsdatum") . "</br>" . getLngt("(TT-MM-JJJJ)") ?>:</div>
            <div <?php echo getDivStyleFullCrvh() ?>>
              <select <?php echo $htmlClass01 ?> name="f_crvh_transport_insurance_date_day" tabindex="1">
                <?php echo addOptionsFromRange(1,31,$f_crvh_transport_insurance_date_day,"1") ?>
              </select>
              /
              <select <?php echo $htmlClass01 ?> name="f_crvh_transport_insurance_date_month" tabindex="1">
                <?php echo addOptionsFromRange(1,12,$f_crvh_transport_insurance_date_month,"1") ?>
              </select>
              /
              <select <?php echo $htmlClass01 ?> name="f_crvh_transport_insurance_date_year" tabindex="1">
                <?php echo addOptionsFromRange(getDateTime("year")-20,getDateTime("year")+1,$f_crvh_transport_insurance_date_year,"1") ?>
              </select>
            	<?php /*
              <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_transport_insurance_date_day" value="<?php echo $f_crvh_transport_insurance_date_day ?>" size="2" maxlength="2" tabindex="110" onBlur="checkDate(this,'day')">&nbsp;
              <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_transport_insurance_date_month" value="<?php echo $f_crvh_transport_insurance_date_month ?>" size="2" maxlength="2" tabindex="114" onBlur="checkDate(this,'month')">&nbsp;
              <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_transport_insurance_date_year" value="<?php echo $f_crvh_transport_insurance_date_year ?>" size="4" maxlength="4" tabindex="117">
              */ ?>
            </div>
          </div>
          <?php // echo htmlDivLineSpacer("5px"); ?>

          <div>
            <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Betriebshaftpflichtversicherung [&euro;]") ?>:</div>
            <div <?php echo getDivStyleFullCrvh() ?>>
              <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_business_liability_insurance_amount" value="<?php echo $f_crvh_business_liability_insurance_amount ?>" size="8" maxlength="8" tabindex="1">
            </div>
          </div>
          <?php // echo htmlDivLineSpacer("5px"); ?>
          
          <div>
            <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Betriebshaftpflichtversicherungsdatum") . "</br>" . getLngt("(TT-MM-JJJJ)") ?>:</div>
            <div <?php echo getDivStyleFullCrvh() ?>>
              <select <?php echo $htmlClass01 ?> name="f_crvh_business_liability_insurance_date_day" tabindex="1">
                <?php echo addOptionsFromRange(1,31,$f_crvh_business_liability_insurance_date_day,"1") ?>
              </select>
              /
              <select <?php echo $htmlClass01 ?> name="f_crvh_business_liability_insurance_date_month" tabindex="1">
                <?php echo addOptionsFromRange(1,12,$f_crvh_business_liability_insurance_date_month,"1") ?>
              </select>
              /
              <select <?php echo $htmlClass01 ?> name="f_crvh_business_liability_insurance_date_year" tabindex="1">
                <?php echo addOptionsFromRange(getDateTime("year")-20,getDateTime("year")+1,$f_crvh_business_liability_insurance_date_year,"1") ?>
              </select>
            	<?php /*
              <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_business_liability_insurance_date_day" value="<?php echo $f_crvh_business_liability_insurance_date_day ?>" size="2" maxlength="2" tabindex="110" onBlur="checkDate(this,'day')">&nbsp;
              <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_business_liability_insurance_date_month" value="<?php echo $f_crvh_business_liability_insurance_date_month ?>" size="2" maxlength="2" tabindex="114" onBlur="checkDate(this,'month')">&nbsp;
              <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_business_liability_insurance_date_year" value="<?php echo $f_crvh_business_liability_insurance_date_year ?>" size="4" maxlength="4" tabindex="117">
              */ ?>
            </div>
          </div>
          <?php // echo htmlDivLineSpacer("5px"); ?>

          <div>
            <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Systemgebühr [&euro;]") ?>:</div>
            <div <?php echo getDivStyleFullCrvh() ?>>
              <input type="text" <?php echo $htmlClass01 ?> name="f_crvh_system_fee_amount" value="<?php echo $f_crvh_system_fee_amount ?>" size="8" maxlength="8" tabindex="1">
            </div>
          </div>
          <?php // echo htmlDivLineSpacer("5px"); ?>
        <?php endif; ?>

        <?php if ($globalVehicleCourierRelation == "1") :  ?>
          <div>
            <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Abrechnungsfahrzeug") ?>:</div>
            <div <?php echo getDivStyleFullCrvh() ?>>
            	<select name="f_crvh_id_inv">
                <option value="0">&nbsp;</option>
                <?php echo addOptionsFromTable("couriervehicle AS crvh, courier AS cr", "crvh_id", "crvh_sid", "crvh_sid", "crvh.cr_id = cr.cr_id AND cr.hq_id = '" . $hq_id . "'", $f_crvh_id_inv); ?>
              </select>
            </div>
          </div>
          <?php // echo htmlDivLineSpacer("5px"); ?>
        <?php endif; ?>

        <?php if (authCheckEmployeeRights($emp_id, "13")) :  ?>
          <div>
            <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Eigenfahrzeug") ?>:</div>
            <div <?php echo getDivStyleFullCrvh() ?>>
              <input type="checkbox" name="f_crvh_special[]" value="1" <?php echo ($f_crvh_special == "1" ? "checked" : ""); ?> tabindex="1">
            </div>
          </div>
          <?php // echo htmlDivLineSpacer("5px"); ?>
        <?php endif; ?>

        <?php if ($globalVehicleCourierRelation == "1") :  ?>
          <div>
            <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Keine&nbsp;graphische&nbsp;Dispo") ?>:</div>
            <div <?php echo getDivStyleFullCrvh() ?>>
              <input type="checkbox" name="f_crvh_vhd_disabled[]" value="1" <?php echo ($f_crvh_vhd_disabled == "1" ? "checked" : ""); ?> tabindex="1">
            </div>
          </div>
          <?php // echo htmlDivLineSpacer("5px"); ?>
        <?php endif; ?>

        <?php // echo htmlDivLineSpacer("20px"); ?>

        <?php if (true) : ?>
          <div>
            <div <?php echo setStyleHtmlDiv($col1,"left","30px",getDivStyleCrvh()); ?>><?php echo getLngt("Aktuelles Fahrzeug einem anderen Fahrerkollegen zuweisen") ?>:</div>
            <div <?php echo getDivStyleFullCrvh() ?>>
              <select <?php echo $htmlClass01 ?> name="f_cr_id_same_contractor" onChange="finishPage('select_new_driver');" tabindex="30">
                <?php echo $outputCouriersOfTheSameContractor; ?>
              </select>
            </div>
          </div>
        <?php endif; ?>

        <?php if ($outputService != "") : ?>
          <?php echo htmlDivLineSpacer("5px"); ?>
          <div>
            <div><?php echo getLngt("Services") ?>:</div>
            <?php echo htmlDivLineSpacer("5px"); ?>
            <div>
            	<?php echo $outputService ?>
            </div>
          </div>
        <?php endif; ?>

        <?php echo htmlDivLineSpacer("20px"); ?>
      </div>

      <!-- Filter -->
      <div style="float: left;">
        <?php echo $outputFilter ?>
      </div>

    <?php else : ?>

      <div <?php echo setStyleHtmlDiv("300px","left"); ?>>
        <div>
          <div <?php echo setStyleHtmlDiv($col1,"left"); ?>><?php echo getLngt("Auswahl:") ?></div>
          <div>
            <select <?php echo $htmlClass01 ?> name="f_crvh_id" onChange="finishPage('selectFromAll');" tabindex="30">
              <?php echo $courierVehicles; ?>
            </select>
          </div>
        </div>
        <?php echo htmlDivLineSpacer("30px"); ?>
      </div>

    <?php endif; ?>
  </div>
  
</form>
</div>
</body>

</html>
