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


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


getSecHttpVars("1",array("f_act", "statusMessage", "deactivateMenu", "numOfRows", "f_search", "initialPageCall", "f_suLoadStates", 
                         "f_su_chkbx", "f_su_atm_chkbx", "f_su_cb_chkbx_00", "f_su_cb_chkbx_01", "f_su_cb_chkbx_02", "f_su_cb_chkbx_03", "f_su_cb_chkbx_04", 
                         "f_su_orderByCol", "f_su_sort_sequence", "f_jb_orderByCol", "f_jb_sort_sequence", "f_log_orderByCol", "f_log_sort_sequence", "f_map_is_active",
                         "f_crvh_selection_00", "f_crvh_selection_01", "f_crvh_selection_02", "f_crvh_selection_03", "f_crvh_selection_04", 
                         "f_col_sel_00", "f_col_sel_01", "f_col_sel_02", "f_col_sel_03", "f_col_sel_04", "f_col_sel_05", "f_col_sel_06", "f_col_sel_07", 
                         "f_col_sel_08", "f_col_sel_09", "f_col_sel_10", "f_col_sel_11", "f_col_sel_12", "f_col_sel_13", "f_col_sel_14", "f_col_sel_15", 
                         "f_col_sel_16", "f_col_sel_17", "f_col_sel_18", "f_col_sel_19",
                         "f_pt_filter_01_01", "f_pt_filter_01_02", "f_pt_filter_01_03", 
                         "f_pt_filter_1", "f_jb_filter_1", "f_jb_filter_2", "f_jb_filter_3", "f_log_filter_1", 
                         "f_cb_admin_filter_1", "f_cb_admin_filter_2", "f_cb_admin_at_id", "f_cb_admin_ati_serialno", "f_cb_admin_stk_id",
                         "f_cdr_admin_filter_1", "f_cdr_admin_filter_2", "f_cdr_admin_at_id", "f_cdr_admin_ati_serialno_from", "f_cdr_admin_ati_serialno_to", 
                         "f_cdr_admin_stk_id", "f_cdr_admin_palette", "f_cdr_admin_ati_serialno_missing",
                         "f_su_admin_filter_1", "f_su_admin_at_id", "f_su_admin_ati_serialno", "f_su_admin_stk_id", "f_su_admin_stk_name", "f_su_admin_stk_barcode",
                         "f_su_admin_ati_data_01", "f_su_admin_ati_data_02", "f_su_admin_ati_data_03", 
                         "f_su_admin_ati_data_22", "f_su_admin_ati_data_23", "f_su_admin_ati_data_24", 
                         "f_su_admin_ati_data_28_00", "f_su_admin_ati_data_28_01", "f_su_admin_ati_data_28_02", "f_su_admin_ati_data_28_03", "f_su_admin_ati_data_28_04", 
                         "f_su_admin_ad_id", "f_su_admin_ad_street", "f_su_admin_stk_hsno", 
                         "f_su_admin_ad_zipcode", "f_su_admin_ad_city", "f_su_tour_no", "f_tour_crvh_assoc",
                         "f_su_admin_ati_data_21_1", "f_su_admin_ati_data_21_2", "f_su_admin_ati_data_21_3", "f_su_admin_ati_data_21_4", 
                         "f_su_admin_ati_data_21_5", "f_su_admin_ati_data_21_6", "f_su_admin_ati_data_21_7", 
                         "maskDisplay00Switch", "maskDisplay01Switch", "maskDisplay02Switch", "maskDisplay03Switch", "maskDisplay04Switch",
                         "maskDisplay05Switch", "maskDisplay06Switch", "maskDisplay07Switch", "maskDisplay08Switch", "maskDisplay09Switch",
                         "day_from_jb", "month_from_jb", "year_from_jb", "day_to_jb", "month_to_jb", "year_to_jb", 
                         "hour_from_jb", "minute_from_jb", "hour_to_jb", "minute_to_jb", "f_showDateAndTime_jb", 
                         "day_prediction", "month_prediction", "year_prediction",
                         "f_actionObjType", "f_actionObjId", "f_actionID"));

// Select user-type for mode of security check 
$userType = getFieldValueFromId("user","usr_id",$usr_id,"usr_type");
$userTypeName = getUserTypeName($userType);

// Check authentication verifying emmployee an his/her costcenter- and customer-association
if ( !( authCheckHQ($hq_id,$usr_id,$emp_id) || authCheck($hq_id,$usr_id,$emp_id,$cscIdRoot,$customerId,$cscIdActual) ) || $userTypeName == "" ) :
   die ("$PHP_SELF: Access denied!");
endif;

$deactivateMenuStatic = "1";

// General output mode
$maskClassicMode = false;  // Set to true for output without Ajax


getLanguage(__FILE__);

$pageTitel = getLngt("WARTUNGSAUFTRAGSPLANUNG");
if ($generatePDF != "1") :
   include_once ("../geo/geocode.inc.php");
endif;
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
include_once ("../include/inc_vehicle.inc.php");
include_once ("../include/inc_stock.inc.php");
include_once ("../include/inc_check_publicholiday.inc.php");
include_once ("../locating/xServer.inc.php");
include_once ("../illt/inc_serviceunit.inc.php");

getCurrentScript(__FILE__);

// Check kind of user agent
$isFirefox = true;
if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") === false) {
   $isFirefox = false;
}

// Check for mode of system usage
$globalParUseRelatedCustomer = getParameterValue("0", "GLOBAL_USE_RELATED_CUSTOMER", "0");


// Get customer regarding placement of jobs into FDS
$csId = getParameterValue("0", "FDS_CUSTOMER_DEFAULT", "0");
$adId = getParameterValue("0", "FDS_ADDRESS_DEFAULT", "0");


// SERVICE UNIT data fields
$dataSU = array();

// Init array for threshold values
$f_tv = array();

// Weight factor array for cashboxes
$cbWeightFactors = array(1500,100,1,1,1);

// Message array
$outReportArray = array();
$generateOutput = true;

// Global state array
$outGlobalStateArray = array();

// Hours per day
// $hours = getParameterValue("0", "DISPOSITION_HOURS", $hq_id);
// if ($hours == "" || !is_numeric($hours)) :
   $hours = getParameterValue("0", "DISPOSITION_HOURS", "0");
   if ($hours == "" || !is_numeric($hours)) :
      $hours = 23;
   endif;
// endif;

// Time units of a hour (e.g. 12 units per 5 minutes <=> 6 units per 10 minutes <=> one hour)
// $hourTimeUnits = getParameterValue("0", "DISPOSITION_HOUR_TIME_UNITS", $hq_id);
// if ($hourTimeUnits == "" || !is_numeric($hourTimeUnits)) :
   $hourTimeUnits = getParameterValue("0", "DISPOSITION_HOUR_TIME_UNITS", "0");
   if ($hourTimeUnits == "" || !is_numeric($hourTimeUnits)) :
      $hourTimeUnits = 6;
   endif;
// endif;

// Get root stock where all service units belong to
$rootStockSU = getParameterValue("0", "SU_STK_ROOT", $hq_id);
if ($rootStockSU != "" && is_numeric($rootStockSU)) :

   // Get db-parameter for the number of lists (frames) to be displayed of the current employee
   // This is important for the call of job lists only !!!
   $empMaskMultiJoblist = getParameterValue($emp_id, "MASK_MULTI_JOBLIST");
   if ($empMaskMultiJoblist == "") :
      $empMaskMultiJoblist = "3";
   endif;
   
   // Get vector of all message codes being critical
   $criticalMessageArray = getColVectorFromDB2ArrayByClause("phoenix.articlemessage", "atm_code", "atm_critical = '1'", "", "atm_code", "1");

   // Get vector of all message being displayed (containing critical !!!!)
   $tmpMessageArray = getColVectorFromDB2ArrayByClause("phoenix.articlemessage", "CONCAT(at_id2,'_',atm_code) AS atm_key", "atm_critical != '0'", "", "atm_key", "1");
   $tmpMessageArrayLen = count($tmpMessageArray);
   $displayMessageArray = array();
   for ($j = 0; $j < $tmpMessageArrayLen; $j++) :
       $tmpAtmArr = explode("_", $tmpMessageArray[$j]);  // "<at_id>_<atm_code>" => 
       $atmAtId2 = $tmpAtmArr[0];
       $atmAtCode = $tmpAtmArr[1];
       $atmAtMatch = getFieldValueFromId("phoenix.article", "at_id", $atmAtId2, "at_match");
       $displayMessageArray[] = array($atmAtId2, $atmAtCode, $atmAtMatch);
   endfor;
   $displayMessageArrayLen = count($displayMessageArray);

   $maxNumOfTours = getParameterValue("0", "MAX_NUM_OF_SU_TOURS", $hq_id);
   if ($maxNumOfTours == "" || !is_numeric($maxNumOfTours)) :
      $maxNumOfTours = "4";
   endif;
   
   // Number of data fields in "articleitem" (ati_data_01, ati_data_02, ...)
   $maxNumOfAtiDataFields = getParameterValue("0", "MAX_NUM_OF_ATI_DATA_FIELDS", $hq_id);
   if ($maxNumOfAtiDataFields == "" || !is_numeric($maxNumOfAtiDataFields)) :
      $maxNumOfAtiDataFields = "30";
   endif;

   // Max. length of the card roll serial numbers
   $maxLenOfCdrSrNo = getParameterValue("0", "MAX_LEN_OF_CDR_SERIAL_NO", $hq_id);
   if ($maxLenOfCdrSrNo == "" || !is_numeric($maxLenOfCdrSrNo)) :
      $maxLenOfCdrSrNo = "6";
   endif;

   // Get vehicles to map... (e.g. 1 <=> HHA101, 2 <=> HHA102, 3 <=> HHA103)
   $mappedCourierArray = array();    // => Example: $mappedCourierArray <=> array("0" => "", "1" => "9322", "2" => "9323", "3" => "9324", ....);
   $mappedCourierArray[0] = "";  // Init because vehicle #0 does not exist in tour planning but #1, #2, #3, etc. do
   $crCrvhArray = getColVectorFromDB2ArrayByClause("phoenix.couriervehicle AS crvh, phoenix.courier AS cr", "crvh.crvh_sid", "crvh.cr_id = cr.cr_id", "cr.cr_id", "", "");
   $crIdArray = array_keys($crCrvhArray);
   $crIdArrayLen = count($crIdArray);
   for ($j = 0; $j < $crIdArrayLen; $j++) :
       $currentSid = $crCrvhArray[$crIdArray[$j]];
       $currentSidSuffixNum = intval(substr($currentSid, -2));
       $mappedCourierArray[$currentSidSuffixNum] = $crIdArray[$j];   // E.g. $mappedCourierArray[3] = $crIdArray[$j];
   endfor;
   $mappedCourierArrayLen = count($mappedCourierArray);

   // Get GROUP numbers for items
   // Ticket machine (here "service unit" ("su"))
   $suGroupId = getParameterValue("0", "SU_TICKET_MACHINE_GROUP_ID", $hq_id);
   if ($suGroupId == "") : $suGroupId = "1"; endif;
   // "Cash box" ("cb")
   $cbGroupId = getParameterValue("0", "SU_CASH_BOX_GROUP_ID", $hq_id);
   if ($cbGroupId == "") : $cbGroupId = "2"; endif;

   // Get vector of article(type) IDs ("at_id") of service units
   // $suAtIdArray = getColVectorFromDB2ArrayByClause("phoenix.article", "at_id", "at_group = '," . $suGroupId . ",'", "", "at_id");
   $suAtIdString = getParameterValue("0", "SU_AT_TYPES_FOR_TV", $hq_id);
   $suAtIdArray = explode(",", $suAtIdString);
   $suAtIdArrayLen = count($suAtIdArray);
  
   // Get new threshold values by frontend
   for ($a = 0; $a < $suAtIdArrayLen; $a++) :
       $atId = $suAtIdArray[$a];
       for ($t = 0; $t < $maxNumOfAtiDataFields; $t++) :
           getSecHttpVars("1",array("f_tv_" . $atId . "_" . pad(($t + 1),2)));
           $f_tv[$atId][($t + 1)] = ${("f_tv_" . $atId . "_" . pad(($t + 1),2))};
       endfor;
   endfor;

   // There could be defined a special stock being parent stock for all service unit (article item) stocks.
   // Otherwise every service unit will be associated to a special root stock (!!!!)
   $suStockIdParentDefault = getParameterValue("0", "SERVICEUNIT_STOCK_PARENT_ID", $hq_id);
   if ($suStockIdParentDefault == "" || !is_numeric($suStockIdParentDefault)) :
      $suStockIdParentDefault = getParameterValue("0", "SERVICEUNIT_STOCK_PARENT_ID", "0");
      if ($suStockIdParentDefault == "" || !is_numeric($suStockIdParentDefault)) :
         $suStockIdParentDefault = "0";
      endif;
   endif;
   // There could be defined a special stock being parent stock for all service unit (article item) stocks.
   // Otherwise every service unit will be associated to a special root stock (!!!!)
   $cbStockIdParentDefault = getParameterValue("0", "CASHBOX_STOCK_PARENT_ID", $hq_id);
   if ($cbStockIdParentDefault == "" || !is_numeric($cbStockIdParentDefault)) :
      $cbStockIdParentDefault = getParameterValue("0", "CASHBOX_STOCK_PARENT_ID", "0");
      if ($cbStockIdParentDefault == "" || !is_numeric($cbStockIdParentDefault)) :
         $cbStockIdParentDefault = "0";
      endif;
   endif;

   // Service time default value
   $suServiceAndWayTimeDefault = getParameterValue("0", "SERVICEUNIT_TIME_DEFAULT", $hq_id);
   if ($suServiceAndWayTimeDefault == "" || !is_numeric($suServiceAndWayTimeDefault)) :
      $suServiceAndWayTimeDefault = getParameterValue("0", "SERVICEUNIT_TIME_DEFAULT", "0");
      if ($suServiceAndWayTimeDefault == "" || !is_numeric($suServiceAndWayTimeDefault)) :
         $suServiceAndWayTimeDefault = 10;
      endif;
   endif;
   if ($f_su_admin_ati_data_24 == "") : 
      $f_su_admin_ati_data_24 = $suServiceAndWayTimeDefault;
   endif;

   // Check for activation of critical behaviour by default vehicle ONLY
   $suServiceIsCriticalByDefaultVehicleOnly = getParameterValue("0", "SERVICEUNIT_CRITICAL_BY_VEHICLE_ONLY", $hq_id);
   if ($suServiceIsCriticalByDefaultVehicleOnly == "") :
      $suServiceIsCriticalByDefaultVehicleOnly = getParameterValue("0", "SERVICEUNIT_CRITICAL_BY_VEHICLE_ONLY", "0");
   endif;

   // Check for activation of critical behaviour if state is semi critical AND default vehicle is set
   $suServiceIsCriticalByStateSemiCriticalAndDefaultVehicle = getParameterValue("0", "SERVICEUNIT_CRITICAL_ADDED_BY_VEHICLE", $hq_id);
   if ($suServiceIsCriticalByStateSemiCriticalAndDefaultVehicle == "") :
      $suServiceIsCriticalByStateSemiCriticalAndDefaultVehicle = getParameterValue("0", "SERVICEUNIT_CRITICAL_ADDED_BY_VEHICLE", "0");
   endif;

   // Disable sawtooth regarding activated prediction date for service units without current amount data
   $suSawtoothIsDisabled = getParameterValue("0", "SERVICEUNIT_SAWTOOTH_DISABLED", $hq_id);
   if ($suSawtoothIsDisabled == "") :
      $suSawtoothIsDisabled = getParameterValue("0", "SERVICEUNIT_SAWTOOTH_DISABLED", "0");
   endif;

   // Init association between vehicle and customer regarding "customervehicle"
   if ($f_tour_crvh_assoc == "") :
      $f_tour_crvh_assoc = array();
      for ($j = 0; $j <= $maxNumOfTours; $j++) :
          $f_tour_crvh_assoc[$j] = $j;
      endfor;
   else :
      $f_tour_crvh_assoc = explode(",", $f_tour_crvh_assoc);
      array_unshift($f_tour_crvh_assoc, "0");
   endif;

   $jsExecBodyOnLoadArray = array("0","0","0","0","0");   // If one component is set to "1" then execute a special JS function according to "body onLoad"
   $suRoutePlanningArray = array();
   for ($j = 0; $j <= $maxNumOfTours; $j++) :
       $suRoutePlanningArray[$j] = array();
   endfor;
   $suRouteOptimizedArray = array();
   $outEventStatesArray = array();
   $outJobArray = array();
   $outLogArray = array();
   $outMessageArray = array();
   
   $constLngOutputTourChars = getLngt("T");  // Constant because there will be a search in the database

   $colArray = array();
   $colArray["bg"] = $constBackground;
   $colArray["blue"]   = "#0000FF";
   $colArray["green"]  = "#00FF00";
   $colArray["red"]    = "#FF0000";
   $colArray["white"]  = "#FFFFFF";
   $colArray["yellow"] = "#FFFF00";
   $colArray["black"]  = "#000000";
   $colArray["gray"]   = "#DDDDDD";
   $colArray["gold"]   = "#969325";
   $colArray["beige"]  = "#EFE4B0";
   $colArray["light_red"]    = "#FF8888";
   $colArray["light_green"]  = "#88FF88";
   $colArray["light_blue"]   = "#8888FF";
   $colArray["light_yellow"] = "#FFFF88";
   $colArray["light_gray"]   = "#EEEEEE";
   
   // Initialize filter parameter, if only one type does exist.
   // Card roll types. 
   $cdrTypeArr = getColVectorFromDB2ArrayByClause("article", "at_id", "at_group LIKE '%,5,%'");
   if (count($cdrTypeArr) == 1) :
      if ($f_cdr_admin_at_id == "") : $f_cdr_admin_at_id = $cdrTypeArr[0]; endif;
      if ($f_cdr_admin_filter_2 == "") : $f_cdr_admin_filter_2 = $cdrTypeArr[0]; endif;
   endif;

   $atiColsTypesArray = array();   // Represents the fields ati_data_01, ati_data_02, ..., ati_data_xx only!
   $atiColsTypes = getParameterValue("0", "STK_ATI_COLUMN_TYPES", $hq_id);
   if ($atiColsTypes != "") :
      $atiColsTypesArray = spliti(",", $atiColsTypes);
   else :
      // Default
      $atiColsTypesArray = array("varchar","number","number","date","integer","float2","integer","float2","integer","","","","","","","","","","integer","integer");
   endif;

   // SERVICEJOBS: Check ranges of time. All fields have to be set
   if ($f_showDateAndTime_jb == "") : $f_showDateAndTime_jb = "0"; endif;  // Show the clock time fields [default "NO"]
   if ($f_showDateAndTime_jb == "0" || $hour_from_jb == "" || $minute_from_jb == "" || $hour_to_jb == "" || $minute_to_jb == "") :
       $hour_from_jb = "00";
       $minute_from_jb = "00";
       $hour_to_jb = "23";
       $minute_to_jb = "59";
       $f_showDateAndTime_jb == "0";
   endif;
   $hour_from_jb = pad($hour_from_jb,2);
   $minute_from_jb = pad($minute_from_jb,2);
   $hour_to_jb = pad($hour_to_jb,2);
   $minute_to_jb = pad($minute_to_jb,2);
   // Time range
   $fromTimeRange = " " . $hour_from_jb . ":" . $minute_from_jb . ":00";
   $toTimeRange = " " . $hour_to_jb . ":" . $minute_to_jb . ":59";
   // Check ranges of date. All fields have to be set
   if ($day_from_jb == "" || $month_from_jb == "" || $year_from_jb == "" || 
       $day_to_jb == "" || $month_to_jb == "" || $year_to_jb == "") :
       // Initialize date-ranges to the current date
       $fromDateRange_jb = getDateTime("3") . $fromTimeRange;
       $toDateRange_jb = getDateTime("3") . $toTimeRange;
       $day_from_jb = getDateTime("day");
       $month_from_jb = getDateTime("month");
       $year_from_jb = getDateTime("year");
       $day_to_jb = getDateTime("day");
       $month_to_jb = getDateTime("month");
       $year_to_jb = getDateTime("year");
   else :
       $fromDateRange_jb = $year_from_jb . "-" . pad($month_from_jb,2) . "-" . pad($day_from_jb,2) . $fromTimeRange;
       $toDateRange_jb = $year_to_jb . "-" . pad($month_to_jb,2) . "-" . pad($day_to_jb,2) . $toTimeRange;
   endif;

   // Init prediction date
   if ($day_prediction == "" || $month_prediction == "" || $year_prediction == "") :
      $day_prediction = getDateTime("day");
      $month_prediction = getDateTime("month");
      $year_prediction = getDateTime("year");
   endif;
   $predictionDate = $year_prediction . "-" . $month_prediction . "-" . $day_prediction;
   $currentDate = getDateTime("3");
   $predictionDays = 0;
   if ($predictionDate > $currentDate) :
      $predictionDays = mcDateDiff($currentDate, $predictionDate);
      if ($predictionDays < 0) :
         $predictionDays = 0;
      endif;
      $outReportArray[] = getLngt("Das eingestellte Datum liegt in der Zukunft!");
   else :
      $day_prediction = getDateTime("day");
      $month_prediction = getDateTime("month");
      $year_prediction = getDateTime("year");
   endif;

   // Public holidays of the next days
   $phToDate = date('Y-m-d', strtotime($predictionDate . ' + 7 days'));
   $phWhereClause = "CONCAT(ph_year,'-',LPAD(ph_month,2,'0'),'-',LPAD(ph_day,2,'0')) > '" . $predictionDate . "' AND "
                  . "CONCAT(ph_year,'-',LPAD(ph_month,2,'0'),'-',LPAD(ph_day,2,'0')) <= '" . $phToDate . "'";
   $publicHolidaysArray = getPublicHolidays(getDateTime(substr($predictionDate,0,4)), "", "", $phWhereClause);
   $phDateArray = convertPublicHolidayArrayToDateArray($publicHolidaysArray);

   // Check map button being displayed after at least one optimization
   if ($f_map_is_active == "") : $f_map_is_active = "1"; endif;

   $f_search = trim($f_search);

   $numOfRowsSU = 0;
   $numOfRowsJB = 0;
   $numOfRowsLOG = 0;

   // Selected service units (checkboxes)
   if ($f_su_chkbx == "") : $f_su_chkbx = array(); endif;
   $f_su_chkbx_len = count($f_su_chkbx);
   // Selected tour
   if ($f_su_tour_no == "") : $f_su_tour_no = array(); endif;
   $f_su_tour_no_len = count($f_su_tour_no);

   // State array for (critical) messages
   if ($f_su_atm_chkbx == "") : $f_su_atm_chkbx = array(); endif;
   $f_su_atm_chkbx_len = count($f_su_atm_chkbx);

   // State array for cash boxes being critical [CB1 : $f_su_cb_chkbx_nn[$row["ati_serialno"]]["0"] = "1", CB2 : $f_su_cb_chkbx_nn[$row["ati_serialno"]]["1"], ....]  
   // The length of all array are identical to $f_su_chkbx_len (!!!!)
   if ($f_su_cb_chkbx_00 == "") : $f_su_cb_chkbx_00 = array(); endif;
   if ($f_su_cb_chkbx_01 == "") : $f_su_cb_chkbx_01 = array(); endif;
   if ($f_su_cb_chkbx_02 == "") : $f_su_cb_chkbx_02 = array(); endif;
   if ($f_su_cb_chkbx_03 == "") : $f_su_cb_chkbx_03 = array(); endif;
   if ($f_su_cb_chkbx_04 == "") : $f_su_cb_chkbx_04 = array(); endif;

   // Sum of initial cash box values
   $tourSumArray = array();
   $tourWeightArray = array();
   $tourCountArray = array();
   for ($i = 0; $i <= $maxNumOfTours; $i++) :
       $tourSumArray[$i] = 0;
       $tourWeightArray[$i] = 0;
       $tourCountArray[$i] = 0;
   endfor;

   // Get global threshold values
   $thresholdValuesArray = getThresholdValues($suAtIdArray);

   // Check default threshold values with frontend values
   $tmpDisplayMsg = false;
   for ($a = 0; $a < $suAtIdArrayLen; $a++) :
       $atId = $suAtIdArray[$a];
       $tvDiffersFromDefault = false;
       for ($t = 0; $t < $maxNumOfAtiDataFields; $t++) :
           if ($f_tv[$atId][($t + 1)] != $thresholdValuesArray[$atId][$t]) :
              $tvDiffersFromDefault = true;
           endif;
       endfor;
       if ($tvDiffersFromDefault) :
          // Store new threshold values for the current "at_id" if requested AND at least one of them differs from current persistent state !!!!
          if ($f_act == "tv_store") :
             setThresholdValues($atId);
          endif;

          // At least one threshold value differs from the default value
          $tmpAtMatch = getFieldValueFromId("phoenix.article", "at_id", $atId, "at_match");
          $outReportArray[] = getLngt("Mindestens ein Schwellwert differiert von den gespeicherten Werten beim Automatentyp " . $tmpAtMatch . "!");
          $tmpDisplayMsg = true;
       endif;
   endfor;
   if ($tmpDisplayMsg) :
      $outReportArray[] = getLngt("[Die initialen Standardwerte können über den gleichnamigen Button geladen werden!");
      $outReportArray[] = getLngt("ACHTUNG: Sollen die Standardwerte dann wieder stetig bei initialem Seitenaufruf geladen werden,");
      $outReportArray[] = getLngt("dann geladene - nicht veränderbare - Standardkonfiguration nochmal speichern für zu ladende Startwerte!]");
   endif;

   // Displayed DIV container by default
   $maskDisplay00Switch = "0";  // Only generate output if there is at least one system message
   if ($maskDisplay01Switch == "") : $maskDisplay01Switch = "0"; endif;
   if ($maskDisplay02Switch == "") : $maskDisplay02Switch = "1"; endif;
   if ($maskDisplay03Switch == "") : $maskDisplay03Switch = "0"; endif;
   if ($maskDisplay04Switch == "") : $maskDisplay04Switch = "0"; endif;
   if ($maskDisplay05Switch == "") : $maskDisplay05Switch = "0"; endif;
   if ($maskDisplay06Switch == "") : $maskDisplay06Switch = "0"; endif;
   if ($maskDisplay07Switch == "") : $maskDisplay07Switch = "1"; endif;
   if ($maskDisplay08Switch == "") : $maskDisplay08Switch = "1"; endif;
   if ($maskDisplay09Switch == "") : $maskDisplay09Switch = "0"; endif;
   
   if ($f_suLoadStates == "") : $f_suLoadStates = "0"; endif;
   if ($initialPageCall == "") : $f_suLoadStates = "1"; endif;  // If page is called initially then set all checkboxes of critical items
   
   if ($f_pt_filter_1 == "") : $f_pt_filter_1 = "0"; endif;
   if ($f_jb_filter_1 == "") : $f_jb_filter_1 = "0"; endif;
   if ($f_jb_filter_2 == "") : $f_jb_filter_2 = ""; endif;
   if ($f_jb_filter_3 == "") : $f_jb_filter_3 = ""; endif;
   if ($f_log_filter_1 == "") : $f_log_filter_1 = "0"; endif;
   if ($f_su_admin_filter_1 == "") : $f_su_admin_filter_1 = ""; endif;
   if ($f_cb_admin_filter_1 == "") : $f_cb_admin_filter_1 = ""; endif;
   if ($f_cb_admin_filter_2 == "") : $f_cb_admin_filter_2 = ""; endif;
   if ($f_cdr_admin_filter_1 == "") : $f_cdr_admin_filter_1 = ""; endif;
   if ($f_cdr_admin_filter_2 == "") : $f_cdr_admin_filter_2 = ""; endif;
   if ($f_su_admin_stk_id == "") : $f_su_admin_stk_id = ""; endif;

   if ($f_pt_filter_01_01 == "") : $f_pt_filter_01_01 = "1"; endif;
   if ($f_pt_filter_01_02 == "") : $f_pt_filter_01_02 = "0"; endif;
   if ($f_pt_filter_01_03 == "") : $f_pt_filter_01_03 = "0"; endif;

   if ($f_crvh_selection_00 == "") : $f_crvh_selection_00 = "1"; endif;
   if ($f_crvh_selection_01 == "") : $f_crvh_selection_01 = "1"; endif;
   if ($f_crvh_selection_02 == "") : $f_crvh_selection_02 = "1"; endif;
   if ($f_crvh_selection_03 == "") : $f_crvh_selection_03 = "1"; endif;
   if ($f_crvh_selection_04 == "") : $f_crvh_selection_04 = "1"; endif;

   if ($f_col_sel_00 == "") : $f_col_sel_00 = "1"; endif;  // FA
   if ($f_col_sel_01 == "") : $f_col_sel_01 = "1"; endif;  // Standort
   if ($f_col_sel_02 == "") : $f_col_sel_02 = "1"; endif;  // Opt.
   if ($f_col_sel_03 == "") : $f_col_sel_03 = "1"; endif;  // Tour
   if ($f_col_sel_04 == "") : $f_col_sel_04 = "1"; endif;  // Sort.
   if ($f_col_sel_05 == "") : $f_col_sel_05 = "1"; endif;  // XXX
   if ($f_col_sel_06 == "") : $f_col_sel_06 = "1"; endif;  // PLZ
   if ($f_col_sel_07 == "") : $f_col_sel_07 = "0"; endif;  // Geog. Breite
   if ($f_col_sel_08 == "") : $f_col_sel_08 = "0"; endif;  // Geog. Länge
   if ($f_col_sel_09 == "") : $f_col_sel_09 = "1"; endif;  // BEK
   if ($f_col_sel_10 == "") : $f_col_sel_10 = "1"; endif;  // MEK
   if ($f_col_sel_11 == "") : $f_col_sel_11 = "1"; endif;  // H1
   if ($f_col_sel_12 == "") : $f_col_sel_12 = "1"; endif;  // H2
   if ($f_col_sel_13 == "") : $f_col_sel_13 = "1"; endif;  // Dispenser
   if ($f_col_sel_14 == "") : $f_col_sel_14 = "1"; endif;  // Messzeitpunkt
   if ($f_col_sel_15 == "") : $f_col_sel_15 = "1"; endif;  // Meldungen
   if ($f_col_sel_16 == "") : $f_col_sel_16 = "0"; endif;  // SW
   if ($f_col_sel_17 == "") : $f_col_sel_17 = "0"; endif;  // Status
   if ($f_col_sel_18 == "") : $f_col_sel_18 = "1"; endif;  // N(otiz)
   if ($f_col_sel_19 == "") : $f_col_sel_19 = "0"; endif;  // Schwellwert-Offset

else :
   $outReportArray[] = getLngt("Es wurden keine Serviceeinheiten aufgefunden!");
   $generateOutput = false;
endif;  // Check for $rootStockSU is defined



// *************
// * Functions *
// *************
// Initialisations
/*
if ($selYear == "") : $selYear = date("Y"); endif;
if ($selMonth == "") : $selMonth = date("m"); endif;
if ($selDay == "") : $selDay = date("d"); endif;
include_once ("../include/inc_calendar.inc.php");
*/
include_once ("../groupware/calendar.php");


