<!--//

$(document).ready(function() {
	$("#contactForm").validate({
		messages: {
			name: 'Please enter your name', 
			email: { 
				required: 'Required Field', 
				email : 'Invalid email address'
			}, 
			regarding: 'Selection required', 
			enquiry: 'Required field'
		}, 
	
		errorPlacement: function(error, element) {
			error.appendTo( element.parent() );
		},

		success : function(label) {
			label.html("&nbsp;").addClass("validated");
		}, 

		submitHandler: function() {

			// hide the submit btn
			$('#contactSubmitBtn').hide();

			// show the spinner
			$('#contactSubmitSpinner').show();

			// submit the form
			$.ajax({
				type: 'POST', 
				url: 'contact/index.html', 
				dataType: 'json', 
				data: {
					fa: 'ajax_submit', 
					name: $('#name').val(), 
					email: $('#email').val(), 
					phone: $('#phone').val(), 
					regarding: $('#regarding').val(), 
					enquiry: $('#enquiry').val()
				}, 
				success: function(data) {

					// hide the spinner
					$('#contactSubmitSpinner').hide();

					if (data.status == 'OK') {
						$('#contactErrors').hide();
						$('#contactForm').hide();
						$('#contactSuccess').show();
					} else {
						$('#contactErrors').html('An error occured');
						$('#contactErrors').show();
						$('#contactSubmitBtn').show();
					}
				}, 
				error: function(XMLHttpRequest, textStatus, errorThrown) {
					// hide the spinner
					$('#contactSubmitSpinner').hide();
					$('#contactSubmitBtn').show();
					$('#contactErrors').html('An error occured');
					$('#contactErrors').show();
				}
			});
		}
	});
});
