JavaLikeCalc.JavaScript
if(f_start) {
	//Init the avialable parameters
	set_item_items = "";
	colors = new Array("#ae77c3", "orange", "blue", "#199696", "#3264C8", "tomato", "magenta", "#B6B600", "#69695C", "darkcyan");
	params = new Array();
	for(iP = 1; iP <= 10; iP++) {
		pO = new Object();
		pO.name = this.doc.attr("p"+iP+"name");
		pO.var = this.doc.attr("p"+iP+"var");
		pO.ed = this.doc.attr("p"+iP+"ed");
		if(pO.ed.isEVal())	pO.ed = "";
		pO.prec = this.doc.attr("p"+iP+"prec");
		pO.min = this.doc.attr("p"+iP+"min");
		pO.max = this.doc.attr("p"+iP+"max");
		pO.isCntr = this.doc.attr("p"+iP+"cntr") == true;
		pO.isMan = this.doc.attr("p"+iP+"isMan") == true;
		pO.color = colors[iP-1];
		if(pO.prec.isEVal())	pO.prec = 0;
		if(!pO.name.isEVal() && pO.name.length && !pO.var.isEVal() && pO.var.length &&
				((aO=SYS.nodeAt(pO.var).arch()) || pO.isMan)) {
			params.push(pO);
			pO.isMess = aO ? false : true;
			if(pO.isMess)	pO.mId = pO.var.slice(((tVl=pO.var.lastIndexOf("/"))<0)?0:tVl-1);
			if(pO.isMan)	set_item_items += (set_item_items.length?"\n":"") + pO.name;
		}
	}
	this.doc.attrSet("params", params);

	curYear = 0;
	SYS.localtime(SYS.time(), 0, 0, 0, 0, 0, curYear);
	year_value = curYear;
	year_items = "";
	while(curYear > year_value.toInt()-doc_depth)
		year_items += (year_items.length?"\n":"")+(curYear--);

	toBuild = true;
	this.attrSet("event", this.attr("event")+"usr_calc\n");	//!!!! Just to calc in the next session cycle for update

	return;
}

for(off = 0; (evCur=event.parse(0,"\n",off)).length; )
	//this.messInfo("evCur="+evCur);
	if(evCur == "ws_CombChange:/year")	toBuild = true;
	else if(evCur == "ws_CombChange:/set_item")	set_val_active = set_item_value.length;
	else if(evCur == "ws_LnAccept:/set_val") {
		// Writing the manual input values to the value or message archive
		for(pO = false, iP = 0; iP < params.length; iP++) {
			if((pO=params[iP]).name != set_item_value)	continue;
			vTm = SYS.timegm(0, 0, 0, 1, set_month_value.match("\\((.+)\\)$")[1].toInt()-1, year_value.toInt());
			//this.messInfo("Time "+SYS.strftime(vTm)+" ("+vTm+") value="+set_val_value.toReal()+" archiver="+this.doc.attr("arch")+" isMess="+pO.isMess);
			if(pO.isMess)
				SYS.Archive.messPut(vTm, 0, "val"+pO.mId, 1, pO.name+": "+set_val_value.toReal(), this.doc.attr("arch").parse(1,";"));
			else SYS.nodeAt(pO.var).arch().setVal(1e6*vTm, set_val_value.toReal(), this.doc.attr("arch").parse(0,";"));
			toBuild = true;
			break;
		}
	}

if(toBuild) {
	toBuild = false;

	//Setting the document time
	doc_bTime = SYS.mktime(0, 0, 0, 1, 0, year_value.toInt());
	doc_time = ((eTime=SYS.mktime(0, 0, 0, 1, 0, year_value.toInt()+1)-1) == doc_time) ? 0 : eTime;
	doc_doc = "";

	//this.messInfo("bTime="+doc_bTime+"; time="+eTime+"; bTimeCntr="+SYS.mktime(0, 0, 0, 1, -1, year_value.toInt()));

	//Loading the manual data
	for(messVals = false, iP = 0; iP < params.length; iP++) {
		if(!(pO=params[iP]).isMan)	continue;
		pO.manData = new Object();
		pO.cntrData = new Object();
		pO.manResCntr = firstV = lastV = EVAL;
		pO.trData = "";
		if(pO.isMess) {
			if(!messVals) {
				bTime = SYS.timegm(0, 0, 0, 1, 0, year_value.toInt());
				eTime = SYS.timegm(0, 0, 0, 1, 0, year_value.toInt()+1);
				messVals = SYS.Archive.messGet(SYS.timegm(0,0,0,1,-1,year_value.toInt()),
											eTime, "val*", 1, this.doc.attr("arch").parse(1,";"));
				//this.messInfo("bTime="+SYS.timegm(0,0,0,1,-1,year_value.toInt())+"; eTime="+eTime+"; messVals.len="+messVals.length+"; messVals="+messVals);
			}
			for(iM = 0; iM < messVals.length; iM++) {
				if((mO=messVals[iM]).categ != "val"+pO.mId || (!pO.isCntr && mO.tm < bTime))	continue;
				pO.manData[mO.tm] = finVl = mVl = mO.mess.parse(1, ": ").toReal();
				if(pO.isCntr) { if(!lastV.isEVal())	pO.cntrData[mO.tm] = finVl = mVl - lastV; else finVl = EVAL; }
				if(firstV.isEVal())	firstV = mVl;
				if(mO.tm < eTime)	lastV = mVl;
				if(!finVl.isEVal() && (curPos=floor((mO.tm-bTime)/86400)) >= 0)
					pO.trData += (pO.trData.length?",":"") + mO.tm.toString() + "=" + finVl;
			}
		}
		else {
			aO = SYS.nodeAt(pO.var).arch();
			bTime = SYS.timegm(0, 0, 0, 1, 0, year_value.toInt());
			tTime = SYS.timegm(0, 0, 0, 1, (pO.isCntr?-1:0), year_value.toInt());
			eTime = SYS.timegm(0, 0, 0, 1, 0, year_value.toInt()+1)-1;

			for(iMonth = (pO.isCntr?-1:0); !(tTime >= eTime || tTime >= SYS.time() || iMonth > 12); ) {
				pO.manData[tTime] = finVl = vVl = aO.getVal(1e6*tTime, false, this.doc.attr("arch").parse(0,";"));
				if(pO.isCntr) { if(!lastV.isEVal())	pO.cntrData[tTime] = finVl = vVl - lastV; else finVl = EVAL; }
				if(firstV.isEVal())	firstV = vVl;
				if(tTime < eTime && !vVl.isEVal())	lastV = vVl;
				if(!finVl.isEVal() && (curPos=floor((tTime-bTime)/86400)) >= 0)
					pO.trData += (pO.trData.length?",":"") + curPos.toString() + "=" + finVl;
				iMonth++; tTime = SYS.timegm(0, 0, 0, 1, iMonth, year_value.toInt());
			}
		}
		if(!lastV.isEVal()) {
			if(pO.isCntr)	pO.manResCntr = lastV - firstV;
			pO.trData += (pO.trData.length?",":"") + (curPos+30).toString() + "=" + SYS.strEncode(EVAL,"HTML");
		}
		if(pO.trData.length) {
			pO.trData = "<d per='0'>"+pO.trData+"</d>";
			//this.messInfo("pO.trData="+pO.trData);
		}
	}
}