<link rel="stylesheet" type="text/css" href="styles/[% $CSSTEMPLATE %]/css/devices.css" />
<div class="row">


    [% if (($ticket.ticketreferenzid < 1 && $ticket.id && $ticket.ticketstatusid != 3 && $ticket.ticketstatusid != 7) || !$ticket.id) %]
        <div class="col-sm-3">
            <a class="btn btn-outline-primary ImageDialogAssetSelection" data-fancybox-type="iframe" href="index.php?module=device&amp;pid=1&amp;cid=[% if $ContactID > 0 %][% $ContactID %][% else %]0[% /if %][% if $setContact %]&setContact=1&con=1[% /if %]" >
                [% $user->gettext('Assets hinzuf&uuml;gen') %] [% $devcontact %]
            </a>
        </div>
    [% /if %]

    <div class="col-sm-7">
        <div class="btn-group" data-toggle="buttons">
            [% if !$user->hasRight(45) %]
                <label class="btn btn-outline-primary" id="DeviceContactLabel" style="display:none;">
                    <input type="checkbox" autocomplete="off" id="DeviceContact" value="1" > [% $user->gettext('Nur Assets des Kontaktes') %]
                </label>
            [% /if %]
            [% if !$user->hasRight(45) %]
                <label class="btn btn-outline-primary" id="DeviceOwnerLabel"  style="display:none;">
                    <input type="checkbox" autocomplete="off" id="DeviceOwner" value="1" > [% $user->gettext('Nur eigene Assets anzeigen') %]
                </label>
            [% /if %]
        </div>
    </div>
    <div class="col-sm-2">
        [% if $setContact %]
            <input type="text" id="DeviceSearchContact" class="form-control" placeholder="Filter" value="[% $search %]" onkeyup="if (true) {
                        getDevices(1);
                    }" />
        [% else %]
            <input type="text" id="DeviceSearch" class="form-control" placeholder="Filter" value="[% $search %]" onkeyup="if (true) {
                        getDevices();
                    }" />
        [% /if %]
    </div>

    <div class="col-sm-12">
        [% if $setContact %]
            <div id="DevicesContact" ></div>
        [% else %]
            <div id="Devices" ></div>
        [% /if %]
    </div>
</div>
<div id="DeviceStructure" class="DropDownList">
    <div id="DeviceStructureResult" class="DropDownResult"></div>
    <div id="DeviceStructureStatus" class="DropDownStatus">&nbsp;
        <a href="#" onclick="document.getElementById('DeviceStructure').style.display = 'none';"><img src="images/close.gif"  width="16" height="16" alt="" border="0" /></a>
    </div>
</div>

<script type="text/JavaScript" language="JavaScript">


  $('#DeviceContact').on('change', function () {
    getDevices([% $setContact %]);
  })
  $('#DeviceOwner').on('change', function () {
    getDevices([% $setContact %]);
  })


var DevicePagePos = 0;
var DeviceStructureID = 0;
var DeviceSelected = 0;
var DeviceTicketID = 0;
var DeviceStatusID = 0;
var DevicePopUP = true;
var DeviceSessionID = false;
var DeviceContactID = 0;
var DeviceRemovePossible = true;

