var _____WB$wombat$assign$function_____=function(name){return (self._wb_wombat && self._wb_wombat.local_init && self._wb_wombat.local_init(name))||self[name];};if(!self.__WB_pmw){self.__WB_pmw=function(obj){this.__WB_source=obj;return this;}}{
let window = _____WB$wombat$assign$function_____("window");
let self = _____WB$wombat$assign$function_____("self");
let document = _____WB$wombat$assign$function_____("document");
let location = _____WB$wombat$assign$function_____("location");
let top = _____WB$wombat$assign$function_____("top");
let parent = _____WB$wombat$assign$function_____("parent");
let frames = _____WB$wombat$assign$function_____("frames");
let opens = _____WB$wombat$assign$function_____("opens");
(function() {
    if (window.InfusionIframeMagicClient) {
        return;
    }

    window.InfusionIframeMagicClient = {};
    InfusionIframeMagicClient.addForm = addForm;
    InfusionIframeMagicClient.receiveMessage = receiveMessage;

    var formId = 0;
    var idPrefix = 'infForm';
    var msgDataRE = /^infform_id(\d+)_h(\d+)_w(\d+)$/;
    var forms = [];
    var isIframeLoading = false;
    var hasIframeToLoad = false;

    var referrer;
    if (parent) {
        referrer = parent.document.URL;
    } else {
        referrer = document.URL;
    }

    if (!window.addEventListener) { // This listener will not be valid in < IE9
        window.attachEvent("onmessage", receiveMessage);
    } else { // For all other browsers other than < IE9
        window.addEventListener("message", receiveMessage, false);
    }

    function receiveMessage(event) {
        var data = event.data;
        console.log("POST MESSAGE RECEIVED: " + data);
        resizeForm(data);
    }

    function resizeForm(data) {
        var found = data.match(msgDataRE);
        if (found) {
            var f = document.getElementById(idPrefix + 'Iframe_' + found[1]);
            if (f) {
                f.height = found[2];
                f.width = found[3];
                f.style.width = found[3];
                formLoaded(found[1]);
            }
            loadNextForm();
        }
    }

    function addForm(url) {
        hasIframeToLoad = true;
        formId = forms.length;
        forms.push({url:url, id:formId, iframeLoaded:false, iframeLoading:false});
        document.write('<div id="' + idPrefix + 'Div_' + formId + '"></div>');
        if (formId == 0) {
            addFormIframe(formId, url);
        }
    }

    function addFormIframe(id, url) {
        var div = document.getElementById(idPrefix + 'Div_' + id);
        if (div) {
            isIframeLoading = true;

            // fix for loading a web form using the js snippet in a file instead of on a website
            var height = "";
            if (startsWith(referrer, "file")) {
                height = " height:100%;";
            }

            var queryStr = "";
            var indexQueryStr = referrer.indexOf("?");

            if (indexQueryStr > -1) {
                queryStr = "&" + referrer.substring(indexQueryStr + 1);
            }

            forms[id].iframeLoading = true;
            div.innerHTML = '<iframe id="' + idPrefix + 'Iframe_' + id + '" name="infFormId=' + id + '&url=' + escape(location.href) +
                    '" allowtransparency="true" src="' + url + '&referrer=' + escape(referrer) + queryStr +
                    '" frameborder="0" scrolling="no" style="overflow:hidden; border:none; width:100%;' +
                    height + '" height="450px"></iframe>';
        }
    }

    function startsWith(str, pattern) {
        if (str == null || pattern == null) return false;
        return str.length >= pattern.length && str.toLowerCase().indexOf(pattern.toLowerCase()) == 0;
    }

    function loadNextForm() {
        if (hasIframeToLoad && !isIframeLoading) {
            for (var i = 0; i < forms.length; i++) {
                var form = forms[i];
                if (!form.iframeLoaded && !form.iframeLoading) {
                    var div = document.getElementById(idPrefix + 'Div_' + form.id);
                    var ifr = document.getElementById(idPrefix + 'Iframe_' + form.id);
                    if (div && !ifr) {
                        addFormIframe(form.id, form.url);
                        break;
                    }
                }
            }
            if (!isIframeLoading) {
                hasIframeToLoad = false;
            }
        }
    }

    function formLoaded(id) {
        forms[id].iframeLoaded = true;
        forms[id].iframeLoading = false;
        isIframeLoading = false;
    }

})();InfusionIframeMagicClient.addForm('https://ys145.infusionsoft.com/app/form/8746ed2667be0eb6998165df5cd032f2?iFrame=true');
}