/////////////////////////////////////////////////////////////////// /*####################### CLASS.CHATCLIENT ######################*/ /////////////////////////////////////////////////////////////////// function JsChatClient() { ////////////////////////////////// ///////// THIS.VARIABLES ///////// ////////////////////////////////// var Id,ClassName; var Domain,Port,PolicyFile,Swf; var Map,User; var Layer,Classer,Flash,Menu,Title,Icons,Minimize,Normalize,Maximize,Freeze,MessageBox,UserList,Input,Button; var Top,Left,Grid; /*############################################*/ /*############# PRIVATE.INITIALIZE ###########*/ /*############################################*/ ////////////////////////////////// ////// FUNCTION.INITIALIZE /////// ////////////////////////////////// this.Initialize=function(Args) { this.Id ='JsChatClient_'+Args[0]+'_'; this.ClassName =Args[1]; this.Swf =Args[2]; this.Domain =Args[3]; this.Port =Args[4]; this.PolicyFile =Args[5]; this.User =Args[6]; this.Map =Args[7]; this.Top =20; this.Left =20; this.Grid =20; window[this.Id+'client']=this; window[this.Id+'unload']=window.onunload; eval('window.onunload=function(){ ('+this.Id+'unload?'+this.Id+'unload():false);'+this.Id+'client.Close(); }'); var Holder=this.GetElement(Args[0]); if(Holder) { var FlashObject =''; var Layer =document.createElement('div'); Layer.className =this.ClassName; var Classer =document.createElement('div'); Classer.className ='normal'; var Flash =document.createElement('div'); Flash.className ='flash'; var Menu =document.createElement('div'); Menu.className ='menu'; Menu.Class =this; Menu.onmousedown =function(e){ this.Class.StartDrag(typeof(event)!='undefined'?event:e); }; var Title =document.createElement('div'); Title.className ='title'; var Icons =document.createElement('div'); Icons.className ='icons'; var Minimize =document.createElement('div'); Minimize.className ='minimize'; Minimize.Class =this; Minimize.onclick =function(){ this.Class.SetWindow(this.className); }; Minimize.innerHTML ='-'; var Normalize =document.createElement('div'); Normalize.className ='normalize'; Normalize.Class =this; Normalize.onclick =function(){ this.Class.SetWindow(this.className); }; Normalize.innerHTML ='n'; var Maximize =document.createElement('div'); Maximize.className ='maximize'; Maximize.Class =this; Maximize.onclick =function(){ this.Class.SetWindow(this.className); }; Maximize.innerHTML ='+'; var Freeze =document.createElement('div'); Freeze.className ='freeze'; Freeze.Class =this; Freeze.onclick =function(){ this.Class.SetWindow(this.className); }; Freeze.innerHTML ='»'; var Content =document.createElement('div'); Content.className ='content'; Content.Class =this; Content.onclick =function(){ this.Class.Input.focus(); }; var Part1 =document.createElement('div'); Part1.className ='part1'; var MessageBox =document.createElement('div'); MessageBox.className='messagebox'; var UserList =document.createElement('div'); UserList.className ='userlist'; var Part2 =document.createElement('div'); Part2.className ='part2'; var Input =document.createElement('input'); Input.className ='input'; Input.type ='text'; Input.Class =this; Input.onkeyup =function(e){ var Event=(typeof(event)!='undefined'?event:e); if(Event.keyCode==13){ this.Class.SendMessage(); } }; var Button =document.createElement('div'); Button.className ='button'; Button.Class =this; Button.onclick =function(e){ this.Class.SendMessage(); }; Holder.appendChild(Layer);Layer.appendChild(Classer); Classer.appendChild(Flash);Classer.appendChild(Menu);Classer.appendChild(Content); Menu.appendChild(Title);Menu.appendChild(Icons); Icons.appendChild(Minimize);Icons.appendChild(Normalize);Icons.appendChild(Maximize);Icons.appendChild(Freeze); Content.appendChild(Part1);Content.appendChild(Part2); Part1.appendChild(MessageBox);Part1.appendChild(UserList); Part2.appendChild(Input);Part2.appendChild(Button); Flash.innerHTML =FlashObject; this.Layer =Layer; this.Classer =Classer; this.Flash =navigator.appName.indexOf("Microsoft")!=-1?window[this.Id+'flashObject']:window.document[this.Id+'flashObject']; this.Menu =Menu; this.Title =Title; this.Icons =Icons; this.Minimize =Minimize; this.Normalize =Normalize; this.Freeze =Freeze; this.Maximize =Maximize; this.MessageBox =MessageBox; this.UserList =UserList; this.Input =Input; this.Button =Button; this.SetWindow('freeze');this.SetWindow('normalize'); } } /*############################################*/ /*############## PRIVATE.CLIENT ##############*/ /*############################################*/ ////////////////////////////////// ///////// FUNCTION.LOAD ////////// ////////////////////////////////// this.Load=function(Data) { if(typeof(window.document.readyState)=='undefined') { window.document.readyState='complete'; } if(window.document.readyState=='complete') { setTimeout(''+this.Id+'client.Connect();',100); } else { setTimeout(''+this.Id+'client.Load();',100); } } ////////////////////////////////// //////// FUNCTION.CONNECT //////// ////////////////////////////////// this.Connect=function() { if(this.Flash.Connect) { this.Flash.Set(this.Domain,this.Port,this.PolicyFile); this.Flash.Connect('ac=ur&md='+this.Map+'&ud='+this.User); } } ////////////////////////////////// ///////// FUNCTION.CLOSE ///////// ////////////////////////////////// this.Close=function() { if(this.Flash.DisConnect) { this.Flash.DisConnect(); } } ////////////////////////////////// ///////// FUNCTION.SEND ////////// ////////////////////////////////// this.Send=function(Data) { if(this.Flash.Recieve) { this.Flash.Recieve(Data); } } ////////////////////////////////// //////// FUNCTION.RECIEVE //////// ////////////////////////////////// this.Recieve=function(Data) { if(Data) { var Parts =Data.split('&'); var Action =false; var Return ={}; for(var a=0;a]{0,}\>/ig,''); var Item=document.createElement('div'); this.MessageBox.appendChild(Item); Item.innerHTML=User+': '+Text; this.MessageBox.scrollTop=this.MessageBox.scrollHeight; } } ////////////////////////////////// ////// FUNCTION.SENDMESSAGE ////// ////////////////////////////////// this.SendMessage=function() { var Text=this.Input.value; Text=Text.replace(/\<[^\>]{0,}\>/ig,''); if(Text) { this.Send('ac=um&um='+escape(Text)); this.Input.value=''; } } ////////////////////////////////// /////// FUNCTION.SETWINDOW /////// ////////////////////////////////// this.SetWindow=function(Type) { switch(Type) { case 'minimize': this.Minimize.style.display ='none'; this.Normalize.style.display='block'; this.Maximize.style.display ='block'; this.Freeze.style.display =this.Layer.style.position=='absolute'?'block':'none'; this.Classer.className ='minimized'; break; case 'normalize': this.Minimize.style.display ='block'; this.Normalize.style.display='none'; this.Maximize.style.display ='block'; this.Freeze.style.display =this.Layer.style.position=='absolute'?'block':'none'; this.Classer.className ='normal'; break; case 'maximize': this.Minimize.style.display ='block'; this.Normalize.style.display='block'; this.Freeze.style.display ='block'; this.Maximize.style.display ='none'; this.Classer.className ='maximized'; this.Layer.style.position ='absolute'; this.Layer.style.left =this.Left+'px'; this.Layer.style.top =this.Top+'px'; break; case 'unfreeze': this.Freeze.style.display ='block'; this.Layer.style.position ='absolute'; break; case 'freeze': this.Freeze.style.display ='none'; this.Layer.style.position ='relative'; this.Layer.style.top ='0px'; this.Layer.style.left ='0px'; if(this.Classer.className=='maximized') { this.SetWindow('normalize'); } break; } this.Input.focus(); this.MessageBox.scrollTop=this.MessageBox.scrollHeight; } /*############################################*/ /*############## PRIVATE.HELP ################*/ /*############################################*/ ////////////////////////////////// ////// FUNCTION.GETELEMENT /////// ////////////////////////////////// this.GetElement=function(Id){ if(document.getElementById){ return document.getElementById(Id); } else if(document.all){ return document.all[Id]; } else{ return document[Id]; } } ////////////////////////////////// /////// FUNCTION.STARTDRAG /////// ////////////////////////////////// this.StartDrag=function(Event){ var PosX=Event.layerX?parseInt(Event.layerX)-parseInt(this.Icons.offsetLeft):-1; var PosX=PosX<0 && (Event.srcElement?(Event.srcElement==this.Menu || Event.srcElement==this.Title):1); if(PosX) { this.SetWindow('unfreeze'); try{ this.Input.focus(); } catch(e){ } window.document.body.DragElement=this; window.document.body.onmousemove=function(e){ this.DragElement?this.DragElement.Drag(e?e:event):false; }; window.document.body.onmouseup =function(e){ this.DragElement?this.DragElement.StopDrag(e?e:event):false; }; var X =typeof(Event.offsetX)!='undefined'?(Event.offsetX+Event.srcElement.offsetLeft):(Event.layerX); var Y =typeof(Event.offsetY)!='undefined'?(Event.offsetY+Event.srcElement.offsetTop):(Event.layerY); this.Layer.Pos={X:(X>0?X:5),Y:(Y>0?Y:5)}; this.Drag(Event); } } ////////////////////////////////// //////// FUNCTION.STOPDRAG /////// ////////////////////////////////// this.StopDrag=function(Event){ window.document.body.DragElement=false; window.document.body.onmousemove=function(){ }; window.document.body.onmouseup =function(){ }; this.Layer.style.left=(Math.round(this.Left/this.Grid)*this.Grid)+'px'; this.Layer.style.top =(Math.round(this.Top/this.Grid)*this.Grid)+'px'; try{ this.Input.focus(); } catch(e){ } } ////////////////////////////////// ////////// FUNCTION.DRAG ///////// ////////////////////////////////// this.Drag=function(Event){ var ScrollElement =document.body.parentElement?document.body.parentElement:document.body; var ScrollX =parseInt(ScrollElement.scrollLeft?ScrollElement.scrollLeft:0); var ScrollY =parseInt(ScrollElement.scrollTop?ScrollElement.scrollTop:0); this.Left =Math.round((Event.pageX?Event.pageX:ScrollX+Event.clientX)-this.Layer.Pos.X); this.Top =Math.round((Event.pageY?Event.pageY:ScrollY+Event.clientY)-this.Layer.Pos.Y); this.Layer.style.left =this.Left+'px'; this.Layer.style.top =this.Top+'px'; try{ this.Input.focus(); } catch(e){ } } ////////////////////////////////// ///////// CALL.INITIALIZE //////// ////////////////////////////////// this.Initialize(arguments); }