var UseAssetDesk = [% if $AssetDesk %]true[% else %]false[% /if %];
var AssetDeskWebPath = '[% $AssetDeskWebPath %]';

    var tree;
    var PageLabel		= "[% $user->gettext('Seite') %]";
    var NoDevLabel 		= "[% $user->gettext('Es wurden keine Assets zugewiesen...') %]";
    var NoDevFound 		= "[% $user->gettext('Keine zugewiesene Assets gefunden...') %]";
    var HWLabel 	 	= "[% $user->gettext('Hardware') %]";
    var DescrLabel 	 	= "[% $user->gettext('Bezeichnung') %]";
    var ValueLabel 	 	= "[% $user->gettext('Wert') %]";
    var SWLabel		 	= "[% $user->gettext('Software') %]";
    var UserDefLabel 	= "[% $user->gettext('Benutzerdefiniert') %]";
    var StructureLabel 	= "[% $user->gettext('Firmenstruktur') %]";
    var CommercialLabel = "[% $user->gettext('Kommerzielle Daten') %]";
    var TicketLabel         = "[% $user->gettext('Tickets') %]";
    var CalendarModule  = [% if $Calendar == 1 %]1[% else %]0[% /if %];
    var CalendarActive  = [% if $user->Security->Calendar && $user->hasRight(61) %]1[% else %]0[% /if %];
    var CommercialDev = new Array();

    CommercialDev["inventorynr"] = "[% $user->gettext('Inventarnr.') %]";
    CommercialDev["inventoryno"] = "[% $user->gettext('Inventarnr.') %]";
    CommercialDev["purchasedate"] = "[% $user->gettext('Kaufdatum') %]";
    CommercialDev["purchaseprice"] = "[% $user->gettext('Kaufpreis') %]";
    CommercialDev["leasingperiod"] = "[% $user->gettext('Leasingdauer') %]";
    CommercialDev["leasingrate"] = "[% $user->gettext('Leasingrate') %]";
    CommercialDev["leasingstartdate"] = "[% $user->gettext('Leasingbeginn') %]";
    CommercialDev["leasingenddate"] = "[% $user->gettext('Leasingende') %]";
    CommercialDev["description"] = "[% $user->gettext('Beschreibung') %]";
    CommercialDev["outdate"] = "[% $user->gettext('Abgang') %]";
    CommercialDev["warrantyend"] = "[% $user->gettext('Garantieende') %]";
    CommercialDev["afabasicprice"] = "[% $user->gettext('AfA-Basispreis') %]";
    CommercialDev["afausingperiod"] = "[% $user->gettext('AfA-Periode') %]";
    CommercialDev["afaaccount"] = "[% $user->gettext('AfA-Verrechnunskonto') %]";
    CommercialDev["afastartdate"] = "[% $user->gettext('AfA-Beginn') %]";
    CommercialDev["afaenddate"] = "[% $user->gettext('AfA-Ende') %]";
    CommercialDev["leasingfactor"] = "[% $user->gettext('Leasingfaktor') %]";
    CommercialDev["leasingbasicprice"] = "[% $user->gettext('Leasingbasispreis') %]";
    CommercialDev["leasingremainvalue"] = "[% $user->gettext('Leasingrestwert') %]";
    CommercialDev["costcenter"] = "[% $user->gettext('Kostenstellennr.') %]";
    CommercialDev["costcenterdescription"] = "[% $user->gettext('Kostenstelle') %]";

    var SoftwareDev = new Array();
    SoftwareDev["productname"] = "[% $user->gettext('Produktname') %]";
    SoftwareDev["version"] = "[% $user->gettext('Version') %]";
    SoftwareDev["category"] = "[% $user->gettext('Kategorie') %]";
    SoftwareDev["type"] = "[% $user->gettext('Type') %]";
    SoftwareDev["buildnr"] = "[% $user->gettext('Build-Nr.') %]";
    SoftwareDev["vendor"] = "[% $user->gettext('Verkäufer') %]";
    SoftwareDev["swlanguage"] = "[% $user->gettext('Sprache') %]";
    SoftwareDev["descr"] = "[% $user->gettext('Beschreibung') %]";
    SoftwareDev["instdate"] = "[% $user->gettext('Install.-Datum') %]";

    DeviceTicketID  = [% if $ticket.id %][% $ticket.id %][% else %]0[% /if %];
    DeviceStatusID  = [% if $ticket.ticketstatusid %][% $ticket.ticketstatusid %][% else %]1[% /if %];
    DeviceSessionID = [% if $ticket.id %]0[% else %]1[% /if %];
    DeviceContactID = [% if $ticket.contactid %][% $ticket.contactid %][% else %]0[% /if %];

    DeviceRemovePossible = [% if $ticket.ticketreferenzid < 1 %]true[% else %]false[% /if %];



     getDevices([% $setContact %]);
        setContactIDToIFrameSrc();

    function chooseDevices() {
            if (document.getElementById('contact_id')) {
                    DeviceContactID = document.getElementById('contact_id').value;
            }
            window.open('index.php?module=device&pid=1&cid='+DeviceContactID, 'Devices', 'dependent=yes,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no');
    }


    function addDeviceTicket(DevID) {
        if (DeviceTicketID > 0) {
            makeHttpRequest("index.php?module=ticket&event=adddev&devid="+DevID+"&tid="+DeviceTicketID,"resDeviceTicketAdd", true);
        } else {
            console.log("Add Device Ticket: "+"index.php?module=ticket&event=adddev&devid="+DevID+"&sessid=1");
            makeHttpRequest("index.php?module=ticket&event=adddev&devid="+DevID+"&tid="+DeviceTicketID+"&sessid=1","resDeviceTicketAdd", true);
        }
//Ggf. Gruppe des Geräts zufügen
    $.post( "index.php?module=assets&event=jsonGetGroups", { devid: DevID }).done(function( data ) {
        $.each(data, function( index, value ) {
            if(value.groupid > 0){
                //$('#group_id').val(value.groupid).trigger('change');
                if($('#group_id').length && $('#group_id').is(":visible")){
                    //TicketNew
                    ConcatedValues = ($("#group_id").val() && $("#group_id").val().lenght) ? $("#group_id").val().concat(value.groupid) : value.groupid;
                    $("#group_id").val(ConcatedValues).trigger("change");
                } if($('#GroupSelect').length && $('#GroupSelect').is(":visible")){
                    //TicketDetails:
                    ConcatedValues = ($("#GroupSelect").select2("val") && $("#GroupSelect").select2("val").lenght) ? $("#GroupSelect").select2("val").concat(value.groupid) : value.groupid;
                    $("#GroupSelect").val(ConcatedValues).trigger("change");
                }
//                ConcatedValues = $("#group_id").val().lenght ? $("#group_id").val().concat(value.groupid) : value.groupid;
//                $("#group_id").val(ConcatedValues).trigger("change");

                noty({
                    text: value.AddedText,
                    type: 'success',
                    timeout: notifyTimeout
                });
            };
        });
        if (typeof saveGroupSupportersAfterDeviceUpdate === 'function') {
            saveGroupSupportersAfterDeviceUpdate();
        }

    });

        $("#device_"+DevID).addClass('addedDevice');
        $("#device_"+DevID+" .addDeviceLink").hide();
        $("#device_"+DevID+" .delDeviceLink").show();

//        if (typeof refreshErrorCodeSelection === 'function') {
//            refreshErrorCodeSelection();
//        }
        if (typeof refreshClassificationSelection === 'function') {
            refreshClassificationSelection();
        }
        if (typeof loadDeviceTicketPanel === 'function') {
                        console.log("Load Device!");

            loadDeviceTicketPanel();
        }
        if (typeof ChangeServiceScheckVisibility === 'function') {
            ChangeServiceScheckVisibility();
        }
        if (typeof RefreshServiceScheckSelection === 'function') {
            RefreshServiceScheckSelection();
        }
        if (typeof LoadServiceScheckExecutionTypes === 'function') {
            LoadServiceScheckExecutionTypes();
        }
        if (typeof ChangeServiceScheckVisibility === 'function') {
            ChangeServiceScheckVisibility();
        }
    }



    function delDeviceTicket(DevID) {
        var DeviceInvNoID = false;
        if(document.getElementById("DeviceInvNoID")) {
            var DeviceInvNoID = document.getElementById("DeviceInvNoID").value;
        }

        if (DeviceTicketID > 0) {
                //Gerät nicht löschbar, wenn Inventarnummer eingetragen
                if(DevID == DeviceInvNoID){
                        alert(DeviceRemoveError);
                } else {
                     makeHttpRequest("index.php?module=ticket&event=deldev&devid="+DevID+"&tid="+DeviceTicketID,
                            "resDeviceTicketAdd", true);
                }

        } else {
            if(DeviceInvNoID && DevID == DeviceInvNoID) {
                document.getElementById("DeviceInvNo").value = "";
                document.getElementById("DeviceInvNoID").value = "0";
                document.getElementById("DeviceInvNo").removeAttribute("readonly");
                document.getElementById('InvNoSearch').style.display='inline' ;
                document.getElementById('InvNoDelete').style.display='none' ;
            }
            makeHttpRequest("index.php?module=ticket&event=deldev&devid="+DevID+"&sessid=1",
                    "resDeviceTicketAdd", true);
        }
        $("#device_"+DevID).removeClass('addedDevice');
        $("#device_"+DevID+" .addDeviceLink").show();
        $("#device_"+DevID+" .delDeviceLink").hide();

//        if (typeof refreshErrorCodeSelection === 'function') {
//            refreshErrorCodeSelection();
//        }
        if (typeof refreshClassificationSelection === 'function') {
            refreshClassificationSelection();
        }
            console.log(typeof loadDeviceTicketPanel);
        if (typeof loadDeviceTicketPanel === 'function') {
            loadDeviceTicketPanel();
        }
        if (typeof ChangeServiceScheckVisibility === 'function') {
            ChangeServiceScheckVisibility();
        }
        if (typeof RefreshServiceScheckSelection === 'function') {
            RefreshServiceScheckSelection();
        }
        if (typeof LoadServiceScheckExecutionTypes === 'function') {
            LoadServiceScheckExecutionTypes();
        }
        if (typeof ChangeServiceScheckVisibility === 'function') {
            ChangeServiceScheckVisibility();
        }
    }

    function resDeviceTicketAdd(xmldoc) {
             console.log("doc", xmldoc);
            var obj = xmldoc.getElementsByTagName('res');
            if (obj.length > 0 && obj[0].firstChild.nodeValue == 1) {
                console.log("getDevices soll aufgerufen werden...");
                    getDevices(0);
            }
            else{
                console.log("Falscher Wert der Devices XML");
            }
    }



    //Richtige ContactID bei der DeviceAuswahl verwenden:
    function setContactIDToIFrameSrc(){
        //run onload code here
        var ContactID = $("#contact_id").val();
        ContactID = (0 < ContactID) ? ContactID : 0;
        var url = "index.php?module=device&pid=1&cid="+ ContactID +"&con=1";
        $('#DeviceSelectFrame').attr('src' , url);
    }



