// prepare the form when the DOM is ready
$(document).ready(function() {
	
	$("#refreshimg").click(function(){
		$.post('./plugins/limeForm/captcha/newsession.php');
		$("#refreshimg").load('./plugins/limeForm/captcha/image_req.php');
		return false;
	});
	
	var v = $("#limeForm").validate({
		submitHandler: function(form) {
			$(form).ajaxSubmit({
				target:       '#msg',
				success:       showResponse,
				beforeSubmit:  showRequest
			});
		},
		rules: {
			captcha: {
				required: true,
				remote: "./plugins/limeForm/captcha/process.php"
			}
		},
		messages: {
			captcha: "El texto introducido no es correcto. Haga click en la imagen para generar uno nuevo"	
		}
		});
	
});

function showRequest(formData, jqForm, options) {
   	$('#sending').show("slow");
}
function showResponse(responseText, statusText)  {
    // 'data' is the json object returned from the server
	$('#sending').hide("slow",showMsg);
	//$('#msg').show();
	//$("#limeForm").resetForm();
}

function showMsg () {
	$('#msg').show();
	$("#limeForm").resetForm();
}
