<%@ include file="/portal/include/include_java.jsp" %>
<asi:importInputFormTagAttributes />
<span class="fieldContainer">
<%/*input mode*/%>
<span class="inputMode" <c:choose><c:when test="${readonly==true}">style="display:none"</c:when><c:otherwise>style="display:block"</c:otherwise></c:choose> >
  <label>
    <span style="display: block" class="label">
      <c:choose>
      <c:when test="${!empty label}" ><asi:out value="${label}" encoding="safehtml" /></c:when>
      <c:otherwise><span style="display: none"><c:out value="${legend}"/></span></c:otherwise>
      </c:choose>
    </span>
    <select name="<c:out value="${property}" />" 
    <c:if test="${!empty id}" >id="<c:out value="${id}" />_selectbox"</c:if> <%-- the id should be on the li, not the select --%>
    <c:if test="${!empty data}" >data="<c:out value="${data}" />"</c:if>
    <c:if test="${!empty onbeforesync}">onbeforesync="<c:out value="${onbeforesync}" />"</c:if>
    <c:if test="${!empty onaftersync}">onaftersync="<c:out value="${onaftersync}" />"</c:if>
    <c:if test="${!empty onclick}">onclick="<c:out value="${onclick}" />"</c:if>
    onchange="<c:if test="${showInConfirmationPage != false}">setFieldConfirmValue(this);</c:if><c:if test="${!empty onchange}"><c:out value="${onchange}" /></c:if>"	
    <c:if test="${!empty onblur}">onblur="<c:out value="${onblur}" />"</c:if>
    <c:if test="${!empty onfocus}">onfocus="<c:out value="${onfocus}" />"</c:if>
    data-asi-required="<c:out value="${required}" />"
    <c:if test="${!empty size}" >size="<c:out value="${size}"/>"</c:if>
    <c:if test="${multiple==true}" >multiple="true"</c:if>
    <c:if test="${required==true}" >data-asi-required="true"</c:if>
    <c:if test="${disabled != false}">disabled="true"</c:if>
    >
    
    <c:choose>
      <c:when test="${multiple==true}">    
        <c:forEach items="${items}" var="item" varStatus="status">
          <option value="<c:out value='${item.value}' />" <c:if test='${selectedOpts[status.index]}'> selected="true"</c:if> <c:if test="${!empty item.id}"> id="<c:out value='${item.id}' />"</c:if>><c:out value="${item.label}" /></option>
        </c:forEach>
      </c:when>
      <c:otherwise>
        <c:forEach items="${items}" var="item" varStatus="status">
          <option value="<c:out value='${item.value}' />" <c:if test='${value == item.value}'> selected="true"</c:if><c:if test="${!empty item.id}"> id="<c:out value='${item.id}' />"</c:if>><c:out value="${item.label}" /></option>
        </c:forEach>
      </c:otherwise>
    </c:choose>
    <c:forEach items="${optionGroups}" var="optionGroup" varStatus="optGroupStatus">
      <c:choose><c:when test="${optionGroup.disabled=='true'}">
        <c:set var="optGroupDisabled" value="disabled"/>
      </c:when><c:otherwise>
        <c:set var="optGroupDisabled" value=""/>
      </c:otherwise></c:choose>
      <optgroup label="<c:out value="${optionGroup.label}"/>" <c:out value="${optGroupDisabled}"/>>
      <c:choose>
        <c:when test="${multiple==true}">    
          <c:forEach items="${optionGroup.items}" var="item" varStatus="status">
            <option value="<c:out value='${item.value}' />" <c:if test='${optGrpsSelectedOpts[optGroupStatus.index][status.index]}'> selected="true"</c:if> <c:if test="${!empty item.id}"> id="<c:out value='${item.id}' />"</c:if>><c:out value="${item.label}" /></option>
          </c:forEach>
        </c:when>
        <c:otherwise>
          <c:forEach items="${optionGroup.items}" var="item" varStatus="status">
            <option value="<c:out value='${item.value}' />" <c:if test='${value == item.value}'> selected="true"</c:if><c:if test="${!empty item.id}"> id="<c:out value='${item.id}' />"</c:if>><c:out value="${item.label}" /></option>
          </c:forEach>
        </c:otherwise>
      </c:choose>
      </optgroup>
    </c:forEach>
    </select>
    <c:if test="${!empty errorMessage}">
      <span class="errorMessage"><asi:out value="${errorMessage}" encoding="safehtml" /></span>
    </c:if>
  </label>
</span>
<%/*end input mode*/%>

<%/*output mode*/%>
<c:if test="${showInConfirmationPage != false}">
<span class="outputMode" <c:choose><c:when test="${readonly==true}">style="display:block"</c:when><c:otherwise>style="display:none"</c:otherwise></c:choose> >
  <label>
    <span class="confirmLabel">  
      <c:choose>
      <c:when test="${!empty label}" ><asi:out value="${label}" encoding="safehtml" />:</c:when>
      <c:otherwise><span style="display: none"><c:out value="${legend}"/></span></c:otherwise>
      </c:choose>
    </span>     
    <span class="confirmValue">
    <c:choose>
      <c:when test="${value == null || value == ''}"><c:out value="${items[0].label}"/></c:when>
      <c:otherwise>
        <c:forEach items="${items}" var="item" varStatus="status">
          <c:if test='${value == item.value}'><c:out value="${item.label}"/></c:if>
        </c:forEach>
      </c:otherwise>
    </c:choose>
    </span>
  </label>
</span>
</c:if>
<%/*end output mode*/%>
</span>