// Check for $rootStockSU is defined
if ($generateOutput) :

   // *******************************************
   // * Store form data for a service unit item *
   // *******************************************
   if ($f_act == "storeDataServiceunit") :

      $f_su_admin_ati_serialno = trim($f_su_admin_ati_serialno);
      $f_su_admin_ati_data_01  = trim($f_su_admin_ati_data_01);
      $f_su_admin_ati_data_02  = trim($f_su_admin_ati_data_02);
      $f_su_admin_ati_data_03  = trim($f_su_admin_ati_data_03);
      $f_su_admin_ati_data_22  = trim($f_su_admin_ati_data_22);
      $f_su_admin_ati_data_23  = trim($f_su_admin_ati_data_23);
      $f_su_admin_ati_data_24  = trim($f_su_admin_ati_data_24);
      
      $f_su_admin_ati_data_28_00 = trim($f_su_admin_ati_data_28_00);
      $f_su_admin_ati_data_28_01 = trim($f_su_admin_ati_data_28_01);
      $f_su_admin_ati_data_28_02 = trim($f_su_admin_ati_data_28_02);
      $f_su_admin_ati_data_28_03 = trim($f_su_admin_ati_data_28_03);
      $f_su_admin_ati_data_28_04 = trim($f_su_admin_ati_data_28_04);
      if ($f_su_admin_ati_data_28_00 == "" || !(is_numeric($f_su_admin_ati_data_28_00))) : $f_su_admin_ati_data_28_00 = "0"; endif;
      if ($f_su_admin_ati_data_28_01 == "" || !(is_numeric($f_su_admin_ati_data_28_01))) : $f_su_admin_ati_data_28_01 = "0"; endif;
      if ($f_su_admin_ati_data_28_02 == "" || !(is_numeric($f_su_admin_ati_data_28_02))) : $f_su_admin_ati_data_28_02 = "0"; endif;
      if ($f_su_admin_ati_data_28_03 == "" || !(is_numeric($f_su_admin_ati_data_28_03))) : $f_su_admin_ati_data_28_03 = "0"; endif;
      if ($f_su_admin_ati_data_28_04 == "" || !(is_numeric($f_su_admin_ati_data_28_04))) : $f_su_admin_ati_data_28_04 = "0"; endif;
      $f_su_admin_ati_data_28 = $f_su_admin_ati_data_28_00 . "," . $f_su_admin_ati_data_28_01 . "," . $f_su_admin_ati_data_28_02 . "," . $f_su_admin_ati_data_28_03 . "," . $f_su_admin_ati_data_28_04;

      $currAtId = getFieldValueFromClause("phoenix.articleitem", "at_id", "ati_serialno = '" . $f_su_admin_ati_serialno . "'");
      $currStkId = getFieldValueFromClause("phoenix.articleitem", "stk_id", "ati_serialno = '" . $f_su_admin_ati_serialno . "'");

      // Offset check
      $currAtiData28 = getFieldValueFromClause("phoenix.articleitem", "ati_data_28", "ati_serialno = '" . $f_su_admin_ati_serialno . "'");
      $suCheckedByNewOffset = false;

      $currentTime = getDateTime("0");
      if ($f_su_admin_at_id != "" && is_numeric($f_su_admin_at_id)) :
         if ($f_su_admin_stk_id != "" && is_numeric($f_su_admin_stk_id)) :
            $doModifyStockarticle = false;

            // Vector of predefined vehicles of days of the week
            $f_su_admin_ati_data_21 = $f_su_admin_ati_data_21_1 . "," . $f_su_admin_ati_data_21_2 . "," . $f_su_admin_ati_data_21_3 . "," . $f_su_admin_ati_data_21_4 . ","
                                    . $f_su_admin_ati_data_21_5 . "," . $f_su_admin_ati_data_21_6 . "," . $f_su_admin_ati_data_21_7;

            // There could be defined a special stock being parent stock for all service unit (article item) stocks.
            // Otherwise every service unit will be associated to a special root stock (!!!!)
            /*
            $suStockIdParent = getParameterValue("0", "SERVICEUNIT_STOCK_PARENT_ID", $hq_id);
            if ($suStockIdParent == "" || !is_numeric($suStockIdParent)) :
               $suStockIdParent = getParameterValue("0", "SERVICEUNIT_STOCK_PARENT_ID", "0");
               if ($suStockIdParent == "" || !is_numeric($suStockIdParent)) :
                  $suStockIdParent = "0";
               endif;
            endif;
            */
            $suStockIdParent = $suStockIdParentDefault;

            // Check for selection of a service unit item
            if ($f_su_admin_filter_1 == "") :
               // * INSERT *
               if (!existsEntry("phoenix.articleitem",array("ati_serialno",$f_su_admin_ati_serialno))) :
                  $atiLastInsertId = dbInsert("phoenix.articleitem", array("at_id", $f_su_admin_at_id, "stk_id", $f_su_admin_stk_id, "ati_serialno", $f_su_admin_ati_serialno, "ati_data_01", $f_su_admin_ati_data_01, "ati_data_02", $f_su_admin_ati_data_02, "ati_data_03", $f_su_admin_ati_data_03, "ati_data_04", $currentTime, "ati_data_21", $f_su_admin_ati_data_21, "ati_data_22", $f_su_admin_ati_data_22, "ati_data_23", $f_su_admin_ati_data_23, "ati_data_24", $f_su_admin_ati_data_24, "ati_data_28", $f_su_admin_ati_data_28));
                  if ($atiLastInsertId != "" && is_numeric($atiLastInsertId) && $atiLastInsertId > 0) :
                     $outReportArray[] = getLngt("Die neuen Automatendaten wurden angelegt!");
                     $doModifyStockarticle = true;                     

                     // Item is a service unit. Insert stock associated to this item if does not exist
                     $opVal = objectInsertStock("ati", $atiLastInsertId, $suStockIdParent, "SYSTEM-SERVICEUNIT", getLngt("FA") . $f_su_admin_ati_serialno, $dbConnection);
                     if ($opVal == "-1") :
                        $outReportArray[] = getLngt("Es wurde kein spezielles Objekt bzw. dessen Typ spezifiziert!");
                     elseif ($opVal == "-2") :
                        $outReportArray[] = getLngt("ACHTUNG! Es existiert kein notwendiges Hauptlager! Bitte den Administrator kontaktieren!");
                     elseif ($opVal == "-3") :
                        $outReportArray[] = getLngt("ACHTUNG! Die Anlage des Lagerortes konnte nicht durchgeführt werden! Bitte wiederholen bzw. den Administrator kontaktieren!");
                     endif;

                     // New offset data are stored, check for displayed checkboxes to be changed
                     if ($f_su_admin_ati_data_28 != $currAtiData28) :
                        $suCheckedByNewOffset = true;
                     endif;
                  else :
                     $outReportArray[] = getLngt("ACHTUNG! Die Anlage des Automats hat nicht geklappt! Bitte wiederholen bzw. den Administrator kontaktieren!");
                  endif;
               else :
                  $outReportArray[] = getLngt("Dieser Automat existiert schon! Schauen Sie bitte in der Auswahl nach!");
               endif;
            else :
               // * UPDATE *
               // Get articleitem ID
               $atiId = getFieldValueFromId("phoenix.articleitem","ati_serialno",$f_su_admin_ati_serialno,"ati_id");
               if ($atiId != "" && is_numeric($atiId) && $atiId > 0) :
                  updateStmt("phoenix.articleitem", "ati_id", $atiId, array("at_id", $f_su_admin_at_id, "stk_id", $f_su_admin_stk_id, "ati_data_01", $f_su_admin_ati_data_01, "ati_data_02", $f_su_admin_ati_data_02, "ati_data_03", $f_su_admin_ati_data_03, "ati_data_04", $currentTime, "ati_data_21", $f_su_admin_ati_data_21, "ati_data_22", $f_su_admin_ati_data_22, "ati_data_23", $f_su_admin_ati_data_23, "ati_data_24", $f_su_admin_ati_data_24, "ati_data_28", $f_su_admin_ati_data_28), "");
                  $doModifyStockarticle = true;

                  // Item is a service unit. Insert stock associated to this item if does not exist
                  $opVal = objectInsertStock("ati", $atiId, $suStockIdParent, "SYSTEM-SERVICEUNIT", getLngt("FA") . $f_su_admin_ati_serialno, $dbConnection);
                  if ($opVal == "-1") :
                     $outReportArray[] = getLngt("Es wurde kein spezielles Objekt bzw. dessen Typ spezifiziert!");
                  elseif ($opVal == "-2") :
                     $outReportArray[] = getLngt("ACHTUNG! Es existiert kein notwendiges Hauptlager! Bitte den Administrator kontaktieren!");
                  elseif ($opVal == "-3") :
                     $outReportArray[] = getLngt("ACHTUNG! Die Anlage des Lagerortes konnte nicht durchgeführt werden! Bitte wiederholen bzw. den Administrator kontaktieren!");
                  endif;

                  // Check for updating stockarticle. Do NOT update the quantities if article item will NEITHER be changed by the article id NOR the stock id!
                  if ($currStkId == $f_su_admin_stk_id && $currAtId == $f_su_admin_at_id) :
                     $doModifyStockarticle = false;
                  endif;
                  $outReportArray[] = getLngt("Die Automatendaten wurden aktualisiert!");

                  // New offset data are stored, check for displayed checkboxes to be changed
                  if ($f_su_admin_ati_data_28 != $currAtiData28) :
                     $suCheckedByNewOffset = true;
                  endif;
               else :
                  $outReportArray[] = getLngt("Die Automatendaten wurden NICHT aktualisiert, da der Automat nicht mehr existiert!");
               endif;
            endif;

            if ($doModifyStockarticle) :
               // *** Update stock quantity from source stock ***
               if ($currStkId > "0") :
                  // Get current item quantity of the specified article and source stock
                  $stkatItemQuantity = getFieldValueFromClause("stockarticle", "stkat_itemquantity", "stk_id = '" . $currStkId . "' AND at_id = '" . $currAtId . "'");
                  if ($stkatItemQuantity > 0) :
                     $stkatItemQuantity = $stkatItemQuantity - 1;
                     if ($stkatItemQuantity > 0) :
                        updateStmt("phoenix.stockarticle","stk_id",$currStkId,array("stkat_quantity",$stkatItemQuantity,"stkat_itemquantity",$stkatItemQuantity),"at_id = '".$currAtId."'");
                     else :
                        deleteStmt("phoenix.stockarticle"," stk_id = '".$currStkId."' AND at_id = '".$currAtId."' ");
                     endif;
                  endif;
               endif;

               // *** Update stock quantity from target stock ***
               if ($f_su_admin_stk_id > "0") :
                  // Get current item quantity of the specified article and target stock
                  $stkatItemQuantity = getFieldValueFromClause("stockarticle", "stkat_itemquantity", "stk_id = '" . $f_su_admin_stk_id . "' AND at_id = '" . $f_su_admin_at_id . "'");
                  if ($stkatItemQuantity != "") : 
                     $stkatItemQuantity = $stkatItemQuantity + 1;
                  endif;
                  if (existsEntry("phoenix.stockarticle",array("stk_id",$f_su_admin_stk_id,"at_id",$f_su_admin_at_id))) :
                     updateStmt("phoenix.stockarticle","stk_id",$f_su_admin_stk_id,array("stkat_quantity",$stkatItemQuantity,"stkat_itemquantity",$stkatItemQuantity),"at_id = '".$f_su_admin_at_id."'");
                  else :
                     insertStmt("phoenix.stockarticle",array("stk_id",$f_su_admin_stk_id,"at_id",$f_su_admin_at_id,"stkat_quantity","1","stkat_itemquantity","1"));
                  endif;
               endif;
            endif;

            if ($suCheckedByNewOffset) :
               $singleUnitCriticalState = false;  // For setting optimization checkbox if at least one cashbox is critical with included threshold offset
               $singleUnitCriticalArray = getCBsToBeChangedByCriticalState($f_su_admin_ati_serialno, "1");

               // $f_su_cb_chkbx_00
               if ($singleUnitCriticalArray[0] == 1) : 
                  if (!in_array($f_su_admin_ati_serialno, $f_su_cb_chkbx_00)) :
                     array_push($f_su_cb_chkbx_00, $f_su_admin_ati_serialno);
                     $singleUnitCriticalState = true;
                  endif;
               else :
                  if (in_array($f_su_admin_ati_serialno, $f_su_cb_chkbx_00)) :
                     $tmpKey = array_search($f_su_admin_ati_serialno, $f_su_cb_chkbx_00);
                     unset($f_su_cb_chkbx_00[$tmpKey]);
                  endif;
               endif;
               // $f_su_cb_chkbx_01
               if ($singleUnitCriticalArray[1] == 1) : 
                  if (!in_array($f_su_admin_ati_serialno, $f_su_cb_chkbx_01)) :
                     array_push($f_su_cb_chkbx_01, $f_su_admin_ati_serialno);
                     $singleUnitCriticalState = true;
                  endif;
               else :
                  if (in_array($f_su_admin_ati_serialno, $f_su_cb_chkbx_01)) :
                     $tmpKey = array_search($f_su_admin_ati_serialno, $f_su_cb_chkbx_01);
                     unset($f_su_cb_chkbx_01[$tmpKey]);
                  endif;
               endif;
               // $f_su_cb_chkbx_02
               if ($singleUnitCriticalArray[2] == 1) : 
                  if (!in_array($f_su_admin_ati_serialno, $f_su_cb_chkbx_02)) :
                     array_push($f_su_cb_chkbx_02, $f_su_admin_ati_serialno);
                     $singleUnitCriticalState = true;
                  endif;
               else :
                  if (in_array($f_su_admin_ati_serialno, $f_su_cb_chkbx_02)) :
                     $tmpKey = array_search($f_su_admin_ati_serialno, $f_su_cb_chkbx_02);
                     unset($f_su_cb_chkbx_02[$tmpKey]);
                  endif;
               endif;
               // $f_su_cb_chkbx_03
               if ($singleUnitCriticalArray[3] == 1) : 
                  if (!in_array($f_su_admin_ati_serialno, $f_su_cb_chkbx_03)) :
                     array_push($f_su_cb_chkbx_03, $f_su_admin_ati_serialno);
                     $singleUnitCriticalState = true;
                  endif;
               else :
                  if (in_array($f_su_admin_ati_serialno, $f_su_cb_chkbx_03)) :
                     $tmpKey = array_search($f_su_admin_ati_serialno, $f_su_cb_chkbx_03);
                     unset($f_su_cb_chkbx_03[$tmpKey]);
                  endif;
               endif;
               // $f_su_cb_chkbx_04
               if ($singleUnitCriticalArray[4] == 1) : 
                  if (!in_array($f_su_admin_ati_serialno, $f_su_cb_chkbx_04)) :
                     array_push($f_su_cb_chkbx_04, $f_su_admin_ati_serialno);
                     $singleUnitCriticalState = true;
                  endif;
               else :
                  if (in_array($f_su_admin_ati_serialno, $f_su_cb_chkbx_04)) :
                     $tmpKey = array_search($f_su_admin_ati_serialno, $f_su_cb_chkbx_04);
                     unset($f_su_cb_chkbx_04[$tmpKey]);
                  endif;
               endif;

               // $f_su_chkbx [optimization checkbox]
               if ($singleUnitCriticalState) : 
                  if (!in_array($f_su_admin_ati_serialno, $f_su_chkbx)) :
                     array_push($f_su_chkbx, $f_su_admin_ati_serialno);   
                  endif;
               else :
                  if (in_array($f_su_admin_ati_serialno, $f_su_chkbx)) :
                     $tmpKey = array_search($f_su_admin_ati_serialno, $f_su_chkbx);
                     unset($f_su_chkbx[$tmpKey]);
                  endif;
               endif;
            endif;
         else :
            $outReportArray[] = getLngt("Es wurde bei der Erfassung kein Standort zugewiesen!");
         endif;
      else :
         $outReportArray[] = getLngt("Es wurde bei der Erfassung kein Automatentypen selektiert!");
      endif;
   endif;


   // ***************************************
   // * Remove data for a service unit item *
   // ***************************************
   if ($f_act == "removeDataServiceunit") :

      $f_su_admin_ati_serialno = trim($f_su_admin_ati_serialno);

      $currAtiId = getFieldValueFromClause("phoenix.articleitem", "ati_id", "ati_serialno = '" . $f_su_admin_ati_serialno . "'");
      $currAtId = getFieldValueFromClause("phoenix.articleitem", "at_id", "ati_serialno = '" . $f_su_admin_ati_serialno . "'");
      $currStkId = getFieldValueFromClause("phoenix.articleitem", "stk_id", "ati_serialno = '" . $f_su_admin_ati_serialno . "'");

      if ($currAtiId != "") :

         // Remove existing stocks for service unit
         $doRemoveSU = true;
         $stkRemoveArray = getColVectorFromDB2ArrayByClause("phoenix.stock", "stk_id", "stk_obj_type = 'ati' AND stk_obj_id = '" . $currAtiId . "'", "", "", "", $dbConnection);
         $stkRemoveArrayLen = count($stkRemoveArray);
         for ($i = 0; $i < $stkRemoveArrayLen; $i++) :
             // Get children
             $suStkChildren = getStockChildren($stkRemoveArray[$i], "1");
             $suStkChildrenKeys = array_keys($suStkChildren);
             $suStkChildrenKeysLen = count($suStkChildrenKeys);

             for ($j = 0; $j < $suStkChildrenKeysLen; $j++) :
                 if (checkStockExistingStockarticle($suStkChildrenKeys[$j], $dbConnection)) :
                    $doRemoveSU = false;
                    break 2;
                 endif;
             endfor;
         endfor;

         if ($doRemoveSU) :
            // Remove stores (they will be updated by renaming and setting to invisible !!!!)
            for ($i = 0; $i < $stkRemoveArrayLen; $i++) :
                deleteStock($stkRemoveArray[$i], $dbConnection);
            endfor;

            // Remove item physically
            deleteStmt("phoenix.articleitem"," ati_id = '" . $currAtiId . "'");

            // Modify "stockarticle" regarding "$currStkId"
            if ($currStkId > "0" && $currAtId > "0") :
               // Get current item quantity of the specified article and source stock
               $stkatItemQuantity = getFieldValueFromClause("stockarticle", "stkat_itemquantity", "stk_id = '" . $currStkId . "' AND at_id = '" . $currAtId . "'");

               if ($stkatItemQuantity > 0) :
                  $stkatItemQuantity = $stkatItemQuantity - 1;
                  if ($stkatItemQuantity > 0) :
                     updateStmt("phoenix.stockarticle","stk_id",$currStkId,array("stkat_quantity",$stkatItemQuantity,"stkat_itemquantity",$stkatItemQuantity),"at_id = '".$currAtId."'");
                  else :
                     deleteStmt("phoenix.stockarticle"," stk_id = '".$currStkId."' AND at_id = '".$currAtId."' ");
                  endif;
               endif;
            endif;

            $outReportArray[] = getLngt("Der Automat wurde gelöscht!");
         else :
            $outReportArray[] = getLngt("Mindestens ein assoziierter Lagerort zu dem Automat ist nicht leer! Eine Löschung darf in diesem Fall nicht erfolgen!");
         endif;
      else :
         $outReportArray[] = getLngt("Der zu löschende Automat wurde nicht gefunden!");
      endif;
   endif;


   // ***********************************************
   // * Store form data for stock (service station) *
   // ***********************************************
   if ($f_act == "storeDataStock") :

      $f_su_admin_stk_name = trim($f_su_admin_stk_name);
      $f_su_admin_stk_barcode = trim($f_su_admin_stk_barcode);
      $f_su_admin_ad_street = trim($f_su_admin_ad_street);
      $f_su_admin_ad_zipcode = trim($f_su_admin_ad_zipcode);
      $f_su_admin_ad_city = trim($f_su_admin_ad_city);
      $f_su_admin_stk_hsno = trim($f_su_admin_stk_hsno);
      if ($f_su_admin_stk_hsno == "") : $f_su_admin_stk_hsno = "."; endif;
      if ($f_su_admin_ad_country == "") : $f_su_admin_ad_country = "DE"; endif;

      // Check for empty entries in address-fields
      if ($f_su_admin_ad_street != "" && $f_su_admin_ad_zipcode != "" && $f_su_admin_ad_city != "" && $f_su_admin_ad_country != "") :
         // Check zipcode and city
         // $addressValidityArray = checkCityZipcode($f_su_admin_ad_zipcode, $f_su_admin_ad_city, $f_su_admin_ad_street);
         // if ($noValidationOfAddress || $addressValidityArray[0] >= 1) :
         if (true) :
            TA("B");
            if ($f_su_admin_stk_name != "") :
               // Check for existing entry in address (because of redundance)
               $tmpArray = insertAddress($f_su_admin_ad_street, $f_su_admin_ad_zipcode, $f_su_admin_ad_city, "", $f_su_admin_ad_country, true);
               $ad_id_new = $tmpArray[0];
               if ($ad_id_new != "" && is_numeric($ad_id_new) ) :
                  // Get current timestamp
                  $currentTime = getDateTime("0");      
                  // Check for selection of a service unit item
                  if ($f_su_admin_stk_id != "" && is_numeric($f_su_admin_stk_id)) :
                     // Check for existence of the stock name
                     $stkIdToCheck = getFieldValueFromId("stock","stk_name",$f_su_admin_stk_name,"stk_id");
                     if ($stkIdToCheck == "" || $f_su_admin_stk_id == $stkIdToCheck) :
                         // Check barcode information still existing
                         $stkBarcodeToCheck = getFieldValueFromClause("phoenix.stock", "stk_barcode", "stk_barcode = '" . $f_su_admin_stk_barcode . "' AND stk_id != '" . $f_su_admin_stk_id . "'");
                         if ($f_su_admin_stk_barcode != "" && $f_su_admin_stk_barcode == $stkBarcodeToCheck) :
                            // Generate info only
                            $outReportArray[] = getLngt("Nur zur Information: Die Standortinfo existiert schon!");
                         endif;
                         // * UPDATE *
                         updateStmt("phoenix.stock", "stk_id", $f_su_admin_stk_id, array("ad_id", $ad_id_new, "stk_name", $f_su_admin_stk_name, "stk_hsno", $f_su_admin_stk_hsno, "stk_barcode", $f_su_admin_stk_barcode), "");
                         $outReportArray[] = getLngt("Die Standortdaten wurden aktualisiert!");
                     else :
                         $outReportArray[] = getLngt("Die neue Standortbezeichnung existiert schon! vergeben Sie bitte einen anderen Namen!");
                     endif;
                  else :
                     if (!existsEntry("phoenix.stock",array("stk_name",$f_su_admin_stk_name))) :
                        // Get complete path of $rootStockSU. $rootStockSU can have a parent which can be a sub stock, too
                        $newStkPath = "//" . $rootStockSU . "//";
                        $tmpStkPath = getFieldValueFromId("stock", "stk_id", $rootStockSU, "stk_path");
                        if ($tmpStkPath != "") :
                           $newStkPath = substr($tmpStkPath,0,-2) . $newStkPath;
                        endif;
                        // * INSERT *
                        insertStmt("phoenix.stock", array("hq_id", $hq_id, "stk_name",$f_su_admin_stk_name, "stk_pre_id", $rootStockSU, "stk_path", $newStkPath, "ad_id", $ad_id_new,"stk_barcode",$f_su_admin_stk_barcode,"stk_modifytime", $currentTime, "stk_visible", "1"));
                        $outReportArray[] = getLngt("Der neue Standort wurde angelegt!");
                     else :
                        $outReportArray[] = getLngt("Dieser Standort existiert schon! Schauen Sie bitte in der Auswahl!");
                     endif;
                  endif;
               else :
                  $outReportArray[] = getLngt("Die Generierung der Adresse hat nicht funktioniert!");
               endif;
            else :
               $outReportArray[] = getLngt("Die Standortangabe ist leer!");
            endif;
            TA("C");    
            TA("E");
         else :
           $outReportArray[] = getLngt("Die Postleitzahl passt nicht zu dem angegebenen Ort!");
         endif;
      else :
         $outReportArray[] = getLngt("Bitte geben Sie die Addressdaten vollständig an!");
      endif;
   endif;


   // **********************************
   // * Store data for a cash box item *
   // **********************************
   if ($f_act == "storeDataCashBox") :

      $f_cb_admin_ati_serialno = trim($f_cb_admin_ati_serialno);
      $f_cb_admin_ati_data_01  = trim($f_cb_admin_ati_data_01);
      $f_cb_admin_ati_data_02  = trim($f_cb_admin_ati_data_02);

      $currAtId = getFieldValueFromClause("phoenix.articleitem", "at_id", "ati_serialno = '" . $f_cb_admin_ati_serialno . "'");
      $currStkId = getFieldValueFromClause("phoenix.articleitem", "stk_id", "ati_serialno = '" . $f_cb_admin_ati_serialno . "'");

      $currentTime = getDateTime("0");
      if ($f_cb_admin_at_id != "" && is_numeric($f_cb_admin_at_id)) :
         if ($f_cb_admin_stk_id != "" && is_numeric($f_cb_admin_stk_id)) :
            $doModifyStockarticle = false;

            // There could be defined a special stock being parent stock for all service unit (article item) stocks.
            // Otherwise every service unit will be associated to a special root stock (!!!!)
            /* 
            $cbStockIdParent = getParameterValue("0", "CASHBOX_STOCK_PARENT_ID", $hq_id);
            if ($cbStockIdParent == "" || !is_numeric($cbStockIdParent)) :
               $cbStockIdParent = getParameterValue("0", "CASHBOX_STOCK_PARENT_ID", "0");
               if ($cbStockIdParent == "" || !is_numeric($cbStockIdParent)) :
                  $cbStockIdParent = "0";
               endif;
            endif;
            */
            $cbStockIdParent = $cbStockIdParentDefault;

            // Check for selection of a service unit item
            if ($f_cb_admin_filter_1 == "") :
               // * INSERT *
               if (!existsEntry("phoenix.articleitem",array("ati_serialno",$f_cb_admin_ati_serialno))) :
                  $atiLastInsertId = dbInsert("phoenix.articleitem", array("at_id", $f_cb_admin_at_id, "stk_id", $f_cb_admin_stk_id, "ati_serialno", $f_cb_admin_ati_serialno, "ati_data_01", $f_cb_admin_ati_data_01, "ati_data_02", $f_cb_admin_ati_data_02, "ati_data_03", $f_cb_admin_ati_data_03, "ati_data_04", $currentTime));
                  if ($atiLastInsertId != "" && is_numeric($atiLastInsertId) && $atiLastInsertId > 0) :
                     $outReportArray[] = getLngt("Die neue Geldkassette wurde eingefügt!");
                     $doModifyStockarticle = true;                     

                     // Item is a service unit. Insert stock associated to this item if does not exist
                     $opVal = objectInsertStock("ati", $atiLastInsertId, $cbStockIdParent, "SYSTEM-CASHBOX", getLngt("GK") . $f_cb_admin_ati_serialno, $dbConnection);
                     if ($opVal == "-1") :
                        $outReportArray[] = getLngt("Es wurde kein spezielles Objekt bzw. dessen Typ spezifiziert!");
                     elseif ($opVal == "-2") :
                        $outReportArray[] = getLngt("ACHTUNG! Es existiert kein notwendiges Hauptlager! Bitte den Administrator kontaktieren!");
                     elseif ($opVal == "-3") :
                        $outReportArray[] = getLngt("ACHTUNG! Die Anlage des Lagerortes konnte nicht durchgeführt werden! Bitte wiederholen bzw. den Administrator kontaktieren!");
                     endif;
                  else :
                     $outReportArray[] = getLngt("ACHTUNG! Die Anlage des Automats hat nicht geklappt! Bitte wiederholen bzw. den Administrator kontaktieren!");
                  endif;
               else :
                  $outReportArray[] = getLngt("Diese Geldkassette existiert schon! Schauen Sie bitte in der Auswahl nach!");
               endif;
            else :
               // * UPDATE *
               // Get articleitem ID
               $atiId = getFieldValueFromId("phoenix.articleitem","ati_serialno",$f_cb_admin_ati_serialno,"ati_id");
               if ($atiId != "" && is_numeric($atiId) && $atiId > 0) :
                  updateStmt("phoenix.articleitem", "ati_id", $atiId, array("at_id", $f_cb_admin_at_id, "stk_id", $f_cb_admin_stk_id, "ati_data_01", $f_cb_admin_ati_data_01, "ati_data_02", $f_cb_admin_ati_data_02, "ati_data_03", $f_cb_admin_ati_data_03, "ati_data_04", $currentTime), "");
                  $doModifyStockarticle = true;

                  // Item is a service unit. Insert stock associated to this item if does not exist
                  $opVal = objectInsertStock("ati", $atiId, $cbStockIdParent, "SYSTEM-SERVICEUNIT", getLngt("FA") . $f_cb_admin_ati_serialno, $dbConnection);
                  if ($opVal == "-1") :
                     $outReportArray[] = getLngt("Es wurde kein spezielles Objekt bzw. dessen Typ spezifiziert!");
                  elseif ($opVal == "-2") :
                     $outReportArray[] = getLngt("ACHTUNG! Es existiert kein notwendiges Hauptlager! Bitte den Administrator kontaktieren!");
                  elseif ($opVal == "-3") :
                     $outReportArray[] = getLngt("ACHTUNG! Die Anlage des Lagerortes konnte nicht durchgeführt werden! Bitte wiederholen bzw. den Administrator kontaktieren!");
                  endif;
                  
                  // Check for updating stockarticle. Do NOT update the quantities if article item will NEITHER be changed by the article id NOR the stock id!
                  if ($currStkId == $f_cb_admin_stk_id && $currAtId == $f_cb_admin_at_id) :
                     $doModifyStockarticle = false;
                  endif;
                  $outReportArray[] = getLngt("Die Kassettendaten wurden aktualisiert!");
               else :
                  $outReportArray[] = getLngt("Die Kassettendaten wurden NICHT aktualisiert, da die Kassette nicht mehr existiert!");
               endif;
            endif;

            if ($doModifyStockarticle) :
               // *** Update stock quantity from source stock ***
               if ($currStkId > "0") :
                  // Get current item quantity of the specified article and source stock
                  $stkatItemQuantity = getFieldValueFromClause("stockarticle", "stkat_itemquantity", "stk_id = '" . $currStkId . "' AND at_id = '" . $currAtId . "'");

                  if ($stkatItemQuantity > 0) :
                     $stkatItemQuantity = $stkatItemQuantity - 1;
                     if ($stkatItemQuantity > 0) :
                        updateStmt("phoenix.stockarticle","stk_id",$currStkId,array("stkat_quantity",$stkatItemQuantity,"stkat_itemquantity",$stkatItemQuantity),"at_id = '".$currAtId."'");
                     else :
                        deleteStmt("phoenix.stockarticle"," stk_id = '".$currStkId."' AND at_id = '".$currAtId."' ");
                     endif;
                  endif;
               endif;

               // *** Update stock quantity from target stock ***
               if ($f_cb_admin_stk_id > "0") :
                  // Get current item quantity of the specified article and target stock
                  $stkatItemQuantity = getFieldValueFromClause("stockarticle", "stkat_itemquantity", "stk_id = '" . $f_cb_admin_stk_id . "' AND at_id = '" . $f_cb_admin_at_id . "'");
                  if ($stkatItemQuantity != "") : 
                     $stkatItemQuantity = $stkatItemQuantity + 1;
                  endif;
                  if (existsEntry("phoenix.stockarticle",array("stk_id",$f_cb_admin_stk_id,"at_id",$f_cb_admin_at_id))) :
                     updateStmt("phoenix.stockarticle","stk_id",$f_cb_admin_stk_id,array("stkat_quantity",$stkatItemQuantity,"stkat_itemquantity",$stkatItemQuantity),"at_id = '".$f_cb_admin_at_id."'");
                  else :
                     insertStmt("phoenix.stockarticle",array("stk_id",$f_cb_admin_stk_id,"at_id",$f_cb_admin_at_id,"stkat_quantity","1","stkat_itemquantity","1"));
                  endif;
               endif;
            endif;
         else :
            $outReportArray[] = getLngt("Es wurde bei der Erfassung kein Standort zugewiesen!");
         endif;
      else :
         $outReportArray[] = getLngt("Es wurde bei der Erfassung kein Automatentypen selektiert!");
      endif;
   endif;


   // ***************************************
   // * Remove data for a cash box item *
   // ***************************************
   if ($f_act == "removeDataCashBox") :

      $f_cb_admin_ati_serialno = trim($f_cb_admin_ati_serialno);

      $currAtiId = getFieldValueFromClause("phoenix.articleitem", "ati_id", "ati_serialno = '" . $f_cb_admin_ati_serialno . "'");
      $currAtId = getFieldValueFromClause("phoenix.articleitem", "at_id", "ati_serialno = '" . $f_cb_admin_ati_serialno . "'");
      $currStkId = getFieldValueFromClause("phoenix.articleitem", "stk_id", "ati_serialno = '" . $f_cb_admin_ati_serialno . "'");

      if ($currAtiId != "") :

         // Remove existing stocks for service unit
         $doRemoveCB = true;
         $stkRemoveArray = getColVectorFromDB2ArrayByClause("phoenix.stock", "stk_id", "stk_obj_type = 'ati' AND stk_obj_id = '" . $currAtiId . "'", "", "", "", $dbConnection);
         $stkRemoveArrayLen = count($stkRemoveArray);
         for ($i = 0; $i < $stkRemoveArrayLen; $i++) :
             // Get children
             $cbStkChildren = getStockChildren($stkRemoveArray[$i], "1");
             $cbStkChildrenKeys = array_keys($cbStkChildren);
             $cbStkChildrenKeysLen = count($cbStkChildrenKeys);

             for ($j = 0; $j < $cbStkChildrenKeysLen; $j++) :
                 if (checkStockExistingStockarticle($cbStkChildrenKeys[$j], $dbConnection)) :
                    $doRemoveCB = false;
                    break 2;
                 endif;
             endfor;
         endfor;

         if ($doRemoveCB) :
            // Remove stores (they will be updated by renaming and setting to invisible !!!!)
            for ($i = 0; $i < $stkRemoveArrayLen; $i++) :
                deleteStock($stkRemoveArray[$i], $dbConnection);
            endfor;

            // Remove item physically
            deleteStmt("phoenix.articleitem"," ati_id = '" . $currAtiId . "'");

            // Modify "stockarticle" regarding "$currStkId"
            if ($currStkId > "0" && $currAtId > "0") :
               // Get current item quantity of the specified article and source stock
               $stkatItemQuantity = getFieldValueFromClause("stockarticle", "stkat_itemquantity", "stk_id = '" . $currStkId . "' AND at_id = '" . $currAtId . "'");

               if ($stkatItemQuantity > 0) :
                  $stkatItemQuantity = $stkatItemQuantity - 1;
                  if ($stkatItemQuantity > 0) :
                     updateStmt("phoenix.stockarticle","stk_id",$currStkId,array("stkat_quantity",$stkatItemQuantity,"stkat_itemquantity",$stkatItemQuantity),"at_id = '".$currAtId."'");
                  else :
                     deleteStmt("phoenix.stockarticle"," stk_id = '".$currStkId."' AND at_id = '".$currAtId."' ");
                  endif;
               endif;
            endif;

            $outReportArray[] = getLngt("Die Geldkassette wurde gelöscht!");
         else :
            $outReportArray[] = getLngt("Mindestens ein assoziierter Lagerort zu der Geldkassette ist nicht leer! Eine Löschung darf in diesem Fall nicht erfolgen!");
         endif;
      else :
         $outReportArray[] = getLngt("Die zu löschende Geldkassette wurde nicht gefunden!");
      endif;
   endif;


   // **********************************
   // * Store data for a cash box item *
   // **********************************
   if ($f_act == "storeDataCardrolls") :

      $f_cdr_admin_ati_serialno_from = trim($f_cdr_admin_ati_serialno_from);
      $f_cdr_admin_ati_serialno_to = trim($f_cdr_admin_ati_serialno_to);

      if ($f_cdr_admin_ati_serialno_from != "" && is_numeric($f_cdr_admin_ati_serialno_from) && $f_cdr_admin_ati_serialno_to != "" && is_numeric($f_cdr_admin_ati_serialno_to) && $f_cdr_admin_ati_serialno_to >= $f_cdr_admin_ati_serialno_from) :

         if (($f_cdr_admin_ati_serialno_to - $f_cdr_admin_ati_serialno_from) <= 300) :

            if ($f_cdr_admin_palette != "" && is_numeric($f_cdr_admin_palette)) :

               $currentTime = getDateTime("0");
               if ($f_cdr_admin_at_id != "" && is_numeric($f_cdr_admin_at_id)) :

                  if ($f_cdr_admin_stk_id != "" && is_numeric($f_cdr_admin_stk_id)) :

                     // Missing serial numbers
                     $f_cdr_admin_ati_serialno_missing = trim($f_cdr_admin_ati_serialno_missing);
                     // $f_cdr_admin_ati_serialno_missing = preg_replace("/[^0-9]/", "," , $f_cdr_admin_ati_serialno_missing);
                     // $f_cdr_admin_ati_serialno_missing = preg_replace("/,+/", ";" , $f_cdr_admin_ati_serialno_missing);
                     $atiSerialnoMissingArray = explode(";", $f_cdr_admin_ati_serialno_missing);
                     $atiSerialnoMissingArrayLen = count($atiSerialnoMissingArray);
                     $countInsertesCardrolls = 0;
                     // if ($f_cdr_admin_filter_1 == "") :
                        // * INSERT *
                        for ($i = $f_cdr_admin_ati_serialno_from; $i <= $f_cdr_admin_ati_serialno_to; $i++) :
                           if ($atiSerialnoMissingArrayLen == 0 || !in_array($i, $atiSerialnoMissingArray)) :
                              if (!existsEntry("phoenix_log.articleitemhistory",array("atih_serialno", $i, "at_id", $f_cdr_admin_at_id))) :                           
                                 $atihLastInsertId = dbInsert("phoenix_log.articleitemhistory", array("at_id", $f_cdr_admin_at_id, "stk_id", $f_cdr_admin_stk_id, "atih_createtime", $currentTime, "atih_serialno", $i, "atih_data_01", $f_cdr_admin_palette, "atih_data_02", $f_cdr_admin_ati_data_02, "atih_data_03", $f_cdr_admin_ati_data_03, "atih_data_04", $currentTime));
                                 if ($atihLastInsertId != "" && is_numeric($atihLastInsertId) && $atihLastInsertId > 0) :
                                    $countInsertesCardrolls++;
                                    // $outReportArray[] = getLngt("Die folgende Kartenrolle wurde eingefügt!") . " [" . $i . "]";
                                 else :
                                    $outReportArray[] = getLngt("ACHTUNG! Die Anlage der folgenden Kartenrolle hat nicht geklappt! Bitte wiederholen bzw. den Administrator kontaktieren!") . " [" . $i . "]";
                                 endif;
                              else :
                                 $outReportArray[] = getLngt("Die folgende Kartenrolle existiert schon! Schauen Sie bitte in der Auswahl nach!") . " [" . $i . "]";
                              endif;
                           endif;
                        endfor;
                     // endif;
               
                     /*
                     if ($countInsertesCardrolls > 0) :
                        // *** Update stock quantity from source stock ***
                        if ($f_cdr_admin_stk_id > "0") :
                           // Get current item quantity of the specified article and source stock
                           $stkatItemQuantity = getFieldValueFromClause("stockarticle", "stkat_itemquantity", "stk_id = '" . $currStkId . "' AND at_id = '" . $currAtId . "'");
               
                           if ($stkatItemQuantity > 0) :
                              $stkatItemQuantity = $stkatItemQuantity - 1;
                              if ($stkatItemQuantity > 0) :
                                 updateStmt("phoenix.stockarticle","stk_id",$currStkId,array("stkat_quantity",$stkatItemQuantity,"stkat_itemquantity",$stkatItemQuantity),"at_id = '".$currAtId."'");
                              else :
                                 deleteStmt("phoenix.stockarticle"," stk_id = '".$currStkId."' AND at_id = '".$currAtId."' ");
                              endif;
                           endif;
                        endif;
               
                        // *** Update stock quantity from target stock ***
                        if ($f_cb_admin_stk_id > "0") :
                           // Get current item quantity of the specified article and target stock
                           $stkatItemQuantity = getFieldValueFromClause("stockarticle", "stkat_itemquantity", "stk_id = '" . $f_cb_admin_stk_id . "' AND at_id = '" . $f_cb_admin_at_id . "'");
                           if ($stkatItemQuantity != "") : 
                              $stkatItemQuantity = $stkatItemQuantity + 1;
                           endif;
                           if (existsEntry("phoenix.stockarticle",array("stk_id",$f_cb_admin_stk_id,"at_id",$f_cb_admin_at_id))) :
                              updateStmt("phoenix.stockarticle","stk_id",$f_cb_admin_stk_id,array("stkat_quantity",$stkatItemQuantity,"stkat_itemquantity",$stkatItemQuantity),"at_id = '".$f_cb_admin_at_id."'");
                           else :
                              insertStmt("phoenix.stockarticle",array("stk_id",$f_cb_admin_stk_id,"at_id",$f_cb_admin_at_id,"stkat_quantity","1","stkat_itemquantity","1"));
                           endif;
                        endif;
                     endif;
                     */
                  else :
                     $outReportArray[] = getLngt("Es wurde bei der Erfassung kein Standort selektiert!");
                  endif;
               else :
                  $outReportArray[] = getLngt("Es wurde bei der Erfassung kein Kartenrollentype selektiert!");
               endif;
            else :
               $outReportArray[] = getLngt("Die Gebindeangabe ist nicht numerisch!");
            endif;
         else :
            $outReportArray[] = getLngt("Die Maximalgröße von 300 wurde überschritten!");
         endif;
      endif;
   endif;


   // Set the global master array and get special array for geo-coordinates of the current selected service units (selected by checkboxes)
   // This has to be called after storing the form data (!!!)
   getPersistentStates("2");


   // ***************************************************
   // * Process specified action for a specified object *
   // ***************************************************
   // if ($f_act == "processAction") :
      if ($f_actionObjType != "" && $f_actionObjId != "" && $f_actionID != "") :
         if ($f_actionObjType = "ati_serialno") :
            if ($f_actionID == "101") :
               // Get position on map
               // ...
            elseif ($f_actionID == "102") :
               // Get log events
               // getLogData("log.logo_id = '1000' AND log.id_01 = '" . $f_actionObjId . "'");
               getSuHistoryData("0", "AND stk.stk_pre_id = '" . $rootStockSU . "' AND atih.atih_serialno = '" . $f_actionObjId . "'");
               if ($f_act == "processAction") :
                  $maskDisplay01Switch = "0";
                  $maskDisplay02Switch = "0";
                  $maskDisplay03Switch = "0";
                  $maskDisplay04Switch = "1";
                  $maskDisplay05Switch = "0";
                  $maskDisplay06Switch = "0";
                  $maskDisplay07Switch = "0";
                  $maskDisplay08Switch = "0";
                  $maskDisplay09Switch = "0";
               endif;
            elseif ($f_actionID == "103") :
               // Get service jobs
               $f_jb_filter_2 = $f_actionObjId;  // Set filter for service jobs regarding the serialnumber of the service unit
               // getServiceJoblist();           // Will be called later including this filter !!!
               if ($f_act == "processAction") :
                  $maskDisplay01Switch = "0";
                  $maskDisplay02Switch = "0";
                  $maskDisplay03Switch = "1";
                  $maskDisplay04Switch = "0";
                  $maskDisplay05Switch = "0";
                  $maskDisplay06Switch = "0";
                  $maskDisplay07Switch = "0";
                  $maskDisplay08Switch = "0";
                  $maskDisplay09Switch = "0";
               endif;
               resetActionParameters();
            elseif ($f_actionID == "104") :
               getSuMessageData($f_actionObjId);
               if ($f_act == "processAction") :
                  $maskDisplay01Switch = "0";
                  $maskDisplay02Switch = "0";
                  $maskDisplay03Switch = "0";
                  $maskDisplay04Switch = "0";
                  $maskDisplay05Switch = "1";
                  $maskDisplay06Switch = "0";
                  $maskDisplay07Switch = "0";
                  $maskDisplay08Switch = "0";
                  $maskDisplay09Switch = "0";
               endif;
            elseif ($f_actionID == "105") :
               // Set form fields for the administration
               $f_su_admin_filter_1 = $f_actionObjId;  // Set filter for administration of the service unit
               $jsExecBodyOnLoadArray[2] = "1";        // Set service unit form data according to $f_actionObjId
               if ($f_act == "processAction") :
                  $jsExecBodyOnLoadArray[0] = "1";   // Set form by "body onLoad"
                  $maskDisplay01Switch = "0";
                  $maskDisplay02Switch = "0";
                  $maskDisplay03Switch = "0";
                  $maskDisplay04Switch = "0";
                  $maskDisplay05Switch = "0";
                  $maskDisplay06Switch = "1";
                  $maskDisplay07Switch = "0";
                  $maskDisplay08Switch = "0";
                  $maskDisplay09Switch = "0";
               endif;
               resetActionParameters();
            endif;
         endif;
   // else :
   //   $outReportArray[] = getLngt("Die gewählte Aktion konnte nicht ausgeführt werden, da nicht alle Angaben gesetzt wurden!");
      endif;

   // $f_act = "";  // Init
   // endif;


   // *****************************************
   // * Save state of the selected checkboxes *
   // *****************************************
   if ($f_act == "savePT" || $f_act == "optimizePT") :

      // Remove existing persistent states
      // ONLY do this if ALL service units are displayed (!!!)
      // OTHERWISE it is NOT necessary because the delta
      if ($f_pt_filter_1 == "0") :
         $sqlStmt = "UPDATE phoenix.articleitem SET ati_data_20 = '0' WHERE stk_id IN (SELECT stk_id FROM stock WHERE stk_pre_id = '" . $rootStockSU . "')";
         $res = $db->query($sqlStmt);
         if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif;
      endif;
      // Update checked service unit checkboxes and cashbox checkboxes and article message checkboxes
      if ($f_su_chkbx_len > 0) :
         for ($i = 0; $i < $f_su_chkbx_len; $i++) :
             // Service unit (important vector for optimization)
             updateStmt("phoenix.articleitem", "ati_serialno", decodeSpecialChars($f_su_chkbx[$i]), array("ati_data_20", "1"));

             // All cashbox checkboxes of the specified service unit
             $tmpSuCbChkbxArr = array((in_array($f_su_chkbx[$i], $f_su_cb_chkbx_00) ? "1" : ""), (in_array($f_su_chkbx[$i], $f_su_cb_chkbx_01) ? "1" : ""), (in_array($f_su_chkbx[$i], $f_su_cb_chkbx_02) ? "1" : ""), (in_array($f_su_chkbx[$i], $f_su_cb_chkbx_03) ? "1" : ""), (in_array($f_su_chkbx[$i], $f_su_cb_chkbx_04) ? "1" : ""));
             updateStmt("phoenix.articleitem", "ati_serialno", decodeSpecialChars($f_su_chkbx[$i]), array("ati_data_27", implode(",", $tmpSuCbChkbxArr)));

             // Message checkboxes of the specified service unit
             $atiData29Val = "";
             if (in_array($f_su_chkbx[$i], $f_su_atm_chkbx)) :
                // updateStmt("phoenix.articleitem", "ati_serialno", $f_su_atm_chkbx[$i], array("ati_data_29", "1"));
                $atiData29Val = "1";
             endif;
             updateStmt("phoenix.articleitem", "ati_serialno", decodeSpecialChars($f_su_chkbx[$i]), array("ati_data_29", $atiData29Val));
         endfor;
      endif;
   endif;


   // **********************
   // * Optimize tour data *
   // **********************
   if ($f_act == "optimizePT") :

      $optimizationDisabled = getParameterValue("0", "OPTIMIZATION_DISABLED", $hq_id);
      if ($optimizationDisabled == "") : $optimizationDisabled = getParameterValue("0", "OPTIMIZATION_DISABLED", "0"); endif;
      if ($optimizationDisabled != "1") :         // Presently no restrictions regarding to the optimization !!!!!!!!!!!!

         // * Optimization process by server *

         $usedVehicleNumberArray = array();
         for ($j = 1; $j <= $maxNumOfTours; $j++) :
             if (count($suRoutePlanningArray[$j]) > 0) :
                $usedVehicleNumberArray[] = $j;   // E.g. ONE vehicle only, but it is the vehicle "3"
             endif;
         endfor;

         // Get potential coordinates of the start and/or end of all tours
         // Start coordinates
         $coordinatesStart = getParameterValue("0", "OPTIMIZATION_COORDINATES_START", $hq_id);
         $coordinatesStartArray = array();      
         if ($coordinatesStart != "") :
            $coordinatesStartArray = explode(",", $coordinatesStart);
         endif;
         $coordinatesStartArrayLen = count($coordinatesStartArray);
         // End coordinates
         $coordinatesEnd = getParameterValue("0", "OPTIMIZATION_COORDINATES_END", $hq_id);
         $coordinatesEndArray = array();      
         if ($coordinatesEnd != "") :
            $coordinatesEndArray = explode(",", $coordinatesEnd);
         endif;
         $coordinatesEndArrayLen = count($coordinatesEndArray);

         // Iterate tours to be created for each vehicle (vehicle #1, vehicle #2, ...)
         $usedVehicleNumberArrayLen = count($usedVehicleNumberArray);

         // Remove old persistent optimization states in "ati.ati_data_19"
         if ($usedVehicleNumberArrayLen > 0) :
            $sqlStmt = "UPDATE phoenix.articleitem SET ati_data_19 = '' WHERE stk_id IN (SELECT stk_id FROM stock WHERE stk_pre_id = '" . $rootStockSU . "')";
            $res = $db->query($sqlStmt);
            if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif;
         endif;

         // Iterate all selected vehicles
         for ($j = 0; $j < $usedVehicleNumberArrayLen; $j++) :

             $tmpVehicleNum = $usedVehicleNumberArray[$j];
             $suRoutePlanningArrayLen = count($suRoutePlanningArray[$tmpVehicleNum]);
             if ($suRoutePlanningArrayLen > 0) :

                // Add start and/or end coordinates if exist
                $tmpLen = 0;
                if ($coordinatesStartArrayLen > 0) :
                   $suRoutePlanningArray[$tmpVehicleNum] = array_merge(array($coordinatesStartArray), $suRoutePlanningArray[$tmpVehicleNum]);
                endif;
                if ($coordinatesEndArrayLen > 0) :
                   $suRoutePlanningArray[$tmpVehicleNum] = array_merge($suRoutePlanningArray[$tmpVehicleNum], array($coordinatesEndArray));
                   $tmpLen = 1;
                endif;

                // Trigger optimization process
                // Data structure in "$suRoutePlanningArray[$tmpVehicleNum]": array(array("92845", "10.241763", "53.661418"), array("92730", "10.064445", "53.586847"), ...)

                // Set last element of the list to be optimized as target address
                // $tmpLen = count($suRoutePlanningArray[$tmpVehicleNum]);

                if ($optimizationDisabled != "1") :
                   $suRouteOptimizedArray[$tmpVehicleNum] = XSplanTourId($suRoutePlanningArray[$tmpVehicleNum], $tmpLen);
                   // print_r($suRoutePlanningArray[$tmpVehicleNum]); echo "&nbsp;&nbsp;&nbsp;&nbsp;" . $tmpLen; echo "<br>\n";
                else :
                   $suRouteOptimizedArray = $suRoutePlanningArray;
                endif;
                // print_r($suRoutePlanningArray[$tmpVehicleNum]); echo "&nbsp;&nbsp;&nbsp;&nbsp;" . $tmpLen; echo "<br>\n";
                $suRouteOptimizedArrayLen = count($suRouteOptimizedArray[$tmpVehicleNum]);
                if ($suRouteOptimizedArrayLen > 0) :

                   // Store optimization sort in table "articleitem"
                   if ($suRouteOptimizedArrayLen > 0) :
                      for ($i = 0; $i < $suRouteOptimizedArrayLen; $i++) :

                          if (!( ($i == 0 && $coordinatesStartArrayLen > 0) || ($i == $suRouteOptimizedArrayLen && $coordinatesEndArrayLen > 0) )) :
                             updateStmt("phoenix.articleitem", "ati_serialno", decodeSpecialChars($suRouteOptimizedArray[$tmpVehicleNum][$i][0]), array("ati_data_19", $constLngOutputTourChars . pad($tmpVehicleNum, 2, "0") . "-" . pad($i, 2, "0")));
                          endif;
                      endfor;
                   endif;
                else :
                   $outReportArray[] = getLngt("Tour") . " " . $tmpVehicleNum . ": " . getLngt("Die Optimierung schlug fehl! Der Rückgabevektor ist leer!");
                endif;
             else :
                $outReportArray[] = getLngt("Tour") . " " . $tmpVehicleNum . ": " . getLngt("Die Optimierung wurde mangels Geo-Koordinaten nicht durchgeführt!");
             endif;
         endfor;

         // After at least one optimization the button for displaying the (currrent optimized) tours will be enabled
         $f_map_is_active = "1";
      endif;
   endif;


   // Get current persistent states of the service units
   getPersistentStates();


   // ************************************************
   // * Make job from persistent optimization vector *
   // ************************************************
   if ($f_act == "makeJobPT") :

      // Get current timestamp
      $currentTime = getDateTime("0");
      $currentDate = getDateTime("3");

      // Init fix values for all jobs
      $cscIdPayer = getParameterValue("0", "CSC_ID_PAYER_DEFAULT", $hq_id);
      if ($cscIdPayer != "" && is_numeric($cscIdPayer)) :
         $cscId = "0"; $jbOrdertime = $currentTime; 
         $jbCrFilter = ""; $jbStatus = "9"; $jbType = ""; $jbTourname = ""; $fixprice = "0"; $cmpPostage = "0"; $csInvmode = "";
         $jbCrvhWeight = ""; $jbCrvhLength = ""; $jbCrvhWidth = ""; $jbCrvhHeight = ""; $jbCrvhPosition = "";  
         $jbTourdata = "";
         $cscIdExternal = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hq_id);
         // $txValue = getFieldValueFromId("tax","tx_id","1","tx_value"); 
         // $txSign = getFieldValueFromId("tax","tx_id","1","tx_sign");
         $txValue = "1"; $txSign = "0";

         // Get required vehicles from the persistent state of the optimized tours
         $usedVehicleNumberArray = array();
         $tmpOptimizedTourArray = getColVectorFromDB2ArrayByClause("phoenix.articleitem", "ati_data_19", "ati_data_19 != ''", "", "", "");
         $tmpOptimizedTourArrayLen = count($tmpOptimizedTourArray);
         for ($j = 0; $j < $tmpOptimizedTourArrayLen; $j++) :
             $tmpArray = spliti("-", $tmpOptimizedTourArray[$j]);
             $tmpTourNo = $tmpArray[0];
             $tmpTourNo = substr($tmpTourNo, strlen($constLngOutputTourChars));
             $x = array_search($tmpTourNo, $usedVehicleNumberArray);
             if ($x === FALSE) :
                $usedVehicleNumberArray[] = $tmpTourNo;
             endif;
         endfor;
         sort($usedVehicleNumberArray);   // The array e.g. contains ("01", "02", "03") [<=> tour numbers]
         $usedVehicleNumberArrayLen = count($usedVehicleNumberArray);
   
         // Iterate all vehicles to get a job for their tour
         if ($usedVehicleNumberArrayLen > 0) :


            // **** RESET CURRENT DAY (START) ****
            TA("B");
            
            // Reset vehicledisposition for the current day
            updateStmt("phoenix.vehicledisposition","","",array("jb_id","0"),"LEFT(vhd_timeslot,10) = '" . $currentDate . "' AND jb_id != '0'");

            // Get default customer ID (cs_id) for disposition in FDS regarding customer vehicle relation in "customervehicle"
            $csId = getParameterValue("0", "FDS_CS_CRVH_RELATION_DEFAULT_CUSTOMER", "0");
            if ($csId == "") : $csId = "829067"; endif;

            // Get the vehicles for the current customer
            $crvhList = array();
            $sqlquery = getStmtCustomerVehicleRelation("", $csId);
            $result = $db->query($sqlquery);
            if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
            while ($row = $result->fetch_assoc()):
                  $crvhList[] = $row["crvh_id"];
            endwhile;
            $result->free();
            $crvhListLen = count($crvhList);

            // Check for each vehicle displayed the existence of entries in "vehicledisposition", "vehicleavailability" and "vehicleavailabilitytimeunits".
            // If it does not exist then generate it to handle the drag and dropping the jobs etc.
            for ($v = 0; $v < $crvhListLen; $v++) :
                updateAllCsVehicleAvailability($crvhList[$v], $csId, $currentDate, $hourTimeUnits);
            endfor;

            // Storno
            $res = updateStmt("job", "", "", array("jb_storno", "2", "usr_id_storno", $usr_id, "jb_status" , "2", "jb_finishtime", $currentTime), "(LEFT(jb_ordertime, 10) = '" . $currentDate . "' AND (jb_status = '8' OR jb_status = '9' OR jb_status = '0' OR jb_status = '1') AND (isnull(jb_storno) OR jb_storno = '0'))");
            if ($db->affected_rows > 0) :
               // Write logdata into log database
               // writeToLogDB("10",$hq_id,"",$usr_id,"","","","");            
            endif;

            TA("C");
            TA("E");
            // **** RESET CURRENT DAY (END) ****


            for ($j = 0; $j < $usedVehicleNumberArrayLen; $j++) :
                $tmpVehicleNum = $usedVehicleNumberArray[$j];    // It is a pad value like "01", "02", "03", ... !!!

                // Get persistent optimized vector of service unit data
                $tmpStrLen = strlen($constLngOutputTourChars) + strlen($tmpVehicleNum);
                $sqlStmt = getStmtGenericStockArticleItems("0", $rootStockSU, "", "1", "ati.ati_data_19 != '' AND LEFT(ati.ati_data_19, " . $tmpStrLen . ") = '" . $constLngOutputTourChars . $tmpVehicleNum . "'", "", "ati.ati_data_19", "");
                if ($sqlStmt != "") :
                   $result = $db->query($sqlStmt);     
                   if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
                   if ($result->numRows() > 0) :

                      TA("B");

                      $crId = $mappedCourierArray[$f_tour_crvh_assoc[intval($tmpVehicleNum)]];  // $f_tour_crvh_assoc contains manuel mapping (tour.no => vehicle.no) by user (!!!!)
                      if ($crId != "") :

                         $crIdOrder = $crId;
                         $crvhId = getFieldValueFromId("couriervehicle","cr_id",$crId,"crvh_id");
                         $vhtId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"vht_id");
                         $crSid = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"crvh_sid");
                         $jbRemark = "";
                         
                         if ($globalParUseRelatedCustomer == "1") :

                            // **** One separate job for each service unit ****
                         
                            // Remove existing cartage note of the vehicle of the day to write new jobs to a new cartage note
                            if ($csId != "" && is_numeric($csId)) :
                               // ....... !!!!!!!!!!!!!!! .......
                               // $retBool = removeAssocCrvhJb($jbId, $csId, $hourTimeUnits);
                            endif;
                         
                            // Create job data
                            $counter = 0;
                            while ($row = $result->fetch_assoc()):

                                  // $checkTime  = getDateTime("datetime_plus_offset", array(0,0,0,0,-($constAmStarttimeInDays),0), "Y-m-d") . " 00:00:00";
                                  // $retVal = date($formatStr, mktime(date("H")+$dateTimeArray[0],date("i")+$dateTimeArray[1],date("s")+$dateTimeArray[2],date("m")+$dateTimeArray[3],date("d")+$dateTimeArray[4],date("Y")+$dateTimeArray[5]));
                                  $timeslots = 4;
                                  /*
                                  $hour = (1 + $counter);
                                  $hourUnit = 0;
                                  $jbOrdertime = $currentDate . " " . pad(strval($hour),2) . ":" . pad(strval($hourUnit),2) . ":00";
                                  */
                                  $minutesPerJob = $timeslots * floor(60 / $hourTimeUnits);
                                  $startTimeMinutes = ($minutesPerJob * $counter);
                                  $hour = floor($startTimeMinutes / 60);
                                  $minutesRest = $startTimeMinutes - ($hour * 60);
                                  $hourUnit = strval(ceil($minutesRest * ($hourTimeUnits / 60)));  // Convert minute to time unit
                                  $hour++;
                                  $jbOrdertime = $currentDate . " " . pad(strval($hour),2) . ":" . pad(strval($minutesRest),2) . ":00";
                         
                                  $jbDispoinfo = $row["ati_data_25"];
                         
                                  // Create general job data
                                  insertStmt("job", array("hq_id", $hq_id, "csc_id", $cscId, "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", $cscIdPayer,
                                                          "jb_payment", "0", "jb_ordertime", $jbOrdertime, "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crIdOrder,
                                                          "jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0", 
                                                          "jb_taketime", "", "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType, 
                                                          "jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $jbTourname,
                                                          "jb_finishtime", "", "emp_id", $usr_id, "jb_fixprice", $fixprice, "jb_totalprice", $fixprice,
                                                          "jb_postage", $cmpPostage, "jb_invmode", $csInvmode, "jb_freetext_1", "",
                                                          "jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth, 
                                                          "jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition, "jb_invtext", $jbRemark,
                                                          "jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", $jbDispoinfo,
                                                          "jb_sales_tax_rate", $txValue, "jb_timeunits", $timeslots, "jb_service", "1", 
                                                          "jb_sales_tax_rate_sign", $txSign, "jb_booktime", ""));
                                  $jbIdNew = getLastInsertId();
                                  // echo "counter = " . $counter . " | " . "minutesPerJob = " . $minutesPerJob . " | " . "startTimeMinutes = " . $startTimeMinutes . " | " . "hour = " . $hour . " | " . "minutesRest = " . $minutesRest . " | " . "hourUnit = " . $hourUnit . " | " . "jbIdNew = " . $jbIdNew . " | " . "jbOrdertime = " . $jbOrdertime . "<br>\n";
                                  // Insert tour data for station 1 (it will be the same for every job (!!!!))
                                  insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $adId, "tr_sort", "1", "tr_comp", "", "tr_comp2", "",
                                                           "tr_hsno", ".", "csc_id", $cscIdPayer, "tr_status", "0", 
                                                           "tr_commission_no", "", "tr_ware_from_to", "", 
                                                           "tr_person", "", "tr_phone", "", "tr_remark", ""));

                                  // Get state of the service unit
                                  $tmpAtiSerialno = $row["ati_serialno"];
                                  $tmpAtiArray = getFieldsValueFromId("articleitem","ati_serialno",$row["ati_serialno"],array("at_id","ati_data_17","ati_data_05","ati_data_06","ati_data_07","ati_data_08","ati_data_09","ati_data_29","ati_data_26","ati_data_04"));
                                  $tmpAtId      = $tmpAtiArray[0];
                                  $tmpAtimCodes = $tmpAtiArray[1];
                                  $tmpAtiData05 = $tmpAtiArray[2];
                                  $tmpAtiData06 = $tmpAtiArray[3];
                                  $tmpAtiData07 = $tmpAtiArray[4];
                                  $tmpAtiData08 = $tmpAtiArray[5];
                                  $tmpAtiData09 = $tmpAtiArray[6];
                                  $tmpAtiData29 = $tmpAtiArray[7];
                                  $tmpAtiData26 = $tmpAtiArray[8];  // Get amount increase values
                                  $tmpAtiData04 = $tmpAtiArray[9];  // Import date with existimg data


                                  // **** Check for old date or prediction state [START] ****
                                  $atGroup = getFieldValueFromId("phoenix.article", "at_id", $tmpAtId, "at_group");
                                  // Check days having access regarding special costcenter (!!!!)
                                  $executeRegardingCscNoBookingDay = checkEcecutionStateRegardingCscNoBookingDay($atGroup);
                                  // Increase amounts for array ($dataSU[5], $dataSU[6], $dataSU[7], $dataSU[8], $dataSU[9], ....)
                                  $amountIncreaseArray = explode(",", $tmpAtiData26);
                                  // Check data missing by service. The timestamp would not be the current date
                                  if ($executeRegardingCscNoBookingDay && is_array($f_tv[$atId]) && count($f_tv[$atId]) > 0) :
                                     $tmpDataSU4 = substr($tmpAtiData04,0,10);
                                     $importDaysDiff = mcDateDiff($tmpDataSU4, $currentDate);
                                     if ($tmpDataSU4 != "" && $importDaysDiff > 0) :
                                         $tmpAtiData05 = cbIncreaseAmountByInterval($tmpAtiData05, $tmpDataSU4, $amountIncreaseArray[0], $f_tv[$tmpAtId][4], $tmpAtiSerialno);
                                         $tmpAtiData06 = cbIncreaseAmountByInterval($tmpAtiData06, $tmpDataSU4, $amountIncreaseArray[1], $f_tv[$tmpAtId][2], $tmpAtiSerialno);                                     
                                         $tmpAtiData07 = cbDecreaseAmountByInterval($tmpAtiData07, $tmpDataSU4, $amountIncreaseArray[2], $f_tv[$tmpAtId][5], $tmpAtiSerialno);
                                         $tmpAtiData08 = cbDecreaseAmountByInterval($tmpAtiData08, $tmpDataSU4, $amountIncreaseArray[3], $f_tv[$tmpAtId][6], $tmpAtiSerialno);
                                         $tmpAtiData09 = cbDecreaseAmountByInterval($tmpAtiData09, $tmpDataSU4, $amountIncreaseArray[4], $f_tv[$tmpAtId][7], $tmpAtiSerialno);
                                     endif;
                                  endif;
                                  // Check for requested prediction and compute future values
                                  if ($executeRegardingCscNoBookingDay && $predictionDays > 0 && is_array($f_tv[$atId]) && count($f_tv[$atId]) > 0) :
                                     $tmpAtiData05 = cbIncreaseAmountByInterval($tmpAtiData05, $predictionDate, $amountIncreaseArray[0], $f_tv[$tmpAtId][4], $tmpAtiSerialno);
                                     $tmpAtiData06 = cbIncreaseAmountByInterval($tmpAtiData06, $predictionDate, $amountIncreaseArray[1], $f_tv[$tmpAtId][2], $tmpAtiSerialno);
                                     $tmpAtiData07 = cbDecreaseAmountByInterval($tmpAtiData07, $predictionDate, $amountIncreaseArray[2], $f_tv[$tmpAtId][5], $tmpAtiSerialno);
                                     $tmpAtiData08 = cbDecreaseAmountByInterval($tmpAtiData08, $predictionDate, $amountIncreaseArray[3], $f_tv[$tmpAtId][6], $tmpAtiSerialno);
                                     $tmpAtiData09 = cbDecreaseAmountByInterval($tmpAtiData09, $predictionDate, $amountIncreaseArray[4], $f_tv[$tmpAtId][7], $tmpAtiSerialno);
                                  endif;
                                  // **** Check for old date or prediction state [END] ****

                                  // Get names of each CB type regarding the current SU type
                                  // Each CB type contains the reference
                                  $tmpCbTypeIDs = getParameterValue("0", "SU_CB_TYPES_" . $tmpAtId, $hq_id);
                                  $tmpCbTypeIDArr = explode(",", $tmpCbTypeIDs);
                                  $tmpCbTypeIDArrLen = count($tmpCbTypeIDArr);
                                  $tmpCbTypeNameArr = array("","","","","","","","","","");
                                  for ($cb = 0; $cb < $tmpCbTypeIDArrLen; $cb++) :
                                      if (is_numeric($tmpCbTypeIDArr[$cb])) :
                                         $tmpCbTypeNameArr[$cb] = getFieldValueFromId("phoenix.article", "at_id", $tmpCbTypeIDArr[$cb], "at_match");
                                      endif;
                                  endfor;

                                  $trPerson = "";
                                  $trRemark = "";

                                  $trRemark .= ($tmpCbTypeNameArr[0] != "" ? $tmpCbTypeNameArr[0] : getLngt("BEK")) . ": " . number_format($tmpAtiData05, 2, ",", ".") . "|";
                                  $trRemark .= ($tmpCbTypeNameArr[1] != "" ? $tmpCbTypeNameArr[1] : getLngt("MEK")) . ": " . number_format($tmpAtiData06, 2, ",", ".") . "|";
                                  $trRemark .= ($tmpCbTypeNameArr[2] != "" ? $tmpCbTypeNameArr[2] : getLngt("H1"))  . ": " . number_format($tmpAtiData07, 2, ",", ".") . "|";
                                  $trRemark .= ($tmpCbTypeNameArr[3] != "" ? $tmpCbTypeNameArr[3] : getLngt("H2"))  . ": " . number_format($tmpAtiData08, 2, ",", ".") . "|";
                                  $trRemark .= ($tmpCbTypeNameArr[4] != "" ? $tmpCbTypeNameArr[4] : getLngt("Dispenser")) . ": " . number_format($tmpAtiData09, 0, ",", ".");

                                  $trSort = "2";

                                  // Get elements of a specified service unit to be critical
                                  // $trPerson = getCBsToBeChangedByCriticalState($row["ati_serialno"]);
                                  $tmpMarkerArray = getCBsToBeChangedByMarker($row["ati_serialno"]);
                                  $tmpMarkerArrayLen = count($tmpMarkerArray);

                                  $serviceByCriticalMsg = array();
                                  if ($tmpAtId != "" && $tmpAtimCodes != "") :
                                     $tmpAtimCodesArray = explode(",", $tmpAtimCodes);
                                     $tmpAtimCodesArrayLen = count($tmpAtimCodesArray);
                                     for ($k = 0; $k < $tmpAtimCodesArrayLen; $k++) :
                                         $tmpAtimCode = $tmpAtimCodesArray[$k];
                                         $tmpAtimDesc = getFieldValueFromClause("articlemessage","atm_desc","at_id = '" . $tmpAtId . "' AND atm_code = '" . $tmpAtimCode . "'");
                                         $tmpAtimShorttext = getFieldValueFromClause("articlemessage","atm_shorttext","at_id = '" . $tmpAtId . "' AND atm_code = '" . $tmpAtimCode . "'");
                                         $tmpAtimText = getFieldValueFromClause("articlemessage","atm_text","at_id = '" . $tmpAtId . "' AND atm_code = '" . $tmpAtimCode . "'");
                                         if ($trRemark != "") : $trRemark .= "|"; endif;
                                         // $trRemark .= "[" . ($k + 1) . ".] " . $tmpAtimCode . ": " . $tmpAtimDesc . " | => " . $tmpAtimText;
                                         $trRemark .= "[" . ($k + 1) . ".] " . $tmpAtimText;

                                         if (in_array($tmpAtimCode, $criticalMessageArray)) :
                                            $serviceByCriticalMsg[] = $tmpAtimShorttext;
                                         endif;

                                         if ($tmpAtiData29 == "1") :
                                            for ($d = 0; $d < $displayMessageArrayLen; $d++) :
                                               if ($displayMessageArray[$d][1] == $tmpAtimCode) :
                                                  array_push($tmpMarkerArray, $displayMessageArray[$d][2] . "=1");  // E.g. "H1=1"
                                                  break 1;
                                               endif;
                                            endfor;
                                            $tmpMarkerArrayLen = count($tmpMarkerArray);
                                         endif;
                                     endfor;
                                  endif;

                                  // Set "jb_service"
                                  $serviceByCriticalMsgLen = count($serviceByCriticalMsg);
                                  if ($serviceByCriticalMsgLen > 0) :
                                     $jbService = "1";
                                     if ($tmpMarkerArrayLen > 0) :
                                        $jbService = "3";
                                     else :
                                        $jbService = "2";
                                     endif;
                                     updateStmt("job", "jb_id", $jbIdNew, array("jb_service", $jbService), "");
                                  endif;

                                  $trPerson = implode("|", $tmpMarkerArray);
                                  $trCsFreetext = implode(",", $serviceByCriticalMsg);
