<%@ include file="/includes.jsp"%>
<% pageContext.setAttribute("newLineChar", "\n"); %>
<!-- emdt/tiles/forms/groupFormsMenu.jsp -->
<c:choose>
	<c:when test="${filterForm.name ne null }"><c:set var="nameOfForm" value="${filterForm.name}" /></c:when>
	<c:otherwise><c:if test="${consultationNoteForm ne null}"><c:set var="nameOfForm" value="${consultationNoteForm.view.formName}" /></c:if></c:otherwise>
</c:choose>
<c:if
	test="${referralsDefinition.formSummaryMapOrder!=null && fn:length(referralsDefinition.formSummaryMapOrder)>0}">
	<c:set var="formSummaryMapOrderLength">${fn:length(referralsDefinition.formSummaryMapOrder)}</c:set>
	<c:set var="index"/>
	<c:set var="addedGroups"/>
	<%
		int rowLenth1 = Integer.parseInt(pageContext.getAttribute("formSummaryMapOrderLength").toString());
			for (int index = 1; index <= rowLenth1; index++) {
				pageContext.setAttribute("index", index);
	%>
	<c:set var="groupAdded"/>
	<c:forEach var="formSummaryMapOrder" items="${referralsDefinition.formSummaryMapOrder}">
		<c:if test="${formSummaryMapOrder.location==index  and formSummaryMapOrder.formExists}">
			<c:choose>
				<c:when test="${formSummaryMapOrder.groupName eq 'Top Level'}">
					<c:choose>
						<c:when test="${formSummaryMapOrder.type=='Form'}">
						<c:choose>
								<c:when	test="${formSummaryMapOrder.formOrSummaryName eq nameOfForm  and summaryName eq null and (addToMeeting eq null or addToMeeting ne true)}">
									<c:set var="menuButtonHolderDivClass" value="menuButtonSquare selected"/>
								</c:when>
								<c:otherwise>
									<c:set var="menuButtonHolderDivClass" value="menuButtonSquare blue"/>
								</c:otherwise>
							</c:choose>
							<div class="<c:out value="${menuButtonHolderDivClass}"/>">
								<a href="javascript:getConsNote(<c:out value="${formSummaryMapOrder.filterFormId}"/>)" style="cursor: pointer;">
								<pre><c:out value="${formSummaryMapOrder.name}"/></pre></a>
							</div>
						
						</c:when>
						<c:otherwise>
						<c:choose>
								<c:when	test="${formSummaryMapOrder.formOrSummaryName eq nameOfForm  and summaryName eq null and (addToMeeting eq null or addToMeeting ne true)}">
									<c:set var="menuButtonHolderDivClass" value="menuButtonSquare selected"/>
								</c:when>
								<c:otherwise>
									<c:set var="menuButtonHolderDivClass" value="menuButtonSquare blue"/>
								</c:otherwise>
							</c:choose>
							<div class="<c:out value="${menuButtonHolderDivClass}"/>">
								<a href="patientSummaryActions.form?method=view&summaryId=<c:out value="${formSummaryMapOrder.summaryId}"/>&page=referrals}">
									<pre><c:out value="${formSummaryMapOrder.name}"/></pre></a>
							</div>
						</c:otherwise>
					</c:choose>
				</c:when>
				<c:otherwise>
					<c:set var="currentGrpName">${formSummaryMapOrder.groupName}></c:set>
					<%
						String currentGroup = (String) pageContext
														.getAttribute("currentGrpName");
												String addedGroup = (String) pageContext
														.getAttribute("addedGroups");

												if (addedGroup.contains(currentGroup)) {
													pageContext.setAttribute("groupAdded",
															"added");
												} else {

													pageContext.setAttribute("groupAdded",
															"notAdded");
													addedGroup += currentGroup;
													pageContext.setAttribute("addedGroups",
															addedGroup);
												}
					%>
					<c:if test="${groupAdded eq 'notAdded'}">
							<c:choose>
								<c:when
									test="${formSummaryMapOrder.groupName eq groupBy and (addToMeeting eq null or addToMeeting ne true)}">
									<c:set var="menuButtonHolderDivClass" value="menuButtonSquare selected group"/>
									<%-- We are now displaying a Group of buttons in the pathway.  Set a flag in the session so we hide the top level button row to save space --%>
								</c:when>
								<c:otherwise>
									<c:set var="menuButtonHolderDivClass" value="menuButtonSquare blue group"/>
								</c:otherwise>
							</c:choose>
							<div class="<c:out value="${menuButtonHolderDivClass}"/>">
								<a href="javascript:getConsNote(<c:out value="${formSummaryMapOrder.filterFormId}"/>)" style="cursor: pointer;"><pre><c:out value="${formSummaryMapOrder.groupName}"/></pre></a>
							</div> 
					</c:if>
				</c:otherwise>
			</c:choose>
		</c:if>
	</c:forEach>
	<%
		}
	%>
</c:if>

