// VALIDATION + AJAX FORM
$(document).ready(function(){

	// show a simple loading indicator
	jQuery(function() {
		var loader = jQuery('<div id="loader"><img src="http://stylozero.com/site/wp-content/themes/stylozero/js/facebox/loading.gif" alt="processing&#8230;" /></div>')
			.css({position: "relative", top: "1em", left: "25em"})
			.appendTo("#actionform")
			.hide();
		jQuery().ajaxStart(function() {
			loader.show();
		}).ajaxStop(function() {
			loader.hide();
		}).ajaxError(function(a, b, e) {
			throw e;
		});
	});
	
	// required to make the simple math captcha working
	$.validator.methods.equal = function(value, element, param) {
		return value == param;
	};
	
	$('#actionform').validate({
		
		// simple math captcha
		rules: {
			math: {
				equal: 9
			}
		},
		
		messages: {
			math: "Please enter the correct result"
		},
	
		// error label placement
		errorPlacement: function(error, element) {
        	$(element).closest('.rowElem').after(error); //the method closest get the closest parent with class rowElem
		},
			
		submitHandler: function(form) {
	     
			$(form).ajaxSubmit({
	      	    
	            success: function() {
	                $('#actionform').hide();
	                $('#content').append("<p class='thanks'>Thanks! Your request has been sent.</p>")
	            }
	       });
	     }
         
    });
});

