/**
 * @author Fabian de Rijk
 * @company Total Active Media
 * @desc Init script for JQuery + extra functions
 */

$.validator.setDefaults({
	submitHandler: function() { document.submitOrder.submit(); }
});

/**
 * @desc Function will be fired after document is ready loading
 */
$(document).ready(function(){
	
	// let the lighbox script know that all a tags with rel="lightbox" have to be shown as lightbox
	$('a[@rel*=lightbox]').lightBox();
	
	// the error container for the form
	var container = $('#error');
	container.hide();
	
	// init the form validation
	$("#submitOrder").validate({
		// set the container in which the errors will be shown
		errorContainer: $("#submitOrder #error"),
		errorLabelContainer: $(container),
		
		// add the rules to the input fields
		rules: {
			firstname: {
				required: true
			},
			lastname: {
				required: true
			},
			company: {
				required: true
			},
			street: {
				required: true
			},
			city: {
				required: true
			},
			zipcode: {
				required: true
			},
			email: {
				email: true,
				required: true
			}
		},
		
		// add the error messages
		messages: {
			firstname: {
				required: "You have to fill in your first name"
			},
			lastname: {
				required: "You have to fill in your last name"
			},
			company: {
				required: "You have to fill in the company name"
			},
			street: {
				required: "You have to fill in the street name"
			},
			city: {
				required: "You have to fill in the city"
			},
			zipcode: {
				required: "You have to fill in the zipcode"
			},
			email: {
				email: "You have to fill in a valid email address",
				required: "You have to fill in your email address"
			}
		}
	});
	
	
})

