mooshop.initSignin=function(){
	$('myform').setProperty('onsubmit','return true;');
	$('myform').addEvent('submit',function(e){
		if($('username').value.trim()==''){
			$('rt').set('html','请填写用户名');
			return false;
		}else if($('password').value.trim()==''){
			$('rt').set('html','请填写密码');
			return false;
		}else{
			new Event(e).stop();
			loading($('myform').getElements('input[type=submit]')[0]);
			this.set('send',{onComplete:function(){
				if(this.response.text=="0"){
					stopLoading($('myform').getElements('input[type=submit]')[0]);
					$("rt").set('html','用户名和密码不匹配');
				}else{
					window.location.href=this.response.text;
				}
			}}).send();
		}
	});
}
var checkEmail=function(signup){
	var email=$('email').value;
	var emailReg = /^[_\.0-9a-zA-Z+-]+@([0-9a-zA-Z]+[0-9a-zA-Z-]*\.)+[a-zA-Z]{2,4}$/;
	var rt=1;
	if(!emailReg.exec(email)){
		$('email_tip').set('html','请输入正确的Email');
		$('email_tip').fade(1);
		rt=0;
	}else if(signup==1){
		var jr = new Request.JSON({url: '/json.php?r=email_reged&email='+email, async: false, onComplete: function(j){
			if(j.reged=="1"){
				$('email_tip').set('html','Email已被注册');
				$('email_tip').fade(1);
				rt=0;
			}else{
				$('email_tip').set('html','');
				$('email_tip').fade();
				rt=1;
			}
		}}).get();
	}else {
		$('email_tip').set('html','');
		$('email_tip').fade();
		rt=1;
	}
	return rt;
}
var checkPassword=function(signup){
	var rt=1;
	var pwLength=$('password').value.length;
	if(pwLength<3||pwLength>30){
		$('pw_tip').fade(1);
		$('pw_tip').set('html','密码应为3-30个字符');
		rt=0;
	}else if(signup==1){
		if($('password').value!=$('repassword').value){
			$('pw_tip').fade();
			$('repw_tip').fade(1);
			$('pw_tip').set('html','');
			$('repw_tip').set('html','两次输入密码不一致');
			rt=0;
		}else{
			$('pw_tip').set('html','');
			$('repw_tip').set('html','');
			$('pw_tip').fade();
			$('repw_tip').fade();
			rt=1;
		}
	}else {
		$('pw_tip').set('html','');
		$('pw_tip').fade();
		rt=1;
	}
	return rt;
}
var checkNickName=function(name){
	var rt=1;
	if(name.length==0){
		$('nname_tip').fade(1);
		$('nname_tip').set('html','请输入昵称');
		rt=0;
	}else if(name.length>30){
		$('nname_tip').fade(1);
		$('nname_tip').set('html','昵称不能超过30个字符');
		rt=0;
	}else{
		$('nname_tip').set('html','');
		$('nname_tip').fade();
		rt=1;
	}
	return rt;
}
mooshop.initSignup=function(){
	$('myform').setProperty('onsubmit','return true;');
	$('email').addEvent('blur',function(){
		checkEmail(1);
	});
	$('password').addEvent('blur',function(){
		checkPassword(1);
	});
	$('repassword').addEvent('blur',function(){
		checkPassword(1);
	});
	$('nick_name').addEvent('blur',function(){
		checkNickName($('nick_name').value);
	});
	$('myform').addEvent('submit',function(e){
		rt1=checkEmail(1);
		rt2=checkPassword(1);
		rt3=checkNickName($('nick_name').value);
		if(!rt1||!rt2||!rt3){
			return false;
		}else if(!$('agreement').checked){
			alert('请阅读并同意注册使用协议');
			return false;
		}else{
			new Event(e).stop();
			loading($('myform').getElements('input[type=submit]')[0]);
			this.set('send',{onComplete:function(){
				if(this.response.text.toInt()>0){
					window.location.href=$('redirecturl').value;
				}else{
					stopLoading($('myform').getElements('input[type=submit]')[0]);
					if(this.response.text.toInt()==-7){
						$('rt').set('html','验证码不正确');
					}else if(this.response.text.toInt()==-1){
						$('rt').set('html','未知错误');
					}else{
						$('rt').set('html','未知错误'+this.response.text);
					}
				}
			}}).send();
		}
	});
}
