<?php
	ob_start("ob_gzhandler");
	require("packages/require_login.php");
  include("controller/controller_index.php");
?>
<!DOCTYPE html>
<html>
<head>
  	<title><?=$title['login'];?></title>
  	<?php include("packages/head-login.php");?>
</head>
<body class="hold-transition login-page bg-login" style="background-image: url('<?=$global['absolute-url'].'img/cms-bg4.jpg';?>');">
<div class="login-box">
  <div class="login-logo">
    <a href="<?=$global['absolute-url'];?>">
      <img src="<?php echo $global['logo'];?>" alt="logo" style="height: 120px;">
      <!-- Administrator -->
    </a>
  </div>
  <!-- /.login-logo -->
  <div class="login-box-body" style="box-shadow: 0 0 10px #5d5d5d;border-radius: 10px;">
    <p class="login-box-msg">Sign in to start your session</p>

    <form action="index.php?action=login" enctype="multipart/form-data" method="post" onsubmit="return validateForm();">
      <div class="form-group has-feedback">
        <input type="text" class="form-control" id="input-email" placeholder="Email" name="email">
        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
        <div id="error-email" class="error-text"></div>
      </div>
      <div class="form-group has-feedback">
        <input type="password" id="input-password" class="form-control" placeholder="Password" name="password">
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
        <div id="error-password" class="error-text"></div>
      </div>
      <div class="row">
        <div class="col-sm-6 col-xs-12">
          <!-- <div class="checkbox icheck" style="margin: 6px 0;">
            <label>
              <input type="checkbox" style="position: inherit;margin: 0;" name="remember" value="1"> Remember Me
            </label>
          </div> -->
        </div>
        <!-- /.col -->
        <div class="col-xs-12">
          <button type="submit" class="btn btn-rms btn-block btn-flat">Sign In</button>
        </div>
        <!-- /.col -->
      </div>
      <div class="up1"></div>
      <div class="row">
        <div class="col-sm-6 hidden-xs"></div>
        <div class="col-sm-6 col-xs-12 text-right">
          <a href="<?=$path['login-forget'];?>">forgot my password</a>
        </div>
      </div>
    </form>

  </div>
  <!-- /.login-box-body -->
</div>
<!-- /.login-box -->

<?php include("packages/footer-login.php");?>
    <script type="text/javascript">
       $(document).ready(function() {
            <?php if($message != "") { ?>
            //use session here for alert success/failed
            var alertText = "<?=$message;?>";
                <?php if($alert != "success"){ ?>
                errorAlert(alertText);// error alert
                <?php } else { ?>
                successAlert(alertText);// success alert
                <?php } ?>
            <?php } ?>
        });
        function validateForm(){
            var email = $("#input-email").val();
            var password = $("#input-password").val();

            var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
            var numFormat = /^\+?[\d+ ]*$/;
            var urlFormat = /^HTTP|HTTP|http(s)?:\/\/(www\.)?[A-Za-z0-9]+([\-\.]{1}[A-Za-z0-9]+)*\.[A-Za-z]{2,40}(:[0-9]{1,40})?(\/.*)?$/;

            if(email != ""){
                if(email.match(mailformat)){
                    $("#error-email").html("");
                    $("#error-email").hide();
                    $("#input-email").removeClass("input-error");
                } else {
                    $("#error-email").show();
                    $("#error-email").html("<i class='fa fa-warning'></i> Incorrect email format.");
                    $("#input-email").addClass("input-error");
                    $("#input-email").focus();
                    return false;
                }
            } else {
                $("#error-email").show();
                $("#error-email").html("<i class='fa fa-warning'></i> This field is required.");
                $("#input-email").addClass("input-error");
                $("#input-email").focus();
                return false;
            }
            if(password != ""){
                $("#error-password").html("");
                $("#error-password").hide();
                $("#input-password").removeClass("input-error");
            } else {
                $("#error-password").show();
                $("#error-password").html("<i class='fa fa-warning'></i> This field is required.");
                $("#input-password").addClass("input-error");
                $("#input-password").focus();
                return false;
            }
        }
    </script>
</body>
</html>
