function expandShoutout(user1, user2) {
	
	new ajax ('/userinfo/ajax/shoutout_expand.php' , {
		postBody: 'user1='+ encodeURI(user1) + '&user2=' + encodeURI(user2), 
		update: '', 
		onComplete: ajaxExpandShoutout
	});
	
	return;
}

function ajaxExpandShoutout(request) {
	var php = new PHP_Serializer(true);
	var elem;
	
	if(!request || request.responseText != '-1') {
		if(request.responseText) {
			info = php.unserialize(request.responseText);
			for(i in info) {
				if(parseInt(i)) {
					if(elem == undefined) { //Try and guess target div
						if($(info[i]['user_id'] + '_thread')) {
							elem = $(info[i]['user_id'] + '_thread');
						} else {
							elem = $(info[i]['friend_id'] + '_thread');
						}
      elem.innerHTML = '';
					}
     elem.innerHTML += '<div class="profile-friend-msg"><span>' + info[i]['fdate'] + ':</span><div>' + info[i]['shoutout'] + '</div></div>';
     $(info[i]['user_id'] + '_load').style.display = 'none';
     $(info[i]['user_id'] + '_msg').style.display = 'block';
				}
			}
		}		
	}
	
	return;
}

function collapseShoutout(id1, id2) {
	thread = $(id1 + '_thread');
	link = $(id1 + '_excol');
	link2 = $(id1 + '_excol2');
	thread.innerHTML = '';
	link2.style.display = 'none';
	link.style.display = 'block';
	return;
}

function saveShoutoutReply(member, friend) {
    var message = document.getElementById(friend + '_message').value;
    //makeRequest('/myfiql/editShout.php?friend=' + x + '&member=' + y + '&submit=1&message=' + message, '');
	
	new ajax ('/myfiql/addComment.php' , {
		postBody: 'ajax=1&message='+ encodeURI(message) + '&friend=' + encodeURI(friend) + '&member=' + encodeURI(member), 
		update: '', 
		onComplete: ajaxShoutoutReply
	});
}

function ajaxShoutoutReply(request) {
	var myurl = document.location;
	window.location.href = myurl; //Refresh so that the message gets displayed.
	return;
}


function cancelReply(friendid) {
	var replyBox = $(friendid + '_shoutreply_input');
	var addLink = $(friendid + '_shoutreply_link');
	
	addLink.style.display = 'block';
	replyBox.style.display = 'none';
	
	if($(friendid + '_excol') != undefined)
		$(friendid + '_excol').style.display = 'block';
	if($(friendid + '_thread') != undefined)
		$(friendid + '_thread').style.display = 'block';
	
	return;
}


 function editShoutout(y, x){
  makeRequest('/userinfo/editShout.php?friend=' + x + '&member=' + y, x + '_shout');
 }

 function replyShoutout(friendid) {
   $('friend-message-id').value = friendid;
   $('friend-message').style.marginTop = (posy - 350) + "px";
   $('friend-message').style.display = 'block';
   $('friend-message-input').focus();
 }

 function saveShoutout(y, x){
  var message = document.getElementById(x + '_message').value;
  makeRequest('/userinfo/editShout.php?friend=' + x + '&member=' + y + '&submit=1&message=' + message, x + '_shout');
 }

var last_open = 0;

function toggleMessages(id) {
 if(last_open == id) {
  $(id).style.display = 'none';
  last_open = 0;
 }
 else {
  if(last_open) {
   $(last_open).style.display = 'none';
  }
  $(id).style.display = 'block';
  last_open = id;
 }
}