<%@page import="com.ardeo.entities.autoforms.FormView"%>
<%@ include file="/includes.jsp" %>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>

<script type="text/javascript">
	function preSubmit() {
		//ensure multi-selections are selected
		var selectTags = document.getElementsByTagName("select");
		for ( var i = 0; i < selectTags.length; i++) {
			if (selectTags[i].multiple) {
				var options = selectTags[i].options;
				for ( var y = 0; y < options.length; y++) {
					options[y].selected = true;
				}
			}
		}
		return true;
	}

	function addEvent(dateFieldId, title) {
		var dateField = document.getElementById(dateFieldId);
		if (dateField) {
			if (!title) title = "";
			var date = dateField.value;
			window.open("../calendar/editEventPopup.jsp?forward=closeWindow&id=new&type=event&date="+ date + "&title=" + title,'editEvent','scrollbars=1,toolbar=0,status=1,menubar=1,resizable=1,location=0,directories=0,width=700,height=500,left=0,top=0');
		}
	}
	function setStyleOnLoad() {
		var table = document.getElementById('dynamicTableId');
		if (table != null) {
			var rows = table.getElementsByTagName('tr');
			var i, j, cells, field;
			for (i = 2, j = rows.length; i < j; ++i) {
				cells = rows[i].getElementsByTagName('td');
				if (!cells.length) {
					continue;
				}
				field = $.trim(cells[0].innerHTML);
				if (document.getElementById(field)) {
					var styleValue = document.getElementById(field).value;
					if (styleValue != '000000000000') {
						if (styleValue.charAt(0) == '1') {
							cells[0].style.fontWeight = 700;
						} else {
							cells[0].style.fontWeight = 400;
						}
						if (styleValue.charAt(1) == '1') {
							cells[0].style.fontStyle = "italic";
						} else {
							cells[0].style.fontStyle = "";
						}
						if (styleValue.charAt(2) == '1') {
							cells[0].style.textDecoration = "underline";
						} else {
							cells[0].style.textDecoration = "";
						}
						cells[0].style.fontSize = styleValue.substring(3, 5)
								+ 'pt';
						cells[0].style.color = styleValue.substring(5, 12);
					}
				}
			}
		}
	}
	// Set form editor styles when page has loaded
	$(document).ready(function() {
		setStyleOnLoad();
		if(document.getElementById("noteModifiedByOtherUser").value == 'yes'){
			   openNoteModificationPopup();
		   }
	});

function send() {
	if(confirm('Please confirm that you want to send this message to the referrer')){
		if("true" == document.getElementById('roleSupportingStaff').value){
			chooseSeniors();
		}else{
			document.getElementById("actionRequired").value = "save";
			preSubmit();
			document.getElementById("consultationNote").submit();
		}
		
	}
}
</script>
<tiles:insertTemplate template ="/nationalMDT/tiles/nationalMDTDetailsTopBar.jsp" />
<c:choose>
<c:when test="${redirectPageTo ne null and fn:length(redirectPageTo)  gt 0}">
<input type="hidden" id="redirectpath" value="${redirectPageTo}"/>
<Script type="text/javascript">
	var filterFormId = getURLParameter('filterFormId');
	document.location=document.getElementById('redirectpath').value+"?filterFormId="+filterFormId;
	
	function getURLParameter(name) {
		var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
		return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
	}
</Script>
</c:when>
<c:otherwise>
<smvc:form modelAttribute="consultationNoteForm" id="consultationNote" enctype="multipart/form-data" action="../nationalMDT/consultationNote.form?${_csrf.parameterName}=${_csrf.token}" >
<input type="hidden" id="csrfparameterName" value="<c:out value="${_csrf.parameterName}"/>" />
<input type="hidden" id="csrfparametervalue" value="<c:out value="${_csrf.token}"/>" />
<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
 	<input id="overrideModifications" name="overrideModifications" value="no" type="hidden"/>
	<c:choose>
		<c:when test="${noteModifiedByOtherUser eq true }">
			<input id="noteModifiedByOtherUser" value="yes"  type="hidden" />
			<%@ include file="../../emdt/tiles/noteModifiedDetailPopup.jsp"%>
		</c:when>
		<c:otherwise>
			<input id="noteModifiedByOtherUser" value="no"  type="hidden" />
		</c:otherwise>
	</c:choose>
	<c:set var="currentFormView" value="${consultationNoteForm.view}"></c:set>
	<%
		FormView currentFormView = (FormView)pageContext.getAttribute("currentFormView");
	    session.setAttribute("currentFormView",currentFormView) ;
	 %>
	<smvc:hidden path="letterPath" />
	<smvc:hidden path="actionRequired" id="actionRequired"  />
	<input type="hidden" name="actionRequired" id="actionRequired" value="" />
	<input type="hidden" name="actionButton" id="actionButton" value="" />
	<input type="hidden" name="gotoPageNum" id="gotoPageNum" />
	<input type="hidden" id="childListId2Filter" name="childListId2Filter" value="" />
	<input type="hidden" id="parentListName" name="parentListName" value="" />
	<input type="hidden" value="false" id="unsaveButtonId" />
	<input type="hidden" value="false" id="commentAreaClickedId" />
	<input type="hidden" name="nationalMDT" value="true"/>
	<input type="hidden" name="clinicianList" id="clinicianList" value=""/>
	
	&nbsp;
	<div class="container">
		<tiles:insertTemplate template ="nationalMDTFormMenu.jsp" />
		<div class="containerSubPage">
			<div class="rowDivSubPage">
				<div class="fieldSetBoxSub fieldSetBoxSubWidth">
					<tiles:insertTemplate template ="forms/formbuttons.jsp" />
					<smvc:errors cssClass="error" path="*" />
					<c:if test="${requestScope.errorMsg ne null}">
						<span class="error"><c:out value="${requestScope.errorMsg}"/></span>
					</c:if>
					<tiles:insertTemplate template="${consultationNoteForm.view.renderer}" />
				</div>
				<c:if test="${consultationNoteForm.view.form.showNotes}">
					<tiles:insertTemplate template ="../../emdt/tiles/commentsPage.jsp"/>
				</c:if>
				
				<div style="margin-left: auto; margin-right: auto;">
				<tiles:insertTemplate template ="../../emdt/tiles/consultationNoteButtons.jsp"/>
				</div>
			</div>
		</div>
	</div>
</smvc:form>
</c:otherwise>
</c:choose>