// Groups List Display Setting
var _devicetype;
var timer, timertx;
var videoswitchingNum = 0, videoswitchingNumtx = 0;
var eventnum;

current_page = "rs232";

$('body').on('click', function () {
    switch (eventnum) {
        case 'Group':
            if (videoswitchingNum == 1) {
                eventnum = '';
                videoswitchingNum = 0;
                console.log('display data1');
                clearInterval(timer);
            }
            if (videoswitchingNumtx == 1) {
                eventnum = '';
                videoswitchingNumtx = 0;
                console.log('display data1');
                clearInterval(timertx);
            }
            break;
    }
    if (checkmouseover!=1) {
        setTimeout(function(){
            $('.listCont li').each(function(){
                if ($(this).hasClass('listContListLiHover')) {
                    if (document.getElementById('CommonList')) {
                        document.getElementById('CommonList').parentNode.removeChild(document.getElementById('CommonList'));
                        $('.listContList:eq(0) li').removeClass('listContListLiHover');
                        $('.listContList:eq(1) li').removeClass('listContListLiHover');
                        //$('.listHeadRightCont li').removeClass('listContListLiHover');
                    }
                    if (document.getElementById('GroupSettingBox')) {
                        document.getElementById('GroupSettingBox').parentNode.removeChild(document.getElementById('GroupSettingBox'));
                        //$('.listContList:eq(0) li').removeClass('listContListLiHover');
                    }
                }
                
            });
        },150);
            
    }

});
$('body').on('click',function(){
    setTimeout(function(){
        if (document.getElementById('CommonList')) {
            document.getElementById('CommonList').parentNode.removeChild(document.getElementById('CommonList'));
            $('.listContList:eq(0) li').removeClass('listContListLiHover');
            $('.listContList:eq(1) li').removeClass('listContListLiHover');
            $('.listHeadRightCont li').removeClass('listContListLiHover');
        }
        if (document.getElementById('GroupSettingBox')) {
            document.getElementById('GroupSettingBox').parentNode.removeChild(document.getElementById('GroupSettingBox'));
        }
    },150);
        
});

addListenEvent();
addDisplayListenEvent(0);
addDisplayListenEvent(1);

