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


function show_addfriend_dialog(to_uid,link_object,source,first_name,post_response_func,pymk_score,is_from_whitelist){if(source===undefined){source='';}
if(pymk_score===undefined){pymk_score=null;}
if(is_from_whitelist===undefined){is_from_whitelist=0;}
post_response_func=post_response_func||_disableAddFriendLink;return _show_addfriend_dialog(to_uid,link_object,source,undefined,undefined,first_name,post_response_func,pymk_score,is_from_whitelist);}
function _show_addfriend_dialog(to_uid,link_object,source,failed_captcha,message,first_name,post_response_func,pymk_score,is_from_whitelist){if(message===undefined){message='';}
dialog=new pop_dialog();dialog.is_stackable=true;if(first_name){dialog.show_loading_title(tx('af09',{user_first_name:first_name}));dialog.do_expand_animation=true;}else{dialog.show_dialog('<div class="dialog_loading">'+tx('sh:loading')+'</div>');}
new AsyncRequest().setURI('/ajax/addfriend.php').setData({uid:to_uid,action:'can_friend',message:message}).setHandler(function(response){var resp=response.getPayload();if(resp==undefined){return false;}
if(resp.karmablocked||resp.karma_warned){dialog.make_modal();}
if(resp.karmablocked){dialog.show_choice(resp.dialog_title,resp.dialog_contents,tx('sh:close-button'),function(){generic_dialog.get_dialog(this).fade_out(100)});}else if(resp.status){if(resp.show_captcha){dialog.show_choice(resp.dialog_title,resp.dialog_contents,tx('af03'),function(){_show_security_check_dialog(to_uid,link_object,source,failed_captcha,$('message').value,first_name,post_response_func,pymk_score,is_from_whitelist)},tx('sh:cancel-button'),function(){if(resp.cancel_js)eval(resp.cancel_js);generic_dialog.get_dialog(this).fade_out(100)});}else{dialog.show_choice(resp.dialog_title,resp.dialog_contents,tx('af03'),function(){_show_followup_dialog(to_uid,link_object,source,failed_captcha,$('message').value,first_name,post_response_func,pymk_score,is_from_whitelist);},tx('sh:cancel-button'),function(){if(resp.cancel_js)eval(resp.cancel_js);generic_dialog.get_dialog(this).fade_out(100)});}}else{dialog.show_message(resp.dialog_title,resp.dialog_contents);}}.bind(this)).setErrorHandler(function(response){generic_dialog.get_dialog(this).fade_out(100);}.bind(this)).send();}
function _show_security_check_dialog(to_uid,link_object,source,failed_captcha,message,first_name,post_response_func,pymk_score,is_from_whitelist){var friend_list_widget=add_to_friend_list_widget.dict[to_uid];var flids='';var flid_name='';if(friend_list_widget){data=friend_list_widget.get_form_data();flids=data.flids;flid_name=data.flid_name;}
var post_vars={'action':'security_check','uid':to_uid,'flids':flids,'flid_name':flid_name,'source':source,'pymk_score':pymk_score,'is_from_whitelist':is_from_whitelist,'message':message,'failed_captcha':(failed_captcha?'1':'0')};new AsyncRequest().setURI('/ajax/addfriend.php').setData(post_vars).setHandler(function(response){var resp=response.getPayload();dialog.show_choice(resp.dialog_title,resp.dialog_contents,tx('af03'),function(){_show_followup_dialog(to_uid,link_object,source,failed_captcha,message,first_name,post_response_func,pymk_score,is_from_whitelist);},tx('sh:cancel-button'),function(){generic_dialog.get_dialog(this).fade_out(100)});}.bind(this)).send();}
function _show_followup_dialog(to_uid,link_object,source,failed_captcha,message,first_name,post_response_func,pymk_score,is_from_whitelist){var friend_list_widget=add_to_friend_list_widget.dict[to_uid];var flids='';var flid_name='';if(friend_list_widget){data=friend_list_widget.get_form_data();flids=data.flids;flid_name=data.flid_name;}
var post_vars={'action':'follow_up','uid':to_uid,'flids':flids,'flid_name':flid_name,'source':source,'pymk_score':pymk_score,'is_from_whitelist':is_from_whitelist,'message':message,'failed_captcha':(failed_captcha?'1':'0')};var captcha_form=ge('captcha_form');if(captcha_form){var captcha_elements=captcha_form.getElementsByTagName('input');for(var i=0;i<captcha_elements.length;i++){post_vars[captcha_elements[i].name]=captcha_elements[i].value;}}
new AsyncRequest().setURI('/ajax/addfriend.php').setData(post_vars).setHandler(function(response){var resp=response.getPayload();if(resp.error!=undefined){dialog.fade_out(100);_show_security_check_dialog(to_uid,link_object,source,true,message,first_name,post_response_func,pymk_score,is_from_whitelist);return false;}
if(resp.suggest_friends){post_response_func(link_object);dialog.hide();FriendSuggesterDialog.show(to_uid,true);}else if(resp.status){post_response_func(link_object);dialog.show_message(resp.dialog_title,resp.dialog_contents);dialog.fade_out(500,1100);}else{dialog.show_choice(resp.dialog_title,resp.dialog_contents,tx('sh:confirm-button'),function(){new AsyncRequest().setURI('/ajax/addfriend.php').setData({'action':'confirm_hs_pending','uid':to_uid}).setHandler(function(response){post_response_func(link_object);dialog.fade_out(100);}).send();},tx('af05'),function(){new AsyncRequest().setURI('/ajax/addfriend.php').setData({'action':'hs_confirm_reject','uid':to_uid}).setHandler(function(response){post_response_func(link_object);dialog.fade_out(100);}).send();},'',tx('af06'),function(){generic_dialog.get_dialog(this).fade_out(100)});}}).send();}
function _disableAddFriendLink(link_object){if(!link_object){return;}
var newNode=document.createElement("span");newNode.innerHTML=tx('af08');newNode.className="holder inactive";if(link_object.parentNode){link_object.parentNode.replaceChild(newNode,link_object);}}
function disableAddFriendLink2(link_object){if(!link_object){return;}
var newNode=document.createElement("span");newNode.innerHTML=tx('af11');newNode.className="holder inactive";if(link_object.parentNode){link_object.parentNode.replaceChild(newNode,link_object);}}
function add_to_friend_list_widget(id,is_reqs_page){this.fl_added=[];this.fbid=id;this.fl_widget=ge('add_to_friend_list_widget_'+this.fbid);if(!this.fl_widget){return;}
this.fl_select=$('add_to_friend_list_widget_select_'+this.fbid);this.fl_input=$('add_to_friend_list_widget_create_name_'+this.fbid);this.fl_add=$('add_to_fl_widget_add_button_'+this.fbid);this.fl_selector=$('add_to_friend_list_widget_selector_'+this.fbid);this.fl_lists_ul=$('add_to_friend_list_widget_lists_'+this.fbid);this.fl_mode_switch=$('add_to_friend_list_widget_mode_switch_'+this.fbid);this.basic_mode_switch=$('add_to_friend_list_widget_basic_mode_switch_'+this.fbid);this.create_list_link=$('add_to_friend_list_widget_create_list_link_'+this.fbid);var a_elem=$('add_to_friend_list_widget_new_list_cancel_button_'+this.fbid).getElementsByTagName('a');if(a_elem&&a_elem.length){a_elem[0].onclick=function(){this.create_list_cancel_link_onclick();return false;}.bind(this);}
if(is_reqs_page){this.is_reqs_page=true;}
if(!add_to_friend_list_widget.list_tdata){add_to_friend_list_widget.list_tdata={};for(var i=0;i<this.fl_select.options.length;i++){if(this.fl_select.options[i].value.indexOf('fl_')!=-1){var flid=this.fl_select.options[i].value.replace('fl_','');add_to_friend_list_widget.list_tdata[flid]=this.fl_select.options[i].text;}}}
this.fl_add.onclick=function(){this.fl_button_click_handler();return false;}.bind(this);this.fl_select.onchange=function(){this.select_onchange_handler();}.bind(this);this.fl_mode_switch.childNodes[0].onclick=function(){this.fl_mode_switch_handler();return false;}.bind(this);this.basic_mode_switch.childNodes[0].onclick=function(){this.basic_mode_switch_handler();return false;}.bind(this);this.create_list_link.childNodes[0].onclick=function(){this.create_list_link_onclick();return false;}.bind(this);this.fl_input.onkeypress=function(event){return this._onkeypress(event||window.event);}.bind(this);add_to_friend_list_widget.instances.push(this);add_to_friend_list_widget.dict[id]=this;}
add_to_friend_list_widget.instances=[];add_to_friend_list_widget.dict={};add_to_friend_list_widget.prototype.fl_select_options=[];add_to_friend_list_widget.prototype.select_onchange_handler=function(){var value=get_form_select_value(this.fl_select);var selected_index=this.fl_select.selectedIndex;if(value=='create_new'){add_css_class_name(this.fl_widget,'add_fl_show_create_list');this.fl_input.focus();}else{if(value.indexOf('fl_')!=-1){var flid=value.replace('fl_','');if(flid==0){var display_value=this.fl_select.options[selected_index].text;}else{var display_value=add_to_friend_list_widget.list_tdata[flid];}
this.fl_select.options[selected_index]=null;this.fl_added.push({key:flid,value:display_value});remove_css_class_name(this.fl_lists_ul,'no_lists_added');this.fl_lists_ul.appendChild(this.build_ul_item(flid,display_value));add_css_class_name(this.fl_selector,'basic_mode_switch_disabled');remove_css_class_name(this.basic_mode_switch,'basic_mode_switch_disabled');add_css_class_name(this.fl_widget,'add_to_friend_list_widget_list_added');}}
set_form_select_value(this.fl_select,'choose');if(this.fl_select.options.length==3){add_css_class_name(this.fl_widget,'add_fl_show_create_list');this.rebuild_fl_select();}}
add_to_friend_list_widget.prototype.remove_friend_list_handler=function(key,value){var list_i=false;for(var i=0;i<this.fl_added.length;i++){if(key!==0){if(this.fl_added[i]['key']==key){list_i=i;break;}}else{if(this.fl_added[i]['value']==value){list_i=i;while(this.fl_select_options.length>0){this.fl_select.options[this.fl_select.options.length]=this.fl_select_options.shift();}
break;}}}
if(list_i!==false){this.fl_added.splice(list_i,1);this.rebuild_fl_select();this.rebuild_ul_list();}
if(this.fl_added.length==0){add_css_class_name(this.fl_lists_ul,'no_lists_added');remove_css_class_name(this.fl_widget,'add_to_friend_list_widget_list_added');this.basic_mode_switch_handler();if(this.has_lists()){remove_css_class_name(this.fl_widget,'add_fl_show_create_list');}else{add_css_class_name(this.fl_widget,'add_fl_show_create_list');}}}
add_to_friend_list_widget.prototype.fl_button_click_handler=function(){if(has_css_class_name(this.fl_input,'DOMControl_placeholder')){return;}
var value=this.fl_input.value;if(value.trim()!=''){this.fl_added.push({key:0,value:value});this.fl_lists_ul.appendChild(this.build_ul_item(0,value));remove_css_class_name(this.fl_lists_ul,'no_lists_added');add_css_class_name(this.fl_selector,'basic_mode_switch_disabled');if(this.has_lists()){remove_css_class_name(this.basic_mode_switch,'basic_mode_switch_disabled');}
this.fl_select_options.push(this.fl_select.options[this.fl_select.options.length-2]);this.fl_select_options.push(this.fl_select.options[this.fl_select.options.length-1]);this.fl_select.options[this.fl_select.options.length-2]=null;this.fl_select.options[this.fl_select.options.length-1]=null;remove_css_class_name(this.fl_widget,'add_fl_show_create_list');add_css_class_name(this.fl_widget,'add_to_friend_list_widget_list_added');this.get_data();}
this.fl_input.value='';}
add_to_friend_list_widget.prototype.has_lists=function(){for(var k in add_to_friend_list_widget.list_tdata){return true;}}
add_to_friend_list_widget.prototype.fl_mode_switch_handler=function(){remove_css_class_name(this.fl_widget,'add_fl_show_create_list');}
add_to_friend_list_widget.prototype.basic_mode_switch_handler=function(){remove_css_class_name(this.fl_selector,'basic_mode_switch_disabled');add_css_class_name(this.basic_mode_switch,'basic_mode_switch_disabled');}
add_to_friend_list_widget.prototype._onkeypress=function(e){var key=e?event_get_keypress_keycode(e):-1;switch(key){case 13:if(!has_css_class_name(this.fl_widget,'add_to_friend_list_widget_is_reqs_no_lists_active')){this.fl_button_click_handler();}
event_prevent(e);return false;}}
add_to_friend_list_widget.prototype.create_list_link_onclick=function(){remove_css_class_name(this.fl_widget,'add_to_friend_list_widget_is_reqs_no_lists');add_css_class_name(this.fl_widget,'add_to_friend_list_widget_is_reqs_no_lists_active');this.fl_input.focus();}
add_to_friend_list_widget.prototype.create_list_cancel_link_onclick=function(){add_css_class_name(this.fl_widget,'add_to_friend_list_widget_is_reqs_no_lists');remove_css_class_name(this.fl_widget,'add_to_friend_list_widget_is_reqs_no_lists_active');}
add_to_friend_list_widget.prototype.rebuild_fl_select=function(){var for_select=[];for(var k in add_to_friend_list_widget.list_tdata){var do_not_include=false;for(var i=0;i<this.fl_added.length;i++){if(this.fl_added[i].key==k){do_not_include=true;break;}}
if(!do_not_include){for_select.push({fbid:k,name:add_to_friend_list_widget.list_tdata[k]});}}
var sorted_names=for_select.sort(function(a,b){if(a.name>b.name)return 1;else if(a.name<b.name)return-1;else return 0;});var other_options=[];for(var i=0;i<this.fl_select.options.length;i++){if(this.fl_select.options[i].value.indexOf('fl_')==-1){other_options.push({value:this.fl_select.options[i].value,text:this.fl_select.options[i].text});}}
this.fl_select.options.length=0;this.fl_select.options[0]=new Option(other_options[0].text,other_options[0].value);for(var i=0;i<sorted_names.length;i++){this.fl_select.options[1+i]=new Option(sorted_names[i]['name'],'fl_'+sorted_names[i]['fbid']);}
for(var i=1;i<other_options.length;i++){this.fl_select.options[this.fl_select.options.length]=new Option(other_options[i].text,other_options[i].value);}
this.fl_select.selectedIndex=0;if(for_select.length>0){remove_css_class_name(this.fl_mode_switch,'mode_switch_disabled');remove_css_class_name(this.fl_mode_switch,'add_to_friend_list_widget_is_reqs_no_lists');this.fl_mode_switch_handler();}else{add_css_class_name(this.fl_mode_switch,'mode_switch_disabled');}}
add_to_friend_list_widget.prototype.get_form_data=function(){var flids='';var flid_name='';data=this.get_data();for(var i=0;i<data.length;++i){if(data[i].fbid){flids+=data[i].fbid+',';}else if(data[i].name){flid_name=data[i].name;}}
return{'flids':flids,'flid_name':flid_name};}
add_to_friend_list_widget.prototype.get_data=function(){var data=[];if(has_css_class_name(this.fl_widget,'add_to_friend_list_widget_is_reqs_no_lists_active')){var value=this.fl_input.value;if(value.trim()!=''){this.fl_added.push({key:0,value:value});}}
for(var i=0;i<this.fl_added.length;i++){var key=this.fl_added[i]['key'];data.push({fbid:key,name:this.fl_added[i]['value']});}
return data;}
add_to_friend_list_widget.prototype.reconfig_display=function(){if(this.fl_select.options.length==4){remove_css_class_name(this.fl_widget,'add_to_friend_list_widget_is_reqs_no_lists_active');remove_css_class_name(this.fl_widget,'add_to_friend_list_widget_is_reqs_no_lists');}}
add_to_friend_list_widget.prototype.build_ul_item=function(key,value){var li=document.createElement('li');var span=document.createElement('span');span.className='fl_widget_text';span.appendChild(document.createTextNode(value+' '));li.appendChild(span);var a=document.createElement('a');a.onclick=function(){this.remove_friend_list_handler(key,value);return false;}.bind(this,{key:key,value:value});a.href='#';a.appendChild(document.createTextNode(tx('af10')));li.appendChild(a);return li;}
add_to_friend_list_widget.prototype.rebuild_ul_list=function(){this.fl_lists_ul.innerHTML='';for(var i=0;i<this.fl_added.length;i++){if(this.fl_added[i]['key']!==0){this.fl_lists_ul.appendChild(this.build_ul_item(this.fl_added[i]['key'],add_to_friend_list_widget.list_tdata[this.fl_added[i]['key']]));}else{this.fl_lists_ul.appendChild(this.build_ul_item(this.fl_added[i]['key'],this.fl_added[i]['value']));}}}
add_to_friend_list_widget.add_new_list=function(name,flid){add_to_friend_list_widget.list_tdata[flid]=name;for(var i=0;i<add_to_friend_list_widget.instances.length;i++){add_to_friend_list_widget.instances[i].rebuild_fl_select();}}
if(window.Bootloader){Bootloader.done(1);}