var XMPS={};XMPS.action=function(config,action)
{config=$merge({success:null,failure:null,timeout:30},config)
config.timeout=config.timeout*1000;var passport=new PHPRPC_Client('http://passport.xinmin.cn/index.php?app=passport&controller=Service&action=phprpc',[action]);passport[action]
(config.username,config.password,0,function(data)
{if(!data)
{config.hint?XMPS.hint('close'):'';$type(config.failure)=='function'?config.failure():alert(action+' failed.');return false;}
var xmps=data;xmps.host=[parseUri('http://passport.xinmin.cn')['host']];var domain=host='';var phprpcItem=[];var serviceArray=['http://bbs.xinmin.cn/xmps/service.php','http://ham.xinmin.cn/xmps/service.php','http://sns.xinmin.cn/xmps/service.php','http://t.xinmin.cn/xmps/service.php'];var counter=0;var total=serviceArray.length;var timer=function()
{if(counter!=total)
{$type(config.failure)=='function'?config.failure('timeout'):alert(action+' timeout.');return false;}}.delay(config.timeout);serviceArray.each
(function(item,index)
{host=parseUri(item)['host'];domain=(host.match(/[^\.]+\.[a-zA-Z]+$/)||host).toString();xmps.host.push(host);var phprpc=new PHPRPC_Client(item,[action]);phprpc[action]
(data.XMPS_KEY,data.XMPS_USERNAME,(domain.indexOf('.')!=-1?'.'+domain:false),function()
{counter++;config.hint?$('PASSPORT_WAITING_PROGRESS').set('html',(counter/total*100).toInt()+'%'):'';if(counter==total)
{$type(config.success)=='function'?config.success(xmps):window.open(config.success,'_self');}})})});}
XMPS.login=function(config)
{config=$merge({success:document.URL,mask:true},config);config.hint?XMPS.hint('in',config.mask,'&#27491;&#22312;&#30331;&#24405;'):'';XMPS.action(config,'login');}
XMPS.logout=function(config)
{config=$merge({success:document.URL,mask:true},config);config.hint?XMPS.hint('in',config.mask,'&#27491;&#22312;&#36864;&#20986;'):'';XMPS.action(config,'logout');}
XMPS.loginCheck=function(config)
{config=$merge({success:'void',failure:'void'},config);if(Cookie.read('XMPS_KEY'))
{var xmps={'XMPS_KEY':Cookie.read('XMPS_KEY'),'XMPS_USERNAME':Cookie.read('XMPS_USERNAME'),'XMPS_NICKNAME':Cookie.read('XMPS_NICKNAME')};$type(config.success)=='function'?config.success(xmps):'';}
else
{$type(config.failure)=='function'?config.failure():'';}}
XMPS.page=function(type,refererUrl,target)
{switch(type)
{case'register':window.open('http://passport.xinmin.cn/index.php?app=passport&controller=Register'+(refererUrl?'&refererUrl='+encodeURIComponent(refererUrl):''),target);break;case'login':window.open('http://passport.xinmin.cn/index.php?app=passport&controller=Login'+(refererUrl?'&refererUrl='+encodeURIComponent(refererUrl):''),target);break;default:window.open('http://passport.xinmin.cn/index.php?app=passport&controller=Index'+(refererUrl?'&refererUrl='+encodeURIComponent(refererUrl):''),target);}}
XMPS.hint=function(mode,mask,msg)
{if(mode=='close')
{$('PASSPORT_WAITING_DIV').destroy();$('PASSPORT_WAITING_MASK').destroy();return true;}
if(!$('PASSPORT_WAITING_MASK')&&mask)
{new Element
('div',{id:'PASSPORT_WAITING_MASK','styles':{'background-color':'#333333','position':'absolute','opacity':'.3','z-index':'9999','top':'0px','left':'0px','width':window.getScrollSize().x+'px','height':window.getScrollSize().y+'px'},events:{'click':function()
{$('PASSPORT_WAITING_DIV').destroy();$('PASSPORT_WAITING_MASK').destroy();}}}).inject(document.body);}
if(!$('PASSPORT_WAITING_DIV'))
{new Element('div',{'id':'PASSPORT_WAITING_DIV','html':'<img height="32" style="margin-right: 8px;  float: left; vertical-align: top;" src="http://passport.xinmin.cn/application/passport/View/template/images/logo_loading.gif"/><span id="PASSPORT_WAITING_MSG">&#27491;&#22312;&#30331;&#38470;</span> <span id="PASSPORT_WAITING_PROGRESS">0%</span><br />&#35831;&#31245;&#20505;&#46;&#46;&#46;','styles':{'position':'absolute','left':'45%','top':'42%','padding':'5px','z-index':'10000','height':'auto','background':'white','color':'#444','font':'bold 13px tahoma,arial,helvetica','border':'1px #ccc solid','opacity':0}}).inject(document.body);}
$('PASSPORT_WAITING_MSG').set('html',msg);$('PASSPORT_WAITING_DIV').fade(mode);}