//Email Footer
function checkMail(String){
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(String);
}
function checkName(Name){
	if(Name.length > 3){
		return true;
	}
	return false;
}
$('#fContactForm input[name=fName]').keyup(function(){
	var name = $(this).val();
	if( checkName(name) == false ){
		$(this).removeClass('fValid');
		$(this).addClass('fNotValid');
	}else{
		$(this).removeClass('fNotValid');
		$(this).addClass('fValid');
	}
});
$('#fContactForm input[name=fEmail]').keyup(function(){
	var email = $(this).val();
	if( checkMail(email) == false ){
		$(this).removeClass('fValid');
		$(this).addClass('fNotValid');
	}else{
		$(this).removeClass('fNotValid');
		$(this).addClass('fValid');
	}
});
$(document).click(function(){
	var name = $('#fContactForm input[name=fName]').val();
	var email = $('#fContactForm input[name=fEmail]').val();
	if ( name.length == 0 ) $('#fContactForm input[name=fName]').removeClass('fNotValid');
	if ( email.length == 0 ) $('#fContactForm input[name=fEmail]').removeClass('fNotValid');
});
$(document).click(function(){
	var name = $('#contactPage fieldset input[name="name"]').val();
	var email = $('#contactPage fieldset input[name="email"]').val();
	var subject = $('#contactPage fieldset input[name="subject"]').val();
	if ( name.length == 0 ) $('#contactPage fieldset input[name="name"]').removeClass('fNotValid');
	if ( email.length == 0 ) $('#contactPage fieldset input[name="email"]').removeClass('fNotValid');
	if ( subject.length == 0 ) $('#contactPage fieldset input[name="subject"]').removeClass('fNotValid');
});
$('#fContactForm input[type=button]').click(function(){
	$('#fCAjax').ajaxStart(function(){
		$(this).html('<strong>Verzenden...<strong>');
	});
	var name = $('#fContact fieldset form input[name=fName]').val();
	var email = $('#fContact fieldset form input[name=fEmail]').val();
	var message = $('#fContact fieldset form textarea').val();
	if( checkName(name) == false ){
		$('#fContactForm input[name=fName]').removeClass('fValid');
		$('#fContactForm input[name=fName]').addClass('fNotValid');
		return false
	}else{
		$('#fContactForm input[name=fName]').removeClass('fNotValid');
		$('#fContactForm input[name=fName]').addClass('fValid');
	}
	if( checkMail(email) == false ){
		$('#fContactForm input[name=fEmail]').removeClass('fValid');
		$('#fContactForm input[name=fEmail]').addClass('fNotValid');
		return false;
	}else{
		$('#fContactForm input[name=fEmail]').removeClass('fNotValid');
		$('#fContactForm input[name=fEmail]').addClass('fValid');
	}
	if( message.length < 5 ){
		return false;
	}
	$.ajax({
		type: 'post',
		data: {"fAName":name,"fAEmail":email,"fAMessage":message},
		success: function(){
			$('#fCAjax').html('<h5>Verzonden!</h5><p>Bericht werd succesvol verzonden, we zullen u iets zo snel mogenlijk laten weten.</p>');
			$('#fContactForm').slideUp('fast');
		},
		error: function(){
			$('#fCAjax').html('<h5>Foutje :(</h5><p>Er is een fout opgetreden tijdens het verzenden van dit bericht.</p>');
		}
	});
});
//End Email Footer
//Contact
$('#contactPage fieldset input[name="name"]').keyup(function(){
	var name = $(this).val();
	if( checkName(name) == false ){
		$(this).removeClass('fValid');
		$(this).addClass('fNotValid');
	}else{
		$(this).removeClass('fNotValid');
		$(this).addClass('fValid');
	}
});
$('#contactPage fieldset input[name="email"]').keyup(function(){
	var email = $(this).val();
	if( checkMail(email) == false ){
		$(this).removeClass('fValid');
		$(this).addClass('fNotValid');
	}else{
		$(this).removeClass('fNotValid');
		$(this).addClass('fValid');
	}
});
$('#contactPage fieldset input[name="subject"]').keyup(function(){
	var subject = $(this).val();
	if( checkName(subject) == false ){
		$(this).removeClass('fValid');
		$(this).addClass('fNotValid');
	}else{
		$(this).removeClass('fNotValid');
		$(this).addClass('fValid');
	}
});
$('#contactPage fieldset input[type=button]').click(function(){
	$('#cContactInfo').ajaxStart(function(){
		$(this).html('<strong>Verzenden...<strong>');
	});
	var name = $('#contactPage fieldset input[name="name"]').val();
	var email = $('#contactPage fieldset input[name="email"]').val();
	var subject = $('#contactPage fieldset input[name="subject"]').val();
	var message = $('#contactPage fieldset textarea').val();
	if( checkName(name) == false ){
		$('#contactPage fieldset input[name="name"]').removeClass('fValid');
		$('#contactPage fieldset input[name="name"]').addClass('fNotValid');
		return false;
	}else{
		$('#contactPage fieldset input[name="name"]').removeClass('fNotValid');
		$('#contactPage fieldset input[name="name"]').addClass('fValid');
	}
	if( checkMail(email) == false ){
		$('#contactPage fieldset input[name="email"]').removeClass('fValid');
		$('#contactPage fieldset input[name="email"]').addClass('fNotValid');
		return false;
	}else{
		$('#contactPage fieldset input[name="email"]').removeClass('fNotValid');
		$('#contactPage fieldset input[name="email"]').addClass('fValid');
	}
	if( checkName(subject) == false ){
		$('#contactPage fieldset input[name="subject"]').removeClass('fValid');
		$('#contactPage fieldset input[name="subject"]').addClass('fNotValid');
		return false;
	}else{
		$('#contactPage fieldset input[name="subject"]').removeClass('fNotValid');
		$('#contactPage fieldset input[name="subject"]').addClass('fValid');
	}
	if( message.length < 5 ){
		return false;
	}
	$.ajax({
		type: 'post',
		data: {"cName":name,"cEmail":email,"cSubject":subject,"cMessage":message},
		success: function(){
			$('#cContactInfo').html('<h5>Verzonden!</h5><p>Bericht werd succesvol verzonden, we zullen u iets zo snel mogenlijk laten weten.</p>');
			$('#contactPage fieldset').slideUp('fast');
		},
		error: function(){
			alert('mislukt');
		}
	});
});
//End Contact
