<%@ 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' %>
<%@ page import='gov.va.med.esr.common.model.lookup.AddressChangeSource' %>
<%@ page import='gov.va.med.esr.common.model.lookup.PhoneSourceOfChange' %>
<%@ page import='gov.va.med.esr.common.model.lookup.EmailSourceOfChange' %>
<%@ page import="gov.va.med.esr.common.model.lookup.VAFacility" %>
<c:set var="notDefined" scope="page"><bean-el:message key="label.isNotDefined"/></c:set>
<c:set var="current" scope="page"><bean-el:message key="label.isCurrent"/></c:set>
<c:set var="notYetCurrent" scope="page"><bean-el:message key="label.isNotYetCurrent"/></c:set>
<c:set var="expired" scope="page"><bean-el:message key="label.hasExpired"/></c:set>
<c:set var="confAddressText"><bean-el:message key="label.addresses.confidentialAddressHeader"/></c:set>
<c:set var="tempAddressText"><bean-el:message key="label.addresses.temporaryAddressHeader"/></c:set>

<!--<script src="../scripts/ESR-Script.js" type="text/javascript"></script> -->
<c:set var="addressVamcConstant"><%= AddressChangeSource.CODE_VAMC.getName() %></c:set>
<c:set var="phoneVamcConstant"><%= PhoneSourceOfChange.CODE_VAMC.getName() %></c:set>
<c:set var="emailVamcConstant"><%= EmailSourceOfChange.CODE_VAMC.getName() %></c:set>
<c:set var="hecFacilityConstant"><%= VAFacility.CODE_HEC.getName() %></c:set>
<c:set var="phoneCount" value="${demographicAddressesForm.phoneSize}"/>
<c:set var="emailCount" value="${demographicAddressesForm.emailSize}"/>
<c:set var="appData" value="${AppData}" scope="session"/>
<c:set var="personKey" value="SelectedPerson"/>
<c:set var="person" value="${appData[personKey]}"/>
<c:set var="viewHistoricalAddresses" scope="page"><bean-el:message key="text.viewHistoricalAddresses"/></c:set>
<c:set var="countryEditable" scope="page" value="true"/>
<c:set var="displayRequiredFieldsIndicator" scope="page" value="true"/>
<c:set var="zipCodeLookup" scope="page" value="true"/>
<c:set var="readOnlyAddress" scope="page" value="true"/>
<c:set var="isAddAPerson" value="false"></c:set>

<!-- set read only falgs based on user permissions -->
<auth:authorize ifAnyGranted="<%=Capability.EDIT_ADDRESS.getName()%>">
  <c:set var="readOnlyAddress" scope="page" value="false"/>
</auth:authorize>
<c:if test="${person.permanentAddress == null}">
  <auth:authorize ifAnyGranted="<%=Capability.ADD_ADDRESS.getName()%>">
    <c:set var="readOnlyAddress" scope="page" value="false"/>
  </auth:authorize>
</c:if>

<%-- Person Locked Check --%>
<c:set var="personLocked" value="${appData[personKey].personLocked}"/>
<c:if test="${personLocked}">
  <c:set var="readOnlyAddress" scope="page" value="true"/>
</c:if>

<c:if test="${readOnlyAddress}">
  <c:set var="countryEditable" scope="page" value="false"/>
  <c:set var="zipCodeLookup" scope="page" value="false"/>
</c:if>

<script type="text/javascript">
  // Perform all page initialization
  function onLoadInit()
  {
    updateCountryFields();
    updateAddressSiteOfChange();
    initPhoneSitesOfChange();
    initEmailSitesOfChange();
    setAddEmailFocus();
    setAddPhoneNumberFocus();
  }
  
