$(document).ready(function() {
$("#cf_email").focus();
$("#analytics_username").focus();

$("#cf_formelement").submit(function() {
	$("#ajaxloader").fadeIn();
	if($("#cf_email").val() == "" || $("#cf_message").val() == "") {
		$("#cf_statusmessage").html("Could not send the message.  Please ensure that the email adress and message fields are completed correctly.");
		$("#cf_statusmessage").addClass("errormessage");
		$("#cf_statusmessage").fadeIn();
		$("#ajaxloader").fadeOut();
		return false;
	} else {
		$("#cf_submit").attr({disabled:"disabled"});
		$("#cf_statusmessage").fadeOut();
		$.post("contact.php", {email:$("#cf_email").val(), name:$("#cf_name").val(), message:$("#cf_message").val()}, function(data, textStatus) {
			if(textStatus == "success" && data == "sent") {
				$("#cf_statusmessage").fadeOut();
				$("#cf_statusmessage").removeClass("errormessage");
				$("#cf_statusmessage").html("Your message has been sent successfully.");
				$("#cf_statusmessage").addClass("successmessage")
				$("#cf_statusmessage").fadeIn();
				$("#cf_formelement").fadeOut();
			} else {
				$("#cf_statusmessage").fadeOut();
				$("#cf_statusmessage").html("There was an error and your message could not be sent.  Please try again or use the email address above.");
				$("#cf_statusmessage").addClass("errormessage");
				$("#cf_statusmessage").fadeIn();
				$("#ajaxloader").fadeOut();
				$("#cf_submit").removeAttr("disabled");
			}
		});
		return false;
	}
});
});