function ajaxForm() {

	$( 'contact_form' ).addEvent( 'submit', function( e ) {

		var x = $( 'contact_form' );

		if( x.first_name.value == '' ){

			alert( 'Please enter your first name.' );

			x.first_name.focus();

			new Event( e ).stop();
			
		} else if( x.last_name.value == '' ){

			alert( 'Please enter your last name.' );

			x.last_name.focus();

			new Event( e ).stop();

		} else if ( !( /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test( x.email.value ) ) ) {

			alert( 'Please enter a valid email address.' );

			x.email.focus();

			new Event( e ).stop();

		} else if( x.phone.value == '' ){

			alert( 'Please enter your phone number.' );

			x.phone.focus();

			new Event( e ).stop();

		} else {

			// Prevent the submit event
			new Event( e ).stop();

			// This empties the log and shows the spinning indicator/
			var log = $( 'response' ).empty().addClass( 'ajax_loading' );

			/*
			send takes care of encoding and returns the Ajax instance.
			onComplete removes the spinner from the log.
			*/

			this.send( {

				update: log,

				onComplete: function() {

					log.removeClass('ajax_loading');

					$( 'contact_form' ).setStyle( 'display', 'none' );
					$( 'response' ).setStyle( 'display', 'block' );
	
				}				

			});

		}

	});

}



window.addEvent('domready', function(){
									 

	ajaxForm()

});
