$(document).ready(function() {

	//validate and submit
	$('#enquiryForm').validate({
		rules: {
			enquiry_name: {
				required: true,
				minlength: 3
			},
			enquiry_email: {
				required: true,
				email: true,
				minlength: 5
			},
			enquiry_comment: {
				required: true,
				minlength: 3
			}
		},
		messages: {
			enquiry_name: {
				required: 'Please fill in your full name.',
				minlength: $.format('At least {0} characters required!')
			},
			enquiry_email: {
				required: 'Please fill in your email address.',
				minlength: $.format('At least {0} characters required!')
			},
			enquiry_comment: {
				required: 'Please fill in your comment.'
			}
		}
	});


});



function doSend() {
	if ($('#enquiryForm').valid()) {
		
		$('#contact_status').html('processing...');
		
		$('#enquiryForm').ajaxSubmit({
			url: '/enquiry/contact_process.php',
			dataType: 'json',
			success: function(json) {
				if (json.success) {
					$('#contact_status').html('enquiry sent succesfully...');
					
					<!--Google Analytics Code-->
					var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");					
					$.getScript(gaJsHost + "google-analytics.com/ga.js", function()
					{

						var pageTracker = _gat._getTracker("UA-7446773-1");
						pageTracker._trackPageview('/enquiry/thank_you.php?ref_no='+json.ref_no+'&launch='+json.launch+'&tour='+json.tour+'&joburg='+json.joburg);
						
						
						pageTracker._addTrans(
							json.ref_no, // Order ID
							"unknown", // Affiliation
							"0", // Total
							"unknown", // City
							"unknown", // State
							"unknown" // Country
						);
						
						if (json.launch == '1') {
							
							pageTracker._addItem(
								json.ref_no, // Item Number
								"Enquiry", // SKU
								"Launch", // Product Name
								"Contact", // Category
								"0", // Price
								"1" // Quantity
							);
						}
						
						if (json.tour == '1') {
							
							pageTracker._addItem(
								json.ref_no, // Item Number
								"Enquiry", // SKU
								"Tour", // Product Name
								"Contact", // Category
								"0", // Price
								"1" // Quantity
							);
						}
						
						if (json.joburg == '1') {
							
							pageTracker._addItem(
								json.ref_no, // Item Number
								"Enquiry", // SKU
								"Joburg", // Product Name
								"Contact", // Category
								"0", // Price
								"1" // Quantity
							);
						}
						
						pageTracker._trackTrans();
						
					});
					
					location.href = '/enquiry/thank_you.php?ref_no='+json.ref_no+'&launch='+json.launch+'&tour='+json.tour+'&joburg='+json.joburg;
					
				} else {
					window.alert('Error:\n' + json.error);
				}
			}
		});
	} else {
		window.status = 'One or more of your fields have a validation error, please check what is filled in.';
	}
}
