﻿
// defer load ad 

function deferLoadAD(iframeName) {
    var iframe = document.getElementById(iframeName);
    var iframeObj = window.frames[iframe.name];
    if (!iframeObj) {
        iframeObj = iframe.contentWindow;
    }
    var body = iframe.innerHTML.replace(/(^\s*)|(\s*$)/g, "");
    if (!(/<\/?[^>]+>/gi.test(body))) {
        var div = document.createElement('div');
        div.innerHTML = body;
        body = div.childNodes[0] ? div.childNodes[0].nodeValue : '';
    }
    var baseHref = "";
    var head = document.getElementsByTagName("head")[0]
    var base = head.getElementsByTagName("base")[0];
    if (base) {
        baseHref = base.href;
    }
    var html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
    html += '<html xmlns="http://www.w3.org/1999/xhtml">'
    html += '<head>';
    if (base) {
        html += '<base href="' + baseHref + '"></base>';
    }
    html += '</head>';
    html += '<body style="margin: 0 0 0 0;">';
    html += body;
    html += '</body>';
    html += '</html>';
    window.open("", iframeName, "");
    iframeObj.document.open('text/html', 'replace');
    iframeObj.document.write(html);
    iframeObj.document.close();
}


function deferLoadADAll() {
    var iframes = document.getElementsByTagName("IFRAME");
    if (iframes) {
        for (var i = 0; i < iframes.length; i++) {
            var iframe = iframes[i];
            var defer = iframe.getAttribute("defer");
            if (defer && defer === "defer") {
                deferLoadAD(iframe.getAttribute("name"));
            }
        }
    }
}
