JavaLikeCalc.JavaScript
function testLev( v1, v2 )
{
	isSub = abs(v1) > 7 && abs(v2) > 7;
	v1_ = abs((!isSub && abs(v1) > 7) ? v1/10 : v1);
	v2_ = abs((!isSub && abs(v2) > 7) ? v2/10 : v2);
	return (v1_ >= v2_);
}

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 || off < highLght.length; ) {
		if(!iH.length || iH[0] == "#")	continue;
		iHo = new Object();
		if(iH.parse(0,":").length > 2)
			iHo.lev = iH.slice(0,2).toInt(), iHo.quiet = iH.slice(2,3).toInt()?1:0;
		else 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(), messCat, -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")+(((tVl=abs(curAlMess[iM].level))>9)?tVl:tVl+"-")+">"+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("Quietance time")+"</s>";
		else if(vC == "lev")	items += "<s>"+tr("Lev.")+"</s>";
		else if(vC == "type")	items += "<s align='center'>"+tr("Type")+"</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(testLev(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 == "type")	items += "<s>"+types.parse(abs(iM.level),";")+"</s>";
			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)
					for(off2 = 0, isFirst = true; (tVl2=srcO[3].parse(0,":",off2)).length; tVl += (tVl.length?".":"")+tVl2, isFirst = false) {
						if(!isFirst)	continue;
						if(!sourceCache[tVl2].isEVal())	tVl2 = sourceCache[tVl2];
						else {
							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() == tVl2) {
									tVl2 = sourceCache[tVl2] = 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);
	}
}