/**
 * @author alex
 */
$(document).ready(function()
{
	
	$("form#enquiry_form").validate({
										'ajax': true,//'captcha_check_mini',
										'url' : 'feedback.php',
										'ajax_callback' : 'result',
										'fieldErrorsCap' : false,
										'errorCallback' : 'got_error',
										'singleErrors' : false,
										'highlightReset' : { 'border': '0px solid #ABABAB' }
									});
});

function captcha_check_mini(param)
{
	var code = $('input#captcha_code').val();
	$.post('ajax.php', {code: code}, function(success)
	{
		//run custom callback function
		if(success == 1)
		{
			$.post('feedback.php', param, function(data)
			{
				//run custom callback function
				result(data);
			});
			$('#captcha2').attr({'src': 'captcha/securimage_show_2.php?sid=' + Math.random()});
			return false;
		}
		else
		{
			$('#captcha2').attr({'src': 'captcha/securimage_show_2.php?sid=' + Math.random()});
			$('input#captcha_code').css({'border':'1px solid red'});
			alert('Please make sure you have entered the right code and that you have not been trying to submit this form for too long.');
			return false;	
		}
	});
}


function result(data)
{
	if(data != "unsuccessful")
	{
		$('#thank_you').show();
	}
	else
	{
		$('#thank_you').hide();
		alert("Unfortunately there was an issue with the form and we did not receive your enquiry, please try again.");
	}
}

function got_error()
{
	alert("Please supply us with your name, a valid number, a valid email address and your enquiry.");
}
