/**
 * Neuron Frame Work
 * for Golem OEE MES
 * www.neuron.com.pl
 */

'use strict';
lang[80]='Postój planowany';
lang[81]='Konserwacja';
lang[82]='Przezbrajanie';
lang[83]='Ustawianie';
lang[84]='Postój nieplanowany';
lang[85]='Awaria';
lang[86]='Praca';
lang[87]='Czas nieoznaczony';
lang[88]='Przerwa technologiczna';
lang[89]='';
lang[90]='PP';
lang[91]='PM';
lang[92]='PZ';
lang[93]='US';
lang[94]='PN';
lang[95]='AW';
lang[96]='Ep';
lang[97]='Mp';
lang[98]='Nz';
lang[99]='Pt1';
lang[100]='Pt2';
lang[110]='b. miesiąc';
lang[111]='b. zmiana robocza';
lang[112]='b. zlecenie';
lang[113]='zmiana-1';
lang[114]='zmiana-2';
lang[115]='zmiana-3';
lang[116]='Auto(zmiana/zlecenie)';
lang[117]='Podstawa OEE/ST';
lang[118]='';
lang[119]='Andon';
lang[120]='Brak wezwania';
lang[121]='Wezwanie pomocy';
lang[122]='Wezwanie pomocy technicznej';
lang[123]='Wezwanie pomocy logistycznej';
lang[124]='Wezwanie pomocy U1';
lang[125]='Wezwanie pomocy U2';
lang[126]='Odwołać wezwanie Andon ?';
lang[127]='Wezwanie Andon';
lang[128]='';
lang[129]='Maszyny';
lang[130]='Powiadomienia';
lang[131]='Powiadomienia - ostatnie __no__ dni';
lang[132]='Powiadomienia - __no__ dni';
lang[133]='Zdarzenie';
lang[134]='';
lang[135]='Board';
lang[136]='Big board';
lang[137]='Group board';
lang[138]='Group board 2';
lang[139]='Matrix';
lang[140]='Matrix andon';
lang[141]='Single SV';
lang[142]='Single SV BigCount';

lang[150]='1 nadzorca SV zamiast grupy';
lang[151]='nr. grupy';
lang[152]='nr. SV';
lang[153]='po 10 błedach zatrzymaj';
lang[154]='wysłane polecenie reload';
lang[155]='nie ustawiono PINu w ustawieniach stacji';
lang[156]='do zrobienia';
lang[157]='cel';
lang[158]='Numer zlecenia';
lang[159]='Ilość zamówiona';
lang[160]='Audio alarm';
lang[161]='Andon+ st.Awaria';
lang[162]='Zlecenie';
lang[163]='Brak aktywnego zlecenia';
lang[164]='prognoza';
lang[165]='Komentarz';
lang[166]='Szybki komentarz';
lang[167]='F Komentarz';
lang[168]='';
lang[169]='Zmiany ststusu w ciągu ostatnich 72 godzin';
lang[170]='Zmianić status na';
lang[171]='Operator';
lang[172]='Status 72h';
lang[173]='Status rozszerzony';
lang[174]='SV Info';
lang[175]='';
lang[176]='Produkt';
lang[177]='Braki';
lang[178]='Operacje';
lang[179]='Dodać braki ?';
lang[180]='Dodać produkt ?';
lang[181]='';
lang[182]='';
lang[183]='';
lang[184]='Przejmuję maszynę';
lang[185]='Zdaję maszynę';
lang[186]='Naprawiam maszynę';
lang[187]='Koniec naprawy';
lang[188]='Ustawiam maszynę';
lang[189]='Koniec Ustawiania';
lang[190]='Deinstalacja narzędzia';
lang[191]='Nowe zlecenie';
lang[192]='Odwieś zlecenie';
lang[193]='Koniec zlecenia';
lang[194]='Zawieszenie zlecenia';
lang[195]='Punkt kontrolny zlecenia';
lang[196]='Tylko tryb 1 albo 2';
lang[197]='Zawiesić zlecenie ?';
lang[198]='Wznowić zlecenie ?';
lang[199]='Task info';

lang[200]='zaznaczona pozycja';
lang[201]='Zlecenia oczekujące';
lang[202]='Zlecenia zawieszone';
lang[203]='';
lang[204]='Andon U1';
lang[205]='Andon U2';
lang[206]='Komunikaty';
lang[207]='Dodano';
lang[208]='Pareto';
lang[209]='Pareto strat';
lang[210]='Pareto strat i przezbrojeń';
lang[211]='Pareto postojów planowanych';
lang[212]='Komentarz użytkownika';
lang[213]='Zmiana statusu';
lang[214]='Operator przejmuje maszynę';
lang[215]='Pracownik UR rozpoczyna naprawę';
lang[216]='Przezbrajacz przejmuje maszynę';
lang[217]='Operator zdaje maszynę';
lang[218]='Pracownik UR kończy naprawę';
lang[219]='Przezbrajacz zdaje maszynę';

lang[220]='Wznowienie pracy';
lang[221]='po';
lang[222]='Koniec zlecenia';
lang[223]='Punkt kontrolny zlecenia';
lang[224]='Kasowanie liczników (quasi-zlecenie)';
lang[225]='Market';
lang[226]='Osiągnięto ilość alarmową';
lang[227]='Uzupełnianie komponentu';
lang[228]='Utylizacja narzędzia operacyjnego';
lang[229]='Formalne potwierdzenie gotowości do realizacji zlecenia';
lang[230]='Osiągnięto ilość zamówioną';
lang[231]='95% ilości zamówionej';
lang[232]='Zmiana wagi';
lang[233]='Dodano braki';
lang[234]='Dodano braki (korekta)';
lang[235]='Zmiana narzędzia';
lang[236]='Dodano produkt ręcznie';
lang[237]='Ręczna korekta produktu';
lang[238]='';
lang[239]='';
// 212..239 - external
lang[240]='Inspekcje';
lang[241]='Dodaj nową inspekcję';
lang[242]='Wybrana inspekcja';
lang[243]='Opis inspekcji';
lang[244]='Anuluj inspekcje';
lang[245]='Zakończ inspekcje';
lang[246]='Nowa inspekcja';
lang[247]='Produkt, parametry bazowe';
lang[248]='Parametry zlecenia oczekującego';
lang[249]='Moje Maszyny (wszystkie grupy)';
lang[250]='Brak maszyn ze statusem AWARIA';
lang[251]='Brak wezwań pomocy technicznej';
lang[252]='Brak wezwań logistycznych';
lang[253]='dla tej grupy nie zdefiniowano planu lub plan nie ma zdefiniowanej grafiki';
lang[254]='z innej maszyny';
lang[255]='';
lang[256]='Niski';
lang[257]='Średni';
lang[258]='Wysoki';
lang[259]='Nie wiem';
lang[260]='Mechanik';
lang[261]='Elektryk';
lang[262]='Automatyk';