// Fix text depending on "at_id" => "parameter" (!!!!)
                                  if ($tmpAtId == "4327") :
                                     $trRemark = "[TEXT]B+R Anlage überprüfen";
                                  endif;

                                  // Insert tour data for station
                                  insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $row["ad_id"], "tr_sort", $trSort, "tr_comp", $row["ati_serialno"], "tr_comp2", $row["ati_data_01"],
                                                           "tr_hsno", $row["stk_hsno"], "csc_id", $cscIdExternal, "tr_status", "0", 
                                                           "tr_commission_no", $row["ati_serialno"], "tr_ware_from_to", "", 
                                                           "tr_person", $trPerson, "tr_phone", "", "tr_remark", $trRemark,
                                                           "tr_mediationarea_id", $row["stk_id"], "tr_mediationarea_name", $row["stk_name"],
                                                           "tr_cs_freetext", $trCsFreetext));
                                  $trIdNew = getLastInsertId();

                                  if ($trIdNew != "" && is_numeric($trIdNew)) :

                                     // Insert tourservice data
                                     $tmpSuSingleChargingLevels = "";
                                     if (in_array($row["ati_serialno"], $f_su_cb_chkbx_00)) :
                                        $tmpSuSingleChargingLevels .= ($tmpCbTypeNameArr[0] != "" ? $tmpCbTypeNameArr[0] : getLngt("BEK")) . number_format($row["ati_data_05"], 0, ",", ".") . ",";
                                     endif;
                                     if (in_array($row["ati_serialno"], $f_su_cb_chkbx_01)) :
                                        $tmpSuSingleChargingLevels .= ($tmpCbTypeNameArr[1] != "" ? $tmpCbTypeNameArr[1] : getLngt("MEK")) . number_format($row["ati_data_06"], 2, ",", ".") . ",";
                                     endif;
                                     if (in_array($row["ati_serialno"], $f_su_cb_chkbx_02)) :
                                        $tmpSuSingleChargingLevels .= ($tmpCbTypeNameArr[2] != "" ? $tmpCbTypeNameArr[2] : getLngt("H1")) .  number_format($row["ati_data_07"], 0, ",", ".") . ",";
                                     endif;
                                     if (in_array($row["ati_serialno"], $f_su_cb_chkbx_03)) :
                                        $tmpSuSingleChargingLevels .= ($tmpCbTypeNameArr[3] != "" ? $tmpCbTypeNameArr[3] : getLngt("H2")) .  number_format($row["ati_data_08"], 2, ",", ".") . ",";
                                     endif;
                                     if (in_array($row["ati_serialno"], $f_su_cb_chkbx_04)) :                                  
                                        $tmpSuSingleChargingLevels .= ($tmpCbTypeNameArr[4] != "" ? $tmpCbTypeNameArr[4] : getLngt("Dispenser")) .  number_format($row["ati_data_09"], 0, ",", ".");
                                     endif;

                                     $tmpSuChargingLevelSum = 0;
                                     $tmpSuWeightOfChargingLevelSum = 0;
                                     if (in_array($row["ati_serialno"], $f_su_cb_chkbx_00) && $row["ati_data_05"] != "" && is_numeric($row["ati_data_05"])) : 
                                        $tmpSuChargingLevelSum += $row["ati_data_05"];
                                        if (!(strpos($row["at_group"], ",6,") === FALSE)) :  // Check for being safebag
                                           $tmpSuWeightOfChargingLevelSum += 1;
                                        else :
                                           $tmpSuWeightOfChargingLevelSum += ($row["ati_data_05"] / $cbWeightFactors[0]);
                                        endif;
                                     endif;
                                     if (in_array($row["ati_serialno"], $f_su_cb_chkbx_01) && $row["ati_data_06"] != "" && is_numeric($row["ati_data_06"])) :
                                        $tmpSuChargingLevelSum += $row["ati_data_06"];
                                        if (!(strpos($row["at_group"], ",6,") === FALSE)) :  // Check for being safebag
                                           $tmpSuWeightOfChargingLevelSum += 1;
                                        else :
                                           $tmpSuWeightOfChargingLevelSum += ($row["ati_data_06"] / $cbWeightFactors[1]);
                                        endif;
                                     endif;
                                     // if (in_array($row["ati_serialno"], $f_su_cb_chkbx_02) && $row["ati_data_07"] != "" && is_numeric($row["ati_data_07"])) : $tmpSuChargingLevelSum += $row["ati_data_07"]; endif;
                                     // if (in_array($row["ati_serialno"], $f_su_cb_chkbx_03) && $row["ati_data_08"] != "" && is_numeric($row["ati_data_08"])) : $tmpSuChargingLevelSum += $row["ati_data_08"]; endif;
                                     // if (in_array($row["ati_serialno"], $f_su_cb_chkbx_04) && $row["ati_data_09"] != "" && is_numeric($row["ati_data_09"])) : $tmpSuChargingLevelSum += $row["ati_data_09"]; endif;
                         
                                     insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort, 
                                                                     "srv_id", "0", "trs_srv_name", getLngt("Geldbestand"), "srvt_id", "0", "trs_srvt_name", "",
                                                                     "trs_price", $tmpSuChargingLevelSum));

                                     // Insert tourarticle
                                     insertStmt("tourarticle", array("jb_id", $jbIdNew, "tr_id", $trIdNew, "tr_sort", $trSort, "trat_name", $row["ati_serialno"], "trat_serialno", $row["ati_serialno"], "trat_weight", $tmpSuWeightOfChargingLevelSum, "trat_createtime", $currentTime));
                                     $tratIdNew = getLastInsertId();

                                     // Insert tourarticleprocess
                                     // Store snapshot of the current data in articleitem of the current service unit
                                     /*
                                     if ($tratIdNew != "" && is_numeric($tratIdNew)) :
                                        // [tratp_type == "5" <=> ati_data_05 <=> e.g. BEK, tratp_type == "6" <=> ati_data_06 <=> e.g. MEK, etc.]
                                        // for ($k = 1; $k <= $maxNumOfAtiDataFields; $k++) :
                                        for ($k = 5; $k <= 9; $k++) :
                                            insertStmt("tourarticleprocess", array("trat_id", $tratIdNew, "tratp_type", $k, "tratp_state", "0", 
                                                                                   "tratp_remark", $row["ati_data_" . pad($k, 2, "0")], "tratp_createtime", $currentTime));
                                        endfor;
                                     endif;
                                     */
                         
                                     // TO BE CHECKED BY SEMANTIC VIEW !!!!!!!!!!!!!!!!!!!!!!!
                                     // Update total price with price value of the service unit (ALL cashboxes and hoppers added!)
                                     updateStmt("phoenix.job", "jb_id", $jbIdNew, array("jb_totalprice", $tmpSuChargingLevelSum), "");
                                  endif;

                                  // Store job into FDS
                                  if ($csId != "" && is_numeric($csId)) :
                                     $retBool = setAssocCrvhJb($jbIdNew, $crvhId, $csId, $currentDate, $hour, $hourUnit, $timeslots);
                                  else :
                                     $outReportArray[] = getLngt("KRITISCHER FEHLER: Der Auftrag mit der Nummer") . " " . $jbIdNew . " " . getLngt("wurde NICHT in die FDS eingetragen, weil die Kundenzuordnung fehlt!");
                                  endif;

                                  $counter++;
                            endwhile;
                         
                         else :
                         
                            // **** One separate job for ALL service units of one vehicle for one day (one job for one cartage note) ****
                         
                            // Create general job data
                            insertStmt("job", array("hq_id", $hq_id, "csc_id", $cscId, "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "csc_id_related", $cscIdPayer,
                                                    "jb_payment", "0", "jb_ordertime", $jbOrdertime, "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crIdOrder,
                                                    "jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0", 
                                                    "jb_taketime", "", "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType, 
                                                    "jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $jbTourname,
                                                    "jb_finishtime", "", "emp_id", $usr_id, "jb_fixprice", $fixprice, "jb_totalprice", $fixprice,
                                                    "jb_postage", $cmpPostage, "jb_invmode", $csInvmode, "jb_freetext_1", "",
                                                    "jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth, 
                                                    "jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition, "jb_invtext", $jbRemark,
                                                    "jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
                                                    "jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_booktime", ""));
                            $jbIdNew = getLastInsertId();
                         
                            if (true || $jbIdNew != "") :  // Could be true regarding TA handling
                            
                               // Create tour data
                               $i = 0;
                               while ($row = $result->fetch_assoc()):
                                     $trSort = $i + 1;
                               
                                     // Get state of the service unit
                                     $trRemark = "";
                                     $tmpAtiArray = getFieldsValueFromId("articleitem","ati_serialno",$row["ati_serialno"],array("at_id","ati_data_17"));
                                     $tmpAtId = $tmpAtiArray[0];
                                     $tmpAtimCodes = $tmpAtiArray[1];
                                     if ($tmpAtId != "" && $tmpAtimCodes != "") :
                                        $tmpAtimCodesArray = spliti(",", $tmpAtimCodes);
                                        $tmpAtimCodesArrayLen = count($tmpAtimCodesArray);
                                        for ($k = 0; $k < $tmpAtimCodesArrayLen; $k++) :
                                            $tmpAtimCode = $tmpAtimCodesArray[$k];
                                            $tmpAtimDesc = getFieldValueFromClause("articlemessage","atm_desc","at_id = '" . $tmpAtId . "' AND atm_code = '" . $tmpAtimCode . "'");
                                            $tmpAtimText = getFieldValueFromClause("articlemessage","atm_text","at_id = '" . $tmpAtId . "' AND atm_code = '" . $tmpAtimCode . "'");
                                            if ($trRemark != "") : $trRemark .= " | "; endif;
                                            $trRemark .= "[" . ($k + 1) . ".] " . $tmpAtimCode . ": " . $tmpAtimDesc . " | => " . $tmpAtimText;
                                        endfor;
                                     endif;
                               
                                     // Insert tour data for station
                                     insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $row["ad_id"], "tr_sort", $trSort, "tr_comp", $row["ati_serialno"], "tr_comp2", "",
                                                              "tr_hsno", $row["stk_hsno"], "csc_id", $cscIdExternal, "tr_status", "0", 
                                                              "tr_commission_no", $row["ati_serialno"], "tr_ware_from_to", "", 
                                                              "tr_person", "", "tr_phone", "", "tr_remark", $trRemark));
                               
                                     // Insert tourservice data
                                     $tmpSuSingleChargingLevels = "";
                                     if (in_array($row["ati_serialno"], $f_su_cb_chkbx_00)) :
                                        $tmpSuSingleChargingLevels .= getLngt("BEK:") . number_format($row["ati_data_05"], 0, ",", ".") . ",";
                                     endif;
                                     if (in_array($row["ati_serialno"], $f_su_cb_chkbx_01)) :
                                        $tmpSuSingleChargingLevels .= getLngt("MEK:") . number_format($row["ati_data_06"], 2, ",", ".") . ",";
                                     endif;
                                     if (in_array($row["ati_serialno"], $f_su_cb_chkbx_02)) :
                                        $tmpSuSingleChargingLevels .= getLngt("H1:") .  number_format($row["ati_data_07"], 0, ",", ".") . ",";
                                     endif;
                                     if (in_array($row["ati_serialno"], $f_su_cb_chkbx_03)) :
                                        $tmpSuSingleChargingLevels .= getLngt("H2:") .  number_format($row["ati_data_08"], 2, ",", ".") . ",";
                                     endif;
                                     if (in_array($row["ati_serialno"], $f_su_cb_chkbx_04)) :                                  
                                        $tmpSuSingleChargingLevels .= getLngt("Dispenser:") .  number_format($row["ati_data_09"], 0, ",", ".");
                                     endif;
                                     $tmpSuChargingLevelSum = 0;
                                     if (in_array($row["ati_serialno"], $f_su_cb_chkbx_00) && $row["ati_data_05"] != "" && is_numeric($row["ati_data_05"])) : $tmpSuChargingLevelSum += $row["ati_data_05"]; endif;
                                     if (in_array($row["ati_serialno"], $f_su_cb_chkbx_01) && $row["ati_data_06"] != "" && is_numeric($row["ati_data_06"])) : $tmpSuChargingLevelSum += $row["ati_data_06"]; endif;
                                     // if (in_array($row["ati_serialno"], $f_su_cb_chkbx_02) && $row["ati_data_07"] != "" && is_numeric($row["ati_data_07"])) : $tmpSuChargingLevelSum += $row["ati_data_07"]; endif;
                                     // if (in_array($row["ati_serialno"], $f_su_cb_chkbx_03) && $row["ati_data_08"] != "" && is_numeric($row["ati_data_08"])) : $tmpSuChargingLevelSum += $row["ati_data_08"]; endif;
                                     // if (in_array($row["ati_serialno"], $f_su_cb_chkbx_04) && $row["ati_data_09"] != "" && is_numeric($row["ati_data_09"])) : $tmpSuChargingLevelSum += $row["ati_data_09"]; endif;
                                     insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort, 
                                                                     "srv_id", "0", "trs_srv_name", $tmpSuSingleChargingLevels, "srvt_id", "0", "trs_srvt_name", "",
                                                                     "trs_price", $tmpSuChargingLevelSum));
                               
                                     // Insert tourarticle
                                     insertStmt("tourarticle", array("jb_id", $jbIdNew, "tr_sort", $trSort, "trat_serialno", $row["ati_serialno"], "trat_createtime", $currentTime));
                                     $tratIdNew = getLastInsertId();
                               
                                     // Insert tourarticleprocess
                                     // Store snapshot of the current data in articleitem of the current service unit
                                     if ($tratIdNew != "" && is_numeric($tratIdNew)) :
                                        // [tratp_type == "5" <=> ati_data_05 <=> e.g. BEK, tratp_type == "6" <=> ati_data_06 <=> e.g. MEK, etc.]
                                        // for ($k = 1; $k <= $maxNumOfAtiDataFields; $k++) :
                                        for ($k = 5; $k <= 9; $k++) :
                                            insertStmt("tourarticleprocess", array("trat_id", $tratIdNew, "tratp_type", $k, "tratp_state", "0", 
                                                                                   "tratp_remark", $row["ati_data_" . pad($k, 2, "0")], "tratp_createtime", $currentTime));
                                        endfor;
                                     endif;
                               
                                     $i++;
                               endwhile;
                            endif;
                            
                            if (existsEntry("job", array("jb_id", $jbIdNew))) :
                               $outReportArray[] = getLngt("Der Auftrag mit der Nummer") . " " . $jbIdNew . " " . getLngt("wurde erzeugt!");
                            else :
                               $outReportArray[] = getLngt("Es wurde leider kein Auftrag erzeugt!");
                            endif;
                         endif;
                      endif;  // Check $cr_id
                      
                      TA("C");
                      TA("E");
                   endif;
                   $result->free();
                endif;
            endfor;
         endif;
      else :
         $outReportArray[] = getLngt("Es existiert kein Default-Bezahler für die Tour. Der Auftrag wurde NICHT angelegt! Bitte der Systemadministration melden!");
      endif;
   endif;


   // Get service jobs
   getServiceJoblist();

