/*
	Ensure all fields are filled out and valid.  Submit ajax.
*/

function SubmitContactForm()
{
	if (document.ContactForm.Name.value.trim().length <= 1 || document.ContactForm.Name.value.trim().length > 50)
	{
		FocusOnField(document.ContactForm.Name);
		ShowPopup("ERROR", "Please enter your name (up to 50 characters).");
		return false;
	}
	else if (!IsValidEmail(document.ContactForm.Email.value) || document.ContactForm.Email.value.trim().length > 50)
	{
		FocusOnField(document.ContactForm.Email);
		ShowPopup("ERROR", "Please enter a valid e-mail address (up to 50 characters).");
		return false;
	}
	else if (document.ContactForm.Phone.value.trim().length <= 1 || document.ContactForm.Phone.value.trim().length > 50)
	{
		FocusOnField(document.ContactForm.Phone);
		ShowPopup("ERROR", "Please enter your phone number (up to 50 characters).");
		return false;
	}
	else if (document.ContactForm.City.value == "")
	{
		FocusOnField(document.ContactForm.City);
		ShowPopup("ERROR", "Please choose your city.");
		return false;
	}
	else if (document.ContactForm.Message.value.trim().length <= 1 || document.ContactForm.Message.value.trim().length > 1000)
	{
		FocusOnField(document.ContactForm.Message);
		ShowPopup("ERROR", "Please enter your message (up to 1000 characters).");
		return false;
	}
	
	Parameters =	"&Name=" + document.ContactForm.Name.value +
			"&Email=" + document.ContactForm.Email.value +
			"&Phone=" + document.ContactForm.Phone.value +
			"&City=" + document.ContactForm.City.value +
			"&Message=" + document.ContactForm.Message.value;

	AjaxCall("POST", "ajax/ajax_submit_contact_form.php", "SubmitContact=1" + Parameters, "AfterSubmitContactForm", true);
}


function AfterSubmitContactForm(xml, text)
{
	//Do this for Google goal tracking.
	pageTracker._trackPageview("/submit_contact_us_form.html");

	ShowPopup("Success", "Thank you, your comments have been submitted!  We will be in contact with you shortly.");
}