// nr added 173

var state_colors=     ['#D8D8D8','#FF9F66','#B9B9FF','#FFB7FF','#B3CEC4','#FF8080','#B5E61D'];
var state_colors_chart=['#D8D8D8','#FF7525','#0066FF','#F900F9','#008080','#FF0000','#B5E61D','#FFFF00','#FFFFFF','#FFCACA','#EFEFEF'];
var state_ico_code=[ '\uf494', '\uf476','\uf2b9', '\uf267', '\uf496','\uf633', '\uf5cc'];
var state_ico=['mdi-pause-circle-outline','mdi-oil','mdi-elevator','mdi-contrast-circle','mdi-pause-octagon-outline','mdi-wrench','mdi-twitter-retweet'];
var svev_ico=['mdi-traffic-light', 'mdi-account-outline', 'mdi-account-outline','mdi-alarm-multiple','mdi-sync-alert','mdi-tooltip-outline','mdi-bell-outline','mdi-bell','','','','mdi-barcode','mdi-cart-outline','mdi-magnify'];

var andon_colors=['#FFD06F','#FFD06F','red','#42A0FF','#5FE0F3','#E498E0'];
var andon_ico_code='\uf188';
var andon_ico_code_n='\uf186';
var insp_ico_code='\uf401';
var insp_ico='mdi-magnify';

/* lista eventów
 100 - koniec pobierania danych grupy
 118 - zmiana id zleccenia
 119 - zmiana statusu / andon
 120 - klikniecie w przycisk w MATRIX
 130 - klikniecie w listę SV w lewym box'ie


 */


var mes_set={   // wartości ustawione
    theme:0,
    nr_group : 1,
    nr_sv : 1,
    use_sv: false,
    refresh_time:4,
    stop_after:true,
    tv_mode:0,
    oee_base:"S",
    audio_alarm:0,

    sv_change:4,
    pin:true,
    logout:30,
    logout2:300,
    b1:false,
    b2:false,

    lang_change:false
};

var mes_set_pset={ // wartosci domyślne - mozna modyfikowac przed inicjacja frameworku
    theme:'S',
    nr_group : "S",
    nr_sv : "S",
    use_sv: "S",
    refresh_time:'S',
    stop_after:'S',
    tv_mode:0,
    oee_base:"S",
    audio_alarm:0,

    sv_change:4,
    pin:true,
    logout:30,
    logout2:300,
    b1:false,
    b2:false,

    lang_change:'S'
};

var mes_set_pset_df={  // wartosci domyslne ( dla brakujacych kluczy )
    theme:0,
    nr_group : 1,
    nr_sv : 1,
    use_sv: false,
    refresh_time:4,
    stop_after:true,
    tv_mode:0,
    audio_alarm:0,

    oee_base:0,
    sv_change:4,
    pin:true,
    logout:30,
    logout2:300,
    b1:false,
    b2:false,
    lang_change:false
};
var use_url_params=false;

NApp_constructor.prototype.mes_set=mes_set;
NApp_constructor.prototype.mes_set_pset=mes_set_pset;
NApp_constructor.prototype.mes_set_pset_df=mes_set_pset_df;




NApp_constructor.prototype.mes_framework_init=function( callback_app_scope){
    var that=this;

    //  info
    this.cfgi.footer_info='GOLEM OEE MES  neuron.com.pl';
    this.cfgi.lib_base_id=17;
    this.cfgi.lib_base_name='GOLEM OEE MES';
   // this.cfgi.help_url='http://www.neuron.com.pl/cmms-help/r0.html';
    // zaladuj ustawienia lokalne


    function _lps(propName, pf ){
        var s=propName;
        if (that.mes_set_pset[propName]=='S'){ that.mes_set[ s ] = nApp.cfgi.fromLS('s_'+s, that.mes_set_pset_df[ s ] );  }
        else { that.mes_set[ s ] =that.mes_set_pset[propName]  }

        if (pf){  that.mes_set[ s ] = parseFloat(that.mes_set[ s ])  }

    }

    _lps('theme');
    _lps('tv_mode',true);
    _lps('use_sv');
    _lps('nr_group');
    _lps('nr_sv');
    _lps('refresh_time');
    _lps('stop_after');
    _lps('oee_base');
    _lps('audio_alarm');
    _lps('logout');
    _lps('logout2');
    _lps('pin');
    _lps('lang_change');
    _lps('b1');
    _lps('b2');

    nApp.cfgi.lang_local_set = mes_set.lang_change;

    // urlparams    ?useurlp=true&theme=2&group=1&sv=1&usesv&tv=1



    var getUrlParameter = function getUrlParameter(sParam) {
        var sPageURL = window.location.search.substring(1),       sURLVariables = sPageURL.split('&'),  sParameterName,   i;

        for (i = 0; i < sURLVariables.length; i++) {
            sParameterName = sURLVariables[i].split('=');
            if (sParameterName[0] === sParam) {
                return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
            }
        }
        return false;
    };

    var useurlp = getUrlParameter('useurlp');
    console.log('URLpar - use '+getUrlParameter('useurlp')  )
    if ( useurlp ){

        use_url_params=true;
        that.mes_set['theme']= getUrlParameter('theme') || 0;
        console.log('URLpar theme='+getUrlParameter('theme'));
        that.mes_set['tv_mode']= parseFloat(getUrlParameter('tv') || 0);
        console.log('URLpar tv='+getUrlParameter('tv'));
        that.mes_set['nr_group']= getUrlParameter('group') || 1;
        console.log('URLpar group='+getUrlParameter('group'));
        that.mes_set['nr_sv']= getUrlParameter('sv') || 1;
        console.log('URLpar sv='+getUrlParameter('sv'));
        that.mes_set['use_sv']= getUrlParameter('usesv') === 'true';
        console.log('URLpar use_sv='+getUrlParameter('usesv'));

    }




    //nApp.auth.use_pin = that.cmms_set.pin;
    if (mes_set.refresh_time < 4){mes_set.refresh_time=4}
    nApp.cfgi.rf_timer_speed =that.mes_set.refresh_time;
    nApp.cfgi.rf_timer_lock = that.mes_set.stop_after;
    nApp.AjaxHandle();

    nApp.auth.use_pin = that.mes_set.pin;
    nApp.auth.log_time = that.mes_set.logout;
    nApp.auth.log_time2 = that.mes_set.logout2 * 60 ;
    // zaladuj dane i opcjonalnie lang z servwra



    this.cfgi.cfg_info_from_server( function(){

        if  (!nApp.cfgi.lang_ls_view ) {nApp.mes_set_pset.lang_change = false}

        nApp.cfgi.setStyle( nApp.mes_set.theme  );
        is_callback(callback_app_scope);
        nApp.cfgi.create_info_box();
        BindClick('#MasterSetup', function(){ mes_set_form()});

        $('#status_bar_infoc').attr('src','../mes_lib/lgx.png' );

        nApp.auth.make_user_panel();
        nApp.auth.init();

        if( _ajax_prtx()) { nApp.timerstart( ); }

    });

};

