<%@ include file="/includes.jsp" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<script>
	//<!--
	function update() {
		
		document.getElementById("cancelField").name = 'org.apache.struts.taglib.html.CANCEL';
		document.getElementById("form").submit();
	}
	
	function deleteUser() {
	   var confirmed;
	   confirmed = confirm("Are you sure you want to delete the user?");
       if(confirmed){
           document.getElementById("delete").value = "true"; 
           return true;            
       }
       else{
          return false;
       }
    }
    function resetSupportingStaff(){
    	document.location='../admin/supportingStaff.form?';
    }
    function callSupportingStaff(){
    	var ssidBox = document.getElementById("supervisorIds");
    	var ssIdValue = ssidBox.value;
    	if(ssIdValue && ssIdValue != ""){
	    	supstaffURL='../admin/supportingStaff.form?patientId="${patientId}&userId='+ssIdValue;
	    	var confirmed;
	   		confirmed = confirm("Is the user who requested you to add supporting staffs to the patient?");
	    	if(confirmed){
	    		document.location=supstaffURL;
	    	}
	    }
    }    
	
	//-->
</script>
	<input type="hidden" name="cancelField" id="cancelField" value="true"/>
	<input type="hidden" name="delete" id="delete" value="false"/>
	<table>
		<tr>
			<td>
				<fieldset class="nobg">
					<legend>Patient Support Staff</legend>
					<c:choose>
						<c:when test ="${empty supervisorUsers}">
							<span class="error">The selected patient does not have an admitting physician in eMDT.<br>
							Please select and admitting physician before adding support staff for the patient.
							</span>
							<fieldset>
								<input type="button" value="Back to Previous Screen" 
								onclick="history.back();"/>&nbsp;
							</fieldset>
						</c:when>
						<c:otherwise>
							<table cellspacing="10" width="100%">
							
								<tr>
									<td valign="top">
											Please select the user who requested you to add  
											supporting staffs to the patient <B>(<c:out value="${ssPatientName}"/>) </B>:
									</td>
								</tr>		
								<tr>
									<td valign="top">
																
										<fieldset>
									<select name="supportingStaffForm" 
														id="supervisorIds" 										
														style="width:300px"
														onchange="callSupportingStaff()"
														>
														
											 <option value="" selected>&nbsp;</option>
										<c:forEach var="user" items="${supervisorUsers}" varStatus="status">
											<c:choose>
												<c:when test="${!empty( fn:trim(user.fullName))}">
													<c:set var="userFullName" >(<c:out value="${user.forename}"/> <c:out value="${user.surname}"/>)</c:set>
												</c:when>
												<c:otherwise>
													<c:set var="userFullName" ></c:set>
												</c:otherwise>
											</c:choose>
											 <option value="<c:out value="${user.id}" />"><c:out value="${user.username}"/> <c:out value="${userFullName}"/></option>	
										</c:forEach>
													</select>
										</fieldset>	
									</td>
								</tr>
								<tr>
									<td>
														
									</td>
								</tr>
							</table>
						</c:otherwise>
					</c:choose>
					<center>
					<span class="error"><c:out value="${msg}"/></span>
					</center>
					
				</fieldset>
				
							<fieldset>
								<input type="button" value="Back to Previous Screen" 
								onclick="history.back();"/>&nbsp;
							</fieldset>
			</td>
		</tr>	
	</table>