/**
 * Show a JavaScript confirmation dialogue to the user. If they click the OK button then the standard formAction
 * function is called with the supplied formName and formActionValue arguments.
 *
 * Describe the action which is being confirmed by the user so that it fits into the sentence "Click 'OK' if you
 * are sure you want to <actionDescription>, otherwise click 'Cancel'.".
 * 
 * @see form-action.js#formAction
 * 
 * @param formName Name of the form which formAction will submit.
 * @param formActionValue Value which formAction will give to the form's form_action parameter.
 * @param actionDescription Optional descriptive text (defaults to "do this").
 */

function formActionConfirm(formName, formActionValue, actionDescription)
{
	if (isSufficientArguments("formActionConfirm", arguments, 2))
	{
		var message = "Click 'OK' if you are sure you want to ";

		if (arguments.length >= 3)
		{
			message += actionDescription;
		}
		else
		{
			message += "do this";
		}

		message += ", otherwise click 'Cancel'.";

		if (window.confirm(message))
		{
			formAction(formName, formActionValue);
		}
	}
}

/**
 * Show a JavaScript confirmation dialogue to the user. If they click the OK button then the standard formAction
 * function is called with the supplied formName and formActionValue arguments. Intended to save a little work
 * when the action being confirmed is the deletion of something.
 *
 * Describe the object the deletion of which is being confirmed by the user so that it fits into the sentence
 * "Click 'OK' if you are sure you want to delete <objectDescription>, otherwise click 'Cancel'.".
 * 
 * @See formActionConfirm
 * 
 * @param formName Name of the form which formAction will submit.
 * @param formActionValue Value which formAction will give to the form's form_action parameter.
 * @param objectDescription Optional descriptive text (defaults to "this").
 */
function formActionConfirmDelete(formName, formActionValue, objectDescription)
{
	if (isSufficientArguments("formActionConfirmDelete", arguments, 2))
	{
		var actionDescription = "delete ";

		if (arguments.length >= 3)
		{
			actionDescription += objectDescription;
		}
		else
		{
			actionDescription += "this";
		}

		formActionConfirm(formName, formActionValue, actionDescription);
	}
}

/**
 * Show a JavaScript confirmation dialogue to the user. If they click the OK button then the standard formAction
 * function is called with the supplied formName and formActionValue arguments. Intended to save a little work
 * when the action being confirmed is the cancellation of something.
 *
 * Describe the object the cancellation of which is being confirmed by the user so that it fits into the sentence
 * "Click 'OK' if you are sure you want to cancel <objectDescription>, otherwise click 'Cancel'.".
 * 
 * @See formActionConfirm
 * 
 * @param formName Name of the form which formAction will submit.
 * @param formActionValue Value which formAction will give to the form's form_action parameter.
 * @param objectDescription Optional descriptive text (defaults to "this").
 */
function formActionConfirmCancel(formName, formActionValue, objectDescription)
{
	if (isSufficientArguments("formActionConfirmCancel", arguments, 2))
	{
		var actionDescription = "cancel ";

		if (arguments.length >= 3)
		{
			actionDescription += objectDescription;
		}
		else
		{
			actionDescription += "this";
		}

		formActionConfirm(formName, formActionValue, actionDescription);
	}
}
