// util.js requires jquery-1.3.2.min.js

// Simple form validation that submits if all fields are not empty
// form: The form ID as a String
// nonRequiredFields: non required input ID's as an Array of Strings
function formSubmitWithCheck(form, nonRequiredFields)
{
	$(this).click(preventDefaultAction);
	
	var selectorString = form + " input:not(";
	for (var j=0; j < nonRequiredFields.length; j++)
	{
		selectorString += nonRequiredFields[j];
	}
	selectorString += ")";
	
	var inputs = $(selectorString).get();
	var validForm = true;
	$(inputs).each(function (i) {
		if ($(this).val() == "")
		{
			alert("All fields are required");
			$(this).focus();
			validForm = false;
			return false;
		}
	});
	if (validForm == true)
	{
		$(form).submit();
	}
}

function preventDefaultAction(event)
{
	event.preventDefault();
}

function onPageReady()
{
	if (window.location.hash == "#thanks")
	{
			$("#formHeader").hide();
			$("#formHeaderThanks").show();
			$("#formBoxPadding p").hide();
			$("#formBoxPadding form").hide();
	}
	else if (window.location.hash == "#error")
	{
			//$("#formHeader").hide();
			$("#formHeaderThanks").hide();
			$("#formHeader").show();
			$("#formHeader").html("There was an error sending your entry, <a href=\"index.php\">click here</a> to try again.<br /><br />");
			$("#formBoxPadding p").hide();
			$("#formBoxPadding form").hide();
	}
	else
	{
			$("#formHeader").show();
			$("#formHeaderThanks").hide();
	}
}

	