<%@ taglib uri="/tags/displaytag" prefix="display" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean-el" prefix="bean-el" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html-el" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/struts-tiles" prefix="tiles" %>
<%@ taglib uri="/tags/struts-nested" prefix="nested" %>
<%@ taglib uri="/tags/esr-core" prefix="esrcore" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/tags/fw" prefix="fw" %>
<%@ taglib uri="/tags/authz" prefix="auth" %>
<%@ page import='gov.va.med.esr.common.model.lookup.Capability' %>

<!-- POW permissions -->
<c:set var="addPOW"><%=Capability.ADD_POW_INFO.getName()%></c:set>
<c:set var="viewPOW"><%=Capability.VIEW_POW_INFO.getName()%></c:set>
<c:set var="editPOW"><%=Capability.EDIT_POW_INFO.getName()%></c:set>
<c:set var="editPOWYesToNo"><%=Capability.POW_YES_TO_NO.getName()%></c:set>
<c:set var="readOnlyPOW" value="true"/>
<c:set var="expandableSectionCollapsed" scope="page"><bean-el:message key="label.expandableSectionCollapsed"/></c:set>

<script type="text/javascript">
function resetPowCaptivityDays(index)
{
  var fieldName = "powCaptivityDays[" + index + "]";
  document.getElementById(fieldName).value = "";
}
</script>

 <!-- POW -->
 <!-- check for read only conditions no powd and has add permission -->
 <!--
 <c:if test="${eligibilityForm.powInd != 'Yes'}">
  <auth:authorize ifAnyGranted="${addPOW}">
    <c:set var="readOnlyPOW" value="false"/>
  </auth:authorize>
 </c:if>
 -->
 <!-- edit permission -->
<auth:authorize ifAnyGranted="${editPOW}">
  <c:set var="readOnlyPOW" value="false"/>
</auth:authorize>

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="moduleShellTableBody" role="presentation">
  <tr>
    <td width="45%" class="moduleLabel">
      <fw:link href="." onclick="expandOrCollapse(powBlock, powImage, powHiddenId); return false">
        <html-el:img alt="${expandableSectionCollapsed}" align="center" border="0" styleId="powImage" src="../images/redArrowRight.gif"/><fw:label property="powInd" forId="powIndId"><bean-el:message key="label.prisonerOfWar"/>:</fw:label>
      </fw:link>&nbsp;
      <html-el:hidden name="eligibilityForm" property="powHiddenId"/>
    </td>
    <td width="55%">
      <table width="20%" border="0"cellspacing="0" cellpadding="0" role="presentation">
        <tr>
          <td class="moduleValue" nowrap>
            <c:set var="powText"><bean-el:message key="label.prisonerOfWar"/></c:set>
            <html-el:text title="${powText}" styleClass="moduleEdit" styleId="powIndId" readonly="true" property="powInd" />
          </td>
          <c:if test="${eligibilityForm.powInd != 'No'}">
          <!-- check for permissions -->
          <auth:authorize ifAnyGranted="${editPOWYesToNo}">
          <td>&nbsp;&nbsp;</td>
          <td><img alt=""  src="../images/buttonEndLeft.gif"/></td>
          <td>
            <html-el:submit property="methodName" style="width:85; vertical-align: top;" styleClass="buttonText">
              <bean-el:message key="button.setNoPow"/>
            </html-el:submit>
          </td>
          <td><img alt=""  src="../images/buttonEndRight.gif"/></td>
          <td width="100%"><img alt=""  src="../images/spacer.gif" width="1" height="1"/></td>
          </auth:authorize>
          </c:if>
        </tr>
      </table>
    </td>
  </tr>
</table>

