function home_load_friend_events() {

  new Ajax.Request('ajax.php',
	{
		parameters: {
      "_action": 'home_friend_event_load'
    },
		onSuccess: function(response) {
      var json_response = response.responseText.evalJSON();
      if(json_response.ajax_status) {
        $('home_friend_events').innerHTML = json_response.html;
      }
		},
		onFailure: function(){ 
			alert("Error loading your friend events.  Please try again later.");
		}
	});
}

function home_load_upcoming_events() {

  new Ajax.Request('ajax.php',
	{
		parameters: {
      "_action": 'home_upcoming_event_load'
    },
		onSuccess: function(response) {
      var json_response = response.responseText.evalJSON();
      if(json_response.ajax_status) {
        $('home_upcoming_events').innerHTML = json_response.html;
      }
		},
		onFailure: function(){ 
			alert("Error loading your friend events.  Please try again later.");
		}
	});
}

function home_respond_friend_request(target_id, accept) {
  
  new Ajax.Request('ajax.php',
	{
		parameters: {
      "_action": 'userfriend_respond',
      "id": target_id,
      "answer": accept
    },
		onSuccess: function(response) {
      var json_response = response.responseText.evalJSON();
      if(json_response.ajax_status) {
        // Hide Friend Request
        $('home_friend_request_'+target_id).hide();
        
        // If count == 0, hide section
        $('home_friend_requests_section_count').value = $('home_friend_requests_section_count').value - 1;
        if($('home_friend_requests_section_count').value == 0) {
          $('home_friend_requests_section').hide();
        }
      }
		},
		onFailure: function(){ 
			alert("Error responding to your friend request.  Please try again later.");
		}
	});
}

function home_respond_event_request(invite_id, answer) {
  
  new Ajax.Request('ajax.php',
	{
		parameters: {
      "_action": 'invite_respond',
      "invite_id": invite_id,
      "answer": answer,
      "source": 'index'
    },
		onSuccess: function(response) {
      var json_response = response.responseText.evalJSON();
      if(json_response.ajax_status) {
        // Hide Friend Request
        $('home_event_request_'+invite_id).hide();
        
        // If count == 0, hide section
        $('home_event_invites_section_count').value = $('home_event_invites_section_count').value - 1;
        if($('home_event_invites_section_count').value == 0) {
          $('home_event_invites_section').hide();
        }
      }
		},
		onFailure: function(){ 
			alert("Error responding to your friend request.  Please try again later.");
		}
	});
}

function home_notice_event_invite_show_rsvp_options(id)
{
  $('home_event_request_'+id+'_rsvp').hide();
  $('home_event_request_'+id+'_options').show();
}
