
<div class="page-content" >
    
    
<div class="row">
    <div class="col-sm-12">
        <div class="widget-box">
            <div class="widget-header" style="height:70px;">
                <h4  style="text-align:center; color:green;"><b>Change Customer Username And Password</b> </h4>
            </div>

            <div class="widget-body" id="success_message">
            <!-- <div class="alert alert-block alert-success">
                                        <h6 id="success_message" class="lighter arial green" style="text-align:center;"><b>
                                                
                                            </b></h6>
                                    </div> --> 
                 <?php
                                $message = $this->session->userdata('message');
                                if (!empty($message)) {
                                    ?>
                                    <div class="alert alert-block alert-success">
                                        <h6 class="lighter arial green" style="text-align:center;"><b>
                                                <?php echo $message;
                                                $this->session->unset_userdata('message');
                                                ?>
                                            </b></h6>
                                    </div>  
                                    <?php
                                }
                                $errormessage = $this->session->userdata('errormessage');
                                if (!empty($errormessage)) {
                                    ?>
                                    <div class="alert alert-block alert-danger">
                                        <h6 class="lighter arial red" style="text-align:center;"><b>
                                                <?php echo $errormessage;
                                                $this->session->unset_userdata('errormessage');
                                                ?>
                                            </b></h6>
                                    </div> 
                                    <?php
                                }
                                ?>
                <div class="widget-main no-padding">
                    <form id="frmchange" action="<?php echo admin_url()?>/newpasswordsetup/changeCustomer_password" method="post">
                       
                        <fieldset class="col-xs-12 col-sm-12">
                            <label class="col-xs-2 col-sm-2"> New User Name </label>
                            <?php echo form_error('data[courrentPassword]', '<div style="color: rgb(255, 0, 0);">', '</div>'); ?>
                            <input type="text" id="user_name" name="data[user_name]" autocomplete="off" value="<?php echo set_value('data[user_name]',false); ?>" placeholder="User name" class="col-xs-4 col-sm-4" />
                            <input type="hidden" id="id" name="id" value="<?php echo $id;?>">
                            &nbsp;&nbsp;&nbsp;&nbsp;<label style="color:red" id="pmessage4"> </label><label style="color:red" id="pmessage"></label>
                         </fieldset>

                        <fieldset class="col-xs-12 col-sm-12">
                            <label class="col-xs-2 col-sm-2"> Confrime New  User name </label>
                            <?php echo form_error('data[courrentPassword]', '<div style="color: rgb(255, 0, 0);">', '</div>'); ?>
                            <input type="text" id="conuser_name" name="data[conuser_name]" autocomplete="off" value="<?php echo set_value('data[conuser_name]',false); ?>" placeholder="Confirm user name" class="col-xs-4 col-sm-4" />
                            &nbsp;&nbsp;&nbsp;&nbsp;<label style="color:red" id="pmessage1"> </label><label style="color:red" id="pmessage"></label>
                        </fieldset>

                        
                        
                        <fieldset class="col-xs-12 col-sm-12">
                            <label class="col-xs-2 col-sm-2"> New Password </label>
                            <?php echo form_error('data[newPassword]', '<div style="color: rgb(255, 0, 0);">', '</div>'); ?>
                            <input type="password" name="data[newPassword]" autocomplete="off" value="<?php echo set_value('data[newPassword]',false); ?>" id="password" placeholder="New Password" class="col-xs-4 col-sm-4" />
                           &nbsp;&nbsp;&nbsp;&nbsp;<label style="color:red" id="pmessage3"> </label><label style="color:red" id="pmessage"></label>
                        </fieldset>
                       
                        <fieldset class="col-xs-12 col-sm-12"> 
                               <label class="col-xs-2 col-sm-2"> Confrime New Password </label>
                            <?php echo form_error('data[confirmPassword]', '<div style="color: rgb(255, 0, 0);">', '</div>'); ?>
                            <input type="password" name="data[confirmPassword]" autocomplete="off" value="<?php echo set_value('data[confirmPassword]',false); ?>" id="varefied_password" onkeyup="Verify_password();" placeholder="Confirm Password" class="col-xs-4 col-sm-4" />
                            &nbsp;&nbsp;&nbsp;&nbsp;<label style="color:red" id="pmessage2"> </label><label style="color:red" id="pmessage"></label>
                        </fieldset>




                        <div class="clearfix"></div>

                        <div class="form-actions center">
                            <button type="submit"  name="btnSave" id="mySubmit" class="btn btn-sm btn-success">
                                 <i class="ace-icon fa fa-check bigger-110"></i>
                                Change Password
                                
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div></div></div> 

<script type="text/javascript">
$(document).ready(function(){
    //alert('hi');
     ClearData();
    $('#conuser_name, #user_name').keyup(function(){
        var user_name= $('#user_name').val();
        var conuser_name= $('#conuser_name').val();
        if(user_name!=null && conuser_name==""){
            $('#pmessage1').html('Confirm user name');
            $('#mySubmit').attr('disabled',true);
         }
        else if(user_name!=conuser_name)
        {
            $('#pmessage1').html('User Name Missmatch');
            $('#mySubmit').attr('disabled',true);
        } 
        else
        {
            $('#pmessage1').html('');
            $('#mySubmit').attr('disabled',false);
        }
        if(user_name=="" && conuser_name==""){
            ClearData();
        }
    });


    $('#varefied_password,#password').keyup(function(){
        
        var password= $("#password").val();
        var varefied_password= $('#varefied_password').val();
        if(password!=null && varefied_password=="")
        {
            $('#pmessage2').html('Confirm Password');
            $('#mySubmit').attr('disabled',true);
         }
        else if(password!=varefied_password)
        {
            $('#pmessage2').html('Password Missmatch');
            $('#mySubmit').attr('disabled',true);
        }
        else
        {
            $('#pmessage2').html('');
            $('#mySubmit').attr('disabled',false);
        }
        if(password=="" && varefied_password==""){
            ClearData();
        }

    });

    function ClearData()
    {
        $('#pmessage1').html('');
        $('#pmessage2').html('');
        $('#pmessage3').html('');
        $('#pmessage4').html('');
        $('#mySubmit').attr('disabled',true);
    }


    $("#frmchange").submit(function (e){
       // var form=$('#frmchange');
       e.preventDefault();
        var url=$(this).attr('action');
        var data=$(this).serialize();
        //alert(data);
        $.ajax({
            url:url,//"<?php echo admin_url()?>/newpasswordsetup/changeCustomer_password ",
            type:'POST',
            dataType:'json',
            data:data,
            success:function(msg){
                //var obj = $.parseJSON(msg);
                 //alert(obj['confirmPassword']);
               //$('#pmessage2').html(msg); 
               if(msg.status==1)
               {
                    $('#pmessage1').html(msg.conuser_name);
                    $('#pmessage2').html(msg.confirmPassword);
                    $('#pmessage3').html(msg.newPassword);
                    $('#pmessage4').html(msg.user_name);
               }
               else if(msg=="3")
               {
                    //window.location="<?php echo admin_url()?>/landcustomerRegistration/ViewLandCustomer";
                    window.location.href = "<?php echo admin_url()?>/landcustomerRegistration/ViewLandCustomer";
               }
               else if(msg=="2")
               {
                    window.location.href = "<?php echo admin_url()?>/landcustomerRegistration/ViewLandCustomer";
                    //$("#success_message").html('<div class="alert alert-block alert-success"><h6 class="lighter arial green" style="text-align:center;"><b>Username Or Password Changed</b></h6></div>');
               }
              
            },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.responseText);
            }
        });

    });
});


</script>