//XPOW JavaScript Document © author:tf2199@yahoo.com.cn  {build:2007.12   lastUpdate:2009.3  version: 1.3.1}

var User = new Object();

User = {
	form : 'logfrom',
	type : 'type',
	pass : 'password',
	user : 'username',
	path : 'vlogin',
	doMain : 'http://passport.chndesign.'+xpow.point.Path.getApp(),
	isCookie : 'autologin',
	oKBtn : '',
	oPath : xpow.point.Path,
	oErr : '',
	doc : document,
	debug : false,
	userTree : '',
	isLoginNow : false,
	aCt : 'action,username,password,autoLogin,type,comefrom',
	aPs : '',
	qUy : '',
	nLg : 0,
	logOutUrl : top.location.href,
	isInit : false,
	cNi : 'showfaildmsg',
	init : function(){
		if (this.isInit){return}
		xpow.JSN.Init('/',this.path,1,this.cNi,0,0)
		this.aPs = this.path;this.nLg = 1
		this.oErr = xpow.point.Error
		this.oErr.title = ''
		this.userTree = xpow.Use('tree')
		this.setErrTree();
		this.RegLog()
		this.isInit = true
	},
	setErrTree : function(){
		this.userTree.addItem('aps','请输入用户名和密码！')
		this.userTree.addItem('nmorps','昵称/ID号，密码不正确！  或个人，企业用户选择错误！')
		this.userTree.addItem('hidden','您的账号没有被激活，请与站长联系！')
	},
	RegLog : function(){xpow.osEvent.attEventList('username,password','okp','User.Parse.Event()');xpow.osEvent.attEvent('user.login.btn','ock','User.parseLogin()')},
	getErrKey : function(key){ return this.userTree.getItem(key)},
	getELN : function(el){ return this.doc.getElementsByName(el)},
	parseErr : function(er){ this.oErr.setErr(er,this.getErrKey(er))},
	logErrOut : function(key){ this.init(); this.parseErr(key); this.oErr.Out(1,'','',2.2);this.doInit()},
	parseLogin : function(comfrom){
		if (this.isLoginNow)return
		this.oKBtn = $('_okBtn').innerHTML
		$('_okBtn').innerHTML='<font color=red>正在登陆...</font>'
		this.isLoginNow = true
		$(this.pass).disabled=true
		$(this.user).disabled=true
		//var tUser = inSpace(doFilter($(this.user).value,2));
		var tUser = inSpace($(this.user).value);
		var tPass = inSpace($(this.pass).value);
		var tType = this.getELN(this.type)[0].checked;
		var tCookie = $(this.isCookie).checked?'yes':'day';
		if (tUser==''||tPass==''){ this.parseErr('aps')}
		if (this.oErr.foundErr){this.logErrOut(); return}
		tType = (tType)?0:1
		var tCfm = ''
		if (parseInt(xpow.point.Cookie.get('apply.type'))>0 && xpow.point.Cookie.get('apply.url')!=''){$('comefrom').value = xpow.point.Cookie.get('apply.url') }
		comfrom = $('comefrom').value.split('/')
		for (var i in comfrom){if (i!='del'){tCfm += comfrom[i]+'$'}}
		tCfm = tCfm.substr(0,tCfm.length-1);
		this.qUy = 'login/'+encodeURI(tUser)+'/'+tPass.MD5()+'/'+tCookie+'/'+tType+'/'+encodeURI(tCfm)+'.html'
		xpow.JSN.format(this.aCt,this.qUy,'')
	},
	doSiteLogin : function(){
		xpow.JSN.Init('/',this.path,1,this.cNi,0,0)
		this.aPs = this.path
		this.nLg = 1
		this.oErr = xpow.point.Error
		this.oErr.title = ''
		this.userTree = xpow.Use('tree')
		this.setErrTree()
		this.RegLog()
	},
	doInit : function(){
		var defaultValue=''
		$(this.pass).value = defaultValue
		$(this.pass).disabled = false
		$(this.user).disabled = false
		this.isLoginNow = false
		//$('showfaildmsg').innerHTML = '&nbsp;'
		$('_okBtn').innerHTML = this.oKBtn
		$(this.user).focus()
		this.RegLog()
	},
	loginSucc : function(){
		var tForm,local
		$('_okBtn').innerHTML = '<B>登陆成功！</B>'
		tForm = $('comefrom').value
		local = this.doMain+'/passport.html?action=suc&timeStamp='+new Date().getTime();
		if (tForm!=''){local=tForm}
		xpow.point.Cookie.set('applyinfo','')
		window.location.href=local
	},
	loginED : function(){
		xpow.point.Path.Redirect('http://idea.chndesign.'+xpow.point.Path.getApp())
	},
	logout : function(){
		if (confirm('您确定退出当前用户登陆吗？')){window.location.href=this.getLogouturl()}
	},
	getLogouturl : function(){
		var tary = this.logOutUrl.toString().toLowerCase().split('/')
		if (tary.length>2){
			if (tary[3]=='myzone'){
				this.logOutUrl=xpow.point.Path.getDomain(1)
			}
		}
		this.oPath.setPath(this.logOutUrl)
		var local=this.doMain+'/logout.html?comefrom='+xpow.URLencode(this.oPath.getFPath().replace('.xpm',''))+'&timeStamp='+new Date().getTime();
		this.oPath.Clear()
		return local
	},
	doAddSocreBack : function(total,els,t,s){
		var intMsg = ''
		switch(t){
		case 0 : intMsg = '\n加分成功,此次共加分：'+s+' 分！\n\n您的总加分额度为：'+total+'分\n\n您今天的加分剩余：'+els+' 分'; break;
		case 1 : intMsg = '\n加分失败,此次共加分：'+s+' 分！\n\n您的总加分额度为：'+total+'分\n\n您今天的加分剩余：'+els+' 分'}
		$('score').value = ''
		$('scoreinner').innerHTML = '您的总加分额度为：'+total+'，今天剩余：'+els+' 分'
		alert(intMsg)
	},
	toUserSpace : function(chnid){return 'http://me.chndesign.'+xpow.point.Path.getApp()+'/'+chnid},
	toCorpSpace : function(chnid){return 'http://co.chndesign.'+xpow.point.Path.getApp()+'/'+chnid},
	Parse : {
		aCt : 'action,rename,type,needlogin',aDir : '',qUy : '',aPs : '',nLg : 0,cNi : 'showfaildmsg',app_qUy : '',
		init : function(){xpow.JSN.Init(this.aDir,this.aPs,1,this.cNi,0,0)},
		Parse : function(){xpow.JSN.format(this.aCt,this.qUy,'')},
		Name : function(n,t){
			this.init();
			this.qUy = 'parsename/'+xpow.URLencode(n)+'/'+t+'/'+this.nLg+this.app_qUy+'.html';
			this.Parse()
		},
		setApp : function(n,t,a,q){
			this.init();n = doFilter(n,2);
			this.qUy = 'parsename/'+xpow.URLencode(n)+'/'+t+'/'+this.nLg+q+'.html';
			this.aCt = 'action,rename,type,needlogin'+a
			this.Parse()
		},
		Client : function(){
			///(this.Client.caller)
			var re = xpow.m_cfg['ELEMT'].split(',')
			var vprop = 'name=Client,id=Client,align=absmiddle,width=86,height=21,cursor=pointer,title=点击更换验证码';
			//var vprop = 'name=Client,id=Client,align=absmiddle,width=66,height=29,cursor=pointer,title=点击更换验证码';
			if (!$('Client'))xpow.CreateElemt(re[7],vprop);
			$('Client').align='absmiddle'
			if ($('Client').width==0){
				if ($('Clients')){
					$('Clients').src='/captch/'+Math.random()
				}else{
					$('sClient').innerHTML = '<img style="cursor=pointer" align="absmiddle" title="更换验证码" id="Clients" name="Clients" src="/captch/'+Math.random()+'" width=86 height=21>'
				}
			}else{
				var vprop = 'name=Clients,id=Clients,align=absmiddle,width=0,height=0,title=点击更换验证码';
				if (!$('Clients'))xpow.CreateElemt(re[7],vprop);
				$('Client').src='/captch/'+Math.random()
				$('sClient').appendChild($('Client'))
			}
			xpow.osEvent.attEventList('Client,Clients','ock','User.Parse.Client()')
		},
		Statu : function(st){
			switch(st){
			case 'nologin':
				msg='无法检测您的登陆状态！'
				window.location.href = User.doMain+'/'
				window.parent.location.href = User.doMain+'/'
				break;
			}
		},
		Event : function(){xpow.osEvent.catchSrc();if(xpow.osEvent.cKeyCode==13){if (xpow.osEvent.cSrcElmt.name=='password' && !User.isLoginNow){User.parseLogin()}}else{xpow.osEvent.setEvent(9)}}},
	Mail : {
		channel : '',
		userid : '',
		box : '',
		mailcookie : xpow.Use('cookie'),
		M_MAILDEL : '确实要删除此信息吗?',
		aCt : 'action,channel',
		qUy : '',
		lines : {ids:''},
		oDLG : xpow.Use('dlg'),
		mDLG : '',
		mBox : '',
		moParm : '',
		readId : 0,
		init : function(){this.moParm = xpow.emObj.Parmas},
		Load : function(p){
			this.init()
			this.setMailBox()
			p=(p)?('&'+p):''
			this.lines.pages=p
			this.Close()
				
/*			xpow.JSN.Init('http://'+this.moParm.Channel+'.chndesign.'+xpow.point.Path.getApp()+'/',this.moParm.MailPS,1,this.moParm.MailStatu,0,2)
			if(xpow.point.Path.getDomain().toLowerCase()!='me'){
				this.reLoad()
				return
			}
*/			xpow.JSN.Init('/',this.moParm.MailPS,1,this.moParm.MailStatu,0,2)
			xpow.JSN.Send('loadmail&channel='+this.moParm.MailChannel+p)
			try{
			
			}catch(e){
				xpow.point.popClear()
				$(this.moParm.MailStatu).innerHTML = '<iframe id="loadmailframe" style="background:#F4F5EB" frameborder=0 width=452 height=380 src="'+xpow.JSN.QueryString+'&skin=default"></iframe>'
			}
		},
		/*reLoad : function(){
			var tobj=$('loadmailframe')
			if(!tobj){
				var tpop = 'id=loadmailframe,name=loadmailframe,height=200,width=300'
				tobj = xpow.CreateElemt('iframe',tpop)
			}
			tobj.src='http://'+this.moParm.Channel+'.chndesign.'+xpow.point.Path.getApp()+'/'+this.moParm.MailPS+'?action=loadmail&export=json&channel='+this.moParm.MailChannel+this.lines.pages
			
		},*/
		RegItem : function(){
			var tAry = $t('_usermailbox','tr')
			this.lines.ids = ''
			for (var i=0; i<tAry.length; i++){
				if (tAry[i]){
					if(tAry[i].getAttribute('for')=='over'){
						this.lines.ids += tAry[i].id+','
						tAry[i].onmouseover = function(){this.className='mailover'}	
						tAry[i].onmouseout = function(){if (!$('mailchk.'+this.getAttribute('li')).checked && User.Mail.readId!=this.id){this.className=''}}
						$('mail.tt_'+tAry[i].getAttribute('li')).onclick = function(){User.Mail.Read(this.id.split('_')[1])}
					}
				}
			}
			
			var tAry = $t('_usermailbox','input')
			for (var i=0; i<tAry.length; i++){
				if (tAry[i]){
					if(tAry[i].name=='mailchk'){
						tAry[i].onclick = function(){
							this.parentNode.parentNode.className = (this.checked)? 'mailover' : ''
						}
						/*tAry[i].parentNode.onclick = function(){
							this.childNodes[0].checked=!this.childNodes[0].checked
						}*/
					}
				}
			}
			
			
			$('_chk_all').onclick = function(){
				for (var i=0; i<tAry.length; i++){
					if (tAry[i]){
						if(tAry[i].name=='mailchk'){
							tAry[i].checked = this.checked
							if(User.Mail.readId!=tAry[i].parentNode.parentNode.id) tAry[i].parentNode.parentNode.className = (this.checked )? 'mailover' : ''
						}
					}
				}	
			}
			
			$('btnDel').onclick = function(){
				User.Mail.lines.delid = ''
				for (var i=0; i<tAry.length; i++){
					if (tAry[i]){
						if(tAry[i].name=='mailchk'){
							if (tAry[i].checked){
								User.Mail.lines.delid+=tAry[i].value+','
							}
						}
					}
				}
				if(User.Mail.lines.delid==''){
					alert('请选择至少一封邮件！')	
				}else{
					if(!confirm('确实要删除选中的邮件吗？')){return}
					User.Mail.Delete(User.Mail.lines.delid.toLeft(1))
				}
			}
			
		},
		setMailBox : function(){
			this.box = '<div id="user.mail"><div class="mailbox" id="'+this.moParm.MailStatu+'"></div></div>'
			if (xpow.emObj.Parmas.mailset){
				if(!$(this.moParm.MailStatu))this.doExport(0,1,'#feb070',xpow.emObj.Parmas.mailset.leftoffset,xpow.emObj.Parmas.mailset.topoffset,'auto',520,this.moParm.MailDer,this.box,0,2)
			}else{
				if(!$(this.moParm.MailStatu))this.doExport(0,1,'#feb070',110,0,'auto',520,this.moParm.MailDer,this.box,0,2)
			}
		},
		Read : function(id){
			this.init()
			xpow.osEvent.catchSrc()
			var tAry = this.lines.ids.split(',')
			for (i=0; i<tAry.length; i++){
				if($(tAry[i])){
					if ($(tAry[i]).getAttribute('li')) if(!$('mailchk.'+$(tAry[i]).getAttribute('li')).checked)$(tAry[i]).className=''
				}
			}

			if (this.mDLG.ISEXPORT){this.mDLG.Clear()}
			this.mDLG = xpow.Use('dlg')
			this.mBox = '<div id="user.mail"><div style="padding:10px" id="mailbox"></div></div>'	
			this.doExportM(0,1,'#feb070',10,80,'auto',455,'mail.tt_'+id,'<div style="padding:10px" id="mailmsg">loading...</div>')
			$('mail.tt_'+id).className = 'mailisread'
			$('mail.tt_'+id).parentNode.className = 'reading'
			this.readId=$('mail.tt_'+id).parentNode.id
			this.qUy = 'readmail&dataId='+id
			if (!this.moParm.Channel){this.moParm.Channel = xpow.point.Path.getDomain()}
			xpow.JSN.Init('/','zone.xhtml',1,'mailmsg',0,2)
			xpow.JSN.Send(this.qUy)
		},
		Delete : function(id){
			this.moParm.Channel = xpow.point.Path.getDomain()
			xpow.JSN.Init('http://'+this.moParm.Channel+'.chndesign.'+xpow.point.Path.getApp()+'/',this.moParm.MailPS,1,'vsi',0)
			this.qUy = 'delmail&dataId='+id+'&channel='+this.moParm.MailChannel+'&page='+$('page').value
			xpow.JSN.Send(this.qUy)
		},
		doExport : function(ismask,istitle,bdcolor,toffset,loffset,h,w,der,restr){
			this.oDLG.doInit('User.Mail.oDLG');
			this.oDLG.isMask = ismask;
			this.mDLG.id = 'User.Mail.oDLG';
			this.oDLG.isTitle = istitle;
			this.oDLG.mTitle = '用户信箱';
			this.oDLG.mTitleColor = '#ffffff';
			this.oDLG.mTitleBgColor = '#ff7300';
			this.oDLG.mBorderColor = bdcolor;
			this.oDLG.mTtBorder = 0
			this.oDLG.topOffset = toffset;
			this.oDLG.leftOffset = loffset;
			if(h!='')this.oDLG.mHeight = h;
			if(w>0)this.oDLG.mWidth = w;
			this.oDLG.der = der;
			this.oDLG.Export(restr);
		},
		doExportM : function(ismask,istitle,bdcolor,toffset,loffset,h,w,der,restr){
			this.mDLG.doInit('User.Mail.mDLG');
			this.mDLG.isMask = ismask;
			this.mDLG.isTitle = istitle;
			this.mDLG.mTitleColor = '#666666';
			this.mDLG.mTitleBgColor = '#ffffff';
			this.mDLG.mBorderColor = bdcolor;
			this.mDLG.id = 'User.Mail.mDLG';
			this.mDLG.mTtBorder = 0
			this.mDLG.Button = {get:true,Submit:'User.Mail.reClose()',Cancel:'User.Mail.reClose()'};
			this.mDLG.topOffset = toffset;
			this.mDLG.leftOffset = loffset;
			if(h>0)this.mDLG.mHeight = h;
			if(w>0)this.mDLG.mWidth = w;
			this.mDLG.der = der;
			this.mDLG.Export(restr);
		},
		reClose : function(){
			this.readId=0
			this.mDLG.Clear()
		},
		Close : function(){ if(this.mDLG)this.mDLG.Clear()},
		parseItem : ''
	}
}

