<style>
    .select2-selection__choice span{
        display:inline-flex !important;
        align-items: center !important;
        align-self: center !important;
        justify-content: center !important;
    }
    .dropdown-menu .divider {
    height: 1px;
    margin: 4px 0 !important;
    overflow: hidden;
    background-color: #e5e5e5;
}
    .TicketEventContent p {
        margin-bottom: 0px !important;
    }
    .img-circular-event{background-image: url('index.php?module=upload&class=download&event=ShowImage&name=standard_avatar.jpg');}
    .img-circular {margin-right: 5px; background-position: center center; border-radius: 50%; width: 40px; height: 40px; background-image: url('index.php?module=upload&class=download&event=ShowImage&name=Medium_standard_avatar.jpg');}
    .img-circular-small{background-image: url('index.php?module=upload&class=download&event=ShowImage&name=Small_standard_avatar.jpg');}
    .img-circular-group-medium{background-image: url('index.php?module=upload&class=download&event=ShowImage&name=Medium_standard_avatar.jpg');}
    .img-circular-group{background-image: url('index.php?module=upload&class=download&event=ShowImage&name=Small_standard_avatar.jpg');}
    [% foreach from=$users item = $supporter %]
        [% if $supporter.avatar != 'standard_avatar.jpg' %]
            #img-circular-[% $supporter.user_id %]{background-image: url('index.php?module=upload&class=download&event=ShowImage&name=Medium_[%  $supporter.avatar %]');}
            #img-circular-small-[% $supporter.user_id %]{background-image: url('index.php?module=upload&class=download&event=ShowImage&name=Small_[%  $supporter.avatar %]');}
    [% /if %]
    [% /foreach %]
    [% foreach from=$all_groups item = $group %]
        [% if $group.avatar != 'standard_avatar.jpg' %]
            #img-circular-group-medium-[% $group.group_id %]{background-image: url('index.php?module=upload&class=download&event=ShowImage&name=Medium_[%  $group.avatar %]');}
            #img-circular-group-[% $group.group_id %]{background-image: url('index.php?module=upload&class=download&event=ShowImage&name=Small_[%  $group.avatar %]');}
        [% /if %]
    [% /foreach %]

    .TicketContent p{
        margin-bottom:0px !important;
    }

    #TicketDescrPanelBody p{
         margin-bottom:0px !important;
    }

    .sepScrollTicketPanel {
        height: 75vH !important;
        overflow-y: scroll !important;
    }

    .sepScrollGeneralPanelBody {
        min-height: 0 !important;
    }

    .sepScrollMainContent {
        height: 88vh !important;
    }

    .ButtonDesign{
        color: #3849A2;
        border-color: #3849A2;
    }
    /*
        #TicketData, #TicketRightPanel {
            height: 58em;
            overflow-y: scroll;
        }

        .panel-fcs-border > .card-body {
            min-height: 0;
        }
        .main_container{
            height: 88vh !important;
        }
    */

    [% if $SennebogenModul && $smarty.const.SHOWBUTTONSASIMAGES %]
        .ActionIconsOnTop img {
            width: 18px !important;
            height: auto !important;
        }
        .ActionIconsOnTop .splitButton {
            height: 36px !important;
        }

        .ActionIconsOnTop .btn:not(.dropdown-toggle) {
          padding-bottom: 8px !important;
        }
         
    [% /if %]
    [% if !$smarty.const.SHOWBUTTONSASIMAGES %]
        .btn.btn-outline-secondary.dropdown-toggle.splitButton, #DetailNewEvent {
            height: 40px !important;
        }

        #TicketRightPanel #TicketActions .splitButton {
            width: 10% !important;
        }
        #TicketRightPanel #TicketActions .editTicket {
            width: 90% !important;
        }
        [% else %]
            .btn.btn-outline-secondary.dropdown-toggle.splitButton, #DetailNewEvent {
            height: 50px !important;
        }
    [% /if %]
</style>

<script type="text/javascript" src="includes/js/fancybox/jquery.fancybox.pack.js"></script>
<script type="text/javascript" src="includes/js/script.js"></script>

<link href="includes/js/fancytree/skin-bootstrap/ui.fancytree.css" rel="stylesheet" class="skinswitcher">
<script src="includes/js/fancytree/jquery.fancytree-all-deps.min.js"></script>
<script src="includes/js/fancytree/fcs_glyphoptions.js" ></script>

<style>
    .bootboxzindex {
    z-index: 9999 !important;
}

    .fancybox-wrap{
    z-index: 9999 !important;
}

</style>

