<%@ include file="/includes.jsp"%>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>

<script language="javascript">
function assignClinician(clinicianId,clinicianName,clinicianMnemonic){
document.getElementById('selectedClinician').value=clinicianId;
document.getElementById('selectedClinicianMnemonic').value=clinicianMnemonic;
document.getElementById('selectedClinicianName').value=clinicianName;
}
function dispatchMethods(methodName){
	dispatch(methodName);
	document.getElementById('altConsultantform').submit();
}


</script>

<smvc:form modelAttribute="patientInfo" method="post" id="altConsultantform" onsubmit = "return submitTheForm();">
<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
<smvc:hidden path="actionMethod" id="dispatchMethod"/>
<smvc:hidden path="selectedClinician" id="selectedClinician"/>
<smvc:hidden path="selectedClinicianMnemonic" id="selectedClinicianMnemonic"/>
<smvc:hidden path="selectedClinicianName" id="selectedClinicianName"/>
<smvc:hidden path="pagination.currentPage" id="pagination.currentPage"/>

     <c:set var="myErrorFlag" value=""/>
    <table>
        <spring:hasBindErrors name="patientInfo">
	        <div class="error"><smvc:errors/>
	        </div>
        <c:set var="myErrorFlag" value="0"></c:set>
        </spring:hasBindErrors>
        <c:choose>
            <c:when test="${errorMsg != null}">
                <tr>
                    <td>
                    <div class="error"><img src="../images/16x16/error.png"
                        alt="e" /><c:out value="${errorMsg}"/></div>
                    </td>
                </tr>
            </c:when>
            <c:otherwise>
                <c:if test="${myErrorFlag != 1}">
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                </c:if>
            </c:otherwise>
        </c:choose>
    </table>
    <table cellspacing="0" width="850" border="0" class="table" align="center">
        <tr>
            <td width="100%">
            <table border="0" width="100%" cellspacing="0" class="table">
                <tr>
                    <td width="50%" class="nrlTableTitleBar">Add To Other Doctor</td>
                    <td width="50%" class="nrlTableTitleBar"></td>
                </tr>
                <tr>
                <td colspan="2">
                    <!-- Patient Info table -->
                    <jsp:include page="../common/nrlPatientInfo.jsp"></jsp:include>
                    <!-- End Patient Info table --></td>
                </tr>
                <tr>
                    <td colspan="2">
                    <table width="100%" class="table" border="0" cellspacing="0" style="border-top: 2px solid;">
                        <tr style="border-top: 2px solid;" bgcolor="#E9DDE7">
                        <td width="4%">&nbsp;</td>
                        <td colspan="2" width="96%" style="font-weight: normal; font-size: 12pt;" class="nrlPDBTableCell" >Next Step</td>
                        </tr>
                        <tr style="border-top: 2px solid #a8abaf;">
                        <td width="4%">&nbsp;</td>
                        <td colspan="2" class="error">&nbsp;<smvc:errors path="notes"/></td>
                        </tr>
                        <tr>
                            <td width="4%">&nbsp;</td>
                            <td width="16%" class="nrlTabBg">Your Notes</td>
                            <td width="80%">&nbsp;</td>
                        </tr>
                        <tr>
                          <td width="4%">&nbsp;</td>
                            <td width="96%" colspan="2" align="left"><smvc:textarea cssClass="txAreaBorder" rows="4" cols="120"
                              path="notes" /></td>
                        </tr>
                        <tr >
                        <td colspan="3">&nbsp;</td>
                        </tr>
                    </table>
                    </td>
                </tr>
                <tr style="border-top: 2px solid #a8abaf; border-bottom: 2px solid #a8abaf;" bgcolor="#E9DDE7">
                    <td colspan="2">&nbsp;</td>
                </tr>
                </table>
            </td>
            </tr>
            <tr>
            <td>
			<table border="0" width="100%">
				<tr style="border-top: 2px solid #a8abaf;" bgcolor="#B9B9FF">
					<td width="100%" colspan="5">&nbsp;</td>
				</tr>
				<tr>
					<td width="100%" colspan="5" >&nbsp;</td>
				</tr>
				<tr>
					<td width="10%" style="font-weight: bold;" align="right">Filter by Department&nbsp;</td>
					<td width="45%">

			<smvc:select path="selectedDeptSet" multiple="false">
			     <smvc:option value="00000" />
				<c:forEach varStatus="loop" items="${patientInfo.deptList}" var="mDMBean">
						<c:forEach items="${patientInfo.selectedDeptSet}" var="selectedMDM">
										<c:if test="${selectedMDM.code == mDMBean.code}">
											<c:set var="selected" value="true" />
										</c:if>
						</c:forEach>
					<smvc:option value="${mDMBean.code}" <c:if test="${selected}">selected='selected'</c:if> > <c:out value="${mDMBean.value}"/> </smvc:option>
				<c:remove var="selected" />
				</c:forEach>
			</smvc:select>
						
				</td>
					<td width="10%" nowrap="nowrap" style="font-weight: bold;">Find a Clinician&nbsp;</td>
					<td width="20%" align="left">
					<smvc:input maxlength="15" size="20" path="findClinicianStr" />
                    </td>
					<td width="15%"><input type="submit" onclick="dispatch('searchClinician');" value="Search" /></td>
				</tr>
				<tr>
				<td width="10%">&nbsp;</td>
				<td colspan="4" width="90%" class="error">&nbsp;<smvc:errors path="selectedClinician"/></td>
				</tr>
				<tr>
				<td colspan="5" align="right">
				<table width="200">
					<tr>
						<td align="right">Page <c:out value="${patientInfo.pagination.currentPage }"/> of <c:out value="${patientInfo.pagination.numberOfPages }"/></td>
						<td width="1">
							<c:choose>
								<c:when test="${patientInfo.pagination.previousPageNum != null}">
									<a title="Previous Page" href="javascript:dispatchMethods('showPrevPage');"><img src="../images/16x16/action_back.png"/></a>
								</c:when>
								<c:otherwise>
									<img src="../images/16x16/action_back_disabled.png"/>
								</c:otherwise>
							</c:choose>
						</td>
						<td width="1" align="right">
							<c:choose>
								<c:when test="${patientInfo.pagination.nextPageNum != null}">
									<a title="Next Page" href="javascript:dispatchMethods('showNextPage');" ><img src="../images/16x16/action_forward.png"/></a>
								</c:when>
								<c:otherwise>
									<img src="../images/16x16/action_forward_disabled.png"/>
								</c:otherwise>
							</c:choose>
						</td>
					</tr>
				</table>
				</td></tr>
				<tr>
				<td width="10%" align="right" valign="top" style="font-weight: bold;">
				Clinicians&nbsp;
				</td>
				<td width="90%" colspan="4">
					<table border="1" width="100%" class="table">
						<tr class="tableHeader">
							<th width="5%" class="tableColHeader">To</th>
							<th width="10%" class="tableColHeader">Title</th>
							<th width="20%" class="tableColHeader">Firstname</th>
							<th width="20%" class="tableColHeader">Lastname</th>
							<th width="15%" class="tableColHeader">Speciality</th>
							<th width="20%" class="tableColHeader">Tel</th>
							<th width="10%" class="tableColHeader">Email To</th>
						</tr> 
						
				<c:set var="resultCount" value="${fn:length(patientInfo.cliniciansList)}"/>
                    <c:choose>
                    <c:when test="${resultCount > 0}">
						
						
						<c:forEach items="${patientInfo.cliniciansList}" var="clinician" varStatus="s" >
						<tr class='<c:out value="${s.count%2 == 0 ? 'odd' : 'even' }"/>Row <c:out value="${selClass }"/>'>
                            <td align="center"><input type="submit" onclick="assignClinician(<c:out value="${clinician.id}"/>,<c:out value="${clinician.userName}"/>,<c:out value="${clinician.mnemonic}"/>);dispatch('addToAltConsultant');" value="To" /> </td>
                            <td><c:out value="${clinician.title}"/></td>
                            <td><c:out value="${clinician.firstName}"/></td>
                            <td><c:out value="${clinician.lastName}"/></td>
                            <td><c:out value="${clinician.speciality}"/></td>
                            <td><c:out value="${clinician.telNumber}"/></td>
                            <td><a href="mailto:<c:out value="${clinician.emailId}"/>?subject="><c:out value="${clinician.emailId}"/></a></td>
                        </tr>
                        </c:forEach>
                       </c:when>
                       <c:otherwise>
                       <tr>
                        <td align="center" class="message" colspan="8">No Record(s) Found</td>
                        </tr>
                       
                       </c:otherwise>
                       </c:choose>
                        
                        
					</table>
					</td>
				</tr>
				<tr>
                    <td>
                    	&nbsp;
                    </td>
                    <td colspan="2" align="right">
                    	Show 
						<smvc:select path="selectPageSize" multiple="false" onchange="dispatchMethods('searchClinician');">
								<smvc:option value="10">10</smvc:option>
								<smvc:option value="20">20</smvc:option>
								<smvc:option value="30">30</smvc:option>
								<smvc:option value="40">40</smvc:option>
								<smvc:option value="50">50</smvc:option>
								<smvc:option value="All">All</smvc:option>
						</smvc:select>
						items per page
                    </td>
                    <td colspan="2" align="right">
                    <table width="200">
						<tr>
							<td align="right">Page <c:out value="${patientInfo.pagination.currentPage }"/> of <c:out value="${patientInfo.pagination.numberOfPages }"/></td>
							<td width="1">
								<c:choose>
									<c:when test="${patientInfo.pagination.previousPageNum != null}">
										<a title="Previous Page" href="javascript:dispatchMethods('showPrevPage');"><img src="../images/16x16/action_back.png"/></a>
									</c:when>
									<c:otherwise>
										<img src="../images/16x16/action_back_disabled.png"/>
									</c:otherwise>
								</c:choose>
							</td>
							<td width="1" align="right">
								<c:choose>
									<c:when test="${patientInfo.pagination.nextPageNum != null}">
										<a title="Next Page" href="javascript:dispatchMethods('showNextPage');" ><img src="../images/16x16/action_forward.png"/></a>
									</c:when>
									<c:otherwise>
										<img src="../images/16x16/action_forward_disabled.png"/>
									</c:otherwise>
								</c:choose>
							</td>
						</tr>
					</table>
                    </td>
                </tr>
				<tr>
                    <td width="100%" colspan="5">&nbsp;</td>
                </tr>
				<tr style="border-bottom: 2px solid #a8abaf;" bgcolor="#B9B9FF">
                    <td width="100%" colspan="5">&nbsp;</td>
                </tr>
			</table>
        </td>
		</tr>
    </table>
</smvc:form>