
$(function(){
$("form#floatForm")
.FormFingerprint()
.submit(function(){
var nameField = $("#fullname");
var emailField = $("#email");
var messageField = $("#question");

nameField.removeClass("kaczmarski_TextAndImagesWithMoreInfoBox_invalidInput");
emailField.removeClass("kaczmarski_TextAndImagesWithMoreInfoBox_invalidInput");
messageField.removeClass("kaczmarski_TextAndImagesWithMoreInfoBox_invalidInput");

var outputDiv = $("#kaczmarski_TextAndImagesWithMoreInfoBox_contactFormResponse");
outputDiv.hide().html("").removeClass('kaczmarski_TextAndImagesWithMoreInfoBox_invalidInput');

var hasError = false;

if(jQuery.trim(nameField.val())==""){ outputDiv.append("Name field is required.<br>"); nameField.addClass("kaczmarski_TextAndImagesWithMoreInfoBox_invalidInput"); hasError=true; }
if(jQuery.trim(emailField.val())==""){ outputDiv.append("Email field is required.<br>"); emailField.addClass("kaczmarski_TextAndImagesWithMoreInfoBox_invalidInput"); hasError=true; }
else if(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(jQuery.trim(emailField.val()))== false){ outputDiv.append("Invalid email address format.<br>"); emailField.addClass("kaczmarski_TextAndImagesWithMoreInfoBox_invalidInput"); hasError=true; }
//if(jQuery.trim(messageField.val())==""){ outputDiv.append("Comment field is required.<br>"); messageField.addClass("kaczmarski_TextAndImagesWithMoreInfoBox_invalidInput"); hasError=true; }

if(hasError){
 outputDiv.addClass('kaczmarski_TextAndImagesWithMoreInfoBox_errorTextColor').show(350);
}
else {
$(this).ajaxSubmit({
dataType: "json",
success: processContactFormJson
});
}

return false; //important
});

//process the response of the contact form submission
function processContactFormJson(data){
$contactFormResponse = $("#kaczmarski_TextAndImagesWithMoreInfoBox_contactFormResponse");
//$contactFormResponse.html(data.message);
if(!data.success){
$contactFormResponse.html(data.message);
$contactFormResponse.addClass('kaczmarski_TextAndImagesWithMoreInfoBox_errorTextColor');
}
else {
$contactFormResponse.html('Your request has been sent. If the Hearing Loss Guide does not automatically open in 5 seconds,&nbsp;<a href="/pdf/KaczmarskiHearing_UnderstandingHearingLoss.pdf" target="_blank">click here</a>&nbsp;to to view it. The Hearing Loss Guide has also been sent to your email address. Thank you.');
$contactFormResponse.removeClass('kaczmarski_TextAndImagesWithMoreInfoBox_errorTextColor');
$("form#floatForm").resetForm();
//$contactFormResponse.oneTime("5s", function(){ $(this).slideUp(500); });
$contactFormResponse.oneTime("5s", function(){ window.location = "/pdf/KaczmarskiHearing_UnderstandingHearingLoss.pdf","mywindow"; });

}
$contactFormResponse.slideDown(400);
}
});


