# wlb_mnEls_mime

ID: led
MIME: image/png;6.2207
DATA:


# wlb_Main

ID: ElCadr
PARENT: /wlb_originals/wdg_Box
ATTRS: path;name;dscr;active;geomW;geomH;evProc;backColor;bordWidth;bordColor;
ICO:

PROC:
JavaLikeCalc.JavaScript
//using Special.FLibSYS;
ev_wrk = ev_rez = "";
if(f_start) cntr = prevCntr = holdCntr = 0;
cntr++;

if(!prmColor.isEVal()) { bordColor = prmColor; bordWidth = 2; }
else { bordColor = "black"; bordWidth = 1; }

//Disable all mutable widgets
info_ed_en = info_var_en = info_sp_en = info_out_en = spToVar_en = up_en = upm_en = upMax_en = down_en = downm_en = downMin_en = lev_out_en = lev_var_en = lev_sp_en = mode_en = modMan_en = modAuto_en =
	modCasc_en = pnl_pid_en = greed_text_en = greed_text1_en = greed_text2_en = greed_text3_en = greed_text4_en = greed_text5_en = 
	com_open_en = com_stop_en = com_close_en = com_text_en = st_open_en = st_close_en = st_text_en = Ramka_en = moveUp_en = moveDwn_en = false;

info_name_text = prmShifr.isEVal() ? "" : prmShifr;

//Impulse processing
if(!prmAnalog.isEVal() && prmAnalog == false) {
	lev_out_en = info_out_en = false; 
	moveUp_en = moveDwn_en = true; 
	moveUp_fillColor = (!prmImpQupTm.isEVal() && prmImpQupTm) ? "cyan" : "black-0"; 
	moveDwn_fillColor = (!prmImpQdwnTm.isEVal() && prmImpQdwnTm) ? "cyan" : "black-0"; 
}

//Check for analog
if(!prmVar.isEVal() || !prmVarIn.isEVal()) {
	info_ed_en = info_var_en = lev_var_en = greed_text_en = greed_text1_en = greed_text2_en = greed_text3_en = greed_text4_en = greed_text5_en = true;
	info_ed_text = prmDemention.isEVal() ? "" : prmDemention;
	pVar = prmVar.isEVal() ? prmVarIn : prmVar;
	if(prmVarIn.isEVal()) info_var_bordWidth = 0;
	if(info_var_clearCnt <= 0) { info_var_arg0val = pVar; info_var_backColor = ""; } else info_var_clearCnt--; 
	lev_var_p1y = max(0,min(140,140*(1-(pVar-min)/(max-min))));
	if(prmPrec.isEVal())	info_var_arg0cfg = "10;f;2";
	else if(prmPrec >= 0)	info_var_arg0cfg = "10;f;"+prmPrec;
	else	info_var_arg0cfg = "10;g;"+abs(prmPrec);

	info_var_color = lev_var_c3 = "#3EFF3E";
	//Warning borders process
	if(!prmWMin.isEVal() && !prmWMax.isEVal() && prmWMax > prmWMin) {
		lev_var_c2 = "yellow";
		lev_var_p6y = lev_var_p7y = 140*(1-(prmWMax-min)/(max-min));
		lev_var_p8y = lev_var_p9y = 140*(1-(prmWMin-min)/(max-min));
		if(pVar >= prmWMax || pVar <= prmWMin) info_var_color = lev_var_c3 = "yellow";
	}
	else lev_var_c2 = "black-0";
	//Alarm borders process
	if(!prmAMin.isEVal() && !prmAMax.isEVal() && prmAMax > prmAMin) {
		lev_var_c1 = "red";
		lev_var_p2y = lev_var_p3y = 140*(1-(prmAMax-min)/(max-min));
		lev_var_p4y = lev_var_p5y = 140*(1-(prmAMin-min)/(max-min));
		if( pVar >= prmAMax || pVar <= prmAMin ) info_var_color = lev_var_c3 = "red";
	}
	else lev_var_c1 = "black-0";

	//EVAL
	if(pVar > max || pVar < min) info_var_color = lev_var_c3 = "lightgray";

	// Check an process PID regulator
	if(!prmVar.isEVal() && !prmSp.isEVal()) {
		lev_out_en = info_out_en = !prmOut.isEVal() && (prmAnalog.isEVal() || prmAnalog == true);
		info_sp_en = lev_sp_en = mode_en = modMan_en = modAuto_en = pnl_pid_en = true;

		modCasc_en = !prmCasc.isEVal();
		spToVar_en = up_en = upm_en = upMax_en = down_en = downm_en = downMin_en = (prmCasc != true);
		lev_out_p1y = 140*(1-prmOut/100);
		lev_sp_p1y = max(0,min(140,140*(1-(prmSp-min)/(max-min))));
		if(info_sp_clearCnt <= 0) { info_sp_arg0val = prmSp; info_sp_backColor = ""; } else info_sp_clearCnt--; 
		if(prmPrec.isEVal())	info_sp_arg0cfg = "10;f;2";
		else if(prmPrec >= 0)	info_sp_arg0cfg = "10;f;"+prmPrec;
		else info_sp_arg0cfg = "10;g;"+abs(prmPrec);

		if(info_out_clearCnt <= 0) { info_out_arg0val = prmOut; info_out_backColor = ""; } else info_out_clearCnt--;
		appToVl = 0;

		//Event process
		for(off = 0; (ev_wrk=event.parse(0,"\n",off)).length; ) {
			prevMode = prmAuto ? ((prmCasc==true)?tr("Cascade"):tr("Automate")) : tr("Manual");      
			if(ev_wrk == "ws_BtPress:/modMan" && prmAuto) {  
				prmAuto = false; if(prmCasc==true) prmCasc = false;
				SYS.messNote("OP:"+this.ownerSess().user()+":"+prmShifr,"'"+prmShifr+"'. "+tr("Mode")+" : "+(prmDescr.isEVal()?"":prmDescr)+" : "+prevMode+" : "+tr("Manual"));
			}
			else if(ev_wrk == "ws_BtPress:/modAuto" && (!prmAuto || prmCasc)) {  
				prmAuto = true; if(prmCasc==true) prmCasc = false;
				SYS.messNote("OP:"+this.ownerSess().user()+":"+prmShifr,"'"+prmShifr+"'. "+tr("Mode")+" : "+(prmDescr.isEVal()?"":prmDescr)+" : "+prevMode+" : "+tr("Automate"));
			}
			else if(ev_wrk == "ws_BtPress:/modCasc" && !prmCasc) {  
		prmAuto = prmCasc = true;
		SYS.messNote("OP:"+this.ownerSess().user()+":"+prmShifr,"'"+prmShifr+"'. "+tr("Mode")+" : "+(prmDescr.isEVal()?"":prmDescr)+" : "+prevMode+" : "+tr("Cascade"));
			}
			else if(ev_wrk == "key_mousePresLeft:/info_sp") {
				SYS.messNote("OP:"+this.ownerSess().user()+":"+prmShifr,"'"+prmShifr+"'. "+tr("Setpoint")+" : "+(prmDescr.isEVal()?"":prmDescr)+" : "+prmSp.toFixed(abs(prmPrec))+" : "+info_sp_arg0val.toFixed(abs(prmPrec)));
				prmSp = info_sp_arg0val; info_sp_backColor = ""; info_sp_clearCnt = 0;
			}
			else if(ev_wrk == "key_mousePresLeft:/info_out") {
				SYS.messNote("OP:"+this.ownerSess().user()+":"+prmShifr,"'"+prmShifr+"'. "+tr("Output")+" : "+(prmDescr.isEVal()?"":prmDescr)+" : "+prmManIn.toFixed(1)+" : "+info_out_arg0val.toFixed(1));
				prmManIn = info_out_arg0val; info_out_backColor = ""; info_out_clearCnt = 0;
			}
			else if(ev_wrk == "ws_BtPress:/spToVar") {
				info_sp_arg0val = info_var_arg0val;
				info_sp_backColor = "darkslategray";
				info_sp_clearCnt = 25;
			}
			else if(ev_wrk == "ws_BtPress:/up")			appToVl = 1;
			else if(ev_wrk == "ws_BtPress:/upm")			appToVl = 10;
			else if(ev_wrk == "ws_BtPress:/upMax")		appToVl = 1e300;
			else if(ev_wrk == "ws_BtPress:/down")			appToVl = -1;
			else if(ev_wrk == "ws_BtPress:/downm")		appToVl = -10;
			else if(ev_wrk == "ws_BtPress:/downMin")	appToVl = -1e300;
			else if(ev_wrk == "ws_BtPress:/pnl_pid") {
				sessNm = path.parsePath(0);
				pidPg = "/"+sessNm + "/pg_so/"+vcaAttrGet("/"+sessNm+"/pg_so/wdg_pgCont/a_pgOpenSrc").parsePath(2)+"/pg_greg/pg_"+prmId;
				if(vcaNodePresent(pidPg)) vcaAttrSet(pidPg+"/a_pgOpen",1);
				else ev_rez += "usr_PidCntrCall\n"; 
			} 
			else ev_rez += ev_wrk+"\n";
		}
		event = ev_rez;

		if(appToVl && (prmAuto || prmOut.isEVal())) {
			if(prmPrec.isEVal())	newVl = ((info_sp_arg0val-min)/(max-min)+appToVl/100)*(max-min)+min;
			else {
				if((cntr-prevCntr)/f_frq > 0.2)	{ holdCntr = cntr; levUp = 0; }
				prevCntr = cntr;
				if((cntr-holdCntr)/f_frq > 3)	{ holdCntr = cntr; levUp++; }
				decMult = max(2,floor(lg((max-min)/pow(10,-prmPrec))));
				newVl = info_sp_arg0val + sign(appToVl) *										//direction
														pow(abs(appToVl),floor(decMult/2)) *		//half for two buttons level
														pow(10,min(levUp,ceil(decMult/2)-1)) *	//levelUp on hold any 3 seconds
														pow(10,-prmPrec);										//precision base
			}
			newVl = max(min,min(max,newVl));
			if(!prmAMin.isEVal() && !prmAMax.isEVal() && prmAMax > prmAMin ) newVl = max(prmAMin,min(prmAMax,newVl));
			info_sp_arg0val = newVl; info_sp_backColor = "darkslategray"; info_sp_clearCnt = 25;
		}
   	else if(appToVl && !prmAuto) {
			if(prmAnalog==false) {
				prmManIn = 50+2.5*appToVl;
				if(appToVl == -1)			SYS.messNote("OP:"+this.ownerSess().user()+":"+prmShifr,"'"+prmShifr+"'."+tr("Output")+": "+(prmDescr.isEVal()?"":prmDescr)+" :: "+tr("Close")+" ( < )");
				else if(appToVl == 1)	SYS.messNote("OP:"+this.ownerSess().user()+":"+prmShifr,"'"+prmShifr+"'."+tr("Output")+": "+(prmDescr.isEVal()?"":prmDescr)+" :: "+tr("Open")+" ( > )");
				else if(appToVl == -10)	SYS.messNote("OP:"+this.ownerSess().user()+":"+prmShifr,"'"+prmShifr+"'."+tr("Output")+": "+(prmDescr.isEVal()?"":prmDescr)+" :: "+tr("Close")+" ( << )");
				else if(appToVl == 10)	SYS.messNote("OP:"+this.ownerSess().user()+":"+prmShifr,"'"+prmShifr+"'."+tr("Output")+": "+(prmDescr.isEVal()?"":prmDescr)+" :: "+tr("Open")+" ( >> )");
			}
			else {
				newVl = max(0,min(100,info_out_arg0val+appToVl));
				info_out_arg0val = newVl; info_out_backColor = "darkslategray"; info_out_clearCnt = 25;
			}
		}

		if(prmAuto && prmCasc) { mode_text = tr("Cascade"); info_sp_bordWidth = info_out_bordWidth = 0; }
		else if(prmAuto) {
			mode_text = tr("Automate");
			info_sp_bordWidth = 1; info_out_bordWidth = 0;
		}
		else {
			mode_text = tr("Manual");
			info_out_bordWidth = 1; info_sp_bordWidth = prmOut.isEVal() ? 1 : 0;
		}
	}
	// Manual variable input
	else if(!prmVarIn.isEVal()) {
		up_en = upm_en = upMax_en = down_en = downm_en = downMin_en = true;
		info_var_bordWidth = 1;
		appToVl = 0;

		//Event process
		for(off = 0; (ev_wrk=event.parse(0,"\n",off)).length; ) {
			if(ev_wrk == "key_mousePresLeft:/info_var") {
				SYS.messNote("OP:"+this.ownerSess().user()+":"+prmShifr,"'"+prmShifr+"'. "+tr("Variable")+" : "+(prmDescr.isEVal()?"":prmDescr)+" : "+prmVarIn.toFixed(abs(prmPrec))+" : "+info_var_arg0val.toFixed(abs(prmPrec)));
				prmVarIn = info_var_arg0val; info_var_backColor = ""; info_var_clearCnt = 0;
			}
			else if(ev_wrk == "ws_BtPress:/up")			appToVl = 1;
			else if(ev_wrk == "ws_BtPress:/upm")			appToVl = 10;
			else if(ev_wrk == "ws_BtPress:/upMax")		appToVl = 1e300;
			else if(ev_wrk == "ws_BtPress:/down")		appToVl = -1;
			else if(ev_wrk == "ws_BtPress:/downm")		appToVl = -10;
			else if(ev_wrk == "ws_BtPress:/downMin")	appToVl = -1e300;
			else ev_rez += ev_wrk + "\n";
		}
		event = ev_rez;

		if(appToVl) {
			if(prmPrec.isEVal()) newVl = ((info_var_arg0val-min)/(max-min)+appToVl/100)*(max-min)+min;
			else {
				if((cntr-prevCntr)/f_frq > 0.2)	{ holdCntr = cntr; levUp = 0; }
				prevCntr = cntr;
				if((cntr-holdCntr)/f_frq > 3)	{ holdCntr = cntr; levUp++; }
				decMult = max(2,floor(lg((max-min)/pow(10,-prmPrec))));
				newVl = info_var_arg0val +	sign(appToVl) *										//direction
															pow(abs(appToVl),floor(decMult/2)) *		//half for two buttons level
															pow(10,min(levUp,ceil(decMult/2)-1)) *	//levelUp on hold any 3 seconds
															pow(10,-prmPrec);										//precision base
			}
			newVl = max(min,min(max,newVl));
			if(!prmAMin.isEVal() && !prmAMax.isEVal() && prmAMax > prmAMin) newVl = max(prmAMin,min(prmAMax,newVl));
			info_var_arg0val = newVl; info_var_backColor = "darkslategray"; info_var_clearCnt = 25;
		}
	}
}
else if(!prmCom.isEVal() || !prmClose.isEVal() || !prmOpenSt.isEVal() || !prmCloseSt.isEVal()) {
	Ramka_en = true;
	com_open_en = com_close_en = (!prmCom.isEVal() || !prmClose.isEVal());
	st_open_en = st_close_en = (!prmOpenSt.isEVal() || !prmCloseSt.isEVal());
	com_stop_en = !prmStop.isEVal();

	if(com_open_en) {
		com_open_name = !digComs.isEVal() ? digComs.parse(0,";").parse(0,"-") : tr("OPEN");
		com_open_color = (digComs.parse(0,";").parse(1,"-") != "") ? digComs.parse(0,";").parse(1,"-") : "green";
		com_open_tipTool = !digComs.isEVal() ? tr("Command")+" "+digComs.parse(0,";").parse(0,"-") : tr("Command")+" "+tr("OPEN");
		com_open_tipStatus = !digComs.isEVal() ? tr("Press for")+" "+digComs.parse(0,";").parse(0,"-") : tr("Press for")+" "+tr("OPEN");
		com_open_en = com_open_name.length;
	}
	if(com_close_en) {
		com_close_name = !digComs.isEVal() ? digComs.parse(1,";").parse(0,"-") : tr("CLOSE");
		com_close_color = (digComs.parse(1,";").parse(1,"-") != "") ? digComs.parse(1,";").parse(1,"-") : "red";
		com_close_tipTool = !digComs.isEVal() ? tr("Command")+" "+digComs.parse(1,";").parse(0,"-") : tr("Command")+" "+tr("CLOSE");
		com_close_tipStatus = !digComs.isEVal() ? tr("Press for")+" "+digComs.parse(1,";").parse(0,"-") : tr("Press for")+" "+tr("CLOSE");
		com_close_en = com_close_name.length;
	}
	if(com_stop_en) { 
		com_stop_name = !digComs.isEVal() ? digComs.parse(2,";").parse(0,"-") : tr("STOP");
		com_stop_color = (digComs.parse(2,";").parse(1,"-") != "") ? digComs.parse(2,";").parse(1,"-") : "yellow";
		com_stop_tipTool = !digComs.isEVal() ? tr("Command")+" "+digComs.parse(2,";").parse(0,"-") : tr("Command")+" "+tr("STOP");
		com_stop_tipStatus = !digComs.isEVal() ? tr("Press for")+" "+digComs.parse(2,";").parse(0,"-") : tr("Press for")+" "+tr("STOP");
		com_stop_en = com_stop_name.length;
	}
	if(st_open_en) {
		st_open_text = !digStts.isEVal() ? digStts.parse(0,";").parse(0,"-") : tr("OPEN");
		st_open_color = (digStts.parse(0,";").parse(1,"-") != "") ? digStts.parse(0,";").parse(1,"-") : "green";
		st_open_tipTool = !digStts.isEVal() ? digStts.parse(0,";").parse(0,"-") : tr("OPEN");
		st_open_tipStatus = !digStts.isEVal() ? tr("State")+" "+digStts.parse(0,";").parse(0,"-") : tr("State")+" "+tr("OPEN");
	}
	if(st_close_en) {
		st_close_text = !digStts.isEVal() ? digStts.parse(1,";").parse(0,"-") : tr("CLOSE");
		st_close_color = (digStts.parse(1,";").parse(1,"-") != "") ? digStts.parse(1,";").parse(1,"-") : "red";
		st_close_tipTool = !digStts.isEVal() ? digStts.parse(1,";").parse(0,"-") : tr("CLOSE");
		st_close_tipStatus = !digStts.isEVal() ? tr("State")+" "+digStts.parse(1,";").parse(0,"-") : tr("State")+" "+tr("CLOSE");
	}

	//Event process
	for(off = 0; (ev_wrk=event.parse(0,"\n",off)).length; ) {
		if(ev_wrk == "ws_BtPress:/com_open") {
			if(!prmCom.isEVal()) prmCom = true; prmClose = false;
			SYS.messNote("OP:"+this.ownerSess().user()+":"+prmShifr,"'"+prmShifr+"'. "+tr("Command")+" : "+(prmDescr.isEVal()?"":prmDescr)+" : : "+com_open_name);
		}
		else if(ev_wrk == "ws_BtPress:/com_close") {
			if(!prmClose.isEVal()) prmClose = true; prmCom = false;
			SYS.messNote("OP:"+this.ownerSess().user()+":"+prmShifr,"'"+prmShifr+"'. "+tr("Command")+" : "+(prmDescr.isEVal()?"":prmDescr)+" : : "+com_close_name);
		}
		else if(ev_wrk == "ws_BtPress:/com_stop") {
			prmStop = true;
			SYS.messNote("OP:"+this.ownerSess().user()+":"+prmShifr,"'"+prmShifr+"'. "+tr("Command")+" : "+(prmDescr.isEVal()?"":prmDescr)+" : : "+com_stop_name);
		}
		else ev_rez+=ev_wrk+"\n";
	}
	event = ev_rez;

	if(st_open_en) st_open_color = !prmOpenSt.isEVal() ? (prmOpenSt ?
		((digStts.parse(0,";").parse(1,"-") != "") ? digStts.parse(0,";").parse(1,"-") : "green") : "gray") :
			(prmCloseSt ? "gray" : ((digStts.parse(0,";").parse(1,"-") != "") ? digStts.parse(0,";").parse(1,"-") : "green"));

	if(st_close_en) st_close_color = !prmCloseSt.isEVal() ? (prmCloseSt ?
		((digStts.parse(1,";").parse(1,"-") != "") ? digStts.parse(1,";").parse(1,"-") : "red") : "gray") :
			(prmOpenSt ? "gray" : ((digStts.parse(1,";").parse(1,"-") != "") ? digStts.parse(1,";").parse(1,"-") : "red"));
}
else if(!prmComText.isEVal() || !prmStText.isEVal()) {
	Ramka_en = true;
	com_text_en = !prmComText.isEVal();
	st_text_en = !prmStText.isEVal();

	//Event process
	for(off = 0; (ev_wrk=event.parse(0,"\n",off)).length; ) {
		if(ev_wrk == "ws_CombChange:/com_text") {
			prmComText = com_text_value;
			SYS.messNote("OP:"+this.ownerSess().user()+":"+prmShifr,"'"+prmShifr+"'. "+tr("Command")+" : "+(prmDescr.isEVal()?"":prmDescr)+" : : "+prmComText);
			com_text_value = "";
		}
		else ev_rez += ev_wrk+"\n";
	}
	event = ev_rez;

	if(com_text_en) {
		com_text_items = "";
		for(off = 0; !digComs.isEVal() && (vIt=digComs.parse(0,";",off)).length; ) com_text_items += vIt + "\n";
		com_text_tipTool = !digComs.isEVal() ? tr("Select command") : "";
		com_text_tipStatus = !digComs.isEVal() ? tr("Press for command select") : "";
		com_text_en = com_text_items.length;
	}
	if(st_text_en) {
		st_text_text = !prmStText.isEVal() ? prmStText.parse(0,":") : "";
		if(com_text_en) com_text_value = st_text_text;
		st_text_color = (prmStText.parse(1,":") != "") ? prmStText.parse(1,":") : "green";
		st_text_tipTool = !prmStText.isEVal() ? prmStText.parse(0,":") : "";
		st_text_tipStatus = !prmStText.isEVal() ? tr("State")+" "+prmStText.parse(0,":") : "";
		st_text_en = st_text_text.length;
		if(st_text_en && com_text_items.indexOf(st_text_text) != -1) com_text_value = st_text_text;
	}
}


ID: grpGraph
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;geomW;geomH;evProc;backColor;bordWidth;bordColor;
ICO:

PROC:
JavaLikeCalc.JavaScript
if(f_start) {
	//Parameter selection enable
	if(allowSelLst.length)
		for(i_el = 0; i_el < 8; i_el++) {
			cEl = this["el"+(i_el+1)];
			cEl.attrSet("enForce",1);
			if(cEl.attr("contextMenu").search(":select$") < 0)
				cEl.attrSet("contextMenu",cEl.attr("contextMenu")+tr("Select")+":select\n");
		}
	cnt = 0;
}
cnt++;
if(cnt == 3)	event = "ws_FocusIn:/trnd1";

curTm = SYS.time();
if(!trnd1_tSek) trnd1_tSek = curTm;
selSingle = 0;
selAll = false;

//Events process
for(ev_rez = "", off = 0; (ev_cur=event.parse(0,"\n",off)).length;  ) {
	if(ev_cur == "key_presComma:/trnd1")			trnd1_tSek -= trnd1_tSize/2;
	else if(ev_cur == "key_presPeriod:/trnd1")	trnd1_tSek += trnd1_tSize/2;
	else if(ev_cur == "ws_SliderChange:/arh")	trnd1_tSek = arh_value*trnd1_tSize;
	else if(ev_cur.search("usr_single:/el") == 0)	selSingle = ev_cur.slice(14).toInt();
	else if(ev_cur.search("usr_all:/el") == 0)	selAll = true;
	else ev_rez += (ev_cur+"\n");
	//SYS.messDebug("Trend","Event: "+ev_cur);
}
event = ev_rez;

//Trend time control
if(trnd1_tSek < curTm) trnd1_trcPer = 0;
else { trnd1_trcPer = 1; trnd1_tSek = 0; }

//Generic
name_arg0val = this.attr("name");

//Scale
typeXY = (trnd1_type==2);
cntrAct = cntrLog = xCntrAct = xCntrLog = 0;
for(i_el = 0; i_el < 10; i_el++) {
	cEl = this["el"+(i_el+1)];
	if(!cEl.attr("en")) continue;
	if(!typeXY || !(i_el%2)) {
		cntrAct++;
		if(cEl.attr("log") == true)	cntrLog++;
	}
	else {
		xCntrAct++;
		if(cEl.attr("log") == true)	xCntrLog++;
	}
}
trnd1_sclVer = (cntrLog > cntrAct/2) ? trnd1_sclVer|0x4 : trnd1_sclVer&(~0x4);
trnd1_sclHor = (xCntrLog > xCntrAct/2) ? trnd1_sclHor|0x4 : trnd1_sclHor&(~0x4);

//Trends
arh_beg = 1e30, arh_end = 0;
for(i_el = 0; i_el < 8; i_el++) {
	cEl = this["el"+(i_el+1)];
	if(selAll)	cEl.attrSet("bordStyle",3);
	if(selSingle) cEl.attrSet("bordStyle",((i_el+1)==selSingle)?3:1);
	cTr = this["trnd1"];
	cTrPrm = "prm"+i_el;
	if(!cEl.attr("en")) cTr.attrSet(cTrPrm+"addr","");
	else {
		cTr.attrSet(cTrPrm+"addr",cEl.attr("addr"));
		cTr.attrSet(cTrPrm+"bordL",cEl.attr("min"));
		cTr.attrSet(cTrPrm+"bordU",cEl.attr("max"));
		cTr.attrSet(cTrPrm+"color",cEl.attr("color"));
		cTr.attrSet(cTrPrm+"width",cEl.attr("bordWidth")*2);
		cEl.attrSet("varEl",cTr.attr(cTrPrm+"val"));
		//Enable/disable of the mode's indication in the regulators ???
		cEl.attrSet("enMode",((curTm-trnd1_curSek) <= 2));
		//Archive depth calculate
		if(cEl.attr("bordStyle") == 3) {
			arh_tmp = cTr.attr(cTrPrm+"prop");
			if((arh_vl=arh_tmp.parse(0,":").toReal())) arh_beg = min(arh_beg,arh_vl);
			if((arh_vl=arh_tmp.parse(1,":").toReal())) arh_end = min(curTm,max(arh_end,arh_vl));
		}
		if(!typeXY || !(i_el%2)) {
			if((cEl.attr("log")==true) == (cntrLog > cntrAct/2) && cEl.attr("bordWidth") == 1) cTr.attrSet(cTrPrm+"scl",0);
			else cTr.attrSet(cTrPrm+"scl",(cEl.attr("log")==true)?6:2);
		}
		else {
			if((cEl.attr("log")==true) == (xCntrLog > xCntrAct/2)) cTr.attrSet(cTrPrm+"scl",0);
			else cTr.attrSet(cTrPrm+"scl",(cEl.attr("log")==true)?6:2);
		}
	}
}
//Set archive scroll
if(arh_end && ((arh_end-arh_beg)/trnd1_tSize > 2)) {
	arh_cfg = "0:"+floor(arh_beg/trnd1_tSize+1)+":"+floor(arh_end/trnd1_tSize+1)+":1:5";
	arh_value = (trnd1_tSek?trnd1_tSek:curTm)/trnd1_tSize;
	arh_tipTool = tr("Archive space")+": ["+SYS.strftime(arh_beg)+" ... "+SYS.strftime(arh_end)+"]";
	arh_active = true;
	if(selSingle) trnd1_tSek = arh_end;
}
else { arh_active = false; arh_tipTool = ""; }


ID: graphSelPrm
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;geomW;geomH;pgOpenSrc;pgGrp;backColor;bordWidth;
ICO:

