$(document).ready(function(){
	var baseBorderColor = $(".contentForm .required").css("borderColor");
	var baseTextColor = $(".contentForm .required").css("color");
	$(".contentForm .required").blur(function(){
		if($(this).val().length<1){
			$(this).css("borderColor","red");
			$(this).css("color","red");
			$(this).css("backgroundImage","url(js/ex.png)").css("backgroundRepeat","no-repeat").css("backgroundPosition","right");
			
			$(this).val("Gelieve dit veld in te vullen.");
			$(this).effect("shake", {distance:2 , times:2 }, 100);
			$(this).focus(function(){
				$(this).val("");
				$(this).css("borderColor", baseBorderColor);
				$(this).css("color", baseTextColor);
				$(this).unbind('focus');
				$(this).css("backgroundImage","none");
			});
		} else {
			$(this).css("borderColor", baseBorderColor);
			$(this).css("color", baseTextColor);
		}
	});
	
	$(".contentForm .submit").click(function(){
		var focussed = false;
		var count = 0;
		$(".contentForm .required").each(function(){
			if ($(this).val().length < 1 || $(this).val() == "Gelieve dit veld in te vullen.") {
				count++;
				if (!focussed) {
					$(this).focus();
					focussed=true;
					$(this).val("");
					$(this).css("borderColor", baseBorderColor);
					$(this).css("color", baseTextColor);
					$(this).unbind('focus');
					$(this).css("backgroundImage","none");
				} else {
					$(this).css("borderColor","red");
					$(this).css("color","red");
					$(this).css("backgroundImage","url(js/ex.png)").css("backgroundRepeat","no-repeat").css("backgroundPosition","right");
					$(this).val("Gelieve dit veld in te vullen.");
					$(this).effect("shake", {distance:2 , times:2 }, 100);
					$(this).focus(function(){
						$(this).val("");
						$(this).css("borderColor", baseBorderColor);
						$(this).css("color", baseTextColor);
						$(this).unbind('focus');
						$(this).css("backgroundImage","none");
					});
					
				}
			}
		});
		if(count == 0){
			$.ajax({url: 'modules/sendform.cfm',
				type: "POST",
				data: ({fNaam : $(".fNaam").val(),fAdres : $(".fAdres").val(),fPostcode : $(".fPostcode").val(),fWoonplaats : $(".fWoonplaats").val(),fTelefoon : $(".fTelefoon").val(),fEmail : $(".fEmail").val(),fVraag : $(".fVraag").val(),fSendto : $(".fSendto").val()}),
				success: function(data) {
    				if(data == "ok"){
						alert('Bericht Verzonden');
					} else {
						alert('Verkeerde email opgegeven')
					}
    				
  				}
			});
			
		}
		return false;
	});
});



