(function() {
if (window.SprayFoamIframeClient) {
return;
}
window.SprayFoamIframeClient = {};
SprayFoamIframeClient.addForm = addForm;
SprayFoamIframeClient.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;
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('');
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 = '';
}
}
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;
}
})();SprayFoamIframeClient.addForm('https://www.sprayfoammagazine.com/api/form/ODCFsoPPLXHb3IBIiBVCpU5yjVzTRrJATjwcVEH5w4fiZPpKxL?iFrame=true');