<script type="text/javascript" language="JavaScript" src="../scripts/ESR-Script.js"></script>
<%@ taglib uri="http://struts.apache.org/tags-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:if test="${deliveryPreferencesForm.deliveryPreference == '1'}">
    <c:set var="disableEmail" value="true"/>
</c:if>

<script type="text/javascript">

function enableOrDisableEmail()
{
  if (document.getElementById("dpSelect").selectedIndex == 0)
  { 
     disableEmail = false;
     document.getElementById("emailTxt").disabled = false;         
     document.getElementById("private").disabled = false;
     document.getElementById("business").disabled = false;
  } else
  {
  	 disableEmail = true;
     document.getElementById("emailTxt").disabled = true;         
     document.getElementById("private").disabled = true;
     document.getElementById("business").disabled = true;
  }
}
</script>


<table width="100%" border="0" cellpadding="0" cellspacing="0"
	class="moduleShell" role="presentation">
	<html-el:form action="/deliveryPreferences" method="post">
  	    <%@ include file="/admin/csrfgentoken.jsp" %>
		<c:set var="viewHistoricalDeliveryPreferences" scope="page">
			<bean-el:message key="text.viewHistoricalDeliveryPreferences" />
		</c:set>
		<tr>
			<td>
			<table width="100%" border="0" cellpadding="0" cellspacing="0"
				class="moduleShellTable" role="presentation">
				<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 style="padding-left: 7px"><bean-el:message
								key="label.comms.deliveryPreferencesHeader" /></td>
							<td width="100%"><img alt="" src="../images/spacer.gif"></td>
							<td nowrap class="moduleBlueLink"
								style="padding: 1px 8px 1px 8px"><fw:link
								action="/deliveryPreferencesHistory?methodName=DISPLAY&amp;history=viewHistoricalDeliveryPreferences"
								paramId="entityId" paramName="deliveryPreferencesForm"
								paramProperty="selectedPersonId">
								<bean-el:message key="text.viewHistoricalDeliveryPreferences" />
							</fw:link></td>
						</tr>
					</table>
					</td>
				</tr>
				<tr>
					<td>
					<table width="100%" border="0" cellspacing="0" cellpadding="0"
						class="moduleShellTableBody" role="presentation">
						<tr>
							<td class="moduleLabel"><fw:label property="deliveryPreference" forId="dpSelect">
								<bean-el:message key="label.comms.deliveryPreferences" />:</fw:label></td>
							<td class="moduleValue">
							<c:set var="deliveryPreferencesText">
								<bean-el:message key="label.comms.deliveryPreferences" />
							</c:set> 
							<html-el:select styleId="dpSelect" title="${deliveryPreferencesText}"
								styleClass="moduleEdit" property="deliveryPreference" onchange="enableOrDisableEmail()">
								<esrcore:options
									collection="gov.va.med.esr.common.model.lookup.DeliveryPreferenceType"
									property="code" labelProperty="description"/>
							</html-el:select>
							</td>
						</tr>
						<tr>
							<c:set var="emailAddressText">
								<bean-el:message key="label.comms.emailAddress" />
							</c:set>
							<td class="moduleLabel"><fw:label required="${requiredAddAPersonFlag}" property="emailAddress" forId="emailTxt">
								<bean-el:message key="label.comms.emailAddress" />:</fw:label></td>
							<td class="moduleValue">
							<html-el:text
								styleId="emailTxt"
								title="${emailAddressText}" styleClass="moduleEdit" 
								property="emailAddress" size="42" maxlength="128" disabled="${disableEmail}" />&nbsp;
							</td>
						</tr>
						<tr>
						    <c:choose>
								<c:when test="${requiredAddAPersonFlag}">
									<td class="moduleLabel"><bean-el:message key="label.required.prefix" />&nbsp;
										<bean-el:message key="label.comms.emailType" />:</td>
									<td class="moduleValue">
										<c:set var="emailPrivateText">
											<bean-el:message key="label.comms.emailType" />&nbsp;(<bean-el:message key="label.comms.private" />)</c:set> 
										<c:set var="emailBusinessText">
											<bean-el:message key="label.comms.emailType" />&nbsp;(<bean-el:message key="label.comms.business" />)</c:set> 
										<html-el:radio styleId="private" title="${emailPrivateText}" property="emailType" value="1" disabled="${disableEmail}" />
										<fw:label property="emailType" forId="private"><bean-el:message key="label.comms.private" /></fw:label> 
										<html-el:radio styleId="business" title="${emailBusinessText}" property="emailType" value="2" disabled="${disableEmail}" />
										<fw:label property="emailType" forId="business"><bean-el:message key="label.comms.business" /></fw:label>  
									</td>
								</c:when>
								<c:otherwise>
									<td class="moduleLabel">
										<bean-el:message key="label.comms.emailType" />:</td>
									<td class="moduleValue">
										<c:set var="emailPrivateText">
											<bean-el:message key="label.comms.emailType" />&nbsp;(<bean-el:message key="label.comms.private" />)</c:set> 
										<c:set var="emailBusinessText">
											<bean-el:message key="label.comms.emailType" />&nbsp;(<bean-el:message key="label.comms.business" />)</c:set> 
										<html-el:radio styleId="private" title="${emailPrivateText}" property="emailType" value="1" disabled="${disableEmail}" />
										<fw:label property="emailType" forId="private"><bean-el:message key="label.comms.private" /></fw:label> 
										<html-el:radio styleId="business" title="${emailBusinessText}" property="emailType" value="2" disabled="${disableEmail}" />
										<fw:label property="emailType" forId="business"><bean-el:message key="label.comms.business" /></fw:label> 
									</td>
								</c:otherwise>
							</c:choose>
						</tr>
						<tr>
							<td colspan=2 height="50">
							<table width="100%" border="0" cellpadding="0" cellspacing="0" role="presentation">
								<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">
										<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>
					</td>
				</tr>
			</table>
			</td>
		</tr>
	</html-el:form>
</table>