// 载入list弹出事件
function addDisplayListenEvent(num) {
    if (num == 0) {// decoder list event
        $('.listContList:eq(0) li').each(function (e) {
            $(this).on('mousedown',function(){
                if (!$(this).hasClass('decodeencodeexist')&&$(this).html()=="<div class=\"DragToDropBtn\"></div>") {
                    return;
                }
                $('.listContList:eq(0) li').each(function (a) {
                    $('.listContList:eq(0) li:eq('+a+') div:eq(0)').removeClass('rs232DisplayStream');
                });
                $('.listContList:eq(1) li').each(function (a) {
                    $('.listContList:eq(1) li:eq('+a+') div:eq(0)').removeClass('rs232DisplayStream');
                });
                if ((e==0)&&$('#decodersGroup li:eq(0)').hasClass('listHover')) return;
                else if(e==1){
                    var _connectionIP = $('.connectionIP').val();
                    $('#box2 div:eq(0)').addClass('rs232DisplayStream');
                    if ($('#encodersGroup li:eq(0)').hasClass('listHover')){
                        var _arr = _data.Rs232_En_De_arr.split(',');
                        for (var i = 0; i < _arr.length-1; i++) {
                          if (Decode_Rs232_DataArr[i]!=''&&typeof(Decode_Rs232_DataArr[i])!='undefined') {
                            if (Decode_Rs232_DataArr[i][5]==_connectionIP) {
                                $('.listCont:eq(1) .listContList ul li:eq(' + (i) + ') div:eq(0)').addClass('rs232DisplayStream');
                            } 
                          }
                        } 
                    }
                    else {
                        for (var i = 0; i < EncodeGroupDataListArr.length; i++) {
                            var _EncodeGroupDataListArr = EncodeGroupDataListArr[i].split(':');
                            for (var j = 0; j < _EncodeArr.length-1; j++) {
                                if (Decode_Rs232_DataArr[j][1]==_EncodeGroupDataListArr[0]) {
                                    if (Decode_Rs232_DataArr[j][5]==_connectionIP) {
                                        $('.listCont:eq(1) .listContList ul li:eq(' + i + ') div:eq(0)').addClass('rs232DisplayStream');
                                    }
                                }
                            }
                        }
                    }
                    return;
                }
                
                $('.listContList:eq(0) li').removeClass('listContListLiHover');
                $('.listContList:eq(1) li').removeClass('listContListLiHover');
                $(this).addClass('listContListLiHover');
                if (e!=0&&e!=1&&$('#decodersGroup li:eq(0)').hasClass('listHover')) {
                    $('.listContList:eq(0) li:eq('+e+') div:eq(0)').addClass('rs232DisplayStream');
                    CheckDeviceRouting(Decode_Rs232_DataArr[e-2][2],'rs232Receiver');
                }
                else {
                        for (var i = 0; i < Decode_Rs232_DataArr.length; i++) {
                            // for (var j = 0; j < EncodeGroupDataListArr.length; j++) {
                                var _EncodeGroupDataListArr = DecodeGroupDataListArr[e].split(':');
                                if (Decode_Rs232_DataArr[i][1]==_EncodeGroupDataListArr[0]) {
                                    CheckDeviceRouting(Decode_Rs232_DataArr[i][2],'rs232Receiver');
                                    $('.listContList:eq(0) li:eq('+e+') div:eq(0)').addClass('rs232DisplayStream');
                                }
                            // }
                        }
                        
                    }
            }); 
            $(this).on('mouseover',function(){
                if (!$(this).hasClass('decodeencodeexist')&&$(this).html()=="<div class=\"DragToDropBtn\"></div>") {
                    return;
                }
                if ((e==0||e==1)&&$('#decodersGroup li:eq(0)').hasClass('listHover')) return;
                checkmouseover = 1;
                checkMouseWherePosition = 'rs232decode';
            });
            $(this).on('mouseleave',function(){
                checkmouseover = 2;
                checkMouseWherePosition = '';
            }); 
        });
    }
    else if (num == 1) {// encoder list event
        $('.listContList:eq(1) li').each(function (e) {
            $(this).on('mousedown',function(){
                if (!$(this).hasClass('decodeencodeexist')&&$(this).html()=="<div class=\"DragToDropBtn\"></div>") {
                    return;
                }
                // if (e==0||e==1) return;
                $('.listContList:eq(0) li').each(function (a) {
                    $('.listContList:eq(0) li:eq('+a+') div:eq(0)').removeClass('rs232DisplayStream');
                });
                $('.listContList:eq(1) li').each(function (a) {
                    $('.listContList:eq(1) li:eq('+a+') div:eq(0)').removeClass('rs232DisplayStream');
                });
                $('.listContList:eq(0) li').removeClass('listContListLiHover');
                $('.listContList:eq(1) li').removeClass('listContListLiHover');
                $(this).addClass('listContListLiHover');
                if ($('#encodersGroup li:eq(0)').hasClass('listHover')) {
                    $('.listContList:eq(1) li:eq('+e+') div:eq(0)').addClass('rs232DisplayStream');
                    CheckDeviceRouting(Encode_Rs232_DataArr[e][5],'rs232Sender');
                }
                else {
                    for (var i = 0; i < Encode_Rs232_DataArr.length; i++) {
                            // for (var j = 0; j < EncodeGroupDataListArr.length; j++) {
                        var _EncodeGroupDataListArr = EncodeGroupDataListArr[e].split(':');
                        if (Encode_Rs232_DataArr[i][1]==_EncodeGroupDataListArr[0]) {
                            CheckDeviceRouting(Encode_Rs232_DataArr[i][5],'rs232Sender');
                        }
                            // }
                    }
                }
            }); 
            $(this).on('mouseover',function(){
                if (!$(this).hasClass('decodeencodeexist')&&$(this).html()=="<div class=\"DragToDropBtn\"></div>") {
                    return;
                }
                checkmouseover = 1;
                checkMouseWherePosition = 'rs232encode';
            });
            $(this).on('mouseleave',function(){
                checkmouseover = 2;
                checkMouseWherePosition = '';
            });
        });
    }
}
// 载入Group分组弹出BOX事件
function addListenEvent() {
    $('#decodersGroup li').each(function (e) {
        $(this).on('mousedown', function (a) {
            _GroupNumber = e;           
        });
        $(this).on('click', function () {
            $('#decodersGroup li').removeClass();
            $(this).addClass('listHover');
            ReadDataFromFile('PositionInfoFromFile=9');
            ReadDataFromFile('PositionInfoFromFile=10');
            if (document.getElementById('GroupSettingBox')) {
                document.getElementById('GroupSettingBox').parentNode.removeChild(document.getElementById('GroupSettingBox'));
            }
            videoswitchingNum = 0;
            //console.log('display data');
            clearInterval(timer);
            var titleinfoDecodeArr = stringToArray(titleinfoDecode,1);
            if (e == 0) {
                $('.listContList:eq(0) ul').html('');
                var _arr = _data.Rs232_De_En_arr.split(',');
                var _li_head = "<li id='box1' ondragover='exp1(event)' ondrop='exp(event)'>\
                                    <span class='macaddress'>All Receivers</span>\
                                    <span>&nbsp;</span>\
                                    <span>All_Rx</span>\
                                    <span></span>\
                                    <span></span>\
                                    <span></span>\
                                    <span></span>\
                                    <span></span>\
                                    <span></span>\
                                    <div class='rs232AllRx'></div>\
				                    <div class='DragToDropBtn'></div>\
                                </li>"+
                                "<li id='box2' ondragover='exp1(event)' ondrop='exp(event)'>\
                                    <span class='macaddress'>All Server</span>\
                                    <span>&nbsp;</span>\
                                    <span>API</span>\
                                    <span></span>\
                                    <span></span>\
                                    <span></span>\
                                    <span></span>\
                                    <span></span>\
                                    <span></span>\
                                    <div class='rs232DisplayType'></div>\
                                    <div class='DragToDropBtn'></div>\
                                </li>";
                $('.listContList:eq(0) ul').append(_li_head);
                for (var i = 0; i < _arr.length - 1; i++) {
                    if (_arr[i]!='') {
                        var _list = "<li id='DeviceDecodePositionID"+(i+2)+"' class='decodeencodeexist' ondragover='exp1(event)' ondrop='deviceToChangePosition(event)' draggable='true' ondragstart='DecodeExpstart(event)'>\
                                        <span class='macaddress' "+(titleinfoDecodeArr[0]=='0'?"style='display:none'":'') + ">" + Decode_Rs232_DataArr[i][0] + "</span>\
                                        <span class='macaddress' "+(titleinfoDecodeArr[1]=='0'?"style='display:none'":'') + ">" + Decode_Rs232_DataArr[i][1] + "</span>\
                                        <span class='macaddress' "+(titleinfoDecodeArr[2]=='0'?"style='display:none'":'') + ">" + Decode_Rs232_DataArr[i][2] + "</span>\
                                        <span class='macaddress' "+(titleinfoDecodeArr[3]=='0'?"style='display:none'":'') + ">V" + Decode_Rs232_DataArr[i][3] + "</span>\
                                        <span class='macaddress'>" + (Decode_Rs232_DataArr[i][4] == true ? 'Point-to-Point' : '') + "</span>\
                                        <span class='macaddress'></span>\
                                        <span class='macaddress'></span>\
                                        <span class='macaddress'></span>\
                                        <span class='macaddress'></span>\
                                        <div class='rs232DisplayType'></div>\
                                        <div class='DragToDropBtn'></div>\
                                    </li>";
                        $('.listContList:eq(0) ul').append(_list);
                        var _arrDecodePinPosition = decodePinPosition.split(',');
                        for (var j = 0; j < _arrDecodePinPosition.length; j++) {
                            var _arrTmp = _arrDecodePinPosition[j].split(':');
                            if (_arrTmp[0]==Decode_Rs232_DataArr[i][1]) {
                                $('#DeviceDecodePositionID'+(i+2)).append("<div class='PositionPIN'></div>");
                            }
                        }
                    } 
                    else{
                        $('.listCont:eq(0) .listContList ul').append("<li id='DeviceDecodePositionID"+(i+2)+"' ondragover='exp1(event)' ondrop='deviceToChangePosition(event)'><div class='DragToDropBtn'></div></li>");
                    }                   
                }
                if ($('.listCont:eq(0) .listContList ul li').length<12) {
                    for (var i = $('.listCont:eq(0) .listContList ul li').length; i <12; i++) {
                        if($('#decodersGroup li:eq(0)').hasClass('listHover')){
                            $('.listCont:eq(0) .listContList ul').append("<li id='DeviceDecodePositionID"+i+"' ondragover='exp1(event)' ondrop='deviceToChangePosition(event)'><div class='DragToDropBtn'></div></li>");
                            Rs232IrReceiverDataDetaileDataArr[i-2] = '';
                            Decode_Rs232_DataArr[i-2] = '';
                        }
                    }
                }
                addDisplayListenEvent(0);
                return;
            } else {
                var data = 'type=6&id=' + $('#decodersGroup li:eq(' + e + ') span').html();
                //console.log(data);
                PageAddGroup(data);
                setTimeout(function(){
                    data = ajaxDataStream;

                    if (data == 'null') {
                        // console.log(data);
                        $('.listContList:eq(0) ul').html('');
                        return;
                    }

                    DecodeGroupDataListArr = data.split(',');
                    //console.log(dataArr);
                    $('.listContList:eq(0) ul').html('');               

                    var _arr = _data.Rs232_De_En_arr.split(',');
                    var _num;
                    $('.listContList:eq(0) ul').append(_li_head);
                    if ($('.listCont:eq(0) .listContList ul li').length<12) {
                        for (var i = $('.listCont:eq(0) .listContList ul li').length; i <12; i++) {                     
                            $('.listCont:eq(0) .listContList ul').append("<li id='DeviceDecodePositionID"+i+"' ondragover='exp1(event)' ondrop='deviceToChangePosition(event)'><div class='DragToDropBtn'></div></li>");
                                
                        }
                    }

                    for (var i = 0; i < DecodeGroupDataListArr.length; i++) {
                        (function(ii){
                            if (DecodeGroupDataListArr[ii]!='') {
                                var _DecodeGroupDataListArrID = DecodeGroupDataListArr[ii].split(':');
                                var _checkOnLine=0;
                                for (var j = 0; j < _arr.length-1; j++) {
                                    (function(jj){                                  
                                        if (_DecodeGroupDataListArrID[0]==_arr[jj]) {
                                            _num = jj;  
                                            _checkOnLine=1;
                                        }
                                    })(j);                              
                                }
                                if (_checkOnLine==0) {
                                    var _list = "<span class='macaddress' "+(titleinfoDecodeArr[0]=='0'?"style='display:none'":'') + ">&nbsp;</span>\
                                                    <span class='macaddress' "+(titleinfoDecodeArr[1]=='0'?"style='display:none'":'') + ">"+_DecodeGroupDataListArrID[0]+"</span>\
                                                    <span class='macaddress' "+(titleinfoDecodeArr[2]=='0'?"style='display:none'":'') + ">&nbsp;</span>\
                                                    <span class='macaddress' "+(titleinfoDecodeArr[3]=='0'?"style='display:none'":'') + ">&nbsp;</span>\
                                                    <span class='macaddress' "+(titleinfoDecodeArr[4]=='0'?"style='display:none'":'') + ">&nbsp;</span>\
                                                    <span class='macaddress' "+(titleinfoDecodeArr[5]=='0'?"style='display:none'":'') + ">&nbsp;</span>\
                                                    <span class='macaddress' "+(titleinfoDecodeArr[6]=='0'?"style='display:none'":'') + ">&nbsp;</span>\
                                                    <span class='macaddress' "+(titleinfoDecodeArr[7]=='0'?"style='display:none'":'') + ">&nbsp;</span>\
                                                    <span class='macaddress' "+(titleinfoDecodeArr[8]=='0'?"style='display:none'":'') + ">&nbsp;</span>\
                                                    <div class='rs232DisplayType'></div>\
                                                    <div class='DragToDropBtn'></div>";
                                    $('#DeviceDecodePositionID'+ii).html(_list);
                                    // $('#DeviceDecodePositionID'+ii).removeClass('decodeencodeexist');
                                    // $('#DeviceDecodePositionID'+ii).addClass('deviceDisconnectedType');
                                    $('#DeviceDecodePositionID'+ii).addClass('decodeencodeexist');
                                    $('#DeviceDecodePositionID'+ii).attr('draggable',true);
                                    $('#DeviceDecodePositionID'+ii).attr('ondragstart','DecodeExpstart(event)');
                                    var _DecodeGroupDataListArrID = DecodeGroupDataListArr[ii].split(':');
                                    if (parseInt(_DecodeGroupDataListArrID[1])>=0) {
                                        $('#DeviceDecodePositionID'+ii).append("<div class='PositionPIN'></div>");
                                    }
                                }
                                else {
                                    if (typeof(Decode_Rs232_DataArr[_num])=='undefined') {
                                        Decode_Rs232_DataArr[_num]=[];
                                    }
                                    //<li id='DeviceDecodePositionID"+(ii)+"' class='decodeencodeexist' ondragover='exp1(event)' ondrop='deviceToChangePosition(event)' draggable='true' ondragstart='DecodeExpstart(event)'>
                                    var _list = "<span class='macaddress' "+(titleinfoDecodeArr[0]=='0'?"style='display:none'":'') + ">"+Decode_Rs232_DataArr[_num][0]+"</span>\
                                                    <span class='macaddress' "+(titleinfoDecodeArr[1]=='0'?"style='display:none'":'') + ">"+Decode_Rs232_DataArr[_num][1]+"</span>\
                                                    <span class='macaddress' "+(titleinfoDecodeArr[2]=='0'?"style='display:none'":'') + ">"+Decode_Rs232_DataArr[_num][2]+"</span>\
                                                    <span class='macaddress' "+(titleinfoDecodeArr[3]=='0'?"style='display:none'":'') + ">V"+Decode_Rs232_DataArr[_num][3]+"</span>\
                                                    <span class='macaddress' "+(titleinfoDecodeArr[4]=='0'?"style='display:none'":'') + "></span>\
                                                    <span class='macaddress' "+(titleinfoDecodeArr[5]=='0'?"style='display:none'":'') + "></span>\
                                                    <span class='macaddress' "+(titleinfoDecodeArr[6]=='0'?"style='display:none'":'') + "></span>\
                                                    <span class='macaddress' "+(titleinfoDecodeArr[7]=='0'?"style='display:none'":'') + "></span>\
                                                    <span class='macaddress' "+(titleinfoDecodeArr[8]=='0'?"style='display:none'":'') + "></span>\
                                                    <div class='rs232DisplayType'></div>\
                                                    <div class='DragToDropBtn'></div>";
                                    $('#DeviceDecodePositionID'+ii).html(_list);
                                    $('#DeviceDecodePositionID'+ii).addClass('decodeencodeexist');
                                    // $('#DeviceDecodePositionID'+ii).removeClass('deviceDisconnectedType');
                                    $('#DeviceDecodePositionID'+ii).attr('draggable',true);
                                    $('#DeviceDecodePositionID'+ii).attr('ondragstart','DecodeExpstart(event)');
                                    var _DecodeGroupDataListArrID = DecodeGroupDataListArr[ii].split(':');
                                    if (parseInt(_DecodeGroupDataListArrID[1])>=0) {
                                        $('#DeviceDecodePositionID'+ii).append("<div class='PositionPIN'></div>");
                                    }
                                    if (Decode_Rs232_DataArr[ii][7]=='0'&&Decode_Rs232_DataArr[ii][8]=='0') {
                                        $('.listCont:eq(0) .listContList ul li:eq(' + ii + ') div:eq(0)').removeClass('rs232DisplayType');
                                        $('.listCont:eq(0) .listContList ul li:eq(' + ii + ') div:eq(0)').removeClass('rs232DisplayType');
                                    }else{
                                        $('.listCont:eq(0) .listContList ul li:eq(' + ii + ') div:eq(0)').addClass('rs232DisplayType');
                                    }
                                }                               
                            }
                        })(i);                                              
                    }
                    addDisplayListenEvent(0);
                    CheckGroupPosition(0,DecodeGroupDataListArr);
                },100);
                    
            }

        });
        $(this).on('mouseover',function(){
            if (e==0) return;
            checkMouseWherePosition = 'rs232decodeGroup';
        });
        $(this).on('mouseleave',function(){
            if (e==0) return;
            checkMouseWherePosition = '';
        });
    });
    $('#encodersGroup li').each(function (e) {
        $(this).on('mousedown', function (a) {
            _GroupNumber = e;           
        });
        $(this).on('click', function () {
            $('#encodersGroup li').removeClass();
            $(this).addClass('listHover');
            ReadDataFromFile('PositionInfoFromFile=9');
            ReadDataFromFile('PositionInfoFromFile=10');
            if (document.getElementById('GroupSettingBox')) {
                document.getElementById('GroupSettingBox').parentNode.removeChild(document.getElementById('GroupSettingBox'));
            }
            videoswitchingNumtx = 0;
            clearInterval(timertx);
            var titleinfoEncodeArr = stringToArray(titleinfoEncode,1);
            if (e == 0) {
                $('.listContList:eq(1) ul').html('');
                var _arr = _data.Rs232_En_De_arr.split(',');

                for (var i = 0; i < _arr.length - 1; i++) {
                    if (_arr[i]!='') {
                        var _list = "<li id='DeviceEncodePositionID"+i+"' class='decodeencodeexist' ondragover='exp1(event)' ondrop='deviceToChangePosition(event)' draggable='true' ondragstart='expstart(event)'>\
                                        <span class='macaddress' "+(titleinfoEncodeArr[0]=='0'?"style='display:none'":'') + ">" + Encode_Rs232_DataArr[i][0] + "</span>\
                                        <span class='macaddress' "+(titleinfoEncodeArr[1]=='0'?"style='display:none'":'') + ">" + Encode_Rs232_DataArr[i][1] + "</span>\
                                        <span class='macaddress' "+(titleinfoEncodeArr[2]=='0'?"style='display:none'":'') + ">" + Encode_Rs232_DataArr[i][2] + "</span>\
                                        <span class='macaddress' "+(titleinfoEncodeArr[3]=='0'?"style='display:none'":'') + ">V" + Encode_Rs232_DataArr[i][3] + "</span>\
                                        <span class='macaddress' "+(titleinfoEncodeArr[4]=='0'?"style='display:none'":'') + ">" + (Encode_Rs232_DataArr[i][4] == true ? 'Point-to-Point' : '') + "</span>\
                                        <span class='macaddress' "+(titleinfoEncodeArr[5]=='0'?"style='display:none'":'') + ">" + Encode_Rs232_DataArr[i][5] + "</span>\
                                        <span class='macaddress' "+(titleinfoEncodeArr[6]=='0'?"style='display:none'":'') + ">" + Encode_Rs232_DataArr[i][6] + "</span>\
                                        <span class='macaddress'></span>\
                                        <span class='macaddress'></span>\
                                        <div class='rs232DisplayType'></div>\
                                        <div class='DragToDropBtn'></div>\
                                    </li>";
                        $('.listContList:eq(1) ul').append(_list);
                        var _arrEncodePinPosition = encodePinPosition.split(',');
                        for (var j = 0; j < _arrEncodePinPosition.length; j++) {
                            var _arrTmp = _arrEncodePinPosition[j].split(':');
                            if (_arrTmp[0]==Encode_Rs232_DataArr[i][1]) {
                                $('#DeviceEncodePositionID'+(i)).append("<div class='PositionPIN'></div>");
                            }
                        }
                    }   
                    else{
                        $('.listCont:eq(1) .listContList ul').append("<li id='DeviceEncodePositionID"+i+"' ondragover='exp1(event)' ondrop='deviceToChangePosition(event)'><div class='DragToDropBtn'></div></li>");
                    }                 
                }
                if ($('.listCont:eq(1) .listContList ul li').length<12) {
                    for (var i = $('.listCont:eq(1) .listContList ul li').length; i <12; i++) {
                        if($('#encodersGroup li:eq(0)').hasClass('listHover')){
                            $('.listCont:eq(1) .listContList ul').append("<li id='DeviceEncodePositionID"+i+"' ondragover='exp1(event)' ondrop='deviceToChangePosition(event)'><div class='DragToDropBtn'></div></li>");
                            Rs232IrSenderDataDetaileDataArr[i] = '';
                            Encode_Rs232_DataArr[i] = '';
                        }                        
                    }
                }
                addDisplayListenEvent(1);
                return;
            } else {
                var data = 'type=6&id=' + $('#encodersGroup li:eq(' + e + ') span').html();
                //console.log(data);
                PageAddGroup(data);
                setTimeout(function(){
                    data = ajaxDataStream;
                if (data == 'null') {
                    $('.listContList:eq(1) ul').html('');
                    return;
                }
                EncodeGroupDataListArr = data.split(',');
                //console.log(dataArr);
                $('.listContList:eq(1) ul').html('');
                var _arr = _data.Rs232_En_De_arr.split(',');
                var _num;
                if ($('.listCont:eq(1) .listContList ul li').length<12) {
                    for (var i = $('.listCont:eq(1) .listContList ul li').length; i <12; i++) {
                        $('.listCont:eq(1) .listContList ul').append("<li id='DeviceEncodePositionID"+i+"' ondragover='exp1(event)' ondrop='deviceToChangePosition(event)'><div class='DragToDropBtn'></div></li>");            
                    }
                }
                for (var i = 0; i < EncodeGroupDataListArr.length; i++) {
                    (function(ii){
                        if (EncodeGroupDataListArr[ii]!='') {
                            var _checkOnLine=0;
                            var _EncodeGroupDataListArrID = EncodeGroupDataListArr[ii].split(':');     
                            for (var j = 0; j < _arr.length-1; j++) {
                                (function(jj){
                                                                 
                                    if (_EncodeGroupDataListArrID[0]==_arr[jj]) {
                                        _num = jj;
                                        _checkOnLine = 1;
                                    }
                                })(j);
                                
                            }
                            if (_checkOnLine==0) {
                                var _list = "<span class='macaddress' "+(titleinfoEncodeArr[0]=='0'?"style='display:none'":'') + ">&nbsp;</span>\
                                                <span class='macaddress' "+(titleinfoEncodeArr[1]=='0'?"style='display:none'":'') + ">"+_EncodeGroupDataListArrID[0]+"</span>\
                                                <span class='macaddress' "+(titleinfoEncodeArr[2]=='0'?"style='display:none'":'') + ">&nbsp;</span>\
                                                <span class='macaddress' "+(titleinfoEncodeArr[3]=='0'?"style='display:none'":'') + ">&nbsp;</span>\
                                                <span class='macaddress' "+(titleinfoEncodeArr[4]=='0'?"style='display:none'":'') + ">&nbsp;</span>\
                                                <span class='macaddress' "+(titleinfoEncodeArr[5]=='0'?"style='display:none'":'') + ">&nbsp;</span>\
                                                <span class='macaddress' "+(titleinfoEncodeArr[6]=='0'?"style='display:none'":'') + ">&nbsp;</span>\
                                                <span class='macaddress' "+(titleinfoEncodeArr[7]=='0'?"style='display:none'":'') + ">&nbsp;</span>\
                                                <span class='macaddress' "+(titleinfoEncodeArr[8]=='0'?"style='display:none'":'') + ">&nbsp;</span>\
                                                <div class='rs232DisplayType'></div>\
                                                <div class='DragToDropBtn'></div>";
                                $('#DeviceEncodePositionID'+ii).html(_list);
                                // $('#DeviceDecodePositionID'+ii).removeClass('decodeencodeexist');
                                // $('#DeviceDecodePositionID'+ii).addClass('deviceDisconnectedType');
                                $('#DeviceEncodePositionID'+ii).addClass('decodeencodeexist');
                                $('#DeviceEncodePositionID'+ii).attr('draggable',true);
                                $('#DeviceEncodePositionID'+ii).attr('ondragstart','expstart(event)');
                                var _EncodeGroupDataListArrID = DecodeGroupDataListArr[ii].split(':');
                                if (parseInt(_EncodeGroupDataListArrID[1])>=0) {
                                    $('#DeviceEncodePositionID'+ii).append("<div class='PositionPIN'></div>");
                                }
                            }
                            else {
                                if (typeof(Encode_Rs232_DataArr[_num])=='undefined') {
                                    Encode_Rs232_DataArr[_num]=[];
                                }
                                //<li class='decodeencodeexist' draggable='true' ondragstart='expstart(event)'>\
                                var _list = "<span class='macaddress' "+(titleinfoEncodeArr[0]=='0'?"style='display:none'":'') + ">"+Encode_Rs232_DataArr[_num][0]+"</span>\
                                                <span class='macaddress' "+(titleinfoEncodeArr[1]=='0'?"style='display:none'":'') + ">"+Encode_Rs232_DataArr[_num][1]+"</span>\
                                                <span class='macaddress' "+(titleinfoEncodeArr[2]=='0'?"style='display:none'":'') + ">"+Encode_Rs232_DataArr[_num][2]+"</span>\
                                                <span class='macaddress' "+(titleinfoEncodeArr[3]=='0'?"style='display:none'":'') + ">V"+Encode_Rs232_DataArr[_num][3]+"</span>\
                                                <span class='macaddress' "+(titleinfoEncodeArr[4]=='0'?"style='display:none'":'') + ">"+Encode_Rs232_DataArr[_num][4]+"</span>\
                                                <span class='macaddress' "+(titleinfoEncodeArr[5]=='0'?"style='display:none'":'') + ">"+Encode_Rs232_DataArr[_num][5]+"</span>\
                                                <span class='macaddress' "+(titleinfoEncodeArr[6]=='0'?"style='display:none'":'') + ">"+Encode_Rs232_DataArr[_num][6]+"</span>\
                                                <span class='macaddress' "+(titleinfoEncodeArr[7]=='0'?"style='display:none'":'') + "></span>\
                                                <div class='rs232DisplayType'></div>\
                                                <div class='DragToDropBtn'></div>";
                                $('#DeviceEncodePositionID'+ii).html(_list);
                                $('#DeviceEncodePositionID'+ii).addClass('decodeencodeexist');
                                $('#DeviceEncodePositionID'+ii).attr('draggable',true);
                                $('#DeviceEncodePositionID'+ii).attr('ondragstart','expstart(event)');
                                var _EncodeGroupDataListArrID = EncodeGroupDataListArr[ii].split(':');
                                if (parseInt(_EncodeGroupDataListArrID[1])>=0) {
                                    $('#DeviceEncodePositionID'+ii).append("<div class='PositionPIN'></div>");
                                }  
                            }                        
                        }
                    })(i);                                              
                }                
                addDisplayListenEvent(1);
                CheckGroupPosition(1,EncodeGroupDataListArr);  
                },100);
                 
            }
        });
        $(this).on('mouseover',function(){
            if (e==0) return;
            checkMouseWherePosition = 'rs232encodeGroup';
        });
        $(this).on('mouseleave',function(){
            if (e==0) return;
            checkMouseWherePosition = '';
        });
    });
}