/*
	
*/


function ChooseService(ServiceType)
{
	//1. Validate choice
	//2. Set value
	//3. Show new window content
	
	// 1.
	switch(ServiceType)
	{
		case 'Self Service':
		case 'Full Service':
			//continue
			break;
		default:
			ShowPopup("ERROR", "Unknown service type '" + ServiceType + "'.  Choose either 'Full Service' or 'Self Service'.");
			return;
			break;
	}
	
	// 2.
	SetCookie("ServiceType", ServiceType);
	
	// 3.
	$('#ServiceButtonsWrapper').slideUp("fast", function ()
						    {
						    	if (ServiceType == "Self Service")
						    		$('#SelfServiceContent').slideDown("fast");
						    	else
						    		$('#FullServiceContent').slideDown("fast");
						    });
}


function TryToSubmitPriceForm(ServiceType)
{
	//1. Validate choice
	//2. Ensure mandatory fields are set
	//3. Send e-mail (AJAX)

	// 1.
	switch(ServiceType)
	{
		case 'Full Service':
		case 'Self Service':
			//continue
			break;
		default:
			ShowPopup("ERROR", "Unknown service type '" + ServiceType + "'.  Choose either 'Full Service' or 'Self Service'.");
			return;
			break;
	}
	
	//2.
	if (ServiceType == "Self Service")
	{
		if (document.PricingForm.SelfService_TypeOfMaterial.value == "")
		{
			FocusOnField(document.PricingForm.SelfService_TypeOfMaterial);
			ShowPopup("ERROR", "Please choose a type of material.");
			return false; 
		}
		else if (document.PricingForm.SelfService_SizeOfBin.value == "")
		{
			FocusOnField(document.PricingForm.SelfService_SizeOfBin);
			ShowPopup("ERROR", "Please choose a bin size.");
			return false; 
		}
		else if (document.PricingForm.SelfService_StartDate.value == "")
		{
			FocusOnField(document.PricingForm.SelfService_StartDate);
			ShowPopup("ERROR", "Please enter a start date for your project.");
			return false; 
		}
		else if (!IsNumeric(document.PricingForm.SelfService_Duration.value))
		{
			FocusOnField(document.PricingForm.SelfService_Duration);
			ShowPopup("ERROR", "Please enter the duration of your project (numbers only).");
			return false; 
		}
		else if (document.PricingForm.SelfService_Name.value == "")
		{
			FocusOnField(document.PricingForm.SelfService_Name);
			ShowPopup("ERROR", "Please enter your name.");
			return false; 
		}
		else if (!IsValidPhoneNumber(document.PricingForm.SelfService_Phone.value))
		{
			FocusOnField(document.PricingForm.SelfService_Phone);
			ShowPopup("ERROR", "Please enter a valid phone number (in the format 123-456-7890).");
			return false; 
		}
		else if (!IsValidEmail(document.PricingForm.SelfService_Email.value))
		{
			FocusOnField(document.PricingForm.SelfService_Email);
			ShowPopup("ERROR", "Please enter a valid email.");
			return false; 
		}
		else if (document.PricingForm.SelfService_Address1.value == "")
		{
			FocusOnField(document.PricingForm.SelfService_Address1);
			ShowPopup("ERROR", "Please enter your address.");
			return false; 
		}
		else if (document.PricingForm.SelfService_City.value == "")
		{
			FocusOnField(document.PricingForm.SelfService_City);
			ShowPopup("ERROR", "Please choose a city.");
			return false; 
		}
		else if (!IsValidPostalCode(document.PricingForm.SelfService_PostalCode.value))
		{
			FocusOnField(document.PricingForm.SelfService_PostalCode);
			ShowPopup("ERROR", "Please enter a valid postal code (in the format A1A1A1).");
			return false; 
		}
		else
		{
			Parameters =	"&ServiceType=" + ServiceType +
					"&TypeOfMaterial=" + document.PricingForm.SelfService_TypeOfMaterial.value +
					"&SizeOfBin=" + document.PricingForm.SelfService_SizeOfBin.value +
					"&StartDate=" + document.PricingForm.SelfService_StartDate.value +
					"&Duration=" + document.PricingForm.SelfService_Duration.value +
					"&Name=" + document.PricingForm.SelfService_Name.value +
					"&Phone=" + document.PricingForm.SelfService_Phone.value +
					"&Email=" + document.PricingForm.SelfService_Email.value +
					"&Address1=" + document.PricingForm.SelfService_Address1.value +
					"&Address2=" + document.PricingForm.SelfService_Address2.value +
					"&City=" + document.PricingForm.SelfService_City.value +
					"&PostalCode=" + document.PricingForm.SelfService_PostalCode.value;

			AjaxCall("POST", "ajax/ajax_submit_price_form.php", "SubmitPrice=1" + Parameters, "AfterSubmitPriceForm", true);
			return false;
		}
	}
	else
	{
		if (document.PricingForm.FullService_TypeOfMaterial.value == "")
		{
			FocusOnField(document.PricingForm.FullService_TypeOfMaterial);
			ShowPopup("ERROR", "Please choose a type of material.");
			return false; 
		}
		else if (document.PricingForm.FullService_Name.value == "")
		{
			FocusOnField(document.PricingForm.FullService_Name);
			ShowPopup("ERROR", "Please enter your name.");
			return false; 
		}
		else if (!IsValidPhoneNumber(document.PricingForm.FullService_Phone.value))
		{
			FocusOnField(document.PricingForm.FullService_Phone);
			ShowPopup("ERROR", "Please enter a valid phone number (in the format 123-456-7890).");
			return false; 
		}
		else if (!IsValidEmail(document.PricingForm.FullService_Email.value))
		{
			FocusOnField(document.PricingForm.FullService_Email);
			ShowPopup("ERROR", "Please enter a valid email.");
			return false; 
		}
		else if (document.PricingForm.FullService_Address1.value == "")
		{
			FocusOnField(document.PricingForm.FullService_Address1);
			ShowPopup("ERROR", "Please enter your address.");
			return false; 
		}
		else if (document.PricingForm.FullService_City.value == "")
		{
			FocusOnField(document.PricingForm.FullService_City);
			ShowPopup("ERROR", "Please choose a city.");
			return false; 
		}
		else if (!IsValidPostalCode(document.PricingForm.FullService_PostalCode.value))
		{
			FocusOnField(document.PricingForm.FullService_PostalCode);
			ShowPopup("ERROR", "Please enter a valid postal code (in the format A1A1A1).");
			return false; 
		}
		else
		{
			Parameters =	"&ServiceType=" + ServiceType +
					"&TypeOfMaterial=" + document.PricingForm.FullService_TypeOfMaterial.value +
					"&Name=" + document.PricingForm.FullService_Name.value +
					"&Phone=" + document.PricingForm.FullService_Phone.value +
					"&Email=" + document.PricingForm.FullService_Email.value +
					"&Address1=" + document.PricingForm.FullService_Address1.value +
					"&Address2=" + document.PricingForm.FullService_Address2.value +
					"&City=" + document.PricingForm.FullService_City.value +
					"&PostalCode=" + document.PricingForm.FullService_PostalCode.value;

			AjaxCall("POST", "ajax/ajax_submit_price_form.php", "SubmitPrice=1" + Parameters, "AfterSubmitPriceForm", true);
			return false;
		}
	}
}


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


	if (GetCookie("ServiceType") == "Self Service")
	{
		$('#SelfServiceContent').slideUp("fast", function ()
						    {
							$('#ResultContent').slideDown("fast");
						    });
	}
	else
	{
		$('#FullServiceContent').slideUp("fast", function ()
						    {
							$('#ResultContent').slideDown("fast");
						    });
	}


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

