<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/xhtml1/strict">
	<xsl:output method="html"/>
	
	<xsl:param name="project-location"/>
	
	<xsl:key match="//node" name="nodeType" use="@type"/>
	
	<xsl:variable name="project-url">
		<xsl:choose>
			<xsl:when test="substring($project-location,1,1) = '\' or substring($project-location,1,1) = '/'">
				<xsl:text>file:</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>file:/</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:value-of select="translate($project-location, '\', '/')"/>
	</xsl:variable>
	<xsl:variable name="project-file-name" select="'project.eau'"/>
	<xsl:variable name="file-extension-nodes" select="document($project-file-name)/project/objects[not(@exclude-from-autoguess = 'yes')]" />
	
	<xsl:param name="is-expanded"/>
	
	<xsl:include href="variables.xsl" />
	<xsl:include href="scripts.xsl" />
	<xsl:include href="helpers.xsl" />
	<xsl:include href="styles.xsl" />
	<xsl:include href="translation.xsl" />

	<xsl:template match="/">
		<body>
			<xsl:copy-of select="$eAuStyles"/>
			<xsl:copy-of select="$eAuScripts"/>
			<div id="eAu-course-floatpanel">
				<xsl:attribute name="style">
					<xsl:value-of select="$eAuStyleFloatpanel"/>
				</xsl:attribute>
				<a
						style="{$eAuStyleFloatpanelButton}"
						onmouseenter="this.style.backgroundColor = '{$eAuStyleFloatpanelButtonHoverColor}'"
						onmouseleave="this.style.backgroundColor = 'transparent';"
						title="{$vApply}"
						onclick="Apply(); return false;"
						href="button:apply"
						id="button-apply"><span style="{$eAuStyleFloatpanelButtonSpan} {$eAuStyleFloatpanelButtonApplySpan}"></span></a>
				<a
						style="{$eAuStyleFloatpanelButton}"
						onmouseenter="this.style.backgroundColor = '{$eAuStyleFloatpanelButtonHoverColor}'"
						onmouseleave="this.style.backgroundColor = 'transparent';"
						title="{$vRefresh}"
						onclick="Refresh(); return false;"
						href="button:reload"
						id="button-reload"><span style="{$eAuStyleFloatpanelButtonSpan} {$eAuStyleFloatpanelButtonRefreshSpan}"></span></a>
				<a
						style="{$eAuStyleFloatpanelButton}"
						onmouseenter="this.style.backgroundColor = '{$eAuStyleFloatpanelButtonHoverColor}'"
						onmouseleave="this.style.backgroundColor = 'transparent';"
						href="button:expand-collapse"
						id="button-expand-collapse">
					<xsl:attribute name="title">
						<xsl:choose>
							<xsl:when test="$is-expanded = 'true'"><xsl:value-of select="$vCollapse"/></xsl:when>
							<xsl:otherwise><xsl:value-of select="$vExpand"/></xsl:otherwise>
						</xsl:choose>
					</xsl:attribute>
					<xsl:attribute name="onclick">
						<xsl:choose>
							<xsl:when test="$is-expanded = 'true'"><xsl:text>Collapse(); return false;</xsl:text></xsl:when>
							<xsl:otherwise><xsl:text>Expand(); return false;</xsl:text></xsl:otherwise>
						</xsl:choose>
					</xsl:attribute>
					<span>
						<xsl:attribute name="style">
							<xsl:value-of select="$eAuStyleFloatpanelButtonSpan"/>
							<xsl:choose>
								<xsl:when test="$is-expanded = 'true'"><xsl:value-of select="$eAuStyleFloatpanelButtonCollapseSpan"/></xsl:when>
								<xsl:otherwise><xsl:value-of select="$eAuStyleFloatpanelButtonExpandSpan"/></xsl:otherwise>
							</xsl:choose>
						</xsl:attribute>
						<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
					</span>
				</a>
			</div>
			<div>
				<div>
					<xsl:attribute name="style">
						padding: 14px 47px;
					</xsl:attribute>
					<div id="root">
						<xsl:attribute name="style">
							border-top-width: 0px;
							zoom: 1;
							cursor: default;
						</xsl:attribute>
						<xsl:for-each select="//node">
							<xsl:if test="count(attributes/attribute) &gt; 0">
								<xsl:if test="attributes/attribute[@name='Название']">
									<div style="padding: 0px 15px; zoom: 1;">
										<input style="display: none;" type="checkbox" checked="true" id="{attributes/attribute[@name='Название']/@checkid}" />
										<input
												type="text"
												value="{attributes/attribute[@name='Название']/@value}" id="{attributes/attribute[@name='Название']/@id}"
												style="border: none; width: 100%; font-size: 22px; font-weight: normal; color: #f78f15; padding: 0px; margin: 0px;"
												onchange="SetModified();">
										</input>
									</div>
								</xsl:if>
								<xsl:for-each select="attributes/attribute[@name != 'Название']">
									<xsl:call-template name="attribute">
										<xsl:with-param name="attr" select="." />
									</xsl:call-template>
								</xsl:for-each>
								<xsl:if test="position() != count(//node)">
									<div>
										<xsl:attribute name="style">
											height: 1px;
											background: transparent url(<xsl:value-of select="$project-url"/>/template-files/dot.gif);
											overflow: hidden;
											margin: 10px 0px;
										</xsl:attribute>
										<xsl:text> </xsl:text>
									</div>
								</xsl:if>
							</xsl:if>
						</xsl:for-each>
					</div>
				</div>
			</div>
		</body>
	</xsl:template>

	<xsl:template name="choice-attribute">
		<xsl:param name="attr" />
		<xsl:variable name="selected">
			<xsl:value-of select="$attr/@value"/>
		</xsl:variable>
		<select id="{$attr/@id}" style="display: none;" tabindex="-1">
			<xsl:for-each select="$attr/case">
				<xsl:variable name="this-text" select="text()"/>
				<option value="{text()}">
					<xsl:if test="$file-extension-nodes/object[@type = $this-text]/mask">
						<xsl:attribute name="filemask">
							<xsl:for-each select="$file-extension-nodes/object[@type = $this-text]/mask"><xsl:value-of select="."/><xsl:text>&#10;</xsl:text></xsl:for-each>
						</xsl:attribute>
					</xsl:if>
					<xsl:if test="$selected = text()">
						<xsl:attribute name="selected">true</xsl:attribute>
					</xsl:if>
					<xsl:value-of select="text()"/>
				</option>
			</xsl:for-each>
			<xsl:if test="$attr/@name = 'Тип' and $attr/../../@name = 'objectType'">
				<option value="any">any</option>
			</xsl:if>
		</select>
		<xsl:choose>
			<xsl:when test="count($attr/case) = 2
					and (
						($attr/case[1] = 'true' and $attr/case[2] = 'false')
						or ($attr/case[1] = 'visible' and $attr/case[2] = 'hidden')
						or ($attr/case[1] = 'yes' and $attr/case[2] = 'no')
					)">
				<div
						tabindex="0"
						style="width: 12px; height: 12px; border: 1px solid #bbb; padding: 1px;"
						id="EU-{$attr/@id}"
						EAUInputType="checkbox">
					<xsl:attribute name="onkeydown">
						if (/^(13|32)$/.test(window.event.keyCode)) {
							this.onmouseup();
							return false;
						}
					</xsl:attribute>
					<xsl:attribute name="onmouseup">
						var node = $(this.id + '-checkbox');
						if (this.getAttribute('checked') == 'unchecked') {
							$('<xsl:value-of select="$attr/@id"/>').selectedIndex = 0;
							this.setAttribute('checked', 'checked');
							node.style.backgroundColor = '#1945a4';
						} else {
							$('<xsl:value-of select="$attr/@id"/>').selectedIndex = 1;
							this.setAttribute('checked', 'unchecked');
							node.style.backgroundColor = 'white';
						}
						<xsl:if test="$attr/@name = 'Оценивать по весам'">
							if (/true/.test($('<xsl:value-of select="$attr/@id" />').value)) {
								$('EU-ATTR-ROW-<xsl:value-of select="$attr/../attribute[@name = 'Максимальный балл']/@id" />')
									.style
									.display = 'none';
							} else {
								$('EU-ATTR-ROW-<xsl:value-of select="$attr/../attribute[@name = 'Максимальный балл']/@id" />')
									.style
									.display = 'block';
							}
						</xsl:if>
						<xsl:if test="$attr/@name = 'Отображать сразу' and $attr/../../@name = 'objectType'">
							if (/true/.test($('<xsl:value-of select="$attr/@id" />').value)) {
								$('EU-ATTR-ROW-<xsl:value-of select="$attr/../attribute[@name = 'Высота']/@id" />')
									.style
									.display = 'block';
								$('EU-ATTR-ROW-<xsl:value-of select="$attr/../attribute[@name = 'Выравнивание']/@id" />')
									.style
									.display = 'block';
							} else {
								$('EU-ATTR-ROW-<xsl:value-of select="$attr/../attribute[@name = 'Высота']/@id" />')
									.style
									.display = 'none';
								$('EU-ATTR-ROW-<xsl:value-of select="$attr/../attribute[@name = 'Выравнивание']/@id" />')
									.style
									.display = 'none';
							}
						</xsl:if>
						SetModified();
						this.focus();
					</xsl:attribute>
					<xsl:attribute name="checked">
						<xsl:choose>
							<xsl:when test="$selected = 'true' or $selected = 'visible'"><xsl:text>checked</xsl:text></xsl:when>
							<xsl:otherwise><xsl:text>unchecked</xsl:text></xsl:otherwise>
						</xsl:choose>
					</xsl:attribute>
					<div id="EU-{$attr/@id}-checkbox">
						<xsl:attribute name="style">
							width: 10px;
							height: 10px;
							overflow: hidden;
							cursor: pointer;
							<xsl:if test="$selected = 'true' or $selected = 'visible'">
								background-color: #1945a4;
							</xsl:if>
						</xsl:attribute>
						<span style="visibility: hidden;">1</span>
					</div>
				</div>
			</xsl:when>
			<xsl:when test="$attr/@name = 'Тип' and $attr/../../@name = 'objectType'">
				<div
						id="EU-{$attr/@id}"
						EAUInputType="select"
						tabindex="-1">
					<xsl:attribute name="style">
						background-color: transparent;
						border: 1px solid #1945a4;
						padding: 1px;
						zoom: 1;
						float: left;
						width: 250px;
					</xsl:attribute>
					<div id="EU-{$attr/@id}-value">
						<xsl:attribute name="style">
							padding: 2px 4px;
							font-size: 80%;
							cursor: default;
							background-color: #1945a4;
							color: white;
						</xsl:attribute>
						<span id="EU-{$attr/@id}-value-none" style="display: block;"><xsl:text>Тип объекта не определён</xsl:text></span>
						<span id="EU-{$attr/@id}-value-sound" style="display: none;"><xsl:text>Аудиофрагмент</xsl:text></span>
						<span id="EU-{$attr/@id}-value-image" style="display: none;"><xsl:text>Изображение</xsl:text></span>
						<span id="EU-{$attr/@id}-value-video" style="display: none;"><xsl:text>Видеофрагмент</xsl:text></span>
						<span id="EU-{$attr/@id}-value-flash" style="display: none;"><xsl:text>Ролик Adobe Flash</xsl:text></span>
						<span id="EU-{$attr/@id}-value-silverlight" style="display: none;"><xsl:text>Ролик Microsoft Silverlight 2.0</xsl:text></span>
						<span id="EU-{$attr/@id}-value-pdf" style="display: none;"><xsl:text>Portable документ (PDF, DjVu)</xsl:text></span>
						<span id="EU-{$attr/@id}-value-html" style="display: none;"><xsl:text>Web документ</xsl:text></span>
						<span id="EU-{$attr/@id}-value-doc" style="display: none;"><xsl:text>Документ</xsl:text></span>
						<span id="EU-{$attr/@id}-value-ppt" style="display: none;"><xsl:text>Презентация</xsl:text></span>
						<span id="EU-{$attr/@id}-value-xls" style="display: none;"><xsl:text>Электронная таблица</xsl:text></span>
						<span id="EU-{$attr/@id}-value-exercise" style="display: none;"><xsl:text>Упражнение</xsl:text></span>
						<span id="EU-{$attr/@id}-value-dwf" style="display: none;"><xsl:text>Чертёж Autocad</xsl:text></span>
						<span id="EU-{$attr/@id}-value-wrl" style="display: none;"><xsl:text>3-х мерная модель VRML</xsl:text></span>
					</div>
				</div>

				<xsl:call-template name="helperScriptOnLoad">
					<xsl:with-param name="code">
						var objectTypeNode = $('<xsl:value-of select="$attr/@id"/>');
						var objectTypeUINode = $('EU-<xsl:value-of select="$attr/@id" />-value');
						var val = "<xsl:value-of select="$attr/../attribute[@name = 'Файл']/@value"/>";
						var objectType = window.eAu_Course.api.detectFileTypeByExtension(
							val
							, window.eAu_Course.api.gatherFileTypeExtensions(objectTypeNode) 
						);
						_.each(_.toArray(objectTypeUINode.getElementsByTagName('span')), function (item) {
							item.style.display = 'none';
						});
						if (objectType) {
							// HACK
							if (objectType == 'html' &amp;&amp; objectTypeNode.value == 'exercise' &amp;&amp; val.toLowerCase().indexOf('./files/exercise') == 0) {
								objectType = objectTypeNode.value;
							}
							objectTypeNode.value = objectType;
							$('EU-<xsl:value-of select="$attr/@id" />-value-' + objectType).style.display = 'block';
						} else {
							$('EU-<xsl:value-of select="$attr/@id" />-value-none').style.display = 'block';
						}
					</xsl:with-param>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<div
						id="EU-{$attr/@id}"
						EAUInputType="select"
						tabindex="0">
					<xsl:attribute name="onkeydown">
						if (window.event.keyCode == 40) {
							selectMoveDown('<xsl:value-of select="$attr/@id"/>');
							return false;
						} else if (window.event.keyCode == 38) {
							selectMoveUp('<xsl:value-of select="$attr/@id"/>');
							return false;
						}
					</xsl:attribute>
					<xsl:attribute name="style">
						background-color: transparent;
						border: 1px solid #1945a4;
						padding: 1px;
						zoom: 1;
						float: left;
						width: 250px;
					</xsl:attribute>
					<xsl:for-each select="$attr/case">
						<div id="EU-{$attr/@id}-{position()}">
							<xsl:attribute name="style">
								padding: 2px 4px;
								font-size: 80%;
								cursor: pointer;
								<xsl:if test="$selected = text()">
									background-color: #1945a4;
									color: white;
								</xsl:if>
							</xsl:attribute>
							<xsl:attribute name="onmousedown">
								var node = $('<xsl:value-of select="$attr/@id"/>');
								var selectedIndex = node.selectedIndex;
								var clickedPosition = parseInt('<xsl:value-of select="position()"/>', 10);
								if (clickedPosition == selectedIndex + 1) {
									return;
								}

								selectSelectThis('<xsl:value-of select="$attr/@id" />', '<xsl:value-of select="position()"/>');

								<xsl:if test="$attr/@name = 'Тип' and $attr/../../@name = 'questionType'">
									if (/single|multiple/.test(node.value)) {
										$('EU-ATTR-ROW-<xsl:value-of select="$attr/../attribute[@name = 'Оценивать по весам']/@id" />')
											.style
											.display = 'block';
										if ($('<xsl:value-of select="$attr/../attribute[@name = 'Оценивать по весам']/@id" />').value == 'true') {
											$('EU-ATTR-ROW-<xsl:value-of select="$attr/../attribute[@name = 'Максимальный балл']/@id" />')
												.style
												.display = 'none';
										} else {
											$('EU-ATTR-ROW-<xsl:value-of select="$attr/../attribute[@name = 'Максимальный балл']/@id" />')
												.style
												.display = 'block';
										}
									} else {
										$('EU-ATTR-ROW-<xsl:value-of select="$attr/../attribute[@name = 'Оценивать по весам']/@id" />')
											.style
											.display = 'none';
										$('EU-ATTR-ROW-<xsl:value-of select="$attr/../attribute[@name = 'Максимальный балл']/@id" />')
											.style
											.display = 'block';
									}
									if (/^(classify|sort)$/.test(node.value)) {
										$('EU-ATTR-ROW-<xsl:value-of select="$attr/../attribute[@name = 'Перемешивать ответы']/@id" />')
											.style
											.display = 'none';
									} else {
										$('EU-ATTR-ROW-<xsl:value-of select="$attr/../attribute[@name = 'Перемешивать ответы']/@id" />')
											.style
											.display = 'block';
									}
								</xsl:if>
								<xsl:if test="$attr/@name = 'Механизм выбора вопросов теста'">
									if (/0/.test(node.value)) {
										$('EU-ATTR-ROW-<xsl:value-of select="$attr/../attribute[@name = 'Количество вопросов в тесте']/@id" />')
											.style
											.display = 'block';
									} else {
										$('EU-ATTR-ROW-<xsl:value-of select="$attr/../attribute[@name = 'Количество вопросов в тесте']/@id" />')
											.style
											.display = 'none';
									}
								</xsl:if>
								SetModified();
							</xsl:attribute>
							<xsl:choose>
								<xsl:when test="text() = '0' and ../@name = 'Механизм выбора вопросов теста'">
									<xsl:text>одинаковое количество вопросов из каждой группы</xsl:text>
								</xsl:when>
								<xsl:when test="text() = '1' and ../@name = 'Механизм выбора вопросов теста'">
									<xsl:text>количество вопросов по группам задано явно</xsl:text>
								</xsl:when>
								<xsl:when test="text() = '0' and ../@name = 'Способ прохождения тестирования'">
									<xsl:text>нельзя пропускать вопросы,</xsl:text><br /><xsl:text>нельзя возвращаться назад</xsl:text>
								</xsl:when>
								<xsl:when test="text() = '1' and ../@name = 'Способ прохождения тестирования'">
									<xsl:text>с возможностью возврата к предыдущим вопросам</xsl:text>
								</xsl:when>
								<xsl:when test="text() = '2' and ../@name = 'Способ прохождения тестирования'">
									<xsl:text>с возможностью пропускать вопросы</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'free'">
									<xsl:text>свободный</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'linear'">
									<xsl:text>линейный</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'left'">
									<xsl:text>по левому краю</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'center'">
									<xsl:text>по центру</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'right'">
									<xsl:text>по правому краю</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'single'">
									<xsl:text>одиночный выбор</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'multiple'">
									<xsl:text>множественный выбор</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'fill'">
									<xsl:text>ввод значения</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'compare'">
									<xsl:text>сопоставление</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'sort'">
									<xsl:text>упорядочивание</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'classify'">
									<xsl:text>классификация</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'sound'">
									<xsl:text>Аудиофрагмент</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'image'">
									<xsl:text>Изображение</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'video'">
									<xsl:text>Видеофрагмент</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'flash'">
									<xsl:text>Ролик Adobe Flash</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'silverlight'">
									<xsl:text>Ролик Microsoft Silverlight 2.0</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'pdf'">
									<xsl:text>Portable документ (PDF, DjVu)</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'html'">
									<xsl:text>Web документ</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'doc'">
									<xsl:text>Документ</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'ppt'">
									<xsl:text>Презентация</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'xls'">
									<xsl:text>Электронная таблица</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'exercise'">
									<xsl:text>Упражнение</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'dwf'">
									<xsl:text>Чертёж Autocad</xsl:text>
								</xsl:when>
								<xsl:when test="text() = 'wrl'">
									<xsl:text>3-х мерная модель VRML</xsl:text>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="text()"/>
								</xsl:otherwise>
							</xsl:choose>
						</div>
					</xsl:for-each>
				</div>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="text-attribute">
		<xsl:param name="attr" />

		<xsl:variable name="minId" select="$attr/../attribute[@name = 'Минимальный балл']/@id"/>
		<xsl:variable name="maxId" select="$attr/../attribute[@name = 'Максимальный балл']/@id"/>

		<xsl:variable name="minValue" select="$attr/../attribute[@name = 'Минимальный балл']/@value"/>
		<xsl:variable name="maxValue" select="$attr/../attribute[@name = 'Максимальный балл']/@value"/>

		<xsl:variable name="c1" select="$attr/../attribute[@name = '1-й базовый цвет']"/>
		<xsl:variable name="c2" select="$attr/../attribute[@name = '2-й базовый цвет']"/>

		<input type="text" value="{$attr/@value}" id="{$attr/@id}">
			<xsl:attribute name="onchange">
				SetModified();
			</xsl:attribute>
			<xsl:attribute name="style">
				border: 1px solid #bbb;
				padding-left: 3px;
				width: 100%;
				background: #f5f5f5;
				<xsl:if test="
						$attr/@name = '1-й базовый цвет'
						or $attr/@name = '2-й базовый цвет'
						or $attr/@name = 'Ограничение времени'
						or $attr/@name = 'Количество вопросов в тесте'
						or $attr/@name = 'Количество вопросов попадающих в тест из группы'
						or $attr/@name = 'Минимальный балл'
						or $attr/@name = 'Вес ответа'
						or $attr/@name = 'Ширина'
						or $attr/@name = 'Высота'
						or $attr/@name = 'Положение относительно верхней стороны'
						or $attr/@name = 'Положение относительно левой стороны'
						or $attr/@name = 'Положение относительно нижней стороны'
						or $attr/@name = 'Положение относительно правой стороны'
						or $attr/@name = 'Ширина текста'
						or $attr/@name = 'Высота текста'
						or $attr/@name = 'Задержка показа подэлементов'
						or $attr/@name = 'Порог прохождения теста'
						or $attr/@name = 'Шаблоны заголовков'
						or $attr/@name = 'CSS для заголовков'
						or $attr/@name = 'Максимальный балл'">
					display: none;
				</xsl:if>
			</xsl:attribute>
		</input>
		
		<xsl:if test="$attr/@name = 'Шаблоны заголовков'">
			<label>H1</label>
			<textarea id="{$attr/@id}-textarea-h1" style="width: 100%; height: 100px; border: 1px solid #bbb; background: #f5f5f5; overflow: auto;"></textarea>
			<label>H2</label>
			<textarea id="{$attr/@id}-textarea-h2" style="width: 100%; height: 100px; border: 1px solid #bbb; background: #f5f5f5; overflow: auto;"></textarea>
			<label>H3</label>
			<textarea id="{$attr/@id}-textarea-h3" style="width: 100%; height: 100px; border: 1px solid #bbb; background: #f5f5f5; overflow: auto;"></textarea>
			
			<xsl:call-template name="helperScriptOnLoad">
				<xsl:with-param name="code">
					(function () {
						var textareaNodeH1 = document.getElementById('<xsl:value-of select="$attr/@id"/>-textarea-h1')
						  , textareaNodeH2 = document.getElementById('<xsl:value-of select="$attr/@id"/>-textarea-h2')
						  , textareaNodeH3 = document.getElementById('<xsl:value-of select="$attr/@id"/>-textarea-h3')
						  , inputNode = document.getElementById('<xsl:value-of select="$attr/@id"/>')
						  , handlers = ['click', 'change', 'mouseup', 'mousedown', 'keypress', 'keyup', 'keydown'];
						
						if (!(!textareaNodeH1 || !textareaNodeH3 || !textareaNodeH3 || !inputNode)) {
							var parsed = {h1: '', h2: '', h3: ''};
							try {
								parsed = JSON.parse(inputNode.value);
							} catch (error) {}
							textareaNodeH1.value = parsed.h1;
							textareaNodeH2.value = parsed.h2; 
							textareaNodeH3.value = parsed.h3;
							for (var i = 0; i &lt; handlers.length; ++i) {
								textareaNodeH1['on' + handlers[i]] = textareaNodeH2['on' + handlers[i]] = textareaNodeH3['on' + handlers[i]] = function () {
									var value = {};
									value.h1 = textareaNodeH1.value || '';
									value.h2 = textareaNodeH2.value || '';
									value.h3 = textareaNodeH3.value || '';
									inputNode.value = JSON.stringify(value);
									SetModified();
								}
							}
						}
					})();
				</xsl:with-param>
			</xsl:call-template>
		</xsl:if>
		
		<xsl:if test="$attr/@name = 'CSS для заголовков'">
			<textarea id="{$attr/@id}-textarea" style="width: 100%; height: 300px; border: 1px solid #bbb; background: #f5f5f5; overflow: auto;">
				<xsl:value-of select="$attr/@value"/>
			</textarea>
			
			<xsl:call-template name="helperScriptOnLoad">
				<xsl:with-param name="code">
					(function () {
						var textareaNode = document.getElementById('<xsl:value-of select="$attr/@id"/>-textarea')
						  , inputNode = document.getElementById('<xsl:value-of select="$attr/@id"/>');
						
						if (!(!textareaNode || !inputNode)) {
							var parsed = '';
							try {
								parsed = JSON.parse(inputNode.value);
							} catch (error) {}
							textareaNode.value = parsed;
							textareaNode.onclick = textareaNode.onchange = textareaNode.onmouseup = textareaNode.onmousedown = textareaNode.onkeypress = textareaNode.onkeyup = textareaNode.onkeydown = function () {
								inputNode.value = JSON.stringify(textareaNode.value || '');
								SetModified();
							}
						}
					})();
				</xsl:with-param>
			</xsl:call-template>
			
		</xsl:if>

		<!-- eAuSpinButton -->
		<xsl:if test="$attr/@name = 'Максимальный балл'">
			<table cellpadding="0" cellspacing="0" border="0"><tr>
				<td><div style="padding-right: 5px; font-size: 14px;">от</div></td>
				<td>
					<table
							id="EU-{$minId}"
							EAUInputType="spin-button"
							cellpadding="0"
							cellspacing="0" 
							style="table-layout: fixed; border-collapse: collapse; width: 63px; height: 24px; border: none;">
						<tr>
							<td
									rowspan="2"
									style="width: 50px;">
								<div>
									<input
											id="EU-{$minId}-spin"
											type="text"
											style="
												background: #f5f5f5;
												width: 50px;
												margin: 0px;
												text-align: center;
												font-size: 14px;
												font-family: monospace;
												border: 1px solid #bbb;
												display: block;">
											<xsl:attribute name="onkeydown">
												if (window.event.keyCode == 38) {
													increaseCountedValue.call(this, '<xsl:value-of select="$minId"/>');
												} else if (window.event.keyCode == 40) {
													decreaseCountedValue.call(this, '<xsl:value-of select="$minId"/>');
												}
												if (window.event.keyCode == 40 || window.event.keyCode == 38) {
													validateMinMax(
														'<xsl:value-of select="$minId" />',
														'<xsl:value-of select="$maxId" />'
													);
													SetModified();
													return false;
												}
											</xsl:attribute>
											<xsl:attribute name="onchange">
												validateCountedValue.call(this, '<xsl:value-of select="$minId"/>');
												validateMinMax(
													'<xsl:value-of select="$minId" />',
													'<xsl:value-of select="$maxId" />'
												);
												SetModified();
											</xsl:attribute>
											<xsl:attribute name="onmousewheel">
												if (window.event.wheelDelta &gt; 0) {
													increaseCountedValue.call(this, '<xsl:value-of select="$minId"/>');
												} else if (window.event.wheelDelta &lt; 0) {
													decreaseCountedValue.call(this, '<xsl:value-of select="$minId"/>');
												}
												validateMinMax(
													'<xsl:value-of select="$minId" />',
													'<xsl:value-of select="$maxId" />'
												);
												SetModified();
												return false;
											</xsl:attribute>
										</input>
								</div>
							</td>
							<td
									style="height: 12px; text-align: right; padding-top: 1px;">
								<div
										style="width: 11px; height: 11px; overflow: hidden; background: white url('{$project-url}/template-files/arrow-top-gray.gif') top left no-repeat; cursor: pointer;"
										onmouseenter="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-top-black.gif\')';"
										onmouseleave="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-top-gray.gif\')';">
									<xsl:attribute name="onmouseup">
										increaseCountedValue.call(this, '<xsl:value-of select="$minId"/>');
										validateMinMax(
											'<xsl:value-of select="$minId" />',
											'<xsl:value-of select="$maxId" />'
										);
										SetModified();
									</xsl:attribute>
								</div>
							</td>
						</tr>
						<tr>
							<td
									style="height: 12px; text-align: right;">
								<div
										style="width: 11px; height: 11px; overflow: hidden; background: white url('{$project-url}/template-files/arrow-bottom-gray.gif') top left no-repeat; cursor: pointer;"
										onmouseenter="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-bottom-black.gif\')';"
										onmouseleave="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-bottom-gray.gif\')';">
									<xsl:attribute name="onmouseup">
										decreaseCountedValue.call(this, '<xsl:value-of select="$minId"/>');
										validateMinMax(
											'<xsl:value-of select="$minId" />',
											'<xsl:value-of select="$maxId" />'
										);
										SetModified();
									</xsl:attribute>
								</div>
							</td>
						</tr>
					</table>
				</td>
				<td><div style="padding: 0px 5px 0px 15px; font-size: 14px;">до</div></td>
				<td>
					<table
							id="EU-{$maxId}"
							EAUInputType="spin-button"
							cellpadding="0"
							cellspacing="0" 
							style="table-layout: fixed; border-collapse: collapse; width: 63px; height: 24px; border: none;">
						<tr>
							<td
									rowspan="2"
									style="width: 50px;">
								<div>
									<input
											id="EU-{$maxId}-spin"
											type="text"
											style="
												background: #f5f5f5;
												width: 50px;
												margin: 0px;
												text-align: center;
												font-size: 14px;
												font-family: monospace;
												border: 1px solid #bbb;
												display: block;">
											<xsl:attribute name="onkeydown">
												if (window.event.keyCode == 38) {
													increaseCountedValue.call(this, '<xsl:value-of select="$maxId"/>');
												} else if (window.event.keyCode == 40) {
													decreaseCountedValue.call(this, '<xsl:value-of select="$maxId"/>');
												}
												if (window.event.keyCode == 40 || window.event.keyCode == 38) {
													validateMinMax(
														'<xsl:value-of select="$minId" />',
														'<xsl:value-of select="$maxId" />'
													);
													SetModified();
													return false;
												}
											</xsl:attribute>
											<xsl:attribute name="onchange">
												validateCountedValue.call(this, '<xsl:value-of select="$maxId"/>');
												validateMinMax(
													'<xsl:value-of select="$minId" />',
													'<xsl:value-of select="$maxId" />'
												);
												SetModified();
											</xsl:attribute>
											<xsl:attribute name="onmousewheel">
												if (window.event.wheelDelta &gt; 0) {
													increaseCountedValue.call(this, '<xsl:value-of select="$maxId"/>');
												} else if (window.event.wheelDelta &lt; 0) {
													decreaseCountedValue.call(this, '<xsl:value-of select="$maxId"/>');
												}
												validateMinMax(
													'<xsl:value-of select="$minId" />',
													'<xsl:value-of select="$maxId" />'
												);
												SetModified();
												return false;
											</xsl:attribute>
										</input>
								</div>
							</td>
							<td
									style="height: 12px; text-align: right; padding-top: 1px;">
								<div
										style="width: 11px; height: 11px; overflow: hidden; background: white url('{$project-url}/template-files/arrow-top-gray.gif') top left no-repeat; cursor: pointer;"
										onmouseenter="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-top-black.gif\')';"
										onmouseleave="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-top-gray.gif\')';">
									<xsl:attribute name="onmouseup">
										increaseCountedValue.call(this, '<xsl:value-of select="$maxId"/>');
										validateMinMax(
											'<xsl:value-of select="$minId" />',
											'<xsl:value-of select="$maxId" />'
										);
										SetModified();
									</xsl:attribute>
								</div>
							</td>
						</tr>
						<tr>
							<td
									style="height: 12px; text-align: right;">
								<div
										style="width: 11px; height: 11px; overflow: hidden; background: white url('{$project-url}/template-files/arrow-bottom-gray.gif') top left no-repeat; cursor: pointer;"
										onmouseenter="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-bottom-black.gif\')';"
										onmouseleave="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-bottom-gray.gif\')';">
									<xsl:attribute name="onmouseup">
										decreaseCountedValue.call(this, '<xsl:value-of select="$maxId"/>');
										validateMinMax(
											'<xsl:value-of select="$minId" />',
											'<xsl:value-of select="$maxId" />'
										);
										SetModified();
									</xsl:attribute>
								</div>
							</td>
						</tr>
					</table>
				</td>
			</tr></table>

			<xsl:call-template name="helperScriptOnLoad">
				<xsl:with-param name="code">
					validateCountedValue.call(this, '<xsl:value-of select="$minId"/>', parseInt('<xsl:value-of select="$minValue"/>' ,10) || 0);
					validateCountedValue.call(this, '<xsl:value-of select="$maxId"/>', parseInt('<xsl:value-of select="$maxValue"/>' ,10) || 0);
					validateMinMax(
						'<xsl:value-of select="$minId" />',
						'<xsl:value-of select="$maxId" />'
					);
				</xsl:with-param>
			</xsl:call-template>
		</xsl:if>

		<xsl:choose>
			<xsl:when test="$attr/@name = 'Ширина' and $attr/../../@name = 'objectType'"></xsl:when>
			<xsl:when test="$attr/@name = 'Высота' and $attr/../../@name = 'objectType'">
				<table cellpadding="0" cellspacing="0" border="0">
					<tr>
						<td>
							<xsl:call-template name="UISpinButton">
								<xsl:with-param name="attr" select="$attr/../attribute[@name = 'Ширина']"/>
								<xsl:with-param name="minValue">
									<xsl:text>0</xsl:text>
								</xsl:with-param>
								<xsl:with-param name="maxValue"></xsl:with-param>
								<xsl:with-param name="customValueValidator">
									var nodeId = '<xsl:value-of select="$attr/../attribute[@name = 'Тип']/@id"/>';
									if ($(nodeId).value == 'image') {
										return (val == 0) ? 'авто' : val;
									} else {
										return val;
									}
								</xsl:with-param>
								<xsl:with-param name="units"></xsl:with-param>
							</xsl:call-template>
						</td>
						<td style="padding: 0px 10px;"><img src="{$project-url}/template-files/cross.gif" /></td>
						<td>
							<xsl:call-template name="UISpinButton">
								<xsl:with-param name="attr" select="$attr"/>
								<xsl:with-param name="minValue">
									<xsl:text>0</xsl:text>
								</xsl:with-param>
								<xsl:with-param name="maxValue"></xsl:with-param>
								<xsl:with-param name="customValueValidator">
									var nodeId = '<xsl:value-of select="$attr/../attribute[@name = 'Тип']/@id"/>';
									if ($(nodeId).value == 'image') {
										return (val == 0) ? 'авто' : val;
									} else {
										return val;
									}
								</xsl:with-param>
								<xsl:with-param name="units"></xsl:with-param>
							</xsl:call-template>
						</td>
						<td style="padding-left: 10px;"><a id="eAu-size-autodetect-{$attr/@id}" href="#" style="font-size: 15px; display: none;">
							<xsl:attribute name="onclick">
								var imgObj = $('eAu-object-image-<xsl:value-of select="$attr/../attribute[@name = 'Файл']/@id"/>');
								var UIWidth = $('EU-<xsl:value-of select="$attr/../attribute[@name = 'Ширина']/@id"/>-spin');
								var UIHeight = $('EU-<xsl:value-of select="$attr/../attribute[@name = 'Высота']/@id"/>-spin');

								if (parseInt(imgObj.getAttribute('realWidth'), 10) &amp;&amp; parseInt(imgObj.getAttribute('realHeight'), 10)) {
									UIWidth.value = parseInt(imgObj.getAttribute('realWidth'), 10);
									UIHeight.value = parseInt(imgObj.getAttribute('realHeight'), 10);
									UIWidth.onchange.call(UIWidth);
									UIHeight.onchange.call(UIHeight);
								}

								return false;
							</xsl:attribute>
							<xsl:text>Определить размер</xsl:text>
						</a></td>
					</tr>
				</table>
			</xsl:when>
			<xsl:when test="$attr/@name = 'Количество вопросов в тесте'
					or $attr/@name = 'Количество вопросов попадающих в тест из группы'
					or $attr/@name = 'Вес ответа'
					or $attr/@name = 'Порог прохождения теста'
					or $attr/@name = 'Положение относительно верхней стороны'
					or $attr/@name = 'Положение относительно левой стороны'
					or $attr/@name = 'Положение относительно нижней стороны'
					or $attr/@name = 'Положение относительно правой стороны'
					or $attr/@name = 'Ширина текста'
					or $attr/@name = 'Задержка показа подэлементов'
					or $attr/@name = 'Высота текста'
					or $attr/@name = 'Ширина'
					or $attr/@name = 'Высота'">
				<xsl:call-template name="UISpinButton">
					<xsl:with-param name="attr" select="$attr"/>
					<xsl:with-param name="minValue">
						<xsl:if test="$attr/@name = 'Количество вопросов в тесте'
								or $attr/@name = 'Количество вопросов попадающих в тест из группы'
								or $attr/@name = 'Порог прохождения теста'
								or $attr/@name = 'Задержка показа подэлементов'
								or $attr/@name = 'Положение относительно верхней стороны'
								or $attr/@name = 'Положение относительно левой стороны'
								or $attr/@name = 'Ширина текста'
								or $attr/@name = 'Высота текста'
								or $attr/@name = 'Положение относительно нижней стороны'
								or $attr/@name = 'Положение относительно правой стороны'
								or $attr/@name = 'Ширина'
								or $attr/@name = 'Высота'">
							<xsl:text>0</xsl:text>
						</xsl:if>
					</xsl:with-param>
					<xsl:with-param name="maxValue">
						<xsl:if test="$attr/@name = 'Порог прохождения теста'">
							<xsl:text>100</xsl:text>
						</xsl:if>
					</xsl:with-param>
					<xsl:with-param name="customValueValidator">
						<xsl:if test="$attr/@name = 'Количество вопросов в тесте'">
							return (val == 0) ? 'все' : val;
						</xsl:if>
						<xsl:if test="$attr/@name = 'Задержка показа подэлементов'">
							return (val == 0) ? 'нет' : val;
						</xsl:if>
						<xsl:if test="$attr/@name = 'Положение относительно верхней стороны'
								or $attr/@name = 'Положение относительно левой стороны'
								or $attr/@name = 'Ширина текста'
								or $attr/@name = 'Высота текста'
								or $attr/@name = 'Положение относительно нижней стороны'
								or $attr/@name = 'Положение относительно правой стороны'">
							return (val == 0) ? 'авто' : val;
						</xsl:if>
					</xsl:with-param>
					<xsl:with-param name="units">
						<xsl:if test="$attr/@name = 'Порог прохождения теста'"><xsl:text> %</xsl:text></xsl:if>
						<xsl:if test="$attr/@name = 'Задержка показа подэлементов'"><xsl:text> сек.</xsl:text></xsl:if>
					</xsl:with-param>
				</xsl:call-template>
			</xsl:when>
		</xsl:choose>

		<!-- eAuTimeSpanButton -->
		<xsl:if test="$attr/@name = 'Ограничение времени'">
			<table
					id="EU-{$attr/@id}"
					EAUInputType="timespan"
					cellpadding="0"
					cellspacing="0"
					border="0"
					style="border-collapse: collapse;"><tr><td>
				<!-- Часы -->
				<table
						cellpadding="0"
						cellspacing="0" 
						style="table-layout: fixed; border-collapse: collapse; width: 47px; height: 28px; border: none;">
					<tr>
						<td
								rowspan="2"
								style="width: 34px;">
							<div>
								<input
										id="EU-{$attr/@id}-hrs"
										type="text"
										maxlength="3"
										onchange="timespanOnchange.call(this, '{$attr/@id}'); SetModified();"
										style="
											background: #f5f5f5 url('{$project-url}/template-files/hrs-bg.gif') top center no-repeat;
											width: 34px;
											height: 28px;
											margin: 0px;
											padding: 13px 0px 0px;
											text-align: center;
											font-size: 14px;
											line-height: 14px;
											font-family: monospace;
											border: 1px solid #bbb;
											border-width: 0px 0px 1px;
											display: block;">
										<xsl:attribute name="onkeydown">
											if (window.event.keyCode == 38) {
												increaseTimeSpan.call(this, '<xsl:value-of select="$attr/@id"/>', 'hrs');
											} else if (window.event.keyCode == 40) {
												decreaseTimeSpan.call(this, '<xsl:value-of select="$attr/@id"/>', 'hrs');
											}
											if (window.event.keyCode == 40 || window.event.keyCode == 38) {
												SetModified();
												return false;
											}
										</xsl:attribute>
										<xsl:attribute name="onmousewheel">
											if (window.event.wheelDelta &lt; 0) {
												decreaseTimeSpan.call(this, '<xsl:value-of select="$attr/@id"/>', 'hrs');
											} else if (window.event.wheelDelta &gt; 0) {
												increaseTimeSpan.call(this, '<xsl:value-of select="$attr/@id"/>', 'hrs');
											}
											SetModified();
											return false;
										</xsl:attribute>
									</input>
							</div>
						</td>
						<td
								style="height: 14px; text-align: right; padding-top: 3px;">
							<div
									style="width: 11px; height: 11px; overflow: hidden; background: white url('{$project-url}/template-files/arrow-top-gray.gif') top left no-repeat; cursor: pointer;"
									onmouseenter="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-top-black.gif\')';"
									onmouseleave="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-top-gray.gif\')';"
									onmouseup="increaseTimeSpan.call(this, '{$attr/@id}', 'hrs'); SetModified();"></div>
						</td>
					</tr>
					<tr>
						<td
								style="height: 14px; text-align: right;">
							<div
									style="width: 11px; height: 11px; overflow: hidden; background: white url('{$project-url}/template-files/arrow-bottom-gray.gif') top left no-repeat; cursor: pointer;"
									onmouseenter="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-bottom-black.gif\')';"
									onmouseleave="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-bottom-gray.gif\')';"
									onmouseup="decreaseTimeSpan.call(this, '{$attr/@id}', 'hrs'); SetModified();"></div>
						</td>
					</tr>
				</table>

			</td><td width="10">
			</td><td>

				<!-- Минуты -->
				<table
						cellpadding="0"
						cellspacing="0" 
						style="table-layout: fixed; border-collapse: collapse; width: 53px; height: 28px; border: none;">
					<tr>
						<td
								rowspan="2"
								style="width: 40px;">
							<div>
								<input
										id="EU-{$attr/@id}-min"
										type="text"
										maxlength="2"
										onchange="timespanOnchange.call(this, '{$attr/@id}'); SetModified();"
										style="
											background: #f5f5f5 url('{$project-url}/template-files/min-bg.gif') top center no-repeat;
											width: 40px;
											height: 28px;
											margin: 0px;
											padding: 13px 0px 0px;
											text-align: center;
											font-size: 14px;
											line-height: 14px;
											font-family: monospace;
											border: 1px solid #bbb;
											border-width: 0px 0px 1px;
											display: block;">
										<xsl:attribute name="onkeydown">
											if (window.event.keyCode == 38) {
												increaseTimeSpan.call(this, '<xsl:value-of select="$attr/@id"/>', 'min');
											} else if (window.event.keyCode == 40) {
												decreaseTimeSpan.call(this, '<xsl:value-of select="$attr/@id"/>', 'min');
											}
											if (window.event.keyCode == 40 || window.event.keyCode == 38) {
												SetModified();
												return false;
											}
										</xsl:attribute>
										<xsl:attribute name="onmousewheel">
											if (window.event.wheelDelta &lt; 0) {
												decreaseTimeSpan.call(this, '<xsl:value-of select="$attr/@id"/>', 'min');
											} else if (window.event.wheelDelta &gt; 0) {
												increaseTimeSpan.call(this, '<xsl:value-of select="$attr/@id"/>', 'min');
											}
											SetModified();
											return false;
										</xsl:attribute>
									</input>
							</div>
						</td>
						<td
								style="height: 14px; text-align: right; padding-top: 3px;">
							<div
									style="width: 11px; height: 11px; overflow: hidden; background: white url('{$project-url}/template-files/arrow-top-gray.gif') top left no-repeat; cursor: pointer;"
									onmouseenter="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-top-black.gif\')';"
									onmouseleave="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-top-gray.gif\')';"
									onmouseup="increaseTimeSpan.call(this, '{$attr/@id}', 'min'); SetModified();"></div>
						</td>
					</tr>
					<tr>
						<td
								style="height: 14px; text-align: right;">
							<div
									style="width: 11px; height: 11px; overflow: hidden; background: white url('{$project-url}/template-files/arrow-bottom-gray.gif') top left no-repeat; cursor: pointer;"
									onmouseenter="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-bottom-black.gif\')';"
									onmouseleave="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-bottom-gray.gif\')';"
									onmouseup="decreaseTimeSpan.call(this, '{$attr/@id}', 'min'); SetModified();"></div>
						</td>
					</tr>
				</table>

			</td><td width="10">
			</td><td>

				<!-- Секунды -->
				<table
						cellpadding="0"
						cellspacing="0" 
						style="table-layout: fixed; border-collapse: collapse; width: 57px; height: 28px; border: none;">
					<tr>
						<td
								rowspan="2"
								style="width: 44px;">
							<div>
								<input
										id="EU-{$attr/@id}-sec"
										type="text"
										maxlength="2"
										onchange="timespanOnchange.call(this, '{$attr/@id}'); SetModified();"
										style="
											background: #f5f5f5 url('{$project-url}/template-files/sec-bg.gif') top center no-repeat;
											width: 44px;
											height: 28px;
											margin: 0px;
											padding: 13px 0px 0px;
											text-align: center;
											font-size: 14px;
											line-height: 14px;
											font-family: monospace;
											border: 1px solid #bbb;
											border-width: 0px 0px 1px;
											display: block;">
										<xsl:attribute name="onkeydown">
											if (window.event.keyCode == 38) {
												increaseTimeSpan.call(this, '<xsl:value-of select="$attr/@id"/>', 'sec');
											} else if (window.event.keyCode == 40) {
												decreaseTimeSpan.call(this, '<xsl:value-of select="$attr/@id"/>', 'sec');
											}
											if (window.event.keyCode == 40 || window.event.keyCode == 38) {
												SetModified();
												return false;
											}
										</xsl:attribute>
										<xsl:attribute name="onmousewheel">
											if (window.event.wheelDelta &lt; 0) {
												decreaseTimeSpan.call(this, '<xsl:value-of select="$attr/@id"/>', 'sec');
											} else if (window.event.wheelDelta &gt; 0) {
												increaseTimeSpan.call(this, '<xsl:value-of select="$attr/@id"/>', 'sec');
											}
											SetModified();
											return false;
										</xsl:attribute>
									</input>
							</div>
						</td>
						<td
								style="height: 14px; text-align: right; padding-top: 3px;">
							<div
									style="width: 11px; height: 11px; overflow: hidden; background: white url('{$project-url}/template-files/arrow-top-gray.gif') top left no-repeat; cursor: pointer;"
									onmouseenter="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-top-black.gif\')';"
									onmouseleave="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-top-gray.gif\')';"
									onmouseup="increaseTimeSpan.call(this, '{$attr/@id}', 'sec'); SetModified();"></div>
						</td>
					</tr>
					<tr>
						<td
								style="height: 14px; text-align: right;">
							<div
									style="width: 11px; height: 11px; overflow: hidden; background: white url('{$project-url}/template-files/arrow-bottom-gray.gif') top left no-repeat; cursor: pointer;"
									onmouseenter="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-bottom-black.gif\')';"
									onmouseleave="this.style.backgroundImage = 'url(\'{$project-url}/template-files/arrow-bottom-gray.gif\')';"
									onmouseup="decreaseTimeSpan.call(this, '{$attr/@id}', 'sec'); SetModified();"></div>
						</td>
					</tr>
				</table>
			</td></tr></table>

			<xsl:call-template name="helperScriptOnLoad">
				<xsl:with-param name="code">
					timespanOnchange('<xsl:value-of select="$attr/@id" />', '<xsl:value-of select="$attr/@value" />');
				</xsl:with-param>
			</xsl:call-template>
		</xsl:if>

		<!-- eAuColorSelect -->
		<xsl:if test="$attr/@name = '2-й базовый цвет'">
			<div
					tabindex="0"
					style="width: 32px; height: 32px; border: 1px solid #bbb; padding: 1px; float: left;"
					EAUInputType="color-select"
					id="EU-{$c1/@id}">
				<xsl:attribute name="onkeydown">
					if (/^(13|32)$/.test(window.event.keyCode)) {
						this.onmouseup();
						return false;
					}
				</xsl:attribute>
				<xsl:attribute name="onmouseup">
					this.focus();
					selectColor('<xsl:value-of select="$c1/@id"/>');
					SetModified();
					this.focus();
				</xsl:attribute>
				<div title="Выбрать цвет" id="EU-{$c1/@id}-cp">
					<xsl:attribute name="style">
						height: 30px;
						width: 30px;
						background: #f78f15;
						cursor: pointer;
					</xsl:attribute>
					<span style="visibility: hidden;">1</span>
				</div>
			</div>
			<!-- <div tabindex="0"
					style="width: 32px; height: 32px; border: 1px solid #bbb; padding: 1px; float: left; margin-left: 5px;"
					EAUInputType="color-select"
					id="EU-{$c2/@id}">
				<xsl:attribute name="onkeydown">
					if (/^(13|32)$/.test(window.event.keyCode)) {
						this.onmouseup();
						return false;
					}
				</xsl:attribute>
				<xsl:attribute name="onmouseup">
					this.focus();
					selectColor('<xsl:value-of select="$c2/@id"/>');
					SetModified();
					this.focus();
				</xsl:attribute>
				<div title="Выбрать цвет" id="EU-{$c2/@id}-cp">
					<xsl:attribute name="style">
						height: 30px;
						width: 30px;
						background: #1945a4;
						cursor: pointer;
					</xsl:attribute>
					<span style="visibility: hidden;">1</span>
				</div>
			</div> -->
			<xsl:call-template name="helperScriptOnLoad">
				<xsl:with-param name="code">
					validateColor('<xsl:value-of select="$c1/@id" />', '<xsl:value-of select="$c1/@value" />');
					/* validateColor('<xsl:value-of select="$c2/@id" />', '<xsl:value-of select="$c2/@value" />'); */
				</xsl:with-param>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="path-attribute">
		<xsl:param name="attr"/>

		<input type="text" value="{$attr/@value}" id="{$attr/@id}" style="display: none;" />
		<div id="EU-{$attr/@id}" EAUInputType="browse-for-file">
			<xsl:attribute name="onkeydown">
				if (/^(13|32)$/.test(window.event.keyCode)) {
					$('EU-<xsl:value-of select="$attr/@id"/>-button').onmouseup();
					return false;
				}
			</xsl:attribute>
			<div
					id="EU-{$attr/@id}-button"
					style="width: 60px; float: right; font-size: 80%; padding: 2px 0px; cursor: pointer; text-align: center; background-color: #f78f15; color: white; border: 1px solid #f78f15;"
					onmouseenter="this.style.backgroundColor = '#1945a4';"
					onmouseleave="this.style.backgroundColor = '#f78f15';">
				<xsl:attribute name="onmouseup">
					<xsl:if test="$attr/@name = 'Файл' and $attr/../../@name = 'objectType'">
						var objectTypeNode = $('<xsl:value-of select="$attr/../attribute[@name = 'Тип']/@id"/>');
						var objectTypeUINode = $('EU-<xsl:value-of select="$attr/../attribute[@name = 'Тип']/@id" />-value');
						var currentType = objectTypeNode.value;
						objectTypeNode.selectedIndex = objectTypeNode.options.length - 1;
					</xsl:if>
					var val = browseForFile('<xsl:value-of select="$attr/@id"/>'<xsl:if test="$attr/@name = 'Файл' and $attr/../../@name = 'objectType'">, '<xsl:value-of select="$attr/../*[@name = 'Тип']/@id"/>'</xsl:if>);
					<xsl:if test="$attr/@name = 'Файл' and $attr/../../@name = 'organization'">
						var eAuLogo = $('eAu-logo-<xsl:value-of select="$attr/@id"/>');
						if (val.length > 0) {
							var projectPath = '<xsl:value-of select="$project-location"/>';
							eAuLogo.style.display = 'none';
							eAuLogo.setAttribute('src', (!val.indexOf('./files') ? projectPath : '') + val);
						} else if (!$('<xsl:value-of select="$attr/@id"/>').value) {
							eAuLogo.style.display = 'none';
						}
					</xsl:if>
					<xsl:if test="$attr/@name = 'Файл' and $attr/../../@name = 'objectType'">
						var eAuImage = $('eAu-object-image-<xsl:value-of select="$attr/@id"/>');
						var autodetectSize = $('eAu-size-autodetect-<xsl:value-of select="$attr/../attribute[@name = 'Высота']/@id"/>');
						var projectUrl = '<xsl:value-of select="$project-url"/>';
						var objectType = window.eAu_Course.api.detectFileTypeByExtension(
							val
							, window.eAu_Course.api.gatherFileTypeExtensions(objectTypeNode) 
						);
						_.each(_.toArray(objectTypeUINode.getElementsByTagName('span')), function (item) {
							item.style.display = 'none';
						});
						eAuImage.style.display = 'none';
						autodetectSize.style.display = 'none';
						if (objectType) {
							// HACK
							if (objectType == 'html' &amp;&amp; currentType == 'exercise' &amp;&amp; val.toLowerCase().indexOf('./files/exercise') == 0) {
								objectType = currentType;
							}
							if (objectType == 'image') {
								eAuImage.setAttribute('src', (!val.indexOf('./files') ? projectUrl : '') + val);
							}
							objectTypeNode.value = objectType;
							$('EU-<xsl:value-of select="$attr/../attribute[@name = 'Тип']/@id" />-value-' + objectType).style.display = 'block';
						} else {
							objectTypeNode.value = currentType;
							$('EU-<xsl:value-of select="$attr/../attribute[@name = 'Тип']/@id" />-value-none').style.display = 'block';
						}

						$('EU-<xsl:value-of select="$attr/../attribute[@name = 'Ширина']/@id"/>-spin').onchange.call(
							$('EU-<xsl:value-of select="$attr/../attribute[@name = 'Ширина']/@id"/>-spin')
						);
						$('EU-<xsl:value-of select="$attr/../attribute[@name = 'Высота']/@id"/>-spin').onchange.call(
							$('EU-<xsl:value-of select="$attr/../attribute[@name = 'Высота']/@id"/>-spin')
						);
					</xsl:if>
					SetModified();
				</xsl:attribute>
				<xsl:text>Обзор...</xsl:text>
			</div>
			<div
					tabindex="0"
					style="padding: 2px;
						margin-right: 62px;
						font-size: 80%;
						word-wrap: break-word;
						cursor: pointer;
						border: 1px solid #bbb;
						background: #f5f5f5;"
						id="EU-{$attr/@id}-value"
						onmouseup="$('EU-{$attr/@id}-button').onmouseup()">
				<xsl:choose>
					<xsl:when test="$attr/@value and $attr/@value != ''">
						<span><xsl:value-of select="$attr/@value" /></span>
					</xsl:when>
					<xsl:otherwise>
						<span style="color: #565655;">выберите файл</span>
					</xsl:otherwise>
				</xsl:choose>
			</div>
		</div>
		<xsl:if test="$attr/@name = 'Файл' and $attr/../../@name = 'organization'">
			<div style="text-align: center;"><img src="" style="display: none; margin: 7px 0px 0px;" id="eAu-logo-{$attr/@id}">
				<xsl:attribute name="onload">
					var LogoUrl = this.getAttribute('src');
					var image = new Image();
					var This = this;
					image.onload = function() {
						if (image.height > 128) {
							This.setAttribute('height', '128');
						} else {
							This.setAttribute('height', image.height);
						}
						image.onload = null;
						image = null;
						This.style.display = 'block';
					}
					image.src = LogoUrl;
				</xsl:attribute>
			</img></div>
		</xsl:if>
		<xsl:if test="$attr/@name = 'Файл' and $attr/../../@name = 'objectType'">
			<div style="text-align: center;"><img src="" style="display: none; margin: 7px 0px 0px;" id="eAu-object-image-{$attr/@id}">
				<xsl:attribute name="onload">
					var image = new Image();
					var autodetectSize = $('eAu-size-autodetect-<xsl:value-of select="$attr/../attribute[@name = 'Высота']/@id"/>');
					image.onload = _.bind(function() {
						this.setAttribute('realWidth', image.width);
						this.setAttribute('realHeight', image.height);
						if (image.width > 400) {
							this.setAttribute('width', '400');
						} else {
							this.setAttribute('width', image.width);
						}
						image.onload = null;
						image = null;
						this.style.display = 'block';
						autodetectSize.style.display = 'block';
					}, this);
					image.onerror = function () {
						image.onerror = null;
						autodetectSize.style.display = 'none';
					}
					image.src = this.getAttribute('src');
				</xsl:attribute>
			</img></div>
		</xsl:if>
		<xsl:call-template name="helperScriptOnLoad">
			<xsl:with-param name="code">
				var eAuLogo = $('eAu-logo-<xsl:value-of select="@id"/>');
				var eAuImage = $('eAu-object-image-<xsl:value-of select="@id"/>');
				if (eAuLogo) {
					eAuLogo.src = window.eAu_Course.api.UrlCreateFromPath("<xsl:value-of select="$project-url"/><xsl:value-of select="$attr/@value"/>");
				}
				if (eAuImage) {
					eAuImage.src = window.eAu_Course.api.UrlCreateFromPath("<xsl:value-of select="$project-url"/><xsl:value-of select="$attr/@value"/>");
				}
			</xsl:with-param>
		</xsl:call-template>
	</xsl:template>

	<xsl:template name="attribute">
		<xsl:param name="attr"/>

		<div id="EU-ATTR-ROW-{$attr/@id}">
			<xsl:attribute name="style">
				<xsl:if test="($attr/@name = 'Тип' and $attr/../../@name = 'organization')
						or ($attr/@name = 'Тип' and $attr/../../@name = 'unitType')
						or ($attr/@name = 'Тип' and $attr/../../@name = 'lessonType')
						or ($attr/@name = 'Тип' and $attr/../../@name = 'introType')
						or ($attr/@name = 'Тип' and $attr/../../@name = 'studiedproblemType')
						or ($attr/@name = 'Тип' and $attr/../../@name = 'studiedproblemsType')
						or ($attr/@name = 'Тип' and $attr/../../@name = 'glossary-term-type')
						or ($attr/@name = 'Тип' and $attr/@value = 'unit')
						or ($attr/@name = 'Тип' and $attr/@value = 'questionExerciseType')
						or $attr/@name = 'Минимальный балл'">
					display: none;
				</xsl:if>
				<xsl:if test="$attr/@name = 'Количество вопросов в тесте' and $attr/../attribute[@name = 'Механизм выбора вопросов теста']/@value = '1'">
					display: none;
				</xsl:if>
				<xsl:if test="$attr/@name = '1-й базовый цвет' or $attr/@name = '2-й базовый цвет'">
					display: none;
				</xsl:if>
				<xsl:if test="$attr/@name = 'Ширина' and $attr/../../@name = 'objectType'">
					display: none;
				</xsl:if>
				<xsl:if test="$attr/@name = 'Максимальный балл'
						and ($attr/../attribute[@name = 'Тип']/@value = 'single' or $attr/../attribute[@name = 'Тип']/@value = 'multiple')
						and $attr/../attribute[@name = 'Оценивать по весам']/@value = 'true'">
					display: none;
				</xsl:if>
				<xsl:if test="$attr/@name = 'Оценивать по весам'
					and not($attr/../attribute[@name = 'Тип']/@value = 'single' or $attr/../attribute[@name = 'Тип']/@value = 'multiple')">
					display: none;
				</xsl:if>
				<xsl:if test="$attr/@name = 'Перемешивать ответы'
					and ($attr/../attribute[@name = 'Тип']/@value = 'sort' or $attr/../attribute[@name = 'Тип']/@value = 'classify')">
					display: none;
				</xsl:if>
				<xsl:if test="($attr/@name = 'Ширина' or $attr/@name = 'Высота' or $attr/@name = 'Выравнивание')
					and not($attr/../attribute[@name = 'Отображать сразу']/@value = 'true')">
					display: none;
				</xsl:if>
				margin: 0px 15px;
				<xsl:if test="count($attr/following-sibling::attribute) != 0">
					border-bottom: 1px solid #bbb;
				</xsl:if>
			</xsl:attribute>
			<input type="checkbox" id="{$attr/@checkid}" style="display: none;" checked="checked" />
			<table cellpadding="4" cellspacing="0" border="0" style="border-collapse: collapse; table-layout: fixed;">
				<tr>
					<td>
						<xsl:attribute name="style">
							cursor: default;
							vertical-align: middle;
							width: 30%;
							font-size: 15px;
							background: #f0f0f0;
						</xsl:attribute>
						<xsl:choose>
							<xsl:when test="$attr/@name = 'Высота' and $attr/../../@name = 'objectType'">
								<xsl:text>Ширина </xsl:text><img src="{$project-url}/template-files/cross-g.gif" /><xsl:text> Высота</xsl:text> <!-- &#10799; -->
							</xsl:when>
							<xsl:when test="$attr/@name = '2-й базовый цвет'">
								<span style="cursor: pointer;">
									<xsl:attribute name="onmouseup">
										var node = $('EU-<xsl:value-of select="$attr/../attribute[@name = '1-й базовый цвет']/@id"/>');
										if (!node) { return; }
										var EAUInputType = node.getAttribute('EAUInputType');
										if (EAUInputType == 'color-select') {
											node.focus();
										}
									</xsl:attribute>
									<xsl:text>Базовые цвета</xsl:text>
								</span>
							</xsl:when>
							<xsl:when test="$attr/@name = 'Максимальный балл'">
								<span style="cursor: pointer;">
									<xsl:attribute name="onmouseup">
										var node = $('EU-<xsl:value-of select="$attr/../attribute[@name = 'Минимальный балл']/@id"/>');
										if (!node) { return; }
										var EAUInputType = node.getAttribute('EAUInputType');
										if (EAUInputType == 'spin-button') {
											$('EU-<xsl:value-of select="$attr/../attribute[@name = 'Минимальный балл']/@id"/>-spin').focus();
										}
									</xsl:attribute>
									<xsl:text>Диапазон баллов</xsl:text>
								</span>
							</xsl:when>
							<xsl:when test="$attr/@name = 'Тип' and $attr/../../@name = 'answerType'">
								<span style="cursor: pointer;" title="для множественного и одиночного выбора">
									<xsl:attribute name="onmouseup">
										var node = $('EU-<xsl:value-of select="$attr/@id"/>');
										if (!node) { return; }
										var EAUInputType = node.getAttribute('EAUInputType');
										if (EAUInputType == 'checkbox') {
											node.onmouseup();
										}
									</xsl:attribute>
									<xsl:text>Верный ответ</xsl:text>
								</span>
							</xsl:when>
							<xsl:when test="$attr/@name = 'Файл' and $attr/../../@name = 'organization'">
								<span style="cursor: pointer;">
									<xsl:attribute name="onmouseup">
										var node = $('EU-<xsl:value-of select="$attr/@id"/>');
										if (!node) { return; }
										var EAUInputType = node.getAttribute('EAUInputType');
										if (EAUInputType == 'browse-for-file') {
											$('EU-<xsl:value-of select="$attr/@id"/>-value').focus();
										}
									</xsl:attribute>
									<xsl:text>Логотип</xsl:text>
								</span>
							</xsl:when>
							<xsl:when test="$attr/@name = 'Файл' and ($attr/../../@name = 'studiedproblemType' or $attr/../../@name = 'studiedproblemsType' or $attr/../../@name = 'unitType' or $attr/../../@name = 'lessonType' or $attr/../../@name = 'introType')">
								<span style="cursor: pointer;">
									<xsl:attribute name="onmouseup">
										var node = $('EU-<xsl:value-of select="$attr/@id"/>');
										if (!node) { return; }
										var EAUInputType = node.getAttribute('EAUInputType');
										if (EAUInputType == 'browse-for-file') {
											$('EU-<xsl:value-of select="$attr/@id"/>-value').focus();
										}
									</xsl:attribute>
									<xsl:text>Звуковое сопровождение</xsl:text>
								</span>
							</xsl:when>
							<xsl:otherwise>
								<span style="cursor: pointer;">
									<xsl:if test="$attr/@name = 'Верное значение' and $attr/../../@name = 'answerType'">
										<xsl:attribute name="title">для вопросов на ввод значения и сопоставление</xsl:attribute>
									</xsl:if>
									<xsl:if test="$attr/@name = 'Классифицирующий термин' and $attr/../../@name = 'answerType'">
										<xsl:attribute name="title">для вопросов на классификацию</xsl:attribute>
									</xsl:if>
									<xsl:attribute name="onmouseup">
										var node = $('EU-<xsl:value-of select="$attr/@id"/>');
										if (!node) {
											try {
												$('<xsl:value-of select="$attr/@id"/>').focus();
											} catch (error) {}
											return;
										}
										var EAUInputType = node.getAttribute('EAUInputType');
										if (EAUInputType == 'checkbox') {
											node.onmouseup();
										} else if (EAUInputType == 'spin-button') {
											$('EU-<xsl:value-of select="$attr/@id"/>-spin').focus();
										} else if (EAUInputType == 'timespan') {
											$('EU-<xsl:value-of select="$attr/@id"/>-hrs').focus();
										} else if (EAUInputType == 'select') {
											node.focus();
										}
									</xsl:attribute>
									<xsl:value-of select="$attr/@name"/>
								</span>
							</xsl:otherwise>
						</xsl:choose>
					</td>
					<td>
						<xsl:attribute name="style">
							width: 70%;
						</xsl:attribute>

						<xsl:if test="$attr/@type='choice'">
							<xsl:call-template name="choice-attribute">
								<xsl:with-param name="attr" select="$attr" />
							</xsl:call-template>
						</xsl:if>

						<xsl:if test="$attr/@type='text'">
							<xsl:call-template name="text-attribute">
								<xsl:with-param name="attr" select="$attr" />
							</xsl:call-template>
						</xsl:if>

						<xsl:if test="$attr/@type='path'">
							<xsl:call-template name="path-attribute">
								<xsl:with-param name="attr" select="$attr" />
							</xsl:call-template>
						</xsl:if>
					</td>
				</tr>
			</table>
		</div>
	</xsl:template>
</xsl:stylesheet>