<script>
    var IsDraft = false;
    var SupporterIsRequired = 0;
    [% if ($type.type_name && $Tools->FCS_InArray('supporter', $require)) %]
    SupporterIsRequired = 1;
    [% /if %]

    var AutoSupporterPossible = 0;
     [% if $smarty.const.AUTOSUPPORTER == 1 && $user->isSupporter() %]
    AutoSupporterPossible = 1;
    [% /if %]

    var ticketSLAid = [% if $ticket.slaid > 0 %][% $ticket.slaid %][% else %]0[% /if %];
    var ts_AktionErforderlich = "[% $user->gettext('Aktion erforderlich') %]";
    var ts_Kategorien = "[% $user->gettext('Kategorien') %]";
    var ts_DokumentLoeschen = "[% $user->gettext("Das Dokument wirklich löschen?") %]";
    var ts_DokumentToBlacklist = "[% $user->gettext("Das Dokument wirklich der Blacklist zufügen?\\nDieses Dokument wird bei Ticketanlage oder Bearbeitung durch die Mail2Ticket-Funktion nicht mehr dem Ticket zugefügt.") %]";

    [% if $ticket.iswprequest %]
    var IsWPRequest = true;
    [% else %]
    var IsWPRequest = false;
    [% /if %]

    [% if $ServiceTicket %]
        var ts_VorfallToProblem = "[% $user->gettext('Soll das Ticket als Problem eingestuft werden?\nDie Gruppen werden dadurch ggf. geändert.') %]";
        var ts_ProblemToVorfall = "[% $user->gettext('Soll das Ticket als Vorfall eingestuft werden?\nDie Gruppen werden dadurch ggf. geändert.') %]";
    [% else %]
        var ts_VorfallToProblem = "[% $user->gettext('Wollen Sie den Vorfall wirklich als Problem einstufen?') %]";
        var ts_ProblemToVorfall = "[% $user->gettext('Wollen Sie das Problem wirklich als Vorfall einstufen?') %]";
    [% /if %]
        var ts_switchToMajorIncident = "[% $user->gettext('Soll das Ticket als Major Incident eingestuft werden?\nDie Gruppen werden dadurch ggf. geändert.') %]";
        var ts_switchFromMajorIncident = "[% $user->gettext('Soll das Ticket nicht mehr als Major Incident eingestuft werden?\nDie Gruppen werden dadurch ggf. geändert.') %]";
        var ts_MajorIncidentError = "[% $user->gettext('Beim Einstufen des Tickets trat ein unerwarteter Fehler auf!') %]";
        var ts_ProblemVorfallError = "[% $user->gettext('Beim Einstufen des Tickets trat ein unerwarteter Fehler auf!') %]";
        var ts_RefLevel2Select = "[% $user->gettext('Bitte ') %][% $ref_level2_name %] [% $user->gettext(' wählen...') %]";
            var ts_changeProjectAssign = "[% $user->gettext('Die Zuordnung wurde geändert.') %]";
            var ts_changeRepairEnddate = "[% $user->gettext('Reparatur-Enddatum ändern?') %]";
            var ts_changeDamageDate = "[% $user->gettext('Schadeneintritt ändern?') %]";
            var ts_DateError1 = "[% $user->gettext('Mindestens eine Ticketbearbeitung ist in der Zukunft datiert.') %]\n [% $user->gettext('Ein Schließen des Tickets ist nicht m&ouml;glich.') %]";
                var ts_Jetzt = '[% $user->gettext("Jetzt") %]';
                var ts_OK = '[% $user->gettext("OK") %]';
                var ts_Zeit = '[% $user->gettext("Zeit") %]';
                var ts_Stunde = '[% $user->gettext("Stunde") %]';
                var ts_SelectCategory = '[% $user->gettext("Kategorie w&auml;hlen") %]';
                var ts_All = '[% $user->gettext("Alle") %]';
                var ts_ArchivierungAufheben = "[% $user->gettext('Archivierung aufheben') %]";
                var ts_Archiviert = "([% $user->gettext('Archiviert') %])";
                var ts_TicketArchivieren = "[% $user->gettext('Ticket archivieren') %]";
                var ts_Keine = '[% $user->gettext("Keine") %]';
                var ts_CategoriesSelected = '[% $user->gettext("Kategorien gewählt") %]';
                var ts_SelectStatus = '[% $user->gettext("Status wählen") %]';
                var ts_WaehlenSie = '[% $user->gettext("Wählen Sie") %]';
                var ts_StatusSelected = '[% $user->gettext("Status gewählt") %]';
                var ts_Selected = "[% $user->gettext("gewählt") %]";
                var ts_UserAsSupporter = "[% $user->gettext('Ihren Benutzer als Supporter eintragen?') %]";
                var ts_TicketCouldNotTakenOver = "[% $user->gettext('Das Ticket konnte NICHT übernommen werden.') %]";
                var ts_TicketTakenOver = "[% $user->gettext('Das Ticket wurde übernommen.') %]";
                var ts_ShouldInformContact = "[% $user->gettext('Benachrichtigung an den Kontakt senden?') %]";
                var ts_InformedContact = "[% $user->gettext('Der Kontakt wurde benachrichtigt.') %]";
                var ts_CouldNotInformedContact = "[% $user->gettext('Der Kontakt wurde nicht benachrichtigt.') %]";
                var ts_PrioBestaetigen = "[% $user->gettext('Wollen Sie die Prio. wirklich bestaetigen?') %]";
                var ts_realyCloseTicket = '[% $user->gettext('Ticket wirklich schließen?') %]';
                var ts_realyCancelTicket = '[% $user->gettext('Ticket wirklich stornieren?') %]';
                var ts_realySetDone = '[% $user->gettext('Ticket wirklich als erledigt markieren?') %]';
                var ts_Cancel = '[% $user->gettext('Abbrechen') %]';
                var ts_ChangeDueDate = '[% $user->gettext("Fälligkeit ändern") %]';
                var ts_ChangeContact = '[% $user->gettext("Kontakt wechseln?") %]';
                var ts_ChangeCat1 = '[% $user->gettext("Kategorie 1 wechseln?") %]';
                var ts_ChangeGroup = '[% $user->gettext("Gruppe wechseln?") %]';
                var ts_ChangeMasterticket = '[% $user->gettext("Ticket einem (neuen) Masterticket zuordnen?") %]<br>[% $user->gettext('<b>Wichtig: </b> Der Tickettyp wird auf den Tickettyp des Mastertickets gewechselt.') %]';
                    var ts_ChangeStory = '[% $user->gettext("Ticket einer (neuen) Story zuordnen?") %]';
                    var ts_ChangeConnectionTicketA = "[% $user->gettext('Ohne Zurückstellung verknüpfen') %]?";
                    var ts_ChangeConnectionTicketB = "[% $user->gettext('Mit Zurückstellung verknüpfen') %]?";
                    var contact_message = "[% $user->gettext('Kontakt wurde geändert') %]";
                    var category1_message = "[% $user->gettext('Kategorie 1 wurde geändert') %]";
                    var category2_message = "[% $user->gettext('Kategorie 2 wurde geändert') %]";
                    var group_message = "[% $user->gettext('Gruppe wurde geändert') %]";
                    var supporter_message = "[% $user->gettext('Supporter wurde geändert') %]";
                    var ts_TicketPrioChanged = "[% $user->gettext('Die Ticketpriorität wurde geändert') %]";
                    var ts_LadeVorgaengerticket = "[% $user->gettext('Lade Vorgängerticket...') %]";
                    var ts_LadeNachfolgerticket = "[% $user->gettext('Lade Nachfolgerticket...') %]";
    [% if $DesireDateChangeApplying %]
                    var ts_changeDesiredate = "[% $user->gettext('Möchten Sie eine Änderung des Fälligkeitsdatums beantragen?') %]";
    [% else %]
                    var ts_changeDesiredate = "[% $user->gettext('Möchten Sie das Fälligkeitsdatum ändern?') %]";
    [% /if %]

                    var ts_changeOnhold = "[% $user->gettext('Soll das Ticket zurückgestellt werden?') %]";
                    var tid = "[% $ticket.id %]";
                    var bool_ActionRequired = [% if $ticket.ticketactionrequired && !($user->inGroup(1) || $CurrentUserIsInGroup || $CurrentUserIsSupporter) %] true [% else %] false [% /if %];
                    var bool_showAttachments = [% if $AttachmentCount > 0 || ($user->hasRight(10) && $ticket.ticketstatusid != 3 && $ticket.ticketstatusid != 7) %] true [% else %] false [% /if %];
                    var bool_NoCatChangeWhenForms = [% if $NoCatChangeWhenForms %] true [% else %] false [% /if %];
                    var bool_CatDepends = [% if $catdep %] true [% else %] false [% /if %];
                    var bool_isAVAG = [% if $hmcompany|strpos:"AVAG HOLDING" !== false %] true [% else %] false [% /if %];
                    var bool_AVAGPrioToAccept = [% if $ticket.ticketstatusid != 3 && $ticket.ticketstatusid != 7 && $hmcompany|strpos:"AVAG HOLDING" !== false && ($user->inGroup(1) || $user->inGroup(2)) %] true [% else %] false [% /if %];
                    var AvailableTagsJSArray = [% if $AvailableTagsJSArray %][% $AvailableTagsJSArray %][% else %]""[% /if %];
                    var int_CutTicketEvents = [% $CUTTICKETEVENTS|default:"0" %];
                    var UncUploadPath = "[% $UncUploadPath %]";
                    var bool_hasRight = new Array();
    [% foreach from=$user->Rights item=RightID %]
                    bool_hasRight[[% $RightID %]] = true;
    [% /foreach %]

                    //TicketDaten:
                    var TicketData = new Array();
                    TicketData['ticketstatusid'] = '[% $ticket.ticketstatusid %]';
                    TicketData['ticketdesiredate'] = '[% $ticket.desiredate|date_format:"%d.%m.%Y %H:%M" %]';
                    TicketData['repairenddate'] = '[% $ticket.repairenddate|date_format:"%d.%m.%Y %H:%M" %]';
                    TicketData['damagedate'] = '[% $ticket.damagedate|date_format:"%d.%m.%Y %H:%M" %]';
                    TicketData['ticketreferenzid'] = [% if $ticket.ticketreferenzid < 1 %] 0 [% else %][% $ticket.ticketreferenzid %][% /if %];
                    TicketData['CategoryFormularID2'] = [% if $categoryforms.formularid2 > 0 %]  [% $categoryforms.formularid2 %][% else %] 0 [% /if %];
                    //UserData
                    var UserData = new Array();
                    UserData['SecurityProjects'] = [% if $user->Security->Projects && $user->hasRight(500) %] true [% else %]false[% /if %];
                        //CategoryFormData
                        var CategoryFormData = {};
                        CategoryFormData['formularid1'] = [% if $categoryforms.formularid1 > 0 %][% $categoryforms.formularid1 %][% else %]0[% /if %];
                            CategoryFormData['required1'] = [% if $categoryforms.required1 > 0 %][% $categoryforms.required1 %][% else %]0[% /if %];
                                CategoryFormData['formularid2'] = [% if $categoryforms.formularid2 > 0 %][% $categoryforms.formularid2 %][% else %]0[% /if %];
                                    CategoryFormData['required2'] = [% if $categoryforms.required2 > 0 %][% $categoryforms.required2 %][% else %]0[% /if %];
                                        CategoryFormData['formularidtt'] = [% if $categoryforms.formularidtt > 0 %][% $categoryforms.formularidtt %][% else %]0[% /if %];
                                            CategoryFormData['requiredtt'] = [% if $categoryforms.requiredtt > 0 %][% $categoryforms.requiredtt %][% else %]0[% /if %];
                                                //console.log("CategoryFormData: " + JSON.stringify(CategoryFormData));

                                                var TicketID = '[% $ticket.id %]';
                                                var contactid = $("#contact_id").val();
                                                var DeviceRemoveError = "[% $user->gettext("Das Gerät kann nicht entfernt werden, da die Inventarnummer im Ticket eingetragen ist.") %]";
                                                var userwindow;
                                                var BOTSuggestedKBIDs = [% if $ticket.botsuggestedkbids %]'[% $ticket.botsuggestedkbids %]'[% else %]false[% /if %];
                                                    var BOTMatchedKBID = [% $ticket.botmatchedkbid|default:"false" %];
    [% if $jsonTicketData != '' %]
        var jsonTicketData = [% $jsonTicketData %];
    [% /if %]
</script>

<!-- Include the SCEditor theme -->
<link rel="stylesheet" href="includes/js/sceditor-2.1.2/minified/themes/default.min.css" type="text/css" media="all" />
<script type="text/javascript" src="includes/js/sceditor-2.1.2/minified/jquery.sceditor.bbcode.min.js"></script>
<script type="text/javascript" src="includes/js/sceditor-2.1.2/languages/[% $user->language_type %].js"></script>
<script src="includes/js/dropzone.js"></script>
<link href="includes/js/dropzone.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="modules/ticket/javascript/newdetails.js"></script>

<style>

    #tab-details-form .card-header a {
        font-style: normal;
        color: inherit;
    }

    .editableform .form-control {
        width: 49em !important;
    }

    .MarginForTicketID{
        margin-left: 15px;
    }

</style>

<!-- Component Ticket-Details begin -->
<!-- ###CONTENT### begin -->
[% if $hasCloseNoty %]
    <div id="snackbarDiv" style="display:none;">
        <div class="row">
            <div class="col-lg-6 text-end">
                [% $user->gettext('Ticket wurde geschlossen') %]!
            </div>
            <div class="col-lg-6 text-left">
                <a href="index.php?module=ticket&event=show&id=[% $ticket.id %]&close=2"><b>[% $user->gettext('RÜCKGÄNGIG MACHEN') %]</b></a>&nbsp &nbsp
            </div>
        </div>
    </div>
    <script>

                                                    //window.history.pushState({}, document.title, "/" + "index.php?module=ticketlist" );
                                                    noty({
                                                    text: $("#snackbarDiv").html(),
                                                            timeout: notifyTimeout,
                                                            //layout: 'top',
                                                            //theme: 'defaultTheme', // or 'relax'
                                                            closeWith: ['click'],
                                                            type: 'success'

                                                    });
    </script>
[% /if %]
[% if $ticket.draft > 0 %]
    <div class="row">
        <div class="col-sm-12">
            <div class="alert alert-danger" role="alert">
                <h2 class="card-title-fcs" style="display:inline-block">[% $smarty.const.TICKETDRAFT_NAME %]</h2>
                <a href="#" class="btn btn-outline-primary" style="margin-top: -14px;margin-left: 2em;" onclick="bootbox.confirm('[% $user->gettext('Entwurf als Ticket speichern?') %]', function(result){if (result){window.location.href = 'index.php?module=ticket&event=saveDraftAsTicket&tid=[% $ticket.id %]'}})">[% $smarty.const.TICKETDRAFT_NAME %] [% $user->gettext('als Ticket speichern') %]</a>

                <a href="#" class="btn btn-outline-primary" style="margin-top: -14px;margin-left: 2em;" onclick="bootbox.confirm('[% $user->gettext('Ticketentwurf löschen?') %]', function(result){if (result){window.location.href = 'index.php?module=ticket&event=deleteTicketDraft&tid=[% $ticket.id %]'}})">[% $smarty.const.TICKETDRAFT_NAME %] [% $user->gettext('löschen') %]</a>

            </div>
        </div>
    </div>

