<?php
require_once('core/includes/encrypt.php');
$per=new encrypthelper();
?>
<script>

  $(function () {

$(document).ready(function(e) {
      $("#login").keypress(function(e) {
        if(e.which == 13) {
          login();
        }
      });
});
//Funcion hacer login//
$(document).on('click', '#login', function(e){
 event.preventDefault(e);
 login();
});


//Funcion hacer login//
function login(){
 $('#login').prop("disabled", true);
 var name_user = $("#username").val().trim();
 var pass = $("#userpass").val().trim();
 if (typeof name_user == 'undefined' || name_user === null || name_user === '' || typeof pass == 'undefined' || pass === null || pass === '' ) {  
   toastr.error('Todos los campos son obligatorios');
   $('#login').prop("disabled", false);
 } else {
  data = {'option':'<?php echo $per->encode('login')?>','name_user':name_user,'pass':pass};
  $.post('<?php echo $url_admin;?>core/login.php', data)
  .done(function(resp){
    if(resp.status == "F"){
      toastr.error(resp.msg);
    }else{
      var url = window.location.href;
      var url2=window.location.pathname;
      var url = url.split(url2);
      var newWindow = window.open("","_self");
      newWindow.location.href =url[0]+'<?php echo $url_admin;?>';
    }
    $('#login').prop("disabled", false);
  });
}
}



});
</script>