	function validateFriend(userID,image,friendName,button)
	{
		
		var xmlData = sendAjaxGetResponse("POST", "index.php?module=module_advancedprofile&&page=modfunc&&func=ajaxValidateFriend&&friend="+userID);
		
		if(button)
		{
			
			clearInnerHTML(button);
			button.appendChild(document.createTextNode("Remove Friend")); 
			button.onclick = function (){removeFriend(userID,image,friendName,button);}
		}
		else{window.location.reload();}
		
	}
	function addFriend(userID,image,friendName,button)
	{
		
		var xmlData = sendAjaxGetResponse("POST", "index.php?module=module_advancedprofile&&page=modfunc&&func=ajaxAddFriend&&friend="+userID);
		
		
		if(parseInt(xmlData) == -1){if(parseInt(xmlData) == -1){locationRedirect("index.php?page=login");}}		
		else
		{
			if(parseInt(xmlData) == 0){locationRedirect("index.php?page=login");}
			else
			{
				if(button)
				{
					clearInnerHTML(button);
					button.appendChild(document.createTextNode("Cancel Friendship Request")); 
					button.onclick = function () {removeFriend(userID,image,friendName,button);}
					
					if(!empty(image)){displayFriendConfirm(image,friendName);}
				}
				else{window.location.reload();}
				
			
			}
		}
		
	}
	function removeFriend(userID,image,friendName,button)
	{
		var xmlData = sendAjaxGetResponse("POST", "index.php?module=module_advancedprofile&&page=modfunc&&func=ajaxRemoveFriend&&friend="+userID);
		
		if(parseInt(xmlData) == -1){if(parseInt(xmlData) == -1){locationRedirect("index.php?page=login");}}
		else
		{
			if(button)
			{
				clearInnerHTML(button);
				button.appendChild(document.createTextNode("Request Friend")); 
				button.onclick = function (evt) {addFriend(userID,image,friendName,button);}
			}
			else{window.location.reload();}
		}
		
	}
	
	
	function displayFriendConfirm(image,friendName)
	{
		
		var div = document.getElementById("friendRequestDiv");
		if(div)
		{
			if(div.style.display == ""){div.style.display = "none";}
			else
			{
				if(!empty(image))
				{
					document.getElementById("requestFriendImage").src = URLDecode(decode64(image));
				}
				var friendUsername = document.getElementById("requestFriendUsername");
				clearInnerHTML(friendUsername);
				friendUsername.appendChild(document.createTextNode(" " + friendName + " "));
				div.style.display = "";
			}
		}
	
	}