//Place focus on "Email Type" field when "Add Email Address" is clicked
  function setAddEmailFocus()
  {
	  if ('${demographicAddressesForm.addEmailType}' != '') {
		  var arr = '${demographicAddressesForm.addEmailType}';
		  var component = document.getElementsByName("emailType[" + arr + "]");
		  component[0].focus();
	  }
  }
  
  //Place focus on "Phone Type" field when "Add Phone Number" is clicked
  function setAddPhoneNumberFocus()
  {
	  if ('${demographicAddressesForm.addPhoneType}' != '') { 
		  var arr = '${demographicAddressesForm.addPhoneType}';
		  var component = document.getElementsByName("phoneType[" + arr + "]");
		  component[0].focus();
	  }
  }

  // Update the address site of change
  function updateAddressSiteOfChange()
  {
    updateSiteOfChange(demographicAddressesForm.addrSourceOfUpdate, '<c:out value="${addressVamcConstant}"/>',
        demographicAddressesForm.siteOfUpdateEdit, demographicAddressesForm.siteOfUpdateEdit2, '<c:out value="${hecFacilityConstant}"/>');
  }

  // Initialize the phone sites of change
  function initPhoneSitesOfChange()
  {
    for (i = 0; i < <c:out value="${phoneCount}"/>; i++)
    {
      updateSiteOfChange(eval("demographicAddressesForm.phoneSourceOfUpdate" + i), '<c:out value="${phoneVamcConstant}"/>',
          eval("demographicAddressesForm.phoneSiteOfUpdateEdit" + i), eval("demographicAddressesForm.phoneSiteOfUpdateEdit2" + i),
          '<c:out value="${hecFacilityConstant}"/>');
    }
  }

  // Initialize the email sites of change
  function initEmailSitesOfChange()
  {
    for (i = 0; i < <c:out value="${emailCount}"/>; i++)
    {
      updateSiteOfChange(eval("demographicAddressesForm.emailSourceOfUpdate" + i), '<c:out value="${emailVamcConstant}"/>',
          eval("demographicAddressesForm.emailSiteOfUpdateEdit" + i), eval("demographicAddressesForm.emailSiteOfUpdateEdit2" + i),
          '<c:out value="${hecFacilityConstant}"/>');
    }
  }
</script>

<table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShell" role="presentation">
<html-el:form action="/demographicAddresses" method="post">
  <%@ include file="/admin/csrfgentoken.jsp" %>
<tr>
<td>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShellTable" role="presentation">
  <%-- Permanent Address Section --%>
<tr>
  <td>
    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShellTableHead" role="presentation">
      <tr>
        <td class="moduleBlueBox"><img alt=""  src="../images/spacer.gif" width="25" height="17"/></td>
       
        <td nowrap> <bean:message key="text.updateAddressLink"/></td>
        <td width="100%"><img alt=""  src="../images/spacer.gif"></td>
        <td nowrap class="moduleBlueLink" style="padding: 1px 8px 1px 8px">
        <fw:link action="/demographicAddresses?methodName=goto508Notes">
            <bean-el:message key="text.508Notes"/>
        </fw:link>
        </td>
        <td width="100%"><img alt=""  src="../images/spacer.gif"></td>
        <td nowrap class="moduleBlueLink" style="padding: 1px 8px 1px 8px"><fw:link action="/demographicAddressesHistory?methodName=DISPLAY&amp;history=viewHistoricalAddresses"><bean-el:message
            key="text.viewHistoricalAddresses"/></fw:link></td>
      </tr>
    </table>
  </td>
