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;
}