PROC:
JavaLikeCalc.JavaScript
if(f_start) {
	apply_active = false;
	name_active = val_min_active = val_max_active = dim_active = log_active = false;
	prm_items = prm_value = name_value = dim_value = "", log_value = false, val_min_value = val_max_value = 0;
	//Connect to linked widget 
	if(pgOpenSrc.length) lWdg = this.wdgAt(pgOpenSrc, true);
	if(lWdg) {
		//Get allowed graphic's sources for the selection
		tmplLst = "";
		prm_items = "<Clear>\n";
		if(lWdg.attrPresent("allowSelLst")) tmplLst = lWdg.attr("allowSelLst");
		else if(lWdg.ownerWdg(true).attrPresent("allowSelLst")) tmplLst = lWdg.ownerWdg(true).attr("allowSelLst");
		for(off = 0; (pIt=tmplLst.parse(0,"\n",off)).length; )
			// Archives list template process
			//t1 = "123";//SYS.messInfo("SEL", "TEST 00");	//!!!! After uncomment it next line will not work. Observe further
			if(pIt == "<varhs>") {
				aLs = SYS.Archive.nodeList("va_");
				for(i_a = 0; i_a < aLs.length; i_a++) {
					itNm = SYS.Archive[aLs[i_a]].cfg("NAME");
					if(!itNm.length) itNm = SYS.Archive[aLs[i_a]].cfg("Source");
					prm_items += tr("Archive")+" '"+itNm+"' (/Archive/"+aLs[i_a]+")\n";
				}
			}
			// Direct items list process by form "{path}:{name}:{min}:{max}:{dim}"
			else if(pIt.search("/(sub_|)Archive/") >= 0) {
				if(!(itObj=SYS.nodeAt(pIt.parse(0,":")))) continue;
				prm_items += tr("Archive")+" '"+pIt.parse(1,":")+"' ("+(pIt.parse(0,":")+":"+pIt.parse(2,":")+":"+pIt.parse(3,":")+":"+pIt.parse(4,":")).replace(new RegExp(":*$"),"")+")\n";
			}
			else {
				pathAbs = pIt.search("/(sub_|)DAQ/") >= 0;
				itObj = pathAbs ? SYS.nodeAt(pIt.parse(0,":")) : SYS.DAQ.nodeAt(pIt.parse(0,":"));
				if(!itObj) continue;
				itNm = pIt.parse(1,":");
				if(!itNm.length && typeof(itObj).search("TCntrNode:TValue[:$]") == 0) itNm = itObj.cntr().cfg("NAME") + " > " + itObj.NAME.get();
				prm_items += "DAQ '"+itNm+(pathAbs?"' (":"' (/DAQ")+(pIt.parse(0,":")+":"+pIt.parse(2,":")+":"+pIt.parse(3,":")+":"+pIt.parse(4,":")).replace(new RegExp(":*$"),"")+")\n";
			}

		//Current value processing
		itAddr = lWdg.link("addr").match("(prm|arh):([^ ]+) \\(\\+\\)");
		if(itAddr.length == 3) {
			//Get Name
			if(lWdg.link("name").search("prm:[^ ]+ \\(\\+\\)") >= 0) name_value = lWdg.attr("name");
			else if((itTmp=lWdg.link("name").match("val:(.+$)")).length == 2) name_value = itTmp[1];
			else name_value = tr("Empty");
			//Get Min and Max
			if(lWdg.link("min").search("prm:[^ ]+ \\(\\+\\)") >= 0) val_min_value = lWdg.attr("min");
			else if((itTmp=lWdg.link("min").match("val:(.+$)")).length == 2) val_min_value = itTmp[1];
			if(lWdg.link("max").search("prm:[^ ]+ \\(\\+\\)") >= 0) val_max_value = lWdg.attr("max");
			else if((itTmp=lWdg.link("max").match("val:(.+$)")).length == 2) val_max_value = itTmp[1];
			//Logarithmic scale
			if(lWdg.link("log").search("prm:[^ ]+ \\(\\+\\)") >= 0) log_value = lWdg.attr("log");
			else if((itTmp=lWdg.link("log").match("val:(.+$)")).length == 2) log_value = itTmp[1];
			//Dimension
			if(lWdg.link("ed").search("prm:[^ ]+ \\(\\+\\)") >= 0) dim_value = lWdg.attr("ed");
			else if((itTmp=lWdg.link("ed").match("val:(.+$)")).length == 2) dim_value = itTmp[1];
			//Current prm name
			if(itAddr[1] == "prm") {
				for(tAddr = "", off = 0, pos = 0; (tAddrEl=itAddr[2].parsePath(0,off)).length; pos++)
					if(pos >= 3 && off < itAddr[2].length)	tAddr += "/prm_"+tAddrEl;
					else if(tAddrEl == "var" && off >= itAddr[2].length)	continue;
					else tAddr += "/"+tAddrEl;
				prm_value = "DAQ '"+name_value+"' (/DAQ"+(tAddr+":"+val_min_value.toPrecision()+":"+val_max_value.toPrecision()+":"+dim_value).replace(new RegExp(":*$"),"")+")";
				//prm_value = "DAQ '"+name_value+"' (/DAQ"+(itAddr[2].replace(new RegExp("/var$"),"")+":"+val_min_value.toPrecision()+":"+val_max_value.toPrecision()+":"+dim_value).replace(new RegExp(":*$"),"")+")";
			}
			else if(itAddr[1] == "arh") prm_value = tr("Archive")+" '"+name_value+"' (/Archive/va_"+(itAddr[2]+":"+val_min_value.toPrecision()+":"+val_max_value.toPrecision()+":"+dim_value).replace(new RegExp(":*$"),"")+")";
			if(prm_value.length) name_active = val_min_active = val_max_active = log_active = dim_active = true;
		}

		//Load current properties
		color_value = lWdg.attr("color");

		//Load the colors list
		color_cfg = "";
		parLs = lWdg.nodePrev().nodeList("wdg_");
		for(iLs = 0; iLs < parLs.length; iLs++)
			 if((tVl=lWdg.nodePrev()[parLs[iLs]].attr("colorDef")).length)
				color_cfg += tVl+"\n";
	}
}

colorBox_backColor = color_value;

//Events for commands process
for(evRez = "", off = 0; (evCur=event.parse(0,"\n",off)).length; ) {
	//this.messInfo("Event: "+evCur);
	if(evCur == "ws_ListChange:/prm") {	//Parameter selected
		//Set properties
		itTmp = prm_value.match(".+'(.*)' \\((.+?)\\)");
		if(itTmp.length == 3) {
			if(itTmp[1].length)	name_value = itTmp[1];
			off1 = 0;
			itVal = itTmp[2].parse(0,":",off1);	//Path
			//Connect to source and get main values for parameter
			if(itVal.parsePath(0) == "DAQ" && typeof(itObj=SYS.nodeAt(itVal)).search("TCntrNode:TValue[:$]") == 0) {
				val_min_value = itObj.min.get();
				val_max_value = itObj.max.get();
				log_value = itObj.log.get();
				dim_value = itObj.ed.get();
			}
			
			//Set direct values
			if((itVal=itTmp[2].parse(0,":",off1)).length) val_min_value = itVal;
			if((itVal=itTmp[2].parse(0,":",off1)).length) val_max_value = itVal;
			if((itVal=itTmp[2].parse(0,":",off1)).length) dim_value = itVal;
		}
		else name_value = dim_value = "", val_min_value = val_max_value = 0, log_value = false;
		apply_active = name_active = val_min_active = val_max_active = log_active = dim_active = true;
		//prmSearch_value = "";
	}
	else if(evCur == "key_relsReturn:/prmSearch" && prmSearch_value.length) {
		sPos = (((sPos=prm_items.indexOf(prm_value))<0)?0:sPos) + prm_value.length;
		if(((sPos=prm_items.indexOf(prmSearch_value,sPos)) >= 0 || (sPos=prm_items.indexOf(prmSearch_value,0)) >= 0)) {
			sPos = ((sPos=prm_items.lastIndexOf("\n",sPos)) < 0) ?	0 : sPos+1;
			prm_value = ((sPos_=prm_items.indexOf("\n",sPos)) >= 0) ? prm_items.slice(sPos,sPos_) : prm_items.slice(sPos);
			event += "ws_ListChange:/prm\n";
		}
	}
	else if(evCur == "ws_LnAccept:/name" || evCur == "ws_LnAccept:/val_min" || evCur == "ws_LnAccept:/val_max" ||
				evCur == "ws_LnAccept:/dim" || evCur == "ws_LnAccept:/color" || evCur == "ws_ChkChange:/log")	apply_active = true;
	else if(evCur == "ws_BtPress:/apply") {
		//Link addr set
		itTmp = prm_value.match(".+\\((.+?)[:\\)]");
		if(itTmp.length != 2)	lWdg.linkSet("addr", "", true);		//Clear
		else {	//Set
			off1 = 0;
			firstEl = itTmp[1].parsePath(0,off1);
			if(firstEl == "Archive") {
				lWdg.linkSet("addr", "", true);	//Clear all othet values
				lWdg.linkSet("addr", "arh:"+itTmp[1].slice(off1+4));		lWdg.linkSet("name", "val:"+name_value);	lWdg.linkSet("ed", "val:"+dim_value);
				lWdg.linkSet("min", "val:"+val_min_value);						lWdg.linkSet("max", "val:"+val_max_value);
				lWdg.linkSet("log", "val:"+log_value);
			}
			else if(firstEl == "DAQ") {
				itObj = SYS.nodeAt(itTmp[1]);
				isPrm = (typeof(itObj).search("TCntrNode:TValue[:$]") == 0);
				lWdg.linkSet("addr", "", true);	//Clear all othet values
				lWdg.linkSet("addr", "prm:"+itTmp[1].slice(off1).replace("/prm_","/"), isPrm);
				if(!isPrm || name_value != itObj.NAME.get())		lWdg.linkSet("name", "val:"+name_value);
				if(!isPrm || val_min_value != itObj.min.get())	lWdg.linkSet("min","val:"+val_min_value);
				if(!isPrm || val_max_value != itObj.max.get())	lWdg.linkSet("max","val:"+val_max_value);
				if(!isPrm || log_value != itObj.log.get())			lWdg.linkSet("log","val:"+log_value);
				if(!isPrm || dim_value != itObj.ed.get())			lWdg.linkSet("ed","val:"+dim_value);
			}
		}
		lWdg.attrSet("color", color_value);
		lWdg.attrSet("event", lWdg.attr("event")+"usr_set\n");

		this.attrSet("pgOpen", false);
	}
	else if(evCur == "ws_BtPress:/cancel")	this.attrSet("pgOpen", false);
	else evRez += evCur+"\n";
}
event = evRez;


ID: RootPgSo
PARENT: /wlb_originals/wdg_Box
ATTRS: path;name;dscr;active;geomW;geomH;evProc;backColor;
ICO:

PROC:
JavaLikeCalc.JavaScript
calcCnt++;

if(f_start) {
	play_en = demoPlayProc.length;
	if(!play_en)	this.infoW.attrSet("geomH",this.play.attr("geomY")+this.play.attr("geomH")-this.infoW.attr("geomY"));
	//Checking the signal object's presenting and creating needed
	soLst = this.nodeList("pg_"); soLstS = new Object();
	for(i = 0; i < soLst.length; i++)
		if((curSO=soLst[i].slice(3).toInt())) {
			soNm = this["pg_"+curSO].attr("name");
			for(soNmSz = 0, off = 0; off < soNm.length; soNmSz++)
				soNm.charAt(off, "UTF-8");
			soLstS[curSO.toString(10,2)] = tVl = new Object();
			tVl.nm = soNm;
			tVl.nmSz = soNmSz;
		}
	//Init views
	viewGrps = new Array(new Object(), new Object(), new Object());
	v = viewGrps[0]; v.cnt = 0, v.first = 1, v.last = 2;
	v = viewGrps[1]; v.cnt = 0, v.first = 3, v.last = 5;
	v = viewGrps[2]; v.cnt = 0, v.first = 6, v.last = 6, v.global = true;	//Only one item currently
	oldViewLs = new Array("mn", "ggraph", "gcadr", "gview", "doc", "rg");

	//Processing SO and views
	logoR = this.logo.attr("geomX") > this.so1.attr("geomX");
	soInterSpecX = logoR ? this.so1.attr("geomX") : (this.logo.attr("en")?this.so1.attr("geomX")-this.logo.attr("geomX")-this.logo.attr("geomW"):2);
	soX = logoR ? soInterSpecX : this.so1.attr("geomX");
	soWdth =	logoR ?	((this.logo.attr("en")?this.logo.attr("geomX"):this.attr("geomW"))-soX) : (this.attr("geomW") - soX);
	soSymbSz = this.so1.attr("font").parse(1," ").toReal()*0.75;

	soInterSpecY = this.so1.attr("geomY");
	soY = this.so1.attr("geomY");
	soY2 = soY + this.so1.attr("geomH") + soInterSpecY;
	row1 = 0, row2 = 0, row1w = 0, row2w = 0;
	oldViews = false;
	for(var iSO in soLstS) {
		if(!(curSO=iSO.toInt()))	continue;
		soNmSz = soLstS[iSO].nmSz*soSymbSz + soInterSpecX;
		if(!row2 && (row1w+soNmSz) < soWdth)		row1w += soNmSz, row1++;
		else if((row2w+soNmSz) < soWdth)			row2w += soNmSz, row2++;
		else continue;	//Too more and long SO
		if(curSO != 1)	this.wdgAdd("so"+curSO, soLstS[iSO].nm, this.attr("parent")+"/wdg_so1");

		soW = this["wdg_so"+curSO];
		soW.attrSet("name", soLstS[iSO].nm)
			.attrSet("color", backColorButton)
			.attrSet("colorText", labColorGood)
			.attrSet("tipTool", tr("Signal object")+" "+curSO+((curSO<=9)?" (CtrlAlt+"+curSO+")":""))
			.attrSet("tipStatus", tr("Press for select signal object")+" "+curSO+((curSO<=9)?" (CtrlAlt+"+curSO+")":""));

		soDscr = this["pg_"+curSO].attr("dscr");
		if(soDscr.length) soW.attrSet("tipTool", soDscr);
		soW.attrSet("en", 1);

		// Appending the events and hotkey processing
		evProc += "ws_BtPress:/so"+curSO+":open:/pg_so/"+curSO+"/*/*\n";
		if(curSO <= 9)	evProc += "key_presCtrlAlt"+curSO+":*:open:/pg_so/"+curSO+"/*/*\n";

		for(iV = viewGrps[0].first; iV <= viewGrps[2].last; iV++) {
			viewGrp = viewGrps[0];
			if(iV >= viewGrps[2].first)	viewGrp = viewGrps[2];
			else if(iV >= viewGrps[1].first)	viewGrp = viewGrps[1];
			if(viewGrp[iV].isEVal()) {
				vNm = "";
				isG = (viewGrp.global == true);
				if(this.nodeList("pg_","/pg_"+(isG?"view"+iV:curSO)+"/pg_view"+iV).length)	vNm = "view"+iV;
				else if(this.nodeList("pg_","/pg_"+(isG?oldViewLs[iV-1]:curSO)+"/pg_"+oldViewLs[iV-1]).length)	vNm = oldViewLs[iV-1];
				if(vNm.length) {
					viewGrp[iV] = true, viewGrp.cnt++;
					// Appending the events processing
					evProc += "ws_BtPress:/go_view"+iV+":open:/pg_so/"+(isG?vNm:"*")+"/"+vNm+"/*\n";
					// Append for the processing events of the hotkeys
					vO = this["wdg_go_view"+iV];
					if((tVl=vO.attr("tipTool").match("\\(CtrlAlt\\+(.)\\)")).length)
						evProc += "key_presCtrlAlt"+tVl[1]+":*:open:/pg_so/"+(isG?vNm:"*")+"/"+vNm+"/*\n"; 
				}
			}
		}
	}

	soWdthAdd = (soWdth-row1w)/row1;
	soOff = soX, i = 0;
	for(var iSO in soLstS) {
		if(!(curSO=iSO.toInt()))	continue;
		if(i > (row1+row2))	break;
		soW = this["so"+curSO];
		soNm = soW.attr("name");
		soNmSz = soLstS[iSO].nmSz*soSymbSz + soInterSpecX;
		soOffY = soY2;
		if(i < row1)	soNmSz += soWdthAdd, soOffY = soY;
		else if(i == row1)	soOff = soX;
		soW.attrSet("geomX",soOff).attrSet("geomY",soOffY).attrSet("geomW",soNmSz-soInterSpecX);
		soOff += soNmSz;
		i++;
	}
	if(row1 == 1)		soOff = soY;
	else if(!row2)	soOff = soY2 - soInterSpecY;
	else soOff = soY2 + this.so1.attr("geomH");
	this.pgCont.attrSet("geomY",soOff).attrSet("geomH",(alarms_en?alarms_geomY:geomH)-soOff);

	//Unused views concealment
	for(iVG = 0; iVG < viewGrps.length; iVG++) {
		viewGrp = viewGrps[iVG];
		viewOff = this["wdg_go_view"+viewGrp.first].attr("geomX");
		viewWdth = this["wdg_go_view"+viewGrp.last].attr("geomX") + this["wdg_go_view"+viewGrp.last].attr("geomW") - viewOff;
		for(iV = viewGrp.first; viewGrp.cnt < (viewGrp.last-viewGrp.first)+1 && iV <= viewGrp.last; iV++) {
			vO = this["wdg_go_view"+iV];
			if(viewGrp[iV].isEVal()) vO.attrSet("en", false);
			else {
				vO.attrSet("geomX", viewOff).attrSet("geomW", (viewWdth/viewGrp.cnt)-2);
				viewOff += viewWdth/viewGrp.cnt;
			}
		}
	}
}

if(pgCont_pgOpenSrc != lastView) {
	this.ownerSess().uiCmd("open", "/pg_control/pg_terminator", this.attr("path"));
	//Checking for SO selection change
	curSO = pgCont_pgOpenSrc.parsePath(2).slice(3);
	lastSO = lastView.parsePath(2).slice(3);
	if(curSO != lastSO) {
		if(lastSO.length) this["wdg_so"+lastSO].attrSet("color", backColorButton);
		if(curSO.length) {
			this["wdg_so"+curSO].attrSet("color", backColorButtonSel);
			// Check for view modes active
			for(iV = viewGrps[0].first; iV <= viewGrps[2].last; iV++) {
				viewGrp = viewGrps[0];
				if(iV >= viewGrps[2].first)		viewGrp = viewGrps[2];
				else if(iV >= viewGrps[1].first)	viewGrp = viewGrps[1];
				if(viewGrp[iV] == true) {
					vNm = "";
					isG = (viewGrp.global == true);
					if(this.nodeList("pg_","/pg_"+(isG?"view"+iV:curSO)+"/pg_view"+iV).length)	vNm = "view"+iV;
					else if(this.nodeList("pg_","/pg_"+(isG?oldViewLs[iV-1]:curSO)+"/pg_"+oldViewLs[iV-1]).length)	vNm = oldViewLs[iV-1];
					this["wdg_go_view"+iV].attrSet("active", vNm.length);
				}
			}
		}
	}
	//Checking for view selection change
	curMode = pgCont_pgOpenSrc.parsePath(3).slice(3);
	lastMode = lastView.parsePath(3).slice(3);
	if(curMode != lastMode) {
		if(lastMode.length)
			this["wdg_go_"+(((tVl=oldViewLs.indexOf(lastMode)) >= 0)?"view"+(tVl.toInt()+1):lastMode)].attrSet("color","");
		if(curMode.length)
			this["wdg_go_"+(((tVl=oldViewLs.indexOf(curMode)) >= 0)?"view"+(tVl.toInt()+1):curMode)].attrSet("color", backColorButtonSel);
	}

	//Pages counter display
	if(pgCont_pgOpenSrc.length && curMode.length) {
		elLst = this["pg_"+curSO]["pg_"+curMode].nodeList("pg_");
		curEl = pgCont_pgOpenSrc.parsePath(4);
		pgSel_items = "";
		for(iEl = 0, iM = -1; iEl < elLst.length; iEl++) {
			oEl = this["pg_"+curSO]["pg_"+curMode][elLst[iEl]];
			if(!(elNm=oEl.attr("name")).length)
				elNm = oEl.ownerPage().attr("name") + " " + iEl;
			elNm += " ("+elLst[iEl].slice(3)+")";
			pgSel_items += (pgSel_items.length?"\n":"") + elNm;
			if(iM < 0 && elLst[iEl] == curEl) { pgSel_value = elNm; iM = iEl; }
			delete oEl;
		}
		pgCntr_text = ""+(iM+1)+"\n("+elLst.length+")";
		prev_active = next_active = pgSel_active = (elLst.length>1);
	}
	else { pgCntr_text = "-"; prev_active = next_active = pgSel_active = false; }

	lastView = pgCont_pgOpenSrc;
}

//Cvitation button's
cvt_light_en = alarmSt&0x100; cvt_alarm_en = alarmSt&0x200; cvt_sound_en = alarmSt&0x400;
cvt_light_active = alarmSt&0x10000; cvt_alarm_active = alarmSt&0x20000; cvt_sound_active = alarmSt&0x40000;

//Per one second's calls
if((calcCnt%f_frq) == 0) {
	//Alarms display
	actSO = pgCont_pgOpenSrc.parsePath(2).slice(3);
	soLst = this.nodeList("pg_");
	for(i = 0; i < soLst.length; i++) {
		curSO = soLst[i].slice(3);

		this["wdg_so"+curSO].attrSet("color", ((curSO==actSO)?backColorButtonSel:backColorButton));

		aSt = this["pg_"+curSO].attr("alarmSt");
		aLev = aSt&0xFF;
		if(aLev && aSt&0x100) {
			if(aLev > 30) wColor = labColorAlarm;
			else wColor = labColorWarning;
			curColor = this["wdg_so"+curSO].attr("colorText");
			this["wdg_so"+curSO].attrSet("colorText",(aSt&0x10000 && curColor==wColor)?"black":wColor);
		}
		else this["wdg_so"+curSO].attrSet("colorText", labColorGood);
	}
}

//Events process
for(off = 0, ev_rez = ""; (sval=event.parse(0,"\n",off)).length; ) {
	if(sval == "ws_CombChange:/pgSel" && (tPg=pgSel_value.match("\\((.+)\\)$")).length)
		this.ownerSess().uiCmd("open", "/pg_so/"+pgCont_pgOpenSrc.parsePath(2)+"/"+pgCont_pgOpenSrc.parsePath(3)+"/pg_"+tPg[1], this.attr("path"));
		//this[pgCont_pgOpenSrc.parsePath(2)][pgCont_pgOpenSrc.parsePath(3)]["pg_"+tPg[1]].attrSet("pgOpen",true);
	else if(sval == "ws_BtPress:/cvt_light")	alarmSt = 0x1000001;
	else if(sval == "ws_BtPress:/cvt_alarm")	alarmSt = 0x1000002;
	else if(sval == "ws_BtPress:/cvt_sound")	alarmSt = 0x1000004;
	else ev_rez += sval+"\n";
}
event = ev_rez;

//Demo play process
if(f_start || !play_value) { stepCur = -1; stepTm = 0; play_img = "start"; }
if(play_value) {
	play_img = "stop";
	if(stepTm > 0) stepTm -= 1/f_frq;
	else {
		var args = new Object();
		args.this = this;
		args.stepTm = stepTm;
		args.stepCur = stepCur;
		SYS.DAQ.funcCall("JavaLikeCalc.JavaScript",args,demoPlayProc);
		stepTm = args.stepTm;
		stepCur = args.stepCur;
	}
}

if((tVl=defUser.toInt()) && (tVl2=defUser.parse(1,"-")).length) {
	if((SYS.time()-this.ownerSess().userActTm()) < tVl*60)	userSetVis = "";
	else if(this.ownerSess().reqUser() != tVl2.parse(0,":"))	userSetVis = tVl2;
}


ID: ElViewCadr
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;geomW;geomH;evProc;backColor;bordWidth;bordColor;bordStyle;
ICO:

PROC:
JavaLikeCalc.JavaScript
text_arg0val = name;
text_arg1val = var;
trnd_prm0addr = addr;
bordColor = (focus&&bordColor!="silver")?"silver":"gray";


ID: grpCadr
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;geomW;geomH;evProc;backColor;bordWidth;bordColor;
ICO:

PROC:
JavaLikeCalc.JavaScript
curTm = SYS.time();
if(!trnd1_tSek) trnd1_tSek = curTm;

//Events process
for(off = 0, ev_rez = ""; (ev_cur=event.parse(0,"\n",off)).length; ) {
	//Special.FLibSYS.messPut("Trend",0,"Event: "+ev_cur);
	if(ev_cur == "key_presSC#3b:/trnd1")			trnd1_tSek -= trnd1_tSize/2;
	else if(ev_cur == "key_presSC#3c:/trnd1")	trnd1_tSek += trnd1_tSize/2;
	else ev_rez += (ev_cur+"\n");
}
event = ev_rez;

//Trend time control
if(trnd1_curSek > trnd1_tSek || trnd1_curSek < (trnd1_tSek-trnd1_tSize)) trnd1_curSek = trnd1_tSek;
if(trnd1_tSek < curTm)	trnd1_trcPer = 0;
else trnd1_trcPer = 1, trnd1_tSek = 0;

//Generic
name_arg0val = grpName;

for(i = 0; i < 8; i++) {
	el = this["el"+(i+1)];
	if(el.attr("prmAddr").isEVal())	{ el.attrSet("en",false); this.trnd1.attrSet("prm"+i+"addr",""); }
	else {
  		el.attrSet("en", true);
		this.trnd1.attrSet("prm"+i+"addr",el.attr("prmAddr"))
						.attrSet("prm"+i+"bordL",el.attr("min")).attrSet("prm"+i+"bordU",el.attr("max"))
						.attrSet("prm"+i+"color",el.attr("bordColor"));
	}
}


ID: anShow
PARENT: /wlb_originals/wdg_Box
ATTRS: path;perm;name;dscr;active;geomH;tipTool;contextMenu;evProc;backColor;bordWidth;bordColor;
ICO:

PROC:
JavaLikeCalc.JavaScript
if(!pDscr.isEVal())
	tipTool = pDscr + ((!pErr.isEVal()&&pErr.toInt())?"\n"+tr("Error")+": "+pErr:"");
name_text = pName.isEVal() ? tr("No data") : pName;
val_arg0val = pVal;
val_font = "Arial 24 1 0 0 0";
if(!pPrec.isEVal()) val_arg0cfg = ((pPrec>=0)?";f;":";g;")+abs(pPrec);
if(pVal.isEVal()) {
	val_color = name_color = "grey";
	val_font = "Arial 24 0 1 0 1";
	alarm = "";
	pErrCode = 0;
	bordColor = "grey", bordWidth = 1;
	return;
}

//Notification create
if(!pErr.isEVal() && pErrCode != pErr) {
	pErrCode = pErr;
	alTp = (!spName.isEVal() && spName.length) ? 7 : 3;
	if(pErrCode == 1 || pErrCode == 2)	alarm = (redEVAL == true) ? "100|"+pName+"|"+spName+" - "+tr("reject")+".|7" : "100|"+pName+"||1";
	else if(pErrCode == 3)	alarm = "50|"+pName+"|"+spName+" "+tr("above alarm border")+".|"+alTp;
	else if(pErrCode == 4)	alarm = "50|"+pName+"|"+spName+" "+tr("bellow alarm border")+".|"+alTp;
	else if(pErrCode == 5)	alarm = "10|"+pName+"|"+spName+" "+tr("above warning border")+".|"+alTp;
	else if(pErrCode == 6)	alarm = "10|"+pName+"|"+spName+" "+tr("bellow warning border")+".|"+alTp;
	else if(pErrCode == 10) alarm = "10|"+pName+"|"+pErr.parse(1,":")+".|"+alTp;
	else if(pErrCode == 11) alarm = "50|"+pName+"|"+pErr.parse(1,":")+".|"+alTp;
	else if(alarmSt&0x100)	alarm = "1|"+pName+"||1";
}
if(!pErrCode && alarmSt&0x100 && !(alarmSt&0x10000)) alarm = "";

//Notification color change
alarmLev = alarmSt&0xFF;
if(alarmLev && alarmSt&0x100) {
	blinkPr = true;
	if(!pErrCode || alarmLev <= 1)	wColor = labColorGood;
	else if(alarmLev < 30)	wColor = labColorWarning;
	else if(alarmLev < 75)	wColor = labColorAlarm;
	else { wColor = "grey"; blinkPr = false; }
	if(blinkPr) name_color = val_color = (alarmSt&0x10000 && name_color == wColor) ? "grey" : wColor;
	else { 
		if(pErrCode == 1 || pErrCode == 2)	{ val_color = wColor; val_font = "Arial 24 0 1 0 1"; name_color = (redEVAL==true) ? labColorAlarm : wColor; }
		else name_color = val_color = wColor;
	}
}
else name_color = val_color = labColorGood;

//Blink focused or linked with ElCadr
if(this.attr("focus") ||
	(!pName.isEVal() && pName.length && this.wdgAt("/s/pg_control/pg_ElCadr",true).attr("pgOpen") && this.wdgAt("/s/pg_control/pg_ElCadr",true).attr("prmShifr") == pName))
{
  bordColor = (bordColor == "silver") ? "grey" : "silver";
  bordWidth = 2;
}
else { bordColor = "grey"; bordWidth = 1; }

//Check the regulator mode
if(pModeC == true) mode_text = tr("C");
else mode_text = pModeA.isEVal() ? "" : ((pModeA) ? tr("A") : tr("M"));


ID: ViewCadr
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;geomW;geomH;backColor;bordWidth;
ICO:

PROC:
JavaLikeCalc.JavaScript
name_arg0val = this.attr("name");

