<%@ page extends="oneit.servlets.jsp.JSPInclude" %>

<%@ include file="/setuprequest.jsp" %>
<%@ include file="/inc/stdimports50.jsp" %><%-- This is in cougar --%>
<%@ include file="/extensions/performa/inc/stdimports.jsp" %>

<oneit:dynIncluded>

<%
    ORMProcessState     process             =   (ORMProcessState)ProcessDecorator.getDefaultProcess(request);
    ObjectTransaction   objTran             =   process.getTransaction ();
    String              candidateID         =   (String) process.getAttribute("candidateID"); //request.getParameter("id");
    String              forgotpasswordCode  =   (String) process.getAttribute("forgotpasswordCode"); //request.getParameter("key");
    SecUser             user                =   (SecUser) process.getAttribute("SecUser");
    String              nextPage            = 	WebUtils.getSamePageInRenderMode(request, "SignIn");
    Job                 job                 =   (Job) process.getAttribute("Job");

    if(request.getParameter("id")!= null)
    {
        candidateID =   request.getParameter("id");
        process.setAttribute("candidateID", candidateID);
    }
    
    if(request.getParameter("key")!= null)
    {
        forgotpasswordCode  =   request.getParameter("key");
        process.setAttribute("forgotpasswordCode", forgotpasswordCode);
    }
    
    if(request.getParameter("jid")!= null)
    {
        String  jobID   =   request.getParameter("jid");
        job             =   Job.getJobByID(objTran, Long.parseLong(jobID));
        process.setAttribute("Job", job);
    }

    if(StringUtils.subBlanks(candidateID) != null)
    {
        Candidate    candidate   =   Candidate.getCandidateForForgotPassword(objTran, candidateID, forgotpasswordCode);

        if(candidate != null)
        {
            user    =  candidate.getUser();

            process.setAttribute("SecUser", user);
        }
    }
%>
    <script type="text/javascript">
        $(document.body).addClass('bg-color');

        $(document).ready(function() {
            validate();
            $('input').on('change keyup', function() { validate() });
        });

        function validate() {
            var empty = false;
            $('.password-field').each(function() {
                if ( $.trim($( this ).val()) == '') {
                    empty = true;
                }
            });

            if (empty) {
                $('.reset-btn').attr('disabled', 'disabled');
            } else {
                $('.reset-btn').removeAttr('disabled');
            }
        }
    </script>
    <style>
        button[disabled] {
            opacity: 0.6;
            background-color: #0582ba;
        }
    </style>
    <div class="main-verify-identity">
        <div class="login-logo"><img src="<%= request.getContextPath() %>/images/logo.svg" /></div>
        <oneit:form name="resetPassword"    method="post">

                <oneit:dynInclude   page="/extensions/applicantportal/inc/multifieldtext.jsp"   data="<%= CollectionUtils.EMPTY_MAP%>"/>

            <%
                if(user!=null)
                {
                    String  key =   Utils.getPwdKeyOfSecUser(request, user, true);
            %>
                    <div class="main-box-layout login-box">
                        <div class="text-left">
                            <p >
                                Please enter a new password below.
                            </p>
                        </div>
                        <div>&nbsp;</div>
                        <div class="form-group text-left">
                            <label>Password *</label>
                            <oneit:input type="password" name="<%= key %>"      class="form-control password-field"/>
                        </div> <!-- form-group -->
                        <div class="form-group text-left">
                            <label>Confirm Password *</label>
                            <oneit:input type="password" name="<%= key + 2 %>"  class="form-control password-field"/>
                        </div> <!-- form-group -->
                        <div class="col-sm-12">
                            <oneit:button   value="Set New Password"    name="resetPassword"  cssClass="box-btn reset-btn"
                                            requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage + "&JobID=" + job.getID().toString())
                                                                                .toMap() %>"/>
                        </div>
                    </div>
            <%
                }
                else
                {
            %>
                    <h3 class="text-danger">Invalid User or this link has been expired, generate new link to access this page.</h3>
            <%
                }
            %>
        </oneit:form>
    </div>
</oneit:dynIncluded>