function reg(){}

var _f = reg.prototype;

_f.loginandreg = function(username){
	return '<img src="images/x_02.gif" width="166px" height="22px" class="float_left" alt="让我的相册动起来" /><span class="float_right">欢迎您，'+username+" <a href=\""+myurl+"/mymolihe.asp\">管理中心</a> <a href=\"index.asp?action=logout\">退出</a>&nbsp;&nbsp;[<a href=\"javascript:window.external.AddFavorite('"+myurl+"','"+my_name+"');\">收藏本站</a>] </span>";
}
_f.checkusername = function(username){
	var msg,ir;
	ir = 0;
	if(username){
		if(!(/^[\w\.-]{4,}$/).test(username)){
			msg = "帐号格式错误！";	
		}else{
			var _ajax = new ajax();
			var isReg = _ajax.StartRequest("./index.asp?action=checkinfo&type=1&value="+username,"text","");
			if (isReg=="0"){
				msg = "填写正确！";	
				ir = 1;
			}else{
				if(isReg=="1"){
					msg = "该用户名已经被使用！";	
				}else{
					msg = "异常错误，请稍后访问！";
				}
			}
		}
	}else{
		msg = "请输入用户名！";
	}
	this.DisPlayError("m_username",msg,ir);
	return ir;
}

//验证Email
_f.checkemail = function(em){
	var msg,ir;
	ir = 0;
	if(em){
		msg = !(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/).test(em) ? "邮箱格式不正确×":"邮箱可以使用！";
		if(msg=="邮箱可以使用！"){
			var _ajax = new ajax();
			var isReg = _ajax.StartRequest("./index.asp?action=checkemail&email="+em,"text",this.check);
			if (isReg==0){
				msg = "填写正确！";	
				ir = 1;
			}else{
				msg = "该邮箱已被占用！";	
			}
		}
	}else{
		msg = "请输入邮箱！";	
	}
	this.DisPlayError("m_email",msg,ir);
	return ir;
}

//检验是否选择类型
_f.checktype = function(){
	var msg,ir;
	ir = 0;
	msg = "请选择用户类型！";
	var obj = document.register.type;
	for(var i=0;i<obj.length;i++){
		if(obj[i].checked==true){
			ir = 1;
			msg = "填写正确！";
			break;
		}
	}
	this.DisPlayError("m_type",msg,ir);
	return ir;
}

_f.gettypevalue = function(){
	var obj = document.register.type;
	for(var i=0;i<obj.length;i++){
		if(obj[i].checked==true){
			return obj[i].value;
			break;
		}
	}
}

//验证密码
_f.checkpwd = function(pwd){
	var msg,ir;
	ir = 0;
	if(pwd){
		if((/^[^ ]{6,}$/).test(pwd)){
			msg = "填写正确√";
			ir = 1;
	}else{
			msg = "密码格式错误×";
		}	
	}
	else{
		msg = "请输入密码!";
	}
	this.DisPlayError("m_pwd",msg,ir);
	return ir;
}

//验证确认密码
_f.checkpwd_c = function(pwd){
	var msg,ir;
	ir = 0;
	if(pwd){
		if(!(/^[^ ]{6,}$/).test(pwd)){
			msg = "确认密码格式错误×";
		}else{
			if(pwd==document.register.pwd.value){
				msg = "填写正确√";	
				ir = 1;
			}else{
				msg = "两次输入的密码不一致！";	
			}
		}	
	}else{
		msg = "请输入确认密码！";
	}
	this.DisPlayError("m_pwd_c",msg,ir);
	return ir;
}

//验证验证码是否正确
_f.checknum = function(inputnum){
	var msg,ir;
	ir = 0;
	if(inputnum){
		var _ajax = new ajax();
		var isRight = _ajax.StartRequest("./index.asp?action=checknum&inputnum="+inputnum,"text","");
		if(isRight==1){
			msg = "输入正确√";
			ir = 1;
		}else{
			msg = "验证码输入错误×";
		}
	}else{
		msg = "请输入验证码×";
	}
	this.DisPlayError("m_inputnum",msg,ir);
	return ir;
}

