// source --> https://pi-dom.com/wp-content/plugins/woocommerce/assets/js/frontend/woocommerce.min.js?ver=10.7.0 
function on_keydown_remove_from_cart(e){" "===e.key&&(e.preventDefault(),e.currentTarget.click())}function focus_populate_live_region(){var e=["woocommerce-message","woocommerce-error","wc-block-components-notice-banner"].map(function(e){return"."+e+'[role="alert"]'}).join(", "),o=document.querySelectorAll(e);if(0!==o.length){var t=o[0];t.setAttribute("tabindex","-1");var n=setTimeout(function(){t.focus(),clearTimeout(n)},500)}}function refresh_sorted_by_live_region(){var e=document.querySelector(".woocommerce-result-count");if(e){var o=e.innerHTML;e.setAttribute("aria-hidden","true");var t=setTimeout(function(){e.setAttribute("aria-hidden","false"),e.innerHTML="",e.innerHTML=o,clearTimeout(t)},2e3)}}function on_document_ready(){focus_populate_live_region(),refresh_sorted_by_live_region()}jQuery(function(e){e(".woocommerce-ordering").on("change","select.orderby",function(){e(this).closest("form").trigger("submit")}),e("input.qty:not(.product-quantity input.qty)").each(function(){var o=parseFloat(e(this).attr("min"));o>=0&&parseFloat(e(this).val())<o&&e(this).val(o)});var o="store_notice"+(e(".woocommerce-store-notice").data("noticeId")||"");if("hidden"===Cookies.get(o))e(".woocommerce-store-notice").hide();else{function t(o){["Enter"," "].includes(o.key)&&(o.preventDefault(),e(".woocommerce-store-notice__dismiss-link").click())}e(".woocommerce-store-notice").show(),e(".woocommerce-store-notice__dismiss-link").on("click",function n(r){Cookies.set(o,"hidden",{path:"/"}),e(".woocommerce-store-notice").hide(),r.preventDefault(),e(".woocommerce-store-notice__dismiss-link").off("click",n).off("keydown",t)}).on("keydown",t)}e(".woocommerce-input-wrapper span.description").length&&e(document.body).on("click",function(){e(".woocommerce-input-wrapper span.description:visible").prop("aria-hidden",!0).slideUp(250)}),e(".woocommerce-input-wrapper").on("click",function(e){e.stopPropagation()}),e(".woocommerce-input-wrapper :input").on("keydown",function(o){var t=e(this).parent().find("span.description");if(27===o.which&&t.length&&t.is(":visible"))return t.prop("aria-hidden",!0).slideUp(250),o.preventDefault(),!1}).on("click focus",function(){var o=e(this).parent(),t=o.find("span.description");o.addClass("currentTarget"),e(".woocommerce-input-wrapper:not(.currentTarget) span.description:visible").prop("aria-hidden",!0).slideUp(250),t.length&&t.is(":hidden")&&t.prop("aria-hidden",!1).slideDown(250),o.removeClass("currentTarget")}),e.scroll_to_notices=function(o){o.length&&e("html, body").animate({scrollTop:o.offset().top-100},1e3)},e('.woocommerce form .woocommerce-Input[type="password"]').wrap('<span class="password-input"></span>'),e(".woocommerce form input").filter(":password").parent("span").addClass("password-input"),e(".password-input").each(function(){const o=e(this).find("input").attr("id");e(this).append('<button type="button" class="show-password-input" aria-label="'+woocommerce_params.i18n_password_show+'" aria-describedBy="'+o+'"></button>')}),e(".show-password-input").on("click",function(o){o.preventDefault(),e(this).hasClass("display-password")?(e(this).removeClass("display-password"),e(this).attr("aria-label",woocommerce_params.i18n_password_show)):(e(this).addClass("display-password"),e(this).attr("aria-label",woocommerce_params.i18n_password_hide)),e(this).hasClass("display-password")?e(this).siblings(['input[type="password"]']).prop("type","text"):e(this).siblings('input[type="text"]').prop("type","password"),e(this).siblings("input").focus()}),e("a.coming-soon-footer-banner-dismiss").on("click",function(o){var t=e(o.target);e.ajax({type:"post",url:t.data("rest-url"),data:{woocommerce_meta:{coming_soon_banner_dismissed:"yes"}},beforeSend:function(e){e.setRequestHeader("X-WP-Nonce",t.data("rest-nonce"))},complete:function(){e("#coming-soon-footer-banner").hide()}})}),"undefined"==typeof wc_add_to_cart_params&&e(document.body).on("keydown",".remove_from_cart_button",on_keydown_remove_from_cart),e(document.body).on("item_removed_from_classic_cart updated_wc_div",focus_populate_live_region)}),document.addEventListener("DOMContentLoaded",on_document_ready);
// source --> https://pi-dom.com/wp-content/plugins/profile-builder-hobbyist//features/form-designs/js/form-designs-s3-front-end.js?ver=3.16.0 
jQuery(document).ready(function() {
    // Handle Form Fields on page load/refresh
    handleFormFields();
});