if(f_start) {
	el1_1_en = !el1_1_addr.isEVal(); el1_2_en = !el1_2_addr.isEVal(); el1_3_en = !el1_3_addr.isEVal(); 
	el1_4_en = !el1_4_addr.isEVal(); el1_5_en = !el1_5_addr.isEVal(); el1_6_en = !el1_6_addr.isEVal();
	el2_1_en = !el2_1_addr.isEVal(); el2_2_en = !el2_2_addr.isEVal(); el2_3_en = !el2_3_addr.isEVal(); 
	el2_4_en = !el2_4_addr.isEVal(); el2_5_en = !el2_5_addr.isEVal(); el2_6_en = !el2_6_addr.isEVal();
	el3_1_en = !el3_1_addr.isEVal(); el3_2_en = !el3_2_addr.isEVal(); el3_3_en = !el3_3_addr.isEVal(); 
	el3_4_en = !el3_4_addr.isEVal(); el3_5_en = !el3_5_addr.isEVal(); el3_6_en = !el3_6_addr.isEVal();
	el4_1_en = !el4_1_addr.isEVal(); el4_2_en = !el4_2_addr.isEVal(); el4_3_en = !el4_3_addr.isEVal(); 
	el4_4_en = !el4_4_addr.isEVal(); el4_5_en = !el4_5_addr.isEVal(); el4_6_en = !el4_6_addr.isEVal();

	rows = new Array(	(el1_1_en||el1_2_en||el1_3_en||el1_4_en||el1_5_en||el1_6_en),
								(el2_1_en||el2_2_en||el2_3_en||el2_4_en||el2_5_en||el2_6_en),
								(el3_1_en||el3_2_en||el3_3_en||el3_4_en||el3_5_en||el3_6_en),
								(el4_1_en||el4_2_en||el4_3_en||el4_4_en||el4_5_en||el4_6_en));
  cols = new Array(	(el1_1_en||el2_1_en||el3_1_en||el4_1_en),
								(el1_2_en||el2_2_en||el3_2_en||el4_2_en),
								(el1_3_en||el2_3_en||el3_3_en||el4_3_en),
								(el1_4_en||el2_4_en||el3_4_en||el4_4_en),
								(el1_5_en||el2_5_en||el3_5_en||el4_5_en),
								(el1_6_en||el2_6_en||el3_6_en||el4_6_en));

	for(xScale = 0, i = 0; i < 6; i++) xScale += cols[i]; if(xScale) xScale = 6/xScale;
	for(yScale = 0, i = 0; i < 4; i++)	yScale += rows[i]; if(yScale) yScale = 4/yScale;
	xScale = yScale = min(xScale, yScale);

	if(xScale > 1)
		for(i = 1; i <= 4; i++) {
			for(j = 1; j <= 6; j++) this["wdg_el"+i+"_"+j].attrSet("geomXsc", xScale);
			this["wdg_el"+i+"_2"].attrSet("geomX", 3+150*xScale*cols[0]);
			this["wdg_el"+i+"_3"].attrSet("geomX", 3+150*xScale*(cols[0]+cols[1]));
			this["wdg_el"+i+"_4"].attrSet("geomX", 3+150*xScale*(cols[0]+cols[1]+cols[2]));
			this["wdg_el"+i+"_5"].attrSet("geomX", 3+150*xScale*(cols[0]+cols[1]+cols[2]+cols[3]));
			this["wdg_el"+i+"_6"].attrSet("geomX", 3+150*xScale*(cols[0]+cols[1]+cols[2]+cols[3]+cols[4]));
		}
	if(yScale > 1)
		for(j = 1; j <= 6; j++) {
			for(i = 1; i <= 4; i++) this["wdg_el"+i+"_"+j].attrSet("geomYsc", yScale);
			this["wdg_el2_"+j].attrSet("geomY", 30+142*yScale*rows[0]);
			this["wdg_el3_"+j].attrSet("geomY", 30+142*yScale*(rows[0]+rows[1]));
			this["wdg_el4_"+j].attrSet("geomY", 30+142*yScale*(rows[0]+rows[1]+rows[2]));
		}
}


ID: anShow1
PARENT: /wlb_originals/wdg_Box
ATTRS: perm;name;dscr;active;geomH;tipTool;evProc;backColor;bordWidth;bordColor;
ICO:

PROC:
JavaLikeCalc.JavaScript
var bordWidth_;
if(bordWidth_.isEVal())	bordWidth_ = bordWidth;
if(f_stop)	bordWidth = bordWidth_;
if(!pDscr.isEVal())
	tipTool = pDscr + ((!pErr.isEVal()&&pErr.toInt())?"\n"+tr("Error")+": "+pErr:"");
name_en = pName.length;
name_text = pName;
name_geomW = pNameSz;
val_arg0val = pVal;
val_font = "Arial 20 1 0 0 0";
if(!prec.isEVal()) val_arg0cfg = ((prec>=0)?";f;":";g;")+abs(prec);
if(pVal.isEVal()) {
	val_color = "grey";
	val_font = "Arial 20 0 1 0 1";
	alarm = "";
	pErrCode = 0;
	bordColor = "gray", bordWidth = bordWidth_;
	return;
}

//Notification create
if(!pErr.isEVal() && pErrCode != pErr) {
	pErrCode = pErr;
	alTp = (!spName.isEVal() && spName.length) ? 7 : 3;
	if(pErrCode == 1 || pErrCode == 2)	alarm = "100|"+pNAME+"||1";
	else if(pErrCode == 3)	alarm = "50|"+pNAME+"|"+spName+" "+tr("above alarm border")+".|"+alTp;
	else if(pErrCode == 4)	alarm = "50|"+pNAME+"|"+spName+" "+tr("bellow alarm border")+".|"+alTp;
	else if(pErrCode == 5)	alarm = "10|"+pNAME+"|"+spName+" "+tr("above warning border")+".|"+alTp;
	else if(pErrCode == 6)	alarm = "10|"+pNAME+"|"+spName+" "+tr("bellow warning border")+".|"+alTp;
	else if(pErrCode == 10) alarm = "10|"+pNAME+"|"+pErr.parse(1,":")+".|"+alTp;
	else if(pErrCode == 11) alarm = "50|"+pNAME+"|"+pErr.parse(1,":")+".|"+alTp;
	else if(alarmSt&0x100) alarm = "1|"+pNAME+"||1";
}
if(!pErrCode && alarmSt&0x100 && !(alarmSt&0x10000)) alarm = "";

//Notification color change
alarmLev = alarmSt&0xFF;
if(alarmLev && alarmSt&0x100) {
	blinkPr = true;
	if(!pErrCode || alarmLev <= 1) wColor = labColorGood;
	else if(alarmLev < 30)	wColor = labColorWarning;
	else if(alarmLev < 75)	wColor = labColorAlarm;
	else { wColor = "grey"; blinkPr = false; }
	if(blinkPr) val_color = (alarmSt&0x10000 && val_color == wColor) ? "grey" : wColor;
	else { 
		if(pErrCode == 1 || pErrCode == 2)	{ val_color = wColor; val_font = "Arial 20 0 1 0 1"; }
		else val_color = wColor;
	}
}
else val_color = labColorGood;

//Blink focused or linked with ElCadr
if(this.attr("focus") ||
	(!pNAME.isEVal() && pNAME.length && this.wdgAt("/s/pg_control/pg_ElCadr",true).attr("pgOpen") && this.wdgAt("/s/pg_control/pg_ElCadr",true).attr("prmShifr") == pNAME))
{
  bordColor = (bordColor == "silver") ? "grey" : "silver";
  bordWidth = 2;
}
else { bordColor = "grey"; bordWidth = bordWidth_; }


ID: cntrRegul
PARENT: /wlb_originals/wdg_Box
ATTRS: id;path;name;dscr;active;geomW;geomH;evProc;pgGrp;backColor;bordWidth;
ICO:

PROC:
JavaLikeCalc.JavaScript
txt_pnlTitle_arg0val = NAME;