[% /if %]
<input type="hidden" name="MinRating" id="MinRating" value="[% $smarty.const.MINRATING %]" />
<form id="closeForm" action="index.php?module=ticketlist" method="post" style="display:none;">
    <input type="hidden" name="meldung" value ="1">
    <input type="hidden" name ="tid" id="tid" value="[% $ticket.id %]">
    <input type='hidden' id='DevID' value='[% $DeviceOfTicket %]'>
</form>

<form id="closeFormStay" action="index.php?module=ticket&event=show&id=[% $ticket.id %]" method="post" style="display:none;">
    <input type="hidden" name="closeMessage" value ="1">
    <input type="hidden" name ="tid" id="tid" value="[% $ticket.id %]">
    <input type='hidden' id='DevID' value='[% $DeviceOfTicket %]'>
</form>

<form  action="index.php?module=ticket&event=show&id=[% $ticket.id %]#ConnectetTicketsItem" method="post" id="hm" style="display:none;">
    <input type="hidden" id="sort" name="sort" value="[% $sort %]" />
    <input type="hidden" id="sortorder" name="sortorder" value="[% $sortorder %]" />
    <input type='hidden' name='TicketType' id="TicketType" value='[% $type.type_id %]' />
</form>
<form action="index.php?module=ticket&event=show&id=[% $ticket.id %]" method="POST" enctype="multipart/form-data" id="tab-details-form" class="form-horizontal form-label-left" name="hm-tab-details">
    <input type="hidden" value="0" id="popup" name="popup" />
    <div class="card panel-fcs-border shadow-sm">
        <div class="card-header">
            <div class="row">

                <div class="col-sm-7">
                    <h2 class="card-title-fcs">[% if $ticket.iswprequest %][% $user->gettext('GA Antrag') %] / Warranty claim[% else if $ticket.isstory %]
                        <img class="lazyImg" title="[% $user->gettext('Story Ticket')%]"  alt="" data-src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.STORY_ICON %]"  height="25"> [% $smarty.const.STORY_NAME %]
                        [% else %][% if !$type.type_id %]
                                <img class="lazyImg" title="[% $user->gettext('Standard Ticket')%]"  alt="" data-src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.STANDARD_ICON %]"  height="25"> [% $smarty.const.STANDARD_NAME %]
                            [% else %][% if $type.path %]
                                    <img class="lazyImg" title="[% $type.type_name%]"  alt="" data-src="index.php?module=upload&class=download&event=ShowImage&name=[% $type.path %]"  height="25">
                                [% else %]
                                    <img class="lazyImg" title="[% $type.type_name%]" alt="" data-src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.NO_ICON %]"  height="25">
                                [% /if %] [% $type.type_name %][% /if %][% /if %]:
                        [% if $ticket.ticketstatusid != 3 && $ticket.ticketstatusid != 7 && $user->hasRight(9) && ($ticket.ticketstatusid != 9 || $user->hasRight(112)) %]
                            <a href="#" class="editable-click" id="ticketdescr" title="[% $user->gettext('Ticketbeschreibung bearbeiten') %]" data-type="text" data-pk="[% $ticket.id %]" data-save="1" data-url="index.php?module=ticket&event=changeTicketDescr&tid=[% $ticket.id %]&save=1&keepOnHold=1" data-title="[% $user->gettext('Ticketbeschreibung bearbeiten') %]">[% $ticket.ticketdescr %]</a>
                        [% else %]
                            [% $ticket.ticketdescr %]
                        [% /if %]
                        <small id="HeadingTicketID">(#[% $ticket.id %])</small>

                    </h2>

                </div>

                <div class="col-sm-5 text-end ActionIconsOnTop">


                    [% if $SennebogenModul && $smarty.const.SHOWBUTTONSASIMAGES %]

                        <div style='visibility:hidden; max-height: 0;'>
                            [% include file=$modulePath|cat:"/panel_Aktionen.tpl" %]
                        </div>
                    [% /if %]

                    <span class="btn-group btn-withMargin" role="group" aria-label="">
                         [% if $SennebogenModul %]
                                        <div class="btn-group">
                                            <button type="button" class="btn btn-outline-secondary dropdown-toggle btnasicon ButtonDesign" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="[% if !$type.type_id %][% $user->gettext('Ticket') %][% else %][% $type.type_name %][% /if %]... ">
                                                <span class='fa fa-bars'></span><span class="caret"></span>
                                            </button>

                                            <ul class="dropdown-menu" aria-labelledby="TicketActionButtons">
                                                [% if $ticket.ticketstatusid != 3 && $ticket.ticketstatusid != 7 %]
                                                    [% if $ticket.ticketreferenzid < 1 && $user->hasRight(110) &&  $ticket.ticketstatusid != 9 && $STATUSDONEACTIVE %]

                                                        [% if $cat1Required %]
                                                            <li><a href="#" class="dropdown-item" onclick="openCategoryRequired(1);">[% $user->gettext('... erledigt') %]</a></li>
                                                            [% else %]
                                                            <li><a href="#" class="dropdown-item" onclick="showBotRatingPopUp();
                                                                checkForm_Close('TicketDone', true);">[% $user->gettext('... erledigt') %]</a></li>
                                                            [% /if %]

                                                    [% /if %]

                                                    [% if $ticket.ticketreferenzid < 1 && ($user->hasRight(26) || $owner)  %]

                                                        [% if !$user->hasRight(116) && ( $user->hasRight(26) ||  $owner ) && ( !$user->hasRight(111) || $ticket.ticketstatusid == 9 || !$STATUSDONEACTIVE) %]


                                                            [% if $cat1Required %]
                                                                <li><a href="#" class="dropdown-item" onclick="openCategoryRequired(1);">[% $user->gettext('... schlie&szlig;en') %]</a></li>
                                                            [% else %]
                                                                <li><a href="#" class="dropdown-item" onclick="showBotRatingPopUp();
                                                                    checkForm_Close2('TicketClose', true);">[% $user->gettext('... schlie&szlig;en') %]</a></li>
                                                            [% /if %]
                                                                <li><a href="#" class="dropdown-item" onclick="checkForm_Close2('TicketStorno', true);">[% $user->gettext('... stornieren') %]</a></li>
                                                        [% /if %]
                                                    [% /if %]

                                                [% else %]

                                                    [% if $user->hasRight(100) %]
                                                        <li><a href="#" class="dropdown-item" onclick="bootbox.confirm('[% $user->gettext('Ticket wirklich entfernen?') %]', function (result) {
                                                            if (result) {
                                                            window.location.href = 'index.php?module=ticket&event=removeTicket&tid=[% $ticket.id %]';
                                                            }
                                                            })">[% $user->gettext('... l&ouml;schen') %]</a></li>

                                                    [% /if %]
                                                    [% if $ticket.ticketreferenzid < 1 && ($user->hasRight(26) || $owner ) && $user->hasRight(27) %]
                                                        <li><a href="#" class="dropdown-item" onclick="var check = true;
                                                            if (check) {
                                                            document.getElementById('TicketClose').value = 2;
                                                            $('#tab-details-form').submit();
                                                            }">[% $user->gettext('... wieder &ouml;ffnen') %]</a></li>
                                                        [% /if %]
                                                    [% /if %]
                                                <li role="separator" class="divider"></li>

                                                [% if $user->hasRight(210) && $user->hasRight(1) %]
                                                    <li><a href="#" class="dropdown-item" onclick="javascript:window.location.href = 'index.php?module=ticket&event=copyTicket&id=[% $ticket.id %]';">[% $user->gettext('... kopieren') %]</a></li>
                                                    [% /if %]

                                                [% if $user->hasRight(401) %]
                                                    <li><a href="#" class="dropdown-item" onclick="javascript:window.location.href = 'index.php?module=ticket&event=createTemplateFromTicket&id=[% $ticket.id %]';">[% $user->gettext('... als Vorlage speichern') %]</a></li>
                                                    [% /if %]

                                                <li role="separator" class="divider"></li>


                                                [% if $user->hasRight(221) %]
                                                    <li><a href="#" class="dropdown-item" id="ArchivButton">[% if $ticket.archived %][% $user->gettext('... dearchivieren') %][% elseif !$type.type_id %][% $user->gettext('... archivieren') %][% else %][% $user->gettext('... archivieren') %][% /if %] [% $user->gettext('') %]</a></li>
                                                    [% /if %]
                                                <li><a href="#" class="dropdown-item" onclick="$('#PrintLink').click();">[% $user->gettext('... drucken') %]</a></li>
                                                <li role="separator" class="divider"></li>
                                                    [% if $user->hasRight(114)%]
                                                    <li> <a href="index.php?popup=1&module=ticket&event=manualMailTicket&id=[% $ticket.id %]" class="dropdown-item" data-fancybox-type="iframe" id="MailenIcon" class="dialog_TicketPrintview">... [% $user->gettext('mailen') %]</a></li>
                                                    [% /if %]
                                                    [% if $user->Security->Backlog %]
                                                        [% if !$ticket.isstory && !$ticket.storyid  %]
                                                        <li role="separator" class="divider"></li>
                                                        <li> <a href="javaScript: changeToStory([% $ticket.id %], 1);" class="dropdown-item" id="">... [% $user->gettext('zu Story machen') %]</a></li>
                                                        [% else if $ticket.isstory && !$hasStorytickets %]
                                                        <li role="separator" class="divider"></li>
                                                        <li> <a href="javaScript: changeToStory([% $ticket.id %], 0);" class="dropdown-item" id="">... [% $user->gettext('zu Standardticket umwandeln') %]</a></li>
                                                        [% /if %]
                                                    [% /if %]
                                                [%*
                                                <li role="separator" class="divider"></li>

                                                <li><a href="#" class="dropdown-item" onclick="ToggleBasket()" id="ButtonTicketBasket">[% if $ticket.ticketbasket %][% $user->gettext('... aus Merkliste entfernen') %][% else %][% $user->gettext('... zur Merkliste zuf&uuml;gen') %][% /if %]</a></li>
                                                *%]

                                                [% if !$ticket.ticketreferenzid && $user->hasRight(23) %]
                                                    <li role="separator" class="divider"></li>
                                                    <li><a href="index.php?module=ticket&class=csvimport&tid=[% $ticket.id %]" class="dropdown-item" >[% $user->gettext('... Childtickets importieren') %]</a></li>
                                                    [% /if %]
                                            </ul>
                                            [% if $SennebogenModul && $user->hasRight(26) %]
                                            <a class="btn btn-outline-secondary ButtonDesign openInBigIFrameModal" href="index.php?module=ticket&event=AddProfessionalSupporterToTicket&TicketID=[% $ticket.id %]" title='[% $user->gettext('Fachsupporteranfrage') %]'><span class="fa fa-headphones"></span></a>
                                            [% /if %]

                                            [% if $user->hasRight(113) && $suggestedsolution %]
                                                <a class="btn btn-outline-secondary ButtonDesign editTicket" href="index.php?module=ticket&event=event&tid=[% $ticket.id %][% if $TicketlistUID != '' %]&amp;tlu=[% $TicketlistUID %][% /if %]&processingtype=[% $suggestedsolution %]" onclick="return checkForm_Edit();" title='[% $user->gettext('Lösungsvorschlag hinzufügen') %]'><span class="fa-regular fa-circle-check ButtonDesign"></span></a>
                                            [% /if %]
                                            [% if $user->hasRight(113) && $consultation %]
                                                <a class="btn btn-outline-secondary ButtonDesign editTicket" href="index.php?module=ticket&event=event&tid=[% $ticket.id %][% if $TicketlistUID != '' %]&amp;tlu=[% $TicketlistUID %][% /if %]&processingtype=[% $consultation %]" onclick="return checkForm_Edit();" title='[% $user->gettext('Rückfrage hinzufügen') %]'><span class="fa-regular fa-circle-question ButtonDesign"></span></a>
                                            [% /if %]
                                            [% if $ticket.ticketstatusid != 3 && $ticket.ticketstatusid != 7 && $user->hasRight(57) %]
                                                <a class="btn btn-outline-secondary editTicket ButtonDesign" href="index.php?module=ticket&event=event&tid=[% $ticket.id %][% if $TicketlistUID != '' %]&amp;tlu=[% $TicketlistUID %][% /if %]&internalnotice=1" onclick="return checkForm_Edit();" title='[% $user->gettext('Interne Notiz hinzufügen') %]'><span class="fa fa-tag ButtonDesign"></span></a>

                                            [% /if %]
                                            <a class="btn btn-outline-secondary ButtonDesign" onclick="$('#AddToInterestIcon').click();" title='[% $user->gettext('Benutzer in den interessierten Kreis hinzufügen') %]'><span class="fa fa-user ButtonDesign"></span></a>
                                            <a class="btn btn-outline-secondary ButtonDesign" onclick="$('#MailenIcon').click();" title='[% $user->gettext('Ticket mailen') %]'><span class="fa fa-envelope ButtonDesign"></span></a>

                                        </div>
                                    [% if $user->inGroup(1) || ($user->hasRight(1007) || !$singleGroup ) %]
                                        <div class="btn-group">
                                            [% if $user->inGroup(1) %]
                                                <a class="btn btn-outline-secondary ButtonDesign" role="button" data-bs-toggle="collapse" href="#collapseGroupSelection" aria-expanded="false" aria-controls="collapseExample" title="[% $user->gettext('Auswahl für Gruppen speichern') %]">
                                                [% if $smarty.const.SHOWBUTTONSASIMAGES %]<img src="images/TicketButtons/SaveLayout.png"  width="32" height="32" alt="" border="0" />[% else %][% $user->gettext('Auswahl für Gruppen speichern') %][% /if %]
                                            </a>
                                        [% /if %]
                                        [% if $user->hasRight(1007) || !$singleGroup %]
                                            <a class="btn btn-outline-secondary ButtonDesign" role="button" data-bs-toggle="collapse" href="#collapseGroupSelection2" aria-expanded="false" aria-controls="collapseExample" title="[% $user->gettext('Ansicht laden') %]">
                                            [% if $smarty.const.SHOWBUTTONSASIMAGES %]<img src="images/TicketButtons/LoadLayout.png"  width="32" height="32" alt="" border="0" />[% else %][% $user->gettext('Ansicht laden') %][% /if %]
                                            </a>
                                        [% /if %]
                                        </div>
                                   [% /if %]
                                    [% if $ticket.ticketstatusid != 3 && $ticket.ticketstatusid != 7 && $user->hasRight(863) %]
                                        <div class="btn-group">
                                            <a aria-expanded="false" aria-haspopup="true" role="button" data-bs-toggle="dropdown" class="btn btn-outline-secondary dropdown-toggle ButtonDesign" style="padding: 0.5em" href="#" title="[% $user->gettext('Tickettyp wählen') %]">
                                                <span id="selected">[% if $smarty.const.SHOWBUTTONSASIMAGES %]<img src="images/TicketButtons/ChangeTickettype.png"  width="32" height="32" alt="" border="0" />[% else %][% $user->gettext('Tickettyp wählen') %] ([%  if !$type.type_id %][% $smarty.const.STANDARD_NAME %][% else %][% $type.type_name %][% /if %] [% $user->gettext('gewählt') %])[% /if %]</span> <span class="caret"></span>
                                            </a>
                                            <ul class="dropdown-menu">
                                                [% if $smarty.const.STANDARDTICKET == 1%]
                                                    <li><a  [% if $type.type_id %]onclick="changeTickettype([% $ticket.id %], [%  if !$type.type_id %]0[% else %][% $type.type_id %][% /if %], 0);"[% /if %] href="#" class="dropdown-icon">[% $smarty.const.STANDARD_NAME %][%  if !$type.type_id %] <span class="fa fa-check"></span>[% /if %]</a></li>
                                                [% /if %]
                                                [% foreach from=$ticket_types item=$ticket_type %]
                                                    <li><a [% if $type.type_id != $ticket_type.type_id %]onclick="changeTickettype([% $ticket.id %], [%  if !$type.type_id %]0[% else %][% $type.type_id %][% /if %], [%  $ticket_type.type_id %]);"[% /if %] href="#"  class="dropdown-icon">[% $ticket_type.type_name %] [% if $type.type_id == $ticket_type.type_id %] <span class="fa fa-check"></span>[% /if %]</a></li>
                                                [% /foreach %]
                                            </ul>
                                        </div>
                                    [% /if %]


                                    [% /if %]

                        [% if !$iframe %]
                        [% if $hmcompany != 'AWB ABFALLWIRTSCHAFTSBETRIEB DES LANDKREISES FFB' %]
                            <button type="button"  class="btn btn-outline-success" title='[% $user->gettext('Vorheriges Ticket') %]' onclick="browseTicket('p');"><span class="fa fa-chevron-left"></span>[% if !$SennebogenModul && !$smarty.const.SHOWBUTTONSASIMAGES %][% $user->gettext('Vorheriges Ticket') %][% /if %]</button>
                            <button type="button" class="btn btn-outline-success" title='[% $user->gettext('N&auml;chstes Ticket') %]' onclick="browseTicket('n');">[% if !$SennebogenModul && !$smarty.const.SHOWBUTTONSASIMAGES %][% $user->gettext('N&auml;chstes Ticket') %][% /if %] <span class="fa fa-chevron-right"></span></button>
                        [% /if %]
                            <button type="button" class="btn btn-outline-primary lightContrast" title='[% $user->gettext('Zurück zur Ticketliste') %]' onclick="window.location.href = '?module=ticketlist[% if $smarty.session.ticketlist.listtype == 1 %]&event=todo[% /if %][% if $smarty.session.ticketlist.listtype == 2 %]&event=queue[% /if %][% if $TicketlistUID != '' %]&TicketlistUID=[% $TicketlistUID %][% /if %]';"><span>[% if !$SennebogenModul && !$smarty.const.SHOWBUTTONSASIMAGES %][% $user->gettext('Liste') %][% else %]<span class="fa fa-list"></span>[% /if %]</span></button>
                                [% else %]
                                    [% if !$WithoutList %]
                                <button type="button" href="index.php?module=ticketlist&event=ContactTickets&id=[% $ticket.contactid %]" class="btn btn-outline-primary" ><span>Liste</span></button>
                            [% /if %]
                        [% /if %]
                    </span>
                </div>
                     [% if $SennebogenModul && $smarty.const.SHOWBUTTONSASIMAGES && ($user->inGroup(1) || ($user->hasRight(1007) || !$singleGroup )) %]
                    <div class="col-sm-12">

