<%@ include file="/includes.jsp"%>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<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="../resetpassword.form">
<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
<input type="hidden" id="containsStrongPw" 	value="${enforceStrngPwdVal}" />
<input type="hidden" id="enforcePasswordHidden"	value="<c:out value="${enforceStrngPwdVal}"/>" />
<input type="hidden" id="isPaswordChanged" name="isPaswordChanged" value="false"/>
	<div class="error"><spring:bind path="user.*">
		<c:if test="${not empty status.errorMessages}">
			<c:forEach items="${status.errorMessages}" var="error">
				<img src="../images/16x16/error_white_bg.png" alt="e" />
				<c:out value="${error}" escapeXml="false" />
				<br />
			</c:forEach>
		</c:if>
	</spring:bind></div>	
	<c:if test="${user ne null }">
	</c:if>
		<table class="dialogBox" width="35%">
		<tr>
			<td colspan="2" class="dialogTitle">Ardeo eMDT Password Assistance</td>
		</tr>

	    <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 height="40px"	valign="bottom">
					<td colspan="2" 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 ='requestpassword.jsp'"/>
					&nbsp;&nbsp;&nbsp;&nbsp;
					&nbsp;&nbsp;&nbsp;&nbsp;</td> 
				</tr>
			</c:if>
	    </c:when>
	    <c:otherwise>
	    		<tr height="40px"  valign="middle">
					<td  colspan="2"><b><font size="3">&nbsp; Reset Your Password Here...</font></b></td>
				</tr>
				<tr height="30px">
					<td class="label" width="40%">Username <span class="mandatory">*</span></td>
					<td class="input" width="60%"><smvc:input path="username" disabled="true" size="30"/>
			</tr>
			<tr>
				<td class="label" width="50%">Forename</td>
				<td class="input"><smvc:input path="forename" disabled="true" size="30"/></td>
			</tr>
	
			<tr>
				<td class="label" width="40%">Surname</td>
				<td class="input"><smvc:input path="surname" disabled="true" size="30"/></td>
			</tr>
			<tr style="display: none;">
				<td><smvc:checkbox path="enforceStrongPassword"
					id="enforceStrongPassword" disabled="true"/>
				</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 height="35px">
				<td colspan="2" class="input" align="right">
					<input type="submit" value="Save"/>
					&nbsp;&nbsp;
				</td> 
			</tr>
		 </c:otherwise>
	   </c:choose>
	</table>

</smvc:form>