$(function() {
	
	$(".submit").click(function() {
		// validate and process form
		// first hide any error messages
		$('.errorBox').text("");
		$('.errorBox').hide();
		$('.messageBox').hide();
		$('.positiveBox').hide();
		
		var name = $("input#Name").val();
		if (name == "") {
			$('.errorBox').text("You must provide a name!");
			$('.errorBox').show();
			$("input#Name").focus();
			return false;
		}
		var email = $("input#Email").val();
		var phone = $("input#Phone").val();
		var fax = $("input#Fax").val();
		if (email == "" && phone == "" && fax == "") {
			$('.errorBox').text("You must provide a conact method. Please provide either an e-mail, phone or fax number!");
			$('.errorBox').show();
			$("input#Email").focus();
			return false;
		}
		
		$('.messageBox').text("Please wait while we process your request...");
		$('.messageBox').show();
		$('input.submit').val("Please wait...");
		
		setTimeout(function(){ self.SubmitForm() }, 750);
		
    return false;
	
	});
	
});

function SubmitForm() {

	var dataString = 'Name='+ $("input#Name").val() + '&Email=' + $("input#Email").val() + '&Phone=' + $("input#Phone").val() + '&Fax=' + $("input#Fax").val();
	dataString += '&Comments=' + $("textarea#Comments").val() + '&MoreInformation=' + $("select#MoreInformation").val() + '&HearAboutPrevent=' + $("select#HearAboutPrevent").val();
	dataString += '&HearAboutPreventOther=' + $("input#HearAboutPreventOther").val() + '&ContactASAP=' + $("select#ContactASAP").val();
		
	$.ajax({
		type: "POST",
		url: "/home/library/ajax_ContactSend.cfm",
		data: dataString,
		success: function() {
			$('.messageBox').hide();
			$('.positiveBox').text("Contact form submitted! We will be in touch soon!");
			$('.positiveBox').show();
			$(':input').val("");
			$('input.submit').val("Submit");
			$('input.reset').val("Reset");
		}
	});
	
}