/**
 * Handles Form Fields
 *
 */
function handleFormFields () {

    // mark disabled fields
    jQuery('.wppb-form-field:not(.login-submit):not(.wppb-two-factor-authentication) input:disabled').parent().addClass('disabled-field');

    // set WYSIWYG to readonly if field is disabled
    jQuery('.wppb-wysiwyg.disabled-field').each(function () {
        let editorId = jQuery(this).find('textarea').attr('id');
        if (typeof tinymce !== 'undefined' && tinymce.get(editorId)) {
            tinymce.get(editorId).setMode('readonly');
        }
    });

    // mark Upload/Avatar Fields on Edit Form, if a file is present
    if ( jQuery('.wppb-avatar').find('.upload-field-details').length > 0 )
        jQuery('.wppb-avatar').addClass('file-selected');
    if ( jQuery('.wppb-upload').find('.upload-field-details').length > 0 )
        jQuery('.wppb-upload').addClass('file-selected');

    // Disable HTML5 validation. It prevents form field error markers to be displayed for required fields.
    jQuery('.wppb-register-user').attr('novalidate', 'novalidate');


    // handle changes for Upload and Avatar Fields
    observeUploadFieldChanges();

    // handle PMS Billing Field Labels
    handleBillingFieldLabels();

}


/**
 * Handles changes for Upload and Avatar Fields
 *
 */
function observeUploadFieldChanges() {

    // mark Upload/Avatar Fields when a file is selected for upload
    const uploadFieldObserver = new MutationObserver(handleUploadFieldChanges);

    jQuery('.wppb-avatar, .wppb-upload').each(function() {
        uploadFieldObserver.observe(this, {
            childList: true,
            subtree: true,
            attributes: true
        });
    });

    function handleUploadFieldChanges(mutationsList) {
        mutationsList.forEach(mutation => {
            if (mutation.type === 'childList' || mutation.type === 'attributes') {
                let uploadField = jQuery(mutation.target);

                if (uploadField.find('.upload-field-details').length > 0) {
                    uploadField.addClass('file-selected');
                } else {
                    uploadField.removeClass('file-selected');
                }
            }
        });
    }

}


/**
 * Handles PMS Billing Fields
 *
 */
function handleBillingFieldLabels() {

    let pmsSelectFields = jQuery('#pms_billing_country, #pms_billing_state');

    if (pmsSelectFields.length > 0) {
        pmsSelectFields.each(function() {
            jQuery(this).on('chosen:ready', function() {
                jQuery('#' + jQuery(this).attr('id') + '_chosen .chosen-single.chosen-default span').html(jQuery('label[for="' + jQuery(this).attr('id') + '"]').html());
            });
        });
    }

};
// source --> https://pi-dom.com/wp-content/plugins/profile-builder-hobbyist/add-ons-advanced/custom-profile-menus/assets/js/wppb_cpm_main.js?ver=3.16.0 
var wppb_cpm_global_height = "";
var wppb_cpm_global_width = "";

jQuery( document ).ready( function() {
    var url;

    jQuery( 'body' ).click( function( e ) {
        if( ( jQuery( e.target ).is( 'span.ubermenu-target-title' ) && jQuery( e.target ).parents( '.ubermenu-item-type-wppb_cpm_login_iframe, .ubermenu-item-type-wppb_cpm_register_iframe, .ubermenu-item-type-wppb_cpm_edit_profile_iframe' ).length )
        || ( jQuery( e.target ).is( 'a.ubermenu-target' ) && jQuery( e.target ).parents( '.ubermenu-item-type-wppb_cpm_login_iframe, .ubermenu-item-type-wppb_cpm_register_iframe, .ubermenu-item-type-wppb_cpm_edit_profile_iframe' ).length ) ) {
            e.preventDefault();

            if( jQuery( e.target ).is( 'span.ubermenu-target-title' ) ) {
                url = jQuery( e.target ).parent().attr( 'href' );
            } else {
                url = jQuery( e.target ).attr( 'href' );
            }

            if( url !== undefined ) {
                wppb_cpm_open_iframe( url );
            }
        }
    } );

    jQuery( '.menu-item-type-wppb_cpm_login_iframe, .menu-item-type-wppb_cpm_edit_profile_iframe, .menu-item-type-wppb_cpm_register_iframe' ).click( function( e ) {
        e.preventDefault();

        url = jQuery( this ).children().attr( 'href' );

        if( url !== undefined ) {
            wppb_cpm_open_iframe( url );
        }
    } );
} );

function wppb_cpm_open_iframe( url ) {
    var title = wppb_getParameterByName( 'wppb_cpm_iframe_title', url );
    wppb_cpm_global_height = wppb_getParameterByName( 'wppb_cpm_iframe_height', url );
    wppb_cpm_global_width = wppb_getParameterByName( 'wppb_cpm_iframe_width', url );

    tb_show( title, url + 'TB_iframe=true&width=' + wppb_cpm_global_width + '&height=' + wppb_cpm_global_height, '' );

    jQuery( '#TB_window').append( '<div id="wppb_cpm_spinner"></div>' );

    wppb_cpm_resize_iframe();

    if( wppb_getMobileOperatingSystem() == 'iOS' ) {
        jQuery( '#TB_iframeContent' ).wrap( "<div class='wppb_cpm_iframe_wrap'></div>" );
    }

    jQuery( '#TB_iframeContent' ).load( function() {
        jQuery( '#wppb_cpm_spinner' ).remove();
        wppb_cpm_resize_iframe();
    } );
}

