/*
 * register funciton
 * @date 2008-03-15
 */


function getSignForm(res){
		var w=new _$w()
		globalWin=w;		
		currentInput=res;
		w.content(res.responseText);
		var titleName   = "注册";
		var closeName 	= "关闭";
		var regName 	= "注册";
		w.title(titleName);		
		w.width(450);
		w.add_bt({"value":closeName,"type":"button"});
		w.show();
		w.height();
		window.resumeDialogWindow = w;
		selectOpt();
}
function submitSign()
{
	if(Sign.checkForm(document.signform))
	{
		Sign.setValue(document.signform,'正在注册...',true);
		document.signform.submit();
	}
}
var Sign=new function(){//注册类
	var validateOK="验证成功";
	var userInfo=["用户名只能为6-16个字符","用户名由数字、英文组成"];
	var nameInfo=["请填写你的姓","请填写你的名字"];
	var jobInfo=["请填写你的职位头衔"];
	var compInfo = ["请填写公司名称"];
	var Indus = ["请填写行业名称"];
	var dateInfo = ["请选择开始年限","请选择结束年限","请选择开始月份","请选择结束月份","请选择入职年限","请选择入职月份","日期错误"];
	var schoolN = ["请输入学校名称"];
	var pswInfo=["6-15位","不能包含中文, 全角符号, &符号","与密码不一致"];
	var fNameFlag,lNameFlag,jobFlag,passFlag,repassFlag,emailFlag,validateFlag,compFlag,curIndusFlag,yearBeginFlag,monthBeginFlag,yearEndFlag,monthEndFlag,schoolFlag,yearFlagE,monthFlagE;
	this.showInfo=function(id,info,flag){
		try{
			$.$(id).innerHTML=info;
			$.$(id).className=(flag?"success":"error");
			if(flag)$.$(id.replace("s_","")).removeAttribute("style");
			else $.$(id.replace("s_","")).style.border="1px solid #ECA11F";
		}catch(e){}
	}
	this.checkFirstName=function(obj){
		var infoBox="s_"+obj.id,value=obj.value,self=this;
		if(!limitLen(value,1,50)){
			this.showInfo(infoBox,nameInfo[0]);
			fNameFlag=false;	
		}
		else{
			this.showInfo(infoBox,validateOK,true);	
			fNameFlag=true;
		}
	}
	this.checkLastName=function(obj){
		var infoBox="s_"+obj.id,value=obj.value,self=this;
		if(!limitLen(value,1,50)){
			this.showInfo(infoBox,nameInfo[1]);
			lNameFlag=false;	
		}
		else{
			this.showInfo(infoBox,validateOK,true);	
			lNameFlag=true;
		}
	}
	this.checkJobtitle=function(obj){
		var infoBox="s_"+obj.id,value=obj.value,self=this;
		if(!limitLen(value,2,50)){
			this.showInfo(infoBox,jobInfo[0]);
			//alert(jobInfo[0]);
			jobFlag=false;	
		}
		else{
			this.showInfo(infoBox,validateOK,true);	
			jobFlag=true;
		}
	}
	//this is addded by denisdeng
	this.checkCompanyName = function(obj){
		var infoBox="s_"+obj.id,value=obj.value,self=this;
		if(!limitLen(value,2,50)){
			this.showInfo(infoBox,compInfo[0]);
			compFlag=false;	
		}
		else{
			this.showInfo(infoBox,validateOK,true);	
			compFlag=true;
		}
	}
	this.checkCurIndustry = function(obj){
		var infoBox="s_"+obj.id,value=obj.value,self=this;
		if(!limitLen(value,2,50)){
			this.showInfo(infoBox,Indus[0]);
			curIndusFlag=false;	
		}
		else{
			this.showInfo(infoBox,validateOK,true);	
			curIndusFlag=true;
		}
	}
	this.checkSchoolName = function(obj){
		var infoBox="s_"+obj.id,value=obj.value,self=this;
		if(!limitLen(value,2,50)){
			this.showInfo(infoBox,schoolN[0]);
			schoolFlag=false;	
		}
		else{
			this.showInfo(infoBox,validateOK,true);	
			schoolFlag=true;
		}
	}
	this.checkYearE = function(obj){
		var infoBox="s_"+obj.id,value=obj.value,self=this;
		if(!limitLen(value,2,50)){
			this.showInfo(infoBox,dateInfo[4]);
			yearFlagE=false;	
		}
		else{
			this.showInfo(infoBox,validateOK,true);	
			yearFlagE=true;
		}
	}
	this.checkMonthE = function(obj){
		var infoBox="s_"+obj.id,value=obj.value,self=this;
		if(!limitLen(value,1,50)){
			this.showInfo(infoBox,dateInfo[5]);
			monthFlagE=false;	
		}
		else{
			this.showInfo(infoBox,validateOK,true);	
			monthFlagE=true;
		}
	}
	this.checkYear = function(obj){
		var infoBox="s_"+obj.id,value=obj.value,self=this;
		if(!limitLen(value,2,50)){
			if(infoBox.indexOf("begin") >0 ){
				yearBeginFlag=false;	
			}else if(infoBox.indexOf("end") >0 ){
				yearEndFlag=false;	
			}
			infoBox = infoBox.replace('begin','');
			infoBox = infoBox.replace('end','');
			infoBox = infoBox.replace('_y','');
			infoBox = infoBox.replace('_m','');			
			this.showInfo(infoBox,dateInfo[6]);
		}
		else{	
			if(infoBox.indexOf("begin") >0)
				yearBeginFlag=true;
			else if(infoBox.indexOf("end") >0 ){
				yearEndFlag=true;	
			}
			infoBox = infoBox.replace('begin','');
			infoBox = infoBox.replace('end','');
			infoBox = infoBox.replace('_y','');
			infoBox = infoBox.replace('_m','');
			if(yearEndFlag&&yearBeginFlag&&monthBeginFlag&&monthEndFlag)
				this.showInfo(infoBox,validateOK,true);
		}
	}
	this.checkMonth = function(obj){
		var infoBox="s_"+obj.id,value=obj.value,self=this;
		if(!limitLen(value,1,50)){
			if(infoBox.indexOf("begin") >0 ){				
				monthBeginFlag=false;
			}else if(infoBox.indexOf("end") >0 ){				
				monthEndFlag=false;
			}
			infoBox = infoBox.replace('begin','');
			infoBox = infoBox.replace('end','');
			infoBox = infoBox.replace('_y','');
			infoBox = infoBox.replace('_m','');
			this.showInfo(infoBox,dateInfo[6]);
		}
		else{				
			if(infoBox.indexOf("begin") >0)
				monthBeginFlag=true;
			else if(infoBox.indexOf("end") >0 ){
				monthEndFlag=true;	
			}
			infoBox = infoBox.replace('begin','');
			infoBox = infoBox.replace('end','');
			infoBox = infoBox.replace('_y','');
			infoBox = infoBox.replace('_m','');
			if(yearEndFlag&&yearBeginFlag&&monthBeginFlag&&monthEndFlag)
				this.showInfo(infoBox,validateOK,true);
		}
	}
	//this is addded by denisdeng
	this.checkUser=function(obj){
		var infoBox="s_"+obj.id,value=obj.value,self=this;
		if(!limitLen(value,6,16)){
			this.showInfo(infoBox,userInfo[0]);
			userFlag=false;	
		}
		else if(!hasAccountChar(value)){
			this.showInfo(infoBox,userInfo[1]);
			userFlag=false;	
		}
		else{
			({}).sendAjax("../space/signup.php?user_name="+value+"&op=checkName&r="+Math.random(),{ //modify by michael
				onSuccess:function(){
					var msg=parseReturnMsg(this.responseXML);
					self.showInfo(infoBox,msg.description,msg.status=="ok"?true:false);
					if(msg.description=="恭喜你,此用户名可以注册!") userFlag=true;
					else userFlag=false;
				}
			});
		}
	}
	this.checkPsw=function(obj,repeat){
		var infoBox="s_"+obj.id,value=obj.value,infoBox2=repeat?"s_"+obj.id.slice(3):"s_re_"+obj.id,v2=$.$(repeat?obj.id.slice(3):"re_"+obj.id).value;
		if(!limitLen(value,6,15)){
			this.showInfo(infoBox,pswInfo[0]);
			if(!repeat){
				passFlag=false;
			}else{
				repassFlag=false;	
			}
		}
		else if(hasChineseChar(value)){
			this.showInfo(infoBox,pswInfo[1]);
			if(!repeat){
				passFlag=false;
			}else{
				repassFlag=false;	
			}
		}
		else{
			if(v2.trim()!=""||repeat){
				if(value.trim()!=v2.trim()){
					this.showInfo(repeat?infoBox:infoBox2,pswInfo[2]);
					repassFlag=false;	
				}
				else {
					this.showInfo(repeat?infoBox:infoBox2,validateOK,true);
					repassFlag=true;
				}
			}
			if(!repeat){
				this.showInfo(infoBox,validateOK,true);	
				passFlag=true;
			}
		}
		if(value.indexOf("&") != -1)
		{
			this.showInfo(infoBox,pswInfo[1]);
			userFlag=false;	
		}
	}
	this.checkEmail=function(obj){
		var infoBox="s_"+obj.id,value=obj.value,flag=isEmail(value),self = this;
		if(!flag){
			this.showInfo(infoBox,"格式不正确");
			emailFlag=false;
		}
		else if(value.length<5){
			this.showInfo(infoBox,"请输入常用邮件");
			emailFlag=false;	
		}
		else {
			({}).sendAjax("../space/signup.php?user_email="+value+"&op=checkEmail&r="+Math.random(),{//modify by michael
				onSuccess:function(){
					var msg=parseReturnMsg(this.responseXML);
					self.showInfo(infoBox,msg.description,msg.status=="ok"?true:false);					
					if(msg.description=="该邮箱可用") emailFlag=true;
					else emailFlag=false;					
				}
			});
		}
		//this.showInfo(infoBox,validateOK,true);
	}
	this.checkLogo=function(obj){
		var infoBox="s_"+obj.id,value=obj.value,ext=value.slice(value.lastIndexOf(".")).toLowerCase();
		if(!".jpg,.gif,.jpeg,.png".inStr(ext)){
			this.showInfo(infoBox,"你的文件不是图片文件!");
			obj.removeAttribute("style");
		}
		else{
			this.showInfo(infoBox,validateOK,true);
			$.$("preview").innerHTML=$.browser.firefox?"你已经选择文件:<br />"+value.slice(value.lastIndexOf("\\")+1):'<img src="'+value+'" width="100px" alt="'+value+'" title="'+value+'" />';
		}
	}
	this.checkLogo2=function(obj,emptyTip){
		if(obj.value=="" && emptyTip){
			msg("你还没有选择图片");
			return false;
		} else if (obj.value==""){
			return false;	
		}
		var infoBox="s_"+obj.id,value=obj.value,ext=value.slice(value.lastIndexOf(".")).toLowerCase();
		if(!".jpg,.gif,.jpeg,.png".inStr(ext)){
			msg("你的文件不是图片文件!");
			obj.removeAttribute("style");
			return false;
		}
		else{
		//	this.showInfo(infoBox,validateOK,true);
			$.$("preview").innerHTML=$.browser.firefox?"你已经选择文件:<br />"+value.slice(value.lastIndexOf("\\")+1):'<img src="'+value+'" width="100px" alt="'+value+'" title="'+value+'" />';
			return true;
		}
	}
	this.checkValidate=function(obj,fun,fun2){
		var infoBox="s_"+obj.id,value=obj.value.trim(),self=this;
		if(value.length==0){
			this.showInfo(infoBox,"请输入验证码");
			validateFlag=false;	
		}
		else{
			({}).sendAjax("../space/verify.php?validate="+value+"&op=checkNum&r="+Math.random(),{ // modify by michael
				onSuccess:function(){
					var msg=parseReturnMsg(this.responseXML);
					self.showInfo(infoBox,msg.description,msg.status=="ok"?true:false);
					if(msg.description=="验证码正确"){
						validateFlag=true;
						if(fun) fun();
					}else{
						validateFlag=false;
						if(fun2) fun2();
					}
				}
			});
		}
	}
	this.setValue=function(obj,value,disabled){
		try{
			$.$(obj).value=value;
			$.$(obj).disabled=disabled||false;
		}catch(e){}
	}
	this.getStyle = function ( elem, name ) {
		if (elem.style[name])
			return elem.style[name];
		else if (elem.currentStyle)
			return elem.currentStyle[name];
		else if (document.defaultView && document.defaultView.getComputedStyle) {
			name = name.replace(/([A-Z])/g,"-$1");
			name = name.toLowerCase();
		var s = document.defaultView.getComputedStyle(elem,"");
			return s && s.getPropertyValue(name);
		} else
		return null;
	}
	this.checkForm=function(fm){
		
		var hash=$F(fm),items=["email","pass","re_pass","validate"];
		for(var i=0,length=items.length;i<length;i++){
			(function(){if(hash[items[i]]==""){
					var isNone = Sign.getStyle($.$(items[i]).parentNode.parentNode,"display");
					if(isNone !== "none"){
						fm[items[i]].focus();						
						return false;
					}
					else
					{
						
					}
			}
		})()
		//fm[items[0]].focus();
		}		
		if(passFlag && repassFlag && emailFlag && validateFlag ){
			if((compFlag == true || typeof compFlag == 'undefined') && (curIndusFlag == true || typeof curIndusFlag == 'undefined')　&& (yearBeginFlag == true || typeof yearBeginFlag == 'undefined') && (monthBeginFlag == true || typeof monthBeginFlag == 'undefined') && (yearEndFlag == true || typeof monthBeginFlag == 'undefined') && (monthEndFlag == true || typeof monthEndFlag == 'undefined') && (schoolFlag == true || typeof schoolFlag == 'undefined') && (jobFlag == true || typeof jobFlag == 'undefined') && (monthFlagE == true || typeof monthFlagE == 'undefined') && (yearFlagE == true || typeof yearFlagE == 'undefined')){
				return true;
			}else{}
		} else {
			return false;
		}
	}
}
function signCallback(xml){//提交注册的返回调用方法
	var msg=parseReturnMsg(xml);
	if(msg.status=="ok"){
		Sign.setValue("next_step",'注册成功并跳转...',true);
		location.href=msg.description;
	}else{
		Sign.setValue("next_step",'提交，完成注册',false);
		showAlert("错误",msg.description,null,4);
	}
}
var Login=new function(){//登录类
	var btnSubmit=null;
	
	var login=function(hash){
		var remember=hash.remember=="1"?1:0;
		({}).sendAjax("../space/login.php?op=checkLogin&user_name="+hash.user_name+"&pass="+hash.pass+"&url="+hash.url+"&act="+hash.act+"&code="+hash.code+"&remember="+remember+"&r="+Math.random(),{
			onSuccess:function(){				
				var msg_result=parseReturnMsg(this.responseXML);				
				if(msg_result.status=="ok"){
					Sign.setValue(btnSubmit,"跳转中...",true);					
					location.href=msg_result.description;
				}else{
					Sign.setValue(btnSubmit,"立即登录",false);
					msg(msg_result.description);
				}
			}
		});
	}
	this.check=function(fm){	
		var hash=$F(fm),items=["user_name","pass"],info=["你的用户名输入有误，请检查！","密码不可为空！"];
		btnSubmit=fm.btnLogin;
		for(var i=0,length=items.length;i<length;i++){
			if(hash[items[i]]==""){
				msg(info[i]);
				return;
			}
		}
		Sign.setValue(btnSubmit,"登录中...",true);
		login(hash);
	}
	this.reloadValidate=function(id){
		try{
			var obj=$.$(id),src=obj.src;
			obj.src=src.substr(0,src.indexOf("?")!=-1?src.indexOf("?"):src.length)+"?r="+Math.random();
		}catch(e){}
		return false;
	}
	var showInfo=function(str){
		try{
			$.$("getPassTip").innerHTML=str;
		}catch(e){}
	}
}
function signValidate(){
	var id="validate",val=$.$("validate").value,oMsg=$.appfn("msg_server");
	if(val.length>0){
		oMsg.sendAjax("../space/verify.php?op=checkNum&"+id+"="+val.trim()+"&r="+Math.random(),{
			onSuccess:function(){
				var msg=parseReturnMsg(this.responseXML);
				showAlert("提示",msg.description,null,msg.status=="ok"?3:4);
			}
		});
	}
}