Cufon.replace("h1, h2, h3, h4");
// scrollTO
(function($){var m=$.scrollTo=function(b,h,f){$(window).scrollTo(b,h,f)};m.defaults={axis:'xy',duration:parseFloat($.fn.jquery)>=1.3?0:1};m.window=function(b){return $(window).scrollable()};$.fn.scrollable=function(){return this.map(function(){var b=this,h=!b.nodeName||$.inArray(b.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!h)return b;var f=(b.contentWindow||b).document||b.ownerDocument||b;return $.browser.safari||f.compatMode=='BackCompat'?f.body:f.documentElement})};$.fn.scrollTo=function(l,j,a){if(typeof j=='object'){a=j;j=0}if(typeof a=='function')a={onAfter:a};if(l=='max')l=9e9;a=$.extend({},m.defaults,a);j=j||a.speed||a.duration;a.queue=a.queue&&a.axis.length>1;if(a.queue)j/=2;a.offset=n(a.offset);a.over=n(a.over);return this.scrollable().each(function(){var k=this,o=$(k),d=l,p,g={},q=o.is('html,body');switch(typeof d){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px)?$/.test(d)){d=n(d);break}d=$(d,this);case'object':if(d.is||d.style)p=(d=$(d)).offset()}$.each(a.axis.split(''),function(b,h){var f=h=='x'?'Left':'Top',i=f.toLowerCase(),c='scroll'+f,r=k[c],s=h=='x'?'Width':'Height';if(p){g[c]=p[i]+(q?0:r-o.offset()[i]);if(a.margin){g[c]-=parseInt(d.css('margin'+f))||0;g[c]-=parseInt(d.css('border'+f+'Width'))||0}g[c]+=a.offset[i]||0;if(a.over[i])g[c]+=d[s.toLowerCase()]()*a.over[i]}else g[c]=d[i];if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],u(s));if(!b&&a.queue){if(r!=g[c])t(a.onAfterFirst);delete g[c]}});t(a.onAfter);function t(b){o.animate(g,j,a.easing,b&&function(){b.call(this,l,a)})};function u(b){var h='scroll'+b;if(!q)return k[h];var f='client'+b,i=k.ownerDocument.documentElement,c=k.ownerDocument.body;return Math.max(i[h],c[h])-Math.min(i[f],c[f])}}).end()};function n(b){return typeof b=='object'?b:{top:b,left:b}}})(jQuery);

