$.validator.setDefaults({
	submitHandler: function() {
		//$("#contactForm").ajaxSubmit();
		//alert("Thank you. You will receive a confirmation email shortly.");
		$('#contact-form').ajaxSubmit({ 
			success: function(t) {
				//alert("Form submission a success. The server has returned: " + t);
				$("#body-copy").html('<h2 class="first">Enquiry Form</h2><p>Thank you. Your enquiry has been submitted.</p>'); 
			}
		});
	}
});
			
$(document).ready(function() {
	// validate contact form when submit button keyup
	$("#contact-form").validate({
		rules: {
			salutation: "required",			
			"first-name": {
				required: true,
				minlength: 2
			},
			"last-name": {
				required: true,
				minlength: 2
			},
			state: "required",
			suburb: "required",
			postcode: {
				required: true,
				number: true
			},
			method: "required",
			phone: {
				required: true,
				number: true
			},
			email: {
				required: true,
				email: true
			}
		},
		messages: {
			salutation: {
				required: "Please select a title"
			},
			"first-name": {
				required: "Please enter your first name",
				minlength: "Your first name must be at least 2 chars"
			},
			"last-name": {
				required: "Please enter your last name",
				minlength: "Your last name must be at least 2 chars"
			},
			state: {
				required: "Please select a state"
			},
			suburb: {
				required: "Please enter your suburb"
			},
			postcode: {
				required: "Please enter your postcode",
				number: "Please enter a number only"
			},
			method: {
				required: "Please select your preferred method of contact"
			},
			phone: {
				required: "Please enter your telephone number",
				number: "Please enter a number only"
			},
			email: {
				required: "Please enter an email address",
				email: "Please enter a valid email address"
			}
		}
	});
	
	// apply inline-box only for mozilla
	if( jQuery.browser.mozilla ) {
		// do when DOM is ready
		$( function() {
			// search form, hide it, search labels to modify, filter classes nocmx and error
			$( '#contact-form' ).hide().find( 'p>label:not(.nocmx):not(.error)' ).each( function() {
				var $this = $(this);
				var labelContent = $this.html();
				var labelWidth = document.defaultView.getComputedStyle( this, '' ).getPropertyValue( 'width' );
				// create block element with width of label
				var labelSpan = $("<span>")
					.css("display", "inline")
					.width(labelWidth)
					.html(labelContent);
				// change display to mozilla specific inline-box
				$this.css("display", "-moz-inline-box")
					// remove children
					.empty()
					// add span element
					.append(labelSpan);
			// show form again
			}).end().show();
		});
	};
});