<script language="JavaScript" src="../scripts/ESR-Script.js"></script>
<%@ taglib uri="/tags/esr-core" prefix="esrcore" %>
<%@ taglib uri="/tags/fw" prefix="fw" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html-el" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean-el" prefix="bean-el" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/tags/valuelist" prefix="vlh" %>
<%@ page import="gov.va.med.esr.ui.util.NameHelper"%>
<%@ page import="gov.va.med.fw.ui.valuelist.SelectableResult"%>
<%@ page import="gov.va.med.esr.common.model.comms.UndeliverableMailInfo"%>

<script type="text/javascript"> 
// Displays a confirmation message for the Update button
function egtSettingStopConfirmMessage()
{
    return confirmMessage('<bean-el:message key="message.comms.confirmUpdateStatus"/>');
}

</script>

<table width="100%" border="1" cellpadding="0" cellspacing="0" class="moduleShell">
<html-el:form action="/undeliverableMailSearchResults" method="post">
  <%@ include file="/admin/csrfgentoken.jsp" %>
<tr>
  <td>
    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShellTable">
      <tr>
        <td>
          <table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShellTableHead">
            <tr>
              <td class="moduleBlueBox"><img alt=""  src="../images/spacer.gif" width="28" height="23"/></td>
              <td nowrap style="padding-left: 7"><bean-el:message key="label.comms.undeliverableMailSearchResults"/></td>
              <td width="100%"><img alt=""  src="../images/spacer.gif"></td>
            </tr>
          </table>
        </td>
      </tr>
      <c:choose>
      <c:when test="${vlhlist.valueListInfo.totalNumberOfEntries == 0}">
      <tr>
        <td class="darkValue" style="padding:10 0 10 10; text-align: left"><bean-el:message key="label.noDataAvailable"/></td>
      </tr>
      </c:when>
      <c:otherwise>
      <tr width="100%">
        <td vAlign="top" align="center">
          <div id="undeliverableMailSearchResults" style="border-width:0px;">
            <table id="mailTableResult" align="center" width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleTable">
              <vlh:root id="undeliverableMailSearchTableId" value="vlhlist" url="?" includeParameters="*" configName="valueListConfigBeanLookAndFeel">
              <vlh:addParam name="checkboxName" value="selected" temp="false"/>
               <tr>
                <td colspan="5">
                  <table class="pagelinks">
                    <tr>
                      <td width="45%"><img alt=""  src="../images/spacer.gif"></td>
                        <td width="5%" nowrap="true">
                          <span class="pagebanner"><c:out value="${vlhlist.valueListInfo.totalNumberOfEntries}"/> Total
                          - Page (<c:out value="${vlhlist.valueListInfo.pagingPage}"/> of <c:out value="${vlhlist.valueListInfo.totalNumberOfPages}"/>).
                          &nbsp;</span>
                        </td>
                        <td width="5%">
                      <c:choose>
                      <c:when test="${vlhlist.valueListInfo.totalNumberOfPages > 1}">
                        <vlh:paging attributes="class=\"pagelinks\"" pages="10"><c:out value="${pageundeliverableMailSearchTableId}"/>&nbsp;</vlh:paging>
                        <!--<esrcore:paging attributes="class=\"pagelinks\"" pages="10"><c:out value="${pageundeliverableMailSearchTableId}"/>&nbsp;
                        </esrcore:paging>-->
                      </c:when>
                      <c:otherwise>
                        &nbsp;
                      </c:otherwise>
                      </c:choose>
                    </td>
                      <td width="45%"><img alt=""  src="../images/spacer.gif"></td>
                    </tr>
                  </table>
                </td>
              </tr>
              <tr vAlign="top">
                <td vAlign="top" align="center">
                  <table summary="List of Undeliverable Letter Search Result" rules="all" class="TableDisplay">
                    <tr>
                      <vlh:row bean="mailInfo">
                        <c:set var="counter" value="${mailInfoRowNumber}" />
                        <vlh:column title="Date Mailed" property="result.commsLogEntry.mailingDate" sortable="asc" attributes="class='valuelistRow1' align=\"left\" scope='col'" default="">
                          <vlh:attribute name="scope">row</vlh:attribute>
                          <esrcore:displayDate name="mailInfo" dateProperty="result.commsLogEntry.mailingDate" displayTime="false" nullText=""/>
                        </vlh:column>

                        <vlh:column title="Recipient Name &amp; Address" property="result.commsLogEntry.address" sortable="asc" attributes="class='valuelistRow1' align=\"left\" scope='col'" default="">
                          <c:if test="${mailInfo.result.commsLogEntry.name != null}">
                            <%= NameHelper.formatNameFirstNameFirst(((UndeliverableMailInfo)((SelectableResult)pageContext.getAttribute("mailInfo")).getResult()).getCommsLogEntry().getName())%>
                          </c:if>
                          <c:if test="${mailInfo.result.commsLogEntry.name != null && mailInfo.result.commsLogEntry.address != null}">
                            <br>
                          </c:if>
                          <c:if test="${mailInfo.result.commsLogEntry.address != null}">
                            <esrcore:displayValue name="mailInfo" property="result.commsLogEntry.address" nullText=""/>
                          </c:if>
                        </vlh:column>

                        <vlh:column title="Form Number" property="result.commsLogEntry.template.commsTemplateFormNumber" sortable="asc" attributes="class='valuelistRow1' align=\"left\" scope='col'" default="">
                          <esrcore:displayValue name="mailInfo" property="result.commsLogEntry.template.commsTemplateFormNumber" nullText=""/> - <esrcore:displayValue name="mailInfo" property="result.commsLogEntry.template.commsTemplateName" nullText=""/>
                        </vlh:column>
                        
                        <vlh:checkbox title="Returned by P.O." property="selected" name="selected" attributes="class='valuelistRow1' align=\"left\" scope='col'">
                        	<fw:label property= "selected" forId="selected${mailInfoRowNumber}"><span style="display:none">Select Letter for <esrcore:displayValue name="mailInfo" property="result.commsLogEntry.name" nullText=""/></span></fw:label>
                            <input type="checkbox" id="selected${mailInfoRowNumber}" title="Select Letter for <esrcore:displayValue name="mailInfo" property="result.commsLogEntry.name" nullText=""/>" name="selected" value="<c:out value="${mailInfoRowNumber}"/>" <c:out value="${selected[mailInfoRowNumber]}"/>>
                        </vlh:checkbox>


                        <vlh:column title="Edit Address" property="result.commsLogEntry.addressId" attributes="class='valuelistRow1' align=\"left\" scope='col'" default="">
                        <c:choose>
                        <c:when test="${mailInfo.result.updatedAddress == null}">
                          <a href="/esr/comms/undeliverableMailEditPermAddressFromSearch.do?methodName=DISPLAY&amp;selectedPersonId=<c:out value="${mailInfo.result.commsLogEntry.personId}"/>"><bean-el:message key="button.editAddress"/></a>
                        </c:when>
                        <c:otherwise>
                          &nbsp;
                        </c:otherwise>
                        </c:choose>
                        </vlh:column>
                      </vlh:row>
                    </tr>
                  </table>
                </td>
              </tr>
              </vlh:root>

              <%-- Button Row --%>
              <tr>
                <td colspan="2" height="50">
                  <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                      <td width="45%"><img alt=""  src="../images/spacer.gif"/></td>
                      <td><img alt=""  src="../images/buttonEndLeft.gif"/></td>
                      <td><html-el:submit property="methodName" style="width:50; vertical-align: top;" styleClass="buttonText" onclick="return(egtSettingStopConfirmMessage())"><bean-el:message key="button.update"/></html-el:submit></td>
                      <td><img alt=""  src="../images/buttonEndRight.gif"/></td>
                      <td width="1%"><img alt=""  src="../images/spacer.gif"/></td>
                      <td><img alt=""  src="../images/buttonEndLeft.gif"/></td>
                      <td><html-el:submit property="methodName" style="width:50; vertical-align: top;" styleClass="buttonText"><bean-el:message key="button.cancel"/></html-el:submit></td>
                      <td><img alt=""  src="../images/buttonEndRight.gif"/></td>
                      <td width="45%"><img alt=""  src="../images/spacer.gif"/></td>
                    </tr>
                  </table>
                </td>
              </tr>

            </table>
          </div>
        </td>
      </tr>
      </c:otherwise>
      </c:choose>
    </table>
  </td>
</tr>
</html-el:form>
</table>