<%@ include file="/includes.jsp"%>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>


<style>
.message {
	font-weight: bold;
	color: blue;
	xmargin-left:250px;
}
</style>
<script type="text/javascript">

			var total = "",prefTime;
			var count = 0;

			function checkTime(thetime){
				var a,b,c,f,err=0;
				a=thetime.value;
				if (a.length != 5) err=1;
				b = a.substring(0, 2);
				c = a.substring(2, 3); 
				f = a.substring(3, 5); 
				if (/\D/g.test(b)) err=1; //not a number
				if (/\D/g.test(f)) err=1; 
				if (b<0 || b>23) err=1;
				if (f<0 || f>59) err=1;
				if (c != ':') err=1;
				if (err==1) {
					alert("That is not a valid Time.\nPlease re-enter in 24hr format HH:MM");
					thetime.value = ""; 
					thetime.focus();
				}
			}
			function checkMinutes(minute){
				var min = minute.value;
				var err = 0;
				if (/\D/g.test(min)) err=1; //not a number
				if (min<0 || min>23) err=1;
				if (err==1){
					alert ("This is not a valid Duration.Please re-enter in terms of Hours(0-23).");
					minute.value = ""; 
					minute.focus();
				}
			}
			
			function maskCheckBox(maskCheckBox){
				if(maskCheckBox.checked == true){
					for(i = 0; i < document.forms[0].elements.length; i++) {
						elm = document.forms[0].elements[i];
						if(elm.type == "checkbox" && elm.value != 8){
								elm.checked = false;
								elm.disabled = true;
						}
					}
				}else{
					for(i = 0; i < document.forms[0].elements.length; i++) {
						elm = document.forms[0].elements[i];
						if(elm.type == "checkbox"){
								elm.disabled = false;
						}
					}
				}
				count = 0;
			}

			function validate(form) { 
				total = "";
				prefTime = "";
				for(var i=0; i < document.setRefFrequencyForm.prefDay.length; i++){
					if(document.setRefFrequencyForm.prefDay[i].checked == true){
						total=document.setRefFrequencyForm.prefDay[i].value;
						count++;
					}
				}
				prefTime = document.setRefFrequencyForm.time.value;
				if(prefTime == "" && total == ""){
					alert("Please Select Day and Enter Time.");
					return false;
				}else if(total == ""){
					alert("Please Select Day.");
					return false;
				}else if(prefTime == ""){
					alert("Please Enter Time.");
					return false;
				}else if(count >= 7){
					alert("Please Select EveryDay Option");
					return false;
				}else
					return true; 				
			}

			function resetPage(){
				location.href= "../referrals/referralsFrequency.jsp";
			}
			
			function disableOthersIfEveryDay(){
			var element = document.getElementById("prefDay");
			if(element.checked){
			for(i = 0; i < document.forms[0].elements.length; i++) {
						elm = document.forms[0].elements[i];
						if(elm.type == "checkbox" && elm.value != 8){
								elm.checked = false;
								elm.disabled = true;
						}
			}
						
			
			}
			}
		</script>


<%--
<body onload="disableOthersIfEveryDay();">

 --%>

&nbsp;
<br />
	 
