//
//External Script
//
window.jQuery = window.jQuery || (() => ({
// these are all methods required by HubSpot
change: () => {},
trigger: () => {},
}));
(function ($) {
//ThankYouButton
if (thankyoubutton == true) {
var dlbutton = '
';
} else {var dlbutton = '';}
if (thankyouInline == true) {
var tyinlinemsg = ' 
Thank You for Your Submission
'+thankyouInlineMessage+'
'+dlbutton+'';
}
else { var tyinlinemsg = '
' }
hbspt.forms.create({
portalId: hsPortalId,
formId: hsformId,
css: "",
inlineMessage: tyinlinemsg,
onFormReady: function($form) {
$('[name="lead_source"]').val(lead_source).change();
$('[name="lead_source_detail"]').val(lead_source_detail).change();
$('[name="lead_source_other"]').val(lead_source_other).change();
$('[name="eid"]').val(emailID).change();
if (window.TVX_solution) {$('[name="which_solution_are_you_interested_in_"]').val(TVX_solution).change();}
if (window.first_name) {$('[name="firstname"]').val(first_name).change();}
if (window.last_name) {$('[name="lastname"]').val(last_name).change();}
if (window.user_email) {$('[name="email"]').val(user_email).change();}
if (window.user_phone) {$('[name="phone"]').val(user_phone).change();}
if (window.account_name) {$('[name="company"]').val(account_name).change();}
if (window.req_feature) {$('[name="comments"]').val(req_feature).change();}
//Add GDPR To Display Fields Array
$(".legal-consent-container").prependTo('.hs_submit');
$(".legal-consent-container .hs-richtext p").unwrap();
//Placeholder Text
if (placeholder_text === undefined || placeholder_text == 'false' ) {
$.fn.placeholder = function() {
var placeholder_text = false;
//FadeIn Form
$form.find('form').fadeIn(200);
}
}
else if (placeholder_text == true) {
$.fn.placeholder = function() {
$form.find(":input").not('input[type=checkbox], input[type=radio]').each(function(index, elem) {
var eId = $(elem).attr("id");
var label = null;
if (eId && (label = $(elem).parents().find("label[for=" + eId + "] span:first-child")).length == 1) {
$form.find('.hs-form-required').remove();
$form.find(elem).attr("placeholder", $(label).html());
$form.find(label).not(".checkbox-aligned").remove();
}
});
//Required Caret
$form.find("input[required], select[required]").each(function() {
$form.find(this).closest(".input").prepend('*');
});
}
//FadeIn Form
$form.find('form').delay(200).fadeIn(400);
}
$.fn.placeholder();
//Submit Button Function
$.fn.submitbutton = function() {
setInterval(function(){
$form.find("input[type=submit]").val(submit_text );
},);
}
$.fn.submitbutton();
//Layout 2 Sort
$.fn.layout2Sort = function() {
$.fn.placeholder();
n = 0;
$form.find(":input").each(function() {
if ($(this).attr('type') != 'hidden' || $(this).prev('input').length ) {
$form.find(this).closest('.hs-form-field').addClass("line").removeClass("fullwidthrow row-odd row-even").removeAttr('row');
if ($(this).is("textarea") || $(this).is(":submit") || $(this).is(":checkbox") || $(this).is(":radio")) {
$form.find(this).closest('.hs-form-field').addClass('fullwidthrow').css("width", "100%").removeClass('line');
}
}
else {
$form.find(this).closest('.hs-form-field').addClass('hidden').appendTo('.hs_submit');
}
});
$form.find(".line").each(function() {
if ($(this).prev('div').hasClass('fullwidthrow')) {
n = 0
}
$form.find(this).closest('.hs-form-field').attr('row', n);
n++;
if (n == 2) {
n = 0
}
});
//ADD CSS CLASSES TO ODD/EVEN ROWS
$form.find(".line").each(function() {
if (($(this).attr('row') == 0 && $(this).next().hasClass('hs_submit')) || ($(this).attr('row') == 0 && $(this).next('.hs-form-field').hasClass('fullwidthrow')) || ($(this).attr('row') == 0 && $(this).next('noscript').length)) {
//if ($(this).attr('row') == 0 && $(this).next('div').hasClass('fullwidthrow')) {
$form.find(this).closest('.hs-form-field').addClass('fullwidthrow').removeClass('line').removeAttr('row');
}
});
$form.find('.line[ row=' + 0 + ']').addClass('row-odd');
$form.find('.line[ row=' + 1 + ']').addClass('row-even');
}
//STATE FILTER FUNCTIONS
//
//Page Load If Country Present
if ($("[name='country']").length) {
//Page Load State Field Country Logic
var provinceArray = ["Alberta", "Manitoba", "British Columbia", "New Brunswick", "Newfoundland and Labrador", "Nova Scotia", "Northwest Territories", "Nunavut", "Ontario", "Prince Edward Island", "Quebec", "Saskatchewan", "Yukon Territory"];
var optionValue = $("[name='state']").val();
//State Filter Function
$.fn.statefilter = function() {
$("[name='state']").children('option').show();
$('[name="state"] option').filter(function() {
if ("United States" == $("[name='country'] option:selected").val()) {
return $.inArray($.trim($(this).val()), provinceArray) !== -1;
}
else if ("Canada" == $("[name='country'] option:selected").val()) {
return $.inArray($.trim($(this).val()), provinceArray) == -1;
}
}).hide();
}
}
//
//START OF COUNTRY/STATE FUNCTIONS
//
//Page Load IP Lookup
$.get("https://extreme-ip-lookup.com/json/", function(e) {
if (e.status == 'success') {
$("[name='country']").val(e.country);
if ($("[name='state']").length) {
$.fn.statefilter();
}
}
});
//Change Function Country
$("[name='country']").change(function() {
if ($("[name='state']").length) {
$.fn.statefilter();
}
});
//Page Load If US/CA Field Merge
if ("United States" == $("[name='country'] option:selected").val() || "Canada" == $("[name='country'] option:selected").val()) {
if ($("[name='state']").length) {
$.fn.statefilter();
}
}
//DEPENDENT Fields
$('.hs-dependent-field :input').change(function() {
if (layout == 2) {
setTimeout(() => {
$.fn.layout2Sort();
if ($("[name='state']").length) {
$.fn.statefilter();
}
$.fn.placeholder();
if (placeholder_text == 'true') {
$('.hs-dependent-field div label').hide();
$.fn.required();
}
},);
}
if (layout == 1) {
setTimeout(() => {
$('.hs-form input[type=submit]').css('width','100%');
if ($("[name='state']").length) {
$.fn.statefilter();
}
$.fn.placeholder();
if (placeholder_text == 'true') {
$('.hs-dependent-field div label').hide();
$.fn.required();
}
},);
}
});
if (layout == 1) {
$('.hs-form input[type=submit]').css('width','100%');
$.fn.placeholder();
}
else if (layout == 2) {
$.fn.layout2Sort();
}
//Add Google Event on Form Submit
var GAeventLabel = title + ' Form Submission';
window.addEventListener("message", function(event) {
if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted') {
console.log('submitted');
dataLayer.push({
'event': 'form-submission',
'formName': 'Televox.com Form Submission',
'eventLabel': GAeventLabel
});
}
});
//End Form Functions
},
onFormSubmitted: function() {
if (thankyouInline == false) {
window.location = redirectLink;
}
}
});
})(jQuery);