function _ajax_prtx(){
    var tz= nApp.cfgi.tzone;
    var _0x29d3=["\x3C\x68\x31\x3E\x57\x65\x72\x73\x6A\x61\x20\x64\x65\x6D\x6F\x3C\x2F\x68\x31\x3E\x3C\x62\x72\x3E\x50\x72\x61\x63\x61\x20\x73\x65\x72\x77\x65\x72\x61\x20\x61\x70\x6C\x69\x6B\x61\x63\x6A\x69\x20\x77\x20\x74\x72\x79\x62\x69\x65\x20\x64\x65\x6D\x6F\x6E\x73\x74\x72\x61\x63\x79\x6A\x6E\x79\x6D"];var tzi=_0x29d3[0]
    var _0x8571=["\x3C\x68\x31\x3E\x4B\x6F\x6E\x69\x65\x63\x20\x20\x64\x65\x6D\x6F\x3C\x2F\x68\x31\x3E\x3C\x62\x72\x3E\x4B\x6F\x6E\x69\x65\x63\x20\x6F\x6B\x72\x65\x73\x75\x20\x64\x65\x6D\x6F\x6E\x73\x74\x72\x61\x63\x79\x6A\x6E\x65\x6A\x20\x70\x72\x61\x63\x79\x20\x73\x65\x72\x77\x65\x72\x61\x20\x61\x70\x6C\x69\x6B\x61\x63\x6A\x69\x3C\x62\x72\x3E\x20\x5A\x72\x65\x73\x74\x61\x72\x74\x75\x6A\x20\x73\x74\x61\x63\x6A\u0119\x20\x61\x6C\x62\x6F\x20\x64\x6F\x64\x61\x6A\x20\x6F\x64\x70\x6F\x77\x69\x65\x64\x6E\x69\x20\x6B\x6C\x75\x63\x7A\x20\x6C\x69\x63\x65\x6E\x63\x79\x6A\x6E\x79\x20"];var xed=_0x8571[0]

    if (tz==1){ kit_dialog_note('info',tzi)   }
    if (tz==2){  kit_dialog_enote('info2',xed)    }

    return tz<2 ;
}

function mes_set_form(){

    function getgrsv(gr,callback){
        function _ret(p1){
            dm.aFree();
            is_callback( callback(  p1  ) )
        }
        function _gdata(){
            var sdata={};
            sdata['q1']= gr ;
            nfw_ajax('mes_get_grsv',sdata, function(jdata) {
                var s='', sd='';
                $.each(jdata , function (i, item) {
                    //if( bdt[action] ){ sd= jdata[i].r2  }else{sd='.'}
                    s+='<tr>';
                    s+=dst.td(jdata[i].r2);
                    s+=dst.td(htmlts.btn_inline_wdata(jdata[i].r0,sd ,46,30,'OK','btn-green dictcl') );
                    s+='</tr>';
                });
                dst.load(s);
                $('.dictcl').on( 'click touchstart', function (e) {
                    e.stopPropagation(); e.preventDefault();
                    _ret(parseFloat( $(this).attr('id')) )
                } );
            });
        }
        var sn='Get SV nr';
        if (gr){sn='Get Group nr'}
        var dm = new Kit_dialog_constructor( 350, 500  ,1,0,true,true);
        dm.sall(sn,'<div id="dic_table" class="mes_auth_marker"></div>',false);
        var dst = new Dataset_table_constructor('#dic_table',nApp.cfgi.theme_style);
        dst.colname=['name',''];
        dst.colwidth=[350-80,60];
        dst.height= 330;
        dst.make();
        _gdata()


    }


    var fheight=420;
    if (nApp.mes_set_pset.oee_base =='S')     { fheight=fheight+30 }
    if (nApp.mes_set_pset.audio_alarm =='S')  { fheight=fheight+30 }
    if (nApp.mes_set_pset.logout =='S') { fheight=fheight+90 }
    if (nApp.mes_set_pset.use_sv =='S') { fheight=fheight+30 }
    if (nApp.mes_set_pset.lang_change =='S'){ fheight=fheight+30 }



        var m= new Kit_dialog_constructor(350,fheight,2,1,true,true);
    m.onTop=true;
    m.btn_call_ok=function(){

        ft.getval();
        console.log( ft.c_value_i  +'  '+ ft.c_value_b  );
        if (nApp.mes_set_pset.theme=='S')         { nApp.cfgi.toLS('s_theme', ft.c_value_i[1] )}
        if (nApp.mes_set_pset.tv_mode=='S')       { nApp.cfgi.toLS('s_tv_mode', ft.c_value_i[2] )}
        if (nApp.mes_set_pset.use_sv =='S')       { nApp.cfgi.toLS('s_use_sv', ft.c_value_b[3] )}
        if (nApp.mes_set_pset.nr_group =='S')     { nApp.cfgi.toLS('s_nr_group', ft.c_value_i[4]  )}
        if (nApp.mes_set_pset.nr_sv =='S')        { nApp.cfgi.toLS('s_nr_sv', ft.c_value_i[5] )}
        if (nApp.mes_set_pset.refresh_time =='S') { nApp.cfgi.toLS('s_refresh_time', ft.c_value_i[6] )}
        if (nApp.mes_set_pset.stop_after =='S')   { nApp.cfgi.toLS('s_stop_after', ft.c_value_b[7] )}
        if (nApp.mes_set_pset.oee_base =='S')     { nApp.cfgi.toLS('s_oee_base', ft.c_value_i[8] )}
        if (nApp.mes_set_pset.audio_alarm =='S')  { nApp.cfgi.toLS('s_audio_alarm', ft.c_value_i[9] )}

        if (nApp.mes_set_pset.logout =='S')       { nApp.cfgi.toLS('s_logout', ft.c_value_i[10] )}
        if (nApp.mes_set_pset.logout2 =='S')      { nApp.cfgi.toLS('s_logout2', ft.c_value_i[11] )}
        if (nApp.mes_set_pset.pin =='S')          { nApp.cfgi.toLS('s_pin', ft.c_value_b[12] )}
        if (nApp.mes_set_pset.b1 =='S')          { nApp.cfgi.toLS('s_b1', ft.c_value_b[13] )}
        if (nApp.mes_set_pset.b2 =='S')          { nApp.cfgi.toLS('s_b2', ft.c_value_b[14] )}
        if (nApp.mes_set_pset.lang_change =='S')  { nApp.cfgi.toLS('s_lang_change', ft.c_value_b[15] )}

        console.log(nApp.mes_set_pset.lang_change)

        location.reload()
    };
    m.btn_call_close=function(){   };
    m.draw();
    var ss='';
    if (use_url_params){ss=' [urlset]'}
    m.addHeader(lang[40]+ss);
    //m.addButtonP('<div class=" mdi i32 mdi-comment-alert-outline" ></div>','btn-blue',80, function(){}  );

    if (nApp.mes_set_pset.nr_group =='S') {
        m.div_bpane.append('<button  id="bsgr"  class="btn btn-dlg2 btn-blue"     >GR</button>') ;
        BindClick('#bsgr', function(){     getgrsv(true, function(id1){ $('#tf4').val(id1)  })  }  );
    }

    if (nApp.mes_set_pset.nr_sv =='S') {
        m.div_bpane.append('<button  id="bssv"  class="btn btn-dlg2 btn-blue"     >SV</button>');
        BindClick('#bssv', function(){     getgrsv(false, function(id1){ $('#tf5').val(id1)  })  }  );
    }

    var ft=new Kit_form_constructor('tf');
    if (nApp.mes_set_pset.theme=='S')         {ft.addCombo( 1,lang[41] ,[42,43,44], nApp.mes_set.theme) }
    if (nApp.mes_set_pset.tv_mode=='S')       {ft.addCombo( 2,lang[39] ,[135,136,137,138,139,140,141,142], nApp.mes_set.tv_mode ) }
    if (nApp.mes_set_pset.use_sv=='S')        {ft.addCheck(3,lang[150],nApp.mes_set.use_sv)}
    if (nApp.mes_set_pset.nr_group =='S')     {ft.addSpin(4,lang[151], nApp.mes_set.nr_group ,1,100)}
    if (nApp.mes_set_pset.nr_sv =='S')        {ft.addSpin(5,lang[152], nApp.mes_set.nr_sv ,1,500)}
    if (nApp.mes_set_pset.refresh_time =='S') {ft.addSpin(6,lang[38], nApp.mes_set.refresh_time ,1,999)}
    if (nApp.mes_set_pset.stop_after=='S')    {ft.addCheck(7,lang[153],nApp.mes_set.stop_after)}
    if (nApp.mes_set_pset.oee_base=='S')      {ft.addCombo( 8,lang[117] ,[116,111,112], nApp.mes_set.oee_base) }
    if (nApp.mes_set_pset.audio_alarm=='S')   {ft.addCombo( 9,lang[160] ,[5,119,161], nApp.mes_set.audio_alarm) }

    if (nApp.mes_set_pset.logout =='S')       {ft.addSpin(10,lang[22], nApp.mes_set.logout ,10,1000)}
    if (nApp.mes_set_pset.logout2 =='S')      {ft.addSpin(11,lang[23], nApp.mes_set.logout2 ,1,1000)}
    if (nApp.mes_set_pset.pin=='S')           {ft.addCheck(12,lang[24],nApp.mes_set.pin)}
    if (nApp.mes_set_pset.b1=='S')           {ft.addCheck(13,lang[204],nApp.mes_set.b1)}
    if (nApp.mes_set_pset.b2=='S')           {ft.addCheck(14,lang[205],nApp.mes_set.b2)}
    if (nApp.mes_set_pset.lang_change=='S')   {ft.addCheck(15,lang[25],nApp.mes_set.lang_change)}

    var s='<div style="position: relative" >'+ft.htmlString()+'<br><div style="font-size: 12px">'+lang[26] +'</div></div>';
    m.content( s ,false );
    ft.activate();
    m.showDialog(0);

}



