<%@ include file="/includes.jsp"%>
<script type="text/javascript">
function patientAuditLog(){
	var radioValue;
	for (i=0; i< document.referralsReport.radios.length; i++) {
		if (document.referralsReport.radios[i].checked) {
			radioValue = document.referralsReport.radios[i].value;
		}
		}
	var hospitalNo = document.getElementById('hospitalNo').value;
	
	if(radioValue=="lastViewedPatient" && hospitalNo.length!=0 || radioValue=="hospitalNo" && hospitalNo.length==0){
		alert("select appropriate radio button");
	}else if(radioValue=="lastViewedPatient"){
		if(document.getElementById('lastPatient').value!='true'){
		alert('no patient viewed, please enter patient hospital number');
		}else{
			location.href  = "../referrals/patientAuditLog.form" ;
		 }
	}else if(radioValue=="hospitalNo"){
		if(typeof hospitalNo!='undefined' && hospitalNo.length==0 ){
			alert('please enter patient hospital number ');
			}
		else{
		 location.href  = "../referrals/patientAuditLog.form?hospitalNo="+hospitalNo;
		}
		}
}
function setCheckedValue(patientId) {
	 var errorMsg=getURLParam("errorMsg");
	 if(errorMsg!=null && errorMsg.length!=0){
		 document.getElementById('errorDisplay').style.display='block';
		 document.referralsReport.radios[1].checked = true;
		 }
	 if(patientId!=null && patientId.length!=0){		
	    document.getElementById('lastPatient').value="true";
		document.referralsReport.radios[0].checked = true;
	 }else{
		document.referralsReport.radios[1].checked = true;
	}
}
function getURLParam(strParamName){
    var strReturn = "";
    var strHref = window.location.href;
    if ( strHref.indexOf("?") > -1 ){
      var strQueryString = strHref.substr(strHref.indexOf("?"));
      var aQueryString = strQueryString.split("&");
      for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
        if (
  aQueryString[iParam].indexOf(strParamName+ "=") > -1 ){
          var aParam = aQueryString[iParam].split("=");
          strReturn = aParam[1];
          break;
        }
      }
    }
    return unescape(strReturn);
  }
</script>
<style>
.menuitem {
	width: 100%;
}

.top {
	align: center;
	margin-top: 150px;
}

.menuButtonDiv {
	background: url("images/blueGradientRectangle.png") repeat scroll 0 0
		transparent;
	color: #ffffff;
	cursor: pointer;
	font-weight: bold;
	height: 35px;
	text-align: center;
	vertical-align: center;
	width: 120px;
}

.menuButtonDiv a {
	color: #ffffff;
}
</style>
<html>
<head>
<title>Referrals Reports Menu</title>
</head>
<body onload="setCheckedValue('<c:out value="${emdt.patient.id}"/>');">
<center><br />
<br />
<br />
<br />
<br />
<br />
<br />
<form name="referralsReport">
<div class="error" id="errorDisplay" style="display: none"><img
	src="../images/16x16/error.png" alt="e" /> <script type="text/javascript"> document.write(getURLParam("errorMsg"));</script><br /><br /></div>
<div class="fieldSetBox2">
<table>
	<tr align="left">
		<th>Select patient:</th>
	</tr>
	<tr>
		<td colspan="2" height="5px"></td>
	</tr>
	<tr>
		<td width=60%><INPUT TYPE="radio" NAME="radios" id="radios1"
			VALUE="lastViewedPatient"> last patient viewed :</td>
		<td width=40%><input type="hidden" id="lastPatient" value="" />
		<c:if test="${emdt.patient ne null}"><c:out value="${emdt.patient.forename}"/> <c:out value="${emdt.patient.surname}"/></c:if>
		<c:if test="${emdt.patient eq null}">no patient viewed</c:if></td>
	</tr>
	<tr>
		<td colspan="2" height="3px"></td>
	</tr>
	<tr>
		<td><INPUT TYPE="radio" NAME="radios" id="radios2"
			VALUE="hospitalNo"> enter patient hospital number :</td>
		<td><input type="text" id="hospitalNo" value=""
			onchange="setCheckedValue();"></input></td>

	</tr>
	<tr>
		<td colspan="2" height="10px"></td>
	</tr>
	<tr>
		<td></td>
		<td align="right"><input type="button" value="View Patient Audit Log"
			onclick="patientAuditLog()" /></td>
	</tr>

</table>
</div>
</form>
<br />
<br />
<div>
	<c:choose>
		<c:when test="${str eq 'referral'}">
			<a href="../referrals/referralsReportMenu.jsp" class="noPrint"><img src="../images/16x16/arrow_undo.png" />&nbsp;&nbsp;Return to previous screen</a>
		</c:when>
		<c:otherwise>
			<a href="../emdt/reportMenu.jsp" class="noPrint"><img src="../images/16x16/arrow_undo.png" />&nbsp;&nbsp;Return to previous screen</a>
		</c:otherwise>
	</c:choose>
</div>
<br />
</center>
</body>
</html>
