<%@ include file="/includes.jsp"%>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<script>
	function patientHistory(){
		document.location.href = "../emdt/patientHistoryActions.form";
	}
	function makeNewReferral(){
		
		document.getElementById('newReferral').value="true";
		var answer = confirm("Make a new referral for this patient.");
		if (answer){
			location.href='../nationalMDT/referralsPatient.form?newReferral=true';
		}
		else{
		}
	}
	function convertInputToDiv(isPatientInfoReadonly){
		if(isPatientInfoReadonly == 'true'){
			var inputs = document.getElementsByTagName('input');
			for(var i=0;i<inputs.length;i++){
				var input=inputs[i];
				var id=input.id;
				var type=input.type;
				if(id!=null && id.length>0){
					if(type!='hidden' && (id!="selectedClinician" && id!="patienthospitalNumber")){
						var element=document.getElementById(id);
						var value=element.value
						var parentNode=element.parentNode;
						var childnodes=parentNode.childNodes;
						for(var j=0;j<childnodes.length;j++){
							if(childnodes[j].tagName=="INPUT"){
								childnodes[j].style.display="none";
							}else{
								parentNode.removeChild(childnodes[j]);
								j--;
							}
						}
						var h=document.createElement("H8")
						var t=document.createTextNode(value);
						h.appendChild(t);				
						parentNode.appendChild(h);
					}
				}
			}
			var textareas = document.getElementsByTagName('textarea');
			for(var i=0;i<textareas.length;i++){
				var textarea=textareas[i];
				var id=textarea.id;
				var type=textarea.type;
				if(id!=null && id.length>0){
					if(id!="comments"){
						var element=document.getElementById(id);
						var value=element.value;
						var parentNode=element.parentNode;
						var childnodes=parentNode.childNodes;
						for(var j=0;j<childnodes.length;j++){
							if(childnodes[j].tagName=="TEXTAREA"){
								childnodes[j].style.display="none";
							}else{
								parentNode.removeChild(childnodes[j]);
								j--;
							}
						}
						var h=document.createElement("H8")
	  					var t=document.createTextNode("");
						h.appendChild(t);				
	  					parentNode.appendChild(h);
						var para=document.createElement("pre");
						var node=document.createTextNode(value);
						para.appendChild(node);
						parentNode.appendChild(para);
					}
				}
			}
		}
	}

</script>
<input type="hidden" value="false" id="unsaveButtonId" />
<tiles:insertTemplate template ="referralsDetailsTopBar.jsp" ></tiles:insertTemplate>

<smvc:form name="viewPatient" modelAttribute="referralPatientDto"
	method="post" onsubmit="return submitTheForm();">
	<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
	<smvc:hidden path="actionRequired" />
	<input type="hidden" id="newReferral" name="newReferral"
		value="" />
	<smvc:errors></smvc:errors>
	<div class="container"><tiles:insertTemplate template ="managementMenu.jsp"></tiles:insertTemplate>
	<div class="bodySection">
	<div class="rightSaveDiv" onclick="savePatient();"  id="save"><br />
	Save Patient Details</div>
	<br />
	<br />
	<br />
	<br />
	<br />
	
	<div><c:if
		test="${requestScope.successMsg != null and fn:length(requestScope.successMsg) != 0}">
		<div class="message"><img src="../images/16x16/information.png"
			alt="i" />&nbsp; <c:out value="${requestScope.successMsg}"/></div>
	</c:if> <c:if test="${requestScope.errorMsg != null and fn:length(requestScope.errorMsg) != 0}">
		<div class="error"><img src="../images/16x16/error.png" alt="i" />&nbsp;
		<c:out value="${requestScope.errorMsg}"/></div>
	</c:if>
	<div class="error"><spring:bind path="referralPatientDto.*">
		<c:if test="${not empty status.errorMessages}">
			<c:forEach items="${status.errorMessages}" var="error">
				<img src="../images/16x16/error.png" alt="i" />&nbsp;<c:out
					value="${error}"/>" escapeXml="false" />
				<br />
			</c:forEach>
		</c:if>
	</spring:bind><br />
	</div>
	</div>
	<tiles:insertTemplate template ="patientDetailsBox.jsp" ></tiles:insertTemplate>
	</div>
	</div>
</smvc:form>

<script>
	convertInputToDiv('<c:out value="${isPatientInfoReadonly}"/>');
</script>