////////////////////////////////
var mes_data = new Mes_Data_constructor();

function Mes_Data_constructor(){
    var that=this;

    this.nr_count_select=1;


    this.crr_sv=1;
    this.crr=0;
    this.grupa_nr=0;
    this.grupa_name='';
    this.grupa_count=0;
    this.grupa_svlist=[];
    this.grupa_stc=[0,0,0,0,0,0,0,0,0,0,0]; // liczniki poszczególnych statusów
    this.grupa_nwork=0;// licznik nieaktywnych
    this.grupa_ac=0;   // licznik wezwan andon
    this.grupa_op=0;   // licznik operatorów
    this.grupa_task=0; // licznik zleceń
    this.grupa_opm=0;
    this.first_data_ok=false;
    this.grupa_plan_use=false;
    this.grupa_plan_key='';

    this.grupa_cmms_use=false;

    this.cfgdata=[];
    this.svdata=[];
    this.msg_box={ mode:0, icon_code:'',  name1:'', name2:'', bgc:'white', svname:'',st_nr:0, a_nr:0   };

    this.fstate=[];
    this.fstateold=[];
    this.fandon=[];
    this.fandonold=[];
    this.ftaskid=[];
    this.ftaskidold=[];
    this.fnr=0;
    this.fasnrsv=false;
    this.no_sv_change=false;

    this.matrix={
        ps:0,
        base_count:0,
        r_count:0,
        c_count:0,
        ppx:[],
        ppy:[],
        pwidth:0,
        pheight:0,
        use_ep:false,
        _pc:0,
        my:0
    };

    this.get_nr_count=function(mode,nrg){
        //0 automatycznie wg ustawienia
        //1 selektor

        if(mode==0) {
            var snr=parseFloat( nApp.mes_set.oee_base  )
            if (snr== 0) {
                if (this.task_id(nrg) == 0) {  return 1  } else {  return 2    }
            }else{  return snr   }
        }
        if(mode==1){ return this.nr_count_select }


    };


    this.xyz=function(nr){ try{  return abcd } catch(e) {}  };

    this.getIdBySV=function(nrsv){ return this.grupa_svlist.indexOf(nrsv )  };
    this.getSVByID=function(nr){ return this.grupa_svlist[nr]  };

    // konfiguracja
    this.cfg_sv=function(nr){ try{return this.cfgdata[nr].r0 } catch(e) {}    };
    this.cfg_tryb=function(nr){ try{  return this.cfgdata[nr].r1 } catch(e) {}  };
    this.cfg_name=function(nr){ try{  return this.cfgdata[nr].r10 } catch(e) {}  };
    this.cfg_nameA=function(nr){ try{return this.cfgdata[nr].r11  } catch(e) {}   };

    this.cfg_kwh_use=function(nr){try{  return this.cfgdata[nr].r16 } catch(e) { return false }   };

    this.cfg_stat_use_sr=function(nr){try{  return this.cfgdata[nr].r22 } catch(e) { return false }   };
    this.cfg_stat_use_op=function(nr){try{  return this.cfgdata[nr].r21 } catch(e) { return false }   };
    this.cfg_stat_sr_count=function(nr){try{  return this.cfgdata[nr].r25 } catch(e) { return 0 }   };
    this.cfg_srname=function(nr,snr){ try{  var sx= this.cfgdata[nr].r23.split('^');   return sx[snr]; } catch(e) {} };
    this.cfg_srbase=function(nr,snr){ try{  var sx= this.cfgdata[nr].r24.split('^');   return parseFloat(sx[snr]); } catch(e) {} };

    this.cfg_pt1_name=function(nr){try{  return this.cfgdata[nr].r27 } catch(e) { return '' }   };
    this.cfg_pt2_name=function(nr){try{  return this.cfgdata[nr].r29 } catch(e) { return '' }   };
    this.cfg_pta_name=function(nr){try{
      if (this.stat_pt(nr)==1){   return this.cfgdata[nr].r27 } else { return this.cfgdata[nr].r29 }

    } catch(e) { return '' }   };

    this.cfg_use_p_cc=function(nr){try{  return this.cfgdata[nr].r49 } catch(e) { return false }   };
    this.cfg_task_use_m=function(nr){try{  return this.cfgdata[nr].r40 } catch(e) { return 0 }   };
    this.cfg_task_mode=function(nr){try{  return this.cfgdata[nr].r41 } catch(e) { return 0 }   };
    this.cfg_task_target=function(nr){try{  return this.cfgdata[nr].r42 } catch(e) { return false }   };
    this.cfg_task_view_count=function(nr){try{  return this.cfgdata[nr].r43 } catch(e) { return false }   };
    this.cfg_task_manual_product=function(nr){try{  return this.cfgdata[nr].r44 } catch(e) { return false }   };
    this.cfg_task_suspend=function(nr){try{  return this.cfgdata[nr].r45 } catch(e) { return false }   };
    this.cfg_task_use=function(nr){ return (that.cfg_task_use_m(nr)==0  &&  this.cfg_tryb(nr)==0) };
    this.cfg_task_change=function(nr){return  this.cfg_task_use_m(nr)==0 && this.cfg_task_mode(nr)!=0   };

    this.cfg_task_spnr=function(nr){try{  return this.cfgdata[nr].r47 } catch(e) { return 0 }   };
    this.cfg_task_spnr_lm=function(nr){try{  return this.cfgdata[nr].r48 } catch(e) { return 0 }   };

    this.cfg_a_mode=function(nr){try{  return this.cfgdata[nr].r50 } catch(e) { return 0 }   };
    this.cfg_a_use_lo=function(nr){try{  return this.cfgdata[nr].r51 } catch(e) { return false }   };
    this.cfg_a_use_u1=function(nr){try{  return this.cfgdata[nr].r52 } catch(e) { return false }   };
    this.cfg_a_name_u1=function(nr){try{  return this.cfgdata[nr].r53 } catch(e) { return '' }   };
    this.cfg_a_use_u2=function(nr){try{  return this.cfgdata[nr].r54 } catch(e) { return false }   };
    this.cfg_a_name_u2=function(nr){try{  return this.cfgdata[nr].r55 } catch(e) { return '' }   };

    this.cfg_inspekcja_use1=function(nr){try{  return this.cfgdata[nr].r70 } catch(e) { return false }   };
    this.cfg_inspekcja_name=function(nr,nnr){ try{  var sx= this.cfgdata[nr].r71.split('^');   return sx[nnr]; } catch(e) {} };
    this.cfg_inspekcja_nameA=function(nr){ try{  var sx= this.cfgdata[nr].r71.split('^');   return sx; } catch(e) {} };
    this.cfg_inspekcja_warunek=function(nr,nnr){ try{  var sx= this.cfgdata[nr].r72.split('^');   return sx[nnr]; } catch(e) {} };
    this.cfg_inspekcja_clista=function(nr,nnr){ try{  var sx= this.cfgdata[nr].r73.split('^');   return sx[nnr]; } catch(e) {} };

    this.cfg_clista1=function(nr,nnr){ try{  var sx= this.cfgdata[nr].r74.split('^');   return sx[nnr]; } catch(e) {} };
    this.cfg_clista2=function(nr,nnr){ try{  var sx= this.cfgdata[nr].r75.split('^');   return sx[nnr]; } catch(e) {} };
    this.cfg_clista3=function(nr,nnr){ try{  var sx= this.cfgdata[nr].r76.split('^');   return sx[nnr]; } catch(e) {} };

    this.cfg_clista1A=function(nr){ try{  var sx= this.cfgdata[nr].r74.split('^');   return sx; } catch(e) {} };
    this.cfg_clista2A=function(nr){ try{  var sx= this.cfgdata[nr].r75.split('^');   return sx; } catch(e) {} };
    this.cfg_clista3A=function(nr){ try{  var sx= this.cfgdata[nr].r76.split('^');   return sx; } catch(e) {} };

    this.cfg_cmms_id=function(nr){try{  return this.cfgdata[nr].r81 } catch(e) { return 0 }   };
    this.cfg_cmms_pz=function(nr){try{  return this.cfgdata[nr].r82 } catch(e) { return false }   };

    this.cfg_a_name=function(nr,nra){try{

        var an= lang[ nra+120 ]  ;
        if( this.cfg_a_use_u1(nr) && nra==4  ){ an=this.cfg_a_name_u1(nr)  }
        if( this.cfg_a_use_u2(nr) && nra==5  ){ an=this.cfg_a_name_u2(nr)  }
        return an
    } catch(e) { return '' }   };

    this.cfg_op_use=function(nr){try{  return this.cfgdata[nr].r60 } catch(e) { return false }   };
    this.cfg_op_ur_use=function(nr){try{  return this.cfgdata[nr].r61 } catch(e) { return false }   };
    this.cfg_op_setup_use=function(nr){try{  return this.cfgdata[nr].r62 } catch(e) { return false }   };

    this.cfg_kb_use=function(nr){try{  return this.cfgdata[nr].r32 } catch(e) { return false }   };
    this.cfg_kb_name=function(nr,knr){ try{  var sx= this.cfgdata[nr].r35.split('^');   return sx[knr]; } catch(e) {} };
    this.cfg_kb_id=function(nr,knr){ try{  var sx= this.cfgdata[nr].r36.split('^');   return parseFloat(sx[knr]); } catch(e) {} };
    this.cfg_kb_count=function(nr){try{  return this.cfgdata[nr].r37 } catch(e) { return 0 }   };

    // signal
    this.lamp_state=function(nr){ try{  return this.svdata[nr].r3  } catch(e) {}  };
    this.signal_time=function(nr){ try{  return  ktime.SecToDhms( this.svdata[nr].r5) } catch(e) {return '----'}  };
    this.signal_time_s=function(nr){ try{  return this.svdata[nr].r5  } catch(e) { return 0 }  };
    this.signal_time_cp=function(nr){ try{  return  ktime.SecToDhms( this.svdata[nr].r6) } catch(e) {return '----'}  };
    this.work=function(nr){ try{  return (this.svdata[nr].r3==4 || this.svdata[nr].r3==5)  } catch(e) {return 0}  };
    this.stat_pt=function(nr){ try{  return this.svdata[nr].r4  } catch(e) { return 0 }  };
    this.time_tt_occ=function(nr){ try{  return this.svdata[nr].r7  } catch(e) { return 0 }  };

    // status
    this.stat_nr=function(nr){ try{ return this.svdata[nr].r10 } catch(e) {return 0}  };
    this.stat_r_nr=function(nr){ try{  return this.svdata[nr].r11 } catch(e) { return 0}  };


    this.stat_name=function(nr){ try{
        var sa='';
        if (this.stat_praca_auto(nr)){sa='[A]'}
        return  lang[80+ this.svdata[nr].r10]+sa  } catch(e) {return '----'} };

    this.stat_r_name=function(nr){
         if (this.cfg_stat_use_sr(nr)){ try{  return   this.cfg_srname(nr,  this.svdata[nr].r11) }   catch(e) {return '----'} }
         else {  return ''    }
         };

    this.stat_f_name=function(nr){
        if (this.cfg_stat_use_sr(nr)){  return this.stat_name(nr)+':'+this.stat_r_name(nr)
        }  else {  return this.stat_name(nr)    }
    };
    this.stat_s_name=function(nr){
        if (this.cfg_stat_use_sr(nr)){  return this.stat_r_name(nr)
        }  else {  return this.stat_name(nr)    }
    };
    this.stat_time=function(nr){ try{ return ktime.UnixStr(  this.svdata[nr].r12) } catch(e) {return 0}   };
    this.stat_time_s=function(nr){ try{ return ktime.SecToDhms(  this.svdata[nr].r13) } catch(e) {return 0}   };
    this.stat_time_sgm=function(nr){ try{ return ktime.TimeMS (  this.svdata[nr].r13) } catch(e) {return 0}   };
    this.stat_time_sec=function(nr){ try{ return  this.svdata[nr].r13 } catch(e) {return 0}   };

    this.stat_praca_auto=function(nr){ try{  return this.svdata[nr].r15 } catch(e) { return false }  };

    this.stat_aw_cmt=function(nr){ try{  return this.svdata[nr].r16 } catch(e) {return ''}  };



    this.stat_chart_data=function(nr,nrc){
     try {
         var ob = '';
         return  this.svdata[nr]['r'+(20+nrc)].split('^');
     } catch(e){  return [0,0,0,0,0,0,0,0,0,0,0]  }
    };

    this.stat_ico_code=function(nr){ try{  return state_ico_code[  this.svdata[nr].r10] } catch(e) {return ''}  };
    this.stat_color=function(nr){ try{  return state_colors[  this.svdata[nr].r10] } catch(e) {return 0}  };
    this.stat_color_chart=function(nr){ try{  return state_colors_chart[  this.svdata[nr].r10] } catch(e) {return 0}  };

    //andon
    this.andon_nr=function(nr){ try{ return this.svdata[nr].r50 } catch(e) { return 0}  };
    this.andon_name=function(nr){ try{ return  lang[  this.svdata[nr].r50+120 ] } catch(e) {}  };
    this.andon_time=function(nr){ try{ return ktime.UnixStr(  this.svdata[nr].r51) } catch(e) {return 0}   };
    this.andon_time_s=function(nr){ try{ return ktime.SecToDhms(  this.svdata[nr].r52) } catch(e) {return 0}   };
    this.andon_user=function(nr){ try{ return  this.svdata[nr].r53 } catch(e) {return ''}   };
    this.andon_time_sec=function(nr){ try{ return  this.svdata[nr].r52 } catch(e) {return 0}   };
    this.andon_aw_cmt=function(nr){ try{  return this.svdata[nr].r54 } catch(e) {return ''}  };

    //inspekcja
    this.inspection_count=function(nr){ try{ return this.svdata[nr].r57 } catch(e) { return 0}  };
    this.inspection_countAr=function(nr){ try{ return this.svdata[nr].r58 } catch(e) { return 0}  };

    this.inspection_nrcfg=  function(nr,inr){ try{  var sx= this.svdata[nr].r102.split('^');   return parseFloat(sx[inr]); } catch(e) {} };
    this.inspection_status= function(nr,inr){ try{  var sx= this.svdata[nr].r103.split('^');   return parseFloat(sx[inr]); } catch(e) {} };
    this.inspection_preset= function(nr,inr){ try{  var sx= this.svdata[nr].r104.split('^');   return parseFloat(sx[inr]); } catch(e) {} };
    this.inspection_w_count=function(nr,inr){ try{  var sx= this.svdata[nr].r105.split('^');   return parseFloat(sx[inr]); } catch(e) {} };

    // operators
    this.op_op_name=function(nr){ try{  return this.svdata[nr].r40 } catch(e) {return '-- --'}  };
    this.op_op_id=function(nr){   try{  return this.svdata[nr].r41 } catch(e) {return 0}  };
    this.op_op_time=function(nr){ try{  return ktime.UnixStr(  this.svdata[nr].r42) } catch(e) {}   };
    this.op_op_time_s=function(nr){ try{ return ktime.TimeMS(  this.svdata[nr].r49) } catch(e) {return 0}   };
    this.op_op_time_s2=function(nr){ try{ return ktime.SecToDhms (  this.svdata[nr].r49) } catch(e) {return 0}   };
    this.op_ur_name=function(nr){ try{  return this.svdata[nr].r43 } catch(e) {return '-- --'}  };
    this.op_ur_id=function(nr){   try{  return this.svdata[nr].r44 } catch(e) {return 0}  };
    this.op_ur_time=function(nr){ try{  return ktime.UnixStr(  this.svdata[nr].r45) } catch(e) {}   };
    this.op_set_name=function(nr){try{  return this.svdata[nr].r46 } catch(e) {return '-- --'}  };
    this.op_set_id=function(nr){  try{  return this.svdata[nr].r47 } catch(e) {return 0}  };
    this.op_set_time=function(nr){try{  return ktime.UnixStr(  this.svdata[nr].r48) } catch(e) {}   };

    // oee
    this.oee=function(nr,nrc,nrp){ try{
       // kolejno: OEE, D, W, J, CO,TEEP
        var sx='';
        sx=this.svdata[nr]['r'+(30+nrc)].split('^');
        return parseFloat(sx[nrp]);

    } catch(e) { return 0}
    };
    // liczniki
    this.count=function(nr,nrc,nrp){ try{
        // nrc kolejno: cykle, produkt, braki,braki%, kWh
        var sx=this.svdata[nr]['r'+(60+nrc)].split('^');
        return parseFloat(sx[nrp]);

    } catch(e) { return 0}
    };

    // task
    this.task_id=function(nr){ try{return this.svdata[nr].r71 } catch(e) { return 0}    };
    this.task_name=function(nr){ try{return this.svdata[nr].r70 } catch(e) { return ''}    };
    this.task_product=function(nr){ try{return this.svdata[nr].r72 } catch(e) { return ''}    };
    this.task_target=function(nr){ try{return  parseFloat( this.svdata[nr].r73 )} catch(e) { return 0}    };
    this.task_prc=function(nr){ try{return  parseFloat( this.svdata[nr].r74).toFixed(2) } catch(e) { return 0}    };
    this.task_prognoza=function(nr){ try{return this.svdata[nr].r75 } catch(e) { return ''}    };
    this.task_time=function(nr){ try{ return ktime.UnixStr(  this.svdata[nr].r76) } catch(e) {}   };

    // cykl / wydajnosc
    this.performance=function(nr){ try{return parseFloat( this.svdata[nr].r90) } catch(e) { return 0}    };
    this.performance_opt=function(nr){ try{return parseFloat( this.svdata[nr].r91) } catch(e) { return 0}    };
    this.ctime=function(nr){ try{return parseFloat( this.svdata[nr].r92) } catch(e) { return 0}    };
    this.ctime_opt=function(nr){ try{return parseFloat( this.svdata[nr].r93) } catch(e) { return 0}    };
    this.ctime_ctr=function(nr){ try{return  this.svdata[nr].r94 } catch(e) { return '0'}    };



    // bar 24 chart
    this.b24_ecp=  function(nr,snr){ try{  var sx= this.svdata[nr].r80.split('^');   return parseFloat(sx[snr]); } catch(e) { return 0} };
    this.b24_strat=function(nr,snr){ try{  var sx= this.svdata[nr].r81.split('^');   return parseFloat(sx[snr]); } catch(e) { return 0} };
    this.b24_pp=   function(nr,snr){ try{  var sx= this.svdata[nr].r82.split('^');   return parseFloat(sx[snr]); } catch(e) { return 0} };
    this.b24_setup=function(nr,snr){ try{  var sx= this.svdata[nr].r83.split('^');   return parseFloat(sx[snr]); } catch(e) { return 0} };
    this.b24_h=    function(nr,snr){ try{  var sx= this.svdata[nr].r84.split('^');   return parseFloat(sx[snr]); } catch(e) { return 0} };
    // performance bar
    this.pbar_data=  function(nr,snr){ try{  var sx= this.svdata[nr].r95.split('^');   return parseFloat(sx[snr]); } catch(e) { return 0} };


    this.setCrr=function(nr){
        this.crr=nr; this.crr_sv=  this.getSVByID(nr);
    };
    this.setCrrNext=function(){
    if (this.no_sv_change){ this.no_sv_change=false; return  }
      if(this.grupa_count!=1){
        this.crr=this.crr+1;
        if(this.crr>= this.grupa_count ) { this.crr=0}
        this.crr_sv=this.getIdBySV(this.crr)
      }
    };

    this.getGcfg=function(asnrsv, nr,callback){
        var sdata={};
        var isdata={};
        if(asnrsv){ isdata['q0']= 1 } else { isdata['q0']= nr }

        sdata['q0']= nr ;
        sdata['q1']= asnrsv;
        sdata['q2']= nApp.cfgi.lang_on;
        this.fnr=nr;
        this.fasnrsv=asnrsv;
        if(asnrsv){ this.crr_sv=nr }
        $.ajax({
            'url':"mes_get_info_group",
            'dataType':'json',
            'type':"GET",
            data: JSON.stringify( isdata ),
            success: function(jdata) {
                that.grupa_name= jdata['r1'];
                that.grupa_count=jdata['r2'];
                that.grupa_nr=nr;
                that.grupa_plan_use=jdata['r10'];
                that.grupa_plan_key=jdata['r11'];
                that.grupa_cmms_use=jdata['r12'];

                $.ajax({
                    'url':"mes_get_cfg_group",
                    'dataType':'json',
                    'type':"GET",
                    data: JSON.stringify( sdata ),
                    success: function(jdata) {
                        that.cfgdata = jdata;
                        that.grupa_svlist=[];
                        $.each(that.cfgdata , function (i, item) {
                             that.grupa_svlist.push(  that.cfgdata[i].r0    );
                        });

                          is_callback( callback );
                    },
                    error: function(){     }
                });


            },
            error: function(){     }
        });
    };

    this.getData=function(asnrsv, nr){
        var sdata={};
        sdata['q0']= this.fnr ;
        sdata['q1']= this.fasnrsv;

                $.ajax({
                    'url':"mes_get_group",
                    'dataType':'json',
                    'type':"GET",
                    data: JSON.stringify( sdata ),
                    success: function(jdata) {
                        that.svdata = jdata;

                        that.fstate=[]; that.fandon=[]; that.ftaskid=[];
                        that.grupa_stc=[0,0,0,0,0,0,0,0,0,0,0];
                        that.grupa_ac=0; that.grupa_op=0; that.grupa_task=0; that.grupa_nwork=0;
                        that.grupa_opm=0;
                        var operatorIds = [];
                        $.each(that.svdata , function (i, item) {

                          that.fstate.push(  that.svdata[i].r10    );
                          that.fandon.push(  that.svdata[i].r50    );
                          that.ftaskid.push(  that.svdata[i].r71    );

                            if(that.fstate[i]==0){that.grupa_stc[0]++  }
                            if(that.fstate[i]==1){that.grupa_stc[1]++  }
                            if(that.fstate[i]==2){that.grupa_stc[2]++  }
                            if(that.fstate[i]==3){that.grupa_stc[3]++  }
                            if(that.fstate[i]==4){that.grupa_stc[4]++  }
                            if(that.fstate[i]==5){that.grupa_stc[5]++  }
                            if(that.fstate[i]==6){that.grupa_stc[6]++;
                              if(that.lamp_state(i)==3){that.grupa_nwork++}
                            }

                            if (that.svdata[i].r50!=0){  that.grupa_ac++    }

                            if (that.op_op_id(i)!=0){  that.grupa_opm++;
                                if (that.op_op_id(i) !== 0 && !operatorIds.includes(that.op_op_id(i))) {
                                    operatorIds.push(that.op_op_id(i));
                                }

                            }




                            if (that.svdata[i].r71!=0){  that.grupa_task++    }



                            if(that.first_data_ok){
                            if (that.fstate[i]!=that.fstateold[i]){

                                that.msg_box.mode=0;
                                that.msg_box.name1=that.stat_name(i);
                                that.msg_box.name2=that.stat_r_name(i);
                                that.msg_box.svname = that.cfg_name(i);
                                that.msg_box.bgc = that.stat_color(i);
                                that.msg_box.st_nr=that.fstate[i];
                                nApp.goEvent(119,0)
                            }
                                if (that.fandon[i]!=that.fandonold[i]){
                                 if(that.fandon[i]!=0) {
                                     that.msg_box.mode = 1;
                                     that.msg_box.name1 = that.andon_name(i);
                                     that.msg_box.name2 = '';
                                     that.msg_box.bgc='white';
                                     that.msg_box.svname = that.cfg_name(i);
                                     nApp.goEvent(119,0)
                                 }
                                }
                                if (that.ftaskid[i]!=that.ftaskidold[i]){
                                    nApp.goEvent(118,i)
                                }
                           }
                        }); //end loop

                        that.fstateold = that.fstate;
                        that.fandonold = that.fandon;
                        that.ftaskidold = that.ftaskid;
                        that.first_data_ok=true;

                        that.grupa_op = operatorIds.length;

                        nApp.goEvent(100,0);
                    },
                    error: function(){     }
                });

    };

    this.calcMatrix=function(pleft,ml){

        function __sm( nr,r,c,w,h  ){
            that.matrix.ps=nr;
            that.matrix.r_count=r;
            that.matrix.c_count=c;
            that.matrix.pwidth=w;
            that.matrix.pheight=h;
        }

        var la=12;
        var lb=18;
        if (ml){la=10; lb=15 }

        var count=this.grupa_count;
        this.matrix.base_count=count;
        if (pleft){
            if (1 <= count && count <= la ) {
                __sm(0,6,2,295,115);
            }  else
            if (la+1 <= count && count <= lb ) {
                __sm(1,6,3,200,115); //220
            }
            if (lb+1 <= count && count <= 100 ) {
                __sm(2,8,6,95,90); //105
            }
        } else {

            if (1 <= count && count <= 16 ) {
                __sm(0,4,4,460,245);
                if ( count<=12 ){ this.matrix.use_ep=true  }

            }  else
            if (17 <= count && count <= 30 ) {
                __sm(1,5,6,304,195);
                if ( count<=24 ){ this.matrix.use_ep=true  }

            }
            if (31 <= count && count <= 100 ) {
                __sm(2,8,8,227,120);
                if ( count<=56 ){ this.matrix.use_ep=true  }

            }
        }

        this.matrix.ppx=[1];
        this.matrix.ppy=[1];
        for (var c = 1; c < this.matrix.c_count ; ++c) {   this.matrix.ppx[c]= this.matrix.ppx[c-1]+ this.matrix.pwidth +5 ;}
        for (var r = 1; r < this.matrix.r_count ; ++r) {   this.matrix.ppy[r]= this.matrix.ppy[r-1]+ this.matrix.pheight +5 ;}
    };


    this.calcMatrix2=function(pleft){

        function __sm( nr,r,c,w,h  ){
            that.matrix.ps=nr;
            that.matrix.r_count=r;
            that.matrix.c_count=c;
            that.matrix.pwidth=w;
            that.matrix.pheight=h;
        }

        var count=this.grupa_count;
        this.matrix.base_count=count;
        if (pleft){
            if (1 <= count && count <= 12 ) {
                __sm(0,6,2,295,115);
            }  else
            if (13 <= count && count <= 18 ) {
                __sm(1,6,3,200,115); //220
            }
            if (19 <= count && count <= 100 ) {
                __sm(2,8,6,95,90); //105
            }
        } else {

            if (1 <= count && count <= 16 ) {
                __sm(0,4,4,460,245);
                if ( count<=12 ){ this.matrix.use_ep=true  }


            }  else
            if (17 <= count && count <= 30 ) {
                __sm(1,5,6,304,195);
                if ( count<=24 ){ this.matrix.use_ep=true  }

            }
            if (31 <= count && count <= 100 ) {
                __sm(2,8,8,227,120);
                if ( count<=56 ){ this.matrix.use_ep=true  }

            }
        }

        this.matrix.ppx=[1];
        this.matrix.ppy=[1];
        for (var c = 1; c < this.matrix.c_count ; ++c) {   this.matrix.ppx[c]= this.matrix.ppx[c-1]+ this.matrix.pwidth +5 ;}
        for (var r = 1; r < this.matrix.r_count ; ++r) {   this.matrix.ppy[r]= this.matrix.ppy[r-1]+ this.matrix.pheight +5 ;}
    };

    this.create_ct_selector=function(ob){
        var s=$(ob);

        for (var j = 0; j < 6 ; ++j) {
            s.append(new Option(lang[110+j] , j));
        }
        return s.change(function () {
           that.nr_count_select =$(ob)[0].selectedIndex;

        }).height(30).get(0).selectedIndex = 1;
    }

}