<div class="collapse" id="collapseGroupSelection2" style="margin-top:5px;">
    <div class="card panel-info shadow-sm rounded">

        <div class="card-body">
            <div class="form-group row mb-3">
                <label class="col-sm-4 col-lg-2 control-label">
                    [%$user->gettext('Ansehen als') %]
                </label>
                <div class="col-sm-8 col-lg-10">
                    <select class="form-control" id="viewAsGroup">

                        [% foreach from=$myGroups item=group %]
                            <option value="[% $group.id %]" [% if $group.id == $view %] selected [% /if %]>[% $group.name %]</option>
                        [% /foreach %]

                        [% if $user->hasRight(1007) %]
                            <optgroup label="[%$user->gettext('Ohne Gruppe') %]">
                                <option value="0" [% if 0 == $view %] selected [% /if %] >[% $user->gettext('Default Ansicht') %]</option>
                                <option value="-1" [% if -1 == $view %] selected [% /if %]>[% $user->gettext('Eigene Ansicht') %]</option>
                            </optgroup>
                        [% /if %]
                    </select>
                    <span class="help-block">
                        [% $user->gettext('Nur wenn Sie die Eigene Ansicht geladen haben werden die Änderungen im Layout gespeichert.') %]
                        [% if $user->inGroup(1) %]
                            <br/>
                            [% $user->gettext('Wenn Sie die Ansicht für Gruppen ändern möchten, müssen Sie dafür zuerst die Eigene Ansicht laden, diese dann ändern und für Gruppen speichern.') %]
                        [% /if %]
                    </span>
                    <span class="btn btn-outline-secondary btn-block" id="resetOwnPositions" >[% $user->gettext('Eigene Ansicht zurücksetzen') %]</span>
                </div>
            </div>
        </div>
    </div>