<smvc:form name="setRefFrequencyForm" modelAttribute="frequencyReportDTO"
	id="setRefFrequencyForm" method="post" action="../referrals/referralsFrequency.form"
	onsubmit="return validate(this);submitTheForm();">
	<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />

		<div>
			<c:choose>
				<c:when test="${requestScope.successMsg ne null || requestScope.errorMsg ne null}">
					<c:if test="${requestScope.successMsg ne null}">
						<div class="message">
							<img src="../images/16x16/information.png" alt="i" /> <c:out value="${requestScope.successMsg}"/>
						</div>
					</c:if>
					<c:if test="${(null ne requestScope.errorMsg) and ('null' ne requestScope.errorMsg) and (fn:length(requestScope.errorMsg) ne 0)}">
						<div class="error">
							<img src="../images/16x16/error.png" alt="e" /><c:out value="${requestScope.errorMsg}"/>
						</div>
						<br />
					</c:if>
				</c:when>
			</c:choose>
		</div>
		
		&nbsp;
		<br />
		<br />

	<div style="margin-left:auto;margin-right:auto;">
		<table class="dialogBox" width="80%">
			<tbody>
				<tr>
					<td class="dialogTitle"><b>Frequency Of Reminder Email</b></td>
				</tr>
				<tr>
					<td>
						<table width="100%" border="0" cellpadding="10" cellspacing="0">

							<tbody>
								<tr>
									<td>
										<table border="0" cellpadding="0" cellspacing="0" width="75%">
											<tbody>
												<tr>
													<td class="label">Frequency&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
													<td class="label">Daily&nbsp;&nbsp;</td>
													<td class="label">Sunday&nbsp;&nbsp;&nbsp;&nbsp;</td>
													<td class="label">Monday&nbsp;&nbsp;&nbsp;&nbsp;</td>
													<td class="label">Tuesday&nbsp;&nbsp;&nbsp;&nbsp;</td>
													<td class="label">Wednesday&nbsp;&nbsp;</td>
													<td class="label">Thursday&nbsp;&nbsp;&nbsp;</td>
													<td class="label">Friday&nbsp;&nbsp;&nbsp;&nbsp;</td>
													<td class="label">Saturday&nbsp;&nbsp;&nbsp;&nbsp;</td>
													<td class="label">Time <br />(HH:MM)&nbsp;&nbsp;&nbsp;&nbsp;
													</td>
													<td class="label">Duration<br /> (Hrs)&nbsp;&nbsp;&nbsp;&nbsp;
													</td>
												</tr>
												<tr>
													<td class="label">Select</td>
													<c:choose>
														<c:when test="${(frequencyReportDTO ne null) and (frequencyReportDTO.preferred_EveryDay eq true)}">
															<td class="input" align="center"><input type="checkbox" name="prefDay8" value="8" id="prefDay" checked="checked"> &nbsp;&nbsp;</td>
														</c:when>
														<c:otherwise>
															<td class="input" align="center"><input type="checkbox" name="prefDay8" value="8" id="prefDay" onclick="maskCheckBox(this);" <c:out value="${param.prefDay8=='8' ? 'checked' : ''}"/>>
																&nbsp;&nbsp;</td>

														</c:otherwise>
													</c:choose>

													<c:choose>
														<c:when test="${(frequencyReportDTO ne null) and (frequencyReportDTO.preferred_SunDay eq true)}">
															<td class="input" align="center"><input type="checkbox" name="prefDay1" value="1" id="prefDay" checked="checked"></td>
														</c:when>
														<c:otherwise>
															<td class="input" align="center"><input type="checkbox" name="prefDay1" value="1" id="prefDay" <c:out value="${param.prefDay1=='1' ? 'checked' : ''}"/>></td>
														</c:otherwise>
													</c:choose>
													<c:choose>
														<c:when test="${(frequencyReportDTO ne null) and (frequencyReportDTO.preferred_MonDay eq true)}">
															<td class="input" align="center"><input type="checkbox" name="prefDay2" value="2" id="prefDay" checked="checked"></td>
														</c:when>
														<c:otherwise>
															<td class="input" align="center"><input type="checkbox" name="prefDay2" value="2" id="prefDay" <c:out value="${param.prefDay2=='2' ? 'checked' : ''}"/>></td>
														</c:otherwise>
													</c:choose>
													<c:choose>
														<c:when test="${(frequencyReportDTO ne null) and (frequencyReportDTO.preferred_TuesDay eq true)}">
															<td class="input" align="center"><input type="checkbox" name="prefDay3" value="3" id="prefDay" checked="checked"></td>
														</c:when>
														<c:otherwise>
															<td class="input" align="center"><input type="checkbox" name="prefDay3" value="3" id="prefDay" <c:out value="${param.prefDay3=='3' ? 'checked' : ''}"/>></td>
														</c:otherwise>
													</c:choose>
													<c:choose>
														<c:when test="${(frequencyReportDTO ne null) and (frequencyReportDTO.preferred_WendsDay eq true)}">
															<td class="input" align="center"><input type="checkbox" name="prefDay4" value="4" id="prefDay" checked="checked"> &nbsp;</td>
														</c:when>
														<c:otherwise>
															<td class="input" align="center"><input type="checkbox" name="prefDay4" value="4" id="prefDay" <c:out value="${param.prefDay4=='4' ? 'checked' : ''}"/>> &nbsp;</td>
														</c:otherwise>
													</c:choose>
													<c:choose>
														<c:when test="${(frequencyReportDTO ne null) and (frequencyReportDTO.preferred_ThursDay eq true)}">
															<td class="input" align="center"><input type="checkbox" name="prefDay5" value="5" id="prefDay" checked="checked"> &nbsp;&nbsp;&nbsp;</td>
														</c:when>
														<c:otherwise>
															<td class="input" align="center"><input type="checkbox" name="prefDay5" value="5" id="prefDay" <c:out value="${param.prefDay5=='5' ? 'checked' : ''}"/>> &nbsp;&nbsp;&nbsp;</td>
														</c:otherwise>
													</c:choose>
													<c:choose>
														<c:when test="${(frequencyReportDTO ne null)and (frequencyReportDTO.preferred_FriDay eq true)}">
															<td class="input" align="center"><input type="checkbox" name="prefDay6" value="6" id="prefDay" checked="checked"> &nbsp;&nbsp;</td>
														</c:when>
														<c:otherwise>
															<td class="input" align="center"><input type="checkbox" name="prefDay6" value="6" id="prefDay" <c:out value="${param.prefDay6=='6' ? 'checked' : ''}"/>> &nbsp;&nbsp;</td>
														</c:otherwise>
													</c:choose>
													<c:choose>
														<c:when test="${(frequencyReportDTO ne null)and (frequencyReportDTO.preferred_SaturDay eq true)}">
															<td class="input" align="center"><input type="checkbox" name="prefDay7" value="7" id="prefDay" checked="checked"></td>
														</c:when>
														<c:otherwise>
															<td class="input" align="center"><input type="checkbox" name="prefDay7" value="7" id="prefDay" <c:out value="${param.prefDay7=='7' ? 'checked' : ''}"/>></td>
														</c:otherwise>
													</c:choose>
													<c:choose>
														<c:when test="${(frequencyReportDTO ne null) and (frequencyReportDTO.preferredHour ne null) and (frequencyReportDTO.preferredMins ne null)}">
															<td class="input" style="border: 0px solid;"><input type="text" name="time" id="time" value="<c:out value="${frequencyReportDTO.preferredHour}"/>:<c:out value="${frequencyReportDTO.preferredMins}"/>" size="5"
																style="width: 40px" onchange="checkTime(this);"></td>
														</c:when>
														<c:otherwise>
															<td class="input" style="border: 0px solid;"><input type="text" name="time" id="time" value="<c:out value="${param.time}"/>" size="4" style="width: 40px" onchange="checkTime(this);"></td>
														</c:otherwise>
													</c:choose>

													<c:choose>
														<c:when test="${(frequencyReportDTO ne null) and (frequencyReportDTO.duration ne null)}">
															<td class="input" style="border: 0px solid;"><input type="text" name="duration" id="duration" value="<c:out value="${frequencyReportDTO.duration}"/>" size="4" style="width: 40px"
																onchange="checkMinutes(this);"></td>
														</c:when>
														<c:otherwise>
															<td class="input" style="border: 0px solid;"><input type="text" name="duration" id="duration" value="<c:out value="${param.duration}"/>" size="4" style="width: 40px" onchange="checkMinutes(this);"></td>
														</c:otherwise>
													</c:choose>

												</tr>
											</tbody>
										</table> <br /> <br />
										<table border="0" cellpadding="0" cellspacing="0" width="100%">
											<tbody>
												<tr>
													<td align="right"><input type="RESET" name="reset" value="Reset" id="reset" onclick="resetPage();"> <input type="SUBMIT" name="save" value="Save" id="save"></td>
												</tr>
											</tbody>
										</table>
									</td>
								</tr>
							</tbody>
						</table>
					</td>
				</tr>
				<tr>
					<td colspan="2" class="dialogSpacer"></td>
				</tr>
				<tr>
					<td colspan="2" class="dialogFooter"></td>
				</tr>
			</tbody>
		</table>
	</div>
	
	</smvc:form>

