window.addEvent('domready',function() {
	 
	$('result').setStyle('opacity',0);
	$('contactForm').store('sent',false);
	
	var loader = new Element('img',{'src':'/img/formSend.gif',
							 'width':16,
							 'height':16,
							 'styles':{'margin-left':6,'vertical-align':'middle','opacity':0,'display':'none'}});
	loader.inject($('ok'));
	
	new FormCheck('contactForm',{
				   'submitByAjax':'true',
				   'indicateErrors':2,
				   'showErrors':1,
				   'onAjaxRequest':function() {
					   
						if(!$defined($('admin')) && $('contactForm').retrieve('sent') == true) {
							return false;
						}
						
						loader.setStyle('display','inline');
						loader.get('tween',{'property':'opacity'}).start(1);
						
				   },
				   'onAjaxSuccess':function(response) {
						
						loader.setStyle('display','none');
						
						 $('result').innerHTML = response;
						 $('result').get('tween',{'property':'opacity'}).start(1);
						 if(!$defined($('edit'))) {
						 	$('contactForm').reset();
						 }
						 $('contactForm').store('sent',true);
						 var myFx = new Fx.Scroll(window).toElement('result');
				   },
				   'onAjaxFailure':function() {
						
						loader.setStyle('display','none');
						
						new Element('p',{'class':'error','text':'* There was a problem submitting the form, please try again later.'}).inject($('result'));
						$('result').get('tween',{'property':'opacity'}).start(1);
						var myFx = new Fx.Scroll(window).toElement('result');
				   }});
	
});
