$(function() {
	// validate contact form
	var validator = $("#contactform").validate({
		rules: {
			name: {
				required: true,
				minlength: 2
			},
			email: {
				required: true,
				email: true,
			},
			message: "required",
		},
		messages: {

			name: {
				required: "Dit veld is verplicht.",
				minlength: $.format("Vul minimaal {0} letters in."),
				remote: $.format("{0} is already in use")
			},
			email: {
				required: "Dit veld is verplicht.",
				minlength: "Het e-mail adres is onjuist.",
			},
			message: "Dit veld is verplicht.",
					},
		// the errorPlacement has to take the table layout into account
		errorPlacement: function(error, element) {
			if ( element.is(":radio") )
				error.appendTo( element.parent().next().next() );
			else if ( element.is(":checkbox") )
				error.appendTo ( element.next() );
			else
				error.appendTo( element.parent().next() );
		},
		// set this class to error-labels to indicate valid fields
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}
	});

	// propose username by combining first- and lastname
	$("#username").focus(function() {
		var firstname = $("#firstname").val();
		var lastname = $("#lastname").val();
		if(firstname && lastname && !this.value) {
			this.value = firstname + "." + lastname;
		}
	});

});


