$(function() {
	load_recaptcha();
});

function load_recaptcha() {
	Recaptcha.create(RECAPTCHA_PUBLIC_KEY, "Captcha", 
		{
			theme: "red",
			callback: Recaptcha.focus_response_field
		});
}

function checkMessageForm()
{
	fdata = $('#ContactAddForm').formToArray();
	data = associate(fdata);
	if(!data['data[Contact][name]'])
	{
		alert("Please enter your name");
		return;
	}

	if(!checkEmail(data['data[Contact][email]']))
	{
		alert("Please enter your valid email address so we can respond");
		return;
	}

	if(!data['data[Contact][subject]'])
	{
		alert("Please enter a subject");
		return;
	}
	
	if(!data['data[Contact][message]'])
	{
		alert("Please enter a message");
		return;
	}
	
	//Confirm that the information is correct
	if(confirm("Is all of the information correct?"))
	{
		//Set the loading message
		$("#status").html("<h3>Sending email...</h3>");
		
		//Sumit the request via AJAX
		$.post(PATH_BASE+'/contact/email', 
			fdata, function(data)
			{
				$("#status").html(data.message);
				if(data.status == 1) {
					setTimeout(function(){window.location = PATH_BASE;}, 1000);
				} else {
					load_recaptcha();
				}
			}, "json");
	}	
}

function clearMessageForm()
{
	$('#ContactAddForm').clearForm();
}