function AudioSubmitController()
{
	var AJAX_SUBMIT_PAGE				= "/ajax/audiosubmit.php";

	var in_transition = false;
	var postbutton = new Button("postbutton");

	this.AudioController = new FileUploadController("portalaudio", 3, new Array("mp3"));
	this.IconController = new FileUploadController("audioicon", 1, new Array("gif"));

	this.Save = function()
	{
		if(in_transition)
		{
			alert("Please wait until the uploads on the page finish.");
			return;
		}

		var agree_element = document.getElementById("agree");
		if((!(IsEdit())) && (agree_element) && (!(agree_element.checked)))
		{
			alert("You must accept the terms of the agreement before you can submit Audio to Newgrounds.");
			document.getElementById("agree").focus();
			return;
		}

		var title_element = document.getElementById("audio_title");
		if(title_element.value.length == 0)
		{
			alert("Please enter a title for your submission.");
			title_element.focus();
			return;
		}

		var audio_upload_id = document.getElementById("portalaudio_temp_upload_id").value;
		if((!(IsEdit())) && (audio_upload_id == ""))
		{
			alert("Please indicate which .mp3 file you'd like to submit.");
			document.getElementById("portalaudio_real").focus();
			return;
		}

		var entryformat_element = document.getElementById("entry_format");
		if(entryformat_element.selectedIndex == 0)
		{
			alert("Please specify whether your submission is a song or a loop.");
			entryformat_element.focus();
			return;
		}

		// Need stuff for genre here.
		var genre_element = document.getElementById("entry_genre");
		if(genre_element.selectedIndex == 0)
		{
			alert("Please specify the genre for your submission.");
			genre_element.focus();
			return;
		}

		var description_element = document.getElementById("author_description");
		if(description_element.value.length == 0)
		{
			alert("Please enter a short description for your submission.");
			description_element.focus();
			return;
		}

		var comments_element = document.getElementById("author_message");
		if(comments_element.value.length == 0)
		{
			alert("Please enter some comments about your submission. Without them, your submission will be harder for users to find.");
			comments_element.focus();
			return;
		}

		// The user could be doing all this without being logged in.
		var username_element = document.getElementById("author_name");
		if(username_element)		// Its presence means they're not logged in yet.
		{
			var userpass_element = document.getElementById("author_pass");

			if(username_element.value.length == 0)
			{
				alert("Please enter your username.");
				username_element.focus();
				return;
			}

			if(userpass_element.value.length == 0)
			{
				alert("Please enter your password.");
				userpass_element.focus();
				return;
			}
		}

		// OK, we're all set.  Assemble our array of stuff to send across
		var params = new Array();
		params["id"] = GetSubmissionID();
		params["agreed"] = "Y";
		params["title"] = title_element.value;
		params["audio_upload_id"] = audio_upload_id;
		params["format_id"] = SelectValue(entryformat_element);
		params["genre"] = SelectValue(genre_element);
		params["description"] = description_element.value;
		params["comments"] = comments_element.value;
		params["icon_upload_id"] = document.getElementById("audioicon_temp_upload_id").value;

		// These may or may not be present
		if(username_element)
		{
			params["username"] = username_element.value;
			params["userpass"] = userpass_element.value;
		}

		StartAnimation();

		var ajax = new AjaxRequest(AJAX_SUBMIT_PAGE);
		ajax.Send(params, HandleSubmitResponse, HandleSubmitError);
	}

	function HandleSubmitResponse(response)
	{
		// Take them right to their new submission!
		window.location.href = response.GetField("url");
	}

	function HandleSubmitError()
	{
		StopAnimation();
	}

	function GetSubmissionID()
	{
		return(document.getElementById("submission_id").value);
	}

	function IsEdit()
	{
		return(GetSubmissionID() != "")
	}

	function StartAnimation()
	{
		in_transition = true;
		postbutton.Disable("Submitting");
		document.getElementById("inprogress").style.display = "";
	}

	function StopAnimation()
	{
		postbutton.Enable();
		document.getElementById("inprogress").style.display = "none";
		in_transition = false;
	}
}