DOMObjects={xmlParse:function(xmlString){var xmlObj=this.xmlRender(xmlString);if(xmlObj){try{if(this.processor==undefined){this.processor=new XSLTProcessor();this.processor.importStylesheet(this.xmlRender('\
\
'));}
var htmlObj=this.processor.transformToDocument(xmlObj).documentElement;if(htmlObj.tagName.toLowerCase()=='html'){htmlObj=htmlObj.firstChild.firstChild;}
return document.importNode(htmlObj,true);}catch(e){try{var htmlObj=document.importNode(xmlObj.documentElement,true);if(htmlObj.tagName.toLowerCase()=="div"){var div_wrapper=document.createElement('div');div_wrapper.appendChild(htmlObj);if(div_wrapper.innerHTML){div_wrapper.innerHTML=div_wrapper.innerHTML;}
htmlObj=div_wrapper.firstChild;}
return htmlObj;}catch(e){alert("TrophyIM Error: Cannot add html to page "+e.message);}}}},xmlRender:function(xmlString){try{var renderObj=new ActiveXObject("Microsoft.XMLDOM");renderObj.async="false";if(xmlString){renderObj.loadXML(xmlString);}}catch(e){try{if(this.parser==undefined){this.parser=new DOMParser();}
var renderObj=this.parser.parseFromString(xmlString,"application/xml");}catch(e){alert("TrophyIM Error: Cannot create new html for page");}}
return renderObj;},getHTML:function(page)
{return this.xmlParse(HTMLSnippets[page]);},getScript:function(script)
{var newscript=document.createElement('script');newscript.setAttribute('src',script);newscript.setAttribute('type','text/javascript');return newscript;}};TrophyIM={controll:{notificationNewUsers:0},autoConnection:{connect:true},activeChatRoom:{name:[]},chatHistory:{},constants:{stale_roster:false},posWindow:{left:400,top:100},statusConn:{connected:false},_timeOut:{renderRoster:null},removeResult:{idResult:[]},setCookie:function(name,value)
{var expire=new Date();expire.setDate(expire.getDate()+365);document.cookie=name+"="+value+"; expires="+expire.toGMTString();},delCookie:function(name)
{var expire=new Date();expire.setDate(expire.getDate()-365);document.cookie=name+"= ; expires="+expire.toGMTString();delete TrophyIM.cookies[name];},getCookies:function()
{var cObj={};var cookies=document.cookie.split(';');for(var i=0;i=TROPHYIM_LOGLEVEL)
{while(TrophyIM.logging_div.childNodes.length>TROPHYIM_LOG_LINES)
{TrophyIM.logging_div.removeChild(TrophyIM.logging_div.firstChild);}
var msg_div=document.createElement('div');msg_div.className='trophyimlogitem';msg_div.appendChild(document.createTextNode(msg));TrophyIM.logging_div.appendChild(msg_div);TrophyIM.logging_div.scrollTop=TrophyIM.logging_div.scrollHeight;}},rawInput:function(data)
{Strophe.debug("RECV: "+data);},rawOutput:function(data)
{Strophe.debug("SEND: "+data);},login:function()
{if(TrophyIM.JSONStore.store_working)
{TrophyIM.JSONStore.delData(['groups','roster','active_chat','chat_history']);}
TrophyIM.connection=new Strophe.Connection(TROPHYIM_BOSH_SERVICE);TrophyIM.connection.rawInput=TrophyIM.rawInput;TrophyIM.connection.rawOutput=TrophyIM.rawOutput;if(arguments.length>0)
{var barejid=arguments[0];var password=arguments[1];TrophyIM.connection.connect(barejid+TROPHYIM_RESOURCE,password,TrophyIM.onConnect);}
else
{var barejid=document.getElementById('trophyimjid').value
var fulljid=barejid+TROPHYIM_RESOURCE;var password=document.getElementById('trophyimpass').value;var button=document.getElementById('trophyimconnect');loadscript.setUserCurrent(barejid,password);if(button.value=='connect')
{button.value='disconnect';TrophyIM.login(barejid,password);_winBuild('window_login_page','remove');}}
TrophyIM.setCookie('trophyimjid',barejid);},logout:function()
{TrophyIM.autoConnection.connect=false;TrophyIM.delCookie('trophyim_bosh_xid');delete TrophyIM['cookies']['trophyim_bosh_xid'];TrophyIM.connection.disconnect();},onConnect:function(status)
{var loading_gif=document.getElementById("JabberIMRosterLoadingGif");if(status==Strophe.Status.CONNECTING)
{loading_gif.style.display="block";Strophe.info('Strophe is connecting.');}
if(status==Strophe.Status.CONNFAIL)
{TrophyIM.delCookie('trophyim_bosh_xid');TrophyIM.statusConn.connected=false;loading_gif.style.display="block";}
if(status==Strophe.Status.DISCONNECTING)
{TrophyIM.statusConn.connected=false;}
if(status==Strophe.Status.DISCONNECTED)
{if(TrophyIM.autoConnection.connect)
{loading_gif.style.display="block";TrophyIM.delCookie('trophyim_bosh_xid');TrophyIM.statusConn.connected=false;setTimeout(function()
{TrophyIM.showLogin();},10000);loadscript.clrAllContacts();loadscript.setStatusJabber(i18n.STATUS_ANAVAILABLE,"unavailable");delete TrophyIM.rosterObj.roster;delete TrophyIM.rosterObj.groups;}}
if(status==Strophe.Status.CONNECTED)
{loadscript.setStatusJabber(i18n.STATUS_AVAILABLE,'available');TrophyIM.statusConn.connected=true;TrophyIM.showClient();}},showClient:function()
{TrophyIM.setCookie('trophyim_bosh_xid',TrophyIM.connection.jid+"|"+
TrophyIM.connection.sid+"|"+TrophyIM.connection.rid);TrophyIM.rosterObj=new TrophyIMRoster();TrophyIM.connection.addHandler(TrophyIM.onVersion,Strophe.NS.VERSION,'iq',null,null,null);TrophyIM.connection.addHandler(TrophyIM.onRoster,Strophe.NS.ROSTER,'iq',null,null,null);TrophyIM.connection.addHandler(TrophyIM.onPresence,null,'presence',null,null,null);TrophyIM.connection.addHandler(TrophyIM.onMessage,null,'message',null,null,null);TrophyIM.connection.send($iq({type:'get',xmlns:Strophe.NS.CLIENT}).c('query',{xmlns:Strophe.NS.ROSTER}).tree());TrophyIM.connection.send($pres().tree());setTimeout(TrophyIM.renderRoster,1000);},clearClient:function()
{if(TrophyIM.logging_div)
{var logging_div=TrophyIM.client_div.removeChild(document.getElementById('trophyimlog'));}
else
{var logging_div=null;}
while(TrophyIM.client_div.childNodes.length>0)
{TrophyIM.client_div.removeChild(TrophyIM.client_div.firstChild);}
return logging_div;},onVersion:function(msg)
{Strophe.debug("Version handler");if(msg.getAttribute('type')=='get')
{var from=msg.getAttribute('from');var to=msg.getAttribute('to');var id=msg.getAttribute('id');var reply=$iq({type:'result',to:from,from:to,id:id}).c('query',{name:"TrophyIM",version:TROPHYIM_VERSION,os:"Javascript-capable browser"});TrophyIM.connection.send(reply.tree());}
return true;},onRoster:function(msg)
{var roster_items=msg.firstChild.getElementsByTagName('item');for(var i=0;i0)
{for(var i=0;i0)
{for(var i=0;i"+messageDate(delay[0].getAttribute('stamp'))+"":dtNow;var barejid=Strophe.getBareJidFromJid(from);var jidChatRoom=Strophe.getResourceFromJid(from);var jid_lower=barejid.toLowerCase();var contact="";var state="";var chatBox=document.getElementById(jid_lower+"__chatState");var chatStateOnOff=null;var active=msg.getElementsByTagName('active');contact=barejid.toLowerCase();contact=contact.substring(0,contact.indexOf('@'));if(TrophyIM.rosterObj.roster[barejid])
{if(TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'])
{contact=TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'];}}
if(elems.length>0)
{state="";chatStateOnOff=document.getElementById(jid_lower+"__chatStateOnOff");if(active.length>0&chatStateOnOff!=null)
{chatStateOnOff.value='on';}
var _message=document.createElement("div");var _text=Strophe.getText(elems[0]);_text=_text.replace(/onblur/gi,"EVENT_DENY");_text=_text.replace(/onchange/gi,"EVENT_DENY");_text=_text.replace(/onclick/gi,"EVENT_DENY");_text=_text.replace(/ondblclick/gi,"EVENT_DENY");_text=_text.replace(/onerror/gi,"EVENT_DENY");_text=_text.replace(/onfocus/gi,"EVENT_DENY");_text=_text.replace(/onkeydown/gi,"EVENT_DENY");_text=_text.replace(/onkeypress/gi,"EVENT_DENY");_text=_text.replace(/onkeyup/gi,"EVENT_DENY");_text=_text.replace(/onmousedown/gi,"EVENT_DENY");_text=_text.replace(/onmousemove/gi,"EVENT_DENY");_text=_text.replace(/onmouseout/gi,"EVENT_DENY");_text=_text.replace(/onmouseover/gi,"EVENT_DENY");_text=_text.replace(/onmouseup/gi,"EVENT_DENY");_text=_text.replace(/onresize/gi,"EVENT_DENY");_text=_text.replace(/onselect/gi,"EVENT_DENY");_text=_text.replace(/onunload/gi,"EVENT_DENY");_text=_text.replace(/style/gi,"EVENT_DENY");_text=_text.replace(/img /gi,"IMG_DENY ");_text=_text.replace(/script /gi,"SCRIPT_DENY ");_text=_text.replace(/div /gi,"DIV_DENY ");_text=_text.replace(/span /gi,"SPAN_DENY ");_text=_text.replace(/iframe /gi,"IFRAME_DENY ");_message.innerHTML=_text;var scripts=_message.getElementsByTagName('script_deny');for(var i=0;i"+contact+"",msg:""+_message.innerHTML};TrophyIM.addMessage(TrophyIM.makeChat(from),jid_lower,message);}}
else if(type=='groupchat')
{if(_message.hasChildNodes())
{var message={contact:"["+stamp+"] "+jidChatRoom+"",msg:""+_message.innerHTML};TrophyIM.addMessage(TrophyIM.makeChatRoom(barejid),jid_lower,message);}}}
else
{if(chatBox!=null)
state=TrophyIM.getChatState(msg);}
var clearChatState=function()
{chatBox.innerHTML='';}
if(chatBox!=null)
{var clearChatStateTimer;chatBox.innerHTML=""+state+"";var _composing=msg.getElementsByTagName('composing');if(_composing.length==0)
clearChatStateTimer=setTimeout(clearChatState,2000);else
clearTimeout(clearChatStateTimer);}
return true;},getChatState:function(msg)
{var state=msg.getElementsByTagName('inactive');if(state.length>0)
{return i18n.INACTIVE;}
else
{state=msg.getElementsByTagName('gone');if(state.length>0)
{return i18n.GONE;}
else
{state=msg.getElementsByTagName('composing');if(state.length>0)
{return i18n.COMPOSING;}
else
{state=msg.getElementsByTagName('paused');if(state.length>0)
{return i18n.PAUSED;}}}}
return'';},makeChat:function(fulljid)
{var barejid=Strophe.getBareJidFromJid(fulljid);var titleWindow="";var paramsChatBox={'enabledPopUp':((loadscript.getIsIE())?"none":"block"),'idChatBox':barejid+"__chatBox",'jidTo':barejid,'path_jabberit':path_jabberit};titleWindow=barejid.toLowerCase();titleWindow=titleWindow.substring(0,titleWindow.indexOf('@'));if(TrophyIM.rosterObj.roster[barejid])
{if(TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'])
{titleWindow=TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'];}}
TrophyIM.posWindow.top=TrophyIM.posWindow.top+10;if(TrophyIM.posWindow.top>200)
TrophyIM.posWindow.top=100;TrophyIM.posWindow.left=TrophyIM.posWindow.left+5;if(TrophyIM.posWindow.left>455)
TrophyIM.posWindow.left=400;var _content=document.createElement('div');_content.innerHTML=loadscript.parse("chat_box","chatBox.xsl",paramsChatBox);_content=_content.firstChild;var _messages=_content.firstChild.firstChild;var _textarea=_content.getElementsByTagName('textarea').item(0);var _send=_content.getElementsByTagName('input').item(0);var _chatStateOnOff=_content.getElementsByTagName('input').item(1);var _send_message=function()
{if(!TrophyIM.sendMessage(barejid,_textarea.value))
return false;TrophyIM.addMessage(_messages,barejid,{contact:""+i18n.ME+"",msg:"
"+_textarea.value});_textarea.value='';_textarea.focus();};var composingTimer_=0;var isComposing_=0;var timeCounter;var setComposing=function()
{var checkComposing=function()
{if(!isComposing_){composingTimer_=0;clearInterval(timeCounter);TrophyIM.sendContentMessage(barejid,'paused');}else{TrophyIM.sendContentMessage(barejid,'composing');}
isComposing_=0;}
if(!composingTimer_){composingTimer_=1;timeCounter=setInterval(checkComposing,4000);}
isComposing_=1;};loadscript.configEvents(_send,'onclick',_send_message);loadscript.configEvents(_textarea,'onkeyup',function(e)
{if(e.keyCode==13){_send_message();composingTimer_=0;clearInterval(timeCounter);}else{if(_chatStateOnOff.value=='on')
setComposing();}});var winChatBox={id_window:"window_chat_area_"+barejid,barejid:barejid,width:387,height:375,top:TrophyIM.posWindow.top,left:TrophyIM.posWindow.left,draggable:true,visible:"display",resizable:true,zindex:loadscript.getZIndex(),title:titleWindow,closeAction:"hidden",content:_content}
_win=_winBuild(winChatBox);loadscript.notification(barejid);loadscript.getPhotoUser(barejid);_textarea.focus();return(_messages=_win.content().firstChild);},makeChatRoom:function()
{var jidChatRoom=arguments[0];var titleWindow="ChatRoom - "+unescape(arguments[1]);var paramsChatRoom={'idChatRoom':jidChatRoom+"__roomChat",'jidTo':jidChatRoom,'lang_Send':i18n.SEND,'lang_Leave_ChatRoom':i18n.LEAVE_CHATROOM,'path_jabberit':path_jabberit};TrophyIM.posWindow.top=TrophyIM.posWindow.top+10;if(TrophyIM.posWindow.top>200)
TrophyIM.posWindow.top=100;TrophyIM.posWindow.left=TrophyIM.posWindow.left+5;if(TrophyIM.posWindow.left>455)
TrophyIM.posWindow.left=400;var _content=document.createElement('div');_content.innerHTML=loadscript.parse("chat_room","chatRoom.xsl",paramsChatRoom);_content=_content.firstChild;var _messages=_content.firstChild.firstChild;var _textarea=_content.getElementsByTagName('textarea').item(0);var _send=_content.getElementsByTagName('input').item(0);var _leaveChatRoom=_content.getElementsByTagName('input').item(1);var _send_message=function()
{if(!TrophyIM.sendMessageChatRoom(jidChatRoom,_textarea.value))
return false;_textarea.value='';_textarea.focus();};loadscript.configEvents(_send,'onclick',_send_message);loadscript.configEvents(_leaveChatRoom,'onclick',function()
{TrophyIM.leaveChatRoom(jidChatRoom);if(TrophyIM.activeChatRoom.name.length>0)
{for(var i=0;i=0)
{TrophyIM.activeChatRoom.name[i]="";}}}
setTimeout(function()
{_winBuild("window_chat_room_"+jidChatRoom,"remove");},650);});loadscript.configEvents(_textarea,'onkeyup',function(e)
{if(e.keyCode==13)
{_send_message();}});var winChatRoom={id_window:"window_chat_room_"+arguments[0],barejid:jidChatRoom,width:500,height:450,top:TrophyIM.posWindow.top,left:TrophyIM.posWindow.left,draggable:true,visible:"display",resizable:true,zindex:loadscript.getZIndex(),title:titleWindow,closeAction:"hidden",content:_content}
_win=_winBuild(winChatRoom);return(_messages=_win.content().firstChild);},addContact:function(jidTo,name,group)
{var _flag=true;if(TrophyIM.removeResult.idResult.length>0)
{for(var i=0;i0)
groups[groups.length]="Geral";groups.sort();for(var i=0;i0)
{var objContact=arguments[0];var group=arguments[1];var element=arguments[2];var showOffline=loadscript.getShowContactsOffline();var presence="unavailable";var status="";var statusColor="black";var statusDisplay="none";var _resource="";var _presence=function(objContact)
{if(objContact.presence)
{for(var resource in objContact.presence)
{if(objContact.presence[resource].constructor==Function)
continue;if(objContact.presence[resource].show!='invisible')
presence=objContact.presence[resource].show;if(objContact.contact.subscription!="both")
presence='subscription';if(objContact.presence[resource].status)
{status=" ( "+objContact.presence[resource].status+" ) ";statusDisplay="block";}}}};var _subscription=function(objContact)
{if(objContact.contact.subscription!="both")
{switch(objContact.contact.subscription)
{case"none":status=" (( "+i18n.ASK_FOR_AUTH+" )) ";statusColor="red";break;case"to":status=" (( "+i18n.CONTACT_ASK_FOR_AUTH+" )) ";statusColor="orange";break;case"from":status=" (( "+i18n.AUTHORIZED+" )) ";statusColor="green";break;case"subscribe":status=" (( "+i18n.AUTH_SENT+" )) ";statusColor="red";break;case"not-in-roster":status=" (( "+i18n.ASK_FOR_AUTH_QUESTION+" )) ";statusColor="orange";break;default:break;}
statusDisplay="block";}};if(objContact.contact.subscription!="remove")
{var itensJid=document.getElementById("itenContact_"+objContact.contact.jid);if(itensJid==null)
{var nameContact="";if(objContact.contact.name)
nameContact=objContact.contact.name;else
{nameContact=objContact.contact.jid;nameContact=nameContact.substring(0,nameContact.indexOf('@'));}
_presence(objContact);var paramsContact={divDisplay:"block",id:'itenContact_'+objContact.contact.jid,jid:objContact.contact.jid,nameContact:nameContact,path_jabberit:path_jabberit,presence:presence,spanDisplay:statusDisplay,status:status,statusColor:"black",subscription:objContact.contact.subscription,resource:_resource}
_subscription(objContact);if(group!="")
{var _NodeChild=element.firstChild;while(_NodeChild)
{if(_NodeChild.childNodes[0].nodeName.toLowerCase()==="span")
{if(_NodeChild.childNodes[0].childNodes[0].nodeValue===group)
{_NodeChild.innerHTML+=loadscript.parse("itens_group","itensGroup.xsl",paramsContact);}}
_NodeChild=_NodeChild.nextSibling;}}}
else
{_presence(objContact);var is_open=itensJid.parentNode.childNodes[0].style.backgroundImage;is_open=is_open.indexOf("arrow_down.gif");_subscription(objContact);itensJid.setAttribute('subscription',objContact.contact.subscription);with(document.getElementById('span_show_'+'itenContact_'+objContact.contact.jid))
{if(presence=="unavailable"&&!showOffline)
{style.display="none";}
else
{if(is_open>0)
{style.display=statusDisplay;style.color=statusColor;innerHTML=status;}}}
if(presence=="unavailable"&&!showOffline)
{itensJid.style.display="none";}
else
{if(is_open>0)
{itensJid.style.display="block";}}
itensJid.style.background="url('"+path_jabberit+"templates/default/images/"+presence+".gif') no-repeat center left";}
if(!objContact.presence&&!showOffline)
{if(objContact.contact.subscription!="remove")
{with(document.getElementById('span_show_'+'itenContact_'+objContact.contact.jid))
{style.display="none";}
with(document.getElementById('itenContact_'+objContact.contact.jid))
{style.display="none";}}}}}};var flag=false;for(var i=0;i0)
{for(var j=0;j0)
{for(i=0;i0)
{var jidTo=arguments[0];var message_input=arguments[1];message_input=message_input.replace(/^\s+|\s+$|^\n|\n$/g,"");if(message_input!=""){var newMessage=$msg({to:jidTo,from:TrophyIM.connection.jid,type:'chat'});newMessage=newMessage.c('body').t(message_input);newMessage.up();newMessage=newMessage.c('active').attrs({xmlns:'http://jabber.org/protocol/chatstates'});TrophyIM.connection.send(newMessage.tree());return true;}}
return false;},sendMessageChatRoom:function()
{if(arguments.length>0)
{var room_nick=arguments[0];var message=arguments[1];var msgid=TrophyIM.connection.getUniqueId();var msg=$msg({to:room_nick,type:"groupchat",id:msgid}).c("body",{xmlns:Strophe.NS.CLIENT}).t(message);msg.up();TrophyIM.connection.send(msg);return true;}},sendContentMessage:function()
{if(arguments.length>0)
{var jidTo=arguments[0];var state=arguments[1];var newMessage=$msg({to:jidTo,from:TrophyIM.connection.jid,type:'chat'});newMessage=newMessage.c(state).attrs({xmlns:'http://jabber.org/protocol/chatstates'});TrophyIM.connection.send(newMessage.tree());}}};function TrophyIMRoster()
{if(TrophyIM.JSONStore.store_working)
{var data=TrophyIM.JSONStore.getData(['roster','groups']);this.roster=(data['roster']!=null)?data['roster']:{};this.groups=(data['groups']!=null)?data['groups']:{};}
else
{this.roster={};this.groups={};}
this.changes=new Array();if(TrophyIM.constants.stale_roster)
{for(var jid in this.roster)
{this.changes[this.changes.length]=jid;}}
this.addChange=function(jid)
{for(var c=0;ccurrent['priority']&&((presence['show']=="chat"||presence['show']=="available")||(current['show']!="chat"||current['show']!="available")))
{current=presence}}}}
return current;}
this.groupHasChanges=function(group)
{for(var c=0;c0){for(var i=0;i0){for(var i=0;i