//Err信息输出
_f.DisPlayError = function(IdName,Str,ir){
	if(document.getElementById(IdName)){
		document.getElementById(IdName).innerHTML = Str;
		document.getElementById(IdName).style.color = ir == 1 ? "#00AA00" : "#fe6600";
	}
}

_f.checkisagree = function(is){
	if(is){
		return "1";
	}else{
		alert("请确认同意我们的服务条款后注册！");
		return "0";
	}
}

_f.register = function(t){
	//alert(t);
	
		
	var f = document.register;
	//alert (this.checknum(f.num.value));
	var fi = f.email.value.split("@");
	if(this.checkisagree(f.isagree.checked)=="1" && this.checkemail(f.email.value)=="1" && this.checkpwd(f.pwd.value)=="1" && this.checkpwd_c(f.pwd_c.value)=="1" && this.checknum(f.num.value)=="1"){
		
		//if(!confirm("确定要注册"+f.email.value.replace(/ /g,"")+"吗？")){
		//	return;
		//}
		
		var _e = new events();
		var _ajax = new ajax();
		var url = "./index.asp?action=register&pwd=" + f.pwd.value + "&email=" + f.email.value + "&num=" + f.num.value;
		//_e.status();
		var result = _ajax.StartRequest(url,"text","");
		/*
		 * 注册程序，结果返回
		 * 0，验证码输入错误
		 * 1，用户名格式错误
		 * 2，密码格式不正确
		 * 3，邮箱格式错误
		 * 4，网络无法连接，请稍后访问
		 * 5，注册成功
		*/
		var err;
		switch(result){
			case "0":
				err = "验证码输入错误";
			 	break;
			case "1":
				err = "用户名格式错误";
			 	break;
			case "2":
				err = "密码格式错误";
			 	break;
			case "3":
				err = "邮箱格式错误";
			 	break;
			case "4":
				err = "网络无法连接，请稍后访问";
			 	break;
			case "5":
				err = "注册成功";
				//_ajax.StartRequest("./register_success.html","text","");
			 	break;
			case "301":
				err = "请不要连续注册多个用户！十分钟后才能继续注册";
			 	break;
			case "201":
				err = "用户名已经存在！";
				break;
			case "104":
				err = "异常错误，注册终止";
				break;
			default:
				err = "异常错误，注册被终止";
				break;
		}
		
		if (result != "5")
		{
			alert(err);
		}
		//_e.setopenwincontent("<br /><br />"+err+"<br /><br /><br />","100px");
		if(result=="5"){
			if(t=="0" || t=="")
			location.href = location.href;
			//location.href = myurl+"/html.asp?tmp=register_success.html";
			if(t=="1"){
				et.closewin();
				et.saveslide();
			}
			if(t=="2"){
				et.closewin();
				sl.editslide_save();
			}
			if(t=="3"){
				et.closewin();
				sl.stepbystep_displaytitle();
				sl.stepbystep_displaycontent();
			}

			if(t=="4"){
				document.getElementById("loginandreg").innerHTML = _f.loginandreg(fi['0']);
				et.closewin();
				location.href = location.href;
			}
		}
	}
}

