$(document).ready(function(){
	$('input[name=submitFooterContact]').click(function(e){
		e.preventDefault();
		
		$.ajax({
			type: "POST",
			url: getBaseURL()+'contact/submit',
			data: $('#footerContactForm').serialize(),
			success: function(msg){
				if(msg=='success')
				{
					clearFooterMessages();
					$('#contactFooterTable').before(showSuccess('Message was successfully submitted'));
					clearForm('#contactFooterTable');
				}
				else
				{
					clearFooterMessages();
					$('#contactFooterTable').before(showError(msg));
				}
			},
			error: function(xhr, textStatus, errorThrown) {
			    msg = 'could not succesfully submit the form because '+xhr.status+' '+xhr.statusText;
				alert(msg);
			}
		});
		
	});
	
	$('#submitContact').click(function(e){
		e.preventDefault();
		
		$.ajax({
			type: "POST",
			url: getBaseURL()+'contact/submit',
			data: $('#contactForm').serialize(),
			success: function(msg){
				if(msg=='success')
				{
					clearFooterMessages();
					$('#contactTable').before(showSuccess('Message was successfully submitted'));
					clearForm('#contactTable');
				}
				else
				{
					clearFooterMessages();
					$('#contactTable').before(showError(msg));
				}
			},
			error: function(xhr, textStatus, errorThrown) {
			    msg = 'could not succesfully submit the form because '+xhr.status+' '+xhr.statusText;
				alert(msg);
			}
		});
		
	});
});

function clearForm(formName)
{
	$(':input',formName)
		.not(':button, :submit, :reset, :hidden')
		.val('')
		.removeAttr('checked')
		.removeAttr('selected');
}

function showSuccess(msg)
{
	return '<div id="footerContactSuccess" style="color: #6BBA70;font-weight: bold;">'+msg+'</div>';
}

function showError(msg)
{
	return '<div id="footerContactError" style="color: #D01F3C;font-weight: bold;">'+msg+'</div>';
}

function clearFooterMessages()
{
	$('#footerContactSuccess').remove();
	$('#footerContactError').remove();
}
