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

	function sendRequest(){
		//Show the spinning indicator.
		var log = $('homeLeftBottomBox3');
		//var log = $('homeLeftBottomBox3').addClass('ajax-loading');
		
		$('requestCallbackForm').set('send', {onComplete: function(response) {
			log.empty();
			//log.removeClass('ajax-loading');
			log.set('html', response);
			addFormEvent();
		}});						
		//Send the form.
		$('requestCallbackForm').send();	
	}
	
	function addFormEvent(){
		$('requestCallbackForm').setProperty('action', sifrLocation+'/request-callback.inc.php');

		if ($('preferred_day')) {
			$('preferred_day').addEvent('change', function(e) {
				e.stop();
				
				$('form_step').value = 1;
				sendRequest();
			});
		}

		if ($('back-link')) {
			$('back-link').addEvent('click', function(e) {
				e.stop();
				
				$('form_step').value = 0;
				sendRequest();
			});
		}		
		
		$('requestCallbackForm').addEvent('submit', function(e) {
			//Prevents the default submit event from loading a new page.
			e.stop();
			$('homeLeftBottomBox3').addClass('no-bg');
			var log = $('homeLeftBottomBox3');
			//var log = $('homeLeftBottomBox3').addClass('ajax-loading');
			
			this.set('send', {onComplete: function(response) { 
				log.setStyle('background-image', 'none');
				log.empty();
				//log.removeClass('ajax-loading');
				log.set('html', response);
				addFormEvent();				
			}});
			//Send the form.
			this.send();
		});
	};
	
	addFormEvent();
});