function showStructureBox() {
    var txtfield = document.getElementById("DeviceStructrueDescr");
    var userbox = document.getElementById("DeviceStructure");

    if (userbox.style.visibility != "visible") {
        var spantop = absTop(txtfield);
        var spanleft = absLeft(txtfield);
        var spanwidth = txtfield.offsetWidth;
        var spanheight = txtfield.offsetHeight;

        //Relative Positionierung der Tabs bei Containerposition berücksichtigen:

        var containerPos = $('#tabs').offset();
        if (containerPos) {
            spantop = spantop - containerPos.top
            spanleft = spanleft - containerPos.left
        }

        spantop = spantop + spanheight;
        spanwidth = spanwidth - 2;

        userbox.style.width = spanwidth + "px";
        userbox.style.left = spanleft + "px";
        userbox.style.top = spantop + "px";

        userbox.style.visibility = "visible";
        userbox.style.display = "block";
        getDeviceStructure();
    } else {
        userbox.style.visibility = "hidden";
        userbox.style.display = "none";
    }
}

function setDeviceStructure(sid, childs, name) {
    DeviceStructureID = sid;
    document.getElementById('DeviceStructrueDescr').value = name;
    showStructureBox();
    switchDevicePage(0);
    $("#delDeviceStructrueDescr").show();
}

function clearDeviceStructure() {
    DeviceStructureID = 0;
    document.getElementById('DeviceStructrueDescr').value = '';
    switchDevicePage(0);
    $("#delDeviceStructrueDescr").hide();
}

function switchDevicePage(pos) {
    DevicePagePos = pos;
    getDevices(0);
}

function switchLDAPDevicePage(pos) {
    DevicePagePos = pos;
    getLDAPDevices();
}

function getDevices(own) {
    console.log('getdevices gestartet...');
   objDeviceList = document.getElementById("Devices");
    sid = (DeviceStructureID > 0) ? "&sid=" + DeviceStructureID : "";
    suche = own == 1 ? encodeURIComponent(document.getElementById('DeviceSearchContact').value) : encodeURIComponent(document.getElementById('DeviceSearch').value);
    var suche = '';
    suche = own == 1 ? $("#DeviceSearchContact").val() : $("#DeviceSearch").val();

    suche = (suche.length > 0) ? "&search=" + suche : "";
    var owndevices = document.getElementById("DeviceOwner");
    check = (owndevices && owndevices.checked) ? "&owndevices=1" : "";
    DeviceTid = (DeviceTicketID > 0) ? "&tid=" + DeviceTicketID : "";
    sessid = (DeviceSessionID == 1) ? "&sessid=1" : "";
    cid = (DeviceContactID > 0) ? "&cid=" + DeviceContactID : "&cid=0";
    var contactdevices = document.getElementById("DeviceContact");
    con = (contactdevices && (contactdevices.checked || own == 1)) ? "&con=1" : "";
    var cal = (CalendarModule && CalendarModule == 1) ? "&cal=1" : "";


    //Kontaktid aus Ticketformular verwenden:
    url = "index.php?module=device&event=getDeviceListXML&pos=" + DevicePagePos + sid + suche + check + DeviceTid + sessid + cid + con + cal;

    if ('' != con) {
        var ContactID = ($("#contact_id").val()) ? $("#contact_id").val() : parent.$("#contact_id").val();

        if ('cid=' != ContactIDString && 0 < ContactID) {
            var ContactIDString = 'cid=' + ContactID;
            var re = /\.*(cid=[0-9]*)\.*/;
            re.exec(url);

            url = url.replace(re, ContactIDString);
        }
    }

    $.post(url, null, function (xmldoc){buildDeviceList(xmldoc, own)});
}

function getLDAPDevices() {
    objDeviceList = document.getElementById("Devices");
    sid = (DeviceStructureID > 0) ? "&sid=" + DeviceStructureID : "";
    suche = encodeURIComponent(document.getElementById('LDAPDeviceSearch').value);
    suche = (suche.length > 0) ? "&search=" + suche : "";
    var owndevices = document.getElementById("DeviceOwner");
    check = (owndevices && owndevices.checked) ? "&owndevices=1" : "";
    DeviceTid = (DeviceTicketID > 0) ? "&tid=" + DeviceTicketID : "";
    sessid = (DeviceSessionID == 1) ? "&sessid=1" : "";
    cid = (DeviceContactID > 0) ? "&cid=" + DeviceContactID : "&cid=0";
    var contactdevices = document.getElementById("DeviceContact");
    con = (contactdevices && contactdevices.checked) ? "&con=1" : "";
    var cal = (CalendarModule && CalendarModule == 1) ? "&cal=1" : "";

    makeHttpRequest(
            "index.php?module=device&event=ldap_getDeviceListXML&pos=" + DevicePagePos + sid + suche + check + DeviceTid + sessid + cid + con + cal,
            "buildLDAPDeviceList", true);
}