if(f_start) clc = 0;
clc++;
if(clc == 3) event += "usr_ElCadr";
for(off = 0, ev_rez = ""; (ev_wrk=event.parse(0,"\n",off)).length; ) {
	if(ev_wrk == "ws_LnAccept:/kp") { SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'.Kp : "+DESCR+" : "+Kp+" : " +kp_value); Kp = kp_value; }
	else if(ev_wrk == "ws_LnAccept:/ki") { SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'.Ki : "+DESCR+" : "+Ki+" : " +ki_value); Ki = ki_value; }
	else if(ev_wrk == "ws_LnAccept:/ti") { SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'.Ti : "+DESCR+" : "+Ti/1000+" : " +ti_value); Ti = 1000*ti_value; }
	else if(ev_wrk == "ws_LnAccept:/kd") { SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'.Kd : "+DESCR+" : "+Kd+" : " +kd_value); Kd = kd_value; }
	else if(ev_wrk == "ws_LnAccept:/td") { SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'.Td : "+DESCR+" : "+Td/1000+" : " +td_value); Td = 1000*td_value; }
	else if(ev_wrk == "ws_LnAccept:/tzd") { SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'.Tzd : "+DESCR+" : "+Tzd+" : " +tzd_value); Tzd = 1000*tzd_value; }
	else if(ev_wrk == "ws_LnAccept:/zn") { SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'.Zn : "+DESCR+" : "+Zi+" : " +zn_value); Zi = zn_value; }
	else if(ev_wrk == "ws_LnAccept:/h1") { SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'.H1 : "+DESCR+" : "+Hdwn+" : " +h1_value); Hdwn = h1_value; }
	else if(ev_wrk == "ws_LnAccept:/h2") { SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'.H2 : "+DESCR+" : "+Hup+" : " +h2_value); Hup = h2_value; }
	else if(ev_wrk == "ws_LnAccept:/k1") { SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'.K1 : "+DESCR+" : "+K1+" : " +k1_value); K1 = k1_value; }
	else if(ev_wrk == "ws_LnAccept:/k2") { SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'.K2 : "+DESCR+" : "+K2+" : " +k2_value); K2 = k2_value; }
	else if(ev_wrk == "ws_LnAccept:/k3") { SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'.K3 : "+DESCR+" : "+K3+" : " +k3_value); K3 = k3_value; }
	else if(ev_wrk == "ws_LnAccept:/k4") { SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'.K4 : "+DESCR+" : "+K4+" : " +k4_value); K4 = k4_value; }
	else if(ev_wrk == "ws_LnAccept:/tiPer") { SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'.TImpPer : "+DESCR+" : "+TImpPer/1000+" : " +tiPer_value); TImpPer = 1000*tiPer_value; }
	else if(ev_wrk == "ws_LnAccept:/tiMin") { SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'.TImpMin : "+DESCR+" : "+TImpMin/1000+" : " +tiMin_value); TImpMin = 1000*tiMin_value; }    
	else if(ev_wrk == "ws_LnAccept:/rfct") { SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'.KImpRfact : "+DESCR+" : "+KImpRfact+" : " +rfct_value); KImpRfact = rfct_value; }
	else ev_rez += ev_wrk+"\n";
}
event = ev_rez;

kp_value = (kp_active=!Kp.isEVal()) ? Kp : 0;
ki_value = (ki_active=!Ki.isEVal()) ? Ki : 0;
ti_value = (ti_active=!Ti.isEVal()) ? Ti/1000 : 0;
kd_value = (kd_active=!Kd.isEVal()) ? Kd : 0;
td_value = (td_active=!Td.isEVal()) ? Td/1000 : 0;
tzd_value = (tzd_active=!Tzd.isEVal()) ? Tzd/1000 : 0;
zn_value = (zn_active=!Zi.isEVal()) ? Zi : 0;
h1_value = (h1_active=!Hdwn.isEVal()) ? Hdwn : 0;
h2_value = (h2_active=!Hup.isEVal()) ? Hup : 0;
k1_value = (k1_active=!K1.isEVal()) ? K1 : 0;
k2_value = (k2_active=!K2.isEVal()) ? K2 : 0;
k3_value = (k3_active=!K3.isEVal()) ? K3 : 0;
k4_value = (k4_active=!K4.isEVal()) ? K4 : 0;
tiPer_value = (tiPer_active=!TImpPer.isEVal()) ? TImpPer/1000 :0;
tiMin_value = (tiMin_active=!TImpMin.isEVal()) ? TImpMin/1000 : 0;
rfct_value = (rfct_active=!KImpRfact.isEVal()) ? KImpRfact : 0;

doc_tmpl = "<body bgcolor='"+backColor+"'><table style='color: "+labColor+"' border='1' cellpadding='1' cellspacing='0' width='100%'>\n";
doc_tmpl += "<tr><td>"+tr("Id")+":</td><td>"+(SHIFR.isEVal()?"":SYS.strEncode(SHIFR,"HTML"))+"</td></tr>\n";
doc_tmpl += "<tr><td>"+tr("Name")+":</td><td>"+(NAME.isEVal()?"":SYS.strEncode(NAME,"HTML"))+"</td></tr>\n";
doc_tmpl += "<tr><td>"+tr("Description")+":</td><td>"+(DESCR.isEVal()?"":SYS.strEncode(DESCR,"HTML"))+"</td></tr>\n";
doc_tmpl += "<tr><td>"+tr("Dimension")+":</td><td>"+(ed.isEVal()?"":SYS.strEncode(ed,"HTML"))+"</td></tr>\n";
doc_tmpl += "<tr><td>"+tr("Setpoint")+":</td><td>"+(trnd_prm1val.isEVal()?"":(prec.isEVal()?trnd_prm1val:trnd_prm1val.toFixed(prec)));
doc_tmpl += ((trnd_prm1val.isEVal() || max.isEVal() || min.isEVal() || max == min)?"":("("+(100*(trnd_prm1val-min)/(max-min).toFixed(1))+"%)"))+"</td></tr>\n";
doc_tmpl += "<tr><td>"+tr("Variable")+":</td><td>"+(trnd_prm2val.isEVal()?"":(prec.isEVal()?trnd_prm2val:trnd_prm2val.toFixed(prec)));
doc_tmpl += ((trnd_prm2val.isEVal() || max.isEVal() || min.isEVal() || max == min)?"":("("+(100*(trnd_prm2val-min)/(max-min).toFixed(1))+"%)"))+"</td></tr>\n";
doc_tmpl += "<tr><td>"+tr("Output")+":</td><td>"+(trnd_prm0val.isEVal()?"":trnd_prm0val.toFixed(1)+"%")+"</td></tr>\n";
doc_tmpl += "<tr><td>"+tr("Scale")+":</td><td>"+(min.isEVal()?"":min)+" ... "+(max.isEVal()?"":max)+"</td></tr>\n";
doc_tmpl += "<tr><td>"+tr("Mode")+":</td><td>"+(trnd_prm3val.isEVal()?" - ":(trnd_prm3val?tr("Automate"):tr("Manual")))+"</td></tr>\n";
doc_tmpl += "</table></body>";

//Diagram
trnd_prm0addr = out_addr;
trnd_prm1addr = sp_addr;
trnd_prm1bordL = min;
trnd_prm1bordU = max;
trnd_prm2addr = var_addr;
trnd_prm2bordL = min;
trnd_prm2bordU = max;
trnd_prm3addr = auto_addr;
trnd_prm4addr = impQup_addr;
trnd_prm5addr = impQdwn_addr;


ID: ResultGraph
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;geomW;geomH;backColor;bordWidth;
ICO:

PROC:
JavaLikeCalc.JavaScript
name_arg0val = grpName.isEVal() ? "" : grpName;

if(f_start) {
	rows = new Array();
	cols = new Array();
	for(i = 0; i < 4; i++) {
		rows[i] = this["wdg_e"+(1+i)].attr("en") || this["wdg_e"+(5+i)].attr("en") || this["wdg_e"+(9+i)].attr("en") || this["wdg_e"+(13+i)].attr("en");
		cols[i] = this["wdg_e"+(1+i*4)].attr("en") || this["wdg_e"+(2+i*4)].attr("en") || this["wdg_e"+(3+i*4)].attr("en") || this["wdg_e"+(4+i*4)].attr("en");
	}

	for(xScale = 0, i = 0; i < 4; i++) xScale += cols[i]; if(xScale) xScale = 4/xScale;
	for(yScale = 0, i = 0; i < 4; i++) yScale += rows[i]; if(yScale) yScale = 4/yScale;
	xScale = yScale = min(xScale, yScale);

	if(xScale > 1)
		for(i = 1; i <= 4; i++) {
			for(j = 1; j <= 4; j++) this["wdg_e"+((i-1)*4+j)].attrSet("geomXsc", xScale);
			this["wdg_e"+(4+i)].attrSet("geomX", 1+224*xScale*cols[0]);
			this["wdg_e"+(8+i)].attrSet("geomX", 1+224*xScale*(cols[0]+cols[1]));
			this["wdg_e"+(12+i)].attrSet("geomX", 1+224*xScale*(cols[0]+cols[1]+cols[2]));
		}
	if(yScale > 1)
		for(j = 1; j <= 4; j++) {
			for(i = 1; i <= 4; i++) this["wdg_e"+((i-1)*4+j)].attrSet("geomYsc", yScale);
			this["wdg_e"+(2+4*(j-1))].attrSet("geomY", 30+142*yScale*rows[0]);
			this["wdg_e"+(3+4*(j-1))].attrSet("geomY", 30+142*yScale*(rows[0]+rows[1]));
			this["wdg_e"+(4+4*(j-1))].attrSet("geomY", 30+142*yScale*(rows[0]+rows[1]+rows[2]));
		}
}


ID: ResultGraphEl
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;en;geomW;geomH;backColor;bordWidth;bordColor;bordStyle;
ICO:

PROC:
JavaLikeCalc.JavaScript
en = !p1_addr.isEVal() || !p2_addr.isEVal() || !p3_addr.isEVal() || !p4_addr.isEVal() || !p5_addr.isEVal();
title_text = title.isEVal() ? "" : title;

p1_text = p1_name.isEVal() ? "" : p1_name; p1_color = p1_clr;
p2_text = p2_name.isEVal() ? "" : p2_name; p2_color = p2_clr;
p3_text = p3_name.isEVal() ? "" : p3_name; p3_color = p3_clr;
p4_text = p4_name.isEVal() ? "" : p4_name; p4_color = p4_clr;
p5_text = p5_name.isEVal() ? "" : p5_name; p5_color = p5_clr;

trnd_prm0addr = p1_addr; trnd_prm0bordL = p1_min; trnd_prm0bordU = p1_max; trnd_prm0color = p1_clr;
trnd_prm1addr = p2_addr; trnd_prm1bordL = p2_min; trnd_prm1bordU = p2_max; trnd_prm1color = p2_clr;
trnd_prm2addr = p3_addr; trnd_prm2bordL = p3_min; trnd_prm2bordU = p3_max; trnd_prm2color = p3_clr;
trnd_prm3addr = p4_addr; trnd_prm3bordL = p4_min; trnd_prm3bordU = p4_max; trnd_prm3color = p4_clr;
trnd_prm4addr = p5_addr; trnd_prm4bordL = p5_min; trnd_prm4bordU = p5_max; trnd_prm4color = p5_clr;


ID: doc_panel
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;geomW;geomH;pgGrp;backColor;bordWidth;bordColor;
ICO:

PROC:
JavaLikeCalc.JavaScript
curTm = SYS.time();
if(n == 0 && !time) { time = curTm; bTime = time - 30; }
size_en = tmTp_en = Text1_en = Text2_en = prev1_en = next1_en = date_en = dateBeg_en = !n;
szVal = time - bTime;

//Archive size
if(n) {
	if(vCur >= 0)	cPos = aCur - vCur;
	if(cPos < 0)		cPos += aSize;
	Text3_text = Text3_text.parse(0,"\n") + "\n" + (cPos+1) + "(" + aSize + ")";
}
else Text3_text = Text3_text.parse(0,"\n");

//Events process
prevTime = time;
for(off = 0, ev_rez = ""; (ev_cur=event.parse(0,"\n",off)).length; ) {
	//SYS.messInfo("Trend control","Event: "+ev_cur);
	if(ev_cur == "ws_LnAccept:/size" || ev_cur == "ws_CombChange:/tmTp") {
		szVal = size_value;
		if(tmTp_value == tr("m"))			szVal = szVal*60;
		else if(tmTp_value == tr("h"))	szVal = szVal*60*60;
		else if(tmTp_value == tr("d"))	szVal = szVal*24*60*60;
		else if(tmTp_value.search("\\d+"+tr("s")) >= 0)	szVal = tmTp_value.toInt();
		else if(tmTp_value.search("\\d+"+tr("m")) >= 0)	szVal = tmTp_value.toInt()*60;
		else if(tmTp_value.search("\\d+"+tr("h")) >= 0)	szVal = tmTp_value.toInt()*60*60;
		else if(tmTp_value.search("\\d+"+tr("d")) >= 0)	szVal = tmTp_value.toInt()*24*60*60;
		time += 1;
	}
	else if(ev_cur == "ws_LnAccept:/dateBeg") { szVal = max(1, date_value-dateBeg_value); time += 1; }
	else if(ev_cur == "ws_LnAccept:/date") time = min(curTm, max(szVal,date_value));
	else if(ev_cur == "ws_BtPress:/curtime") {	
		if(n == 0) time = curTm;
		else vCur = aCur;
	}
	else if(ev_cur == "ws_BtPress:/prev") {
		if(n == 0) time = min(curTm, max(szVal,time-szVal));
		else vCur = -2;
	}
	else if(ev_cur == "ws_BtPress:/next") {
		if(n == 0) time = min(curTm, max(szVal,time+szVal)); 
		else vCur = -1;
	}
	else if(ev_cur == "ws_BtPress:/prev1") time = min(curTm, max(5*szVal,time-5*szVal));
	else if(ev_cur == "ws_BtPress:/next1") time = min(curTm, max(5*szVal,time+5*szVal));
	else ev_rez += (ev_cur+"\n");
}
event = ev_rez;

//Time control
date_value = time;
if(n == 0 && prevTime != time) { bTime = time - szVal; doc=""; }
if(szVal < 60)						{ tmTp_value = tr("s"); size_value = szVal; }
else if(szVal < 60*60)			{ tmTp_value = tr("m"); size_value = szVal/60; }
else if(szVal < 24*60*60)	{ tmTp_value = tr("h"); size_value = szVal/(60*60); }
else									{ tmTp_value = tr("d"); size_value = szVal/(24*60*60); }
dateBeg_value = date_value - szVal;


ID: terminator
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;geomW;geomH;pgGrp;backColor;bordWidth;
ICO:


ID: grph_panel
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;geomW;geomH;pgGrp;backColor;bordWidth;
ICO:

PROC:
JavaLikeCalc.JavaScript
curTm = SYS.time();
tSek = tSek ? tSek : curTm;

//Archivators real list forming
if(f_start) {
	arch_items = tr("All");
	mods = SYS.Archive.nodeList("mod_");
	for(i_m = 0; i_m < mods.length; i_m++) {
		vas = SYS.Archive[mods[i_m]].nodeList("val_");
		for(i_va = 0; i_va < vas.length; i_va++)
			arch_items += "\n"+mods[i_m].slice(4)+"."+vas[i_va].slice(4);
	}
}

//Events process
for(/*ev_rez = "", */off = 0; (ev_cur=event.parse(0,"\n",off)).length; ) {
	//SYS.messInfo("Trend control", "Event: "+ev_cur);
	if(ev_cur == "ws_LnAccept:/size" || ev_cur == "ws_CombChange:/tmTp") {
		tSzPrev = tSize;
		tSize = size_value;
		if(tmTp_value == tr("m"))			tSize = tSize*60;
		else if(tmTp_value == tr("h"))	tSize = tSize*60*60;
		else if(tmTp_value == tr("d"))	tSize = tSize*24*60*60;
		else if(tmTp_value.search("\\d+"+tr("s")) >= 0)	tSize = tmTp_value.toInt();
		else if(tmTp_value.search("\\d+"+tr("m")) >= 0)	tSize = tmTp_value.toInt()*60;
		else if(tmTp_value.search("\\d+"+tr("h")) >= 0)	tSize = tmTp_value.toInt()*60*60;
		else if(tmTp_value.search("\\d+"+tr("d")) >= 0)	tSize = tmTp_value.toInt()*24*60*60;
		//if(tSize < tSzPrev && curSek < tSek && curSek > (tSek-tSzPrev)) tSek = curSek;
	}
	else if(ev_cur == "ws_LnAccept:/dateBeg")	{
		tSzPrev = tSize; tSize = max(1, date_value-dateBeg_value);
		//if(tSize < tSzPrev && curSek < tSek && curSek > (tSek-tSzPrev)) tSek = curSek;
	}
	else if(ev_cur == "ws_LnAccept:/date")		{ tSek = date_value; if(sclWin == true) sclWin = false; }
	else if(ev_cur == "ws_BtPress:/curtime")	{ tSek = curSek = curTm; if(sclWin == true) sclWin = false; }
	else if(ev_cur == "ws_BtPress:/curstime")	{ tSek = curSek; if(sclWin == true) sclWin = false; }
	else if(ev_cur == "ws_BtPress:/prev")		{ tSek -= tSize/2; if(sclWin == true) sclWin = false; }
	else if(ev_cur == "ws_BtPress:/prev1")		{ tSek -= 5*tSize; if(sclWin == true) sclWin = false; }
	else if(ev_cur == "ws_BtPress:/next")		{ tSek += tSize/2; if(sclWin == true) sclWin = false; }
	else if(ev_cur == "ws_BtPress:/next1")		{ tSek += 5*tSize; if(sclWin == true) sclWin = false; }
	else if(ev_cur == "ws_CombChange:/arch")	valArch=(arch_value==tr("All")) ? "" : arch_value;
	else if(ev_cur == "ws_CombChange:/type")	{ type = (type_value==tr("Spectrum"))?1:((type_value==tr("XY"))?2:0); if(sclWin == true) sclWin = false; }
	else if(ev_cur == "ws_BtPress:/zoomIn")		{ sclVer *= 0.9; if(sclWin == true) sclWin = false; }
	else if(ev_cur == "ws_BtPress:/zoomOut")	{ sclVer *= 1.1; if(sclWin == true) sclWin = false; }
	else if(ev_cur == "ws_BtPress:/zoomOffUp")	{ sclVerOff += sclVer/10; if(sclWin == true) sclWin = false; }
	else if(ev_cur == "ws_BtPress:/zoomOffDown")	{ sclVerOff -= sclVer/10; if(sclWin == true) sclWin = false; }
	else if(ev_cur == "ws_BtPress:/zoomDef")	{ sclVer = 100, sclVerOff = 0; if(sclWin == true) sclWin = false; }
	else if(ev_cur == "ws_BtPress:/xZoomIn")	sclHor *= 0.9;
	else if(ev_cur == "ws_BtPress:/xZoomOut")	sclHor *= 1.1;
	else if(ev_cur == "ws_BtPress:/xZoomOffRight")sclHorOff += sclHor/10;
	else if(ev_cur == "ws_BtPress:/xZoomOffLeft") sclHorOff -= sclHor/10;
	else if(ev_cur == "ws_BtPress:/xZoomDef")	sclHor = 100, sclHorOff = 0;
	else if(ev_cur == "ws_BtToggleChange:/selWin") {
		if(selWin_value && !sclWinCtx.isEVal()) {
			sclWinCtx.tSek = tSek; sclWinCtx.tSize = tSize; sclWinCtx.sclVer = sclVer; sclWinCtx.sclVerOff = sclVerOff; }
		else if(!selWin_value && !sclWinCtx.isEVal() && !sclWinCtx.tSek.isEVal()) {
			tSek = sclWinCtx.tSek; tSize = sclWinCtx.tSize; sclVer = sclWinCtx.sclVer; sclVerOff = sclWinCtx.sclVerOff; }
		sclWin = selWin_value;
	}
	//else ev_rez += (ev_cur+"\n");
}
event = "";//ev_rez;

//scaleInfo
scaleInfo_arg0val = 1e4/sclVer; scaleInfo_arg1val = sclVerOff;
xScaleInfo_arg0val = 1e4/sclHor; xScaleInfo_arg1val = sclHorOff;

//Trend time control
date_value = tSek;
if(tSek < curTm) trcPer = 0; else trcPer = 1, tSek = 0;
if(tSize < 60)						tmTp_value = tr("s"), size_value = tSize;
else if(tSize < 60*60)			tmTp_value = tr("m"), size_value = tSize/60;
else if(tSize < 24*60*60)	tmTp_value = tr("h"), size_value = tSize/(60*60);
else									tmTp_value = tr("d"), size_value = tSize/(24*60*60);
dateBeg_value = date_value - tSize;

arch_value = valArch.length ? valArch : tr("All");
cursor_en = !curSek.isEVal() && type != 2;
if(cursor_en && type == 0) cursor_arg0val = SYS.strftime(curSek,"%d.%m.%Y %H:%M:%S") + ((curUSek && (tSize/1000) < 1)?"."+curUSek:"");
if(cursor_en && type == 1) cursor_arg0val = tr("Frequency")+":\n"+(1e6/(1e6*curSek+curUSek)).toFixed(2)+" "+tr("Hz");
type_value = (type==1)?tr("Spectrum"):((type==2)?tr("XY"):tr("Graph"));
xScaleInfo_en = xZoomIn_en = xZoomOut_en = xZoomOffRight_en = xZoomOffLeft_en = xZoomDef_en = (type==2);
selWin_en = (type == 0 && !sclWin.isEVal());
if(selWin_en)	selWin_value = sclWin;


ID: cntrPasp
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;geomW;geomH;pgGrp;backColor;bordWidth;bordColor;bordStyle;
ICO:

PROC:
JavaLikeCalc.JavaScript
//if(f_start) focus = true;
//if(focus) SYS.messInfo("TEST","TEST 00");

wLst = aLst = EVAL_REAL;
pwName = pName;
pwName = pwName.slice(0,pwName.lastIndexOf("/"));
req = SYS.XMLNode("info").setAttr("path", pwName+"/%2fval");
doc_tmpl = "<body><table border='1' cellpadding='2' cellspacing='0' width='100%'>";
if(SYS.cntrReq(req) == 0 && req.childSize()) {
	chldRoot = req.childGet(0);
	for(i = 0; i < chldRoot.childSize(); i++) {
		aID = chldRoot.childGet(i).attr("id");
		aDscr = chldRoot.childGet(i).attr("dscr");
		reqVl = SYS.XMLNode("get").setAttr("path", pwName+"/%2fval%2f"+aID);
		SYS.cntrReq(reqVl);
		aVl = reqVl.text();

		//Filter
		if(aID == "com" || aID == "close" || aID == "stop" || aVl.isEVal()) continue;
		if(aID == "aMax" || aID == "aMin") {
			if(aLst.isEVal()) { aLst = aVl; continue; }
			aDscr = tr("Alarm border");
			if(aID == "aMax" && aLst < aVl)			aVl = "" + aLst + " ... " + aVl;
			else if(aID == "aMin" && aLst > aVl)	aVl = "" + aVl + " ... " + aLst;
			else aVl = tr("not set");
		}
		else if(aID == "wMax" || aID == "wMin") {
			if(wLst.isEVal()) { wLst = aVl; continue; }
			aDscr = tr("Warning border");
			if(aID == "wMax" && wLst < aVl)			aVl = "" + wLst + " ... " + aVl;
			else if(aID == "wMin" && wLst > aVl)	aVl = ""+aVl+" ... "+wLst;
			else aVl = tr("not set");
		}
		//Put record
		doc_tmpl += "<tr><td>"+SYS.strEncode(aDscr,"HTML")+"</td><td>"+SYS.strEncode(aVl,"HTML")+"</td></tr>\n";
	}
}
doc_tmpl += "</table></body>";


ID: ElViewGraph
PARENT: /wlb_originals/wdg_Box
ICO:

PROC:
JavaLikeCalc.JavaScript
var user_;
if(f_start)	{
	colorDef_ = color_ = "";
	allowSel = this.ownerWdg(true).attr("allowSelLst").length;
	perUserSel = this.ownerWdg(true).attr("perUserSel");
}
if(colorDef_ != colorDef)	color = colorDef_ = colorDef;
user = (perUserSel == true) ? this.ownerSess().user() : "";
if(f_start || user != user_) { loadFromSess = false; user_ = user; }
en = enForce || !name.isEVal();
if(allowSel && ((en && name.isEVal()) || !loadFromSess)) {
	//Load stored session's assignments
	loadOK = false;
	if(!loadFromSess) {
		for(off = 0; (lnA="addr;name;dscr;min;max;ed;log;prec;aMax;aMin;wMax;wMin;pModeA;pModeC;color".parse(0,";",off)).length; )
			if(lnA == "color") {
				if((tVl=this.attr(user+lnA,true)).length)	color = tVl;
			}
			else {
				if(!f_start) this.linkSet(lnA, "");
				if((wA=this.attr(user+lnA,true)).length) { this.linkSet(lnA, wA); loadOK = true; }
			}
		//if((cVal=this.attr("color",true)).length) this.color = cVal;
		loadFromSess = true;
	}
	if(!loadOK)	name = tr("<No selected>");
}
lb_sfr_text = name;
if(varEl.isEVal()) lb_val_arg0val = "-";
else if(!digStts.isEVal() && digStts.length) lb_val_arg0val = (varEl^digRevers) ? digStts.parse(0,";").parse(0,"-") : digStts.parse(1,";").parse(0,"-");
else lb_val_arg0val = prec.isEVal() ? varEl.toPrecision(6) : ((prec < 0) ? varEl.toPrecision(abs(prec)) : ((log==true)?varEl.toExponential(prec):varEl.toFixed(prec)));
lb_val_color = lb_sfr_color = lb_ed_color = labColorGood;
if(varEl.isEVal() || (!min.isEVal() && max > min && varEl < min) || (!max.isEVal() && max > min && varEl > max)) lb_val_color = lb_sfr_color = lb_ed_color =  "grey";
else if(!aMax.isEVal() && !aMin.isEVal() && aMax > aMin && (varEl >= aMax || varEl <= aMin)) lb_val_color = lb_sfr_color = lb_ed_color =  labColorAlarm;
else if(!wMax.isEVal() && !wMin.isEVal() && wMax > wMin && (varEl >= wMax || varEl <= wMin)) lb_val_color = lb_sfr_color = lb_ed_color =  labColorWarning;

lb_ed_text = ed.isEVal() ? "" : ed;

//Blink focused or linked with ElCadr
if(this.attr("focus") ||
		(!name.isEVal() && name.length && this.wdgAt("/s/pg_control/pg_ElCadr",true).attr("pgOpen") && this.wdgAt("/s/pg_control/pg_ElCadr",true).attr("prmShifr") == name))
{
  bordColor = (bordColor == "silver") ? "gray" : "silver";
  bordWidth =  2;
}
else { bordWidth =  1; bordColor = "black"; }

//Check the regulator mode
if(!enMode.isEVal() && enMode) { 
  mode_en = true; 
  if(!pModeC.isEVal() && pModeC) mode_text = tr("C");
  else mode_text = pModeA.isEVal() ? "" : ((pModeA) ? tr("A") : tr("M")); 
}
else mode_en = false;

//Events process
toSave = false;
for(evRez = "", off = 0; (evCur=event.parse(0,"\n",off)).length; ) {
	//this.messInfo("Event: "+evCur);
	if(evCur == "key_mouseDblClick" || evCur == "usr_hideshow") bordStyle = (bordStyle==1) ? 3 : 1;
	//Store session's assignments
	else if(evCur == "usr_set")	toSave = true;
	else evRez += evCur+"\n";
}
event = evRez;

if(toSave || (f_start && allowSel && !loadOK)) {
	for(off = 0; (lnA="addr;name;dscr;min;max;log;ed;prec;aMax;aMin;wMax;wMin;pModeA;pModeC;color".parse(0,";",off)).length; )
		if(lnA == "color")	this.attrSet(user+lnA, color, true);
		else this.attrSet(user+lnA, this.link(lnA), true);
}

if(!color_.length)	color_ = color;
if(bordStyle == 1 && color != "-")			color_ = color, color = "-";
else if(bordStyle != 1 && color == "-")	color = color_;
trClr_lineClr = (color.length && color != "-") ? color : "gray";

tipTool = "";
if(!name.isEVal())	tipTool += tr("Name")+": "+name+"\n";
if(!min.isEVal() && !max.isEVal() && max > min) tipTool += tr("Scale")+": "+min+" ... "+max+"\n";
if(!aMin.isEVal() && !aMax.isEVal() && aMax > aMin) tipTool += tr("Alarm border")+": "+aMin+" ... "+aMax+"\n";
if(!wMin.isEVal() && !wMax.isEVal() && wMax > wMin) tipTool += tr("Warning border")+": "+wMin+" ... "+wMax+"\n";
if(!dscr.isEVal()) {
	tipTool += tr("Description")+": "+dscr+"\n";
	tipStatus = dscr;
}

ATTRS:
path;perm;name;dscr;en;active;geomW;geomH;tipTool;tipStatus;contextMenu;evProc;backColor;bordWidth;bordColor;bordStyle;


ID: prescrEdit
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;geomW;geomH;evProc;pgGrp;backColor;bordWidth;bordColor;bordStyle;
ICO:

PROC:
JavaLikeCalc.JavaScript
if(f_start) save_active = false;
progLbUpdt = progSelPrg = progSelCom = progSelTp = false;
var comOp = "";

//Events for commands process
for(ev_rez = "", off = 0; (ev_cur=event.parse(0,"\n",off)).length; ) {
	//SYS.messInfo(this.nodePath(),"Event: "+ev_cur);
	if(ev_cur == "ws_BtPress:/progAdd") {
		if(!progNm_value.length) progNm_value = tr("New program");
		SYS.BD.nodeAt(dbDB,".").SQLReq("INSERT INTO "+dbProgs+" (name) VALUES ('"+progNm_value+"');");
		lib_value = progNm_value;
		progLbUpdt = progSelPrg = progSelCom = true; prog_value = "";
	}
	else if(ev_cur == "ws_BtPress:/progCopy") {
		if(!progNm_value.length) progNm_value = tr("New program");
		rez = SYS.BD.nodeAt(dbDB,".").SQLReq("SELECT prgTxt FROM "+dbProgs+" WHERE name='"+lib_value+"';");
		if(rez.length > 1) {
			SYS.BD.nodeAt(dbDB,".").SQLReq("INSERT INTO "+dbProgs+" (name, prgTxt) VALUES ('"+progNm_value+"', '"+rez[1][0].replace("'","''")+"');");
			lib_value = progNm_value;
			progLbUpdt = progSelPrg = progSelCom = true; prog_value = "";
		}
	}
	else if(ev_cur == "ws_BtPress:/progRename") {
		SYS.BD.nodeAt(dbDB,".").SQLReq("UPDATE "+dbProgs+" SET name='"+progNm_value+"' WHERE name='"+lib_value+"';");
		lib_value = progNm_value;
		progLbUpdt = progSelPrg = progSelCom = true; prog_value = "";
	}
	else if(ev_cur == "dlg_Apply:/progDel" && lib_value.length) {
	//else if(ev_cur == "ws_BtPress:/progDel" && lib_value.length) {
		SYS.BD.nodeAt(dbDB,".").SQLReq("DELETE FROM "+dbProgs+" WHERE name='"+lib_value+"';");
		lib_value = "";
		progLbUpdt = progSelPrg = true;
	}
	else if(ev_cur == "ws_TreeChange:/lib")	{ progSelPrg = progSelCom = true; prog_value = ""; }
	else if(ev_cur == "ws_BtPress:/comAdd")	comOp = "add";
	else if(ev_cur == "ws_BtPress:/comIns")	comOp = "ins";
	else if(ev_cur == "ws_BtPress:/comInAdd")	comOp = "inAdd";
	else if(ev_cur == "ws_BtPress:/comDel") comOp = "del";
	else if(ev_cur == "ws_BtPress:/comUp")	comOp = "up";
	else if(ev_cur == "ws_BtPress:/comDwn") comOp = "dwn";
	else if(ev_cur == "ws_TreeChange:/prog"){ progSelCom = true; save_active = false; }
	else if(ev_cur == "ws_CombChange:/type"){ progSelTp = true; save_active = true; }
	else if(ev_cur == "ws_BtPress:/save" && prog_value.length) {
		rez = SYS.BD.nodeAt(dbDB,".").SQLReq("SELECT prgTxt FROM "+dbProgs+" WHERE name='"+lib_value+"';");
		if(rez.length > 1) {
			comTree = selNd = SYS.XMLNode("prg"); comTree.load(rez[1][0]);
			parentPath = "";
			for(offPV = 0; (vIt=prog_value.parsePath(0,offPV)).length; ) {
				if(offPV < prog_value.length) parentPath += "/"+vIt;
				selNd = selNd.childGet((i_c=vIt.toInt()));
			}
			if(selNd) {
				selNd.setAttr("id", type_value);
				selNd.setAttr("name", name_value);
				selNd.setAttr("descr", descr_value);
				selNd.setAttr("backgrnd", backgrnd_value);
				for(i_a = 1; i_a <= 5; i_a++) {
					argObj = this["arg"+i_a];
					argVal = argObj.attr("value");
					if(!argObj.attr("min").isEVal()) argVal = max(argVal,argObj.attr("min"));
					if(!argObj.attr("max").isEVal()) argVal = min(argVal,argObj.attr("max"));
					selNd.setAttr("arg"+i_a, argVal);
				}
				SYS.BD.nodeAt(dbDB,".").SQLReq("UPDATE "+dbProgs+" SET prgTxt='"+comTree.save().replace("'","''")+"' WHERE name='"+lib_value+"';");
				prog_value = parentPath+"/"+i_c+":"+(name_value.length?name_value:type_value);
				//SYS.messInfo(this.nodePath(),"prog_value: "+prog_value);
				progSelPrg = true;
			}
		}
		save_active = false;
	}
	else if(ev_cur == "ws_BtPress:/progExport" && lib_value.length) {
		rez = SYS.BD.nodeAt(dbDB,".").SQLReq("SELECT prgTxt FROM "+dbProgs+" WHERE name='"+lib_value+"';");
		if(rez.length > 1) {
			expTree = SYS.XMLNode("OpenSCADA_Prescr");
			expTree.childAdd("prg").load(rez[1][0]);
			expTree.childGet(0).setAttr("id",lib_value);
			progExport_value = tr("Prescription-Program")+" (*.prscr)|"+tr("Prescription file")+"|"+lib_value.replace("/","_")+".prscr\n"+expTree.save(0x05);
		}
	} 
	//else if(ev_cur == "ws_BtPress:/progImport")
	else if(ev_cur == "ws_BtLoad:/progImport" && progImport_value.length && (pCtx=progImport_value.indexOf("\n")) > 0)
	{
		expTree = SYS.XMLNode("OpenSCADA_Prescr");
		expTree.load(progImport_value.slice(pCtx+1));
		progImport_value = progImport_value.slice(0,pCtx);
		// Save all recors to DB
		for(i_p = 0; i_p < expTree.childSize(); i_p++) {
			treeNd = expTree.childGet(i_p);
			if(treeNd.name() != "prg") continue;
			if(lib_items.search(treeNd.attr("id")+"(\n|\\z)") < 0)
				SYS.BD.nodeAt(dbDB,".").SQLReq("INSERT INTO "+dbProgs+" (name,prgTxt) VALUES ('"+treeNd.attr("id")+"','"+treeNd.save().replace("'","''")+"');");
			else
				SYS.BD.nodeAt(dbDB,".").SQLReq("UPDATE "+dbProgs+" SET prgTxt='"+treeNd.save().replace("'","''")+"' WHERE name='"+treeNd.attr("id")+"';");	
		}
		progLbUpdt = progSelPrg = progSelCom = true;
	}
	else if(ev_cur == "ws_LnAccept:/name" || ev_cur == "ws_TxtAccept:/descr" || ev_cur == "ws_ChkChange:/backgrnd" || (rez=ev_cur.match("ws_LnAccept:\\/arg(\\d)")).length)	save_active = true;
	else if((rez=ev_cur.match("ws_FocusOut:\\/arg(\\d)")).length) {
		argObj = this["arg"+rez[1]];
		argVal = argObj.attr("value");
		if(!argObj.attr("min").isEVal()) argVal = max(argVal,argObj.attr("min"));
		if(!argObj.attr("max").isEVal()) argVal = min(argVal,argObj.attr("max"));
		argObj.attrSet("value",argVal);
	}
	else ev_rez += (ev_cur+"\n");
}
event = ev_rez;

//Get programms into library list
if(f_start || progLbUpdt) {
	rez = SYS.BD.nodeAt(dbDB,".").SQLReq("SELECT name FROM "+dbProgs+";");
	lib_items = "";
	for(i_p = 1; i_p < rez.length; i_p++)
		lib_items += ((i_p==1)?"":"\n")+rez[i_p][0];
	lib_items = lib_items.split("\n").sort().join("\n");
	progNm_cfg = lib_items;
}
progCopy_active = progRename_active = progDel_active = progExport_active = comAdd_active = lib_value.length;

//Command operations process
if(comOp.length && lib_value.length) {
	rez = SYS.BD.nodeAt(dbDB,".").SQLReq("SELECT prgTxt FROM "+dbProgs+" WHERE name='"+lib_value+"';");
	if(rez.length > 1) {
		comTree = selNd = SYS.XMLNode("prg");
		comTree.load(rez[1][0]);
		parentPath = "";
		if(prog_value.length) {
			for(offPV = 0; (vIt=prog_value.parsePath(0,offPV)).length; ) {
				if(offPV < prog_value.length) parentPath += "/"+vIt;
				selNd = selNd.childGet((i_c=vIt.toInt()));
			}
			selNd = selNd.parent();
		}
		if(comOp == "add") {
			selNd.childAdd("com").setAttr("id",tr("New command"));
			prog_value = parentPath+"/"+(selNd.childSize()-1)+":"+tr("New command");
		}
		else {
			// Get selected command node and position
			if(i_c < selNd.childSize()) {
				if(comOp == "inAdd") {
					selNd.childGet(i_c).childAdd("com").setAttr("id",tr("New command"));
					prog_value = parentPath+"/"+i_c+":"+selNd.childGet(i_c).attr("id")+"/"+(selNd.childGet(i_c).childSize()-1)+":"+tr("New command");
				}
				else if(comOp == "ins") {
					selNd.childIns(i_c,"com").setAttr("id",tr("New command"));
					prog_value = parentPath+"/"+i_c+":"+tr("New command");
				}
				else if(comOp == "del") {
					selNd.childDel(i_c);
					if(!selNd.childSize())	prog_value = parentPath;
					else {
						if(i_c >= selNd.childSize()) i_c = selNd.childSize()-1;
						prog_value = parentPath+"/"+i_c+":"+selNd.childGet(i_c).attr("id");
					}
				}
				else if((comOp == "up" && i_c) || (comOp == "dwn" && i_c < (selNd.childSize()-1))) {
					storeNd = selNd.childGet(i_c);
					selNd.childDel(i_c);
					if(comOp == "up") i_c--; else i_c++;
					selNd.childIns(i_c,storeNd);
					prog_value = parentPath+"/"+i_c+":"+storeNd.attr("id");
				}
			}
		}

		//Save changes
		SYS.BD.nodeAt(dbDB,".").SQLReq("UPDATE "+dbProgs+" SET prgTxt='"+comTree.save().replace("'","''")+"' WHERE name='"+lib_value+"';");
		progSelPrg = progSelCom = true;
	}
}

//Get commands of selected program into commands list
if(f_start || progSelPrg) {
	prog_items = "";
	if(lib_value.length) {
		rez = SYS.BD.nodeAt(dbDB,".").SQLReq("SELECT prgTxt FROM "+dbProgs+" WHERE name='"+lib_value+"';");
		if(rez.length > 1) {
			comTree = SYS.XMLNode("prg");
			comTree.load(rez[1][0]);
			curNd = comTree; curPos = 0; curPath = ""; comLevs = new Array();
			for( ; true; curPos++) {
				if(curPos >= curNd.childSize()) {
					if(!comLevs.length) break;
					stObj = comLevs.pop();
					curNd = curNd.parent();
					curPos = stObj.curPos; curPath = stObj.curPath;
					continue;
				}
				prog_items += (prog_items.length?"\n":"")+(wPath=curPath+"/"+curPos+":"+curNd.childGet(curPos).attr(curNd.childGet(curPos).attr("name").length?"name":"id"));
				if(curNd.childGet(curPos).childSize()) {
					curNd = curNd.childGet(curPos);
					comLevs.push((stObj=new Object()));
					stObj.curPos = curPos; stObj.curPath = curPath;
					curPos = -1; curPath = wPath;
					continue;
				}
			}
		}
	}
	labProg_arg0val = progNm_value = lib_value;
}
comIns_active = comInAdd_active = comDel_active = comUp_active = comDwn_active = prog_value.length;

//Get command properties
if(f_start || progSelCom || progSelTp) {
	if(!progSelTp) name_value = type_value = descr_value = "", backgrnd_value = false;
	for(i_a = 1; i_a <= 5; i_a++) {
		this["labArg"+i_a].attrSet("en",false).attrSet("text","");
		this["arg"+i_a].attrSet("en",false).attrSet("value","");
	}

	// Types/commands list load
	if(f_start && !prExtComLs.isEVal()) {
		type_items = descr_value = ""; backgrnd_value = false;
		for(var c_nm in prExtComLs)
			if(c_nm != "Error" && c_nm != "Stop")
				type_items += (type_items.length?"\n":"")+c_nm;
	}

	if(prog_value.length) {
		selNd = false;
		rez = SYS.BD.nodeAt(dbDB,".").SQLReq("SELECT prgTxt FROM "+dbProgs+" WHERE name='"+lib_value+"';");
		if(rez.length > 1) {
			selNd = SYS.XMLNode("prg"); selNd.load(rez[1][0]);
			for(off = 0; (vIt=prog_value.parsePath(0,off)).length; ) selNd = selNd.childGet(vIt.toInt());
		}
		if(!progSelTp && selNd) {
			name_value = selNd.attr("name");
			type_value = selNd.attr("id");
			descr_value = selNd.attr("descr");
			backgrnd_value = selNd.attr("backgrnd");
		}
		// Load command argument's names
		if(!prExtComLs.isEVal() && !prExtComLs[type_value].isEVal()) {
			if((progSelTp || !descr_value.length) && (descr_value=prExtComLs[type_value]["descr"]).isEVal()) descr_value = "";
			for(i_a = 1; i_a <= 5; i_a++) {
				argLab = prExtComLs[type_value]["arg"+i_a];
				if(argLab.isEVal() || !argLab.length)	continue;
				off = 0;
				this["labArg"+i_a].attrSet("en",true).attrSet("text",argLab.parse(0,"|",off));
				argBord = argLab.parse(0,"|",off);
				this["arg"+i_a].attrSet("min",argBord.length?argBord.toReal():EVAL_REAL);
				argBord = argLab.parse(0,"|",off);
				this["arg"+i_a].attrSet("max",argBord.length?argBord.toReal():EVAL_REAL);
				this["arg"+i_a].attrSet("en",true);
			}
		}

		// Load arguments' values
		if(!progSelTp && selNd)
			for(i_a = 1; selNd && i_a <= 5; i_a++) this["arg"+i_a].attrSet("value",selNd.attr("arg"+i_a));
	}
}
type_active = prog_value.length;


ID: prescrRun
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;geomW;geomH;evProc;pgGrp;backColor;bordWidth;bordColor;
ICO:

PROC:
JavaLikeCalc.JavaScript
//Get programms into library list
if(f_start) {
	prEndRun = true;
	lib_value = "";
	btStop_active = false;
	prCnt = 0;
}
if(prExtMode.isEVal() || prExtProg.isEVal() || prExtStartTm.isEVal() || prExtCurCom.isEVal() || prExtWork.isEVal())
	return;

//Check for program list update
if(f_start || (prCnt%max(1,f_frq)) == 0) {
	rez = SYS.BD.nodeAt(dbDB,".").SQLReq("SELECT name FROM "+dbProgs+";");
	curPrLst = "";
	for(i_p = 1; i_p < rez.length; i_p++)
		curPrLst += (curPrLst.length?"\n":"")+rez[i_p][0];
	curPrLst = curPrLst.split("\n").sort().join("\n");
	if(curPrLst != lib_items) lib_items = curPrLst;
}

//Check for ready
btStart_active = prExtProg.length;

if(prExtMode <= 0)		{ btStart_img = "start"; btStart_value = false; btStop_active = btPass_active = false; }
else if(prExtMode == 1){ btStart_img = "pause"; btStart_value = false; btStop_active = btPass_active = true; prEndRun = false; }
else if(prExtMode == 2){ btStart_img = "start"; btStart_value = true; btStop_active = true; btPass_active = true; }

//Prepare call status document
pTxt = "";
if((prExtMode == 1 || prExtMode == 2 || prExtMode == 3 || ((prCnt%max(1,f_frq)) == 0 && prExtMode <= 0))) {
	pTxt = "<body>";
	off = 0;
	labProg_arg0val = prExtWork.attr("name");

	if(prExtMode < 0 && !prEndRun) {
		prEndRun = true;
		prog_aCur = -1;	//Archiving
	}

	//Build result table
	pTxt += "<i>"+tr("Program:")+" </i>"+Special.FLibSYS.strEnc2HTML(labProg_arg0val)+"<br/>\n";
	if(prExtMode > 0 || (prExtMode < 0 && prog_aCur < 0)) {
		pTxt += "<i>"+tr("Started:")+" </i>"+SYS.strftime(prExtStartTm)+"<br/>\n";
		if(prog_aCur < 0) {
			if(prExtMode == -1) pTxt += "<i>"+tr("Status:")+" </i>"+tr("Error")+"<br/>\n";
			else if(prExtMode == -2) pTxt += "<i>"+tr("Status:")+" </i>"+tr("Successful finish")+"<br/>\n";
			else if(prExtMode == -3) pTxt += "<i>"+tr("Status:")+" </i>"+tr("Terminated")+"<br/>\n";
			else pTxt += "<i>"+tr("Status:")+" </i>"+tr("Unknown")+"<br/>\n";
		}
	}
	if(prExtMode == 1) {
		wtm = max(0,prExtWork.attr("wtm").toInt()-(SYS.time()-prExtStartTm));
		pTxt += "<i>"+tr("Remain:")+" </i>"+(wtm/3600).toString(10)+":"+((wtm/60)%60).toString(10,2)+":"+(wtm%60).toString(10,2)+"<br/>";
	}
	pTxt += "<table border='1' cellpadding='2' cellspacing='0' width='100%'>\n"
					"<tr><th>"+tr("#")+"</th><th>"+tr("Command")+"</th><th>"+tr("Comments")+"</th><th>"+tr("Time")+"</th>";
	pTxt += "</tr>\n";

	for(comElN = prExtWork, comPos = 0, comLev = 0, comCur = true, comAftCur = false, comN = "", comPath = ""; true; comPos++) {
		if(comPos >= comElN.childSize()) {
			if((comElN=comElN.parent())) {
				comLev--;
				comPos = comElN.attr("seekPos").toInt();
				comCur = comElN.attr("comCur").toInt();
				comN = comElN.attr("comN");
				comPath = comElN.attr("comPath");
				continue;
			}
			break;
		}
		comEl = comElN.childGet(comPos);
		comN_ = (comN.length?comN+":":"") + comPos;
		comPath_ = (comPath.length?comPath+": ":"") + (comEl.attr("name").length?comEl.attr("name"):comEl.attr("id"));
		isCurCmd = comCur && (tmpComLv=prExtCurCom.parse(comLev,":")).length && tmpComLv.toInt() == comPos && !prExtCurCom.parse(comLev+1,":").length;
		if(isCurCmd) comAftCur = true;
		rezVl = comEl.attr("rez");
		toMark = true;
		if((isCurCmd || (rezVl.length && rezVl.toInt() == 0)) && (prExtMode > 0 || (prExtMode < 0 && prog_aCur < 0)))				pTxt += "<tr class='"+(prEndRun?"err":"run")+"'>";
		else if(!comAftCur && (prExtMode > 0 || (prExtMode < 0 && prog_aCur < 0)))	pTxt += "<tr class='"+((rezVl.toInt()==-10)?"skip":((rezVl.toInt()<0)?"err":"pass"))+"'>";
		else { pTxt += "<tr>"; toMark = false; }
		pTxt += "<td>"+comN_+"</td>";
		pTxt += "<td>"+Special.FLibSYS.strEnc2HTML(comPath_)+(comEl.attr("backgrnd")?" "+tr("(background)"):"")+"</td><td>";
		if(toMark && rezVl.parse(1,":").length) pTxt += Special.FLibSYS.strEnc2HTML(rezVl.parse(1,":"));
		else {
			//Arguments values
			for(i_a = 1; i_a <= 5; i_a++)
				if(comEl.attr("labArg"+i_a).length)
					pTxt += Special.FLibSYS.strEnc2HTML(comEl.attr("labArg"+i_a).parse(0,"|")+" = "+comEl.attr("arg"+i_a)+"; ");
		}
		pTxt += "</td>";
		comTm = comEl.attr("tm").toInt();
		if(toMark && comTm) {
			comTm -= prExtStartTm;
			pTxt += "<td>"+(comTm/3600).toString(10)+":"+
									((comTm/60)%60).toString(10,2)+":"+
									(comTm%60).toString(10,2)+"</td>";
		}
		else pTxt += "<td>---</td>";
		pTxt += "</tr>\n";

		if(comEl.childSize()) {
			comElN.setAttr("seekPos",comPos).setAttr("comCur",comCur).setAttr("comN",comN).setAttr("comPath",comPath);
			comElN = comEl;
			comCur = comCur && (tmpComLv=prExtCurCom.parse(comLev,":")).length && tmpComLv.toInt() == comPos;
			comPos = -1; comLev++; comN = comN_; comPath = comPath_;
		}
	}
	pTxt += "</table></body>";
}

if(!prExtProg.length && f_start) pTxt = "<body><H1>"+tr("Select a program please")+"</H1></body>";

if(pTxt.length) {
	this.prog.attrSet("aDoc",pTxt);
	if(this.prog.attr("aCur") == this.prog.attr("vCur")) prog_doc = pTxt;
}

prCnt++;

//Events for commands process
for(ev_rez = "", off = 0; (ev_cur=event.parse(0,"\n",off)).length; ) {
	//SYS.messDebug("Prescription edit control","Event: "+ev_cur);
	if(ev_cur == "ws_TreeChange:/lib") {
		prog_vCur = prog_aCur;
		prExtProg = lib_value;
	}
	else if(ev_cur == "ws_BtPress:/btStart") {
		if(prExtMode <= 0)	prExtMode = 1;
		else if(prExtMode == 1)	prExtMode = 2;
		prog_vCur = prog_aCur;
	}
	else if(ev_cur == "ws_BtRelease:/btStart")	prExtMode = 1;
	else if(ev_cur == "ws_BtPress:/btStop" && prExtMode >= 0) {
		prExtMode = prExtCurCom = 0;
		prog_vCur = prog_aCur;
	}
	else if(ev_cur == "ws_BtPress:/btPass" && (prExtMode == 1 || prExtMode == 2))	prExtMode = 3;
	else ev_rez += (ev_cur+"\n");
}
event = ev_rez;

//Programm select process
if(!prExtProg.length || lib_items.search("^"+prExtProg.replace(new RegExp("(\\[|\\]|\\(|\\)|\\.|\\+|\\*|\\?|\\^|\\$|\\<|\\>|\\{|\\}|\\\\)","g"),"\\$1")+"$","m") < 0)
	prExtProg = lib_value;
else lib_value = prExtProg;


ID: prescrRunSimple
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;geomW;geomH;evProc;backColor;bordWidth;bordColor;bordStyle;
ICO:

PROC:
JavaLikeCalc.JavaScript
//Get programms into library list
if(f_start) {
	prEndRun = true;
	lib_name = lib_selValue = "";
	btStop_active = false;
	prCnt = 0;
}
if(prExtMode.isEVal() || prExtProg.isEVal() || prExtStartTm.isEVal() || prExtCurCom.isEVal() || prExtWork.isEVal())
	return;

//Check for program list update
if(f_start || (prCnt%max(1,f_frq)) == 0) {
	rez = SYS.BD.nodeAt(dbDB,".").SQLReq("SELECT name FROM "+dbProgs+";");
	curPrLst = "";
	for(i_p = 1; i_p < rez.length; i_p++)
		curPrLst += (curPrLst.length?"\n":"")+rez[i_p][0];
	curPrLst = curPrLst.split("\n").sort().join("\n");
	if(curPrLst != lib_items) lib_items = curPrLst;
}

//Check for ready
btStart_active = prExtProg.length;

if(prExtMode <= 0)		{ btStart_img = "start"; btStart_value = false; btStop_active = btPass_active = false; }
else if(prExtMode == 1){ btStart_img = "pause"; btStart_value = false; btStop_active = btPass_active = true; prEndRun = false; }
else if(prExtMode == 2){ btStart_img = "start"; btStart_value = true; btStop_active = true; btPass_active = true; }

//Prepare call status document
pTxt = "";
if((prExtMode == 1 || prExtMode == 2 || prExtMode == 3 || ((prCnt%max(1,f_frq)) == 0 && prExtMode <= 0))) {
	pTxt = "<body>";
	//off = 0;
	labProg_arg0val = prExtWork.attr("name");

	if(prExtMode < 0 && !prEndRun)	prEndRun = true;

	//Build result
	pTxt += "<i>"+tr("Program:")+" </i>"+Special.FLibSYS.strEnc2HTML(lib_name);
	if(prExtMode > 0) pTxt += "\n<br/><i>"+tr("Started:")+" </i>"+SYS.strftime(prExtStartTm);
	if(prExtMode == 1) {
		wtm = max(0,prExtWork.attr("wtm").toInt()-(SYS.time()-prExtStartTm));
		pTxt += "\n<br/><i>"+tr("Remain:")+" </i>"+(wtm/3600).toString(10)+":"+((wtm/60)%60).toString(10,2)+":"+(wtm%60).toString(10,2);
	}
	if(prExtMode > 0 && prExtCurCom.parse(0,":").toInt() < prExtWork.childSize()) {
		pTxt += "<table border='1' cellpadding='2' cellspacing='0' width='100%'>\n"
					"<tr><th>"+tr("#")+"</th><th>"+tr("Command")+"</th><th>"+tr("Comments")+"</th><th>"+tr("Time")+"</th></tr>\n";
		for(comElN = prExtWork, comPos = 0, comLev = 0, comN = "", comPath = ""; true; comPos++) {
			if(comPos >= comElN.childSize()) {
				if((comElN=comElN.parent())) {
					comLev--;
					comPos = comElN.attr("seekPos2").toInt();
					comN = comElN.attr("comN2");
					comPath = comElN.attr("comPath2");
					continue;
				}
				break;
			}
			comEl = comElN.childGet(comPos);
			comN_ = (comN.length?comN+":":"") + comPos;
			comPath_ = (comPath.length?comPath+": ":"") + (comEl.attr("name").length?comEl.attr("name"):comEl.attr("id"));
			rezVl = comEl.attr("rez");
			toMark = true;
			if((rezVl.length && rezVl.toInt() == 0)) {
				pTxt += "<tr class='" + (prEndRun?"err":"run") + "'>" +
					"<td>" + comN_ + "</td>"+
					"<td>" + Special.FLibSYS.strEnc2HTML(comPath_) + "</td><td>";
				if(toMark && rezVl.parse(1,":").length) pTxt += Special.FLibSYS.strEnc2HTML(rezVl.parse(1,":"));
				else {
					//Arguments values
					for(i_a = 1; i_a <= 5; i_a++)
						if(comEl.attr("labArg"+i_a).length)
							pTxt += Special.FLibSYS.strEnc2HTML(comEl.attr("labArg"+i_a).parse(0,"|")+" = "+comEl.attr("arg"+i_a)+"; ");
				}
				pTxt += "</td>";
				comTm = comEl.attr("tm").toInt();
				if(toMark && comTm) {
					comTm -= prExtStartTm;
					pTxt += "<td>"+(comTm/3600).toString(10)+":"+
										((comTm/60)%60).toString(10,2)+":"+
										(comTm%60).toString(10,2)+"</td>";
				}
				else pTxt += "<td>---</td>";
				pTxt += "</tr>\n";
			}

			if(comEl.childSize()) {
				comElN.setAttr("seekPos2",comPos).setAttr("comN2",comN).setAttr("comPath2",comPath);
				comElN = comEl;
				comPos = -1; comLev++; comN = comN_; comPath = comPath_;
			}
		}
		pTxt += "</table>";

		/*comN = 0;
		if(prExtMode == 0)	comEl = prExtWork.childGet(0);
		else {
			comEl = prExtWork;
			for(off = 0; comEl && (tVl=prExtCurCom.parse(0,":",off)).length; )	comEl = comEl.childGet(tVl.toInt());
			if(!comEl) comEl = prExtWork.childGet(0); else comN = prExtCurCom;
		}
		for(comPath = "", comElI = comEl; comElI; comElI = comElI.parent())
			if(comElI.name() == "com")
				comPath = comElI.attr(comElI.attr("name").length?"name":"id")+(comPath.length?": ":"")+comPath;
		rezVl = comEl.attr("rez");
		if(prExtMode != 0) pTxt += "<tr class='"+((prExtMode==-1)?"err":"run")+"'>";
		else pTxt += "<tr>";
		pTxt += "<td>"+comN+"</td>";
		pTxt += "<td>"+Special.FLibSYS.strEnc2HTML(comPath)+"</td><td>";
		if(rezVl.parse(1,":").length) pTxt += Special.FLibSYS.strEnc2HTML(rezVl.parse(1,":"));
		else {
			//Arguments values
			for(i_a = 1; i_a <= 5; i_a++)
				if(comEl.attr("labArg"+i_a).length)
					pTxt += Special.FLibSYS.strEnc2HTML(comEl.attr("labArg"+i_a).parse(0,"|")+" = "+comEl.attr("arg"+i_a)+"; ");
		}
		pTxt += "</td>";
		comTm = comEl.attr("tm").toInt();
		if(!comTm) pTxt += "<td>---</td>";
		else {
			comTm -= prExtStartTm;
			pTxt += "<td>"+(comTm/3600).toString(10)+":"+
									((comTm/60)%60).toString(10,2)+":"+
									(comTm%60).toString(10,2)+"</td>";
		}
		pTxt += "</tr>\n</table>";*/
	}
	pTxt += "</body>";
}

if(!prExtProg.length && f_start) pTxt = "<body><H1>"+tr("Select a program")+"</H1></body>";

if(pTxt.length)	prog_doc = pTxt;

prCnt++;

//Events for commands process
for(ev_rez = "", off = 0; (ev_cur=event.parse(0,"\n",off)).length; ) {
	//SYS.messInfo("Prescription edit control","Event: "+ev_cur);
	//if(ev_cur == "ws_CombChange:/lib") prExtProg = lib_name;
	//if(ev_cur.slice(0,11) == "ws_BtMenu=/")	prExtProg = ev_cur.slice(11).parse(0,":");
	if(ev_cur == "dlg_Apply:/lib")	prExtProg = lib_selValue;
	else if(ev_cur == "ws_BtPress:/btStart") {
		if(prExtMode <= 0)			prExtMode = 1;
		else if(prExtMode == 1)	prExtMode = 2;
	}
	else if(ev_cur == "ws_BtRelease:/btStart")	prExtMode = 1;
	else if(ev_cur == "ws_BtPress:/btStop" && prExtMode >= 0)	prExtMode = prExtCurCom = 0;
	else if(ev_cur == "ws_BtPress:/btPass" && (prExtMode == 1 || prExtMode == 2))	prExtMode = 3;
	else ev_rez += (ev_cur+"\n");
}
event = ev_rez;

//Programm select process
if(!prExtProg.length || lib_items.search("^"+prExtProg.replace(new RegExp("(\\[|\\]|\\(|\\)|\\.|\\+|\\*|\\?|\\^|\\$|\\<|\\>|\\{|\\}|\\\\)","g"),"\\$1")+"$","m") < 0)
	prExtProg = lib_name;
else lib_name = lib_selValue = prExtProg;


ID: accept
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;geomW;geomH;pgGrp;backColor;bordWidth;
ICO:

PROC:
JavaLikeCalc.JavaScript
if(f_start) mess_text = elMess;

//Events for commands process
for(off = 0, ev_rez = ""; (ev_cur=event.parse(0,"\n",off)).length; ) {
	//SYS.messDebug("Prescription edit control","Event: "+ev_cur);
	if(ev_cur == "ws_BtPress:/apply") {
		elEvent += "dlg_Apply\n";
		this.attrSet("pgOpen",false);
	}
	else if(ev_cur == "ws_BtPress:/cancel")	this.attrSet("pgOpen", false);
	else ev_rez += (ev_cur+"\n");
}
event = ev_rez;


ID: treeSelect
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;geomW;geomH;pgGrp;backColor;bordWidth;
ICO:

PROC:
JavaLikeCalc.JavaScript
if(f_start) { select_items = elItems; select_value = selValue; }

//Events for commands process
for(off = 0, ev_rez = ""; (ev_cur=event.parse(0,"\n",off)).length; ) {
	//SYS.messInfo("Prescription edit control","Event: "+ev_cur);
	if(ev_cur == "ws_BtPress:/apply") {
		if(select_value.length)	{ selValue = select_value; elEvent += "dlg_Apply\n"; }
		this.attrSet("pgOpen", false);
	}
	else if(ev_cur == "ws_BtPress:/cancel")	this.attrSet("pgOpen", false);
	else ev_rez += ev_cur + "\n";
}
event = ev_rez;


ID: TextLab
PARENT: /wlb_originals/wdg_Text
ATTRS: name;dscr;active;geomW;geomH;contextMenu;evProc;backColor;bordWidth;bordColor;font;alignment;text;
ICO:

PROC:
JavaLikeCalc.JavaScript
if(f_start)	isErr = false, alBlnk = false, cnt = 0, fixText = (text != "---");

//Prepare/update the context menu
if(f_start || ((cnt++)%max(1,f_frq*10)) == 0) {
	contextMenu = "";
	if(!digComs.isEVal() && digComs.length) {
		if(!com_text.isEVal())
			for(off = 0; (comVal=digComs.parse(0,";",off)).length; )
				contextMenu += comVal.parse(0,"-") + ":" + comVal.parse(0,"-") + "\n";
		else {
			if((comVal=digComs.parse(0,";")).length)	contextMenu += comVal.parse(0,"-") + ":open\n";
			if((comVal=digComs.parse(1,";")).length)	contextMenu += comVal.parse(0,"-") + ":close\n";
			if((comVal=digComs.parse(2,";")).length)	contextMenu += comVal.parse(0,"-") + ":stop\n";
		}
	}
}

//Display label from st_text
stCur = -1;
if(!st_text.isEVal() && st_text.length) {
	if(!fixText)	text = st_text.parse(0,":");
	blink = st_text.parse(2,":").toInt();
	backClr = st_text.parse(1,":").parse(0,"-");
	if(blink) {
		backClrBl = st_text.parse(1,":").parse(1,"-");
		if(!backClrBl.length)	backClrBl = "gray";
		backColor = (backColor!=backClr) ? backClr : backClrBl;
	}
	else	backColor = backClr;
}
//Display typical for st_open
else if(st_open == true || st_close == false) {
	backColor = (stVal=digStts.parse(0,";").parse(1,"-")).length ? stVal : "green";
	if(!fixText)
		text = (!digStts.isEVal() && (stVal=digStts.parse(0,";").parse(0,"-")).length) ? stVal : tr("Enable");
	stCur = 1;
}
else if(st_open == false || st_close == true) {
	backColor = (stVal=digStts.parse(1,";").parse(1,"-")).length ? stVal : "blue";
	if(!fixText)
		text = (!digStts.isEVal() && (stVal=digStts.parse(1,";").parse(0,"-")).length) ? stVal : tr("Disable");
	stCur = 0;
}
else {
	backColor = "grey";
	if(!fixText) text = "---";
	return;
}
if(!backColor.length)	backColor = "black-1";	//For the activity cursor

//Blink linked with ElCadr
if(this.attr("focus") ||
	(!NAME.isEVal() && this.wdgAt("/s/pg_control/pg_ElCadr",true).attr("pgOpen") && this.wdgAt("/s/pg_control/pg_ElCadr",true).attr("prmShifr") == NAME))
{
  bordColor = (bordColor != "white") ? "white" : "black";
  bordWidth = 2;
}
else if(bordWidth) { bordWidth = 1; bordColor = "black"; }

//Notification create
if(ntf.length && (ntf.toInt() == stCur) != isErr) {
	if((isErr=(ntf.toInt()==stCur)))	alarm = "50|"+NAME+"|"+ntf.parse(2,":")+".|"+ntf.parse(1,":");
	else if(alarmSt&0x100)	alarm = "1|"+NAME+"||1";
}
if(!isErr && alarmSt&0x100 && !(alarmSt&0x10000)) alarm = "";
if(alarmSt&0x100) {
	if(!(alarmSt&0x10000) || alBlnk)	backColor = isErr ? "red" : backColor;
	else backColor = (backColor=="gray")?"#383838":"gray";
	alBlnk = !alBlnk;
}

//Events process
for(ev_rez = "", off = 0; (sval=event.parse(0,"\n",off)).length; ) {
	//SYS.messInfo("TextLab","Event: "+sval);
	if(!com_text.isEVal() && sval.indexOf("usr_") == 0) {
		com_text = comVal = sval.slice(4);
		SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'. "+tr("Command")+" : "+DESCR+" : : "+comVal);
	}
	else if(sval == "usr_open") {
		if(!com.isEVal())	com = true;
		else close = false;
		comVal = (comVal=digComs.parse(0,";")).length ? comVal.parse(0,"-") : tr("ENABLE");
		SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'. "+tr("Command")+" : "+DESCR+" : : "+comVal);
	}
	else if(sval == "usr_close") {
		if(!close.isEVal())	close = true;
		else com = false;
		comVal = (comVal=digComs.parse(1,";")).length ? comVal.parse(0,"-") : tr("DISABLE");
		SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'. "+tr("Command")+" : "+DESCR+" : : "+comVal);
	}
	else if(sval == "usr_stop") {
		if(!stop.isEVal())	stop = true;
		comVal = (comVal=digComs.parse(2,";")).length ? comVal.parse(0,"-") : tr("STOP");
		SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'. "+tr("Command")+" : "+DESCR+" : : "+comVal);
	}
	else ev_rez += sval+"\n";
}
event = ev_rez;


ID: cntrPaspExt
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;geomW;geomH;pgGrp;backColor;bordWidth;bordColor;bordStyle;
ICO:

PROC:
JavaLikeCalc.JavaScript
using Special.FLibSYS;

if(f_start) {
	if(!name_.length)	name_ = this.attr("name");
	viewSet_geomY_ = viewSet_geomY, viewSet_geomH_ = viewSet_geomH;
	pAddr = pName.slice(0, pName.lastIndexOf("/"));
	if(!(pObj=SYS.nodeAt(pAddr)))	return;
	scLog = (pObj.nodeAt("a_log").get() == true);
	aLst = pObj.nodeList("a_");
	this.attrSet("name", name_+": "+SYS.nodeAt(pName).get());

	selTab = "view";

	//View mode clean up
	view_value = ""; view_geomH = geomH-view_geomY-1;

	//Standard parameters
	stdPrms = "var;sp;out;auto;aMin;aMax;wMin;wMax;com;close;stop;st_open;st_close;";
	//pColors = new Array("darkmagenta", "orange", "blue", "lightgreen", "cyan", "tomato", "magenta", "wheat", "lightyellow", "darkcyan");

	//Trends prepare
	trN = 0, trNMax = 10, trNClr = 0; trDigN = 0;
	trendsList_items = "<tbl sel='row' colsWdthFit='1'><h><s width='0px'>"+tr("ID")+"</s><s width='50%'>"+tr("Name")+"</s><s edit='1' width='25%'>"+tr("Minimum")+"</s><s edit='1' width='25%'>"+tr("Maximum")+"</s></h>";
	trendsList_value = "";
	trObj = this.wdgAt("trends");
	trObj.attrSet("sclVer", scLog?6:2);
	trObj.attrSet("parNum", trNMax);
	// Clear previous trends
	for(iTr = 0; iTr < trNMax; iTr++) trObj.attrSet("prm"+iTr+"addr", "");
	for(off = 0; (sP=stdPrms.parse(0,";",off)).length && trN < trNMax; ) {
		if(!(aObj=pObj.nodeAt("a_"+sP)) ||
			(sP == "aMin" && ((tV=aObj.get()) >= pObj.nodeAt("a_aMax").get() || tV <= pObj.nodeAt("a_min").get())) ||
			(sP == "aMax" && ((tV=aObj.get()) <= pObj.nodeAt("a_aMin").get() || tV >= pObj.nodeAt("a_max").get())) ||
			(sP == "wMin" && ((tV=aObj.get()) >= pObj.nodeAt("a_wMax").get() || tV <= pObj.nodeAt("a_min").get())) ||
			(sP == "wMax" && ((tV=aObj.get()) <= pObj.nodeAt("a_wMin").get() || tV >= pObj.nodeAt("a_max").get())))	continue;
		isBool = (typeof(aObj.get())=="boolean");
		trObj.attrSet("prm"+trN+"addr", pAddr+"/a_"+sP);
		trObj.attrSet("prm"+trN+"color", (trClr=this.attr("labColorGrph"+(trNClr+1)))+(isBool?"-127":""));
		trObj.attrSet("prm"+trN+"width", 2);
		if((sP == "var" || sP == "sp" || sP == "aMin" || sP == "aMax" || sP == "wMin" || sP == "wMax") && pObj.nodeAt("a_min")) {
			trObj.attrSet("prm"+trN+"bordL", pObj.nodeAt("a_min").get()).attrSet("prm"+trN+"bordU", pObj.nodeAt("a_max").get()).attrSet("prm"+trN+"scl",0);
			if(sP == "aMin" || sP == "aMax" || sP == "wMin" || sP == "wMax")
				trObj.attrSet("prm"+trN+"addr","line:"+aObj.get()).attrSet("prm"+trN+"color",(trClr=(sP[0]=="a")?"red":"yellow"));
		}
		else if(sP == "out") trObj.attrSet("prm"+trN+"bordL",0).attrSet("prm"+trN+"bordU",100).attrSet("prm"+trN+"scl",2);
		else if(isBool) { trObj.attrSet("prm"+trN+"bordL", -trDigN).attrSet("prm"+trN+"bordU", 20-trDigN).attrSet("prm"+trN+"scl",2); trDigN++; }
		else trObj.attrSet("prm"+trN+"scl",2);
		trendsList_items += "<r><s>"+trN+"</s>"
											"<s color='"+trClr.parse(0,"-")+"'>"+strEnc2HTML(aObj.descr())+"</s>"
											"<r>"+trObj.attr("prm"+trN+"bordL")+"</r>"
											"<r>"+trObj.attr("prm"+trN+"bordU")+"</r></r>";
		trN++; trNClr++;
	}
	for(iA = 0; iA < aLst.length && trN < trNMax; iA++) {
		aId = aLst[iA].slice(2);
		if(stdPrms.indexOf(aId+";") != -1 || !(aObj=pObj.nodeAt(aLst[iA])) || !aObj.arch()) continue;
		isBool = (typeof(aObj.get())=="boolean");
		trObj.attrSet("prm"+trN+"addr", pAddr+"/a_"+sP);
		trObj.attrSet("prm"+trN+"color", this.attr("labColorGrph"+(trNClr+1))+(isBool?"-127":""));
		trObj.attrSet("prm"+trN+"width", 2);
		if(isBool) { trObj.attrSet("prm"+trN+"bordL", -trDigN).attrSet("prm"+trN+"bordU", 20-trDigN); trDigN++; }
		trendsList_items += "<r><s>"+trN+"</s>"
											"<s color='"+this.attr("labColorGrph"+(trNClr+1))+"'>"+strEnc2HTML(aObj.descr())+"</s>"
											"<s>"+trObj.attr("prm"+trN+"bordL")+"</s>"
											"<s>"+trObj.attr("prm"+trN+"bordU")+"</s></r>";
		trN++; trNClr++;
	}
	trendsList_items += "</tbl>";
	sel_trends_en = trN;

	//Data table prepare
	dtALst = new Array();
	dtPeriod = 1;
	for(off = 0; (sP=stdPrms.parse(0,";",off)).length; )
		if((aObj=pObj.nodeAt("a_"+sP)) && aObj.arch()) {
			dtALst.push(aObj);
			dtPeriod = max(dtPeriod, ceil(aObj.arch().cfg("BPER")));
		}
	for(iA = 0; iA < aLst.length; iA++) {
		aId = aLst[iA].slice(2);
		if(stdPrms.indexOf(aId+";") == -1 && (aObj=pObj.nodeAt(aLst[iA])) && aObj.arch()) {
			dtALst.push(aObj);
			dtPeriod = max(dtPeriod, ceil(aObj.arch().cfg("BPER")));
		}
	}
	sel_data_en = dtALst.length;
	if(!sel_trends_en && !sel_data_en)	 { view_geomH += view_geomY-sel_view_geomY; view_geomY = sel_view_geomY; }
}
if(f_stop) viewSet_geomY = viewSet_geomY_, viewSet_geomH = viewSet_geomH_;

//View update
if(pObj && view_en) {
	view_items = "<tbl sel='row' colsWdthFit='1'><h><s width='0px'>"+tr("ID")+"</s><s width='60%'>"+tr("Name")+"</s><s width='30%'>"+tr("Value")+"</s></h>";
	for(iA = 0; iA < aLst.length; iA++) {
		if(!hideAttrs.isEVal() && hideAttrs.match("(;|^)"+aLst[iA].slice(2)+"(;|$)").length)	continue;
		aObj = pObj.nodeAt(aLst[iA]);
		view_items += "<r><s>"+aLst[iA]+"</s>"
									"<s>"+strEnc2HTML(aObj.descr())+"</s>"
									"<s>"+strEnc2HTML(aObj.get())+"</s></r>";
	}
	view_items += "</tbl>";
}

//Data update
if(pObj && data_en) {
	data_tmpl = "<body docProcLang='JavaLikeCalc.JavaScript'>\n"
		"<table class='data' cellpadding='2' cellspacing='0' export='1' valign='middle' width='100%'>\n";
	// Header
	data_tmpl += "<tr><th>Date</th>";
	for(iA = 0; iA < dtALst.length; iA++)
		data_tmpl += "<th>"+strEnc2HTML(dtALst[iA].descr())+"</th>";
	data_tmpl += "</tr>\n";

	// Date
	curTime = SYS.time();
	for(i_rec = curTime; i_rec > (curTime-100*dtPeriod); i_rec-=dtPeriod) {
		data_tmpl += "<tr><td>"+SYS.strftime(i_rec,"%d %m %H:%M:%S")+"</td>";
		for(iA = 0; iA < dtALst.length; iA++) {
			i_rec_ = i_rec;
			data_tmpl += "<td>"+strEnc2HTML(dtALst[iA].get(i_rec_))+"</td>";
		}
		data_tmpl += "</tr>\n";
	}
	data_tmpl += "</table></body>\n";
}

//Events process
ev_rez = "";
for(off = 0; true; ) {
	sval = event.parse(0, "\n", off);
	if(!sval.length) break;
	//SYS.messInfo("ObjProps","Event: "+sval);
	if(sval.slice(0,16) == "ws_BtPress:/sel_") selTab = sval.slice(16);
	else if(sval == "ws_TableChangeSel:/view" && (aObj=pObj.nodeAt(view_value))) {
		if(!(aObj.flg()&0x04)) {
			if(typeof(aObj.get()) == "string" && aObj.flg()&0x08) {
				this.viewSet.attrSet("elType",1);	//Text editor
				viewSet_geomY = viewSet_geomY_ - viewSet_geomH_*3;
				viewSet_geomH = viewSet_geomH_*4;
				view_geomH = viewSet_geomY - view_geomY - 1;
			}
			else {
				this.viewSet.attrSet("elType",0).attrSet("view",1);	//Combo box
				this.viewSet.attrSet("cfg", (aObj.flg()&0x01) ? aObj.values().split(";").join("\n") : "");
				viewSet_geomH = viewSet_geomH_, viewSet_geomY = viewSet_geomY_;
				view_geomH = viewSet_geomY - view_geomY - 1;
			}
			this.viewSet.attrSet("value",aObj.get());
		}
		else view_geomH = geomH-view_geomY-1;
	}
	else if((sval == "ws_LnAccept:/viewSet" || sval == "ws_TxtAccept:/viewSet") && (aObj=pObj.nodeAt(view_value))) aObj.set(this.viewSet.attr("value"));
	else if(sval == "ws_TableChangeSel:/trendsList")
		for(i_tr = 0; i_tr < trN; i_tr++)
			trObj.attrSet("prm"+i_tr+"width", ((i_tr==trendsList_value)?3:2));
	else if((reRez=sval.match("ws_TableEdit_(\\d+)_(\\d+)\\:\\/trendsList")).length)
		trObj.attrSet("prm"+trendsList_value+((reRez[1]==2)?"bordL":"bordU"), trendsList_set);
	else ev_rez += sval+"\n";
}
event = ev_rez;

//Tab selection process
if(f_start || selTab != prevTab) {
	wLs = this.nodeList("wdg_");
	for(iW = 0; iW < wLs.length; iW++) {
		wId = wLs[iW].slice(4);
		wObj = this.wdgAt(wId);
		if(wId.indexOf("sel_") != -1)	wObj.attrSet("color",(wId.slice(4)==selTab)?backColorButtonSel:backColorButton);
		else if(wId.indexOf(selTab) != -1) wObj.attrSet("en",true);
		else if(wId.indexOf(prevTab) != -1) wObj.attrSet("en",false);
	}
	prevTab = selTab;
}


ID: objProps
PARENT: /wlb_originals/wdg_Box
ATTRS: perm;name;dscr;geomW;geomH;pgOpenSrc;pgGrp;backColor;bordWidth;bordColor;
ICO:

PROC:
JavaLikeCalc.JavaScript
using Special.FLibSYS;

if(f_start) {
	props_value = "";
	props_geomH = geomH-props_geomY;
	objErrCode = 0;
}

title_text = objName.isEVal() ? tr("Unknown") : objName;
title_tipTool = objDescr.isEVal() ? "" : objDescr;

//Setting alarms state
if(!objErr.isEVal() && objErrCode != objErr.toInt()) {
	objErrCode = objErr.toInt();
	if(objErrCode == 2)			alarm = "50|"+objName+"||3";
	else if(objErrCode == 1)	alarm = "10|"+objName+"||3";
	else if(alarmSt&0x100)		alarm = "1|"+objName+"||1";
}
if(!objErrCode && alarmSt&0x100 && !(alarmSt&0x10000)) alarm = "";

//Changing notification-title color
alarmLev = alarmSt&0xFF;
if(alarmLev && alarmSt&0x100) {
	blinkPr = true;
	if(!objErrCode || alarmLev <= 1)	wColor = "lime";
	else if(alarmLev < 30)	wColor = "yellow";
	else if(alarmLev < 75)	wColor = "red";
	else { wColor = "grey"; blinkPr = false; }
	if(blinkPr) title_backColor = (alarmSt&0x10000 && title_backColor == wColor) ? "grey" : wColor;
	else title_backColor = wColor;
}
else title_backColor = "lime";

/*if(!objErr.isEVal()) {
	if(objErr.toInt() == 0)		title_backColor = "lime";
	else if(objErr.toInt() == 1)	title_backColor = "yellow";
	else if(objErr.toInt() == 2)	title_backColor = "red";
	else title_backColor = "gray";
}
else title_backColor = "gray";*/

if(!objItems.isEVal()) {
	//Load table with variables
	tbl = "<tbl sel='row' colsWdthFit='1'>\n"
		"<h><s width='0px'>"+tr("Property")+"</s><s width='55%'>"+tr("Description")+"</s><s width='30%'>"+tr("Value")+"</s></h>";
	for(var aIt in objItems) {
		it = objItems[aIt];
		if(it.alarm == 1)	tbl += "<r color='yellow'>";
		else if(it.alarm == 2)	tbl += "<r color='red'>";
		else tbl += "<r>";
		tbl += "<s>"+aIt+"</s><s>"+strEnc2HTML(it.descr)+"</s><s>"+strEnc2HTML(it.val)+"</s></r>\n";
	}
	tbl += "</tbl>";
	props_items = tbl;
}

for(ev_rez = "", off = 0; (sval=event.parse(0,"\n",off)).length; ) {
	//SYS.messInfo("ObjProps","Event: "+sval);
	if(sval == "ws_TableChangeSel:/props" && (it=objItems[props_value])) {
		if(!it.wr.isEVal() && it.wr != false) {
			props_geomH = set_geomY-props_geomY-2;
			set_cfg = it.wr.length ? it.wr.split(";").join("\n") : "";
			set_value = it.val;
		}
		else props_geomH = geomH-props_geomY;
		//SYS.messInfo("ObjProps","WR: "+it.wr+"; it="+it);
	}
	else if(sval == "ws_LnAccept:/set" && (it=objItems[props_value])) it.set = set_value;
	else ev_rez += sval+"\n";
}
event = ev_rez;


ID: grpGraph10
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;geomW;geomH;evProc;backColor;bordWidth;bordColor;
ICO:

PROC:
JavaLikeCalc.JavaScript
if(f_start) {
	//Parameter selection enable
	if(allowSelLst.length)
		for(i_el = 0; i_el < 10; i_el++) {
			cEl = this["el"+(i_el+1)];
			cEl.attrSet("enForce", 1);
			if(cEl.attr("contextMenu").search(":select$") < 0)
				cEl.attrSet("contextMenu",cEl.attr("contextMenu")+tr("Select")+":select\n");
		}
	cnt = 0;
}
cnt++;
if(cnt == 3)	event = "ws_FocusIn:/trnd1";

curTm = SYS.time();
if(!trnd1_tSek) trnd1_tSek = curTm;
selSingle = 0;
selAll = false;

//Events process
evRez = "";
for(off = 0; (evCur=event.parse(0,"\n",off)).length; ) {
	if(evCur == "key_presComma:/trnd1")		trnd1_tSek -= trnd1_tSize/2;
	else if(evCur == "key_presPeriod:/trnd1")	trnd1_tSek += trnd1_tSize/2;
	else if(evCur == "ws_SliderChange:/arh")	trnd1_tSek = arh_value*trnd1_tSize;
	else if(evCur.search("usr_single:/el") == 0)	selSingle = evCur.slice(14).toInt();
	else if(evCur.search("usr_all:/el") == 0)		selAll = true;
	else evRez += evCur+"\n";
	//SYS.messDebug("Trend","Event: "+evCur);
}
event = evRez;

//Trend time control
if(trnd1_tSek < curTm) trnd1_trcPer = 0;
else { trnd1_trcPer = 1; trnd1_tSek = 0; }

//Generic
name_arg0val = this.attr("name");

//Scale
typeXY = (trnd1_type==2);
cntrAct = cntrLog = xCntrAct = xCntrLog = 0;
for(i_el = 0; i_el < 10; i_el++) {
	cEl = this["el"+(i_el+1)];
	if(!cEl.attr("en")) continue;
	if(!typeXY || !(i_el%2)) {
		cntrAct++;
		if(cEl.attr("log") == true)	cntrLog++;
	}
	else {
		xCntrAct++;
		if(cEl.attr("log") == true)	xCntrLog++;
	}
}
trnd1_sclVer = (cntrLog > cntrAct/2) ? trnd1_sclVer|0x4 : trnd1_sclVer&(~0x4);
trnd1_sclHor = (xCntrLog > xCntrAct/2) ? trnd1_sclHor|0x4 : trnd1_sclHor&(~0x4);

//Trends
arh_beg = 1e30, arh_end = 0;
for(i_el = 0; i_el < 10; i_el++) {
	cEl = this["el"+(i_el+1)];
	if(selAll)	cEl.attrSet("bordStyle",3);
	if(selSingle) cEl.attrSet("bordStyle",((i_el+1)==selSingle)?3:1);
	cTr = this["trnd1"];
	cTrPrm = "prm"+i_el;
	if(!cEl.attr("en")) cTr.attrSet(cTrPrm+"addr","");
	else {
		cTr.attrSet(cTrPrm+"addr",cEl.attr("addr"));
		cTr.attrSet(cTrPrm+"bordL",cEl.attr("min"));
		cTr.attrSet(cTrPrm+"bordU",cEl.attr("max"));
		cTr.attrSet(cTrPrm+"color",cEl.attr("color"));
		cTr.attrSet(cTrPrm+"width",cEl.attr("bordWidth")*2);
		cEl.attrSet("varEl",cTr.attr(cTrPrm+"val"));
		//Enable/disable of the mode's indication in the regulators ???
		cEl.attrSet("enMode",((curTm-trnd1_curSek) <= 2));
		//Archive depth calculate
		if(cEl.attr("bordStyle") == 3) {
			arh_tmp = cTr.attr(cTrPrm+"prop");
			if((arh_vl=arh_tmp.parse(0,":").toReal())) arh_beg = min(arh_beg,arh_vl);
			if((arh_vl=arh_tmp.parse(1,":").toReal())) arh_end = min(curTm,max(arh_end,arh_vl));
		}
		if(!typeXY || !(i_el%2)) {
			if((cEl.attr("log")==true) == (cntrLog > cntrAct/2) && cEl.attr("bordWidth") == 1) cTr.attrSet(cTrPrm+"scl",0);
			else cTr.attrSet(cTrPrm+"scl",(cEl.attr("log")==true)?6:2);
		}
		else {
			if((cEl.attr("log")==true) == (xCntrLog > xCntrAct/2)) cTr.attrSet(cTrPrm+"scl",0);
			else cTr.attrSet(cTrPrm+"scl",(cEl.attr("log")==true)?6:2);
		}
	}
}
//Set archive scroll
if(arh_end && ((arh_end-arh_beg)/trnd1_tSize > 2)) {
	arh_cfg = "0:"+floor(arh_beg/trnd1_tSize+1)+":"+floor(arh_end/trnd1_tSize+1)+":1:5";
	arh_value = (trnd1_tSek?trnd1_tSek:curTm)/trnd1_tSize;
	arh_tipTool = tr("Archive space")+": ["+SYS.strftime(arh_beg)+" ... "+SYS.strftime(arh_end)+"]";
	arh_active = true;
	if(selSingle) trnd1_tSek = arh_end;
}
else { arh_active = false; arh_tipTool = ""; }


ID: anShow1s
PARENT: /wlb_Main/wdg_anShow1
ATTRS: name;geomW;
ICO:


ID: calendar
PARENT: /wlb_originals/wdg_Box
ATTRS: name;dscr;geomW;geomH;backColor;
ICO:

PROC:
JavaLikeCalc.JavaScript
if(f_start) {
	selDay = selMonth = selYear = selWDay = isDst = 0;	//Selected data parts
	maxDayInMonth = 30;			//Maximum days into selected month
	selTime = SYS.time();		//Selected time, ordered to days
	prevTime = 0;					//Previous time for detect time selection change
	cntr = 0;						//Global counter for update period limit for some parts
}

//Years list update
if(f_start || (cntr%(f_frq*3600*24)) == 0)	{	//By day
	curYear = 0;
	SYS.localtime(SYS.time(), 0, 0, 0, 0, 0, curYear);
	year_items = "";
	for(i_y = 0; i_y < 10; i_y++)	year_items += (i_y?"\n":"")+(curYear-i_y);
}

//Events process
for(ev_rez = "", off = 0; (ev_cur=event.parse(0,"\n",off)).length; ) {
	//SYS.messInfo("MnCntr","Event: "+ev_cur);
	if(ev_cur == "ws_BtPress:/curDay")	selTime = SYS.time();
	else if(ev_cur == "ws_CombChange:/year")
		selTime = SYS.mktime(0, 0, 0, selDay, selMonth, year_value, 0, 0, isDst);
	else if(ev_cur == "ws_CombChange:/month")
		selTime = SYS.mktime(0, 0, 0, selDay, (month_value.match("\\((\\d+)\\)","")[1].toInt()-1), selYear, 0, 0, isDst);
	else if(ev_cur.indexOf("key_mousePresLeft:/w") == 0) {
		weekWdg = this.wdgAt(ev_cur.slice(19));
		if(weekWdg.attr("text").length)
			selTime = SYS.mktime(0, 0, 0, weekWdg.attr("text"), selMonth, selYear, 0, 0, isDst);
	}
	else ev_rez += (ev_cur+"\n");
}
event = ev_rez;

if(selTime != prevTime) {
	selTime = min(selTime, SYS.time());
	SYS.localtime(selTime, 0, 0, 0, selDay, selMonth, selYear, 0, 0, isDst);
	selTime = SYS.mktime(0, 0, 0, selDay, selMonth, selYear, 0, 0, isDst);
	selWDay = 0;
	selTimeMonth = SYS.mktime(0, 0, 0, 1, selMonth, selYear, selWDay, 0, isDst);
	title_arg0val = SYS.strftime(selTime, "%d.%m.%Y");

	year_value = selYear;
	month_value = month_items.match("([^\n]*\\("+(selMonth+1)+"\\))","m")[0];

	//Days number into selected month
	tMonth = selMonth, tYear = selYear, tisDst = isDst;
	for(maxDayInMonth = 29; true; maxDayInMonth++) {
		tDayInMonth = maxDayInMonth;
		SYS.mktime(0, 0, 0, tDayInMonth, tMonth, tYear, 0, 0, tisDst);
		if(tDayInMonth != maxDayInMonth)	{ maxDayInMonth--; break; }
		if(maxDayInMonth >= 31)	break;
	}

	//Week box update
	for(i_w = 0, i_d = 1; i_w < 6; i_w++)
		for(i_wd = 0; i_wd < 7; i_wd++)
			if((i_w == 0 && i_wd < (((tVl=selWDay-1)<0)?7+tVl:tVl)) || i_d > maxDayInMonth)	//Clear cell
				this.wdgAt("w"+i_w+"_"+i_wd).attrSet("text","").attrSet("bordWidth","0").attrSet("backColor","");
			else {
				this.wdgAt("w"+i_w+"_"+i_wd).attrSet("text",i_d).attrSet("bordWidth","0").attrSet("backColor","lightgray-1");
				if(i_d == selDay)						//Selected day
					this.wdgAt("w"+i_w+"_"+i_wd).attrSet("text",i_d).attrSet("bordWidth","1").attrSet("backColor","lightgreen");
				i_d++;
			}
	prevTime = selTime;
}

cntr++;


ID: alarmsAct
PARENT: /wlb_originals/wdg_FormEl
ATTRS: owner;name;dscr;active;geomY;geomW;geomH;contextMenu;evProc;elType;value;items;set;
ICO:

PROC:
JavaLikeCalc.JavaScript
if(f_start) {
	cnt = 0;
	toUpdate = false;
	messItSep = ": ";
	alUnSel = 0;
	geomH_ = geomH;
	highLght_ = new Array();
	for(off = 0; (iH=highLght.parse(0,"\n",off)).length; ) {
		iHo = new Object();
		iHo.lev = iH.slice(0,1).toInt(); iHo.quiet = iH.slice(1,2).toInt()?1:0;
		iHo.color = iH.parse(1,":"); iHo.font = iH.parse(2,":"); iHo.fontColor = iH.parse(3,":");
		highLght_.push(iHo);
	}
	sourceCache = new Object();
}

if(focus)	alUnSel = 10;	//Wait for 10 seconds
else if(alUnSel > 0 && (alUnSel=max(0,alUnSel-1/f_frq)) <= 0)	{
	value = "";
	if(this.wdgAt("/s/pg_control/pg_ElCadr",true).attr("prmShifr") == NAME)
		this.wdgAt("/s/pg_control/pg_terminator",true).attrSet("pgOpen", true);
}
if(com) { event += "usr_qtc\n"; st_open = true; }

//Call per 1 seconds, start or force update
if(((cnt++)%(f_frq*1) == 0 || f_start || toUpdate) && !f_stop) {
	curAlMess = SYS.Archive.messGet(0, SYS.time(), "", -1);

	//Sort the messages
	sortAr = new Array();
	for(iM = 0; iM < curAlMess.length; iM++)
		//!!!! Define here self sort criteries
		sortAr.push(">"+(curAlMess[iM].mess.parse(3,messItSep).length?"0":"1")+curAlMess[iM].level+">"+iM.toString(10,6)+"\n"+iM);
	sortAr = sortAr.sort().reverse();

	//The table content update
	items = "<tbl sel='row' colsWdthFit='1' hHdrVis='"+(hHdrVis?1:0)+"' vHdrVis='"+(vHdrVis?1:0)+"'>\n";
	items += "<h><s width='0px'>ID</s>";
	for(vC = "", off = 0; (vC=colms.parse(0,",",off)).length; )
		if(vC == "atm")			items += "<s>"+tr("Alarm time")+"</s>";
		else if(vC == "qttm")	items += "<s>"+tr("Quittance time")+"</s>";
		else if(vC == "lev")	items += "<s>"+tr("Lev.")+"</s>";
		else if(vC == "cat")	items += "<s>"+tr("Category")+"</s>";
		else if(vC == "mess")	items += "<s>"+tr("Message")+"</s>";
		else if(vC == "prm")	items += "<s>"+tr("Source")+"</s>";
		else if(vC == "dscr")	items += "<s>"+tr("Description")+"</s>";
		else if(vC == "alrm")	items += "<s>"+tr("Alarm")+"</s>";
		else if(vC == "cmnt")	items += "<s edit='1'>"+tr("Comment")+"</s>";
		//else if(vC == "src")	items += "<s>"+tr("Source")+"</s>";
		else if(vC.slice(0,8) == "dscrCust")
			items += "<s>"+((tVl=colDscrCustNames.parse(vC.slice(8).toInt(),";")).length?tVl:tr("Custom")+" "+vC.slice(8))+"</s>";
	items += "</h>\n";
	for(iSM = 0; iSM < sortAr.length; iSM++) {
		iM = curAlMess[iMid=sortAr[iSM].parse(1,"\n").toInt()];
		//Check for higlight properties match
		for(iHgl = false, iH = 0; iH < highLght_.length && !iHgl; iH++) {
			iHo = highLght_[iH];
			//this.messInfo("TEST 00: lev: "+iM.level+":"+iHo.lev);
			if(abs(iM.level) >= iHo.lev && (iM.mess.parse(3,messItSep).length?1:0) == iHo.quiet)
				iHgl = iHo;
		}
		items += "<r"+(iHgl?" color='"+iHgl.color+"' font='"+iHgl.font+"' colorText='"+iHgl.fontColor+"'":"")+"><i>"+iMid+"</i>";
		for(vC = "", off = 0; (vC=colms.parse(0,",",off)).length; )
			if(vC == "atm")	items += "<s>"+SYS.strftime(iM.tm,formDtTm.replace("%MS",(iM.utm/1000).toString(10,3)).replace("%US",iM.utm.toString(10,6)))+"</s>";
			else if(vC == "qttm")	items += ((tVl=iM.mess.parse(3,messItSep)).length ? "<s>"+tVl+"</s>" : "<b edit='1'>0</b>");
			else if(vC == "lev")	items += "<i>"+abs(iM.level)+"</i>";
			else if(vC == "cat")	items += "<s>"+SYS.strEncode(iM.categ,"HTML")+"</s>";
			else if(vC == "mess")	items += "<s>"+SYS.strEncode(iM.mess,"HTML")+"</s>";
			else if(vC == "prm") {
				srcO = iM.categ.match("^al(.+):([^\\.]+)|^([^:]+).*:al");
				tVl = "";
				//From remote station
				if(srcO.length == 4 && (tVl=sourceCache[srcO[3]]).isEVal()) {
					req = SYS.XMLNode("get").setAttr("path","/Transport/%2fsub%2fehost").setAttr("upRiseSYS",1);
					SYS.cntrReq(req);
					for(iTr = 0; req.childSize() && iTr < req.childGet(0).childSize(); iTr++)
						if(req.childGet(0).childGet(iTr).text() == srcO[3]) {
							sourceCache[srcO[3]] = tVl = req.childGet(1).childGet(iTr).text();
							break;
						}
				}

				items += "<s>"+SYS.strEncode((tVl.length?tVl+" > ":"")+iM.mess.parse(0,messItSep),"HTML")+"</s>";
			}
			else if(vC == "dscr")	items += "<s>"+SYS.strEncode(iM.mess.parse(1,messItSep).replace(new RegExp("\\[\\[.+\\]\\]"),""),"HTML")+"</s>";
			else if(vC == "alrm")	items += "<s>"+SYS.strEncode(iM.mess.parse(2,messItSep),"HTML")+"</s>";
			else if(vC == "cmnt")	items += "<s>"+SYS.strEncode(iM.mess.parse(5,messItSep),"HTML")+"</s>";
			else if(vC.slice(0,8) == "dscrCust") {
			    sVl = (sVl=iM.mess.parse(1,messItSep).match("\\[\\[(.+)\\]\\]")).length ? sVl[1].parse(vC.slice(8).toInt(),"=>") : "";
			    items += "<s>"+SYS.strEncode(sVl,"HTML")+"</s>";
			}
		items += "</r>\n";
	}
	items += "</tbl>";
	toUpdate = false;
}

//Events process
for(off = 0; (sval=event.parse(0,"\n",off)).length; ) {
	//this.messInfo("TEST 01: Event="+sval);
	if(abs(expOnFocus) && sval == "ws_FocusIn" && expOnItems >= 0 && sortAr.length > expOnItems && geomH == geomH_) {
		if(expOnFocus < 0) geomY += expOnFocus;
		geomH += abs(expOnFocus);
		if(value.length) event += "usr_goquiet\n";
	}
	else if(abs(expOnFocus) && sval == "ws_FocusOut" && expOnItems >= 0 && sortAr.length > expOnItems && geomH != geomH_) {
		if(expOnFocus < 0) geomY -= expOnFocus;
		geomH -= abs(expOnFocus);
	}
	else if(sval == "ws_TableChangeSel") {
		iM = curAlMess[value];
		NAME = iM.mess.parse(0, messItSep);
		DESCR = iM.mess.parse(1, messItSep) + " -> " + iM.mess.parse(2, messItSep);
		st_open = iM.mess.parse(3, messItSep).length;
		if(value.length) event += "usr_goquiet\n";
	}
	else if(( (sval == "usr_qtc" && (iM=curAlMess[value])) ||
					(sval.slice(0,12) == "ws_TableEdit" && colms.parse(sval.parse(2,"_").toInt()-1,",") == "qttm" && (iM=curAlMess[sortAr[sval.parse(3,"_").toInt()].parse(1,"\n").toInt()])) )
			&& !iM.mess.parse(3,messItSep).length)
	{
		//this.messInfo("TEST 02: value="+value+"; set="+set);
		if(!com) SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME, "'"+NAME+"'. "+tr("Command")+" : "+DESCR+" : : "+digComs.parse(0,";").parse(0,"-"));
		var tmU;
		tMess = iM.mess.parse(0,messItSep)+messItSep+iM.mess.parse(1,messItSep)+messItSep+iM.mess.parse(2,messItSep)+messItSep+
					SYS.strftime(SYS.time(tmU),formDtTm.replace("%MS",(tmU/1000).toString(10,3)).replace("%US",tmU.toString(10,6)));
		if((tVl1=iM.mess.parse(4,messItSep)).length || (tVl2=iM.mess.parse(5,messItSep)).length) {
			tMess += messItSep+tVl1;
			if((tVl2=iM.mess.parse(5,messItSep)).length) tMess += messItSep+tVl2;
		}
		iM.mess = tMess;
		SYS.Archive.messPut(iM.tm, iM.utm, iM.categ, iM.level, iM.mess);
		toUpdate = true;
		com = false;
	}
	else if(sval == "usr_qtcMass")
		for(i = 0; i < curAlMess.length; i++) {
			iM = curAlMess[i];
			if(!iM.mess.parse(3,messItSep).length) {
				SYS.messNote("OP:"+this.ownerSess().user()+":"+iM.mess.parse(0,messItSep),
						"'"+iM.mess.parse(0,messItSep)+"'. "+tr("Command")+" : "+iM.mess.parse(1, messItSep) + " -> " + iM.mess.parse(2, messItSep)+" : : "+digComs.parse(0,";").parse(0,"-"));
				tMess = iM.mess.parse(0,messItSep)+messItSep+iM.mess.parse(1,messItSep)+messItSep+iM.mess.parse(2,messItSep)+messItSep+
						SYS.strftime(SYS.time(tmU),formDtTm.replace("%MS",(tmU/1000).toString(10,3)).replace("%US",tmU.toString(10,6)));
				if((tVl1=iM.mess.parse(4,messItSep)).length || (tVl2=iM.mess.parse(5,messItSep)).length) {
					tMess += messItSep+tVl1;
					if((tVl2=iM.mess.parse(5,messItSep)).length) tMess += messItSep+tVl2;
				}
				iM.mess = tMess;
				SYS.Archive.messPut(iM.tm, iM.utm, iM.categ, iM.level, iM.mess);
			}
		}
	else if(sval.slice(0,12) == "ws_TableEdit" && colms.parse(sval.parse(2,"_").toInt()-1,",") == "cmnt") {
		iM = curAlMess[sortAr[sval.parse(3,"_").toInt()].parse(1,"\n").toInt()];
		//this.messInfo("TEST 02: value="+value+"; set="+set);
		SYS.Archive.messPut(iM.tm, iM.utm, iM.categ, iM.level, iM.mess.parse(0,messItSep)+messItSep+iM.mess.parse(1,messItSep)+messItSep+iM.mess.parse(2,messItSep)+messItSep+
										iM.mess.parse(3,messItSep)+messItSep+iM.mess.parse(4,messItSep)+messItSep+set);
	}
}


ID: alarmsSt
PARENT: /wlb_originals/wdg_Box
ATTRS: owner;name;dscr;geomX;geomY;geomW;geomH;geomZ;evProc;pgOpenSrc;pgGrp;backColor;bordWidth;bordColor;
ICO:

PROC:
JavaLikeCalc.JavaScript
function getSrc( categ, sourceCache ) {
	srcO = categ.match("^al(.+):([^\\.]+)|^([^:]+).*:al");
	tVl = "";
	//From remote station
	if(srcO.length == 4 && (tVl=sourceCache[srcO[3]]).isEVal()) {
		req = SYS.XMLNode("get").setAttr("path","/Transport/%2fsub%2fehost").setAttr("upRiseSYS",1);
		SYS.cntrReq(req);
		for(iTr = 0; req.childSize() && iTr < req.childGet(0).childSize(); iTr++)
			if(req.childGet(0).childGet(iTr).text() == srcO[3]) {
				sourceCache[srcO[3]] = tVl = req.childGet(1).childGet(iTr).text();
				break;
			}
	}

	return tVl;
}

if(f_start) {
	cnt = 0;
	toUpdate = makeReport = toMassQuitt = false;
	wTm = 0;							//From current time
	realPrTm = prTm = SYS.time() - 86400*size_value, prTmU = 0;		//From default set depth
	messItSep = ": ";
	als = new Array();			//Hierarchical alarms with the statuses
	cAls = new Object();		//Last alarms by the criteria
	alUnSel = 0;
	highLght_ = new Array();
	for(off = 0; (iH=highLght.parse(0,"\n",off)).length; ) {
		iHo = new Object();
		iHo.lev = iH.slice(0,1).toInt(); iHo.quiet = iH.slice(1,2).toInt()?1:0; iHo.act = iH.slice(2,3).toInt()?1:0;
		iHo.color = iH.parse(1,":"); iHo.font = iH.parse(2,":"); iHo.fontColor = iH.parse(3,":");
		highLght_.push(iHo);
	}
	colVars = new Array();
	//Filters curent state proceed
	fMax = 5;
	fTopOrig = fTop = this["fltr0"].attr("geomY") + this["fltr0"].attr("geomH");
	for(iF = fMax-1; iF > 0 && !this["fltr"+iF].attr("en"); iF--) ;
	fTop = this["fltr"+iF].attr("geomY") + this["fltr"+iF].attr("geomH");

	sourceCache = new Object();

	user = user_ = "";
}

//Permitions load
user = this.ownerSess().user();
if(f_start || user != user_) {
	user_ = user;
	permLoc = EVAL, permLev = 0;
	if(user != "root") {
		permLoc = new Array();
		permLev = 10;
		gList = SYS.Security["usr_"+user].groups();
		for(iG = 0; iG < gList.length; iG++) {
			if(gList[iG] == "root") { permLoc = EVAL; break; }
			gDescr = SYS.Security["grp_"+gList[iG]].cfg("LONGDESCR");
			for(iLc = 0; iLc < 10; iLc++) {
				if(permLoc[iLc].isEVal())	permLoc[iLc] = new Object();
				if((itLc=gDescr.match("^loc"+iLc+"=(.+?)$","m")).length)
					for(off = 0; (tVl=itLc[1].parse(0,";",off)).length; )
						permLoc[iLc][tVl] = true;
			}
			if((itLev=gDescr.match("^lev=(.+?)$","m")).length)	permLev = min(permLev, itLev[1].toInt());
		}
		if(permLev == 10)	permLev = 0;
	}

	//To reload
	realPrTm = prTm = (wTm?wTm:SYS.time()) - 86400*size_value, prTmU = 0;
	als = new Array(); cAls = new Object();
	toUpdate = true;
}

if(alarms_focus)	alUnSel = 10;	//Wait for 10 seconds
else if(alUnSel > 0 && (alUnSel=max(0,alUnSel-1/f_frq)) <= 0) {
	alarms_value = "";
	if(this.wdgAt("/s/pg_control/pg_ElCadr",true).attr("prmShifr") == alarms_NAME)
		this.wdgAt("/s/pg_control/pg_terminator",true).attrSet("pgOpen", true);
}
if(alarms_com) { event += "usr_qtc:/alarms\n"; alarms_st_open = true; }

//Call per 1 seconds, start or force update
if((((cnt++)%(f_frq*1) == 0 && !wTm) || f_start || toUpdate) && !f_stop) {
	alMess = SYS.Archive.messGet(realPrTm, (wTm?wTm:SYS.time()), messCat, 1, alArch);

	for(iM = 0, iRecv = 0, iAppend = 0; iM < alMess.length && iAppend < messLim; iM++) {
		iMo = alMess[iM];
		if(iMo.tm < prTm || (iMo.tm == prTm && iMo.utm <= prTmU) || abs(iMo.level) < permLev) continue;
		// Check for permited location
		if(!permLoc.isEVal() && (sVl=iMo.mess.parse(1,messItSep).match("\\[\\[(.+)\\]\\]")).length) {
			for(off = 0, iLc = 0; (sVl2=sVl[1].parse(0,"=>",off)).length; iLc++)
				if(!(permLoc[iLc]["*"] == true || permLoc[iLc][sVl2] == true))	break;
			if(sVl2.length)	continue;
		}

		if(iMo.level < 0) {	//Alarm message
			iMoA = cAls[iMo.categ];
			// !!!! To prevent the duplicate entries for new alarms in that category.
			if(!iMoA.isEVal() && iMoA.categ == iMo.categ && iMoA.tm == iMo.tm && iMoA.utm == iMo.utm) continue;
			if(!iMoA.isEVal() && !iMoA.mess.parse(4,messItSep).length) {	//Renewal state set for not marked as NORMAL
				iMoA.mess = iMoA.mess.parse(0,messItSep)+messItSep+iMoA.mess.parse(1,messItSep)+messItSep+iMoA.mess.parse(2,messItSep)+messItSep+iMoA.mess.parse(3,messItSep)+messItSep+
						tr("Renewal")+messItSep+iMoA.mess.parse(5,messItSep);
				/*if(iMoA.mess.parse(3,messItSep).length && !iMo.mess.parse(3,messItSep).length)	//Inherit the quietance fact from the previous
					iMo.mess = iMo.mess.parse(0,messItSep)+messItSep+iMo.mess.parse(1,messItSep)+messItSep+iMo.mess.parse(2,messItSep)+messItSep+iMoA.mess.parse(3,messItSep)+messItSep+
						iMo.mess.parse(4,messItSep)+messItSep+iMo.mess.parse(5,messItSep);
				if(iMoA.mess.parse(5,messItSep).length && !iMo.mess.parse(5,messItSep).length)	//Inherit the comment from the previous
					iMo.mess = iMo.mess.parse(0,messItSep)+messItSep+iMo.mess.parse(1,messItSep)+messItSep+iMo.mess.parse(2,messItSep)+messItSep+iMo.mess.parse(3,messItSep)+messItSep+
						iMo.mess.parse(4,messItSep)+messItSep+iMoA.mess.parse(5,messItSep);*/
			}
			cAls[iMo.categ] = iMo;
			iMo.lsPos = als.length;
			als.push(iMo);
			iAppend++;
		}
		else if(!(iMoA=cAls[iMo.categ]).isEVal()) {	//Norma or quietance
			/*if(iMo.mess.parse(2,messItSep).match("\\s*(.+?)\\s*$")[1] == tr("QUITANCE")) {
				if(!iMoA.mess.parse(3,messItSep).length)	//Fill for missed
					iMoA.mess = iMoA.mess.parse(0,messItSep)+messItSep+iMoA.mess.parse(1,messItSep)+messItSep+iMoA.mess.parse(2,messItSep)+messItSep+
						SYS.strftime(iMo.tm,formDtTm.replace("%MS",(iMo.utm/1000).toString(10,3)).replace("%US",iMo.utm.toString(10,6)))+messItSep+
						iMoA.mess.parse(4,messItSep)+messItSep+iMoA.mess.parse(5,messItSep);
			}
			else*/
			if(!(tVl=iMoA.mess.parse(4,messItSep)).length || tVl == tr("Norm on down"))	//Fill for missed
				iMoA.mess = iMoA.mess.parse(0,messItSep)+messItSep+iMoA.mess.parse(1,messItSep)+messItSep+iMoA.mess.parse(2,messItSep)+messItSep+iMoA.mess.parse(3,messItSep)+messItSep+
						SYS.strftime(iMo.tm,formDtTm.replace("%MS",(iMo.utm/1000).toString(10,3)).replace("%US",iMo.utm.toString(10,6)))+messItSep+
						iMoA.mess.parse(5,messItSep);
		}
		iRecv++;
		prTm = iMo.tm; prTmU = iMo.utm;
	}
	if(iM < alMess.length && iAppend >= messLim)	{ sizeLim_text = ((alMess.tm-alMess[iM-1].tm)/86400).toFixed(3); go_prev_sizeLim_en = true; }
	else if(wTm || (SYS.time()-realPrTm) > 3600) { sizeLim_text = ""; go_prev_sizeLim_en = false; }
	realPrTm = alMess.tm;
	//Active alarms get for the gone on down ones detect
	if(!wTm) {
		actAlMess = SYS.Archive.messGet(0, SYS.time(), messCat, -1);
		actAls = new Object();
		for(iM = 0; iM < actAlMess.length; iM++) {
			iMo = actAlMess[iM];
			if(abs(iMo.level) < permLev) continue;
			// Check for permited location
			if(!permLoc.isEVal() && (sVl=iMo.mess.parse(1,messItSep).match("\\[\\[(.+)\\]\\]")).length) {
				for(off = 0, iLc = 0; (sVl2=sVl[1].parse(0,"=>",off)).length; iLc++)
					if(!(permLoc[iLc]["*"] == true || permLoc[iLc][sVl2] == true))	break;
				if(sVl2.length)	continue;
			}

			actAls[iMo.categ] = iMo;
		}
		//Detect and mark "Norm on down"
		for(var iA in cAls)
			if(!(iMo=cAls[iA]).mess.parse(4,messItSep).length && !actAls[iMo.categ])
				iMo.mess = iMo.mess.parse(0,messItSep)+messItSep+iMo.mess.parse(1,messItSep)+messItSep+iMo.mess.parse(2,messItSep)+messItSep+iMo.mess.parse(3,messItSep)+messItSep+
						tr("Norm on down")+messItSep+iMo.mess.parse(5,messItSep);
		//Force placing the active alarms to the list
		for(var iA in actAls) {
			iMo = cAls[iA]; iMo1 = actAls[iA];
			if(iMo.isEVal() /*|| iMo1.tm > iMo.tm || (iMo1.tm == iMo.tm && iMo1.utm > iMo.utm)*/)
			{ als.push(iMo1); cAls[iA] = iMo1; iRecv = true; }
		}
	}

	if(iRecv || toUpdate) {
		//Sort the messages
		sortAr = new Array();
		sR = sort_value.match("\\((.+)\\)")[1];
		//this.messInfo("TEST 00: sR="+sR);		
		for(iM = 0; iM < als.length; iM++) {
			iMo = als[iM];
			tvl = iM.toString(10,6);
			if((sR_=sR.parse(0,":")) == "atm")	tvl = SYS.strftime(iMo.tm,formDtTm.replace("%MS",(iMo.utm/1000).toString(10,3)).replace("%US",iMo.utm.toString(10,6)));
			else if(sR_ == "qttm")	tvl = iMo.mess.parse(3, messItSep);
			else if(sR_ == "nrmtm")tvl = iMo.mess.parse(4, messItSep);
			else if(sR_ == "lev")	tvl = iMo.level;
			else if(sR_ == "cat")	tvl = iMo.categ;
			else if(sR_ == "mess")	tvl = iMo.mess;
			else if(sR_ == "prm")	{
				tvl = iMo.mess.parse(0, messItSep);
				if((tvl2=getSrc(iMo.categ,sourceCache)).length)	tvl = tvl2 + " > " + tvl;
			}
			else if(sR_ == "dscr")	tvl = iMo.mess.parse(1, messItSep).replace(new RegExp("\\[\\[.+\\]\\]"),"");
			else if(sR_ == "alrm")	tvl = iMo.mess.parse(2, messItSep);
			else if(sR_ == "cmnt")	tvl = iMo.mess.parse(5, messItSep);
			//else if(sR_ == "src")	tvl = getSrc(iMo.categ, sourceCache);
			else if(sR_.slice(0,8) == "dscrCust")
				tvl = (tvl=iMo.mess.parse(1,messItSep).match("\\[\\[(.+)\\]\\]")).length ? tvl[1].parse(sR_.slice(8).toInt(),"=>") : "";
			sortAr.push(">"+tvl+"\n"+iM);
		}
		sortAr = sortAr.sort();
		if(sR.isEVal() || sR.parse(1,":") == "!")	sortAr = sortAr.reverse();
		sort_items = tr("Disable");

		for(iF = 0; iF < fMax; iF++) this["fltrCol"+iF].attrSet("items", tr("Disable"));

		//The table content update
		alarms_items = "<tbl sel='row' sortEn='1' colsWdthFit='1' hHdrVis='"+(hHdrVis?1:0)+"' vHdrVis='"+(vHdrVis?1:0)+"'>\n";
		alarms_items += "<h><s width='0px'>ID</s>";
		if(makeReport) rep = "<body>\n"
			"<h1>"+tr("Alarms report for")+" "+SYS.strftime(wTm?wTm:SYS.time())+"</h1>\n"
			"<table class='data' width='100%' export='1'><tr>\n";
		for(vC = "", off = 0; (vC=colms.parse(0,",",off)).length; ) {
			tvl = ""; toEdit = false;
			if(vC == "atm")			tvl = tr("Alarm time");
			else if(vC == "qttm")	tvl = tr("Quittance time");
			else if(vC == "nrmtm")	{ tvl = tr("Norm"); colVars[vC] = new Object(); }
			else if(vC == "lev")	tvl = tr("Lev.");
			else if(vC == "cat")	tvl = tr("Category");
			else if(vC == "mess")	tvl = tr("Message");
			else if(vC == "prm")	tvl = tr("Source");
			else if(vC == "dscr")	tvl = tr("Description");
			else if(vC == "alrm")	tvl = tr("Alarm");
			else if(vC == "cmnt")	tvl = tr("Comment"), toEdit = true;
			//else if(vC == "src")	tvl = tr("Source");
			else if(vC.slice(0,8) == "dscrCust") {
				nCust = vC.slice(8).toInt();
				tvl = (tVl=colDscrCustNames.parse(nCust,";")).length ? tVl : tr("Custom")+" "+nCust;
				colVars[vC] = new Object();
			}
			if(tvl.length) {
				alarms_items += "<s"+(toEdit?" edit='1'":"")+((vC=="atm")?" sort='0'":"")+">"+tvl+"</s>";
				if(makeReport) rep += "<th>"+tvl+"</th>";
				sort_items += "\n"+tvl+" ("+vC+")\n"+tvl+", "+tr("reversed")+" ("+vC+":!)";
				for(iF = 0; iF < fMax; iF++)
					this["fltrCol"+iF].attrSet("items", this["fltrCol"+iF].attr("items")+"\n"+tvl+" ("+vC+")");
			}
		}
		alarms_items += "</h>\n";
		if(makeReport) rep += "</tr>\n";
		for(iSM = 0; iSM < sortAr.length; iSM++) {
			iM = als[iMid=sortAr[iSM].parse(1,"\n").toInt()];
			//Check for higlight properties match
			for(iHgl = false, iH = 0; iH < highLght_.length && !iHgl; iH++) {
				iHo = highLght_[iH];
				if(abs(iM.level) >= iHo.lev && (iM.mess.parse(3,messItSep).length?1:0) == iHo.quiet &&
																 ((wTm||iM.mess.parse(4,messItSep).length)?0:1) == iHo.act)
					iHgl = iHo;
			}
			aRow = "<r"+(iHgl?" color='"+iHgl.color+"' font='"+iHgl.font+"' colorText='"+iHgl.fontColor+"'":"")+"><i>"+iMid+"</i>";
			if(makeReport) repRow = "<tr>\n";
			for(vC = "", off = 0, isMatch = true; isMatch && (vC=colms.parse(0,",",off)).length; ) {
				if(vC == "atm")			{ sVl = SYS.strftime(iM.tm,formDtTm.replace("%MS",(iM.utm/1000).toString(10,3)).replace("%US",iM.utm.toString(10,6))); aRow += "<s>"+sVl+"</s>"; }
				else if(vC == "qttm")	{ sVl = iM.mess.parse(3, messItSep); aRow += (sVl.length ? "<s>"+sVl+"</s>" : "<b edit='1'>0</b>"); }
				else if(vC == "nrmtm")	{
					if(!(sVl=iM.mess.parse(4,messItSep)).length && !wTm) sVl = tr("Active");
					aRow += "<s>"+sVl+"</s>";
					if(!sVl.toInt()) colVars[vC][sVl] = true;
				}
				else if(vC == "lev")	{ sVl = abs(iM.level).toString(); aRow += "<i>"+sVl+"</i>"; }
				else if(vC == "cat")	{ sVl = iM.categ; aRow += "<s>"+SYS.strEncode(sVl,"HTML")+"</s>"; }
				else if(vC == "mess")	{ sVl = iM.mess; aRow += "<s>"+SYS.strEncode(sVl,"HTML")+"</s>"; }
				else if(vC == "prm")	{
					sVl = iM.mess.parse(0, messItSep);
					if((tvl2=getSrc(iM.categ, sourceCache)).length)	sVl = tvl2 + " > " + sVl;
					aRow += "<s>"+SYS.strEncode(sVl,"HTML")+"</s>";
				}
				else if(vC == "dscr")	{ sVl = iM.mess.parse(1, messItSep).replace(new RegExp("\\[\\[.+\\]\\]"),""); aRow += "<s>"+SYS.strEncode(sVl,"HTML")+"</s>"; }
				else if(vC == "alrm")	{ sVl = iM.mess.parse(2, messItSep); aRow += "<s>"+SYS.strEncode(sVl,"HTML")+"</s>"; }
				else if(vC == "cmnt")	{ sVl = iM.mess.parse(5, messItSep); aRow += "<s>"+SYS.strEncode(sVl,"HTML")+"</s>"; }
				//else if(vC == "src")	{ sVl = getSrc(iM.categ, sourceCache); aRow += "<s>"+SYS.strEncode(sVl,"HTML")+"</s>"; }
				else if(vC.slice(0,8) == "dscrCust") {
					nCust = vC.slice(8).toInt();
					sVl = (sVl=iM.mess.parse(1,messItSep).match("\\[\\[(.+)\\]\\]")).length ? sVl[1].parse(nCust,"=>") : "";
					aRow += "<s>"+SYS.strEncode(sVl,"HTML")+"</s>";
					colVars[vC][sVl] = true;
				}
				for(iF = 0; iF < fMax; iF++)
					if(vC == this["fltrCol"+iF].attr("value").match("\\((.+)\\)")[1] && (tVl=this["fltr"+iF].attr("value")).length) {
							if(vC == "lev")	isMatch = (sVl.toInt() >= tVl.toInt());
							else if(vC == "nrmtm" || vC.slice(0,8) == "dscrCust")	isMatch = (sVl.match(tVl).length > 0);
							else isMatch = (sVl.indexOf(tVl) >= 0);
					}
				if(makeReport) repRow += "<td>"+SYS.strEncode(sVl,"HTML")+"</td>";
			}
			if(isMatch) {
				alarms_items += aRow + "</r>\n";
				if(makeReport) rep += repRow + "</tr>\n";
				if(toMassQuitt && !iM.mess.parse(3,messItSep).length) {
					SYS.messNote("OP:"+this.ownerSess().user()+":"+iM.mess.parse(0,messItSep),
						"'"+iM.mess.parse(0,messItSep)+"'. "+tr("Command")+" : "+iM.mess.parse(1, messItSep) + " -> " + iM.mess.parse(2, messItSep)+" : : "+alarms_digComs.parse(0,";").parse(0,"-"));
					tmU = 0;
					tMess = iM.mess.parse(0,messItSep)+messItSep+iM.mess.parse(1,messItSep)+messItSep+iM.mess.parse(2,messItSep)+messItSep+
						SYS.strftime(SYS.time(tmU),formDtTm.replace("%MS",(tmU/1000).toString(10,3)).replace("%US",tmU.toString(10,6)));
					if((tVl1=iM.mess.parse(4,messItSep)).length || (tVl2=iM.mess.parse(5,messItSep)).length) {
						tMess += messItSep+tVl1;
						if((tVl2=iM.mess.parse(5,messItSep)).length) tMess += messItSep+tVl2;
					}
					iM.mess = tMess;
					isCurAct = ((iAo=actAls[iM.categ]) && iAo.tm == iM.tm && iAo.utm == iM.utm);
					SYS.Archive.messPut(iM.tm, iM.utm, iM.categ, iM.level, iM.mess, isCurAct?"":alArch);
				}
			}
		}
		alarms_items += "</tbl>";
		if(makeReport) { rep += "</table>\n</body>\n"; go_report_report = rep; }

		//Filter's selection list update
		for(iF = 0; iF < fMax; iF++) {
			iFCo = this["fltrCol"+iF]; iFo = this["fltr"+iF];
			fCol = iFCo.attr("value").match("\\((.+)\\)")[1];
			fCfg = "";
			if(colVars[fCol]) {
				fCfgPref = iFo.attr("value");
				for(sumVl = "", tVl1 = "", off = 0; (tVl=fCfgPref.parse(0,"|",off)).length; tVl1 = tVl)
					if(tVl1.length) { sumVl += (sumVl.length?"|":"")+tVl1; fCfg += sumVl + "\n"; }
				custColO = colVars[fCol];
				for(var iFv in custColO)
					if(iFv.length && fCfgPref.indexOf(iFv) < 0) fCfg += (fCfgPref.length?fCfgPref+"|":"") + iFv + "\n";
			}
			iFo.attrSet("cfg", fCfg);
		}
	}
	toUpdate = makeReport = false;
}

if(toMassQuitt) { toMassQuitt = false; toUpdate = true; }

//Events process
for(off = 0; (sval=event.parse(0,"\n",off)).length; ) {
	//this.messInfo("TEST 01: Event="+sval+" : "+alarms_value);
	isFirst = isSec = false;
	if(sval == "ws_FocusIn:/alarms") {
		alarms_geomY = fTopOrig; alarms_geomH += fTop-fTopOrig;
		if(alarms_value.length) event += "usr_goquiet:/alarms\n";
	}
	else if(sval == "ws_FocusOut:/alarms")	{ alarms_geomY = fTop; alarms_geomH -= fTop-fTopOrig; }
	else if(( (sval == "usr_qtc:/alarms" && (iM=als[alarms_value])) ||
					(sval.slice(0,12) == "ws_TableEdit" && colms.parse(sval.parse(2,"_").toInt()-1,",") == "qttm" && (iM=als[sortAr[sval.parse(3,"_").toInt()].parse(1,"\n").toInt()])) )
			&& !iM.mess.parse(3,messItSep).length)
	{
		//this.messInfo("TEST 02: value="+alarms_value+"; set="+alarms_set);
		if(!alarms_com) SYS.messNote("OP:"+this.ownerSess().user()+":"+alarms_NAME, "'"+alarms_NAME+"'. "+tr("Command")+" : "+alarms_DESCR+" : : "+alarms_digComs.parse(0,";").parse(0,"-"));
		tmU = 0;
		tMess = iM.mess.parse(0,messItSep)+messItSep+iM.mess.parse(1,messItSep)+messItSep+iM.mess.parse(2,messItSep)+messItSep+
					SYS.strftime(SYS.time(tmU),formDtTm.replace("%MS",(tmU/1000).toString(10,3)).replace("%US",tmU.toString(10,6)));
		if((tVl1=iM.mess.parse(4,messItSep)).length || (tVl2=iM.mess.parse(5,messItSep)).length) {
			tMess += messItSep+tVl1;
			if((tVl2=iM.mess.parse(5,messItSep)).length) tMess += messItSep+tVl2;
		}
		iM.mess = tMess;
		isCurAct = ((iAo=actAls[iM.categ]) && iAo.tm == iM.tm && iAo.utm == iM.utm);
		SYS.Archive.messPut(iM.tm, iM.utm, iM.categ, iM.level, iM.mess, isCurAct?"":alArch);
		toUpdate = true;
		alarms_com = false;
	}
	else if(sval == "ws_BtPress:/quietMass")	toMassQuitt = toUpdate = true;
	else if(sval == "ws_TableChangeSel:/alarms") {
		iM = als[alarms_value];
		alarms_NAME = iM.mess.parse(0, messItSep);
		alarms_DESCR = iM.mess.parse(1, messItSep) + " -> " + iM.mess.parse(2, messItSep);
		alarms_st_open = iM.mess.parse(3, messItSep).length;
		if(alarms_value.length) event += "usr_goquiet:/alarms\n";
	}
	else if(sval.slice(0,12) == "ws_TableEdit" && colms.parse(sval.parse(2,"_").toInt()-1,",") == "cmnt") {
		iM = als[sortAr[sval.parse(3,"_").toInt()].parse(1,"\n").toInt()];
		//this.messInfo("TEST 03: value="+alarms_value+"; set="+alarms_set);
		iM.mess = iM.mess.parse(0,messItSep)+messItSep+iM.mess.parse(1,messItSep)+messItSep+iM.mess.parse(2,messItSep)+messItSep+
						iM.mess.parse(3,messItSep)+messItSep+iM.mess.parse(4,messItSep)+messItSep+alarms_set;
		isCurAct = ((iAo=actAls[iM.categ]) && iAo.tm == iM.tm && iAo.utm == iM.utm);
		SYS.Archive.messPut(iM.tm, iM.utm, iM.categ, iM.level, iM.mess, isCurAct?"":alArch);
	}
	else if(sval == "ws_CombChange:/sort")	toUpdate = true;
	else if(sval.slice(0,22) == "ws_CombChange:/fltrCol") {
		fN = sval.slice(22).toInt();
		fAct = !this["fltrCol"+fN].attr("value").match("\\((.+)\\)")[1].isEVal();
		this["fltr"+fN].attrSet("active", fAct).attrSet("value", "");
		if(fAct && (fN+1) < fMax && !this["fltrCol"+(fN+1)].attr("en")) {
			this["fltrCol"+(fN+1)].attrSet("en", true);
			this["fltr"+(fN+1)].attrSet("en", true).attrSet("active", false).attrSet("value", "");
		}
		else for(iF = fMax-1; !fAct && iF >= fN; iF--)
			if(iF < (fMax-1)) {
				this["fltrCol"+(iF+1)].attrSet("en", false).attrSet("value", tr("Disable"));
				this["fltr"+(iF+1)].attrSet("en", false).attrSet("active", false).attrSet("value", "");
			}
		//Apply filter vertical offset and size
		for(iF = fMax-1; iF > 0 && !this["fltr"+iF].attr("en"); iF--) ;
		fTop_ = this["fltr"+iF].attr("geomY") + this["fltr"+iF].attr("geomH");
		alarms_geomH += fTop-fTop_; fTop = fTop_; alarms_geomY = fTop;

		toUpdate = true;
	}
	else if(sval.slice(0,17) == "ws_LnAccept:/fltr")	toUpdate = true;
	else if((isFirst=(sval=="ws_LnAccept:/size")) || (isSec=(sval=="ws_LnAccept:/time")) || sval == "ws_BtPress:/go_cur") {
		if(!isFirst)	{
			wTm = isSec ? time_value : 0;
			if(wTm >= SYS.time()) wTm = 0;
		}
		realPrTm = prTm = (wTm?wTm:SYS.time()) - 86400*size_value, prTmU = 0;
		als = new Array(); cAls = new Object();
		toUpdate = true;
	}
	else if((isFirst=(sval=="ws_BtPress:/go_prev")) || (isSec=(sval=="ws_BtPress:/go_prev_sizeLim")) || sval == "ws_BtPress:/go_prev1") {
		wTm = max(0, (wTm?wTm:SYS.time())-86400*(isSec?sizeLim_text.toReal():size_value)*((isFirst||isSec)?1:5));
		realPrTm = prTm = wTm - 86400*size_value, prTmU = 0;
		als = new Array(); cAls = new Object();
		toUpdate = true;
	}
	else if((isFirst=(sval=="ws_BtPress:/go_next")) || sval == "ws_BtPress:/go_next1") {
		if((wTm=(wTm?wTm:SYS.time()) + 86400*size_value*(isFirst?1:5)) >= SYS.time()) wTm = 0;
		realPrTm = prTm = (wTm?wTm:SYS.time()) - 86400*size_value, prTmU = 0;
		als = new Array(); cAls = new Object();
		toUpdate = true;
	}
	else if(sval == "ws_BtPress:/go_report")				toUpdate = makeReport = true;
}

time_value = wTm ? wTm : SYS.time();
//go_cur_active = wTm;


ID: ImgLab
PARENT: /wlb_originals/wdg_Media
ATTRS: owner;name;dscr;active;geomW;geomH;contextMenu;evProc;backColor;bordWidth;bordColor;src;fit;
ICO:

PROC:
JavaLikeCalc.JavaScript
if(f_start)	isErr = false, alBlnk = false, cnt = 0;

//Prepare/update the context menu
if(f_start || ((cnt++)%max(1,f_frq*10)) == 0) {
	EVALclr = imgs.parse(2,":").parse(1,"-");
	contextMenu = "";
	if(!digComs.isEVal() && digComs.length) {
		if(!com_text.isEVal())
			for(off = 0; (comVal=digComs.parse(0,";",off)).length; )
				contextMenu += comVal.parse(0,"-") + ":" + comVal.parse(0,"-") + "\n";
		else {
			if((comVal=digComs.parse(0,";")).length)	contextMenu += comVal.parse(0,"-") + ":open\n";
			if((comVal=digComs.parse(1,";")).length)	contextMenu += comVal.parse(0,"-") + ":close\n";
			if((comVal=digComs.parse(2,";")).length)	contextMenu += comVal.parse(0,"-") + ":stop\n";
		}
	}
}

//Display label from st_img
stCur = -1;
if(!st_img.isEVal() && st_img.length) {
	src = st_img.parse(0,":");
	blink = st_img.parse(2,":").toInt();
	backClr = st_img.parse(1,":").parse(0,"-");
	if(blink) {
		backClrBl = st_img.parse(1,":").parse(1,"-");
		if(!backClrBl.length)	backClrBl = EVALclr;
		backColor = (backColor!=backClr) ? backClr : backClrBl;
	}
	else	backColor = backClr;
}
//Display typical for st_open
else if(st_open == true || st_close == false) {
	backColor = (stVal=imgs.parse(0,":").parse(1,"-")) ? "*" : digStts.parse(0,";").parse(1,"-");
	src = imgs.parse(0, ":");
	stCur = 1;
}
else if(st_open == false || st_close == true) {
	backColor = (stVal=imgs.parse(1,":").parse(1,"-")) ? "*" : digStts.parse(1,";").parse(1,"-");
	src = imgs.parse(1, ":");
	stCur = 0;
}
else {
	src = imgs.parse(2,":").parse(0,"-");
	backColor = EVALclr;
	return;
}
if(!backColor.length)	backColor = "black-1";	//For the activity cursor

//Blink linked with ElCadr
if(this.attr("focus") ||
	(!NAME.isEVal() && this.wdgAt("/s/pg_control/pg_ElCadr",true).attr("pgOpen") && this.wdgAt("/s/pg_control/pg_ElCadr",true).attr("prmShifr") == NAME))
{
	bordColor = (bordColor != "white") ? "white" : "black";
	if(bordWidth) bordWidth = 2;
}
else { if(bordWidth) bordWidth = 1; bordColor = "black"; }

//Notification create
if(ntf.length && (ntf.toInt() == stCur) != isErr) {
	if((isErr=(ntf.toInt()==stCur)))	alarm = "50|"+NAME+"|"+ntf.parse(2,":")+".|"+ntf.parse(1,":");
	else if(alarmSt&0x100)	alarm = "1|"+NAME+"||1";
}
if(!isErr && alarmSt&0x100 && !(alarmSt&0x10000)) alarm = "";
if(alarmSt&0x100) {
	if(!(alarmSt&0x10000) || alBlnk)	backColor = isErr ? "red" : backColor;
	else backColor = (backColor==EVALclr)?"#383838":EVALclr;
	alBlnk = !alBlnk;
}

//Events process
for(ev_rez = "", off = 0; (sval=event.parse(0,"\n",off)).length; ) {
	//SYS.messInfo("TextLab","Event: "+sval);
	if(!com_text.isEVal() && sval.indexOf("usr_") == 0) {
		com_text = comVal = sval.slice(4);
		SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'. "+tr("Command")+" : "+DESCR+" : : "+comVal);
	}
	else if(sval == "usr_open") {
		if(!com.isEVal())	com = true;
		else close = false;
		comVal = (comVal=digComs.parse(0,";")).length ? comVal.parse(0,"-") : tr("ENABLE");
		SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'. "+tr("Command")+" : "+DESCR+" : : "+comVal);
	}
	else if(sval == "usr_close") {
		if(!close.isEVal())	close = true;
		else com = false;
		comVal = (comVal=digComs.parse(1,";")).length ? comVal.parse(0,"-") : tr("DISABLE");
		SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'. "+tr("Command")+" : "+DESCR+" : : "+comVal);
	}
	else if(sval == "usr_stop") {
		if(!stop.isEVal())	stop = true;
		comVal = (comVal=digComs.parse(2,";")).length ? comVal.parse(0,"-") : tr("STOP");
		SYS.messNote("OP:"+this.ownerSess().user()+":"+NAME,"'"+NAME+"'. "+tr("Command")+" : "+DESCR+" : : "+comVal);
	}
	else ev_rez += sval+"\n";
}
event = ev_rez;


ID: userManager
PARENT: /wlb_Main/wdg_RootPgSo/wdg_pgCont
ATTRS: id;owner;perm;name;dscr;geomH;evProc;backColor;
ICO:

PROC:
JavaLikeCalc.JavaScript
if(f_start) {
	grpLs = new Array(); userSelVl = lib_value_ = sesUer = "";
	userLbUpdt = userSel = 0;
}

if(sesUer != this.ownerSess().reqUser()) {
	userSel = userLbUpdt = SYS.mtime();
	userSelVl = sesUer = this.ownerSess().reqUser();
}

//Events for commands process
for(ev_rez = "", offEv = 0; (ev_cur=event.parse(0,"\n",offEv)).length; ) {
	//this.messInfo("Event: "+ev_cur);
	if(ev_cur == "ws_ListChange:/lib") {
		userSel = SYS.mtime();
		userSelVl = ((userSelVl=lib_value.match("\\((.+)\\)$")).length > 1) ? userSelVl[1] : "";
	}
	if(ev_cur == "ws_BtPress:/userAdd") {
		if(!userNm_value.length) userNm_value = tr("NewUser");
		req = SYS.XMLNode("add").setAttr("path","/sub_Security/%2fbr%2fusr_").setText(userNm_value);
		if(!SYS.cntrReq(req).toInt()) {
			userNm_value = req.text();
			if(storeDB.length)
				SYS.cntrReq(SYS.XMLNode("set").setAttr("path","/sub_Security/"+userNm_value+"/%2fprm%2fdb").setText(storeDB));
			for(off = 0; (iIt=newUseGrps.parse(0,";",off)).length; )
				if((oIt=SYS.Security.nodeAt("grp_"+iIt)))
					oIt.cfgSet("USERS", oIt.cfg("USERS")+userNm_value+";");
			lib_value_ = userNm_value+" ("+userNm_value+")"; userSelVl = userNm_value;
			userLbUpdt = userSel = SYS.mtime()+500;

			SYS.messNote("OP:"+this.ownerSess().user()+":{Page}."+this.attr("id"), title_text+" : "+tr("Added user \"%1\"").replace("%1",userNm_value));
		}

		SYS.cntrReq(SYS.XMLNode("save").setAttr("path","/sub_Security/%2fobj"));	//To save all users and groups
	}
	else if(ev_cur == "dlg_Apply:/userDel" && userSelVl.length) {
		req = SYS.XMLNode("del").setAttr("path","/sub_Security/%2fbr%2fusr_").setText(userSelVl);
		rez = SYS.cntrReq(req);
		SYS.messNote("OP:"+this.ownerSess().user()+":{Page}."+this.attr("id"), title_text+" : "+tr("Deleted user \"%1\"").replace("%1",userNm_value));
		//this.messInfo("Result: "+rez+": "+req.save());
		lib_value_ = userSelVl = "";
		userLbUpdt = userSel = SYS.mtime()+500;

		SYS.cntrReq(SYS.XMLNode("save").setAttr("path","/sub_Security/%2fobj"));	//To save all groups
	}
	else if(ev_cur == "ws_LnAccept:/fullName" && (oIt=SYS.Security.nodeAt("usr_"+userSelVl))) {
		oIt.cfgSet("DESCR", fullName_value);
		SYS.cntrReq(SYS.XMLNode("save").setAttr("path","/sub_Security/usr_"+userSelVl+"/%2fobj"));
		SYS.messNote("OP:"+this.ownerSess().user()+":{Page}."+this.attr("id"), title_text+" : "+tr("Set the user \"%1\" for").replace("%1",userSelVl)+" "+tr("Full name")+" : : "+fullName_value);
		lib_value_ = fullName_value + " ("+userSelVl+")";
		userLbUpdt = userSel = SYS.mtime()+500;
	}
	else if(ev_cur == "ws_TxtAccept:/descr" && (oIt=SYS.Security.nodeAt("usr_"+userSelVl))) {
		oIt.cfgSet("LONGDESCR", descr_value);
		SYS.cntrReq(SYS.XMLNode("save").setAttr("path","/sub_Security/usr_"+userSelVl+"/%2fobj"));
		SYS.messNote("OP:"+this.ownerSess().user()+":{Page}."+this.attr("id"), title_text+" : "+tr("Set the user \"%1\" for").replace("%1",userSelVl)+" "+tr("Description")+" : : "+descr_value);
		userSel = SYS.mtime()+500;
	}
	else if(ev_cur == "ws_LnAccept:/pass" && (oIt=SYS.Security.nodeAt("usr_"+userSelVl))) {
		oIt.cfgSet("PASS", pass_value);
		SYS.cntrReq(SYS.XMLNode("save").setAttr("path","/sub_Security/usr_"+userSelVl+"/%2fobj")); 
		SYS.messNote("OP:"+this.ownerSess().user()+":{Page}."+this.attr("id"), title_text+" : "+tr("Set the user \"%1\" for").replace("%1",userSelVl)+" "+tr("Password")+" : : "+tr("CHANGED"));
		userSel = SYS.mtime()+500;
	}
	else if(ev_cur == "ws_TableChangeSel:/grp" && (oIt=SYS.Security.nodeAt("usr_"+userSelVl)) &&
			grp_value.length && (oIt1=SYS.Security.nodeAt(grp_value))) {
		grp_value = grp_value.slice(4);
		SYS.messNote("OP:"+this.ownerSess().user()+":{Page}."+this.attr("id"), title_text+" : "+tr("Set the user \"%1\" for").replace("%1",userSelVl)+" "+(oIt1.user(userSelVl)?tr("Group uncheck"):tr("Group check"))+" : : "+grp_value);
		users = oIt1.cfg("USERS");
		//this.messInfo("grp_value="+grp_value+"; users="+users);
		oIt1.cfgSet("USERS", oIt1.user(userSelVl) ? users.replace(userSelVl+";","") : users+userSelVl+";");
		SYS.cntrReq(SYS.XMLNode("save").setAttr("path","/sub_Security/usr_"+userSelVl+"/%2fobj")); 
		userSel = SYS.mtime()+500;
	}
	else ev_rez += (ev_cur+"\n");
}
event = ev_rez;

//Get users and groups list
if(f_start || (userLbUpdt && SYS.mtime() >= userLbUpdt)) {
	userLbUpdt = 0;
	rez = SYS.Security.nodeList("usr_");
	//rez = SYS.BD.nodeAt(dbDB,".").SQLReq("SELECT name FROM "+dbProgs+";");
	lib_items = userNm_cfg = "";
	for(iIt = 0; iIt < rez.length; iIt++) {
		if(denyUsers.indexOf(rez[iIt].slice(4)) >= 0 || !(oIt=SYS.Security.nodeAt(rez[iIt])))	continue;
		tVl1 = ((tVl=oIt.cfg("DESCR")).length?tVl:rez[iIt].slice(4)) + " ("+rez[iIt].slice(4)+")";
		lib_items += (lib_items.length?"\n":"") + tVl1;
		userNm_cfg += (userNm_cfg.length?"\n":"") + rez[iIt].slice(4);
		if(userSelVl == rez[iIt].slice(4))	lib_value_ = tVl1;
	}
	lib_value = lib_value_;

	grpLs = SYS.Security.nodeList("grp_");
	for(iL = 0; iL < grpLs.length; iL++)
		if(denyGroups.indexOf(grpLs[iL].slice(4)) >= 0)
		{ grpLs.splice(iL, 1); iL--; }
}
userDel_active = userSelVl.length;

if(userSel && SYS.mtime() >= userSel) {
	userSel = 0;
	fullName_active = descr_active = pass_active = grp_active = false;
	name_value = fullName_value = descr_value = pass_value = grp_items = "";

	if(userSelVl.length && (oIt=SYS.Security.nodeAt(userSelVl))) {
		//this.messInfo("userSelVl="+userSelVl);
		fullName_active = descr_active = pass_active = grp_active = true;
		name_value = oIt.cfg("NAME");
		fullName_value = oIt.cfg("DESCR");
		descr_value = oIt.cfg("LONGDESCR");
		pass_value = oIt.cfg("PASS");
		//Groups
		grp_items = "<tbl sel='row' colsWdthFit='1' vHdrVis='0' hHdrVis='0' keyID='0'>\n"
			"<h><s width='0'>Ідентифікатор</s><s>Група</s></h>\n";
		for(iIt = 0; iIt < grpLs.length; iIt++) {
			if(!(oIt=SYS.Security.nodeAt(grpLs[iIt])))	continue;
			grp_items += "<r"+(oIt.user(userSelVl)?" color='#777799'":"")+">"
				"<s>"+SYS.strEncode(grpLs[iIt],"HTML")+"</s>"
				"<s>"+SYS.strEncode(oIt.cfg("DESCR")+" ("+grpLs[iIt].slice(4)+")","HTML")+"</s></r>";
		}
		grp_items += "</tbl>";
		grp_value = "";
	}
}


ID: graphCalc
PARENT: /wlb_originals/wdg_Box
ATTRS: owner;name;dscr;geomW;geomH;pgOpenSrc;pgGrp;backColor;bordWidth;
ICO:

PROC:
JavaLikeCalc.JavaScript
if(f_start) {
	//Connect to linked widget 
	if(pgOpenSrc.length) lWdg = this.wdgAt(pgOpenSrc, true);
	if(lWdg) {
		attrO = SYS.nodeAt(lWdg.attr("addr"));
		if(typeof(attrO) == "TCntrNode:TVal")	archO = attrO.arch();
		else archO = attrO;
		//this.messInfo("attrO="+typeof(attrO));
	}

	funcLs_active = funcCode_active = (lWdg && archO);
	result_value = "";

	if(funcCode_active) {
		dtTm = lWdg.nodePrev().trnd1.attr("tSek");
		if(dtTm <= 0)	dtTm = SYS.time();
		dtTmBeg = dtTm - lWdg.nodePrev().trnd1.attr("tSize");
		valArch = lWdg.nodePrev().trnd1.attr("valArch");

		//Prepare the execution context
		inPrcId = this.nodePath("_");
		inPrcLng = "JavaLikeCalc.JavaScript";
		inPrcErr = "";
		inPrcArgs = new Object();
		inPrcArgs.beg = dtTmBeg*1e6;
		inPrcArgs.end = dtTm*1e6;
		inPrcArgs.per = (inPrcArgs.end-inPrcArgs.beg) / 1000;
		inPrcArgs.data = archO.getVals(inPrcArgs.beg, inPrcArgs.end, inPrcArgs.per, valArch);

		title_text = tr("Calculation for the parameter \"%1\" archive at the data range [%2...%3] and the archiver \"%4\"")
			.replace("%1", lWdg.attr("name"))
			.replace("%2", SYS.strftime(1e-6*inPrcArgs.beg,"%Y-%m-%dT%H:%M:%S"))
			.replace("%3", SYS.strftime(1e-6*inPrcArgs.end,"%Y-%m-%dT%H:%M:%S"))
			.replace("%4", valArch.length ? valArch : tr("All"));

		//Functions library
		fLib = new Object();
		fLib[tr("Sum, at hour")] = "vl = 0, prVl = EVAL;\n"
			"for(i = 0; i < data.length; i++) {\n"
			"	if((cVl=data[i]).isEVal() && !prVl.isEVal())	cVl = prVl;\n"
			"	if(cVl.isEVal())	continue;\n"
			"	vl += cVl;\n"
			"	prVl = cVl;\n"
			"}\n"
			"result = \"Summary=\"+vl.toPrecision(6)+\"; \"\n"
			"	\"Hours=\"+((end-beg)/3600e6).toPrecision(6)+\"; \"\n"
			"	\"Value*hours=\"+(vl*per/3600e6).toPrecision(6);";
		fLib[tr("Average and range")] = "vl = EVAL, cnt = 0, vlMax = -1e300, tmMax = 0, vlMin = 1e300, tmMin = 0;\n"
			"for(i = 0; i < data.length; i++)\n"
			"	if((cVl=data[i]).isEVal())	continue;\n"
			"	else {\n"
			"		if(vl.isEVal())	vl = cVl;\n"
			"		else vl += cVl;\n"
			"		if(cVl > vlMax)	vlMax = cVl, tmMax = i;\n"
			"		if(cVl < vlMin)	vlMin = cVl, tmMin = i;\n"
			"		cnt++;\n"
			"	}\n"
			"result = \"Average=\"+(vl/cnt).toPrecision(6)+\"; \"\n"
			"	\"Minimum=\"+vlMin.toPrecision(6)+\"(\"+SYS.strftime(1e-6*(beg+tmMin*per))+\"); \"\n"
			"	\"Maximum=\"+vlMax.toPrecision(6)+\"(\"+SYS.strftime(1e-6*(beg+tmMax*per))+\")\";";

		funcLs_items = "";
		for(var iL in fLib)	funcLs_items += (funcLs_items.length?"\n":"") + iL;			
	}
	else title_text = tr("Error connecting to the widget '%1'!").replace("%1", pgOpenSrc);

	toCalc = funcCode_value.length;
}

//Events for commands process
for(evRez = "", off = 0; (evCur=event.parse(0,"\n",off)).length; ) {
	//this.messInfo("Event: "+evCur);
	if(evCur == "ws_CombChange:/funcLs" && !fLib[funcLs_value].isEVal())
		funcCode_value = fLib[funcLs_value], toCalc = true;
	else if(evCur == "ws_TxtAccept:/funcCode")	toCalc = true;
}

//Calculation
if(toCalc)	{
	inPrcArgs.result = "";
	rez = SYS.DAQ.funcCall(inPrcLng, inPrcArgs, funcCode_value, inPrcId, inPrcErr);
	result_value = rez ? inPrcArgs.result : inPrcErr;
	toCalc = false;
}


ID: alarmsStReport
PARENT: /wlb_originals/wdg_Box
ATTRS: owner;name;dscr;geomW;geomH;pgGrp;backColor;bordWidth;
ICO:

PROC:
JavaLikeCalc.JavaScript
//Events for commands process
for(off = 0, ev_rez = ""; (ev_cur=event.parse(0,"\n",off)).length; ) {
	if(ev_cur == "ws_BtPress:/apply")	this.attrSet("pgOpen",false);
	else ev_rez += ev_cur + "\n";
}
event = ev_rez;


ID: storeHouse
PARENT: /wlb_originals/wdg_Box
ATTRS: owner;name;dscr;geomX;geomY;geomW;geomH;geomZ;evProc;pgOpenSrc;pgGrp;backColor;bordWidth;bordColor;
ICO:

PROC:
JavaLikeCalc.JavaScript
function messByLang(iMess) {
	if((tVl=iMess.match("^"+(this.ownerSess().reqLang().length?this.ownerSess().reqLang():SYS.lang())+":(.+)$","m")).length)
		return tVl[1];
	return iMess.parseLine(0);
}

if(f_start) {
	toUpdate = false;
	fMax = 5;
	btClassEdit_en = dataEditable && classEditable;
	if(classFix.length)	classNm_text = class = classFix;
	else classSel_en = true;
	btEdit_en = dataEditable;
	colVars = new Object();
	btClassEdit_value = btEdit_value = false;
	wUser = "";
}

if(wUser != this.ownerSess().reqUser()) {
	wUser = this.ownerSess().reqUser();

	btClassEdit_value = btEdit_value = false;
	toUpdate = true;
}

//Common events process
for(off = 0; (sval=event.parse(0,"\n",off)).length; ) {
	//this.messInfo("TEST 01: Event="+sval);
	if(sval == "ws_BtToggleChange:/btClassEdit") {
		classEd_en = !classFix.length && btClassEdit_value;
		classSel_en = !classFix.length && !btClassEdit_value;
		toUpdate = true;
		itDel_active = itCopy_active = false;
	}
	else if(sval == "ws_BtToggleChange:/btEdit")	toUpdate = true;
	else if(sval == "ws_CombChange:/classSel")	{ class = ((tVl=classSel_value.match("\\((.+)\\)$")).length) ? tVl[1] : classSel_value; toUpdate = true; colVars = new Object(); }
	else if(sval == "ws_LnAccept:/classEd")		{ class = classEd_value; toUpdate = true; colVars = new Object(); }
}

if((f_start || toUpdate) /*&& !classFix.length*/) {
	clsLs = SYS.BD.nodeAt(db,".").SQLReq("SELECT DISTINCT CLASS FROM `classes`;");
	classSel_items = "";
	for(iR = 1; iR < clsLs.length; iR++) {
		clsNm = SYS.BD.nodeAt(db,".").SQLReq("SELECT `NAME` FROM `classes` WHERE `CLASS`='"+clsLs[iR][0]+"' AND `ID`='NAME';");
		classSel_items = (classSel_items.length?"\n":"") + ((clsNm.length==2)?messByLang(clsNm[1][0]) + " ("+clsLs[iR][0]+")":clsLs[iR][0]);
	}
	classEd_cfg = classSel_items;

	clsNm = SYS.BD.nodeAt(db,".").SQLReq("SELECT `NAME` FROM `classes` WHERE `CLASS`='"+class+"' AND `ID`='NAME';");
	classNm_text = classSel_value = classEd_value = class;
	if(clsNm.length == 2)	classNm_text = classSel_value = messByLang(clsNm[1][0]) + " ("+class+")";

	dataTbl_geomY = btClassEdit_value ? lab_fltr_geomY : fltrCol0_geomY + fltrCol0_geomH;
	dataTbl_geomH = itDel_geomY - dataTbl_geomY + ((btClassEdit_value||btEdit_value)?0:itDel_geomH);

	//Apply filter vertical offset and size
	if(!btClassEdit_value) {
		for(iF = fMax-1; iF > 0 && !this["fltr"+iF].attr("en"); iF--) ;
		dataTbl_geomY = this["fltr"+iF].attr("geomY") + this["fltr"+iF].attr("geomH");
		dataTbl_geomH = itDel_geomY + (btEdit_value?0:itDel_geomH) - dataTbl_geomY;
	}

	btClassEdit_active = class.length;
	itCopy_en = !btClassEdit_value;
}

//The class edition mode
if(btClassEdit_value) {
	SYS.BD.nodeAt(db,".").SQLReq("CREATE TABLE IF NOT EXISTS `classes` (`CLASS` varchar(20) DEFAULT '', `ID` varchar(20) DEFAULT '', `NAME` text, `TP` varchar(100) DEFAULT '', `TBL` varchar(100) DEFAULT '', `FILTER` text, PRIMARY KEY (`CLASS`,`ID`));");

	//Updation the main table
	if(f_start || toUpdate) {
		// Requesting the table structure
		dataTbl = SYS.BD.nodeAt(db,".").SQLReq("SELECT `ID`,`NAME`,`TP`,`TBL`,`FILTER` FROM `classes` WHERE `CLASS`='"+class+"';");
		dataTbl_items = "<tbl sel='row' colsWdthFit='0' hHdrVis='1' vHdrVis='1'>\n";
		for(iR = 0; iR < dataTbl.length; iR++) {
			dataTbl_items += iR ? "<r>" : "<h>";
			for(iC = 0; iC < dataTbl[iR].length; iC++) {
				itVl = dataTbl[iR][iC];
				tNm = "s", opt = "";
				if(iR == 0)	 {
					opt += " edit='1'";
					if(itVl == "ID")				itVl = tr("Identifier");
					else if(itVl == "NAME")	itVl = tr("Name");
					else if(itVl == "TP")		itVl = tr("Type");
					else if(itVl == "TBL")		itVl = tr("Table properties");
					else if(itVl == "FILTER")	itVl = tr("Filter");
				}
				else {
				    if(iC == 1)	tNm = "t";
				    if(itVl == "<NULL>")	itVl = "";
				}
				dataTbl_items += "<"+tNm+opt+">"+SYS.strEncode(itVl,"HTML")+"</"+tNm+">";
			}
			dataTbl_items += iR ? "</r>\n" : "</h>\n";
		}
		dataTbl_items += "</tbl>";

		toUpdate = false;
	}

	//Class edition events process
	for(off = 0; (sval=event.parse(0,"\n",off)).length; ) {
		//this.messInfo("TEST 01: Event="+sval);
		itDel_active = itCopy_active = dataTbl_value.length;
		if(sval == "ws_BtRelease:/itAdd") {
			// Creation the empty data table with the default structure
			if(dataTbl.length == 1)
				SYS.BD.nodeAt(db,".").SQLReq("CREATE TABLE IF NOT EXISTS `sh_"+class+"` (`ID` INT AUTO_INCREMENT, `NAME` varchar(200) DEFAULT '', `DSCR` text, PRIMARY KEY (`ID`));");
			SYS.BD.nodeAt(db,".").SQLReq("INSERT INTO `classes` (`CLASS`,`ID`,`NAME`,`TP`) VALUES ('"+class+"','NewItem','"+tr("New item")+"','varchar(100)');");
			SYS.BD.nodeAt(db,".").SQLReq("ALTER TABLE `sh_"+class+"` ADD `SP_NewItem` varchar(100) DEFAULT '';");
			toUpdate = true;
		}
		else if(sval == "dlg_Apply:/itDel") {
		//else if(sval == "ws_BtRelease:/itDel") {
			SYS.BD.nodeAt(db,".").SQLReq("DELETE FROM `classes` WHERE `ID`='"+dataTbl_value+"';");
			if(dataTbl.length > 2)	SYS.BD.nodeAt(db,".").SQLReq("ALTER TABLE `sh_"+class+"` DROP `SP_"+dataTbl_value+"`;");
			else SYS.BD.nodeAt(db,".").SQLReq("DROP TABLE `sh_"+class+"`;");
			toUpdate = true;
		}
		else if(sval.slice(0,12) == "ws_TableEdit") {
			col = sval.parse(0,"_",13).toInt(); row = sval.parse(1,"_",13).toInt();
			colID = dataTbl[0][col];
			if(!SYS.BD.nodeAt(db,".").SQLReq("UPDATE `classes` SET `"+colID+"`='"+SYS.strEncode(dataTbl_set,"SQL")+"' WHERE `CLASS`='"+class+"' AND `ID`='"+dataTbl[row+1][0]+"';").err.length) {
				if(colID == "ID") SYS.BD.nodeAt(db,".").SQLReq("ALTER TABLE `sh_"+class+"` CHANGE `SP_"+dataTbl[row+1][0]+"` `SP_"+dataTbl_set+"` "+dataTbl[row+1][2].parse(0,":")+";");	
				else if(colID == "TP") SYS.BD.nodeAt(db,".").SQLReq("ALTER TABLE `sh_"+class+"` MODIFY `SP_"+dataTbl[row+1][0]+"` "+dataTbl_set.parse(0,":")+";");	
			}
			toUpdate = true;
		}
	}

	return;
}

//The data representing mode
if(f_start || toUpdate) {
	// Initiate the filter
	for(iF = 0; iF < fMax; iF++)
		this["fltrCol"+iF].attrSet("items", tr("Disabled")+"\n"+tr("Name")+" (NAME)\n"+tr("Description")+" (DSCR)");

	// Requesting the table structure
	clsLs = SYS.BD.nodeAt(db,".").SQLReq("SELECT `ID`,`NAME`,`TP`,`TBL`,`FILTER` FROM `classes` WHERE `CLASS`='"+class+"';");
	clsLsO = new Object();	
	for(iR = 1; iR < clsLs.length; iR++) {
		clsLsO[clsLs[iR][0]] = tO = new Object();
		tO.name = ((tO.name=clsLs[iR][1]) == "<NULL>" || !tO.name.length) ? clsLs[iR][0] : messByLang(tO.name);
		tO.tp = clsLs[iR][2];
		tO.tbl = clsLs[iR][3];
		if((tO.fltr=clsLs[iR][4]) == "<NULL>")	tO.fltr = "";

		for(iF = 0; iF < fMax; iF++)
			this["fltrCol"+iF].attrSet("items", this["fltrCol"+iF].attr("items")+"\n"+tO.name+" (SP_"+clsLs[iR][0]+")");
	}

	//Updation the main table
	// Where prepairing for the filter
	for(wherePart = "", iF = 0; iF < fMax; iF++) {
		if(!(tVl=this["fltr"+iF].attr("value")).length)	continue;
		itVl = this["fltrCol"+iF].attr("value").match("\\((.+)\\)")[1];
		wherePart += (wherePart.length?"AND":"") + " `"+itVl+"` REGEXP '"+tVl+"' ";
		if(!colVars[itVl].isEVal())	colVars[itVl]["<lock>"] = true;
	}
	for(var iC in colVars)
		if(colVars[iC]["<lock>"] == true)	delete colVars[iC]["<lock>"];
		else delete colVars[iC];
	// Same requesting
	dataTbl = SYS.BD.nodeAt(db,".").SQLReq("SELECT * FROM `sh_"+class+"` "+(wherePart.length?"WHERE"+wherePart:"")+"ORDER BY 'ID';");
	dataTbl_items = "<tbl sel='row' sortEn='"+(btEdit_value?0:1)+"' colsWdthFit='0' hHdrVis='1' vHdrVis='1'>\n";
	colTps = new Object();
	for(iR = 0; iR < dataTbl.length; iR++) {
		dataTbl_items += iR ? "<r>" : "<h>";
		for(iC = 0; iC < dataTbl[iR].length; iC++) {
			itVl = dataTbl[iR][iC];
			opt = "";
			if(iR == 0) {
				if(itVl == "ID")	opt += " width='0px'";
				else {
					opt += btEdit_value ? " edit='1'" : "";
					if(itVl == "NAME")	{ itVl = tr("Name"); opt += " width='170px' align='center'"; }
					else if(itVl == "DSCR")	{ colTps[iC] = "t"; itVl = tr("Description"); opt += " width='350px'"; }
					else if(itVl.slice(0,3) == "SP_" && !(tVl=clsLsO[itVl.slice(3)]).isEVal()) {
						if((tVl.fltr == "index" || tVl.fltr.indexOf("list") == 0) && colVars[itVl].isEVal()) {
							colVars[itVl] = new Object();
							colVars[itVl].ls = new Object();
							colVars[itVl].fltr = tVl.fltr;
						}
						itVl = tVl.name;
						if(tVl.tp.search("bool","i") >= 0)		colTps[iC] = "b";
						else if(tVl.tp.search("int","i") >= 0)	colTps[iC] = "i";
						else if(tVl.tp.search("(float|double)","i") >= 0) colTps[iC] = "r";
						else if(tVl.tp.search("text","i") >= 0)	colTps[iC] = "t";
						if((tVl2=tVl.tbl.parse(0,":")).length)	opt += " align='"+tVl2+"'";
						if((tVl2=tVl.tbl.parse(1,":")).length)	opt += " width='"+tVl2+"'";
						//this.messInfo("iC="+iC+"; tp="+tVl.tp+" = "+colTps[iC]+"; tVl.fltr="+tVl.fltr);
					}
				}
				dataTbl_items += "<s"+opt+">"+SYS.strEncode(itVl,"HTML")+"</s>";
			}
			else {
				if(itVl == "<NULL>")	itVl = "";
				if(!colTps[iC].isEVal())	dataTbl_items += "<"+colTps[iC]+opt+">"+SYS.strEncode(itVl,"HTML")+"</"+colTps[iC]+">";
				else dataTbl_items += "<s"+opt+">"+SYS.strEncode(itVl,"HTML")+"</s>";
				if(!(tVl2=colVars[dataTbl[0][iC]]).isEVal())	{
					if(tVl2.fltr == "index" && itVl.length)	tVl2.ls[itVl] = true;
					else if(tVl2.fltr.indexOf("list") == 0) {
						tLs = itVl.split(tVl2.fltr[4]);
						for(iLs = 0; iLs < tLs.length; iLs++)
							tVl2.ls[tLs[iLs].trim()] = true;
					}
				}
			}
		}
		dataTbl_items += iR ? "</r>\n" : "</h>\n";
	}
	dataTbl_items += "</tbl>";

	//Filter's selection list update
	for(iF = 0; iF < fMax; iF++) {
		iFCo = this["fltrCol"+iF]; iFo = this["fltr"+iF];
		fCol = iFCo.attr("value").match("\\((.+)\\)")[1];
		//this.messInfo("iF="+iF+"; fCol="+fCol+"; colVars[fCol]="+colVars[fCol]);
		if((tO=colVars[fCol]).isEVal())	continue;
		tO = tO.ls;
		fCfg = "";
		fCfgPref = iFo.attr("value");
		for(sumVl = "", tVl1 = "", off = 0; (tVl=fCfgPref.parse(0,"|",off)).length; tVl1 = tVl)
			if(tVl1.length) { sumVl += (sumVl.length?"|":"")+tVl1; fCfg += sumVl + "\n"; }
		for(var iFv in tO)
			if(iFv.length && fCfgPref.indexOf(iFv) < 0)
				fCfg += (fCfgPref.length?fCfgPref+"|":"") + iFv + "\n";
			//fCfg += iFv+"\n";
		iFo.attrSet("cfg", fCfg);
	}

	toUpdate = false;
}

//Representing events process
for(off = 0; (sval=event.parse(0,"\n",off)).length; ) {
	//this.messInfo("TEST 01: Event="+sval+" : "+dataTbl_value);
	itDel_active = itCopy_active = dataTbl_value.length;
	if(sval == "ws_BtRelease:/itAdd") {
		nmLs = vlLs = "";
		//Prepairing the filter values
		for(iF = 0; iF < fMax; iF++) {
			if(!(tVl=this["fltr"+iF].attr("value")).length)	continue;
			nmLs += (nmLs.length?",":"") + "`"+this["fltrCol"+iF].attr("value").match("\\((.+)\\)")[1]+"`";
			vlLs += (vlLs.length?",":"") + "'"+tVl+"'";
		}
		if(nmLs.indexOf("`NAME`") < 0)	{ nmLs += (nmLs.length?",":"") + "`NAME`"; vlLs += (vlLs.length?",":"") + "'"+tr("New item")+"'"; }
		SYS.BD.nodeAt(db,".").SQLReq("INSERT INTO `sh_"+class+"` ("+nmLs+") VALUES ("+vlLs+");");
		toUpdate = true;
	}
	else if(sval == "dlg_Apply:/itDel") {
	//else if(sval == "ws_BtRelease:/itDel") {
		SYS.BD.nodeAt(db,".").SQLReq("DELETE FROM `sh_"+class+"` WHERE `ID`='"+dataTbl_value+"';");
		toUpdate = true;
	}
	else if(sval == "ws_BtRelease:/itCopy") {
		for(colLs = "", iC = 1; iC < dataTbl[0].length; iC++)
			colLs += (colLs.length?", ":"") + "`"+dataTbl[0][iC]+"`";
		SYS.BD.nodeAt(db,".").SQLReq("INSERT INTO `sh_"+class+"` ("+colLs+") (SELECT "+colLs+" FROM `sh_"+class+"` WHERE `ID` = "+dataTbl_value+");");
		toUpdate = true;
	}
	else if(sval.slice(0,12) == "ws_TableEdit") {
		col = sval.parse(0,"_",13).toInt(); row = sval.parse(1,"_",13).toInt();
		SYS.BD.nodeAt(db,".").SQLReq("UPDATE `sh_"+class+"` SET `"+dataTbl[0][col]+"`='"+SYS.strEncode(dataTbl_set,"SQL")+"' WHERE `"+dataTbl[0][0]+"`='"+dataTbl[row+1][0]+"';");
		//toUpdate = true;	//!!!! To prevent the spare flicking
	}
	else if(sval.slice(0,22) == "ws_CombChange:/fltrCol") {
		fN = sval.slice(22).toInt();
		fAct = !this["fltrCol"+fN].attr("value").match("\\((.+)\\)")[1].isEVal();
		this["fltr"+fN].attrSet("active", fAct).attrSet("value", "").attrSet("cfg", "");
		if(fAct && (fN+1) < fMax && !this["fltrCol"+(fN+1)].attr("en")) {
			this["fltrCol"+(fN+1)].attrSet("en", true);
			this["fltr"+(fN+1)].attrSet("en", true).attrSet("active", false).attrSet("value", "");
		}
		else for(iF = fMax-1; !fAct && iF >= fN; iF--)
			if(iF < (fMax-1)) {
				this["fltrCol"+(iF+1)].attrSet("en", false).attrSet("value", tr("Disabled"));
				this["fltr"+(iF+1)].attrSet("en", false).attrSet("active", false).attrSet("value", "");
			}

		toUpdate = true;
	}
	else if(sval.slice(0,17) == "ws_LnAccept:/fltr")	toUpdate = true;
}


