<%@ include file="/includes.jsp"%>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<script type="text/javascript">
var formSubmitted = false;
function submitTheForm(){
    var enforceStrongPasswordChkBox = document.getElementById("enforceStrongPassword").checked;	 
    	if(enforceStrongPasswordChkBox == true){
    	   var str=document.getElementById("password1").value;
    		if(str.length <=7){
		    	alert("Please enter at least 8 character in Password");
		    	return false;
		    }
		    if(document.getElementById("isPaswordChanged").value !='true'){	
		    	alert("Password strength should be either 'Strong' or 'Very Strong'");
		   		return false;
		    }    	
	    }
	
    var result= validate();
    if(result=='true'){
		if(formSubmitted == true){
			return false;
		}else{
			formSubmitted = true;
			return true;
		}
	}
	return true;
}
function validate(){
	if(document.getElementById('password1').value.length<=0){
		alert('Password can not be empty.');
		document.getElementById('password1').focus();
		return false;
	}else if(document.getElementById('password2').value.length<=0){
		alert('please verify Password. ');
		document.getElementById('password2').focus();
		return false;
	} 
	return true;
}
function verifyPassword(){
	if(document.getElementById('password1').value != document.getElementById('password2').value){
		alert('Password verification failed. Re-enter password to verify:');
		document.getElementById('password2').value="";
		document.getElementById('password2').focus();
		return false;
	}
	return true;
}
</script>
<smvc:form modelAttribute="user" method="POST" onsubmit="return submitTheForm();" action="../applyforaccount.form">
	<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
	<input type="hidden" id="containsStrongPw"
		value="<c:out value="${enforceStrngPwdVal}" />" />
	<input type="hidden" id="enforcePasswordHidden"
		value="<c:out value="${enforceStrngPwdVal}" />" />
	<input type="hidden" id="isPaswordChanged" name="isPaswordChanged"
		value="false" />
	<input type="hidden" id="action" name="action" value="submit" />
	<input type="hidden" id="accountCreationReqdate"
		name="accountCreationReqdate" value="<c:out value="${accountCreationReqdate}" />" />
	<br />&nbsp;
	<table align="center" width="600px">
		<tr>
			<td>
			<fieldset><legend>Apply for User Account</legend>
			<table cellspacing="10" width="100%">
				<c:choose>
					<c:when
						test="${requestScope.successMsg ne null || requestScope.errMsg ne null}">
						<c:if test="${requestScope.successMsg ne null}">
							<tr height="40px" valign="bottom">
								<td colspan="2" class="input" align="center">
								<div class="message"><img
									src="images/16x16/information.png" alt="i" />
								<c:out value="${requestScope.successMsg}"/></div>
								</td>
							</tr>
							<tr>
								<td colspan="2" class="input" align="right"><br />
								<img src="images/16x16/continue.png"
									onclick="document.location.href ='login.form'" />
								&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</td>
							</tr>
						</c:if>
						<c:if
							test="${ requestScope.successMsg eq null and requestScope.errMsg ne null}">
							<tr >
								<td colspan="5" class="input" align="center">
								<div class="error"><img src="../images/16x16/error.png"
									alt="e" /><c:out value="${requestScope.errMsg}"/></div>
								</td>
							</tr>
							<tr>
								<td colspan="2" class="input" align="right"><br />
								<img src="images/16x16/continue.png"
									onclick="document.location.href ='loginapplication.jsp'" />
								&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</td>
							</tr>
						</c:if>
					</c:when>
					<c:otherwise>
						<tr>
							<td valign="top">
							<fieldset>
							<table width="500px">
								<tr>
									<td class="label">Username <span class="mandatory">*</span></td>
									<td class="input"><smvc:input path="username" /></td>
								</tr>
								<tr>
									<td class="label">Honorific Prefix</td>
									<td class="input"><smvc:select path="prefix">
										<smvc:option value=""></smvc:option>
										<c:if test="${fn:length(prefixList)>0}">
											<c:forEach var="prefix" items="${prefixList}">
												<smvc:option value="${prefix}"><c:out value="${prefix}"/></smvc:option>
											</c:forEach>
										</c:if>
									</smvc:select></td>
								</tr>
								<tr>
									<td class="label">Forename</td>
									<td class="input"><smvc:input path="forename" /></td>
								</tr>
								<tr>
									<td class="label">Middle name(s)</td>
									<td class="input"><smvc:input path="middlename" /></td>
								</tr>
								<tr>
									<td class="label">Surname</td>
									<td class="input"><smvc:input path="surname" /></td>
								</tr>
								<tr>
									<td class="label">Honorific Suffix</td>
									<td class="input"><smvc:select path="suffix">
										<smvc:option value=""></smvc:option>
										<c:if test="${fn:length(suffixList)>0}">
											<c:forEach var="suffix" items="${suffixList}">
												<smvc:option value="${suffix}"><c:out value="${suffix}"/></smvc:option>
											</c:forEach>
										</c:if>
									</smvc:select></td>
								</tr>
								<tr>
									<td class="label">Hospital</td>
									<td class="input"><select name="hospitalCode">
										<c:forEach var="hospitals" items="${hospList}">
											<option value="${hospitals.hospitalCode}" ><c:out value="${hospitals.hospitalName}"/></option>
										</c:forEach>
									</select></td>
								</tr>
								<tr>
									<td class="label">Enabled</td>
									<td class="input"><smvc:checkbox path="enabled"
										id="enabled" disabled="true" /></td>
								</tr>
								<tr>
									<td class="label">Enforce Strong Password</td>
									<td class="input"><smvc:checkbox
										path="enforceStrongPassword" id="enforceStrongPassword"
										disabled="true" /></td>
								</tr>
								<tr>
									<td colspan="2">
									<hr />
									</td>
								</tr>
								<tr id="noStrngPwdId">
									<td class="label" width="40%">New Password <span
										class="mandatory">*</span></td>
									<td class="input"><smvc:password path="password"
										id="password1" size="30"
										onkeyup="passwordStrength(this.value);"
										onkeydown="passwordStrength(this.value);" /></td>
								</tr>
								<tr id="pwdStrength">
									<td class="label" width="40%">Password strength</td>
									<td class="input">
									<div id="passwordDescription" class="label">Minimum
									number of characters is 8.</div>
									<div id="passwordStrength" class="strength0"></div>
									</td>
								</tr>
								<tr height="40px">
									<td class="label" width="50%">Verify Password<span
										class="mandatory">*</span></td>
									<td class="input"><input type="password" id="password2"
										size="30" /></td>
								</tr>
								<tr>
									<td class="label">Email <span class="mandatory">*</span></td>
									<td class="input"><smvc:input path="email" readonly="true" /></td>
								</tr>
							</table>
							</fieldset>
							<fieldset class="buttonFieldset"><input type="reset"
								value="reset" />&nbsp;<input type="submit" value="Save" /></fieldset>
							</td>
						</tr>
					</c:otherwise>
				</c:choose>
			</table>
			</fieldset>
			</td>
		</tr>
	</table>
</smvc:form>