// JavaScript Document









//	VALIDATE ESTIMATE FORM
function validate_estimate_form()
{
	//	Verify the required fields have data
	if( $('First').value == "" || $('Last').value == ""  || $('Email').value == "" || $('Phone').value == "" || $('Agree').clicked == false ) {
		alert('You must complete all fields that have a * next to them and click Agree to complete this form.\n\nPlease try again!');
		return false;
	}
	
	//	Hide the quote section and show progress
	hide_element('contact-form');
	show_element('formprogress');
	
	new Ajax.Request('ajax/residential.php', {	
  		method: 'post',
		onSuccess: function(e) 
					{ 
						var response = e.responseText.split('^');
						var success = response[0];	// "true" or "false"
						var message = response[1];
						
						success = success.replace(/\s/gi, '');
						
						if( success === "false")
						{
							alert("Error sending your message! The following error was given:\n\n"+message);
							
							//	Hide the progress indicator
							hide_element('formprogress');
							//	Re-show the form
							show_element('contact-form');
						}
						else
						{
							//
							alert(message);								
							//	Success
							$('formprogress').innerHTML = "<h2>Your message has been sent!</h2>".message;
							
							setTimeout("window.location='residential.php'", 2000);				
				
						}
					},
		onFailure: function(e) { 
						alert('Unable to submit request. Please try again.');
						
						//	Hide the progress and show the form again
						hide_element('formprogress');
						show_element('contact-form');
					},
  		parameters: 
			{
				option: 'request',
				type: 'submitform',
				first: $('First').value,
				last: $('Last').value,
				email: $('Email').value,
				phone: $('Phone').value,
				address: $('Address').value,
				city: $('City').value,
				state: $('State').value,
				zip: $('Zip').value,
				message: $('Message').value
			} 
	});
}