  <body id="page-top" class="imm">

    <header class="imagr text-center text-white ">

    

      <div class="container text-center">

        <h3>TheNewBroker</h3>

        <p>Start buying and selling bitcoins by creating an account at <br>Bitcove.</p>

        <div class = " box1 box pt-4 mx-auto">

            <form class="container mx-auto" method="post" name="frmChange" onSubmit="return validateInput(event)">

                <div class = "form-group">

                    <div class = "container">

                      <div class = "row" >

                        <div>

                            <a href="<?php echo base_url();?>" class = "" ><i class = "fa fa-arrow-left"></i>  </a>

                        </div>

                         <div class = "ic mx-auto">

                           <h4>Sign In</h4>

                            <hr class = "pt-0 mt-0 pb-2 hr-length">

                        </div>

                    </div>

                    </div> 

                <input type="email" id="email" name="email" class="form-control sign" placeholder="Email">

                    <span id="email_res" style="color: red" class="required"></span><br/>  



                

                <input type="password" id="password" name="psw" class="form-control sign" placeholder="Password">

                    <span id="password_res" style="color: red" class="required"></span><br/>  



                <button type="submit" id="btn" class="btn btp light form-control log mt-4 mb-5" >Sign In</button>

                 <img id="loader" src="assets/img/loader.gif"/>

            </form>



          </div>



      </div>

    

      </div>

      <div class = "text-center">

        <a class="forgot mx-auto logg" href="<?php echo base_url();?>register">Create an Account</a>



        <a class="forgot mx-auto logg pl-5" href="<?php echo base_url();?>forgot_password">Forgot Password</a>

      </div>

      <br>

      <br>

    </header>



    <script>

      $(document).ready(function() {

      $("#loader").hide();

      });

       const validateInput = e => {

        e.preventDefault();

          var email, password, output  = true;

          email = document.frmChange.email;

          password = document.frmChange.psw;



          if(!email.value) {

            email.focus();

            document.getElementById("email").style.borderColor = "red";

            document.getElementById('email_res').innerHTML = "This field is required";

            output = false;

          } else {

            document.getElementById("email").style.borderColor = "";

            document.getElementById('email_res').innerHTML = "";

            output = true;

          }

          

          if(!password.value) {

            password.focus();

            document.getElementById("password").style.borderColor = "red";

            document.getElementById('password_res').innerHTML = "This field is required";

            output = false;

          } else {

            document.getElementById("password").style.borderColor = "";

            document.getElementById('password_res').innerHTML = "";

            output = true;

          }



          if(output == true) {

            $.ajax({

                  url: "login",

                  type: "POST",

                  data: {

                    email: email.value,

                    password: password.value

                  },

                  dataType: "JSON",

                  cache: false,

                  beforeSend: function() {

                    

                    $("#loader").show();

                   $("#btn").hide();

                  },

                  success: function(jsonStr) {

                     $("#loader").hide();

                   $("#btn").show();



                    if (jsonStr.status == "error") {

                      if (jsonStr.code == 0) {

                        toastr.warning("Sorry fields cannot be null");

                      }else if (jsonStr.code == 1) {

                        toastr.warning("Sorry all fields must be filled");

                      }else if (jsonStr.code == 2) {

                        toastr.warning("Sorry email already exist");

                        email.focus();

                      } else {

                        toastr.error("Error in operation, Please try again");

                      }

                    }

                    if (jsonStr.status == "success") {

                      if (jsonStr.code == 0) {

                        toastr.success("Login successful");

                        window.location = "<?php echo base_url();?>verify"

                      } else {
                        toastr.warning("Invalid login details, Please try again");
                      }

                    }

                    // $("#result").text(JSON.stringify(jsonStr));

                  }

                });

          }

      }

</script>

