/*       Source:  Local Cache                                                                 */
/*     Location:  rsrc:107632:/html/inbox/js/megaboxx.js                                      */
/*      Machine:  10.16.139.109                                                               */
/*    Generated:  July 23rd 2008 7:16:10 AM PDT                                               */
/*    HTTP Host:  static.ak.fbcdn.net                                                         */


var Megaboxx=function(){this._endpoint='/inbox/ajax/ajax.php';}
copy_properties(Megaboxx,{_instance:null,getInstance:function(){if(!Megaboxx._instance){Megaboxx._instance=new Megaboxx();}
return Megaboxx._instance;}});Megaboxx.prototype.select_dropdown_onchange=function(obj){if(obj.value=='^_^'){return false;}
var status=obj.value?this['STATUS_'+obj.value.toUpperCase()]:this.STATUS_NONE;this.set_selection(status);}
Megaboxx.prototype.status_menu_onclick=function(obj,action,threads){threads=threads?threads:this.get_selected_threads();if(!threads.length||(typeof obj=='object'&&obj.parentNode.className.indexOf('disabled')!=-1)){this.update_status_buttons();return false;}
this.reload_needed=false;var post={action:action,ids:threads,folder:megaboxx_data.folder,time:megaboxx_data.time};if(action=='delete'){if(typeof obj=='boolean'&&obj){var boxx=ge('megaboxx');for(var i=0;i<threads.length;i++){var row=document.getElementById('thread_'+threads[i]);row.parentNode.removeChild(row);}
post.page=megaboxx_data.page;post.nav_base=megaboxx_data.nav_base;post.slice=boxx.getElementsByTagName('tr').length;var loading=ge('loading_boxx');if(!boxx.getElementsByTagName('tr').length){this.reload_needed=true;}
if(!loading){var loading=document.createElement('div');loading.innerHTML=['<table id="loading_boxx" class="',boxx.className,'"><tr><td></td></tr></table>'].join('');loading=loading.getElementsByTagName('table')[0];boxx.parentNode.insertBefore(loading,boxx.nextSibling);}else{loading.style.display='';}}else{var dialog=new contextual_dialog();dialog.set_context(obj);dialog.show_choice(((threads.length==1)?tx('inbox:are-you-sure-delete-single'):tx('inbox:are-you-sure-delete-plural')),tx('inbox:this-will-remove-messages'),tx('inbox:delete-button'),function(){this[0].status_menu_onclick(true,action,threads);this[1].hide()}.bind([this,dialog]),tx('sh:cancel-button'),function(){generic_dialog.get_dialog(this).hide()});return false;}}else{for(var i=0;i<threads.length;i++){var row=document.getElementById('thread_'+threads[i]);var status=this.get_status(row);if(action=='toggle_read'){if(status==this.STATUS_UNREAD){action='mark_read';}else{action='mark_unread';}
post.action=action;}
if(action=='mark_read'){row.className=trim(row.className.replace('new_message',''));}else{row.className=trim(row.className.replace(/ ?new_message ?|$/,' new_message '));}}}
new AsyncRequest().setHandler(this.ajax_callback.bind(this)).setData(post).setURI(this._endpoint).send();this.update_status_buttons();var message_selector=ge('message_selector');message_selector?message_selector.selectedIndex=0:false;return false;}
Megaboxx.prototype.ajax_callback=function(response){var result=response.getPayload();if(typeof result=='undefined'){return;}
if(result=='refresh'||this.reload_needed){document.location.reload();return;}
if(typeof(result.nav)!='undefined'&&(megabox_pager=ge('megabox_pager'))){$('megaboxx_pager').innerHTML=result.nav;}
if(typeof(result.rows)!='undefined'){if(result.rows){var tbody=document.createElement('tbody');var boxx=ge('megaboxx');boxx.appendChild(tbody);tbody.innerHTML=result.rows;var rows=tbody.getElementsByTagName('tr');var first_tbody=$('megaboxx').getElementsByTagName('tbody')[0];while(rows.length){first_tbody.appendChild(rows[0]);}
tbody.parentNode.removeChild(tbody);}
$('loading_boxx').style.display='none';}
if(typeof(result.top_nav)!='undefined'){$('nav_inbox').innerHTML=result.top_nav;}}
Megaboxx.prototype.selection_onchange=function(obj){this.update_status_buttons();}
Megaboxx.prototype.get_status=function(row){if(row.className.indexOf('new_message')!=-1){return this.STATUS_UNREAD;}else{return this.STATUS_READ;}}
Megaboxx.prototype.get_thread_id=function(row){return/thread_(\d+)/.exec(row.id)[1];}
Megaboxx.prototype.is_selected=function(row){var inputs=row.getElementsByTagName('input');return inputs.length&&inputs[0].checked;}
Megaboxx.prototype.get_selected_threads=function(){var rows=$('megaboxx').getElementsByTagName('tr');var threads=[];for(var i=0;i<rows.length;i++){if(this.is_selected(rows[i])){threads.push(this.get_thread_id(rows[i]));}}
return threads;}
Megaboxx.prototype.set_selection=function(status){var rows=$('megaboxx').getElementsByTagName('tr');var threads=[];for(var i=0;i<rows.length;i++){if(!status||this.get_status(rows[i])==status){threads.push(this.get_thread_id(rows[i]));}}
this.select_threads(threads,true);}
Megaboxx.prototype.select_threads=function(threads,set){var rows=$('megaboxx').getElementsByTagName('tr');for(var i=0;i<rows.length;i++){if(threads.indexOf(this.get_thread_id(rows[i]))!=-1){rows[i].getElementsByTagName('input')[0].checked=true;}else if(set){rows[i].getElementsByTagName('input')[0].checked=false;}}
this.update_status_buttons();}
Megaboxx.prototype.update_status_buttons=function(){var buttons=ge('inbox_status_buttons');if(!buttons){return;}
var threads=this.get_selected_threads();var unread_disabled=true;var read_disabled=true;for(var i=0;i<threads.length;i++){var status=this.get_status(ge('thread_'+threads[i]));if(status==this.STATUS_UNREAD){read_disabled=false;}else{unread_disabled=false;}}
var message_selector=ge('message_selector');if(!threads.length&&message_selector){message_selector.selectedIndex=0;}
var delete_disabled=read_disabled&&unread_disabled;var li=buttons.getElementsByTagName('li');var loop=[{l:li[0],d:unread_disabled},{l:li[1],d:read_disabled},{l:li[2],d:delete_disabled}];for(var i=0;i<loop.length;i++){if(loop[i].l){loop[i].l.className=trim(loop[i].l.className.replace('menu_disabled',''))+(loop[i].d?' menu_disabled':'');}}}
Megaboxx.prototype.create_hidden_input_helper=function(name,value){var new_input=document.createElement('input');new_input.name=name;new_input.value=value;new_input.type='hidden';return new_input;}
Megaboxx.prototype.submit_prehook=function(obj,inline,captcha_input){var form=ge('compose_message');var length=trim(form.message.value).length;var error_text=null;var ids=ge('ids');var is_update=ge('fbpage_update');var empty_ok=inboxAttachments.attachment_added||(form.subject&&trim(form.subject.value).length);if(length==0&&!empty_ok){error_text=tx('inbox:MSG_ERR_NO_BODY');}else if(length>10000){error_text=tx('inbox:MSG_ERR_TOO_LONG');}else if(!is_update&&ids&&tokenizer.is_empty(ids)){error_text=tx('inbox:MSG_ERR_NO_RECIP');}
if(error_text){var error=ge('error');if(error){error.parentNode.removeChild(error);}
error=document.createElement('div');error.id='error';error.innerHTML='<h2>'+error_text+'</h2>';form.insertBefore(error,form.firstChild);var conf=ge('conf');if(conf){conf.parentNode.removeChild(conf);}
return false;}
if(document.getElementsByName('emails[]').length>0){display_captcha=may_captcha;}
if(typeof captcha_html!='undefined'&&!captcha_input&&display_captcha){var dialog=(new pop_dialog('captcha')).show_choice(tx('inbox:security-check'),captcha_html,tx('sh:submit-button'),function(){this.submit_prehook(obj,inline,get_all_form_inputs(dialog.content));}.bind(this));var inputs=dialog.content.getElementsByTagName('input');for(var i=0;i<inputs.length;i++){if(inputs[i].type=='text'){inputs[i].focus();break;}}
create_captcha();return false;}
if(form.rand_id.value==0){form.rand_id.value=Math.floor((Math.random()*100000000));}
if(inboxAttachments){inboxAttachments.fix_app_inputs_on_send();}
if(inline){var form=obj.form;var post={action:'send_reply',id:form.thread.value,message:form.message.value};if(captcha_input){for(var i=0;i<captcha_input.length;i++){post[captcha_input[i].name]=captcha_input[i].value;}}
var attachment=ge(inboxAttachments.view_id);var inputs=[];if(attachment){inputs=attachment.getElementsByTagName('input');for(var i=0;i<inputs.length;i++){post[inputs[i].name]=inputs[i].value;}}
if(form.extra&&form.extra.checked){post['extra']=form.extra.value;}
new AsyncRequest().setURI(this._endpoint).setData(post).setStatusElement('message_post_status').setHandler(function(response){var text=response.getPayload();var thread=ge('messages');var msg=document.createElement('div');thread.appendChild(msg);set_inner_html(msg,text);form.getElementsByTagName('textarea')[0].value='';var i=0;var msg=null;while(msg=ge('msg_'+(i++))){remove_css_class_name(msg,'unread');}
inboxAttachments.remove_attachment_view();this.enable_all_attachment_forms();var hidden_count=ge('hidden_count');if(hidden_count){hidden_count.innerHTML=parseInt(hidden_count.innerHTML,10)+1;var total_count=ge('total_count');total_count.innerHTML=parseInt(total_count.innerHTML,10)+1;}
var error=ge('error');if(error){error.parentNode.removeChild(error);}}.bind(this)).setFinallyHandler(function(response){get_all_form_inputs(form).each(function(obj){obj.disabled=false;});}).send();inputs=[form.getElementsByTagName('textarea')[0]];var form_inputs=form.getElementsByTagName('input');for(var i=0;i<form_inputs.length;i++){if(form_inputs[i].type=='button'){inputs.push(form_inputs[i]);}}
for(var i=0;i<inputs.length;i++){inputs[i].disabled=true;}}else if(captcha_input){var form=ge('compose_message');var span=document.createElement('span');var html=[];for(var i=0;i<captcha_input.length;i++){html.push('<input type="hidden" name="',captcha_input[i].name,'" value="',htmlspecialchars(captcha_input[i].value),'" />');}
span.innerHTML=html.join('');form.appendChild(span);form.onsubmit=null;form.submit();}
return!inline;}
Megaboxx.prototype.submit_delete=function(obj){(new pop_dialog).show_choice(tx('inbox:delete-thread-title'),tx('inbox:are-you-sure-delete-single'),tx('inbox:delete-button'),function(){var span=document.createElement('span');span.innerHTML='<input name="delete" type="hidden" value="1" />'+'<input name="folder" type="hidden" value="'+megaboxx_data.folder+'" />'+'<input name="time" type="hidden" value="'+megaboxx_data.time+'" />';obj.appendChild(span);var form=obj.getElementsByTagName('input')[0].form;if(megaboxx_data.folder){form.action+='?f=1';}
form.submit();},tx('sh:cancel-button'),function(){generic_dialog.get_dialog(this).hide();});return false;}
Megaboxx.prototype.submit_forward_tps=function(obj){(new pop_dialog).show_choice('Forward Thread to TPS','If you forward this thread to TPS, a ticket will be created for UO to work through with all of the correspondence thus far and you will send the user a message indicating you have forwarded their query to UO.<p>'+'Please note the user will not be able to see your profile due to any of the above, but if you "regular" reply they will be able to see your (limited) profile.</p>'+'<p>Finally, if you\'re corresponding with all Facebook employees, no ticket will be generated.  I think we can all agree that would be pretty silly.</p>','Forward to TPS',function(){var span=document.createElement('span');span.innerHTML='<input name="forward_tps" type="hidden" value="1" />'+'<input name="folder" type="hidden" value="'+megaboxx_data.folder+'" />'+'<input name="time" type="hidden" value="'+megaboxx_data.time+'" />';obj.appendChild(span);var form=obj.getElementsByTagName('input')[0].form;if(megaboxx_data.folder){form.action+='?f=1';}
form.submit();},tx('sh:cancel-button'),function(){generic_dialog.get_dialog(this).hide();});return false;}
Megaboxx.prototype.toggle_all_attachment_forms=function(value){(value?hide:show)(ge('dd_attachment'));(value?hide:show)(ge('dt_attachment'));}
Megaboxx.prototype.enable_all_attachment_forms=function(){this.toggle_all_attachment_forms(false);}
Megaboxx.prototype.disable_all_attachment_forms=function(){this.toggle_all_attachment_forms(true);}
Megaboxx.prototype.reset_rand_id=function(){try{$('compose_message').rand_id.value=0;}catch(e){};}
Megaboxx.prototype.fetch_thread_history=function(count,notice){notice.innerHTML='<span class="loading"><span>'+tx('sh:loading')+'</span></span>';new AsyncRequest().setURI(this._endpoint).setData({id:megaboxx_data.thread_id,action:'history',count:count,folder:megaboxx_data.folder}).setHandler(function(response){var messages=document.createElement('div');notice.parentNode.insertBefore(messages,notice);hide(notice);set_inner_html(messages,response.getPayload());}).send();}
Megaboxx.prototype.STATUS_ALL=0;Megaboxx.prototype.STATUS_READ=1;Megaboxx.prototype.STATUS_UNREAD=2;Megaboxx.prototype.STATUS_NONE=-1;if(typeof tokenizer!='undefined'){tokenizer.prototype.onselect=function(){Megaboxx.getInstance().reset_rand_id();}}
function inbox_search_typeahead(obj,source,properties){this.anchor_block=true;this.parent.construct(this,obj,source,properties);}
inbox_search_typeahead.extend(typeaheadpro);inbox_search_typeahead.prototype.auto_select=false;inbox_search_typeahead.prototype.less_than_n_chars=true;inbox_search_typeahead.prototype.touch_fired=false;inbox_search_typeahead.prototype.show=function(){if(!this.less_than_n_chars){this.parent.show();this.dropdown.style.width='200px';}else{this.hide();}}
inbox_search_typeahead.prototype.hide=function(){this.parent.hide();remove_css_class_name(ge('inbox_search'),'typeahead_border');}
inbox_search_typeahead.prototype.fireTouch=function(){if(!this.touch_fired){AsyncRequest.pingURI('/inbox/ajax/touch.php',{},false);this.touch_fired=true;}}
inbox_search_typeahead.prototype.found_suggestions=function(suggestions,text,fake_data){this.parent.found_suggestions(suggestions,text,fake_data);if(this.list.firstChild&&this.list.firstChild.firstChild){add_css_class_name(this.list.firstChild.firstChild,'blue_top_border');remove_css_class_name(this.list,'no_border_list');add_css_class_name(this.list.lastChild.lastChild,'blue_bottom_border');add_css_class_name(ge('inbox_search'),'typeahead_border');}else{remove_css_class_name(ge('inbox_search'),'typeahead_border');remove_css_class_name(ge('inbox_search'),'typeahead_border');add_css_class_name(this.list,'no_border_list');}}
function inbox_search_friend_source(get_param){this.parent.construct(this,get_param);new AsyncRequest().setMethod('GET').setReadOnly(true).setURI('/inbox/ajax/inbox_search.php?'+get_param).setErrorHandler(function(){}).setHandler(function(response){this.values=response.getPayload().entries;this.build_index();}.bind(this)).send();}
inbox_search_friend_source.extend(static_source);inbox_search_friend_source.prototype.cache_results=true;inbox_search_friend_source.prototype.gen_html=function(friend,highlight){return['<div>',typeahead_source.highlight_found(friend.t,highlight),'</div><div><small>',friend.n,'</small></div>'].join('');}
inbox_search_friend_source.prototype.search_value=function(text){if(!this.is_ready){this.owner.less_than_n_chars=true;return[];}else if(text.length>=2){this.owner.fireTouch();this.owner.less_than_n_chars=false;return this.parent.search_value(text);}
return[];}
function inbox_search_onsubmit(friend){if(friend){goURI(friend.u);return false;}}
function inbox_search_note_close(){AsyncRequest.pingURI('/inbox/ajax/search_note_close.php',{},false);hide(ge('inbox_search_note'));}
if(window.Bootloader){Bootloader.done(1);}