// FLEX_LP-custom.js


// =======[Floating Form Labels]======= // 
// requires mktoForm-floatingLabels.css (.activeLabel styles)
// requires Marketo form label setting set to "Above" (instead of "Left")
function floatingLabels() {
        // clear Radio and Checkbox labels
        $('.mktoRadioList, .mktoCheckboxList').parent().children('label').addClass('d-none');
        // clear first option of select elements
        $('select option:nth-of-type(1)').html("");

        // all form input elements
        var inputs = $('.mktoForm input[type=url], .mktoForm input[type=text], .mktoForm input[type=date], .mktoForm input[type=tel], .mktoForm input[type=email], .mktoForm input[type=number], .mktoForm textarea.mktoField, .mktoForm select.mktoField');

        // add .activeLabel when field is focused
        $(inputs).focus(function(){ 
            var fieldID = $(this).attr('id');  
            fieldLabel = 'label.mktoLabel[for=' + fieldID +']'; 
            $(fieldLabel).addClass('activeLabel') 
        }); 

        // remove .activeLabel when field is blurred if empty
        $(inputs).blur(function(){ 
            var fieldID = $(this).attr('id');  
            fieldLabel = 'label.mktoLabel[for=' + fieldID +']';
            if ($(this).val() == ""){
                $(fieldLabel).removeClass('activeLabel');
            } 
        }); 
    }

$(window).on('load',function(){
    $(document).ready(function() {
      
            if($('body').is('.floatingLabels-on')){
                MktoForms2.whenReady(function (form){
                    $(floatingLabels)
                    $('form.mktoForm').on('change', floatingLabels); 
                });   
            }
            else {}
        
    });
});

// animate form offset after page loads w/ delay
$(document).ready(function(){
    setTimeout(function() { 
       $('body').addClass('form-offset');    
    }, 1000);
});