
$(document).ready( function() {
	//ie6 css3 selectors
	$("input[@type=radio]").css("border", "none");
	$("input[@type=checkbox]").css("border", "none");

	$("#input06, #input25").mask("9999aa", {placeholder:" "});


	//form validation starts here:
	var std = "verplicht"; //standard message
		
	$(".aanpasaanmeld").validate({
		messages: {
			//page01
			input01: std,
			input02: std,
			input03: std,
			input04: "nummer",
			input06: std,
			input07: std,
			input08: std,
			input09: std,
			input10: std,
			input11: "vul hier een nummer in, zonder spaties",
			input12: "vul hier een geldig e-mailadres in",
			
			//page2
			input13: std,
			input14: std,
			input15: std,			
			input18: std,
			input19: std,
			input20: "vul 0 in als u niemand meer nodig heeft",
			input20a: "&eacute;&eacute;n is het minimum",
			//page3
			input22: std,
			input23: std,
			input25: "vul hier een postcode in",
			input25a: std,
			input27: std,
			input28: "vul hier een geldig e-mailadres in",
			input29: "vul hier een nummer in, zonder spaties",
			
			//page4
			input30: "vul hier een geldig e-mailadres in",
			input31: "vul hier een geldig e-mailadres in",
			input32: "vul hier een geldig e-mailadres in",
			input33: "vul hier een geldig e-mailadres in",
			input34: "vul hier een geldig e-mailadres in",
			input35: "vul hier een geldig e-mailadres in"
			
			
			},
			
		rules:{
			//page01
			input04: {number:true},
			input06: {rangelength:[6,7]}, //postcode
			input11: {number: true},
			input12: {email: true},
			input20: {number: true},
			input20a: {number: true},
			input25: {rangelength:[6,7]}, //postcode
			input28: {email: true},
			input29: {number: true},
			
			//page4
			
			input30: {email: true},
			input31: {email: true},
			input32: {email: true},
			input33: {email: true},
			input34: {email: true},
			input35: {email: true}
			
			
			//page2
			
		}
	});	
	
	// accordion functions
	var accordion = $("#stepForm").accordion({
		autoheight: true 
	});
	
	var current = 0;
	
	$.validator.addMethod("pageRequired", function(value, element) {
		var $element = $(element)
		function match(index) {
			return current == index && $(element).parents("#sf" + (index + 1)).length;
		}
		if (match(0) || match(1) || match(2) || match(3)) {
			return !this.optional(element);
		}
		return "dependency-mismatch";
	}, $.validator.messages.required)
	
	var v = $("#cmaForm").validate({
		debug: true,					   
		errorClass: "warning",
		onkeyup: false,
		onblur: false,
		submitHandler: function() {
			form.submit();
		}
	});
	
	// back buttons do not need to run validation
	$("#sf2 .prevbutton").click(function(){
		accordion.activate(0);
		current = 0;
	}); 
	$("#sf3 .prevbutton").click(function(){
		accordion.activate(1);
		current = 1;
	}); 
	$("#sf4 .prevbutton").click(function(){
		accordion.activate(2);
		current = 2;
	}); 
	
	// these buttons all run the validation, overridden by specific targets above
	$(".open3").click(function() {
	  if (v.form()) {
		accordion.activate(3);
		current = 3;
	  }
	});
	$(".open2").click(function() {
	  if (v.form()) {
		accordion.activate(2);
		current = 2;
	  }
	});
	$(".open1").click(function() {
	  //$(".gegevens").css('height','auto')
	  if (v.form()) {
		accordion.activate(1);
		current = 1;
	  }
	});
	$(".open0").click(function() {
	  //$(".gegevens").css('height','auto')
	  if (v.form()) {
		accordion.activate(0);
		current = 0;
	  }
	});
	
	
	
	
});