endif;  // Check for $rootStockSU is defined



// **********
// * Output *
// **********

// Output threshold values
$outThresholdValues = "";
if ($generateOutput) :

   for ($a = 0; $a < $suAtIdArrayLen; $a++) :

       $atId = $suAtIdArray[$a];
       $tmpAtMatch = getFieldValueFromId("phoenix.article", "at_id", $atId, "at_match");
       $tmpAtGroup = getFieldValueFromId("phoenix.article", "at_id", $atId, "at_group");

       $dummyLowerRange = 0;
       $dummyUpperRange = 99999;

       if (!(strpos($tmpAtGroup, ",6,") === FALSE)) :
          for ($t = 1; $t <= 2; $t++) :
              $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_" . $atId . "_" . pad($t, 2) . "\" value=\"" . $dummyUpperRange . "\">";
          endfor;

          $outThresholdValues .= "<table border=\"1\">";
          $outThresholdValues .= "<tr><td class=\"f8np1\" colspan=\"3\" style=\"width:495;text-align:left;color:" . $colArray["white"] . ";background-color:" . $colArray["light_blue"] . ";\"><b>" . getLngt("VERKAUFSSTELLE") . " " . $tmpAtMatch . "</b></td>"
                                 . "</tr>";
          $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;color:" . $colArray["white"] . ";background-color:" . $colArray["light_blue"] . ";\"><b>" . getLngt("TYP") . "</b></td>"
                                 . "  <td class=\"f8np1\" style=\"width:150;text-align:left;color:" . $colArray["white"] . ";background-color:" . $colArray["light_blue"] . ";\"><b>" . getLngt("EINHEIT") . "</td>"
                                 . "  <td class=\"f8np1\" style=\"width:45;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["light_blue"] . ";\"><b>" . " " . "</td>"
                                 . "</tr>";
          $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Safebag") . "</b></td>"
                                 . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("gelb") . "</td>"
                                 . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_" . $atId . "_03\" value=\"" . $f_tv[$atId][3] . "\" size=\"10\">" . "</td>"
                                 . "</tr>";
          $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Safebag") . "</b></td>"
                                 . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("rot") . "</td>"
                                 . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_" . $atId . "_04\" value=\"" . $f_tv[$atId][4] . "\" size=\"10\">" . "</td>"
                                 . "</tr>";
          $outThresholdValues .= "</table>";

          // Prepare for remaining threshold values. Use hidden parameters
          $startValueForRemainingFields = 5;
          for ($t = $startValueForRemainingFields; $t <= $maxNumOfAtiDataFields; $t++) :
              $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_" . $atId . "_" . pad($t, 2) . "\" value=\"" . $dummyLowerRange . "\">";
          endfor;
       else :
          $outThresholdValues .= "<table border=\"1\">";
          $outThresholdValues .= "<tr><td class=\"f8np1\" colspan=\"3\" style=\"width:495;text-align:left;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\"><b>" . getLngt("AUTOMATENTYP") . " " . $tmpAtMatch . "</b></td>"
                                 . "</tr>";
          $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\"><b>" . getLngt("KASSETTENTYP") . "</b></td>"
                                 . "  <td class=\"f8np1\" style=\"width:150;text-align:left;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\"><b>" . getLngt("ART") . "</td>"
                                 . "  <td class=\"f8np1\" style=\"width:45;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\"><b>" . getLngt("BETRAG") . "</td>"
                                 . "</tr>";
          $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Münzkassette (MEK)") . "</b></td>"
                                 . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("MEK gelb") . "</td>"
                                 . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_" . $atId . "_01\" value=\"" . $f_tv[$atId][1] . "\" size=\"10\">" . "</td>"
                                 . "</tr>";
          $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Münzkassette (MEK)") . "</b></td>"
                                 . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("MEK rot") . "</td>"
                                 . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_" . $atId . "_02\" value=\"" . $f_tv[$atId][2] . "\" size=\"10\">" . "</td>"
                                 . "</tr>";
          $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Banknotenkassetten (BEK)") . "</b></td>"
                                 . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("BEK gelb") . "</td>"
                                 . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_" . $atId . "_03\" value=\"" . $f_tv[$atId][3] . "\" size=\"10\">" . "</td>"
                                 . "</tr>";
          $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Banknotenkassetten (BEK)") . "</b></td>"
                                 . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("BEK rot") . "</td>"
                                 . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_" . $atId . "_04\" value=\"" . $f_tv[$atId][4] . "\" size=\"10\">" . "</td>"
                                 . "</tr>";
          $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Wechselgeldspeicher (Kassetten)") . "</b></td>"
                                 . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("Hopper 1 (2 EUR) gelb") . "</td>"
                                 . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_" . $atId . "_08\" value=\"" . $f_tv[$atId][8] . "\" size=\"10\">" . "</td>"
                                 . "</tr>";
          $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Wechselgeldspeicher (Kassetten)") . "</b></td>"
                                 . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("Hopper 2 (10 ct) gelb") . "</td>"
                                 . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_" . $atId . "_09\" value=\"" . $f_tv[$atId][9] . "\" size=\"10\">" . "</td>"
                                 . "</tr>";
          $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Wechselgeldspeicher (Kassetten)") . "</b></td>"
                                 . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("Hopper 3 (5 ct) gelb") . "</td>"
                                 . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_" . $atId . "_10\" value=\"" . $f_tv[$atId][10] . "\" size=\"10\">" . "</td>"
                                 . "</tr>";
          $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Wechselgeldspeicher (Kassetten)") . "</b></td>"
                                 . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("Hopper 1 (2 EUR) rot") . "</td>"
                                 . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_" . $atId . "_05\" value=\"" . $f_tv[$atId][5] . "\" size=\"10\">" . "</td>"
                                 . "</tr>";
          $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Wechselgeldspeicher (Kassetten)") . "</b></td>"
                                 . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("Hopper 2 (10 ct) rot") . "</td>"
                                 . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_" . $atId . "_06\" value=\"" . $f_tv[$atId][6] . "\" size=\"10\">" . "</td>"
                                 . "</tr>";
          $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Wechselgeldspeicher (Kassetten)") . "</b></td>"
                                 . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("Hopper 3 (5 ct) rot") . "</td>"
                                 . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_" . $atId . "_07\" value=\"" . $f_tv[$atId][7] . "\" size=\"10\">" . "</td>"
                                 . "</tr>";
          $outThresholdValues .= "</table>";

          // Prepare for remaining threshold values. Use hidden parameters
          $startValueForRemainingFields = 11;
          for ($t = $startValueForRemainingFields; $t <= $maxNumOfAtiDataFields; $t++) :
              $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_" . $atId . "_" . pad($t, 2) . "\" value=\"" . $f_tv[$atId][$t] . "\">";
          endfor;
       endif;
   endfor;
endif;


// Output current states of service units
$outEventStates = "";
if ($generateOutput) :
   $outEventStatesArrayLen = count($outEventStatesArray);
   if ($outEventStatesArrayLen > 0) :
      $outEventStates .= "<table width=\"100%\" border=\"1\">";
      $outEventStates .= "<tr><td class=\"f8np1 f_col_sel_00\" style=\"width:45;text-align:left;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('0');\"><b>" . getLngt("FA") . "</b></td>";
      $outEventStates .= "  <td class=\"f8np1 f_col_sel_19\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('19');\"><b>" . getLngt("SW-Offset") . "</td>";
      $outEventStates .= "  <td class=\"f8np1 f_col_sel_18\" style=\"width:20;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('18');\"><b>" . getLngt("N") . "</td>";
      $outEventStates .= "  <td class=\"f8np1 f_col_sel_01\" style=\"width:240;text-align:left;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('1');\"><b>" . getLngt("Standort") . "</td>";
      $outEventStates .= "  <td class=\"f8np1 f_col_sel_02\" style=\"width:30;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('2');\"><b>" . getLngt("Opt.") . "</td>";
      $outEventStates .= "  <td class=\"f8np1 f_col_sel_03\" style=\"width:30;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('3');\"><b>" . getLngt("Tour") . "</td>";
      $outEventStates .= "  <td class=\"f8np1 f_col_sel_04\" style=\"width:50;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('4');\"><b>" . getLngt("Sort.") . "</td>";
      // $outEventStates .= "  <td class=\"f8np1 f_col_sel_05\" style=\"width:50;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('5');\"><b>" . getLngt("XXX") . "</td>";
      $outEventStates .= "  <td class=\"f8np1 f_col_sel_06\" style=\"width:50;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('6');\"><b>" . getLngt("PLZ") . "</td>";
      $outEventStates .= "  <td class=\"f8np1 f_col_sel_07\" style=\"width:80;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('7');\"><b>" . getLngt("Geog. Breite") . "</td>";
      $outEventStates .= "  <td class=\"f8np1 f_col_sel_08\" style=\"width:80;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('8');\"><b>" . getLngt("Geog. Länge") . "</td>";
      $outEventStates .= "  <td class=\"f8np1 f_col_sel_09\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('9');\"><b>" . getLngt("BEK") . "</td>";
      $outEventStates .= "  <td class=\"f8np1 f_col_sel_10\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('10');\"><b>" . getLngt("MEK") . "</td>";
      $outEventStates .= "  <td class=\"f8np1 f_col_sel_11\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('11');\"><b>" . getLngt("H1") . "</td>";
      $outEventStates .= "  <td class=\"f8np1 f_col_sel_12\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('12');\"><b>" . getLngt("H2") . "</td>";
      $outEventStates .= "  <td class=\"f8np1 f_col_sel_13\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('13');\"><b>" . getLngt("Dispenser") . "</td>";
      $outEventStates .= "  <td class=\"f8np1 f_col_sel_14\" style=\"width:80;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('14');\"><b>" . getLngt("Messzeitpunkt") . "</td>";
      $outEventStates .= "  <td class=\"f8np1 f_col_sel_15\" style=\"width:80;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('15');\"><b>" . getLngt("Meldungen") . "</td>";

      // $outEventStates .= "  <td class=\"f8np1 f_col_sel_16\" style=\"width:40;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('16');\"><b>" . getLngt("SW") . "</td>";
      // $outEventStates .= "  <td class=\"f8np1 f_col_sel_17\" style=\"width:40;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('17');\"><b>" . getLngt("Status") . "</td>";
      $outEventStates .= "</tr>";
      for ($j = 0; $j < $outEventStatesArrayLen; $j++) :
          $outEventStates .= $outEventStatesArray[$j];
      endfor;
      $outEventStates .= "</table>";
   endif;
endif;


// Output service jobs
$outServiceJobs = "";
$outServiceJobJsDate = "";
$jbDateFilter = "";
if ($generateOutput) :
   $outJobArrayLen = count($outJobArray);
   if ($outJobArrayLen > 0) :
      $outServiceJobs .= "<table width=\"100%\" border=\"1\">";
      $outServiceJobs .= "<tr>";
      $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:40;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('0');\"><b>" . getLngt("Auftrag") . "</b></td>";
      $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:40;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('1');\"><b>" . getLngt("Fahrzeug") . "</td>";
      $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:20;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('2');\"><b>" . getLngt("Station") . "</td>";
      $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:120;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('3');\"><b>" . getLngt("Erledigungszeit") . "</td>";
      $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:50;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('4');\"><b>" . getLngt("Automat") . "</td>";
      $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:240;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('5');\"><b>" . getLngt("Standort") . "</td>";
      $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:50;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('6');\"><b>" . getLngt("PLZ") . "</td>";
      // $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:120;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('7');\"><b>" . getLngt("Auftragsbeginn") . "</td>";
      // $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:120;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('8');\"><b>" . getLngt("Annahmezeit") . "</td>";
      // $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:120;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('9');\"><b>" . getLngt("Auftragsende") . "</td>";
      $outServiceJobs .= "  <td class=\"f8np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('10');\"><b>" . getLngt("Wartungsarbeiten") . "</td>";
      $outServiceJobs .= "</tr>";
      for ($j = 0; $j < $outJobArrayLen; $j++) :
          $outServiceJobs .= $outJobArray[$j];
      endfor;
      $outServiceJobs .= "</table>";
   endif;

   $outServiceJobJsDate .= "<script src=\"../include/lib_global.js\" type=\"text/javascript\">\n";
   $outServiceJobJsDate .= "</script>\n";
   $outServiceJobJsDate .= "\n";
   $outServiceJobJsDate .= "<script type=\"text/javascript\">\n";
   $outServiceJobJsDate .= "<!--\n";
   $outServiceJobJsDate .= "function initForm() {\n";
   $outServiceJobJsDate .= "  fillDateFields(1,\"maincontent\",\"servicejobs\",\"\",\"day_from_jb\",\"month_from_jb\",\"year_from_jb\",\"\",\"\",\"\");\n";
   $outServiceJobJsDate .= "  setDateTimeFields(\"maincontent\",\"servicejobs\",".$day_from_jb.",".$month_from_jb.",".$year_from_jb.", \"\", \"\", \"day_from_jb\", \"month_from_jb\", \"year_from_jb\", \"\", \"\", \"\");\n";
   $outServiceJobJsDate .= "  fillDateFields(1,\"maincontent\",\"servicejobs\", \"\", \"day_to_jb\", \"month_to_jb\", \"year_to_jb\", \"\", \"\", \"\");\n";
   $outServiceJobJsDate .= "  setDateTimeFields(\"maincontent\",\"servicejobs\",".$day_to_jb.",".$month_to_jb.",".$year_to_jb.", \"\", \"\", \"day_to_jb\", \"month_to_jb\", \"year_to_jb\", \"\", \"\", \"\");\n";
   $outServiceJobJsDate .= "  FILLDATEFIELDSSTARTYEAR=" . getDateTime("year") . ";\n";
   $outServiceJobJsDate .= "  fillDateFields(1,\"maincontent\",\"servicejobs\",\"\",\"day_prediction\",\"month_prediction\",\"year_prediction\",\"\",\"\",\"\");\n";
   $outServiceJobJsDate .= "  setDateTimeFields(\"maincontent\",\"servicejobs\",".$day_prediction.",".$month_prediction.",".$year_prediction.", \"\", \"\", \"day_prediction\", \"month_prediction\", \"year_prediction\", \"\", \"\", \"\");\n";
   $outServiceJobJsDate .= "}\n";
   $outServiceJobJsDate .= "-->\n";
   $outServiceJobJsDate .= "</script>\n";
   
   // Date ranges
   $jbDateFilter  = "von:\n";      
   $jbDateFilter .= "<select name=\"day_from_jb\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'servicejobs', 'day_from_jb', 'day_from_jb', 'month_from_jb', 'year_from_jb', '', '', '', 'day_to_jb', 'month_to_jb', 'year_to_jb', '', '', '')\"></select>\n";
   $jbDateFilter .= "<select name=\"month_from_jb\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'servicejobs', 'month_from_jb', 'day_from_jb', 'month_from_jb', 'year_from_jb', '', '', '', 'day_to_jb', 'month_to_jb', 'year_to_jb', '', '', '')\"></select>\n";
   $jbDateFilter .= "<select name=\"year_from_jb\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'servicejobs', 'year_from_jb', 'day_from_jb', 'month_from_jb', 'year_from_jb', '', '', '', 'day_to_jb', 'month_to_jb', 'year_to_jb', '', '', '')\"></select>\n";      
   $jbDateFilter .= "&nbsp;&nbsp;bis:\n";     
   $jbDateFilter .= "<select name=\"day_to_jb\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'servicejobs', 'day_to_jb', 'day_from_jb', 'month_from_jb', 'year_from_jb', '', '', '', 'day_to_jb', 'month_to_jb', 'year_to_jb', '', '', '')\"></select>\n";
   $jbDateFilter .= "<select name=\"month_to_jb\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'servicejobs', 'month_to_jb', 'day_from_jb', 'month_from_jb', 'year_from_jb', '', '', '', 'day_to_jb', 'month_to_jb', 'year_to_jb', '', '', '')\"></select>\n";
   $jbDateFilter .= "<select name=\"year_to_jb\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'servicejobs', 'year_to_jb', 'day_from_jb', 'month_from_jb', 'year_from_jb', '', '', '', 'day_to_jb', 'month_to_jb', 'year_to_jb', '', '', '')\"></select>\n";
   $jbDateFilter .= "&nbsp;";

   // Time ranges
   /*
   $jbTimeFilter = "[";
   $jbTimeFilter .= "Ohne<input class=\"smaller\" type=\"radio\" name=\"f_showDateAndTime_jb\" value=\"0\" " . ($f_showDateAndTime_jb == "0" ? "checked" : "") . ">|";
   $jbTimeFilter .= "Mit<input class=\"smaller\" type=\"radio\" name=\"f_showDateAndTime_jb\" value=\"1\" " . ($f_showDateAndTime_jb == "1" ? "checked" : "") . ">";
   $jbTimeFilter .= "Einschränkung auf Zeitintervall von:\n";
   $jbTimeFilter .= "<select name=\"hour_from_jb\" class=\"f8np1\">" . addOptionsFromRange("0","23",$hour_from_jb,"1") . "</select>\n";
   $jbTimeFilter .= "<select name=\"minute_from_jb\" class=\"f8np1\">" . addOptionsFromRange("0","59",$minute_from_jb,"1") . "</select>\n";
   $jbTimeFilter .= "Uhr&nbsp;&nbsp;bis:\n";      
   $jbTimeFilter .= "<select name=\"hour_to_jb\" class=\"f8np1\">" . addOptionsFromRange("0","23",$hour_to_jb,"1") . "</select>\n";
   $jbTimeFilter .= "<select name=\"minute_to_jb\" class=\"f8np1\">" . addOptionsFromRange("0","59",$minute_to_jb,"1") . "</select>\n";
   $jbTimeFilter .= "Uhr]\n";
   */

   // Prediction date
   $jbDatePrediction = "<select name=\"day_prediction\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'servicejobs', 'day_prediction', 'day_prediction', 'month_prediction', 'year_prediction', '', '', '', '', '', '', '', '', '')\"></select>\n";
   $jbDatePrediction .= "<select name=\"month_prediction\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'servicejobs', 'month_prediction', 'day_prediction', 'month_prediction', 'year_prediction', '', '', '', '', '', '', '', '', '')\"></select>\n";
   $jbDatePrediction .= "<select name=\"year_prediction\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'servicejobs', 'year_prediction', 'day_prediction', 'month_prediction', 'year_prediction', '', '', '', '', '', '', '', '', '')\"></select>\n";
endif;


// Output log data
$outLogData = "";
if ($generateOutput) :
   $outLogArrayLen = count($outLogArray);
   if ($outLogArrayLen > 0) :
      $outLogData .= "<table width=\"100%\" border=\"1\">";
      $outLogData .= "<tr><td colspan=\"6\" class=\"f10np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . $f_actionObjId . "<b></td></tr>";
      $outLogData .= "<tr><td class=\"f8np1\" style=\"width:120;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\" onClick=\"logChangeOrderBy('0');\"><b>" . getLngt("Zeitpunkt") . "</b></td>"
                         . "  <td class=\"f8np1\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\" onClick=\"logChangeOrderBy('1');\"><b>" . getLngt("BEK") . "</td>"
                         . "  <td class=\"f8np1\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\" onClick=\"logChangeOrderBy('2');\"><b>" . getLngt("MEK") . "</td>"
                         . "  <td class=\"f8np1\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\" onClick=\"logChangeOrderBy('3');\"><b>" . getLngt("H1") . "</td>"
                         . "  <td class=\"f8np1\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\" onClick=\"logChangeOrderBy('4');\"><b>" . getLngt("H2") . "</td>"
                         . "  <td class=\"f8np1\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\" onClick=\"logChangeOrderBy('5');\"><b>" . getLngt("Dispenser") . "</td>"
                   . "</tr>";
      for ($j = 0; $j < $outLogArrayLen; $j++) :
          $outLogData .= $outLogArray[$j];
      endfor;
      $outLogData .= "</table>";
   endif;
endif;


// Output message data
$outMessageData = "";
if ($generateOutput) :
   $outMessageArrayLen = count($outMessageArray);
   if ($outMessageArrayLen > 0) :
      $outMessageData .= "<table width=\"100%\" border=\"1\">";
      $outMessageData .= "<tr><td colspan=\"6\" class=\"f10np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . $f_actionObjId . "<b></td></tr>";
      $outMessageData .= "<tr><td class=\"f8np1\" style=\"width:100;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . getLngt("Code") . "</b></td>"
                         . "  <td class=\"f8np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . getLngt("Beschreibung") . "</td>"
                         . "  <td class=\"f8np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . getLngt("Text") . "</td>"
                   . "</tr>";
      for ($j = 0; $j < $outMessageArrayLen; $j++) :
          $outMessageData .= $outMessageArray[$j];
      endfor;
      $outMessageData .= "</table>";
   endif;
endif;