_f.register_2 = function(){
	//alert(t);
	var f = document.register;
	//alert (this.checknum(f.num.value));
	var fi = f.email.value.split("@");
	
	if(this.checkemail(f.email.value)!="1") {
		this.DisPlayError("login_err_s","邮箱格式错误或该邮箱已注册",0);
		return false
	}
	if(this.checkpwd(f.pwd.value)!="1") {
		this.DisPlayError("login_err_s","密码格式错误",0);
		return false
	}
	if(this.checkpwd_c(f.pwd_c.value)!="1") {
		this.DisPlayError("login_err_s","密码不相同",0);
		return false
	}
		var _e = new events();
		var _ajax = new ajax();
		var url = "./index.asp?action=register&pwd=" + f.pwd.value + "&email=" + f.email.value + "&num=" + f.num.value;
		//_e.status();
		var result = _ajax.StartRequest(url,"text","");
		
		var err;
		switch(result){			
			case "0":
				err = "验证码输入错误";
			 	break;
			case "1":
				err = "用户名格式错误";
			 	break;
			case "4":
				err = "网络无法连接，请稍后访问";
			 	break;
			case "5":
				err = "注册成功";
			 	break;
			case "104":
				err = "异常错误，注册终止";
				break;
			default:
				err = "异常错误，注册被终止";
				break;
		}
		if(result=="5"){
			var formurl = document.getElementById('fromurl').value;
			if(formurl.length>0){
				location.href = formurl;
			}else{
				location.href = myurl;
			}
			return false;
		}
		if (document.getElementById('login_err_s')) {
			this.DisPlayError("login_err_s",err,0);
			return false;
		}
}

_f.getpass = function(){
	var l = document.getpass;
	/*if(l.username.value==""){
		this.DisPlayError("getpass_err","错误：请输入您的用户名",0);
		l.username.focus();
		return;
	}*/
	
	if(l.email.value==""){
		this.DisPlayError("getpass_err","错误：请输入您的邮箱",0);
		l.email.focus();
		return false;
	}

	if(!(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/).test(l.email.value)){
		this.DisPlayError("getpass_err","错误：邮箱格式不正确",0);
		l.email.focus();
		return false;
	}
	

	if(l.num.value==""){
		this.DisPlayError("getpass_err","错误：请输入右侧的验证码",0);
		l.num.focus();
		return false;
	}
	
	var _ajax = new ajax();
	var isRight = _ajax.StartRequest("./index.asp?action=checknum&inputnum="+l.num.value,"text","");
	if(isRight!="1"){
		this.DisPlayError("getpass_err","错误：验证码输入不正确",0);
		return false;
	}


	
	var isRight = _ajax.StartRequest("./index.asp?action=getpass&email="+l.email.value+"&num="+l.num.value,"text","");
	if(isRight=="1"){
		alert("您的新密码已经发送到您的邮箱！");
		window.close();
	}else{
		this.DisPlayError("getpass_err","错误：您输入的用户名或邮箱不正确",0);
	}
	return false;

}

