<div class="page-head text-center">
    <p>Change Password</p>
    <div class="clearfix"></div>
</div>

<div class="page-container">
  <div class="page-content">
    <div class="page-content-inner">
        <div class="container">
            <div class="white-bg marginbottom20"> 
              <form method="post" action="<?php echo base_url(); ?>ChangePassword/UpdateHod">
                <?php if ($this->session->flashdata('fail')!='') { ?>

                  <div class="alert alert-danger">
                    <?php echo $this->session->flashdata('fail'); ?>
                  </div>

                <?php } ?>
                <?php if ($this->session->flashdata('success')!='') { ?>

                  <div class="alert alert-success">
                    <?php echo $this->session->flashdata('success'); ?>
                  </div>

                <?php } ?>
                <div class="col-md-6 col-sm-6">
                  <div class="form-group">
                    <label for="old"> Username <span class="star">*</span> </label>
                    <input type="text" name="user" class="form-control" id="user" value=" <?php echo $this->session->userdata('admin_user_id'); ?>" readonly>
                  </div>
                </div>
                <div class="col-md-6 col-sm-6">
                  <div class="form-group">
                    <label for="old"> Old Password <span class="star">*</span> </label>
                    <input type="password" name="old" class="form-control" id="old" onchange="checkPass()" placeholder="Enter Old Password" data-validation="required " data-validation-error-msg-required="Please enter old password." data-validation-error-msg-container="#old_e">
                    <div id="old_e"></div>
                  </div>
                </div>
                <div class="clearfix"></div>
                <div class="col-md-6 col-sm-6">
                  <div class="form-group">
                    <label for="new"> New Password <span class="star">*</span> </label>
                    <input type="password" name="new" class="form-control" id="new" placeholder="Enter New Password" data-validation="required " data-validation-error-msg-required="Please enter New password." data-validation-error-msg-container="#new_e">
                    <div id="new_e"></div>
                  </div>
                </div>
                <div class="col-md-6 col-sm-6">
                  <div class="form-group">
                    <label for="newC"> Confirm New Password <span class="star">*</span> </label>
                    <input type="password" name="newC" class="form-control" id="newC" placeholder="Confirm New Password" data-validation="required " data-validation-error-msg-required="Please Confirm password." data-validation-error-msg-container="#newC_e">
                    <div id="newC_e"></div>
                  </div>
                </div>
                <div class="clearfix"></div>
                <div class="submit-btn">
                    <div class="col-md-6 col-sm-6">
                        <input name="" type="submit" value="Submit" class="light-blue-btn full-btn btnglobal">
                    </div>
                    <div class="col-md-6 col-sm-6">
                        <input name="" type="Reset" value="Cancel" class="full-btn reset-btn btnglobal">
                    </div>
                    <div class="clearfix"></div>
                </div>
              </form>
           </div>
        </div>
      </div>
    </div>
  </div>
</div>      

<script type="text/javascript">
function checkPass(){
  var old = $("#old").val();

  var url = "<?php echo base_url() ?>ChangePassword/check";

  $.ajax({

    url: url,
    method: "post",
    data:{
      old: old
    },

    success: function(res){

      if(res == 'false'){
        $("#old_e").html('<span class="help-block form-error">Password didn\'t match.</span>');
        $("#old_e").attr("class", "has-error");
        $("#old").attr("class", "form-control error");

      } else if(res == 'true'){
        $("#old_e").html('');
        $("#old_e").attr("class", "has-success");
        $("#old").attr("class", "form-control has-success")
      }
    }

  });

}
</script>
