formularcheck();

function formularcheck(){
 $(document).ready(function() {
	$("button[name=send]").click(function () 
		{
			
			var name = $('input[name=kontaktname]').val();
			var email = $('input[name=kontaktemail]').val();
			var nachricht = $('textarea[name=kontaktnachricht]').val();			
			var sendData = 'kontaktname='+name+'&kontaktemail='+email+'&kontaktnachricht='+nachricht;

			// Validation
			if (name == "Name")
			{ 
				$('input[name=kontaktname]').css('border','2px red solid');
				$('.checker1').css('display','block');
				$('input[name=kontaktname]').keypress(function(){
					if ($('input[name=kontaktname]').val() != "Max Mustermann")	{
						$('input[name=kontaktname]').css('border','2px solid #4e5050');
						$('.checker1').css('display','none');
					}
				});
				
			}

			if (email == "E-Mail")
			{ 
				$('input[name=kontaktemail]').css('border','2px red solid');
				$('.checker2').css('display','block');
				$('input[name=kontaktemail]').keypress(function(){
					if ($('input[name=kontaktemail]').val() != "max@mustermann.de")	{
						$('input[name=kontaktemail]').css('border','2px solid #4e5050');
						$('.checker2').css('display','none');
					}
				});
			}			

			if (nachricht == "")
			{ 
				$('textarea[name=kontaktnachricht]').css('border','2px red solid');
				$('.checker3').css('display','block');
				$('textarea[name=kontaktnachricht]').keypress(function(){
					if ($('textarea[name=kontaktnachricht]').val() != "")	{
						$('textarea[name=kontaktnachricht]').css('border','2px solid #4e5050');
						$('.checker3').css('display','none');
					}
				});
			}
			
			if ((nachricht == "") || (email == "E-Mail") || (name == "Name")) {
				return false;
			}
			// End Validation
			
			$(".loadinfo").toggle();

			// Send to PHP
			function sendToPhp (maildata){
				$.ajax({
					url: "assets/code/formularsend.php",	
					type: "POST",
					data: maildata,		
					success: function (reqCode) {

						if (reqCode.match("erfolgreich"))	{
							function donebuttongood(){$(".done").fadeIn(1000);$(".loadinfo").toggle();}
							$("button[name=send]").fadeOut(200,donebuttongood);
							$("form > input, form > textarea").attr("disabled", true);
							$("form > input, form > textarea").css("background-color", "#eee");
						}
						else {
							function donebuttonbad(){$(".failed").fadeIn(1000);$(".loadinfo").toggle();
								$("button[name=send]").html("Nochmal")
								$("button[name=send]").fadeIn(200);
							}
							$("button[name=send]").fadeOut(200,donebuttonbad);
						}
					}	
				});
			} // End Send to PHP

			sendToPhp(sendData);
			return false;
	});
});

};
