<%@ taglib uri="/tags/struts-bean-el" prefix="bean-el" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html-el" %>
<%@ taglib uri="/tags/esr-core" prefix="esrcore" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/tags/fw" prefix="fw" %>

<c:set var="expandableSectionCollapsed" scope="page"><bean-el:message key="label.expandableSectionCollapsed"/></c:set>

<c:set var="nonVeteran" value="false"/>
<c:if test="${eligibilityForm.veteranIndicator == 'n'}">
    <c:set var="nonVeteran" value="true"/>
</c:if>

<c:set var="notyesVaPension" value="false"/> 
<c:if test="${eligibilityForm.vaPension == 'n' || eligibilityForm.vaPension == ''}">
    <c:set var="notyesVaPension" value="true"/>
</c:if>

<c:set var="notnoVaPension" value="false"/>
<c:if test="${eligibilityForm.vaPension == 'y' || eligibilityForm.vaPension == ''}">
    <c:set var="notnoVaPension" value="true"/>
</c:if>

<script type="text/javascript">
var pAwdCode;
var pEff;
var pEffDate;
var pTerm;
var pTcode1;
var pTcode2;
var pTcode3;
var pTcode4;

function enableVaPensionAward(value) 
{
    pEffDate.disabled = value;
	pAwdCode.disabled = value;
	pEff.disabled = value;
}

function enableVaPensionTermination(value) 
{	 
	pTerm.disabled = value;
    pTermDate.disabled = value;
    pTcode1.disabled = value;
    pTcode2.disabled = value;
    pTcode3.disabled = value;
    pTcode4.disabled = value;
}

function processVaPensionIndicator()
{  
    var vaPension_y = document.getElementById('idVaPension_y');
    var vaPension_n = document.getElementById('idVaPension_n');
    
    pEff = document.getElementById('peffBlock'); // effective date block
    pTerm = document.getElementById('ptmBlock'); //termination date block
    var imageElement = document.getElementById('vaArrowImage');
    pEffDate = document.getElementById('idPensionAwardEffectiveDate');
    pTermDate = document.getElementById('idPensionAwardTerminationDate');
    pAwdCode = document.getElementById('idPensionAwardReasonCode');
    pTcode1 = document.getElementById('idPensionAwardTerminationReasonCode1');
    pTcode2 = document.getElementById('idPensionAwardTerminationReasonCode2');
    pTcode3 = document.getElementById('idPensionAwardTerminationReasonCode3');
    pTcode4 = document.getElementById('idPensionAwardTerminationReasonCode4');

	// vaPension null however esr vaPension default is no.
	// if ( vaPension_n.checked == true || vaPension_y.value == null || vaPension_y.checked == false ) 
	if (vaPension_n.checked == true)
	{		
			expandSection(pTerm, imageElement, null);	
			if ( pEffDate.value == null || pEffDate.value ==  '')
    		{
    			pAwdCode.options[0].selected = true;
      			pAwdCode.selectedIndex = 0;
      			collapseSection(pEff, imageElement, null);
      				
      		}
      		else
      		{	
      			expandSection(pEff, imageElement, null);	
      		}
      		enableVaPensionTermination(false);
      		enableVaPensionAward(true);
     }
  	 else 
  	 {	// yes must be checked
  	 	// if ( vaPension_y.checked == true || vaPension_n.value == null || vaPension_n.checked == false ) 
  	 		expandSection(pEff, imageElement, null);	
  	 		if ( pTermDate.value == null || pTermDate.value ==  '')
    		{
    			pTcode1.options[0].selected = true;
    			pTcode2.options[0].selected = true;
    			pTcode3.options[0].selected = true;
    			pTcode4.options[0].selected = true;
    			pTcode1.selectedIndex = 0;
    			pTcode2.selectedIndex = 0;
    			pTcode3.selectedIndex = 0;
    			pTcode4.selectedIndex = 0;
    			collapseSection(pTerm, imageElement, null);
      	 	}
      	 	else
      	 	{	
      			expandSection(pTerm, imageElement, null);	
      		}
      		enableVaPensionTermination(true);
      		enableVaPensionAward(false);
    }
}

function processPensionEffectiveDate()
{
    var vaPension_y = document.getElementById('idVaPension_y');
    var vaPension_n = document.getElementById('idVaPension_n');

    pEffDate = document.getElementById('idPensionAwardEffectiveDate');
    pAwdCode = document.getElementById('idPensionAwardReasonCode');

    if (  vaPension_n.checked == true  &&  ( pEffDate.value == '' || pEffDate.value == null) )
    {
    	pAwdCode.options[0].selected = true;
    	pAwdCode.selectedIndex = 0;
    }
}