<div id=powBlock style="display:none" class="expandCollapseBody">
  <table width="100%" border="0" cellspacing="0" cellpadding="0" class="moduleShellTableBody" role="presentation">
    <c:choose>
    <c:when test="${eligibilityForm.powInd == 'Yes'}">
    <c:forEach var="pow" items="${eligibilityForm.powIdList}" varStatus="status">
    <c:set var="counter" value="${status.count - 1}" />
    <tr>
      <td colspan="2" width="100%"><img alt=""  src="../images/spacer.gif" width="1" height="10"/></td>
    </tr>
    <tr>
      <td width="45%" class="moduleLabel"><fw:label property="powSource[${counter}]" forId="powSourceId${counter}"><bean-el:message key="label.powSource"/>:</fw:label></td>
      <td width="55%" class="moduleValue">
        <c:set var="powSourceText"><bean-el:message key="label.powSource"/></c:set>
        <html-el:select title="${powSourceText} ${status.count}" styleClass="moduleEdit" styleId="powSourceId${counter}" property="powSource[${counter}]" disabled="${readOnlyPOW}">
        <html-el:option value=""><bean-el:message key="label.select" /></html-el:option>
          <esrcore:options collection="gov.va.med.esr.ui.common.beans.POWDataSource" property="code" labelProperty="description"/>
        </html-el:select>
      </td>
    </tr>
    <tr>
      <td width="45%" class="moduleLabel"><fw:label property="powDocumentType[${counter}]" forId="powDocTypeId${counter}"><bean-el:message key="label.powDocumentType"/>:</fw:label></td>
      <td width="55%" class="moduleValue">
        <c:set var="powDocumentTypeText"><bean-el:message key="label.powDocumentType"/></c:set>
        <html-el:select title="${powDocumentTypeText} ${status.count}" styleClass="moduleEdit" styleId="powDocTypeId${counter}" property="powDocumentType[${counter}]" disabled="${readOnlyPOW}">
        <html-el:option value=""><bean-el:message key="label.select" /></html-el:option>
          <esrcore:options collection="gov.va.med.esr.common.model.lookup.POWDocumentType" property="code" labelProperty="description"/>
        </html-el:select>
      </td>
    </tr>
    <tr>
      <td width="45%" class="moduleLabel"><fw:label required="true" property="powCaptureDate[${counter}]" forId="powCaptureDate[${counter}]"><bean-el:message key="label.powCaptureDate"/>:</fw:label></td>
      <td width="55%" class="moduleValue">
        <c:set var="powCaptureDateText"><bean-el:message key="label.required"/>, <bean-el:message key="label.powCaptureDate"/></c:set>
        <html-el:text title="${powCaptureDateText} ${status.count}" styleClass="moduleEdit" property="powCaptureDate[${counter}]" styleId="powCaptureDate[${counter}]" readonly="${readOnlyPOW}" onkeyup="resetPowCaptivityDays(${counter});" onblur="javascript:powCaptivityDays(${counter})"/>
      </td>
    </tr>
    <tr>
      <td width="45%" class="moduleLabel"><fw:label  required="true" property="powReleaseDate[${counter}]" forId="powReleaseDate[${counter}]"><bean-el:message key="label.powReleaseDate"/>:</fw:label></td>
      <td width="55%" class="moduleValue">
        <c:set var="powReleaseDateText"><bean-el:message key="label.required"/>, <bean-el:message key="label.powReleaseDate"/></c:set>
        <html-el:text title="${powReleaseDateText} ${status.count}" styleClass="moduleEdit" property="powReleaseDate[${counter}]" styleId="powReleaseDate[${counter}]" readonly="${readOnlyPOW}" onkeyup="resetPowCaptivityDays(${counter});" onblur="javascript:powCaptivityDays(${counter})"/>
      </td>
    </tr>
    <tr>
      <td width="45%" class="moduleLabel"><fw:label property="powCaptivityDays[${counter}]" forId="powCaptivityDaysId${counter}"><bean-el:message key="label.powCaptivityDays"/>:</fw:label></td>
      <td width="55%" class="moduleValue">
        <c:set var="powCaptivityDaysText"><bean-el:message key="label.powCaptivityDays"/></c:set>
        <html-el:text title="${powCaptivityDaysText} ${status.count}" readonly="true" styleClass="moduleEdit" styleId="powCaptivityDaysId${counter}" property="powCaptivityDays[${counter}]" />
      </td>
    </tr>
    <tr>
      <td width="45%" class="moduleLabel"><fw:label required="true" property="powConfinementLocation[${counter}]" forId="powConfinementLocation[${counter}]"><bean-el:message key="label.powConfinementLocation"/>:</fw:label></td>
      <td width="55%" class="moduleValue">
        <c:set var="powConfinementLocationText"><bean-el:message key="label.required"/>, <bean-el:message key="label.powConfinementLocation"/></c:set>
        <html-el:select title="${powConfinementLocationText} ${status.count}" styleClass="moduleEdit" styleId="powConfinementLocation[${counter}]" property="powConfinementLocation[${counter}]" disabled="${readOnlyPOW}" >
        <html-el:option value=""><bean-el:message key="label.select" /></html-el:option>
          <esrcore:options collection="gov.va.med.esr.common.model.lookup.PrisonerOfWarLocation" property="code" labelProperty="description"/>
        </html-el:select>
      </td>
    </tr>
    <tr>
      <td width="45%" class="moduleLabel"><fw:label property="powCampLocation[${counter}]" forId="powCampLocationId${counter}"><bean-el:message key="label.powCamp"/>:</fw:label></td>
      <td width="55%" class="moduleValue">
        <c:set var="powCampLocationText"><bean-el:message key="label.powCamp"/></c:set>
        <html-el:select title="${powCampLocationText} ${status.count}" styleClass="moduleEdit" styleId="powCampLocationId${counter}" property="powCampLocation[${counter}]" disabled="${readOnlyPOW}" onchange="javascript:lookupCampLocation(this, ${counter})">
        <html-el:option value=""><bean-el:message key="label.select" /></html-el:option>
          <esrcore:options collection="gov.va.med.esr.common.model.lookup.POWCampLocation" property="code" labelProperty="nameAndLocation"/>
        </html-el:select>
      </td>
    </tr>
    <tr>
      <td width="45%" class="moduleLabel"><fw:label property="powCampCode[${counter}]" forId="powCampCodeId${counter}"><bean-el:message key="label.powCampCode"/>:</fw:label></td>
      <td width="55%" class="moduleValue">
        <c:set var="powCampCodeText"><bean-el:message key="label.powCampCode"/></c:set>
        <html-el:text title="${powCampCodeText} ${status.count}" readonly="true" styleClass="moduleEdit" styleId="powCampCodeId${counter}" property="powCampCode[${counter}]"/>
      </td>
    </tr>
    <tr>
      <td width="45%" class="moduleLabel"><fw:label property="powCampCity[${counter}]" forId="powCampCityId${counter}"><bean-el:message key="label.powCampCity"/>:</fw:label></td>
      <td width="55%" class="moduleValue">
        <c:set var="powCampCityText"><bean-el:message key="label.powCampCity"/></c:set>
        <html-el:text title="${powCampCityText} ${status.count}" readonly="true" styleClass="moduleEdit" styleId="powCampCityId${counter}" property="powCampCity[${counter}]" size="45"/>
      </td>
    </tr>
    <c:if test="${eligibilityForm.powDateEnteredList[counter] != null && eligibilityForm.powDateEnteredList[counter] != ''}">
    <tr>
      <td width="45%" class="moduleLabel"><bean-el:message key="label.powDateEntered"/>:</td>
      <c:set var="powDateEnteredText"><bean-el:message key="label.powDateEntered"/></c:set>
      <td title="<c:out value="${powDateEnteredText} ${status.count}"/>" width="55%" class="moduleValue">
      	<c:out value="${eligibilityForm.powDateEnteredList[counter]}" />
      	<html-el:hidden name="eligibilityForm" property="powDateEnteredList[${counter}]" />
      </td>
    </tr>
    </c:if>
    </c:forEach>
    </c:when>
    <c:otherwise>
    <tr>
      <td width="45%" class="moduleLabel" style="padding-bottom: 10"><bean-el:message key="label.noPOWAvailable"/>&nbsp;</td>
      <td width="55%" class="moduleValue">&nbsp;</td>
    </tr>
    </c:otherwise>
    </c:choose>
  </table>

  <!-- Display add button only for veterans -->
  <c:if test="${eligibilityForm.veteranIndicator == 'y'}">

  <!-- Do not display the add button if it is read only -->
  <c:if test="${not readOnlyPOW}">
  <table width="100%" border="0" cellpadding="0" cellspacing="0" style="padding: 10 0 10 0" class="moduleShellTableBody" role="presentation">
    <tr>
      <td width="49%"><img alt=""  src="../images/spacer.gif"/></td>
      <td><img alt=""  src="../images/buttonEndLeft.gif"/></td>
      <td><html-el:submit property="methodName" style="width:110; vertical-align: top;" styleClass="buttonText"><bean-el:message key="button.addPow"/></html-el:submit></td>
      <td><img alt=""  src="../images/buttonEndRight.gif"/></td>
      <td width="49%"><img alt=""  src="../images/spacer.gif"/></td>
    </tr>
  </table>
  </c:if>

  </c:if>
</div>
