// I set the debug option to true, so the data is not commited, 
// enabling me to review the outcome.
$.validator.setDefaults({
	debug: false
});


$(document).ready(function() {
	 // validate signup form on keyup and submit
	$("#contactForm").validate({
	
		//As soon as a key within a form field in “myform” is release then start
		event: "keyup",
		
		//Here the rules for the individual inputs are defined.
		rules: {
			
			//for id "username"
			naam: {
				required: true,
				minlength: 2
			},
			adres: {
				required: true,
				minlength: 3
			},
			plaats: {
				required: true,
				minlength: 2
			},
			email: {
				required: true,
				//It is an E-Mail address
				email: true
			},
			telefoon: {
				required: function(element) { return (($("#mobiel").val().length < 1) && ($("#fax").val().length < 1)); },
				minlength: 10,
				digits: true
			},
			mobiel: {
				required: function(element) { return (($("#telefoon").val().length < 1) && ($("#fax").val().length < 1)); },
				minlength: 10,
				digits: true
			},
			fax: {
				required: function(element) { return (($("#mobiel").val().length < 1) && ($("#telefoon").val().length < 1)); },
				minlength: 10,
				digits: true
			}
		},
		
		//Here the error messages for all rules are defined.
		messages: {
			naam: 'Vul uw naam in',
			adres: 'Vul uw adres in',
			telefoon: {
				required: 'Vul uw telefoonnummer in',
				minlength: 'Vul uw 10 cijferige telefoonnummer in',
				digits: 'Alleen de cijfers van uw telefoonnummer'
			},
			mobiel: {
				required: 'Of vul uw mobiele nummer in',
				minlength: 'Vul uw 10 cijferige telefoonnummer in',
				digits: 'Alleen de cijfers van uw telefoonnummer'
			},
			fax: {
				required: 'Of vul uw faxnummer in',
				minlength: 'Vul uw 10 cijferige faxnummer in',
				digits: 'Alleen de cijfers van uw faxnummer'
			},
			plaats: 'Vul uw plaats in',
			email: 'Vul een correct email adres in'
		},
		
        // specifying a submitHandler prevents the default submit, good for the demo 
        //submitHandler: function() { 
        //    alert("submitted!"); 
        //}, 
        // set this class to error-labels to indicate valid fields 
        success: function(label) { 
            // set   as text for IE 
            label.html(" ").addClass("checked"); 
        }
	});
});