$outSuFormData = "";
$outCbFormData = "";
$outCdrFormData = "";
if ($generateOutput) :
   $tmpCol_bg_01 = $colArray["bg"];       $tmpCol_bg_02 = $colArray["green"];      $tmpCol_bg_03 = $colArray["blue"];
   $tmpCol_fg_01 = $colArray["black"];    $tmpCol_fg_02 = $colArray["black"];      $tmpCol_fg_03 = $colArray["black"];      $tmpCol_fg_04 = $colArray["beige"];      $tmpCol_fg_05 = $colArray["light_blue"];
   
   $outSuFormData .= "<table width=\"100%\" border=\"1\">";

   // Service unit data
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td colspan=\"2\" class=\"f8np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . getLngt("Automaten mit Standort") . "</b></td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Automatennummer") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_02 . ";\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_ati_serialno\" value=\"" . $f_su_admin_ati_serialno . "\" size=\"50\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Automatentyp") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_02 . ";\">&nbsp;";
   $outSuFormData .= "    <select name=\"f_su_admin_at_id\">";
   $outSuFormData .= "      <option value=\"\" " . ($f_su_admin_at_id == "" ? "selected" : "") . "></option>";
   $outSuFormData .=        addOptionsFromTable("article AS at, articleitem AS ati, stock AS stk","at.at_id","at.at_match","at.at_match","at.at_id = ati.at_id AND at.at_group LIKE '%,1,%' AND ati.stk_id = stk.stk_id AND stk.stk_pre_id = '" . $rootStockSU . "' ",$f_su_admin_at_id,"DISTINCT");
   $outSuFormData .= "    </select>";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Bemerkung") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_02 . ";\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_ati_data_01\" value=\"" . $f_su_admin_ati_data_01 . "\" size=\"50\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Schwellwert-Offset") . "[€]</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_02 . ";\">&nbsp;";
   $outSuFormData .= "    " . getLngt("BEK") . ":<input type=\"text\" name=\"f_su_admin_ati_data_28_00\" value=\"" . $f_su_admin_ati_data_28_00 . "\" size=\"7\">";
   $outSuFormData .= "    " . getLngt("MEK") . ":<input type=\"text\" name=\"f_su_admin_ati_data_28_01\" value=\"" . $f_su_admin_ati_data_28_01 . "\" size=\"7\">";
   $outSuFormData .= "    " . getLngt("H1") . ":<input type=\"text\" name=\"f_su_admin_ati_data_28_02\" value=\"" . $f_su_admin_ati_data_28_02 . "\" size=\"7\">";
   $outSuFormData .= "    " . getLngt("H2") . ":<input type=\"text\" name=\"f_su_admin_ati_data_28_03\" value=\"" . $f_su_admin_ati_data_28_03 . "\" size=\"7\">";
   $outSuFormData .= "    " . getLngt("Dispenser") . ":<input type=\"text\" name=\"f_su_admin_ati_data_28_04\" value=\"" . $f_su_admin_ati_data_28_04 . "\" size=\"7\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Geographische Breite Automat") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_02 . ";\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_ati_data_02\" value=\"" . $f_su_admin_ati_data_02 . "\" size=\"50\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Geographische Länge Automat") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_02 . ";\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_ati_data_03\" value=\"" . $f_su_admin_ati_data_03 . "\" size=\"50\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Wegezeit und Servicezeit [Min.]") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_02 . ";\">&nbsp;";
   $outSuFormData .= "    <select name=\"f_su_admin_ati_data_24\">";
   $outSuFormData .=        addOptionsFromRange(5,25,$f_su_admin_ati_data_24,"1");
   $outSuFormData .= "    </select>";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Geographische Breite Parkplatz") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_02 . ";\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_ati_data_22\" value=\"" . $f_su_admin_ati_data_22 . "\" size=\"50\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Geographische Länge Parkplatz") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_02 . ";\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_ati_data_23\" value=\"" . $f_su_admin_ati_data_23 . "\" size=\"50\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Präselektion für Tourenoptimierung [Tourennummer]") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_02 . ";\">&nbsp;";
   for ($j = 1; $j <= 7; $j++) :   
       $tmpAtiFieldValue = ${("f_su_admin_ati_data_21_" . $j)};
       $outSuFormData .= substr($calWeekDays[($j - 1)], 0, 2) . "&nbsp;";
       $outSuFormData .= "    <select name=\"f_su_admin_ati_data_21_" . $j . "\">";
       $outSuFormData .= "      <option value=\"\" " . ($tmpAtiFieldValue == "" ? "selected" : "") . "></option>";
       for ($k = 1; $k <= $maxNumOfTours; $k++) :
           $outSuFormData .= "      <option value=\"" . $k . "\" " . ($tmpAtiFieldValue == $k ? "selected" : "") . ">" . $k . "</option>";
       endfor;
       $outSuFormData .= "    </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
   endfor;
   $outSuFormData .= "    <b>" . getLngt("ALLE") . "</b>&nbsp;&nbsp;";
   $outSuFormData .=      "<select id=\"f_su_admin_ati_data_21_all\" name=\"f_su_admin_ati_data_21_all\" onChange=\"setPreselectedVehicles();\">";
   $outSuFormData .= "      <option value=\"\" selected></option>";
   for ($k = 1; $k <= $maxNumOfTours; $k++) :
       $outSuFormData .= "      <option value=\"" . $k . "\">" . $k . "</option>";
   endfor;
   $outSuFormData .= "    </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
   
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Aktionen") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_02 . ";\">&nbsp;";
   $outSuFormData .= "    " . defineButtonType08("Automatendaten speichern", "action_store_form_serviceunit", "finishFormServiceUnitStore();", "200", "left", "2");
   $outSuFormData .= "    " . defineButtonType08("Automatendaten entfernen", "action_remove_form_serviceunit", "finishFormServiceUnitRemove();", "200", "left", "2");
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";

   // Stock data (service stations)
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td colspan=\"2\" class=\"f8np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . getLngt("Standorte, Haltestellen") . "</b></td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Standort") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_03 . ";\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_stk_name\" value=\"" . $f_su_admin_stk_name . "\" size=\"50\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Info") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_03 . ";\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_stk_barcode\" value=\"" . $f_su_admin_stk_barcode . "\" size=\"5\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Strasse, Hausnr.") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_03 . ";\">&nbsp;";
   $outSuFormData .= "    <input type=\"hidden\" name=\"f_su_admin_ad_id\" value=\"" . $f_su_admin_ad_id . "\">";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_ad_street\" value=\"" . $f_su_admin_ad_street . "\" size=\"40\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_stk_hsno\" value=\"" . $f_su_admin_stk_hsno . "\" size=\"10\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("PLZ, Ort") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_03 . ";\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_ad_zipcode\" value=\"" . $f_su_admin_ad_zipcode . "\" size=\"10\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_ad_city\" value=\"" . $f_su_admin_ad_city . "\" size=\"40\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Aktionen") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_03 . ";\">&nbsp;";
   $outSuFormData .= "    " . defineButtonType08("Standortdaten speichern", "action_store_form_stock", "finishFormStock();", "200", "left", "2");
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "</table>";

   // Cash boxes
   $outCbFormData .= "<table width=\"100%\" border=\"1\">";
   $outCbFormData .= "<tr>";
   $outCbFormData .= "  <td colspan=\"2\" class=\"f8np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["gold"] . ";\"><b>" . getLngt("Geldkassetten") . "</b></td>";
   $outCbFormData .= "</tr>";
   $outCbFormData .= "<tr>";
   $outCbFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outCbFormData .= "    <b>" . getLngt("Nummer") . "</b>&nbsp;:&nbsp;";
   $outCbFormData .= "  </td>";
   $outCbFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_fg_04 . ";\">&nbsp;";
   $outCbFormData .= "    <input type=\"text\" name=\"f_cb_admin_ati_serialno\" value=\"" . $f_cb_admin_ati_serialno . "\" size=\"50\">";
   $outCbFormData .= "  </td>";
   $outCbFormData .= "</tr>";
   $outCbFormData .= "<tr>";
   $outCbFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outCbFormData .= "    <b>" . getLngt("Kassettentyp") . "</b>&nbsp;:&nbsp;";
   $outCbFormData .= "  </td>";
   $outCbFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_fg_04 . ";\">&nbsp;";
   $outCbFormData .= "    <select name=\"f_cb_admin_at_id\">";
   $outCbFormData .= "      <option value=\"\" " . ($f_cb_admin_at_id == "" ? "selected" : "") . "></option>";
   $outCbFormData .=        addOptionsFromTable("article AS at","at_id","at_match","at.at_match","at_group LIKE '%,2,%' ",$f_cb_admin_at_id,"DISTINCT");
   $outCbFormData .= "    </select>";
   $outCbFormData .= "  </td>";
   $outCbFormData .= "</tr>";
   $outCbFormData .= "<tr>";
   $outCbFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outCbFormData .= "    <b>" . getLngt("Aktueller Standort") . "</b>&nbsp;:&nbsp;";
   $outCbFormData .= "  </td>";
   $outCbFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_fg_04 . ";\">&nbsp;";
   $outCbFormData .= "    <select name=\"f_cb_admin_stk_id\">";
   $outCbFormData .= "      <option value=\"\" " . ($f_cb_admin_stk_id == "" ? "selected" : "") . "></option>";
   $outCbFormData .=        addOptionsFromTable("articleitem AS ati, stock AS stk, article AS at, stock AS stk2","stk2.stk_id","stk2.stk_name","stk2.stk_name","ati.at_id = at.at_id AND at.at_group LIKE '%,1,%' AND ati.stk_id = stk.stk_id AND stk.stk_pre_id = '" . $rootStockSU . "' AND stk2.stk_obj_type = 'ati' AND stk2.stk_obj_id = ati.ati_id", $f_cb_admin_stk_id);
   $outCbFormData .= "    </select>";
   $outCbFormData .= "  </td>";
   $outCbFormData .= "</tr>";
   $outCbFormData .= "<tr>";
   $outCbFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outCbFormData .= "    <b>" . getLngt("Aktionen") . "</b>&nbsp;:&nbsp;";
   $outCbFormData .= "  </td>";
   $outCbFormData .= "  <td class=\"f8np1\" style=\"text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_fg_04 . ";\">&nbsp;";
   $outCbFormData .= "    " . defineButtonType08("Kassettendaten speichern", "action_store_form_cb", "finishFormCashBoxStore();", "200", "left", "2");
   $outCbFormData .= "    " . defineButtonType08("Kassettendaten entfernen", "action_remove_form_cb", "finishFormCashBoxRemove();", "200", "left", "2");
   $outCbFormData .= "  </td>";
   $outCbFormData .= "</tr>";
   $outCbFormData .= "</table>";

   // Card rolls
   $outCdrFormData .= "<table width=\"100%\" border=\"1\">";
   $outCdrFormData .= "<tr>";
   $outCdrFormData .= "  <td colspan=\"2\" class=\"f8np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\"><b>" . getLngt("Kartenrollen") . "</b></td>";
   $outCdrFormData .= "</tr>";
   $outCdrFormData .= "<tr>";
   $outCdrFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outCdrFormData .= "    <b>" . getLngt("Nummernkreis") . "</b>&nbsp;:&nbsp;";
   $outCdrFormData .= "  </td>";
   $outCdrFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_fg_05 . ";\">&nbsp;";
   $outCdrFormData .= "    <input type=\"text\" name=\"f_cdr_admin_ati_serialno_from\" value=\"" . $f_cdr_admin_ati_serialno_from . "\" size=\"25\">";
   $outCdrFormData .= "    &nbsp;-&nbsp;";
   $outCdrFormData .= "    <input type=\"text\" name=\"f_cdr_admin_ati_serialno_to\" value=\"" . $f_cdr_admin_ati_serialno_to . "\" size=\"25\">";
   $outCdrFormData .= "  </td>";
   $outCdrFormData .= "</tr>";   
   $outCdrFormData .= "<tr>";
   $outCdrFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outCdrFormData .= "    <b>" . getLngt("Kartenrollentyp") . "</b>&nbsp;:&nbsp;";
   $outCdrFormData .= "  </td>";
   $outCdrFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_fg_05 . ";\">&nbsp;";
   $outCdrFormData .= "    <select name=\"f_cdr_admin_at_id\">";
   $outCdrFormData .= "      <option value=\"\" " . ($f_cdr_admin_at_id == "" ? "selected" : "") . "></option>";
   $outCdrFormData .=        addOptionsFromTable("article AS at","at_id","at_match","at.at_match","(at.at_group LIKE '%,5,%')",$f_cdr_admin_at_id,"DISTINCT");
   $outCdrFormData .= "    </select>";
   $outCdrFormData .= "  </td>";
   $outCdrFormData .= "</tr>";
   $outCdrFormData .= "<tr>";
   $outCdrFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outCdrFormData .= "    <b>" . getLngt("Aktueller Standort") . "</b>&nbsp;:&nbsp;";
   $outCdrFormData .= "  </td>";
   $outCdrFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_fg_05 . ";\">&nbsp;";
   $outCdrFormData .= "    <select name=\"f_cdr_admin_stk_id\">";
   $outCdrFormData .= "      <option value=\"\" " . ($f_cdr_admin_stk_id == "" ? "selected" : "") . "></option>";
   $outCdrFormData .=        addOptionsFromTable("articleitem AS ati, stock AS stk, article AS at, stock AS stk2","stk2.stk_id","stk2.stk_name","stk2.stk_name","ati.at_id = at.at_id AND at.at_group LIKE '%,1,%' AND ati.stk_id = stk.stk_id AND stk.stk_pre_id = '" . $rootStockSU . "' AND stk2.stk_obj_type = 'ati' AND stk2.stk_obj_id = ati.ati_id", $f_cdr_admin_stk_id);
   $outCdrFormData .= "    </select>";
   $outCdrFormData .= "  </td>";
   $outCdrFormData .= "</tr>";
   $outCdrFormData .= "<tr>";
   $outCdrFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outCdrFormData .= "    <b>" . getLngt("Palette") . "</b>&nbsp;:&nbsp;";
   $outCdrFormData .= "  </td>";
   $outCdrFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_fg_05 . ";\">&nbsp;";
   $outCdrFormData .= "    <input type=\"text\" name=\"f_cdr_admin_palette\" value=\"" . $f_cdr_admin_palette . "\" size=\"4\">";
   $outCdrFormData .= "  </td>";
   $outCdrFormData .= "</tr>";

   $outCdrFormData .= "<tr>";
   $outCdrFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outCdrFormData .= "    <b>" . getLngt("Fehlende Kartenrollen") . "</b>&nbsp;:&nbsp;";
   $outCdrFormData .= "  </td>";
   $outCdrFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_fg_05 . ";\">&nbsp;";
   $outCdrFormData .= "    <textarea id=\"f_cdr_admin_ati_serialno_missing\" name=\"f_cdr_admin_ati_serialno_missing\" cols=\"50\" rows=\"4\"></textarea>";  //  onblur=\"javascript:checkCdrSerialNoMissing();\"
   $outCdrFormData .= "  </td>";
   $outCdrFormData .= "</tr>";
   $outCdrFormData .= "<tr>";
   $outCdrFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outCdrFormData .= "    <b>" . getLngt("Aktionen") . "</b>&nbsp;:&nbsp;";
   $outCdrFormData .= "  </td>";
   $outCdrFormData .= "  <td class=\"f8np1\" style=\"text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_fg_05 . ";\">&nbsp;";
   $outCdrFormData .= "    " . defineButtonType08("Kartenrollendatendaten speichern", "action_store_form_cdr", "finishFormCardrollsStore();", "200", "left", "2");
   // $outCdrFormData .= "    " . defineButtonType08("Kartenrollendatendaten entfernen", "action_remove_form_cdr", "finishFormCardrollsRemove();", "200", "left", "2");
   $outCdrFormData .= "  </td>";
   $outCdrFormData .= "</tr>";
   $outCdrFormData .= "</table>";
endif;


// Output report entries and system messages
$outReport = "";
$outReportArrayLen = count($outReportArray);
if ($outReportArrayLen > 0) :
   $maskDisplay00Switch = "1";   // Activate output if there is at least one message to be displayed
   $outReport .= "<table width=\"100%\" border=\"0\">";
   for ($j = 0; $j < $outReportArrayLen; $j++) :
       $outReport .= "<tr><td><span class=\"f8np1_red\">" . $outReportArray[$j] . "</span></td></tr>";
   endfor;
   $outReport .= "</table>";
endif;

// $xTest = getServiceUnits();
// print_r($xTest);
// echo "f_map_is_active = " . $f_map_is_active . "<br>";
?>


<?php if (!$isFirefox) : ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "../include/strict.dtd">
<?php endif; ?>

<html>

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

