<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v2004 rel. 3 U (http://www.xmlspy.com) by alex (mmlab) -->
<rmml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="L:\collaborative-nir\program\Cscl3DWS\rmml\RMML.xsd">
	<include src="button.xml" />
	<include src="imhint.xml" />
	<composition _name="CComments" _depth="-100">
		<script>
			this.maxWidth = 534;
			this.minHeight = 58;
			this.minYPosition = 600;
			this.sResPath = '';
			this.instruction = "";
			this.comments = new Array();
			this.currentComment = null;
			this.currentSize = 14;
			this.state="minimized";
			this.spacing=8;
			this.bSecureMode=false;
			this.showOpenCloseBtns = true;
		</script>
		<!-- Иконки -->
		<!--<composition name="btnRepeat" class="CImageButton"  x="-54" y="3">
			<image _name="img" src="eval(ENVRPATH+'textwnd\\iconrepeat.png')"/>
		</composition>-->
		<composition name="btnSecure" class="CImageButton"  x="-27" y="1">
			<image _name="img" src="eval(ENVRPATH+'textwnd\\iconsecure.png')"  class="CHintImage">
				<script>
					this.hint="Включить автораскрытие";
				</script>
			</image>
			<script event="onClick">
				parent.secureMode(true);
			</script>
		</composition>
		<composition name="btnSecureOn" class="CImageButton"  x="-27" y="3" visible="false">
			<image _name="img" src="eval(ENVRPATH+'textwnd\\iconsecureOn.png')"  class="CHintImage">
				<script>
					this.hint="Выключить автораскрытие";
				</script>
			</image>
			<script event="onClick">
				parent.secureMode(false);
			</script>
		</composition>
		<script>
			function secureMode(mode)
			{
				if( mode)
				{
					btnSecure.hide();
					btnSecureOn.show();
				}
				else
				{
					btnSecure.show();
					btnSecureOn.hide();
				}
				this.bSecureMode = mode;
			}
		</script>
		<composition name="btnOpen" class="CImageButton"   x="244" y="-3" depth="-2" >
			<image _name="img" src="eval(ENVRPATH+'textwnd\\open.png')"/>
			<script event="onClick" >
				parent.onPaperPress();
			</script>
		</composition>
		<composition name="btnClose" class="CImageButton"   x="244" y="-3" depth="-2" visible="false" >
			<image _name="img" src="eval(ENVRPATH+'textwnd\\close.png')"/>
			<script event="onClick" >
				parent.onPaperPress();
			</script>
		</composition>

		<styles _name="stlComments" fontSize="14" fontFamily="Microsoft Sans Serif" textAlign="justify" color="#000000"/>
		<text _name="tcomment" style="parent.stlComments" _depth="-2" _x="8"/>
		<xml _name="engine"/>
		<script src="comments.mjs"/>
		<script><![CDATA[
			function addComment(txt, id)
			{
				var comment = new CCommentItem();
				comment.id = id;
				comment.text = txt;
				this.comments.push(comment);
			}
			function Initialize()
			{
				var Level1=this.engine.XMLDocument.firstChild.childNodes;
				var len=Level1.length;
trace("len="+len);
				for(var ii=0; ii<len; ii++)
				{
					item=Level1.item(ii);
					if( item.nodeName == null)	continue;
					else	if( item.nodeName == "instruction")
						loadInstruction(item);
					else	if( item.nodeName == "comments")
						loadComments(item);
				}
				if( this.comments.length>1)	showComment(0);
			}
			function loadInstruction(node)
			{
				var children=node.childNodes;
				var len=children.length;
				for(var ii=0; ii<len; ii++)
				{
					child=children.item(ii);
					if( child.nodeName == "#text")
					{
						this.instruction = child.nodeValue;
					}
				}
			}
			function loadComments(node)
			{
				var children=node.childNodes;
				var len=children.length;
				for(var ii=0; ii<len; ii++)
				{
					child=children.item(ii);
					if( child.nodeName == "entry")
						loadComment(child);
				}
			}
			function loadComment(node)
			{
				var children=node.childNodes;
				if( children==null || children==undefined)	return;
				var len=children.length;
				for(var ii=0; ii<len; ii++)
				{
					child=children.item(ii);
					if( child.nodeName == "#text")
					{
						var comment = new CCommentItem();
						comment.id = node.getAttribute('id');
						comment.text = child.nodeValue;
						this.comments[this.comments.length] = comment;
					}
				}
			}
			function showComment(id)
			{
//			return;
//			trace("showComment "+id);
				if( id == undefined)
				{
					showTextComment("");
					return;
				}
				this.currentComment=null;
				if( isNaN(parseInt(id)))	// is not numeric
				{
					for(var ii=0;ii<this.comments.length;ii++)
					{
						if( this.comments[ii].id==id)
						{
							this.currentComment = this.comments[ii];
							break;
						}
					}
				}
				else
				{
					if( id >= this.comments.length)	return;
					this.currentComment = this.comments[id];
				}
				if(this.currentComment==null)
					showTextComment(id);
				else
					showTextComment(this.currentComment.text);
			}
			function showTextComment(txt)
			{
				this.tcomment._visible = false;
				this.tcomment._width = this.maxWidth;
				//var	tvalue = "<p align=\"left\"><font size=\"" + this.currentSize + "\">" + txt + "</font></p>";
				var	tvalue = "<p align=\"left\">" + txt + "</p>";
				this.tcomment.value = tvalue;
				UpdateLayout();
				this.alignText();
				this.btnOpen.hide();
				this.btnClose.hide();
				if( this.textIsSliced())
				{
					//trace("state = "+state);
					if (this.showOpenCloseBtns)
					{
						if( state == "minimized")	this.btnOpen.show();
						else	if( state == "minimized")	this.btnClose.show();
					}

					trace("&&&&&&&&&&&& this.bSecureMode="+this.bSecureMode);
					if( this.bSecureMode)
					{
						if( this.state == "minimized")
							this.Maximize();
					}
				}
				this.tcomment._visible = true;
			}
			
			function showOpenCloseBtns(show)
			{
				if (show)
				{
					this.showOpenCloseBtns = true;
					if( state == "minimized")	this.btnOpen.show();
					else	if( state == "minimized")	this.btnClose.show();
					this.frame.enabled = true;
				}
				else
				{
					this.showOpenCloseBtns = false;
					this.btnClose.visible = false;
					this.btnOpen.visible = false;
					this.frame.enabled = false;
				}
				
			}
			
			function SetPaperSize(tw, th)
			{
				var frameHeight = this.frame.getTopBorder()+this.frame.getBottomBorder();
				//trace("frameHeight["+frameHeight+"]" + this.frame.getTopBorder() + ":" + this.frame.getBottomBorder());
				this.frame.resize(tw+this.frame.getLeftBorder()+this.frame.getRightBorder()+spacing, th + frameHeight);
				this.tcomment._height = th;
				this._y = this.minYPosition - th - frameHeight;
				alignText();
				arrangeIcons();
			}
			function Minimize()
			{
				//trace("Minimize text comment");
				this.state="minimized";
				SetPaperSize(this.maxWidth, this.minHeight);
				this.btnOpen._visible = this.textIsSliced();
				this.btnClose.hide();
			}
			function Maximize()
			{
//				trace("Maximize text comment");
				this.state="maximized";
				trace("this.tcomment.getMediaSize().height="+this.tcomment.getMediaSize().height);
				trace("this.tcomment.height="+this.tcomment.height);
				if( this.textIsSliced())
				{
					SetPaperSize(this.maxWidth, this.tcomment.getMediaSize().height);
					this.btnOpen.hide();
					this.btnClose.show();
				}
				else
					Minimize();
			}
			function arrangeIcons()
			{
				//this.btnRepeat.y = this.tcomment._height - 19;
				//this.btnRepeat.y = this.tcomment._height - 19;
				this.btnSecure.y = this.tcomment._height - 21;
				this.btnSecureOn.y = this.tcomment._height - 19;
			}
			function textIsSliced()
			{
				return this.tcomment.getMediaSize().height > this.tcomment.height+this.currentSize/2;
			}
			function  getVShiftBySize()
			{
				if( this.currentSize >= 20)	return 3;
				return 0;
			}
			function UpdateLayout()
			{
				if( this.state=="minimized")
					this.Minimize();
				else	if( this.state=="maximized")
					this.Maximize();
			}
			function alignText()
			{
				// V center this text
				var rh = this.tcomment.getMediaSize().height;
				if( this.state=="minimized" || this.textIsSliced())
				{
					this.tcomment._y = this.frame.lt._height - getVShiftBySize();
				}
				else
				{
					this.tcomment._y = (this.tcomment.height-rh)/2 + this.frame.lt._height - getVShiftBySize();
				}
			}
			function resize(w, h)
			{
				this.maxWidth = w;
				this.minHeight = h;
				this.btnClose.x = (w-this.btnClose.width)/2;
				this.btnOpen.x = (w-this.btnOpen.width)/2;
				this.Minimize();
			}
		]]></script>
		<composition _name="frame" _depth="-1">
			<image _name="lt" src="eval(ENVRPATH+'comments.png')" _visible="true" ><script>this.crop(0,0,3,6);	</script></image>
			<image _name="ct" src="eval(ENVRPATH+'comments.png')" _visible="true"><script>this.crop(3,0,10,6);	</script></image>
			<image _name="rt" src="eval(ENVRPATH+'comments.png')" _visible="true"><script>this.crop(13,0,3,6);	</script></image>
			<image _name="lc" src="eval(ENVRPATH+'comments.png')" _visible="true"><script>this.crop(0,6,3,21);	</script></image>
			<image _name="cc" src="eval(ENVRPATH+'comments.png')" _visible="true"><script>this.crop(3,6,10,21);	</script></image>
			<image _name="rc" src="eval(ENVRPATH+'comments.png')" _visible="true"><script>this.crop(13,6,3,21);	</script></image>
			<image _name="lb" src="eval(ENVRPATH+'comments.png')" _visible="true"><script>this.crop(0, 27,3,5);	</script></image>
			<image _name="cb" src="eval(ENVRPATH+'comments.png')" _visible="true"><script>this.crop(3, 27,10,5);	</script></image>
			<image _name="rb" src="eval(ENVRPATH+'comments.png')" _visible="true"><script>this.crop(13,27,3,5);	</script></image>
			<script>
				function	resize(w, h)
				{
					ct._x = lt.width;
					ct.width = w - lt.width - rt.width;
					rt._x = w - rt.width;

					lc._y = lt.height;			lc.height = h - lt.height - lb.height;
					rc._x = w - rc.width;	rc.height = lc.height;	rc._y = rt._height;

					lb._y = h - lb.height;
					cb._x = lb._width;	cb._y = h - cb.height;	cb._width = w - lb.width - rb.width;
					rb._x = w - rb.width;	rb._y = h - rb.height;

					cc._x = lt._width;	cc._y = lt._height;
					cc._width = w - lc.width - rc.width;
					cc._height = h - ct._height - cb._height;
				}
				function	getLeftBorder(){ return lc._width;}
				function	getTopBorder(){ return ct._height;}
				function	getRightBorder(){ return rc._width;}
				function	getBottomBorder(){ return cb._height;}
			</script>
			<script event="onPress">
				parent.onPaperPress();
			</script>
		</composition>

		<script>
			function onPaperPress()
			{
				if( this.state=="minimized")
					this.Maximize();
				else	if( this.state=="maximized")
					this.Minimize();
				else	trace("Error: unknown state in comments.xml[onPress]");
			}
		</script>
		<script><![CDATA[
			this.frame.resize(this.maxWidth, this.maxHeight);
			this.tcomment.sliceTail="...";
		]]></script>
	</composition>
</rmml>
