<%@ include file="/includes.jsp" %>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<tr>
	<td class="label">Style</td>
	<td class="input">
		<smvc:select path="formField.fieldType" onchange="update()">
			<smvc:option value="100">Hidden</smvc:option>
			<smvc:option value="101">Read-only</smvc:option>
			<smvc:option value="102">Scoring</smvc:option>
		</smvc:select>
	</td>
</tr>
<%--
<c:set var="definition" value="${emdt.currentForm}"/>
 --%>
<c:set var="cf" value="${formObjectForm.formField.parent.parent.parent}"/>
<c:if test="${formObjectForm.formField.fieldType eq 102 }">
	<tr>
		<td></td>
		<td><img src="../images/16x16/help.png" alt="Help" border="0"/> The value of this field will be derived from another field's value.<br/>This can be used to assess a score or assign a banding,<br/>depending on the range of values the other field has.<br/></td>
	</tr>
	<tr>
		<td class="label">Test value of other field:</td>
		<td class="input">
			<smvc:select path="formField.referencedField">
				<c:forEach var="otherObj" items="${cf.toFlatList()}">
					<c:if test="${(otherObj.type eq 5) && (otherObj.name ne formObjectForm.formField.name)}">
						<c:if test="${otherObj.inputType eq 2 or otherObj.inputType eq 3 or otherObj.inputType eq 5 }">
							<c:choose>
								<c:when test="${otherObj.inputType eq 5}">
									<c:if test="${not empty (otherObj.optionsMapDomain) && not empty (otherObj.optionsMapName)}">
									   <webapp:namedList id="nl" domain="${otherObj.optionsMapDomain}" name="${otherObj.optionsMapName}" filterHospCode="${formObjectForm.formField.filterHospitalCode}"/>
										<c:set var="isNumericList" value="true"/>
										<c:forEach var="pair" items="${nl.pairs}">
											<c:if test="${isNumericList eq true }">
												<c:catch var="isNumber">
												   <c:set var="temp" value="${pair.first * 1}" />
												</c:catch>
												<c:if test="${isNumber != null}">
													<c:set var="isNumericList" value="false"/>
												</c:if>
											</c:if>
										</c:forEach>
										<c:if test="${isNumericList eq 'true'}">
											<c:choose>
												<c:when test="${formObjectForm.formField.referencedField eq otherObj.name}">
													<smvc:option value="${otherObj.name}" selected="selected"><c:out value="${otherObj.name}"/> - <c:out value="${fn:substring(otherObj.label, 0, 30)}"/></smvc:option>
												</c:when>
												<c:otherwise>
													<smvc:option value="${otherObj.name}"><c:out value="${otherObj.name}"/> - <c:out value="${fn:substring(otherObj.label, 0, 30)}"/></smvc:option>
												</c:otherwise>
											</c:choose>
										</c:if>
									</c:if>
								</c:when>
								<c:otherwise>
									<c:choose>
										<c:when test="${formObjectForm.formField.referencedField eq otherObj.name}">
											<smvc:option value="${otherObj.name}" selected="selected"><c:out value="${otherObj.name}"/> - <c:out value="${fn:substring(otherObj.label, 0, 30)}"/></smvc:option>
										</c:when>
										<c:otherwise>
											<smvc:option value="${otherObj.name}"><c:out value="${otherObj.name}"/> - <c:out value="${fn:substring(otherObj.label, 0, 30)}"/></smvc:option>
										</c:otherwise>
									</c:choose>
								</c:otherwise>
							</c:choose>
						</c:if>
					</c:if>
				</c:forEach>
			</smvc:select>
		</td>
	</tr>

	
	<tr>
		<td class="label">When other field value is within the range:</td>
		<td class="input">
			<table>
				<tr>
					<td align="center">Low value<br/><smvc:input size="15" title="Enter the low value for this range" path="bandingDataNew.lowerBand"/></td>
					<td align="center">High value<br/><smvc:input size="15" title="Enter the high value for this range" path="bandingDataNew.higherBand"/></td>		
					<td align="center">Assign this field value<br/><smvc:input size="15" title="Enter a value for this field" path="bandingDataNew.assignValue"/></td>
					<td align="center"><br/><input type="submit" value="Add Band" onclick="return dispatch('addBanding')"/></td>
				</tr>
				<c:if test="${not empty formObject.bandingData}">
					<tr>
						<td><u>Low</u></td>
						<td><u>High</u></td>
						<td><u>Assign value</u></td>
						<td></td>
					</tr>
					<c:forEach var="bandingData" items="${formObject.bandingData}" varStatus="index">
						<tr>
							<td><c:out value="${bandingData.lowerBand}"/></td>
							<td><c:out value="${bandingData.higherBand}"/></td>
							<td><c:out value="${bandingData.assignValue}"/></td>
							<td>
								<img src="../images/delete.png" alt="delete" title="Remove this banding range" border="0" style="cursor: pointer;" onclick="javascript:removeBanding('<c:out value="${index.count-1}"/>');"/>
								<smvc:hidden path="selectedBandingDataIndex" id="selectedBandingDataIndex"/>
							</td>
						</tr>
					</c:forEach>
					</c:if>
			</table>
		</td>
	</tr>
</c:if>