function wppb_cpm_check_iframe() {
    var current_url = jQuery( document )[0]['URL'];
    var iFrame_check = ( window.location != window.parent.location );

    if( iFrame_check ) {
        if( current_url.indexOf( "wppb_cpm_redirect=yes" ) !== -1 && current_url.indexOf( "wppb_cpm_iframe=yes" ) === -1 ) {
            window.parent.location.href = current_url;
            parent.wppb_tb_remove();
        } else {
            jQuery( window ).on("unload", function() {
                if( jQuery( '.wppb-cpm-logged-in' ).length !== 0 && current_url.indexOf( "wppb_cpm_form=login" ) !== -1 ) {
                    window.parent.location.reload();
                }
            } );
        }
    }

    removeQueryVariable( 'wppb_cpm_redirect', current_url );
}
wppb_cpm_check_iframe();

function removeQueryVariable( variable, current_url ) {

    var url_parts       = current_url.split('?');
    var urlSearchParams = new URLSearchParams( url_parts[1] );

    if ( urlSearchParams.has( variable ) ){
        urlSearchParams.delete( variable );

        var url = url_parts[0] + urlSearchParams.toString();

        window.history.replaceState({}, document.title, url);
    }
}

// edited tb_remove() function
function wppb_tb_remove() {
    jQuery( "#TB_imageOff" ).unbind( "click" );
    jQuery( "#TB_closeWindowButton" ).unbind( "click" );
    jQuery( '#TB_window, #TB_overlay, #TB_HideSelect' ).trigger( 'tb_unload' ).unbind().remove();
    jQuery( 'body' ).removeClass( 'modal-open' );
    jQuery( "#TB_load" ).remove();
    if( typeof document.body.style.maxHeight == "undefined" ) { // if IE 6
        jQuery( "body", "html" ).css( { height: "auto", width: "auto" } );
        jQuery( "html" ).css( "overflow", "" );
    }
    jQuery( document ).unbind( '.thickbox' );
    return false;
}

jQuery( window ).resize( function() {
    if( document.getElementById( 'TB_iframeContent' ) && document.getElementById( 'TB_iframeContent' )['src'].indexOf( "wppb_cpm_iframe=yes" ) !== -1 ) {
        wppb_cpm_resize_iframe();
    }
} );

function wppb_cpm_resize_iframe() {
    var max_height = wppb_cpm_global_height;
    var max_width = wppb_cpm_global_width;

    var iframe_max_height = jQuery( window ).height() * 75 / 100;
    var iframe_max_width = jQuery( window ).width() * 80 / 100;

    var iframe_selector = jQuery( '#TB_iframeContent');
    var iframe_wrap_selector = jQuery( '.wppb_cpm_iframe_wrap');
    var tb_window_selector = jQuery( '#TB_window');

    iframe_selector.height( ( iframe_max_height < max_height ? iframe_max_height : max_height ) );
    iframe_wrap_selector.height( ( iframe_max_height < max_height ? iframe_max_height : max_height ) );
    tb_window_selector.css( "margin-top", parseInt( "-" + ( iframe_max_height < max_height ? iframe_max_height : max_height ) / 2 ) );
    tb_window_selector.css( "margin-left", parseInt( "-" + ( iframe_max_width < max_width ? iframe_max_width : max_width ) / 2 ) );
    iframe_selector.width( ( iframe_max_width < max_width ? iframe_max_width : max_width ) );
    iframe_wrap_selector.width( ( iframe_max_width < max_width ? iframe_max_width : max_width ) );
    tb_window_selector.width( ( iframe_max_width < max_width ? iframe_max_width : max_width ) );
}

/**
 * Determine the mobile operating system.
 * This function either returns 'iOS' or 'unknown'
 *
 * @returns {String}
 */
function wppb_getMobileOperatingSystem() {
    var userAgent = navigator.userAgent || navigator.vendor || window.opera;

    if( userAgent.match( /iPad/i ) || userAgent.match( /iPhone/i ) || userAgent.match( /iPod/i ) ) {
        return 'iOS';
    } else {
        return 'unknown';
    }
}

/**
 * Get parameters from url (by name)
 *
 * @returns {String}
 */
function wppb_getParameterByName( name, url ) {
    name = name.replace( /[\[\]]/g, "\\$&" );

    var regex = new RegExp( "[?&]" + name + "(=([^&#]*)|&|#|$)" ), results = regex.exec( url );

    if( ! results)
        return null;

    if( ! results[2])
        return '';

    return decodeURIComponent( results[2].replace( /\+/g, " " ) );
};