jQuery(document).ready(function () {
var useGlobal = true;
var htmlContents = '
';
if (useGlobal) {
var container = $("img[alt='incentive-container']").closest(".widget-image");
if (container.length) {
container.parent().prepend("")
container.remove();
$('.incentivesContainer').html(htmlContents);
} else {
$("#webspecials-global").addClass("incentivesContainer");
$("#webspecials-global").html(htmlContents);
}
} else {
$("#webspecials").html(htmlContents);
}
$(".contact-form #specialsContactForm input").blur(function () {
$(this).removeClass("hasErrors");
})
});
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
function showContactForm(specialId) {
$('.contact-form #specialId').val(specialId);
$('.contact-form').fadeIn();
}
function closeForm() {
$(".contact-form #specialsContactForm input").removeClass("hasErrors");
$(".contact-form .messages .errors").html("");
$('.contact-form .sending').hide();
$('.contact-form .thanks').hide();
$('.contact-form .message').hide();
$('.contact-form').fadeOut();
$(".contact-form #specialsContactForm").get(0).reset();
setTimeout(function () {
$('.contact-form .controls').show();
$(".contact-form .contactFormTitle").show();
}, 1000);
}
function sendData() {
$(".contact-form #specialsContactForm input").removeClass("hasErrors");
$(".contact-form .messages .errors").html("");
var hasErrors = false;
if (!$(".contact-form #specialsContactForm #first_name").val()) {
$(".contact-form #specialsContactForm #first_name").addClass("hasErrors");
hasErrors = true;
}
if (!$(".contact-form #specialsContactForm #last_name").val()) {
$(".contact-form #specialsContactForm #last_name").addClass("hasErrors");
hasErrors = true;
}
if (!$(".contact-form #specialsContactForm #email").val()) {
$(".contact-form #specialsContactForm #email").addClass("hasErrors");
hasErrors = true;
}
if (hasErrors) {
$(".contact-form .messages .errors").html("Please complete all required fields");
alert("Please complete all required fields");
return;
}
if (!validateEmail($(".contact-form #specialsContactForm #email").val())) {
$(".contact-form #specialsContactForm #email").addClass("hasErrors");
$(".contact-form .messages .errors").html("Please enter a valid email address");
alert("Please enter a valid email address");
return;
}
$(".contact-form .sending").fadeIn();
$.ajax({
type: "POST",
url: "https://api.quirkspecials.com/v2/api/specials/emailLead",
data: $(".contact-form #specialsContactForm").serialize(),
success: function (response) {
$(".contact-form #specialsContactForm").get(0).reset();
$(".contact-form .sending").fadeOut();
$(".contact-form .contactFormTitle").hide();
$('.contact-form .controls').hide();
$(".contact-form .thanks").show();
},
error: function (response) {
$(".contact-form .sending").fadeOut();
alert("We can't send your message right now, please try again later");
}
});
}