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

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

	AjaxCall("POST", "ajax/ajax_submit_free_quote.php", "SubmitFreeQuote=1" + Parameters, "AfterSubmitFreeQuoteForm", true);
}


function AfterSubmitFreeQuoteForm(xml, text)
{
	if (text == "")
	{
		//Do this for Google goal tracking.
		pageTracker._trackPageview("/submit_free_quote_form.html");
		
		ShowPopup("Success", "Thank you, your quote request has been submitted!  We will be in contact with you shortly.");
	}
	else
		ShowPopup("ERROR", text);
}


function AdjustNavWidthForMac()
{
	switch (BrowserDetect.OS)
	{
		case 'Mac':
		case 'iPhone/iPod':
			document.getElementById('NavWrapper').style.width = "422px";
			break;
		default:
			break;
	}
}