<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
  <?php include_once ("../css/navigation.css.php"); ?>
  .navfixed {position:fixed; top:0px; background-color: #97bcFF; width: 100%;}
  .navlabel {width: 170px; height: 22px;}
</style>

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

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

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



function mcRound(value, decimals) {
	var retVal = Number(Math.round(value+'e'+decimals)+'e-'+decimals);
	if (isNaN(retVal)) {retVal = 0;};
  return retVal;
}

function mcIsInt(n) {
    return Number(n) === n && n % 1 === 0;
}

function mcIsFloat(n) {
    return Number(n) === n && n % 1 !== 0;
}

function decodeSpecialChars(encodedInput) {
  // Das "Wörterbuch" muss mit der PHP-Version synchron sein.
  // Hier sind die Paare jedoch umgedreht: 'kodiert' -> 'dekodiert'.
  const replacements = {
    '__spc__': ' ',
    '__plus__': '+',
    '__amp__': '&',
    '__qmark__': '?'
  };
  let decodedString = encodedInput;
  // Iterate rules in "replacements"
  for (const [encoded, decoded] of Object.entries(replacements)) {
    // Ersetze alle Vorkommen des kodierten Werts durch das Originalzeichen.
    decodedString = decodedString.replaceAll(encoded, decoded);
  }
  return decodedString;
}

// Sum of cash box amounts and weights for each tour
var tourSumArray = Array(<?php echo $maxNumOfTours ?>);
var tourSumArrayLen = tourSumArray.length; 
var tourWeightArray = Array(<?php echo $maxNumOfTours ?>);
var tourCountArray = Array(<?php echo $maxNumOfTours ?>);
<?php
// print_r($tourCountArray); echo "<br><br>\n\n";
for ($i = 1; $i <= $maxNumOfTours; $i++) :
    echo "tourSumArray[" . $i . "] = " . $tourSumArray[$i] . "\n";
    echo "tourWeightArray[" . $i . "] = " . $tourWeightArray[$i] . "\n";
    echo "tourCountArray[" . $i . "] = " . $tourCountArray[$i] . "\n";
endfor;
?>
var tourSumOutput = '';
var tourWeightOutput = '';
var tourCountOutput = '';
for (var i = 1; i <= tourSumArrayLen; i++) {
   tourSumOutput = tourSumOutput.concat('Tour ' + i + ': ' + mcRound(tourSumArray[i],2) + ' | ');
   tourWeightOutput = tourWeightOutput.concat('Tour ' + i + ': ' + mcRound(tourWeightArray[i],2) + ' | ');
   tourCountOutput = tourCountOutput.concat('Tour ' + i + ': ' + tourCountArray[i] + ' | ');
}
// $('#tour_amounts').html('<b> ' + tourSumOutput + ' ' + tourWeightOutput + ' ' + tourCountOutput + '</b>');  // body.onLoad()

var cbWeightFactorArray = Array(<?php echo $cbWeightFactors[0] ?>,<?php echo $cbWeightFactors[1] ?>,<?php echo $cbWeightFactors[2] ?>,<?php echo $cbWeightFactors[3] ?>,<?php echo $cbWeightFactors[4] ?>);

// Current focused select box to remember the current tour
var remCurrentValueOfFocusedTour = 0;
var remCurrentValueOfCashbox00 = 0;
var remCurrentValueOfCashbox01 = 0;
var remCurrentValueOfCashbox02 = 0;
var remCurrentValueOfCashbox03 = 0;
var remCurrentValueOfCashbox04 = 0;

function setCurrentValueOfFocusedTour(tour_no, cb_00, cb_01, cb_02, cb_03, cb_04) {
	if (tour_no != '') {
	   remCurrentValueOfFocusedTour = tour_no;
     remCurrentValueOfCashbox00 = cb_00;
     remCurrentValueOfCashbox01 = cb_01;
     remCurrentValueOfCashbox02 = cb_02;
     remCurrentValueOfCashbox03 = cb_03;
     remCurrentValueOfCashbox04 = cb_04;
	};
}

var checkboxStateVectorWasChanged = false;

var currentIdOfNavContainer = '';
var remCurrentIdOfNavContainer = '';
var remOldIdOfNavContainer = '';

// Change navigation container to be fixed
function changeNavState(currentIdOfNavContainer) {
	if (currentIdOfNavContainer != '') {
	   // var elemZIndex = $(currentIdOfNavContainer).zIndex();
	   var elemZIndex = $(currentIdOfNavContainer).css('zIndex');
     $(window).scroll(function(){
     	 // Handle old one
	      if (currentIdOfNavContainer != remCurrentIdOfNavContainer) {
	      	  if (remCurrentIdOfNavContainer) {
               $(remCurrentIdOfNavContainer).removeClass('navfixed');
               $(remCurrentIdOfNavContainer).css('zIndex','0');
            }
            remOldIdOfNavContainer = remCurrentIdOfNavContainer;
 	          remCurrentIdOfNavContainer = currentIdOfNavContainer;
	     	 }
     	  // Handle new one
         if ($(this).scrollTop() > 175) {
            $(currentIdOfNavContainer).addClass('navfixed');
            $(currentIdOfNavContainer).css('zIndex','5');
         } else {
            $(currentIdOfNavContainer).removeClass('navfixed');
            $(currentIdOfNavContainer).css('zIndex','0');
         }
     });
  };
};

// Before showing or hiding the container the navigation styles has to be set
function preChangeHideShow(item,activeState) {
	if (item != '') {
		 var tmpNum = item.substr(item.length - 1);
		 currentIdOfNavContainer = '#nav0' + tmpNum;
		 var itemNavAction = '#' + item + 'Action';
	   if (activeState == 'on') {
		    $(itemNavAction).prop('checked', true);
		    $(itemNavAction).button('refresh');
		    if (item) {changeNavState(currentIdOfNavContainer)};
	   }
	   if (activeState == 'off') {
		    $(itemNavAction).prop('checked', false);
		    $(itemNavAction).button('refresh');
		    if (currentIdOfNavContainer == remCurrentIdOfNavContainer) {
		    	 currentIdOfNavContainer = remOldIdOfNavContainer;
		    	 if (item) {changeNavState(currentIdOfNavContainer)};
		    }
	   }
	   changeHideShow2(item,activeState);
	}
};

function setCheckboxStateVectorWasChanged() {
	checkboxStateVectorWasChanged = true;
}

function removeSystemMessage() {
  preChangeHideShow('maskDisplay00','off');
  vSetElementContent('maskDisplay00Content', '');
}

function suCheckAll(numOfRows) {
  for (i = 0; i < numOfRows; i++) {
  	if (document.getElementsByName('f_su_chkbx[]')[i]) {
	     document.getElementsByName('f_su_chkbx[]')[i].checked = true;
	  }
	}
	setCheckboxStateVectorWasChanged();
}

function suUncheckAll(numOfRows) {
  for (i = 0; i < numOfRows; i++) {
  	if (document.getElementsByName('f_su_chkbx[]')[i]) {
	     document.getElementsByName('f_su_chkbx[]')[i].checked = false;
	  }
  }
  setCheckboxStateVectorWasChanged();
}

function jsItemSetCSS(item, cssKey, cssValue) {
	if (item && cssKey && cssValue) {
     var cssKeyLen = cssKey.length;
     for ( var i = 0; i < cssKeyLen; i++ ) {
         $('#' + item).css(cssKey[i], cssValue[i]);
     }
  }
}

function ajaxRequestContainerHtmlGet(url, item, content) {
  $.ajax({
    url: url,
    type: 'GET',
    dataType: 'html',
    data: content,
    async: false,
    cache: false
  }).done(function ( data ) {
    // $('#' + item).append(data);
    $('#' + item).html(data);
  });
}

function finishPage(f_act) {
	disableItems(true);
	document.forms[0].f_act.value = f_act;
	document.forms[0].initialPageCall.value = '1';
	document.forms[0].submit();
}	

function preFinishPage(f_act) {
	var doFinishPage = true;
	if (checkboxStateVectorWasChanged) {
		 doFinishPage = false;
		 if (confirm('<?php echo getLngt("Die Auswahl (Checkboxen) wurde verändert! Möchten Sie trotzdem fortfahren? Ansonsten bitte den Auswahlzustand sichern!") ?>')) {
		 	  doFinishPage = true;
		 }
  }
	if (doFinishPage) {
     finishPage(f_act);
  }
}

function suCheckboxes() {
  var frm = document.forms[0]; 
  if (frm.f_pt_action_1.options[1].selected == true) {
     frm.f_suLoadStates.value = '1';
     if (confirm('<?php echo getLngt("Möchten Sie den aktuellen Auswahlzustand verwerfen?") ?>')) {
        finishPage('');
     }
  }
  if (frm.f_pt_action_1.options[2].selected == true) {
     frm.f_suLoadStates.value = '3';
     if (confirm('<?php echo getLngt("Möchten Sie die kritischen der aktuellen Auswahl zufügen?") ?>')) {
        finishPage('');
     }
  }
  if (frm.f_pt_action_1.options[3].selected == true) {
  	 if (confirm('<?php echo getLngt("Möchten Sie den aktuellen Auswahlzustand verwerfen?") ?>')) {
        suCheckAll(<?php echo $numOfRowsSU ?>);
     }
  }
  if (frm.f_pt_action_1.options[4].selected == true) {
  	 if (confirm('<?php echo getLngt("Möchten Sie den aktuellen Auswahlzustand verwerfen?") ?>')) {
        suUncheckAll(<?php echo $numOfRowsSU ?>);
     }
  }
  if (frm.f_pt_action_1.options[5].selected == true) {
  	 if (confirm('<?php echo getLngt("Möchten Sie den gespeicherten Auswahlzustand überschreiben?") ?>')) {
        finishPage('savePT');
     }
  }
  if (frm.f_pt_action_1.options[6].selected == true) {
     frm.f_suLoadStates.value = '2';
     if (confirm('<?php echo getLngt("Möchten Sie den gespeicherten Auswahlzustand laden?") ?>')) {
        finishPage('');
     }
  }
  if (frm.f_pt_action_1.options[7].selected == true) {
     frm.f_suLoadStates.value = '4';
     if (confirm('<?php echo getLngt("Möchten Sie den aktuellen Auswahlzustand verwerfen?") ?>')) {
        finishPage('');
     }
  }
  if (frm.f_pt_action_1.options[8].selected == true) {
     frm.f_suLoadStates.value = '5';
     if (confirm('<?php echo getLngt("Möchten Sie die Fahrzeugvorbelegungen der aktuellen Auswahl zufügen?") ?>')) {
        finishPage('');
     }
  }
  setSelectedValue('f_pt_action_1', '0');
  setCheckboxStateVectorWasChanged();
};

function suOptimize() {
  if (confirm('<?php echo getLngt("Möchten Sie für den angezeigten Auswahlzustand eine Optimierung vornehmen? Der aktuelle Auswahlzustand wird automatisch gespeichert!") ?>')) {
  	 // First check all service units being checked have to have a vehicle
     var numOfRows = <?php echo $numOfRowsSU ?>;
     var doOptimize = true;
     var msg = '';
     var f_su_tour_no = Array();
     var numOfTours = <?php echo $f_su_tour_no_len ?>;
     var count_tour_no = Array(numOfTours);
     var suId, elemIndex, len, pos;

     // Init counter array
     for (var i = 1; i <= numOfTours; i++) {
     	   count_tour_no[i] = 0;
     }

     // Get all vehicle selects
     var selects = document.getElementsByTagName('select');
     var selLen = selects.length;
     for (var i = 0; i < selLen; i++) {
     	   if (selects[i].name.substring(0,12) == 'f_su_tour_no') {
     	   	  // Get number of the service unit out of the name of the current <select> tag
     	   	  elemIndex = selects[i].name.substring(13,(selects[i].name.length - 1));
            len = selects[i].length;
            for(var j=0; j<len; ++j) {
               if (selects[i].options[j].selected == true) {
              	  f_su_tour_no[elemIndex] = selects[i].options[j].value;
                  // alert(elemIndex + ' :: ' + selects[i].name + ' :: ' + selects[i].options[j].value);
               }
            }
         }
     }

     // Iterate all service units
     for (var i = 0; i < numOfRows; i++) {
     	   if (document.getElementsByName('f_su_chkbx[]')[i]) {
	          if (document.getElementsByName('f_su_chkbx[]')[i].checked == true) {
	             suId = document.getElementsByName('f_su_chkbx[]')[i].value;
	          	 if (suId != '') {
                  count_tour_no[f_su_tour_no[suId]]++;
	          	    if (f_su_tour_no[suId] == '') {
	          	       doOptimize = false;
	          	       msg += ' [' + suId + ']';
	          	    }
	          	 } else {
	          	 	  doOptimize = false;
	          	 	  msg += ' [' + suId + ']';
	          	 }
	          }
	       }
	   }

	   // Check tour having too many jobs and therefore being too long
	   if (doOptimize) {
        for (var i = 1; i <= numOfTours; i++) {
        	   if (count_tour_no[i] > 100) {
        	      doOptimize = false;
        	      msg += '<?php echo getLngt("Folgende Tour hat zu viele Aufträge:") ?>' + ' ' + i;
        	      break;
        	   }
        }
     }

     if (doOptimize) {
        finishPage('optimizePT');
     } else {
     	  alert('<?php echo getLngt("Die Optimierung wurde nicht ausgeführt! Keine Fahrzeugzuordnung bei folgenden betroffene Einheiten:") ?>' + msg);
     }
  }	
}

function suMakeJob() {
  if (confirm('<?php echo getLngt("Möchten Sie auf Basis der angezeigten Sortierung Fuhraufträge erzeugen?") ?>')) {
     finishPage('makeJobPT');
  }	
}

function tvSetDefaults() {
	var frm = document.forms[0];
	<?php
    // Get global DEFAULT threshold values
    $thresholdDefaultValuesArray = getThresholdValues($suAtIdArray, "1");     	
	  for ($a = 0; $a < $suAtIdArrayLen; $a++) :
      $atId = $suAtIdArray[$a];
      for ($t = 0; $t < $maxNumOfAtiDataFields; $t++) :
          echo "frm.f_tv_" . $atId . "_" . pad(($t + 1),2) . ".value = '" . $thresholdDefaultValuesArray[$atId][$t] . "';";
      endfor;
    endfor;
  ?>
	// preFinishPage('');
	finishPage('');
}

function suChangeOrderBy(col) {
	if (col != '') {
		 document.forms[0].f_su_orderByCol.value = col;
		 finishPage('');
  }
}

function jbChangeOrderBy(col) {
	if (col != '') {
		 document.forms[0].f_jb_orderByCol.value = col;
		 finishPage('');
  }
}

function logChangeOrderBy(col) {
	if (col != '') {
		 document.forms[0].f_log_orderByCol.value = col;
		 finishPage('');
  }
}

function openMap(stkId) {
  var widthPopupWin = 1200;
  var heightPopupWin = 800;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../locating/map_stock.php?stk_id=" + stkId,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openTourMap() {
  var widthPopupWin = 1200;
  var heightPopupWin = 800;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../locating/map.php","","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openImportSOAP() {
  var widthPopupWin = 600;
  var heightPopupWin = 400;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../import/import_SOAP_HHA.php?f_act=executeImport","","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

// Every element (service unit serialno, job ID, zipcode, ...) has some possibilities to be selected for
function selAction(actionObjType, actionObjId, actionObjIdInfo) {
	var frm = document.forms[0];
	// IMPORTANT: Init parameters to be submitted because no DB operation will be executed for the next page submit for a specified service unit !!!
	frm.f_actionObjType.value = '';
	frm.f_actionObjId.value = '';
	frm.f_actionID.value = '';
	// Define selected form parameters
	frm.actionObjType.value = actionObjType;
	frm.actionObjId.value = actionObjId;
  if (actionObjType == 'ati_serialno') {
  	 vSetElementContent('ac_title', '<b>Automat&nbsp;' + decodeSpecialChars(actionObjId) + '</b>&nbsp;&nbsp;' + actionObjIdInfo);
  	 vSetElementContent('ac_01', '<a href="javascript:execAjaxAction(\'' + actionObjType + '\',\'' + actionObjId + '\',' + '\'101\'' + ')"><?php echo getLngt("Standort auf der Karte") ?></a>');
  	 vSetElementContent('ac_02', '<a href="javascript:<?php echo ($maskClassicMode ? "execAction" : "execAjaxAction") ?>(\'' + actionObjType + '\',\'' + actionObjId + '\',' + '\'102\'' + ')"><?php echo getLngt("Zustandsverlauf anzeigen") ?></a>');
  	 vSetElementContent('ac_03', '<a href="javascript:execAction(\'' + actionObjType + '\',\'' + actionObjId + '\',' + '\'103\'' + ')"><?php echo getLngt("Aufträge anzeigen") ?></a>');
  	 vSetElementContent('ac_04', '<a href="javascript:<?php echo ($maskClassicMode ? "execAction" : "execAjaxAction") ?>(\'' + actionObjType + '\',\'' + actionObjId + '\',' + '\'104\'' + ')"><?php echo getLngt("Betriebsmeldungen anzeigen") ?></a>');
  	 vSetElementContent('ac_05', '<a href="javascript:execAction(\'' + actionObjType + '\',\'' + actionObjId + '\',' + '\'105\'' + ')"><?php echo getLngt("Verwaltung") ?></a>');
  	 vSetElementContent('ac_06', '');
  	 vSetElementContent('ac_07', '');

  	 // State of the service unit (Disabled)
  	 var suStateDisabled = "";
  	 ajaxRequestGet('../include/ajaxReqLib.php', 'mode=0&db_table=articleitem&db_id_field=ati_serialno&search_value=' + encodeURIComponent(decodeSpecialChars(actionObjId)) + '&db_return_field=ati_data_30');
  	 if (retValue == '1') {
  	 	  suStateDisabled = "checked";
  	 }
     vSetElementContent('ac_08', '<?php echo getLngt("Automat deaktiviert") ?>&nbsp;:&nbsp;&nbsp;<input type="checkbox" id="f_su_content_108" name="f_su_content_108" value="1" ' + suStateDisabled + ' onChange="javascript:execAjaxAction(\'' + actionObjType + '\',\'' + actionObjId + '\',' + '\'108\'' + ')">');

  	 // Notice associated to a service unit
  	 ajaxRequestGet('../include/ajaxReqLib.php', 'mode=0&db_table=articleitem&db_id_field=ati_serialno&search_value=' + encodeURIComponent(decodeSpecialChars(actionObjId)) + '&db_return_field=ati_data_25');
     vSetElementContent('ac_09', '<input type="text" name="f_su_content_109" value="' + retValue + '" size="50"><br><a href="javascript:execAjaxAction(\'' + actionObjType + '\',\'' + actionObjId + '\',' + '\'109\'' + ')"><?php echo getLngt("Notiz speichern") ?></a>');
  }
  if (actionObjType == 'jb_id') {
  	 vSetElementContent('ac_title', '<b>Auftrag&nbsp;' + actionObjId + '</b>&nbsp;&nbsp;' + actionObjIdInfo);
  	 vSetElementContent('ac_01', '<a href="../tools/jb_detail_MC.php?jbId=' + actionObjId + '" target="_blank"><?php echo getLngt("Auftragsdetails") ?></a>');
  	 vSetElementContent('ac_02', '');
  	 vSetElementContent('ac_03', '');
  	 vSetElementContent('ac_04', '');
  	 vSetElementContent('ac_05', '');
  	 vSetElementContent('ac_06', '');
  	 vSetElementContent('ac_07', '');
  	 vSetElementContent('ac_08', '');
  	 vSetElementContent('ac_09', '');
  }
  myhide('contentcontainer');
  myshow('actioncontainer');
}

// Execute a selected action for a specified object
function execAction(actionObjType, actionObjId, actionID) {
	myhide('actioncontainer');
	var frm = document.forms[0];
  if (actionObjType != '' && actionObjId != '' && actionID != '') {
  	 frm.f_actionObjType.value = actionObjType;
	   frm.f_actionObjId.value = actionObjId;
	   frm.f_actionID.value = actionID;
	   finishPage('processAction');
  }
}

// Execute a selected action for a specified object
function execAjaxAction(actionObjType, actionObjId, actionID) {
	// myhide('actioncontainer');
	var frm = document.forms[0];
	var htmlOutput = '';
	var cssKey = [];
	var cssValue = [];
  if (actionObjType != '' && actionObjId != '' && actionID != '') {
     if (actionObjType == 'ati_serialno') {
     	  var atId = '0';
     	  var atiData25 = '';
     	  var atiData30 = '';
        if (actionID == '101') {
           ajaxRequestGet('../include/ajaxReqLib.php', 'mode=0&db_table=articleitem&db_id_field=ati_serialno&search_value=' + encodeURIComponent(decodeSpecialChars(actionObjId)) + '&db_return_field=stk_id');
           if (retValue != '') {
              openMap(retValue);    // Open map tith stock ID
           }
        }
        // Service unit history data
        if (actionID == '102') {
        	 <?php
        	   $jsTv = "";
        	   /*
        	   for ($j = 1; $j <= 25; $j++) :
        	       $jsTv .= "&value_". pad($j,2) . "=" . ${("f_tv_" . pad($j,2))};
        	   endfor;
        	   */
        	 ?>
        	 ajaxRequestContainerHtmlGet('../illt/ajaxReqIllt.php', 'cc_01', 'mode=getSuHistoryData&actionObjType=' + actionObjType + '&actionObjId=' + encodeURIComponent(decodeSpecialChars(actionObjId)) + '&filter_1=<?php echo $f_log_filter_1 ?>&rootStockSU=<?php echo $rootStockSU ?><?php echo $jsTv ?>');
        	 myshow('contentcontainer');
        }
        // Service unit messages
        if (actionID == '104') {
        	 // cssKey = ['background-color'];
        	 // cssValue = ['#BBBBBB'];
        	 // jsItemSetCSS('contentcontainer', cssKey, cssValue);
        	 ajaxRequestContainerHtmlGet('../illt/ajaxReqIllt.php', 'cc_01', 'mode=getSuMessageData&actionObjType=' + actionObjType + '&actionObjId=' + encodeURIComponent(decodeSpecialChars(actionObjId)));
        	 myshow('contentcontainer');
        }
        if (actionID == '108' || actionID == '109') {
        	 ajaxRequestGet('../include/ajaxReqLib.php', 'mode=0&db_table=articleitem&db_id_field=ati_serialno&search_value=' + encodeURIComponent(decodeSpecialChars(actionObjId)) + '&db_return_field=at_id');
  	       atId = retValue;
           ajaxRequestGet('../include/ajaxReqLib.php', 'mode=0&db_table=articleitem&db_id_field=ati_serialno&search_value=' + encodeURIComponent(decodeSpecialChars(actionObjId)) + '&db_return_field=ati_data_25');
  	       atiData25 = retValue;
           ajaxRequestGet('../include/ajaxReqLib.php', 'mode=0&db_table=articleitem&db_id_field=ati_serialno&search_value=' + encodeURIComponent(decodeSpecialChars(actionObjId)) + '&db_return_field=ati_data_30');
           atiData30 = retValue;
        }
        if (actionID == '108') {
           if (frm.f_su_content_108) {
           	  var su = '#f_su_content_108';
           	  var atiData30 = "";
              if ($(su).is(':checked')) {
              	var atiData30 = "1";
           	  }
              ajaxRequestGet('../include/ajaxReqLib.php', 'mode=100&db_table=articleitem&db_id_field=ati_serialno&search_value=' + encodeURIComponent(decodeSpecialChars(actionObjId)) + '&db_op_field=ati_data_30&new_content=' + atiData30);

              if (atiData30 != '') {
                 // vSetElementContent(actionObjId + '_notice', 'D');        // Set deactivated flag into the table cell
                 // Reset DB field for messages
                 ajaxRequestGet('../include/ajaxReqLib.php', 'mode=100&db_table=articleitem&db_id_field=ati_serialno&search_value=' + encodeURIComponent(decodeSpecialChars(actionObjId)) + '&db_op_field=ati_data_17&new_content=');
                 vSetElementContent(actionObjId + '_msgs', '');        // Set asterisk into the table cell
              } else {
                 // vSetElementContent(actionObjId + '_notice', '&nbsp;');   // Remove asterisk out of the table cell
              }
           }
        }
        if (actionID == '109') {
           if (frm.f_su_content_109) {
           	  atiData25 = frm.f_su_content_109.value;
              ajaxRequestGet('../include/ajaxReqLib.php', 'mode=100&db_table=articleitem&db_id_field=ati_serialno&search_value=' + encodeURIComponent(decodeSpecialChars(actionObjId)) + '&db_op_field=ati_data_25&new_content=' + atiData25);
              /*
              if (atiData25 != '') {
                 vSetElementContent(actionObjId + '_notice', '*');        // Set asterisk into the table cell
              } else {
                 vSetElementContent(actionObjId + '_notice', '&nbsp;');   // Remove asterisk out of the table cell
              }
              */
           }
        }
        if (actionID == '108' || actionID == '109') {
           var noticeText = '';
           if (atiData25 != '') {
              noticeText += '*';
           }
           if (atiData30 != '') {
           	  if (atId == '4327') {
           	  	 noticeText += 'E';
           	  } else {
           	  	 noticeText += 'D';
           	  }              
           }
           vSetElementContent(actionObjId + '_notice', noticeText);        // Set asterisk and/or deactivation stete into the table cell
        }
     }
  }
  // myshow('contentcontainer');
}

function setSuFormData() {
  var frm = document.forms[0];
  setSelectedValue('f_su_admin_at_id', '<?php echo $f_su_admin_at_id; ?>');
  setSelectedValue('f_su_admin_stk_id', '<?php echo $f_su_admin_stk_id; ?>');
  frm.f_su_admin_ati_serialno.value = '<?php echo $f_su_admin_ati_serialno; ?>';
  frm.f_su_admin_stk_name.value = '<?php echo $f_su_admin_stk_name; ?>';
  frm.f_su_admin_stk_barcode.value = '<?php echo $f_su_admin_stk_barcode; ?>';
  frm.f_su_admin_ati_data_01.value = '<?php echo $f_su_admin_ati_data_01; ?>';
  frm.f_su_admin_ati_data_02.value = '<?php echo $f_su_admin_ati_data_02; ?>';
  frm.f_su_admin_ati_data_03.value = '<?php echo $f_su_admin_ati_data_03; ?>';
  frm.f_su_admin_ati_data_28_00.value = '<?php echo $f_su_admin_ati_data_28_00; ?>';
  frm.f_su_admin_ati_data_28_01.value = '<?php echo $f_su_admin_ati_data_28_01; ?>';
  frm.f_su_admin_ati_data_28_02.value = '<?php echo $f_su_admin_ati_data_28_02; ?>';
  frm.f_su_admin_ati_data_28_03.value = '<?php echo $f_su_admin_ati_data_28_03; ?>';
  frm.f_su_admin_ati_data_28_04.value = '<?php echo $f_su_admin_ati_data_28_04; ?>';
  frm.f_su_admin_ad_id.value = '<?php echo $f_su_admin_ad_id; ?>';
  frm.f_su_admin_ad_street.value = '<?php echo $f_su_admin_ad_street; ?>';
  frm.f_su_admin_stk_hsno.value = '<?php echo $f_su_admin_stk_hsno; ?>';
  frm.f_su_admin_ad_zipcode.value = '<?php echo $f_su_admin_ad_zipcode; ?>';
  frm.f_su_admin_ad_city.value = '<?php echo $f_su_admin_ad_city; ?>';
  <?php
    for ($i = 1; $i <= 7; $i++) :
        echo "frm.f_su_admin_ati_data_21_" . $i . ".value = '" . ${("f_su_admin_ati_data_21_" . $i)} . "';";
    endfor;
  ?>
  frm.f_su_admin_ati_data_22.value = '<?php echo $f_su_admin_ati_data_22; ?>';
  frm.f_su_admin_ati_data_23.value = '<?php echo $f_su_admin_ati_data_23; ?>';
  setSelectedValue('f_su_admin_ati_data_24', '<?php echo $f_su_admin_ati_data_24; ?>');
}

function resetSuFormData() {
  var frm = document.forms[0];
  setSelectedValue('f_su_admin_filter_1', '');
  setSelectedValue('f_su_admin_at_id', '');
  setSelectedValue('f_su_admin_stk_id', '');
  frm.f_su_admin_ati_serialno.value = '';
  frm.f_su_admin_stk_name.value = '';
  frm.f_su_admin_stk_barcode.value = '';
  frm.f_su_admin_ati_data_01.value = '';
  frm.f_su_admin_ati_data_02.value = '';
  frm.f_su_admin_ati_data_03.value = '';
  frm.f_su_admin_ati_data_28_00.value = 0;
  frm.f_su_admin_ati_data_28_01.value = 0;
  frm.f_su_admin_ati_data_28_02.value = 0;
  frm.f_su_admin_ati_data_28_03.value = 0;
  frm.f_su_admin_ati_data_28_04.value = 0;
  frm.f_su_admin_ad_id.value = '';
  frm.f_su_admin_ad_street.value = '';
  frm.f_su_admin_stk_hsno.value = '';
  frm.f_su_admin_ad_zipcode.value = '';
  frm.f_su_admin_ad_city.value = '';
  <?php
    for ($i = 1; $i <= 7; $i++) :
        echo "frm.f_su_admin_ati_data_21_" . $i . ".value = '';";
    endfor;
  ?>
  frm.f_su_admin_ati_data_22.value = '';
  frm.f_su_admin_ati_data_23.value = '';
  setSelectedValue('f_su_admin_ati_data_24', '<?php echo $suServiceAndWayTimeDefault ?>');
  removeSystemMessage();
}

function setCbFormData() {
  var frm = document.forms[0];
  setSelectedValue('f_cb_admin_filter_1', '<?php echo $f_cb_admin_filter_1; ?>');
  setSelectedValue('f_cb_admin_filter_2', '<?php echo $f_cb_admin_filter_2; ?>');
  setSelectedValue('f_cb_admin_at_id', '<?php echo $f_cb_admin_at_id; ?>');
  setSelectedValue('f_cb_admin_stk_id', '<?php echo $f_cb_admin_stk_id; ?>');
  frm.f_cb_admin_ati_serialno.value = '<?php echo $f_cb_admin_ati_serialno; ?>';
  frm.f_cb_admin_stk_id.value = '<?php echo $f_cb_admin_stk_id; ?>';
}

function resetCbFormData() {
  var frm = document.forms[0];
  setSelectedValue('f_cb_admin_filter_1', '');
  setSelectedValue('f_cb_admin_filter_2', '');
  setSelectedValue('f_cb_admin_at_id', '');
  setSelectedValue('f_cb_admin_stk_id', '');
  frm.f_cb_admin_ati_serialno.value = '';
  frm.f_cb_admin_stk_id.value = '';
  removeSystemMessage();
}

function setCdrFormData() {
  var frm = document.forms[0];
  // setSelectedValue('f_cdr_admin_filter_1', '<?php echo $f_cdr_admin_filter_1; ?>');
  setSelectedValue('f_cdr_admin_filter_2', '<?php echo $f_cdr_admin_filter_2; ?>');
  setSelectedValue('f_cdr_admin_at_id', '<?php echo $f_cdr_admin_at_id; ?>');
  setSelectedValue('f_cdr_admin_stk_id', '<?php echo $f_cdr_admin_stk_id; ?>');
  frm.f_cdr_admin_ati_serialno_from.value = '<?php echo $f_cdr_admin_ati_serialno_from; ?>';
  frm.f_cdr_admin_ati_serialno_to.value = '<?php echo $f_cdr_admin_ati_serialno_to; ?>';
  frm.f_cdr_admin_stk_id.value = '<?php echo $f_cdr_admin_stk_id; ?>';
}

function resetCdrFormData() {
  var frm = document.forms[0];
  // setSelectedValue('f_cdr_admin_filter_1', '');
  setSelectedValue('f_cdr_admin_filter_2', '');
  setSelectedValue('f_cdr_admin_at_id', '');
  setSelectedValue('f_cdr_admin_stk_id', '');
  frm.f_cdr_admin_ati_serialno_from.value = '';
  frm.f_cdr_admin_ati_serialno_to.value = '';
  frm.f_cdr_admin_stk_id.value = '';
  removeSystemMessage();
}

function finishFormServiceUnitStore() {
	var frm = document.forms[0];
	var msg = '';
	var doStore = true;
	
  // Get current selected value for article id
  var atId = getSelectedValue("f_su_admin_at_id");

  // Get current selected value for stock id
  var stkId = getSelectedValue("f_su_admin_stk_id");

	// If a service unit was selected (option value is NOT "") then there have to be an article id and a stock id
	var filter_1 = getSelectedValue("f_su_admin_filter_1");
	if (filter_1 != '' && filter_1 != frm.f_su_admin_ati_serialno.value)  {
		 doStore = false;
		 msg += '<?php echo getLngt("Die Automatennummer stimmt nicht mit der Filterauswahl überein!") ?> ';
  }

  // Check article (service unit type)
	if (atId == '') {
		  doStore = false;
		  msg += '<?php echo getLngt("Bitte einen Automatentyp wählen!") ?> ';
	}
	// Check stock (service station)
	if (stkId == '') {
		  doStore = false;
		  msg += '<?php echo getLngt("Bitte einen Standort selektieren!") ?> ';
	}
  // Check coordinates service unit
  if (frm.f_su_admin_ati_data_02.value == '' || isNaN(frm.f_su_admin_ati_data_02.value) ||
      frm.f_su_admin_ati_data_03.value == '' || isNaN(frm.f_su_admin_ati_data_03.value)) {
		 doStore = false;
		 msg += '<?php echo getLngt("Bitte geben Sie die Geo-Koordinaten des Automatens korrekt ein!") ?> ';
  }
  // Threshold value offsets
  if (frm.f_su_admin_ati_data_28_00.value == '' || isNaN(frm.f_su_admin_ati_data_28_00.value) ||
      frm.f_su_admin_ati_data_28_01.value == '' || isNaN(frm.f_su_admin_ati_data_28_01.value) ||
      frm.f_su_admin_ati_data_28_02.value == '' || isNaN(frm.f_su_admin_ati_data_28_02.value) ||
      frm.f_su_admin_ati_data_28_03.value == '' || isNaN(frm.f_su_admin_ati_data_28_03.value) ||
      frm.f_su_admin_ati_data_28_04.value == '' || isNaN(frm.f_su_admin_ati_data_28_04.value)) {
		 doStore = false;
		 msg += '<?php echo getLngt("Bitte geben Sie ein Zahl für den Schwellwert-Offset sein!") ?> ';
  }
  // Check coordinates parking place
  if (frm.f_su_admin_ati_data_22.value == '' || isNaN(frm.f_su_admin_ati_data_22.value) ||
      frm.f_su_admin_ati_data_23.value == '' || isNaN(frm.f_su_admin_ati_data_23.value)) {
		 // doStore = false;  // If does not exist take coordinates from the service unit
		 msg += '<?php echo getLngt("Optional geben Sie bitte noch die Geo-Koordinaten des Parkplatzes für den Automaten ein!") ?> ';
  }
  // Check preselection for optimization process
  var doStoreTours = true;  // Switch to "false" if has to be checked
  <?php
    echo "if (!doStoreTours) {";
    for ($i = 1; $i <= 7; $i++) :
        for ($j = 1; $j <= $maxNumOfTours; $j++) :
            echo "if (frm.f_su_admin_ati_data_21_" . $i . ".options[" . $j . "].selected == true) {";
            echo "   doStoreTours = true;";
            echo "};";
        endfor;
    endfor;
    echo "};";
  ?>
  if (!doStoreTours) {
		 doStore = false;
		 msg += '<?php echo getLngt("Bitte ordnen Sie eine Tour zu!") ?> ';
  }
  if (doStore) {
     finishPage('storeDataServiceunit');
	} else {
     alert(msg + ' ' + '<?php echo getLngt("Die Daten wurden nicht gespeichert!") ?>');
	}
}

function finishFormServiceUnitRemove() {
	var frm = document.forms[0];
	var msg = '';
	var doRemove = true;

	// If a service unit was selected (option value is NOT "") then there have to be an article id and a stock id
	var filter_1 = getSelectedValue("f_su_admin_filter_1");
	if (filter_1 != '' && filter_1 != frm.f_su_admin_ati_serialno.value)  {
		 doRemove = false;
		 msg += '<?php echo getLngt("Die Automatennummer stimmt nicht mit der Filterauswahl überein!") ?> ';
  }

  if (doRemove) {
     finishPage('removeDataServiceunit');
	} else {
     alert(msg + ' ' + '<?php echo getLngt("Die Daten wurden nicht gelöscht!") ?>');
	}
}

function finishFormStock() {
	var frm = document.forms[0];
	var msg = '';
	var doStore = true;

  // Get current selected value for stock id
  var stkId = getSelectedValue("f_su_admin_stk_id");

	// Check the name of the stock has been set
  if (trim(frm.f_su_admin_stk_name.value) == '') {
		 doStore = false;
		 msg += '<?php echo getLngt("Die Bezeichnung des Standorts darf nicht leer sein!") ?> ';
  }
  // Check preselection for optimization process
  if (trim(frm.f_su_admin_ad_street.value) == '' || trim(frm.f_su_admin_stk_hsno.value) == '' || trim(frm.f_su_admin_ad_zipcode.value) == '' || trim(frm.f_su_admin_ad_city.value) == '') {
		 doStore = false;
		 msg += '<?php echo getLngt("Bitte geben Sie die Adressdaten vollständig ein! Als Straße verwenden Sie bspw. die Standortbezeichnung oder bei der Hausnummer lediglich einen Punkt. Die PLZ und die Ortsangabe sollten richtig angegeben werden.") ?> ';
  }
  if (doStore) {
     finishPage('storeDataStock');
	} else {
     alert(msg + ' ' + '<?php echo getLngt("Die Daten wurden nicht gespeichert!") ?>');
	}
}

function finishFormCashBoxStore() {
	var frm = document.forms[0];
	var msg = '';
	var doStore = true;
	
  // Get current selected value for article id
  var atId = getSelectedValue("f_cb_admin_at_id");

  // Get current selected value for stock id
  var stkId = getSelectedValue("f_cb_admin_stk_id");

	// If a cash box was selected (option value is NOT "") then there have to be an article id and a stock id
	var filter_1 = getSelectedValue("f_cb_admin_filter_1");
	if (filter_1 != '' && filter_1 != frm.f_cb_admin_ati_serialno.value)  {
		 doStore = false;
		 msg += '<?php echo getLngt("Die Kassettennummer stimmt nicht mit der Filterauswahl überein!") ?> ';
  }

  // Check article (cash box type)
	if (atId == '') {
		  doStore = false;
		  msg += '<?php echo getLngt("Bitte einen Kassettentyp wählen!") ?> ';
	}
	// Check stock (service station)
	if (stkId == '') {
		  doStore = false;
		  msg += '<?php echo getLngt("Bitte einen Standort selektieren!") ?> ';
	}
  if (doStore) {
     finishPage('storeDataCashBox');
	} else {
     alert(msg + ' ' + '<?php echo getLngt("Die Daten wurden nicht gespeichert!") ?>');
	}
}

function finishFormCashBoxRemove() {
	var frm = document.forms[0];
	var msg = '';
	var doRemove = true;

	// If a cash box was selected (option value is NOT "") then there have to be an article id and a stock id
	var filter_1 = getSelectedValue("f_cb_admin_filter_1");
	if (filter_1 != '' && filter_1 != frm.f_cb_admin_ati_serialno.value)  {
		 doRemove = false;
		 msg += '<?php echo getLngt("Die Kassettennummer stimmt nicht mit der Filterauswahl überein!") ?> ';
  }

  if (doRemove) {
     finishPage('removeDataCashBox');
	} else {
     alert(msg + ' ' + '<?php echo getLngt("Die Daten wurden nicht gelöscht!") ?>');
	}
}

function checkCdrSerialNoMissing() {
  var frm = document.forms[0];
  var retBool = false;
  var missingSerNumsOrg = frm.f_cdr_admin_ati_serialno_missing.value;
  var missingSerNums = missingSerNumsOrg.replace(/[^0-9]/g, ",");
  missingSerNums = missingSerNums.replace(/,+/g, ";");
  if (confirm('<?php echo getLngt("Bitte prüfen Sie final die folgend aufgelisteten fehlenden Seriennummern:") ?> ' + missingSerNums)) {
     frm.f_cdr_admin_ati_serialno_missing.value = missingSerNums;
     retBool = true;
  }
  return retBool;
}

function finishFormCardrollsStore () {
	var frm = document.forms[0];
	var msg = '';
	var doStore = true;
	
  // Get current selected value for article id
  var atId = getSelectedValue("f_cdr_admin_at_id");

  // Get current selected value for stock id
  var stkId = getSelectedValue("f_cdr_admin_stk_id");

  // Get current value for palette
  var numOfPalette = parseFloat(frm.f_cdr_admin_palette.value);

	// Interval
	var val_from = frm.f_cdr_admin_ati_serialno_from.value;
	var val_to = frm.f_cdr_admin_ati_serialno_to.value;
	if (val_from != '' && val_to != '') {
		 doStore = checkIsNaN(val_from, '<?php echo getLngt("Die Eingabe der Startseriennummer ist nicht numerisch!") ?>');
		 if (doStore) {
		    doStore = checkIsNaN(val_to, '<?php echo getLngt("Die Eingabe der Endseriennummer ist nicht numerisch!") ?>');
		 }
     if (doStore) {
	      if (val_from > val_to) {
		       doStore = false;
		       msg += '<?php echo getLngt("Die Startseriennummer darf nicht größer sein als die Endseriennummer!") ?> ';
	      }
     }
     if (doStore) {
        var lenFrom = val_from.toString().length;
        var lenTo = val_to.toString().length;
	      if (lenFrom != <?php echo $maxLenOfCdrSrNo ?> || lenFrom != lenTo) {
		       doStore = false;
		       msg += '<?php echo getLngt("Die Seriennummern müssen ausschließlich die folgende Länge aufweisen: ") . " " . $maxLenOfCdrSrNo ?> ';
	      }
     }
	} else {
		doStore = false;
		msg += '<?php echo getLngt("Bitte einen Startseriennummer eintragen!") ?> ';
	}
	// Check palette
	if (doStore) {
     doStore = checkIsNaN(numOfPalette, '<?php echo getLngt("Die Eingabe der Palettennummer ist nicht numerisch!") ?>');
     if (doStore) {
        if (!mcIsInt(numOfPalette)) {
		       doStore = false;
		       msg += '<?php echo getLngt("Die Palettennummer muss ganzzahlig sein!") ?> ';
        }
     }
  }
  // Check article (card roll type)
	if (atId == '') {
		  doStore = false;
		  msg += '<?php echo getLngt("Bitte einen Kartenrollentyp wählen!") ?> ';
	}
	// Check stock (service station)
	if (stkId == '') {
	   doStore = false;
	   msg += '<?php echo getLngt("Bitte einen Standort selektieren!") ?> ';
	}
	// Check missing card rolls
	if (doStore) {
	   doStore = checkCdrSerialNoMissing();
	}
  if (doStore) {
     finishPage('storeDataCardrolls');
	} else {
    frm.f_cdr_admin_ati_serialno_from.value = '';
    frm.f_cdr_admin_ati_serialno_to.value = '';
    alert(msg + ' ' + '<?php echo getLngt("Die Daten wurden nicht gespeichert!") ?>');
	}
}

function finishFormCardrollsRemove () {
  // .........
}


function getServiceunitData (atiSerialNoSpecial) {
	var frm = document.forms[0];
	var atiSerialno = '';
	
	if (atiSerialNoSpecial != '') {
		 atiSerialno = atiSerialNoSpecial;
  } else {
     // Get current selected value for service unit item
     atiSerialno = getSelectedValue("f_su_admin_filter_1");
  }

  if (atiSerialno != '') {
     ajaxRequestGet('../include/ajaxReqLib.php', 'mode=1&db_table=articleitem&db_id_field=ati_serialno&search_value=' + encodeURIComponent(decodeSpecialChars(atiSerialno)) + '&db_return_field=at_id---stk_id---ati_data_01---ati_data_02---ati_data_03---ati_data_21---ati_data_22---ati_data_23---ati_data_24---ati_data_28');
     frm.f_su_admin_ati_serialno.value = atiSerialno;
     frm.f_su_admin_at_id.value = retValue['at_id'];
     frm.f_su_admin_stk_id.value = retValue['stk_id'];
     frm.f_su_admin_ati_data_01.value = retValue['ati_data_01'];
     frm.f_su_admin_ati_data_02.value = retValue['ati_data_02'];
     frm.f_su_admin_ati_data_03.value = retValue['ati_data_03'];
     frm.f_su_admin_ati_data_22.value = retValue['ati_data_22'];
     frm.f_su_admin_ati_data_23.value = retValue['ati_data_23'];
     
     var tv_offset = retValue['ati_data_28'];
     var tv_offset_arr = tv_offset.split(',');
     if (tv_offset_arr[0]) { frm.f_su_admin_ati_data_28_00.value = tv_offset_arr[0]} else { frm.f_su_admin_ati_data_28_00.value = 0};
     if (tv_offset_arr[1]) { frm.f_su_admin_ati_data_28_01.value = tv_offset_arr[1]} else { frm.f_su_admin_ati_data_28_01.value = 0};
     if (tv_offset_arr[2]) { frm.f_su_admin_ati_data_28_02.value = tv_offset_arr[2]} else { frm.f_su_admin_ati_data_28_02.value = 0};
     if (tv_offset_arr[3]) { frm.f_su_admin_ati_data_28_03.value = tv_offset_arr[3]} else { frm.f_su_admin_ati_data_28_03.value = 0};
     if (tv_offset_arr[4]) { frm.f_su_admin_ati_data_28_04.value = tv_offset_arr[4]} else { frm.f_su_admin_ati_data_28_04.value = 0};

     var suTimeServicetimeValue = retValue['ati_data_24'];
     if (suTimeServicetimeValue == '') {
        suTimeServicetimeValue = '<?php echo $suServiceAndWayTimeDefault ?>';
     }
     setSelectedValue('f_su_admin_ati_data_24', suTimeServicetimeValue);

     var atiData21 = retValue['ati_data_21'];
     var atiData21Array = atiData21.split(",");
     var atiData21ArrayLen = atiData21Array.length;
     var tmpFrmData21 = '';
     var elemNo;
     for(i=0;i<atiData21ArrayLen;++i) {    	  
     	  tmpFrmData21 = 'f_su_admin_ati_data_21_' + (i + 1).toString();
     	  setSelectedValue(tmpFrmData21, atiData21Array[i]);
     }

     if (retValue['at_id'] != '') {
     	  setSelectedValue('f_su_admin_at_id', retValue['at_id']);
     }
     if (retValue['stk_id'] != '') {
        ajaxRequestGet('../include/ajaxReqLib.php', 'mode=1&db_table=stock&db_id_field=stk_id&search_value=' + retValue['stk_id'] + '&db_return_field=ad_id---stk_hsno---stk_name---stk_barcode');
        frm.f_su_admin_stk_name.value = retValue['stk_name'];
        frm.f_su_admin_ad_id.value = retValue['ad_id'];
        frm.f_su_admin_stk_hsno.value = retValue['stk_hsno'];
        frm.f_su_admin_stk_barcode.value = retValue['stk_barcode'];
        if (retValue['ad_id'] != '') {
           ajaxRequestGet('../include/ajaxReqLib.php', 'mode=1&db_table=address&db_id_field=ad_id&search_value=' + retValue['ad_id'] + '&db_return_field=ad_street---ad_zipcode---ad_city');
           frm.f_su_admin_ad_street.value = retValue['ad_street'];        
           frm.f_su_admin_ad_zipcode.value = retValue['ad_zipcode'];
           frm.f_su_admin_ad_city.value = retValue['ad_city'];
        }
     }
  }

  removeSystemMessage();
}

function getStockData () {
	var frm = document.forms[0];

  // Get current selected value for stock id
  var stkId = getSelectedValue("f_su_admin_stk_id");
  
  if (stkId != '') {
     ajaxRequestGet('../include/ajaxReqLib.php', 'mode=1&db_table=stock&db_id_field=stk_id&search_value=' + stkId + '&db_return_field=ad_id---stk_hsno---stk_name---stk_barcode');
     frm.f_su_admin_stk_name.value = retValue['stk_name'];
     frm.f_su_admin_ad_id.value = retValue['ad_id'];
     frm.f_su_admin_stk_hsno.value = retValue['stk_hsno'];
     frm.f_su_admin_stk_barcode.value = retValue['stk_barcode'];
     if (retValue['ad_id'] != '') {
        ajaxRequestGet('../include/ajaxReqLib.php', 'mode=1&db_table=address&db_id_field=ad_id&search_value=' + retValue['ad_id'] + '&db_return_field=ad_street---ad_zipcode---ad_city');
        frm.f_su_admin_ad_street.value = retValue['ad_street'];        
        frm.f_su_admin_ad_zipcode.value = retValue['ad_zipcode'];
        frm.f_su_admin_ad_city.value = retValue['ad_city'];
     }
  }
  
  removeSystemMessage();
}

function getCashBoxData (atiSerialNoSpecial) {
	var frm = document.forms[0];
	var atiSerialno = '';
	
	if (atiSerialNoSpecial != '') {
		 atiSerialno = atiSerialNoSpecial;
  } else {
     // Get current selected value for cash box item
     atiSerialno = getSelectedValue("f_cb_admin_filter_1");
  }

  if (atiSerialno != '') {
     ajaxRequestGet('../include/ajaxReqLib.php', 'mode=1&db_table=articleitem&db_id_field=ati_serialno&search_value=' + encodeURIComponent(decodeSpecialChars(atiSerialno)) + '&db_return_field=at_id---stk_id---ati_data_01---ati_data_02---ati_data_03');
     frm.f_cb_admin_ati_serialno.value = atiSerialno;
     frm.f_cb_admin_at_id.value = retValue['at_id'];
     frm.f_cb_admin_stk_id.value = retValue['stk_id'];
     frm.f_cb_admin_ati_data_01.value = retValue['ati_data_01'];
     frm.f_cb_admin_ati_data_02.value = retValue['ati_data_02'];
     frm.f_cb_admin_ati_data_03.value = retValue['ati_data_03'];

     if (retValue['at_id'] != '') {
     	  setSelectedValue('f_cb_admin_at_id', retValue['at_id']);
     }
     if (retValue['stk_id'] != '') {
     	  setSelectedValue('f_cb_admin_stk_id', retValue['stk_id']);
     }
  }

  removeSystemMessage();
}

function getCardrollData (atiSerialNoSpecial) {
	var frm = document.forms[0];
	var atiSerialno = '';
	
	if (atiSerialNoSpecial != '') {
		 atiSerialno = atiSerialNoSpecial;
  } else {
     // Get current selected value for card roll item
     // atiSerialno = getSelectedValue("f_cdr_admin_filter_1");
  }

  if (atiSerialno != '') {
     ajaxRequestGet('../include/ajaxReqLib.php', 'mode=1&db_table=articleitem&db_id_field=ati_serialno&search_value=' + encodeURIComponent(decodeSpecialChars(atiSerialno)) + '&db_return_field=at_id---stk_id---ati_data_01---ati_data_02---ati_data_03');
     frm.f_cdr_admin_ati_serialno_from.value = atiSerialno;
     frm.f_cdr_admin_ati_serialno_to.value = atiSerialno;
     frm.f_cdr_admin_at_id.value = retValue['at_id'];
     frm.f_cdr_admin_stk_id.value = retValue['stk_id'];
     frm.f_cdr_admin_ati_data_01.value = retValue['ati_data_01'];
     frm.f_cdr_admin_ati_data_02.value = retValue['ati_data_02'];
     frm.f_cdr_admin_ati_data_03.value = retValue['ati_data_03'];

     if (retValue['at_id'] != '') {
     	  setSelectedValue('f_cdr_admin_at_id', retValue['at_id']);
     }
     if (retValue['stk_id'] != '') {
     	  setSelectedValue('f_cdr_admin_stk_id', retValue['stk_id']);
     }
  }

  removeSystemMessage();
}

function setFilter () {
	// Toggle states
	// Critical, etc.
  var f_pt_filter_01_01 = $('#f_pt_filter_01_01').val();  // Button for displaying critical items
  var f_pt_filter_01_02 = $('#f_pt_filter_01_02').val();  // Button for displaying semi critical items
  var f_pt_filter_01_03 = $('#f_pt_filter_01_03').val();  // Button for displaying normal items

  var buttonCol = '';
  buttonCol = '<?php echo $colArray["light_red"] ?>';
  if (f_pt_filter_01_01 == '1') { buttonCol = '<?php echo $colArray["red"] ?>'; };
  $('#f_pt_button_filter_01_01').css('background-color', buttonCol);
  buttonCol = '<?php echo $colArray["light_yellow"] ?>';
  if (f_pt_filter_01_02 == '1') { buttonCol = '<?php echo $colArray["yellow"] ?>'; };
  $('#f_pt_button_filter_01_02').css('background-color', buttonCol);
  buttonCol = '<?php echo $colArray["white"] ?>';
  if (f_pt_filter_01_03 == '1') { buttonCol = '<?php echo $colArray["gray"] ?>'; };
  $('#f_pt_button_filter_01_03').css('background-color', buttonCol);

  // Default vehicle selection
  var f_crvh_selection_00 = $('#f_crvh_selection_00').val();  // Button for displaying vehicles
  var f_crvh_selection_01 = $('#f_crvh_selection_01').val();  // ....
  var f_crvh_selection_02 = $('#f_crvh_selection_02').val();
  var f_crvh_selection_03 = $('#f_crvh_selection_03').val();
  var f_crvh_selection_04 = $('#f_crvh_selection_04').val();

  buttonCol = '<?php echo $colArray["gray"] ?>';
  if (f_crvh_selection_00 == '1') { buttonCol = '<?php echo $colArray["light_blue"] ?>'; };
  $('#f_crvh_button_selection_00').css('background-color', buttonCol);
  buttonCol = '<?php echo $colArray["gray"] ?>';
  if (f_crvh_selection_01 == '1') { buttonCol = '<?php echo $colArray["light_blue"] ?>'; };
  $('#f_crvh_button_selection_01').css('background-color', buttonCol);
  buttonCol = '<?php echo $colArray["gray"] ?>';
  if (f_crvh_selection_02 == '1') { buttonCol = '<?php echo $colArray["light_blue"] ?>'; };
  $('#f_crvh_button_selection_02').css('background-color', buttonCol);
  buttonCol = '<?php echo $colArray["gray"] ?>';
  if (f_crvh_selection_03 == '1') { buttonCol = '<?php echo $colArray["light_blue"] ?>'; };
  $('#f_crvh_button_selection_03').css('background-color', buttonCol);
  buttonCol = '<?php echo $colArray["gray"] ?>';
  if (f_crvh_selection_04 == '1') { buttonCol = '<?php echo $colArray["light_blue"] ?>'; };
  $('#f_crvh_button_selection_04').css('background-color', buttonCol);

  // Toggle individual combination class
  // ".state_<level>_<vehicle>" [e.g. ".state_01_00" <=> state critical and vehicle "00"]
  // Critical
  if (f_pt_filter_01_01 == '1' && f_crvh_selection_00 == '1') { $(".state_01_00").show(); } else { $(".state_01_00").hide(); };
  if (f_pt_filter_01_01 == '1' && f_crvh_selection_01 == '1') { $(".state_01_01").show(); } else { $(".state_01_01").hide(); };
  if (f_pt_filter_01_01 == '1' && f_crvh_selection_02 == '1') { $(".state_01_02").show(); } else { $(".state_01_02").hide(); };
  if (f_pt_filter_01_01 == '1' && f_crvh_selection_03 == '1') { $(".state_01_03").show(); } else { $(".state_01_03").hide(); };
  if (f_pt_filter_01_01 == '1' && f_crvh_selection_04 == '1') { $(".state_01_04").show(); } else { $(".state_01_04").hide(); };
  // Semi-critical
  if (f_pt_filter_01_02 == '1' && f_crvh_selection_00 == '1') { $(".state_02_00").show(); } else { $(".state_02_00").hide(); };
  if (f_pt_filter_01_02 == '1' && f_crvh_selection_01 == '1') { $(".state_02_01").show(); } else { $(".state_02_01").hide(); };
  if (f_pt_filter_01_02 == '1' && f_crvh_selection_02 == '1') { $(".state_02_02").show(); } else { $(".state_02_02").hide(); };
  if (f_pt_filter_01_02 == '1' && f_crvh_selection_03 == '1') { $(".state_02_03").show(); } else { $(".state_02_03").hide(); };
  if (f_pt_filter_01_02 == '1' && f_crvh_selection_04 == '1') { $(".state_02_04").show(); } else { $(".state_02_04").hide(); };
  // Normal
  if (f_pt_filter_01_03 == '1' && f_crvh_selection_00 == '1') { $(".state_03_00").show(); } else { $(".state_03_00").hide(); };
  if (f_pt_filter_01_03 == '1' && f_crvh_selection_01 == '1') { $(".state_03_01").show(); } else { $(".state_03_01").hide(); };
  if (f_pt_filter_01_03 == '1' && f_crvh_selection_02 == '1') { $(".state_03_02").show(); } else { $(".state_03_02").hide(); };
  if (f_pt_filter_01_03 == '1' && f_crvh_selection_03 == '1') { $(".state_03_03").show(); } else { $(".state_03_03").hide(); };
  if (f_pt_filter_01_03 == '1' && f_crvh_selection_04 == '1') { $(".state_03_04").show(); } else { $(".state_03_04").hide(); };

  // Default table column selection
  var f_col_sel_00 = $('#f_col_sel_00').val();  // Buttons for displaying table columns
  var f_col_sel_01 = $('#f_col_sel_01').val();  // ....
  var f_col_sel_02 = $('#f_col_sel_02').val();
  var f_col_sel_03 = $('#f_col_sel_03').val();
  var f_col_sel_04 = $('#f_col_sel_04').val();
  var f_col_sel_05 = $('#f_col_sel_05').val();
  var f_col_sel_06 = $('#f_col_sel_06').val();
  var f_col_sel_07 = $('#f_col_sel_07').val();
  var f_col_sel_08 = $('#f_col_sel_08').val();
  var f_col_sel_09 = $('#f_col_sel_09').val();
  var f_col_sel_10 = $('#f_col_sel_10').val();
  var f_col_sel_11 = $('#f_col_sel_11').val();
  var f_col_sel_12 = $('#f_col_sel_12').val();
  var f_col_sel_13 = $('#f_col_sel_13').val();
  var f_col_sel_14 = $('#f_col_sel_14').val();
  var f_col_sel_15 = $('#f_col_sel_15').val();
  var f_col_sel_16 = $('#f_col_sel_16').val();
  var f_col_sel_17 = $('#f_col_sel_17').val();
  var f_col_sel_18 = $('#f_col_sel_18').val();
  var f_col_sel_19 = $('#f_col_sel_19').val();

  if (f_col_sel_00 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_00").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_00").hide();
  };
  $('#f_col_button_sel_00').css('background-color', buttonCol);
  if (f_col_sel_01 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_01").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_01").hide();
  };
  $('#f_col_button_sel_01').css('background-color', buttonCol);
  if (f_col_sel_02 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_02").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_02").hide();
  };
  $('#f_col_button_sel_02').css('background-color', buttonCol);
  if (f_col_sel_03 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_03").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_03").hide();
  };
  $('#f_col_button_sel_03').css('background-color', buttonCol);
  if (f_col_sel_04 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_04").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_04").hide();
  };
  $('#f_col_button_sel_04').css('background-color', buttonCol);
