// Functions to help with challenge-related code

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Accepts the challenge with the given id
function AcceptChallenge(challengeId)
{
	if (confirm("Are you sure you want to accept this challenge?"))
	{
		MakeAjaxRequest('dbConn.php?action=acceptChallenge&id='+challengeId, "challengeDiv", "tabberAutomatic()");
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Declines the challenge with the given id
function DeclineChallenge(challengeId)
{
	if (confirm("Are you sure you want to decline this challenge?"))
	{
		MakeAjaxRequest('dbConn.php?action=declineChallenge&id='+challengeId, "challengeDiv", "tabberAutomatic()");
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Adds a new challenge to the database
function AddNewChallenge(sender_id, receiver_id, game_id, points_to_beat, duration_in_weeks)
{
	if (receiver_id == 0)
	{
		document.getElementById("add_challenge_result").innerHTML = "<strong class='tahoma11red'>Please select the friend you want to challenge.</strong>";
	}
	else if (duration_in_weeks == 0)
	{
		document.getElementById("add_challenge_result").innerHTML = "<strong class='tahoma11red'>Please select a duration for this challenge.</strong>";
	}
	else
	{
		MakeAjaxRequest('dbConn.php?action=addChallenge&sender='+sender_id+'&receiver='+receiver_id+'&game_id='+game_id+'&points='+points_to_beat+'&duration='+duration_in_weeks, "add_challenge_result", 
						"MakeAjaxRequest('dbConn.php?action=displayChallengeInformation&user_id="+sender_id+"&game_id="+game_id+"', 'challengeDiv', 'tabberAutomatic()');");
	}
}