function buildLDAPDeviceList(xmldoc) {

    var HTMLOutput = "";
    var devices = xmldoc.getElementsByTagName("device");
    var navigation = xmldoc.getElementsByTagName("navigation")[0];
    var Pages = navigation.getAttribute("pages");
    var navigationString = "&nbsp;";


    if (Pages > 1) {

        var EntriesPerPage = navigation.getAttribute("entriesperpage");
        var Entries = navigation.getAttribute("entries");
        var Page = navigation.getAttribute("page");
        var pos = navigation.getAttribute("pos");

        posback = (parseInt(pos) > 0) ? parseInt(pos) - 1 : 0;
        lastpage = (parseInt(Pages) > 0) ? parseInt(Pages) - 1 : 0;
        nextpage = (parseInt(pos) < lastpage) ? parseInt(pos) + 1 : lastpage;


        navigationString = "<tr><td colspan=\"10\" >&nbsp;&nbsp;<div class=\"navigation\">";
        navigationString += '<ul>';
        navigationString += '<li>Seite: </li>';
        if (parseInt(pos) > 0) {
            navigationString += '<li><a href="#" onclick="switchLDAPDevicePage(' + posback + ')" class="button button-grey"><span>&laquo;</span></a></li>';
        }
        if (0 < parseInt(Pages)) {
            navigationString += '<li><href="#" onclick="switchLDAPDevicePage(0)" class="button button-';
            navigationString += (pos == 0) ? 'green' : 'grey';
            navigationString += '"><span>1</span></a></li>';
        }
        if (1 < parseInt(Pages)) {
            navigationString += '<li><href="#" onclick="switchLDAPDevicePage(1)" class="button button-';
            navigationString += (pos == 1) ? 'green' : 'grey';
            navigationString += '"><span>2</span></a></li>';
        }
        if (2 < parseInt(Pages)) {
            navigationString += '<li><href="#" onclick="switchLDAPDevicePage(2)" class="button button-';
            navigationString += (pos == 2) ? 'green' : 'grey';
            navigationString += '"><span>3</span></a></li>';
        }
        if (3 < parseInt(Pages)) {
            navigationString += '<li><href="#" onclick="switchLDAPDevicePage(3)" class="button button-';
            navigationString += (pos == 3) ? 'green' : 'grey';
            navigationString += '"><span>4</span></a></li>';
        }
        if (4 < parseInt(Pages)) {
            navigationString += '<li><href="#" onclick="switchLDAPDevicePage(4)" class="button button-';
            navigationString += (pos == 4) ? 'green' : 'grey';
            navigationString += '"><span>5</span></a></li>';
        }
        if (5 < parseInt(Pages)) {

            if (5 < pos) {
                navigationString += '<li>...</li>'
            }
            ;
            if (4 < pos && (parseInt(pos) + 1) < Pages) {

                navigationString += '<li><a href="#" onclick="" class="button button-green"><span>' + nextpage + '</span></a></li>';

                navigationString += '<li>...</li>';
            }

            navigationString += '<li><href="#" onclick="switchLDAPDevicePage(' + lastpage + ')" class="button button-';
            navigationString += (pos == lastpage) ? 'green' : 'grey';
            navigationString += '"><span>' + parseInt(Pages) + '</span></a></li>';
            navigationString += '<li><a href="#" onclick="switchLDAPDevicePage(' + nextpage + ')" class="button button-grey"><span>&raquo;</span></a></li>';

        }
        navigationString += '</ul>';
        navigationString += '</div>';
        navigationString += "</td></tr>";
    } else {
        navigationString = "";
    }

    if (devices.length > 0) {
        for (i = 0; i < devices.length; i++) {

            imgNode = devices[i].getElementsByTagName('TypeFileName')[0];
            devidNode = devices[i].getElementsByTagName('DevID')[0];
            devicenameNode = devices[i].getElementsByTagName('DeviceName')[0];
            modelNode = devices[i].getElementsByTagName('Model')[0];
            locationNode = devices[i].getElementsByTagName('Location')[0];
            descrNode = devices[i].getElementsByTagName('Description')[0];
            osNode = devices[i].getElementsByTagName('OS')[0];
            TypeNode = devices[i].getElementsByTagName('Type')[0];

            imgVal = imgNode.firstChild.nodeValue;
            devidVal = devidNode.firstChild.nodeValue;
            devicenameVal = devicenameNode.firstChild.nodeValue;
            modelVal = modelNode.firstChild.nodeValue;
            locationVal = locationNode.firstChild.nodeValue;
            descrVal = descrNode.firstChild.nodeValue;
            osVal = osNode.firstChild.nodeValue;
            typeVal = TypeNode.firstChild.nodeValue;



            HTMLOutput += '<div class="device" onmouseover="this.className=\'device_hover\'" onmouseout="this.className=\'device\'">';
            HTMLOutput += '  <div class="device_img device_' + imgVal + '"><img src="images/blank.gif" height="48" width="48" alt=""></div>';
            HTMLOutput += '  <div class="device_name">' + devicenameVal + ' (' + typeVal + ')';

            if (DevicePopUP) {
                HTMLOutput += '&nbsp;<a href="JavaScript:void(0);" onclick="addLDAPDevice(' + devidVal + ');"><img src="images/add.gif" width="16" height="16" alt="" border="0"  /></a>';
            }

            if ((DeviceRemovePossible && DeviceTicketID > 0 && DeviceStatusID != 3 && DeviceStatusID != 7) || DeviceSessionID == 1) {
                HTMLOutput += '&nbsp;<a href="JavaScript:void(0);" onclick="delLDAPDeviceTicket(' + devidVal + ');"><img src="images/delete2.gif" width="16" height="16" alt="" border="0"  /></a>';
            }

            HTMLOutput += '</div>';
            HTMLOutput += LocationLabel + ': ' + locationVal + ' <br />';

            if (typeVal == 'WS') {
                HTMLOutput += ' OS: ' + osVal + ' <br />';
                HTMLOutput += DescrLabel + ': ' + descrVal;
            } else {
                HTMLOutput += ModelLabel + ': ' + modelVal + ' <br />';
                HTMLOutput += CommentLabel + ': ' + descrVal;
            }

            HTMLOutput += '</div>';

        }
    } else {


        HTMLOutput = '<div class="card panel-info shadow-sm rounded" style="margin-top:15px;"><div class="card-body">'+NoDevFound+'</div></div>';
    }

    document.getElementById('LDAPDevices').innerHTML = HTMLOutput;
    document.getElementById('LDAPDeviceNavigation').innerHTML = navigationString;


}

