	$(document).ready(function() {

		//###   CONTACT US FORM   ###
		if ( $("#contact").length > 0 ) {
			$("#contact").validate({
				submitHandler: function(form) {
					$(form).ajaxSubmit({ beforeSubmit: showRequest,	 success: contact_Response });
					return false;
				},
				highlight: function(element, errorClass) {$(element).addClass('error');}
			});
		}
	});

	function showRequest(formData, jqForm, options) {
		return true; 
	}
	function errorCheck(Errors) {
		//###   Check for errors   ###
//alert("error:"+jQuery("h1", responseText).html());
//		if ( jQuery("h1", responseText):contains("Error").length > 0 ) {
//alert("error found");
//}

	}
	function contact_Response(responseText, statusText) {
		if ( $("#contact").length > 0 ) {
			$("#contact").hide();
			if ( $("#enquiry").val().length > 0) {
				$("#contact").after("<p id='form-success'>Thank you - we'll process your enquiry as soon as possible.<p>");
				if ( $("#newsletter-signup").is(":checked") == true) {SubmitNewsletter();}
			} else if ( $("#newsletter-signup").is(":checked") == true) {
				$("#contact").after("<p id='form-success'>Thank you - you've successfully subscribed to our newsletter.<p>");
				SubmitNewsletter();
			} else {
				$("#contact").after("<p id='form-success'>Thank you - we've received your details. " + $("#newsletter-signup").is(":checked") + "<p>");
			}

			ClearForm();
		}
	}

function SubmitNewsletter() {
	$("#nl-name").val( $("#fullname").val() );
	$("#jrtuit-jrtuit").val( $("#email").val() );
	$("#CompanyName").val( $("#company").val() );

	ClearForm();

	// OLD= $("#newsletter-form").submit();

	//###   Serialize form values to be submitted with POST
	var str = $("#newsletter-form").serialize();

	//###   Grab form action
	var formAction = $("#newsletter-form").attr("action");
			
	//###   Add form action to end of serialized data
	var final = str + "&action=" + formAction;

	//###   Submit the form via ajax
	$.ajax({
		url: "/themes/site_themes/donky/js/newsletter-proxy.php",
		type: "POST",
		data: final,
		success: function(html) {//alert("subscribed");}
	});
}

function ClearForm() {
			//###   Reset Form   ###
			$(":input", "#contact").each(function() {
				var type = this.type;
				var tag = this.tagName.toLowerCase();
				if (type == 'text' || type == 'password' || tag == 'textarea') {
					this.value = "";
				}
			});
}