_f.login = function(obj,t){
	if(obj){
		var l = obj;
		var errid = "login_err_s";
	}else{
		var l = document.login;
		var errid = "login_err";
	}
	var fi = l.email.value.split("@");
	if(l.email.value==""){
		this.DisPlayError(errid,"错误：请输入您的邮箱",0);
		l.email.focus();
		return false;
	}
	if(!(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/).test(l.email.value.replace(/ /g,""))){
		this.DisPlayError(errid,"错误：您输入的邮箱格式不正确",0);
		l.email.focus();
		return false;
	}
	if(l.pwd.value==""){
		this.DisPlayError(errid,"错误：请输入您的密码",0);
		l.pwd.focus();
		return false;
	}
	if(l.num.value==""){
		this.DisPlayError(errid,"错误：请输入右侧的验证码",0);
		l.num.focus();
		return false;
	}
	var issavelogin;
	if(l.issavelogin.checked){
		issavelogin = "on";
	}else{
		issavelogin = "";
	}
	
	var _ajax = new ajax();
	var isRight = _ajax.StartRequest("./index.asp?action=checknum&inputnum="+l.num.value,"text","");
	if (isRight!=1){
		this.DisPlayError(errid,"错误：验证码输入错误，请重新输入",0);
		l.num.focus;
		return false;
	}

	if(_ajax.StartRequest("./index.asp?action=checkemail&email="+l.email.value.replace(/ /g,""),"text","")=="0"){
	
		if(!confirm(l.email.value.replace(/ /g,"")+"这个邮箱用户还未注册，你如果确定要用此邮箱地址注册魔豆，请点[确定]即可注册成功并自动登录，否则请点[取消]。【友情提醒：请使用真实邮箱注册，以便您找回密码！】")){
			return;
		}
	}

	this.DisPlayError(errid,"系统正在验证您的登陆，请稍后……",0);
	var result = _ajax.StartRequest("./index.asp?action=login&num="+l.num.value+"&email="+l.email.value+"&pwd="+l.pwd.value+"&issavelogin="+issavelogin,"text","");
	//alert(result);
	var err;
	switch(result){
		case "0":
			err = "错误：验证码输入错误，请重新输入";
			break;
		case "1":
			err = "网络无法连接，请稍后访问…";
			break;
		case "2":
			err = "尚未通过确认，暂时无法登陆…";
			break;
		case "3":
			err = "已被管理员锁定账号，暂时无法登陆…";
			break;
		case "205":
			err = "错误：邮箱或密码输入错误…";
			break;
		case "204":
			err = "错误：您输入的密码错误…";
			break;
		case "301":
			err = "请不要连续注册多个用户！十分钟后才能继续注册";
			break;
		case "4":
			err = "登陆成功";
			break;
		case "5":
			err = "已成功注册，但要通过审核后才能登陆…";
			break;
		default:
			err = "异常错误，操作被终止";
			break;
	}
	if(result==4){
		var _e = new events();
		if(!obj){
			_e.setopenwincontent("<br /><br />"+err+"<br /><br /><br />","100px");
		}
		if(t=="0" || t=="" || t==null)
			if(obj){
				location.href = l.fromurl.value;
			}else{
				location.href = location.href;
			}
		if(t=="1"){
			et.closewin();
			et.saveslide();
		}
		if(t=="2"){
			et.closewin();
			sl.editslide_save();
		}
		if(t=="3"){
			sl.stepbystep_displaytitle();
			sl.stepbystep_displaycontent();
		}
		if(t=="4"){
			document.getElementById("loginandreg").innerHTML = _f.loginandreg(fi['0']);
			et.closewin();
			location.href = location.href;
		}
	}else{
		//alert(result);
		this.DisPlayError(errid,err,0);
		
	}
	return false;
}

_f.login_s = function(){
	var l = document.login_s;
	if(l.username.value==""){
		this.DisPlayError("login_err","错误：请输入您的用户名",0);
		l.username.focus();
		return;
	}
	if(l.pwd.value==""){
		this.DisPlayError("login_err","错误：请输入您的密码",0);
		l.pwd.focus();
		return;
	}
	if(l.num.value==""){
		this.DisPlayError("login_err","错误：请输入右侧的验证码",0);
		l.num.focus();
		return;
	}
	
	var issavelogin;
	if(l.issavelogin.checked){
		issavelogin = "on";
	}else{
		issavelogin = "";
	}
	
	var _ajax = new ajax();
	var isRight = _ajax.StartRequest("./checknum.asp?inputnum="+l.num.value,"text","");
	if (isRight!=1){
		this.DisPlayError("login_err_s","错误：验证码输入错误，请重新输入",0);
		l.num.focus;
		return;
	}
	this.DisPlayError("login_err_s","系统正在验证您的登陆，请稍后……",0);
	var result = _ajax.StartRequest("./login.asp?num="+l.num.value+"&username="+l.username.value+"&pwd="+l.pwd.value+"&issavelogin="+issavelogin,"text","");
	//alert(result);
	var err;
	switch(result){
		case "0":
			err = "错误：验证码输入错误，请重新输入";
			break;
		case "1":
			err = "网络无法连接，请稍后访问…";
			break;
		case "2":
			err = "错误：您输入的用户名不存在…";
			break;
		case "3":
			err = "错误：您输入的密码错误…";
			break;
		case "4":
			err = "登陆成功";
			break;
		default:
			err = "异常错误，操作被终止";
			break;
	}
	if(result==4){
		//var _e = new events();
		//_e.setopenwincontent("<br /><br />"+err+"<br /><br /><br />","100px");
		location.href = location.href;
		
		
	}else{
		this.DisPlayError("login_err_s",err,0);
	}
}

		