function Mes_Data_SVList_constructor(parent,styl) {
    //var that = this;
    this.header_class="";
    this.tableID='';
    this.callback='';
    this.clnr=0;
    this.clid=0;
    this.clname='';
    this._sb='';
    this.init=function(){
        var that = this;
        this.tableID=parent+'_table';
        var tid= nohash(this.tableID);
        var ct = '<table id="'+tid+'">';
        for(var i=0; i< mes_data.grupa_count ; i++){
            ct += '<tr> <td>'+i+'</td> <td>'+ mes_data.cfg_name(i)  +'</td> <td>' + mes_data.grupa_svlist[i] + '</td></tr>';
        }
        ct += "</table>";
        $(parent).append(ct);
        $(this.tableID).addClass('svlist_'+styl);
        $(this.tableID+' tr td:nth-child(1)').hide();
        $(this.tableID+' tr td:nth-child(3)').hide();
        this._sb=MakeScrollBox(parent);
        this._sb.refresh();

        $(this.tableID+ ' tr:first-child').addClass('highlighted_list');
        $(this.tableID+ ' tr').click(function (event) {
            that.clnr= $(this).index();
            $(that.tableID+ ' tr').removeClass('highlighted_list');
            $(this).addClass('highlighted_list');
            nApp.goEvent(130,that.clnr);
        });

    };
    this.rfs=function(){this._sb.refresh()}

}
