/**
*	客户端主js
*	来自官网：http://www.rockoa.com 
*	作者：信呼开发团队(雨中磐石)
*/

var chatobj={},windowfocus=true,jietubool=false;
var reim={loadtime:60,init:function(){for(var i in tabd)this[i]=tabd[i];for(var i in cofst)this[i]=cofst[i];document.ondragover=function(e){e.preventDefault();};document.ondrop=function(e){e.preventDefault();};date=js.now('Y-m-d');nwjs.init();bodyunload=function(){nwjs.removetray();}
this.resize();$('#leftmainlist').perfectScrollbar();$(window).resize(this.resize);this.addtabs('home','<div align="center" style="font-size:150px;color:#e8e8e8;margin-top:30%"><i class="icon-headphones"></i></div>');this.initdata();$('#cogbtnss').click(function(){reim.showcog(this);return false;});notifyobj=new notifyClass({title:lang('xttodo'),sound:'res/sound/todo.ogg',sounderr:'',soundbo:this.getsound(),showbool:false});nwjs.createtray(document.title+'-'+adminname,1);$(window).focus(function(){windowfocus=true;reim.winfocus();});$(window).blur(function(){windowfocus=false});this.righthistroboj=$.rockmenu({data:[],itemsclick:function(d){reim.rightclick(d);}});setInterval('reim.sInterval()',this.loadtime*1000);$('body').keydown(function(e){return reim.bodykeydown(e);});uploadobj=$.rockupload({inputfile:'allfileinput',initpdbool:false,updir:'reimchat',urlparams:{noasyn:'yes'},onchange:function(d){im.sendfileshow(d);},onprogress:function(f,per,evt){im.upprogresss(per);},onsuccess:function(f,str,o1){im.sendfileok(f,str);},onerror:function(str){js.msg('msg',str);im.senderror();}});strformat.upobj=uploadobj;strformat.openurl=function(url){reim.openurl(url);}
for(var i=0;i<4;i++)if(get('lefttab'+i+''))get('lefttab'+i+'').title=lang('lefttab'+i+'');},winfocus:function(){nwjs.jumpclear();im.windowfocus();},geturl:function(m1,a1){return'api.php?m='+m1+'&a='+a1+'&token='+admintoken+'&locallang='+rocklang+'';},ajax:function(url,das,fun,can,efun){var urla=url.split(',');if(!das)das={};var cans={url:this.geturl(urla[0],urla[1]),data:das,dataType:'json',success:function(ret){js.unloading();if(ret.success){if(fun)fun(ret);}else{js.msg('msg',ret.msg);if(ret.code==199){js.msg();js.alert(ret.msg,function(){reim.exitlogin(true);},lang('xtexit'));}
if(efun)efun(ret);}}};if(can)if(typeof(can)=='string'){cans.type=can;}else{for(var i in can)cans[i]=can[i];}
js.ajax(cans);},delchat:function(type,sid){$('#lists_'+type+''+sid+'').remove();this.ajax('reim,delchat',{type:type,sid:sid});this.chatbadge();},sInterval:function(){this.initdata();},initdata:function(){this.ajax('reim,clientdata',false,function(ret){reim.showdata(ret.data);});},showdata:function(ret){if(!this.showconfigarr){this.showconfigarr=ret.config;this.websocketlink(ret.config);}
if(ret.userarr)this.showlist(ret.userarr);if(ret.zixunarr)this.showzixun(ret.zixunarr);if(ret.history)this.showlishi(ret.history);if(ret.waitarr)this.showwait(ret.waitarr);},resize:function(){var hei=winHb();viewheight=hei;$('#leftdiv').css('height',''+hei+'px');$('#leftmainlist').css('height',''+(hei-60)+'px');$('#viewzhulist').css('height',''+hei+'px');var obj=$('div[resizeh]'),o,hei;for(var i=0;i<obj.length;i++){o=$(obj[i]);hei=parseInt(o.attr('resizeh'));o.css('height',''+(viewheight-hei)+'px');}},historysdata:{},showhistorys:function(d,pad,lex){if(!d.div)d.div='leftshow0';var s,ty,o=$('#'+d.div+''),d1,st=d.stotal,attr;var num=d.num,na=d.name;$('#lists_'+num+'').remove();this.historysdata[num]=d;var ops=d.optdt.substr(11,5);if(d.optdt.indexOf(date)!=0)ops=d.optdt.substr(5,5);if(!st||st<=0)st='';if(!d.names)d.names='';s='<div class="lists" onclick="reim.showchat(\''+num+'\')" temp="temp" id="lists_'+num+'" oncontextmenu="reim.historyright(this,event,\''+num+'\')">';s+='<table cellpadding="0" border="0" width="100%"><tr>';s+='<td style="padding-right:8px"><div style="height:34px;overflow:hidden"><img src="'+d.face+'"></div></td>';s+='<td align="left" width="100%"><div title="'+na+'" class="name"><font>'+na+'</font>&nbsp'+d.names+'</div><div class="huicont">'+jm.base64decode(d.cont)+'</div></td>';s+='<td align="right" nowrap><span id="'+d.div+'_stotal_'+num+'" class="badge red">'+st+'</span><br><span style="color:#aaaaaa;font-size:10px">'+ops+'</span></td>';s+='</tr></table>';s+='</div>';if(!pad){o.append(s);}else{o.prepend(s)}},historyright:function(o1,e,num){var d=this.historysdata[num];if(d.type=='user')return false
this.rightdivobj=o1;var da=[];da.push({name:lang('open'),lx:0,num:num});da.push({name:lang('deljl'),lx:2,num:num});this.righthistroboj.setData(da);this.righthistroboj.showAt(e.clientX-3,e.clientY-3);return false;},rightclick:function(d){var da=this.historysdata[d.num];var o1=$(this.rightdivobj),lx=d.lx;if(lx==0){this.rightdivobj.onclick();}
if(lx==2){if(d.num==this.nowtabs)this.closenowtabs();this.delchat(da.type,da.id);this.reshowwait();}},showlist:function(a){$('#leftshow1').html('');var i,len=a.length;for(i=0;i<len;i++){this.showhistorys({id:a[i].id,type:'user',div:'leftshow1',num:'user'+a[i].id+'',name:a[i].name,face:a[i].face,cont:jm.base64encode(a[i].ranking),optdt:''});}
$('#leftshow1').append('<div style="font-size:12px;color:#cccccc;padding:5px" align="center">共'+len+'人</div>');},onoffline(id,one){if(one==0){$('#online_zixun'+id+'').remove();$('#online_wait'+id+'').remove();}},showzixun:function(a){$('#leftshow0').html('');var i,len=a.length,nas='';for(i=0;i<len;i++){nas='';if(a[i].online==1)nas='<span id="online_zixun'+a[i].id+'" class="badgeonline">'+lang('online')+'</span>';this.showhistorys({id:a[i].id,type:'zixun',div:'leftshow0',num:'zixun'+a[i].id+'',name:a[i].name,face:a[i].face,cont:a[i].cont,optdt:a[i].optdt,stotal:a[i].stotal,names:nas});}
this.chatbadge();},showlishi:function(a){var i,len=a.length;for(i=0;i<len;i++){if(a[i].type=='uchat')a[i].names='<span class="badgeuser">'+lang('user')+'</span>';if(a[i].online==1)a[i].names='<span id="online_'+a[i].num+'" class="badgeonline">'+lang('online')+'</span>';this.showhistorys(a[i]);}
if(this.nowtabs)$('#lists_'+this.nowtabs+'').addClass('active');this.chatbadge();},showwait:function(a){$('#leftshow2').html('');var i,len=a.length,nas;for(i=0;i<len;i++){nas='';if(a[i].online==1)nas='<span id="online_wait'+a[i].id+'" class="badgeonline">'+lang('online')+'</span>';this.showhistorys({id:a[i].id,type:'wait',div:'leftshow2',num:'wait'+a[i].id+'',name:a[i].name,face:a[i].face,cont:a[i].cont,optdt:a[i].optdt,names:nas,stotal:1});}
this.reshowwait();},reloadhist:function(d){if(d.type=='uchat'&&d.sendid==adminid)return;this.ajax('reim,gethistory',false,function(ret){reim.showdata(ret.data);});var num=''+d.type+''+d.sendid+'';try{chatobj[num].recedata()}catch(e){}
var sopenfun=function(b){notifyobj.close();reim.showchat(b.num);return false;}
if(!windowfocus){notifyobj.showpopup(jm.base64decode(d.mess),{icon:d.face,num:num,title:jm.base64decode(d.title),click:function(b){return sopenfun(b);}});nwjs.jumpicon();}},reloadwait:function(d){js.alertclose();this.ajax('reim,gewait',{kfuid:d.kfuid},function(ret){reim.showdata(ret.data);});if(d.mess){nwjs.jumpicon();notifyobj.showpopup(jm.base64decode(d.mess),{title:jm.base64decode(d.title),sound:'res/sound/jias.wav',click:function(b){return false;}});}},yidu:function(type,sid){this.ajax('reim,yidu',{type:type,sid:sid});this.chatbadge();},showchat:function(num){var d=this.historysdata[num];if(d.type=='zixun'||d.type=='uchat'){var spid='leftshow0_stotal_'+num+'',stt=$('#'+spid+'').html();$('#'+spid+'').html('');var bo=this.addtabs(''+num+'','webmain/kefu/chat.html?num='+num+'');try{if(bo)chatobj[num].onshow(stt);}catch(e){}
this.chatbadge();}
if(d.type=='user'){this.changleft(0);if(get('lists_uchat'+d.id+'')){}else{this.showhistorys({id:d.id,type:'uchat',num:'uchat'+d.id+'',name:d.name,face:d.face,cont:'',optdt:js.serverdt(),stotal:0,names:'<span class="badgeuser">'+lang('user')+'</span>'},true);this.ajax('reim,addhis',{type:'uchat',sid:d.id});}
this.showchat('uchat'+d.id+'');}
if(d.type=='wait'){js.confirm(lang('waitjd',d.name),function(jg){if(jg=='yes')reim.showjieda(num,false)});}},showjieda:function(num,bo){var d=this.historysdata[num];if(!bo){js.loading(lang('zzjiar'));this.ajax('reim,addzixun',{sid:d.id},function(ret){reim.showjieda(num,true);});return;}
$('#lists_'+d.num+'').remove();d.type='zixun';d.num='zixun'+d.id+'';d.div='';d.stotal=0;this.changleft(0);this.showhistorys(d,true);this.showchat(d.num);this.reshowwait();},reshowwait:function(){var obj=$('div[id^="lists_wait"]');var len=obj.length;if(len==0)len='';$('#waitbadge').html(len);},chatbadge:function(){var obj=$('span[id^="leftshow0_stotal_"]');var len=obj.length,sto=0,i,s1;for(i=0;i<len;i++){s1=obj[i].innerHTML;if(!s1)s1=0;sto+=parseInt(s1);}
if(sto==0)sto='';$('#chatbadge').html(sto);},showcog:function(o1){if(!this.cogmenu)this.cogmenu=$.rockmenu({data:[],width:120,itemsclick:function(d){reim.clickcogclick(d);}});var d=[{'name':lang('reload'),lx:'sx'}];if(admintype=='1')d.push({'name':lang('htgl'),lx:'huo'});d.push({'name':lang('editpass'),lx:'pass'});d.push({'name':lang('exit'),lx:'exit'});this.cogmenu.setData(d);var off=$(o1).offset();this.cogmenu.showAt(60,off.top+d.length*36);},clickcogclick:function(d){var lx=d.lx;if(lx=='sx'){js.loading(lang('sxing'));js.reload();}
if(lx=='exit'){this.exitlogin();}
if(lx=='huo'){reim.openurl(''+NOWURL+'?m=index');}
if(lx=='pass'){this.addtabs('editpass','webmain/kefu/editpass.html?num=editpass');}},exitlogin:function(bo){if(!bo){js.confirm(lang('qudtc'),function(jg){if(jg=='yes')reim.exitlogin(true)});return;}
js.loading(lang('tczon'));this.ajax('login,exit',false,function(){js.setoption('lgautodl','');js.location('?m=login&a=kefu&tform=main');});},backemts:function(s){chatobj[this.nowtabs].addinput(s);$('#aemtsdiv').hide();},bodykeydown:function(e){var code=e.keyCode;if(code==27){if($.imgviewclose())return false;if(get('alert_main')){js.tanclose('alert');}else{this.closenowtabs();}
return false;}},}
var tabd={nowtabs:'',addtabs:function(num,nr){var ids='tabs_'+num+'',bo,s;if(!get(ids)){if(nr.substr(0,7)=='webmain'){var urlpms='',ura=nr.split('?'),i;if(ura[1]){var nusa=ura[1].split('&');for(i=0;i<nusa.length;i++){var nus=nusa[i].split('=');urlpms+=",'"+nus[0]+"':'"+nus[1]+"'";}
if(urlpms!='')urlpms=urlpms.substr(1);}
s='<div tabs="'+num+'" id="'+ids+'"><div style="padding:20px"><img src="images/mloading.gif"></div></div>';var rand=js.getrand();$.get(nr+'&rand='+rand+'',function(da){var s1=da;s1=s1.replace(/\{rand\}/gi,rand);s1=s1.replace(/\{params\}/gi,"var params={"+urlpms+"};");$('#'+ids+'').html(s1);reim.resize();});}else{s='<div tabs="'+num+'" id="'+ids+'">'+nr+'</div>';}
$('#viewzhulist').append(s);bo=false;}else{bo=true;}
this.showtabs(num);return bo;},closetabs:function(num){var ids='tabs_'+num+'';$('#'+ids+'').remove();var ood=$('#viewzhulist div[tabs]:last');var snu=ood.attr('tabs');this.showtabs(snu);},closenowtabs:function(){if(this.nowtabs)this.closetabs(this.nowtabs);},showtabs:function(num){$('div[tabs]').hide();var ids='tabs_'+num+'';$('#'+ids+'').show();$('div[temp]').removeClass('active');$('#lists_'+num+'').addClass('active');this.nowtabs=num;},changleft:function(oi){$('div[ltabs="left"]').removeClass('leftactive');$('div[ltabs="left"]:eq('+oi+')').addClass('leftactive');$('div[ltabs="cont"]').hide();$('#leftshow'+oi+'').show();}}
var cofst={websocketlink:function(a){if(this.connectbool){this.serverstatus(1);return false;}
if(!a){this.serverstatus(3);return false;}
var wsurl=jm.base64decode(a.wsurl),receid=a.recid;this.showconfigarr=a;if(isempt(wsurl)||wsurl.indexOf('ws')<0){this.serverstatus(3);return false;}
clearTimeout(this.relianshotime_time);websocketobj=new websocketClass({adminid:adminid,reimfrom:receid,wshost:wsurl,sendname:adminname,onerror:function(o,ws){reim.connectbool=false;reim.serverstatus(0);js.msg('msg',''+lang('wflia')+'<br><span id="lianmiaoshoetime"></span><a href="javascript:;" onclick="reim.connectservers()">['+lang('clixn')+']</a>',0);reim.relianshotime(30);},onmessage:function(str){reim.connectbool=true;clearTimeout(reim.relianshotime_time);var a=js.decode(str);reim.receivemesb(a);},onopen:function(){reim.connectbool=true;reim.serverstatus(1);clearTimeout(reim.relianshotime_time);js.msg('none');},onclose:function(o,e){reim.connectbool=false;if(reim.otherlogin)return;reim.serverstatus(0);js.msg('msg',''+lang('wfli2')+'<br><span id="lianmiaoshoetime"></span><a href="javascript:;" onclick="reim.connectservers()">['+lang('clixn')+']</a>',0);reim.relianshotime(10);}});},connectservers:function(){if(this.connectbool){this.serverstatus(1);return;}
var bo=this.websocketlink(this.showconfigarr);if(bo)js.msg('wait',lang('linking'));},serverstatus:function(lx){},relianshotime:function(oi){clearTimeout(this.relianshotime_time);$('#lianmiaoshoetime').html('('+oi+''+lang('mssex')+')');if(oi<=0){this.connectservers();}else{this.relianshotime_time=setTimeout('reim.relianshotime('+(oi-1)+')',1000);}},serversend:function(a){if(!this.connectbool)return false;websocketobj.send(a);return true;},getonline:function(){this.serversend({'atype':'getonline'});},otherlogins:function(){this.otherlogin=true;var msg=lang('bdfad');js.alert(msg);this.serverstatus(2);},receivemesb:function(d){var lx=d.type,sendid=d.adminid;if(lx=='offoline'){this.otherlogins();return;}
if(lx=='uchat'||lx=='zixun'){this.reloadhist(d);}
if(lx=='rewait'){if(d.sendid!=adminid)this.reloadwait(d);}
if(lx=='zxoff'){this.onoffline(d.zixunid,0);}},getsound:function(){var lx=js.getoption('soundcog'),chs=false;if(lx=='')lx='1';if(lx==1)chs=true;return chs;},setsound:function(o1){var lx=(o1.checked)?'1':'2';js.setoption('soundcog',lx);notifyobj.setsound(o1.checked);},getzhuom:function(){var lx=js.getoption('zhuomcog'),chs=false;if(lx=='')lx='1';if(lx==1)chs=true;return chs;},setzhuom:function(o1){var lx=(o1.checked)?'1':'2';js.setoption('zhuomcog',lx);},openurl:function(url){if(!nwjsgui){window.open(url);}else{js.open(url,950,550);}}}
var im={clickqipao:function(o1,e){},rightqipao:function(o1,e,rnd){chatobj[reim.nowtabs].rightqipao(o1,e,rnd);},backemts:function(s){chatobj[reim.nowtabs].addinput(s);$('#aemtsdiv').hide();},sendfileshow:function(f){var num=uploadobj.nownum;chatobj[num].sendfileshow(f);},upprogresss:function(per){var num=uploadobj.nownum;strformat.upprogresss(per);},sendfileok:function(f,str){var num=uploadobj.nownum;chatobj[num].sendfileok(f,str);},senderror:function(){var num=uploadobj.nownum;chatobj[num].senderrornss();},readclip:function(num,e){chatobj[num].readclip(e);},upbase64:function(nuid){var o=get('jietuimg_'+nuid+'');chatobj[reim.nowtabs].sendbase64(o.src);},cropScreen:function(){if(nwjsgui){var oatg=nwjs.getpath();nw.Shell.openItem(''+oatg+'/images/reimcaptScreen.exe');}},windowfocus:function(){if(jietubool){chatobj[reim.nowtabs].pasteimg(true);}
jietubool=false;},fileyulan:function(pn,fid){var url='?m=public&a=fileviewer&id='+fid+'';js.open(url,800,500);}}