function buildDeviceList(xmldoc, SetContact) {
    var HTMLOutput = '<ul class="list-group">';
    var devices = xmldoc.getElementsByTagName("device");
    var navigation = xmldoc.getElementsByTagName("navigation")[0];
    var Pages = navigation.getAttribute("pages");
    var navigationString = "&nbsp;";

    if (Pages > 1) {

        var EntriesPerPage = navigation.getAttribute("entriesperpage");
        var Entries = navigation.getAttribute("entries");
        var Page = navigation.getAttribute("page");
        var pos = navigation.getAttribute("pos");

        posback = (parseInt(pos) > 0) ? parseInt(pos) - 1 : 0;
        lastpage = (parseInt(Pages) > 0) ? parseInt(Pages) - 1 : 0;
        nextpage = (parseInt(pos) < lastpage) ? parseInt(pos) + 1 : lastpage;


        navigationString = "<div class=\"navigation\">";
        navigationString += '<ul class="pagination" style="float:right;">';
        if (parseInt(pos) > 0) {
            navigationString += '<li><a onclick="switchDevicePage(' + posback + ')" class="button button-grey"><span>&laquo;</span></a></li>';
        }
        if (0 < parseInt(Pages)) {
            navigationString += '<li><a  onclick="switchDevicePage(0)" class="btn btn-outline-primary" ';
            navigationString += (pos != 0) ? '' : ' disabled="disabled"';
            navigationString += '><span>1</span></a></li>';
        }
        if (1 < parseInt(Pages)) {
           navigationString += '<li><a onclick="switchDevicePage(1)" class="btn btn-outline-primary" ';
            navigationString += (pos != 1) ? '' : ' disabled="disabled"';
            navigationString += '><span>2</span></a></li>';
        }
        if (2 < parseInt(Pages)) {
            navigationString += '<li><a  onclick="switchDevicePage(2)" class="btn btn-outline-primary"';
             navigationString += (pos != 2) ? '' : ' disabled="disabled"';
            navigationString += '><span>3</span></a></li>';
        }
        if (3 < parseInt(Pages)) {
            navigationString += '<li><a  onclick="switchDevicePage(3)" class="btn btn-outline-primary"';
            navigationString += (pos != 3) ? '' : ' disabled="disabled"';
            navigationString += '><span>4</span></a></li>';
        }
        if (4 < parseInt(Pages)) {
             navigationString += '<li><a onclick="switchDevicePage(4)" class="btn btn-outline-primary"';
             navigationString += (pos != 4) ? '' : ' disabled="disabled"';
            navigationString += '><span>5</span></a></li>';
        }
        if (5 < parseInt(Pages)) {

            if (5 < pos) {
                navigationString += '<li>...</li>'
            }
            ;
            if (4 < pos && (parseInt(pos) + 1) < Pages) {

                navigationString += '<li><a  onclick="" class="button button-green"><span>' + nextpage + '</span></a></li>';

                navigationString += '<li>...</li>';
            }

            navigationString += '<li><a  onclick="switchDevicePage(' + lastpage + ')" class="btn btn-outline-primary"';
            navigationString += (pos != lastpage) ? '' : ' disabled="disabled"';
            navigationString += '><span>' + parseInt(Pages) + '</span></a></li>';
            navigationString += '<li><a  onclick="switchDevicePage(' + nextpage + ')" class="button button-default"><span>&raquo;</span></a></li>';

        }
        navigationString += '</ul>';
        navigationString += '</div>';
    } else {
        navigationString = "";
    }

    if (devices.length > 0) {
        for (i = 0; i < devices.length; i++) {

            imgNode = devices[i].getElementsByTagName('TypeFileName')[0];
            devidNode = devices[i].getElementsByTagName('DevID')[0];
            hostnameNode = devices[i].getElementsByTagName('Hostname')[0];
            devicenameNode = devices[i].getElementsByTagName('DeviceName')[0];
            modelNode = devices[i].getElementsByTagName('Model')[0];
            manufactNode = devices[i].getElementsByTagName('Manufacturer')[0];
            typenameNode = devices[i].getElementsByTagName('TypeName')[0];
            domainNode = devices[i].getElementsByTagName('DomainName')[0];
            ownerNode = devices[i].getElementsByTagName('Owner')[0];
            contactNode = devices[i].getElementsByTagName('Contact')[0];

            imgVal = imgNode.firstChild.nodeValue;
            devidVal = devidNode.firstChild.nodeValue;
            hostnameVal = hostnameNode.firstChild.nodeValue;
            devicenameVal = devicenameNode.firstChild.nodeValue;
            modelVal = modelNode.firstChild.nodeValue;
            manufactVal = manufactNode.firstChild.nodeValue;
            typenameVal = typenameNode.firstChild.nodeValue;
            domainVal = domainNode.firstChild.nodeValue;
            ownerVal = ownerNode.firstChild.nodeValue;
            contactVal = contactNode.firstChild.nodeValue;
            inventorynoNode = devices[i].getElementsByTagName('InventoryNo')[0];
            inventorynoVal = inventorynoNode.firstChild.nodeValue;
            physicalPathNode = devices[i].getElementsByTagName('physicalPath')[0];
            physicalPathVal = physicalPathNode.firstChild.nodeValue;

            addedToTicketNode = devices[i].getElementsByTagName('addedToTicket')[0];
            addedToTicketVal = addedToTicketNode.firstChild.nodeValue;

AddClass = (addedToTicketVal == 1 && SetContact == 1 ) ? 'addedDevice' : '' ;
            HTMLOutput += '<li class="list-group-item"><div class="device '+AddClass+'" id="device_'+devidVal+'">';
            HTMLOutput += '<div class="card panel-default"><div class="card-header">';
            HTMLOutput += '<div class="row"><div class="col-sm-6"><h3 class="card-title">' + hostnameVal + ' (' + typenameVal + ')</h3></div>';
            HTMLOutput += '<div class="col-sm-6 text-end">';



            if (contactVal == 1) {
                //HTMLOutput += ' <img src="images/hm.gif" width="16" height="16" alt="owner" >';
                HTMLOutput += ' <span class="fa fa-circle-info"></span> ';
            }

            if (ownerVal == 1) {
                //HTMLOutput += ' <img src="images/status_online.gif" width="16" height="16" alt="owner" >';
                HTMLOutput += ' <span class="fa fa-user"></span>';
            }


            loadAssetDetailsJQString = '$("#Device' + devidVal + '").load("index.php?module=device&event=assetInfo&id=' + devidVal + '", function () {activateDataTable();});$("#Device' + devidVal + '").toggle();';
            HTMLOutput += '<div class="btn-group">';

            if(UseAssetDesk && AssetDeskWebPath != ''){
            HTMLOutput += ' <a class="btn btn-outline-primary btn-sm lightContrast" target="_blank" href="' + AssetDeskWebPath + '3/' + devidVal + '" title="Gerät in AssetDesk-Web öffnen">' +
                        '<img src="images/LogoAssetDeskWeb_small.png" style="width:17.5px; height:17.5px;" alt="AssetDesk">' +
                        '</a>';
            }

                HTMLOutput += ' <a class="btn btn-outline-primary btn-sm lightContrast" href="JavaScript:void(0)" onclick=\''+ loadAssetDetailsJQString +'\' title="Details"><span class="fa fa-info"></span></a>';

            if (DevicePopUP ) {
                AddStyle = addedToTicketVal == 1 ? ' style="display:none" ' : '' ;
                //HTMLOutput += '&nbsp;<a href="JavaScript:void(0);" onclick="addDevice(' + devidVal + ');"><img src="images/add.gif" width="16" height="16" alt="" border="0"  /></a>';
                HTMLOutput += ' <a class="btn btn-outline-primary btn-sm addDeviceLink lightContrast" ' + AddStyle +' href="JavaScript:void(0);" onclick="addDeviceTicket(' + devidVal + ');"><span class="fa fa-plus"></span></a>';

            }

            if (CalendarActive && CalendarActive == 1){
                //HTMLOutput += '&nbsp;<a href="index.php?module=calendar&event=device&class=event&iframe=1&caldeviceid='+ devidVal + '" class="calDeviceEvent dialog" data-fancybox-type="iframe" ><img src="images/cal.gif" width="16" height="16" alt="Calendar" border="0" title="Reservieren" /></a>';
                HTMLOutput += ' <a class="btn btn-outline-primary btn-sm" href="index.php?module=calendar&event=device&class=event&iframe=1&caldeviceid='+ devidVal + '" class="calDeviceEvent dialog" data-fancybox-type="iframe" title="[% $user->gettext('Kalenderevent zufügen') %]"><span class="fa fa-calendar"></span></a>';
            }
            HTMLOutput += "<a class=\"btn btn-outline-primary btn-sm lightContrast\" href=\"javascript: copyElementToClipboard('table_" + devidVal + "') \" title=\"Assetdaten in Clipboard kopieren\"><span class=\"fa fa-copy\"></span></a>";


            if ((DeviceRemovePossible && DeviceTicketID > 0 && DeviceStatusID != 3 && DeviceStatusID != 7) || DeviceSessionID == 1) {
                AddStyle2 = addedToTicketVal != 1 ? ' style="display:none" ' : '' ;
                //HTMLOutput += '&nbsp;<a href="JavaScript:void(0);" onclick="delDeviceTicket(' + devidVal + ');"><img src="images/delete2.gif" width="16" height="16" alt="" border="0"  /></a>';
                HTMLOutput += ' <a class="btn btn-outline-primary btn-sm delDeviceLink lightContrast " ' + AddStyle2 +' href="JavaScript:void(0);" onclick="delDeviceTicket(' + devidVal + ');" title="[% $user->gettext('Zuordnung entfernen') %]"><span class="fa fa-times"></span></a>';
            }
                        HTMLOutput += '</div>';

                HTMLOutput += '</div></div></div><div class="card-body">';
            HTMLOutput += '  <div class="device_img device_' + imgVal + '"><img src="images/blank.gif" height="48" width="48" alt=""></div>';

            HTMLOutput += '<div class="pysicalPath" title="[% $user->gettext('Pfad zum Asset') %]">' + physicalPathVal + '</div>';

            HTMLOutput += '  <span title="[% $user->gettext('Domäne') %]">' + domainVal + '</span>';

            if (domainVal != '' && devicenameVal != '') {
                HTMLOutput += ' / <span title="[% $user->gettext('Asset-Name') %]">';
                HTMLOutput += devicenameVal + '</span>';
            }


            if (devicenameVal != '' && inventorynoVal != '') {
                HTMLOutput += ' / <span title="[% $user->gettext('Inventarnummer') %]">';
                HTMLOutput += inventorynoVal + '</span><br />'
            }


            HTMLOutput += '  <span title="[% $user->gettext('Hersteller') %]">' + manufactVal + '</span>';
            if (manufactVal != '' && modelVal != '') {
                HTMLOutput += ' / <span title="[% $user->gettext('Modell') %]">';
                HTMLOutput += modelVal + '</span>';
            }
             var TableOutPut = '<div style="display:none;" id="table_' + devidVal + '"><p><strong>Assetname:</strong>' + devicenameVal + '</p><p><strong>Assettyp:</strong> ' + typenameVal + '</p>';
            if (domainVal !== '') {
                TableOutPut += '<p><strong>Domäne:</strong>' + domainVal + '</p>';
            }
            if (physicalPathVal !== '') {
                TableOutPut += '<p><strong>Pfad:</strong>' + physicalPathVal + '</p>';
            }
            if (inventorynoVal !== '') {
                TableOutPut += '<p><strong>Inventarnummer:</strong>' + inventorynoVal + '</p>';
            }
            if (manufactVal !== '' && modelVal !== '') {
                TableOutPut += '<p><strong>Hersteller:</strong>' + manufactVal + '</p><p>Modell:' + modelVal + '</p>';
            }
            TableOutPut += '</div>';
            HTMLOutput += TableOutPut;
            HTMLOutput += '<br />';
            HTMLOutput += '<div id="Device' + devidVal + '" class="DeviceDetails" style="display:none;"></div></div></li>';
        }
    } else {

        HTMLOutput = '<div class="card panel-info shadow-sm rounded" style="margin-top:15px;"><div class="card-body">'+NoDevFound+'</div></div>';
    }
    HTMLOutput += '</ul><div id="DeviceNavigation">' + navigationString + '</div>';

    if (SetContact)
    {
        document.getElementById('DevicesContact').innerHTML = HTMLOutput;
        ChangeAllDeviceCountersContact(devices.length);
    }
    else
    {
        document.getElementById('Devices').innerHTML = HTMLOutput;
        ChangeAllDeviceCounters(devices.length);
    }
}


