window.addEvent('domready', function() {
	// You can skip the following two lines of code. We need them to make sure demos
	// are runnable on MooTools demos web page.
	
	var container = $('msg');
	
	var addMsg = function(text) {

		container.empty();
		var span = new Element('span', {'class': 'fade', 'id': 'form_message'});
		span.setHTML(text);
		//container.inject(span);
		span.inject(container);

		Fat.fade_all();
	};

	var event = function() {
	  container.empty();
	  container2.inject(container);
	}


        var fx = {
         'loading': new Fx.Style( 'loading', 'opacity',{ duration: 3000 } ),
         'success': new Fx.Style( 'success', 'opacity',{ duration: 200 } ),
         'fail': new Fx.Style( 'fail', 'opacity',{ duration: 200 } )
        };

        // Hides the loading div, and shows the el div for
        // a period of four seconds.
        var showHide = function( el ){
          fx.loading.set(0);
          (fx[ el ]).start(0,1);
          (function(){ (fx[ el ]).start(1,0); }).delay( 4000 );
        }

	$('question').addEvent('click', function(e) {$('question').value = '';});

	$('contact_submit').addEvent('click', function(e) {
		new Event(e).stop();

	        $('enquiry_form').setProperty('action', 'ajax_checkform.php');
        	$('enquiry_form').send({
                	onRequest: function(){
                            // Show loading div.
			    container.empty();
			    $('loading').style.display = 'block';
			    fx.loading.start(1,0);
        	        },
                	onSuccess: function(text){
			    fx.loading.stop();
			    $('loading').style.display = 'none';
			    addMsg(text);
                	    // Hide loading and show success for 3 seconds.
	                },
        	        onFailure: function(){
                	        // Hide loading and show fail for 3 seconds.
                        	showHide( 'fail' );
	                }
                });
	});
})
;
