<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>
<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>登录 - 诉讼担保管理系统</title>

    <link href="${contextPath}/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="${contextPath}/static/font-awesome/css/font-awesome.css" rel="stylesheet">

    <link href="${contextPath}/static/css/animate.css" rel="stylesheet">
    <link href="${contextPath}/static/css/style.css" rel="stylesheet">

</head>

<body class="gray-bg">

    <div class="middle-box text-center loginscreen animated fadeInDown">
        <div>
            <div>

                <h1 class="logo-name">保</h1>

            </div>
            <!-- <h3>欢迎使用诉讼担保管理平台</h3>
            <p>Perfectly designed and precisely prepared admin theme with over 50 pages with extra new web app views.
                Continually expanded and constantly improved Inspinia Admin Them (IN+)
            </p>  -->
            <p>平台登录</p>
            <form class="m-t" role="form" action="index.html">
                <div class="form-group">
	                <input type="text" id="userName" class="form-control" placeholder="用户名">
	            </div>
	            <div class="form-group">
	                <input type="password" id="password" class="form-control" placeholder="密码">
	            </div>
                <button id="loginButton" type="button" class="btn btn-primary block full-width m-b">登录</button>

            </form>
            <p class="m-t"> <small>广州法度信息科技有限公司 &copy; 2016</small> </p>
        </div>
    </div>

    <!-- Mainly scripts -->
    <script src="${contextPath}/static/js/jquery-2.1.1.js"></script>
    <script src="${contextPath}/static/js/bootstrap.min.js"></script>

</body>

</html>

<script type="text/javascript">
jQuery(function($) {
	// 按回车键触发登录事件
	$(document).keydown(function(event) {
		var key = window.event ? event.keyCode : event.which;
		if (key == 13) {
			$("#loginButton").click();
		}
	});

	// 验证登录表单
	$("#loginButton").bind("click", function() {
		if($('#userName').val()==''||$('#password').val()==''){
			alert("用户名和密码不能为空！");
			return;
		}
		
		$.ajax({
			dataType : "json",
			url : "${contextPath}/pub/doLogin",
			type : "post",
			data : {
				loginName : $('#userName').val(),
				password : $('#password').val()
			},
			complete : function(xmlRequest) {
				var res = eval("(" + xmlRequest.responseText + ")");
				if(res.success){
					document.location.href = "${contextPath}/user/index";
				}else{
					alert(res.message);
				}
			}
			
		});
	});
});
</script>