function ChangeAllDeviceCounters(Count) {
    $.get('index.php?module=ticket&event=CountDevice&TicketID='+TicketID, function(res){
        Count = res;
        var allElems = document.getElementsByTagName('span');
    for (var i = 0; i < allElems.length; i++) {
        var thisElem = allElems[i];
        if (thisElem.className && thisElem.className == 'DeviceCount') {
            thisElem.innerHTML = Count;
        }
    }
    });

}

function ChangeAllDeviceCountersContact(Count) {
    /*
    var allElems = document.getElementsByTagName('span');
    for (var i = 0; i < allElems.length; i++) {
        var thisElem = allElems[i];
        if (thisElem.className && thisElem.className == 'DeviceCountContact') {
            thisElem.innerHTML = Count;
        }
    }
    */
}

function ShowDevDetails(DevID) {

    var divObj = document.getElementById("Device" + DevID);
    divObj.style.display = (divObj.style.display != "block")
            ? "block" : "none";

    DeviceSelected = DevID;

    if (divObj.style.display == "block" && divObj.innerHTML.length == 0) {
        ShowHardware(DevID);
    }
}

function ShowHardware(DevID) {

    DeviceSelected = DevID;
    var divObj = document.getElementById("Device" + DevID);
    switchDeviceTab(DevID, "Hardware");

    if (divObj.innerHTML.length == 0) {

        divObj.innerHTML = '<img src="images/ajax-loader.gif" width="31" height="31" alt="Loading..." title="Loading.." />';

        makeHttpRequest("index.php?module=device&event=getHardwareXML&id=" + DevID,
                "buildDeviceHardware", true);
    }
}

function ShowTickets(DevID) {

    DeviceSelected = DevID;
    var divObj = document.getElementById("DeviceTicket" + DevID);
    switchDeviceTab(DevID, "Ticket");

    //if (divObj.innerHTML.length == 0) {
    {

        divObj.innerHTML = '<img src="images/ajax-loader.gif" width="31" height="31" alt="Loading..." title="Loading.." />';

        //makeHttpRequest("index.php?module=device&event=getDeviceTickets&id=" + DevID,"buildDeviceTickets", false);
        $("#DeviceTicket"+DevID).load("index.php?module=device&event=getDeviceTickets&id=" + DevID);
    }
}


function ShowSoftware(DevID) {

    DeviceSelected = DevID;
    var divObj = document.getElementById("DeviceSoftware" + DevID);
    switchDeviceTab(DevID, "Software");

    if (divObj.innerHTML.length == 0) {

        divObj.innerHTML = '<img src="images/ajax-loader.gif" width="31" height="31" alt="Loading..." title="Loading.." />';

        makeHttpRequest("index.php?module=device&event=getSoftwareXML&id=" + DevID,
                "buildDeviceSoftware", true);
    }
}