</tr>
<tr>
<td>
       <table width="100%" border="0" cellspacing="0" cellpadding="0" class="moduleShellTableBody" role="presentation">
                   
                       
                       <auth:authorize ifAnyGranted="<%=Capability.ADDRESS%>"> 
                   
						<c:if test="${not empty demographicOverviewForm.residentialAddress }">
							<tr>
								<td  class="label" valign="top">
								<c:if test="${demographicOverviewForm.activeAddress == 'P'}">
								<span><img alt=""  src="../images/check_green.gif"></span>
							</c:if>
								<fw:link action="/demographicAddresses.do?methodName=Addresses&addressType=P" module="/demographic">
	                           <bean:message key="label.address.residentialaddress"/></fw:link>:</td>
								<td width="5"><img alt=""  src="../images/spacer.gif"></td>
								<td class="value">
								<esrcore:displayValue name="demographicOverviewForm" property="residentialAddress"/>
								 	<br/>
						   	<esrcore:displayValue name="demographicOverviewForm" property="phoneNumber"/>
						  
								</td>
								<td width="100" valign="top"><bean:message key="label.address.cassCertified"/></td>
								<td width="50" valign="top" >NC</td>
								<td width="80" valign="top" ><!-- bean:message key="label.address.cassCertifiedStartDate"/ --></td>
								<td width="80" valign="top" ><!-- bean:message key="label.address.cassCertifiedEndDate"/ --></td>
							</tr>
						</c:if>
					
					
						  <c:if test="${not empty demographicOverviewForm.permanentAddress }">
						      <tr>
							 	<td  class="label" valign="top">
							 	<c:if test="${demographicOverviewForm.activeAddress == 'M'}">
								<span><img alt=""  src="../images/check_green.gif"></span>
							</c:if>
							 	<fw:link action="/demographicAddresses.do?methodName=Addresses&addressType=M" module="/demographic"><bean:message key="label.address.permanentaddress"/></fw:link>:</td>
							   	<td width="5"><img alt=""  src="../images/spacer.gif"></td>
								<td class="value">
								  <c:if test="${demographicOverviewForm.badAddressReasonPerm != null}">
								    <span style="color: red" class="darklabel"><bean:message key="label.addresses.badAddressReason"/>:</span><br/>
								    <span class="darkvalue"><esrcore:displayValue name="demographicOverviewForm" property="badAddressReasonPerm"/></span><br/>
								  </c:if>
							   	<esrcore:displayValue name="demographicOverviewForm" property="permanentAddress"/>
							   	<br/>
							   	<esrcore:displayValue name="demographicOverviewForm" property="phoneNumber"/>
							   </td>
							   <td width="100" valign="top"><bean:message key="label.address.cassCertified"/></td>
							   <td width="50" valign="top" >NC</td>
							   <td width="80" valign="top" ><!-- bean:message key="label.address.cassCertifiedStartDate"/ --></td>
							   <td width="80" valign="top" ><!-- bean:message key="label.address.cassCertifiedEndDate"/ --></td>
							</tr>
						</c:if>
					
					
						  <c:if test="${not empty demographicOverviewForm.temporaryAddress}">
		
						      <tr>
							 	<td  class="label" valign="top">
							 	<c:if test="${demographicOverviewForm.activeAddress == 'C'}">
								<span><img alt=""  src="../images/check_green.gif"></span>
							</c:if>
							 	<fw:link action="/demographicAddresses.do?methodName=Addresses&addressType=C" module="/demographic"><bean:message key="label.address.temporaryAddress"/></fw:link>:</td>
							   	<td width="5"><img alt=""  src="../images/spacer.gif"></td>
								<td class="value">
								 <c:if test="${demographicOverviewForm.badAddressReasonTemp != null}">
								    <span style="color: red" class="darklabel"><bean:message key="label.addresses.badAddressReason"/>:</span><br/>
								    <span class="darkvalue"><esrcore:displayValue name="demographicOverviewForm" property="badAddressReasonTerm"/></span><br/>
								  </c:if>
							   	<esrcore:displayValue name="demographicOverviewForm" property="temporaryAddress"/>
							   	<br/>
							   	<esrcore:displayValue name="demographicOverviewForm" property="phoneNumber"/>
							   </td>
							   <td width="100" valign="top"><bean:message key="label.address.cassCertified"/></td>
							   <td width="50" valign="top" >NC</td>
							   <td width="80" valign="top" ><!-- bean:message key="label.address.cassCertifiedStartDate"/ --></td>
							   <td width="80" valign="top" ><!-- bean:message key="label.address.cassCertifiedEndDate"/ --></td>
							</tr>
	
					    </c:if>
					
					    <c:if test="${not empty demographicOverviewForm.confidentialAddress}">
	
					      <tr>
						 	<td  class="label" valign="top">
						 	<c:if test="${demographicOverviewForm.activeAddress == 'CNF'}">
								<span><img alt=""  src="../images/check_green.gif"></span>
							</c:if>
						 	<fw:link action="/demographicAddresses.do?methodName=Addresses&addressType=CNF" module="/demographic"><bean:message key="label.address.confidentialrddress"/></fw:link>:</td>
						   	<td width="5"><img alt=""  src="../images/spacer.gif"></td>
							<td class="value">
							 <c:if test="${demographicOverviewForm.badAddressReasonPerm != null}">
								    <span style="color: red" class="darklabel"><bean:message key="label.addresses.badAddressReason"/>:</span><br/>
								    <span class="darkvalue"><esrcore:displayValue name="demographicOverviewForm" property="badAddressReasonPerm"/></span><br/>
								  </c:if>
						   	<esrcore:displayValue name="demographicOverviewForm" property="confidentialAddress"/>
						   	<br/>
						   	<esrcore:displayValue name="demographicOverviewForm" property="phoneNumber"/>
						   </td>
						   <td width="100" valign="top"><bean:message key="label.address.cassCertified"/></td>
						   <td width="50" valign="top" >NC</td>
						   <td width="80" valign="top" ><!-- bean:message key="label.address.cassCertifiedStartDate"/ --></td>
						   <td width="80" valign="top" ><!-- bean:message key="label.address.cassCertifiedEndDate"/ --></td>
						</tr>
		
						</c:if>
				

                      </auth:authorize>
                      
                      </table>
</td>
</tr>
</table>
</td>
</tr>
</table>

  <html-el:hidden name="demographicAddressesForm" property="addAPerson"/>
</html-el:form>
</table>
