$(function() {
	$(".btnSend").click(function() {
		$.post("validateEmail.php", { email: $("#eMail").val() },
			function(data) {
				if (data.succes) {
					$("#eMail").css({borderColor: "#6F6F6F", backgroundColor: "#FFFFFF"});
					validateForm(true);
				} else {
					$("#eMail").css({borderColor: "#AF0000", backgroundColor: "#FAFAD0"});
					validateForm(false);
				}
			}, "json");
	});
});

function validateForm(status) {
	$(".validateField").each(function(i) {
		if ($(this).attr("name") != "emailadres") {
			if ($(this).attr('type') == "checkbox" && !$(this).attr('checked')) {
				$('#'+$(this).attr('name')).css({color: "#AF0000"});
				status = false;
			}
			else if ($(this).attr('type') == "checkbox") {
				$(this).css({borderColor: "#6F6F6F", backgroundColor: "#FFFFFF"});
			}

			if ($(this).attr('type') != "checkbox" && $.trim($(this).val()) == "" && $(this).css("display") != "none") {
				status = false;
				$(this).css({borderColor: "#AF0000", backgroundColor: "#FAFAD0"});
			} else if ($(this).attr('type') != "checkbox") {
				$(this).css({borderColor: "#6F6F6F", backgroundColor: "#FFFFFF"});
			}
		}
	});
	if (!status) {
		$(".errorMessage").show();
	} else {
		$(".errorMessage").hide();
		$("form").submit();
	}
}
