$(document).ready(function() {

	//validate and submit
	$('#contact_form').validate({
		rules: {
			enquiry_first_name: {
				required: true,
				minlength: 3
			},
/*			enquiry_surname: {
				required: true,
				minlength: 3
			},
*/			enquiry_email: {
				required: true,
				email: true
			}
/*			enquiry_email_validate: {
				required: true,
				email: true,
				equalTo : "#enquiry_email"
			}
*/		},
		messages: {
			enquiry_first_name: {
				required: 'Please fill in your first name.',
				minlength: $.format('At least {0} characters required!')
			},
/*				enquiry_surname: {
				required: 'Please fill in your surname.',
				minlength: $.format('At least {0} characters required!')
			},
*/				enquiry_email: {
				required: 'Please fill in your email.'
			}
/*				enquiry_email_validate: {
				required: 'Please verify your email.',
				equalTo : 'Email addresses must match.'
			}
*/		}
	});

	/*$("#enquiry_email").blur(function() {
	  $("#enquiry_email_validate").valid();
	});*/
});

function doSend() {
	if ($('#contact_form').valid()) {
		$('#contact_form').ajaxSubmit({
			url: '/contact_us/contact_post.php',
			type: 'post',
			dataType: 'json',
			success: function(json) {
				if (json.success) {

					//add google tracking
					var google_conversion_id = 1039606778;
					var google_conversion_language = "en";
					var google_conversion_format = "2";
					var google_conversion_color = "666666";
					var google_conversion_value = 0;

					if (queryType =='cu') { //contact us
						//<!-- Google Code for Lead (OE) Conversion Page -->
						var google_conversion_label = "NnfxCIbaswEQ-sfc7wM";
						$.getScript('http://www.googleadservices.com/pagead/conversion.js' , function(){
							$('#google_cu').html('<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1039606778/?label=NnfxCIbaswEQ-sfc7wM&amp;guid=ON&amp;script=0"/>');
						});
					}

					if (queryType =='td') { //Test Drive
						//<!-- Google Code for Test Drive (OE) Conversion Page -->
						var google_conversion_label = "s8j_CODaswEQ-sfc7wM";
						$.getScript('http://www.googleadservices.com/pagead/conversion.js' , function(){
							$('#google_td').html('<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1039606778/?label=s8j_CODaswEQ-sfc7wM&amp;guid=ON&amp;script=0"/>');
						});
					}

					if (queryType =='ns') { //contact us
						//<!-- Google Code for Lead (OE) Conversion Page -->
						var google_conversion_label = "NQVNCLrbswEQ-sfc7wM";
						$.getScript('http://www.googleadservices.com/pagead/conversion.js' , function(){
							$('#google_ns').html('<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1039606778/?label=NQVNCLrbswEQ-sfc7wM&amp;guid=ON&amp;script=0"/>');
						});
					}
					location.href = '/contact_us/thank_you.php?q='+queryType;
				} else {
					alert('Error:\n' + json.error);
				}
			}
		});
	//} else {
		//window.status = 'One or more of your fields have a validation error, please check what is filled in.';
	}
}
