function friendadd(username)
{
	new Ajax.Request(
		'../profile/friendadd_xml.aspx',
		{
			method:'post',
			parameters:'u='+username,
			onSuccess:friendadd_success,
			onFailure:friendadd_error
		}
	);
}

function friendadd_error(t)
{
	floatbox_setmessage("Error trying to add friend");
	floatbox_show();
}

function friendadd_success(t)
{
	var xmlDoc = t.responseXML.documentElement;
	var msg=xmlDoc.getAttribute("msg");
	
	switch (msg)
	{
		case "success":
			document.getElementById("friendadd_btn").style.display="none";
			floatbox_setmessage("A friend request has been sent.");
			break;
		case "failure":
			floatbox_setmessage("Can not add as friend.");
			break;
		case "blocked":
			floatbox_setmessage("You have been blocked.");
			break;
		case "unauthorised":
			floatbox_setmessage("Please login.");
			break;
		case "yourself":
			floatbox_setmessage("You can not add yourself as a friend.");
			break;
	}
	
	floatbox_show();
}

function getmp3(username,originusername)
{
	var str="";
	if (originusername!=null)
	{
		str='<a href="/'+originusername+'">'+originusername+'</a> originally uploaded this file.<br />';
	}
	floatbox_confirm(str+"This will overwrite your existing mp3. Are you sure?","getmp3_yes('"+username+"');","floatbox_hide();");
}


function getmp3_yes(username)
{
	new Ajax.Request(
		'../profile/getmp3_xml.aspx',
		{
			method:'post',
			parameters:'u='+username,
			onSuccess:getmp3_success,
			onFailure:getmp3_error
		}
	);
}


function getmp3_error(t)
{
	floatbox_setmessage("Error trying to get mp3");
	floatbox_show();
}

function getmp3_success(t)
{
	var xmlDoc = t.responseXML.documentElement;
	var msg=xmlDoc.getAttribute("msg");
	
	switch (msg)
	{
		case "blocked":
			floatbox_setmessage("You have been blocked.");
			break;
		case "success":
			floatbox_setmessage('This is now your mp3.<br /><a href="/mystreakr/">Return to my profile</a>');
			break;
		case "failure":
			floatbox_setmessage("Could not get mp3.");
			break;
		case "unauthorised":
			floatbox_setmessage("Please login.");
			break;
		case "yourself":
			floatbox_setmessage("You already have this mp3.");
			break;
	}
	
	floatbox_show();
}

