Event.observe(window, 'load', init);
function init() {
	if($('enquiry-form')) {
	$('enquiry-form').observe('submit', submitForm);
	$('form-hint').hide();
	}
}
function submitForm (event) {
	event.preventDefault();
	var className = 'input_error';
	var hasError = false;
	$('name', 'phone', 'message').each(function(input) {
		if(input.value.length === 0) {
			input.addClassName(className);
			hasError = true;
			return;
		} else {
			input.removeClassName(className);
		}
	});
	if(hasError) {		
		if(!$('form-hint').visible()) {		
			Effect.Grow('form-hint');
		} else {
			new Effect.Highlight('form-hint', {startcolor: '#484842', endcolor: '#6f6f68'});
		}
		return;
	}		
	new Ajax.Request('form.php',{
		onSuccess: function(transport) {
			$('enquiry-form').remove();
			$('form-hint').remove();
			$('enquiry').insert({bottom: transport.responseText}).blindDown();
		},
		onFailure: function() {
			alert('Sorry, a problem occured, please try again!');
		},
		parameters: { ugar: true, name: $('name').value, phone: $('phone').value, message: $('message').value }					  
	});	
}