/*
  if (f_col_sel_05 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_05").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_05").hide();
  };
  $('#f_col_button_sel_05').css('background-color', buttonCol);
*/
  if (f_col_sel_06 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_06").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_06").hide();
  };
  $('#f_col_button_sel_06').css('background-color', buttonCol);
  if (f_col_sel_07 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_07").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_07").hide();
  };
  $('#f_col_button_sel_07').css('background-color', buttonCol);
  if (f_col_sel_08 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_08").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_08").hide();
  };
  $('#f_col_button_sel_08').css('background-color', buttonCol);
  if (f_col_sel_09 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_09").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_09").hide();
  };
  $('#f_col_button_sel_09').css('background-color', buttonCol);
  if (f_col_sel_10 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_10").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_10").hide();
  };
  $('#f_col_button_sel_10').css('background-color', buttonCol);
  if (f_col_sel_11 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_11").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_11").hide();
  };
  $('#f_col_button_sel_11').css('background-color', buttonCol);
  if (f_col_sel_12 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_12").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_12").hide();
  };
  $('#f_col_button_sel_12').css('background-color', buttonCol);
  if (f_col_sel_13 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_13").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_13").hide();
  };
  $('#f_col_button_sel_13').css('background-color', buttonCol);
  if (f_col_sel_14 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_14").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_14").hide();
  };
  $('#f_col_button_sel_14').css('background-color', buttonCol);
  if (f_col_sel_15 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_15").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_15").hide();
  };
  $('#f_col_button_sel_15').css('background-color', buttonCol);
/*
  if (f_col_sel_16 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_16").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_16").hide();
  };
  $('#f_col_button_sel_16').css('background-color', buttonCol);
  if (f_col_sel_17 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_17").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_17").hide();
  };
  $('#f_col_button_sel_17').css('background-color', buttonCol);
*/
  if (f_col_sel_18 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_18").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_18").hide();
  };
  $('#f_col_button_sel_18').css('background-color', buttonCol);
  if (f_col_sel_19 == '1') { 
  	  buttonCol = '<?php echo $colArray["light_blue"] ?>'; 
  	  $(".f_col_sel_19").show(); 
  } else { 
  	  buttonCol = '<?php echo $colArray["gray"] ?>';
  	  $(".f_col_sel_19").hide();
  };
  $('#f_col_button_sel_19').css('background-color', buttonCol);
}

function toggleFilter(item) {
	var elemVal = $('#' + item).val();
	if (elemVal == '1') {
		 $('#' + item).val('0');
  } else {
  	$('#' + item).val('1');
  }
  setFilter();
}

function setPreselectedVehicles () {
  var elemVal = $('#f_su_admin_ati_data_21_all').val();
  if (elemVal != '') {
     if (confirm('<?php echo getLngt("Möchten Sie die Auswahl für alle Wochentage übernehmen?") ?>')) {
     	  setSelectedValue('f_su_admin_ati_data_21_1', elemVal);
     	  setSelectedValue('f_su_admin_ati_data_21_2', elemVal);
     	  setSelectedValue('f_su_admin_ati_data_21_3', elemVal);
     	  setSelectedValue('f_su_admin_ati_data_21_4', elemVal);
     	  setSelectedValue('f_su_admin_ati_data_21_5', elemVal);
     	  setSelectedValue('f_su_admin_ati_data_21_6', elemVal);
     	  setSelectedValue('f_su_admin_ati_data_21_7', elemVal);
     	  setSelectedValue('f_su_admin_ati_data_21_all', '');
  	 }
  }
}

function getCurrentTourNoOfSpecialServiceunit (serialno) {
  // Get all vehicle selects
  var tour_no = '';
  var selects = document.getElementsByTagName('select');
  var selLen = selects.length;
  for (var i = 0; i < selLen; i++) {
  	   if (selects[i].name.substring(0,12) == 'f_su_tour_no') {
  	   	  // Get number of the service unit out of the name of the current <select> tag
  	   	  elemIndex = selects[i].name.substring(13,(selects[i].name.length - 1));
         if (elemIndex == serialno) {
            len = selects[i].length;
            for (var j=0; j<len; ++j) {
               if (selects[i].options[j].selected == true) {
              	   tour_no = selects[i].options[j].value;
                  // alert(elemIndex + ' :: ' + selects[i].name + ' :: ' + selects[i].options[j].value);
               }
            }
         }
      }
  }
  return tour_no;
}

function displayTourData () {
  var tourSumOutput = '';
  var tourWeightOutput = '';
  var tourCountOutput = '';
  for (var i = 1; i <= tourSumArrayLen; i++) {
	    tourSumOutput = tourSumOutput.concat('Tour ' + i + ': ' + mcRound(tourSumArray[i],2) + ' | ');
	    tourWeightOutput = tourWeightOutput.concat('Tour ' + i + ': ' + mcRound(tourWeightArray[i],2) + ' | ');
	    tourCountOutput = tourCountOutput.concat('Tour ' + i + ': ' + tourCountArray[i] + ' | ');
  }
  $('#tour_amounts').html('<b>BETRÄGE: ' + tourSumOutput + '</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + '<b>GEWICHT: ' + tourWeightOutput + '</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + '<b>ANZAHL: ' + tourCountOutput + '</b>');
}

function setCheckboxCashboxStateVectorWasChanged(serialno, amount, cbStateChecked, cbTypeNo) {
	var su = '#' + 'f_su_chkbx_' + serialno;
	var su_atm = '#' + 'f_su_atm_chkbx_' + serialno;
	var su_cb_00 = '#' + 'f_su_cb_chkbx_00_' + serialno;
	var su_cb_01 = '#' + 'f_su_cb_chkbx_01_' + serialno;
	var su_cb_02 = '#' + 'f_su_cb_chkbx_02_' + serialno;
	var su_cb_03 = '#' + 'f_su_cb_chkbx_03_' + serialno;
	var su_cb_04 = '#' + 'f_su_cb_chkbx_04_' + serialno;
// alert($(su_atm).is(':checked') + ' | ' + $(su_cb_00).is(':checked') + ' | ' + $(su_cb_01).is(':checked') + ' | ' + $(su_cb_02).is(':checked') + ' | ' + $(su_cb_03).is(':checked') + ' | ' + $(su_cb_04).is(':checked'));
  var remChecked = $(su).is(':checked');
  var tour_no = getCurrentTourNoOfSpecialServiceunit(serialno);
  
  $(su).prop('checked', false);
  if ($(su_cb_00).is(':checked') || $(su_cb_01).is(':checked') || $(su_cb_02).is(':checked') || $(su_cb_03).is(':checked') || $(su_cb_04).is(':checked')) {
     $(su).prop('checked', true);
  }
  if ($(su_atm) && $(su_atm).is(':checked')) {
     $(su).prop('checked', true);
  }
  if (!remChecked == $(su).is(':checked')) {
     setCheckboxStateVectorWasChanged();
     if ($(su).is(':checked')) {
        tourCountArray[tour_no]++;
     } else {
     	  tourCountArray[tour_no]--;
     }
  }
  if (isNaN(cbTypeNo)) {
  	 cbTypeNo = 1;
  }
  // Change amount for each tour
  if (!isNaN(amount) && amount != 0) {
     if (tour_no != '') {
     	  if (cbStateChecked) {
     	     tourSumArray[tour_no] += amount;
     	     tourWeightArray[tour_no] += (amount / cbWeightFactorArray[cbTypeNo]);
     	  } else {
     	  	 tourSumArray[tour_no] -= amount;
     	  	 tourWeightArray[tour_no] -= (amount / cbWeightFactorArray[cbTypeNo]);
     	  }
     	  displayTourData();
     }
  }
}

function setVehicleWasChanged(serialno, currentValueOfFocusedTour) {
	var su = '#' + 'f_su_chkbx_' + serialno;
	var su_cb_00 = '#' + 'f_su_cb_chkbx_00_' + serialno;
	var su_cb_01 = '#' + 'f_su_cb_chkbx_01_' + serialno;
	var su_cb_02 = '#' + 'f_su_cb_chkbx_02_' + serialno;
	var su_cb_03 = '#' + 'f_su_cb_chkbx_03_' + serialno;
	var su_cb_04 = '#' + 'f_su_cb_chkbx_04_' + serialno;
// alert(serialno + ' ' + remCurrentValueOfFocusedTour + ' ' + currentValueOfFocusedTour + ' ' + remCurrentValueOfCashbox00 + ' ' + remCurrentValueOfCashbox01 + ' ' + remCurrentValueOfCashbox02 + ' ' + remCurrentValueOfCashbox03 + ' ' + remCurrentValueOfCashbox04);
  if (currentValueOfFocusedTour != '' && $(su).is(':checked')) {
     if ($(su_cb_00).is(':checked')) {
     	  tourSumArray[remCurrentValueOfFocusedTour] -= remCurrentValueOfCashbox00;
        tourSumArray[currentValueOfFocusedTour] += remCurrentValueOfCashbox00;
     	  tourWeightArray[remCurrentValueOfFocusedTour] -= (remCurrentValueOfCashbox00 / cbWeightFactorArray[0]);
        tourWeightArray[currentValueOfFocusedTour] += (remCurrentValueOfCashbox00 / cbWeightFactorArray[0]);
     }
     if ($(su_cb_01).is(':checked')) {
     	  tourSumArray[remCurrentValueOfFocusedTour] -= remCurrentValueOfCashbox01;
        tourSumArray[currentValueOfFocusedTour] += remCurrentValueOfCashbox01;
     	  tourWeightArray[remCurrentValueOfFocusedTour] -= (remCurrentValueOfCashbox01 / cbWeightFactorArray[1]);
        tourWeightArray[currentValueOfFocusedTour] += (remCurrentValueOfCashbox01 / cbWeightFactorArray[1]);
     }
     if ($(su_cb_02).is(':checked')) {
     	  tourSumArray[remCurrentValueOfFocusedTour] -= remCurrentValueOfCashbox02;
        tourSumArray[currentValueOfFocusedTour] += remCurrentValueOfCashbox02;
     	  tourWeightArray[remCurrentValueOfFocusedTour] -= (remCurrentValueOfCashbox02 / cbWeightFactorArray[2]);
        tourWeightArray[currentValueOfFocusedTour] += (remCurrentValueOfCashbox02 / cbWeightFactorArray[2]);
     }
     if ($(su_cb_03).is(':checked')) {
     	  tourSumArray[remCurrentValueOfFocusedTour] -= remCurrentValueOfCashbox03;
        tourSumArray[currentValueOfFocusedTour] += remCurrentValueOfCashbox03;
     	  tourWeightArray[remCurrentValueOfFocusedTour] -= (remCurrentValueOfCashbox03 / cbWeightFactorArray[3]);
        tourWeightArray[currentValueOfFocusedTour] += (remCurrentValueOfCashbox03 / cbWeightFactorArray[3]);
     }
     if ($(su_cb_04).is(':checked')) {
     	  tourSumArray[remCurrentValueOfFocusedTour] -= remCurrentValueOfCashbox04;
        tourSumArray[currentValueOfFocusedTour] += remCurrentValueOfCashbox04;
     	  tourWeightArray[remCurrentValueOfFocusedTour] -= (remCurrentValueOfCashbox04 / cbWeightFactorArray[4]);
        tourWeightArray[currentValueOfFocusedTour] += (remCurrentValueOfCashbox04 / cbWeightFactorArray[4]);
     }

     tourCountArray[remCurrentValueOfFocusedTour]--;
     tourCountArray[currentValueOfFocusedTour]++;

     displayTourData();
     $(su).focus();
  } else {
  	 if ($(su).is(':checked')) {
  	 	  tourCountArray[remCurrentValueOfFocusedTour]--;
  	 } else {
  	 	  // tourCountArray[remCurrentValueOfFocusedTour]--;
  	 }
  	 displayTourData();
  }
}

function setOptimizationCheckbox(serialno, cb_00, cb_01, cb_02, cb_03, cb_04) { 
	var su = '#' + 'f_su_chkbx_' + serialno;
	var su_cb_00 = '#' + 'f_su_cb_chkbx_00_' + serialno;
	var su_cb_01 = '#' + 'f_su_cb_chkbx_01_' + serialno;
	var su_cb_02 = '#' + 'f_su_cb_chkbx_02_' + serialno;
	var su_cb_03 = '#' + 'f_su_cb_chkbx_03_' + serialno;
	var su_cb_04 = '#' + 'f_su_cb_chkbx_04_' + serialno;

	setCheckboxStateVectorWasChanged();

  // Change amount for each tour
  tour_no = getCurrentTourNoOfSpecialServiceunit(serialno);
  if (tour_no != '') {
     if ($(su).is(':checked')) {
     	  tourCountArray[tour_no]++;
        if ($(su_cb_00).is(':checked') && !isNaN(cb_00) && cb_00 != 0) {
           tourSumArray[tour_no] += cb_00;
           tourWeightArray[tour_no] += (cb_00 / cbWeightFactorArray[0]);
        }
        if ($(su_cb_01).is(':checked') && !isNaN(cb_01) && cb_01 != 0) {
           tourSumArray[tour_no] += cb_01;
           tourWeightArray[tour_no] += (cb_01 / cbWeightFactorArray[1]);
        }
        if ($(su_cb_02).is(':checked') && !isNaN(cb_02) && cb_02 != 0) {
           tourSumArray[tour_no] += cb_02;
           tourWeightArray[tour_no] += (cb_02 / cbWeightFactorArray[2]);
        }
        if ($(su_cb_03).is(':checked') && !isNaN(cb_03) && cb_03 != 0) {
           tourSumArray[tour_no] += cb_03;
           tourWeightArray[tour_no] += (cb_03 / cbWeightFactorArray[3]);
        }
        if ($(su_cb_04).is(':checked') && !isNaN(cb_04) && cb_04 != 0) {
           tourSumArray[tour_no] += cb_04;
           tourWeightArray[tour_no] += (cb_04 / cbWeightFactorArray[4]);
        }
     } else {
     	  tourCountArray[tour_no]--;
        if ($(su_cb_00).is(':checked') && !isNaN(cb_00) && cb_00 != 0) {
           tourSumArray[tour_no] -= cb_00;
           tourWeightArray[tour_no] -= (cb_00 / cbWeightFactorArray[0]);
           $(su_cb_00).prop('checked', false);
        }
        if ($(su_cb_01).is(':checked') && !isNaN(cb_01) && cb_01 != 0) {
           tourSumArray[tour_no] -= cb_01;
           tourWeightArray[tour_no] -= (cb_01 / cbWeightFactorArray[1]);
           $(su_cb_01).prop('checked', false);
        }
        if ($(su_cb_02).is(':checked') && !isNaN(cb_02) && cb_02 != 0) {
           tourSumArray[tour_no] -= cb_02;
           tourWeightArray[tour_no] -= (cb_02 / cbWeightFactorArray[2]);
           $(su_cb_02).prop('checked', false);
        }
        if ($(su_cb_03).is(':checked') && !isNaN(cb_03) && cb_03 != 0) {
           tourSumArray[tour_no] -= cb_03;
           tourWeightArray[tour_no] -= (cb_03 / cbWeightFactorArray[3]);
           $(su_cb_03).prop('checked', false);
        }
        if ($(su_cb_04).is(':checked') && !isNaN(cb_04) && cb_04 != 0) {
           tourSumArray[tour_no] -= cb_04;
           tourWeightArray[tour_no] -= (cb_04 / cbWeightFactorArray[4]);
           $(su_cb_04).prop('checked', false);
        }
     }
  }
  displayTourData();
}

function setCheckboxMessageStateVectorWasChanged(serialno) {
  setCheckboxCashboxStateVectorWasChanged(serialno, 0);
  // setCheckboxStateVectorWasChanged();
}

// **** VEHICLE SELECTION START ****
var vehicleSelectionIsDisplayed = false;
function callVehicleSelection() {
	if (vehicleSelectionIsDisplayed) {
		 myhide('vehicleselectioncontainer');
		 vehicleSelectionIsDisplayed = false;
  } else {
     myshow('vehicleselectioncontainer');
     vehicleSelectionIsDisplayed = true;
  }
}
// **** VEHICLE SELECTION END ****

// **** TABLE COLUMN SELECTION START ****
var tableColSelectionIsDisplayed = false;
function callTableColSelection() {
	if (tableColSelectionIsDisplayed) {
		 myhide('tablecolselectioncontainer');
		 tableColSelectionIsDisplayed = false;
  } else {
     myshow('tablecolselectioncontainer');
     tableColSelectionIsDisplayed = true;
  }
}
// **** TABLE COLUMN SELECTION END ****


// Manual mapping "tour" => "vehicle"
function changeTourVehicleAssoc(tour_no) {
	var maxNumOfTours = '<?php echo $maxNumOfTours ?>';
	var maxNumOfVehicles = '<?php echo $mappedCourierArrayLen ?>';
	var elemCurrent;
	var elemChanged = 'f_tour_crvh_assoc_' + padl(tour_no.toString(),2,'0');
	var changedVehicleSelectedValue = getSelectedValue(elemChanged);
	var currVehicleSelectedValue;
	// Check all other select boxes having the same value as the selected and reset each of them matching
	for (var i = 1; i <= maxNumOfTours; i++) {
      // Get current selected value for article id
      elemCurrent = 'f_tour_crvh_assoc_' + padl(i.toString(),2,'0');
      if (tour_no != i) {
         currVehicleSelectedValue = getSelectedValue(elemCurrent);
         if (currVehicleSelectedValue == changedVehicleSelectedValue) {
         	  setSelectedValue(elemCurrent, 0);
         }
      }
	}
	var newVehicleMapping = '';
	for (var i = 1; i <= maxNumOfTours; i++) {
		  if (newVehicleMapping != '') {
		  	 newVehicleMapping += ',';
		  }
      // Get current selected value for article id
      elemCurrent = 'f_tour_crvh_assoc_' + padl(i.toString(),2,'0');
      currVehicleSelectedValue = getSelectedValue(elemCurrent);
      newVehicleMapping += currVehicleSelectedValue;
	}
	document.forms[0].f_tour_crvh_assoc.value = newVehicleMapping;
	// alert(document.forms[0].f_tour_crvh_assoc.value);
}


function execBodyOnLoad() {
	myhide('actioncontainer');
	myhide('contentcontainer');
	myhide('vehicleselectioncontainer');
	myhide('tablecolselectioncontainer');
	initForm();
	setFilter();
	// $('#category_buttons').buttonset({disabled: true});
	$('#category_buttons').buttonset({ items: "input[type=checkbox]" });
	// $('#category_buttons').buttonset();
  <?php
    if ($maskDisplay00Switch == "1") : echo "preChangeHideShow('maskDisplay00','on');"; else : echo "changeHideShow2('maskDisplay00','off');"; endif;
    if ($maskDisplay01Switch == "1") : echo "preChangeHideShow('maskDisplay01','on');"; else : echo "changeHideShow2('maskDisplay01','off');"; endif;
    if ($maskDisplay02Switch == "1") : echo "preChangeHideShow('maskDisplay02','on');"; else : echo "changeHideShow2('maskDisplay02','off');"; endif;
    if ($maskDisplay03Switch == "1") : echo "preChangeHideShow('maskDisplay03','on');"; else : echo "changeHideShow2('maskDisplay03','off');"; endif;
    if ($maskDisplay04Switch == "1") : echo "preChangeHideShow('maskDisplay04','on');"; else : echo "changeHideShow2('maskDisplay04','off');"; endif;
    if ($maskDisplay05Switch == "1") : echo "preChangeHideShow('maskDisplay05','on');"; else : echo "changeHideShow2('maskDisplay05','off');"; endif;
    if ($maskDisplay06Switch == "1") : echo "preChangeHideShow('maskDisplay06','on');"; else : echo "changeHideShow2('maskDisplay06','off');"; endif;
    if ($maskDisplay07Switch == "1") : echo "preChangeHideShow('maskDisplay07','on');"; else : echo "changeHideShow2('maskDisplay07','off');"; endif;
    if ($maskDisplay08Switch == "1") : echo "preChangeHideShow('maskDisplay08','on');"; else : echo "changeHideShow2('maskDisplay08','off');"; endif;
    if ($maskDisplay09Switch == "1") : echo "preChangeHideShow('maskDisplay09','on');"; else : echo "changeHideShow2('maskDisplay09','off');"; endif;

    if ($initialPageCall == "") : 
       echo "preChangeHideShow('maskDisplay02','on');"; 
    endif;

    if ($jsExecBodyOnLoadArray[0] == "1") : echo "setSuFormData(); setCbFormData(); setCdrFormData();"; endif;
    if ($jsExecBodyOnLoadArray[1] == "1") : echo "resetSuFormData(); resetCbFormData(); resetCdrFormData();"; endif;
    if ($jsExecBodyOnLoadArray[2] == "1") : echo "getServiceunitData('" . $f_su_admin_filter_1 . "'); getCashBoxData('" . $f_cb_admin_filter_1 . "');"; endif;  // getCardrollData('" . $f_cdr_admin_filter_1 . "');
  ?>
  disableItems(false);
  myshow('maincontent');  
  $('#tour_amounts').html('<b>BETRÄGE: ' + tourSumOutput + '</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + '<b>GEWICHT: ' + tourWeightOutput + '</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + '<b>ANZAHL: ' + tourCountOutput + '</b>');
  changeNavState('#nav02');  // Init fixed header for service units
  displayStatusMessage();
}

function disableItems (boolState) {
  $('#action_optimize').prop('disabled',boolState);
  $('#action_map').prop('disabled',boolState);
  $('#action_makejob').prop('disabled',boolState);
}

$(document).ready(function() {
  disableItems(false);
});
-->
</script>

<?php echo $outServiceJobJsDate ?>

<?php
  if ($isFirefox) :
     $vehicleselectioncontainerDivPos = "style=\"position:fixed; top:100px; left:370px; width:280px; height:300px; z-index:13; border:grey 3px solid; overflow:auto; background-color:#AACCAA; box-shadow: 10px 20px 30px grey;\"";
     $tablecolselectioncontainerDivPos = "style=\"position:fixed; top:100px; left:35px; width:1200px; height:130px; z-index:13; border:grey 3px solid; overflow:auto; background-color:#AACCAA; box-shadow: 10px 20px 30px grey;\"";
     $actioncontainerDivPos = "style=\"position:fixed; top:100px; left:300; width:500px; height:500px; border:grey 3px solid; background-color:#8888FF; box-shadow: 10px 20px 30px grey;\"";
     $contentcontainerDivPos = "style=\"position:fixed; top:150px; left:500; width:1024px; height:768px; z-index:12; border:grey 3px solid; overflow:auto; background-color:#AACCAA; box-shadow: 10px 20px 30px grey;\"";
  else :
     $vehicleselectioncontainerDivPos = "";
     $actioncontainerDivPos = "";
     $contentcontainerDivPos = "";
?>
   <style type="text/css">
   	 #vehicleselectioncontainer { position:fixed; top:100px; left:370px; width:280px; height:300px; z-index:13; border:grey 3px solid; background-color:#AACCAA; box-shadow: 10px 20px 30px grey; }
   	 #tablecolselectioncontainer { position:fixed; top:100px; left:30px; width:1200px; height:130px; z-index:13; border:grey 3px solid; background-color:#AACCAA; box-shadow: 10px 20px 30px grey; }
     #actioncontainer { position:absolute; top:100px; left:300px; width:500px; height:500px; border:grey 3px solid; background-color:#8888FF; box-shadow: 10px 20px 30px grey; }
     #contentcontainer { position:absolute; top:150px; left:500px; width:1024px; height:768px; z-index:12; border:grey 3px solid; background-color:#AACCAA; box-shadow: 10px 20px 30px grey; }
     html>body #actioncontainer { position: fixed; }
   </style>
   <!--[if lt IE 7]>
   <style type="text/css">
     @media screen {
       html, body {
         height: 100%; overflow-y: hidden;
       }
       #scrollcontainer {
         height: 100%; width: 100%; overflow: auto;
       }
     }
   </style>
   <![endif]-->
<?php   
  endif;
?>


</head>

<body onLoad="execBodyOnLoad();">

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

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

