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;