<%@ include file="/includes.jsp"%>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
	<script type="text/javascript">
		function createNewHospitalForm(passedVal) {
			document.getElementById("taskId").value = passedVal;
			var fsForm = document.getElementById("formHospital");
			fsForm.method="POST";
			fsForm.action = "../admin/listhospitals.form";
			fsForm.submit();
		}
		
		function processEditDelete(task,id){	
			var isProceed = true;
			if(task == "4"){
				if(!confirm("Are you sure you want to delete this hospital?")){
					isProceed = false;
				}
			}	
			if(isProceed){
				document.getElementById("hospitalId").value = id;			
				createNewHospitalForm(task);
			}
		}
		
		function nullifyId(){
		document.getElementById("taskId").value = null;
		}
	</script>
	<sec:authorize access="hasRole('ADMIN')">
	<body onload="nullifyId();">
	<smvc:form id="formHospital">
		<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
		<br></br>
		<br></br>
		<br></br>
		<c:choose>
			<c:when test="${requestScope.successMsg != null || requestScope.errorMsg != null}">
				<c:if test="${requestScope.successMsg != null}">
					<span class="info"><c:out value="${requestScope.successMsg}"/></span>
				</c:if>
				<c:if test="${requestScope.errorMsg != null}">
					<span class="error"><c:out value="${requestScope.errorMsg}"/></span>
				</c:if>
			</c:when>
			<c:otherwise>
			</c:otherwise>
		</c:choose>
		<smvc:errors />
		<input type="hidden" name="mode" id="mode" value=""/>
		<fieldset style="width: 90%" class="nobg"><legend>Hospitals</legend>
		<fieldset><input type="hidden" name="task" id="taskId" />
		<input type="hidden" name="hospitalId" id="hospitalId" />
		<table>
			<tr>
				<td colspan="9"><B>List of Hospitals</B></td>
			</tr>
			<tr>
				<td colspan="9">&#160;</td>
			</tr>
		</table>
		<table width="100%" border="1" bordercolor="#F8F8FF">
			<tr>
				<th class="tableHeader" width="15%">Hospital Name</th>
				<th class="tableHeader" width="15%">Hospital Description</th>
				<th class="tableHeader" width="10%">Hospital Code</th>
				<th class="tableHeader" width="35%">Image Transfer Method</th>
				<th class="tableHeader" width="3%">&#160;</th>
				<th class="tableHeader" width="3%">&#160;</th>
			</tr>
			<c:forEach var="hospital" items="${hospitalsDTOList}">
				<tr>
					<td width="15%" align="left" valign="top"><c:out value="${hospital.hospitalName}"/></td>
					<td width="15%" align="left" valign="top"><c:out value="${hospital.hospitalDesc}"/></td>
					<td width="10%" align="left" valign="top"><c:out value="${hospital.hospitalCode}"/></td>
					<td width="15%" align="left" valign="top">
					<table width="100%">
						<c:forEach var="mageTransferMapping"
							items="${hospital.imageTransferMapping}">
							<tr class="rowline">
								<td align="left" valign="top"><c:out value="${mageTransferMapping.imgTansMethod.description}"/></td>
								<td align="right"><c:if test="${mageTransferMapping.isPreferred eq true}"><b>(preferred)</b></c:if> </td>
							</tr>
						</c:forEach>
					</table>
					</td>
					<td width="3%" align="center"><a href="javascript:void(0)" onClick="processEditDelete(3,<c:out value="${hospital.hospitalId}"/>);return false;">Edit</a></td>
					<td width="3%" align="center"><c:choose>
						<c:when test="${hospital.centralHub}"><a href="javascript:void(0)" onClick="javascript:alert('Hub hospital can not be deleted'); return false;">Delete</a></c:when>
						<c:otherwise>
							<a href="javascript:void(0)" onClick="processEditDelete(4,<c:out value="${hospital.hospitalId}"/>); return false;">Delete</a>
						</c:otherwise>
					</c:choose></td>
				</tr>
			</c:forEach>
		</table>
		</fieldset>
		<fieldset class="buttonFieldset"><input type="button"
			value="New" onclick="createNewHospitalForm(1);" /></fieldset>
		</fieldset>


	</smvc:form>
	</body></sec:authorize>