$(document).ready(function(){

	
	function check_persons()
	{
		var naamok = true;
		$("#personen li").each(function()
		{
			var gb = parseInt($(".yrin",this).val() + $(".mnin",this).val() + $(".dgin",this).val());
			if ($("input:first", this).val().length < 4)
			{
				naamok = false;
				$("input:first", this).css({'background-color':'#ffc0c0'});
			}
			else
			{
				$("input:first", this).css({'background-color':'transparent'});
			}
/*			
			if (!parseInt($(".dgin", this).val()))
			{
				naamok = false;
				$(".dgin", this).css({'background-color':'#ffc0c0'});
			}
			else
			{
				$(".dgin", this).css({'background-color':'transparent'});
			}
			
			if (!parseInt($(".mnin", this).val()))
			{
				naamok = false;
				$(".mnin", this).css({'background-color':'#ffc0c0'});
			}
			else
			{
				$(".mnin", this).css({'background-color':'transparent'});
			}
			
			if (!parseInt($(".yrin", this).val())) 
			{
				naamok = false;
				$(".yrin", this).css({'background-color':'#ffc0c0'});
			}
			else
			{
				$(".yrin", this).css({'background-color':'transparent'});
			}
*/		

			if (gb < 18000000)
			{
				$(".dgin", this).css({'background-color':'#ffc0c0'});
				$(".mnin", this).css({'background-color':'#ffc0c0'});
				$(".yrin", this).css({'background-color':'#ffc0c0'});
			}
			else
			{
				
				$(".dgin", this).css({'background-color':'transparent'});
				$(".yrin", this).css({'background-color':'transparent'});
				$(".mnin", this).css({'background-color':'transparent'});
				
				
			}
	
			if (!$("input:radio:checked", this).val())
			{
				naamok = false;
				$(".gender", this).css({'background-color':'#ffc0c0'});
			}
			else
			{
				$(".gender", this).css({'background-color':'transparent'});
			}
			
			
			
			if ((gb && gb <= 20090716) || !gb)
			{
				
			
			
				if ($(".voucher", this).val().length < 5)
				{
					naamok = false;
					$(".voucher", this).css({'background-color':'#ffc0c0'});
				}
				else			
				{
					$(".voucher", this).css({'background-color':'transparent'});
					if ($(".controle", this).val().length < 4)
					{
						naamok = false;
						$(".controle", this).css({'background-color':'#ffc0c0'});
					}					
					else
					{
						$(".controle", this).css({'background-color':'transparent'});
					}				
				}	
			}
			else
			{
				$(".voucher", this).css({'background-color':'transparent'});
				$(".controle", this).css({'background-color':'transparent'});
				$(".voucher", this).val('baby');
				
			}
		});
		return naamok;
	};		
		
	
	
	function check_naw()
	{
		var naamok = true;
				
		if ($("input[name='straat']").val().length < 2)
		{
			naamok = false;
			$("input[name='straat']").css({'background-color':'#ffc0c0'});
		}
		else			
		{
			$("input[name='straat']").css({'background-color':'transparent'});
		}			
			
		if ($("input[name='nummer']").val().length < 1)
		{
			naamok = false;
			$("input[name='nummer']").css({'background-color':'#ffc0c0'});
		}
		else			
		{
			$("input[name='nummer']").css({'background-color':'transparent'});
		}			
		
		if ($("input[name='pc']").val().length < 6)
		{
			naamok = false;
			$("input[name='pc']").css({'background-color':'#ffc0c0'});
		}
		else			
		{
			$("input[name='pc']").css({'background-color':'transparent'});
		}	
			
		if ($("input[name='wp']").val().length < 2)
		{
			naamok = false;
			$("input[name='wp']").css({'background-color':'#ffc0c0'});
		}
		else			
		{
			$("input[name='wp']").css({'background-color':'transparent'});
		}	
		
		if ($("input[name='tel']").val().length < 10)
		{
			naamok = false;
			$("input[name='tel']").css({'background-color':'#ffc0c0'});
		}
		else			
		{
			$("input[name='tel']").css({'background-color':'transparent'});
		}
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if (!reg.test($("input[name='eml']").val()))
		{
			naamok = false;
			$("input[name='eml']").css({'background-color':'#ffc0c0'});
		}
		else			
		{
			$("input[name='eml']").css({'background-color':'transparent'});
		}					
		
		
		return naamok;
	};		
	
	function check_thuis()
	{
		var naamok = true;
				
		if ($("input[name='thuis']").val().length < 4)
		{
			naamok = false;
			$("input[name='thuis']").css({'background-color':'#ffc0c0'});
		}
		else			
		{
			$("input[name='thuis']").css({'background-color':'transparent'});
		}			
			
		if ($("input[name='thuistel']").val().length < 9)
		{
			naamok = false;
			$("input[name='thuistel']").css({'background-color':'#ffc0c0'});
		}
		else			
		{
			$("input[name='thuistel']").css({'background-color':'transparent'});
		}
		return naamok;
	}	
	
	
	
	
	function equalHeight(group) 
	{
		var tallest = 0;
		group.each(function() 
		{
			var thisHeight = $(this).height();
			if(thisHeight > tallest) 
			{
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	}		
    $(".avw").fancybox();

	$("input[type=text]").live("keydown", function()
	{
		if ($(this).val().length > 1)
		{
			//$(this).css({'background-color':'lightgreen'});
		}
	});

	$("#personen ol").load("/engine.php?f=personen&id=1", function()
	{
		$(this).parent().show();
	});
	
	$("#addone").click(function()
	{
		$.get("/engine.php?f=personen&id=" + this.className, function(data)
		{
			$("#personen ol").append(data);
			$(window).scrollTo("ol li:last", 'normal');
			$("#personen h3").html('1. Persoonsgegevens reizigers');
			Cufon.replace("h3");
			Cufon.now();
			
		});	
		this.className = parseInt(this.className) + 1;
		if (parseInt(this.className) > 9)
		{
			$(this).remove();
		}
		return false;
	});
	
	$("#volgende1").click(function()
	{
		if (check_persons())
		{
			$("#naw").show();
			$(window).scrollTo(this, 'normal');
			$(this).remove();
		}
		return false;	
		
	});

	$("#volgende2").click(function()
	{
		if (check_persons() && check_naw())
		{		
			$("#thuis").show();
			$(window).scrollTo(this, 'normal');
			$(this).remove();
		}
		return false;	
		
	});	
	$("#volgende3").click(function()
	{
		if (check_persons() && check_naw() && check_thuis())
		{			
			$("#opstap").show();
			$(window).scrollTo(this, 'normal');		
			$(this).remove();
		}
		return false;	
		
	});	
	$("#opstappl").change(function()
	{
		if ($(this).val() != "")
		{
			$("#ok").show();
			$(window).scrollTo(this, 'normal');
		}
		else
		{
			$("#ok").hide();
			$(window).scrollTo(this, 'normal');
			
		}
		return false;	
		
	});	
	
	$("#gegevens").submit(function()
	{
		return false;
	});

	$("input:first").live("keyup",function()
	{
		$("#hoofd").val($(this).val());	
	});
	
	
	
	$(".voucher").live("keyup",function()
	{
		if ($(this).val().length > 4)
		{
			$(this).parent().next("label").show();
		}	
	});	
	
	
	
	$(".delone").live("click", function()
	{
		$(this).parent().remove();
		if ($("ol li").length == 1)
		{
			$("#personen h3").html('1. Persoonsgegevens reiziger');
			Cufon.replace("h3");
			Cufon.now();
		}
		return false;	
	});
	
	$("input[type=submit]").css({'font-size':'11pt','background-color':'blue','font-weight':'bold','color':'white','border':'none','padding':'5px 10px'});
	
	$("#submit").click(function()
	{
		if ($("#avw").attr('checked') && check_persons() && check_naw() && check_thuis())
		{
			$("#err").load("/engine.php?f=boeken&" + $("form").serialize().replace("'", "`"));
			return false;
		}
		else
		{
			$("#avw").parent().css({'background-color':'#ffc0c0'});
			return false;
		}
	});	
});
