///////////////////////////////////
//         ajax im 3.41          //
//    AJAX Instant Messenger     //
//   Copyright (c) 2006-2008     //
//    http://www.ajaxim.com/     //
//   Do not remove this notice   //
///////////////////////////////////
/*
function getFlexApp(winId) {
if (navigator.appName.indexOf ("Microsoft") !=-1) {
return window[winId+'_videoEngine'];
} else {
return document[winId+'_videoEngine'];
}
}
function insertVideo(winId, placeId) {
var childId = winId+'_videoEngine';
var swfHolder = document.getElementById(placeId);
swfHolder.innerHTML = "";
var divChild = document.createElement('div');
swfHolder.appendChild(divChild);
divChild.id=childId;
var flashvars = {};
var params = {};
params.allowScriptAccess = "always";
params.scale ="noscale";
//      params.wmode ="opaque";
var attributes = {};
attributes.scale ="noscale";
//      attributes.wmode ="opaque";
swfobject.embedSWF("videoCall.swf", childId, "1", "1", "9.0.0", "",flashvars,params,attributes);
}
*/
var historyInProgress = false;
/**
* AjaxIM Class
*
* @author Joshua Gross
**/
var AjaxIM = {
windows: {},                 // JavaScript object to hold all IM windows
sendBoxWithFocus: null,      // current box that has focus
/**
* Create new IM window
*
* @author Joshua Gross
* @update Benjamin Hutchins
**/
create: function(name, imTitle) {
var buddyicon = typeof Buddylist.listObjects[name] == 'undefined' ? 'none' : Buddylist.listObjects[name].icon;
var iconsrc = (buddyicon=='none'?defaultIcon:pathToIcons+name+'.'+buddyicon);
var imLeft = Math.round(Math.random()*(Browser.width()-360))+'px';
var imTop  = Math.round(Math.random()*(Browser.height()-400))+'px';
var winId = randomString(32) + '_im';
this.windows[name] = new IMWindow({id: winId, className: "dialog", width: 350, height: 335, top: imTop, left: imLeft, resizable: true, title: imTitle, draggable: true, detachable: imDetachable, minWidth: 350, minHeight: 150, showEffectOptions: {duration: 0}, hideEffectOptions: {duration: 0}});
this.windows[name].setConstraint(true, {left: 0, right: 0, top: 0, bottom: 0});
this.windows[name].getContent().innerHTML = '<div class="userToolbar" style="width:100%;" id="' + winId + '_userFuncs">' +
'<img src="themes/'+theme+'/window/call.gif" style="float:right;padding-right:10px;" class="toolbarButton" onclick="BlazeDS.initCall(\'' + name + '\');return false;" alt="" title="" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);" onmousedown="buttonDown(this);" onmouseup="buttonNormal(this);" /> ' +
//'<img src="themes/'+theme+'/window/webcam.png" style="float:right;padding-right:10px;" class="toolbarButton" onclick="IM.windows[\'' + name + '\'].initVideo();return false;" alt="" title="" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);" onmousedown="buttonDown(this);" onmouseup="buttonNormal(this);" /> ' +
'<img src="themes/'+theme+'/window/addbuddy.png" class="toolbarButton" onclick="Dialogs.newBuddy();$(\'newBuddyUsername\').value=\'' + name + '\'" 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(\'' + name + '\');" alt="" title="" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);" onmousedown="buttonDown(this);" onmouseup="buttonNormal(this);" />' +
'</div>' +
(useIcons?(defaultIcon==""&&buddyicon=="none"?'':'<img src="'+iconsrc+'" id="buddyIcon_'+name+'" alt="Buddy Icon" class="buddyIcon" onmouseover="IM.buddyIconHover(this);" onmouseout="IM.buddyIconNormal(this);" />'):'') +
//'<div class="videoBlock" style="text-align:center;" id="' + winId + '_video"></div>' +
'<div class="userToolbar" id="'+winId+'_history">'+Languages.get('history')+' \
<a class="historyLink" onclick="IM.windows[\'' + name + '\'].showHistory(\'1day\'); return false;" href="#">'+Languages.get('1day')+'</a> | \
<a class="historyLink" onclick="IM.windows[\'' + name + '\'].showHistory(\'1week\'); return false;" href="#">'+Languages.get('1week')+'</a> | \
<a class="historyLink" onclick="IM.windows[\'' + name + '\'].showHistory(\'2weeks\'); return false;" href="#">'+Languages.get('2weeks')+'</a> | \
<a class="historyLink" onclick="IM.windows[\'' + name + '\'].showHistory(\'1month\'); return false;" href="#">'+Languages.get('1month')+'</a> | \
<a class="historyLink" onclick="IM.windows[\'' + name + '\'].showHistory(\'2months\'); return false;" href="#">'+Languages.get('2months')+'</a> | \
<a class="historyLink" onclick="IM.windows[\'' + name + '\'].showHistory(\'6months\'); return false;" href="#">'+Languages.get('6months')+'</a> | \
<a class="historyLink" onclick="IM.windows[\'' + name + '\'].showHistory(\'all\'); return false;" href="#">'+Languages.get('all')+'</a>\
</div>' +
'<div class="rcvdMessages" id="' + winId + '_rcvd"></div>' + "\n" +
'<div class="imToolbar" id="' + winId + '_toolbar" onmousemove="return false;" onselectstart="return false;"><img src="themes/'+theme+'/window/bold_off.png" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);" onclick="IM.windows[\'' + name + '\'].toggleBold();" onmousedown="return false;" alt="' + Languages.get('bold') + '" id="' + winId + '_bold" /> ' +
'<img src="themes/'+theme+'/window/italic_off.png" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);" onclick="IM.windows[\'' + name + '\'].toggleItalic();" onmousedown="return false;" alt="' + Languages.get('italic') + '" id="' + winId + '_italic" /> '+
'<img src="themes/'+theme+'/window/underline_off.png" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);" onclick="IM.windows[\'' + name + '\'].toggleUnderline();" onmousedown="return false;" alt="' + Languages.get('underline') + '" id="' + winId + '_underline" /></div>' +
' <a href="#" class="setFontLink" id="' + winId + '_setFont" onclick="IM.windows[\'' + name + '\'].toggleFontList();return false;" onselectstart="return false;">Tahoma</a>' +
' <a href="#" class="setFontSizeLink" id="' + winId + '_setFontSize" onclick="IM.windows[\'' + name + '\'].toggleFontSizeList();return false;" onselectstart="return false;">12</a>' +
' <a href="#" class="setFontColorLink" id="' + winId + '_setFontColor" onclick="IM.windows[\'' + name + '\'].toggleFontColorList();return false;" onselectstart="return false;"><div id="' + winId + '_setFontColorColor" style="width:14px;height:14px;display:block;"></div></a>' +
' <a href="#" class="insertEmoticonLink" id="' + winId + '_insertEmoticon" onclick="IM.windows[\'' + name + '\'].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="' + winId + '_sendBox" onfocus="blinkerOn(false);IM.sendBoxWithFocus=this;" onblur="IM.sendBoxWithFocus=null;" onkeypress="return IM.windows[\'' + name + '\'].keyHandler(event);"></textarea></div>';
this.windows[name].setUsername(name);
//$(winId + '_video').setStyle({height: '200px'});
//$(winId + '_video').setStyle({height: '1px'});
//$(winId + '_rcvd').setStyle({top: ($(winId+'_video').getStyle('height')), height: (this.windows[name].getSize().height - 280) + 'px', width: (this.windows[name].getSize().width - 10) + 'px'});
$(winId + '_history').setStyle({top: '60px', height: '10px', width: (this.windows[name].getSize().width - 10) + 'px'});
$(winId + '_rcvd').setStyle({top: '70px', height: (this.windows[name].getSize().height - 150) + 'px', width: (this.windows[name].getSize().width - 10) + 'px'});
$(winId + '_toolbar').setStyle({top: (this.windows[name].getSize().height - 73) + 'px', width: (this.windows[name].getSize().width - 10) + 'px'});
$(winId + '_setFont').setStyle({top: (this.windows[name].getSize().height - 65) + 'px'});
$(winId + '_setFontSize').setStyle({top: (this.windows[name].getSize().height - 65) + 'px'});
$(winId + '_setFontColor').setStyle({top: (this.windows[name].getSize().height - 65) + 'px'});
$(winId + '_setFontColorColor').setStyle({backgroundColor: '#000'});
$(winId + '_insertEmoticon').setStyle({top: (this.windows[name].getSize().height - 65) + 'px'});
$(winId + '_sendBox').setStyle({top: (this.windows[name].getSize().height - 45) + 'px', left: '2px', width: (this.windows[name].getSize().width - 16) + 'px', fontWeight: '400', fontStyle: 'normal', textDecoration: 'none'});
this.windows[name].show();
try{ this.windows[name].toFront(); } catch (e) {};
Windows.focusedWindow = this.windows[name];
setTimeout("$('"+winId+"_sendBox').focus();", 250);
if (vanishingIcons){setTimeout("if($('buddyIcon_"+name+"')){$('buddyIcon_"+name+"').hide();}", vanishingSpeed);}
//      insertVideo(winId, winId+'_video');
},
/**
* Sends a message to the server
*
* @arguments
*   username - who the message is being sent to
*   message - the message to send
*   chatroom - (bool) is this a chatroom
*   isBold - (bool) is the message bolded
*   isItalic - (bool) is the message italicized
*   isUnderline - (bool) is the message underlined
*   fontName - font family for the message
*   fontSize - font size for the message
*   fontColor - font color for the message
*
* @author Joshua Gross
**/
sendMessage: function(recipient, message, chatroom, isBold, isItalic, isUnderline, fontName, fontSize, fontColor) {
if (typeof(Buddylist.listObjects[recipient]) != 'undefined' && Buddylist.listObjects[recipient].isOnline == false) {
var error = Languages.get('notifySentButOffline');
IM.windows[recipient].sendResult('', isBold, isItalic, isUnderline, fontName, fontSize, fontColor, error);
}
BlazeDS.sendMessage(recipient, message, chatroom, isBold, isItalic, isUnderline, fontName, fontSize, fontColor);
if(audioNotify == true) soundManager.play('msg_out');
},
/**
* Replaces emotes with images
*
* @arguments
*   str - the message to run replaces on
*   itemsList - array of emotes
**/
emoteReplace: function(str, itemsList) {
var r;
for(var s in itemsList) {
if(str.indexOf(s) > -1)
str = str.replace(new RegExp(regExpEscape(s), 'g'), '<img src="themes/' + theme + '/emoticons/' + itemsList[s] + '" alt="' + itemsList[s] + '" title="' + s + '" />');
}
return str;
},
/**
* Start a new message with a user that might not be in your buddy list,
* ran via Dialogs.newIM()
*
* @author Joshua Gross
**/
newIMWindow: function() {
var toWhom = $('sendto').value.replace(/^\s*|\s*$/g,"");
if (toWhom == user) return;
if(toWhom.length == 0) {
$('newim_error_msg').innerHTML = Languages.get('newIMPlease');
return;
}
if(toWhom.length > 16 || toWhom.match(/[,\'`\"\)\(%\^&*<>\\\/]+/)) {
$('newim_error_msg').innerHTML = Languages.get('newIMProper');
return;
}
if(typeof(this.windows[toWhom]) == 'undefined') {
this.create(toWhom, toWhom);
} else {
if(!this.windows[toWhom].isVisible()) {
this.windows[toWhom].show();
setTimeout("scrollToBottom('" + this.windows[toWhom].getId() + "_rcvd')", 125);
}
}
Windows.close('newIM');
this.windows[toWhom].toFront();
setTimeout("$('" + this.windows[toWhom].getId() + "_sendBox').focus()", 125);
},
/**
* @author Joshua Gross
**/
handleClose: function(eventName, win) {
if(win.getId().indexOf('_im') == -1 && win.getId().indexOf('_chat') == -1) return;
if(typeof(win.room) !== 'undefined') Chatroom.leave(win.room);
var rcvdBox = $(win.getId() + '_rcvd');
if(imHistory == true) {
rcvdBox.innerHTML = '<span class="imHistory">' + rcvdBox.innerHTML +
//rcvdBox.innerHTML.replace(new RegExp('\(' + Languages.get('autoreply') + ':\)/g'), Languages.get('autoreply') + ':').replace(/<(\/?[biuspan] ?[\w ()=",:;-]*\/?)+>/ig, '')+ //.replace(/<(?![Bb][Rr] ?\/?)([^>]+)>/ig, '') +
"</span>\n";
} else {
rcvdBox.innerHTML = '';
}
//win.toggleVideo(true);
},
handleFocus: function(eventName, win) {
var sendBox = $(win.getId() + '_sendBox');
if (sendBox != null) {
try { sendBox.focus(); } catch(e) {};
}
},
/**
* @author Joshua Gross
**/
handleMinimize: function(eventName, win) {
if(win.getId().indexOf('_im') == -1) return;
var curIM = $(win.getId() + '_rcvd');
curIM.scrollTop = curIM.scrollHeight - curIM.clientHeight + 6;
//win.toggleVideo(true);
},
/**
* Create a timestamp to use in a chat window based off the
* configuration variable 'timestamp'
*
* @author Joshua Gross
**/
createTimestamp: function(date) {
if (date) {
Stamp = date;
} else {
Stamp = new Date();
}
var tH = String(Stamp.getHours()); var ti = String(Stamp.getMinutes()); var ts = String(Stamp.getSeconds());
var th = tH > 12 ? tH - 12 : tH; var ta = tH > 12 ? 'pm' : 'am'; var tA = tH > 12 ? 'PM' : 'AM';
var td = String(Stamp.getDate()); var tm = String(Stamp.getMonth() + 1);
var tM = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'July', 'Aug', 'Sep', 'Nov', 'Dec'][tm - 1];
var tY = String(Stamp.getFullYear()); var ty = tY.substring(2);
tu = tm; tx = td; tQ = tH;
tH = (tH.length > 1) ? tH : "0"+tH; ti = (ti.length > 1) ? ti : "0"+ti;
tq = (th.length > 1) ? th : "0"+th; ts = (ts.length > 1) ? ts : "0"+ts;
td = (td.length > 1) ? td : "0"+td; tm = (tm.length > 1) ? tm : "0"+tm;
if(typeof timestamp == 'undefined') {
timestamp = self.opener.timestamp;
}
return timestamp.replace(/H/, tH).replace(/h/, th).replace(/i/, ti).replace(/s/, ts)
.replace(/d/, td).replace(/Y/, tY).replace(/y/, ty).replace(/m/, tm)
.replace(/u/, tu).replace(/x/, tx).replace(/Q/, tQ).replace(/q/, tq)
.replace(/a/, ta).replace(/A/, tA).replace(/M/, tM);
},
/**
* Append status changes to chat window
*
* @author Benjamin Hutchins
**/
notifyUser: function(username, error) {
if(typeof(IM.windows[username]) != 'undefined') {
if(IM.windows[username].isVisible()) {
IM.windows[username].sendResult('', '', '', '', '', '', '', error);
}
}
},
/**
* Add effects to a buddy icon.
*
* @arguments
*   el - buddy icon element
*
* @author Benjamin Hutchins
**/
buddyIconHover: function(el) {
/*var clone = new Element('img', {
'src': $(el).src,
//   'id': $(el).id + '_clone',
//   'class': 'buddyIconClone',
//  'alt': '' // valid XHTML
}).insert(Element.getOffsetParent(el), 'content'); //.setStyle({'position': 'absolute', 'top': el.offsetTop, 'left': el.offsetLeft});
//clonePosition(clone, el, {setLeft:true, setTop:true});*/
},
/**
* Restore effects set by IM.buddyIconHover back to 'Normal'
*
* @arguments
*   el - buddy icon element
*
* @author Benjamin Hutchins
**/
buddyIconNormal: function(el) {
if ($(el.id + '_clone')) {
$(el.id + '_clone').remove();
}
}
};
/**
* A class to mantain an IM Window's guts.
*
* @author Joshua Gross
**/
var AjaxIMWindow = Class.create();
Object.extend(AjaxIMWindow.prototype, Window.prototype);
Object.extend(AjaxIMWindow.prototype, {
/**
* Set the class' username variable
*
* @author Joshua Gross
**/
setUsername: function(username) {
this.username = username;
},
send: function() {
// do nothing here.
},
showHistory: function(period) {
if (demoMode) return;
if (historyInProgress) {
return;
}
historyInProgress = true;
var fromDate = new Date();
fromDate.setHours(0);
fromDate.setMinutes(0);
fromDate.setSeconds(0);
fromDate.setMilliseconds(0);
if (period == '1day') fromDate.setDate(fromDate.getDate()-1);
else if (period == "1week") fromDate.setDate(fromDate.getDate()-7);
else if (period == "2weeks") fromDate.setDate(fromDate.getDate()-14);
else if (period == "1month") fromDate.setMonth(fromDate.getMonth()-1);
else if (period == "2months") fromDate.setMonth(fromDate.getMonth()-2);
else if (period == "6months") fromDate.setMonth(fromDate.getMonth()-6);
else if (period == "all") {
fromDate.setDate(1);
fromDate.setMonth(0);
fromDate.setFullYear(2009);
}
var toDate = new Date();
toDate.setHours(23);
toDate.setMinutes(59);
toDate.setSeconds(59);
toDate.setMilliseconds(999);
var contact = this.username;
$(this.getId() + '_rcvd').innerHTML = "";
IMService.getChatHistory(contact, fromDate, toDate, function(response) {
var messages = response.data.chatHistory;
var serverTZ = response.data.serverTZ;
for (var i=0; i<messages.length; i++) {
var sender = messages[i].contact;
var date = messages[i].date;
var tzOffset = date.getTimezoneOffset() * 60000 + serverTZ; //calculate time zone offset
date.setTime(date.getTime()+tzOffset);
var message = messages[i].text;
var isBold = ""+messages[i].bold;
var isItalic = ""+messages[i].italic;
var isUnderline = ""+messages[i].underline;
var fontName = messages[i].fontName;
var fontSize = messages[i].fontSize;
var fontColor = messages[i].fontColor;
IM.windows[contact].printResult(sender, message, isBold, isItalic, isUnderline, fontName, fontSize, fontColor, null, date);
}
historyInProgress = false;
});
},
printResult: function(sender, message, isBold, isItalic, isUnderline, fontName, fontSize, fontColor, result, date) {
var winId = this.getId();
var sendBox = $(winId + '_sendBox');
var rcvdBox = $(winId + '_rcvd');
if(trim(message).length > 0) {
message = message.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>');
message = IM.emoteReplace(message, smilies);
var userClass = "user"+ (sender == user ? 'A' : 'B');
if(message.replace(/<([^>]+)>/ig, '').indexOf('/me') == 0)
rcvdBox.innerHTML = rcvdBox.innerHTML + "<b class=\""+userClass+"\">" + IM.createTimestamp(date) + " <i>" + sender + ' ' + message.replace(/<([^>]+)>/ig, '').replace(/\/me/, '') + "</i></b><br>\n";
else
rcvdBox.innerHTML = rcvdBox.innerHTML + "<b class=\""+userClass+"\">" + IM.createTimestamp(date) + " " + sender + ":</b> <span style=\"font-family:" + fontName + ",sans-serif;font-size:" + fontSize + "px;color:" + fontColor + ";\">" + (isBold == 'true' ? "<b>" : "") + (isItalic == 'true' ? "<i>" : "") + (isUnderline == 'true' ? "<u>" : "") + message + (isBold == 'true' ? "</b>" : "") + (isItalic == 'true' ? "</i>" : "") + (isUnderline == 'true' ? "</u>" : "") + "</span><br>\n";
}
if(result != null) {
rcvdBox.innerHTML = rcvdBox.innerHTML + '<span class="imError">' + result + '</span><br>';
}
scrollToBottom(winId + '_rcvd');
},
/**
* After a message is sent to the server via IM.sendMessage(),
* this function is ran to append the message to the user's window
*
* @arguments
*   message - the message to send
*   isBold - (bool) is the message bolded
*   isItalic - (bool) is the message italicized
*   isUnderline - (bool) is the message underlined
*   fontName - font family for the message
*   fontSize - font size for the message
*   fontColor - font color for the message
*
* @author Joshua Gross
* @update Benjamin Hutchins
**/
sendResult: function(message, isBold, isItalic, isUnderline, fontName, fontSize, fontColor, result) {
this.printResult(user, message, isBold, isItalic, isUnderline, fontName, fontSize, fontColor, result);
},
/*
initVideo: function() {
if (!this.videoEnabled) {
BlazeDS.initCall(this.username);
} else {
this.toggleVideo(false);
}
},
toggleVideo: function(forceClose, sender, recepient, callID, red5url) {
var winId = this.getId()
var width = this.getSize().width;
var height = this.getSize().height;
var delta;
if (typeof forceClose != 'undefined' && forceClose && !this.videoEnabled) {
return;
}
var ve = document.getElementById(winId+'_videoEngine');
var vemb = document.getElementById(winId+'_embed');
if (typeof this.videoEnabled == 'undefined') this.videoEnabled = false;
//      alert('min '+this.options.minHeight);
if (!this.videoEnabled) {
this.videoEnabled = true;
height = height + 150;
delta = 150;
ve.style.width = '217px';
//ve.style.width = width + 'px';
ve.style.height = '142px';
try {
vemb.style.width = '217px';
//vemb.style.width = width + 'px';
vemb.style.height = '142px';
} catch (e) {}
setTimeout(function(){
swfobject.getObjectById(winId+'_videoEngine').startVideo(sender, recepient, callID, red5url);
}, 15);
} else {
swfobject.getObjectById(winId+'_videoEngine').stopVideo();
ve.style.width = '1px';
ve.style.height = '1px';
try {
vemb.style.width = '1px';
vemb.style.height = '1px';
} catch (e) {}
delta = -150;
height = height - 150;
this.videoEnabled = false;
}
this.options.minHeight+=delta;
var curIM = $(winId + '_rcvd');
var curIM_height = curIM.getStyle('height');
curIM_height = parseInt(curIM_height.substring(0, curIM_height.length-2))-delta;
curIM.setStyle({top: (this.getSize()['height'] - 80-curIM_height)  + 'px', height: (curIM_height)+'px'});
this.setSize(width, this.getSize().height+(delta/2));
IM.handleResize('', this, false);
},
*/
/**
* @author Joshua Gross
**/
toggleBold: function() {
var winId = this.getId();
var sendBox = $(winId + '_sendBox');
sendBox.hide(); // horrah weird Opera 9 input refresh!
if(sendBox.style.fontWeight == '400') {
$(winId + '_bold').src = 'themes/' + theme + '/window/bold_on.png';
sendBox.setStyle({fontWeight: '700'});
} else {
sendBox.setStyle({fontWeight: '400'});
$(winId + '_bold').src = 'themes/' + theme + '/window/bold_off.png';
}
sendBox.show(); // horrah weird Opera 9 input refresh!
setTimeout("$('" + winId + "_sendBox').focus();", 125);
},
/**
* @author Joshua Gross
**/
toggleItalic: function() {
var winId = this.getId();
var sendBox = $(winId + '_sendBox');
sendBox.hide(); // horrah weird Opera 9 input refresh!
if(sendBox.style.fontStyle == 'normal') {
sendBox.setStyle({fontStyle: 'italic'});
$(winId + '_italic').src = 'themes/' + theme + '/window/italic_on.png';
} else {
sendBox.setStyle({fontStyle: 'normal'});
$(winId + '_italic').src = 'themes/' + theme + '/window/italic_off.png';
}
sendBox.show(); // horrah weird Opera 9 input refresh!
setTimeout("$('" + winId + "_sendBox').focus();", 125);
},
/**
* @author Joshua Gross
**/
toggleUnderline: function() {
var winId = this.getId();
var sendBox = $(winId + '_sendBox');
sendBox.hide(); // horrah weird Opera 9 input refresh!
if(sendBox.style.textDecoration == 'none') {
sendBox.setStyle({textDecoration: 'underline'});
$(winId + '_underline').src = 'themes/' + theme + '/window/underline_on.png';
} else {
sendBox.setStyle({textDecoration: 'none'});
$(winId + '_underline').src = 'themes/' + theme + '/window/underline_off.png';
}
sendBox.show(); // horrah weird Opera 9 input refresh!
setTimeout("$('" + winId + "_sendBox').focus();", 125);
},
/**
* @author Joshua Gross
**/
toggleFontList: function() {
var fL = $('fontsList');
var fLBtn = $(this.getId() + '_setFont');
$('emoticonList', 'fontColorList', 'fontSizeList').invoke('hide');
if($('fontsList').style.display == 'block') {
fL.hide();
} else {
fL.setStyle({left:    Position.cumulativeOffset(fLBtn)[0] + 'px',
top:     (Position.cumulativeOffset(fLBtn)[1] + Element.getHeight(fLBtn) - 1) + 'px',
zIndex:  Windows.maxZIndex + 20,
display: 'block'});
IM.active = this;
}
},
/**
* @author Joshua Gross
**/
toggleFontSizeList: function() {
var fsL = $('fontSizeList');
var fsLBtn = $(this.getId() + '_setFontSize');
$('emoticonList', 'fontsList', 'fontColorList').invoke('hide');
if($('fontSizeList').style.display == 'block') {
$('fontSizeList').setStyle({display: 'none'});
} else {
fsL.setStyle({left:    Position.cumulativeOffset(fsLBtn)[0] + 'px',
top:     (Position.cumulativeOffset(fsLBtn)[1] + Element.getHeight(fsLBtn) - 1) + 'px',
zIndex:  Windows.maxZIndex + 20,
display: 'block'});
IM.active = this;
}
},
/**
* @author Joshua Gross
**/
toggleEmoticonList: function() {
var eL = $('emoticonList');
var eLBtn = $(this.getId() + '_insertEmoticon');
$('fontsList', 'fontSizeList', 'fontColorList').invoke('hide');
if($('emoticonList').style.display == 'block') {
$('emoticonList').setStyle({display: 'none'});
} else {
eL.setStyle({left:    Position.cumulativeOffset(eLBtn)[0] + 'px',
top:     (Position.cumulativeOffset(eLBtn)[1] + Element.getHeight(eLBtn) - 1) + 'px',
zIndex:  Windows.maxZIndex + 20,
display: 'block'});
IM.active = this;
}
},
/**
* @author Joshua Gross
**/
toggleFontColorList: function() {
var fcL = $('fontColorList');
var fcLBtn = $(this.getId() + '_setFontColor');
$('fontsList', 'fontSizeList', 'emoticonList').invoke('hide');
if($('fontColorList').style.display == 'block') {
$('fontColorList').setStyle({display: 'none'});
} else {
fcL.setStyle({left:    Position.cumulativeOffset(fcLBtn)[0] + 'px',
top:     (Position.cumulativeOffset(fcLBtn)[1] + Element.getHeight(fcLBtn) - 1) + 'px',
zIndex:  Windows.maxZIndex + 20,
display: 'block'});
IM.active = this;
}
},
/**
* @author Joshua Gross
**/
setFont: function(fontname) {
var winId = this.getId();
var sendBox = $(winId + '_sendBox');
sendBox.hide();
sendBox.setStyle({fontFamily: fontname + ', sans-serif'});
sendBox.show();
$(winId + '_setFont').innerHTML = fontname;
setTimeout("$('" + winId + "_sendBox').focus();", 125);
this.toggleFontList('');
},
/**
* @author Joshua Gross
**/
setFontSize: function(size) {
var winId = this.getId();
var sendBox = $(winId + '_sendBox');
sendBox.hide();
sendBox.setStyle({fontSize: size + 'px'});
sendBox.show();
$(winId + '_setFontSize').innerHTML = size;
setTimeout("$('" + winId + "_sendBox').focus();", 125);
this.toggleFontSizeList('');
},
/**
* @author Joshua Gross
**/
setFontColor: function(color) {
var winId = this.getId();
var sendBox = $(winId + '_sendBox');
sendBox.setStyle({color: color});
$(winId + '_setFontColorColor').setStyle({backgroundColor: color});
setTimeout("$('" + winId + "_sendBox').focus();", 125);
this.toggleFontColorList('');
},
/**
* Adds text to a windows' message box
*
* @author Joshua Gross
**/
insertText: function(tti) {
var winId = this.getId();
var sendBox = $(winId + '_sendBox');
sendBox.value += tti;
setTimeout("$('" + winId + "_sendBox').focus();", 125);
this.toggleEmoticonList();
return false;
},
/**
* Checks for pressing on 'Return' or 'Enter'
*
* @author Joshua Gross
* @update Benjamin Hutchins
**/
keyHandler: function(event) {
event = event || window.event;
var asc = document.all ? event.keyCode : event.which;
var shift = event.shiftKey;
Status.lastAction = new Date().getTime();
if(useLingo) {
var message = $(this.getId() + '_sendBox').value;
if(trim(message).length > 0) {
for(var i=0; i<lingoPunction.length; i++) {
if(RegExp(lingoPunction[i][0]+"$").test(message)) {
$(this.getId() + '_sendBox').value = Languages.lingoReplace(message, lingoPunction[i]);
if(asc == 13 && !shift){}else{return true;}
}
}
}
}
if(asc == 13 && !shift) {
this.send();
return false;
}
return true;
},
/**
* Detaches an IM window to a new window
*
* @author Joshua Gross
* @update Benjamin Hutchins
**/
detach: function() {
var winId = this.getId();
newWin = this.username;
newWinRcvd = $(winId + '_rcvd').innerHTML;
this.hide();
this.popup = window.open('./popup.html', winId + '_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;
}
});