</div>
[% if $user->inGroup(1) %]
    <div class="collapse" id="collapseGroupSelection"  style="margin-top:5px;">
        <div class="card panel-info shadow-sm rounded">

            <div class="card-body">
                <div class="form-group row mb-3">
                    <label class="col-lg-12 control-label">[% $user->gettext('Diese Anordnung für die gewählten Gruppen speichern') %]</label>
                    <div class="col-lg-12">
                        <select name="TicketDetailsViewGroupIDsSelection[]" id="TicketDetailsViewGroupSelection" class="form-control"   multiple="multiple" >
                            [% foreach from=$allGroups item=group %]
                                <option value="[% $group.id %]" >[% $group.name %]</option>
                            [% /foreach %]
                        </select>

                    </div>
                </div>

                <button class="btn btn-outline-primary" id="saveTicketDetailsViewGroupSelection">Speichern</button>

            </div>
        </div>
    </div>
[% /if %]
</div>
[% /if %]
            </div>
        </div>
        <div class="card-body">
            [% include file=$modulePath|cat:"/details.tab-details.tpl" %]
        </div>
    </div>


    <!-- ###DIALOGS### begin -->


    <div id="dialog-add-document" style="display:none;">
        <form action="index.php?module=upload&tid=[% $ticket.id %]" method="POST" enctype="multipart/form-data" id="UploadFile">

            <div id="TicketHeader">
                <h2><strong>[% $user->gettext('Neues Dokument') %]</strong></h2>

                <input type="submit" value="[% $user->gettext('Speichern') %]" id="aUploadDokument" class="button button-black" onclick="$.fancybox.close();" />

            </div>

            [% if $error != '' %]
                <p class="errorNotice">[% $error %]</p>
            [% /if %]

            <fieldset id="TicketFieldsDokument">
                <div class="TicketField">
                    <label for="ShortDescr">[% $user->gettext('Titel') %]</label>
                    <div class="TextFieldInput">
                        <input type="text" maxlength="80" class="textbox"  name="ShortDescr" id="aShortDescr" value="[% $ShortDescr %]" />
                    </div>
                </div>

                <div class="TicketField">
                    <label for="URL">[% $user->gettext('URL') %]</label>
                    <div class="TextFieldInput">
                        <input type="text" maxlength="80" class="textbox" name="URL" id="aURL" value="[% $URL %]"/>
                    </div>
                </div>

                <div class="TicketField">
                    <label for="LongDescr">[% $user->gettext('Beschreibung') %]</label>
                    <div class="TextFieldInput">
                        <textarea class="textbox" cols="70" rows="15" id="aLongDescr" name="LongDescr">[% $LongDescr %]</textarea>
                    </div>
                </div>

                <div class="TicketField">
                    <label for="UploadFile">[% $user->gettext('Datei') %]</label>
                    <div class="TextFieldInput">
                        <input type="file" class="textbox" name="UploadFile" id="aUploadFile" value="" />
                    </div>
                </div>

            </fieldset>

        </form>
    </div> <!--dialog-add-document-->

    <div id="dialog-category" style="display:none;" width="500" hight="500">

    </div> <!--dialog-category-->

    <div id="dialog-editExpExpense" style="display:none;">
        <form action="index.php?module=ticket&event=changeExpExpense" target="_self" method="POST" enctype="multipart/form-data" id="editExpExpense">
            <input type="hidden" name="tid" value="[% $ticket.id %]" />
            <input type="hidden" name="save" value="1" />

            <div class="card panel-info shadow-sm rounded">
                <div class="card-header">
                    <div class="row">
                        <div class="col-sm-6">
                            <h6 class="card-title">
                                [% $user->gettext('Erwarteten Aufwand ändern') %]
                            </h6>
                        </div>
                        <div class="col-sm-6 text-end">
                            <input type="submit" value="Speichern" class="btn btn-outline-primary" />
                        </div>
                    </div>
                </div>

                <div class="card-body">
                    <div id="errorbox2" style="color:#FFF;font-weight:bold;"></div>
                    <div class="form-group row mb-3">
                        <label class="control-label col-sm-4" for="ExpExpense">[% $user->gettext('Erwarteter Aufwand') %]</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <input type="number" min="0" class="form-control"  name="ExpExpense" id="ExpExpense" value="[% $ticket.expexpense %]" />
                                <span class="input-group-text">[% $user->gettext('Minuten') %]</span>
                            </div>
                        </div>
                    </div>

                    [% if $ticket.diffonhold > 0 %]
                        <div class="form-group row mb-3">
                            <label class="control-label col-sm-4" for="keepOnHold">[% $user->gettext('Zurückstellung erhalten') %]</label>
                            <div class="col-sm-8">
                                <input type="checkbox" name="keepOnHold" value="1" />
                            </div>
                        </div>
                    [% /if %]

                </div>
            </div>

        </form>
    </div> <!--dialog-editExpExpense-->

    <div id="dialog-EditWorkingHours" style="display:none;">
        <form action="index.php?module=errorpatterns&event=ChangeWorkingHours" target="_self" method="POST" enctype="multipart/form-data" id="EditWorkingHoursForm">
            <input type="hidden" name="tid" value="[% $ticket.id %]" />
            <input type="hidden" name="save" value="1" />

            <div class="card panel-info shadow-sm rounded">
                <div class="card-header">
                    <div class="row">
                        <div class="col-sm-6">
                            <h6 class="card-title">
                                [% $user->gettext('Betriebsstunden ändern') %]

                            </h6>
                        </div>
                        <div class="col-sm-6 text-end">
                            <input type="button" value="Speichern" id="SaveWorkingHours" class="btn btn-outline-primary" />
                        </div>
                    </div>
                </div>

                <div class="card-body">
                    <div id="errorbox2" style="color:#FFF;font-weight:bold;"></div>
                    <div class="form-group row mb-3">
                        <label class="control-label col-sm-4" for="WorkingHours">[% $user->gettext('Betriebsstunden') %]</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <input type="number" min="0" class="form-control"  name="WorkingHours" id="editWorkingHours" value="[% $WorkingHours %]" />
                                <span class="input-group-text">[% $user->gettext('Stunden') %]</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>

    <div id="dialog-LoadTicket" title="[% $user->gettext('Lade Ticket') %]..." style="display:none;">

    </div>

    [% if $ticket.ticketactionrequired && !($user->inGroup(1) || $CurrentUserIsInGroup || $CurrentUserIsSupporter) %]
        <div class="modal" id="RequiredActionModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="false">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="card panel-info shadow-sm rounded">
                        <div class="card-header">
                            <div class="row">
                                <div class="col-sm-4">
                                    <span class="fcs-card-title h3">
                                        [% $user->gettext('Aktion angefordert') %]
                                    </span>
                                </div>
                                <div class="col-sm-8 text-end">
                                    <div class="btn-group">
                                        <button class="btn btn-outline-primary" onclick="window.location.href = 'index.php?module=ticket&event=RequiredActionSolved&id=[% $ticket.id %]';"><span class="fa fa-check"></span> [% $user->gettext("Aktion durchgeführt")%]</button>
                                        <button class="btn btn-outline-danger" onclick="window.location.href = 'index.php?module=ticketlist[% if $TicketlistUID != '' %]&TicketlistUID=[% $TicketlistUID %][% /if %]';"><span class="fa fa-times"></span> [% $user->gettext("Zurück zur Ticketliste")%]</button>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="card-body">
                            <h6 class="modal-title" id="myModalLabel">[% $user->gettext('Zur weiteren Bearbeitung des Tickets ist es notwendig, folgende Aktion durchzuführen:') %]</h6>
                            <br />
                            [% $ticket.requiredticketactiondesc  %]
                        </div>
                    </div>
                </div>
            </div>
        </div>

    [% /if %]


    <div id="TicketDetailModal" class="modal fade">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-body">
                    <p>Loading...</p>
                </div>
            </div>
        </div>
    </div>

    [% include file=$modulePath|cat:"/WPModals.tpl" %]

    [% if $iframe %]
    </body>
