<%@ page language="java" contentType="text/html; charset=UTF-8"
	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"%>

<%@ taglib prefix="webpath" uri="/WEB-INF/tlds/path.tld"%>
<%@ taglib prefix="webpage" uri="/WEB-INF/tlds/pageview.tld"%>


<head>
	<style type="text/css">
     	body{
			background:url(<webpath:path/>/resources/images/timg1.jpg);
			filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale')";  
			-moz-background-size:100% 100%;  
			background-size:100% 100%;  
			background-attachment: fixed;
		}
		.h22 {
			FONT-SIZE: 30px; font-family:PingFangSC,helvetica neue,hiragino sans gb,arial,microsoft yahei ui,microsoft yahei,simsun,"sans-serif" !important;font-weight: bold; COLOR: #f0f0f0; FONT-WEIGHT: 5px;
		}
		.divTityle{
			border-bottom: 1px solid rgba(255,255,255,0.3);	
		}
		.form-control{
			height:40px;
		}
		label.error{
			color:#ff0000;
		}
	</style>

</head>

<div class="main-container col-sm-12" style="padding:0px; margin:0px;">
			<div class="main-content col-sm-12"  style="padding:0px; margin:0px;">
				<div class="row" style="width:100%;margin:0;">
					<div class="col-sm-12" style="padding:0px; margin:0px;">
						<div class="login-container divTityle" style="width:100%; height:80px;">
							<div class="left col-sm-12 " style="height:0; padding:20px;padding-left:60px;"  >
                            	<img alt="logo" src="<webpath:path/>/resources/images/logo.png" height="40" style=""/>&nbsp;&nbsp;&nbsp;
                                <img alt="wz" src="<webpath:path/>/resources/images/wz.png"  height="40" style="margin-top:5px; "/>&nbsp;&nbsp;&nbsp;
							</div>
		
							<div class="space-6"></div>
							<div class="position-relative" style="top:120px" >
								<div id="login-box" class="login-box visible widget-box no-border " style="width: 500px; margin-left: auto;margin-right: auto; padding: 0px;" >
									<div class="widget-body" style="margin-bottom:180px;">
										<div class="widget-main" style="padding: 40px;">
										
											<h3 class="blue lighter bigger" style="text-align: center;margin:0;height:50px;">大赛报名</h3> 
											<div class="space-6"></div>
											<form action="#" id="reg_form" name="reg_form" method="post" onsubmit="return false">
												<fieldset>
													<label class="block clearfix">
														<span class="block ">
															<select type="text" class="form-control" placeholder="分组" id="groups" name="groups" style="height: 40px;">
                                                            	<option value="">大赛分组</option>                                        
															</select>                                       
															
														</span>
													</label>	
													<label class="block clearfix">
														<span class="block ">
															<input type="text" class="form-control" placeholder="手机号" id="mobile" name="mobile"/>
														</span>
													</label>
													
													
													<label class="block clearfix">
														<span class="block ">
															<input type="password" class="form-control" placeholder="密码" id="pwd" name="pwd"/>
															
														</span>
													</label>
													<label class="block clearfix">
														<span class="block ">
															<input type="password" class="form-control" placeholder="确认密码" id="confirmpassword" name="confirmpassword"/>
															
														</span>
													</label>
													
													<label class="block clearfix">
														<span class="block ">
															<input type="text" class="form-control" placeholder="邮箱" id="email" name="email"/>
														</span>
													</label>
													
													<label class="block clearfix">
														<span class="block ">
															<input type="text" class="form-control" placeholder="团队名称" id="teamName" name="teamName"/>
														</span>
													</label>
													
													<label class="block clearfix">
														<span class="block ">
															<input type="text" class="form-control" placeholder="单位名称" id="userName" name="userName"/>
														</span>
													</label>
													
													
													<label class="block clearfix">
														<span class="block ">
															<input type="text" class="form-control" placeholder="联系人" id="contacts" name="contacts"/>
														</span>
													</label>
													

													<div class="space"></div>
													<div class="clearfix" style="text-align: center;">
														<a class="inline" >
														</a>
														<button type="submit" class="pull-left btn btn-sm btn-primary col-sm-5" style="height: 40px;">
															注册
														</button>
														
														<button type="button" class="pull-right btn btn-sm btn-primary col-sm-5" onclick="window.location.href='<webpath:path/>/'" style="height: 40px;">
															返回
														</button>
														
													</div>
													<div class="space-4"></div>
												</fieldset>
											</form>
										</div><!-- /widget-main -->
									</div><!-- /widget-body -->
								</div><!-- /login-box -->
							</div><!-- /position-relative -->
						</div>
					</div><!-- /.col -->		
				</div><!-- /.row -->
			</div>
		</div><!-- /.amin-container -->

	<script type="text/javascript">
			if("ontouchend" in document)
				document.write("<script src='resources/assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
		</script>
		<script type="text/javascript" src="resources/js/tools/jquerysession.js"></script>
	
		<script type="text/javascript">
		var isSubmit = true;
			$().ready(function() {
				var groupInfo=$('#groups');
				groupInfo.append("<option value='1'>本科生组</option>");
				groupInfo.append("<option value='2'>研究生组</option>");
				groupInfo.append("<option value='3'>业界组</option>");
				/**
				$.ajax({
					  type: "post",
					  url: "/api/getGroup",
					  dataType:'json',
					  success: function(data) {
						var status=data.status;
						if(status==1){
						}else{
							var info=data.data;
							var groupInfo=$('#group');
							$.each(info, function(i,val){ 
								groupInfo.append("<option value='"+val.id+"'>"+val.name+"</option>");
						  }); 
						}
					  },
					  error: function(){
						alert("");
					  }
				});
				**/
				
				jQuery.validator.addMethod("isMobile", function(value, element) {  
			        var length = value.length;  
			        var mobile = /^1[0-9]{10}$/;  
			        return this.optional(element) || (length == 11 && mobile.test(value));  
			    }, "请填写正确的手机号码");  

				
				$("#reg_form").validate({
					rules:{
						userName:{
							required: true
					    },
				      	teamName:{
							required: true
					    },
						groups:{
							required: true
						},
						contacts:{
							required: true
						},
						mobile:{
							required: true,
							isMobile: true,
			                maxlength:11,
			                minlength:11
						},
						email:{
							required: true,
							email:true
						},
						pwd:{
							required:true
						},
						confirmpassword:{
							required: true,
							equalTo:"#pwd"
						}
					},
					messages:{
						userName:{
							required:"请填写单位名称!"
					    },
					    teamName:{
							required:"请填写团队名称!"
					    },
					    groups:{
							required: "请选择分组!"
						},
						contacts:{
							required: "请填写联系人!"
						},
						mobile:{
							required: "请填写手机!"
						},
						email:{
							required: "请填写邮箱!",
							email:"邮箱格式不正确!"
						},
						pwd:{
							required:"请填写密码!"
					    },
					    confirmpassword:{
							required: "请再次填写密码!",
							equalTo:"两次输入密码不一致!"
						}
					},
					submitHandler:function(form){
						
						if (isSubmit){
							isSubmit = false;
							var pwd=$('#pwd').val();
							var confirmpassword=$('#confirmpassword').val();
							var userName=$('#userName').val();
							var teamName=$('#teamName').val();
							var groups=$('#groups').val();
							var contacts=$('#contacts').val();
							var mobile=$('#mobile').val();
							var email=$('#email').val();
							
							$.ajax({
								  type: 'POST',
								  url: '/api/user/save',
								  dataType:'json',
								  data: {
									  pwd:pwd,
									  userName:userName,
									  teamName:teamName,
									  groups:groups,
									  contacts:contacts,
									  mobile:mobile,
									  email:email
								  },
								  success: function(data){
									  var status=data.status;
										if(status==1){//注册成功
											bootbox.dialog({
												message:"注册成功,请返回首页登录",
													buttons:{
														"success":{
															"label":"OK",
															"className":"btn-sm btn-primary",
															"callback": function () {
																$('#pwd').val("");
																$('#confirmpassword').val("");
																$('#userName').val("");
																$('#groups').val("");
																$('#contacts').val("");
																$('#mobile').val("");
																$('#email').val("");
																
																window.location.href='<webpath:path/>/';
									                        }
														}
													}
												});
											
										}else{
											isSubmit = true;
											var message=data.message;
											if(message=="userIsExist_mobile"){
												bootbox.dialog({
													message:"手机号已被使用，注册失败！",
													buttons:{
														"success":{
															"label":"OK",
															"className":"btn-sm btn-primary"
		
														}
													}
												});
											}else if(message=="userIsExist_teamName"){
												bootbox.dialog({
												message:"团队名称已存在，注册失败！",
												buttons:{
													"success":{
														"label":"OK",
														"className":"btn-sm btn-primary"
														}
													}
												});
											}
											
										}
									  }
								});
						}
						
					}
				});
			});
		</script>