function ShowCommercialDevData(DevID) {

    DeviceSelected = DevID;
    var divObj = document.getElementById("DeviceCommercialDevData" + DevID);
    switchDeviceTab(DevID, "CommercialDevData");

    if (divObj.innerHTML.length == 0) {

        divObj.innerHTML = '<img src="images/ajax-loader.gif" width="31" height="31" alt="Loading..." title="Loading.." />';

        makeHttpRequest("index.php?module=device&event=getCommercialDevData&id=" + DevID,
                "buildDeviceCommercialDevData", true);
    }
}

function ShowUserDefInfos(DevID) {

    DeviceSelected = DevID;
    var divObj = document.getElementById("DeviceUserDefInfos" + DevID);
    switchDeviceTab(DevID, "UserDefInfos");

    if (divObj.innerHTML.length == 0) {

        divObj.innerHTML = '<img src="images/ajax-loader.gif" width="31" height="31" alt="Loading..." title="Loading.." />';

        makeHttpRequest("index.php?module=device&event=getUserDefInfosXML&id=" + DevID,
                "buildDeviceUserDefInfos", true);
    }
}

function buildDeviceHardware(xmldoc) {

    var divObj = document.getElementById("Device" + DeviceSelected);
    var HTMLOutput = "";
    var Device = xmldoc.getElementsByTagName("Device");
    var TABOutput = "";
    var DIVOutput = "";

    // Device
    if (Device.length > 0 && Device[0].childNodes.length > 0) {

        TABOutput += '<li><a href="JavaScript:void(0);" class="active" id="HardwareTab' + DeviceSelected + '" onclick="ShowHardware(' + DeviceSelected + ');"><span>' + HWLabel + '</span></a></li>';
        HTMLOutput += "<table id=\"Hardware" + DeviceSelected + "\" class=\"table table-striped\">";
        HTMLOutput += "<thead><tr><th>" + DescrLabel + "&nbsp;</th><th>" + ValueLabel + "&nbsp;</th></tr></thead><tbody>";

        for (i = 0; i < Device[0].childNodes.length; i++) {
            if ((Device[0].childNodes[i].nodeType == 1)) {

                tmpNode = Device[0].getElementsByTagName(Device[0].childNodes[i].nodeName)[0];
                tmpVal = (tmpNode.childNodes.length > 0)
                        ? tmpNode.firstChild.nodeValue : "";

                if (Device[0].childNodes[i].nodeName == "swproduct") {

                    if (tmpVal > 0) {
                        TABOutput += '<li><a href="JavaScript:void(0);" id="SoftwareTab' + DeviceSelected + '" onclick="ShowSoftware(' + DeviceSelected + ');"><span>' + SWLabel + '</span></a></li>';
                        DIVOutput += '<div id="DeviceSoftware' + DeviceSelected + '" class=\"SoftwareCatalog\" style=\"display:none;\"></div>';
                    }
                    continue;
                }

                if (Device[0].childNodes[i].nodeName == "userdefinfos") {
                    if (tmpVal > 0) {
                        TABOutput += '<li><a href="JavaScript:void(0);" id="UserDefInfosTab' + DeviceSelected + '" onclick="ShowUserDefInfos(' + DeviceSelected + ');"><span>' + UserDefLabel + '</span></a></li>';
                        DIVOutput += '<div id="DeviceUserDefInfos' + DeviceSelected + '" style=\"display:none;\"></div>';
                    }
                    continue;
                }

                if (Device[0].childNodes[i].nodeName == "commercialdevdata") {
                    if (tmpVal > 0) {
                        TABOutput += '<li><a href="JavaScript:void(0);" id="CommercialDevDataTab' + DeviceSelected + '" onclick="ShowCommercialDevData(' + DeviceSelected + ');"><span>' + CommercialLabel + '</span></a></li>';
                        DIVOutput += '<div id="DeviceCommercialDevData' + DeviceSelected + '" style=\"display:none;\"></div>';
                    }
                    continue;
                }

                //HTMLOutput += "<tr class=\"row0\">";
                if (i % 2 == 0) {
                    HTMLOutput += "<tr class=\"even\">";
                } else {
                    HTMLOutput += "<tr class=\"odd\">";
                }
                HTMLOutput += "<td>" + Device[0].childNodes[i].nodeName + "</td>";
                HTMLOutput += "<td style=\"width:100%;\">" + tmpVal + "&nbsp;</td>";
                HTMLOutput += "</tr>";
            }
        }
        HTMLOutput += "</tbody></table>";
        TABOutput += '<li><a href="JavaScript:void(0);" class="active" id="TicketTab' + DeviceSelected + '" onclick="ShowTickets(' + DeviceSelected + ');"><span>' + TicketLabel + '</span></a></li>';
        DIVOutput += '<div id="DeviceTicket' + DeviceSelected + '" style=\"display:none;\">AA</div>';
    }

    HTMLOutput = '<div class="DeviceTabs" id="DeviceTabs' + DeviceSelected + '"><ul>' + TABOutput +
            "</ul><br style=\"clear:both;\"></div>" + HTMLOutput +
            DIVOutput;

    divObj.innerHTML = HTMLOutput;
}

function buildDeviceTickets(xmldoc)
{
    var divObj = document.getElementById("DeviceTicket" + DeviceSelected);
    divObj.innerHTML = xmldoc;
    $('.footable_DeviceTickets').footable();
}

function buildDeviceSoftware(xmldoc) {

    divObj = document.getElementById("DeviceSoftware" + DeviceSelected);

    var HTMLOutput = "";
    var Software = xmldoc.getElementsByTagName("apps");

    if (Software.length > 0) {

        HeaderOutput = "<tr>";
        HTMLOutputSW = "";
        var tmpDescr = '';

        for (i = 0; i < Software.length; i++) {

            evenodd = i % 2;

            HTMLOutputSW += "<tr class=\"row" + evenodd + "\">";


            for (j = 0; j < Software[i].childNodes.length; j++) {

                if ((Software[i].childNodes[j].nodeType == 1)) {

                    tmpNode = Software[i].getElementsByTagName(Software[i].childNodes[j].nodeName)[0];
                    tmpVal = (tmpNode.childNodes.length > 0)
                            ? tmpNode.firstChild.nodeValue
                            : "";

                    HTMLOutputSW += "<td>" + tmpVal + "&nbsp;</td>";

                    if (i == 0) {
                        if (undefined != SoftwareDev[Software[i].childNodes[j].nodeName]) {
                            tmpDescr = SoftwareDev[Software[i].childNodes[j].nodeName];
                        } else {
                            tmpDescr = Software[i].childNodes[j].nodeName;
                        }
                        if (tmpDescr == 'Produktname') {
                            HeaderOutput += "<th data-toggle=\"true\">" + tmpDescr + "</th>";
                        } else {
                            HeaderOutput += "<th data-hide=\"phone,tablet\">" + tmpDescr + "</th>";
                        }

                    }
                }
            }
            HTMLOutputSW += "</tr>";
        }

        HTMLOutput += "<table border=\"0\" cellspacing=\"0\" class=\"footable_DeviceSW\">";
        HTMLOutput += "<thead>" + HeaderOutput + "</tr></thead>";
        HTMLOutput += "<tbody>" + HTMLOutputSW + "</tbody></table>";
    }
    divObj.innerHTML = HTMLOutput;
    $('.footable_DeviceSW').footable();
}