function processPensionTerminationDate()
{
    var vaPension_y = document.getElementById('idVaPension_y');
    var vaPension_n = document.getElementById('idVaPension_n');
    var pTermDate = document.getElementById('idPensionAwardTerminationDate');
    var pTcode1 = document.getElementById('idPensionAwardTerminationReasonCode1');
    var pTcode2 = document.getElementById('idPensionAwardTerminationReasonCode2');
    var pTcode3 = document.getElementById('idPensionAwardTerminationReasonCode3');
    var pTcode4 = document.getElementById('idPensionAwardTerminationReasonCode4');

    if ( vaPension_y.checked == true  &&  ( pTermDate.value == '' || pTermDate.value == null )  )
    {
    	pTcode1.options[0].selected = true;
    	pTcode2.options[0].selected = true;
    	pTcode3.options[0].selected = true;
    	pTcode4.options[0].selected = true;
    	pTcode1.selectedIndex = 0;
    	pTcode2.selectedIndex = 0;
    	pTcode3.selectedIndex = 0;
    	pTcode4.selectedIndex = 0;
    	// thisForm.pensionAwardTerminationReasonCode1.value = '';
    	// thisForm.pensionAwardTerminationReasonCode2.value = '';
    	// thisForm.pensionAwardTerminationReasonCode3.value = '';
    	// thisForm.pensionAwardTerminationReasonCode4.value = '';
    }
}
</script>

