﻿$(document).ready(function () {
	$("#guestbookform")
		.append($("<input type='hidden' name='form-type' value='guestbook-item' />"))
		.submit(function(){
			var result = true;

			if ($("#gb-name").val() == "") {
				$("#gb-name").css("background-color", "rgb(217, 149, 148)");
				result = false;
			}
			if ($("#gb-email").val() == "") {
				$("#gb-email").css("background-color", "rgb(217, 149, 148)");
				result = false;
			}
			if ($("#gb-message").val() == "") {
				$("#gb-message").css("background-color", "rgb(217, 149, 148)");
				result = false;
			}
			
			return result;
		});
	
	$("#newsfeedback")
		.append($("<input type='hidden' name='form-type' value='news-item' />"))
		.submit(function(){
			var result = true;

			if ($("#news-name").val() == "") {
				$("#news-name").css("background-color", "rgb(217, 149, 148)");
				result = false;
			}
			if ($("#news-email").val() == "") {
				$("#news-email").css("background-color", "rgb(217, 149, 148)");
				result = false;
			}
			if ($("#news-message").val() == "") {
				$("#news-message").css("background-color", "rgb(217, 149, 148)");
				result = false;
			}
			
			return result;
		});
		
		
		if ( $(".datefield").length > 0 )
		{
			$.datepicker.setDefaults($.datepicker.regional['nl']);
			$(".datefield").datepicker();
		}
					
		$(".customform")
			.append($("<input type='hidden' name='form-type' value='custom-form' />"))
			.submit(function(){
				var result = true;
				
				$(".customform .required").each(function(i){
					if ($(this).val() == "") {
						$(this).css("background-color", "rgb(217, 149, 148)");
						result = false;
					}
					else
						$(this).css("background-color", "#fff");					
				});
				
				$(".customform .emailfield").each(function(i){
					var myRegxp = new RegExp("^[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}$");
					
					if ( !myRegxp.test($(this).val()) ) {
						$(this).css("background-color", "rgb(217, 149, 148)");
						result = false;
					}
					else
						$(this).css("background-color", "#fff");					
				});
	
				return result;			
			});
});

function checkCode() {
	if ($("#code").val() == "2275"){
		$(".customform").show();
		$(".form-description").show();
		$(".codeform").hide();
	}
	else {	
		alert("De code is niet juist.");
	}
}
