$(function(){
	$("a").focus(function(){this.blur()});
	//$(document).bind('contextmenu',function(){return false;});
	//$(document).bind('selectstart',function(){return false;});
});
//************************************************************
function Validate(o,r){
	reg = r;
	if(!reg.test($('#'+o).val())){
		return false;
	}else{
		return true;
	}	
}
//************************************************************
$(function(){
	$('#register').submit(function(){
		if (!Validate('username',/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/)){
			$('#username').focus();
			$('.username').html('必须以字母开头，使用字母、数字或下划线，5-20个字符');
			return false;
		}
		else{
			$('.username').html('');
		}		
		if (!Validate('password',/^(\w){5,20}$/)){
			$('#password').focus();
			$('.password').html('密码只能输入5-20个字母、数字、下划线');
			return false;
		}
		else{
			$('.password').html('');
		}		
		if($('#conpassword').val()!=$('#password').val()){
			$('#conpassword').focus();
			$('.conpassword').html('确认密码与密码不一致');
			return false;
		}
		else{
			$('.conpassword').html('');
		}		
		if($('#name').val()==""){
			$('#name').focus();
			$('.name').html('请输入您的姓名');
			return false;
		}
		else{
			$('.name').html('');
		}		
		if($('#phone').val()==""){
			$('#phone').focus();
			$('.phone').html('请输入您的电话');
			return false;
		}
		else{
			$('.phone').html('');
		}		
		if (!Validate('email',/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/)){
			$('#email').focus();
			$('.email').html('非法的电子邮件格式');
			return false;
		}
		else{
			$('.email').html('');
		}		
		var queryString = $("#register").formSerialize();
		$.post('jquery.php', queryString, 
			function(data){
				switch(data.state){
					case "success":
						alert(data.msg);
						window.location='index.html';
						break;
					case "failure":
						$(".username").html(data.msg);
						break;
					default:
						$(".username").html("系统故障");
				}
			}
		, "json");
		return false;
	});
});
$(function(){
	if ($('#pages_1').length>0){
		$('#pages_2').html($('#pages_1').html());
	}

});
//************************************************************
$(function(){
	if ($('#user_login').length>0){
		$.post('jquery.php', 'action=user_login', 
			function(data){
				switch(data.state){
					case "success":
						$('#user_login').html(data.html);
						break;
					default:
						alert('系统故障');
				}
			}
		, "json");
	}
});
//************************************************************
$(function(){
	$('#login').submit(function(){
		if($('#username').val()==""){
			$('#username').focus();
			alert('请输入用户名');
			return false;
		}
		if($('#password').val()==""){
			$('#password').focus();
			alert('请输入密码');
			return false;
		}
		if($('#checkcode').val()==""){
			$('#checkcode').focus();
			alert('请输入验证码');
			return false;
		}				
		var queryString = $("#login").formSerialize();
		$.post('jquery.php', queryString, 
			function(data){
				switch(data.state){
					case "success":
						window.location='index.html';
						break;
					case "failure":
						alert(data.msg);
						break;
					default:
						alert('系统故障');
				}
			}
		, "json");
		return false;
	});
});
//************************************************************
$(function(){
	$('#message').submit(function(){
		if($('#name').val()==""){
			$('#name').focus();
			$('.h_name').html('请输入您的姓名');
			return false;
		}
		else{
			$('.h_name').html('');
		}		
		if (!Validate('email',/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/)){
			$('#email').focus();
			$('.h_email').html('非法的电子邮件格式');
			return false;
		}
		else{
			$('.h_email').html('');
		}		
		if($('#title').val()==""){
			$('#title').focus();
			$('.h_title').html('请输入您的标题');
			return false;
		}
		else{
			$('.h_title').html('');
		}		
		if($('#content').val()==""){
			$('#content').focus();
			$('.h_content').html('请输入您的内容');
			return false;
		}
		else{
			$('.h_content').html('');
		}
		if($('#checkcode').val()==""){
			$('#checkcode').focus();
			$('.checkcode').html('请输入验证码');
			return false;
		}	
		else{
			$('.checkcode').html('');
		}
		var queryString = $("#message").formSerialize();
		$.post('jquery.php', queryString, 
			function(data){
				switch(data.state){
					case "success":
						alert(data.msg);
						window.location='message.php';
						break;
					case "failure":
						alert(data.msg);
						break;
					default:
						alert("系统故障");
				}
			}
		, "json");
		return false;		
	});   
});
//************************************************************
$(function(){
	$('#apply')	.submit(function(){
		if($('#name').val()==""){
			$('#name').focus();
			$('.name').html('请输入您的姓名');
			return false;
		}
		else{
			$('.name').html('');
		}		
		if (!Validate('email',/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/)){
			$('#email').focus();
			$('.email').html('非法的电子邮件格式');
			return false;
		}
		else{
			$('.email').html('');
		}		
		if($('#phone').val()==""){
			$('#phone').focus();
			$('.phone').html('请输入您的家庭电话');
			return false;
		}
		else{
			$('.phone').html('');
		}		
		if($('#mobile').val()==""){
			$('#mobile').focus();
			$('.mobile').html('请输入您的手机号码');
			return false;
		}
		else{
			$('.mobile').html('');
		}
		if($('#school').val()==""){
			$('#school').focus();
			$('.school').html('请输入您的拟报考学校');
			return false;
		}
		else{
			$('.school').html('');
		}		
		if($('#content').val()==""){
			$('#content').focus();
			$('.content').html('请输入您对培训的具体要求');
			return false;
		}
		else{
			$('.content').html('');
		}		
		var queryString = $("#apply").formSerialize();
		$.post('jquery.php', queryString, 
			function(data){
				switch(data.state){
					case "success":
						alert(data.msg);
						window.location='wsbm.html';
						break;
					case "failure":
						alert(data.msg);
						break;
					default:
						alert("系统故障");
				}
			}
		, "json");
		return false;
		
	});   
});
//************************************************************
$(function(){
	$('#update').submit(function(){
		if($('#password').val()!=""){
			if (!Validate('password',/^(\w){5,20}$/)){
				$('#password').focus();
				$('.password').html('密码只能输入5-20个字母、数字、下划线');
				return false;
			}
			else{
				$('.password').html('');
			}
		}		
		if($('#name').val()==""){
			$('#name').focus();
			$('.name').html('请输入您的姓名');
			return false;
		}
		else{
			$('.name').html('');
		}		
		if($('#phone').val()==""){
			$('#phone').focus();
			$('.phone').html('请输入您的电话');
			return false;
		}
		else{
			$('.phone').html('');
		}		
		if (!Validate('email',/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/)){
			$('#email').focus();
			$('.email').html('非法的电子邮件格式');
			return false;
		}
		else{
			$('.email').html('');
		}		
		var queryString = $("#update").formSerialize();
		$.post('jquery.php', queryString, 
			function(data){
				switch(data.state){
					case "success":
						alert(data.msg);
						window.location='member.php';
						break;
					case "failure":
						alert(data.msg);
						break;
					default:
						alert("系统故障");
				}
			}
		, "json");
		return false;
	});
});