[% /if %]
<script>

    $('.lazyImg').Lazy({
    // your configuration goes here
    scrollDirection: 'vertical',
            effect: 'fadeIn',
            visibleOnly: true,
            onError: function(element) {
            console.log('error loading ' + element.data('src'));
            }
    });
    /* js-Funktionen sind @innerder Datei newdetails.js zu finden */
    setTicketID([% $ticket.id %]);
    [% if $cat1Required %]
    noty({
    text: "[% $user->gettext("Kategorie 1 muss gewählt sein!<br/>Bitte wählen Sie die Kategorie aus.") %]",
            //layout: 'top',
            //theme: 'defaultTheme', // or 'relax'
            //closeWith: ['click', 'hover'],
            type: 'error',
            timeout: notifyTimeout
    });
    [% /if %]







    [% if ($ticket.ticketstatusid != 3 && $ticket.ticketstatusid != 7 && $user->hasRight(5) && ($ticket.ticketstatusid != 9 || $user->hasRight(112))) && !($NoCatChangeWhenForms && $categoryforms.formularid2 > 0)%]
    function nqi_searchCat2 (task, text_name, id_name)
    {
    var previus_name = $("#" + text_name).val();
    var previus_id = $("#" + id_name).val();
    $("#" + text_name).autocomplete(task, {
    minChars:2,
            matchSubset:1,
            matchContains:1,
            cacheLength:1,
            onItemSelect:selectItem,
            formatItem:formatItem,
            //    		autoFill:1,       //Verfolständigt eingabe beim Tippen
            max:0,
            extraParams: {
        [% if $catdep %]
            //var id = getCat1ID();
            id: function(){return $('#CategoryID1').val(); },
                    cid: "2"
        [% else %]
            id: "0"
        [% /if %]

        [% if $hmcompany|strpos:"AVAG HOLDING" !== false %]
            , view: "eds",
                    tid: TicketID
        [% /if %]
            }
    });
    $("#" + text_name).result(function(event, data, formatted) {
    if (data && data[1] != previus_id){

    bootbox.confirm("Kategorie 2 wechseln?", function(result){
    if (result){
    $.getJSON("index.php?module=category&class=select&save=1&confirmOnHold=hold&ajax=1", { tid: TicketID, cid: data[1], id: 2 }, function(json) {
    if (json != ''){
    $("#TicketDesireDate").val(json.expires);
    //noty:
    noty({
    text: json.ResponseMsg,
            //layout: 'top',
            //theme: 'defaultTheme', // or 'relax'
            //closeWith: ['click', 'hover'],
            type: 'success',
            timeout: notifyTimeout
    });
    $("#" + id_name).val(data[1]);
    //Wenn Kontakt gewechselt wird, die neuen Daten merken:
    previus_name = $("#" + text_name).val();
    previus_id = $("#" + id_name).val();
    }
    });
    } else {
    //Wenn auf confirm = Nein ist, alte Daten einfüllen:
    $("#" + text_name).val(previus_name);
    $("#" + id_name).val(previus_id);
    }
    });
    }
    });
    }
    [% /if %]


    $(document).ready(function () {

    $('.hm-avatar-small').popover();
    });
    var $groupSelect = $("#GroupSelect").select2({theme: 'bootstrap-5',
    [% if $ServiceTicket %]disabled:true,[% /if %]
    [% if $hmcompany != 'BHS BAD HOMBURGER SERVICEGESELLSCHAFT'  %]
        closeOnSelect: false,
    [% /if %]
    [% if $smarty.const.SHOWAVATAR %]
        templateResult: formatSelectGroup,
                templateSelection: formatStateGroup,
    [% /if %]
        language: ts_lang
        }).on("select2:select", function (e) {
        var $el = $('#GroupSelect');
        var $search = $el.data('select2').dropdown.$search || $el.data('select2').selection.$search;
        $search.val('');
        $search.trigger('input');
        $search.focus();
        }).on("select2:unselecting", function (e) {
        [% if $smarty.const.GROUPSUPPORTERREQUIRED %]
        var groups = $("#GroupSelect").val();
        if (!$("#SupporterSelect").val() && groups.length === 1){
        alert("[% $user->gettext('Ticket muss mindestens eine Gruppe oder einen Supporter haben.') %]");
        return false;
        }
        [% /if %]
        }).on("change", function (e) {
        $("#SupporterSelect").prop('disabled', true);
        showSupporter(this);
        $('.lazyImg').Lazy({
        scrollDirection: 'vertical',
                effect: 'fadeIn',
                visibleOnly: true,
                onError: function(element) {console.log('error loading ' + element.data('src')); }
        });
        loadCSSBG();

        [% if !$ServiceTicket %]
        if (!$("#SupporterSelect").is(":visible")){ // Nur, wenn Supporterselect nicht sichtbar
        console.log("trigger saveGroupSupporters() in details.tpl in $groupSelect on change");
        setTimeout('saveGroupSupporters()', 500);
                                                    }
    [% /if %]
                                                    })[% if $ServiceTicket %].attr('disabled', true)[% /if %]; //end onChange

var $supporterSelect = $("#SupporterSelect").select2({
    theme: 'bootstrap-5',
                templateResult: formatSelect,
                templateSelection: formatState,
        [% if $hmcompany != 'BHS BAD HOMBURGER SERVICEGESELLSCHAFT'  %]
        closeOnSelect: false,
        [% /if %]
        language: ts_lang
}).on("select2:select", function (e) {
                var $el = $('#SupporterSelect');
        var $search = $el.data('select2').dropdown.$search || $el.data('select2').selection.$search;
        $search.val('');
        $search.trigger('input');
        $search.focus();
}).on("select2:unselecting", function (e) {
                var supporters = $("#SupporterSelect").val();
        [% if $smarty.const.GROUPSUPPORTERREQUIRED %]
        if (!$("#GroupSelect").val() && supporters.length === 1){
        alert("[% $user->gettext('Ticket muss mindestens eine Gruppe oder einen Supporter haben.') %]");
        return false;
        }
        [% /if %]
    }).on("change", function (e) {
                setTimeout(function(){
                $('.lazyImg').Lazy({
                scrollDirection: 'vertical',
                        effect: 'fadeIn',
                        visibleOnly: true,
                        onError: function(element) {console.log('error loading ' + element.data('src')); }
            });
                loadCSSBG();
                }, 500);
                
                console.log("trigger saveGroupSupporters() in details.tpl in $supporterSelect on change");
    saveGroupSupporters();
                                                    })
                                                    
                                                    [% if !($ticket.ticketstatusid != 3 && $ticket.ticketstatusid != 7 && $user->hasRight(216) && ($ticket.ticketstatusid != 9 || $user->hasRight(112))) %]
                                                    $("#GroupSelect").prop("disabled", true);
                                                    $("#SupporterSelect").prop("disabled", true);
                                                            [% /if %]
                                                            
                                                            
                                                            
                                                            
                                                            
                                                    

function formatService (contact) {
                                if (!contact.id) { return contact.text; }
            var string = '<div class="ContactSelectListItem"><span class="ContactTitle"> ' + service.servicetitle + '</span><span class="ServiceLvlTitle">' + service.servicelvltitle + '</span>';
                if (service.servicedescr != ''){
                                string = string.concat('<span class="ServiceDescr">[% $user->gettext('Beschreibung') %]: ' + service.servicedescr + '</span>');
                }
                if (service.risks != ''){
                                string = string.concat('<span class="ServiceRisks">[% $user->gettext('Risiken') %]: ' + service.risks + '</span>');
                }
                string = string.concat('</div>');
                var $service = $(
                string
                );
                return $service;
                };
                [% if $ticket.master %]
                $(function() {
                                $("#MasterticketPanel").on('show.bs.collapse', function(e) {
                        if ($(this).is(e.target)) {
                        $("#RefTicketContainer").load("index.php?module=ticketlist&event=TRefTickets&tid=[% $ticket.id %]&notabs=1&noform=1");
}
})
});
[% /if %]

