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

var windowfocus=false,agentkey='';
var reim={key:'',loadci:0,loadtime:10,maxlenfz:60*5,maxlenss:0,listdata:{},receinfo:{name:'',id:0},init:function(){document.title=''+lang('title')+'_'+agentname+'';this.key=agentkey;this.title=document.title;this.minid=999999999;this.maxid=0;this.inputobj=$('#input_content');this.showobj=$('#viewcontent');this.showobj.perfectScrollbar();maxupgloble=5;this.resize();this.loaddata();this.inputobj.keydown(function(e){return reim.onkeydown(e);});this.inputobj.focus();$(window).focus(function(){windowfocus=true;reim.winfocus();});$(window).blur(function(){windowfocus=false});window.onbeforeunload=function(){reim.bodyunload();}
this.Intervaltime=setInterval('reim.sInterval()',this.loadtime*1000);strformat.openurl=function(url){reim.openurl(url);}
get('tools0').title=lang('tools0');get('tools1').title=lang('tools1');$('#fuwutitle').html(lang('fuwutitle'));$('#wentititle').html(lang('wentititle'));get('sendbtn').value=lang('sendbtn');$('#tools0').click(function(){reim.tools(this,'emts');return false;});$('#tools1').click(function(){reim.tools(this,'file');return false;});uploadobj=$.rockupload({inputfile:'allfileinput',initpdbool:false,uptype:'gif,png,jpeg,jpg,docx,doc,pdf,xls,xlsx,ppt,pptx,rar,txt,zip',updir:'reimweb',urlparams:{noasyn:'yes',key:this.key,device:device},onchange:function(d){reim.sendfileshow(d);},onprogress:function(f,per,evt){reim.upprogresss(per);},onsuccess:function(f,str,o1){reim.sendfileok(f,str);},onerror:function(str){js.msg('msg',str);reim.senderrornss();}});strformat.upobj=uploadobj;},resize:function(){var hei=(winHb()-$('#maindiv').height()-40)*0.5;if(!isIE)$('#maxheng').css('height',''+hei+'px');},loaddata:function(iref){var iref=(!iref)?false:true;var minid=0;this.loadci++;if(iref)minid=this.minid;this.ajax('front,getdata',{device:device,minid:minid,loadci:this.loadci},function(ret){reim.ldshinof(ret,iref);});},bodyunload:function(){var url=NOWURL+this.geturl('front','offline')+'&sid='+this.sendinfo.id+'';var bo=this.serversend({atype:'runurl',url:url});if(!bo)this.ajax('front,offline',{sid:this.sendinfo.id});},addmsg:function(msg){this.addcont('<div class="showblanks">'+msg+'</div>');},ldshinof:function(ret,iref){var da=ret.data;this.showkfinfo(da.receinfo);this.sendinfo=da.sendinfo;if(da.config){this.showconfigarr=da.config;this.websocketlink(da.config);}
this.showwenti(da.wentiarr);this.showkuaia(da.kuaiarr);this.loaddatashow(da,iref);this.kefuzaxian(da.kefuonline);},showkfinfo:function(info){if(!info)return;this.receinfo=info;get('receface').src=info.face;$('#recenamediv').html(info.name);},onkeydown:function(e){var code=e.keyCode;if(code==13&&!e.ctrlKey){this.sendcont();return false;}
if(e.altKey&&code==83){this.sendcont();return false;}
if(e.ctrlKey&&code==13){this.addinput('\n');return false;}
return true;},addinput:function(s){var val=this.inputobj.val()+s;this.inputobj.val(val).focus();},loaddatashow:function(ret,isbf,isls){this.showkfinfo(ret.receinfo);var a=ret.rows;this.lastdt=ret.nowdt;var i,len=a.length,cont,lex,nas,fase,nr,d,na=[],rnd,sid;if(len==0)return;$('#loadmored').remove();if(isbf){if(len>0)this.showobj.prepend('<div class="showblanks">---------'+lang('newload')+'---------</div>');na=a;}else{for(i=len-1;i>=0;i--)na.push(a[i]);}
for(i=0;i<len;i++){d=na[i];sid=parseFloat(d.id);lex='right';nas=this.sendinfo.name;fase=this.sendinfo.face;if(d.slx=='1'){lex='left';nas=d.sendname;fase=d.sendface;}
nr=this.contshozt(d.filers);if(nr=='')nr=jm.base64decode(d.cont);rnd='mess_'+sid+'';if(get('qipaocont_'+rnd+''))continue;cont=strformat.showqp(lex,nas,d.optdt,nr,'',fase,rnd);if(!isbf){this.addcont(cont,isbf);}else{this.showobj.prepend(cont);}
this.listdata[rnd]=d;if(sid<this.minid)this.minid=sid;if(sid>this.maxid)this.maxid=sid;}
if(ret.nextbo&&!isls){this.showobj.prepend('<div id="loadmored" class="showblanks"><a href="javascript:;" style="color:#aaaaaa;font-size:12px;" onclick="reim.loadmoreda(this)"><i class="icon-time"></i> '+lang('moregd',ret.sheny)+'</a></div>');}else if(len>0&&!isls){this.showobj.prepend('<div id="loadmored" class="showblanks">'+lang('meyoul')+'</div>');}},geturl:function(m1,a1){return'api.php?m='+m1+'&a='+a1+'&key='+this.key+'&locallang='+rocklang+'';},ajax:function(url,das,fun,can){var urla=url.split(',');if(!das)das={};var cans={url:this.geturl(urla[0],urla[1]),data:das,dataType:'json',success:function(ret){if(ret.success){fun(ret);}else{js.msg('msg',ret.msg);}}};if(can)if(typeof(can)=='string'){cans.type=can;}else{for(var i in can)cans[i]=can[i];}
js.ajax(cans);},contshozt:function(d){return strformat.contshozt(d,0);},loadmoreda:function(o1){$(o1).html('<i class="icon-spinner"></i> '+lang('loading')+'</a>');this.loaddata(true);},scrollboot:function(){this.showobj.animate({scrollTop:get('viewcontent').scrollHeight},100);},addcont:function(cont,isbf){var o=this.showobj;if(cont){if(isbf){o.prepend(cont);}else{o.append(cont);}}
clearTimeout(this.scrolltime);this.scrolltime=setTimeout(function(){reim.scrollboot();reim._addclickf();},50);},_addclickf:function(){var o=this.showobj.find('img[fid]');o.unbind('click');o.click(function(){reim.clickimg(this);});},clickimg:function(o1){var o=$(o1);var fid=o.attr('fid');var src=o1.src.replace('_s.','.');$.imgview({url:src,ismobile:ismobile});},send:function(){this.sendcont('');},sendcont:function(ssnr){if(this.sendbool)return;js.msg('none');var o=this.inputobj;var nr=strformat.sendinstr(o.val());nr=nr.replace(/</gi,'&lt;').replace(/>/gi,'&gt;').replace(/\n/gi,'<br>');if(ssnr)nr=ssnr;if(isempt(nr))return false;var conss=jm.base64encode(nr);if(conss.length>3998){js.msg('msg',lang('fataid'));return;}
var nuid=js.now('time'),optdt=js.serverdt();var cont=strformat.showqp('right',this.sendinfo.name,optdt,nr,nuid,this.sendinfo.face,nuid);this.addcont(cont);o.val('').focus();this.sendconts(conss,nuid,optdt,0);return false;},sendconts:function(conss,nuid,optdt,fid){this.sendbool=true;var d={cont:conss,zixunid:this.sendinfo.id,nuid:nuid,optdt:optdt,fileid:fid,device:device};reim.ajax('front,sendcont',d,function(ret){reim.sendsuccess(ret.data);},'post');},senderror:function(nuid){get(nuid).src='images/error.png';get(nuid).title=lang('senderr');this.sendbool=false;},sendsuccess:function(d){this.sendbool=false;if(!d.id){this.senderror(nuid);return;}
$('#'+d.nuid+'').remove();$('#tishizaix').remove();if(d.kefuonline==0){this.addmsg('<div id="tishizaix">'+lang('sendliu')+'</div>');}},winfocus:function(){this.maxlenss=0;this.jumpclear();},jumptitle:function(oi,bo){clearTimeout(this.jumptime);var s=this.title;if(oi==1)s=lang('xinxiao');document.title=s
oi=(oi==1)?0:1;if(!bo)this.jumptime=setTimeout('reim.jumptitle('+oi+')',500);},jumpclear:function(){this.jumptitle(0,true);},showwenti:function(ad){if(!ad)return;var i,len=ad.length,str='';for(i=0;i<len;i++){str+='<div>△ <a style="color:'+ad[i].color+'" href="'+ad[i].url+'" target="_blank">'+ad[i].title+'</a></div>';}
$('#wentilist').html(str);},showkuaia:function(ad){if(!ad)return;this.showkuaiaa=ad;var i,len=ad.length,str='';for(i=0;i<len;i++){str+='<div>◇ <a style="color:'+ad[i].color+'" onclick="reim.kuaicok('+i+')" class="hui">'+ad[i].title+'</a></div>';}
$('#wentilist').append(str);},kuaicok:function(i){var d=this.showkuaiaa[i];var nr='<b>'+d.title+'</b><br>'+d.content+'';var optdt=js.serverdt();var cont=strformat.showqp('right',this.sendinfo.name,optdt,d.title,'',this.sendinfo.face,js.getrand());this.addcont(cont);cont=strformat.showqp('left',agentname,optdt,nr,'',agentface,js.getrand());this.addcont(cont);},loadnew:function(lx){this.loadci++;this.ajax('front,getdata',{lolx:lx,device:device,minid:0,loadci:this.loadci,maxid:this.maxid},function(ret){if(ret.data.total>0)reim.jumptitle();reim.loaddatashow(ret.data,false,true);});},sInterval:function(){this.loadnew(1);this.maxlenss+=10;if(this.maxlenss>=this.maxlenfz){clearInterval(this.Intervaltime);js.alert(lang('chang'),function(){js.reload();});}},kefuzaxian:function(zx){if(zx==0){var kefid=this.receinfo.name;var str=lang('buzaix0');if(kefid)str=lang('buzaix1',kefid);this.addmsg(str);}},websocketlink:function(a){if(this.connectbool||!a||typeof(FormData)==undefined)return false;var wsurl=jm.base64decode(a.wsurl),receid=jm.base64decode(a.recid);this.showconfigarr=a;if(isempt(wsurl)||wsurl.indexOf('ws')<0){return false;}
clearTimeout(this.relianshotime_time);websocketobj=new websocketClass({adminid:a.linkid,reimfrom:receid,wshost:wsurl,sendname:a.linkname,onerror:function(o,ws){reim.connectbool=false;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;clearTimeout(reim.relianshotime_time);js.msg('none');},onclose:function(o,e){reim.connectbool=false;if(reim.otherlogin)return;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'));},relianshotime:function(oi){clearTimeout(this.relianshotime_time);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;},receivemesb:function(d){var lx=d.type;if(lx=='zixun'){this.loadnew(0);}
if(lx=='joinkf'){this.jumptitle();this.addmsg(jm.base64decode(d.mess));if(d.kfinfo)this.showkfinfo(d.kfinfo);}},openurl:function(url){window.open(url);},tools:function(o1,lx){var o=$(o1);if(lx=='emts')this.getemts(o);if(lx=='file')this.sendfile(o);},getemts:function(o){if(!get('aemtsdiv')){var s='<div id="aemtsdiv" style="width:400px;height:200px;overflow-y:auto;border:1px #cccccc solid;background:white;box-shadow:0px 0px 5px rgba(0,0,0,0.3);left:3px;top:5px;position:absolute;display:none;z-index:6">';s+='<div style="padding:5px">';s+=this.getemtsbq('qq',0,104,11,24);s+='</div>';s+='</div>';$('body').append(s);js.addbody('emts','hide','aemtsdiv');}
var o1=$('#aemtsdiv');o1.toggle();var off=o.offset();o1.css({'top':''+(off.top-205)+'px','left':''+(off.left)+'px'});},getemtsbq:function(wj,oi1,oi2,fzd,dx){var i,oi=0,j1=js.float(100/fzd);var s='<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>';for(i=oi1;i<=oi2;i++){oi++;s+='<td width="'+j1+'%" title="'+strformat.emotsarr[i+1]+'" align="center"><img onclick="reim.backemts(\''+strformat.emotsarr[i+1]+'\')" src="images/im/emots/'+wj+'/'+i+'.gif" width="'+dx+'" height="'+dx+'"></td>';if(oi%fzd==0)s+='</tr><tr>';}
s+='</tr></table>';return s;},backemts:function(s){this.addinput(s);$('#aemtsdiv').hide();},sendfile:function(bo){uploadobj.click();},sendfileshow:function(f){f.face=this.sendinfo.face;var fa=strformat.showupfile(f);var cont=fa.cont;this.upfilearr=fa;this.addcont(cont);},sendfileok:function(f,str){var a=js.decode(str);if(!a.id){js.msg('msg',str);this.senderrornss();return;}
var tm=this.upfilearr,conss='';f=a;strformat.upsuccess(a,'',0);if(js.isimg(f.fileext)){conss='['+lang('tupian')+' '+f.filesizecn+']';this._addclickf();}else{conss='['+f.filename+' '+f.filesizecn+']'}
this.sendconts(jm.base64encode(conss),tm.nuid,tm.optdt,a.id);},senderrornss:function(){this.senderror(this.upfilearr.nuid);},upprogresss:function(per){strformat.upprogresss(per);}}