// JavaScript Document
$(function(){
		var base_url = $("base").attr("href");
	   $("#register").live('click',function(){
	        //alert('1222');
			$("#memberFrame").html('');
			$("#backMit").show();
			$("#memberFrame").load(base_url+'member/register.php?'+Math.random());
			$("#memberFrame").show();
		});
	   
	   $("#member_login").live('click',function(){
			$("#memberFrame").html('');
			$("#backMit").show();
			$("#memberFrame").load(base_url+'member/login.php?'+Math.random());
			$("#memberFrame").show();
		});
        
        $('#finepass').live('click',function(){
			$("#memberFrame").html('');
            $("#backMit").show();
			$("#memberFrame").load(base_url+'member/finepass.php?'+Math.random());
			$("#memberFrame").show();
        });
	   
	   $("#clear").live('click',function(){
			$("#backMit").hide();
			$("#memberFrame").html('');
			$("#memberFrame").hide();
		});
        
        //刷新验证码
        $('#code').live('click',function(){
            $(this).attr('src', 'code.php?'+Math.random());
        })
        
        //注册
        $('#submitRegister').live('click',function(){
            //$('#registerFrame span').css('color', '#000').text(' *');
            var theField = $('#registerFrame').serialize();
            //判断输入
            var username = $('#username').val();
            var password = $('#password').val();
            var password2 = $('#password2').val();
            var email = $('#email').val();
            var code = $('#code').val();
            var emailFormat = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
            if(username == ''){
                //$('#username').next('span').css('color', 'red').text(' * 用户名不能为空!');
				alert('用户名不能为空!');
				$('#username').focus();
                return false;
            }
            if(password == ''){
                //$('#password').next('span').css('color', 'red').text(' * 密码不能为空!');
				alert('密码不能为空!');
				$('#password').focus();
                return false;
            }
            if(password2 != password){
                //$('#password2').next('span').css('color', 'red').text(' * 两次密码输入不同');
				alert('两次密码输入不同!');
				$('#password2').focus();
                return false;
            }
            if(code == ''){
                //$('#code').next('span').css('color', 'red').text(' * 验证码不能为空!');
				alert('验证码不能为空!');
				$('#code').focus();
                return false;
            }
            if(!emailFormat.test(email)){
               // $('#email').next('span').css('color', 'red').text(' * 电子邮箱格式错误!');
			   alert('电子邮箱格式错误!');
				$('#email').focus();
                return false;
            }
            //提交表单
            $.ajax({
                url:'member.php',
                timeout:10000,
                type:'post',
                datatype:'text',
                data:'action=register&'+theField,
                success:function(text){
                    alert(text);
                    $("#backMit").hide();
                    $("#memberFrame").html('');
                    $("#memberFrame").hide();
                }
            })
            return false;
        });
        
        //登陆
        $('#submitLogin').live('click',function(){
           // $('#loginFrameForm span').css('color', '#000').text(' *');
            var theField = $('#loginFrameForm').serialize();
            //判断输入
            var username = $('#username').val();
            var password = $('#password').val();
           // var code = $('#code').val();
            if(username == ''){
                //$('#username').next('span').css('color', 'red').text(' * 用户名不能为空!');
				alert('用户名不能为空!');
				$('#username').focus();
                return false;
            }
            if(password == ''){
                //$('#password').next('span').css('color', 'red').text(' * 密码不能为空!');
				alert('密码不能为空!');
				$('#password').focus();
                return false;
            }
            //if(code == ''){
               // $('#code').next('span').css('color', 'red').text(' * 验证码不能为空!');
               // return false;
           // }
            //提交表单
            $.ajax({
                url:'member.php',
                timeout:10000,
                type:'post',
                datatype:'text',
                data:'action=login&'+theField,
                success:function(text){
                    if(text=='登录成功')
					{
						window.location.reload();
					}
					else
					{
					    alert(text);	
					}
                    $("#backMit").hide();
                    $("#memberFrame").html('');
                    $("#memberFrame").hide();
                }
            })
            return false;
        });
        
        //发送密码
        $('#submitFinePass').live('click',function(){
            //$('#finePassFrame span').css('color', '#000').text(' *');
            var theField = $('#finePassFrame').serialize();
            //判断输入
            var username = $('#username').val();
            var email = $('#email').val();
            var code = $('#code').val();
            var emailFormat = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
            if(username == ''){
                //$('#username').next('span').css('color', 'red').text(' * 用户名不能为空!');
				alert('用户名不能为空');
				$('#username').focus();
                return false;
            }
            if(email == ''){
                //$('#email').next('span').css('color', 'red').text(' * 电子邮箱不能为空!');
				alert('电子邮箱不能为空');
				$('#email').focus();
                return false;
            }
            if(!emailFormat.test(email)){
                //$('#email').next('span').css('color', 'red').text(' * 电子邮箱格式错误!');
				alert('电子邮箱格式错误');
				$('#email').focus();
                return false;
            }
            if(code == ''){
                //$('#code').next('span').css('color', 'red').text(' * 验证码不能为空!');
				alert('验证码不能为空');
				$('#code').focus();
                return false;
            }
            //提交表单
            $.ajax({
                url:'member.php',
                timeout:10000,
                type:'post',
                datatype:'text',
                data:'action=sendPass&'+theField,
                success:function(text){
                    alert(text);
                    $("#backMit").hide();
                    $("#memberFrame").html('');
                    $("#memberFrame").hide();
                }
            })
            return false;
        })
	}
)
//
	   function member_login()
	   {
		   var base_url = $("base").attr("href");
			$("#memberFrame").html('');
			$("#backMit").show();
			$("#memberFrame").load(base_url+'member/login.php');
			$("#memberFrame").show();
	   } 
