function removeBox(obj, application_name, app_id) {
  var dialog = new contextual_dialog();
  dialog.set_context(obj);
  dialog.show_prompt('Would you like to remove ' + application_name + ' from your profile?', get_remove_prompt(application_name, app_id));
  add_css_class_name(obj, 'box_remove_selected');
  return false;
}

var REMOVE_BOX_ONLY = 1;
var REMOVE_ENTIRE_APP = 2;

function get_remove_prompt(application_name, app_id) {
  return '<div class=\'remove_option\' onclick="remove_app(event, ' + 
    REMOVE_BOX_ONLY + ',\'' + app_id +
    '\'); generic_dialog.get_dialog(this).hide();">Remove this box from my profile but keep the application.</div>' + 

    '<div class=\'remove_option\' onclick="remove_app(event, ' + 
    REMOVE_ENTIRE_APP + ',\'' + app_id + 
    '\'); generic_dialog.get_dialog(this).hide();">Remove this application ' + 
    'from my Facebook account.' + '</div>' + 

    '<a href="#" style="padding: 4px 0px 0px 5px;" onclick="generic_dialog.get_dialog(this).hide(); ' +
    'remove_css_class_name(ge(\'remove_' + app_id + '\'), \'box_remove_selected\');' + 
    'return false;">Cancel</a>';
}

function remove_app(e, remove_type, app_id) {
  ge(app_id).style.display = 'none';
  var error_message = 'Sorry, removing this profile box failed.';
  var ajax = new Ajax( function(obj, text) {
                         eval(text);
                         if (!success) {
                           alert(error_message);
                         }
                       });

  ajax.onFail = function() {
    alert(error_message); 
  }
  var post = {'app_id' : app_id, 'remove_type' : remove_type };
  ajax.post('/ajax/profile_boxes.php', post);
}

function flexToggle(el) { 
  if (el.className == 'flex_open') { 
    el.className = 'flex_shut'; 
    profileFlexAjax(el.id, 1); 
  } else { 
    el.className = 'flex_open'; 
    profileFlexAjax(el.id, 0); 
  } 
} 


function boxFlexToggle(el) {
  if (has_css_class_name(el, 'flex_open')) {
    remove_css_class_name(el, 'flex_open');
    add_css_class_name(el, 'flex_shut');
    profileBoxFlexAjax(el.id, 1);
  } else {
    remove_css_class_name(el, 'flex_shut');
    add_css_class_name(el, 'flex_open');
    profileBoxFlexAjax(el.id, 0); 
  }
  
  return false;
}

profileFlexAjax = function(elId, val) {
  var ajax = new Ajax()
  ajax.onDone = function() {
  }
  ajax.onFail = function() {
  }
  ajax.post('ajax/profile_flex_ajax.php', elId + '=' + val); 
}

profileBoxFlexAjax = function(elId, val) { 
  var ajax = new Ajax() 
  ajax.onDone = function() { 
  } 
  ajax.onFail = function() { 
  } 

  ajax.post('ajax/profile_box_flex_ajax.php', { 'app_id' : elId, 'value' : val }); 
} 

function minifeed_hide(clickedElement, story_id)
{
  var minifeed_dialog_handle=new contextual_dialog();
  minifeed_dialog_handle.set_context(clickedElement);
  minifeed_dialog_handle.show_choice('Are you sure you want to hide this mini-feed story?', 'Hiding will remove the story from your Mini-Feed and prevent anyone from seeing it.', 'Hide Story', '', 'Cancel', '');
  var minifeed_inputs=minifeed_dialog_handle.obj.getElementsByTagName('input');
  minifeed_inputs[0].onclick=function() { minifeed_hide_click(story_id); generic_dialog.get_dialog(this).fade_out(100); };
  minifeed_inputs[1].onclick=function() { generic_dialog.get_dialog(this).hide(); };
  return false;
}

function minifeed_hide_click(hide_id)
{
  ajax = new Ajax();
    
  ajax.onDone = function () {
    
  }
  ajax.onFail = function () {
    alert("Sorry, hiding this story failed");
  }

  story=ge('story_' + hide_id);
  if (story.previousSibling.className=='date_divider' && story.nextSibling.className.indexOf('story')==-1) {
    remove_node(story.previousSibling);
  }
  else if (story.previousSibling.className=='date_divider') {
    story.nextSibling.className+=' no_border';
  }
  remove_node(story);
  
  minifeed_decrement_story_count();
  
  ajax.post('minifeed.php', { 'hide_ministory_key' : hide_id });
}

function minifeed_decrement_story_count() {
  var text;
  var mf_story_count_string_array = new Array();
  var count_el = ge('mf_story_count_string');
  if (!count_el) return;
  var count = parseInt(count_el.innerHTML.split(' ')[0]);
  count = count - 1;
  if(count == 1) {
    text = 'story';
  } else {
    text = 'stories';
  }
  count_el.innerHTML = (count)+' '+text;
}

function show_profile_layout_dialog() {
 
  var dialog = new pop_dialog();
  dialog.show_message('Profile Layout',
                      'You can edit the layout of your profile at any time. Use your mouse to drag and drop the boxes for Information, Photos, etc.'
                     +' Hover over the header for a box, then drag and drop the box wherever you want it.'
                     +'<br/><br/>'
                     +' Please note that you cannot move your Mini-Feed or Friends box.'
                     );
}

 
function show_public_profile_dialog(url) {
  var dialog = new pop_dialog();
  dialog.show_message('Public Listing',
                      'Your public listing contains some information about you that anyone can see, such as your name and networks.'
                     +'<br/><br/>'
                     +'Anyone who is not logged into Facebook can view your public listing at this URL:'
                     +'<br/><br/>'
                     +'<span style="color: #3b5998; border: 1px solid #ccc; padding: 5px; margin: 5px;">'
                     +url
                     +'</span>'
                     +'<br/><br/>'
                     +'It is only available if you have not restricted any of your search privacy settings.'
                     );
}



