var AjaxIM={windows:{},sendBoxWithFocus:null,create:function(B,F){var A=typeof Buddylist.listObjects[B]=="undefined"?"none":Buddylist.listObjects[B].icon;var D=(A=="none"?defaultIcon:pathToIcons+B+"."+A);var E=Math.round(Math.random()*(Browser.width()-360))+"px";var G=Math.round(Math.random()*(Browser.height()-400))+"px";var C=randomString(32)+"_im";this.windows[B]=new IMWindow({id:C,className:"dialog",width:320,height:335,top:G,left:E,resizable:true,title:F,draggable:true,detachable:imDetachable,minWidth:320,minHeight:150,showEffectOptions:{duration:0},hideEffectOptions:{duration:0}});this.windows[B].setConstraint(true,{left:0,right:0,top:0,bottom:0});this.windows[B].getContent().innerHTML='<div class="userToolbar" id="'+C+'_userFuncs"><img src="themes/'+theme+'/window/addbuddy.png" class="toolbarButton" onclick="Dialogs.newBuddy();$(\'newBuddyUsername\').value=\''+B+'\'" alt="'+Languages.get("addBuddyButton")+'" title="'+Languages.get("addBuddyButton")+'" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);" onmousedown="buttonDown(this);" onmouseup="buttonNormal(this);" /> <img src="themes/'+theme+'/window/block.png" class="toolbarButton" onclick="Dialogs.blockBuddy(\''+B+'\');" alt="" title="" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);" onmousedown="buttonDown(this);" onmouseup="buttonNormal(this);" /></div>'+(useIcons?(defaultIcon==""&&A=="none"?"":'<img src="'+D+'" id="buddyIcon_'+B+'" alt="Buddy Icon" class="buddyIcon" onmouseover="IM.buddyIconHover(this);" onmouseout="IM.buddyIconNormal(this);" />'):"")+'<div class="rcvdMessages" id="'+C+'_rcvd"></div>\n<div class="imToolbar" id="'+C+'_toolbar" onmousemove="return false;" onselectstart="return false;"><img src="themes/'+theme+'/window/bold_off.png" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);" onclick="IM.windows[\''+B+'\'].toggleBold();" onmousedown="return false;" alt="'+Languages.get("bold")+'" id="'+C+'_bold" /> <img src="themes/'+theme+'/window/italic_off.png" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);" onclick="IM.windows[\''+B+'\'].toggleItalic();" onmousedown="return false;" alt="'+Languages.get("italic")+'" id="'+C+'_italic" /> <img src="themes/'+theme+'/window/underline_off.png" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);" onclick="IM.windows[\''+B+'\'].toggleUnderline();" onmousedown="return false;" alt="'+Languages.get("underline")+'" id="'+C+'_underline" /></div> <a href="#" class="setFontLink" id="'+C+'_setFont" onclick="IM.windows[\''+B+'\'].toggleFontList();return false;" onselectstart="return false;">Tahoma</a> <a href="#" class="setFontSizeLink" id="'+C+'_setFontSize" onclick="IM.windows[\''+B+'\'].toggleFontSizeList();return false;" onselectstart="return false;">12</a> <a href="#" class="setFontColorLink" id="'+C+'_setFontColor" onclick="IM.windows[\''+B+'\'].toggleFontColorList();return false;" onselectstart="return false;"><div id="'+C+'_setFontColorColor" style="width:14px;height:14px;display:block;"></div></a> <a href="#" class="insertEmoticonLink" id="'+C+'_insertEmoticon" onclick="IM.windows[\''+B+'\'].toggleEmoticonList();return false;" onselectstart="return false;"><img src="themes/'+theme+'/emoticons/mini_smile.gif" width="14" height="14" style="border:0;" /></a>\n<div style="overflow:auto;"><textarea class="inputText" id="'+C+'_sendBox" onfocus="blinkerOn(false);IM.sendBoxWithFocus=this;" onblur="IM.sendBoxWithFocus=null;" onkeypress="return IM.windows[\''+B+"'].keyHandler(event);\"></textarea></div>";this.windows[B].setUsername(B);$(C+"_rcvd").setStyle({height:(this.windows[B].getSize().height-135)+"px",width:(this.windows[B].getSize().width-10)+"px"});$(C+"_toolbar").setStyle({top:(this.windows[B].getSize().height-73)+"px",width:(this.windows[B].getSize().width-10)+"px"});$(C+"_setFont").setStyle({top:(this.windows[B].getSize().height-65)+"px"});$(C+"_setFontSize").setStyle({top:(this.windows[B].getSize().height-65)+"px"});$(C+"_setFontColor").setStyle({top:(this.windows[B].getSize().height-65)+"px"});$(C+"_setFontColorColor").setStyle({backgroundColor:"#000"});$(C+"_insertEmoticon").setStyle({top:(this.windows[B].getSize().height-65)+"px"});$(C+"_sendBox").setStyle({top:(this.windows[B].getSize().height-45)+"px",left:"2px",width:(this.windows[B].getSize().width-16)+"px",fontWeight:"400",fontStyle:"normal",textDecoration:"none"});this.windows[B].show();this.windows[B].toFront();Windows.focusedWindow=this.windows[B];setTimeout("$('"+C+"_sendBox').focus();",250);if(vanishingIcons){setTimeout("if($('buddyIcon_"+B+"')){$('buddyIcon_"+B+"').hide();}",vanishingSpeed)}},sendMessage:function(G,J,E,C,A,D,B,I,H){var F=new XHConn();F.connect(pingTo,"POST","call=send&recipient="+G+"&chatroom="+E+"&bold="+C+"&italic="+A+"&underline="+D+"&font="+B+"&fontsize="+I+"&fontcolor="+H+"&message="+encodeURIComponent(J),function(L){var K=null;switch(L.responseText){case"sent":break;case"sent_offline":K=Languages.get("notifySentButOffline");break;case"not_online":K=Languages.get("errorNotLoggedIn");break;case"too_long":K=Languages.get("errorMsgTooLong");break;case"not_logged_in":if(typeof System!="undefined"){System.logout()}else{self.opener.System.logout()}break;default:K=Languages.get("errorUnknown");break}if(E=="true"){Chatroom.windows[G].sendResult(J,C,A,D,B,I,H,K)}else{IM.windows[G].sendResult(J,C,A,D,B,I,H,K)}});if(audioNotify==true){soundManager.play("msg_out")}},emoteReplace:function(C,D){var B;for(var A in D){if(C.indexOf(A)>-1){C=C.replace(new RegExp(regExpEscape(A),"g"),'<img src="themes/'+theme+"/emoticons/"+D[A]+'" alt="'+D[A]+'" title="'+A+'" />')}}return C},newIMWindow:function(){if($("sendto").value.replace(/^\s*|\s*$/g,"").length>0){var A=$("sendto").value;if(typeof (this.windows[A])=="undefined"){this.create(A,A)}else{if(!this.windows[A].isVisible()){this.windows[A].show();setTimeout("scrollToBottom('"+this.windows[A].getId()+"_rcvd')",125)}}Windows.close("newIM");this.windows[A].toFront();setTimeout("$('"+this.windows[A].getId()+"_sendBox').focus()",125)}else{$("newim_error_msg").innerHTML=Languages.get("newIMProper")}},handleClose:function(A,C){if(C.getId().indexOf("_im")==-1&&C.getId().indexOf("_chat")==-1){return }if(typeof (C.room)!=="undefined"){Chatroom.leave(C.room)}var B=$(C.getId()+"_rcvd");if(imHistory==true){B.innerHTML='<span class="imHistory">'+B.innerHTML.replace(new RegExp("("+Languages.get("autoreply")+":)/g"),Languages.get("autoreply")+":").replace(/<(?![Bb][Rr] ?\/?)([^>]+)>/ig,"")+"</span>\n"}else{B.innerHTML=""}},handleMinimize:function(A,B){if(B.getId().indexOf("_im")==-1){return }var C=$(B.getId()+"_rcvd");C.scrollTop=C.scrollHeight-C.clientHeight+6},createTimestamp:function(){Stamp=new Date();var G=String(Stamp.getHours());var A=String(Stamp.getMinutes());var H=String(Stamp.getSeconds());var B=G>12?G-12:G;var F=G>12?"pm":"am";var J=G>12?"PM":"AM";var D=String(Stamp.getDate());var K=String(Stamp.getMonth()+1);var C=["Jan","Feb","Mar","Apr","May","Jun","July","Aug","Sep","Nov","Dec"][K-1];var I=String(Stamp.getFullYear());var E=I.substring(2);tu=K;tx=D;tQ=G;G=(G.length>1)?G:"0"+G;A=(A.length>1)?A:"0"+A;tq=(B.length>1)?B:"0"+B;H=(H.length>1)?H:"0"+H;D=(D.length>1)?D:"0"+D;K=(K.length>1)?K:"0"+K;if(typeof timestamp=="undefined"){timestamp=self.opener.timestamp}return timestamp.replace(/H/,G).replace(/h/,B).replace(/i/,A).replace(/s/,H).replace(/d/,D).replace(/Y/,I).replace(/y/,E).replace(/m/,K).replace(/u/,tu).replace(/x/,tx).replace(/Q/,tQ).replace(/q/,tq).replace(/a/,F).replace(/A/,J).replace(/M/,C)},notifyUser:function(B,A){if(typeof (IM.windows[B])!="undefined"){if(IM.windows[B].isVisible()){IM.windows[B].sendResult("","","","","","","",A)}}},buddyIconHover:function(A){},buddyIconNormal:function(A){if($(A.id+"_clone")){$(A.id+"_clone").remove()}}};var AjaxIMWindow=Class.create();Object.extend(AjaxIMWindow.prototype,Window.prototype);Object.extend(AjaxIMWindow.prototype,{setUsername:function(A){this.username=A},send:function(){},sendResult:function(J,D,A,E,B,I,H,K){var G=this.getId();var C=$(G+"_sendBox");var F=$(G+"_rcvd");if(K!=null){F.innerHTML=F.innerHTML+'<span class="imError">'+K+"</span><br>"}if(trim(J).length>0){J=J.replace(/<br\/>/g,"\n").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/<([^>]+)>/ig,"").replace(/\n/g,"<br/>").replace(/(\s|\n|>|^)(\w+:\/\/[^<\s\n]+)/,'$1<a href="$2" target="_blank">$2</a>');J=IM.emoteReplace(J,smilies);if(J.replace(/<([^>]+)>/ig,"").indexOf("/me")==0){F.innerHTML=F.innerHTML+'<b class="userA">'+IM.createTimestamp()+" <i>"+user+" "+J.replace(/<([^>]+)>/ig,"").replace(/\/me/,"")+"</i></b><br>\n"}else{F.innerHTML=F.innerHTML+'<b class="userA">'+IM.createTimestamp()+" "+user+':</b> <span style="font-family:'+B+",sans-serif;font-size:"+I+"px;color:"+H+';">'+(D=="true"?"<b>":"")+(A=="true"?"<i>":"")+(E=="true"?"<u>":"")+J+(D=="true"?"</b>":"")+(A=="true"?"</i>":"")+(E=="true"?"</u>":"")+"</span><br>\n"}}scrollToBottom(G+"_rcvd")},toggleBold:function(){var B=this.getId();var A=$(B+"_sendBox");A.hide();if(A.style.fontWeight=="400"){$(B+"_bold").src="themes/"+theme+"/window/bold_on.png";A.setStyle({fontWeight:"700"})}else{A.setStyle({fontWeight:"400"});$(B+"_bold").src="themes/"+theme+"/window/bold_off.png"}A.show();setTimeout("$('"+B+"_sendBox').focus();",125)},toggleItalic:function(){var B=this.getId();var A=$(B+"_sendBox");A.hide();if(A.style.fontStyle=="normal"){A.setStyle({fontStyle:"italic"});$(B+"_italic").src="themes/"+theme+"/window/italic_on.png"}else{A.setStyle({fontStyle:"normal"});$(B+"_italic").src="themes/"+theme+"/window/italic_off.png"}A.show();setTimeout("$('"+B+"_sendBox').focus();",125)},toggleUnderline:function(){var B=this.getId();var A=$(B+"_sendBox");A.hide();if(A.style.textDecoration=="none"){A.setStyle({textDecoration:"underline"});$(B+"_underline").src="themes/"+theme+"/window/underline_on.png"}else{A.setStyle({textDecoration:"none"});$(B+"_underline").src="themes/"+theme+"/window/underline_off.png"}A.show();setTimeout("$('"+B+"_sendBox').focus();",125)},toggleFontList:function(){var A=$("fontsList");var B=$(this.getId()+"_setFont");$("emoticonList","fontColorList","fontSizeList").invoke("hide");if($("fontsList").style.display=="block"){A.hide()}else{A.setStyle({left:Position.cumulativeOffset(B)[0]+"px",top:(Position.cumulativeOffset(B)[1]+Element.getHeight(B)-1)+"px",zIndex:Windows.maxZIndex+20,display:"block"});IM.active=this}},toggleFontSizeList:function(){var A=$("fontSizeList");var B=$(this.getId()+"_setFontSize");$("emoticonList","fontsList","fontColorList").invoke("hide");if($("fontSizeList").style.display=="block"){$("fontSizeList").setStyle({display:"none"})}else{A.setStyle({left:Position.cumulativeOffset(B)[0]+"px",top:(Position.cumulativeOffset(B)[1]+Element.getHeight(B)-1)+"px",zIndex:Windows.maxZIndex+20,display:"block"});IM.active=this}},toggleEmoticonList:function(){var B=$("emoticonList");var A=$(this.getId()+"_insertEmoticon");$("fontsList","fontSizeList","fontColorList").invoke("hide");if($("emoticonList").style.display=="block"){$("emoticonList").setStyle({display:"none"})}else{B.setStyle({left:Position.cumulativeOffset(A)[0]+"px",top:(Position.cumulativeOffset(A)[1]+Element.getHeight(A)-1)+"px",zIndex:Windows.maxZIndex+20,display:"block"});IM.active=this}},toggleFontColorList:function(){var B=$("fontColorList");var A=$(this.getId()+"_setFontColor");$("fontsList","fontSizeList","emoticonList").invoke("hide");if($("fontColorList").style.display=="block"){$("fontColorList").setStyle({display:"none"})}else{B.setStyle({left:Position.cumulativeOffset(A)[0]+"px",top:(Position.cumulativeOffset(A)[1]+Element.getHeight(A)-1)+"px",zIndex:Windows.maxZIndex+20,display:"block"});IM.active=this}},setFont:function(C){var B=this.getId();var A=$(B+"_sendBox");A.hide();A.setStyle({fontFamily:C+", sans-serif"});A.show();$(B+"_setFont").innerHTML=C;setTimeout("$('"+B+"_sendBox').focus();",125);this.toggleFontList("")},setFontSize:function(C){var B=this.getId();var A=$(B+"_sendBox");A.hide();A.setStyle({fontSize:C+"px"});A.show();$(B+"_setFontSize").innerHTML=C;setTimeout("$('"+B+"_sendBox').focus();",125);this.toggleFontSizeList("")},setFontColor:function(A){var C=this.getId();var B=$(C+"_sendBox");B.setStyle({color:A});$(C+"_setFontColorColor").setStyle({backgroundColor:A});setTimeout("$('"+C+"_sendBox').focus();",125);this.toggleFontColorList("")},insertText:function(A){var C=this.getId();var B=$(C+"_sendBox");B.value+=A;setTimeout("$('"+C+"_sendBox').focus();",125);this.toggleEmoticonList();return false},keyHandler:function(E){E=E||window.event;var D=document.all?E.keyCode:E.which;var A=E.shiftKey;if(useLingo){var C=$(this.getId()+"_sendBox").value;if(trim(C).length>0){for(var B=0;B<lingoPunction.length;B++){if(RegExp(lingoPunction[B][0]+"$").test(C)){$(this.getId()+"_sendBox").value=Languages.lingoReplace(C,lingoPunction[B]);if(D==13&&!A){}else{return true}}}}}if(D==13&&!A){this.send();return false}return true},detach:function(){var A=this.getId();newWin=this.username;newWinRcvd=$(A+"_rcvd").innerHTML;this.hide();this.popup=window.open("./popup.html",A+"_im","left="+this.getLocation()["left"]+",top="+this.getLocation()["top"]+",width=320,height=335,toolbar=0,location=1,status=0,menubar=0,resizable=1,scrollbars=0");this.detached=true}});