function buildDeviceCommercialDevData(xmldoc) {

    divObj = document.getElementById("DeviceCommercialDevData" + DeviceSelected);

    var HTMLOutput = "";
    var Commercial = xmldoc.getElementsByTagName("CommercialDevData");
    var j = 0;

    // Device
    if (Commercial.length > 0) {

        HTMLOutput += "<table class=\"table table-striped\">";
        HTMLOutput += "<thead><tr><th>" + DescrLabel + "&nbsp;</th>" +
                "<th>" + ValueLabel + "&nbsp;</th></tr></thead><tbody>";

        for (i = 0; i < Commercial[0].childNodes.length; i++) {

            if ((Commercial[0].childNodes[i].nodeType == 1)) {
                tmpNode = Commercial[0].getElementsByTagName(
                        Commercial[0].childNodes[i].nodeName)[0];
                tmpVal = (tmpNode.childNodes.length > 0)
                        ? tmpNode.firstChild.nodeValue
                        : "";
                evenodd = j % 2;
                HTMLOutput += "<tr class=\"row" + evenodd + "\">";
                HTMLOutput += "<td>" +
                        CommercialDev[Commercial[0].childNodes[i].nodeName] +
                        "&nbsp;</td>";
                HTMLOutput += "<td style=\"width:100%;\">" + tmpVal + "&nbsp;</td>";
                HTMLOutput += "</tr>";
                j++;
            }
        }

        HTMLOutput += "</tbody></table>";
    }
    divObj.innerHTML = HTMLOutput;
}

function buildDeviceUserDefInfos(xmldoc) {

    divObj = document.getElementById("DeviceUserDefInfos" + DeviceSelected);

    var HTMLOutput = "";
    var UserDef = xmldoc.getElementsByTagName("UserDefInfos");

    if (UserDef.length > 0 && UserDef[0].childNodes.length > 0) {

        var j = 0;
        var evenodd = 0;

        HTMLOutput += "<table  class=\"table table-striped\">";
        HTMLOutput += "<thead><tr><th>" + DescrLabel + "&nbsp;</th><th>" + ValueLabel + "&nbsp;</th></tr></thead><tbody>";

        for (i = 0; i < UserDef[0].childNodes.length; i++) {
            if ((UserDef[0].childNodes[i].nodeType == 1)) {

                evenodd = j % 2;
                tmpNode = UserDef[0].getElementsByTagName(UserDef[0].childNodes[i].nodeName)[0];
                tmpVal = (tmpNode.childNodes.length > 0)
                        ? tmpNode.firstChild.nodeValue
                        : "";

                HTMLOutput += "<tr class=\"row" + evenodd + "\">";
                HTMLOutput += "<td>" + UserDef[0].childNodes[i].nodeName + "</td>";
                HTMLOutput += "<td style=\"width:100%;\">" + tmpVal + "&nbsp;</td>";
                HTMLOutput += "</tr>";
                j++;
            }
        }
        HTMLOutput += "</tbody></table>";
    }
    divObj.innerHTML = HTMLOutput;
}

function switchDeviceTab(devid, tab) {

    var divObj = document.getElementById("DeviceTabs" + devid);

    if (divObj) {
        var tabs = divObj.getElementsByTagName("a");
        for (i = 0; i < tabs.length; i++) {
            tabs[i].className = "";
        }

        document.getElementById(tab + "Tab" + devid).className = 'active';

        if (obj = document.getElementById("Hardware" + devid)) {
            obj.style.display = "none";
        }

        if (obj = document.getElementById("DeviceTicket" + devid)) {
            obj.style.display = "none";
        }

        if (obj = document.getElementById("DeviceSoftware" + devid)) {
            obj.style.display = "none";
        }

        if (obj = document.getElementById("DeviceUserDefInfos" + devid)) {
            obj.style.display = "none";
        }

        if (obj = document.getElementById("DeviceCommercialDevData" + devid)) {
            obj.style.display = "none";
        }

        tab = (tab !== "Hardware")
                ? "Device" + tab + devid : tab + devid;

        if (obj = document.getElementById(tab)) {
            obj.style.display = "block";
        }
    }
}

function activateDataTable(){
    $(".softwaredevicetable, .deviceticketstable").DataTable().destroy();

    $(".softwaredevicetable, .deviceticketstable").DataTable({
        "paging":   true,
            "oLanguage": {
                "sLengthMenu": "Zeige _MENU_ Eintr&auml;ge",
                "sZeroRecords": "Keine Eintr&auml;ge gefunden",
                "sInfo": "Eintrag _START_ bis _END_ (von _TOTAL_)",
                "sInfoEmpty": " ",
                "sInfoFiltered": " - gefiltert aus _MAX_ Eintr&auml;gen",
                "sSearch": "Filter",
                "oPaginate": {
                    "sFirst": "&lt;&lt;",
                    "sLast": "&gt;&gt;",
                    "sNext": "&gt;",
                    "sPrevious": "&lt;"
                }
            }
//            ,
//        "scrollY":        "300px",
//        "scrollCollapse": true

    });
}

function getDeviceStructure() {
        $("#DeviceStructureResult").fancytree({
            source: {
              url: "index.php?module=structure&event=JSONStructureTree&id=0&dev=1"
            },
            checkbox: false,
            autoActivate: true, // Automatically activate a node when it is focused (using keys).
            selectMode: 1, // 1:single, 2:multi, 3:multi-hier
            activeVisible: true,
            activate: function(event, data){
            // A node was activated: display its title:
            var node = data.node;
            setDeviceStructure(node.key, 0, node.title);
            //$("#echoActive").text(node.title);
            //alert(node.title);
            },
            lazyLoad: function(event, data){
                var node = data.node;
                // Load child nodes via ajax GET /getTreeData?mode=children&parent=1234
                data.result = {
                    url: node.data.src,
                  //url: "index.php?module=category&event=json&type=ticket",
                  data: {mode: "children", parent: node.key},
                  cache: false
                };
            }
        }).show();
    }

function copyElementToClipboard(element) {
    $("#" + element).show();
    window.getSelection().removeAllRanges();
    let range = document.createRange();
    range.selectNode(typeof element === 'string' ? document.getElementById(element) : element);
    window.getSelection().addRange(range);
    document.execCommand('copy');
    window.getSelection().removeAllRanges();
    $("#" + element).hide();
    noty({
        text: "Assetdaten wurden in Clipboard kopiert",
        type: 'success',
        timeout: notifyTimeout
    });
}

</script>