[% if $user->hasRight(219) %]
$tags = $("#TicketTags").select2({theme:'bootstrap-5'}/*{
                                tags: true,
                                tokenSeparators: [',', ';'],
                                createTag: function (params) {
                                var term = $.trim(params.term);
                                if (term === '') {
                                return null;
    }
    
    return {
                                        id: term,
                                        text: term,
                                        newTag: true // add additional parameters
}
}
}*/).on('change', function(e) {
                                        /*
                                         var isNew = $(this).find('[data-select2-tag="true"]');
                                         if (isNew.length){
                                         
                                         $.ajax({
                                         type: "POST",
                                         url: "index.php?module=ticket&event=addTag",
                                         data: {tid: TicketID, tag: isNew.val()}
                                         }).done(function (data) {
                                         if (data) {
                                         
                                         //Neuer Tag angelegt und verknüpft
                                         isNew.replaceWith('<option selected value="' + data + '">' + isNew.val() + '</option>');
                                         $("#TicketTags").trigger('change'); //update select2
                                         
                                         
                                         } else {
                                         //Fehler beim Speichern
                                         }
                                         });
                                         }
                                         */
                                        var data = $("#TicketTags").trigger('change.select2').val();
                                $.ajax({
                                type: "POST",
                                        url: "index.php?module=ticket&event=changeTicketTags",
                                        data: {tid: TicketID, tagids: data}
                                })
                                });
                                    [% /if %]
                                    
                                    
                                    
                                    $("#Category1Form").load("index.php?module=formwizard&event=viewFormular&tid=[% $ticket.id %]&fid=[% $categoryforms.formularid1 %]");
                        $("#Category2Form").load("index.php?module=formwizard&event=viewFormular&tid=[% $ticket.id %]&fid=[% $categoryforms.formularid2 %]");
                            $("#TemplateForm").load("index.php?module=formwizard&event=viewFormular&tid=[% $ticket.id %]&fid=[% $categoryforms.formularidtt %]");
                            [% if ($ticket.ticketstatusid != 3 && $ticket.ticketstatusid != 7 && $user->hasRight(5) && ($ticket.ticketstatusid != 9 || $user->hasRight(112))) && !($NoCatChangeWhenForms && $categoryforms.formularid2 > 0)%]
                            $("#CategoryDescr1").select2({theme: 'bootstrap-5',
                                                language: ts_lang,
                                                ajax: {
                                                url: "index.php?module=category&event=autocompleteJson",
                                                        dataType: 'json',
                                                        delay: 250,
                                                        data: function (params) {
                                                        return {
                                                        q: params.term, // search term
                                                                id: 0,
                                                                type: 'ticket',
        [% if $type.type_id %]
                                                        typeid: [% $type.type_id %],
        [% /if %]
        [% if $catdep %]
                                                        cid: 1,
        [% /if %]
        [% if $hmcompany|strpos:"AVAG HOLDING" !== false %]
                                                        view:'avag',
                                                                tid: 0,
        [% /if %]
                                                        ttt:0
                                            };
                                                },
                                                processResults: function (data) {
                                                                return {
                                                                results: data.items
                                                };
                                                }
                                                },
                                                    escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
                                                    }).on("select2:select", function(e) {
                                                                        var data = e.params.data;
                                                                if (data && data.id != $("#CategoryID1").val()) {
                                                                $("#CategoryID1").val(data.id).trigger('change');
                                                                $.post("index.php?module=category&class=select&type=ticket&tid=" + tid + "&id=1&cid=" + $("#CategoryID1").val() + "&save=1").done(function (json) {
                                                                location.reload();
                                                    })
                                                    
                                                    }
                                                        });
                                                        $("#CategoryDescr2").select2({theme: 'bootstrap-5',
                                                                        language: "[% $user->language_type %]",
                                                                        ajax: {
                                                                        url: "index.php?module=category&event=autocompleteJson",
                                                                                dataType: 'json',
                                                                                delay: 250,
                                                                                data: function (params) {
                                                                                return {
                                                                                q: params.term, // search term
                                                                                        cid: 2,
                                                                                        type: 'ticket',
        [% if $type.type_id %]
                                                                                typeid: [% $type.type_id %],
        [% /if %]
        [% if $catdep %]
                                                                                id: $('#CategoryID1').val(),
        [% else %]
                                                                                id: "0",
        [% /if %]

        [% if $hmcompany|strpos:"AVAG HOLDING" !== false %]
                                                                                view: "eds",
        [% /if %]
                                                                                ttt:0
                                                    };
                                                    },
                                                        processResults: function (data) {
                                                                                        return {
                                                                                        results: data.items
                                                            };
                                                            }
                                                            },
                                                            escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
                                                }).on("select2:select", function(e) {
                                                                                                var data = e.params.data;
                                                                                        if (data && data.id != $("#CategoryID2").val()) {
                                                                                        $("#CategoryID2").val(data.id).trigger('change');
                                                                                        $.post("index.php?module=category&class=select&type=ticket&tid=" + tid + "&id=2&cid=" + $("#CategoryID2").val() + "&save=1").done(function (json) {
                                                                                        location.reload();
                                                    })
                                                }
                                                });
                                                [% /if %]
                                                    
                                                    $("[id^=textarea_]").sceditor({
                                                                                                format: "bbcode",
                                                                                                style: "includes/js/sceditor-2.1.2/minified/jquery.sceditor.default.min.css",
                                                                                                toolbar: "bold,italic,underline,subscript,superscript,horizontalrule,bulletlist,orderedlist|font,color|pastetext,source,maximize|insertSnippet,addSnippet,showSnippetlist",
                                                                                                //toolbar: "bold,italic,underline,subscript,superscript,horizontalrule,bulletlist,orderedlist|font,color|pastetext,source,maximize",
                                                                                                colors: '#000|#F00|#11C11D|#00F|#B700B7|#FF8C00|#008080|#808080|#D3D3D3',
                                                                                                emoticonsEnabled: false,
                                                                                                charset: 'ISO-8859-1',
                                                                                                autoUpdate: true,
                                                                                                width: '85%',
                                                                                                //autoExpand: true,
                                                                                                autofocus: true,
                                                                                                enablePasteFiltering: true,
                                                                                                locale: ts_lang
                                                })
                                                
                                                function formatState (opt) {
                                                                                                // console.log(opt);
                                                                                                var avatar = $("#SupporterSelect option[value=" + opt.id + "]").attr("avatar");
                                                                                                console.log(avatar);
                                                                                        var crop = $("#SupporterSelect option[value=" + opt.id + "]").attr("crop");
                                                                                        var $opt = '';
                                                                                        if (!opt.id) {
                                                                                        return opt.text.toUpperCase();
}
if (parseInt(crop) == 1){
                                                                                                $opt = $(
                                                                                                        '<span id="img-set-' + opt.id + '">[% if $smarty.const.SHOWAVATAR %]<img class="lazyImg hm-avatar-medium" data-src="index.php?module=upload&class=download&event=ShowImage&name=Medium_' + avatar + '"/> [% /if %]' + opt.text + '</span>'
                                                                                                        );
                                                }
                                                else{
                                                                                                $opt = $(
                                                                                                        '<span>[% if $smarty.const.SHOWAVATAR %]<span class="lazy-img-circular" id="lazy-img-circular-' + opt.id + '"></span> [% /if %]' + '<span>' + opt.text + '</span>' + '</span>'
                                                                                                        );
                                            }
                                            
                                            return $opt;
                                                };
                                                function formatSelect(opt){
                                               
                                                                                                var avatar = $("#SupporterSelect option[value=" + opt.id + "]").attr("avatar");
                                                                                        var department = $("#SupporterSelect option[value=" + opt.id + "]").attr("department");
                                                                                        var crop = $("#SupporterSelect option[value=" + opt.id + "]").attr("crop");
                                                                                        var remarktext = $("#SupporterSelect option[value=" + opt.id + "]").attr("remarktext");
                                                                                        var $opt = '';
                                                                                        if (!opt.id) {
                                                                                        return opt.text.toUpperCase();
                                        }
                                            if (department != ''){
                                                                                                if (parseInt(crop) == 1){
                                                                                        $opt = $(
                                                                                                '<div class="row">' +
                                                                                                '<div class="col-md-2 col-sm-12">[% if $smarty.const.SHOWAVATAR %]<img class="hm-avatar-medium" src="index.php?module=upload&class=download&event=ShowImage&name=Medium_' + avatar + '"/>[% /if %]</div>' +
                                                                                                '<div class="col-md-10 col-sm-12 text-left">' + opt.text + '<p style="font-style:italic; font-size: 0.8em;">' + department + '</p>' + '<p style="font-size: 0.8em;">' + remarktext + '</p></div>' +
                                                                                                '</div>'
                                                                                                );
                                            }
                                            else{
                                                                                                $opt = $(
                                                                                                        '<div class="row">' +
                                                                                                        '<div class="col-md-2 col-sm-12">[% if $smarty.const.SHOWAVATAR %]<div class="img-circular" id="img-circular-' + opt.id + '"></div>[% /if %]</div>' +
                                                                                                        '<div class="col-md-10 col-sm-12 text-left">' + opt.text + '<p style="font-style:italic; font-size: 0.8em;">' + department + '</p>' + '<p style="font-size: 0.8em;">' + remarktext + '</p></div>' +
                                                                                                        '</div>'
                                                                                                        );
                                                }
                                                
                                                }
                                            else{
                                                                                                if (parseInt(crop) == 1){
                                                                                        $opt = $(
                                                                                                '<div class="row">' +
                                                                                                '<div class="col-md-2 col-sm-12">[% if $smarty.const.SHOWAVATAR %]<img class=" hm-avatar-medium" src="index.php?module=upload&class=download&event=ShowImage&name=Medium_' + avatar + '"/>[% /if %]</div>' +
                                                                                                '<div class="col-md-10 col-sm-12 text-left">' + opt.text + '<p style="font-style:italic; font-size: 0.8em;">Supporter</p>' + '<p style="font-size: 0.8em;">' + remarktext + '</p></div>' +
                                                                                                '</div>'
                                                                                                );
                                            }
                                        else{
                                                                                                $opt = $(
                                                                                                        '<div class="row">' +
                                                                                                        '<div class="col-md-2 col-sm-12">[% if $smarty.const.SHOWAVATAR %]<div class="img-circular" id="img-circular-' + opt.id + '"></div>[% /if %]</div>' +
                                                                                                        '<div class="col-md-10 col-sm-12 text-left">' + opt.text + '<p style="font-style:italic; font-size: 0.8em;">Supporter</p>' + '<p style="font-size: 0.8em;">' + remarktext + '</p></div>' +
                                                                                                        '</div>'
                                                                                                        );
                            }
                            
                            }
                            return $opt;
                            }
                            
                            
                            
                            function formatStateGroup (opt) {
                                                                                                var avatar = $("#GroupSelect option[value=" + opt.id + "]").attr("avatar");
                                                                                        //console.log(avatar);
                                                                                        var crop = $("#GroupSelect option[value=" + opt.id + "]").attr("crop");
                                                                                        var $opt = '';
                                                                                        if (!opt.id) {
                                                                                        return opt.text.toUpperCase();
    }
    if (parseInt(crop) == 1){
                                                                                                $opt = $(
                                                                                                        '<span><img class="lazyImg hm-avatar-medium" alt="" data-src="index.php?module=upload&class=download&event=ShowImage&name=Medium_' + avatar + '"/> ' + opt.text + '</span>'
                                                                                                        );
                            }
                            else{
                                                                                                $opt = $(
                                                                                                        '<span><div class="img-circular lazy-img-circular-group-medium" id="lazy-img-circular-group-medium-' + opt.id + '"></div> ' + opt.text + '</span>'
                                                                                                        );
                            }
                        
                        return $opt;
                    };
                    function formatSelectGroup(opt) {
                                                                                                var avatar = $("#GroupSelect option[value=" + opt.id + "]").attr("avatar");
                                                                                        var crop = $("#GroupSelect option[value=" + opt.id + "]").attr("crop");
                                                                                        var $opt = '';
                                                                                        if (!opt.id) {
                                                                                        return opt.text.toUpperCase();
    }
    
    if (parseInt(crop) == 1){
                                                                                                $opt = $(
                                                                                                        '<div class="row">' +
                                                                                                        '<div class="col-md-2 col-sm-12"><img class="hm-avatar-medium" alt="" src="index.php?module=upload&class=download&event=ShowImage&name=Medium_' + avatar + '"/></div>' +
                                                                                                        '<div class="col-md-10 col-sm-12 text-left">' + opt.text + '</div>' +
                                                                                                        '</div>'
                                                                                                        );
                }
                else{
                                                                                                $opt = $(
                                                                                                        '<div class="row">' +
                                                                                                        '<div class="col-md-2 col-sm-12"><div class="img-circular img-circular-group-medium" id="img-circular-group-medium-' + opt.id + '"></div></div>' +
                                                                                                        '<div class="col-md-10 col-sm-12 text-left">' + opt.text + '</div>' +
                                                                                                        '</div>'
                                                                                                        );
                }
                
            
            return $opt;
            };
            function showBotRatingPopUp() {
                                                                                                if (BOTSuggestedKBIDs && !BOTMatchedKBID){
                                                                                        $('.bootbox-confirm').css('z-index', '200');
                                                                                        url = "index.php?module=ticket&event=BOTRatingPopUp&tid=" + TicketID;
                                                                                        $("#myBigIFrameModal").modal("show").css('z-index', 20000);
                        }
                        }
                    var $navbar = $("#HMMenuNavbar");
                $("a").on("mousedown", function(e){
                                                                                                switch (e.which)
                                                                                        {
                                                                                        case 1:
                                                                                                //left Click
                                                                                                break;
                                                                                        case 2:
//                AdjustHeader(); // Incase the user loads the page from halfway down (or something);
                                                                                                $(window).on("scroll", function () {
                                                                                        AdjustHeader();
        });
        //middle Click
        break;
        case 3:
        //right Click
            break;
            }
            return true; // to allow the browser to know that we handled it.
            });
            function AdjustHeader() {
                                                                                                if ($(window).scrollTop() > 60) {
                                                                                        if (!$navbar.hasClass("navbar-fixed-top")) {
                                                                                        $navbar.addClass("navbar-fixed-top");
                        }
                            } else {
                                                                                                $navbar.removeClass("navbar-fixed-top");
                }
                }
                    
                    
                    /**
                    * Prüft, ob die Benbutzerdefinierten Felder gefüllt sind
                        */
                        function checkUserDefFields() {

                                                                                                ValidPage = true;
    [% if $definedFields %]
        [% foreach $definedFields as $field %]
            [% if $field.requiredonclose || $field.required %]

                                                                                        if (($("#field_[% $field.field_id %]").is(':checkbox') && !$("#field_[% $field.field_id %]").is(':checked')) ||
                                                                                                (!$("#field_[% $field.field_id %]").val() && !$("#textarea_[% $field.field_id %]").val())
                                                                                                )
                                                                                        {
                                                                                        noty({
                                                                                        text: "[% $user->gettext("Folgendes Feld muss beim Schließen gefüllt sein:") %] [%$field.field_name %]",
                                                                                                                                                                                    type: 'error',
                                                                                                                                                                                    timeout: notifyTimeout
            });
            ValidPage = false;
            }
            [% /if %]
            [% /foreach %]
            [% /if%]
            [% if $definedDefFields %]
            [% foreach $definedDefFields as $field %]
                [% if $field.requiredonclose  || $field.required %]
                    [% if $field.showasradio != 1 %]
                    if (!$("#userfield_[%$field.userdeffieldid  %]").val())
                            {
                                                                                                                                                                                    noty({
                                                                                                                                                                                    text: "[% $user->gettext("Folgendes Feld muss beim Schließen gefüllt sein:") %] [% $field.fieldname %]",
                                                                                                                                                                                                                                                                                        type: 'error',
                                                                                                                                                                                                                                                                                        timeout: notifyTimeout
                                });
                                ValidPage = false;
                                }
                            [% else %]
                    if ($('input[name=DefField_[% $field.userdeffieldid %]]:checked').length) {

    }
    else {
                                                                                                                                                                                                                                                                                        noty({
                                                                                                                                                                                                                                                                                        text: "[% $user->gettext("Folgendes Feld muss beim Schließen gefüllt sein:") %] [% $field.fieldname %]",
                                                                                                                                                                                                                                                                                                                                                                                                    type: 'error',
                                                                                                                                                                                                                                                                                                                                                                                                    timeout: notifyTimeout
                                        });
                                        ValidPage = false;
                                        }
                                        [% /if %]
                                        [% /if %]
                                    
                                [% /foreach %]
                            [% /if%]
                        return ValidPage;
                        }
                            
                            
                            function changeToStory(TicketID, toStory) {
                                                                                                                                                                                                                                                                                                                                                                                                    $.post('index.php?module=ticket&event=changeToStory', {"TicketID": TicketID, 'toStory': toStory}, function(){
                                                                                                                                                                                                                                                                                                                                                                                                            window.location = 'index.php?module=ticket&event=show&id=' + TicketID;
    });
    }
    
    $(".modal-header").on("mousedown", function(mousedownEvt) {
                                                                                                                                                                                                                                                                                                                                                                                                            console.log("Down!");
                                                                                                                                                                                                                                                                                                                                                                                                    var $draggable = $(this);
                                                                                                                                                                                                                                                                                                                                                                                                    var x = mousedownEvt.pageX - $draggable.offset().left,
                                                                                                                                                                                                                                                                                                                                                                                                            y = mousedownEvt.pageY - $draggable.offset().top;
                                                                                                                                                                                                                                                                                                                                                                                                    $("body").on("mousemove.draggable", function(mousemoveEvt) {
                                                                                                                                                                                                                                                                                                                                                                                                    $draggable.closest(".modal-dialog").offset({
                                                                                                                                                                                                                                                                                                                                                                                                    "left": mousemoveEvt.pageX - x,
                                                                                                                                                                                                                                                                                                                                                                                                            "top": mousemoveEvt.pageY - y
        });
        });
        $("body").one("mouseup", function() {
                                                                                                                                                                                                                                                                                                                                                                                                            $("body").off("mousemove.draggable");
                });
        $draggable.closest(".modal").one("bs.modal.hide", function() {
                                                                                                                                                                                                                                                                                                                                                                                                            $("body").off("mousemove.draggable");
                });
                });
                
                
    $('#ticketdescr').on('shown', function(e, editable)
                {
                                                                                                                                                                                                                                                                                                                                                                                                            $('#HeadingTicketID').addClass('MarginForTicketID');
        });
        $('#ticketdescr').on('hidden', function(e, editable)
    {
        $('#HeadingTicketID').removeClass('MarginForTicketID');
    });
    var addedArtikel = [];
    var addedPositionObjects = {};


    $('#SaveWorkingHours').on( "click", function(e) {
    var dataString = $('#EditWorkingHoursForm').serialize();
    var url = 'index.php?module=errorpatterns&event=ChangeWorkingHours';    
    $.ajax({
      type: "POST",
      url: url,
      data: dataString,
      dataType: 'JSON',
      success: function(response){
        if(response.error){
            noty({
            text: response.message,
            type: 'error',
            timeout: notifyTimeout
            });
        } else {
            $('#WorkingHours').val(response.newWorkingHours);
            noty({
            text: response.message,
            type: 'success',
            timeout: notifyTimeout
            });
        }
        $.fancybox.close();
      }
    });
    e.preventDefault();
  });




            function DeletePosition(ETNumber, WarrantyProcessingRequestPositionID, pAPositionsNr) {
                    bootbox.confirm('[% $user->gettext('Positon mit ET-Nr.') %] <strong>' + ETNumber + '</strong> [% $user->gettext('wirklich löschen?') %]', function (result) {
                        if (result)
                        {
                            var url = 'index.php?module=wprequest&event=RemoveWPRPosition';
                            $.post(url, {WarrantyProcessingRequestPositionID: WarrantyProcessingRequestPositionID, pAPositionsNr:pAPositionsNr}, function (json) {
//                                console.log('Artikel entfernt: ');
//                                console.log(json);
                                noty({
                                    text: json.message,
                                    type: json.error ? 'error' : 'success',
                                    timeout: notifyTimeout
                                });
                                if(!json.error){
                                    $('#TableRowForPosition_' + ETNumber).remove(); //Tabelleneintrag entfernen
                                    $("[id^='PositionFormData_" + ETNumber + "_']").remove(); //Formularfelder mit den Artikeldaten entfernen

                                    $('#TableRowForPosition_' + WarrantyProcessingRequestPositionID).remove(); //Tabelleneintrag entfernen
                                    $("[id^='PositionFormData_" + WarrantyProcessingRequestPositionID + "_']").remove(); //Formularfelder mit den Artikeldaten entfernen

                                    //Eintrag aus Array entfernen:
                                    indexNo = addedArtikel.indexOf(ETNumber);
                                    if (indexNo > -1) {
                                      addedArtikel.splice(indexNo, 1);
                                    } 
                                    //Dropzone entfernen:
                                    try {
                                        Dropzone.forElement("#WPPositionDropzoneField_" + ETNumber).destroy();
                                    } catch (error) {
                            
                                    }
                        
                                } else {
                                    alert(json.message);
                                }
                            });
                        }
                    })
                }


            function DeletePositionFromSelection(ETNumber, WarrantyProcessingRequestPositionID, pAPositionsNr) {                  
                $('#TableRowForPosition_' + ETNumber).remove(); //Tabelleneintrag entfernen
                $("[id^='PositionFormData_" + ETNumber + "_']").remove(); //Formularfelder mit den Artikeldaten entfernen 
                //Eintrag aus Array entfernen:
                indexNo = addedArtikel.indexOf(ETNumber);
                if (indexNo > -1) {
                    addedArtikel.splice(indexNo, 1);
                }
                delete addedPositionObjects[ETNumber];
                //Dropzone entfernen:
                try {
                    Dropzone.forElement("#WPPositionDropzoneField_" + ETNumber).destroy();
                } catch (error) {
                            
                } 
            }

        
</script>


<!-- Component Ticket-Details end -->