<!-- Pension Group Data -->
	
	  <table width="100%" border="0" cellspacing="0" cellpadding="0" class="moduleShellTableBody" role="presentation">
   			<tr>
   				<td width="45%" class="moduleLabel" nowrap><html-el:img alt="${expandableSectionCollapsed}" align="center" styleId="vaArrowImage" src="../images/redArrowRight.gif" /><bean-el:message key="label.pension"/>:</td>
                <td width="55%" class="moduleValue">
                 <c:forEach var="item" items="${yesNoList}">
                  <c:set var="pensionText"><bean-el:message key="label.pension"/>&nbsp;(<bean-el:message key="${item.label}" />)</c:set>
                   <html-el:radio title="${pensionText}" styleId="idVaPension_${item.value}"  name="eligibilityForm" property="vaPension" disabled="${nonVeteran}" onclick="processVaPensionIndicator()" onKeyPress="processVaPensionIndicator()" value="${item.value}" />
                   <fw:label property="vaPension" forId="idVaPension_${item.value}"><bean-el:message key="${item.label}" /></fw:label>
                 </c:forEach>
                </td>
              </tr>
      </table>

      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="moduleShellTableBody" role="presentation">        
        <tr>
          <td width="100%" colspan="2">
            <div id="peffBlock" class="expandCollapseBody">
              <table width="100%" cellSpacing=0 cellPadding=0 border=0 role="presentation"> 
              <tr>
                <td width="45%" class="moduleLabel"><fw:label property="pensionAwardEffectiveDate" forId="idPensionAwardEffectiveDate"><bean-el:message key="label.pensionAwardEffectiveDate"/>:</fw:label></td>
                <td width="55%" class="moduleValue">
                  <c:set var="pensionAwardEffectiveDateText"><bean-el:message key="label.pensionAwardEffectiveDate"/> <bean-el:message key="label.mmddyyyy"/></c:set>
                  <html-el:text title="${pensionAwardEffectiveDateText}" styleClass="moduleEdit" styleId="idPensionAwardEffectiveDate" disabled="${nonVeteran}" property="pensionAwardEffectiveDate"  onchange="processPensionEffectiveDate()" onkeyup="processPensionEffectiveDate()" onkeydown="processPensionEffectiveDate()"/>&nbsp;<bean-el:message key="label.mmddyyyy"/>
                  <html-el:hidden name="eligibilityForm" property="oldPensionAwardEffectiveDate" />
                </td>
              </tr>
              <tr>
                <td width="45%" class="moduleLabel"><fw:label property="pensionAwardReasonCode" forId="idPensionAwardReasonCode"><bean-el:message key="label.pensionAwardReasonCode"/>:</fw:label></td>
                <td width="55%" class="moduleValue">
                    <c:set var="pensionAwardReasonCodeText"><bean-el:message key="label.pensionAwardReasonCode"/></c:set>
                    <html-el:select title="${pensionAwardReasonCodeText}" styleClass="moduleEdit" styleId="idPensionAwardReasonCode" property="pensionAwardReasonCode" disabled="${nonVeteran}">
                    <html-el:option value=""><bean-el:message key="label.select" /></html-el:option>
                    <esrcore:options collection="gov.va.med.esr.common.model.lookup.PensionReasonCode" property="code" labelProperty="name"/>
                    </html-el:select>
                </td>
              </tr>
              </table>
             </div>
           </td>
       </tr>
     </table>
                
     <table width="100%" border="0" cellspacing="0" cellpadding="0" class="moduleShellTableBody" role="presentation"> 
        <tr>
          <td width="100%" colspan="2">
            <div id="ptmBlock" class="expandCollapseBody">
              <table width="100%" cellSpacing=0 cellPadding=0 border=0 role="presentation">     
              <!--  pension award termination date -->
              <tr>
                <td width="45%" class="moduleLabel"><fw:label property="pensionAwardTerminationDate" forId="idPensionAwardTerminationDate"><bean-el:message key="label.pensionAwardTerminationDate"/>:</fw:label></td>
                <td width="55%" class="moduleValue">
                  <c:set var="pensionAwardTerminationDateText"><bean-el:message key="label.pensionAwardTerminationDate"/> <bean-el:message key="label.mmddyyyy"/></c:set>
                  <html-el:text title="${pensionAwardTerminationDateText}" disabled="${nonVeteran}" styleClass="moduleEdit" styleId="idPensionAwardTerminationDate" property="pensionAwardTerminationDate" onchange="processPensionTerminationDate()" onkeyup="processPensionTerminationDate()" onkeydown="processPensionTerminationDate()"/>&nbsp;<bean-el:message key="label.mmddyyyy"/>
                  <html-el:hidden name="eligibilityForm" property="oldPensionAwardTerminationDate"/>
                </td>
              </tr>
              
              <!--  pension award termination reason codes 1 -->
               <tr>
                <td width="45%" class="moduleLabel"><fw:label property="pensionAwardTerminationReasonCode1" forId="idPensionAwardTerminationReasonCode1"><bean-el:message key="label.pensionAwardTerminationReasonCode1"/>:</fw:label></td>
                <td width="55%" class="moduleValue">
                    <c:set var="pensionAwardTerminationReasonCode1Text"><bean-el:message key="label.pensionAwardTerminationReasonCode1"/></c:set>
                  	<html-el:select title="${pensionAwardTerminationReasonCode1Text}" disabled="${nonVeteran}" styleId="idPensionAwardTerminationReasonCode1" styleClass="moduleEdit" property="pensionAwardTerminationReasonCode1">
                    	<html-el:option value=""><bean-el:message key="label.select" /></html-el:option>
                    	<esrcore:options collection="gov.va.med.esr.common.model.lookup.PensionReasonCode" property="code" labelProperty="name"/>
                  </html-el:select>
                </td>
              </tr>
              
               <!--  pension award termination reason codes 2 -->
               <tr>
                <td width="45%" class="moduleLabel"><fw:label property="pensionAwardTerminationReasonCode2" forId="idPensionAwardTerminationReasonCode2"><bean-el:message key="label.pensionAwardTerminationReasonCode2"/>:</fw:label></td>
                <td width="55%" class="moduleValue">
                    <c:set var="pensionAwardTerminationReasonCode2Text"><bean-el:message key="label.pensionAwardTerminationReasonCode2"/></c:set>
                  	<html-el:select title="${pensionAwardTerminationReasonCode2Text}" disabled="${nonVeteran}" styleId="idPensionAwardTerminationReasonCode2" styleClass="moduleEdit" property="pensionAwardTerminationReasonCode2">
                    	<html-el:option value=""><bean-el:message key="label.select" /></html-el:option>
                    	<esrcore:options collection="gov.va.med.esr.common.model.lookup.PensionReasonCode" property="code" labelProperty="name"/>
                  </html-el:select>
                </td>
              </tr>
              
                <!--  pension award termination reason codes 3 -->
               <tr>
                <td width="45%" class="moduleLabel"><fw:label property="pensionAwardTerminationReasonCode3" forId="idPensionAwardTerminationReasonCode3"><bean-el:message key="label.pensionAwardTerminationReasonCode3"/>:</fw:label></td>
                <td width="55%" class="moduleValue">
                    <c:set var="pensionAwardTerminationReasonCode3Text"><bean-el:message key="label.pensionAwardTerminationReasonCode3"/></c:set>
                  	<html-el:select title="${pensionAwardTerminationReasonCode3Text}" disabled="${nonVeteran}" styleId="idPensionAwardTerminationReasonCode3" styleClass="moduleEdit" property="pensionAwardTerminationReasonCode3">
                    	<html-el:option value=""><bean-el:message key="label.select" /></html-el:option>
                    	<esrcore:options collection="gov.va.med.esr.common.model.lookup.PensionReasonCode" property="code" labelProperty="name"/>
                  </html-el:select>
                </td>
              </tr>
              
               <!--  pension award termination reason codes 4 -->
               <tr>
                <td width="45%" class="moduleLabel"><fw:label property="pensionAwardTerminationReasonCode4" forId="idPensionAwardTerminationReasonCode4"><bean-el:message key="label.pensionAwardTerminationReasonCode4"/>:</fw:label></td>
                <td width="55%" class="moduleValue">
                    <c:set var="pensionAwardTerminationReasonCode4Text"><bean-el:message key="label.pensionAwardTerminationReasonCode4"/></c:set>
                  	<html-el:select title="${pensionAwardTerminationReasonCode4Text}" disabled="${nonVeteran}" styleId="idPensionAwardTerminationReasonCode4" styleClass="moduleEdit" property="pensionAwardTerminationReasonCode4">
                    	<html-el:option value=""><bean-el:message key="label.select" /></html-el:option>
                    	<esrcore:options collection="gov.va.med.esr.common.model.lookup.PensionReasonCode" property="code" labelProperty="name"/>
                  </html-el:select>
                </td>
              </tr>
			</table>
          </div>
        </td>
       </tr>
</table>
