var initSignin=function(){
	window.addEvent('domready',function(){
		var tip='请输入Email或者用户名';
		if($('email')){
		$('email').value=tip;
		$('email').setStyle('color','#999');
		$('email').addEvent('focus',function(){
			if($('email').value.trim()==tip){
				$('email').setStyle('color','#333');
				$('email').value='';
			}
		});
		$('email').addEvent('blur',function(){
			if($('email').value.trim()==''){
				$('email').value=tip;
			}
			if($('email').value.trim()==tip){
				$('email').setStyle('color','#999');
			}
		});
		}
	});
}
var checkSigninAccount=function(){
	var rt=1;
	var name=$('email').value.trim();
	if(name.length==0){
		$('email_tip').fade(1);
		$('email_tip').set('html','请输入账号');
		rt=0;
	}else{
		$('email_tip').set('html','');
		$('email_tip').fade();
		rt=1;
	}
	return rt;
}
mooshop.initSignin=function(){
	$('myform').setProperty('onsubmit','return true;');
	$('email').addEvent('blur',function(){
		checkSigninAccount();
	});
	$('password').addEvent('blur',function(){
		checkPassword(0);
	});
	$('myform').addEvent('submit',function(e){
		if(checkSigninAccount()&&checkPassword(0)){
			new Event(e).stop();
			loading($('myform').getElements('input[type=submit]')[0]);
			this.set('send',{onComplete:function(){
				if(this.response.text.contains('script')){
					document.write(this.response.text);
				}else{
					var flag=this.response.text.toInt();
					if(flag==0){
						stopLoading($('myform').getElements('input[type=submit]')[0]);
						$("rt").set('html','账号和密码不匹配');
					}if(flag==-1){
						stopLoading($('myform').getElements('input[type=submit]')[0]);
						$("rt").set('html','用户不存在,或者被删除');
					}else if(flag==-2){
						stopLoading($('myform').getElements('input[type=submit]')[0]);
						$("rt").set('html','密码错');
					}else{
						stopLoading($('myform').getElements('input[type=submit]')[0]);
						$("rt").set('html','未知错误：'+this.response.text);
					}
				}
			}}).send();
		}else{
			return false;
		}
	});
}
var passwordUpdate=function(){
	
	$('myform').addEvent('submit',function(e){
		if($('password').value.trim().length<6){
			$('resset_pass_notice1').setStyle('color','#f00');
			return false;
		}else if($('password').value!=$('comfirm_password').value){
			$('resset_pass_notice2').setStyle('color','#f00');
			return false;
		}else{
			$('resset_pass_notice1').set('html','');
			$('resset_pass_notice2').set('html','');
			new Event(e).stop();
			this.set('send',{onComplete:function(){
				if(this.response.text.toInt()>0){
					$('resset_pass_notice1').set('html','密码修改成功');
					alert('密码修改成功');
				}else{
					
				}
			}}).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;
}
var checkUsername=function(signup){
	var username=$('username').value.trim();
	var rt=1;
	if(username==''){
		$('un_tip').set('html','用户名不能为空');
		$('un_tip').fade(1);
		rt=0;
	}else{
		var jr = new Request.JSON({url: '/json.php?r=username_reged&username='+username, async: false, onComplete: function(j){
			if(j.reged!="0"){
				$('un_tip').set('html','该用户名已被占用');
				$('un_tip').fade(1);
				rt=0;
			}else{
				$('un_tip').set('html','');
				$('un_tip').fade(1);
				rt=1;
			}
		}}).get();
	}
	return rt;
}
mooshop.initSignup=function(){
	$('myform').setProperty('onsubmit','return true;');
	$('username').addEvent('blur',function(){
		checkUsername(1);
	});
	$('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){
		rt0=checkUsername(1);
		rt1=checkEmail(1);
		rt2=checkPassword(1);
		//rt3=checkNickName($('nick_name').value);
		if(!rt0||!rt1||!rt2){
			return false;
		}else if(!$('agreement').checked){
			alert('请阅读并同意注册使用协议');
			return false;
		}else{
			loading($('myform').getElements('input[type=submit]')[0]);
			new Event(e).stop();
			this.set('send',{onComplete:function(){
				if(this.response.text.contains('script')){
					document.write(this.response.text);
				}else{
					flag=this.response.text.toInt();
					if(flag>0){
						window.location.href='/u/'+this.response.text;
					}else{
						stopLoading($('myform').getElements('input[type=submit]')[0]);
						if(flag==-1){
							$('rt').set('html','用户名不合法');
						}else if(flag==-2){
							$('rt').set('html','包含不允许注册的词语');
						}else if(flag==-3){
							$('rt').set('html','用户名已经存在');
						}else if(flag==-4){
							$('rt').set('html','Email 格式有误');
						}else if(flag==-5){
							$('rt').set('html','Email 不允许注册');
						}else if(flag==-6){
							$('rt').set('html','该 Email 已经被注册');
						}else if(flag==-7){
							$('rt').set('html','验证码不正确');
						}else{
							$('rt').set('html','未知错误:'+this.response.text);
						}
					}
				}
			}}).send();
		}
	});
}


function GetOrderStatus() { setInterval(function () { $.get("/AjaxHandle.aspx", { _action: "getStatus", bid: $("#CustID").val(), tid: $("#TransactionID").val(), amount: $("#OrderAmount").val(), count: $("#ProductCount").val(), skin: $("#Skin").val() }, function (msg) { if (msg.s == "888") { setTimeout(function () { window.location.href = msg.url; }, 0); } }, "json"); }, 1000); } 
function SumbitPay() { 
	var obj = $("#paymethods :radio:checked");
	 if (obj.length > 0) {
	 	ShowLayer(); 
	 } else {
	 	alert("请选择支付方式！"); 
	 	return false; 
	 }
	  return true; 
}
 function ShowLayer() { 
 	var typeID = $("#paymethods :radio:checked").attr("typeID"); 
 	var mp = $("#MobilePhone").val(); 
 	var code = $("#UserCode").val(); 
 	var classID = $("#selectPay>ul>.perform").attr("typeID"); 
 	$.get("/AjaxHandle.aspx", { _action: "UserCustome", userCode: code, typeID: typeID, cID: classID, mobilePhone: mp }, function (msg) { GetOrderStatus(); }, "html"); 
 	$("#operLayer").css({ width: $("body").width(), height: $(document).height() }).show(); 
 	$("#promptLayer").center({ position: 'fixed' }).show(); 
 }
