var gschat={newMsgWait:false,newMsgTimer:0,timerId:0,helpBull:1,lastUpdate:0,flagActif:1,flagOpen:0,flagWriting:0,pageTitle:"",init:function(){window.onblur=function(a){gschat.flagActif=0};window.onfocus=function(a){gschat.flagActif=1};$("#gschat_textarea").focus(function(){gschat.flagWriting=1});$("#gschat_textarea").blur(function(){gschat.flagWriting=0});this.pageTitle=window.document.title;$("#gschat_textarea").keypress(this.postMsg);$("#gschat").show();if(this.helpBull==0){this.hideHelpBull()}if(this.flagOpen==1){this.openChat()}$("#gschat_content").scrollTop($("#gschat_inner_content").height());this.timerId=window.setTimeout(function(){gschat.updater()},5000)},updater:function(){$.ajax({type:"POST",url:"/modules/chat/updater.php",data:{task:"update",helpBull:this.helpBull,flagActif:this.flagActif,flagOpen:this.flagOpen,flagWriting:this.flagWriting,pageTitle:this.pageTitle},success:function(b,c,a){if(b.length>0&&b!=""){$("#gschat_inner_content").append(b);if(gschat.flagOpen==0){gschat.openChat()}gschat.newMsgWait=true;gschat.updateTitle();$("#gschat_content").animate({scrollTop:$("#gschat_inner_content").height()},2000)}},error:function(a,c,b){},dataType:"text"});this.timerId=window.setTimeout(function(){gschat.updater()},5000)},hideHelpBull:function(){this.helpBull=0;$("#gschat_bulle").hide()},openChat:function(){this.flagOpen=1;$("#gschat_form").show();$("#gschat_btn").hide();$("#gschat_bulle").hide();$("#gschat_content").scrollTop($("#gschat_inner_content").height());if(this.timerId!=0){window.clearTimeout(gschat.timerId);this.updater()}},closeChat:function(){this.flagOpen=0;$("#gschat_form").hide();$("#gschat_btn").show();if(this.helpBull==1){$("#gschat_bulle").show()}if(this.timerId!=0){window.clearTimeout(gschat.timerId);this.updater()}},postMsg:function(a){if(a.keyCode=="13"){a.preventDefault();var b=$("#gschat_textarea").val();if(b!=""){window.clearTimeout(gschat.timerId);$("#gschat_textarea").val("");$.ajax({type:"POST",url:"/modules/chat/updater.php",data:{task:"post",helpBull:gschat.helpBull,flagActif:gschat.flagActif,flagOpen:gschat.flagOpen,flagWriting:gschat.flagWriting,pageTitle:gschat.pageTitle,msg:b},success:function(d,e,c){if(d.length>0&&d!=""){$("#gschat_inner_content").append(d);if(gschat.flagOpen==0){gschat.openChat()}$("#gschat_content").animate({scrollTop:$("#gschat_inner_content").height()},2000)}gschat.timerId=window.setTimeout(function(){gschat.updater()},5000)},error:function(c,e,d){gschat.timerId=window.setTimeout(function(){gschat.updater()},5000)},dataType:"text"})}}},updateTitle:function(){if(gschat.newMsgWait==true&&gschat.flagActif==0){if(window.document.title==gschat.pageTitle){window.document.title="*** NEW MESSAGES ***"}else{window.document.title=gschat.pageTitle}gschat.newMsgTimer=window.setTimeout(function(){gschat.updateTitle()},1000)}else{window.clearTimeout(gschat.newMsgTimer);gschat.newMsgWait=false;window.document.title=gschat.pageTitle}}};