<script type="text/javascript">myhide('maincontent');</script>

  <form name="servicejobs" action="../illt/servicejob.php" method="post">
  	
  <div id="scrollcontainer">

    <input type="hidden" name="f_act" value="">
    <?php echo $phpCurrentNavigationInputHidden ?>
    <input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
    <input type="hidden" name="statusMessage" value="">

    <input type="hidden" name="initialPageCall" value="<?php echo $initialPageCall ?>">
    <input type="hidden" name="f_suLoadStates" value="0">
    <input type="hidden" name="f_su_orderByCol" value="<?php echo ec($f_su_orderByCol) ?>">
    <input type="hidden" name="f_jb_orderByCol" value="<?php echo ec($f_jb_orderByCol) ?>">
    <input type="hidden" name="f_log_orderByCol" value="<?php echo ec($f_log_orderByCol) ?>">
    <input type="hidden" name="f_map_is_active" value="<?php echo ec($f_map_is_active) ?>">
    <input type="hidden" name="f_tour_crvh_assoc" value="">

    <input type="hidden" name="maskDisplay00Switch" value="<?php echo $maskDisplay00Switch ?>">
    <input type="hidden" name="maskDisplay01Switch" value="<?php echo $maskDisplay01Switch ?>">
    <input type="hidden" name="maskDisplay02Switch" value="<?php echo $maskDisplay02Switch ?>">
    <input type="hidden" name="maskDisplay03Switch" value="<?php echo $maskDisplay03Switch ?>">
    <input type="hidden" name="maskDisplay04Switch" value="<?php echo $maskDisplay04Switch ?>">
    <input type="hidden" name="maskDisplay05Switch" value="<?php echo $maskDisplay05Switch ?>">
    <input type="hidden" name="maskDisplay06Switch" value="<?php echo $maskDisplay06Switch ?>">
    <input type="hidden" name="maskDisplay07Switch" value="<?php echo $maskDisplay07Switch ?>">
    <input type="hidden" name="maskDisplay08Switch" value="<?php echo $maskDisplay08Switch ?>">
    <input type="hidden" name="maskDisplay09Switch" value="<?php echo $maskDisplay09Switch ?>">

    <input type="hidden" name="f_actionObjType" value="<?php echo $f_actionObjType ?>">
    <input type="hidden" name="f_actionObjId" value="<?php echo $f_actionObjId ?>">
    <input type="hidden" name="f_actionID" value="<?php echo $f_actionID ?>">

    <table width="100%" border="0">
    	<tr>
    		<td width="20">
    	  </td>

        <td>
        	<!-- LOGO -->
          <div style="float:left;width:215px;height:50px;">
        	  <div style="float:left;">
        	    <div><img src="../images/external/hochbahn_hh.jpg" border="0" height="46" width="210"></div>
        	    <?php echo htmlDivLineSpacer("5px"); ?>
        	    <?php // echo defineButtonType08("Automatendaten importieren", "action_import", "finishPage('');", "205", "", "") ?>
        	    <?php // echo htmlDivLineSpacer("5px"); ?>
        	    <!--
        	    <div class="f10bp1_blue" style="float:left;"><input type="text" name="f_search" value="<?php echo $f_search ?>" size="17">&nbsp;</div>
        	    <?php echo defineButtonType08("Suche", "import", "finishPage('');", "70", "", "") ?>
        	    -->
        	  </div>
          </div>

        	<!-- NAVIGATION START -->
        	<div id="category_buttons">
            <input id="maskDisplay00Action" type="checkbox" value="0" onChange="preChangeHideShow('maskDisplay00', ($(this).is(':checked') ? 'on' : 'off'));" /><label for="maskDisplay00Action" class="navlabel">SYSTEMMELDUNGEN</label>
            <input id="maskDisplay01Action" type="checkbox" value="1" onChange="preChangeHideShow('maskDisplay01', ($(this).is(':checked') ? 'on' : 'off'));" /><label for="maskDisplay01Action" class="navlabel">SCHWELLWERTE</label>
            <input id="maskDisplay02Action" type="checkbox" value="2" onChange="preChangeHideShow('maskDisplay02', ($(this).is(':checked') ? 'on' : 'off'));" /><label for="maskDisplay02Action" class="navlabel">AUTOMATENZUSTÄNDE</label>
            <input id="maskDisplay03Action" type="checkbox" value="3" onChange="preChangeHideShow('maskDisplay03', ($(this).is(':checked') ? 'on' : 'off'));" /><label for="maskDisplay03Action" class="navlabel">AUFTRÄGE</label>
            <?php if ($maskClassicMode) : ?>
              <input id="maskDisplay04Action" type="checkbox" value="4" onChange="preChangeHideShow('maskDisplay04', ($(this).is(':checked') ? 'on' : 'off'));" /><label for="maskDisplay04Action" class="navlabel">ZUSTANDSVERLAUF</label>
              <input id="maskDisplay05Action" type="checkbox" value="5" onChange="preChangeHideShow('maskDisplay05', ($(this).is(':checked') ? 'on' : 'off'));" /><label for="maskDisplay05Action" class="navlabel">BETRIEBSMELDUNGEN</label>
            <?php endif; ?>
            <input id="maskDisplay06Action" type="checkbox" value="6" onChange="preChangeHideShow('maskDisplay06', ($(this).is(':checked') ? 'on' : 'off'));" /><label for="maskDisplay06Action" class="navlabel">VERWALTUNG</label>
            <input id="maskDisplay07Action" type="checkbox" value="7" onChange="preChangeHideShow('maskDisplay07', ($(this).is(':checked') ? 'on' : 'off'));" /><label for="maskDisplay07Action" class="navlabel">GLOBALE WERTE</label>
            <input id="maskDisplay08Action" type="checkbox" value="4" onChange="preChangeHideShow('maskDisplay08', ($(this).is(':checked') ? 'on' : 'off'));" /><label for="maskDisplay08Action" class="navlabel">DATENIMPORT</label>
            <input id="maskDisplay09Action" type="checkbox" value="5" onChange="preChangeHideShow('maskDisplay09', ($(this).is(':checked') ? 'on' : 'off'));" /><label for="maskDisplay09Action" class="navlabel">ABHOLUNGEN</label>
          </div>

          <?php echo htmlDivLineSpacer("20px", "", "left"); ?>
          <!-- NAVIGATION END -->

          <!-- ******************************************************************************************** -->

          <!-- GLOBAL STATE VALUES OF ALL SERVICEUNITS -->
          <div id="maskDisplay07" name="maskDisplay07">
            <?php echo defineButtonType08("-", "action_global_state_values", "preChangeHideShow('maskDisplay07','off');", "10", "left", "2") ?>
            <div class="f10bp1_blue" style="float:left">
              <?php echo getLngt("GLOBALE WERTE:") ?>&nbsp;&nbsp;&nbsp;&nbsp;
            </div>
            <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
            <div id="maskDisplay07Content" name="maskDisplay07Content">
              <?php 
                getGlobalStateData ();
                echo getLngt("AUTOMATENANZAHL:") . "&nbsp;" . $outGlobalStateArray["numOfRowsSU"] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                echo getLngt("KRITISCHE AUTOMATEN:") . "&nbsp;" . $outGlobalStateArray["numOfCriticalRowsSU"] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                echo getLngt("SEMIKRITISCHE AUTOMATEN:") . "&nbsp;" . $outGlobalStateArray["numOfSemiCriticalRowsSU"] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                /*
                echo "<br><br>";
                echo getLngt("BEK:") . "&nbsp;" . number_format($outGlobalStateArray["ati_data_05"], 0, ",", ".") . "&nbsp;€&nbsp;&nbsp;&nbsp;&nbsp;";
                echo getLngt("MEK:") . "&nbsp;" . number_format($outGlobalStateArray["ati_data_06"], 2, ",", ".") . "&nbsp;€&nbsp;&nbsp;&nbsp;&nbsp;";
                echo getLngt("H1:")  . "&nbsp;" . number_format($outGlobalStateArray["ati_data_07"], 0, ",", ".") . "&nbsp;€&nbsp;&nbsp;&nbsp;&nbsp;";
                echo getLngt("H2:")  . "&nbsp;" . number_format($outGlobalStateArray["ati_data_08"], 2, ",", ".") . "&nbsp;€&nbsp;&nbsp;&nbsp;&nbsp;";
                echo getLngt("Dispenser:")  . "&nbsp;" . number_format($outGlobalStateArray["ati_data_09"], 2, ",", ".") . "&nbsp;€&nbsp;&nbsp;&nbsp;&nbsp;";
                $outGlobalSum = $outGlobalStateArray["ati_data_05"] + $outGlobalStateArray["ati_data_06"] + $outGlobalStateArray["ati_data_07"] + $outGlobalStateArray["ati_data_08"] + $outGlobalStateArray["ati_data_09"];
                echo getLngt("Summe:")  . "&nbsp;" . number_format( $outGlobalSum, 2, ",", ".") . "&nbsp;€";
                */
              ?>
            </div>
            <?php echo htmlDivLineSpacer("20px"); ?>
          </div>

          <!-- IMPORT DATA OF ALL SERVICEUNITS -->
          <div id="maskDisplay08" name="maskDisplay08">
            <?php echo defineButtonType08("-", "action_global_state_values", "preChangeHideShow('maskDisplay08','off');", "10", "left", "2") ?>
            <div class="f10bp1_blue" style="float:left">
              <?php echo getLngt("DATENIMPORT:") ?>&nbsp;&nbsp;&nbsp;&nbsp;
            </div>
            <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
            <div id="maskDisplay08Content" name="maskDisplay08Content">
            	<?php echo htmlDivLineSpacer("5px"); ?>
            	<?php echo defineButtonType08(getLngt("Manueller Import"), "action_import_SOAP", "openImportSOAP();", "130", "left", "2", "", "", "", "") ?>
              <?php 
                // echo "<a href=\"../import/soap.php?hq_id=1&mode=1&timestamp=" . getDateTime("date_plus_offset", array(0,-1,0), "YmdHis") . "\" target=\"_blank\">" . getLngt("Import Stammdaten") . "</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;";
                // echo "<a href=\"../import/soap.php?hq_id=1&mode=0&timestamp=" . getDateTime("date_plus_offset", array(0,-1,0), "YmdHis") . "\" target=\"_blank\">" . getLngt("Import Statusdaten") . "</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;";
                // echo "<a href=\"../import/import_SOAP_HHA.php?f_act=executeImport\" target=\"_blank\">" . getLngt("Manueller Import") . "</a>" . "&nbsp;&nbsp;&nbsp;&nbsp;";
              ?>
            </div>
            <?php echo htmlDivLineSpacer("40px"); ?>
          </div>

          <!-- DAILY CARGO LIST -->
          <div id="maskDisplay09" name="maskDisplay09">
            <?php echo defineButtonType08("-", "action_cargo_list", "preChangeHideShow('maskDisplay09','off');", "10", "left", "2") ?>
            <div class="f10bp1_blue" style="float:left">
              <?php echo getLngt("ABHOLUNGEN:") ?>&nbsp;&nbsp;&nbsp;&nbsp;
            </div>
            <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
            <div id="maskDisplay09Content" name="maskDisplay09Content">
              <?php 
                // Get number of all article types
                $articleGroupPhrase = "(at_group LIKE '%4%' OR at_group LIKE '%7%') ";
                // $numOfAllArticleTypes = getCountOfTable("article", $articleGroupPhrase);  // Number of ALL article types
                $articleTypeArray = getColVectorFromDB2ArrayByClause("article", "at_id", $articleGroupPhrase, "", "at_id", "");
                $numOfAllArticleTypes = count($articleTypeArray);
                
                // Get all customer IDs of sales points, etc.
                $csIdArray = getColVectorFromDB2ArrayByClause("customer AS cs, company AS cmp", "cs_id", "cs.cmp_id = cmp.cmp_id AND cmp.cmp_type = '1'", "", "", "");
                $csIdArrayLen = count($csIdArray);

                $outCargoList = "";
                for ($c = 0; $c < $csIdArrayLen; $c++) :
                    $tmpCmpId = getFieldValueFromId("customer","cs_id",$csIdArray[$c],"cmp_id");
                    $tmpCmpComp = getFieldValueFromId("company","cmp_id",$tmpCmpId,"cmp_comp");
                    $tmpCmpComp2 = getFieldValueFromId("company","cmp_id",$tmpCmpId,"cmp_comp2");
                    $outCargoList .= "<br><span class=\"f10bp1_darkgreen\">" . $tmpCmpComp . "&nbsp;" . $tmpCmpComp2 . "</span><br>";

                    // Get all costcenters of each customer being a sales points, etc. (No root costcenters !!!!)
                    $cscIdArray = getColVectorFromDB2ArrayByClause("costcenter AS csc", "csc_id", "csc.cs_id = '" . $csIdArray[$c] . "' AND (NOT ISNULL(csc.csc_pre_id)) AND csc.csc_pre_id != ''", "", "", "");
                    $cscIdArrayLen = count($cscIdArray);

                    for ($d = 0; $d < $cscIdArrayLen; $d++) :
                        $tmpCscName = getFieldValueFromId("costcenter","csc_id",$cscIdArray[$d],"csc_name");
                        
                        $outCargoList .= "<br><br><span class=\"f10bp1_darkgreen\">" . "&nbsp;&nbsp;" . $tmpCscName . "</span><br><br>";

                        for ($a = 0; $a < $numOfAllArticleTypes; $a++) :
                            $tmpDate = substr($predictionDate,0,4) . substr($predictionDate,5,2) . substr($predictionDate,8,2);
                            $outCargoArray = getSpecialAnnouncements($cscIdArray[$d], $articleTypeArray[$a], $tmpDate, "2");

                            if (count($outCargoArray[0]) > 0) :
                               $tmpAtDescription = getFieldValueFromId("article","at_id",$articleTypeArray[$a],"at_description");
                               $outCargoList .= "<span class=\"f8np1_red\">" . $tmpAtDescription . "</span>";
                               $outCargoList .= "<br>";
                               $outCargoList .= getSpecialAnnouncements($cscIdArray[$d], $articleTypeArray[$a], $tmpDate, "2");
                            else :
                               $outCargoList .= "&nbsp;:&nbsp;" . getLngt("Keine") . "<br>";
                            endif;
                            $outCargoList .= "<br>";
                        endfor;
                    endfor;
                    $outCargoList .= "<br><br>";
                endfor;
                echo $outCargoList;
              ?>
            </div>
            <?php echo htmlDivLineSpacer("20px"); ?>
          </div>

          <!-- ******************************************************************************************** -->

          <!-- ******************************************************************************************** -->

          <!-- REPORT ENTRIES, SYSTEM MESSAGES -->
          <div id="maskDisplay00" name="maskDisplay00">
            <?php echo defineButtonType08("-", "action_reports", "preChangeHideShow('maskDisplay00','off');", "10", "left", "2") ?>
            <div class="f10bp1_red" style="float:left">
              <?php echo getLngt("SYSTEMMELDUNGEN:") ?>&nbsp;&nbsp;&nbsp;&nbsp;
            </div>
            <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
            <div id="maskDisplay00Content" name="maskDisplay00Content">
              <?php echo $outReport ?>
            </div>
            <?php echo htmlDivLineSpacer("20px"); ?>
          </div>

          <!-- THRESHOLD VALUES -->
          <div id="maskDisplay01" name="maskDisplay01">
          	<div id="nav01" name="nav01">
              <?php echo defineButtonType08("-", "action_states", "preChangeHideShow('maskDisplay01','off');", "10", "left", "2") ?>
              <div class="f10bp1_blue">
                <?php echo getLngt("SCHWELLWERTE:") ?>&nbsp;&nbsp;&nbsp;&nbsp;
              </div>
              <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
              <?php echo defineButtonType08("Aktuelle Werte speichern", "action_tv_default", "finishPage('tv_store');", "180", "left", "2") ?>
              <?php echo defineButtonType08("Standardwerte laden", "action_tv_default", "tvSetDefaults();", "180", "left", "2") ?>
              <?php echo defineButtonType08("Automatenzustände aktualisieren", "action_tv_reload", "finishPage('');", "200", "left", "2") ?>
              <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
            </div>
            <div>
              <div>
                <?php echo $outThresholdValues ?>
              </div>
              <?php echo htmlDivLineSpacer("20px"); ?>
            </div>
          </div>

          <!-- ADMINISTRATION OF SERVICE UNITS, CASHBOXES, ETC. -->
          <div id="maskDisplay06" name="maskDisplay06">
          	<div id="nav06" name="nav06">
              <?php echo defineButtonType08("-", "action_log", "preChangeHideShow('maskDisplay06','off');", "10", "left", "2") ?>
              <div class="f10bp1_blue">
                <?php echo getLngt("VERWALTUNG:") ?>
              </div>
              <?php echo htmlDivLineSpacer("5px"); ?>
              <!-- SERVICE UNITS -->
              <div class="f10bp1_blue" style="float:left">
                <select name="f_su_admin_filter_1" onChange="getServiceunitData('');">
       	          <option value=""><?php echo getLngt("SERVICEEINHEITEN:") ?></option>
                  <?php echo addOptionsFromTable("articleitem AS ati, stock AS stk, article AS at","ati_serialno","ati_serialno","ati_serialno","ati.at_id = at.at_id AND at.at_group LIKE '%,1,%' AND ati.stk_id = stk.stk_id AND stk.stk_pre_id = '" . $rootStockSU . "' ",$f_su_admin_filter_1); ?>
                </select>&nbsp;&nbsp;
                <select name="f_su_admin_stk_id" onChange="getStockData();">
       	          <option value=""><?php echo getLngt("STANDORTE:") ?></option>
                  <?php echo addOptionsFromTable("stock","stk_id","stk_name","stk_name","stk_pre_id = '" . $rootStockSU . "' ",$f_su_admin_stk_id); ?>
                </select>&nbsp;&nbsp;
              </div>
              <?php // echo defineButtonType08("Automatendaten speichern", "action_store_form_serviceunit", "finishFormServiceUnitStore();", "200", "left", "2") ?>
              <?php // echo defineButtonType08("Standortdaten speichern", "action_store_form_stock", "finishFormStock();", "200", "left", "2") ?>
              <?php echo defineButtonType08("Zurücksetzen", "action_reset_form_su", "resetSuFormData();", "140", "left", "2") ?>
              <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
            </div>
            <div>
              <div>
                <?php echo $outSuFormData ?>
              </div>
              <?php echo htmlDivLineSpacer("20px"); ?>
              <!-- CASH BOXES -->
              <div class="f10bp1_blue" style="float:left">
                <select name="f_cb_admin_filter_1" onChange="getCashBoxData('');">
       	          <option value=""><?php echo getLngt("GELDKASSETTEN:") ?></option>
                  <?php echo addOptionsFromTable("articleitem AS ati, stock AS stk, article AS at","ati_serialno","ati_serialno","ati_serialno","ati.at_id = at.at_id AND at.at_group LIKE '%,2,%' AND ati.stk_id = stk.stk_id",$f_cb_admin_filter_1); ?>
                </select>&nbsp;&nbsp;
                <select name="f_cb_admin_filter_2">
       	          <option value=""><?php echo getLngt("TYPEN:") ?></option>
                  <?php echo addOptionsFromTable("article","at_id","at_match","at_match","at_group LIKE '%,2,%' ",$f_cb_admin_filter_2); ?>
                </select>&nbsp;&nbsp;
              </div>
              <?php echo defineButtonType08("Zurücksetzen", "action_reset_form_cb", "resetCbFormData();", "140", "left", "2") ?>
              <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
              <div>
                <?php echo $outCbFormData ?>
              </div>
              <?php echo htmlDivLineSpacer("20px"); ?>
              <!-- CARD ROLLS -->
              <div class="f10bp1_blue" style="float:left">
              	<!--
                <select name="XXXX_f_cdr_admin_filter_1" onChange="getCardrollData('');">
       	          <option value=""><?php // echo getLngt("KARTENROLLEN:") ?></option>
                  <?php // echo addOptionsFromTable("articleitem AS ati, stock AS stk, article AS at","ati_serialno","ati_serialno","ati_serialno","ati.at_id = at.at_id AND at.at_group LIKE '%,5,%' AND ati.stk_id = stk.stk_id",$f_cdr_admin_filter_1); ?>
                </select>&nbsp;&nbsp;
                -->
                <?php echo getLngt("KARTENROLLEN:") ?>
                <select name="f_cdr_admin_filter_2">
       	          <option value=""><?php echo getLngt("TYPEN:") ?></option>
                  <?php echo addOptionsFromTable("article","at_id","at_match","at_match","at_group LIKE '%,5,%' ",$f_cdr_admin_filter_2); ?>
                </select>&nbsp;&nbsp;
              </div>
              <?php echo defineButtonType08("Zurücksetzen", "action_reset_form_cb", "resetCdrFormData();", "140", "left", "2") ?>
              <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
              <div>
                <?php echo $outCdrFormData ?>
              </div>
              <?php echo htmlDivLineSpacer("20px"); ?>
            </div>
          </div>

          <!-- CURRENT STATES OF SERVICE UNITS -->
          <div id="maskDisplay02" name="maskDisplay02">
          	<div id="nav02" name="nav02">
              <?php echo defineButtonType08("-", "action_threshold", "preChangeHideShow('maskDisplay02','off');", "10", "left", "2") ?>
              <div class="f10bp1_blue" style="float:left">
                <?php echo getLngt("AUTOMATENZUSTÄNDE:") ?>&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="hidden" id="f_pt_filter_01_01" name="f_pt_filter_01_01" value="<?php echo $f_pt_filter_01_01 ?>">
                <input type="button" id="f_pt_button_filter_01_01" style="size:10px;" onClick="toggleFilter('f_pt_filter_01_01');">&nbsp;&nbsp;
                <input type="hidden" id="f_pt_filter_01_02" name="f_pt_filter_01_02" value="<?php echo $f_pt_filter_01_02 ?>">
                <input type="button" id="f_pt_button_filter_01_02" style="size:10px;" onClick="toggleFilter('f_pt_filter_01_02');">&nbsp;&nbsp;
                <input type="hidden" id="f_pt_filter_01_03" name="f_pt_filter_01_03" value="<?php echo $f_pt_filter_01_03 ?>">
                <input type="button" id="f_pt_button_filter_01_03" style="size:10px;" onClick="toggleFilter('f_pt_filter_01_03');">&nbsp;&nbsp;
                <input type="button" id="call_vehicleselection" value="<?php echo getLngt("Touren") ?>" onClick="callVehicleSelection();">&nbsp;&nbsp;
                <input type="button" id="call_tablecolselection" value="<?php echo getLngt("Anzeige") ?>" onClick="callTableColSelection();">&nbsp;&nbsp;
                <select name="f_su_sort_sequence" onChange="finishPage('');">
       	          <option value="0" <?php echo ($f_su_sort_sequence == "0" ? "selected" : ""); ?>><?php echo getLngt("Sortierung aufsteigend") ?></option>
       	          <option value="1" <?php echo ($f_su_sort_sequence == "1" ? "selected" : ""); ?>><?php echo getLngt("Sortierung absteigend") ?></option>
                </select>&nbsp;&nbsp;&nbsp;&nbsp;
                <!--
                <select name="f_pt_filter_1" onChange="preFinishPage('');">
       	          <option value="0" <?php echo ($f_pt_filter_1 == "0" ? "selected" : ""); ?>><?php echo getLngt("Alle Automaten") ?></option>
       	          <option value="1" <?php echo ($f_pt_filter_1 == "1" ? "selected" : ""); ?>><?php echo getLngt("Nur kritische Automaten") ?></option>
       	          <option value="2" <?php echo ($f_pt_filter_1 == "2" ? "selected" : ""); ?>><?php echo getLngt("Nur unkritische Automaten") ?></option>
                </select>&nbsp;&nbsp;&nbsp;&nbsp;
                -->
                <select name="f_pt_action_1" onChange="suCheckboxes();">
       	          <option value="0"><?php echo getLngt("AUSWAHLAKTIONEN:") ?></option>
       	          <option value="1"><?php echo getLngt("Ausschließlich alle kritischen auswählen") ?></option>
       	          <option value="2"><?php echo getLngt("Kritische der aktuellen Auswahl zufügen") ?></option>
       	          <option value="3"><?php echo getLngt("Alle auswählen") ?></option>
       	          <option value="4"><?php echo getLngt("Alle abwählen") ?></option>
       	          <option value="5"><?php echo getLngt("Auswahlzustand sichern") ?></option>
       	          <option value="6"><?php echo getLngt("Auswahlzustand laden") ?></option>
       	          <?php if ($suServiceIsCriticalByDefaultVehicleOnly == "1") : ?>
       	            <option value="7"><?php echo getLngt("Ausschließlich Fahrzeugvorbelegungen auswählen") ?></option>
       	            <option value="8"><?php echo getLngt("Fahrzeugvorbelegungen der aktuellen Auswahl zufügen") ?></option>
       	          <?php endif; ?>
                </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              </div>
              <?php echo defineButtonType08("Optimierung", "action_optimize", "suOptimize();", "100", "left", "2") ?>
              <?php echo defineButtonType08("Karte", "action_map", "openTourMap();", "100", "left", "2", "", "", "", "") ?>
              <?php echo defineButtonType08("Touren erzeugen", "action_makejob", "suMakeJob();", "130", "left", "7", "", "", "", "") ?>
              <div style="float:left">
                <?php echo getLngt("Prognose:") ?>&nbsp;<?php echo $jbDatePrediction ?>&nbsp;&nbsp;&nbsp;&nbsp;
              </div>
              <?php echo defineButtonType08("Aktualisieren", "action_su_reload", "finishPage('');", "100", "left", "2") ?>
              <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
              <div id="tour_amounts">
            	
              </div>
              <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
            </div>
            <div>
              <div>
              	<?php echo $outEventStates ?>
              </div>
              <?php echo htmlDivLineSpacer("20px"); ?>
            </div>
          </div>          

          <!-- SERVICE JOBS -->
          <div id="maskDisplay03" name="maskDisplay03">
            <div id="nav03" name="nav03">
              <?php echo defineButtonType08("-", "action_states", "preChangeHideShow('maskDisplay03','off');", "10", "left", "2") ?>
              <div class="f10bp1_blue" style="float:left">
                <?php echo getLngt("AUFTRÄGE:") ?>&nbsp;&nbsp;
                <?php 
                  echo $jbDateFilter;
                  // echo $jbTimeFilter;
                ?>
                <select name="f_jb_sort_sequence" onChange="finishPage('');">
       	            <option value="0" <?php echo ($f_jb_sort_sequence == "0" ? "selected" : ""); ?>><?php echo getLngt("Sortierung aufsteigend") ?></option>
       	            <option value="1" <?php echo ($f_jb_sort_sequence == "1" ? "selected" : ""); ?>><?php echo getLngt("Sortierung absteigend") ?></option>
                </select>&nbsp;&nbsp;
                <select name="f_jb_filter_1" onChange="preFinishPage('');">
       	          <option value="0" <?php echo ($f_jb_filter_1 == "0" ? "selected" : ""); ?>><?php echo getLngt("Alle Aufträge") ?></option>
       	          <option value="1" <?php echo ($f_jb_filter_1 == "1" ? "selected" : ""); ?>><?php echo getLngt("Laufende Aufträge") ?></option>
       	          <option value="2" <?php echo ($f_jb_filter_1 == "2" ? "selected" : ""); ?>><?php echo getLngt("Erledigte Aufträge") ?></option>
                </select>&nbsp;&nbsp;
                <select name="f_jb_filter_2" onChange="preFinishPage('');">
       	          <option value=""><?php echo getLngt("SERVICEEINHEITEN:") ?></option>
                  <?php echo addOptionsFromTable("articleitem AS ati, stock AS stk","ati_serialno","ati_serialno","ati_serialno","ati.stk_id = stk.stk_id AND stk.stk_pre_id = '" . $rootStockSU . "' ",$f_jb_filter_2); ?>
                </select>&nbsp;&nbsp;
                <select name="f_jb_filter_3" onChange="preFinishPage('');">
       	          <option value=""><?php echo getLngt("STANDORTE:") ?></option>
                  <?php echo addOptionsFromTable("stock","stk_name","stk_name","stk_name","stk_pre_id = '" . $rootStockSU . "' ",$f_jb_filter_3); ?>
                </select>&nbsp;&nbsp;
              </div>
              <?php echo htmlDivLineSpacer("15px", "", "left"); ?>
              <?php echo defineButtonType08("Aktualisieren", "action_jb_reload", "finishPage('');", "140", "left", "2") ?>
              <?php echo defineLinkButtonType08("Auftragslisten", "action_jb_list", "../admin/jb_list_fs.php?maskNumOfWins=" . $empMaskMultiJoblist, "140", "left", "2") ?>
              <?php echo htmlDivLineSpacer("15px", "", "left"); ?>
            </div>
            <div>
              <div>
                <?php echo $outServiceJobs ?>
              </div>
              <?php echo htmlDivLineSpacer("20px"); ?>
            </div>
          </div>

          <?php if ($maskClassicMode) : ?>
            <!-- STATE LOG OF A SPECIFIED SERVICE UNIT -->
            <div id="maskDisplay04" name="maskDisplay04">
              <?php echo defineButtonType08("-", "action_log", "preChangeHideShow('maskDisplay04','off');", "10", "left", "2") ?>
              <div class="f10bp1_blue" style="float:left">
                <?php echo getLngt("ZUSTANDSVERLAUF:") ?>&nbsp;&nbsp;&nbsp;&nbsp;
                <select name="f_log_filter_1" onChange="finishPage('processAction');">
       	          <option value="0" <?php echo ($f_log_filter_1 == "0" ? "selected" : ""); ?>><?php echo getLngt("Alle Zustandsdatensätze") ?></option>
       	          <option value="1" <?php echo ($f_log_filter_1 == "1" ? "selected" : ""); ?>><?php echo getLngt("Kritische Zustandsdatensätze (mindestens ein Wert)") ?></option>
       	          <option value="2" <?php echo ($f_log_filter_1 == "2" ? "selected" : ""); ?>><?php echo getLngt("Unkritische Zustandsdatensätze (alle Werte)") ?></option>
                </select>&nbsp;&nbsp;&nbsp;&nbsp;
              </div>
              <?php echo defineButtonType08("Aktualisieren", "action_log_reload", "finishPage('processAction');", "140", "left", "2") ?>
              <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
              <div>
                <?php echo $outLogData ?>
              </div>
              <?php echo htmlDivLineSpacer("20px"); ?>
            </div>
          <?php endif; ?>

          <?php if ($maskClassicMode) : ?>
            <!-- STATE LOG OF A SPECIFIED SERVICE UNIT -->
            <div id="maskDisplay05" name="maskDisplay05">
              <?php echo defineButtonType08("-", "action_log", "preChangeHideShow('maskDisplay05','off');", "10", "left", "2") ?>
              <div class="f10bp1_blue" style="float:left">
                <?php echo getLngt("BETRIEBSMELDUNGEN:") ?>&nbsp;&nbsp;&nbsp;&nbsp;
              </div>
              <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
              <div>
                <?php echo $outMessageData ?>
              </div>
              <?php echo htmlDivLineSpacer("20px"); ?>
            </div>
          <?php endif ?>

          <!-- ADMINISTRATION ... -->
          <!-- ... -->

        </td>       

    	  <td width="20">
    	  </td>
      </tr>
    </table>

  </div>   <!-- scrollcontainer -->
  

  <!-- Container for vehicle selection entries -->
  <div id="vehicleselectioncontainer" <?php echo $vehicleselectioncontainerDivPos ?>>
  	<div id="vehicleselection" style="text-align:center; vertical-align:middle;"></div>
    <?php  	
      // Vehicle buttons
      echo "<br>&nbsp;&nbsp;" . getLngt("Anzeige der Tourenvorbelegung:") . "<br><br>&nbsp;&nbsp;";
    ?>
    <input type="hidden" id="f_crvh_selection_00" name="f_crvh_selection_00" value="<?php echo $f_crvh_selection_00 ?>">
    <input type="button" id="f_crvh_button_selection_00" style="size:10px;" value="0" onClick="toggleFilter('f_crvh_selection_00');">&nbsp;&nbsp;
    <input type="hidden" id="f_crvh_selection_01" name="f_crvh_selection_01" value="<?php echo $f_crvh_selection_01 ?>">
    <input type="button" id="f_crvh_button_selection_01" style="size:10px;" value="1" onClick="toggleFilter('f_crvh_selection_01');">&nbsp;&nbsp;
    <input type="hidden" id="f_crvh_selection_02" name="f_crvh_selection_02" value="<?php echo $f_crvh_selection_02 ?>">
    <input type="button" id="f_crvh_button_selection_02" style="size:10px;" value="2" onClick="toggleFilter('f_crvh_selection_02');">&nbsp;&nbsp;
    <input type="hidden" id="f_crvh_selection_03" name="f_crvh_selection_03" value="<?php echo $f_crvh_selection_03 ?>">
    <input type="button" id="f_crvh_button_selection_03" style="size:10px;" value="3" onClick="toggleFilter('f_crvh_selection_03');">&nbsp;&nbsp;
    <input type="hidden" id="f_crvh_selection_04" name="f_crvh_selection_04" value="<?php echo $f_crvh_selection_04 ?>">
    <input type="button" id="f_crvh_button_selection_04" style="size:10px;" value="4" onClick="toggleFilter('f_crvh_selection_04');">&nbsp;&nbsp;
  	<?php echo htmlDivLineSpacer("25px"); ?>
    <?php
    $outTourCrvhAssoc = "&nbsp;&nbsp;" . getLngt("Zuordnung bei der Tourenerzeugung") . "<br>\n";
    $outTourCrvhAssoc .= "&nbsp;&nbsp;" . getLngt("TOUR => FAHRZEUG") . "<br><br>\n";
    for ($j = 1; $j <= $maxNumOfTours; $j++) :
        $outTourCrvhAssoc .= "&nbsp;&nbsp;" . pad($j, 2) . "&nbsp;&nbsp;=>&nbsp;&nbsp;";
        $outTourCrvhAssoc .= "<select name=\"f_tour_crvh_assoc_" . pad($j, 2) . "\" onChange=\"changeTourVehicleAssoc(" . $j . ")\">\n";
        $outTourCrvhAssoc .= "  <option value=\"0\">" . "----" . "</option>\n";
        for ($k = 1; $k <= $mappedCourierArrayLen; $k++) :
            $tmpCrvhSid = getFieldValueFromId("couriervehicle","cr_id",$mappedCourierArray[$k],"crvh_sid");
            if ($tmpCrvhSid != "") :
               $outTourCrvhAssoc .= "  <option value=\"" . $k . "\" " . ($k == $j ? "selected" : "") . ">" . $tmpCrvhSid . "</option>\n";
            endif;
        endfor;
        $outTourCrvhAssoc .= "</select><br>\n";
    endfor;
    echo $outTourCrvhAssoc;
  	?>
  	<?php echo htmlDivLineSpacer("25px"); ?>
  	<div style="text-align:center; vertical-align:middle;"><input type="button" name="close_vehicleselection" value="<?php echo "Schließen" ?>" onClick="callVehicleSelection();"></div>
  </div>


  <!-- Container for table columns to show or hide -->
  <div id="tablecolselectioncontainer" <?php echo $tablecolselectioncontainerDivPos ?>>
  	<div id="tablecolselection" style="text-align:center; vertical-align:middle;"></div>
    <?php  	
      // Table column buttons
      echo "<br>&nbsp;&nbsp;" . getLngt("Anzeige der Spalten:") . "<br><br>&nbsp;&nbsp;";
    ?>
    <input type="hidden" id="f_col_sel_00" name="f_col_sel_00" value="<?php echo $f_col_sel_00 ?>">    
    <input type="button" id="f_col_button_sel_00" value="FA" onClick="toggleFilter('f_col_sel_00');">
    <input type="hidden" id="f_col_sel_19" name="f_col_sel_19" value="<?php echo $f_col_sel_19 ?>">    
    <input type="button" id="f_col_button_sel_19" value="SW-Offset" onClick="toggleFilter('f_col_sel_19');">
    <input type="hidden" id="f_col_sel_18" name="f_col_sel_18" value="<?php echo $f_col_sel_18 ?>">    
    <input type="button" id="f_col_button_sel_18" value="N" onClick="toggleFilter('f_col_sel_18');">
    <input type="hidden" id="f_col_sel_01" name="f_col_sel_01" value="<?php echo $f_col_sel_01 ?>">    
    <input type="button" id="f_col_button_sel_01" value="Standort" onClick="toggleFilter('f_col_sel_01');">
    <input type="hidden" id="f_col_sel_02" name="f_col_sel_02" value="<?php echo $f_col_sel_02 ?>">    
    <input type="button" id="f_col_button_sel_02" value="Opt." onClick="toggleFilter('f_col_sel_02');">
    <input type="hidden" id="f_col_sel_03" name="f_col_sel_03" value="<?php echo $f_col_sel_03 ?>">    
    <input type="button" id="f_col_button_sel_03" value="Tour" onClick="toggleFilter('f_col_sel_03');">
    <input type="hidden" id="f_col_sel_04" name="f_col_sel_04" value="<?php echo $f_col_sel_04 ?>">    
    <input type="button" id="f_col_button_sel_04" value="Sort." onClick="toggleFilter('f_col_sel_04');">
    <!--
    <input type="hidden" id="f_col_sel_05" name="f_col_sel_05" value="<?php echo $f_col_sel_05 ?>">    
    <input type="button" id="f_col_button_sel_05" value="XXX" onClick="toggleFilter('f_col_sel_05');">
    -->
    <input type="hidden" id="f_col_sel_06" name="f_col_sel_06" value="<?php echo $f_col_sel_06 ?>">    
    <input type="button" id="f_col_button_sel_06" value="PLZ" onClick="toggleFilter('f_col_sel_06');">
    <input type="hidden" id="f_col_sel_07" name="f_col_sel_07" value="<?php echo $f_col_sel_07 ?>">    
    <input type="button" id="f_col_button_sel_07" value="Geog. Breite" onClick="toggleFilter('f_col_sel_07');">
    <input type="hidden" id="f_col_sel_08" name="f_col_sel_08" value="<?php echo $f_col_sel_08 ?>">    
    <input type="button" id="f_col_button_sel_08" value="Geog. Länge" onClick="toggleFilter('f_col_sel_08');">
    <input type="hidden" id="f_col_sel_09" name="f_col_sel_09" value="<?php echo $f_col_sel_09 ?>">    
    <input type="button" id="f_col_button_sel_09" value="BEK" onClick="toggleFilter('f_col_sel_09');">
    <input type="hidden" id="f_col_sel_10" name="f_col_sel_10" value="<?php echo $f_col_sel_10 ?>">    
    <input type="button" id="f_col_button_sel_10" value="MEK" onClick="toggleFilter('f_col_sel_10');">
    <input type="hidden" id="f_col_sel_11" name="f_col_sel_11" value="<?php echo $f_col_sel_11 ?>">    
    <input type="button" id="f_col_button_sel_11" value="H1" onClick="toggleFilter('f_col_sel_11');">
    <input type="hidden" id="f_col_sel_12" name="f_col_sel_12" value="<?php echo $f_col_sel_12 ?>">
    <input type="button" id="f_col_button_sel_12" value="H2" onClick="toggleFilter('f_col_sel_12');">
    <input type="hidden" id="f_col_sel_13" name="f_col_sel_13" value="<?php echo $f_col_sel_13 ?>">
    <input type="button" id="f_col_button_sel_13" value="Dispenser" onClick="toggleFilter('f_col_sel_13');">
    <input type="hidden" id="f_col_sel_14" name="f_col_sel_14" value="<?php echo $f_col_sel_14 ?>">
    <input type="button" id="f_col_button_sel_14" value="Messzeitpunkt" onClick="toggleFilter('f_col_sel_14');">
    <input type="hidden" id="f_col_sel_15" name="f_col_sel_15" value="<?php echo $f_col_sel_15 ?>">
    <input type="button" id="f_col_button_sel_15" value="Meldungen" onClick="toggleFilter('f_col_sel_15');">
    <!--
    <input type="hidden" id="f_col_sel_16" name="f_col_sel_16" value="<?php echo $f_col_sel_16 ?>">    
    <input type="button" id="f_col_button_sel_16" value="SW" onClick="toggleFilter('f_col_sel_16');">
    <input type="hidden" id="f_col_sel_17" name="f_col_sel_17" value="<?php echo $f_col_sel_17 ?>">    
    <input type="button" id="f_col_button_sel_17" value="Status" onClick="toggleFilter('f_col_sel_17');">
    -->

  	<?php echo htmlDivLineSpacer("15px"); ?>
  	<div style="text-align:center; vertical-align:middle;"><input type="button" name="close_tablecolselection" value="<?php echo "Schließen" ?>" onClick="callTableColSelection();"></div>
  </div>
  

  <div id="actioncontainer" <?php echo $actioncontainerDivPos ?>>
  	<input type="hidden" name="actionObjType" value="">
  	<input type="hidden" name="actionObjId" value="">
  	
  	<?php echo defineButtonType08("Schließen", "action_actioncontainer_close", "myhide('actioncontainer');", "100", "", "") ?>
  	<?php echo htmlDivLineSpacer("30px"); ?>
  	
  	<div style="float:left;width:40px;height:100%">
  		&nbsp;
    </div>
    <div>
  	  <div id="ac_title"></div>
  	  <?php echo htmlDivLineSpacer("20px"); ?>
  	  <div id="ac_01"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="ac_02"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="ac_03"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="ac_04"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="ac_05"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="ac_06"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="ac_07"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="ac_08"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="ac_09"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	</div>
  </div>


  <div id="contentcontainer" <?php echo $contentcontainerDivPos ?>>
  	<input type="hidden" name="contentObjType" value="">
  	<input type="hidden" name="contentObjId" value="">
  	
  	<?php echo defineButtonType08("Schließen", "action_contentcontainer_close", "myhide('contentcontainer');", "100", "", "") ?>
  	<?php echo htmlDivLineSpacer("20px"); ?>
  	
  	<div style="float:left;width:40px;height:100%">
  		&nbsp;
    </div>
    <div>
  	  <div id="cc_title"></div>
  	  <?php echo htmlDivLineSpacer("20px"); ?>
  	  <div id="cc_01"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="cc_02"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="cc_03"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="cc_04"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="cc_05"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="cc_06"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="cc_07"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="cc_08"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="cc_09"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	</div>
  </div>  
  
  </form>

</div>

</body>

</html>



<?php
/*

****************
* HOCHBAHN AG: *
****************

Special usage of the fields
Semantic of the data fields in table "articleitem"
ati_data_01 : Added informations to the stations
ati_data_02 : Latitude of the station
ati_data_03 : Longitude of the station
ati_data_04 : Timestamp of the persistent measured data
ati_data_05 : BEK
ati_data_06 : MEK
ati_data_07 : Hopper 1
ati_data_08 : Hopper 2
ati_data_09 : Hopper 3
ati_data_10 : RSG (10)
ati_data_11 : RSG (11)
ati_data_12 : RSG (12)
ati_data_13 : RSG (13)
ati_data_14 : RSG (14)
ati_data_15 : RSG (15)
ati_data_16 : Priorities (presently not needed)
ati_data_17 : Persistent state of the message code(s)
ati_data_18 : Persistent state of probabilities regarding to the service intervals
ati_data_19 : Persistent state of optimized locations
ati_data_20 : Persistent state of selected checkboxes
ati_data_21 : Preselection for the number of the tour for each day of the week ("1" = Tour #1, "2" = Tour #2, ...)
ati_data_22 : 
ati_data_23 : 
ati_data_24 : 
ati_data_25 : 

INSERT INTO parameter (par_key, hq_id, emp_id, par_value, par_text) VALUES ('MASK_SU_TV_01', 1, 0, '900', NULL);
INSERT INTO parameter (par_key, hq_id, emp_id, par_value, par_text) VALUES ('MASK_SU_TV_02', 1, 0, '1800', NULL);
INSERT INTO parameter (par_key, hq_id, emp_id, par_value, par_text) VALUES ('MASK_SU_TV_03', 1, 0, '2250', NULL);
INSERT INTO parameter (par_key, hq_id, emp_id, par_value, par_text) VALUES ('MASK_SU_TV_04', 1, 0, '4500', NULL);
INSERT INTO parameter (par_key, hq_id, emp_id, par_value, par_text) VALUES ('MASK_SU_TV_05', 1, 0, '50', NULL);
INSERT INTO parameter (par_key, hq_id, emp_id, par_value, par_text) VALUES ('MASK_SU_TV_06', 1, 0, '25', NULL);
INSERT INTO parameter (par_key, hq_id, emp_id, par_value, par_text) VALUES ('MASK_SU_TV_07', 1, 0, '25', NULL);

*/
?>