$(document).ready(function() {
	var loader = $('<p id="loader"><img src="images/ajax-loader.gif" alt="loading..." />Sending form ..... </p>').hide();
	$().ajaxStart(function() {
		$("#result").show().html(loader);
		loader.show();
	}).ajaxStop(function() {
		loader.hide();
		refreshVerImg('imgCaptcha');
	});

	$().ajaxError(function(a, b, e) {
		throw e;
	});
	
	var v = $("#contactForm").validate({
		errorPlacement: function(error, element) {
			error.appendTo( element.parent("td").next("td") );
		},
		submitHandler: function(form) {
			$(form).ajaxSubmit({
				target: "#result",
				after: function(result) {
					$("#result").show();
					if(result.status) {
						v.showErrors(result.text);
						v.focusInvalid();
					}
				}
			});
		}
	});
	
	$("#trimite").click(function(){
		$("#contactForm").submit();
	});
	
});
